cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r412739 - in /incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne: modeler/dialog/codegen/ modeler/dialog/pref/ swing/ swing/control/
Date Thu, 08 Jun 2006 12:59:49 GMT
Author: aadamchik
Date: Thu Jun  8 05:59:48 2006
New Revision: 412739

URL: http://svn.apache.org/viewvc?rev=412739&view=rev
Log:
CAY-562

Modified:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/codegen/GeneratorController.java
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/pref/TemplateCreator.java
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/BindingFactory.java
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/control/FileChooser.java

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/codegen/GeneratorController.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/codegen/GeneratorController.java?rev=412739&r1=412738&r2=412739&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/codegen/GeneratorController.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/codegen/GeneratorController.java
Thu Jun  8 05:59:48 2006
@@ -366,17 +366,39 @@
      * Returns a predicate for default entity selection in a given mode.
      */
     public Predicate getDefaultEntityFilter() {
-        return new Predicate() {
+        final ObjEntity selectedEntity = Application
+                .getInstance()
+                .getFrameController()
+                .getProjectController()
+                .getCurrentObjEntity();
 
-            public boolean evaluate(Object object) {
-                if (object instanceof ObjEntity) {
-                    return getParentController().getProblem(
-                            ((ObjEntity) object).getName()) == null;
+        // select a single entity
+        if (selectedEntity != null) {
+            final boolean hasProblem = getParentController().getProblem(
+                    selectedEntity.getName()) != null;
+
+            return new Predicate() {
+
+                public boolean evaluate(Object object) {
+                    return !hasProblem && object == selectedEntity;
                 }
+            };
+        }
+        // select all entities
+        else {
+
+            return new Predicate() {
 
-                return false;
-            }
-        };
+                public boolean evaluate(Object object) {
+                    if (object instanceof ObjEntity) {
+                        return getParentController().getProblem(
+                                ((ObjEntity) object).getName()) == null;
+                    }
+
+                    return false;
+                }
+            };
+        }
     }
 
     public File getOutputDir() {

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/pref/TemplateCreator.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/pref/TemplateCreator.java?rev=412739&r1=412738&r2=412739&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/pref/TemplateCreator.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/modeler/dialog/pref/TemplateCreator.java
Thu Jun  8 05:59:48 2006
@@ -56,6 +56,8 @@
 package org.objectstyle.cayenne.modeler.dialog.pref;
 
 import java.awt.Component;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -70,6 +72,7 @@
 import org.objectstyle.cayenne.pref.Domain;
 import org.objectstyle.cayenne.pref.PreferenceEditor;
 import org.objectstyle.cayenne.swing.BindingBuilder;
+import org.objectstyle.cayenne.swing.control.FileChooser;
 import org.objectstyle.cayenne.util.Util;
 
 public class TemplateCreator extends CayenneController {
@@ -103,6 +106,21 @@
         return view;
     }
 
+    FSPath getLastTemplateDirectory() {
+        // find start directory in preferences
+
+        FSPath path = (FSPath) getViewDomain().getDetail(
+                "lastTemplate",
+                FSPath.class,
+                true);
+
+        if (path.getPath() == null) {
+            path.setPath(getLastDirectory().getPath());
+        }
+
+        return path;
+    }
+
     protected void initBindings() {
         BindingBuilder builder = new BindingBuilder(
                 getApplication().getBindingFactory(),
@@ -110,6 +128,18 @@
 
         builder.bindToAction(view.getCancelButton(), "cancelAction()");
         builder.bindToAction(view.getOkButton(), "okAction()");
+
+        final FSPath path = getLastTemplateDirectory();
+        view.getTemplateChooser().setCurrentDirectory(path.getExistingDirectory(false));
+        view.getTemplateChooser().addPropertyChangeListener(
+                FileChooser.CURRENT_DIRECTORY_PROPERTY,
+                new PropertyChangeListener() {
+
+                    public void propertyChange(PropertyChangeEvent evt) {
+                        File directory = view.getTemplateChooser().getCurrentDirectory();
+                        path.setDirectory(directory);
+                    }
+                });
     }
 
     public void okAction() {

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/BindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/BindingFactory.java?rev=412739&r1=412738&r2=412739&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/BindingFactory.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/BindingFactory.java
Thu Jun  8 05:59:48 2006
@@ -66,7 +66,7 @@
 /**
  * A factory for a number of common bindings.
  * 
- * @author Andrei Adamchik
+ * @author Andrus Adamchik
  */
 public class BindingFactory {
 

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/control/FileChooser.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/control/FileChooser.java?rev=412739&r1=412738&r2=412739&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/control/FileChooser.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/modeler/java/org/objectstyle/cayenne/swing/control/FileChooser.java
Thu Jun  8 05:59:48 2006
@@ -72,17 +72,22 @@
 import com.jgoodies.forms.layout.FormLayout;
 
 /**
- * A control that renders as a text field and a button to choose a file.
+ * A control that renders as a text field and a button to choose a file. Fires a property
+ * change event when a current directory is changed, either explictly or during a file
+ * selection by the user.
  * 
  * @author Andrus Adamchik
  */
 public class FileChooser extends JPanel {
 
+    public static final String CURRENT_DIRECTORY_PROPERTY = "currentDirectory";
+
     protected boolean existingOnly;
     protected boolean allowFiles;
     protected boolean allowDirectories;
     protected FileFilter fileFilter;
     protected String title;
+    protected File currentDirectory;
 
     protected JTextField fileName;
     protected JButton chooseButton;
@@ -144,7 +149,9 @@
             chooser.setFileFilter(fileFilter);
         }
 
-        // getLastDirectory().updateChooser(chooser);
+        if (currentDirectory != null) {
+            chooser.setCurrentDirectory(currentDirectory);
+        }
 
         chooser.setDialogTitle(makeTitle(mode));
 
@@ -153,6 +160,8 @@
             File selected = chooser.getSelectedFile();
             fileName.setText(selected != null ? selected.getAbsolutePath() : "");
         }
+
+        setCurrentDirectory(chooser.getCurrentDirectory());
     }
 
     protected String makeTitle(int selectionMode) {
@@ -232,5 +241,20 @@
 
     public int getColumns() {
         return fileName.getColumns();
+    }
+
+    /**
+     * Returns the last directory visited when picking a file.
+     */
+    public File getCurrentDirectory() {
+        return currentDirectory;
+    }
+
+    public void setCurrentDirectory(File currentDirectory) {
+        if (!Util.nullSafeEquals(this.currentDirectory, currentDirectory)) {
+            File oldValue = this.currentDirectory;
+            this.currentDirectory = currentDirectory;
+            firePropertyChange(CURRENT_DIRECTORY_PROPERTY, oldValue, currentDirectory);
+        }
     }
 }



Mime
View raw message