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.io.File;
 
 
Controller of the main application frame.

Author(s):
Andrus Adamchik
 
 public class CayenneModelerController extends CayenneController {
 
     protected ProjectController projectController;
 
     protected CayenneModelerFrame frame;
     protected File initialProject;
 
     public CayenneModelerController(Application applicationFile initialProject) {
         super(application);
 
         this. = initialProject;
         this. = new CayenneModelerFrame(application.getActionManager());
         this. = new ProjectController(this);
     }
 
     public Component getView() {
         return ;
     }
 
         return ;
     }
 
     public FSPath getLastEOModelDirectory() {
         // find start directory in preferences
 
         FSPath path = (FSPathgetViewDomain()
                 .getDetail("lastEOMDir"FSPath.classtrue);
 
         if (path.getPath() == null) {
             path.setPath(getLastDirectory().getPath());
         }
 
         return path;
     }
 
     protected void initBindings() {
 
         .addWindowListener(new WindowAdapter() {
 
             public void windowClosing(WindowEvent e) {
                 ((ExitActiongetApplication().getAction(ExitAction.getActionName()))
                         .exit();
             }
         });
 
         Domain prefDomain = .getPreferenceDomain().getSubdomain(
                 .getClass());
         ComponentGeometry geometry = ComponentGeometry.getPreference(prefDomain);
         geometry.bind(, 650, 550, 30);
     }
    public void startupAction() {
        initBindings();
        .setVisible(true);
        // open project
        if ( != null) {
            OpenProjectAction openAction = (OpenProjectActiongetApplication()
                    .getAction(OpenProjectAction.getActionName());
            openAction.openProject();
        }
    }
    public void projectModifiedAction() {
                ? "[New]"
                : .getProject().getMainFile().getAbsolutePath();
        .setTitle("* - " + . + " - " + title);
    }
    public void projectSavedAction() {
        .setDirty(false);
        updateStatus("Project saved...");
                + " - "
                + .getProject().getMainFile().getAbsolutePath());
    }

    
Action method invoked on project closing.
    public void projectClosedAction() {
        // --- update view
        .setView(null);
        // repaint is needed, since sometimes there is a
        // trace from menu left on the screen
        .repaint();
        .setProject(null);
        .reset();
        updateStatus("Project Closed...");
    }

    
Handles project opening control. Updates main frame, then delegates control to child controllers.
    public void projectOpenedAction(Project project) {
        .setProject(project);
        // do status update AFTER the project is actually opened...
        if (project.isLocationUndefined()) {
            updateStatus("New project created...");
            .setTitle(. + "- [New]");
        }
        else {
            updateStatus("Project opened...");
            .setTitle(.
                    + " - "
                    + project.getMainFile().getAbsolutePath());
        }
        // update preferences
        if (!project.isLocationUndefined()) {
            getLastDirectory().setDirectory(project.getProjectDirectory());
            RecentFileMenu recentFileMenu = .getRecentFileMenu();
            recentFileMenu.rebuildFromPreferences();
            recentFileMenu.setEnabled(recentFileMenu.getMenuComponentCount() > 0);
        }
        // --- check for load errors
        if (project.getLoadStatus().hasFailures()) {
            // mark project as unsaved
            project.setModified(true);
            .setDirty(true);
            // show warning dialog
            ValidatorDialog.showDialog(new Validator(projectproject
                    .getLoadStatus()));
        }
    }

    
Adds path to the list of last opened projects in preferences.
    public void addToLastProjListAction(String path) {
        ModelerPreferences pref = ModelerPreferences.getPreferences();
        Vector arr = pref.getVector(.);
        // Add proj path to the preferences
        // Prevent duplicate entries.
        if (arr.contains(path)) {
            arr.remove(path);
        }
        arr.insertElementAt(path, 0);
        while (arr.size() > 4) {
            arr.remove(arr.size() - 1);
        }
        Iterator iter = arr.iterator();
        while (iter.hasNext()) {
            pref.addProperty(.iter.next());
        }
    }

    
Performs status bar update with a message. Message will dissappear in 6 seconds.
    public void updateStatus(String message) {
        .getStatus().setText(message);
        // start message cleanup thread that would remove the message after X seconds
        if (message != null && message.trim().length() > 0) {
            Thread cleanup = new ExpireThread(message, 6);
            cleanup.start();
        }
    }
    class ExpireThread extends Thread {
        protected int seconds;
        protected String message;
        public ExpireThread(String messageint seconds) {
            this. = seconds;
            this. = message;
        }
        public void run() {
            try {
                sleep( * 1000);
            }
            catch (InterruptedException e) {
                // ignore exception
            }
            if (.equals(.getStatus().getText())) {
                updateStatus(null);
            }
        }
    }
New to GrepCode? Check out our FAQ X