Revision: 3782
Author: [email protected]
Date: Thu Jul 22 13:10:20 2010
Log: Reverted the change to allow the critics editor panel generate fields for properties of the critics.

Now there is a factory in both the Architect and Enterprise editions that returns the correct critic settings panel for the critics. This allows the critic group panels in Architect to display critic settings panels that only exist in the enterprise edition.
http://code.google.com/p/power-architect/source/detail?r=3782

Added:
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/EditCriticSettingsAction.java /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticSettingsPanelFactory.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticAndSettings.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticGroupingPanel.java /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticManagerPanel.java /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticSettingsPanel.java

=======================================
--- /dev/null
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/action/EditCriticSettingsAction.java Thu Jul 22 13:10:20 2010
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.swingui.action;
+
+import java.awt.event.ActionEvent;
+
+import javax.annotation.Nonnull;
+import javax.swing.JDialog;
+
+import ca.sqlpower.architect.swingui.ArchitectFrame;
+import ca.sqlpower.architect.swingui.Messages;
+import ca.sqlpower.architect.swingui.critic.CriticManagerPanel;
+import ca.sqlpower.architect.swingui.critic.CriticSettingsPanelFactory;
+import ca.sqlpower.swingui.DataEntryPanelBuilder;
+
+/**
+ * This action will display the critic manager editor panel. With this panel the
+ * user can set all of the settings of all of the critics the manager knows
+ * about.
+ */
+public class EditCriticSettingsAction extends AbstractArchitectAction {
+
+ private CriticSettingsPanelFactory settingsPanelFactory = new CriticSettingsPanelFactory();
+
+    public EditCriticSettingsAction(ArchitectFrame frame) {
+ super(frame, "Validation Manager...", "Display the settings of the validation framework.");
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+ CriticManagerPanel criticManagerPanel = new CriticManagerPanel(getSession(), settingsPanelFactory); + JDialog criticManagerDialog = DataEntryPanelBuilder.createDataEntryPanelDialog(
+                criticManagerPanel, frame,
+ Messages.getString("ArchitectFrame.criticManagerName"), DataEntryPanelBuilder.OK_BUTTON_LABEL);
+        criticManagerDialog.pack();
+        criticManagerDialog.setVisible(true);
+    }
+
+    /**
+     * Sets the settings panel factory. Cannot be null.
+     */
+ public void setSettingsPanelFactory(@Nonnull CriticSettingsPanelFactory settingsPanelFactory) {
+        this.settingsPanelFactory = settingsPanelFactory;
+    }
+
+}
=======================================
--- /dev/null
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticSettingsPanelFactory.java Thu Jul 22 13:10:20 2010
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.swingui.critic;
+
+import ca.sqlpower.architect.ddl.critic.CriticAndSettings;
+
+/**
+ * Returns critic panels that allow for editing any critic in Architect. This + * can be overridden in other places to provide different editors with other
+ * properties as necessary.
+ */
+public class CriticSettingsPanelFactory {
+
+ public CriticSettingsPanel createCriticsSettingsPanel(CriticAndSettings settings) {
+        return new CriticSettingsPanel(settings);
+    }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticAndSettings.java Thu Jul 22 09:06:16 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticAndSettings.java Thu Jul 22 13:10:20 2010
@@ -21,7 +21,6 @@

 import java.util.Collections;
 import java.util.List;
-import java.util.Map;

 import ca.sqlpower.architect.ArchitectProject;
 import ca.sqlpower.architect.ddl.DB2DDLGenerator;
@@ -41,7 +40,6 @@
 import ca.sqlpower.object.annotation.Constructor;
 import ca.sqlpower.object.annotation.ConstructorParameter;
 import ca.sqlpower.object.annotation.Mutator;
-import ca.sqlpower.object.annotation.NonProperty;

 /**
* The settings of a specific {...@link Critic}. Includes if the critic is enabled
@@ -265,49 +263,4 @@
         return session;
     }

-    /**
-     * Returns a map of property names to their properties that a user can
- * change and update to affect the settings of a critic. These properties - * can be of different types which can affect how the user can interact with
-     * them. This method exists to allow an editor interface to display and
- * change the properties of a critic in a way that is not implementation
-     * specific.
-     * <p>
-     * If this method is overridden you must also override
-     * {...@link #setProperty(String, Object)}
-     * <p>
-     * If the properties in this map are to be persisted they need proper
-     * getters and setters that are annotated.
-     */
-    @NonProperty
-    public Map<String, Object> getProperties() {
-        return Collections.emptyMap();
-    }
-
-    /**
-     * @see #getProperties()
-     */
-    @NonProperty
-    public void setProperty(String propertyName, Object value) {
-        //do nothing
-    }
-
-    /**
- * Returns a user-friendly description of what the property is used for in the - * critic. If the property name is not known in this critic a null value will be returned.
-     */
-    @NonProperty
-    public String getPropertyDescription(String propertyName) {
-        return null;
-    }
-
-    /**
- * Returns the list of enum objects that the given property can be set to. - * If the property is not an enum or does not exist in the object null will
-     * be returned.
-     */
-    public List<Object> getEnumPropertyValues(String propertyName) {
-        return null;
-    }
-
-}
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java Wed Jul 21 08:10:13 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java Thu Jul 22 13:10:20 2010
@@ -104,6 +104,7 @@
import ca.sqlpower.architect.swingui.action.DatabaseConnectionManagerAction;
 import ca.sqlpower.architect.swingui.action.DeleteSelectedAction;
 import ca.sqlpower.architect.swingui.action.EditColumnAction;
+import ca.sqlpower.architect.swingui.action.EditCriticSettingsAction;
 import ca.sqlpower.architect.swingui.action.EditRelationshipAction;
 import ca.sqlpower.architect.swingui.action.EditSelectedAction;
 import ca.sqlpower.architect.swingui.action.EditSelectedIndexAction;
@@ -136,7 +137,6 @@
 import ca.sqlpower.architect.swingui.action.ZoomResetAction;
 import ca.sqlpower.architect.swingui.action.ZoomToFitAction;
import ca.sqlpower.architect.swingui.action.enterprise.RefreshProjectAction;
-import ca.sqlpower.architect.swingui.critic.CriticManagerPanel;
 import ca.sqlpower.architect.swingui.enterprise.ProjectSecurityPanel;
 import ca.sqlpower.architect.swingui.enterprise.RevisionListPanel;
 import ca.sqlpower.architect.swingui.enterprise.SecurityPanel;
@@ -152,7 +152,6 @@
 import ca.sqlpower.sqlobject.SQLDatabase;
 import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.SQLTable.TransferStyles;
-import ca.sqlpower.swingui.DataEntryPanelBuilder;
 import ca.sqlpower.swingui.RecentMenu;
 import ca.sqlpower.swingui.SPSUtils;
 import ca.sqlpower.swingui.StackedTabComponent;
@@ -263,15 +262,7 @@

private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();

- private Action showCriticsManagerAction = new AbstractAction(Messages.getString("ArchitectFrame.criticManagerName")) {
-        public void actionPerformed(ActionEvent e) {
- JDialog criticManagerDialog = DataEntryPanelBuilder.createDataEntryPanelDialog( - new CriticManagerPanel(currentSession), ArchitectFrame.this, - Messages.getString("ArchitectFrame.criticManagerName"), DataEntryPanelBuilder.OK_BUTTON_LABEL);
-            criticManagerDialog.pack();
-            criticManagerDialog.setVisible(true);
-        }
-    };
+ private final EditCriticSettingsAction showCriticsManagerAction = new EditCriticSettingsAction(this);

     /**
      * Closes all sessions and terminates the JVM.
@@ -1060,7 +1051,7 @@
                 currentSession.getProfileDialog().setVisible(true);
             }
         });
-        windowMenu.add(new JMenuItem(showCriticsManagerAction));
+        windowMenu.add(new JMenuItem(getShowCriticsManagerAction()));

         menuBar.add(windowMenu);

@@ -1579,6 +1570,10 @@
         return currentSession;
     }

+    public EditCriticSettingsAction getShowCriticsManagerAction() {
+        return showCriticsManagerAction;
+    }
+
     private class TabDropTargetListener implements DropTargetListener {

         public void dragEnter(DropTargetDragEvent dtde) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticGroupingPanel.java Thu Jul 22 09:04:34 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticGroupingPanel.java Thu Jul 22 13:10:20 2010
@@ -237,7 +237,7 @@
      * grouping panels.
      */
     private final CriticManagerPanel parentPanel;
-
+
public CriticGroupingPanel(CriticGrouping grouping, CriticManagerPanel parentPanel) {
         this.grouping = grouping;
         this.parentPanel = parentPanel;
@@ -246,7 +246,8 @@
         DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(
                 "pref, 0dlu, pref:grow", "top:pref"), panel);
         for (CriticAndSettings settings : grouping.getSettings()) {
- final CriticSettingsPanel settingsPanel = new CriticSettingsPanel(settings);
+            final CriticSettingsPanel settingsPanel =
+ parentPanel.getSettingsPanelFactory().createCriticsSettingsPanel(settings);
             settingsPanels.put(settings, settingsPanel);
         }

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticManagerPanel.java Thu Jul 8 13:13:42 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticManagerPanel.java Thu Jul 22 13:10:20 2010
@@ -66,9 +66,15 @@
      * in the critic settings panel to line up.
      */
     private int preferredCriticPanelSize = 0;
-
-    public CriticManagerPanel(ArchitectSwingSession session) {
-
+
+    /**
+     * This factory will be used to create the settings editors.
+     */
+    private final CriticSettingsPanelFactory settingsPanelFactory;
+
+ public CriticManagerPanel(ArchitectSwingSession session, CriticSettingsPanelFactory settingsPanelFactory) {
+
+        this.settingsPanelFactory = settingsPanelFactory;
         mainPanel = new JPanel();
DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref"));

@@ -170,5 +176,9 @@
     public int getPreferredCriticPanelSize() {
         return preferredCriticPanelSize;
     }
+
+    public CriticSettingsPanelFactory getSettingsPanelFactory() {
+        return settingsPanelFactory;
+    }

 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticSettingsPanel.java Thu Jul 22 09:06:16 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticSettingsPanel.java Thu Jul 22 13:10:20 2010
@@ -22,9 +22,7 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;

 import javax.swing.JComboBox;
 import javax.swing.JComponent;
@@ -50,31 +48,25 @@
* The critic settings the panel will allow editing of. The settings will
      * not change until apply changes has been called.
      */
-    private final CriticAndSettings settings;
+    protected final CriticAndSettings settings;

     /**
      * The main panel of this data entry panel.
      */
-    private final JPanel panel;
+    protected final JPanel panel;

     /**
      * Allows users to change the severity level on a critic.
      */
-    private final JComboBox severityCombo;
+    protected final JComboBox severityCombo;

     /**
* The listeners in this list will be notified when there is a change to the * model that causes the UI to update. Components that may need to repaint
      * on these changes can listen and be notified here.
      */
- private final List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
-
-    /**
- * This map stores all of the property names to their combo boxes that a
-     * user can use to change the property of a setting with.
-     */
- private final Map<String, JComboBox> criticPropertyChoosers = new HashMap<String, JComboBox>();
-
+ protected final List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+
     /**
      * Updates the severity combo box due to changes to the model.
      */
@@ -94,18 +86,6 @@
     public CriticSettingsPanel(CriticAndSettings settings) {
         this.settings = settings;

- for (Map.Entry<String, Object> entry : settings.getProperties().entrySet()) {
-            if (entry.getValue() instanceof Boolean) {
- //TODO display a check box with the parameter name to the left of it
-            } else if (entry.getValue() instanceof String) {
- //TODO display a text field with a parameter name to the left of it
-            } else if (entry.getValue().getClass().isEnum()) {
- JComboBox box = new JComboBox(settings.getEnumPropertyValues(entry.getKey()).toArray());
-                box.setSelectedItem(entry.getValue());
-                criticPropertyChoosers.put(entry.getKey(), box);
-            }
-        }
-
         panel = new JPanel();
         severityCombo = new JComboBox(Severity.values());
if (settings.getPlatformType().equals(StarterPlatformTypes.CONFIGURATION.getName())) {
@@ -114,26 +94,15 @@
         severityCombo.setSelectedItem(settings.getSeverity());
//It would be nice if the layout used a pref:grow style for the first //column but it makes it difficult to set the preferred size correctly. - DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("pref, 10dlu, fill:pref:grow, 5dlu, pref"), panel);
-        builder.append(new JLabel(settings.getName()), 3);
+ DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout("fill:pref:grow, 5dlu, pref"), panel);
+        builder.append(new JLabel(settings.getName()));
         builder.append(severityCombo);

- for (Map.Entry<String, JComboBox> entry : criticPropertyChoosers.entrySet()) {
-            builder.nextLine();
-            builder.append("");
- builder.append(settings.getPropertyDescription(entry.getKey()));
-            builder.append(entry.getValue());
-
-        }
-
         settings.addSPListener(severitySettingListener);
     }

     public boolean applyChanges() {
         settings.setSeverity(((Severity) severityCombo.getSelectedItem()));
- for (Map.Entry<String, JComboBox> enumProperty : criticPropertyChoosers.entrySet()) { - settings.setProperty(enumProperty.getKey(), enumProperty.getValue().getSelectedItem());
-        }
         return true;
     }

@@ -147,12 +116,6 @@

     public boolean hasUnsavedChanges() {
if (!((Severity) severityCombo.getSelectedItem()).equals(settings.getSeverity())) return true; - for (Map.Entry<String, JComboBox> enumProperty : criticPropertyChoosers.entrySet()) { - if ((settings.getProperties().get(enumProperty.getKey()) == null && enumProperty.getValue().getSelectedItem() != null) - | | !settings.getProperties().get(enumProperty.getKey()).equals(enumProperty.getValue().getSelectedItem())) {
-                return true;
-            }
-        }
         return false;
     }

Reply via email to