diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/image_obj.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/image_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..830be0ea08df3f7f3de47ec1e3b92a4052e4c85a Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/image_obj.gif differ diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/overview_obj.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/overview_obj.gif new file mode 100644 index 0000000000000000000000000000000000000000..0624021bc1ecd0a712580622c66eb03987039afc Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/overview_obj.gif differ diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps.gif new file mode 100644 index 0000000000000000000000000000000000000000..d11c996e570dfe06518631ba3f0f1893a21f88d1 Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps.gif differ diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps2.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps2.gif new file mode 100644 index 0000000000000000000000000000000000000000..2460e6a3f70de1a8e594535101cd9e8f4f3eb158 Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps2.gif differ diff --git a/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps3.gif b/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps3.gif new file mode 100644 index 0000000000000000000000000000000000000000..963bf79d8097c47c7e71b2dcfbdf665fe401c0f5 Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/eclipse16/prop_ps3.gif differ diff --git a/de.bmotionstudio.gef.editor/icons/icon_table.gif b/de.bmotionstudio.gef.editor/icons/icon_table.gif new file mode 100644 index 0000000000000000000000000000000000000000..d11c996e570dfe06518631ba3f0f1893a21f88d1 Binary files /dev/null and b/de.bmotionstudio.gef.editor/icons/icon_table.gif differ diff --git a/de.bmotionstudio.gef.editor/plugin.xml b/de.bmotionstudio.gef.editor/plugin.xml index c1986900c6bf97aa08dd8992e4523f31b0563ded..5be99e2974e7bb3004ff6166878b13223ed00f95 100644 --- a/de.bmotionstudio.gef.editor/plugin.xml +++ b/de.bmotionstudio.gef.editor/plugin.xml @@ -166,7 +166,7 @@ </group> <control groupid="de.bmotionstudio.gef.editor.group.main" - icon="icons/icon_image.gif" + icon="icons/eclipse16/image_obj.gif" id="de.bmotionstudio.gef.editor.image" name="Image" service="de.bmotionstudio.gef.editor.service.BImageService"> @@ -194,7 +194,7 @@ </control> <control groupid="de.bmotionstudio.gef.editor.group.main" - icon="icons/icon_composite.gif" + icon="icons/eclipse16/overview_obj.gif" id="de.bmotionstudio.gef.editor.composite" name="Composite" service="de.bmotionstudio.gef.editor.service.BCompositeService"> @@ -234,6 +234,27 @@ name="Connection" service="de.bmotionstudio.gef.editor.service.BConnectionService"> </control> + <control + groupid="de.bmotionstudio.gef.editor.group.main" + icon="icons/eclipse16/prop_ps.gif" + id="de.bmotionstudio.gef.editor.table" + name="Table" + service="de.bmotionstudio.gef.editor.service.BTableService"> + </control> + <control + groupid="de.bmotionstudio.gef.editor.group.main" + icon="icons/eclipse16/prop_ps2.gif" + id="de.bmotionstudio.gef.editor.tablecolumn" + name="Column" + service="de.bmotionstudio.gef.editor.service.BTableColumnService"> + </control> + <control + groupid="de.bmotionstudio.gef.editor.group.main" + icon="icons/eclipse16/prop_ps3.gif" + id="de.bmotionstudio.gef.editor.tablecell" + name="Cell" + service="de.bmotionstudio.gef.editor.service.BTableCellService"> + </control> </extension> <extension point="de.bmotionstudio.gef.editor.observer"> @@ -269,6 +290,10 @@ class="de.bmotionstudio.gef.editor.observer.ExternalObserverScript" name="External Observer Script"> </observer> + <observer + class="de.bmotionstudio.gef.editor.observer.ColumnObserver" + name="Column Observer"> + </observer> </extension> <extension point="de.bmotionstudio.gef.editor.schedulerEvent"> @@ -349,6 +374,12 @@ <control id="de.bmotionstudio.gef.editor.connection"> </control> + <control + id="de.bmotionstudio.gef.editor.tablecell"> + </control> + <control + id="de.bmotionstudio.gef.editor.table"> + </control> </observer> <observer id="de.bmotionstudio.gef.editor.observer.SwitchCoordinates"> @@ -379,6 +410,9 @@ <control id="de.bmotionstudio.gef.editor.ellipse"> </control> + <control + id="de.bmotionstudio.gef.editor.table"> + </control> </observer> <observer id="de.bmotionstudio.gef.editor.observer.SimpleValueDisplay"> @@ -394,6 +428,9 @@ <control id="de.bmotionstudio.gef.editor.button"> </control> + <control + id="de.bmotionstudio.gef.editor.tablecell"> + </control> </observer> <observer id="de.bmotionstudio.gef.editor.observer.SetAttribute"> @@ -427,6 +464,12 @@ <control id="de.bmotionstudio.gef.editor.textfield"> </control> + <control + id="de.bmotionstudio.gef.editor.tablecell"> + </control> + <control + id="de.bmotionstudio.gef.editor.table"> + </control> </observer> <observer id="de.bmotionstudio.gef.editor.observer.SwitchChildCoordinates"> @@ -469,6 +512,12 @@ <control id="de.bmotionstudio.gef.editor.textfield"> </control> + <control + id="de.bmotionstudio.gef.editor.tablecell"> + </control> + <control + id="de.bmotionstudio.gef.editor.table"> + </control> </observer> <observer id="de.bmotionstudio.gef.editor.observer.SwitchImage"> @@ -485,6 +534,12 @@ id="de.bmotionstudio.gef.editor.ellipse"> </control> </observer> + <observer + id="de.bmotionstudio.gef.editor.observer.ColumnObserver"> + <control + id="de.bmotionstudio.gef.editor.tablecolumn"> + </control> + </observer> </include> </extension> </plugin> diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AppContextMenuProvider.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AppContextMenuProvider.java index 68d5c225496232e58686bf258dc583d44f00198a..221e61ab8575c5fd656f01a173c4c8bf4c58ff7b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AppContextMenuProvider.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AppContextMenuProvider.java @@ -174,7 +174,9 @@ public class AppContextMenuProvider extends ContextMenuProvider { String langID = configurationElement .getAttribute("language"); - if (langID.equals(control.getVisualization().getLanguage())) { + if (langID != null + && langID.equals(control.getVisualization() + .getLanguage())) { for (IConfigurationElement cObserver : configurationElement .getChildren("observer")) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AttributeConstants.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AttributeConstants.java index 30a8655e4f2ad8f757cd253baa3778b936534a4a..56ddf9afb27f53172c11eb238f659cb74684dda4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AttributeConstants.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/AttributeConstants.java @@ -16,6 +16,9 @@ public final class AttributeConstants { public static final String ATTRIBUTE_ID = "de.bmotionstudio.gef.editor.attribute.BAttributeID"; public static final String ATTRIBUTE_VISIBLE = "de.bmotionstudio.gef.editor.attribute.BAttributeVisible"; + public static final String ATTRIBUTE_COLUMNS = "de.bmotionstudio.gef.editor.attribute.BAttributeColumns"; + public static final String ATTRIBUTE_ROWS = "de.bmotionstudio.gef.editor.attribute.BAttributeRows"; + public static final String ATTRIBUTE_BACKGROUND_IMAGE = "de.bmotionstudio.gef.editor.attribute.BAttributeImage"; public static final String ATTRIBUTE_BACKGROUND_COLOR = "de.bmotionstudio.gef.editor.attribute.BAttributeBackgroundColor"; public static final String ATTRIBUTE_FOREGROUND_COLOR = "de.bmotionstudio.gef.editor.attribute.BAttributeForegroundColor"; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeColumns.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeColumns.java new file mode 100644 index 0000000000000000000000000000000000000000..12a636d196f8838fb2daf5c2561d8c3aa829aae2 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeColumns.java @@ -0,0 +1,42 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.attribute; + +import org.eclipse.ui.views.properties.PropertyDescriptor; + +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.property.IntegerPropertyDescriptor; + +public class BAttributeColumns extends AbstractAttribute { + + public BAttributeColumns(Object value) { + super(value); + } + + public PropertyDescriptor preparePropertyDescriptor() { + IntegerPropertyDescriptor descriptor = new IntegerPropertyDescriptor( + getID(), getName()); + return descriptor; + } + + @Override + public String validateValue(Object value, BControl control) { + if (!(String.valueOf(value)).trim().matches("\\d*")) { + return "Value must be a number"; + } + if ((String.valueOf(value)).trim().length() == 0) { + return "Value must not be empty string"; + } + return null; + } + + @Override + public String getName() { + return "Columns"; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeCoordinates.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeCoordinates.java index e251e8320a94782e62777ac6740322abe0c12d3e..2aeb359d027bd32783119b814a50786e7f8c476b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeCoordinates.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeCoordinates.java @@ -27,9 +27,12 @@ public class BAttributeCoordinates extends AbstractAttribute { Point point = (Point) element; StringBuffer buf = new StringBuffer(); buf.append("["); - buf.append(point.x); - buf.append(", "); - buf.append(point.y); + if (point.x >= 0) + buf.append(point.x); + if (point.y >= 0) { + buf.append(", "); + buf.append(point.y); + } buf.append("]"); return buf.toString(); } @@ -39,11 +42,22 @@ public class BAttributeCoordinates extends AbstractAttribute { @Override public Object getEditableValue() { - int x = Integer.valueOf(getChildren() - .get(AttributeConstants.ATTRIBUTE_X).getValue().toString()); - int y = Integer.valueOf(getChildren() - .get(AttributeConstants.ATTRIBUTE_Y).getValue().toString()); + + AbstractAttribute atrX = getChildren().get( + AttributeConstants.ATTRIBUTE_X); + AbstractAttribute atrY = getChildren().get( + AttributeConstants.ATTRIBUTE_Y); + + int x = -1; + int y = -1; + + if (atrX != null) + x = Integer.valueOf(atrX.getValue().toString()); + if (atrY != null) + y = Integer.valueOf(atrY.getValue().toString()); + return new Point(x, y); + } @Override diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeRows.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeRows.java new file mode 100644 index 0000000000000000000000000000000000000000..b3df0f422b0fab661a49ac893d785b2c3cda0a00 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeRows.java @@ -0,0 +1,42 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.attribute; + +import org.eclipse.ui.views.properties.PropertyDescriptor; + +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.property.IntegerPropertyDescriptor; + +public class BAttributeRows extends AbstractAttribute { + + public BAttributeRows(Object value) { + super(value); + } + + public PropertyDescriptor preparePropertyDescriptor() { + IntegerPropertyDescriptor descriptor = new IntegerPropertyDescriptor( + getID(), getName()); + return descriptor; + } + + @Override + public String validateValue(Object value, BControl control) { + if (!(String.valueOf(value)).trim().matches("\\d*")) { + return "Value must be a number"; + } + if ((String.valueOf(value)).trim().length() == 0) { + return "Value must not be empty string"; + } + return null; + } + + @Override + public String getName() { + return "Rows"; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeSize.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeSize.java index 5024a0e35ed468e15de2807dc4867e7b634c1d27..1920190f623c1673e57861794d8c816dc21a6796 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeSize.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/attribute/BAttributeSize.java @@ -27,9 +27,12 @@ public class BAttributeSize extends AbstractAttribute { Point point = (Point) element; StringBuffer buf = new StringBuffer(); buf.append("["); - buf.append(point.x); - buf.append(", "); - buf.append(point.y); + if (point.x >= 0) + buf.append(point.x); + if (point.y >= 0) { + buf.append(", "); + buf.append(point.y); + } buf.append("]"); return buf.toString(); } @@ -39,12 +42,22 @@ public class BAttributeSize extends AbstractAttribute { @Override public Object getEditableValue() { - int width = Integer.valueOf(getChildren() - .get(AttributeConstants.ATTRIBUTE_WIDTH).getValue().toString()); - int height = Integer - .valueOf(getChildren().get(AttributeConstants.ATTRIBUTE_HEIGHT) - .getValue().toString()); + + AbstractAttribute atrWidth = getChildren().get( + AttributeConstants.ATTRIBUTE_WIDTH); + AbstractAttribute atrHeight = getChildren().get( + AttributeConstants.ATTRIBUTE_HEIGHT); + + int width = -1; + int height = -1; + + if (atrWidth != null) + width = Integer.valueOf(atrWidth.getValue().toString()); + if (atrHeight != null) + height = Integer.valueOf(atrHeight.getValue().toString()); + return new Point(width, height); + } @Override diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/AddCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/AddCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..8310dc4371d939c53c076d428159a487841401b4 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/AddCommand.java @@ -0,0 +1,55 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.command; + +import de.bmotionstudio.gef.editor.model.BControl; + +public class AddCommand extends org.eclipse.gef.commands.Command { + + private BControl child; + private BControl parent; + private int index = -1; + + public AddCommand() { + super("Add Control"); + } + + public void execute() { + if (index < 0) + parent.addChild(child); + else + parent.addChild(child, index); + } + + public BControl getParent() { + return parent; + } + + public void redo() { + if (index < 0) + parent.addChild(child); + else + parent.addChild(child, index); + } + + public void setChild(BControl subpart) { + child = subpart; + } + + public void setIndex(int i) { + index = i; + } + + public void setParent(BControl newParent) { + parent = newParent; + } + + public void undo() { + parent.removeChild(child); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/ReorderPartCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/ReorderPartCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..4303b61d04b346d1cca0f5183310ab92c34f5eb8 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/ReorderPartCommand.java @@ -0,0 +1,36 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ +package de.bmotionstudio.gef.editor.command; + +import org.eclipse.gef.commands.Command; + +import de.bmotionstudio.gef.editor.model.BControl; + +public class ReorderPartCommand extends Command { + + private int oldIndex, newIndex; + private BControl child; + private BControl parent; + + public ReorderPartCommand(BControl child, BControl parent, int newIndex) { + super("Reorder Control"); + this.child = child; + this.parent = parent; + this.newIndex = newIndex; + } + + public void execute() { + oldIndex = parent.getChildrenArray().indexOf(child); + parent.removeChild(child); + parent.addChild(child, newIndex); + } + + public void undo() { + parent.removeChild(child); + parent.addChild(child, oldIndex); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/AppEditLayoutPolicy.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/AppEditLayoutPolicy.java index b379e570073f87abde193bdb8a720239ded78f9f..5fcc1fe24c6c002c48b4e7b7dd3dae3ccf268a1e 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/AppEditLayoutPolicy.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/AppEditLayoutPolicy.java @@ -23,8 +23,8 @@ import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.attribute.BAttributeHeight; import de.bmotionstudio.gef.editor.attribute.BAttributeWidth; import de.bmotionstudio.gef.editor.command.BControlChangeLayoutCommand; -import de.bmotionstudio.gef.editor.command.CreateCommand; import de.bmotionstudio.gef.editor.command.ChangeGuideCommand; +import de.bmotionstudio.gef.editor.command.CreateCommand; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.BMotionGuide; import de.bmotionstudio.gef.editor.part.AppAbstractEditPart; diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java new file mode 100644 index 0000000000000000000000000000000000000000..956819493c3a5554155a51cf5f936bd59fd19356 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioFlowEditPolicy.java @@ -0,0 +1,113 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ +package de.bmotionstudio.gef.editor.editpolicy; + +import org.eclipse.draw2d.FlowLayout; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.editpolicies.FlowLayoutEditPolicy; +import org.eclipse.gef.requests.CreateRequest; + +import de.bmotionstudio.gef.editor.command.AddCommand; +import de.bmotionstudio.gef.editor.command.ReorderPartCommand; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BTable; +import de.bmotionstudio.gef.editor.model.BTableCell; +import de.bmotionstudio.gef.editor.model.BTableColumn; + +public class BMotionStudioFlowEditPolicy extends FlowLayoutEditPolicy { + + @Override + protected Command createAddCommand(EditPart child, EditPart after) { + + BControl childModel = (BControl) child.getModel(); + BControl parentModel = (BControl) getHost().getModel(); + if ((childModel instanceof BTableColumn && parentModel instanceof BTable) + || (childModel instanceof BTableCell + && parentModel instanceof BTableColumn && childModel + .getParent().equals(parentModel))) { + AddCommand command = new AddCommand(); + command.setChild(childModel); + command.setParent(parentModel); + int index = getHost().getChildren().indexOf(after); + command.setIndex(index); + return command; + } + return null; + } + + /** + * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart) + */ + protected EditPolicy createChildEditPolicy(EditPart child) { + BMotionStudioResizableEditPolicy policy = new BMotionStudioResizableEditPolicy(); + policy.setResizeDirections(PositionConstants.EAST + | PositionConstants.WEST); + return policy; + } + + @Override + protected Command createMoveChildCommand(EditPart child, EditPart after) { + + + BControl childModel = (BControl) child.getModel(); + BControl parentModel = (BControl) getHost().getModel(); + + if ((childModel instanceof BTableColumn && parentModel instanceof BTable) + || (childModel instanceof BTableCell && parentModel instanceof BTableColumn)) { + int oldIndex = getHost().getChildren().indexOf(child); + int newIndex = getHost().getChildren().indexOf(after); + if (newIndex > oldIndex) + newIndex--; + ReorderPartCommand command = new ReorderPartCommand(childModel, + parentModel, newIndex); + return command; + } + + return null; + + } + + @Override + protected Command getCreateCommand(CreateRequest request) { + // CreateCommand command = new CreateCommand( + // (BControl) request.getNewObject(), (BControl) getHost() + // .getModel()); + // EditPart after = getInsertionReference(request); + // command.setLayout(new Rectangle(0, 0, 100, 25)); + // int index = getHost().getChildren().indexOf(after); + // command.setIndex(index); + // return command; + return null; + } + + @Override + protected boolean isHorizontal() { + IFigure figure = getLayoutContainer(); + if (figure.getLayoutManager() instanceof ToolbarLayout) { + return ((ToolbarLayout) figure.getLayoutManager()).isHorizontal(); + } else if (figure.getLayoutManager() instanceof FlowLayout) { + return ((FlowLayout) figure.getLayoutManager()).isHorizontal(); + } + return false; + } + + @Override + public void showLayoutTargetFeedback(Request request) { + if (request instanceof CreateRequest) { + Object newObject = ((CreateRequest) request).getNewObject(); + if (!(newObject instanceof BTableColumn || newObject instanceof BTableCell)) + return; + } + super.showLayoutTargetFeedback(request); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioResizableEditPolicy.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioResizableEditPolicy.java new file mode 100644 index 0000000000000000000000000000000000000000..cbe96daaf417a66b0d166d8d4fa292a28c853097 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/editpolicy/BMotionStudioResizableEditPolicy.java @@ -0,0 +1,83 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ +package de.bmotionstudio.gef.editor.editpolicy; + +import java.util.Iterator; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.LayerConstants; +import org.eclipse.gef.editpolicies.ResizableEditPolicy; + +public class BMotionStudioResizableEditPolicy extends ResizableEditPolicy { + + /** + * Creates the figure used for feedback. + * + * @return the new feedback figure + */ + protected IFigure createDragSourceFeedbackFigure() { + IFigure figure = createFigure((GraphicalEditPart) getHost(), null); + figure.setBounds(getInitialFeedbackBounds()); + addFeedback(figure); + return figure; + } + + protected IFigure createFigure(GraphicalEditPart part, IFigure parent) { + IFigure child = getCustomFeedbackFigure(part.getModel()); + + if (parent != null) + parent.add(child); + + Rectangle childBounds = part.getFigure().getBounds().getCopy(); + + IFigure walker = part.getFigure().getParent(); + + while (walker != ((GraphicalEditPart) part.getParent()).getFigure()) { + walker.translateToParent(childBounds); + walker = walker.getParent(); + } + + child.setBounds(childBounds); + + Iterator<?> i = part.getChildren().iterator(); + + while (i.hasNext()) + createFigure((GraphicalEditPart) i.next(), child); + + return child; + } + + protected IFigure getCustomFeedbackFigure(Object modelPart) { + IFigure figure; + figure = new RectangleFigure(); + ((RectangleFigure) figure).setXOR(true); + ((RectangleFigure) figure).setFill(true); + figure.setBackgroundColor(ColorConstants.blue); + figure.setForegroundColor(ColorConstants.white); + return figure; + } + + /** + * Returns the layer used for displaying feedback. + * + * @return the feedback layer + */ + protected IFigure getFeedbackLayer() { + return getLayer(LayerConstants.SCALED_FEEDBACK_LAYER); + } + + /** + * @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#getInitialFeedbackBounds() + */ + protected Rectangle getInitialFeedbackBounds() { + return getHostFigure().getBounds(); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/AbstractTableFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/AbstractTableFigure.java new file mode 100644 index 0000000000000000000000000000000000000000..2a3cad0bf8089fb5e23c2399bdc25dfcd6cc4d67 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/AbstractTableFigure.java @@ -0,0 +1,29 @@ +package de.bmotionstudio.gef.editor.figure; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +public class AbstractTableFigure extends AbstractBMotionFigure { + + private Color foregroundColor; + + @Override + public Color getForegroundColor() { + return foregroundColor; + } + + public void setForegroundColor(RGB rgb) { + if (foregroundColor != null) + foregroundColor.dispose(); + this.foregroundColor = new Color(Display.getDefault(), rgb); + repaint(); + } + + @Override + public void deactivateFigure() { + if (foregroundColor != null) + foregroundColor.dispose(); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableCellFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableCellFigure.java new file mode 100644 index 0000000000000000000000000000000000000000..09fa6fa84acfab68cb940adbfe6c51657d82c5dc --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableCellFigure.java @@ -0,0 +1,74 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.figure; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +public class TableCellFigure extends AbstractTableFigure { + + private String text; + private Color backgroundColor; + private Color textColor; + + public TableCellFigure() { + setOpaque(true); + } + + @Override + protected void paintBorder(Graphics g) { + Rectangle r = getClientArea(); + g.setBackgroundColor(backgroundColor); + g.fillRectangle(r.x, r.y, r.x + r.width, r.y + r.height); + g.setForegroundColor(textColor); + g.drawText(text, r.x + 3, r.y + 3); + Color foregroundColor = getForegroundColor(); + if (foregroundColor != null) + g.setForegroundColor(foregroundColor); + g.drawLine(r.x, r.y, r.x + r.width, r.y); + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + repaint(); + } + + public void setBackgroundColor(RGB rgb) { + if (backgroundColor != null) + backgroundColor.dispose(); + backgroundColor = new Color(Display.getDefault(), rgb); + repaint(); + } + + public void setTextColor(RGB rgb) { + if (textColor != null) + textColor.dispose(); + textColor = new Color(Display.getDefault(), rgb); + repaint(); + } + + @Override + public void deactivateFigure() { + if (backgroundColor != null) + backgroundColor.dispose(); + if (textColor != null) + textColor.dispose(); + super.deactivateFigure(); + } + + public void setFont(String string) { + // TODO Auto-generated method stub + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableColumnFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableColumnFigure.java new file mode 100644 index 0000000000000000000000000000000000000000..e036e5d6863b911b900ce07012635ed3b6ff0715 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableColumnFigure.java @@ -0,0 +1,28 @@ +package de.bmotionstudio.gef.editor.figure; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Color; + +public class TableColumnFigure extends AbstractTableFigure { + + public TableColumnFigure() { + ToolbarLayout toolbarLayout = new ToolbarLayout(); + setLayoutManager(toolbarLayout); + setOpaque(true); + } + + @Override + protected void paintBorder(Graphics g) { + Rectangle r = getClientArea(); + Color foregroundColor = getForegroundColor(); + if (foregroundColor != null) + g.setForegroundColor(foregroundColor); + g.drawLine(r.x, r.y, r.x + r.width, r.y); + g.drawLine(r.x, r.y, r.x, r.y + r.height - 1); + g.drawLine(r.x, r.y + r.height - 1, r.x + r.width, r.y + r.height - 1); + super.paintBorder(g); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableFigure.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableFigure.java new file mode 100644 index 0000000000000000000000000000000000000000..fb322781139451c5f90a087cb2513e1eabdfc9bf --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/figure/TableFigure.java @@ -0,0 +1,32 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.figure; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.ToolbarLayout; +import org.eclipse.draw2d.geometry.Rectangle; + +public class TableFigure extends AbstractTableFigure { + + public TableFigure() { + ToolbarLayout toolbarLayout = new ToolbarLayout(); + toolbarLayout.setHorizontal(true); + toolbarLayout.setStretchMinorAxis(false); + setLayoutManager(toolbarLayout); + setOpaque(true); + } + + @Override + protected void paintBorder(Graphics g) { + Rectangle r = getClientArea(); + g.setForegroundColor(getForegroundColor()); + g.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height + - 1); + super.paintBorder(g); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/BControlPropertySource.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/BControlPropertySource.java index 6d27311b8678f8f2221bfa912dbdaa9f2743f383..0dffa83af3bf68c5c5a3964c8eb79464fb1266e8 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/BControlPropertySource.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/BControlPropertySource.java @@ -30,27 +30,32 @@ public class BControlPropertySource extends AbstractAttribute { for (AbstractAttribute atr : control.getAttributes().values()) { - atr.setControl(control); + if (atr.show()) { - String group = atr.getGroup(); + atr.setControl(control); - if (group != null) { + String group = atr.getGroup(); - // If group is root node --> add to root - if (group.equals(ROOT)) { - addChild(atr); - } else { - AbstractAttribute groupAtr = control.getAttribute(group); - if (groupAtr != null) { - groupAtr.addChild(atr); + if (group != null) { + + // If group is root node --> add to root + if (group.equals(ROOT)) { + addChild(atr); } else { - miscAttribute.addChild(atr); + AbstractAttribute groupAtr = control + .getAttribute(group); + if (groupAtr != null) { + groupAtr.addChild(atr); + } else { + miscAttribute.addChild(atr); + } } + + } else { + // No group, add to misc attribute node + miscAttribute.addChild(atr); } - } else { - // No group, add to misc attribute node - miscAttribute.addChild(atr); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java index 5b69d5695fd63a38b6925aa1825dfb410b7a1386..0af0557d5e5d946e0e4a40d39b66a0dbc0f764d6 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java @@ -16,7 +16,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.draw2d.geometry.Dimension; @@ -29,7 +28,6 @@ import de.bmotionstudio.gef.editor.Animation; import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.BMotionEditorPlugin; import de.bmotionstudio.gef.editor.BMotionStudioImage; -import de.bmotionstudio.gef.editor.IBControlService; import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; import de.bmotionstudio.gef.editor.attribute.BAttributeCoordinates; import de.bmotionstudio.gef.editor.attribute.BAttributeCustom; @@ -369,6 +367,16 @@ public abstract class BControl implements IAdaptable, Cloneable { getListeners().firePropertyChange(PROPERTY_ADD, index, child); } + public void removeAllChildren() { + getChildrenArray().clear(); + getListeners().firePropertyChange(PROPERTY_REMOVE, null, null); + } + + public boolean removeChild(int index) { + BControl control = children.get(index); + return removeChild(control); + } + public boolean removeChild(BControl child) { boolean b = children.remove(child); if (b) @@ -587,50 +595,38 @@ public abstract class BControl implements IAdaptable, Cloneable { BControl clonedControl = (BControl) super.clone(); - IConfigurationElement configElement = BMotionEditorPlugin - .getControlServices().get(getType()); - if (configElement != null) { - - try { - - IBControlService service = (IBControlService) configElement - .createExecutableExtension("service"); - clonedControl = service.createControl(visualization); - - clonedControl.setParent(getParent()); - - String newID = clonedControl.getID(); - - Map<String, AbstractAttribute> newProperties = new HashMap<String, AbstractAttribute>(); - for (Entry<String, AbstractAttribute> e : getAttributes() - .entrySet()) { - AbstractAttribute idAtr = e.getValue().clone(); - newProperties.put(e.getKey(), idAtr); - } + clonedControl.setParent(getParent()); - clonedControl.setAttributes(newProperties); - clonedControl.setAttributeValue( - AttributeConstants.ATTRIBUTE_ID, newID); + String newID = clonedControl.getID(); - Iterator<BControl> it = getChildrenArray().iterator(); - while (it.hasNext()) { - clonedControl.addChild(((BControl) it.next()).clone()); - } + Map<String, AbstractAttribute> newProperties = new HashMap<String, AbstractAttribute>(); + for (Entry<String, AbstractAttribute> e : getAttributes().entrySet()) { + AbstractAttribute idAtr = e.getValue().clone(); + newProperties.put(e.getKey(), idAtr); + } - for (Observer observer : observers.values()) { - clonedControl.addObserver(observer.clone()); - } + clonedControl.setAttributes(newProperties); + clonedControl.setAttributeValue(AttributeConstants.ATTRIBUTE_ID, newID); - for (Map.Entry<String, SchedulerEvent> e : events.entrySet()) { - clonedControl.addEvent(e.getKey(), e.getValue().clone()); - } + clonedControl.setChildrenArray(new BControlList()); + Iterator<BControl> it = getChildrenArray().iterator(); + while (it.hasNext()) { + clonedControl.addChild(((BControl) it.next()).clone()); + } - } catch (CoreException e) { - e.printStackTrace(); - } + clonedControl.setObserverMap(new HashMap<String, Observer>()); + for (Observer observer : observers.values()) { + clonedControl.addObserver(observer.clone()); + } + clonedControl.setEventMap(new HashMap<String, SchedulerEvent>()); + for (Map.Entry<String, SchedulerEvent> e : events.entrySet()) { + clonedControl.addEvent(e.getKey(), e.getValue().clone()); } + clonedControl.listeners = new PropertyChangeSupport(clonedControl); + clonedControl.observerListener = new ArrayList<IObserverListener>(); + return clonedControl; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java new file mode 100644 index 0000000000000000000000000000000000000000..dbb450c311d872077d1542c36331160fd9fd099a --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTable.java @@ -0,0 +1,64 @@ +package de.bmotionstudio.gef.editor.model; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.geometry.Rectangle; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.attribute.BAttributeColumns; +import de.bmotionstudio.gef.editor.attribute.BAttributeForegroundColor; +import de.bmotionstudio.gef.editor.attribute.BAttributeRows; +import de.bmotionstudio.gef.editor.command.CreateCommand; + +public class BTable extends BControl { + + public static transient String TYPE = "de.bmotionstudio.gef.editor.table"; + + public BTable(Visualization visualization) { + + super(visualization); + + int numberOfColumns = 2; + int numberOfRows = 2; + + CreateCommand cmd; + for (int i = 0; i < numberOfColumns; i++) { + BTableColumn bTableColumn = new BTableColumn(visualization); + cmd = new CreateCommand(bTableColumn, this); + cmd.setLayout(new Rectangle(0, 0, 50, 25)); + cmd.execute(); + for (int z = 0; z < numberOfRows; z++) { + cmd = new CreateCommand(new BTableCell(getVisualization()), + bTableColumn); + cmd.setLayout(new Rectangle(0, 0, 50, 20)); + cmd.execute(); + } + } + + } + + @Override + public boolean canHaveChildren() { + return true; + } + + @Override + protected void initAttributes() { + initAttribute(new BAttributeForegroundColor( + ColorConstants.black.getRGB())); + initAttribute(new BAttributeColumns(2)); + initAttribute(new BAttributeRows(2)); + getAttributes().get(AttributeConstants.ATTRIBUTE_SIZE).setShow(false); + getAttributes().get(AttributeConstants.ATTRIBUTE_COORDINATES).setShow( + false); + getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable( + false); + getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH).setEditable( + false); + } + + @Override + public String getType() { + return TYPE; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java new file mode 100644 index 0000000000000000000000000000000000000000..587e2cdf6281cc14a709f88dd0bd30aa713dae02 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableCell.java @@ -0,0 +1,47 @@ +package de.bmotionstudio.gef.editor.model; + +import org.eclipse.draw2d.ColorConstants; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.attribute.BAttributeBackgroundColor; +import de.bmotionstudio.gef.editor.attribute.BAttributeForegroundColor; +import de.bmotionstudio.gef.editor.attribute.BAttributeText; +import de.bmotionstudio.gef.editor.attribute.BAttributeTextColor; + +public class BTableCell extends BControl { + + public static transient String TYPE = "de.bmotionstudio.gef.editor.tablecell"; + + public BTableCell(Visualization visualization) { + super(visualization); + } + + @Override + protected void initAttributes() { + + initAttribute(new BAttributeBackgroundColor( + ColorConstants.white.getRGB())); + BAttributeForegroundColor bAttributeForegroundColor = new BAttributeForegroundColor( + ColorConstants.black.getRGB()); + bAttributeForegroundColor.setShow(false); + initAttribute(bAttributeForegroundColor); + initAttribute(new BAttributeTextColor(ColorConstants.black.getRGB())); + initAttribute(new BAttributeText("")); + setAttributeValue(AttributeConstants.ATTRIBUTE_HEIGHT, 20); + setAttributeValue(AttributeConstants.ATTRIBUTE_WIDTH, 50); + getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable( + false); + getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH).setEditable( + false); + getAttributes().get(AttributeConstants.ATTRIBUTE_SIZE).setShow(false); + getAttributes().get(AttributeConstants.ATTRIBUTE_COORDINATES).setShow( + false); + + } + + @Override + public String getType() { + return TYPE; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableColumn.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableColumn.java new file mode 100644 index 0000000000000000000000000000000000000000..fc64b9ed8123ebd1dfd0499dafd92857e872eb06 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BTableColumn.java @@ -0,0 +1,47 @@ +package de.bmotionstudio.gef.editor.model; + +import org.eclipse.draw2d.ColorConstants; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.attribute.BAttributeForegroundColor; + +public class BTableColumn extends BControl { + + public static transient String TYPE = "de.bmotionstudio.gef.editor.tablecolumn"; + + public BTableColumn(Visualization visualization) { + super(visualization); + } + + @Override + protected void initAttributes() { + + // initAttribute(new BAttributeBackgroundColor( + // ColorConstants.white.getRGB())); + BAttributeForegroundColor bAttributeForegroundColor = new BAttributeForegroundColor( + ColorConstants.black.getRGB()); + bAttributeForegroundColor.setShow(false); + initAttribute(bAttributeForegroundColor); + // initAttribute(new + // BAttributeTextColor(ColorConstants.black.getRGB())); + getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable( + false); + getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT).setShow(false); + getAttributes().get(AttributeConstants.ATTRIBUTE_COORDINATES).setShow( + false); + + // Background Color + // Font + // Foreground Color + + // Width + // Height (not editable) --> determined by number of cells + + } + + @Override + public String getType() { + return TYPE; + } + +} \ No newline at end of file diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java new file mode 100644 index 0000000000000000000000000000000000000000..5b02178d00847f836dd6c3ea5b56c99c6d8054fb --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/ColumnObserver.java @@ -0,0 +1,73 @@ +package de.bmotionstudio.gef.editor.observer; + +import de.bmotionstudio.gef.editor.Animation; +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.observer.wizard.WizardColumnObserver; +import de.bmotionstudio.gef.editor.util.BMSUtil; + +public class ColumnObserver extends Observer { + + private String expression; + private String predicate; + + @Override + public void check(Animation animation, BControl control) { + + // First evaluate predicate (predicate field) + String bolValue = "true"; + if (predicate != null && predicate.length() > 0) { + bolValue = BMSUtil.parsePredicate(predicate, control, animation); + } + + if (Boolean.valueOf(bolValue)) { + + String fEval = BMSUtil.parseExpression(expression, control, + animation); + fEval = fEval.replace("}", "").replace("{", ""); + String[] splitArray = fEval.split(","); + + AbstractAttribute attributeRows = control.getParent().getAttribute( + AttributeConstants.ATTRIBUTE_ROWS); + + Integer defaultRows = Integer.valueOf(attributeRows + .getInitValue().toString()); + + control.getParent().setAttributeValue( + AttributeConstants.ATTRIBUTE_ROWS, + defaultRows + splitArray.length, true, false); + + for (int i = defaultRows; i < splitArray.length + defaultRows; i++) { + control.getChildrenArray() + .get(i) + .setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT, + splitArray[i - defaultRows]); + } + + } + + } + + public void setExpression(String expression) { + this.expression = expression; + } + + public String getExpression() { + return expression; + } + + public String getPredicate() { + return predicate; + } + + public void setPredicate(String predicate) { + this.predicate = predicate; + } + + @Override + public ObserverWizard getWizard(BControl control) { + return new WizardColumnObserver(control, this); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java new file mode 100644 index 0000000000000000000000000000000000000000..04c3a5cd6d6850073f3666b70767eb971400eba6 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/wizard/WizardColumnObserver.java @@ -0,0 +1,125 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.observer.wizard; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.observer.ColumnObserver; +import de.bmotionstudio.gef.editor.observer.Observer; +import de.bmotionstudio.gef.editor.observer.ObserverWizard; + +public class WizardColumnObserver extends ObserverWizard { + + private class ColumnObserverPage extends WizardPage { + + private Text txtExpression; + private Text txtPredicate; + + public Text getTxtExpression() { + return txtExpression; + } + + protected ColumnObserverPage(final String pageName) { + super(pageName); + } + + public void createControl(final Composite parent) { + + final DataBindingContext dbc = new DataBindingContext(); + + Composite container = new Composite(parent, SWT.NONE); + + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + container.setLayout(new GridLayout(2, false)); + + Label lb = new Label(container, SWT.NONE); + lb.setText("Predicate:"); + + txtPredicate = new Text(container, SWT.BORDER); + txtPredicate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + txtPredicate.setFont(new Font(Display.getDefault(), new FontData( + "Arial", 10, SWT.NONE))); + + lb = new Label(container, SWT.NONE); + lb.setText("Expression:"); + lb.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + + txtExpression = new Text(container, SWT.BORDER | SWT.MULTI + | SWT.WRAP); + txtExpression.setLayoutData(new GridData(GridData.FILL_BOTH)); + + initBindings(dbc); + + setControl(container); + + } + + private void initBindings(DataBindingContext dbc) { + + dbc.bindValue(SWTObservables.observeText(txtPredicate, SWT.Modify), + BeansObservables.observeValue( + (ColumnObserver) getObserver(), "predicate")); + + dbc.bindValue( + SWTObservables.observeText(txtExpression, SWT.Modify), + BeansObservables.observeValue( + (ColumnObserver) getObserver(), "expression")); + + } + + } + + public WizardColumnObserver(BControl bcontrol, + Observer bobserver) { + super(bcontrol, bobserver); + addPage(new ColumnObserverPage("ColumnObserverPage")); + } + + @Override + protected Boolean prepareToFinish() { + + ColumnObserverPage page = (ColumnObserverPage) getPage("ColumnObserverPage"); + + String errorStr = ""; + + if (page.getTxtExpression().getText().length() == 0) + errorStr += "Please enter an expression.\n"; + + if (page.getErrorMessage() != null) + errorStr += "Please check the syntax/parser error.\n"; + + if (errorStr.length() > 0) { + MessageDialog.openError(Display.getDefault().getActiveShell(), + "An Error occured", errorStr); + return false; + } + + return true; + + } + + @Override + public Point getSize() { + return new Point(600, 500); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java index 91e73bff97e9777486da75c13b95de080b142937..91a5bc5ac8126ea58d40898cac1c77e759e5f432 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/AppAbstractEditPart.java @@ -195,12 +195,12 @@ public abstract class AppAbstractEditPart extends AbstractGraphicalEditPart } else if (Arrays.asList(layoutAttributes).contains(propName)) { // Layout attribute if (isRunning()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { + // Display.getDefault().asyncExec(new Runnable() { + // @Override + // public void run() { refreshEditLayout(figure, model); - } - }); + // } + // }); } else { refreshEditLayout(figure, model); } @@ -208,12 +208,12 @@ public abstract class AppAbstractEditPart extends AbstractGraphicalEditPart // Custom attribute if (isRunning()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { + // Display.getDefault().asyncExec(new Runnable() { + // @Override + // public void run() { refreshEditFigure(figure, model, evt); - } - }); + // } + // }); } else { refreshEditFigure(figure, model, evt); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java new file mode 100644 index 0000000000000000000000000000000000000000..dba8ecf10865c8195fb1d48a36b55ac813c4d0e2 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableCellPart.java @@ -0,0 +1,77 @@ +package de.bmotionstudio.gef.editor.part; + +import java.beans.PropertyChangeEvent; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.swt.graphics.RGB; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.edit.TextCellEditorLocator; +import de.bmotionstudio.gef.editor.edit.TextEditManager; +import de.bmotionstudio.gef.editor.editpolicy.CustomDirectEditPolicy; +import de.bmotionstudio.gef.editor.editpolicy.RenamePolicy; +import de.bmotionstudio.gef.editor.figure.TableCellFigure; +import de.bmotionstudio.gef.editor.model.BControl; + +public class BTableCellPart extends AppAbstractEditPart { + + @Override + protected IFigure createEditFigure() { + return new TableCellFigure(); + } + + @Override + protected void prepareEditPolicies() { + installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, + new CustomDirectEditPolicy()); + installEditPolicy(EditPolicy.NODE_ROLE, new RenamePolicy()); + } + + @Override + protected void prepareRunPolicies() { + } + + @Override + public void refreshEditFigure(IFigure figure, BControl model, + PropertyChangeEvent evt) { + + Object value = evt.getNewValue(); + String aID = evt.getPropertyName(); + + if (aID.equals(AttributeConstants.ATTRIBUTE_TEXT)) { + ((TableCellFigure) figure).setText(value.toString()); + } + + if (aID.equals(AttributeConstants.ATTRIBUTE_BACKGROUND_COLOR)) { + ((TableCellFigure) figure).setBackgroundColor((RGB) value); + } + + if (aID.equals(AttributeConstants.ATTRIBUTE_TEXT_COLOR)) { + ((TableCellFigure) figure).setTextColor((RGB) value); + } + + if (aID.equals(AttributeConstants.ATTRIBUTE_FOREGROUND_COLOR)) { + ((TableCellFigure) figure).setForegroundColor((RGB) value); + } + + if (aID.equals(AttributeConstants.ATTRIBUTE_FONT)) + ((TableCellFigure) figure).setFont((value.toString())); + + } + + private void performDirectEdit() { + new TextEditManager(this, new TextCellEditorLocator( + (IFigure) getFigure())).show(); + } + + @Override + public void performRequest(Request request) { + super.performRequest(request); + if (request.getType() == RequestConstants.REQ_DIRECT_EDIT) + performDirectEdit(); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java new file mode 100644 index 0000000000000000000000000000000000000000..49cfccce4221d7aea645ef752e40062d925e844c --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTableColumnPart.java @@ -0,0 +1,83 @@ +package de.bmotionstudio.gef.editor.part; + +import java.beans.PropertyChangeEvent; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.gef.EditPolicy; +import org.eclipse.swt.graphics.RGB; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.editpolicy.BMotionNodeEditPolicy; +import de.bmotionstudio.gef.editor.editpolicy.BMotionStudioFlowEditPolicy; +import de.bmotionstudio.gef.editor.figure.TableColumnFigure; +import de.bmotionstudio.gef.editor.model.BControl; + +public class BTableColumnPart extends AppAbstractEditPart { + + @Override + protected IFigure createEditFigure() { + return new TableColumnFigure(); + } + + @Override + protected void prepareEditPolicies() { + installEditPolicy(EditPolicy.LAYOUT_ROLE, + new BMotionStudioFlowEditPolicy()); + installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, + new BMotionNodeEditPolicy()); + } + + @Override + protected void prepareRunPolicies() { + } + + @Override + public void refreshEditFigure(IFigure figure, BControl model, + PropertyChangeEvent evt) { + + Object value = evt.getNewValue(); + String aID = evt.getPropertyName(); + + // if (aID.equals(AttributeConstants.ATTRIBUTE_BACKGROUND_COLOR)) { + // for (BControl cell : model.getChildrenArray()) + // cell.setAttributeValue( + // AttributeConstants.ATTRIBUTE_BACKGROUND_COLOR, value); + // } + // + if (aID.equals(AttributeConstants.ATTRIBUTE_FOREGROUND_COLOR)) { + ((TableColumnFigure) figure).setForegroundColor((RGB) value); + for (BControl cell : model.getChildrenArray()) + cell.setAttributeValue( + AttributeConstants.ATTRIBUTE_FOREGROUND_COLOR, value); + } + // + // if (aID.equals(AttributeConstants.ATTRIBUTE_TEXT_COLOR)) { + // for (BControl cell : model.getChildrenArray()) + // cell.setAttributeValue(AttributeConstants.ATTRIBUTE_TEXT_COLOR, + // value); + // } + // + // if (aID.equals(AttributeConstants.ATTRIBUTE_FONT)) { + // for (BControl cell : model.getChildrenArray()) + // cell.setAttributeValue(AttributeConstants.ATTRIBUTE_FONT, value); + // } + + } + + @Override + protected void refreshEditLayout(IFigure figure, BControl control) { + if (getParent() instanceof AppAbstractEditPart) { + AppAbstractEditPart tablePart = (AppAbstractEditPart) getParent(); + tablePart.refreshEditLayout(tablePart.getFigure(), + control.getParent()); + } + super.refreshEditLayout(figure, control); + } + + @Override + public List<BControl> getModelChildren() { + return ((BControl) getModel()).getChildrenArray(); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTablePart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTablePart.java new file mode 100644 index 0000000000000000000000000000000000000000..78d6bc0d12c7319ffd0c67d1dfdebe50b1fb0fa1 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BTablePart.java @@ -0,0 +1,151 @@ +package de.bmotionstudio.gef.editor.part; + +import java.beans.PropertyChangeEvent; +import java.util.List; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPolicy; +import org.eclipse.swt.graphics.RGB; + +import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.command.CreateCommand; +import de.bmotionstudio.gef.editor.editpolicy.AppDeletePolicy; +import de.bmotionstudio.gef.editor.editpolicy.BMotionNodeEditPolicy; +import de.bmotionstudio.gef.editor.editpolicy.BMotionStudioFlowEditPolicy; +import de.bmotionstudio.gef.editor.figure.TableFigure; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BTableCell; +import de.bmotionstudio.gef.editor.model.BTableColumn; + +public class BTablePart extends AppAbstractEditPart { + + @Override + protected IFigure createEditFigure() { + return new TableFigure(); + } + + @Override + protected void prepareEditPolicies() { + installEditPolicy(EditPolicy.LAYOUT_ROLE, + new BMotionStudioFlowEditPolicy()); + installEditPolicy(EditPolicy.COMPONENT_ROLE, new AppDeletePolicy()); + installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, + new BMotionNodeEditPolicy()); + } + + @Override + protected void prepareRunPolicies() { + } + + @Override + protected void refreshEditLayout(IFigure figure, BControl control) { + + int width = 0; + + int rows = Integer.valueOf(control.getAttributeValue( + AttributeConstants.ATTRIBUTE_ROWS).toString()); + + for (BControl column : control.getChildrenArray()) { + width = width + column.getLayout().width; + } + + // Set the correct size of the table + figure.getParent().setConstraint( + figure, + new Rectangle(control.getLocation().x, control.getLocation().y, + width + 1, (rows * 20) + 1)); + + } + + @Override + public void refreshEditFigure(IFigure figure, BControl model, + PropertyChangeEvent evt) { + + Object value = evt.getNewValue(); + Object oldValue = evt.getOldValue(); + String aID = evt.getPropertyName(); + + if (aID.equals(AttributeConstants.ATTRIBUTE_FOREGROUND_COLOR)) { + ((TableFigure) figure).setForegroundColor((RGB) value); + for (BControl child : model.getChildrenArray()) + child.setAttributeValue( + AttributeConstants.ATTRIBUTE_FOREGROUND_COLOR, value); + } + + if (aID.equals(AttributeConstants.ATTRIBUTE_COLUMNS)) { + + if (oldValue == null || value.equals(oldValue)) + return; + + // Create columns + Integer numberOfColumns = Integer.valueOf(value.toString()); + Integer numberOfCurrentColumns = Integer.valueOf(oldValue + .toString()); + + if (numberOfColumns < numberOfCurrentColumns) { + for (int i = numberOfCurrentColumns - 1; i >= numberOfColumns; i--) { + model.removeChild(i); + } + } + + for (int i = numberOfCurrentColumns; i < numberOfColumns; i++) { + BTableColumn bTableColumn = new BTableColumn( + model.getVisualization()); + CreateCommand cmd = new CreateCommand(bTableColumn, model); + cmd.setLayout(new Rectangle(0, 0, 50, 25)); + cmd.execute(); + Integer numberOfRows = Integer.valueOf(model.getAttributeValue( + AttributeConstants.ATTRIBUTE_ROWS).toString()); + refreshRows(bTableColumn, numberOfRows); + } + + refreshEditLayout(figure, model); + + } + + if (aID.equals(AttributeConstants.ATTRIBUTE_ROWS)) { + + if (oldValue == null || value.equals(oldValue)) + return; + + // Create rows + + Integer numberOfRows = Integer.valueOf(value.toString()); + + List<BControl> columnChildren = model.getChildrenArray(); + for (BControl column : columnChildren) { + refreshRows(column, numberOfRows); + } + + refreshEditLayout(figure, model); + + } + + } + + private void refreshRows(BControl column, int numberOfRows) { + + Integer numberOfCurrentRows = column.getChildrenArray().size(); + + if (numberOfRows < numberOfCurrentRows) { + for (int i = numberOfCurrentRows - 1; i >= numberOfRows; i--) { + column.removeChild(i); + } + } + + for (int i = numberOfCurrentRows; i < numberOfRows; i++) { + CreateCommand cmd = new CreateCommand(new BTableCell( + column.getVisualization()), column); + cmd.setLayout(new Rectangle(0, 0, 50, 20)); + cmd.execute(); + } + + } + + @Override + public List<BControl> getModelChildren() { + return ((BControl) getModel()).getChildrenArray(); + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java new file mode 100644 index 0000000000000000000000000000000000000000..36bd5c52047bc58d165b7e74a0290abb8fac9b9a --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableCellService.java @@ -0,0 +1,29 @@ +package de.bmotionstudio.gef.editor.service; + +import de.bmotionstudio.gef.editor.AbstractBControlService; +import de.bmotionstudio.gef.editor.IBControlService; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BTableCell; +import de.bmotionstudio.gef.editor.model.Visualization; +import de.bmotionstudio.gef.editor.part.AppAbstractEditPart; +import de.bmotionstudio.gef.editor.part.BTableCellPart; + +public class BTableCellService extends AbstractBControlService implements + IBControlService { + + @Override + public BControl createControl(Visualization visualization) { + return new BTableCell(visualization); + } + + @Override + public AppAbstractEditPart createEditPart() { + return new BTableCellPart(); + } + + @Override + public boolean showInPalette() { + return false; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java new file mode 100644 index 0000000000000000000000000000000000000000..ea26c6326c5b225dd9ee8293d681bef037cba479 --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableColumnService.java @@ -0,0 +1,29 @@ +package de.bmotionstudio.gef.editor.service; + +import de.bmotionstudio.gef.editor.AbstractBControlService; +import de.bmotionstudio.gef.editor.IBControlService; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BTableColumn; +import de.bmotionstudio.gef.editor.model.Visualization; +import de.bmotionstudio.gef.editor.part.AppAbstractEditPart; +import de.bmotionstudio.gef.editor.part.BTableColumnPart; + +public class BTableColumnService extends AbstractBControlService implements + IBControlService { + + @Override + public BControl createControl(Visualization visualization) { + return new BTableColumn(visualization); + } + + @Override + public AppAbstractEditPart createEditPart() { + return new BTableColumnPart(); + } + + @Override + public boolean showInPalette() { + return false; + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java new file mode 100644 index 0000000000000000000000000000000000000000..da6182eb66ce3f9ab851be83e7a5da67531a01bd --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/service/BTableService.java @@ -0,0 +1,24 @@ +package de.bmotionstudio.gef.editor.service; + +import de.bmotionstudio.gef.editor.AbstractBControlService; +import de.bmotionstudio.gef.editor.IBControlService; +import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.BTable; +import de.bmotionstudio.gef.editor.model.Visualization; +import de.bmotionstudio.gef.editor.part.AppAbstractEditPart; +import de.bmotionstudio.gef.editor.part.BTablePart; + +public class BTableService extends AbstractBControlService implements + IBControlService { + + @Override + public BControl createControl(Visualization visualization) { + return new BTable(visualization); + } + + @Override + public AppAbstractEditPart createEditPart() { + return new BTablePart(); + } + +}