cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r919452 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/ modeler/action/ modeler/dialog/ modeler/dialog/codegen/ modeler/dialog/pref/ modeler/pref/ pref/
Date Fri, 05 Mar 2010 15:37:09 GMT
Author: oltka
Date: Fri Mar  5 15:37:08 2010
New Revision: 919452

URL: http://svn.apache.org/viewvc?rev=919452&view=rev
Log:
CAY-1327  Migrate HSQLDB modeler preferences to Java preferences API

* Remove Domain, DomainPreference, PreferenceService

Removed:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/PreferencesDataSourceFactory.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceService.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Domain.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/DomainPreference.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceService.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PrefDetail.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceService.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/_Domain.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/_DomainPreference.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferencesView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceDetail.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceEditor.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
Fri Mar  5 15:37:08 2010
@@ -29,7 +29,6 @@
 import java.util.prefs.Preferences;
 
 import javax.swing.JFrame;
-import javax.swing.JOptionPane;
 import javax.swing.JRootPane;
 import javax.swing.SwingUtilities;
 
@@ -47,10 +46,6 @@
 import org.apache.cayenne.modeler.util.CayenneUserDir;
 import org.apache.cayenne.pref.CayennePreference;
 import org.apache.cayenne.pref.CayenneProjectPreferences;
-import org.apache.cayenne.pref.Domain;
-import org.apache.cayenne.pref.HSQLEmbeddedPreferenceEditor;
-import org.apache.cayenne.pref.HSQLEmbeddedPreferenceService;
-import org.apache.cayenne.pref.PreferenceService;
 import org.apache.cayenne.project2.CayenneProjectModule;
 import org.apache.cayenne.project2.Project;
 import org.apache.cayenne.swing.BindingFactory;
@@ -87,7 +82,6 @@
     protected static Application instance;
 
     protected FileClassLoadingService modelerClassLoader;
-    protected HSQLEmbeddedPreferenceService preferenceService;
     protected ActionManager actionManager;
     protected CayenneModelerController frameController;
 
@@ -239,24 +233,10 @@
         return bindingFactory;
     }
 
-    /**
-     * Returns Application preferences service.
-     */
-    public PreferenceService getPreferenceService() {
-        return preferenceService;
-    }
-
     public CayenneProjectPreferences getCayenneProjectPreferences() {
         return cayenneProjectPreferences;
     }
 
-    /**
-     * Returns top preferences Domain for the application.
-     */
-    public Domain getPreferenceDomain() {
-        return getPreferenceService().getDomain(getName(), true);
-    }
-
     public static Preferences getMainPreferenceForProject() {
         String path = CayennePreference
                 .filePathToPrefereceNodePath(((DataChannelDescriptor) getProject()
@@ -332,40 +312,7 @@
     }
 
     protected void initPreferences() {
-        HSQLEmbeddedPreferenceService service = new HSQLEmbeddedPreferenceService(
-                preferencesDB,
-                PREFERENCES_MAP_PACKAGE,
-                getName());
         this.cayenneProjectPreferences = new CayenneProjectPreferences();
-        service.stopOnShutdown();
-        this.preferenceService = service;
-        this.preferenceService.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.";
-
-        static final HSQLEmbeddedPreferenceEditor.Delegate sharedInstance = new PreferencesDelegate();
-
-        public boolean deleteMasterLock(File lock) {
-            int result = JOptionPane.showConfirmDialog(null, message);
-            if (result == JOptionPane.YES_OPTION || result == JOptionPane.OK_OPTION) {
-                if (!lock.delete()) {
-                    JOptionPane.showMessageDialog(null, failureMessage);
-                    return false;
-                }
-            }
-
-            return true;
-        }
     }
 
     final class ModelerContext extends SwingContext {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerController.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerController.java
Fri Mar  5 15:37:08 2010
@@ -42,7 +42,6 @@
 import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog;
 import org.apache.cayenne.modeler.editor.EditorView;
 import org.apache.cayenne.modeler.pref.ComponentGeometry;
-import org.apache.cayenne.modeler.pref.DataMapDefaults;
 import org.apache.cayenne.modeler.pref.FSPath;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.project2.Project;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
Fri Mar  5 15:37:08 2010
@@ -116,7 +116,6 @@
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.modeler.util.CircularArray;
 import org.apache.cayenne.modeler.util.Comparators;
-import org.apache.cayenne.pref.Domain;
 import org.apache.cayenne.project.ProjectPath;
 import org.apache.cayenne.project2.Project;
 import org.apache.cayenne.query.Query;
@@ -263,7 +262,6 @@
     protected boolean dirty;
 
     protected Project project;
-    protected Domain projectPreferences;
 
     protected Preferences projectControllerPreferences;
 
@@ -306,7 +304,6 @@
         {
 
             this.project = currentProject;
-            this.projectPreferences = null;
             this.projectControllerPreferences = null;
 
             if (project == null) // null project -> no files to watch
@@ -342,13 +339,6 @@
         }
     }
 
-    /**
-     * Returns top preferences Domain for the application.
-     */
-    public Domain getApplicationPreferenceDomain() {
-        return getApplication().getPreferenceDomain();
-    }
-
     public void updateEntityResolver() {
 
         entityResolver.clearCache();
@@ -362,29 +352,6 @@
         }
     }
 
-    /**
-     * Returns top preferences Domain for the current project, throwing an exception if no
-     * project is selected.
-     */
-    public Domain getPreferenceDomainForProject() {
-        if (getProject() == null) {
-            throw new CayenneRuntimeException("No Project selected");
-        }
-
-        if (projectPreferences == null) {
-            String key = getProject().getConfigurationResource() == null ? new String(
-                    IDUtil.pseudoUniqueByteSequence16()) : project
-                    .getConfigurationResource()
-                    .getURL()
-                    .getPath();
-
-            projectPreferences = getApplicationPreferenceDomain().getSubdomain(
-                    Project.class).getSubdomain(key);
-        }
-
-        return projectPreferences;
-    }
-
     public Preferences getPreferenceForProject() {
         if (getProject() == null) {
             throw new CayenneRuntimeException("No Project selected");

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAction.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAction.java
Fri Mar  5 15:37:08 2010
@@ -26,7 +26,6 @@
 
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.pref.CayennePreferenceForProject;
-import org.apache.cayenne.pref.Domain;
 import org.apache.cayenne.project2.Project;
 import org.apache.cayenne.project2.ProjectSaver;
 
@@ -63,8 +62,6 @@
         else {
 
             String oldPath = p.getConfigurationResource().getURL().getPath();
-            // obtain preference object before save, when the project path may change.....
-            Domain preference = getProjectController().getPreferenceDomainForProject();
 
             getProjectController().getProjectWatcher().pauseWatching();
 
@@ -72,8 +69,6 @@
                     ProjectSaver.class);
             saver.save(p);
 
-            preference.rename(p.getConfigurationResource().getURL().getPath());
-
             CayennePreferenceForProject.removeOldPreferences();
 
             // if change DataChanelDescriptor name - as result change name of xml file

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
Fri Mar  5 15:37:08 2010
@@ -35,7 +35,6 @@
 import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.pref.CayennePreferenceForProject;
-import org.apache.cayenne.pref.Domain;
 import org.apache.cayenne.project.ProjectPath;
 import org.apache.cayenne.project2.Project;
 import org.apache.cayenne.project2.ProjectSaver;
@@ -83,9 +82,6 @@
             oldPath = p.getConfigurationResource().getURL().getPath();
         }
 
-        // obtain preference object before save, when the project path may change.....
-        Domain preference = getProjectController().getPreferenceDomainForProject();
-
         File projectDir = fileChooser.newProjectDir(Application.getFrame(), p);
         if (projectDir == null) {
             return false;
@@ -112,9 +108,6 @@
                 ProjectSaver.class);
         saver.saveAs(p, res);
 
-        // update preferences domain key
-        preference.rename(projectDir.getPath());
-
         if (oldPath != null
                 && oldPath.length() != 0
                 && !oldPath.equals(p.getConfigurationResource().getURL().getPath()))
{

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
Fri Mar  5 15:37:08 2010
@@ -62,7 +62,6 @@
         if (shouldDelete) {
             Preferences pref = Application.getInstance().getPreferencesNode(ClassGenerationAction.class,
"");
             pref.putBoolean(GeneralPreferences.DELETE_PROMPT_PREFERENCE, neverPromptAgainBox.isSelected());
-            Application.getInstance().getPreferenceService().savePreferences();
         }
     }
     

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorTabController.java
Fri Mar  5 15:37:08 2010
@@ -26,7 +26,7 @@
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.pref.CayenneProjectPreferences;
-import org.apache.cayenne.pref.PrefDetail;
+import org.apache.cayenne.pref.PreferenceDetail;
 import org.apache.cayenne.swing.BindingBuilder;
 import org.apache.cayenne.util.Util;
 
@@ -46,7 +46,7 @@
 
     protected GeneratorTabPanel view;
     protected Map controllers;
-    protected PrefDetail preferences;
+    protected PreferenceDetail preferences;
 
     public GeneratorTabController(CodeGeneratorControllerBase parent) {
         super(parent);
@@ -85,7 +85,7 @@
         
         CayenneProjectPreferences cayPrPref = application.getCayenneProjectPreferences();
         
-        this.preferences = (PrefDetail) cayPrPref.getProjectDetailObject(PrefDetail.class,
getViewPreferences().node("controller"));
+        this.preferences = (PreferenceDetail) cayPrPref.getProjectDetailObject(PreferenceDetail.class,
getViewPreferences().node("controller"));
         
         if (Util.isEmptyString(preferences.getProperty("mode"))) {
             preferences.setProperty("mode", STANDARD_OBJECTS_MODE);
@@ -99,7 +99,7 @@
     }
 
     
-    public PrefDetail getPreferences() {
+    public PreferenceDetail getPreferences() {
         return preferences;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
Fri Mar  5 15:37:08 2010
@@ -20,23 +20,19 @@
 package org.apache.cayenne.modeler.dialog.pref;
 
 import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.FileClassLoadingService;
-import org.apache.cayenne.pref.Domain;
-import org.apache.cayenne.pref.HSQLEmbeddedPreferenceEditor;
-import org.apache.cayenne.pref.HSQLEmbeddedPreferenceService;
-import org.apache.cayenne.pref.PreferenceDetail;
+import org.apache.cayenne.pref.CayennePreferenceEditor;
 
 /**
  * Specialized preferences editor for CayenneModeler.
  * 
  */
-public class CayenneModelerPreferenceEditor extends HSQLEmbeddedPreferenceEditor {
+public class CayenneModelerPreferenceEditor extends CayennePreferenceEditor {
 
     protected boolean refreshingClassLoader;
     protected Application application;
 
     public CayenneModelerPreferenceEditor(Application application) {
-        super((HSQLEmbeddedPreferenceService) application.getPreferenceService(), application.getCayenneProjectPreferences());
+        super(application.getCayenneProjectPreferences());
         this.application = application;
     }
 
@@ -57,21 +53,7 @@
         }
     }
 
-    public PreferenceDetail createDetail(Domain domain, String key) {
-        changeInDomain(domain);
-        return super.createDetail(domain, key);
-    }
-
-    public PreferenceDetail deleteDetail(Domain domain, String key) {
-        changeInDomain(domain);
-        return super.deleteDetail(domain, key);
-    }
-
-    protected void changeInDomain(Domain domain) {
-        if (!refreshingClassLoader
-                && domain != null
-                && FileClassLoadingService.class.getName().equals(domain.getName()))
{
-            refreshingClassLoader = true;
-        }
+    @Override
+    protected void restart() {
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferences.java
Fri Mar  5 15:37:08 2010
@@ -27,11 +27,9 @@
 import org.apache.cayenne.gen.ClassGenerationAction;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.pref.CayennePreferenceEditor;
-import org.apache.cayenne.pref.CayennePreferenceService;
 import org.apache.cayenne.pref.PreferenceEditor;
 import org.apache.cayenne.swing.BindingBuilder;
 import org.apache.cayenne.swing.ObjectBinding;
-import org.apache.cayenne.validation.ValidationException;
 
 /**
  */
@@ -50,7 +48,6 @@
 
     protected Preferences preferences;
 
-    protected ObjectBinding saveIntervalBinding;
     protected ObjectBinding encodingBinding;
     protected ObjectBinding autoLoadProjectBinding;
     protected ObjectBinding deletePromptBinding;
@@ -65,7 +62,6 @@
             this.view.setEnabled(true);
             initBindings();
 
-            saveIntervalBinding.updateView();
             encodingBinding.updateView();
             autoLoadProjectBinding.updateView();
             deletePromptBinding.updateView();
@@ -101,10 +97,6 @@
                 getApplication().getBindingFactory(),
                 this);
 
-        this.saveIntervalBinding = builder.bindToTextField(
-                view.getSaveInterval(),
-                "timeInterval");
-
         this.encodingBinding = builder.bindToProperty(
                 encodingSelector,
                 "encoding",
@@ -119,10 +111,6 @@
                 "deletePrompt");
     }
 
-    public double getTimeInterval() {
-        return this.editor.getSaveInterval() / 1000.0;
-    }
-
     public String getEncoding() {
         return encoding;
     }
@@ -132,17 +120,6 @@
         this.encoding = encoding;
     }
 
-    public void setTimeInterval(double d) {
-        int ms = (int) (d * 1000.0);
-        if (ms < CayennePreferenceService.MIN_SAVE_INTERVAL) {
-            throw new ValidationException(
-                    "Time interval is too small, minimum allowed is "
-                            + (CayennePreferenceService.MIN_SAVE_INTERVAL / 1000.0));
-        }
-
-        this.editor.setSaveInterval(ms);
-    }
-
     public boolean getAutoLoadProject() {
         return autoLoadProjectPreference;
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferencesView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferencesView.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferencesView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/GeneralPreferencesView.java
Fri Mar  5 15:37:08 2010
@@ -30,17 +30,13 @@
  */
 public class GeneralPreferencesView extends JPanel {
 
-    protected JTextField saveInterval;
-    protected JLabel saveIntervalLabel;
     protected EncodingSelectorView encodingSelector;
     protected JLabel encodingSelectorLabel;
     protected JCheckBox autoLoadProjectBox;
     protected JCheckBox deletePromptBox;
 
     public GeneralPreferencesView() {
-        this.saveInterval = new JTextField();
         this.encodingSelector = new EncodingSelectorView();
-        this.saveIntervalLabel = new JLabel("Preferences Save Interval (sec):");
         this.encodingSelectorLabel = new JLabel("File Encoding:");
         this.autoLoadProjectBox = new JCheckBox("Automatically Load Last Opened Project");
         this.deletePromptBox = new JCheckBox("Always Delete Items Without Prompt");
@@ -53,8 +49,7 @@
         PanelBuilder builder = new PanelBuilder(layout);
         builder.setDefaultDialogBorder();
         builder.addSeparator("General Preferences", cc.xyw(1, 1, 5));
-        builder.add(saveIntervalLabel, cc.xy(1, 3));
-        builder.add(saveInterval, cc.xy(3, 3));
+
         builder.add(encodingSelectorLabel, cc.xy(1, 5));
         builder.add(encodingSelector, cc.xywh(3, 5, 3, 3));
         builder.add(autoLoadProjectBox, cc.xy(1, 7, CellConstraints.LEFT, CellConstraints.DEFAULT));
@@ -68,18 +63,13 @@
 
     public void setEnabled(boolean b) {
         super.setEnabled(b);
-        saveInterval.setEnabled(b);
-        saveIntervalLabel.setEnabled(b);
+
         encodingSelector.setEnabled(b);
         encodingSelectorLabel.setEnabled(b);
         autoLoadProjectBox.setEnabled(b);
         deletePromptBox.setEnabled(b);
     }
 
-    public JTextField getSaveInterval() {
-        return saveInterval;
-    }
-
     public EncodingSelectorView getEncodingSelector() {
         return encodingSelector;
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
Fri Mar  5 15:37:08 2010
@@ -27,40 +27,28 @@
 import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
 
-import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-
 /**
  * An editor for modifying CayennePreferenceService.
  * 
  */
 public abstract class CayennePreferenceEditor implements PreferenceEditor {
 
-    protected CayennePreferenceService service;
-    protected DataContext editingContext;
     protected boolean restartRequired;
-    protected int saveInterval;
     protected CayenneProjectPreferences cayenneProjectPreferences;
     private Map<Preferences, Map<String, String>> changedPreferences;
     private Map<Preferences, Map<String, String>> removedPreferences;
     private Map<Preferences, Map<String, Boolean>> changedBooleanPreferences;
     private List<Preferences> removedNode;
     private List<Preferences> addedNode;
-    
+
     private static Log logger = LogFactory.getLog(CayennePreferenceEditor.class);
 
-    public CayennePreferenceEditor(CayennePreferenceService service,
-            CayenneProjectPreferences cayenneProjectPreferences) {
-        this.service = service;
-        this.editingContext = service
-                .getDataContext()
-                .getParentDataDomain()
-                .createDataContext();
-        this.saveInterval = service.getSaveInterval();
+    public CayennePreferenceEditor(CayenneProjectPreferences cayenneProjectPreferences) {
         this.cayenneProjectPreferences = cayenneProjectPreferences;
         this.changedPreferences = new HashMap<Preferences, Map<String, String>>();
         this.removedPreferences = new HashMap<Preferences, Map<String, String>>();
@@ -68,12 +56,11 @@
         this.removedNode = new ArrayList<Preferences>();
         this.addedNode = new ArrayList<Preferences>();
     }
-    
-    
+
     public List<Preferences> getAddedNode() {
         return addedNode;
     }
-    
+
     public List<Preferences> getRemovedNode() {
         return removedNode;
     }
@@ -82,7 +69,6 @@
         return removedPreferences;
     }
 
-
     public Map<Preferences, Map<String, String>> getChangedPreferences() {
         return changedPreferences;
     }
@@ -99,75 +85,8 @@
         this.restartRequired = restartOnSave;
     }
 
-    protected DataContext getEditingContext() {
-        return editingContext;
-    }
-
-    public Domain editableInstance(Domain object) {
-        if (object.getObjectContext() == getEditingContext()) {
-            return object;
-        }
-
-        return (Domain) getEditingContext().localObject(object.getObjectId(), null);
-    }
-
-    public PreferenceDetail createDetail(Domain domain, String key) {
-        domain = editableInstance(domain);
-        DomainPreference preference = getEditingContext().newObject(
-                DomainPreference.class);
-        preference.setDomain(domain);
-        preference.setKey(key);
-
-        return preference.getPreference();
-    }
-
-    public PreferenceDetail createDetail(Domain domain, String key, Class javaClass) {
-        domain = editableInstance(domain);
-        DomainPreference preferenceLink = getEditingContext().newObject(
-                DomainPreference.class);
-        preferenceLink.setDomain(domain);
-        preferenceLink.setKey(key);
-
-        PreferenceDetail detail = (PreferenceDetail) getEditingContext().newObject(
-                javaClass);
-
-        detail.setDomainPreference(preferenceLink);
-        return detail;
-    }
-
-    public PreferenceDetail deleteDetail(Domain domain, String key) {
-        domain = editableInstance(domain);
-        PreferenceDetail detail = domain.getDetail(key, false);
-
-        if (detail != null) {
-            DomainPreference preference = detail.getDomainPreference();
-            preference.setDomain(null);
-            getEditingContext().deleteObject(preference);
-            getEditingContext().deleteObject(detail);
-        }
-
-        return detail;
-    }
-
-    public int getSaveInterval() {
-        return saveInterval;
-    }
-
-    public void setSaveInterval(int ms) {
-        if (saveInterval != ms) {
-            saveInterval = ms;
-            restartRequired = true;
-        }
-    }
-
-    public PreferenceService getService() {
-        return service;
-    }
-
     public void save() {
         cayenneProjectPreferences.getDetailObject(DBConnectionInfo.class).save();
-        service.setSaveInterval(saveInterval);
-        editingContext.commitChanges();
 
         if (restartRequired) {
             restart();
@@ -178,41 +97,41 @@
         while (it.hasNext()) {
             Map.Entry entry = (Map.Entry) it.next();
             Preferences pref = (Preferences) entry.getKey();
-            Map<String, Boolean> map =  (Map<String, Boolean>) entry.getValue();
+            Map<String, Boolean> map = (Map<String, Boolean>) entry.getValue();
 
             Iterator iterator = map.entrySet().iterator();
             while (iterator.hasNext()) {
                 Map.Entry en = (Map.Entry) iterator.next();
                 String key = (String) en.getKey();
                 Boolean value = (Boolean) en.getValue();
-                
+
                 pref.putBoolean(key, value);
             }
         }
-        
+
         // update string preferences
         Iterator iter = changedPreferences.entrySet().iterator();
         while (iter.hasNext()) {
             Map.Entry entry = (Map.Entry) iter.next();
             Preferences pref = (Preferences) entry.getKey();
-            Map<String, String> map =  (Map<String, String>) entry.getValue();
+            Map<String, String> map = (Map<String, String>) entry.getValue();
 
             Iterator iterator = map.entrySet().iterator();
             while (iterator.hasNext()) {
                 Map.Entry en = (Map.Entry) iterator.next();
                 String key = (String) en.getKey();
                 String value = (String) en.getValue();
-                
+
                 pref.put(key, value);
             }
         }
-        
+
         // remove string preferences
         Iterator iterator = removedPreferences.entrySet().iterator();
         while (iterator.hasNext()) {
             Map.Entry entry = (Map.Entry) iterator.next();
             Preferences pref = (Preferences) entry.getKey();
-            Map<String, String> map =  (Map<String, String>) entry.getValue();
+            Map<String, String> map = (Map<String, String>) entry.getValue();
 
             Iterator itRem = map.entrySet().iterator();
             while (itRem.hasNext()) {
@@ -221,38 +140,37 @@
                 pref.remove(key);
             }
         }
-        
+
         // remove preferences node
         Iterator<Preferences> iteratorNode = removedNode.iterator();
         while (iteratorNode.hasNext()) {
-             Preferences pref = iteratorNode.next();
-             try {
+            Preferences pref = iteratorNode.next();
+            try {
                 pref.removeNode();
             }
             catch (BackingStoreException e) {
                 logger.warn("Error removing preferences");
             }
         }
-        
+
         Application.getInstance().initClassLoader();
     }
 
     public void revert() {
-        
+
         // remove added preferences node
         Iterator<Preferences> iteratorNode = addedNode.iterator();
         while (iteratorNode.hasNext()) {
-             Preferences pref = iteratorNode.next();
-             try {
+            Preferences pref = iteratorNode.next();
+            try {
                 pref.removeNode();
             }
             catch (BackingStoreException e) {
                 // do nothing
             }
         }
-        
+
         cayenneProjectPreferences.getDetailObject(DBConnectionInfo.class).cancel();
-        editingContext.rollbackChanges();
         restartRequired = false;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceDetail.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceDetail.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceDetail.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceDetail.java
Fri Mar  5 15:37:08 2010
@@ -16,198 +16,24 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-
 package org.apache.cayenne.pref;
 
-import java.util.Properties;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.CayenneDataObject;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.util.Util;
-
-/**
- * A superclass of concrete preference classes.
- * <p>
- * Complete preference descriptor is composed out of two classes - DomainPreference that
- * defines how the preference is located with in domain, and a GenericPreference.
- * GenericPreference API is designed for the application use, while internal
- * DomainPreference is managed behind the scenes. Note that there is no real Cayenne
- * relationship from concrete preference entity to the preference framework entities, so
- * this class handles all needed wiring...
- * 
- */
-public class PreferenceDetail extends CayenneDataObject {
-
-    protected DomainPreference domainPreference;
-
-    /**
-     * Changes the key of this preference. If there is a sibling prefrence with same key,
-     * such sibling is renamed using generated unique name. This operation essentially
-     * substitutes one prefrence entry with another.
-     */
-    public void rename(String newKey) {
-        if (Util.nullSafeEquals(getKey(), newKey)) {
-            return;
-        }
-
-        DomainPreference domainPrefrence = getDomainPreference();
-        Domain parent = domainPrefrence.getDomain();
-
-        if (parent == null) {
-            domainPrefrence.setKey(newKey);
-            return;
-        }
-
-        DomainPreference other = parent.getDomainPreference(newKey);
-        if (other != null && other != domainPrefrence) {
-            String otherName = null;
-            for (int i = 1; i < 1000; i++) {
-                if (parent.getDomainPreference(newKey + i) == null) {
-                    otherName = newKey + i;
-                    break;
-                }
-            }
-
-            if (otherName == null) {
-                throw new PreferenceException("Can't rename an existing preference '"
-                        + newKey
-                        + "'.");
-            }
-
-            other.setKey(otherName);
-        }
+import java.util.prefs.Preferences;
 
-        domainPrefrence.setKey(newKey);
-    }
-
-    public int getIntProperty(String key, int defaultValue) {
-        String value = getProperty(key);
-
-        if (value == null) {
-            return defaultValue;
-        }
-
-        try {
-            return Integer.parseInt(value);
-        }
-        catch (NumberFormatException ex) {
-            throw new PreferenceException("Error converting to int: " + value);
-        }
-    }
-
-    public String getKey() {
-        if (getDomainPreference() == null) {
-            throw new PreferenceException(
-                    "Preference not initialized, can't work with properties.");
-        }
+public class PreferenceDetail extends CayennePreference {
 
-        return domainPreference.getKey();
-    }
-
-    public void setIntProperty(String key, int value) {
-        setProperty(key, String.valueOf(value));
+    public PreferenceDetail(Preferences node) {
+        setCurrentPreference(node);
     }
 
     /**
      * Returns a named property for a given key.
      */
     public String getProperty(String key) {
-        return getProperties().getProperty(key);
+        return getCurrentPreference().get(key, null);
     }
 
     public void setProperty(String key, String value) {
-        getProperties().setProperty(key, value);
-    }
-
-    public boolean getBooleanProperty(String key) {
-        return "true".equalsIgnoreCase(getProperty(key));
-    }
-
-    public void setBooleanProperty(String key, boolean value) {
-        setProperty(key, "" + value);
-    }
-
-    public DomainPreference getDomainPreference() {
-        if (domainPreference == null) {
-            // try to fetch..
-
-            ObjectContext context = getObjectContext();
-
-            if (context != null && getObjectId() != null) {
-                int pk = Cayenne.intPKForObject(this);
-
-                domainPreference = Cayenne.objectForPK(
-                        context,
-                        DomainPreference.class,
-                        pk);
-            }
-        }
-
-        return domainPreference;
-    }
-
-    /**
-     * Initializes internal DomainPreference object.
-     */
-    public void setDomainPreference(DomainPreference domainPreference) {
-        if (this.domainPreference != domainPreference) {
-            this.domainPreference = domainPreference;
-
-            ObjectId oid = getObjectId();
-            if (oid != null && oid.isTemporary()) {
-                oid.getReplacementIdMap().put("id", new Integer(buildPermanentId()));
-            }
-        }
-    }
-
-    /**
-     * Returns initialized non-null properties map.
-     */
-    protected Properties getProperties() {
-        if (getDomainPreference() == null) {
-            throw new PreferenceException(
-                    "Preference not initialized, can't work with properties.");
-        }
-
-        return domainPreference.getProperties();
-    }
-
-    /**
-     * Creates permanent ID based on DomainPreference id.
-     */
-    protected int buildPermanentId() {
-        ObjectId otherId = getDomainPreference().getObjectId();
-        if (otherId == null) {
-            throw new PreferenceException(
-                    "Can't persist preference. DomainPreference has no ObjectId");
-        }
-
-        // force creation of otherId
-        if (otherId.isTemporary() && !otherId.isReplacementIdAttached()) {
-            DbEntity entity = getObjectContext().getEntityResolver().lookupObjEntity(
-                    domainPreference).getDbEntity();
-
-            DataNode node = ((DataContext) getObjectContext())
-                    .getParentDataDomain()
-                    .lookupDataNode(entity.getDataMap());
-
-            try {
-                Object pk = node.getAdapter().getPkGenerator().generatePk(
-                        node,
-                        entity.getPrimaryKeys().iterator().next());
-                otherId.getReplacementIdMap().put(DomainPreference.ID_PK_COLUMN, pk);
-            }
-            catch (Throwable th) {
-                throw new PreferenceException("Error creating primary key", Util
-                        .unwindException(th));
-            }
-        }
-
-        return Cayenne.intPKForObject(domainPreference);
+        getCurrentPreference().put(key, value);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceEditor.java?rev=919452&r1=919451&r2=919452&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/PreferenceEditor.java
Fri Mar  5 15:37:08 2010
@@ -26,25 +26,6 @@
  */
 public interface PreferenceEditor {
 
-    /**
-     * Returns an underlying PreferenceService which is a parent of this editor.
-     */
-    public PreferenceService getService();
-
-    /**
-     * Creates a generic PreferenceDetail.
-     */
-    public PreferenceDetail createDetail(Domain domain, String key);
-
-    /**
-     * Creates PreferenceDetail of specified class.
-     */
-    public PreferenceDetail createDetail(Domain domain, String key, Class javaClass);
-
-    public PreferenceDetail deleteDetail(Domain domain, String key);
-
-    public Domain editableInstance(Domain domain);
-
     public void save();
 
     public void revert();



Mime
View raw message