Author: koen.aers(a)jboss.com
Date: 2009-01-26 16:13:45 -0500 (Mon, 26 Jan 2009)
New Revision: 13281
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ContainerEditPart.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ElementEditPart.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/RootEditPart.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractContainerWrapper.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractFlowWrapper.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractNodeWrapper.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ContainerWrapper.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/FlowWrapper.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ModelEvent.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/NodeWrapper.java
Log:
- elements can have a label
- the event model supports notification of the event with the changed object (to support
direct editing when a node is added)
Modified: trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd 2009-01-26
18:13:18 UTC (rev 13280)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd 2009-01-26
21:13:45 UTC (rev 13281)
@@ -79,7 +79,7 @@
</documentation>
</annotation>
</attribute>
- <attribute name="name" type="string">
+ <attribute name="label" type="string">
<annotation>
<documentation>
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ContainerEditPart.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ContainerEditPart.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ContainerEditPart.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -19,12 +19,14 @@
import java.util.List;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.MouseWheelHelper;
import org.eclipse.gef.editparts.ViewportMouseWheelHelper;
import org.jboss.tools.flow.common.figure.ElementContainerFigure;
import org.jboss.tools.flow.common.policy.ElementContainerLayoutEditPolicy;
import org.jboss.tools.flow.common.wrapper.AbstractContainerWrapper;
+import org.jboss.tools.flow.common.wrapper.ContainerWrapper;
import org.jboss.tools.flow.common.wrapper.ModelEvent;
import org.jboss.tools.flow.common.wrapper.NodeWrapper;
@@ -45,7 +47,16 @@
}
public void modelChanged(ModelEvent event) {
- if (event.getChange() == AbstractContainerWrapper.CHANGE_ELEMENTS) {
+ if (event.getChange() == ContainerWrapper.ADD_ELEMENT) {
+ refreshChildren();
+ Object changedObject = event.getChangedObject();
+ if (changedObject != null) {
+ EditPart editPart =
(EditPart)getViewer().getEditPartRegistry().get(changedObject);
+ if (editPart instanceof ElementEditPart) {
+ ((ElementEditPart)editPart).performDirectEdit();
+ }
+ }
+ } else if (event.getChange() == ContainerWrapper.REMOVE_ELEMENT) {
refreshChildren();
} else {
super.modelChanged(event);
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ElementEditPart.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ElementEditPart.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ElementEditPart.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -99,10 +99,16 @@
}
public void modelChanged(ModelEvent event) {
- if (event.getChange() == NodeWrapper.CHANGE_INCOMING_CONNECTIONS) {
+ if (event.getChange() == NodeWrapper.ADD_INCOMING_CONNECTION) {
+ System.out.println("first");
refreshTargetConnections();
- } else if (event.getChange() == NodeWrapper.CHANGE_OUTGOING_CONNECTIONS) {
+ } else if (event.getChange() == NodeWrapper.REMOVE_INCOMING_CONNECTION) {
+ refreshTargetConnections();
+ } else if (event.getChange() == NodeWrapper.ADD_OUTGOING_CONNECTION) {
+ System.out.println("second");
refreshSourceConnections();
+ } else if (event.getChange() == NodeWrapper.REMOVE_OUTGOING_CONNECTION) {
+ refreshSourceConnections();
} else if (event.getChange() == NodeWrapper.CHANGE_VISUAL) {
refreshVisuals();
}
@@ -132,7 +138,7 @@
// do nothing
}
- private void performDirectEdit() {
+ protected void performDirectEdit() {
Label label = ((ElementFigure) getFigure()).getLabel();
if (label == null) {
return;
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/RootEditPart.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/RootEditPart.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/RootEditPart.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -28,16 +28,17 @@
import org.eclipse.draw2d.ManhattanConnectionRouter;
import org.eclipse.draw2d.ShortestPathConnectionRouter;
import org.eclipse.draw2d.XYLayout;
-import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.SnapToGrid;
import org.eclipse.gef.SnapToHelper;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
-import org.jboss.tools.flow.common.figure.ElementFigure;
import org.jboss.tools.flow.common.policy.ElementContainerLayoutEditPolicy;
+import org.jboss.tools.flow.common.wrapper.ContainerWrapper;
import org.jboss.tools.flow.common.wrapper.FlowWrapper;
import org.jboss.tools.flow.common.wrapper.ModelEvent;
import org.jboss.tools.flow.common.wrapper.ModelListener;
@@ -83,7 +84,18 @@
}
public void modelChanged(ModelEvent event) {
- if (event.getChange() == FlowWrapper.CHANGE_ELEMENTS) {
+ if (event.getChange() == ContainerWrapper.ADD_ELEMENT) {
+ refreshChildren();
+ Object changedObject = event.getChangedObject();
+ if (changedObject != null) {
+ EditPart editPart =
(EditPart)getViewer().getEditPartRegistry().get(changedObject);
+ if (editPart instanceof ElementEditPart) {
+ ((ElementEditPart)editPart).performDirectEdit();
+ // force selection to update the properties view
+ getViewer().setSelection(new StructuredSelection(editPart));
+ }
+ }
+ } else if (event.getChange() == ContainerWrapper.REMOVE_ELEMENT) {
refreshChildren();
} else if (event.getChange() == FlowWrapper.CHANGE_VISUAL) {
refreshVisuals();
@@ -120,18 +132,18 @@
Animation.run(400);
}
- @SuppressWarnings("unchecked")
- public boolean setTableModelBounds() {
- List<ElementEditPart> tableParts = getChildren();
- for (ElementEditPart elementEditPart: tableParts) {
- ElementFigure elementFigure = (ElementFigure) elementEditPart.getFigure();
- if (elementFigure == null) {
- continue;
- }
- Rectangle constraint = elementFigure.getBounds().getCopy();
- NodeWrapper elementWrapper = elementEditPart.getElementWrapper();
- elementWrapper.setConstraint(constraint);
- }
- return true;
- }
+// @SuppressWarnings("unchecked")
+// public boolean setTableModelBounds() {
+// List<ElementEditPart> tableParts = getChildren();
+// for (ElementEditPart elementEditPart: tableParts) {
+// ElementFigure elementFigure = (ElementFigure) elementEditPart.getFigure();
+// if (elementFigure == null) {
+// continue;
+// }
+// Rectangle constraint = elementFigure.getBounds().getCopy();
+// NodeWrapper elementWrapper = elementEditPart.getElementWrapper();
+// elementWrapper.setConstraint(constraint);
+// }
+// return true;
+// }
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractContainerWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractContainerWrapper.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractContainerWrapper.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -21,14 +21,12 @@
public abstract class AbstractContainerWrapper extends AbstractNodeWrapper implements
ContainerWrapper {
- public static final int CHANGE_ELEMENTS = 4;
-
List<NodeWrapper> elements = new ArrayList<NodeWrapper>();
public void addElement(NodeWrapper element) {
internalAddElement(element);
localAddElement(element);
- notifyListeners(CHANGE_ELEMENTS);
+ notifyListeners(ADD_ELEMENT, element);
}
public void localAddElement(NodeWrapper element) {
@@ -42,7 +40,7 @@
internalRemoveElement(element);
elements.remove(element);
element.setParent(null);
- notifyListeners(CHANGE_ELEMENTS);
+ notifyListeners(REMOVE_ELEMENT, element);
}
protected abstract void internalRemoveElement(NodeWrapper element);
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractFlowWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractFlowWrapper.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractFlowWrapper.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -37,7 +37,7 @@
public void setRouterLayout(Integer routerLayout) {
internalSetRouterLayout(routerLayout);
- notifyListeners(CHANGE_VISUAL);
+ notifyListeners(CHANGE_VISUAL, null);
}
protected void internalSetRouterLayout(Integer routerLayout) {
@@ -56,7 +56,7 @@
if (!acceptsElement(element)) return;
internalAddElement(element);
localAddElement(element);
- notifyListeners(CHANGE_ELEMENTS);
+ notifyListeners(ADD_ELEMENT, element);
}
public void localAddElement(NodeWrapper element) {
@@ -79,7 +79,7 @@
public void removeElement(NodeWrapper element) {
localRemoveElement(element);
internalRemoveElement(element);
- notifyListeners(CHANGE_ELEMENTS);
+ notifyListeners(REMOVE_ELEMENT, element);
}
protected abstract void internalRemoveElement(NodeWrapper element);
@@ -96,8 +96,8 @@
listeners.remove(listener);
}
- public void notifyListeners(int change) {
- ModelEvent event = new ModelEvent(change);
+ protected void notifyListeners(int change, NodeWrapper wrapper) {
+ ModelEvent event = new ModelEvent(change, wrapper);
for (ModelListener listener: listeners) {
listener.modelChanged(event);
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractNodeWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractNodeWrapper.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/AbstractNodeWrapper.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -50,7 +50,7 @@
public void setConstraint(Rectangle constraint) {
this.constraint = constraint;
internalSetConstraint(constraint);
- notifyListeners(CHANGE_VISUAL);
+ notifyListeners(CHANGE_VISUAL, this);
}
protected abstract void internalSetConstraint(Rectangle constraint);
@@ -91,7 +91,7 @@
public void addIncomingConnection(ConnectionWrapper connection) {
localAddIncomingConnection(connection);
internalAddIncomingConnection(connection);
- notifyListeners(CHANGE_INCOMING_CONNECTIONS);
+ notifyListeners(ADD_INCOMING_CONNECTION, connection);
}
public void localAddIncomingConnection(ConnectionWrapper connection) {
@@ -104,7 +104,7 @@
public void removeIncomingConnection(ConnectionWrapper connection) {
incomingConnections.remove(connection);
internalRemoveIncomingConnection(connection);
- notifyListeners(CHANGE_INCOMING_CONNECTIONS);
+ notifyListeners(REMOVE_INCOMING_CONNECTION, connection);
}
protected void internalRemoveIncomingConnection(ConnectionWrapper connection) {
@@ -113,7 +113,7 @@
public void addOutgoingConnection(ConnectionWrapper connection) {
localAddOutgoingConnection(connection);
internalAddOutgoingConnection(connection);
- notifyListeners(CHANGE_OUTGOING_CONNECTIONS);
+ notifyListeners(ADD_OUTGOING_CONNECTION, connection);
}
public void localAddOutgoingConnection(ConnectionWrapper connection) {
@@ -126,7 +126,7 @@
public void removeOutgoingConnection(ConnectionWrapper connection) {
outgoingConnections.remove(connection);
internalRemoveOutgoingConnection(connection);
- notifyListeners(CHANGE_OUTGOING_CONNECTIONS);
+ notifyListeners(REMOVE_OUTGOING_CONNECTION, connection);
}
protected void internalRemoveOutgoingConnection(ConnectionWrapper connection) {
@@ -134,7 +134,7 @@
public void setName(String name) {
internalSetName(name);
- notifyListeners(CHANGE_VISUAL);
+ notifyListeners(CHANGE_VISUAL, this);
}
protected void internalSetName(String name) {
@@ -148,8 +148,8 @@
listeners.remove(listener);
}
- protected void notifyListeners(int change) {
- ModelEvent event = new ModelEvent(change);
+ protected void notifyListeners(int change, Object object) {
+ ModelEvent event = new ModelEvent(change, object);
for (ModelListener listener: listeners) {
listener.modelChanged(event);
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ContainerWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ContainerWrapper.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ContainerWrapper.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -19,7 +19,11 @@
import java.util.List;
public interface ContainerWrapper extends Wrapper {
-
+
+ int ADD_ELEMENT = 1;
+ int REMOVE_ELEMENT = 2;
+ int CHANGE_VISUAL = 3;
+
void addElement(NodeWrapper element);
void localAddElement(NodeWrapper element);
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/FlowWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/FlowWrapper.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/FlowWrapper.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -2,9 +2,6 @@
public interface FlowWrapper extends ContainerWrapper {
- int CHANGE_ELEMENTS = 1;
- int CHANGE_VISUAL = 2;
-
Integer ROUTER_LAYOUT_MANUAL = new Integer(0);
Integer ROUTER_LAYOUT_MANHATTAN = new Integer(1);
Integer ROUTER_LAYOUT_SHORTEST_PATH = new Integer(2);
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ModelEvent.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ModelEvent.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/ModelEvent.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -24,13 +24,23 @@
public class ModelEvent {
private int change;
+ private Object changedObject;
public ModelEvent(int change) {
this.change = change;
}
+ public ModelEvent(int change, Object changedObject) {
+ this.change = change;
+ this.changedObject = changedObject;
+ }
+
public int getChange() {
return change;
}
-
+
+ public Object getChangedObject() {
+ return changedObject;
+ }
+
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/NodeWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/NodeWrapper.java 2009-01-26
18:13:18 UTC (rev 13280)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/NodeWrapper.java 2009-01-26
21:13:45 UTC (rev 13281)
@@ -27,9 +27,11 @@
*/
public interface NodeWrapper extends Wrapper {
- static final int CHANGE_INCOMING_CONNECTIONS = 1;
- static final int CHANGE_OUTGOING_CONNECTIONS = 2;
- static final int CHANGE_VISUAL = 3;
+ static final int ADD_INCOMING_CONNECTION = 1;
+ static final int REMOVE_INCOMING_CONNECTION = 2;
+ static final int ADD_OUTGOING_CONNECTION = 3;
+ static final int REMOVE_OUTGOING_CONNECTION = 4;
+ static final int CHANGE_VISUAL = 5;
String getId();
String getName();