Bug 356218 - Added hasDoneChanges updates to update diagram feature and
called features via editor command stack to check it, including JUnit
and Bot tests
diff --git a/plugins/org.eclipse.graphiti.ui/.settings/.api_filters b/plugins/org.eclipse.graphiti.ui/.settings/.api_filters
index 9dc351e..bcf63b6 100644
--- a/plugins/org.eclipse.graphiti.ui/.settings/.api_filters
+++ b/plugins/org.eclipse.graphiti.ui/.settings/.api_filters
@@ -1,109 +1,125 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<component id="org.eclipse.graphiti.ui" version="2">
- <resource path="src/org/eclipse/graphiti/ui/features/AbstractCopyFeature.java" type="org.eclipse.graphiti.ui.features.AbstractCopyFeature">
- <filter id="574619656">
- <message_arguments>
- <message_argument value="ICopyFeature"/>
- <message_argument value="AbstractCopyFeature"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/features/AbstractPasteFeature.java" type="org.eclipse.graphiti.ui.features.AbstractPasteFeature">
- <filter id="574619656">
- <message_arguments>
- <message_argument value="IPasteFeature"/>
- <message_argument value="AbstractPasteFeature"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/features/DefaultDeleteFeature.java" type="org.eclipse.graphiti.ui.features.DefaultDeleteFeature">
- <filter id="574619656">
- <message_arguments>
- <message_argument value="IDeleteFeature"/>
- <message_argument value="DefaultDeleteFeature"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/action/DeleteAction.java" type="org.eclipse.graphiti.ui.internal.action.DeleteAction">
- <filter id="572522506">
- <message_arguments>
- <message_argument value="MultiDeleteInfo"/>
- <message_argument value="DeleteAction"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/command/EclipseProgress.java" type="org.eclipse.graphiti.ui.internal.command.EclipseProgress">
- <filter id="574619656">
- <message_arguments>
- <message_argument value="IProgress"/>
- <message_argument value="EclipseProgress"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/command/ReconnectCommand.java" type="org.eclipse.graphiti.ui.internal.command.ReconnectCommand">
- <filter id="574619656">
- <message_arguments>
- <message_argument value="IFeatureAndContext"/>
- <message_argument value="ReconnectCommand"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/config/ConfigurationProvider.java" type="org.eclipse.graphiti.ui.internal.config.ConfigurationProvider">
- <filter id="574660632">
- <message_arguments>
- <message_argument value="IConfigurationProvider"/>
- <message_argument value="IFeatureProviderHolder"/>
- <message_argument value="ConfigurationProvider"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/config/IConfigurationProvider.java" type="org.eclipse.graphiti.ui.internal.config.IConfigurationProvider">
- <filter id="571473929">
- <message_arguments>
- <message_argument value="IFeatureProviderHolder"/>
- <message_argument value="IConfigurationProvider"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/parts/IPictogramElementDelegate.java" type="org.eclipse.graphiti.ui.internal.parts.IPictogramElementDelegate">
- <filter id="571473929">
- <message_arguments>
- <message_argument value="IFeatureProviderHolder"/>
- <message_argument value="IPictogramElementDelegate"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/parts/IPictogramElementEditPart.java" type="org.eclipse.graphiti.ui.internal.parts.IPictogramElementEditPart">
- <filter id="571473929">
- <message_arguments>
- <message_argument value="IFeatureProviderHolder"/>
- <message_argument value="IPictogramElementEditPart"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/platform/DiagramTypeImpl.java" type="org.eclipse.graphiti.ui.internal.platform.DiagramTypeImpl">
- <filter id="574619656">
- <message_arguments>
- <message_argument value="IDiagramType"/>
- <message_argument value="DiagramTypeImpl"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/internal/services/impl/UiLayoutService.java" type="org.eclipse.graphiti.ui.internal.services.impl.UiLayoutService">
- <filter comment="test" id="574660632">
- <message_arguments>
- <message_argument value="IUiLayoutService"/>
- <message_argument value="ILayoutService"/>
- <message_argument value="UiLayoutService"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/graphiti/ui/services/IUiLayoutService.java" type="org.eclipse.graphiti.ui.services.IUiLayoutService">
- <filter id="571473929">
- <message_arguments>
- <message_argument value="ILayoutService"/>
- <message_argument value="IUiLayoutService"/>
- </message_arguments>
- </filter>
- </resource>
-</component>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.graphiti.ui" version="2">
+ <resource path="src/org/eclipse/graphiti/ui/features/AbstractCopyFeature.java" type="org.eclipse.graphiti.ui.features.AbstractCopyFeature">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="ICopyFeature"/>
+ <message_argument value="AbstractCopyFeature"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/features/AbstractPasteFeature.java" type="org.eclipse.graphiti.ui.features.AbstractPasteFeature">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="IPasteFeature"/>
+ <message_argument value="AbstractPasteFeature"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/features/DefaultDeleteFeature.java" type="org.eclipse.graphiti.ui.features.DefaultDeleteFeature">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="IDeleteFeature"/>
+ <message_argument value="DefaultDeleteFeature"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/action/DeleteAction.java" type="org.eclipse.graphiti.ui.internal.action.DeleteAction">
+ <filter id="572522506">
+ <message_arguments>
+ <message_argument value="MultiDeleteInfo"/>
+ <message_argument value="DeleteAction"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/command/EclipseProgress.java" type="org.eclipse.graphiti.ui.internal.command.EclipseProgress">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="IProgress"/>
+ <message_argument value="EclipseProgress"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/command/ReconnectCommand.java" type="org.eclipse.graphiti.ui.internal.command.ReconnectCommand">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="IFeatureAndContext"/>
+ <message_argument value="ReconnectCommand"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/config/ConfigurationProvider.java" type="org.eclipse.graphiti.ui.internal.config.ConfigurationProvider">
+ <filter id="574660632">
+ <message_arguments>
+ <message_argument value="IConfigurationProvider"/>
+ <message_argument value="IFeatureProviderHolder"/>
+ <message_argument value="ConfigurationProvider"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/config/IConfigurationProvider.java" type="org.eclipse.graphiti.ui.internal.config.IConfigurationProvider">
+ <filter id="571473929">
+ <message_arguments>
+ <message_argument value="IFeatureProviderHolder"/>
+ <message_argument value="IConfigurationProvider"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorDummy.java" type="org.eclipse.graphiti.ui.internal.editor.DiagramEditorDummy">
+ <filter comment="Allow direct implementation accross Graphiti projects to make dummy editor available" id="574619656">
+ <message_arguments>
+ <message_argument value="IDiagramEditor"/>
+ <message_argument value="DiagramEditorDummy"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInternal.java" type="org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal">
+ <filter comment="Allow implementation accross Graphiti project borders" id="574619656">
+ <message_arguments>
+ <message_argument value="IDiagramEditor"/>
+ <message_argument value="DiagramEditorInternal"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/parts/IPictogramElementDelegate.java" type="org.eclipse.graphiti.ui.internal.parts.IPictogramElementDelegate">
+ <filter id="571473929">
+ <message_arguments>
+ <message_argument value="IFeatureProviderHolder"/>
+ <message_argument value="IPictogramElementDelegate"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/parts/IPictogramElementEditPart.java" type="org.eclipse.graphiti.ui.internal.parts.IPictogramElementEditPart">
+ <filter id="571473929">
+ <message_arguments>
+ <message_argument value="IFeatureProviderHolder"/>
+ <message_argument value="IPictogramElementEditPart"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/platform/DiagramTypeImpl.java" type="org.eclipse.graphiti.ui.internal.platform.DiagramTypeImpl">
+ <filter id="574619656">
+ <message_arguments>
+ <message_argument value="IDiagramType"/>
+ <message_argument value="DiagramTypeImpl"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/internal/services/impl/UiLayoutService.java" type="org.eclipse.graphiti.ui.internal.services.impl.UiLayoutService">
+ <filter comment="test" id="574660632">
+ <message_arguments>
+ <message_argument value="IUiLayoutService"/>
+ <message_argument value="ILayoutService"/>
+ <message_argument value="UiLayoutService"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/graphiti/ui/services/IUiLayoutService.java" type="org.eclipse.graphiti.ui.services.IUiLayoutService">
+ <filter id="571473929">
+ <message_arguments>
+ <message_argument value="ILayoutService"/>
+ <message_argument value="IUiLayoutService"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorDummy.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorDummy.java
index 2aba90f..a20400c 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorDummy.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorDummy.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -9,6 +9,8 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -20,6 +22,8 @@
import org.eclipse.graphiti.datatypes.IDimension;
import org.eclipse.graphiti.datatypes.ILocation;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeature;
+import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.internal.datatypes.impl.DimensionImpl;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.platform.IDiagramEditor;
@@ -111,4 +115,8 @@
public ILocation getCurrentMouseLocation() {
return null;
}
+
+ @Override
+ public void executeFeature(IFeature feature, IContext context) {
+ }
}
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInternal.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInternal.java
index e85daad..130f677 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInternal.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/DiagramEditorInternal.java
@@ -18,6 +18,8 @@
* mwenz - Bug 345347 - There should be a way to not allow other plugins to contribute to the diagram context menu
* mwenz - Bug 346932 - Navigation history broken
* mwenz - Bug 356828 - Escaped diagram name is used as editor title
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -32,6 +34,7 @@
import java.util.Map;
import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.IFigure;
@@ -87,14 +90,21 @@
import org.eclipse.graphiti.datatypes.IDimension;
import org.eclipse.graphiti.datatypes.ILocation;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.IDirectEditingInfo;
+import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.IPrintFeature;
import org.eclipse.graphiti.features.ISaveImageFeature;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ISaveImageContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.SaveImageContext;
import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.internal.command.AddFeatureCommandWithContext;
+import org.eclipse.graphiti.internal.command.FeatureCommandWithContext;
+import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
import org.eclipse.graphiti.internal.datatypes.impl.DimensionImpl;
import org.eclipse.graphiti.internal.datatypes.impl.LocationImpl;
import org.eclipse.graphiti.internal.pref.GFPreferences;
@@ -121,6 +131,7 @@
import org.eclipse.graphiti.ui.internal.action.RemoveAction;
import org.eclipse.graphiti.ui.internal.action.SaveImageAction;
import org.eclipse.graphiti.ui.internal.action.UpdateAction;
+import org.eclipse.graphiti.ui.internal.command.GefCommandWrapper;
import org.eclipse.graphiti.ui.internal.config.ConfigurationProvider;
import org.eclipse.graphiti.ui.internal.config.IConfigurationProvider;
import org.eclipse.graphiti.ui.internal.config.IConfigurationProviderHolder;
@@ -1685,6 +1696,46 @@
return editingDomain;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.graphiti.platform.IDiagramEditor#executeFeature(org.eclipse
+ * .graphiti.features.IFeature,
+ * org.eclipse.graphiti.features.context.IContext)
+ */
+ @Override
+ public void executeFeature(IFeature feature, IContext context) {
+ DefaultEditDomain domain = getEditDomain();
+
+ // Make sure the editor is valid
+ Assert.isNotNull(domain);
+ CommandStack commandStack = domain.getCommandStack();
+
+ // Create the correct feature command
+ FeatureCommandWithContext featureCommand = null;
+ if (feature instanceof IAddFeature) {
+ // Context must fit to the feature
+ Assert.isTrue(context instanceof IAddContext);
+ featureCommand = new AddFeatureCommandWithContext(feature, context);
+ } else {
+ featureCommand = new GenericFeatureCommandWithContext(feature, context);
+ }
+
+ // Execute the feature using the command
+ GefCommandWrapper commandWrapper = new GefCommandWrapper(featureCommand, editingDomain);
+ commandStack.execute(commandWrapper);
+
+ if (featureCommand instanceof AddFeatureCommandWithContext) {
+ // In case of an add feature, select the newly added shape
+ PictogramElement addedPictogramElement = ((AddFeatureCommandWithContext) featureCommand)
+ .getAddedPictogramElements();
+ if (addedPictogramElement != null) {
+ setPictogramElementForSelection(addedPictogramElement);
+ }
+ }
+ }
+
/**
*
* @return the resource set
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IFeatureProvider.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IFeatureProvider.java
index 85f025f..f1731c3 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IFeatureProvider.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/IFeatureProvider.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -11,6 +11,8 @@
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 323155 - Check usage scenarios for DefaultPrintFeature and
* DefaultSaveImageFeature
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -402,7 +404,9 @@
* @param context
* the context
*
- * @return status and reason
+ * @return status and reason, simply a <code>true</code> {@link IReason} in
+ * case the layout operation was executed, a <code>false</code>
+ * {@link IReason} otherwise.
*/
IReason layoutIfPossible(ILayoutContext context);
@@ -438,13 +442,6 @@
*/
IReason updateNeeded(IUpdateContext context);
- // /**
- // * Gets the transactional editing domain.
- // *
- // * @return transactional editing domain which is linked to the editor
- // */
- // TransactionalEditingDomain getTransactionalEditingDomain();
-
/**
* This is called to dispose the object.
*/
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractFeatureProvider.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractFeatureProvider.java
index e724abb..34b62d4 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractFeatureProvider.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/AbstractFeatureProvider.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -10,6 +10,8 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 340627 - Features should be able to indicate cancellation
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -69,9 +71,6 @@
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.internal.ExternalPictogramLink;
-import org.eclipse.graphiti.internal.command.AddFeatureCommandWithContext;
-import org.eclipse.graphiti.internal.command.CommandExec;
-import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
import org.eclipse.graphiti.internal.services.GraphitiInternal;
import org.eclipse.graphiti.internal.util.T;
import org.eclipse.graphiti.mm.Property;
@@ -250,13 +249,9 @@
boolean b = false;
IUpdateFeature updateFeature = getUpdateFeature(context);
if (updateFeature != null) {
- // if (updateSemanticsFeature != null &&
- // updateSemanticsFeature.canUpdate(context)) {
- // ret = updateSemanticsFeature.update(context);
- // }
- TransactionalEditingDomain editingDomain = getDiagramTypeProvider().getDiagramEditor().getEditingDomain();
+ IDiagramEditor diagramEditor = getDiagramTypeProvider().getDiagramEditor();
try {
- b = CommandExec.getSingleton().executeCommand(new GenericFeatureCommandWithContext(updateFeature, context), editingDomain);
+ diagramEditor.executeFeature(updateFeature, context);
} catch (Exception e) {
// Wrap in RuintimeException (handled by all callers)
if (e instanceof RuntimeException) {
@@ -283,12 +278,12 @@
boolean b = false;
ILayoutFeature layoutSemanticsFeature = getLayoutFeature(context);
if (layoutSemanticsFeature != null) {
- TransactionalEditingDomain editingDomain = getDiagramTypeProvider().getDiagramEditor().getEditingDomain();
+ IDiagramEditor diagramEditor = getDiagramTypeProvider().getDiagramEditor();
try {
- b = CommandExec.getSingleton().executeCommand(new GenericFeatureCommandWithContext(layoutSemanticsFeature, context),
- editingDomain);
+ diagramEditor.executeFeature(layoutSemanticsFeature, context);
+ b = true;
} catch (Exception e) {
- // Wrap in RuintimeException (handled by all callers)
+ // Wrap in RuntimeException (handled by all callers)
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
@@ -354,11 +349,9 @@
PictogramElement ret = null;
if (canAdd(context).toBoolean()) {
IAddFeature feature = getAddFeature(context);
- AddFeatureCommandWithContext addFeatureCommandWithContext = new AddFeatureCommandWithContext(feature, context);
- TransactionalEditingDomain editingDomain = getDiagramTypeProvider().getDiagramEditor().getEditingDomain();
- boolean b = false;
+ IDiagramEditor diagramEditor = getDiagramTypeProvider().getDiagramEditor();
try {
- b = CommandExec.getSingleton().executeCommand(addFeatureCommandWithContext, editingDomain);
+ diagramEditor.executeFeature(feature, context);
} catch (Exception e) {
// Wrap in RuintimeException (handled by all callers)
if (e instanceof RuntimeException) {
@@ -367,13 +360,6 @@
throw new RuntimeException(e);
}
}
- if (b) {
- ret = addFeatureCommandWithContext.getAddedPictogramElements();
- IDiagramEditor diagramEditor = getDiagramTypeProvider().getDiagramEditor();
- if (diagramEditor != null) {
- diagramEditor.setPictogramElementForSelection(ret);
- }
- }
}
if (info) {
T.racer().exiting(AbstractFeatureProvider.class, SIGNATURE, ret);
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultUpdateDiagramFeature.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultUpdateDiagramFeature.java
index a96030b..711d4c2 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultUpdateDiagramFeature.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultUpdateDiagramFeature.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -9,6 +9,8 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -37,6 +39,8 @@
*/
public class DefaultUpdateDiagramFeature extends AbstractUpdateFeature {
+ private boolean hasDoneChanges = false;
+
/**
* Creates a new {@link DefaultUpdateDiagramFeature}.
*
@@ -69,8 +73,15 @@
connToUpdate.put(updateFeature, updateContext);
}
}
+
+ // Reset hasDoneChanges flag because no changes have happened so far
+ hasDoneChanges = false;
for (IUpdateFeature feature : connToUpdate.keySet()) {
feature.update(connToUpdate.get(feature));
+ if (feature.hasDoneChanges()) {
+ // At least one sub feature did some changes
+ hasDoneChanges = true;
+ }
}
}
return true;
@@ -100,4 +111,14 @@
}
return Reason.createFalseReason();
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.graphiti.features.impl.AbstractFeature#hasDoneChanges()
+ */
+ @Override
+ public boolean hasDoneChanges() {
+ return hasDoneChanges;
+ }
}
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/command/CommandExec.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/command/CommandExec.java
index f7a7265..5dc766b 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/command/CommandExec.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/internal/command/CommandExec.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -10,6 +10,8 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 340627 - Features should be able to indicate cancellation
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -40,7 +42,16 @@
}
/**
- * Execute command.
+ * Execute a given command within the given
+ * {@link TransactionalEditingDomain}.<br>
+ * IMPORTANT: use this method only in situations in which you don't have an
+ * open diagram editor. This method will simply execute the command on the
+ * command stack of the EMF editing domain, while the editor wraps this with
+ * a workspace command stack that will additionally monitor if an operation
+ * has really done any changes and in case not will reset the editor dirty
+ * flag again (see {@link IFeature#hasDoneChanges()}.<br>
+ * If you have a DiagramEditor instance use its method executeFeature
+ * instead.
*
* @param command
* the command
@@ -106,7 +117,16 @@
}
/**
- * Execute feature with context.
+ * Execute feature with context.<br>
+ * IMPORTANT: use this method only in situations in which you don't have an
+ * open diagram editor. This method will simply execute the command on the
+ * command stack of the EMF editing domain, while the editor wraps this with
+ * a workspace command stack that will additionally monitor if an operation
+ * has really done any changes and in case not will reset the editor dirty
+ * flag again (see {@link IFeature#hasDoneChanges()}.<br>
+ * If you have a DiagramEditor instance use its method executeFeature
+ * instead.
+ *
*
* @param feature
* the feature
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/platform/IDiagramEditor.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/platform/IDiagramEditor.java
index f995f82..312799b 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/platform/IDiagramEditor.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/platform/IDiagramEditor.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -9,6 +9,8 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -20,10 +22,15 @@
import org.eclipse.graphiti.datatypes.IDimension;
import org.eclipse.graphiti.datatypes.ILocation;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeature;
+import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
/**
* The Interface IDiagramEditor.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ * Extend DiagramEditor instead.
*/
public interface IDiagramEditor {
@@ -137,4 +144,19 @@
* @return the mouse location
*/
ILocation getCurrentMouseLocation();
+
+ /**
+ * Executes the given feature in the given context using the command stack
+ * and editing domain of the diagram editor. In case of an IAddFeature being
+ * passed this method will also trigger the selection of the newly added
+ * shape.
+ *
+ * @param feature
+ * The feature to execute
+ * @param context
+ * The context object to use with the feature
+ *
+ * @since 0.9
+ */
+ void executeFeature(IFeature feature, IContext context);
}
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/tb/AbstractContextEntry.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/tb/AbstractContextEntry.java
index 5790854..4f4fbb4 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/tb/AbstractContextEntry.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/tb/AbstractContextEntry.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -10,6 +10,8 @@
* Contributors:
* SAP AG - initial API, implementation and documentation
* mwenz - Bug 340627 - Features should be able to indicate cancellation
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature
+ * and called features via editor command stack to check it
*
* </copyright>
*
@@ -18,13 +20,11 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.transaction.RollbackException;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
-import org.eclipse.graphiti.internal.command.CommandExec;
-import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
import org.eclipse.graphiti.internal.util.T;
+import org.eclipse.graphiti.platform.IDiagramEditor;
/**
* The Class AbstractContextEntry.
@@ -65,11 +65,9 @@
}
public void execute() {
- GenericFeatureCommandWithContext genericFeatureCommandWithContext = new GenericFeatureCommandWithContext(getFeature(), getContext());
- TransactionalEditingDomain editingDomain = getFeature().getFeatureProvider().getDiagramTypeProvider().getDiagramEditor()
- .getEditingDomain();
+ IDiagramEditor diagramEditor = getFeature().getFeatureProvider().getDiagramTypeProvider().getDiagramEditor();
try {
- CommandExec.getSingleton().executeCommand(genericFeatureCommandWithContext, editingDomain);
+ diagramEditor.executeFeature(getFeature(), getContext());
} catch (Exception e) {
if (e instanceof RollbackException) {
// Just log it as info (operation was cancelled on purpose)
diff --git a/tests/org.eclipse.graphiti.bot.tests/plugin.xml b/tests/org.eclipse.graphiti.bot.tests/plugin.xml
index 8b661b4..0b3a321 100644
--- a/tests/org.eclipse.graphiti.bot.tests/plugin.xml
+++ b/tests/org.eclipse.graphiti.bot.tests/plugin.xml
Binary files differ
diff --git a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/DTPwithAutoUpdateAtStartup.java b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/DTPwithAutoUpdateAtStartup.java
new file mode 100644
index 0000000..afa2f09
--- /dev/null
+++ b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/DTPwithAutoUpdateAtStartup.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2011 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:
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature and
+ * called features via editor command stack to check it
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.bot.tests;
+
+import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
+
+public class DTPwithAutoUpdateAtStartup extends AbstractDiagramTypeProvider implements IDiagramTypeProvider {
+
+ public DTPwithAutoUpdateAtStartup() {
+ super();
+ setFeatureProvider(new DefaultFeatureProvider(this));
+ }
+
+ @Override
+ public boolean isAutoUpdateAtStartup() {
+ return true;
+ }
+}
diff --git a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/GFOtherTests.java b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/GFOtherTests.java
index 47ec975..e504c10 100644
--- a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/GFOtherTests.java
+++ b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/GFOtherTests.java
@@ -13,6 +13,8 @@
* mwenz - Bug 348662 - Setting tooptip to null in tool behavior provider doesn't clear up
* tooltip if the associated figure has a previous tooltip
* mwenz - Bug 356828 - Escaped diagram name is used as editor title
+ * mwenz - Bug 356218 - Added hasDoneChanges updates to update diagram feature and
+ * called features via editor command stack to check it
*
* </copyright>
*
@@ -1109,6 +1111,15 @@
assertEquals("Diagram Object", wp.getGefEditor().getTitle());
}
+ @Test
+ public void testAutoUpdateAtStartup() throws Exception {
+ // Test for Bug 356218 - DefaultUpdateDiagramFeature correctly
+ // triggered via editor command stack
+ DiagramEditor diagramEditor = openDiagram(ITestConstants.DIAGRAM_TYPE_ID_WITH_AUTO_UPDATE_AT_STARTUP);
+ Thread.sleep(1000);
+ assertFalse(diagramEditor.isDirty());
+ }
+
private IFile createPersistentDiagram() throws Exception {
return createPersistentDiagram(null);
}
diff --git a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/util/ITestConstants.java b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/util/ITestConstants.java
index 2e17701..9fcff06 100644
--- a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/util/ITestConstants.java
+++ b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/util/ITestConstants.java
@@ -38,4 +38,11 @@
*/
public static final String DIAGRAM_TYPE_ID_TUTORIAL = "tutorial";
+ /**
+ * The Constant DIAGRAM_TYPE_ID_WITH_AUTO_UPDATE_AT_STARTUP.
+ *
+ * @since 0.9
+ */
+ public static final String DIAGRAM_TYPE_ID_WITH_AUTO_UPDATE_AT_STARTUP = "dtWithAutoUpdateAtStartup";
+
}
diff --git a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/DefaultFeaturesTest.java b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/DefaultFeaturesTest.java
index 66cdaf6..431bc69 100644
--- a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/DefaultFeaturesTest.java
+++ b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/DefaultFeaturesTest.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 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
@@ -9,6 +9,8 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * Bug 356218 - Added hasDoneChanges updates to update diagram feature and
+ * called features via editor command stack to check it
*
* </copyright>
*
@@ -30,6 +32,8 @@
import org.eclipse.graphiti.datatypes.ILocation;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.IReason;
+import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.AddBendpointContext;
import org.eclipse.graphiti.features.context.impl.AreaAnchorContext;
import org.eclipse.graphiti.features.context.impl.MoveBendpointContext;
@@ -39,6 +43,8 @@
import org.eclipse.graphiti.features.context.impl.RemoveBendpointContext;
import org.eclipse.graphiti.features.context.impl.RemoveContext;
import org.eclipse.graphiti.features.context.impl.ResizeShapeContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.DefaultAddBendpointFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveAnchorFeature;
import org.eclipse.graphiti.features.impl.DefaultMoveBendpointFeature;
@@ -48,6 +54,8 @@
import org.eclipse.graphiti.features.impl.DefaultRemoveBendpointFeature;
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
+import org.eclipse.graphiti.features.impl.DefaultUpdateDiagramFeature;
+import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor;
import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
@@ -78,6 +86,9 @@
private static IFeatureProvider fpMock;
+ // Update feature instance used for DefaultUpdateDiagramFeature tests
+ private static AbstractUpdateFeatureExtension abstractUpdateFeature = new AbstractUpdateFeatureExtension(fpMock);
+
@BeforeClass
public static void prepareClass() {
fpMock = createNiceMock(IFeatureProvider.class);
@@ -89,6 +100,7 @@
expect(fpMock.getDiagramTypeProvider()).andReturn(dtpMock).anyTimes();
expect(fpMock.getRemoveFeature(isA(RemoveContext.class))).andReturn(new DefaultRemoveFeature(fpMock));
expect(dtpMock.getDiagramEditor()).andReturn(editorMock).anyTimes();
+ expect(fpMock.getUpdateFeature(isA(UpdateContext.class))).andReturn(abstractUpdateFeature).anyTimes();
replay(fpMock, dtpMock, editorMock);
}
@@ -252,6 +264,46 @@
}
+ @Test
+ public void updateDiagramNoChildren() throws Exception {
+ // Test for Bug 356218 - DefaultUpdateDiagramFeature correctly
+ // implements hasDoneChanges
+ Diagram diagram = Graphiti.getPeCreateService().createDiagram("dummy", "Test", true);
+ DefaultUpdateDiagramFeature feature = new DefaultUpdateDiagramFeature(fpMock);
+ UpdateContext context = new UpdateContext(diagram);
+ assertTrue(feature.canExecute(context));
+ feature.execute(context);
+ assertFalse(feature.hasDoneChanges());
+ }
+
+ @Test
+ public void updateDiagramWithChildrenNegative() throws Exception {
+ // Test for Bug 356218 - DefaultUpdateDiagramFeature correctly
+ // implements hasDoneChanges
+ Diagram diagram = Graphiti.getPeCreateService().createDiagram("dummy", "Test", true);
+ ContainerShape containerShape = Graphiti.getPeCreateService().createContainerShape(diagram, true);
+ ((AbstractUpdateFeatureExtension) (fpMock.getUpdateFeature(new UpdateContext(containerShape)))).hasDoneChanges = false;
+ DefaultUpdateDiagramFeature feature = new DefaultUpdateDiagramFeature(fpMock);
+ UpdateContext context = new UpdateContext(diagram);
+ assertTrue(feature.canExecute(context));
+ feature.execute(context);
+ assertFalse(feature.hasDoneChanges());
+ }
+
+ @Test
+ public void updateDiagramWithChildrenPositive() throws Exception {
+ // Test for Bug 356218 - DefaultUpdateDiagramFeature correctly
+ // implements hasDoneChanges
+ Diagram diagram = Graphiti.getPeCreateService().createDiagram("dummy", "Test", true);
+ ContainerShape containerShape = Graphiti.getPeCreateService().createContainerShape(diagram, true);
+ ((AbstractUpdateFeatureExtension) (fpMock.getUpdateFeature(new UpdateContext(containerShape)))).hasDoneChanges = true;
+ DefaultUpdateDiagramFeature feature = new DefaultUpdateDiagramFeature(fpMock);
+ UpdateContext context = new UpdateContext(diagram);
+ assertTrue(feature.canExecute(context));
+ feature.execute(context);
+ assertTrue(feature.hasDoneChanges());
+ }
+
@After
public void uninitializeTest() {
@@ -262,4 +314,41 @@
fpMock = null;
}
+ /**
+ *
+ */
+ private static final class AbstractUpdateFeatureExtension extends AbstractUpdateFeature {
+
+ boolean hasDoneChanges = false;
+
+ private AbstractUpdateFeatureExtension(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public IReason updateNeeded(IUpdateContext context) {
+ return Reason.createTrueReason();
+ }
+
+ @Override
+ public boolean update(IUpdateContext context) {
+ return true;
+ }
+
+ @Override
+ public boolean canUpdate(IUpdateContext context) {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.graphiti.features.impl.AbstractFeature#hasDoneChanges()
+ */
+ @Override
+ public boolean hasDoneChanges() {
+ return hasDoneChanges;
+ }
+ }
}