cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r906967 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/ modeler/action/ modeler/dialog/codegen/ modeler/editor/ modeler/editor/datanode/ modeler/pref/ pref/
Date Fri, 05 Feb 2010 15:24:58 GMT
Author: oltka
Date: Fri Feb  5 15:24:56 2010
New Revision: 906967

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

* DataMapDefaults to API
* change node name (in preferences) if change dataNode or dataMap name

Removed:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/_DataMapDefaults.java
Modified:
    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/ExitAction.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/codegen/ClientModeController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataMapDefaults.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java

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=906967&r1=906966&r2=906967&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 Feb  5 15:24:56 2010
@@ -317,8 +317,8 @@
 
                 watchdog.reconfigure();
 
-//                addDomainListener(((ModelerProjectConfiguration) project
-//                        .getConfiguration()).getGraphRegistry());
+                // addDomainListener(((ModelerProjectConfiguration) project
+                // .getConfiguration()).getGraphRegistry());
             }
         }
     }
@@ -340,10 +340,9 @@
         }
 
         if (projectPreferences == null) {
-            String key = getProject().getConfigurationResource() == null//getProject().isLocationUndefined()

-                    ? new String(IDUtil
-                    .pseudoUniqueByteSequence16()) : project
-                    .getConfigurationResource().getURL().getPath();
+            String key = getProject().getConfigurationResource() == null
+                    ? new String(IDUtil.pseudoUniqueByteSequence16())
+                    : project.getConfigurationResource().getURL().getPath();
 
             projectPreferences = getApplicationPreferenceDomain().getSubdomain(
                     Project.class).getSubdomain(key);
@@ -357,10 +356,9 @@
             throw new CayenneRuntimeException("No Project selected");
         }
         if (projectControllerPreferences == null) {
-            String key = getProject().getConfigurationResource() == null//getProject().isLocationUndefined()

-                ? new String(IDUtil
-                    .pseudoUniqueByteSequence16()) : project
-                    .getConfigurationResource().getURL().getPath();
+            String key = getProject().getConfigurationResource() == null
+                    ? new String(IDUtil.pseudoUniqueByteSequence16())
+                    : project.getConfigurationResource().getURL().getPath();
 
             projectControllerPreferences = Preferences.userNodeForPackage(Project.class);
 
@@ -375,23 +373,13 @@
     }
 
     /**
-     * Returns top preferences Domain for the current project, throwing an exception if no
+     * Returns top preferences for the current project, throwing an exception if no
      * project is selected.
      */
-    public Domain getPreferenceDomainForDataDomain() {
-        DataChannelDescriptor dataDomain = (DataChannelDescriptor)getProject().getRootNode();
-        if (dataDomain == null) {
-            throw new CayenneRuntimeException("No DataDomain selected");
-        }
-
-        return getPreferenceDomainForProject()
-                .getSubdomain(DataChannelDescriptor.class)
-                .getSubdomain(dataDomain.getName());
-    }
-
     public Preferences getPreferenceForDataDomain() {
-        
-        DataChannelDescriptor dataDomain = (DataChannelDescriptor)getProject().getRootNode();
+
+        DataChannelDescriptor dataDomain = (DataChannelDescriptor) getProject()
+                .getRootNode();
         if (dataDomain == null) {
             throw new CayenneRuntimeException("No DataDomain selected");
         }
@@ -411,14 +399,17 @@
             throw new CayenneRuntimeException("No DataMap selected");
         }
 
-        if (nameSuffix == null) {
-            nameSuffix = "";
+        Preferences pref;
+        if (nameSuffix == null || nameSuffix.length() == 0) {
+            pref = getPreferenceForDataDomain().node("DataMap").node(map.getName());
         }
-
-        return (DataMapDefaults) getPreferenceDomainForDataDomain().getDetail(
-                map.getName() + nameSuffix,
-                DataMapDefaults.class,
-                true);
+        else {
+            pref = getPreferenceForDataDomain().node("DataMap").node(map.getName()).node(
+                    nameSuffix);
+        }
+        return (DataMapDefaults) application
+                .getCayenneProjectPreferences()
+                .getProjectDetailObject(DataMapDefaults.class, pref);
     }
 
     /**
@@ -1656,7 +1647,8 @@
         // new map was added.. link it to domain (and node if possible)
         currentState.domain.getDataMaps().add(map);
 
-        if (currentState.node != null && !currentState.node.getDataMapNames().contains(map.getName()))
{
+        if (currentState.node != null
+                && !currentState.node.getDataMapNames().contains(map.getName()))
{
             currentState.node.getDataMapNames().add(map.getName());
             fireDataNodeEvent(new DataNodeEvent(this, currentState.node));
         }
@@ -1914,7 +1906,8 @@
     }
 
     public ArrayList<Embeddable> getEmbeddableNamesInCurRentDataDomain() {
-        DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor)getProject().getRootNode();
+        DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) getProject()
+                .getRootNode();
         Collection<DataMap> maps = dataChannelDescriptor.getDataMaps();
         Iterator<DataMap> it = maps.iterator();
         ArrayList<Embeddable> embs = new ArrayList<Embeddable>();

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ExitAction.java
Fri Feb  5 15:24:56 2010
@@ -21,6 +21,7 @@
 
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.dialog.LogConsole;
+import org.apache.cayenne.pref.CayennePreferenceForProject;
 import org.apache.cayenne.project.ProjectPath;
 
 import java.awt.event.ActionEvent;
@@ -48,13 +49,12 @@
         if (!checkSaveOnClose()) {
             return;
         }
-        
-		// write prefs to persistent store
-//		ModelerPreferences.storePreferences();
 		
 		//stop logging before JVM shutdown to prevent hanging
 		LogConsole.getInstance().stopLogging();
 
+		CayennePreferenceForProject.removeNewPreferences();
+		
 		// goodbye
         System.exit(0);
     }

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=906967&r1=906966&r2=906967&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 Feb  5 15:24:56 2010
@@ -25,6 +25,7 @@
 import javax.swing.KeyStroke;
 
 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;
@@ -72,6 +73,8 @@
 
         preference.rename(p.getConfigurationResource().getURL().getPath());
 
+        CayennePreferenceForProject.removeOldPreferences();
+        
         getApplication().getFrameController().changePathInLastProjListAction(oldPath, 
                 p.getConfigurationResource().getURL().getPath());
         Application.getFrame().fireRecentFileListChanged();

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=906967&r1=906966&r2=906967&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 Feb  5 15:24:56 2010
@@ -34,6 +34,7 @@
 import org.apache.cayenne.modeler.dialog.validator.ValidationDisplayHandler;
 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.project.validator.ValidationInfo;
@@ -110,6 +111,8 @@
 
         // update preferences domain key
         preference.rename(projectDir.getPath());
+        
+        CayennePreferenceForProject.removeOldPreferences();
 
         if (oldPath != null && oldPath.length() != 0) {
             getApplication().getFrameController().changePathInLastProjListAction(

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/ClientModeController.java
Fri Feb  5 15:24:56 2010
@@ -64,7 +64,7 @@
         DataMapDefaults prefs = getApplication()
                 .getFrameController()
                 .getProjectController()
-                .getDataMapPreferences("__client");
+                .getDataMapPreferences(this.getClass().getName().replace(".", "/"));
 
         prefs.updateSuperclassPackage(getParentController().getDataMap(), true);
         this.preferences = prefs;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/CustomModeController.java
Fri Feb  5 15:24:56 2010
@@ -146,10 +146,11 @@
     }
 
     protected DataMapDefaults createDefaults() {
+        Class obt = this.getClass();
         DataMapDefaults prefs = getApplication()
                 .getFrameController()
                 .getProjectController()
-                .getDataMapPreferences("__custom");
+                .getDataMapPreferences(this.getClass().getName().replace(".", "/"));
 
         prefs.updateSuperclassPackage(getParentController().getDataMap(), false);
         this.preferences = prefs;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java
Fri Feb  5 15:24:56 2010
@@ -23,6 +23,8 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.Map;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
@@ -31,6 +33,7 @@
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataRowStore;
 import org.apache.cayenne.cache.MapQueryCacheFactory;
@@ -352,14 +355,33 @@
         DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application
                 .getProject()
                 .getRootNode();
-        Domain prefs = projectController.getPreferenceDomainForDataDomain();
+        Preferences prefs = projectController.getPreferenceForDataDomain();
 
         DomainEvent e = new DomainEvent(
                 this,
                 dataChannelDescriptor,
                 dataChannelDescriptor.getName());
         ProjectUtil.setDataDomainName(dataChannelDescriptor, newName);
-        prefs.rename(newName);
+
+        // rename preference
+        
+        Preferences oldPref = prefs;
+        try {
+            String[] names = oldPref.keys();
+            
+            Preferences parent = oldPref.parent();
+            Preferences newPref = parent.node(newName);
+            for(int i=0; i<names.length; i++){
+                newPref.put(names[i], oldPref.get(names[i], ""));
+            }
+          
+          
+            oldPref.removeNode();
+        }
+        catch (BackingStoreException ex) {
+           new CayenneRuntimeException("Error remane preferences");
+        }
+        
         projectController.fireDomainEvent(e);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapView.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapView.java
Fri Feb  5 15:24:56 2010
@@ -523,7 +523,7 @@
         DataMapDefaults pref = eventController.getDataMapPreferences("");
         DataMapEvent e = new DataMapEvent(this, map, map.getName());
         ProjectUtil.setDataMapName((DataChannelDescriptor)eventController.getProject().getRootNode(),
map, newName);
-        pref.rename(newName);
+        pref.copyPreferences(newName);
         eventController.fireDataMapEvent(e);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
Fri Feb  5 15:24:56 2010
@@ -47,6 +47,7 @@
 import org.apache.cayenne.modeler.event.DataNodeDisplayEvent;
 import org.apache.cayenne.modeler.event.DataNodeDisplayListener;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
+import org.apache.cayenne.modeler.pref.DataNodeDefaults;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.modeler.util.ProjectUtil;
 import org.apache.cayenne.swing.BindingBuilder;
@@ -157,6 +158,7 @@
         }
 
         ProjectController parent = (ProjectController) getParent();
+        DataNodeDefaults oldPref = parent.getDataNodePreferences();
         DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor)Application.getProject().getRootNode();
 
         Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();
@@ -177,6 +179,9 @@
         // TODO: fixme....there is a slight chance that domain is different than the one
         // cached node belongs to
         ProjectUtil.setDataNodeName((DataChannelDescriptor)parent.getProject().getRootNode(),
node, newName);
+        
+    
+        oldPref.copyPreferences(newName);
     }
 
     // ======== other stuff

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataMapDefaults.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataMapDefaults.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataMapDefaults.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataMapDefaults.java
Fri Feb  5 15:24:56 2010
@@ -18,19 +18,40 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.pref;
 
+import java.util.prefs.Preferences;
+
 import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.pref.CayennePreferenceForProject;
 import org.apache.cayenne.util.Util;
 
-public class DataMapDefaults extends _DataMapDefaults {
+public class DataMapDefaults extends CayennePreferenceForProject {
 
+    private boolean generatePairs;
+    private String outputPath;
+    private String subclassTemplate;
+    private String superclassPackage;
+    private String superclassTemplate;
+    
+    private boolean initGeneratePairs;
+    
+    public static final String GENERATE_PAIRS_PROPERTY = "generatePairs";
+    public static final String OUTPUT_PATH_PROPERTY = "outputPath";
+    public static final String SUBCLASS_TEMPLATE_PROPERTY = "subclassTemplate";
+    public static final String SUPERCLASS_PACKAGE_PROPERTY = "superclassPackage";
+    public static final String SUPERCLASS_TEMPLATE_PROPERTY = "superclassTemplate";
+    
     public static final String DEFAULT_SUPERCLASS_PACKAGE_SUFFIX = "auto";
+    
+    public DataMapDefaults(Preferences pref) {
+        super(pref);
+    }
 
     /**
      * Returns a superlcass package tailored for a given DataMap.
      */
     public void updateSuperclassPackage(DataMap dataMap, boolean isClient) {
 
-        String storedPackage = super.getSuperclassPackage();
+        String storedPackage = getSuperclassPackage();
         if (Util.isEmptyString(storedPackage)
                 || DEFAULT_SUPERCLASS_PACKAGE_SUFFIX.equals(storedPackage)) {
             String mapPackage = (isClient) ? dataMap.getDefaultClientPackage() : dataMap
@@ -86,4 +107,101 @@
         String dot = (suffix.length() > 0 && prefix.length() > 0) ? "." : "";
         setSuperclassPackage(prefix + dot + suffix);
     }
+    
+    public boolean getGeneratePairs() {
+        if(!initGeneratePairs){
+            generatePairs = getCurrentPreference().getBoolean(GENERATE_PAIRS_PROPERTY, false);
+            initGeneratePairs = true;
+        }
+        return generatePairs;
+    }
+    
+    public void setGeneratePairs(Boolean bool) {
+        if (getCurrentPreference() != null) {
+            this.generatePairs = bool;
+            getCurrentPreference().putBoolean(GENERATE_PAIRS_PROPERTY, bool);
+        }
+    }
+    
+    public String getOutputPath() {
+        if(outputPath == null){
+            outputPath = getCurrentPreference().get(OUTPUT_PATH_PROPERTY, null);
+        }
+        return outputPath;
+    }
+    
+    public void setOutputPath(String outputPath) {
+        if (getCurrentPreference() != null) {
+            this.outputPath = outputPath;
+            getCurrentPreference().put(OUTPUT_PATH_PROPERTY, outputPath);
+        }
+    }
+
+    public String getSubclassTemplate() {
+        if(subclassTemplate == null){
+            subclassTemplate = getCurrentPreference().get(SUBCLASS_TEMPLATE_PROPERTY, null);
+        }
+        return subclassTemplate;
+    }
+
+    public void setSubclassTemplate(String subclassTemplate) {
+        if (getCurrentPreference() != null) {
+            this.subclassTemplate = subclassTemplate;
+            getCurrentPreference().put(SUBCLASS_TEMPLATE_PROPERTY, subclassTemplate);
+        }
+    }
+    
+    public String getSuperclassPackage() {
+        if(superclassPackage == null){
+            superclassPackage = getCurrentPreference().get(SUPERCLASS_PACKAGE_PROPERTY, null);
+        }
+        return superclassPackage;
+    }
+    
+    public void setSuperclassPackage(String superclassPackage) {
+        if (getCurrentPreference() != null) {
+            this.superclassPackage = superclassPackage;
+            getCurrentPreference().put(SUPERCLASS_PACKAGE_PROPERTY, superclassPackage);
+        }
+    }
+    
+    public String getSuperclassTemplate() {
+        if(superclassTemplate == null){
+            superclassTemplate = getCurrentPreference().get(SUPERCLASS_TEMPLATE_PROPERTY,
null);
+        }
+        return superclassTemplate;
+    }
+    
+    public void setSuperclassTemplate(String superclassTemplate) {
+        if (getCurrentPreference() != null) {
+            this.superclassTemplate = superclassTemplate;
+            getCurrentPreference().put(SUPERCLASS_TEMPLATE_PROPERTY, superclassTemplate);
+        }
+    }
+    
+    public String getProperty(String property) {
+        if(property == null){
+            return getCurrentPreference().get(property, null);
+        }
+        return null;
+    }
+    
+    public void setProperty(String property, String value) {
+        if (getCurrentPreference() != null) {
+            getCurrentPreference().put(property, value);
+        }
+    }
+    
+    public void setBooleanProperty(String property, boolean value) {
+        if (getCurrentPreference() != null) {
+            getCurrentPreference().putBoolean(property, value);
+        }
+    }
+    
+    public boolean getBooleanProperty(String property) {
+        if(property == null){
+            return getCurrentPreference().getBoolean(property, false);
+        }
+        return false;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
Fri Feb  5 15:24:56 2010
@@ -25,13 +25,13 @@
 public class DataNodeDefaults extends CayennePreferenceForProject {
     
     private String localDataSource;
+    
+    public static final String LOCAL_DATA_SOURCE_PROPERTY = "localDataSource";
 
     public DataNodeDefaults(Preferences pref) {
         super(pref);
     }
 
-    public static final String LOCAL_DATA_SOURCE_PROPERTY = "localDataSource";
-
     public void setLocalDataSource(String localDataSource) {
         if (getCurrentPreference() != null) {
             this.localDataSource = localDataSource;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java?rev=906967&r1=906966&r2=906967&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java
Fri Feb  5 15:24:56 2010
@@ -18,11 +18,139 @@
  ****************************************************************/
 package org.apache.cayenne.pref;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
 
+import org.apache.cayenne.CayenneRuntimeException;
 
 public abstract class CayennePreferenceForProject extends CayennePreference {
+
+    private static List<Preferences> newNode; 
+    private static List<Preferences> oldNode;
+
     public CayennePreferenceForProject(Preferences pref) {
         setCurrentPreference(pref);
     }
+
+    public void copyPreferences(String newName) {
+
+        Preferences oldPref = getCurrentPreference();
+        try {
+            
+            // copy all preferences in this node
+            String[] names = oldPref.keys();
+            Preferences parent = oldPref.parent();
+            Preferences newPref = parent.node(newName);
+            for (int i = 0; i < names.length; i++) {
+                newPref.put(names[i], oldPref.get(names[i], ""));
+            }
+
+            String[] children = oldPref.childrenNames();
+            String oldPath = oldPref.absolutePath();
+            String newPath = newPref.absolutePath();
+
+            // copy children nodes and its preferences
+
+            ArrayList<Preferences> childrenOldPref = childrenCopy(oldPref, oldPath,
newPath);
+
+            while (childrenOldPref.size() > 0) {
+
+                ArrayList<Preferences> childrenPrefTemp = new ArrayList<Preferences>();
+
+                Iterator<Preferences> it = childrenOldPref.iterator();
+                while (it.hasNext()) {
+                    Preferences child = it.next();
+                    ArrayList<Preferences> childArray = childrenCopy(child, oldPath,
newPath);
+
+                    childrenPrefTemp.addAll(childArray);
+                }
+
+                childrenOldPref.clear();
+                childrenOldPref.addAll(childrenPrefTemp);
+            }
+
+            if (newNode == null) {
+                newNode = new ArrayList<Preferences>();
+            }
+            if (oldNode == null) {
+                oldNode = new ArrayList<Preferences>();
+            }
+
+            newNode.add(newPref);
+            oldNode.add(oldPref);
+            setCurrentPreference(newPref);
+        }
+        catch (BackingStoreException e) {
+            new CayenneRuntimeException("Error remane preferences");
+        }
+    }
+
+    private ArrayList<Preferences> childrenCopy(Preferences pref, String oldPath, String
newPath) {
+
+        try {
+            String[] children = pref.childrenNames();
+
+            ArrayList<Preferences> prefChild = new ArrayList<Preferences>();
+
+            for (int j = 0; j < children.length; j++) {
+                String child = children[j];
+                // get old preference
+                Preferences childNode = pref.node(child);
+                
+                // path to node
+                String path = childNode.absolutePath().replace(oldPath, newPath);
+                
+                // copy all preferences in this node
+                String[] names = childNode.keys();
+                Preferences newPref = Preferences.userRoot().node(path);
+                for (int i = 0; i < names.length; i++) {
+                    newPref.put(names[i], pref.get(names[i], ""));
+                }
+                prefChild.add(childNode);
+            }
+
+            return prefChild;
+        }
+        catch (BackingStoreException e) {
+        }
+        return null;
+    }
+
+    public static void removeOldPreferences() {
+        if (oldNode != null) {
+            Iterator<Preferences> it = oldNode.iterator();
+
+            while (it.hasNext()) {
+                Preferences pref = it.next();
+                try {
+                    pref.removeNode();
+                }
+                catch (BackingStoreException e) {
+                }
+            }
+            oldNode.clear();
+            newNode.clear();
+        }
+
+    }
+
+    public static void removeNewPreferences() {
+        if (newNode != null) {
+            Iterator<Preferences> it = newNode.iterator();
+
+            while (it.hasNext()) {
+                Preferences pref = it.next();
+                try {
+                    pref.removeNode();
+                }
+                catch (BackingStoreException e) {
+                }
+            }
+            oldNode.clear();
+            newNode.clear();
+        }
+    }
 }



Mime
View raw message