Author: koen.aers(a)jboss.com
Date: 2009-02-05 22:23:31 -0500 (Thu, 05 Feb 2009)
New Revision: 13502
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/properties/DefaultLabelWrapperPropertySource.java
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/command/RenameElementCommand.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/LabelEditPart.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/policy/ElementDirectEditManager.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditPolicy.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultLabelWrapper.java
Log:
direct editing of labels
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/command/RenameElementCommand.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/command/RenameElementCommand.java 2009-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/command/RenameElementCommand.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -17,7 +17,9 @@
*/
import org.eclipse.gef.commands.Command;
-import org.jboss.tools.flow.common.wrapper.NodeWrapper;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.jboss.tools.flow.common.properties.IPropertyId;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
/**
* A command for renaming an element.
@@ -26,12 +28,16 @@
*/
public class RenameElementCommand extends Command {
- private NodeWrapper source;
+ private Wrapper source;
private String name;
private String oldName;
+
public void execute() {
- source.setName(name);
+ IPropertySource propertySource =
(IPropertySource)source.getAdapter(IPropertySource.class);
+ if (propertySource != null) {
+ propertySource.setPropertyValue(IPropertyId.NAME, name);
+ }
}
public void setName(String string) {
@@ -42,11 +48,14 @@
oldName = string;
}
- public void setSource(NodeWrapper action) {
+ public void setSource(Wrapper action) {
source = action;
}
public void undo() {
- source.setName(oldName);
+ IPropertySource propertySource =
(IPropertySource)source.getAdapter(IPropertySource.class);
+ if (propertySource != null) {
+ propertySource.setPropertyValue(IPropertyId.NAME, oldName);
+ }
}
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/LabelEditPart.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/LabelEditPart.java 2009-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/LabelEditPart.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -9,17 +9,25 @@
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.gef.tools.DragEditPartsTracker;
+import org.jboss.tools.flow.common.policy.ElementDirectEditManager;
+import org.jboss.tools.flow.common.policy.ElementDirectEditPolicy;
import org.jboss.tools.flow.common.policy.LabelGraphicalNodeEditPolicy;
import org.jboss.tools.flow.common.wrapper.LabelWrapper;
import org.jboss.tools.flow.common.wrapper.ModelEvent;
import org.jboss.tools.flow.common.wrapper.ModelListener;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
public class LabelEditPart extends AbstractGraphicalEditPart implements ModelListener {
+ private DirectEditManager manager;
+
@Override
protected IFigure createFigure() {
return new Label();
@@ -27,12 +35,12 @@
@Override
protected void createEditPolicies() {
- installEditPolicy("GraphicalNodeEditPoliy", new
LabelGraphicalNodeEditPolicy());
+ installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new LabelGraphicalNodeEditPolicy());
+ installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new ElementDirectEditPolicy());
}
protected void refreshVisuals() {
String text = getLabelWrapper().getText();
-// if (text == null || "".equals(text)) text = "text";
Polyline polyline = (Polyline)((ConnectionEditPart)getParent()).getConnectionFigure();
Point location = ((LabelWrapper)getModel()).getLocation();
if (location == null) {
@@ -50,6 +58,25 @@
return new Point(- (textDimension.width +5) , -(textDimension.height + 5));
}
+ public void performRequest(Request request) {
+ if (request.getType() == RequestConstants.REQ_DIRECT_EDIT) {
+ performDirectEdit();
+ } else {
+ super.performRequest(request);
+ }
+ }
+
+ protected void performDirectEdit() {
+ Label label = (Label) getFigure();
+ if (label == null) {
+ return;
+ }
+ if (manager == null) {
+ manager = new ElementDirectEditManager(this, new CellEditorLocator(label));
+ }
+ manager.show();
+ }
+
public LabelWrapper getLabelWrapper() {
return (LabelWrapper)getModel();
}
@@ -65,9 +92,15 @@
public void activate() {
super.activate();
getLabelWrapper().addListener(this);
+ if (getParent().getModel() instanceof Wrapper) {
+ ((Wrapper)getParent().getModel()).addListener(this);
+ }
}
public void deactivate() {
+ if (getParent().getModel() instanceof Wrapper) {
+ ((Wrapper)getParent().getModel()).removeListener(this);
+ }
getLabelWrapper().removeListener(this);
super.deactivate();
}
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-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/RootEditPart.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -121,18 +121,4 @@
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;
-// }
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditManager.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditManager.java 2009-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditManager.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -16,12 +16,14 @@
* limitations under the License.
*/
+import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.widgets.Text;
-import org.jboss.tools.flow.common.editpart.ElementEditPart;
-import org.jboss.tools.flow.common.wrapper.NodeWrapper;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.jboss.tools.flow.common.properties.IPropertyId;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
/**
* Manager for directly editing elements.
@@ -30,15 +32,22 @@
*/
public class ElementDirectEditManager extends DirectEditManager {
- private NodeWrapper element;
+ private IPropertySource propertySource;
- public ElementDirectEditManager(ElementEditPart source, CellEditorLocator locator) {
+ public ElementDirectEditManager(GraphicalEditPart source, CellEditorLocator locator)
{
super(source, TextCellEditor.class, locator);
- element = source.getElementWrapper();
+ Object object = source.getModel();
+ if (object instanceof Wrapper) {
+ propertySource =
(IPropertySource)((Wrapper)object).getAdapter(IPropertySource.class);
+ }
}
protected void initCellEditor() {
- getCellEditor().setValue(element.getName());
+ String initialValue = null;
+ if (propertySource != null) {
+ initialValue = (String)propertySource.getPropertyValue(IPropertyId.NAME);
+ }
+ getCellEditor().setValue(initialValue == null ? "" : initialValue);
Text text = (Text) getCellEditor().getControl();
text.selectAll();
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditPolicy.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditPolicy.java 2009-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/policy/ElementDirectEditPolicy.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -16,12 +16,16 @@
* limitations under the License.
*/
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.DirectEditPolicy;
import org.eclipse.gef.requests.DirectEditRequest;
+import org.eclipse.ui.views.properties.IPropertySource;
import org.jboss.tools.flow.common.command.RenameElementCommand;
import org.jboss.tools.flow.common.figure.ElementFigure;
-import org.jboss.tools.flow.common.wrapper.NodeWrapper;
+import org.jboss.tools.flow.common.properties.IPropertyId;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
/**
* Policy for directly editing elements.
@@ -32,15 +36,23 @@
protected Command getDirectEditCommand(DirectEditRequest request) {
RenameElementCommand cmd = new RenameElementCommand();
- cmd.setSource((NodeWrapper) getHost().getModel());
- cmd.setOldName(((NodeWrapper) getHost().getModel()).getName());
+ cmd.setSource((Wrapper) getHost().getModel());
+ IPropertySource propertySource =
(IPropertySource)((Wrapper)getHost().getModel()).getAdapter(IPropertySource.class);
+ if (propertySource != null) {
+ cmd.setOldName((String)propertySource.getPropertyValue(IPropertyId.NAME));
+ }
cmd.setName((String) request.getCellEditor().getValue());
return cmd;
}
protected void showCurrentEditValue(DirectEditRequest request) {
String value = (String) request.getCellEditor().getValue();
- ((ElementFigure) getHostFigure()).setText(value);
+ IFigure figure = getHostFigure();
+ if (figure instanceof Label) {
+ ((Label)figure).setText(value);
+ } else if (figure instanceof ElementFigure){
+ ((ElementFigure)figure).setText(value);
+ }
}
}
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/properties/DefaultLabelWrapperPropertySource.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/properties/DefaultLabelWrapperPropertySource.java
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/properties/DefaultLabelWrapperPropertySource.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -0,0 +1,22 @@
+package org.jboss.tools.flow.common.properties;
+
+import org.jboss.tools.flow.common.wrapper.DefaultLabelWrapper;
+
+public class DefaultLabelWrapperPropertySource extends WrapperPropertySource implements
IPropertyId {
+
+ private DefaultLabelWrapper wrapper = null;
+
+ public DefaultLabelWrapperPropertySource(DefaultLabelWrapper wrapper) {
+ super(wrapper);
+ this.wrapper = wrapper;
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ if (NAME.equals(id)) {
+ if (value instanceof String) {
+ wrapper.setText((String)value);
+ }
+ }
+ super.setPropertyValue(id, value);
+ }
+}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java 2009-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -67,7 +67,7 @@
((Element)element).setMetaData("configurationElement",
configurationElement);
ConnectionWrapper result = new DefaultConnectionWrapper();
result.setElement((Element)element);
- result.setLabel(new DefaultLabelWrapper((Element)element));
+ result.setLabel(new DefaultLabelWrapper(result));
return result;
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultLabelWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultLabelWrapper.java 2009-02-06
01:40:55 UTC (rev 13501)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultLabelWrapper.java 2009-02-06
03:23:31 UTC (rev 13502)
@@ -1,22 +1,23 @@
package org.jboss.tools.flow.common.wrapper;
import org.eclipse.ui.views.properties.IPropertySource;
-import org.jboss.tools.flow.common.model.Element;
import org.jboss.tools.flow.common.properties.IPropertyId;
public class DefaultLabelWrapper extends AbstractLabelWrapper {
private IPropertySource propertySource;
- public DefaultLabelWrapper(Element element) {
- if (element != null) {
- propertySource = (IPropertySource)element.getMetaData("propertySource");
+ public DefaultLabelWrapper(Wrapper owner) {
+ if (owner != null) {
+ propertySource = (IPropertySource)owner.getAdapter(IPropertySource.class);
+ setElement(owner.getElement());
}
}
public void setText(String text) {
if (propertySource != null) {
propertySource.setPropertyValue(IPropertyId.LABEL, text);
+ notifyListeners(CHANGE_VISUAL, text);
}
}
@@ -28,4 +29,13 @@
return result;
}
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ if (adapter == IPropertySource.class && propertySource != null) {
+ return propertySource;
+ }
+ return super.getAdapter(adapter);
+ }
+
+
}