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 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  org.apache.cayenne.project.CayenneUserDir;
 import  org.apache.cayenne.project.Project;
 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:
  • - 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".
 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 = "";
     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;
     protected CayenneUndoManager undoManager;
     // This is for OS X support
     private boolean isQuittingApplication = false;
     public static Application getInstance() {
         return ;
     // static methods that should probably go away eventually...
    public static CayenneModelerFrame getFrame() {
    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);
        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 undo-edits controller.
        return ;

Returns controller for the main frame.
        return ;

Starts the application.
    public void startup() {
        // init subsystems
        this. = new BindingFactory();
        this. = new AdapterMapping();
        // ...Scope
        // TODO: this will go away if switch away from Scope
        // force Scope to use CayenneModeler properties
        // init actions before the frame, as it will attempt to build menus out of
        // actions.
        this. = new ActionManager(this);
        this. = new org.apache.cayenne.modeler.undo.CayenneUndoManager(this);
        // ...create main frame
        this. = new CayenneModelerController(this);
        // update Scope to work nicely with main frame
        ViewContext.setGlobalContext(new ModelerContext(.getFrame()));
        // open up
After prefs have been loaded, we can now show the console if needed
    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(
        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());
        this. = classLoader;
        // set as EventDispatch thread default class loader
        if (SwingUtilities.isEventDispatchThread()) {
        else {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
    protected void initPreferences() {
        this. = service;
        // test service
    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()) {
                    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) {
            if (inView.getDisplayMode() == SwingView.MODAL_DIALOG) {
            else {
            setupWindow(dialog.getRootPane(), inViewtrue);

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 ;
    public boolean isQuittingApplication() {
        return ;
    public void setQuittingApplication(boolean isQuittingApplication) {
        this. = isQuittingApplication;
New to GrepCode? Check out our FAQ X