Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/workflow/editor/model/commands/ShapeCreateCommand.java')
-rw-r--r--plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/workflow/editor/model/commands/ShapeCreateCommand.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/workflow/editor/model/commands/ShapeCreateCommand.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/workflow/editor/model/commands/ShapeCreateCommand.java
new file mode 100644
index 00000000000..351e9a76993
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/workflow/editor/model/commands/ShapeCreateCommand.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2005 Donald G. Dunne and others.
+�* All rights reserved. This program and the accompanying materials
+�* are made available under the terms of the Eclipse Public License v1.0
+�* which accompanies this distribution, and is available at
+�* http://www.eclipse.org/legal/epl-v10.html
+�*
+�* Contributors:
+�*����Donald G. Dunne - initial API and implementation
+�*******************************************************************************/
+package org.eclipse.osee.ats.workflow.editor.model.commands;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.osee.ats.workflow.editor.model.Shape;
+import org.eclipse.osee.ats.workflow.editor.model.WorkflowDiagram;
+
+/**
+ * A command to add a Shape to a ShapeDiagram. The command can be undone or redone.
+ *
+ * @author Donald G. Dunne
+ */
+public class ShapeCreateCommand extends Command {
+
+ /** The new shape. */
+ private final Shape newShape;
+ /** ShapeDiagram to add to. */
+ private final WorkflowDiagram parent;
+ /** The bounds of the new Shape. */
+ private final Rectangle bounds;
+
+ /**
+ * Create a command that will add a new Shape to a WorkflowDiagram.
+ *
+ * @param newShape the new Shape that is to be added
+ * @param parent the WorkflowDiagram that will hold the new element
+ * @param bounds the bounds of the new shape; the size can be (-1, -1) if not known
+ * @throws IllegalArgumentException if any parameter is null, or the request does not provide a new Shape instance
+ */
+ public ShapeCreateCommand(Shape newShape, WorkflowDiagram parent, Rectangle bounds) {
+ this.newShape = newShape;
+ this.newShape.setWorkflowDiagram(parent);
+ this.parent = parent;
+ this.bounds = bounds;
+ setLabel("shape creation");
+ }
+
+ /**
+ * Can execute if all the necessary information has been provided.
+ *
+ * @see org.eclipse.gef.commands.Command#canExecute()
+ */
+ @Override
+ public boolean canExecute() {
+ boolean create = newShape != null && parent != null && bounds != null;
+ if (!create) return false;
+ if (parent.hasChild(newShape)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ newShape.setLocation(bounds.getLocation());
+ Dimension size = bounds.getSize();
+ if (size.width > 0 && size.height > 0) newShape.setSize(size);
+ redo();
+ }
+
+ @Override
+ public void redo() {
+ parent.addChild(newShape);
+ }
+
+ @Override
+ public void undo() {
+ parent.removeChild(newShape);
+ }
+
+} \ No newline at end of file

Back to the top