Revision: 3439
Author: silva.josemanuel1
Date: Wed Apr  7 12:43:35 2010
Log: Fixed child ordering of PlayPenContentPane.
http://code.google.com/p/power-architect/source/detail?r=3439

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/swingui/ContainerPane.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenContentPane.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ContainerPane.java Tue Apr 6 14:44:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ContainerPane.java Wed Apr 7 12:43:35 2010
@@ -325,6 +325,7 @@
     /**
      * Returns a list of the items to be displayed with the model.
      */
+    @Transient @Accessor
     protected abstract List<C> getItems();

     /**
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Tue Apr 6 14:44:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPen.java Wed Apr 7 12:43:35 2010
@@ -682,19 +682,19 @@
PlayPenContentPane contentPane = (PlayPenContentPane) this.contentPane;
                    if (ppc instanceof TablePane) {
                        TablePane tp = (TablePane) ppc;
- addImpl(new TablePane(tp, contentPane), ppc.getPreferredLocation(), i); + addImpl(new TablePane(tp, contentPane), ppc.getPreferredLocation());
                    } else if (ppc instanceof Relationship) {
                        Relationship rel = (Relationship) ppc;
- addImpl(new Relationship(rel, contentPane), ppc.getPreferredLocation(), i); + addImpl(new Relationship(rel, contentPane), ppc.getPreferredLocation());
                    } else if (ppc instanceof CubePane) {
                        CubePane cp = (CubePane) ppc;
- addImpl(new CubePane(cp, contentPane), ppc.getPreferredLocation(), i); + addImpl(new CubePane(cp, contentPane), ppc.getPreferredLocation());
                    } else if (ppc instanceof DimensionPane) {
                        DimensionPane dp = (DimensionPane) ppc;
- addImpl(new DimensionPane(dp, contentPane), ppc.getPreferredLocation(), i); + addImpl(new DimensionPane(dp, contentPane), ppc.getPreferredLocation());
                    } else if (ppc instanceof VirtualCubePane) {
                        VirtualCubePane vcp = (VirtualCubePane) ppc;
- addImpl(new VirtualCubePane(vcp, contentPane), ppc.getPreferredLocation(), i); + addImpl(new VirtualCubePane(vcp, contentPane), ppc.getPreferredLocation());
                    } else if (ppc instanceof UsageComponent) {
                        UsageComponent uc = (UsageComponent) ppc;
                        contentPane.addChild(new UsageComponent(uc, 
contentPane), i);
@@ -717,9 +717,9 @@
      * @param index ignored for now, but would normally specify the
      * index of insertion for c in the child list.
      */
- protected void addImpl(PlayPenComponent c, Object constraints, int index) {
+    protected void addImpl(PlayPenComponent c, Object constraints) {
         if (c instanceof Relationship || c instanceof UsageComponent) {
-            contentPane.addChild(c, 0);
+ contentPane.addChild(c, contentPane.getFirstDependentComponentIndex());
         } else if (c instanceof ContainerPane) {
             if (constraints instanceof Point) {
                 c.setLocation((Point) constraints);
@@ -1114,7 +1114,7 @@
        }

        public void addRelationship(Relationship r) {
-               addImpl(r, null, getPPComponentCount());
+               addImpl(r, null);
        }

     /**
@@ -1124,7 +1124,7 @@
      * @param point
      */
     public void addTablePane(TablePane tp, Point point) {
-        addImpl(tp, point, getPPComponentCount());
+        addImpl(tp, point);
     }

     /**
@@ -1140,7 +1140,7 @@
      *            they connect) then this argument can be null.
      */
     public void addPlayPenComponent(PlayPenComponent ppc, Point point) {
-        addImpl(ppc, point, getPPComponentCount());
+        addImpl(ppc, point);
     }

        /**
@@ -1272,7 +1272,7 @@

                TablePane tp = new TablePane(newTable, getContentPane());
                logger.info("adding table "+newTable); //$NON-NLS-1$
-               addImpl(tp, preferredLocation, getPPComponentCount());
+               addImpl(tp, preferredLocation);
                tp.revalidate();

if (duplicateProperties.getDefaultTransferStyle() == TransferStyles.REVERSE_ENGINEER) {
@@ -1376,7 +1376,7 @@
                                    
newRel.attachRelationship(oldTable,newTable,false);
                                }

- addImpl(new Relationship(newRel, contentPane),null,getPPComponentCount());
+                               addImpl(new Relationship(newRel, contentPane), 
null);

                                Iterator<? extends SQLObject> mappings = 
r.getChildren().iterator();
                                while (mappings.hasNext()) {
@@ -1693,10 +1693,13 @@
         */
        public void childAdded(SPChildEvent e) {
                logger.debug("SQLObject children got inserted: "+e); 
//$NON-NLS-1$
-               childAdded = true;
-               boolean fireEvent = false;
                SPObject child = e.getChild();
-               addHierarchyListeners(child);
+        addHierarchyListeners(child);
+
+ if (!contentPane.isMagicEnabled() | | !e.getSource().isMagicEnabled()) return;
+
+        childAdded = true;
+        boolean fireEvent = false;
                try {
             if (child instanceof SQLTable
                     || (child instanceof SQLRelationship
@@ -1705,8 +1708,8 @@

PlayPenComponent ppc = removedComponents.get(child.getUUID());
                 if (ppc != null) {
-                    if (ppc instanceof Relationship) {
-                        contentPane.addChild(ppc, 0);
+ if (contentPane.isDependentComponentType(ppc.getClass())) { + contentPane.addChild(ppc, contentPane.getFirstDependentComponentIndex());
                     } else {
                         contentPane.addChild(ppc, 0);
                     }
@@ -1730,9 +1733,12 @@
         */
        public void childRemoved(SPChildEvent e) {
                logger.debug("SQLObject children got removed: "+e); 
//$NON-NLS-1$
-               boolean foundRemovedComponent = false;
                SPObject child = e.getChild();
                removeHierarchyListeners(child);
+
+ if (!contentPane.isMagicEnabled() || !e.getSource().isMagicEnabled()) return;
+
+               boolean foundRemovedComponent = false;

                try {
                    if (child instanceof SQLTable) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenContentPane.java Tue Apr 6 14:44:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/PlayPenContentPane.java Wed Apr 7 12:43:35 2010
@@ -32,6 +32,7 @@

 import ca.sqlpower.architect.ArchitectProject;
 import ca.sqlpower.architect.olap.OLAPSession;
+import ca.sqlpower.architect.swingui.olap.UsageComponent;
 import ca.sqlpower.object.AbstractSPListener;
 import ca.sqlpower.object.AbstractSPObject;
 import ca.sqlpower.object.ObjectDependentException;
@@ -52,10 +53,29 @@
        @SuppressWarnings("unchecked")
        public static final List<Class<? extends SPObject>> allowedChildTypes =
            Collections.unmodifiableList(new ArrayList<Class<? extends 
SPObject>>(
-                   Arrays.asList(PlayPenComponent.class)));
+                   Arrays.asList(PlayPenComponent.class)));
+
+       /**
+ * A list of component types that are dependent on other components (see dependentComponents)
+        */
+ private static final List<Class<? extends PlayPenComponent>> dependentComponentTypes = + Collections.unmodifiableList(new ArrayList<Class<? extends PlayPenComponent>>(
+                   Arrays.asList(Relationship.class, UsageComponent.class)));

     private PlayPen playPen;
+
+    /**
+     * The list of components not dependent on any other components.
+     * They are first in the children list.
+     */
private List<PlayPenComponent> components = new ArrayList<PlayPenComponent>();
+
+       /**
+        * These components are dependent on the first list of components.
+        * They come after that list in terms of the overall children list.
+        * Currently stores Relationships and UsageComponents
+        */
+ private List<PlayPenComponent> dependentComponents = new ArrayList<PlayPenComponent>();

     private SPObject modelContainer;

@@ -177,6 +197,19 @@
         }
         return null;
     }
+
+    @NonBound
+    public int getFirstDependentComponentIndex() {
+        return components.size();
+    }
+
+    @NonBound
+ public boolean isDependentComponentType(Class<? extends PlayPenComponent> componentType) { + for (Class<? extends PlayPenComponent> dependentType : dependentComponentTypes) {
+            if (dependentType.isAssignableFrom(componentType)) return true;
+        }
+        return false;
+    }

     /**
      * Fixes table pane sizes after the play pen's zoom changes (because
@@ -191,23 +224,34 @@
         }
     }

-    protected void addChildImpl(SPObject child, int pos) {
-        components.add(pos, (PlayPenComponent) child);
-        child.setParent(this);
+    protected void addChildImpl(SPObject child, int pos) {
         PlayPenComponent ppc = (PlayPenComponent) child;
+        if (dependentComponentTypes.contains(ppc.getClass())) {
+            dependentComponents.add(pos - components.size(), ppc);
+        } else {
+            components.add(pos, ppc);
+        }
+        ppc.setParent(this);
         if (getPlayPen() != null) {
             ppc.addSelectionListener(getPlayPen());
         }
-        fireChildAdded(child.getClass(), ppc, pos);
+        fireChildAdded(ppc.getClass(), ppc, pos);
         ppc.revalidate();
     }

     @Override
-    protected boolean removeChildImpl(SPObject child) {
-        int i = components.indexOf(child);
-        if (!components.remove(child)) return false;
-        fireChildRemoved(child.getClass(), child, i);
+    protected boolean removeChildImpl(SPObject child) {
+        int index = getChildren().indexOf(child);
+        boolean removed;
+        if (dependentComponentTypes.contains(child.getClass())) {
+            removed = dependentComponents.remove(child);
+        } else {
+            removed = components.remove(child);
+        }
+        if (!removed) return false;
+        fireChildRemoved(child.getClass(), child, index);
         child.setParent(null);
+        playPen.repaint();
         return true;
     }

@@ -228,7 +272,10 @@
     }

     public List<? extends PlayPenComponent> getChildren() {
-        return Collections.unmodifiableList(components);
+ List<PlayPenComponent> children = new ArrayList<PlayPenComponent>();
+        children.addAll(components);
+        children.addAll(dependentComponents);
+        return children;
     }

     @Accessor


--
To unsubscribe, reply using "remove me" as the subject.

Reply via email to