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.util;
 
 import java.awt.Point;
 
 
 import  org.apache.log4j.Logger;
 import  org.apache.cayenne.util.Util;

A superclass of CayenneModeler controllers.

Author(s):
Andrus Adamchik
 
 public abstract class CayenneController implements BoundComponent {
 
     private static final Logger logObj = Logger.getLogger(CayenneController.class);
 
     protected CayenneController parent;
     protected Application application;
 
     public CayenneController(CayenneController parent) {
         this. = (parent != null) ? parent.getApplication() : null;
         this. = parent;
     }
 
     public CayenneController(Application application) {
         this. = application;
     }
 
     public Application getApplication() {
         return ;
     }
 
     public CayenneController getParent() {
         return ;
     }

    
Returns the vie wassociated with this Controller.
 
     public abstract Component getView();

    
Returns last file system directory visited by user for this component. If there is no such directory set up in the preferences, creates a new object, setting its path to the parent last directory or to the user HOME directory.
 
     public FSPath getLastDirectory() {
         // find start directory in preferences
         FSPath path = (FSPathgetViewDomain().getDetail("lastDir"FSPath.classtrue);
 
         if (path.getPath() == null) {
 
             String pathString = (getParent() != null) ? getParent()
                     .getLastDirectory()
                     .getPath() : System.getProperty("user.home");
             path.setPath(pathString);
         }
 
         return path;
     }

    
Returns preference domaing for this component view.
    protected Domain getViewDomain() {
    }

    
Utility method to provide a visual indication an execution error. This implementation logs an error and pops up a dialog window with error message.
    protected void reportError(String titleThrowable th) {
        th = Util.unwindException(th);
        .info("Error in " + getClass().getName(), th);
        JOptionPane.showMessageDialog(getView(),
                th.getMessage(),
                title,
                .);
    }

    
Centers view on parent window.
    protected void centerView() {
        Window parentWindow = .getWindow();
        Dimension parentSize = parentWindow.getSize();
        Dimension windowSize = getView().getSize();
        Point parentLocation = new Point(0, 0);
        if (parentWindow.isShowing()) {
            parentLocation = parentWindow.getLocationOnScreen();
        }
        int x = parentLocation.x + parentSize.width / 2 - windowSize.width / 2;
        int y = parentLocation.y + parentSize.height / 2 - windowSize.height / 2;
        getView().setLocation(xy);
    }

    
If this view or a parent view is a JDialog, makes it closeable on ESC hit. Dialog "defaultCloseOperation" property is taken into account when processing ESC button click.
    protected void makeCloseableOnEscape() {
        Window window = getWindow();
        if (!(window instanceof JDialog)) {
            return;
        }
        final JDialog dialog = (JDialogwindow;
        KeyStroke escReleased = KeyStroke.getKeyStroke(., 0, true);
        ActionListener closeAction = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (dialog.isVisible()) {
                    switch (dialog.getDefaultCloseOperation()) {
                        case .:
                            dialog.setVisible(false);
                            break;
                        case .:
                            dialog.setVisible(false);
                            dialog.dispose();
                            break;
                        case .:
                        default:
                            break;
                    }
                }
            }
        };
        dialog.getRootPane().registerKeyboardAction(closeAction,
                escReleased,
                .);
    }

    
Finds a Window in the view hierarchy.
    public Window getWindow() {
        Component view = getView();
        while (view != null) {
            if (view instanceof Window) {
                return (Windowview;
            }
            view = view.getParent();
        }
        return null;
    }

    
Finds a JFrame in the view hierarchy.
    public JFrame getFrame() {
        Component view = getView();
        while (view != null) {
            if (view instanceof JFrame) {
                return (JFrameview;
            }
            view = view.getParent();
        }
        return null;
    }

    
Fires property change event. Exists for the benefit of subclasses.
    protected void firePropertyChange(
            String propertyName,
            Object oldValue,
            Object newValue) {
        if ( != null) {
            .firePropertyChange(propertyNameoldValuenewValue);
        }
    }

    
Adds a listener for property change events.
    public void addPropertyChangeListener(
            String expression,
            PropertyChangeListener listener) {
        if ( == null) {
             = new PropertyChangeSupport(this);
        }
        .addPropertyChangeListener(expressionlistener);
    }

    
Default implementation is a noop. Override to handle parent binding updates.
    public void bindingUpdated(String expressionObject newValue) {
        // do nothing...
    }
New to GrepCode? Check out our FAQ X