Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.apache.cayenne.modeler;
 
 import java.awt.Frame;
 import java.io.File;
 
 
 import  org.scopemvc.controller.basic.ViewContext;
 import  org.scopemvc.controller.swing.SwingContext;
 import  org.scopemvc.core.View;
 import  org.scopemvc.util.UIStrings;
 import  org.scopemvc.view.swing.SwingView;

A main modeler application class that provides a number of services to the Modeler components. Configuration properties:
  • cayenne.modeler.application.name - name of the application, 'CayenneModeler' is default. Used to locate prerferences domain among other things.
  • cayenne.modeler.pref.version - a version of the preferences DB schema. Default is "1.1".

Author(s):
Andrus Adamchik
 
 public class Application {
 
     public static final String PREFERENCES_VERSION = "1.2";
     public static final String PREFERENCES_DB_SUBDIRECTORY = "prefs";
     public static final String PREFERENCES_MAP_PACKAGE = "pref";
     public static final String APPLICATION_NAME_PROPERTY = "cayenne.modeler.application.name";
     public static final String PREFERENCES_VERSION_PROPERTY = "cayenne.modeler.pref.version";
 
     public static final String DEFAULT_APPLICATION_NAME = "CayenneModeler";
 
     // TODO: implement cleaner IoC approach to avoid using this singleton...
     protected static Application instance;
 
     protected ActionManager actionManager;
 
     protected File initialProject;
     protected String name;
     protected String preferencesDB;
     protected BindingFactory bindingFactory;
     protected AdapterMapping adapterMapping;
 
     public static Application getInstance() {
         return ;
     }
 
     // static methods that should probabaly go away eventually...
 
     public static CayenneModelerFrame getFrame() {
         return (CayenneModelerFramegetInstance().getFrameController().getView();
     }
 
     public static Project getProject() {
    }
    public Application(File initialProject) {
        this. = initialProject;
        // configure startup settings
        String configuredName = System.getProperty();
        this. = (configuredName != null) ? configuredName : ;
        String subdir = System.getProperty();
        if (subdir == null) {
            subdir = ;
        }
        File dbDir = new File(CayenneUserDir.getInstance().resolveFile(
                ), subdir);
        dbDir.mkdirs();
        this. = new File(dbDir"db").getAbsolutePath();
    }
    public String getName() {
        return ;
    }
        return ;
    }
    public AdapterMapping getAdapterMapping() {
        return ;
    }

    
Returns an action for key.
    public CayenneAction getAction(String key) {
        return getActionManager().getAction(key);
    }

    
Returns action controller.
    public ActionManager getActionManager() {
        return ;
    }

    
Returns controller for the main frame.
        return ;
    }

    
Starts the application.
    public void startup() {
        // init subsystems
        initPreferences();
        initClassLoader();
        this. = new BindingFactory();
        this. = new AdapterMapping();
        // ...Scope
        // TODO: this will go away if switch away from Scope
        // force Scope to use CayenneModeler properties
        UIStrings.setPropertiesName(.);
        ViewContext.clearThreadContext();
        // init actions before the frame, as it will attempt to build menus out of
        // actions.
        this. = new ActionManager(this);
        // ...create main frame
        this. = new CayenneModelerController(this);
        // update Scope to work nicely with main frame
        ViewContext.setGlobalContext(new ModelerContext(.getFrame()));
        // open up
    }
    public BindingFactory getBindingFactory() {
        return ;
    }

    
Returns Application preferences service.
        return ;
    }

    
Returns top preferences Domain for the application.
    public Domain getPreferenceDomain() {
        return getPreferenceService().getDomain(getName(), true);
    }
    
    
Returns a new instance of CodeTemplateManager.
        return new CodeTemplateManager(this);
    }

    
Reinitializes ModelerClassLoader from preferences.
    public void initClassLoader() {
        final FileClassLoadingService classLoader = new FileClassLoadingService();
        // init from preferences...
        Domain classLoaderDomain = getPreferenceDomain().getSubdomain(
                FileClassLoadingService.class);
        Collection details = classLoaderDomain.getPreferences();
        if (details.size() > 0) {
            // transform preference to file...
            Transformer transformer = new Transformer() {
                public Object transform(Object object) {
                    DomainPreference pref = (DomainPreferenceobject;
                    return new File(pref.getKey());
                }
            };
            classLoader.setPathFiles(CollectionUtils.collect(detailstransformer));
        }
        this. = classLoader;
        // set as EventDispatch thread default class loader
        if (SwingUtilities.isEventDispatchThread()) {
            Thread.currentThread().setContextClassLoader(classLoader.getClassLoader());
        }
        else {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Thread.currentThread().setContextClassLoader(
                            classLoader.getClassLoader());
                }
            });
        }
    }
    protected void initPreferences() {
                ,
                ,
                getName());
        service.stopOnShutdown();
        this. = service;
        this..startService();
        // test service
        getPreferenceDomain();
    }
    static final class PreferencesDelegate implements
            HSQLEmbeddedPreferenceEditor.Delegate {
        static final String message = "Preferences Database is locked by another application. "
                + "Do you want to remove the lock?";
        static final String failureMessage = "Failed to remove database lock. "
                + "Preferences will we saved for this session only.";
        public boolean deleteMasterLock(File lock) {
            int result = JOptionPane.showConfirmDialog(null);
            if (result == . || result == .) {
                if (!lock.delete()) {
                    JOptionPane.showMessageDialog(null);
                    return false;
                }
            }
            return true;
        }
    }
    final class ModelerContext extends SwingContext {
        JFrame frame;
        public ModelerContext(JFrame frame) {
            this. = frame;
        }
        protected void showViewInPrimaryWindow(SwingView view) {
        }

        
Creates closeable dialogs.
        protected void showViewInDialog(SwingView inView) {
            // NOTE:
            // copied from superclass, except that JDialog is substituted for
            // CayenneDialog
            // Keep in mind when upgrading Scope to the newer versions.
            // Make a JDialog to contain the view.
            Window parentWindow = getDefaultParentWindow();
            final CayenneDialog dialog;
            if (parentWindow instanceof Dialog) {
                dialog = new CayenneDialog((DialogparentWindow);
            }
            else {
                dialog = new CayenneDialog((FrameparentWindow);
            }
            // Set title, modality, resizability
            if (inView.getTitle() != null) {
                dialog.setTitle(inView.getTitle());
            }
            if (inView.getDisplayMode() == SwingView.MODAL_DIALOG) {
                dialog.setModal(true);
            }
            else {
                dialog.setModal(false);
            }
            dialog.setResizable(inView.isResizable());
            setupWindow(dialog.getRootPane(), inViewtrue);
            dialog.toFront();
        }

        
Overrides super implementation to allow using Scope together with normal Swing code that CayenneModeler already has.
        public JRootPane findRootPaneFor(View view) {
            JRootPane pane = super.findRootPaneFor(view);
            if (pane != null) {
                return pane;
            }
            if (((SwingView) view).getDisplayMode() != SwingView.PRIMARY_WINDOW) {
                return pane;
            }
            return .getRootPane();
        }
        protected Window getDefaultParentWindow() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X