cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r687668 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor: ./ datanode/
Date Thu, 21 Aug 2008 09:35:43 GMT
Author: aadamchik
Date: Thu Aug 21 02:35:42 2008
New Revision: 687668

URL: http://svn.apache.org/viewvc?rev=687668&view=rev
Log:
CAY-1094 CM DataNode panel reorg - pull the password encoding options into a tab
(applying patch by Dima Loiko)

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataNodeEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataSourceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java?rev=687668&r1=687667&r2=687668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
Thu Aug 21 02:35:42 2008
@@ -28,6 +28,7 @@
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
 
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.ProjectTreeView;
@@ -78,10 +79,10 @@
     protected ProjectController eventController;
     protected JSplitPane splitPane;
     protected Container detailPanel;
-
     protected CardLayout detailLayout;
-
     private ProjectTreeView treePanel;
+    
+    
     public ProjectTreeView getProjectTreeView() {
         return treePanel;
     }
@@ -126,7 +127,7 @@
         detailPanel.add(new JScrollPane(domainView), DOMAIN_VIEW);
 
         DataNodeEditor nodeController = new DataNodeEditor(eventController);
-        detailPanel.add(nodeController.getView(), NODE_VIEW);
+        detailPanel.add(nodeController.getView(), NODE_VIEW); 
 
         Component dataMapView = new DataMapTabbedView(eventController);
         detailPanel.add(dataMapView, DATA_MAP_VIEW);

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataNodeEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataNodeEditor.java?rev=687668&r1=687667&r2=687668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataNodeEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataNodeEditor.java
Thu Aug 21 02:35:42 2008
@@ -23,6 +23,7 @@
 
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
+import javax.swing.text.StyledEditorKit.BoldAction;
 
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.util.CayenneController;
@@ -36,13 +37,18 @@
 
     public DataNodeEditor(ProjectController parent) {
         super(parent);
-
+        
         this.view = new JTabbedPane();
-        view.addTab("Main", new JScrollPane(new MainDataNodeEditor(parent).getView()));
+        view.addTab("Main", new JScrollPane(new MainDataNodeEditor(parent,this).getView()));
         view.addTab("Adapter", new AdapterEditor(parent).getView());
+        view.addTab("Password Encoder", new PasswordEncoderEditor(parent).getView()) ;
     }
 
     public Component getView() {
         return view;
     }
+    
+    public JTabbedPane getTabComponent() {
+        return view;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataSourceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataSourceEditor.java?rev=687668&r1=687667&r2=687668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataSourceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/DataSourceEditor.java
Thu Aug 21 02:35:42 2008
@@ -43,6 +43,8 @@
         initBindings();
     }
 
+   
+
     public DataNode getNode() {
         return node;
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java?rev=687668&r1=687667&r2=687668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
Thu Aug 21 02:35:42 2008
@@ -42,6 +42,7 @@
     public JDBCDataSourceEditor(ProjectController parent,
             BindingDelegate nodeChangeProcessor) {
         super(parent, nodeChangeProcessor);
+
     }
 
     public Component getView() {
@@ -51,7 +52,8 @@
     protected void prepareBindings(BindingBuilder builder) {
         this.view = new JDBCDataSourceView();
 
-        fieldAdapters = new ObjectBinding[10];
+        
+        fieldAdapters = new ObjectBinding[6];
         fieldAdapters[0] =
           builder.bindToTextField(view.getUserName(), "node.dataSource.dataSourceInfo.userName");
         fieldAdapters[1] =
@@ -64,91 +66,17 @@
           builder.bindToTextField(view.getMaxConnections(), "node.dataSource.dataSourceInfo.maxConnections");
         fieldAdapters[5] =
           builder.bindToTextField(view.getMinConnections(), "node.dataSource.dataSourceInfo.minConnections");
-        fieldAdapters[6] =
-          builder.bindToComboSelection(view.getPasswordEncoder(), "node.dataSource.dataSourceInfo.passwordEncoderClass");
-        fieldAdapters[7] =
-          builder.bindToTextField(view.getPasswordKey(), "node.dataSource.dataSourceInfo.passwordEncoderKey");
-        fieldAdapters[8] =
-          builder.bindToComboSelection(view.getPasswordLocation(), "node.dataSource.dataSourceInfo.passwordLocation");
-        fieldAdapters[9] =
-          builder.bindToTextField(view.getPasswordSource(), "node.dataSource.dataSourceInfo.passwordSource");
         
-        // one way binding
-        builder.bindToAction(view.getPasswordEncoder(),  "validatePasswordEncoderAction()");
-        builder.bindToAction(view.getPasswordLocation(), "passwordLocationChangedAction()");
-        builder.bindToAction(view.getSyncWithLocal(),    "syncDataSourceAction()");
-    }
 
-    /**
-     * This action is called when a new password encoder is specified.  It
-     * warns the user if the encoder class is not available and advises them
-     * to check their classpath.
-     */
-    public void validatePasswordEncoderAction()
-    {
-      if (getNode() == null || getNode().getDataSource() == null)
-        return;
-
-      DataSourceInfo dsi = ((ProjectDataSource) getNode().getDataSource()).getDataSourceInfo();
-
-      if (view.getPasswordEncoder().getSelectedItem().equals(dsi.getPasswordEncoderClass())
== false)
-        return;
-
-      if (dsi.getPasswordEncoder() == null)
-      {
-        JOptionPane.showMessageDialog(getView(),
-                                      "A valid Password Encoder should be specified (check
your CLASSPATH).",
-                                      "Invalid Password Encoder",
-                                      JOptionPane.ERROR_MESSAGE);
-      }
+        builder.bindToAction(view.getSyncWithLocal(),    "syncDataSourceAction()");
     }
 
-    /**
-     * Updates labels and editability of the password related fields.
-     * Called by the passwordLocationChangedAction method.
-     * 
-     * @param isPasswordFieldEnabled True if password field is editable, false if not.
-     * @param isPasswordLocationEnabled True if password location field is editable, false
if not.
-     * @param passwordText The password (which is obscured to the user, of course).
-     * @param passwordLocationLabel Label for the password location.
-     * @param passwordLocationText Text of the password location field.
-     */
-    private void updatePasswordElements(boolean isPasswordFieldEnabled,
-                                        boolean isPasswordLocationEnabled,
-                                        String  passwordText,
-                                        String  passwordLocationLabel,
-                                        String  passwordLocationText)
-    {
-      view.getPassword().setEnabled(isPasswordFieldEnabled);
-      view.getPassword().setText(passwordText);
-      view.getPasswordSource().setEnabled(isPasswordLocationEnabled);
-      view.getPasswordSourceLabel().setText(passwordLocationLabel);
-      view.getPasswordSource().setText(passwordLocationText);
-    }
 
     /**
      * This action is called whenever the password location is changed
      * in the GUI pulldown.  It changes labels and editability of the
      * password fields depending on the option that was selected.
      */
-    public void passwordLocationChangedAction()
-    {
-      if (getNode() == null || getNode().getDataSource() == null)
-        return;
-
-      DataSourceInfo dsi = ((ProjectDataSource) getNode().getDataSource()).getDataSourceInfo();
-
-      String selectedItem = (String) view.getPasswordLocation().getSelectedItem();
-
-      if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_CLASSPATH))
-        updatePasswordElements(true, true, dsi.getPassword(), "Password Filename:", dsi.getPasswordSourceFilename());
-      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE))
-        updatePasswordElements(false, true, null, "Password Executable:", dsi.getPasswordSourceExecutable());
-      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_MODEL))
-        updatePasswordElements(true, false, dsi.getPassword(), "Password Source:", dsi.getPasswordSourceModel());
-      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_URL))
-        updatePasswordElements(false, true, null, "Password URL:", dsi.getPasswordSourceUrl());
-    }
 
 
     public void syncDataSourceAction() {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java?rev=687668&r1=687667&r2=687668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceView.java
Thu Aug 21 02:35:42 2008
@@ -51,53 +51,16 @@
     protected JTextField     url;
     protected JTextField     userName;
     protected JPasswordField password;
-    protected JComboBox      passwordEncoder;
-    protected JComboBox      passwordLocation;
-    protected JTextField     passwordKey;
-    protected JTextField     passwordSource;
-    protected JLabel         passwordSourceLabel;
+
     protected JTextField     minConnections;
     protected JTextField     maxConnections;
     protected JButton        syncWithLocal;
 
-    private static final String PASSWORD_CLASSPATH  = "Classpath Search (File System)";
-    private static final String PASSWORD_EXECUTABLE = "Executable Program";
-    private static final String PASSWORD_MODEL      = "Cayenne Model";
-    private static final String PASSWORD_URL        = "URL (file:, http:, etc)";
-
-    private static final Object[] PASSWORD_LOCATIONS = new Object[] {
-            DataSourceInfo.PASSWORD_LOCATION_MODEL,
-            DataSourceInfo.PASSWORD_LOCATION_CLASSPATH,
-            DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE,
-            DataSourceInfo.PASSWORD_LOCATION_URL };
-
-    private static final Map<String, String> passwordSourceLabels = new TreeMap<String,
String>();
-
-    static
-    {
-      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_MODEL, PASSWORD_MODEL);
-      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_CLASSPATH, PASSWORD_CLASSPATH);
-      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE, PASSWORD_EXECUTABLE);
-      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_URL, PASSWORD_URL);
-    }
 
 
-    final class PasswordLocationRenderer extends DefaultListCellRenderer
-    {
-      public Component getListCellRendererComponent(JList list,
-                                                    Object object,
-                                                    int arg2,
-                                                    boolean arg3,
-                                                    boolean arg4)
-      {
-        if (object != null)
-          object = passwordSourceLabels.get(object);
-        else
-          object = PASSWORD_MODEL;
 
-        return super.getListCellRendererComponent(list, object, arg2, arg3, arg4);
-      }
-    }
+
+
 
     public JDBCDataSourceView() {
 
@@ -105,32 +68,11 @@
         url              = new JTextField();
         userName         = new JTextField();
         password         = new JPasswordField();
-        passwordEncoder  = new JComboBox();
-        passwordLocation = new JComboBox();
-        passwordSource   = new JTextField();
-        passwordKey      = new JTextField();
         minConnections   = new JTextField(6);
         maxConnections   = new JTextField(6);
         syncWithLocal    = new JButton("Sync with Local");
         syncWithLocal.setToolTipText("Update from local DataSource");
 
-        // init combo box choices                                                       
                                                                                         
              
-        passwordEncoder.setModel(new DefaultComboBoxModel(PasswordEncoding.standardEncoders));
-        passwordEncoder.setEditable(true);
-
-        passwordLocation = CayenneWidgetFactory.createComboBox();
-        passwordLocation.setRenderer(new PasswordLocationRenderer());
-        //        passwordSource.setModel(new DefaultComboBoxModel(passwordLocations));
-//      EntityResolver resolver = mediator.getCurrentDataDomain().getEntityResolver();
-        DefaultComboBoxModel passwordLocationModel = new DefaultComboBoxModel(PASSWORD_LOCATIONS);
-        //passwordSourceModel.setSelectedItem(query.getMetaData(resolver).getCachePolicy());
-        passwordLocation.setModel(passwordLocationModel);
-//        passwordLocation.addActionListener(new ActionListener() {
-//          public void actionPerformed(ActionEvent event) {
-//              Object source = passwordLocation.getModel().getSelectedItem();
-//              System.out.println(source);
-//          }
-//      });
 
 
         // assemble
@@ -144,7 +86,7 @@
 
         PanelBuilder builder = new PanelBuilder(layout);
         builder.setDefaultDialogBorder();
-
+        
         builder.addSeparator("JDBC Configuration", cc.xywh(1, 1, 7, 1));
         builder.addLabel("JDBC Driver:", cc.xy(1, 3));
         builder.add(driver, cc.xywh(3, 3, 5, 1));
@@ -154,28 +96,11 @@
         builder.add(userName, cc.xywh(3, 7, 5, 1));
         builder.addLabel("Password:", cc.xy(1, 9));
         builder.add(password, cc.xywh(3, 9, 5, 1));
-
-        builder.addLabel("Password Encoder:", cc.xy(1, 11));
-        builder.add(passwordEncoder, cc.xywh(3, 11, 5, 1));
-
-        builder.addLabel("Password Encoder Key:", cc.xy(1, 13));
-        builder.add(passwordKey, cc.xywh(3, 13, 5, 1));
-
-        builder.addLabel("Note: Cayenne supplied encoders do not use a key.", cc.xywh(3,
15, 5, 1));
-
-        builder.addLabel("Password Location:", cc.xy(1, 17));
-        builder.add(passwordLocation, cc.xywh(3, 17, 5, 1));
-
-        passwordSourceLabel = builder.addLabel("Password Source:", cc.xy(1, 19));
-        builder.add(passwordSource, cc.xywh(3, 19, 5, 1));
-
-        builder.addLabel("Min Connections:", cc.xy(1, 21));
-        builder.add(minConnections, cc.xy(3, 21));
-        
-        builder.addLabel("Max Connections:", cc.xy(1, 23));
-        builder.add(maxConnections, cc.xy(3, 23));
-
-        builder.add(syncWithLocal, cc.xy(7, 25));
+        builder.addLabel("Min Connections:", cc.xy(1, 11));
+        builder.add(minConnections, cc.xy(3, 11));
+        builder.addLabel("Max Connections:", cc.xy(1, 13));
+        builder.add(maxConnections, cc.xy(3, 13));
+        builder.add(syncWithLocal, cc.xy(7, 15));
 
         this.setLayout(new BorderLayout());
         this.add(builder.getPanel(), BorderLayout.CENTER);
@@ -208,44 +133,4 @@
     public JButton getSyncWithLocal() {
         return syncWithLocal;
     }
-
-    /**
-     * @return the passwordEncoder
-     */
-    public JComboBox getPasswordEncoder()
-    {
-      return passwordEncoder;
-    }
-
-    /**
-     * @return the passwordLocation
-     */
-    public JComboBox getPasswordLocation()
-    {
-      return passwordLocation;
-    }
-
-    /**
-     * @return the passwordKey
-     */
-    public JTextField getPasswordKey()
-    {
-      return passwordKey;
-    }
-
-    /**
-     * @return the passwordSource
-     */
-    public JTextField getPasswordSource()
-    {
-      return passwordSource;
-    }
-
-    /**
-     * @return the passwordLocationLabel
-     */
-    public JLabel getPasswordSourceLabel()
-    {
-      return passwordSourceLabel;
-    }
-}
+}
\ No newline at end of file

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=687668&r1=687667&r2=687668&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
Thu Aug 21 02:35:42 2008
@@ -28,6 +28,8 @@
 import java.util.Map;
 
 import javax.swing.DefaultComboBoxModel;
+import javax.swing.JOptionPane;
+import javax.swing.JTabbedPane;
 
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataNode;
@@ -38,6 +40,7 @@
 import org.apache.cayenne.map.event.DataNodeEvent;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog;
+import org.apache.cayenne.modeler.editor.EditorView;
 import org.apache.cayenne.modeler.event.DataNodeDisplayEvent;
 import org.apache.cayenne.modeler.event.DataNodeDisplayListener;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
@@ -64,7 +67,7 @@
                      DBCPDataSourceFactory.class.getName() };
 
     protected MainDataNodeView view;
-
+    protected DataNodeEditor tabbedPaneController;
     protected DataNode node;
     protected Map datasourceEditors;
     protected Map localDataSources;
@@ -74,14 +77,16 @@
     protected BindingDelegate nodeChangeProcessor;
     protected ObjectBinding[] bindings;
     protected ObjectBinding localDataSourceBinding;
+    
 
-    public MainDataNodeEditor(ProjectController parent) {
+    public MainDataNodeEditor(ProjectController parent,DataNodeEditor tabController) {
+        
         super(parent);
-
+        this.tabbedPaneController = tabController;
         this.view = new MainDataNodeView();
         this.datasourceEditors = new HashMap();
         this.localDataSources = new HashMap();
-
+        
         this.nodeChangeProcessor = new BindingDelegate() {
 
             public void modelUpdated(
@@ -174,7 +179,6 @@
     protected void initController() {
         view.getDataSourceDetail().add(defaultSubeditor.getView(), "default");
         view.getFactories().setEditable(true);
-
         // init combo box choices
         view.getFactories().setModel(
                 new DefaultComboBoxModel(standardDataSourceFactories));
@@ -208,7 +212,7 @@
         // use delegate for the rest of them
 
         builder.setDelegate(nodeChangeProcessor);
-
+        
         bindings = new ObjectBinding[2];
         bindings[0] = builder.bindToTextField(view.getDataNodeName(), "nodeName");
         bindings[1] = builder.bindToComboSelection(view.getFactories(), "factoryName");
@@ -273,7 +277,7 @@
      */
     protected void showDataSourceSubview(String factoryName) {
         DataSourceEditor c = (DataSourceEditor) datasourceEditors.get(factoryName);
-
+        
         // create subview dynamically...
         if (c == null) {
 
@@ -307,11 +311,26 @@
             // this is needed to display freshly added panel...
             view.getDataSourceDetail().getParent().validate();
         }
-
+        
         // this will refresh subview...
         c.setNode(node);
-
+        disabledTab(factoryName);
         // display the right subview...
         view.getDataSourceDetailLayout().show(view.getDataSourceDetail(), factoryName);
+        
+    }
+    
+    protected void disabledTab(String name){
+        
+        if(name.equals(standardDataSourceFactories[0])){
+            tabbedPaneController.getTabComponent().setEnabledAt(2, true);
+        }
+        else if(name.equals(standardDataSourceFactories[1])){
+            tabbedPaneController.getTabComponent().setEnabledAt(2, false);
+        }
+        if(name.equals(standardDataSourceFactories[2])){
+            tabbedPaneController.getTabComponent().setEnabledAt(2, false);
+        }
+        
     }
 }

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderEditor.java?rev=687668&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderEditor.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderEditor.java
Thu Aug 21 02:35:42 2008
@@ -0,0 +1,169 @@
+/*****************************************************************
+ *   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.editor.datanode;
+
+import java.awt.Component;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+
+import javax.swing.JOptionPane;
+
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.event.DataNodeDisplayEvent;
+import org.apache.cayenne.modeler.event.DataNodeDisplayListener;
+import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.project.ProjectDataSource;
+import org.apache.cayenne.swing.BindingBuilder;
+import org.apache.cayenne.swing.ObjectBinding;
+
+
+public class PasswordEncoderEditor extends CayenneController  {
+    
+    protected DataNode node;
+    protected ObjectBinding[] bindings;
+    protected PasswordEncoderView view;
+    
+    public PasswordEncoderEditor(CayenneController parent){
+
+        super(parent);
+        
+        this.view = new PasswordEncoderView();
+        initController();
+    }
+    
+    protected void initController() {
+        BindingBuilder builder = new BindingBuilder(
+                getApplication().getBindingFactory(),
+                this);
+
+        bindings = new ObjectBinding[4];
+        
+        bindings[0] =
+              builder.bindToComboSelection(view.getPasswordEncoder(), "node.dataSource.dataSourceInfo.passwordEncoderClass");
+        bindings[1] =
+              builder.bindToTextField(view.getPasswordKey(), "node.dataSource.dataSourceInfo.passwordEncoderKey");
+        bindings[2] =
+              builder.bindToComboSelection(view.getPasswordLocation(), "node.dataSource.dataSourceInfo.passwordLocation");
+        bindings[3] =
+              builder.bindToTextField(view.getPasswordSource(), "node.dataSource.dataSourceInfo.passwordSource");
+
+          ((ProjectController) getParent())
+          .addDataNodeDisplayListener(new DataNodeDisplayListener() {
+        
+              public void currentDataNodeChanged(DataNodeDisplayEvent e) {
+                  refreshView(e.getDataNode());
+              }
+          });
+        
+          getView().addComponentListener(new ComponentAdapter() {
+        
+              public void componentShown(ComponentEvent e) {
+                  refreshView(node != null ? node : ((ProjectController) getParent())
+                          .getCurrentDataNode());
+              }
+          });
+      
+        builder.bindToAction(view.getPasswordEncoder(),  "validatePasswordEncoderAction()");
+        builder.bindToAction(view.getPasswordLocation(), "passwordLocationChangedAction()");
+      
+    }
+    
+    protected void refreshView(DataNode node) {
+        this.node = node;
+
+        if (node == null) {
+            getView().setVisible(false);
+            return;
+        }
+        
+        for (int i = 0; i < bindings.length; i++) {
+            bindings[i].updateView();
+        }
+        
+    }
+    
+    public void validatePasswordEncoderAction()
+    {
+      if (node == null || node.getDataSource() == null)
+        return;
+
+      DataSourceInfo dsi = ((ProjectDataSource) node.getDataSource()).getDataSourceInfo();
+
+      if (view.getPasswordEncoder().getSelectedItem().equals(dsi.getPasswordEncoderClass())
== false)
+        return;
+
+      if (dsi.getPasswordEncoder() == null)
+      {
+        JOptionPane.showMessageDialog(getView(),
+                                      "A valid Password Encoder should be specified (check
your CLASSPATH).",
+                                      "Invalid Password Encoder",
+                                      JOptionPane.ERROR_MESSAGE);
+      }
+    }
+    
+    private void updatePasswordElements(boolean isPasswordFieldEnabled,
+            boolean isPasswordLocationEnabled,
+            String  passwordText,
+            String  passwordLocationLabel,
+            String  passwordLocationText)
+    {
+        view.getPasswordSource().setEnabled(isPasswordLocationEnabled);
+        view.getPasswordSourceLabel().setText(passwordLocationLabel);
+        view.getPasswordSource().setText(passwordLocationText);
+    }
+    
+    public void passwordLocationChangedAction()
+    {
+      if (node == null || node.getDataSource() == null)
+        return;
+
+      DataSourceInfo dsi = ((ProjectDataSource) node.getDataSource()).getDataSourceInfo();
+
+      String selectedItem = (String) view.getPasswordLocation().getSelectedItem();
+
+      if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_CLASSPATH))
+        updatePasswordElements(true, true, dsi.getPassword(), "Password Filename:", dsi.getPasswordSourceFilename());
+      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE))
+        updatePasswordElements(false, true, null, "Password Executable:", dsi.getPasswordSourceExecutable());
+      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_MODEL))
+        updatePasswordElements(true, false, dsi.getPassword(), "Password Source:", dsi.getPasswordSourceModel());
+      else if (selectedItem.equals(DataSourceInfo.PASSWORD_LOCATION_URL))
+        updatePasswordElements(false, true, null, "Password URL:", dsi.getPasswordSourceUrl());
+    }
+
+    public Component getView() {
+        return view;
+    }
+
+    
+    public DataNode getNode() {
+        return node;
+    }
+
+    
+    public void setNode(DataNode node) {
+        this.node = node;
+    }
+
+
+
+
+}

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java?rev=687668&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/PasswordEncoderView.java
Thu Aug 21 02:35:42 2008
@@ -0,0 +1,182 @@
+/*****************************************************************
+ *   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.editor.datanode;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import org.apache.cayenne.conf.PasswordEncoding;
+import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+
+public class PasswordEncoderView extends JPanel{
+    
+    protected JComboBox      passwordEncoder;
+    protected JComboBox      passwordLocation;
+    protected JTextField     passwordKey;
+    protected JTextField     passwordSource;
+    protected JLabel         passwordSourceLabel;
+    
+    private static final String PASSWORD_CLASSPATH  = "Classpath Search (File System)";
+    private static final String PASSWORD_EXECUTABLE = "Executable Program";
+    private static final String PASSWORD_MODEL      = "Cayenne Model";
+    private static final String PASSWORD_URL        = "URL (file:, http:, etc)";
+    
+    private static final Object[] PASSWORD_LOCATIONS = new Object[] {
+        DataSourceInfo.PASSWORD_LOCATION_MODEL,
+        DataSourceInfo.PASSWORD_LOCATION_CLASSPATH,
+        DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE,
+        DataSourceInfo.PASSWORD_LOCATION_URL };
+    
+    private static final Map<String, String> passwordSourceLabels = new TreeMap<String,
String>();
+
+    static
+    {
+      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_MODEL, PASSWORD_MODEL);
+      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_CLASSPATH, PASSWORD_CLASSPATH);
+      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE, PASSWORD_EXECUTABLE);
+      passwordSourceLabels.put(DataSourceInfo.PASSWORD_LOCATION_URL, PASSWORD_URL);
+    }
+    
+    final class PasswordLocationRenderer extends DefaultListCellRenderer
+    {
+      public Component getListCellRendererComponent(JList list,
+                                                    Object object,
+                                                    int arg2,
+                                                    boolean arg3,
+                                                    boolean arg4)
+      {
+        if (object != null)
+          object = passwordSourceLabels.get(object);
+        else
+          object = PASSWORD_MODEL;
+
+        return super.getListCellRendererComponent(list, object, arg2, arg3, arg4);
+      }
+    }
+    
+    public PasswordEncoderView(){
+        
+        this.passwordEncoder  = new JComboBox();
+        this.passwordLocation = new JComboBox();
+        this.passwordSource   = new JTextField();
+        this.passwordKey      = new JTextField();
+        
+
+        
+        // init combo box choices                                                       
                                                                                         
              
+        passwordEncoder.setModel(new DefaultComboBoxModel(PasswordEncoding.standardEncoders));
+        passwordEncoder.setEditable(true);
+
+        passwordLocation = CayenneWidgetFactory.createComboBox();
+        passwordLocation.setRenderer(new PasswordLocationRenderer());
+
+        DefaultComboBoxModel passwordLocationModel = new DefaultComboBoxModel(PASSWORD_LOCATIONS);
+
+        passwordLocation.setModel(passwordLocationModel);
+
+        
+        CellConstraints cc = new CellConstraints();
+
+        FormLayout layout =
+            new FormLayout("right:80dlu, 3dlu, fill:50dlu, 3dlu, fill:74dlu, 3dlu, fill:70dlu",
// Columns
+                   "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu,
p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); // Rows
+        
+        PanelBuilder builder = new PanelBuilder(layout);
+        builder.setDefaultDialogBorder();
+        
+        builder.addSeparator("Encoder", cc.xywh(1, 1, 7, 1));
+        
+        builder.addLabel("Password Encoder:", cc.xy(1, 11));
+        builder.add(passwordEncoder, cc.xywh(3, 11, 5, 1));
+
+        builder.addLabel("Password Encoder Key:", cc.xy(1, 13));
+        builder.add(passwordKey, cc.xywh(3, 13, 5, 1));
+
+        builder.addLabel("Note: Cayenne supplied encoders do not use a key.", cc.xywh(3,
15, 5, 1));
+
+        builder.addLabel("Password Location:", cc.xy(1, 17));
+        builder.add(passwordLocation, cc.xywh(3, 17, 5, 1));
+
+        passwordSourceLabel = builder.addLabel("Password Source:", cc.xy(1, 19));
+        builder.add(passwordSource, cc.xywh(3, 19, 5, 1));
+
+
+        this.setLayout(new BorderLayout());
+        this.add(builder.getPanel(), BorderLayout.CENTER);
+
+    }
+    
+    /**
+     * @return the passwordEncoder
+     */
+    public JComboBox getPasswordEncoder()
+    {
+      return passwordEncoder;
+    }
+
+    /**
+     * @return the passwordLocation
+     */
+    public JComboBox getPasswordLocation()
+    {
+      return passwordLocation;
+    }
+
+    /**
+     * @return the passwordKey
+     */
+    public JTextField getPasswordKey()
+    {
+      return passwordKey;
+    }
+
+    /**
+     * @return the passwordSource
+     */
+    public JTextField getPasswordSource()
+    {
+      return passwordSource;
+    }
+
+    /**
+     * @return the passwordLocationLabel
+     */
+    public JLabel getPasswordSourceLabel()
+    {
+      return passwordSourceLabel;
+    }
+
+}



Mime
View raw message