add test tools for bot tests
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/.classpath b/tests/org.eclipse.graphiti.testtool.sketch/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/.project b/tests/org.eclipse.graphiti.testtool.sketch/.project
new file mode 100644
index 0000000..4e2705a
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.graphiti.testtool.sketch</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.graphiti.testtool.sketch/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..25c6cc0
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Tue Apr 06 16:33:57 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/META-INF/MANIFEST.MF b/tests/org.eclipse.graphiti.testtool.sketch/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9fb9a8c
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/META-INF/MANIFEST.MF
@@ -0,0 +1,25 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.graphiti.sample.sketch;singleton:=true
+Bundle-Version: 0.7.0.qualifier
+Bundle-ClassPath: .
+Bundle-Activator: org.eclipse.graphiti.sample.sketch.SketchPlugin
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.emf.transaction,
+ org.eclipse.gef,
+ org.eclipse.graphiti,
+ org.eclipse.graphiti.ui,
+ org.eclipse.jdt.core,
+ org.eclipse.ui.views.properties.tabbed,
+ org.eclipse.graphiti.pattern;bundle-version="0.7.0",
+ org.eclipse.graphiti.examples.common;bundle-version="0.7.0"
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.graphiti.sample.sketch,
+ org.eclipse.graphiti.sample.sketch.features,
+ org.eclipse.graphiti.sample.sketch.features.bd,
+ org.eclipse.graphiti.sample.sketch.features.create,
+ org.eclipse.graphiti.sample.sketch.features.pool,
+ org.eclipse.graphiti.sample.sketch.features.style
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/about.html b/tests/org.eclipse.graphiti.testtool.sketch/about.html
new file mode 100644
index 0000000..c258ef5
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/build.properties b/tests/org.eclipse.graphiti.testtool.sketch/build.properties
new file mode 100644
index 0000000..f4b0c26
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/build.properties
@@ -0,0 +1,27 @@
+###############################################################################
+# <copyright>
+#
+# Copyright (c) 2005, 2010 SAP AG.
+# 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:
+# SAP AG - initial API, implementation and documentation
+#
+# </copyright>
+#
+###############################################################################
+
+bin.includes = .,\
+ META-INF/,\
+ plugin.properties,\
+ plugin.xml,\
+ about.html
+jars.compile.order = .
+source.. = src/
+output.. = bin/
+src.includes = src/,\
+ META-INF/,\
+ plugin.properties
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/plugin.properties b/tests/org.eclipse.graphiti.testtool.sketch/plugin.properties
new file mode 100644
index 0000000..f54015c
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/plugin.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# <copyright>
+#
+# Copyright (c) 2005, 2010 SAP AG.
+# 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:
+# SAP AG - initial API, implementation and documentation
+#
+# </copyright>
+#
+###############################################################################
+pluginName = Graphiti Sample Sketch (Incubation)
+providerName = Eclipse Modeling Project
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/plugin.xml b/tests/org.eclipse.graphiti.testtool.sketch/plugin.xml
new file mode 100644
index 0000000..c2fc25f
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/plugin.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<!--
+ <copyright>
+
+ Copyright (c) 2005, 2010 SAP AG.
+ 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:
+ SAP AG - initial API, implementation and documentation
+
+ </copyright>
+
+ -->
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
+ <propertyContributor
+ typeMapper="org.eclipse.graphiti.examples.common.property.TypeMapper"
+ contributorId="sample.sketch.PropertyContributor"
+ labelProvider="org.eclipse.graphiti.examples.common.property.PropertiesLabelProvider">
+ <propertyCategory category="gfw-legacy" />
+ </propertyContributor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
+ <propertyTabs
+ contributorId="sample.sketch.PropertyContributor">
+ <propertyTab
+ label="Advanced" category="gfw-legacy"
+ id="org.eclipse.graphiti.properties.legacytab">
+ </propertyTab>
+ </propertyTabs>
+ </extension>
+
+ <extension
+ point="org.eclipse.graphiti.ui.diagramTypes">
+ <diagramType
+ description="diagram type for sketch samples"
+ id="org.eclipse.graphiti.sample.sketch.SketchDiagramType"
+ name="Sample Sketch DT"
+ type="sample.sketch">
+ </diagramType>
+ </extension>
+
+
+ <extension
+ point="org.eclipse.graphiti.ui.diagramTypeProviders">
+ <diagramTypeProvider
+ class="org.eclipse.graphiti.sample.sketch.SketchDiagramTypeProvider"
+ description="A sample sketch editor"
+ id="org.eclipse.graphiti.sample.sketch.SketchDiagramTypeProvider"
+ name="Sketch">
+ <diagramType
+ id="org.eclipse.graphiti.sample.sketch.SketchDiagramType">
+ </diagramType>
+ <imageProvider
+ id="org.eclipse.graphiti.examples.common.SampleImageProvider">
+ </imageProvider>
+ </diagramTypeProvider>
+ </extension>
+
+
+</plugin>
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/CanFigure.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/CanFigure.java
new file mode 100644
index 0000000..92571ed
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/CanFigure.java
@@ -0,0 +1,370 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.RectangleFigure;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.graphiti.platform.ga.IGraphicsAlgorithmRenderer;
+import org.eclipse.graphiti.platform.ga.IVisualState;
+import org.eclipse.graphiti.platform.ga.IVisualStateChangeListener;
+import org.eclipse.graphiti.platform.ga.IVisualStateHolder;
+import org.eclipse.graphiti.platform.ga.VisualState;
+import org.eclipse.graphiti.platform.ga.VisualStateChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * The Class CanFigure.
+ */
+public class CanFigure extends RectangleFigure implements IGraphicsAlgorithmRenderer, IVisualStateHolder, IVisualStateChangeListener {
+
+ private static final int SELECTION_LINE_WIDTH_PRIMARY = 4;
+
+ private static final int SELECTION_LINE_WIDTH_SECONDARY = 3;
+
+ private static final Color SELECTION_BACKGROUND_PRIMARY = ColorConstants.blue;
+
+ private static final Color SELECTION_BACKGROUND_SECONDARY = ColorConstants.lightBlue;
+
+ private static final boolean ADVANCED_GRAPHIC = true;
+
+ private static final int DEFAULT_ELLIPSE_PROPORTION = 4;
+
+ private static final Color DEFAULT_TEXT_COLOR = ColorConstants.black;
+
+ private Insets defaultFigureInsets = new Insets(2);
+
+ private boolean dropShadow = true;
+
+ private Image icon;
+
+ private String label = "";
+
+ private int mProportion = DEFAULT_ELLIPSE_PROPORTION;
+
+ private boolean ovalTop;
+
+ private Color storeColor;
+
+ private String storeText;
+
+ private Color textColor = DEFAULT_TEXT_COLOR;
+
+ boolean highlight = false;
+
+ private VisualState visualState;
+
+ private int storeLineWidth = -1;
+
+ /**
+ * Instantiates a new can figure.
+ *
+ * @param ovalTop
+ * the oval top
+ */
+ public CanFigure(boolean ovalTop) {
+ this(ovalTop, DEFAULT_ELLIPSE_PROPORTION);
+ }
+
+ /**
+ * Instantiates a new can figure.
+ *
+ * @param ovalTop
+ * the oval top
+ * @param ellipseProportion
+ * the ellipse proportion
+ */
+ public CanFigure(boolean ovalTop, int ellipseProportion) {
+ super();
+ if (ellipseProportion > 0) {
+ mProportion = ellipseProportion;
+ }
+ this.ovalTop = ovalTop;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.draw2d.Figure#containsPoint(int, int)
+ */
+ @Override
+ public boolean containsPoint(int x, int y) {
+ if (!super.containsPoint(x, y))
+ return false;
+
+ Rectangle ell = getInnerBounds().getCopy();
+ ell.height /= mProportion;
+
+ Rectangle topEll = ell;
+ if (containsPoint(topEll, x, y))
+ return true;
+
+ Rectangle bottomEll = ell.getCopy().translate(0, getHeight(ell));
+ if (containsPoint(bottomEll, x, y))
+ return true;
+ return new Rectangle(topEll.getLeft(), bottomEll.getRight()).contains(x, y);
+ }
+
+ /**
+ * Gets the figure insets.
+ *
+ * @return the figure insets
+ */
+ public Insets getFigureInsets() {
+ return defaultFigureInsets;
+ }
+
+ /**
+ * Returns the visual state of this shape.
+ *
+ * @return The visual state of this shape.
+ */
+ public IVisualState getVisualState() {
+ if (visualState == null) {
+ visualState = new VisualState();
+ visualState.addChangeListener(this);
+ }
+ return visualState;
+ }
+
+ /**
+ * Is called after the visual state changed.
+ */
+ public void visualStateChanged(VisualStateChangedEvent e) {
+ int selectionFeedback = getVisualState().getSelectionFeedback();
+ if (selectionFeedback == IVisualState.SELECTION_PRIMARY) {
+ // text
+ if (storeText == null) {
+ storeText = getCaption();
+ }
+ setCaption("primary select");
+
+ // text color
+ setTextColor(ColorConstants.white);
+
+ // background color
+ if (storeColor == null) {
+ storeColor = getBackgroundColor();
+ }
+ setBackgroundColor(SELECTION_BACKGROUND_PRIMARY);
+
+ // line width
+ if (storeLineWidth < 0) {
+ storeLineWidth = getLineWidth();
+ }
+ setLineWidth(SELECTION_LINE_WIDTH_PRIMARY);
+ } else if (selectionFeedback == IVisualState.SELECTION_SECONDARY) {
+ // text
+ if (storeText == null) {
+ storeText = getCaption();
+ }
+ setCaption("secondary select");
+
+ // text color
+ setTextColor(ColorConstants.white);
+
+ // background color
+ if (storeColor == null) {
+ storeColor = getBackgroundColor();
+ }
+ setBackgroundColor(SELECTION_BACKGROUND_SECONDARY);
+
+ // line width
+ if (storeLineWidth < 0) {
+ storeLineWidth = getLineWidth();
+ }
+ setLineWidth(SELECTION_LINE_WIDTH_SECONDARY);
+ } else if (selectionFeedback == IVisualState.SELECTION_FEEDBACK_OFF) {
+ // text color
+ if (storeText != null) {
+ setCaption(storeText);
+ storeText = null;
+ }
+
+ // text color
+ setTextColor(DEFAULT_TEXT_COLOR);
+
+ // background color
+ if (storeColor != null) {
+ setBackgroundColor(storeColor);
+ storeColor = null;
+ }
+
+ // line width
+ if (storeLineWidth >= 0) {
+ setLineWidth(storeLineWidth);
+ storeLineWidth = -1;
+ }
+ }
+ }
+
+ /**
+ * Sets the caption.
+ *
+ * @param label
+ * the new caption
+ */
+ public void setCaption(String label) {
+ this.label = label;
+ setToolTip(new Label(" " + label + " "));
+ repaint();
+ }
+
+ /**
+ * Sets the drop shadow.
+ *
+ * @param dropShadow
+ * the new drop shadow
+ */
+ public void setDropShadow(boolean dropShadow) {
+ this.dropShadow = dropShadow;
+ }
+
+ /**
+ * Sets the highlight.
+ *
+ * @param highlight
+ * the new highlight
+ */
+ public void setHighlight(boolean highlight) {
+ this.highlight = highlight;
+ repaint();
+ }
+
+ /**
+ * Sets the icon.
+ *
+ * @param icon
+ * the new icon
+ */
+ public void setIcon(Image icon) {
+ this.icon = icon;
+ repaint();
+ }
+
+ /**
+ * Sets the text color.
+ *
+ * @param textColor
+ * the new text color
+ */
+ public void setTextColor(Color textColor) {
+ this.textColor = textColor;
+ }
+
+ private boolean containsPoint(Rectangle el, int x, int y) {
+
+ long ux = x - el.x - el.width / 2;
+ long uy = y - el.y - el.height / 2;
+ return ((ux * ux) << 10) / (el.width * el.width) + ((uy * uy) << 10) / (el.height * el.height) <= 256;
+ }
+
+ private String getCaption() {
+ return label;
+ }
+
+ private int getHeight(Rectangle topEllipse) {
+ return getInnerBounds().height - topEllipse.height;
+ }
+
+ private Rectangle getInnerBounds() {
+ return getBounds().getCopy().getCropped(defaultFigureInsets);
+ }
+
+ @Override
+ protected void fillShape(Graphics g) {
+ if (ADVANCED_GRAPHIC)
+ g.setAntialias(SWT.ON);
+ Rectangle upperArc = getInnerBounds();
+ upperArc.height /= mProportion;
+
+ Rectangle lowerArc = upperArc.getCopy().translate(0, getHeight(upperArc));
+ if (highlight) {
+ g.setBackgroundColor(ColorConstants.blue);
+ g.fillRectangle(getBounds());
+ } else if (dropShadow) {
+
+ for (int i = 0; i < 3; i++) {
+ switch (i) {
+ case 0:
+ g.setBackgroundColor(ColorConstants.lightGray);
+ break;
+ case 1:
+ g.setBackgroundColor(ColorConstants.gray);
+ break;
+ case 2:
+ g.setBackgroundColor(ColorConstants.darkGray);
+ break;
+ }
+
+ g.fillRectangle(new Rectangle(upperArc.getLeft(), lowerArc.getRight()).getTranslated(3, 3).getExpanded(-i, 1));
+ g.fillArc(new Rectangle(upperArc.getLocation(), upperArc.getBottomRight()).getTranslated(3, 2).getExpanded(-i, -i), 0, 180);
+ g.fillArc(new Rectangle(lowerArc.getLocation(), lowerArc.getBottomRight()).getTranslated(3, 3).getExpanded(-i, -i), 180,
+ 180);
+
+ }
+
+ }
+ g.setBackgroundColor(getBackgroundColor());
+
+ g.fillRectangle(new Rectangle(upperArc.getLeft(), lowerArc.getRight()));
+ g.fillArc(new Rectangle(upperArc.getLocation(), upperArc.getBottomRight().getTranslated(0, 1)), 0, 180);
+ g.fillArc(new Rectangle(lowerArc.getLocation(), lowerArc.getBottomRight()), 180, 180);
+ }
+
+ @Override
+ protected void outlineShape(Graphics g) {
+
+ Rectangle innerBounds = getInnerBounds();
+
+ Rectangle ovalBounds = innerBounds.getCopy();
+
+ ovalBounds.height /= mProportion;
+
+ // Rectangle ovalBounds = ellipseBounds.getCopy().shrink((lineWidth - 1)
+ // / 2, (lineWidth - 1) / 2);
+ if (ovalTop) {
+ g.drawOval(ovalBounds);
+ } else {
+ g.drawArc(ovalBounds, 0, 180);
+ }
+
+ Rectangle arcBounds = ovalBounds.getCopy().translate(0, getHeight(ovalBounds));
+ g.drawLine(ovalBounds.getLeft(), arcBounds.getLeft());
+ g.drawLine(ovalBounds.getRight(), arcBounds.getRight());
+ g.drawArc(new Rectangle(arcBounds.getLocation(), arcBounds.getBottomRight().translate(-2, -1)), 180, 180);
+
+ int maxChars = (innerBounds.width - 40) / g.getFontMetrics().getAverageCharWidth();
+ if (maxChars < 3)
+ maxChars = 3;
+
+ if (label != null) {
+ String newCaption = label;
+ if (label.length() > maxChars)
+ newCaption = label.substring(0, maxChars - 3) + "...";
+
+ g.setForegroundColor(textColor);
+ g.drawText(newCaption, innerBounds.x + 25, innerBounds.y + innerBounds.height / 2 - 6);
+ if (icon != null)
+ g.drawImage(icon, innerBounds.x + 5, innerBounds.y + innerBounds.height / 2 - 8);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchDiagramTypeProvider.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchDiagramTypeProvider.java
new file mode 100644
index 0000000..78b8b99
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchDiagramTypeProvider.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch;
+
+import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
+import org.eclipse.graphiti.features.ConfigurableFeatureProviderWrapper;
+import org.eclipse.graphiti.platform.ga.IGraphicsAlgorithmRendererFactory;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+
+/**
+ * The Class SketchDiagramTypeProvider.
+ */
+public class SketchDiagramTypeProvider extends AbstractDiagramTypeProvider {
+
+ private IToolBehaviorProvider[] availableToolBehaviorProviders;
+
+ private IGraphicsAlgorithmRendererFactory factory;
+
+ /**
+ * Instantiates a new sketch diagram type provider.
+ */
+ public SketchDiagramTypeProvider() {
+ super();
+ setFeatureProvider(new ConfigurableFeatureProviderWrapper(new SketchFeatureProvider(this)));
+ }
+
+ @Override
+ public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() {
+ if (availableToolBehaviorProviders == null) {
+ availableToolBehaviorProviders = new IToolBehaviorProvider[] { new SketchToolBehaviour(this),
+ new SketchViewerModeToolBehavior(this) };
+ }
+ return availableToolBehaviorProviders;
+ }
+
+ @Override
+ public IGraphicsAlgorithmRendererFactory getGraphicsAlgorithmRendererFactory() {
+ if (factory == null) {
+ factory = new SketchGraphicsAlgorithmRendererFactory();
+ }
+ return factory;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchFeatureProvider.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchFeatureProvider.java
new file mode 100644
index 0000000..619844c
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchFeatureProvider.java
@@ -0,0 +1,426 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.ICopyFeature;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.IDirectEditingFeature;
+import org.eclipse.graphiti.features.ILayoutFeature;
+import org.eclipse.graphiti.features.IMoveShapeFeature;
+import org.eclipse.graphiti.features.IPasteFeature;
+import org.eclipse.graphiti.features.IResizeShapeFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICopyContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IDirectEditingContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.context.IMoveShapeContext;
+import org.eclipse.graphiti.features.context.IPasteContext;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Ellipse;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.LineStyle;
+import org.eclipse.graphiti.mm.pictograms.MultiText;
+import org.eclipse.graphiti.mm.pictograms.Orientation;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Polygon;
+import org.eclipse.graphiti.mm.pictograms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.RoundedRectangle;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.sample.sketch.features.AddAnythingFeature;
+import org.eclipse.graphiti.sample.sketch.features.AddDiagramFeature;
+import org.eclipse.graphiti.sample.sketch.features.AddLinkFeature;
+import org.eclipse.graphiti.sample.sketch.features.BackgroundColorFeature;
+import org.eclipse.graphiti.sample.sketch.features.ChangeAlignmentFeature;
+import org.eclipse.graphiti.sample.sketch.features.CornerDimensionFeature;
+import org.eclipse.graphiti.sample.sketch.features.FontColorFeature;
+import org.eclipse.graphiti.sample.sketch.features.ForegroundColorFeature;
+import org.eclipse.graphiti.sample.sketch.features.GradientColorFeature;
+import org.eclipse.graphiti.sample.sketch.features.LayoutContainerShapeGhostAndInnerShapeFeature;
+import org.eclipse.graphiti.sample.sketch.features.LineStyleFeature;
+import org.eclipse.graphiti.sample.sketch.features.LineWidthFeature;
+import org.eclipse.graphiti.sample.sketch.features.SendToBackFeature;
+import org.eclipse.graphiti.sample.sketch.features.SendToFrontFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchDeleteFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchFontFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchGhostLayoutFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchLabelDirectEditingFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchLayoutFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchMoveShapeFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchResizeShapeFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchTextDirectEditingFeature;
+import org.eclipse.graphiti.sample.sketch.features.SwitchModeFeature;
+import org.eclipse.graphiti.sample.sketch.features.ToggleDecorator;
+import org.eclipse.graphiti.sample.sketch.features.TransparencyFeature;
+import org.eclipse.graphiti.sample.sketch.features.bd.CreateChannelFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.CreateCsGhostAndInnerShapeFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateCanFigureFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateFreeformConnectionFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateGaContainerFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateGaContainerFeatureWithGhost;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateGaShapeFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateGaShapeFeatureWithGhost;
+import org.eclipse.graphiti.sample.sketch.features.pool.CreateLaneFeauture;
+import org.eclipse.graphiti.sample.sketch.features.pool.CreatePoolFeature;
+import org.eclipse.graphiti.sample.sketch.features.pool.LayoutPoolFeature;
+import org.eclipse.graphiti.sample.sketch.features.style.CreateDefaultStylesFeature;
+import org.eclipse.graphiti.sample.sketch.features.style.IgnoreAllFeature;
+import org.eclipse.graphiti.sample.sketch.features.style.MakeStyleFeature;
+import org.eclipse.graphiti.sample.sketch.features.style.SetStyleFeature;
+import org.eclipse.graphiti.sample.sketch.features.style.UnsetStyleFeature;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+
+/**
+ * The Class SketchFeatureProvider.
+ */
+public class SketchFeatureProvider extends DefaultFeatureProvider {
+
+ public static final String CF_RECTANGLE_MULTI_TEXT = "Rectangle";
+
+ public static final String CF_RECTANGLE_SINGLE_TEXT = "Rectangle Single Text";
+
+ private static final String NO_MOVE = "no move";
+
+ private static final boolean TEST_RESIZE_SHAPE_FEATURE = false;
+
+ private final int TRANSPARENCY_STEP_SIZE = 5;
+
+ private final int LINE_WIDTH_STEP_SIZE = 1;
+
+ private boolean testMode = false; // if true, then this feature provider is used in the test suite
+
+ private final Dimension CORNER_DIMENSION[] = new Dimension[] { new Dimension(0, 0), new Dimension(4, 4), new Dimension(8, 8),
+ new Dimension(20, 20), new Dimension(21, 21), new Dimension(100, 100), new Dimension(101, 101), new Dimension(200, 200),
+ new Dimension(100, 20), new Dimension(20, 100), };
+
+ /**
+ * Instantiates a new sketch feature provider.
+ *
+ * @param dtp
+ * the dtp
+ */
+ public SketchFeatureProvider(IDiagramTypeProvider dtp) {
+ super(dtp);
+ }
+
+ @Override
+ public ICreateFeature[] getCreateFeatures() {
+
+ List<ICreateFeature> features = new ArrayList<ICreateFeature>();
+
+ features.add(new CreateCsGhostAndInnerShapeFeature(this, "CS + Ghost + inner Shape", "create CS with Ghost and inner Shape"));
+
+ features.add(createCreateGaContainerFeature("Rectangle Container", "draw rectangle", Rectangle.class));
+ features.add(createCreateGaContainerFeature("Rounded Rectangle Container", "draw rounded rectangle", RoundedRectangle.class));
+ features.add(createCreateGaContainerFeature("Ellipse Container", "draw ellipse", Ellipse.class));
+ features.add(createCreateGaContainerFeature("Triangle Container", "draw triangle", Polygon.class));
+
+ features.add(createCreateGaShapeFeature(CF_RECTANGLE_MULTI_TEXT, "draw rectangle", Rectangle.class));
+ features.add(createCreateGaShapeFeatureSingleText(CF_RECTANGLE_SINGLE_TEXT, "draw rectangle with a single line text",
+ Rectangle.class));
+ features.add(createCreateGaShapeFeature("Rounded Rectangle", "draw rounded rectangle", RoundedRectangle.class));
+ features.add(createCreateGaShapeFeature("Ellipse", "draw ellipse", Ellipse.class));
+ features.add(createCreateGaShapeFeature("Triangle", "draw triangle", Polygon.class));
+ features.add(createCreateGaShapeFeature("Arrow", "draw Arrow outline", Polygon.class));
+ features.add(createCreateGaShapeFeature("Line", "draw line", Polyline.class));
+
+ features.add(createCreateGaShapeFeatureWithGhost("Rectangle Ghost", "rectangle with ghost", Rectangle.class));
+ features
+ .add(createCreateGaShapeFeatureWithGhost("Rounded Rectangle Ghost", "rounded rectangle with ghost", RoundedRectangle.class));
+ features.add(createCreateGaShapeFeatureWithGhost("Ellipse Ghost", "ellipse with ghost", Ellipse.class));
+
+ features
+ .add(createCreateGaContainerFeatureWithGhost("Rectangle Container Ghost", "rectangle container with ghost", Rectangle.class));
+ features.add(createCreateGaContainerFeatureWithGhost("Rounded Container Rectangle Ghost", "rounded rectangle container with ghost",
+ RoundedRectangle.class));
+ features.add(createCreateGaContainerFeatureWithGhost("Ellipse Container Ghost", "ellipse container with ghost", Ellipse.class));
+
+ features.add(new CreatePoolFeature(this, "Pool", "create a pool"));
+
+ features.add(new SketchCreateCanFigureFeature(this, "Can figure", "example for a platform ga"));
+
+ return features.toArray(new ICreateFeature[0]);
+ }
+
+ @Override
+ public ICustomFeature[] getCustomFeatures(ICustomContext context) {
+
+ List<ICustomFeature> retList = new ArrayList<ICustomFeature>();
+
+ for (int i = 0; i <= 10; i += LINE_WIDTH_STEP_SIZE) {
+ retList.add(new LineWidthFeature(this, i));
+ }
+
+ retList.add(new LineStyleFeature(this, LineStyle.SOLID));
+ retList.add(new LineStyleFeature(this, LineStyle.DASH));
+ retList.add(new LineStyleFeature(this, LineStyle.DASHDOT));
+ retList.add(new LineStyleFeature(this, LineStyle.DASHDOTDOT));
+ retList.add(new LineStyleFeature(this, LineStyle.DOT));
+
+ for (int i = 0; i < CORNER_DIMENSION.length; i++) {
+ retList.add(new CornerDimensionFeature(this, CORNER_DIMENSION[i]));
+ }
+
+ retList.add(new SendToFrontFeature(this));
+ retList.add(new SendToBackFeature(this));
+
+ retList.add(new ForegroundColorFeature(this));
+ retList.add(new BackgroundColorFeature(this));
+ retList.add(new GradientColorFeature(this));
+ retList.add(new FontColorFeature(this));
+
+ retList.add(new SketchFontFeature(this));
+
+ retList.add(new CreateLaneFeauture(this));
+
+ retList.add(new ChangeAlignmentFeature(this, "Left", Orientation.ALIGNMENT_LEFT, null));
+ retList.add(new ChangeAlignmentFeature(this, "Center", Orientation.ALIGNMENT_CENTER, null));
+ retList.add(new ChangeAlignmentFeature(this, "Right", Orientation.ALIGNMENT_RIGHT, null));
+
+ retList.add(new ChangeAlignmentFeature(this, "Top", null, Orientation.ALIGNMENT_TOP));
+ retList.add(new ChangeAlignmentFeature(this, "Middle", null, Orientation.ALIGNMENT_CENTER));
+ retList.add(new ChangeAlignmentFeature(this, "Bottom", null, Orientation.ALIGNMENT_BOTTOM));
+
+ retList.add(new ChangeAlignmentFeature(this, "Top Left", Orientation.ALIGNMENT_LEFT, Orientation.ALIGNMENT_TOP));
+ retList.add(new ChangeAlignmentFeature(this, "Top Right", Orientation.ALIGNMENT_RIGHT, Orientation.ALIGNMENT_TOP));
+ retList.add(new ChangeAlignmentFeature(this, "Middle Center", Orientation.ALIGNMENT_CENTER, Orientation.ALIGNMENT_CENTER));
+ retList.add(new ChangeAlignmentFeature(this, "Bottom Left", Orientation.ALIGNMENT_LEFT, Orientation.ALIGNMENT_BOTTOM));
+ retList.add(new ChangeAlignmentFeature(this, "Bottom Right", Orientation.ALIGNMENT_RIGHT, Orientation.ALIGNMENT_BOTTOM));
+
+ for (int i = 0; i < 100; i += TRANSPARENCY_STEP_SIZE) {
+ retList.add(new TransparencyFeature(this, i));
+ }
+ retList.add(new TransparencyFeature(this, 100));
+
+ retList.add(new ToggleDecorator(this));
+
+ retList.add(new CreateDefaultStylesFeature(this));
+
+ retList.add(new MakeStyleFeature(this));
+
+ Collection<Style> styles = getDiagramTypeProvider().getDiagram().getStyles();
+ for (Style style : styles) {
+ createSetStyleFeatures(style, retList);
+ }
+
+ retList.add(new UnsetStyleFeature(this));
+
+ retList.add(new IgnoreAllFeature(this));
+
+ retList.add(new SwitchModeFeature(this));
+
+ return retList.toArray(new ICustomFeature[0]);
+ }
+
+ private void createSetStyleFeatures(Style parentStyle, List<ICustomFeature> retList) {
+ retList.add(new SetStyleFeature(parentStyle, this));
+ Collection<Style> styles = parentStyle.getStyles();
+ for (Style style : styles) {
+ createSetStyleFeatures(style, retList);
+ }
+ }
+
+ @Override
+ public ICreateConnectionFeature[] getCreateConnectionFeatures() {
+ List<ICreateConnectionFeature> retList = new ArrayList<ICreateConnectionFeature>();
+
+ retList.add(new SketchCreateFreeformConnectionFeature(this, "free", "freeform connection"));
+ retList.add(new CreateChannelFeature(this, "channel", "channel connection"));
+
+ return retList.toArray(new ICreateConnectionFeature[0]);
+ }
+
+ private ICreateFeature createCreateGaContainerFeature(String name, String description, Class gaType) {
+ ICreateFeature createFeature = new SketchCreateGaContainerFeature(this, name, description, gaType);
+ return createFeature;
+ }
+
+ private ICreateFeature createCreateGaShapeFeature(String name, String description, Class gaType) {
+ ICreateFeature createFeature = new SketchCreateGaShapeFeature(this, name, description, gaType);
+ return createFeature;
+ }
+
+ private ICreateFeature createCreateGaShapeFeatureSingleText(String name, String description, Class gaType) {
+ ICreateFeature createFeature = new SketchCreateGaShapeFeature(this, name, description, gaType, false);
+ return createFeature;
+ }
+
+ private ICreateFeature createCreateGaShapeFeatureWithGhost(String name, String description, Class gaType) {
+ // breaks the build: ICreateFeature createFeature = new
+ // SketchCreateGaShapeFeatureWithGhost(this, name, description,
+ // gaType);
+ ICreateFeature createFeature = new SketchCreateGaShapeFeatureWithGhost(this, name, description, gaType);
+ return createFeature;
+ }
+
+ private ICreateFeature createCreateGaContainerFeatureWithGhost(String name, String description, Class gaType) {
+ // breaks the build: ICreateFeature createFeature = new
+ // SketchCreateGaShapeFeatureWithGhost(this, name, description,
+ // gaType);
+ ICreateFeature createFeature = new SketchCreateGaContainerFeatureWithGhost(this, name, description, gaType);
+ return createFeature;
+ }
+
+ @Override
+ public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) {
+ Shape shape = context.getShape();
+ if (shape != null) {
+ GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
+ if (checkNoMove(ga)) {
+ return null;
+ }
+ }
+ return new SketchMoveShapeFeature(this);
+ }
+
+ private boolean checkNoMove(GraphicsAlgorithm ga) {
+ if (ga instanceof AbstractText) {
+ AbstractText at = (AbstractText) ga;
+ if (NO_MOVE.equalsIgnoreCase(at.getValue())) {
+ return true;
+ }
+ } else {
+ List<GraphicsAlgorithm> gaChildren = ga.getGraphicsAlgorithmChildren();
+ for (GraphicsAlgorithm child : gaChildren) {
+ if (checkNoMove(child)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public IAddFeature getAddFeature(IAddContext context) {
+ IAddFeature ret = super.getAddFeature(context);
+
+ Object newObject = context.getNewObject();
+ if (newObject instanceof Diagram) {
+ ret = new AddDiagramFeature(this);
+ } else if (!(context.getTargetContainer() instanceof Diagram) && !(newObject instanceof PictogramElement)) {
+ // works only container shapes, because drop is only allowed on container shapes
+ ret = new AddLinkFeature(this);
+ } else {
+ return new AddAnythingFeature(this);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public ILayoutFeature getLayoutFeature(ILayoutContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ if (SketchUtil.getLabelGa(pe) != null) {
+ return new SketchLayoutFeature(this);
+ } else if (SketchUtil.getGhostGa(pe) != null) {
+ return new SketchGhostLayoutFeature(this);
+ } else if (SketchUtil.isPoolPe(pe)) {
+ return new LayoutPoolFeature(this);
+ } else {
+ boolean check = context.getPictogramElement() instanceof ContainerShape;
+ ContainerShape cs = (ContainerShape) pe;
+ List<Shape> children = cs.getChildren();
+ if (!children.isEmpty()) {
+ Shape firstChild = children.get(0);
+ if (firstChild != null) {
+ GraphicsAlgorithm ga = firstChild.getGraphicsAlgorithm();
+ check = check && ga instanceof Ellipse;
+ if (check) {
+ return new LayoutContainerShapeGhostAndInnerShapeFeature(this);
+ }
+ }
+ }
+ }
+ return super.getLayoutFeature(context);
+ }
+
+ @Override
+ public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext context) {
+ IDirectEditingFeature ret = null;
+ PictogramElement pe = context.getPictogramElement();
+ AbstractText labelGa = SketchUtil.getLabelGa(pe);
+ if (labelGa != null) {
+ if (labelGa instanceof MultiText) {
+ ret = new SketchLabelDirectEditingFeature(this);
+ } else {
+ ret = new SketchTextDirectEditingFeature(this);
+ }
+ }
+
+ return ret;
+ }
+
+ @Override
+ public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) {
+ final PictogramElement pe = context.getPictogramElement();
+ if (pe instanceof ConnectionDecorator) {
+ return null;
+ }
+ if (pe.getGraphicsAlgorithm() instanceof Polyline) {
+ return null;
+ }
+
+ if (TEST_RESIZE_SHAPE_FEATURE) {
+ return new SketchResizeShapeFeature(this);
+ } else {
+ return super.getResizeShapeFeature(context);
+ }
+ }
+
+ @Override
+ public ICopyFeature getCopyFeature(ICopyContext context) {
+ //return new DefaultCopyFeature(this);
+ return null;
+ }
+
+ @Override
+ public IPasteFeature getPasteFeature(IPasteContext context) {
+ //return new DefaultPasteFeature(this);
+ return null;
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ IDeleteFeature ret = null;
+ ret = new SketchDeleteFeature(this);
+ return ret;
+ }
+
+ public void setTestMode(boolean testMode) {
+ this.testMode = testMode;
+ }
+
+ public boolean isTestMode() {
+ return testMode;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchGraphicsAlgorithmRendererFactory.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchGraphicsAlgorithmRendererFactory.java
new file mode 100644
index 0000000..f08a231
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchGraphicsAlgorithmRendererFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.graphiti.platform.ga.IGraphicsAlgorithmRenderer;
+import org.eclipse.graphiti.platform.ga.IGraphicsAlgorithmRendererFactory;
+import org.eclipse.graphiti.platform.ga.IRendererContext;
+
+/**
+ * A factory for creating SketchGraphicsAlgorithmRenderer objects.
+ */
+public class SketchGraphicsAlgorithmRendererFactory implements IGraphicsAlgorithmRendererFactory {
+
+ /**
+ * The Constant CANFIGURE.
+ */
+ public final static String CANFIGURE = "sketch.canfigure";
+
+ public IGraphicsAlgorithmRenderer createGraphicsAlgorithmRenderer(IRendererContext context) {
+ if (CANFIGURE.equals(context.getPlatformGraphicsAlgorithm().getId())) {
+ return createCanFigure();
+ }
+ return null;
+ }
+
+ private CanFigure createCanFigure() {
+ CanFigure ret = new CanFigure(false);
+ ret.setDropShadow(false);
+ ret.setTextColor(ColorConstants.blue);
+ ret.setBackgroundColor(ColorConstants.yellow);
+ ret.setCaption("can figure test");
+ return ret;
+
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchPlugin.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchPlugin.java
new file mode 100644
index 0000000..112da64
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchPlugin.java
@@ -0,0 +1,89 @@
+package org.eclipse.graphiti.sample.sketch;
+
+import java.net.URL;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * The main-class of the plugin. It is mostly used to acces the 'environment' of
+ * this plugin.
+ */
+public class SketchPlugin extends AbstractUIPlugin {
+
+ private static SketchPlugin _plugin;
+
+ /**
+ * Creates the Plugin and caches its default instance.
+ */
+ public SketchPlugin() {
+ _plugin = this;
+ }
+
+ // ======================== static access methods ==========================
+
+ /**
+ * Gets the default-instance of this plugin. Actually the default-instance
+ * should always be the only instance -> Singleton.
+ *
+ * @return the default
+ */
+ public static SketchPlugin getDefault() {
+ return _plugin;
+ }
+
+ // =========================== public helper methods ======================
+
+ /**
+ * Returns the current Workspace.
+ *
+ * @return The current Workspace.
+ */
+ public static IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ /**
+ * Returns the URL, which points to where this Plugin is installed.
+ *
+ * @return The URL, which points to where this Plugin is installed.
+ */
+ public static URL getInstallURL() {
+ return getDefault().getBundle().getEntry("/");
+ }
+
+ /**
+ * Returns the Plugin-ID.
+ *
+ * @return The Plugin-ID.
+ */
+ public static String getID() {
+ return getDefault().getBundle().getSymbolicName();
+ }
+
+ /**
+ * Returns the currently active WorkbenchPage.
+ *
+ * @return The currently active WorkbenchPage.
+ */
+ public static IWorkbenchPage getActivePage() {
+ IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (workbenchWindow != null)
+ return workbenchWindow.getActivePage();
+ return null;
+ }
+
+ /**
+ * Returns the currently active Shell.
+ *
+ * @return The currently active Shell.
+ */
+ public static Shell getShell() {
+ return getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchToolBehaviour.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchToolBehaviour.java
new file mode 100644
index 0000000..8a194bf
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchToolBehaviour.java
@@ -0,0 +1,515 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.graphiti.IExecutionInfo;
+import org.eclipse.graphiti.IName;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.examples.common.ISampleImageConstants;
+import org.eclipse.graphiti.features.ICreateConnectionFeature;
+import org.eclipse.graphiti.features.ICreateFeature;
+import org.eclipse.graphiti.features.IFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
+import org.eclipse.graphiti.features.context.impl.CustomContext;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.LineStyle;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.RoundedRectangle;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.palette.IPaletteCompartmentEntry;
+import org.eclipse.graphiti.palette.impl.ConnectionCreationToolEntry;
+import org.eclipse.graphiti.palette.impl.ObjectCreationToolEntry;
+import org.eclipse.graphiti.palette.impl.PaletteCompartmentEntry;
+import org.eclipse.graphiti.platform.IPlatformImageConstants;
+import org.eclipse.graphiti.sample.sketch.features.ChangeAlignmentFeature;
+import org.eclipse.graphiti.sample.sketch.features.CornerDimensionFeature;
+import org.eclipse.graphiti.sample.sketch.features.LineStyleFeature;
+import org.eclipse.graphiti.sample.sketch.features.LineWidthFeature;
+import org.eclipse.graphiti.sample.sketch.features.SketchFontFeature;
+import org.eclipse.graphiti.sample.sketch.features.TransparencyFeature;
+import org.eclipse.graphiti.sample.sketch.features.create.SketchCreateCanFigureFeature;
+import org.eclipse.graphiti.sample.sketch.features.style.SetStyleFeature;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.tb.ContextButtonEntry;
+import org.eclipse.graphiti.tb.ContextEntryHelper;
+import org.eclipse.graphiti.tb.ContextMenuEntry;
+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IContextButtonEntry;
+import org.eclipse.graphiti.tb.IContextButtonPadData;
+import org.eclipse.graphiti.tb.IContextMenuEntry;
+import org.eclipse.graphiti.tb.IRenderingDecorator;
+import org.eclipse.graphiti.tb.ISelectionInfo;
+import org.eclipse.graphiti.tb.ImageRenderingDecorator;
+import org.eclipse.graphiti.tb.SelectionInfoImpl;
+import org.eclipse.graphiti.ui.internal.editor.IEclipseImageDescriptor;
+import org.eclipse.graphiti.util.IColorConstant;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * The Class SketchToolBehaviour.
+ */
+public class SketchToolBehaviour extends DefaultToolBehaviorProvider implements IName {
+ private class MyObjectCreationToolEntry extends ObjectCreationToolEntry implements IEclipseImageDescriptor {
+
+ private final String imageFilePath;
+
+ public MyObjectCreationToolEntry(String label, String description, ICreateFeature createFeature, String imageFilePath) {
+ super(label, description, null, null, createFeature);
+ this.imageFilePath = imageFilePath;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return AbstractUIPlugin.imageDescriptorFromPlugin(SketchPlugin.getID(), imageFilePath);
+ }
+
+ }
+
+ private class MyPaletteCompartmentEntry extends PaletteCompartmentEntry implements IEclipseImageDescriptor {
+
+ private final String imageFilePath;
+
+ public MyPaletteCompartmentEntry(String label, String imageFilePath) {
+ super(label, null);
+ this.imageFilePath = imageFilePath;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return AbstractUIPlugin.imageDescriptorFromPlugin(SketchPlugin.getID(), imageFilePath);
+ }
+ }
+
+ private static final String ICON_CAN_FIGURE = "icons/pid16.gif"; //$NON-NLS-1$
+
+ private static final String ICON_CONNECTION_COMPARTMENT = "icons/connection16.gif"; //$NON-NLS-1$
+
+ private static final double[] ZOOM_LEVELS = new double[] { 0.05, 0.1, 0.5, 1, 1.5, 2, 3, 4 };
+
+ private static final boolean TEST_SHOW_WARNING_DECORATORS = false;
+
+ private final ISelectionInfo selectionInfo = new SelectionInfoImpl(IColorConstant.BLUE, IColorConstant.LIGHT_BLUE, IColorConstant.RED,
+ LineStyle.DOT);
+
+ /**
+ * Instantiates a new sketch tool behaviour.
+ *
+ * @param diagramTypeProvider
+ * the diagram type provider
+ */
+ public SketchToolBehaviour(IDiagramTypeProvider diagramTypeProvider) {
+ super(diagramTypeProvider);
+ }
+
+ @SuppressWarnings("unused")
+ private PictogramElement findParentToBeSelected(PictogramElement originalPe, PictogramElement[] oldSelection) {
+ List<PictogramElement> oldSelectList = Arrays.asList(oldSelection);
+ if (oldSelectList.contains(originalPe)) {
+ return null;
+ }
+
+ if (originalPe instanceof Shape) {
+ Shape shape = (Shape) originalPe;
+ ContainerShape container = shape.getContainer();
+ if (container instanceof Diagram || oldSelectList.contains(container)) {
+ return shape;
+ } else {
+ return findParentToBeSelected(container, oldSelection);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public PictogramElement getAlternativeSelection(PictogramElement originalPe, PictogramElement[] oldSelection) {
+ if (SketchUtil.isLonelyLanePe(originalPe)) {
+ if (originalPe instanceof ContainerShape) {
+ ContainerShape cs = (ContainerShape) originalPe;
+ return cs.getContainer();
+ }
+ }
+
+ return super.getAlternativeSelection(originalPe, oldSelection);
+ }
+
+ @Override
+ public GraphicsAlgorithm getChopboxAnchorGraphicsAlgorithm(PictogramElement pe) {
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ IGaService gaService = Graphiti.getGaService();
+ if (!gaService.isFilled(ga, true) && !gaService.isLineVisible(ga, true)) {
+ return ga.getGraphicsAlgorithmChildren().get(0);
+ } else
+ return super.getChopboxAnchorGraphicsAlgorithm(pe);
+ }
+
+ @Override
+ public ISelectionInfo getConnectionSelectionInfo(Connection connection) {
+ if (connection instanceof FreeFormConnection) {
+ return selectionInfo;
+ }
+ return super.getConnectionSelectionInfo(connection);
+ }
+
+ @Override
+ public IContextButtonPadData getContextButtonPadData(IPictogramElementContext context) {
+ IContextButtonPadData ret = super.getContextButtonPadData(context);
+ PictogramElement pictogramElement = context.getPictogramElement();
+ if (!SketchUtil.isLanePe(pictogramElement)) {
+ List<IContextButtonEntry> specificContextButtons = ret.getDomainSpecificContextButtons();
+ IFeatureProvider featureProvider = getFeatureProvider();
+ CustomContext customContext = new CustomContext(new PictogramElement[] { pictogramElement });
+ ICustomFeature[] customFeatures = featureProvider.getCustomFeatures(customContext);
+ ContextButtonEntry lineWidthFeatureButton = null;
+ ContextButtonEntry lineStyleFeatureButton = null;
+ ContextButtonEntry transparencyFeatureButton = null;
+ for (int i = 0; i < customFeatures.length; i++) {
+ ICustomFeature customFeature = customFeatures[i];
+ if (customFeature instanceof SketchFontFeature) {
+ // example for a collapse button
+ IContextButtonEntry collapseButton = ContextEntryHelper.createCollapseContextButton(true, customFeature, customContext);
+ ret.setCollapseContextButton(collapseButton);
+ } else if (customFeature.isAvailable(customContext)) {
+ ContextButtonEntry contextButtonEntry = new ContextButtonEntry(customFeature, customContext);
+ contextButtonEntry.setIconId(IPlatformImageConstants.IMG_ECLIPSE_QUICKASSIST);
+ if (customFeature instanceof LineWidthFeature) {
+ if (lineWidthFeatureButton == null) {
+ lineWidthFeatureButton = new ContextButtonEntry(null, null);
+ lineWidthFeatureButton.setText("Line width");
+ lineWidthFeatureButton.setDescription("Change line width");
+ lineWidthFeatureButton.setIconId(ISampleImageConstants.IMG_TREE_LEFT);
+ specificContextButtons.add(lineWidthFeatureButton);
+ }
+ lineWidthFeatureButton.getContextButtonMenuEntries().add(contextButtonEntry);
+ } else if (customFeature instanceof LineStyleFeature) {
+ if (lineStyleFeatureButton == null) {
+ lineStyleFeatureButton = new ContextButtonEntry(null, null);
+ lineStyleFeatureButton.setText("Line style");
+ lineStyleFeatureButton.setDescription("Change line style");
+ lineStyleFeatureButton.setIconId(ISampleImageConstants.IMG_TREE_LEFT);
+ specificContextButtons.add(lineStyleFeatureButton);
+ }
+ lineStyleFeatureButton.getContextButtonMenuEntries().add(contextButtonEntry);
+ } else if (customFeature instanceof TransparencyFeature) {
+ if (transparencyFeatureButton == null) {
+ transparencyFeatureButton = new ContextButtonEntry(null, null);
+ transparencyFeatureButton.setText("Transparency");
+ transparencyFeatureButton.setDescription("Change transparency");
+ transparencyFeatureButton.setIconId(ISampleImageConstants.IMG_TREE_RIGHT);
+ specificContextButtons.add(transparencyFeatureButton);
+ }
+ transparencyFeatureButton.getContextButtonMenuEntries().add(contextButtonEntry);
+ } else {
+ specificContextButtons.add(contextButtonEntry);
+ }
+ }
+ }
+
+ if (showCreateConnectionFeatures()) {
+ ICreateConnectionFeature[] createConnectionFeatures = featureProvider.getCreateConnectionFeatures();
+ ContextButtonEntry cbEntryForDnD = null;
+ for (int i = 0; i < createConnectionFeatures.length; i++) {
+ ICreateConnectionFeature createConnectionFeature = createConnectionFeatures[i];
+ if (createConnectionFeature.isAvailable(context)) {
+ if (cbEntryForDnD == null) {
+ cbEntryForDnD = new ContextButtonEntry(null, context);
+ cbEntryForDnD.setText("Create connection");
+ cbEntryForDnD.setIconId(IPlatformImageConstants.IMG_ECLIPSE_INFORMATION);
+ specificContextButtons.add(cbEntryForDnD);
+ }
+ cbEntryForDnD.addDragAndDropFeature(createConnectionFeature);
+
+ ContextButtonEntry cbe = new ContextButtonEntry(null, context);
+ cbe.addDragAndDropFeature(createConnectionFeature);
+ cbe.setText(createConnectionFeature.getCreateName());
+ cbe.setDescription(createConnectionFeature.getCreateDescription());
+ cbe.setIconId(IPlatformImageConstants.IMG_ECLIPSE_INFORMATION_TSK);
+ specificContextButtons.add(cbe);
+ }
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ protected boolean showCreateConnectionFeatures() {
+ return true;
+ }
+
+ @Override
+ public IContextMenuEntry[] getContextMenu(IContext context) {
+ IContextMenuEntry[] ret = NO_CONTEXT_MENU_ENTRIES;
+ List<IContextMenuEntry> retList = new ArrayList<IContextMenuEntry>();
+ for (int i = 0; i < ret.length; i++) {
+ retList.add(ret[i]);
+ }
+
+ // custom features
+ if (context instanceof ICustomContext) {
+ ICustomContext customContext = (ICustomContext) context;
+ ICustomFeature[] customFeatures = getFeatureProvider().getCustomFeatures(customContext);
+
+ // menu groups
+ ContextMenuEntry changeAlignmentEntry = null;
+ ContextMenuEntry changetTransparencyEntry = null;
+ ContextMenuEntry changetLineWidthEntry = null;
+ ContextMenuEntry changetLineStyleEntry = null;
+ ContextMenuEntry changetCornerDimensionEntry = null;
+ ContextMenuEntry setStyleEntry = null;
+
+ for (int i = 0; i < customFeatures.length; i++) {
+ ICustomFeature customFeature = customFeatures[i];
+ if (isContextMenuApplicable(customFeature)) {
+ ContextMenuEntry contextMenuEntry = new ContextMenuEntry(customFeature, context);
+ if (customFeature instanceof ChangeAlignmentFeature) {
+ if (changeAlignmentEntry == null) {
+ changeAlignmentEntry = new ContextMenuEntry(null, null);
+ changeAlignmentEntry.setSubmenu(true);
+ changeAlignmentEntry.setText("Text Alignment");
+ changeAlignmentEntry.setDescription("Change Text Alignment");
+ retList.add(changeAlignmentEntry);
+ }
+ changeAlignmentEntry.add(contextMenuEntry);
+ } else if (customFeature instanceof TransparencyFeature) {
+ if (changetTransparencyEntry == null) {
+ changetTransparencyEntry = new ContextMenuEntry(null, null);
+ changetTransparencyEntry.setSubmenu(true);
+ changetTransparencyEntry.setText("Transparency");
+ changetTransparencyEntry.setDescription("Change Shape Transparency");
+ retList.add(changetTransparencyEntry);
+ }
+ changetTransparencyEntry.add(contextMenuEntry);
+ } else if (customFeature instanceof LineWidthFeature) {
+ if (changetLineWidthEntry == null) {
+ changetLineWidthEntry = new ContextMenuEntry(null, null);
+ changetLineWidthEntry.setSubmenu(true);
+ changetLineWidthEntry.setText("Line Width");
+ changetLineWidthEntry.setDescription("Change Line Width");
+ retList.add(changetLineWidthEntry);
+ }
+ changetLineWidthEntry.add(contextMenuEntry);
+ } else if (customFeature instanceof LineStyleFeature) {
+ if (changetLineStyleEntry == null) {
+ changetLineStyleEntry = new ContextMenuEntry(null, null);
+ changetLineStyleEntry.setSubmenu(true);
+ changetLineStyleEntry.setText("Line Style");
+ changetLineStyleEntry.setDescription("Change Line Style");
+ retList.add(changetLineStyleEntry);
+ }
+ changetLineStyleEntry.add(contextMenuEntry);
+ } else if (customFeature instanceof CornerDimensionFeature) {
+ if (changetCornerDimensionEntry == null) {
+ changetCornerDimensionEntry = new ContextMenuEntry(null, null);
+ changetCornerDimensionEntry.setSubmenu(true);
+ changetCornerDimensionEntry.setText("Corner Dimension");
+ changetCornerDimensionEntry.setDescription("Change Corner Dimension");
+ retList.add(changetCornerDimensionEntry);
+ }
+ changetCornerDimensionEntry.add(contextMenuEntry);
+ } else if (customFeature instanceof SetStyleFeature) {
+ if (setStyleEntry == null) {
+ setStyleEntry = new ContextMenuEntry(null, null);
+ setStyleEntry.setSubmenu(true);
+ setStyleEntry.setText("Set Style");
+ setStyleEntry.setDescription("Set Shape's Style");
+ retList.add(setStyleEntry);
+ }
+ setStyleEntry.add(contextMenuEntry);
+ } else {
+ retList.add(contextMenuEntry);
+ }
+ }
+ }
+ }
+
+ ret = retList.toArray(NO_CONTEXT_MENU_ENTRIES);
+ return ret;
+ }
+
+ @Override
+ public IPaletteCompartmentEntry[] getPaletteCompartments() {
+ List<IPaletteCompartmentEntry> compartments = new ArrayList<IPaletteCompartmentEntry>();
+
+ {
+ final PaletteCompartmentEntry connectionsCompartmentEntry = new MyPaletteCompartmentEntry("Connections",
+ ICON_CONNECTION_COMPARTMENT);
+ connectionsCompartmentEntry.setInitiallyOpen(false);
+ compartments.add(connectionsCompartmentEntry);
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ ICreateConnectionFeature[] createConnectionFeatures = featureProvider.getCreateConnectionFeatures();
+ if (createConnectionFeatures.length > 0) {
+
+ ConnectionCreationToolEntry multiTool = null;
+ if (createConnectionFeatures.length > 1) {
+ multiTool = new ConnectionCreationToolEntry("Connection", "dynamic connection", null, null);
+ connectionsCompartmentEntry.addToolEntry(multiTool);
+ }
+
+ for (ICreateConnectionFeature createConnectionFeature : createConnectionFeatures) {
+ ConnectionCreationToolEntry ccTool = new ConnectionCreationToolEntry(createConnectionFeature.getCreateName(),
+ createConnectionFeature.getCreateDescription(), createConnectionFeature.getCreateImageId(),
+ createConnectionFeature.getCreateLargeImageId());
+ ccTool.addCreateConnectionFeature(createConnectionFeature);
+ if (multiTool != null) {
+ multiTool.addCreateConnectionFeature(createConnectionFeature);
+ }
+ connectionsCompartmentEntry.addToolEntry(ccTool);
+ }
+
+ }
+ }
+
+ {
+ final PaletteCompartmentEntry objectsCompartmentEntry = new PaletteCompartmentEntry("Objects", null);
+ objectsCompartmentEntry.setInitiallyOpen(true);
+ compartments.add(objectsCompartmentEntry);
+
+ IFeatureProvider featureProvider = getFeatureProvider();
+ ICreateFeature[] createFeatures = featureProvider.getCreateFeatures();
+
+ for (ICreateFeature createFeature : createFeatures) {
+ ObjectCreationToolEntry objectCreationToolEntry;
+ // create icon for the canFigure entry with an image descriptor
+ // instead an image id
+ if (createFeature instanceof SketchCreateCanFigureFeature) {
+ objectCreationToolEntry = new MyObjectCreationToolEntry(createFeature.getCreateName(), createFeature
+ .getCreateDescription(), createFeature, ICON_CAN_FIGURE);
+ } else {
+ objectCreationToolEntry = new ObjectCreationToolEntry(createFeature.getCreateName(), createFeature
+ .getCreateDescription(), createFeature.getCreateImageId(), createFeature.getCreateLargeImageId(), createFeature);
+ }
+ objectsCompartmentEntry.addToolEntry(objectCreationToolEntry);
+ }
+ }
+
+ return compartments.toArray(new IPaletteCompartmentEntry[compartments.size()]);
+ }
+
+ @Override
+ public IRenderingDecorator[] getRenderingDecorators(PictogramElement pe) {
+ if (!TEST_SHOW_WARNING_DECORATORS) {
+ return super.getRenderingDecorators(pe);
+ }
+ ImageRenderingDecorator rd = new ImageRenderingDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING);
+ int x = 22;
+ int y = 33;
+ rd.setX(x);
+ rd.setY(y);
+ rd.setMessage("Warning (x=" + x + " y=" + y + ")");
+
+ IRenderingDecorator[] ret = new IRenderingDecorator[] { rd };
+ return ret;
+ }
+
+ @Override
+ public GraphicsAlgorithm[] getSelectionArea(PictogramElement pe) {
+ GraphicsAlgorithm ghostGa = SketchUtil.getGhostGa(pe);
+ if (ghostGa != null) {
+ return ghostGa.getGraphicsAlgorithmChildren().toArray(new GraphicsAlgorithm[0]);
+ }
+ return super.getSelectionArea(pe);
+ }
+
+ @Override
+ public GraphicsAlgorithm getSelectionGraphicsAlgorithm(PictogramElement pe) {
+ GraphicsAlgorithm ghostGa = SketchUtil.getGhostGa(pe);
+ if (ghostGa != null) {
+ return ghostGa.getGraphicsAlgorithmChildren().get(0);
+ }
+ return super.getSelectionGraphicsAlgorithm(pe);
+ }
+
+ @Override
+ public ISelectionInfo getShapeSelectionInfo(Shape shape) {
+ if (shape instanceof ContainerShape) {
+ return selectionInfo;
+ }
+ return super.getShapeSelectionInfo(shape);
+ }
+
+ @Override
+ public String getToolTip(GraphicsAlgorithm ga) {
+ if (ga instanceof AbstractText && ga.getParentGraphicsAlgorithm() != null) {
+ return getToolTip(ga.getParentGraphicsAlgorithm());
+ } else {
+ final int x = ga.getX();
+ final int y = ga.getY();
+ final int width = ga.getWidth();
+ final int height = ga.getHeight();
+ String ret = ga.getClass().getSimpleName() + " (x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + ")";
+ return ret;
+ }
+ }
+
+ @Override
+ public double[] getZoomLevels() {
+ return ZOOM_LEVELS;
+ }
+
+ @Override
+ protected boolean isContextMenuApplicable(IFeature feature) {
+ // consider all custom features as candidates for the context menu
+ boolean ret = (feature instanceof ICustomFeature);
+ return ret;
+ }
+
+ @Override
+ public void postExecute(IExecutionInfo executionInfo) {
+ super.postExecute(executionInfo);
+
+ Graphiti.getPeService().moveBendpoints(executionInfo);
+ }
+
+ @Override
+ public void preExecute(IExecutionInfo executionInfo) {
+ super.preExecute(executionInfo);
+ }
+
+ @Override
+ public GraphicsAlgorithm getContentGraphicsAlgorithm(ContainerShape cs) {
+ if (cs != null && cs.getGraphicsAlgorithm() != null && SketchUtil.isContainer(cs) && SketchUtil.isGhost(cs)) {
+ if (SketchUtil.isRectangle(cs) || SketchUtil.isRoundedRectangle(cs)) {
+ List<GraphicsAlgorithm> gaChildren = cs.getGraphicsAlgorithm().getGraphicsAlgorithmChildren();
+ if (gaChildren != null && gaChildren.size() == 2) {
+ GraphicsAlgorithm ga = gaChildren.get(0);
+ if (ga instanceof Rectangle || ga instanceof RoundedRectangle) {
+ return ga;
+ }
+ }
+ }
+ }
+ return super.getContentGraphicsAlgorithm(cs);
+ }
+
+ public String getName() {
+ return "Edit Mode";
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchUtil.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchUtil.java
new file mode 100644
index 0000000..a8a520a
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchUtil.java
@@ -0,0 +1,181 @@
+package org.eclipse.graphiti.sample.sketch;
+
+import java.util.List;
+
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchUtil.
+ */
+public class SketchUtil {
+
+ /**
+ * The Constant POOL_TAG.
+ */
+ public static final String POOL_TAG = "POOL"; //$NON-NLS-1$
+
+ /**
+ * The Constant LANE_TAG.
+ */
+ public static final String LANE_TAG = "LANE"; //$NON-NLS-1$
+
+ public static final String GHOST_TAG = "GHOST_TAG"; //$NON-NLS-1$
+ public static final String CONTAINER_TAG = "CONTAINER_TAG"; //$NON-NLS-1$
+ public static final String GA_TAG = "GA_TAG"; //$NON-NLS-1$
+
+ // values for key GA_TAG
+ public static final String GA_RECTANGLE = "GA_RECTANGLE"; //$NON-NLS-1$
+ public static final String GA_ROUNDED_RECTANGLE = "GA_ROUNDED_RECTANGLE"; //$NON-NLS-1$
+ public static final String GA_ELLIPSE = "GA_ELLIPSE"; //$NON-NLS-1$
+
+ /**
+ * Gets the current label value.
+ *
+ * @param containerPe
+ * the container pe
+ *
+ * @return the current label value
+ */
+ public static String getCurrentLabelValue(PictogramElement containerPe) {
+
+ String ret = ""; //$NON-NLS-1$
+
+ AbstractText text = getLabelGa(containerPe);
+ if (text != null) {
+ ret = text.getValue();
+ }
+
+ return ret;
+ }
+
+ /**
+ * Sets the current label value.
+ *
+ * @param containerPe
+ * the container pe
+ * @param newValue
+ * the new value
+ */
+ public static void setCurrentLabelValue(PictogramElement containerPe, String newValue) {
+
+ AbstractText text = getLabelGa(containerPe);
+ if (text != null) {
+ text.setValue(newValue);
+ }
+ }
+
+ /**
+ * Gets the label ga.
+ *
+ * @param containerPe
+ * the container pe
+ *
+ * @return the label ga
+ */
+ public static AbstractText getLabelGa(PictogramElement containerPe) {
+
+ AbstractText ret = null;
+ List<GraphicsAlgorithm> children = containerPe.getGraphicsAlgorithm().getGraphicsAlgorithmChildren();
+ if (children.size() > 0) {
+ GraphicsAlgorithm ga = children.get(0);
+ if (ga instanceof AbstractText) {
+ ret = (AbstractText) ga;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Checks if is pool pe.
+ *
+ * @param pe
+ * the pe
+ *
+ * @return true, if is pool pe
+ */
+ public static boolean isPoolPe(PictogramElement pe) {
+ return Graphiti.getPeService().getProperty(pe, POOL_TAG) != null;
+ }
+
+ /**
+ * Checks if is lane pe.
+ *
+ * @param pe
+ * the pe
+ *
+ * @return true, if is lane pe
+ */
+ public static boolean isLanePe(PictogramElement pe) {
+ return Graphiti.getPeService().getProperty(pe, LANE_TAG) != null;
+ }
+
+ /**
+ * Checks if is lonely lane pe.
+ *
+ * @param pe
+ * the pe
+ *
+ * @return true, if is lonely lane pe
+ */
+ public static boolean isLonelyLanePe(PictogramElement pe) {
+ boolean isLane = isLanePe(pe);
+ if (isLane && pe instanceof ContainerShape) {
+ ContainerShape cs = (ContainerShape) pe;
+ ContainerShape container = cs.getContainer();
+ if (isPoolPe(container)) {
+ List<Shape> children = container.getChildren();
+ int laneCounter = 0;
+ for (Object child : children) {
+ if (child instanceof PictogramElement) {
+ PictogramElement childPe = (PictogramElement) child;
+ if (isLanePe(childPe)) {
+ laneCounter++;
+ }
+ }
+ }
+ return laneCounter == 1;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Gets the ghost ga.
+ *
+ * @param pictogramElement
+ * the pictogram element
+ *
+ * @return the ghost ga
+ */
+ public static GraphicsAlgorithm getGhostGa(PictogramElement pictogramElement) {
+ final GraphicsAlgorithm potGhostGa = pictogramElement.getGraphicsAlgorithm();
+ final List<GraphicsAlgorithm> gaChildren = potGhostGa.getGraphicsAlgorithmChildren();
+ if (gaChildren.size() == 2) {
+ if (gaChildren.get(1) instanceof AbstractText) {
+ return potGhostGa;
+ }
+ }
+ return null;
+ }
+
+ public static boolean isGhost(PictogramElement pe) {
+ return Graphiti.getPeService().getProperty(pe, GHOST_TAG) != null;
+ }
+
+ public static boolean isContainer(PictogramElement pe) {
+ return Graphiti.getPeService().getProperty(pe, CONTAINER_TAG) != null;
+ }
+
+ public static boolean isRectangle(PictogramElement pe) {
+ return GA_RECTANGLE.equals(Graphiti.getPeService().getPropertyValue(pe, GA_TAG));
+ }
+
+ public static boolean isRoundedRectangle(PictogramElement pe) {
+ return GA_ROUNDED_RECTANGLE.equals(Graphiti.getPeService().getPropertyValue(pe, GA_TAG));
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchViewerModeChecker.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchViewerModeChecker.java
new file mode 100644
index 0000000..7a50558
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchViewerModeChecker.java
@@ -0,0 +1,9 @@
+package org.eclipse.graphiti.sample.sketch;
+
+
+public class SketchViewerModeChecker extends ViewerModeChecker {
+
+ public SketchViewerModeChecker() {
+ super();
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchViewerModeToolBehavior.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchViewerModeToolBehavior.java
new file mode 100644
index 0000000..8a25e6a
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/SketchViewerModeToolBehavior.java
@@ -0,0 +1,55 @@
+package org.eclipse.graphiti.sample.sketch;
+
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeature;
+import org.eclipse.graphiti.features.IFeatureChecker;
+import org.eclipse.graphiti.features.IFeatureCheckerHolder;
+import org.eclipse.graphiti.palette.IPaletteCompartmentEntry;
+
+public class SketchViewerModeToolBehavior extends SketchToolBehaviour implements IFeatureCheckerHolder {
+
+ private static final double[] ZOOM_LEVELS = new double[] { 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 3, 4, 5 };
+ private IFeatureChecker featureChecker;
+
+ public SketchViewerModeToolBehavior(IDiagramTypeProvider diagramTypeProvider) {
+ super(diagramTypeProvider);
+ }
+
+ @Override
+ protected boolean showCreateConnectionFeatures() {
+ return false;
+ }
+
+ @Override
+ public IPaletteCompartmentEntry[] getPaletteCompartments() {
+ return new IPaletteCompartmentEntry[0];
+ }
+
+ @Override
+ public double[] getZoomLevels() {
+ return ZOOM_LEVELS;
+ }
+
+ @Override
+ public boolean isPaletteApplicable(IFeature feature) {
+ return false;
+ }
+
+ @Override
+ public boolean isToolbarApplicable(IFeature feature) {
+ return false;
+ }
+
+ @Override
+ public String getName() {
+ return "Viewer Mode";
+ }
+
+ public IFeatureChecker getFeatureChecker() {
+ if (featureChecker == null) {
+ featureChecker = new SketchViewerModeChecker();
+
+ }
+ return featureChecker;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/ViewerModeChecker.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/ViewerModeChecker.java
new file mode 100644
index 0000000..fe7a8e4
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/ViewerModeChecker.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch;
+
+import org.eclipse.graphiti.features.FeatureCheckerAdapter;
+import org.eclipse.graphiti.features.IFeature;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.impl.CustomContext;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.sample.sketch.features.SwitchModeFeature;
+
+public class ViewerModeChecker extends FeatureCheckerAdapter {
+
+ public ViewerModeChecker() {
+ super(false);
+ }
+
+ @Override
+ public boolean allow(IFeature feature, IContext context) {
+ if (feature instanceof SwitchModeFeature) {
+ if (context instanceof CustomContext) {
+ CustomContext cc = (CustomContext) context;
+ PictogramElement[] pes = cc.getPictogramElements();
+ return pes[0] instanceof Diagram;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean allowCustomFeatures(ICustomContext context) {
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AbstractColorFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AbstractColorFeature.java
new file mode 100644
index 0000000..2e566b4
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AbstractColorFeature.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+/**
+ * The Class AbstractColorFeature.
+ */
+public abstract class AbstractColorFeature extends AbstractCustomFeature {
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public AbstractColorFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.sap.tc.emf.gfw.dt.jmof.features.custom.AbstractColorFeature#isAvailable(com.sap.tc.emf.gfw.features.context.ICustomContext)
+ */
+ @Override
+ public boolean isAvailable(IContext context) {
+ boolean ret = false;
+ if (context instanceof ICustomContext) {
+ PictogramElement[] pes = ((ICustomContext) context).getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ ret = true;
+ for (int i = 0; ret && i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe instanceof Shape && !(pe instanceof Diagram)) {
+ Shape s = (Shape) pe;
+ GraphicsAlgorithm ga = s.getGraphicsAlgorithm();
+ if (ga != null) {
+ ret = true;
+ }
+ }
+ }
+ }
+ }
+ return ret;
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddAnythingFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddAnythingFeature.java
new file mode 100644
index 0000000..319f34a
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddAnythingFeature.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.mm.pictograms.Text;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class AddAnythingFeature.
+ */
+public class AddAnythingFeature extends AbstractAddFeature {
+
+ /**
+ * Instantiates a new adds the anything feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public AddAnythingFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public PictogramElement add(IAddContext context) {
+ Object newObject = context.getNewObject();
+ Shape shape = Graphiti.getPeCreateService().createShape(context.getTargetContainer(), true);
+
+ IGaService gaService = Graphiti.getGaService();
+ Rectangle r = gaService.createRectangle(shape);
+ gaService.setLocationAndSize(r, context.getX(), context.getY(), 400, 100);
+ r.setBackground(gaService.manageColor(getDiagram(), IColorConstant.WHITE));
+
+ String text = newObject.getClass().getName() + " - " + newObject.toString();
+ Text textGa = gaService.createDefaultText(r, text);
+ gaService.setLocationAndSize(textGa, 0, 0, 400, 100);
+ textGa.setAngle(-1);
+
+ return shape;
+ }
+
+ public boolean canAdd(IAddContext context) {
+ return context.getTargetContainer() != null;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddDiagramFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddDiagramFeature.java
new file mode 100644
index 0000000..c228ac5
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddDiagramFeature.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.Collection;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+/**
+ * The Class AddDiagramFeature.
+ */
+public class AddDiagramFeature extends AbstractAddShapeFeature {
+
+ /**
+ * Instantiates a new adds the diagram feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public AddDiagramFeature(IFeatureProvider fp) {
+ super(fp);
+ // TODO Auto-generated constructor stub
+ }
+
+ public PictogramElement add(IAddContext context) {
+ ((Collection) context.getTargetContainer().getChildren()).add(context.getNewObject());
+ return null;
+ }
+
+ public boolean canAdd(IAddContext context) {
+ if (context.getTargetContainer() != null && context.getNewObject() instanceof Diagram) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddLinkFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddLinkFeature.java
new file mode 100644
index 0000000..49d14e3
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/AddLinkFeature.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.impl.AbstractAddFeature;
+import org.eclipse.graphiti.mm.links.LinksFactory;
+import org.eclipse.graphiti.mm.links.PictogramLink;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The Class AddLinkFeature.
+ */
+public class AddLinkFeature extends AbstractAddFeature {
+
+ /**
+ * Instantiates a new adds the link feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public AddLinkFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public boolean canAdd(IAddContext context) {
+ boolean ret = false;
+ Object newObject = context.getNewObject();
+ if (newObject instanceof EObject) {
+ ret = true;
+ }
+ return ret;
+ }
+
+ public PictogramElement add(IAddContext context) {
+ Object newObject = context.getNewObject();
+ if (newObject instanceof EObject) {
+ boolean sure = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Are you sure?",
+ "Do you really want to link the object?");
+ if (sure) {
+ URI uri = EcoreUtil.getURI((EObject) newObject);
+ EObject newEObject = getDiagramEditor().getResourceSet().getEObject(uri, true);
+ ContainerShape targetContainer = context.getTargetContainer();
+ PictogramLink link = Graphiti.getLinkService().getLinkForPictogramElement(targetContainer);
+ if (link == null) {
+ link = LinksFactory.eINSTANCE.createPictogramLink();
+ link.setPictogramElement(targetContainer);
+ }
+ link.getBusinessObjects().add(newEObject);
+ return targetContainer;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/BackgroundColorFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/BackgroundColorFeature.java
new file mode 100644
index 0000000..6969775
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/BackgroundColorFeature.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.examples.common.SampleUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.mm.datatypes.Color;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class BackgroundColorFeature.
+ */
+public class BackgroundColorFeature extends AbstractColorFeature {
+
+ private static final String NAME = "Background Color...";
+
+ private static final String DESCRIPTION = "Modify Background Color";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public BackgroundColorFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ boolean ret = false;
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ if (ga.getBackground() != null) {
+ ret = true;
+ } else {
+ Style style = ga.getStyle();
+ if (style != null) {
+ if (style.getBackground() != null) {
+ ret = true;
+ }
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ Color newColor;
+ {
+ Color oldBackground = Graphiti.getGaService().getBackgroundColor(ga, true);
+ newColor = SampleUtil.editColor(oldBackground);
+ if (newColor == null) {
+ return;
+ }
+ }
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm currentGa = pe.getGraphicsAlgorithm();
+ if (currentGa.getBackground() != null) {
+ currentGa.setBackground(newColor);
+ } else {
+ currentGa.getStyle().setBackground(newColor);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ChangeAlignmentFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ChangeAlignmentFeature.java
new file mode 100644
index 0000000..f7d4bb4
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ChangeAlignmentFeature.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.MultiText;
+import org.eclipse.graphiti.mm.pictograms.Orientation;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class ChangeAlignmentFeature.
+ */
+public class ChangeAlignmentFeature extends AbstractCustomFeature {
+
+ private String name;
+
+ private Orientation hTextOrientation;
+
+ private Orientation vTextOrientation;
+
+ /**
+ * Instantiates a new change alignment feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param hTextOrientation
+ * the h text orientation
+ * @param vTextOrientation
+ * the v text orientation
+ */
+ public ChangeAlignmentFeature(IFeatureProvider fp, String name, Orientation hTextOrientation, Orientation vTextOrientation) {
+ super(fp);
+ this.name = name;
+ this.hTextOrientation = hTextOrientation;
+ this.vTextOrientation = vTextOrientation;
+ }
+
+ public void execute(ICustomContext context) {
+ MultiText text = (MultiText) context.getInnerGraphicsAlgorithm();
+ if (hTextOrientation != null) {
+ text.setHorizontalAlignment(hTextOrientation);
+ }
+ if (vTextOrientation != null) {
+ text.setVerticalAlignment(vTextOrientation);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ MultiText text = (MultiText) context.getInnerGraphicsAlgorithm();
+ if (hTextOrientation != null && !hTextOrientation.equals(Graphiti.getGaService().getHorizontalAlignment(text, true))) {
+ return true;
+ }
+ if (vTextOrientation != null && !vTextOrientation.equals(Graphiti.getGaService().getVerticalAlignment(text, true))) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ if (context instanceof ICustomContext) {
+ ICustomContext customContext = (ICustomContext) context;
+ GraphicsAlgorithm innerGraphicsAlgorithm = customContext.getInnerGraphicsAlgorithm();
+ if (innerGraphicsAlgorithm instanceof MultiText) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/CornerDimensionFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/CornerDimensionFeature.java
new file mode 100644
index 0000000..2f98b1d
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/CornerDimensionFeature.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.RoundedRectangle;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+/**
+ * The Class CornerDimensionFeature.
+ */
+public class CornerDimensionFeature extends AbstractCustomFeature {
+
+ /**
+ * The dimension.
+ */
+ Dimension dimension;
+
+ /**
+ * Instantiates a new corner dimension feature.
+ *
+ * @param fp
+ * the fp
+ * @param dimension
+ * the dimension
+ */
+ public CornerDimensionFeature(IFeatureProvider fp, Dimension dimension) {
+ super(fp);
+ this.dimension = dimension;
+ }
+
+ @Override
+ public String getName() {
+ return "(w=" + dimension.width + ", h=" + dimension.height + ")";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ return true;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe != null && pe.getGraphicsAlgorithm() != null) {
+ RoundedRectangle rect = (RoundedRectangle) pe.getGraphicsAlgorithm();
+ rect.setCornerWidth(dimension.width);
+ rect.setCornerHeight(dimension.height);
+ }
+ }
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ boolean ret = false;
+ if (context instanceof ICustomContext) {
+ PictogramElement[] pes = ((ICustomContext) context).getPictogramElements();
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe instanceof Shape && pe.getGraphicsAlgorithm() instanceof RoundedRectangle && !(pe instanceof Diagram)) {
+ ret = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return ret;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/FontColorFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/FontColorFeature.java
new file mode 100644
index 0000000..f5d0ad8
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/FontColorFeature.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.examples.common.SampleUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.mm.datatypes.Color;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class FontColorFeature.
+ */
+public class FontColorFeature extends AbstractColorFeature {
+
+ private static final String NAME = "Font Color...";
+
+ private static final String DESCRIPTION = "Modify Font Color";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public FontColorFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ for (PictogramElement pe : pes) {
+ if (SketchUtil.getLabelGa(pe) == null) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+
+ Color oldColor;
+ if (pes.length > 1) {
+ oldColor = manageColor(IColorConstant.BLACK);
+ } else {
+ AbstractText ga = SketchUtil.getLabelGa(pes[0]);
+ oldColor = ga.getForeground();
+ }
+
+ Color newColor = SampleUtil.editColor(oldColor);
+ if (newColor != null) {
+ for (PictogramElement pe : pes) {
+ AbstractText ga = SketchUtil.getLabelGa(pe);
+ ga.setForeground(newColor);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ForegroundColorFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ForegroundColorFeature.java
new file mode 100644
index 0000000..882f30b
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ForegroundColorFeature.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.examples.common.SampleUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.mm.datatypes.Color;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class ForegroundColorFeature.
+ */
+public class ForegroundColorFeature extends AbstractColorFeature {
+
+ private static final String NAME = "Foreground Color...";
+
+ private static final String DESCRIPTION = "Modify Foreground Color";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public ForegroundColorFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ boolean ret = false;
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ if (ga.getForeground() != null) {
+ ret = true;
+ } else {
+ Style style = ga.getStyle();
+ if (style != null) {
+ if (style.getForeground() != null) {
+ ret = true;
+ }
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ Color newColor;
+ {
+ Color oldForeground = Graphiti.getGaService().getForegroundColor(ga, true);
+ newColor = SampleUtil.editColor(oldForeground);
+ if (newColor == null) {
+ return;
+ }
+ }
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm currentGa = pe.getGraphicsAlgorithm();
+ if (currentGa.getForeground() != null) {
+ currentGa.setForeground(newColor);
+ } else {
+ currentGa.getStyle().setForeground(newColor);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/GradientColorFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/GradientColorFeature.java
new file mode 100644
index 0000000..17a0036
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/GradientColorFeature.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.graphiti.examples.common.SampleUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.util.IPredefinedRenderingStyle;
+
+/**
+ * The Class GradientColorFeature.
+ */
+public class GradientColorFeature extends AbstractColorFeature {
+
+ private static final String NAME = "Gradient Color...";
+
+ private static final String DESCRIPTION = "Modify Gradient Color";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public GradientColorFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ boolean ret = false;
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ ret = true;
+ }
+ }
+ return ret;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ // init with default-values
+ String id = IPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID;
+
+ {
+ // ask user for new values
+ while (true) {
+ List<String> allIDs = Arrays.asList(IPredefinedRenderingStyle.ALL_IDS);
+ String askString = SampleUtil.askString("Enter gradient values",
+ "Enter the predefined style ID here. The following IDs are supported: " + allIDs, id);
+ if (askString == null) {
+ return;
+ }
+ if (allIDs.contains(askString)) {
+ id = askString;
+ break;
+ }
+ }
+ }
+
+ // set new values to all selected pictogram-elements
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm currentGa = pe.getGraphicsAlgorithm();
+ Graphiti.getGaService().setRenderingStyle(currentGa, id);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LayoutContainerShapeGhostAndInnerShapeFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LayoutContainerShapeGhostAndInnerShapeFeature.java
new file mode 100644
index 0000000..fd9a12e
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LayoutContainerShapeGhostAndInnerShapeFeature.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.datatypes.IDimension;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+
+/**
+ * The Class LayoutContainerShapeGhostAndInnerShapeFeature.
+ */
+public class LayoutContainerShapeGhostAndInnerShapeFeature extends AbstractLayoutFeature {
+ private static final int INSET = 30;
+
+ /**
+ * Instantiates a new layout container shape ghost and inner shape feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public LayoutContainerShapeGhostAndInnerShapeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public boolean canLayout(ILayoutContext context) {
+ boolean ret = context.getPictogramElement() instanceof ContainerShape;
+ return ret;
+ }
+
+ public boolean layout(ILayoutContext context) {
+ ContainerShape cs = (ContainerShape) context.getPictogramElement();
+ IGaService gaService=Graphiti.getGaService();
+ GraphicsAlgorithm ghost = cs.getGraphicsAlgorithm();
+ IDimension ghostSize = gaService.calculateSize(ghost);
+ int ghostWidth = ghostSize.getWidth();
+ int ghostHeight = ghostSize.getHeight();
+ gaService.setLocationAndSize(ghost.getGraphicsAlgorithmChildren().get(0), INSET, INSET, ghostWidth - INSET - INSET,
+ ghostHeight - INSET - INSET);
+
+ Shape innerShape = cs.getChildren().get(0);
+ int width = INSET;
+ int height = width;
+ int x = (ghostWidth - width) / 2;
+ int y = INSET - (height / 2);
+ gaService.setLocationAndSize(innerShape.getGraphicsAlgorithm(), x, y, width, height);
+
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LineStyleFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LineStyleFeature.java
new file mode 100644
index 0000000..78f305f
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LineStyleFeature.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.LineStyle;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class LineWidthFeature.
+ */
+public class LineStyleFeature extends AbstractCustomFeature {
+
+ /**
+ * The line style.
+ */
+ private LineStyle lineStyle;
+
+ /**
+ * Instantiates a new line width feature.
+ *
+ * @param fp
+ * the fp
+ * @param lineWidth
+ * the line style
+ */
+ public LineStyleFeature(IFeatureProvider fp, LineStyle lineStyle) {
+ super(fp);
+ this.lineStyle = lineStyle;
+ }
+
+ public void execute(ICustomContext context) {
+
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe != null && pe.getGraphicsAlgorithm() != null) {
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ if (ga.getLineStyle() != null) {
+ Style style = ga.getStyle();
+ if (style != null) {
+ style.setLineStyle(lineStyle);
+ } else {
+ ga.setLineStyle(lineStyle);
+ }
+ } else {
+ ga.setLineStyle(lineStyle);
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getName() {
+ return getLineStyleName(lineStyle);
+ }
+
+ private static String getLineStyleName(LineStyle lineStyle) {
+ return lineStyle.toString().toLowerCase();
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ boolean ret = false;
+ if (context instanceof ICustomContext) {
+ PictogramElement[] pes = ((ICustomContext) context).getPictogramElements();
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe instanceof Shape && pe.getGraphicsAlgorithm() != null && !(pe instanceof Diagram)) {
+ ret = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement pe = context.getPictogramElements()[0];
+ if (pe != null && pe.getGraphicsAlgorithm() != null) {
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ LineStyle currentLineStyle = Graphiti.getGaService().getLineStyle(ga, true);
+ return currentLineStyle != lineStyle;
+ }
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LineWidthFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LineWidthFeature.java
new file mode 100644
index 0000000..678842c
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/LineWidthFeature.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class LineWidthFeature.
+ */
+public class LineWidthFeature extends AbstractCustomFeature {
+
+ private static final String UNIT = " px";
+
+ /**
+ * The line width.
+ */
+ int lineWidth;
+
+ /**
+ * Instantiates a new line width feature.
+ *
+ * @param fp
+ * the fp
+ * @param lineWidth
+ * the line width
+ */
+ public LineWidthFeature(IFeatureProvider fp, int lineWidth) {
+ super(fp);
+ this.lineWidth = lineWidth;
+ }
+
+ public void execute(ICustomContext context) {
+
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe != null && pe.getGraphicsAlgorithm() != null) {
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ if (ga.getLineWidth() != null) {
+ Style style = ga.getStyle();
+ if (style != null) {
+ style.setLineWidth(lineWidth);
+ } else {
+ ga.setLineWidth(lineWidth);
+ }
+ } else {
+ ga.setLineWidth(lineWidth);
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getName() {
+ return Integer.toString(lineWidth) + UNIT;
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ boolean ret = false;
+ if (context instanceof ICustomContext) {
+ PictogramElement[] pes = ((ICustomContext) context).getPictogramElements();
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe instanceof Shape && pe.getGraphicsAlgorithm() != null && !(pe instanceof Diagram)) {
+ ret = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement pe = context.getPictogramElements()[0];
+ if (pe != null && pe.getGraphicsAlgorithm() != null) {
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ int currentLineWidth = Graphiti.getGaService().getLineWidth(ga, true);
+ return currentLineWidth != lineWidth;
+ }
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SendToBackFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SendToBackFeature.java
new file mode 100644
index 0000000..f866917
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SendToBackFeature.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.List;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class BackgroundColorFeature.
+ */
+public class SendToBackFeature extends AbstractCustomFeature {
+
+ private static final String NAME = "Send to back";
+
+ private static final String DESCRIPTION = "Send to the back";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public SendToBackFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ boolean ret = false;
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ PictogramElement pe = pes[0];
+ if (pe instanceof Shape) {
+ Shape shape = (Shape) pe;
+ ContainerShape containerShape = shape.getContainer();
+ if (containerShape != null) {
+ List<Shape> childList = containerShape.getChildren();
+ if (childList.size() > 1 && childList.indexOf(shape) > 0) {
+ return true;
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ PictogramElement pe = pes[0];
+ if (pe instanceof Shape) {
+ Shape shape = (Shape) pe;
+ ContainerShape containerShape = shape.getContainer();
+ List<Shape> childList = containerShape.getChildren();
+ if (childList.size() > 1 && childList.indexOf(shape) > 0) {
+ Graphiti.getPeService().sendToBack(shape);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SendToFrontFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SendToFrontFeature.java
new file mode 100644
index 0000000..d6808cc
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SendToFrontFeature.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+/*
+ * Created on 12.12.2005
+ */
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.List;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class BackgroundColorFeature.
+ */
+public class SendToFrontFeature extends AbstractCustomFeature {
+
+ private static final String NAME = "Send to front";
+
+ private static final String DESCRIPTION = "Send to the front";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public SendToFrontFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ boolean ret = false;
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ PictogramElement pe = pes[0];
+ if (pe instanceof Shape) {
+ Shape shape = (Shape) pe;
+ ContainerShape containerShape = shape.getContainer();
+ if (containerShape != null) {
+ List<Shape> childList = containerShape.getChildren();
+ int size = childList.size();
+ int index = childList.indexOf(shape);
+ if (size > 1 && index < size - 1) {
+ return true;
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes != null && pes.length == 1) {
+ PictogramElement pe = pes[0];
+ if (pe instanceof Shape) {
+ Shape shape = (Shape) pe;
+ ContainerShape containerShape = shape.getContainer();
+ List<Shape> childList = containerShape.getChildren();
+ int size = childList.size();
+ int index = childList.indexOf(shape);
+ if (size > 1 && index < size) {
+ Graphiti.getPeService().sendToFront(shape);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchDeleteFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchDeleteFeature.java
new file mode 100644
index 0000000..bd32e01
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchDeleteFeature.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
+
+/**
+ * The Class SketchDeleteFeature.
+ */
+public class SketchDeleteFeature extends DefaultDeleteFeature {
+
+ /**
+ * Instantiates a new sketch delete feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchDeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ final PictogramElement pe = context.getPictogramElement();
+ final Object bo = getBusinessObjectForPictogramElement(pe);
+ if (bo != null) {
+ return super.canDelete(context);
+ }
+ return false;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchFontFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchFontFeature.java
new file mode 100644
index 0000000..85bf734
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchFontFeature.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.examples.common.ColoredFont;
+import org.eclipse.graphiti.examples.common.SampleUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.datatypes.Color;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.Font;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchFontFeature.
+ */
+public class SketchFontFeature extends AbstractCustomFeature {
+
+ private static final String NAME = "Font...";
+
+ private static final String DESCRIPTION = "Modify Font";
+
+ /**
+ * The Constructor.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchFontFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ return true;
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+
+ AbstractText textGa = SketchUtil.getLabelGa(pes[0]);
+
+ Font font = textGa.getFont();
+ Color fgColor = textGa.getForeground();
+ ColoredFont coloredFont = SampleUtil.editFont(textGa, new ColoredFont(font, fgColor), getDiagram());
+ if (coloredFont == null) {
+ return; // cancel in dialog
+ }
+ Font f = coloredFont.getFont();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe != null) {
+ textGa = SketchUtil.getLabelGa(pe);
+ if (textGa != null) {
+ Font clonedFont = Graphiti.getGaCreateService().createFont(textGa, f.getName(), f.getSize(), f.isItalic(), f.isBold());
+ textGa.setFont(clonedFont);
+ textGa.setForeground(coloredFont.getColor());
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ boolean ret = false;
+ if (context instanceof ICustomContext) {
+ PictogramElement[] pes = ((ICustomContext) context).getPictogramElements();
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (SketchUtil.getLabelGa(pe) != null) {
+ ret = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return ret;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchGhostLayoutFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchGhostLayoutFeature.java
new file mode 100644
index 0000000..866fd2b
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchGhostLayoutFeature.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.List;
+
+import org.eclipse.graphiti.datatypes.IDimension;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+
+/**
+ * The Class SketchGhostLayoutFeature.
+ */
+public class SketchGhostLayoutFeature extends AbstractLayoutFeature {
+
+ /**
+ * The TOP.
+ */
+ public static int TOP = 10;
+
+ /**
+ * The BOTTOM.
+ */
+ public static int BOTTOM = 10;
+
+ /**
+ * The LEFT.
+ */
+ public static int LEFT = 10;
+
+ /**
+ * The RIGHT.
+ */
+ public static int RIGHT = 10;
+
+ /**
+ * The DIST.
+ */
+ public static int DIST = 10;
+
+ /**
+ * Instantiates a new sketch ghost layout feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchGhostLayoutFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public boolean canLayout(ILayoutContext context) {
+ boolean ret = (SketchUtil.getGhostGa(context.getPictogramElement()) != null);
+ return ret;
+ }
+
+ public boolean layout(ILayoutContext context) {
+ IGaService gaService=Graphiti.getGaService();
+ final PictogramElement pe = context.getPictogramElement();
+ GraphicsAlgorithm containerGa = pe.getGraphicsAlgorithm();
+ final List<GraphicsAlgorithm> gaChildren = containerGa.getGraphicsAlgorithmChildren();
+ if (SketchUtil.getGhostGa(pe) != null) {
+ final IDimension containerGaSize = gaService.calculateSize(containerGa);
+ final int containerWidth = containerGaSize.getWidth();
+ final int containerHeight = containerGaSize.getHeight();
+ final GraphicsAlgorithm firstGa = gaChildren.get(0);
+ final GraphicsAlgorithm textGa = gaChildren.get(1);
+ final int textHeight = 20; // textGa.getHeight();
+
+ // first GA
+ gaService.setLocationAndSize(firstGa, LEFT, TOP, containerWidth - LEFT - RIGHT, containerHeight - TOP - BOTTOM
+ - DIST - textHeight, true);
+ final List<GraphicsAlgorithm> firstGaChildren = firstGa.getGraphicsAlgorithmChildren();
+ if (!firstGaChildren.isEmpty()) {
+ final GraphicsAlgorithm innerFirstGa = firstGaChildren.get(0);
+ final int innerDistX = gaService.calculateSize(firstGa).getWidth() / 8;
+ final int innerDistY = gaService.calculateSize(firstGa).getHeight() / 8;
+ gaService.setLocationAndSize(innerFirstGa, innerDistX, innerDistY, firstGa.getWidth() - (2 * innerDistX),
+ firstGa.getHeight() - (2 * innerDistY));
+ }
+
+ // text GA
+ gaService.setSize(textGa, containerWidth - LEFT - RIGHT, textHeight);
+ gaService.setLocation(textGa, LEFT, containerHeight - BOTTOM - textHeight, true);
+ }
+
+ AbstractText text = SketchUtil.getLabelGa(pe);
+ if (text != null) {
+ gaService.setSize(text, containerGa.getWidth(), containerGa.getHeight());
+ }
+
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchLabelDirectEditingFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchLabelDirectEditingFeature.java
new file mode 100644
index 0000000..727c4c8
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchLabelDirectEditingFeature.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IDirectEditingContext;
+import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+
+/**
+ * The Class SketchLabelDirectEditingFeature.
+ */
+public class SketchLabelDirectEditingFeature extends AbstractDirectEditingFeature {
+
+ /**
+ * Instantiates a new sketch label direct editing feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchLabelDirectEditingFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public int getEditingType() {
+ return TYPE_MULTILINETEXT;
+ }
+
+ public String getInitialValue(IDirectEditingContext context) {
+ return SketchUtil.getCurrentLabelValue(context.getPictogramElement());
+ }
+
+ public void setValue(String value, IDirectEditingContext context) {
+ SketchUtil.setCurrentLabelValue(context.getPictogramElement(), value);
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchLayoutFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchLayoutFeature.java
new file mode 100644
index 0000000..c3b37d8
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchLayoutFeature.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.List;
+
+import org.eclipse.graphiti.datatypes.IDimension;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+
+/**
+ * The Class SketchLayoutFeature.
+ */
+public class SketchLayoutFeature extends AbstractLayoutFeature {
+
+ /**
+ * The TOP.
+ */
+ public static int TOP = 10;
+
+ /**
+ * The BOTTOM.
+ */
+ public static int BOTTOM = 10;
+
+ /**
+ * The LEFT.
+ */
+ public static int LEFT = 10;
+
+ /**
+ * The RIGHT.
+ */
+ public static int RIGHT = 10;
+
+ /**
+ * The DIST.
+ */
+ public static int DIST = 10;
+
+ /**
+ * Instantiates a new sketch layout feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchLayoutFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public boolean canLayout(ILayoutContext context) {
+ boolean ret = (SketchUtil.getLabelGa(context.getPictogramElement()) != null);
+ return ret;
+ }
+
+ public boolean layout(ILayoutContext context) {
+ IGaService gaService=Graphiti.getGaService();
+ final PictogramElement pe = context.getPictogramElement();
+ GraphicsAlgorithm containerGa = pe.getGraphicsAlgorithm();
+ final List<GraphicsAlgorithm> gaChildren = containerGa.getGraphicsAlgorithmChildren();
+ if (SketchUtil.getGhostGa(pe) != null) {
+ final IDimension containerGaSize = gaService.calculateSize(containerGa);
+ final int containerWidth = containerGaSize.getWidth();
+ final int containerHeight = containerGaSize.getHeight();
+ final GraphicsAlgorithm firstGa = gaChildren.get(0);
+ final GraphicsAlgorithm textGa = gaChildren.get(1);
+ final int textHeight = 20; // textGa.getHeight();
+ gaService.setLocationAndSize(firstGa, LEFT, TOP, containerWidth - LEFT - RIGHT, containerHeight - TOP - BOTTOM
+ - DIST - textHeight, true);
+ gaService.setSize(textGa, containerWidth - LEFT - RIGHT, textHeight);
+ gaService.setLocation(textGa, LEFT, containerHeight - BOTTOM - textHeight, true);
+ }
+
+ AbstractText text = SketchUtil.getLabelGa(pe);
+ if (text != null) {
+ gaService.setSize(text, containerGa.getWidth(), containerGa.getHeight());
+ }
+
+ return true;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchMoveShapeFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchMoveShapeFeature.java
new file mode 100644
index 0000000..8fb7f38
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchMoveShapeFeature.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.Collection;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IMoveShapeContext;
+import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchMoveShapeFeature.
+ */
+public class SketchMoveShapeFeature extends DefaultMoveShapeFeature {
+
+ /**
+ * Instantiates a new sketch move shape feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchMoveShapeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canMoveShape(IMoveShapeContext context) {
+ return true;
+ }
+
+ @Override
+ protected void internalMove(IMoveShapeContext context) {
+
+ super.internalMove(context);
+
+ Connection targetConnection = context.getTargetConnection();
+ if (targetConnection != null) {
+ if (context.getSourceContainer().equals(context.getTargetContainer())) {
+
+ Shape shape = context.getShape();
+ GraphicsAlgorithm ga = shape.getGraphicsAlgorithm();
+
+ Graphiti.getGaService().setLocation(ga, context.getX() - (ga.getWidth() / 2),
+ context.getY() - (ga.getHeight() / 2));
+
+ Collection<Anchor> anchors = shape.getAnchors();
+ if (anchors.size() > 0) {
+ Anchor newAnchor = anchors.iterator().next();
+
+ Anchor oldEndAnchor = targetConnection.getEnd();
+ targetConnection.setEnd(newAnchor);
+
+ Connection connection = Graphiti.getPeCreateService().createFreeFormConnection(getDiagram());
+ Polyline p = Graphiti.getGaCreateService().createPolyline(connection);
+
+ GraphicsAlgorithm targetConnectionGraphicsAlgorithm = targetConnection.getGraphicsAlgorithm();
+ p.setLineWidth(targetConnectionGraphicsAlgorithm.getLineWidth());
+ p.setForeground(targetConnectionGraphicsAlgorithm.getForeground());
+ p.setLineStyle(targetConnectionGraphicsAlgorithm.getLineStyle());
+
+ connection.setStart(newAnchor);
+ connection.setEnd(oldEndAnchor);
+ }
+ }
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchResizeShapeFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchResizeShapeFeature.java
new file mode 100644
index 0000000..4a46dc1
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchResizeShapeFeature.java
@@ -0,0 +1,31 @@
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.DefaultResizeConfiguration;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IResizeConfiguration;
+import org.eclipse.graphiti.features.context.IResizeShapeContext;
+import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
+
+public class SketchResizeShapeFeature extends DefaultResizeShapeFeature {
+
+ private static final boolean RANDOM_CAN_RESIZE = false;
+
+ public SketchResizeShapeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canResizeShape(IResizeShapeContext context) {
+ return RANDOM_CAN_RESIZE ? Math.random() > 0.5 : super.canResizeShape(context);
+ }
+
+ @Override
+ public IResizeConfiguration getResizeConfiguration() {
+ return new DefaultResizeConfiguration() {
+ @Override
+ public boolean isHorizantalResizeAllowed() {
+ return false;
+ }
+ };
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchTextDirectEditingFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchTextDirectEditingFeature.java
new file mode 100644
index 0000000..bfd2c27
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SketchTextDirectEditingFeature.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IDirectEditingContext;
+import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+
+/**
+ * The Class SketchLabelDirectEditingFeature.
+ */
+public class SketchTextDirectEditingFeature extends AbstractDirectEditingFeature {
+
+ /**
+ * Instantiates a new sketch label direct editing feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public SketchTextDirectEditingFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public int getEditingType() {
+ return TYPE_TEXT;
+ }
+
+ public String getInitialValue(IDirectEditingContext context) {
+ return SketchUtil.getCurrentLabelValue(context.getPictogramElement());
+ }
+
+ public void setValue(String value, IDirectEditingContext context) {
+ SketchUtil.setCurrentLabelValue(context.getPictogramElement(), value);
+ }
+
+ @Override
+ public boolean isCompletionAvailable() {
+ return true;
+ }
+
+ @Override
+ public boolean isAutoCompletionEnabled() {
+ return false;
+ }
+
+ @Override
+ public String[] getValueProposals(String value, int caretPos, IDirectEditingContext context) {
+ return new String[] { "value1", "value2" };
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SwitchModeFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SwitchModeFeature.java
new file mode 100644
index 0000000..0d158ba
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/SwitchModeFeature.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.IName;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+
+public class SwitchModeFeature extends AbstractCustomFeature {
+
+ public SwitchModeFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ private int calculateNextTBPIndex() {
+ IDiagramTypeProvider dtp = getFeatureProvider().getDiagramTypeProvider();
+ IToolBehaviorProvider[] availableToolBehaviorProviders = dtp.getAvailableToolBehaviorProviders();
+ int providerCount = availableToolBehaviorProviders.length;
+ int newIndex = (dtp.getCurrentToolBahaviorIndex() + 1) % providerCount;
+ return newIndex;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ if (getDiagramEditor().isDirty()) {
+ return false;
+ }
+
+ IToolBehaviorProvider[] availableToolBehaviorProviders = getFeatureProvider().getDiagramTypeProvider()
+ .getAvailableToolBehaviorProviders();
+ return availableToolBehaviorProviders.length > 1;
+ }
+
+ public void execute(ICustomContext context) {
+ IDiagramTypeProvider dtp = getFeatureProvider().getDiagramTypeProvider();
+ int newIndex = calculateNextTBPIndex();
+ dtp.setCurrentToolBahaviorIndex(newIndex);
+ }
+
+ @Override
+ public String getDescription() {
+ return getName();
+ }
+
+ @Override
+ public String getName() {
+ IDiagramTypeProvider dtp = getFeatureProvider().getDiagramTypeProvider();
+ IToolBehaviorProvider nextTBP = dtp.getAvailableToolBehaviorProviders()[calculateNextTBPIndex()];
+ String name = nextTBP.getClass().getSimpleName();
+ if (nextTBP instanceof IName) {
+ name = ((IName) nextTBP).getName();
+
+ }
+ return "Switch to " + name;
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ if (context instanceof ICustomContext) {
+ ICustomContext cContext = (ICustomContext) context;
+ PictogramElement[] pes = cContext.getPictogramElements();
+ if (pes.length == 1) {
+ if (pes[0] instanceof Diagram) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ToggleDecorator.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ToggleDecorator.java
new file mode 100644
index 0000000..9d4552c
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/ToggleDecorator.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class ToggleDecorator.
+ */
+public class ToggleDecorator extends AbstractCustomFeature {
+
+ /**
+ * Instantiates a new toggle decorator.
+ *
+ * @param fp
+ * the fp
+ */
+ public ToggleDecorator(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public void execute(ICustomContext context) {
+ Collection<Connection> connections = getDiagram().getConnections();
+ for (Connection connection : connections) {
+ Collection<ConnectionDecorator> decorators = connection.getConnectionDecorators();
+ if (decorators.size() > 0) {
+ ConnectionDecorator[] decoratorArray = decorators.toArray(new ConnectionDecorator[0]);
+ for (ConnectionDecorator decorator : decoratorArray) {
+ EcoreUtil.delete(decorator, true);
+ }
+ } else {
+ IPeCreateService pecService = Graphiti.getPeCreateService();
+ ConnectionDecorator decorator = pecService.createConnectionDecorator(connection, true, 0.25, true);
+ IGaService gaService = Graphiti.getGaService();
+ Rectangle rectangle = gaService.createRectangle(decorator);
+ rectangle.setForeground(manageColor(IColorConstant.BLUE));
+ rectangle.setBackground(manageColor(IColorConstant.BLUE));
+ gaService.setLocationAndSize(rectangle, 0, -20, 5, 40);
+
+ decorator = pecService.createConnectionDecorator(connection, true, 0.75, true);
+ Polyline polyline = gaService.createPolyline(decorator, new int[] { 0, -20, 0, 20 });
+ polyline.setForeground(manageColor(IColorConstant.RED));
+ polyline.setBackground(manageColor(IColorConstant.RED));
+ }
+ }
+
+ if (getDiagram().getConnections().size() > 0) {
+ }
+ }
+
+ @Override
+ public String getName() {
+ return "Toggle decorator";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ return true;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/TransparencyFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/TransparencyFeature.java
new file mode 100644
index 0000000..63fae8a
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/TransparencyFeature.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+
+/**
+ * The Class TransparencyFeature.
+ */
+public class TransparencyFeature extends AbstractCustomFeature {
+
+ private static final String PERCENT = " %";
+
+ /**
+ * The transparency.
+ */
+ double transparency;
+
+ /**
+ * Instantiates a new transparency feature.
+ *
+ * @param fp
+ * the fp
+ * @param transparency
+ * the transparency
+ */
+ public TransparencyFeature(IFeatureProvider fp, double transparency) {
+ super(fp);
+ this.transparency = transparency;
+ }
+
+ public void execute(ICustomContext context) {
+
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe != null && pe.getGraphicsAlgorithm() != null) {
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ ga.setTransparency(transparency / 100);
+ }
+ }
+ }
+
+ @Override
+ public String getName() {
+ // return Double.toString(transparency) + PERCENT;
+ return Math.round(transparency) + PERCENT;
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ boolean ret = false;
+ if (context instanceof ICustomContext) {
+ PictogramElement[] pes = ((ICustomContext) context).getPictogramElements();
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ if (pe instanceof Shape && pe.getGraphicsAlgorithm() != null && !(pe instanceof Diagram)) {
+ ret = true;
+ } else {
+ return false;
+ }
+ }
+ }
+ return ret;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/bd/CreateChannelFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/bd/CreateChannelFeature.java
new file mode 100644
index 0000000..99f573a
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/bd/CreateChannelFeature.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.bd;
+
+import org.eclipse.graphiti.datatypes.ILocation;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Ellipse;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.LineStyle;
+import org.eclipse.graphiti.mm.pictograms.Polyline;
+import org.eclipse.graphiti.sample.sketch.features.create.AbstractSketchCreateConnectionFeature;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class CreateChannelFeature.
+ */
+public class CreateChannelFeature extends AbstractSketchCreateConnectionFeature implements IBlockDiagramConfiguration {
+
+ /**
+ * Instantiates a new creates the channel feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public CreateChannelFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ public Connection create(ICreateConnectionContext context) {
+ Anchor startAnchor = context.getSourceAnchor();
+ Anchor endAnchor = context.getTargetAnchor();
+
+ if (startAnchor == null || endAnchor == null) {
+ return null;
+ }
+
+ ILocation startLocation = Graphiti.getLayoutService().getLocationRelativeToDiagram(startAnchor);
+ ILocation endLocation = Graphiti.getLayoutService().getLocationRelativeToDiagram(endAnchor);
+
+ int xPosForChannelShape = (startLocation.getX() + endLocation.getX() - CHANNEL_SIZE) / 2;
+ int yPosForChannelShape = (startLocation.getY() + endLocation.getY() - CHANNEL_SIZE) / 2;
+
+ // create channel itself
+ Anchor channelAnchor = createChannelShape(xPosForChannelShape, yPosForChannelShape);
+
+ // create start and en connection
+ Connection startConnection = createConnection(startAnchor, channelAnchor);
+ createConnection(channelAnchor, endAnchor);
+
+ return startConnection;
+ }
+
+ private Anchor createChannelShape(int x, int y) {
+ ContainerShape channelShape = Graphiti.getPeCreateService().createContainerShape(getDiagram(), true);
+ Graphiti.getPeService().setPropertyValue(channelShape, BLOCK_DIAGRAM_ELEMENT_TYPE, BD_CHANNEL);
+ Ellipse channelEllipse = Graphiti.getGaCreateService().createEllipse(channelShape);
+ Graphiti.getGaService().setLocationAndSize(channelEllipse, x, y, CHANNEL_SIZE, CHANNEL_SIZE, true);
+ channelEllipse.setLineWidth(2);
+ channelEllipse.setLineStyle(LineStyle.SOLID);
+ channelEllipse.setFilled(false);
+ channelEllipse.setForeground(manageColor(IColorConstant.LIGHT_BLUE));
+ Anchor channelAnchor = Graphiti.getPeCreateService().createChopboxAnchor(channelShape);
+ return channelAnchor;
+ }
+
+ private Connection createConnection(Anchor startAnchor, Anchor endAnchor) {
+ FreeFormConnection ret = Graphiti.getPeCreateService().createFreeFormConnection(getDiagram());
+ ret.setStart(startAnchor);
+ ret.setEnd(endAnchor);
+
+ Polyline p = Graphiti.getGaCreateService().createPolyline(ret);
+ p.setLineWidth(2);
+ p.setForeground(manageColor(IColorConstant.LIGHT_BLUE));
+ p.setLineStyle(LineStyle.SOLID);
+
+ return ret;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/bd/IBlockDiagramConfiguration.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/bd/IBlockDiagramConfiguration.java
new file mode 100644
index 0000000..7ffcd43
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/bd/IBlockDiagramConfiguration.java
@@ -0,0 +1,28 @@
+package org.eclipse.graphiti.sample.sketch.features.bd;
+
+/**
+ * The Interface IBlockDiagramConfiguration.
+ */
+public interface IBlockDiagramConfiguration {
+
+ /**
+ * The Constant BD_CHANNEL.
+ */
+ static final String BD_CHANNEL = "BD_CHANNEL";
+
+ /**
+ * The Constant BD_ACTOR.
+ */
+ static final String BD_ACTOR = "BD_ACTOR";
+
+ /**
+ * The Constant BLOCK_DIAGRAM_ELEMENT_TYPE.
+ */
+ static final String BLOCK_DIAGRAM_ELEMENT_TYPE = "BLOCK_DIAGRAM_ELEMENT_TYPE";
+
+ /**
+ * The CHANNE l_ size.
+ */
+ static int CHANNEL_SIZE = 20;
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/AbstractSketchCreateConnectionFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/AbstractSketchCreateConnectionFeature.java
new file mode 100644
index 0000000..79b5b88
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/AbstractSketchCreateConnectionFeature.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+
+/**
+ * The Class AbstractSketchCreateConnectionFeature.
+ */
+public abstract class AbstractSketchCreateConnectionFeature extends AbstractCreateConnectionFeature {
+
+ /**
+ * Instantiates a new abstract sketch create connection feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public AbstractSketchCreateConnectionFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ public boolean canCreate(ICreateConnectionContext context) {
+ boolean ret = false;
+
+ // allow connection creation only if anchors do not belong to the same
+ // container
+ Anchor sourceAnchor = context.getSourceAnchor();
+ Anchor targetAnchor = context.getTargetAnchor();
+ if (sourceAnchor != null && targetAnchor != null) {
+ AnchorContainer sourceParent = sourceAnchor.getParent();
+ if (sourceParent != null && !sourceParent.equals(targetAnchor.getParent())) {
+ ret = true;
+ }
+ }
+
+ return ret;
+ }
+
+ public boolean canStartConnection(ICreateConnectionContext context) {
+ boolean ret = false;
+
+ if (context.getSourceAnchor() != null) {
+ ret = true;
+ }
+
+ return ret;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/AbstractSketchCreateSimpleConnectionFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/AbstractSketchCreateSimpleConnectionFeature.java
new file mode 100644
index 0000000..e4d7da4
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/AbstractSketchCreateSimpleConnectionFeature.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.mm.datatypes.Point;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.LineStyle;
+import org.eclipse.graphiti.mm.pictograms.Polyline;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaCreateService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class AbstractSketchCreateSimpleConnectionFeature.
+ */
+abstract class AbstractSketchCreateSimpleConnectionFeature extends AbstractSketchCreateConnectionFeature {
+
+ /**
+ * Instantiates a new abstract sketch create simple connection feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public AbstractSketchCreateSimpleConnectionFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ public Connection create(ICreateConnectionContext context) {
+
+ Anchor startAnchor = context.getSourceAnchor();
+ Anchor endAnchor = context.getTargetAnchor();
+
+ if (startAnchor == null || endAnchor == null) {
+ return null;
+ }
+
+ IGaCreateService gaCreateService = Graphiti.getGaCreateService();
+ Connection connection = createConnection();
+ Polyline p = gaCreateService.createPolyline(connection);
+ p.setLineWidth(3);
+ p.setForeground(manageColor(IColorConstant.LIGHT_BLUE));
+ p.setLineStyle(LineStyle.DASHDOT);
+
+ connection.setStart(startAnchor);
+ connection.setEnd(endAnchor);
+
+ /* add bend point midway */
+ if (false && connection instanceof FreeFormConnection) {
+ GraphicsAlgorithm startGa = startAnchor.getParent().getGraphicsAlgorithm();
+ GraphicsAlgorithm endGa = endAnchor.getParent().getGraphicsAlgorithm();
+ int startAnchorX = startGa.getX() + startGa.getWidth() / 2;
+ int startAnchorY = startGa.getY() + startGa.getHeight() / 2;
+ int endAnchorX = endGa.getX() + endGa.getWidth() / 2;
+ int endAnchorY = endGa.getY() + endGa.getHeight() / 2;
+ int bendpointX = (startAnchorX + endAnchorX) / 2;
+ int bendpointY = (startAnchorY + endAnchorY) / 2;
+ Point bendpoint = gaCreateService.createPoint(bendpointX, bendpointY);
+ ((FreeFormConnection) connection).getBendpoints().add(bendpoint);
+ }
+ return connection;
+ }
+
+ /**
+ * Creates the connection.
+ *
+ * @return the connection
+ */
+ protected abstract Connection createConnection();
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/CreateCsGhostAndInnerShapeFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/CreateCsGhostAndInnerShapeFeature.java
new file mode 100644
index 0000000..80a2534
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/CreateCsGhostAndInnerShapeFeature.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Ellipse;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.RoundedRectangle;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.util.ColorConstant;
+
+/**
+ * The Class CreateCsGhostAndInnerShapeFeature.
+ */
+public class CreateCsGhostAndInnerShapeFeature extends AbstractCreateFeature {
+
+ /**
+ * Instantiates a new creates the cs ghost and inner shape feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public CreateCsGhostAndInnerShapeFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ public boolean canCreate(ICreateContext context) {
+ return (context.getTargetContainer() != null);
+ }
+
+ public Object[] create(ICreateContext context) {
+ ContainerShape targetContainer = context.getTargetContainer();
+ final IPeCreateService peCreateService = Graphiti.getPeCreateService();
+ IGaService gaService=Graphiti.getGaService();
+ ContainerShape ret = peCreateService.createContainerShape(targetContainer, true);
+ peCreateService.createChopboxAnchor(ret);
+ Rectangle ghostRect = gaService.createInvisibleRectangle(ret);
+ RoundedRectangle roundedRectangle = gaService.createRoundedRectangle(ghostRect, 10, 10);
+ roundedRectangle.setBackground(manageColor(ColorConstant.GREEN));
+ Shape innerShape = peCreateService.createShape(ret, true);
+ peCreateService.createChopboxAnchor(innerShape);
+ Ellipse ellipse = gaService.createEllipse(innerShape);
+ ellipse.setBackground(manageColor(ColorConstant.RED));
+
+ gaService.setLocationAndSize(ghostRect, context.getX(), context.getY(), context.getWidth(), context.getHeight(),
+ true);
+
+ layoutPictogramElement(ret);
+
+ return new Object[] { ret };
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateCanFigureFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateCanFigureFeature.java
new file mode 100644
index 0000000..b4ec3c9
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateCanFigureFeature.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.sample.sketch.SketchGraphicsAlgorithmRendererFactory;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchCreateCanFigureFeature.
+ */
+public class SketchCreateCanFigureFeature extends AbstractCreateFeature {
+
+ /**
+ * Instantiates a new sketch create can figure feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public SketchCreateCanFigureFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ public boolean canCreate(ICreateContext context) {
+ boolean ret = false;
+ ContainerShape targetContainer = context.getTargetContainer();
+ if (targetContainer != null) {
+ ret = true;
+ }
+ return ret;
+ }
+
+ public Object[] create(ICreateContext context) {
+ ContainerShape targetContainer = context.getTargetContainer();
+ AnchorContainer newAc = Graphiti.getPeCreateService().createContainerShape(targetContainer, true);
+ Graphiti.getPeCreateService().createChopboxAnchor(newAc);
+
+ int width = context.getWidth() < 50 ? 50 : context.getWidth();
+ int height = context.getHeight() < 50 ? 50 : context.getHeight();
+
+ GraphicsAlgorithm newGa = Graphiti.getGaCreateService().createPlatformGraphicsAlgorithm(newAc,
+ SketchGraphicsAlgorithmRendererFactory.CANFIGURE);
+ Graphiti.getGaService().setLocationAndSize(newGa, context.getX(), context.getY(), width, height);
+ layoutPictogramElement(newAc);
+
+ return new Object[] { newAc };
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateFreeformConnectionFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateFreeformConnectionFeature.java
new file mode 100644
index 0000000..5071983
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateFreeformConnectionFeature.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchCreateFreeformConnectionFeature.
+ */
+public class SketchCreateFreeformConnectionFeature extends AbstractSketchCreateSimpleConnectionFeature {
+
+ /**
+ * Instantiates a new sketch create freeform connection feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public SketchCreateFreeformConnectionFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ @Override
+ protected Connection createConnection() {
+ return Graphiti.getPeCreateService().createFreeFormConnection(getDiagram());
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaContainerFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaContainerFeature.java
new file mode 100644
index 0000000..84c0b13
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaContainerFeature.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchCreateGaContainerFeature.
+ */
+public class SketchCreateGaContainerFeature extends SketchCreateGaFeature {
+
+ /**
+ * Instantiates a new sketch create ga container feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ * @param gaType
+ * the ga type
+ */
+ public SketchCreateGaContainerFeature(IFeatureProvider fp, String name, String description, Class<GraphicsAlgorithm> gaType) {
+ super(fp, name, description, gaType);
+ }
+
+ @Override
+ protected AnchorContainer createAnchorContainer(ContainerShape targetContainer) {
+ return Graphiti.getPeCreateService().createContainerShape(targetContainer, true);
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaContainerFeatureWithGhost.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaContainerFeatureWithGhost.java
new file mode 100644
index 0000000..8e350ec
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaContainerFeatureWithGhost.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Ellipse;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithmContainer;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.RoundedRectangle;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class SketchCreateGaContainerFeature.
+ */
+public class SketchCreateGaContainerFeatureWithGhost extends SketchCreateGaFeature {
+
+ private static final int FRAME = 10;
+
+ /**
+ * Instantiates a new sketch create ga container feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ * @param gaType
+ * the ga type
+ */
+ public SketchCreateGaContainerFeatureWithGhost(IFeatureProvider fp, String name, String description, Class<GraphicsAlgorithm> gaType) {
+ super(fp, name, description, gaType);
+ }
+
+ @Override
+ protected AnchorContainer createAnchorContainer(ContainerShape targetContainer) {
+ IPeService peService = Graphiti.getPeService();
+ ContainerShape cs = peService.createContainerShape(targetContainer, true);
+
+ String value = null;
+ if (RoundedRectangle.class.equals(getGaType())) {
+ value = SketchUtil.GA_ROUNDED_RECTANGLE;
+ } else if (Rectangle.class.equals(getGaType())) {
+ value = SketchUtil.GA_RECTANGLE;
+ } else if (Ellipse.class.equals(getGaType())) {
+ value = SketchUtil.GA_ELLIPSE;
+ }
+
+ if (value != null) {
+ peService.setPropertyValue(cs, SketchUtil.GA_TAG, value);
+ }
+
+ peService.setPropertyValue(cs, SketchUtil.GHOST_TAG, "");
+ peService.setPropertyValue(cs, SketchUtil.CONTAINER_TAG, "");
+
+ return cs;
+ }
+
+ @Override
+ protected GraphicsAlgorithm createGa(GraphicsAlgorithmContainer gac, int width, int height) {
+ IGaService gaService=Graphiti.getGaService();
+ final Rectangle ghostGa = gaService.createInvisibleRectangle((PictogramElement) gac);
+ gaService.setSize(ghostGa, width, height);
+ final int newWidth = width - 2 * FRAME;
+ final int newHeight = height - 2 * FRAME;
+ final GraphicsAlgorithm innerGa = super.createGa(ghostGa, newWidth, newHeight);
+ gaService.setLocationAndSize(innerGa, FRAME, FRAME, newWidth, newHeight);
+ innerGa.setBackground(gaService.manageColor(getDiagram(), IColorConstant.BLUE));
+
+ // inner inner GA
+ final Ellipse innerInnerGa = gaService.createEllipse(innerGa);
+ innerInnerGa.setBackground(gaService.manageColor(getDiagram(), IColorConstant.ORANGE));
+ innerInnerGa.setForeground(gaService.manageColor(getDiagram(), IColorConstant.GREEN));
+ innerInnerGa.setLineWidth(3);
+
+ return ghostGa;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaFeature.java
new file mode 100644
index 0000000..bde35f8
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaFeature.java
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.AbstractText;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor;
+import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Ellipse;
+import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithmContainer;
+import org.eclipse.graphiti.mm.pictograms.Orientation;
+import org.eclipse.graphiti.mm.pictograms.Polygon;
+import org.eclipse.graphiti.mm.pictograms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.mm.pictograms.RoundedRectangle;
+import org.eclipse.graphiti.sample.sketch.SketchFeatureProvider;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class SketchCreateGaFeature.
+ */
+public abstract class SketchCreateGaFeature extends AbstractCreateFeature {
+
+ private static final String NEW_ELEMENT = "new element";
+ private Class gaType;
+
+ /**
+ * Instantiates a new sketch create ga feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ * @param gaType
+ * the ga type
+ */
+ public SketchCreateGaFeature(IFeatureProvider fp, String name, String description, Class<GraphicsAlgorithm> gaType) {
+ super(fp, name, description);
+ setGaType(gaType);
+ }
+
+ public boolean canCreate(ICreateContext context) {
+ boolean ret = false;
+ ContainerShape targetContainer = context.getTargetContainer();
+ if (targetContainer != null) {
+ ret = true;
+ }
+ return ret;
+ }
+
+ public Object[] create(ICreateContext context) {
+ ContainerShape targetContainer = context.getTargetContainer();
+ AnchorContainer newAc = createAnchorContainer(targetContainer);
+ IPeCreateService pecService = Graphiti.getPeCreateService();
+ IGaService gaService = Graphiti.getGaService();
+ final ChopboxAnchor newAnchor = pecService.createChopboxAnchor(newAc);
+
+ int width = context.getWidth() < 50 ? 50 : context.getWidth();
+ int height = context.getHeight() < 50 ? 50 : context.getHeight();
+
+ GraphicsAlgorithm newGa = createGa(newAc, width, height);
+
+ gaService.setLocationAndSize(newGa, context.getX(), context.getY(), width, height);
+
+ AbstractText label;
+ if (isMultiLineText()) {
+ label = gaService.createDefaultMultiText(newGa, NEW_ELEMENT);
+ } else {
+ label = gaService.createText(newGa, NEW_ELEMENT);
+ }
+ gaService.createFont(label, "Comic Sans MS", 14);
+ label.setForeground(manageColor(IColorConstant.BLUE));
+ label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
+ label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
+ gaService.setLocationAndSize(label, 0, 0, width, height);
+ layoutPictogramElement(newAc);
+
+ final Connection targetConnection = context.getTargetConnection();
+ if (targetConnection != null) {
+ gaService.setLocation(newGa, context.getX() - (width / 2), context.getY() - (height / 2));
+
+ Anchor oldEndAnchor = targetConnection.getEnd();
+ targetConnection.setEnd(newAnchor);
+
+ Connection connection = pecService.createFreeFormConnection(getDiagram());
+ Polyline p = gaService.createPolyline(connection);
+
+ GraphicsAlgorithm targetConnectionGraphicsAlgorithm = targetConnection.getGraphicsAlgorithm();
+ p.setLineWidth(targetConnectionGraphicsAlgorithm.getLineWidth());
+ p.setForeground(targetConnectionGraphicsAlgorithm.getForeground());
+ p.setLineStyle(targetConnectionGraphicsAlgorithm.getLineStyle());
+
+ connection.setStart(newAnchor);
+ connection.setEnd(oldEndAnchor);
+ }
+
+ SketchFeatureProvider fp = (SketchFeatureProvider) getFeatureProvider();
+ if (fp.isTestMode() && (newGa instanceof Rectangle)) {
+ BoxRelativeAnchor bra = pecService.createBoxRelativeAnchor(newAc);
+ Rectangle r = gaService.createRectangle(bra);
+ gaService.setLocationAndSize(r, -5, 0, 10, 10);
+ r.setTransparency(1.0);
+ bra.setRelativeWidth(0.5);
+
+ FixPointAnchor fpa = pecService.createFixPointAnchor(newAc);
+ r = gaService.createRectangle(fpa);
+ gaService.setLocationAndSize(r, 0, 0, 10, 10);
+ r.setTransparency(1.0);
+ fpa.setLocation(gaService.createPoint(10, 10));
+ }
+
+ return new Object[] { newAc };
+ }
+
+ /**
+ * Creates the anchor container.
+ *
+ * @param targetContainer
+ * the target container
+ *
+ * @return the anchor container
+ */
+ abstract protected AnchorContainer createAnchorContainer(ContainerShape targetContainer);
+
+ /**
+ * Creates the ga.
+ *
+ * @param gac
+ * the gac
+ * @param width
+ * the width
+ * @param height
+ * the height
+ *
+ * @return the graphics algorithm
+ */
+ protected GraphicsAlgorithm createGa(GraphicsAlgorithmContainer gac, int width, int height) {
+ GraphicsAlgorithm ret = null;
+ IGaService gaService = Graphiti.getGaService();
+ if (RoundedRectangle.class.equals(gaType)) {
+ ret = gaService.createRoundedRectangle(gac, 10, 10);
+ } else if (Rectangle.class.equals(gaType)) {
+ ret = gaService.createRectangle(gac);
+ } else if (Ellipse.class.equals(gaType)) {
+ ret = gaService.createEllipse(gac);
+ } else if (Polyline.class.equals(gaType)) {
+ // top-left, top-right, bottom-right, bottom-left
+ int[] xy = new int[] { 0, 0, width, 0, width, height, 0, height };
+ int[] ba = new int[] { 0, 0, 20, 40, 40, 20, 0, 0 };
+ Polyline p = gaService.createPolyline(gac, xy, ba);
+ ret = p;
+ } else if (Polygon.class.equals(gaType)) {
+ if (getCreateName().startsWith("Tria")) { // triangle
+ // top-middle, bottom-right, bottom-left
+ int xy[] = new int[] { width / 2, 0, width, height, 0, height };
+ int ba[] = new int[] { 0, 0, 40, 40, 40, 40 };
+ Polygon p = gaService.createPolygon(gac, xy, ba);
+ ret = p;
+ } else { // arrow
+ // top-left, top-middle, middle-right, bottom-middle, bottom-right
+ int xy[] = new int[] { 0, 0, (2 * width / 3), 0, width, height / 2, (2 * width / 3), height, 0, height };
+ int ba[] = new int[] { 0, 0, 30, 15, 0, 0, 15, 30, 60, 60 };
+ Polygon p = gaService.createPolygon(gac, xy, ba);
+ ret = p;
+ }
+ }
+
+ if (ret != null) {
+ Diagram diagram = getDiagram();
+ ret.setForeground(gaService.manageColor(diagram, IColorConstant.BLACK));
+ ret.setBackground(gaService.manageColor(diagram, IColorConstant.WHITE));
+ ret.setTransparency(0.3);
+ ret.setLineWidth(2);
+ }
+
+ return ret;
+ }
+
+ private void setGaType(Class gaType) {
+ this.gaType = gaType;
+ }
+
+ protected Class getGaType() {
+ return gaType;
+ }
+
+ protected boolean isMultiLineText() {
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaShapeFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaShapeFeature.java
new file mode 100644
index 0000000..e429f39
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaShapeFeature.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class SketchCreateGaShapeFeature.
+ */
+public class SketchCreateGaShapeFeature extends SketchCreateGaFeature {
+
+ private boolean multiLineText = true;
+
+ /**
+ * Instantiates a new sketch create ga shape feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ * @param gaType
+ * the ga type
+ */
+ public SketchCreateGaShapeFeature(IFeatureProvider fp, String name, String description, Class<GraphicsAlgorithm> gaType) {
+ super(fp, name, description, gaType);
+ }
+
+ public SketchCreateGaShapeFeature(IFeatureProvider fp, String name, String description, Class<GraphicsAlgorithm> gaType,
+ boolean multiLineText) {
+ this(fp, name, description, gaType);
+ this.multiLineText = multiLineText;
+ }
+
+ @Override
+ protected AnchorContainer createAnchorContainer(ContainerShape targetContainer) {
+ final Shape ret = Graphiti.getPeCreateService().createShape(targetContainer, true);
+ return ret;
+ }
+
+ @Override
+ protected boolean isMultiLineText() {
+ return multiLineText;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaShapeFeatureWithGhost.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaShapeFeatureWithGhost.java
new file mode 100644
index 0000000..3742d52
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/create/SketchCreateGaShapeFeatureWithGhost.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.create;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Ellipse;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithmContainer;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Rectangle;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class SketchCreateGaShapeFeatureWithGhost.
+ */
+public class SketchCreateGaShapeFeatureWithGhost extends SketchCreateGaShapeFeature {
+
+ private static final int FRAME = 10;
+
+ /**
+ * Instantiates a new sketch create ga shape feature with ghost.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ * @param gaType
+ * the ga type
+ */
+ public SketchCreateGaShapeFeatureWithGhost(IFeatureProvider fp, String name, String description, Class<GraphicsAlgorithm> gaType) {
+ super(fp, name, description, gaType);
+ }
+
+ @Override
+ protected AnchorContainer createAnchorContainer(ContainerShape targetContainer) {
+ final AnchorContainer ret = super.createAnchorContainer(targetContainer);
+ return ret;
+ }
+
+ @Override
+ protected GraphicsAlgorithm createGa(GraphicsAlgorithmContainer gac, int width, int height) {
+ IGaService gaService=Graphiti.getGaService();
+ final Rectangle ghostGa = gaService.createInvisibleRectangle((PictogramElement) gac);
+ gaService.setSize(ghostGa, width, height);
+ final int newWidth = width - 2 * FRAME;
+ final int newHeight = height - 2 * FRAME;
+ final GraphicsAlgorithm innerGa = super.createGa(ghostGa, newWidth, newHeight);
+ gaService.setLocationAndSize(innerGa, FRAME, FRAME, newWidth, newHeight);
+ innerGa.setBackground(gaService.manageColor(getDiagram(), IColorConstant.BLUE));
+
+ // inner inner GA
+ final Ellipse innerInnerGa = gaService.createEllipse(innerGa);
+ innerInnerGa.setBackground(gaService.manageColor(getDiagram(), IColorConstant.ORANGE));
+ innerInnerGa.setForeground(gaService.manageColor(getDiagram(), IColorConstant.GREEN));
+ innerInnerGa.setLineWidth(3);
+
+ return ghostGa;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/CreateLaneFeauture.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/CreateLaneFeauture.java
new file mode 100644
index 0000000..d4a1010
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/CreateLaneFeauture.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.pool;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class CreateLaneFeauture.
+ */
+public class CreateLaneFeauture extends AbstractCustomFeature {
+
+ private static final String NAME = "Add Lane";
+
+ /**
+ * Instantiates a new creates the lane feauture.
+ *
+ * @param fp
+ * the fp
+ */
+ public CreateLaneFeauture(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public void execute(ICustomContext context) {
+ ContainerShape poolPe = (ContainerShape) context.getInnerPictogramElement();
+ createLaneInPool(poolPe, getDiagram());
+
+ layoutPictogramElement(poolPe);
+ }
+
+ /**
+ * Creates the lane in pool.
+ *
+ * @param poolPe
+ * the pool pe
+ * @param diagram
+ * the diagram
+ */
+ static void createLaneInPool(ContainerShape poolPe, Diagram diagram) {
+ final IPeService peService = Graphiti.getPeService();
+ IGaService gaService = Graphiti.getGaService();
+ ContainerShape lanePe = peService.createContainerShape(poolPe, true);
+ peService.setPropertyValue(lanePe, SketchUtil.LANE_TAG, "");
+ peService.createChopboxAnchor(lanePe);
+ GraphicsAlgorithm laneGa = gaService.createRectangle(lanePe);
+ laneGa.setBackground(gaService.manageColor(diagram, IColorConstant.VC_LIGHT_ORANGE));
+ laneGa.setForeground(gaService.manageColor(diagram, IColorConstant.VC_DARK_ORANGE));
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ return SketchUtil.isPoolPe(context.getInnerPictogramElement());
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/CreatePoolFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/CreatePoolFeature.java
new file mode 100644
index 0000000..80e2a71
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/CreatePoolFeature.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.pool;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.services.IPeService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class CreatePoolFeature.
+ */
+public class CreatePoolFeature extends AbstractCreateFeature {
+
+ /**
+ * Instantiates a new creates the pool feature.
+ *
+ * @param fp
+ * the fp
+ * @param name
+ * the name
+ * @param description
+ * the description
+ */
+ public CreatePoolFeature(IFeatureProvider fp, String name, String description) {
+ super(fp, name, description);
+ }
+
+ public boolean canCreate(ICreateContext context) {
+ boolean ret = false;
+ ContainerShape targetContainer = context.getTargetContainer();
+ if (targetContainer != null) {
+ ret = true;
+ }
+ return ret;
+ }
+
+ public Object[] create(ICreateContext context) {
+ ContainerShape targetContainer = context.getTargetContainer();
+ int width = context.getWidth() < 50 ? 50 : context.getWidth();
+ int height = context.getHeight() < 50 ? 50 : context.getHeight();
+
+ // create pool
+ final IPeService peService = Graphiti.getPeService();
+ IGaService gaService=Graphiti.getGaService();
+ ContainerShape poolPe = peService.createContainerShape(targetContainer, true);
+ peService.setPropertyValue(poolPe, SketchUtil.POOL_TAG, "");
+ Diagram diagram = getDiagram();
+ {
+ peService.createChopboxAnchor(poolPe);
+ GraphicsAlgorithm poolGa = gaService.createRectangle(poolPe);
+ gaService.setLocationAndSize(poolGa, context.getX(), context.getY(), width, height);
+ poolGa.setBackground(gaService.manageColor(diagram, IColorConstant.RED));
+ poolGa.setForeground(gaService.manageColor(diagram, IColorConstant.DARK_GRAY));
+ }
+
+ // create lane
+ CreateLaneFeauture.createLaneInPool(poolPe, diagram);
+
+ layoutPictogramElement(poolPe);
+
+ return new Object[] { poolPe };
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/LayoutPoolFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/LayoutPoolFeature.java
new file mode 100644
index 0000000..21c41e1
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/pool/LayoutPoolFeature.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.pool;
+
+import java.util.List;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.sample.sketch.SketchUtil;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class LayoutPoolFeature.
+ */
+public class LayoutPoolFeature extends AbstractLayoutFeature {
+ private static final int LANE_INDENT = 5;
+
+ private static final int LANE_DISTANCE = 3;
+
+ /**
+ * Instantiates a new layout pool feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public LayoutPoolFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public boolean canLayout(ILayoutContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ return SketchUtil.isPoolPe(pe);
+ }
+
+ public boolean layout(ILayoutContext context) {
+ PictogramElement pe = context.getPictogramElement();
+ if (pe instanceof ContainerShape) {
+ ContainerShape poolCs = (ContainerShape) pe;
+ List lanePes = poolCs.getChildren();
+ int laneCount = lanePes.size();
+ GraphicsAlgorithm poolGa = poolCs.getGraphicsAlgorithm();
+ int poolHeight = poolGa.getHeight();
+ int laneHeight = poolHeight - (2 * LANE_INDENT);
+ int poolWidth = poolGa.getWidth();
+ int laneWidth = (poolWidth - (2 * LANE_INDENT) - ((laneCount - 1) * LANE_DISTANCE)) / laneCount;
+
+ int x = LANE_INDENT;
+ for (Object object : lanePes) {
+ if (object instanceof ContainerShape) {
+ ContainerShape laneCs = (ContainerShape) object;
+ GraphicsAlgorithm laneGa = laneCs.getGraphicsAlgorithm();
+ Graphiti.getGaService().setLocationAndSize(laneGa, x, LANE_INDENT, laneWidth, laneHeight);
+ }
+ x += laneWidth + LANE_DISTANCE;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/CreateDefaultStylesFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/CreateDefaultStylesFeature.java
new file mode 100644
index 0000000..7011d55
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/CreateDefaultStylesFeature.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.style;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.graphiti.util.IColorConstant;
+
+/**
+ * The Class CreateDefaultStylesFeature.
+ */
+public class CreateDefaultStylesFeature extends AbstractCustomFeature {
+
+ private static final String BLUE = "Blue";
+
+ /**
+ * Instantiates a new creates the default styles feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public CreateDefaultStylesFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public void execute(ICustomContext context) {
+ Diagram diagram = getDiagram();
+
+ IGaService gaService = Graphiti.getGaService();
+ Style style_blue = gaService.createStyle(diagram, BLUE);
+ style_blue.setDescription(BLUE);
+ style_blue.setBackground(gaService.manageColor(diagram, IColorConstant.LIGHT_BLUE));
+ style_blue.setForeground(gaService.manageColor(diagram, IColorConstant.DARK_BLUE));
+ style_blue.setLineWidth(2);
+ style_blue.setLineVisible(true);
+ style_blue.setFilled(true);
+
+ Style style_blue_1 = gaService.createStyle(style_blue, "Blue 1");
+ style_blue_1.setDescription("Blue 1");
+ style_blue_1.setBackground(null);
+ style_blue_1.setForeground(null);
+ style_blue_1.setLineWidth(4);
+ style_blue_1.setLineVisible(true);
+ style_blue_1.setFilled(true);
+
+ Style style_blue_2 = gaService.createStyle(style_blue, "Blue red 2");
+ style_blue_2.setDescription("Blue red 2");
+ style_blue_2.setBackground(null);
+ style_blue_2.setForeground(gaService.manageColor(diagram, IColorConstant.RED));
+ style_blue_2.setLineWidth(8);
+ style_blue_2.setLineVisible(true);
+ style_blue_2.setFilled(true);
+ }
+
+ @Override
+ public String getName() {
+ return "Create Default Styles";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes.length == 1) {
+ if (pes[0] instanceof Diagram) {
+ return Graphiti.getGaService().findStyle(getDiagram(), BLUE) == null;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/IgnoreAllFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/IgnoreAllFeature.java
new file mode 100644
index 0000000..80665ee
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/IgnoreAllFeature.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.style;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class IgnoreAllFeature.
+ */
+public class IgnoreAllFeature extends AbstractCustomFeature {
+ private static final String NAME = "Ignore All";
+
+ /**
+ * Instantiates a new ignore all feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public IgnoreAllFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ Graphiti.getGaService().ignoreAll(ga);
+ }
+
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/MakeStyleFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/MakeStyleFeature.java
new file mode 100644
index 0000000..9e88b5e
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/MakeStyleFeature.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.style;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Style;
+import org.eclipse.graphiti.services.Graphiti;
+
+/**
+ * The Class MakeStyleFeature.
+ */
+public class MakeStyleFeature extends AbstractCustomFeature {
+
+ /**
+ * Instantiates a new make style feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public MakeStyleFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public void execute(ICustomContext context) {
+ String styleId = Double.toString(Math.random());
+ Style style = Graphiti.getGaCreateService().createStyle(getDiagram(), styleId);
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+
+ if (i == 0) {
+ // copy attributes from GA to style
+ style.setBackground(ga.getBackground());
+ style.setForeground(ga.getForeground());
+ style.setLineStyle(ga.getLineStyle());
+ Graphiti.getGaService().deleteRenderingStyle(style); // delete the old style
+ // first to avoid garbage
+ style.setRenderingStyle(ga.getRenderingStyle());
+ style.setLineWidth(ga.getLineWidth());
+ style.setDescription(styleId);
+ }
+
+ ga.setStyle(style);
+
+ // unset/reset attributes in GA
+ ga.setBackground(null);
+
+ ga.setForeground(null);
+
+ ga.setLineStyle(null);
+
+ ga.setRenderingStyle(null);
+
+ ga.setLineWidth(null);
+ }
+
+ }
+
+ @Override
+ public String getName() {
+ return "Make Style";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ return (ga.getStyle() == null);
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/SetStyleFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/SetStyleFeature.java
new file mode 100644
index 0000000..2e8cc67
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/SetStyleFeature.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.style;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Style;
+
+/**
+ * The Class SetStyleFeature.
+ */
+public class SetStyleFeature extends AbstractCustomFeature {
+ private Style style;
+
+ /**
+ * Instantiates a new sets the style feature.
+ *
+ * @param style
+ * the style
+ * @param fp
+ * the fp
+ */
+ public SetStyleFeature(Style style, IFeatureProvider fp) {
+ super(fp);
+ setStyle(style);
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ ga.setStyle(getStyle());
+ }
+
+ }
+
+ @Override
+ public String getName() {
+ final Style style = getStyle();
+ return style.getId() + " (" + style.getDescription() + ")";
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private Style getStyle() {
+ return style;
+ }
+
+ private void setStyle(Style style) {
+ this.style = style;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/UnsetStyleFeature.java b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/UnsetStyleFeature.java
new file mode 100644
index 0000000..1d2f8e2
--- /dev/null
+++ b/tests/org.eclipse.graphiti.testtool.sketch/src/org/eclipse/graphiti/sample/sketch/features/style/UnsetStyleFeature.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2010 SAP AG.
+ * 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:
+ * SAP AG - initial API, implementation and documentation
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.sample.sketch.features.style;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
+import org.eclipse.graphiti.mm.pictograms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+
+/**
+ * The Class UnsetStyleFeature.
+ */
+public class UnsetStyleFeature extends AbstractCustomFeature {
+ private static final String NAME = "Unset Style";
+
+ /**
+ * Instantiates a new unset style feature.
+ *
+ * @param fp
+ * the fp
+ */
+ public UnsetStyleFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ public void execute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+
+ for (int i = 0; i < pes.length; i++) {
+ PictogramElement pe = pes[i];
+ GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
+ ga.setStyle(null);
+ }
+
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ PictogramElement[] pes = context.getPictogramElements();
+ if (pes.length >= 1) {
+ GraphicsAlgorithm ga = pes[0].getGraphicsAlgorithm();
+ if (ga != null) {
+ return true;
+ }
+ }
+ return false;
+ }
+}