Skip to content

Commit 2a9227d

Browse files
ptzieglerazoitl
authored andcommitted
Deprecate CommandStackListener for removal
This interface has been deprecated a long time ago in favor of the CommandStackEventListener.
1 parent 6048a18 commit 2a9227d

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

org.eclipse.gef.examples.flow/src/org/eclipse/gef/examples/flow/ui/FlowEditor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.ObjectInputStream;
2020
import java.io.ObjectOutputStream;
2121
import java.io.OutputStream;
22-
import java.util.EventObject;
2322

2423
import org.eclipse.swt.SWT;
2524

@@ -46,6 +45,8 @@
4645
import org.eclipse.gef.DefaultEditDomain;
4746
import org.eclipse.gef.KeyHandler;
4847
import org.eclipse.gef.KeyStroke;
48+
import org.eclipse.gef.commands.CommandStackEvent;
49+
import org.eclipse.gef.commands.CommandStackEventListener;
4950
import org.eclipse.gef.dnd.TemplateTransferDragSourceListener;
5051
import org.eclipse.gef.dnd.TemplateTransferDropTargetListener;
5152
import org.eclipse.gef.editparts.ScalableRootEditPart;
@@ -77,12 +78,14 @@ public FlowEditor() {
7778
}
7879

7980
/**
80-
* @see org.eclipse.gef.commands.CommandStackListener#commandStackChanged(java.util.EventObject)
81+
* @see CommandStackEventListener#stackChanged(CommandStackEvent event)
8182
*/
8283
@Override
83-
public void commandStackChanged(EventObject event) {
84-
firePropertyChange(IEditorPart.PROP_DIRTY);
85-
super.commandStackChanged(event);
84+
public void stackChanged(CommandStackEvent event) {
85+
if (event.isPostChangeEvent()) {
86+
firePropertyChange(IEditorPart.PROP_DIRTY);
87+
}
88+
super.stackChanged(event);
8689
}
8790

8891
/**

org.eclipse.gef.tests/src/org/eclipse/gef/test/CommandStackTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void stackChanged(CommandStackEvent event) {
159159
}
160160

161161
@Test
162-
@SuppressWarnings("static-method")
162+
@SuppressWarnings({ "static-method", "removal" })
163163
public void testConcurrentModification2() {
164164
CommandStack stack = new CommandStack();
165165
CommandStackListener listener = new CommandStackListener() {

org.eclipse.gef/src/org/eclipse/gef/commands/CommandStack.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -132,9 +132,10 @@ public class CommandStack {
132132
* The list of {@link CommandStackListener}s.
133133
*
134134
* @deprecated This field should not be referenced, use
135-
* {@link #notifyListeners()}
135+
* {@link #notifyListeners()}. This field will be removed after the
136+
* 2027-03 release.
136137
*/
137-
@Deprecated
138+
@Deprecated(since = "3.11", forRemoval = true)
138139
protected List<CommandStackListener> listeners = new CopyOnWriteArrayList<>();
139140

140141
private final Stack<Command> redoable = new Stack<>();
@@ -170,9 +171,9 @@ public void addCommandStackEventListener(CommandStackEventListener listener) {
170171
* @param listener the listener
171172
* @deprecated Use
172173
* {@link #addCommandStackEventListener(CommandStackEventListener)}
173-
* instead.
174+
* instead. This method will be removed after the 2027-03 release.
174175
*/
175-
@Deprecated
176+
@Deprecated(since = "3.11", forRemoval = true)
176177
public void addCommandStackListener(CommandStackListener listener) {
177178
listeners.add(listener);
178179
}
@@ -342,9 +343,10 @@ public void markSaveLocation() {
342343
/**
343344
* Sends notification to all {@link CommandStackListener}s.
344345
*
345-
* @deprecated Use {@link #notifyListeners(Command, int)} instead.
346+
* @deprecated Use {@link #notifyListeners(Command, int)} instead. This method
347+
* will be removed after the 2027-03 release.
346348
*/
347-
@Deprecated
349+
@Deprecated(since = "3.11", forRemoval = true)
348350
protected void notifyListeners() {
349351
EventObject event = new EventObject(this);
350352
listeners.forEach(listener -> listener.commandStackChanged(event));
@@ -397,9 +399,10 @@ public void removeCommandStackEventListener(CommandStackEventListener listener)
397399
* Removes the first occurrence of the specified listener.
398400
*
399401
* @param listener the listener
400-
* @deprecated Use {@link CommandStackEventListener} instead.
402+
* @deprecated Use {@link CommandStackEventListener} instead. This method will
403+
* be removed after the 2027-03 release.
401404
*/
402-
@Deprecated
405+
@Deprecated(since = "3.11", forRemoval = true)
403406
public void removeCommandStackListener(CommandStackListener listener) {
404407
listeners.remove(listener);
405408
}

org.eclipse.gef/src/org/eclipse/gef/commands/CommandStackListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -19,8 +19,10 @@
1919
* has changed.
2020
*
2121
* @deprecated Use {@link CommandStackEventListener} instead and filter for
22-
* post-events using {@link CommandStack#POST_MASK}.
22+
* post-events using {@link CommandStack#POST_MASK}. This interface
23+
* will be removed after the 2027-03 release.
2324
*/
25+
@Deprecated(since = "3.11", forRemoval = true)
2426
public interface CommandStackListener {
2527

2628
/**

org.eclipse.gef/src/org/eclipse/gef/ui/parts/GraphicalEditor.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -38,6 +38,8 @@
3838
import org.eclipse.gef.GraphicalEditPart;
3939
import org.eclipse.gef.GraphicalViewer;
4040
import org.eclipse.gef.commands.CommandStack;
41+
import org.eclipse.gef.commands.CommandStackEvent;
42+
import org.eclipse.gef.commands.CommandStackEventListener;
4143
import org.eclipse.gef.commands.CommandStackListener;
4244
import org.eclipse.gef.ui.actions.ActionBarContributor;
4345
import org.eclipse.gef.ui.actions.ActionRegistry;
@@ -60,7 +62,9 @@
6062
*
6163
* @author hudsonr
6264
*/
63-
public abstract class GraphicalEditor extends EditorPart implements CommandStackListener, ISelectionListener {
65+
@SuppressWarnings("removal")
66+
public abstract class GraphicalEditor extends EditorPart
67+
implements CommandStackListener, CommandStackEventListener, ISelectionListener {
6468

6569
private DefaultEditDomain editDomain;
6670
private GraphicalViewer graphicalViewer;
@@ -81,12 +85,28 @@ public GraphicalEditor() {
8185
* are updated.
8286
*
8387
* @param event the change event
88+
* @deprecated Use {@link #stackChanged(CommandStackEvent)} instead. This method
89+
* will be removed after the 2027-03 release.
8490
*/
8591
@Override
92+
@Deprecated(since = "3.21", forRemoval = true)
8693
public void commandStackChanged(EventObject event) {
8794
updateActions(stackActions);
8895
}
8996

97+
/**
98+
* When the command stack changes, the actions interested in the command stack
99+
* are updated.
100+
*
101+
* @param event the change event
102+
*/
103+
@Override
104+
public void stackChanged(CommandStackEvent event) {
105+
if (event.isPostChangeEvent()) {
106+
commandStackChanged(event);
107+
}
108+
}
109+
90110
/**
91111
* Called to configure the graphical viewer before it receives its contents.
92112
* This is where the root editpart should be configured. Subclasses should

0 commit comments

Comments
 (0)