Bug 531207 - Prepare removal of deprecated CommandStackListener GEF
interface

Change-Id: I21a657ccbb183c253c7118d94fe3fd5d62c14110
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditor.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditor.java
index e463df8..c893bc2 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditor.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/DiagramEditor.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * <copyright>
  *
- * Copyright (c) 2005, 2014 SAP AG.
+ * Copyright (c) 2005, 2018 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
@@ -38,6 +38,7 @@
  *    mwenz - Bug 430687 - UpdateBehaviour createEditingDomain should be able to access diagram input (sphinx compatibility)
  *    Hernan Gonzales (mwenz) - Bug 436601 - Race condition on save
  *    mwenz - Bug 407894 - Luna: After DiagramsInViews change graphical viewer is configured and initialized only by a workaround
+ *    mwenz - Bug 531207 - Prepare removal of deprecated CommandStackListener GEF interface
  *
  * </copyright>
  *
@@ -59,6 +60,9 @@
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
 import org.eclipse.gef.DefaultEditDomain;
 import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.commands.CommandStackEvent;
+import org.eclipse.gef.commands.CommandStackEventListener;
 import org.eclipse.gef.palette.PaletteRoot;
 import org.eclipse.gef.ui.actions.ActionRegistry;
 import org.eclipse.gef.ui.palette.FlyoutPaletteComposite.FlyoutPreferences;
@@ -136,7 +140,7 @@
  * 
  */
 public class DiagramEditor extends GraphicalEditorWithFlyoutPalette implements IDiagramContainerUI,
-		ITabbedPropertySheetPageContributor, IEditingDomainProvider {
+		ITabbedPropertySheetPageContributor, IEditingDomainProvider, CommandStackEventListener {
 
 	private String contributorId;
 	private DiagramBehavior diagramBehavior;
@@ -226,7 +230,7 @@
 			// In case of error simply show an primitive editor with a label
 			return;
 		}
-		getCommandStack().addCommandStackListener(this);
+		getCommandStack().addCommandStackEventListener(this);
 		getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
 		initializeActionRegistry();
 		// ... End of GEF functionality taken over
@@ -857,10 +861,21 @@
 		return super.getSelectionActions();
 	}
 
+	@Override
 	public void commandStackChanged(EventObject event) {
 		super.commandStackChanged(event);
 	}
 
+	/**
+	 * @since 0.15
+	 */
+	@Override
+	public void stackChanged(CommandStackEvent event) {
+		if ((event.getDetail() & CommandStack.POST_MASK) != 0) {
+			commandStackChanged(event);
+		}
+	}
+
 	public void setGraphicalViewer(GraphicalViewer viewer) {
 		super.setGraphicalViewer(viewer);
 	}
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/GraphicalComposite.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/GraphicalComposite.java
index 8080693..6f02ed5 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/GraphicalComposite.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/editor/GraphicalComposite.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * <copyright>
  *
- * Copyright (c) 2015 SRC
+ * Copyright (c) 2015-2018 SRC, SAP SE
  * 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,7 @@
  * Contributors:
  *    pjpaulin - initial API, implementation and documentation
  *    jsivadier - Bug 467502 - Improve DiagramComposite implementation without IWorkbenchPart
+ *    mwenz - Bug 531207 - Prepare removal of deprecated CommandStackListener GEF interface
  *
  * </copyright>
  *
@@ -29,6 +30,8 @@
 import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.GraphicalViewer;
 import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.commands.CommandStackEvent;
+import org.eclipse.gef.commands.CommandStackEventListener;
 import org.eclipse.gef.commands.CommandStackListener;
 import org.eclipse.gef.ui.actions.ActionBarContributor;
 import org.eclipse.gef.ui.actions.ActionRegistry;
@@ -60,7 +63,8 @@
  *               changed without prior notice!
  */
 @SuppressWarnings("rawtypes")
-public abstract class GraphicalComposite extends Composite implements CommandStackListener,
+public abstract class GraphicalComposite extends Composite
+		implements CommandStackListener, CommandStackEventListener,
         ISelectionListener {
 
     @SuppressWarnings("serial")
@@ -100,15 +104,34 @@
     }
 
     /**
-     * When the command stack changes, the actions interested in the command stack are updated.
-     * 
-     * @param event
-     *            the change event
-     */
-    public void commandStackChanged(EventObject event) {
-        updateActions(stackActions);
+	 * When the command stack changes, the actions interested in the command
+	 * stack are updated.
+	 * 
+	 * @param event
+	 *            the change event
+	 * @since 0.15
+	 */
+	@Override
+	public void stackChanged(CommandStackEvent event) {
+		if ((event.getDetail() & CommandStack.POST_MASK) != 0) {
+			updateActions(stackActions);
+		}
     }
 
+	/**
+	 * When the command stack changes, the actions interested in the command
+	 * stack are updated.
+	 * 
+	 * @param event
+	 *            the change event
+	 * @deprecated Replaced by {@link #stackChanged(CommandStackEvent)} because
+	 *             the class {@link CommandStackListener} is deprecated by GEF
+	 */
+	@Override
+	public void commandStackChanged(EventObject event) {
+		updateActions(stackActions);
+	}
+
     /**
      * Called to configure the graphical viewer before it receives its contents. This is where the
      * root editpart should be configured. Subclasses should extend or override this method as
@@ -179,7 +202,7 @@
      * @see org.eclipse.ui.IWorkbenchPart#dispose()
      */
     public void dispose() {
-        getCommandStack().removeCommandStackListener(this);
+		getCommandStack().removeCommandStackEventListener(this);
 		if (getWorkbenchPart() != null)
 			this.getWorkbenchPart().getSite().getWorkbenchWindow().getSelectionService()
                 .removeSelectionListener(this);
@@ -217,7 +240,7 @@
      * 
      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
      */
-    public Object getAdapter(Class type) {
+	public Object getAdapter(Class type) {
         if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) {
             return new UndoablePropertySheetPage(getCommandStack(), getActionRegistry().getAction(
                     ActionFactory.UNDO.getId()), getActionRegistry().getAction(
@@ -324,7 +347,7 @@
     }
 
     protected void init() {
-        getCommandStack().addCommandStackListener(this);
+		getCommandStack().addCommandStackEventListener(this);
 		if (getWorkbenchPart() != null) {
 			this.getWorkbenchPart().getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
 			initializeActionRegistry();