Skip to content

Commit

Permalink
Deprecate CommandStackListener for removal
Browse files Browse the repository at this point in the history
This interface has been deprecated a long time ago in favor of the
CommandStackEventListener.
  • Loading branch information
ptziegler authored and azoitl committed Jan 18, 2025
1 parent 6048a18 commit 2a9227d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.EventObject;

import org.eclipse.swt.SWT;

Expand All @@ -46,6 +45,8 @@
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.KeyHandler;
import org.eclipse.gef.KeyStroke;
import org.eclipse.gef.commands.CommandStackEvent;
import org.eclipse.gef.commands.CommandStackEventListener;
import org.eclipse.gef.dnd.TemplateTransferDragSourceListener;
import org.eclipse.gef.dnd.TemplateTransferDropTargetListener;
import org.eclipse.gef.editparts.ScalableRootEditPart;
Expand Down Expand Up @@ -77,12 +78,14 @@ public FlowEditor() {
}

/**
* @see org.eclipse.gef.commands.CommandStackListener#commandStackChanged(java.util.EventObject)
* @see CommandStackEventListener#stackChanged(CommandStackEvent event)
*/
@Override
public void commandStackChanged(EventObject event) {
firePropertyChange(IEditorPart.PROP_DIRTY);
super.commandStackChanged(event);
public void stackChanged(CommandStackEvent event) {
if (event.isPostChangeEvent()) {
firePropertyChange(IEditorPart.PROP_DIRTY);
}
super.stackChanged(event);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void stackChanged(CommandStackEvent event) {
}

@Test
@SuppressWarnings("static-method")
@SuppressWarnings({ "static-method", "removal" })
public void testConcurrentModification2() {
CommandStack stack = new CommandStack();
CommandStackListener listener = new CommandStackListener() {
Expand Down
21 changes: 12 additions & 9 deletions org.eclipse.gef/src/org/eclipse/gef/commands/CommandStack.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -132,9 +132,10 @@ public class CommandStack {
* The list of {@link CommandStackListener}s.
*
* @deprecated This field should not be referenced, use
* {@link #notifyListeners()}
* {@link #notifyListeners()}. This field will be removed after the
* 2027-03 release.
*/
@Deprecated
@Deprecated(since = "3.11", forRemoval = true)
protected List<CommandStackListener> listeners = new CopyOnWriteArrayList<>();

private final Stack<Command> redoable = new Stack<>();
Expand Down Expand Up @@ -170,9 +171,9 @@ public void addCommandStackEventListener(CommandStackEventListener listener) {
* @param listener the listener
* @deprecated Use
* {@link #addCommandStackEventListener(CommandStackEventListener)}
* instead.
* instead. This method will be removed after the 2027-03 release.
*/
@Deprecated
@Deprecated(since = "3.11", forRemoval = true)
public void addCommandStackListener(CommandStackListener listener) {
listeners.add(listener);
}
Expand Down Expand Up @@ -342,9 +343,10 @@ public void markSaveLocation() {
/**
* Sends notification to all {@link CommandStackListener}s.
*
* @deprecated Use {@link #notifyListeners(Command, int)} instead.
* @deprecated Use {@link #notifyListeners(Command, int)} instead. This method
* will be removed after the 2027-03 release.
*/
@Deprecated
@Deprecated(since = "3.11", forRemoval = true)
protected void notifyListeners() {
EventObject event = new EventObject(this);
listeners.forEach(listener -> listener.commandStackChanged(event));
Expand Down Expand Up @@ -397,9 +399,10 @@ public void removeCommandStackEventListener(CommandStackEventListener listener)
* Removes the first occurrence of the specified listener.
*
* @param listener the listener
* @deprecated Use {@link CommandStackEventListener} instead.
* @deprecated Use {@link CommandStackEventListener} instead. This method will
* be removed after the 2027-03 release.
*/
@Deprecated
@Deprecated(since = "3.11", forRemoval = true)
public void removeCommandStackListener(CommandStackListener listener) {
listeners.remove(listener);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -19,8 +19,10 @@
* has changed.
*
* @deprecated Use {@link CommandStackEventListener} instead and filter for
* post-events using {@link CommandStack#POST_MASK}.
* post-events using {@link CommandStack#POST_MASK}. This interface
* will be removed after the 2027-03 release.
*/
@Deprecated(since = "3.11", forRemoval = true)
public interface CommandStackListener {

/**
Expand Down
24 changes: 22 additions & 2 deletions org.eclipse.gef/src/org/eclipse/gef/ui/parts/GraphicalEditor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -38,6 +38,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;
Expand All @@ -60,7 +62,9 @@
*
* @author hudsonr
*/
public abstract class GraphicalEditor extends EditorPart implements CommandStackListener, ISelectionListener {
@SuppressWarnings("removal")
public abstract class GraphicalEditor extends EditorPart
implements CommandStackListener, CommandStackEventListener, ISelectionListener {

private DefaultEditDomain editDomain;
private GraphicalViewer graphicalViewer;
Expand All @@ -81,12 +85,28 @@ public GraphicalEditor() {
* are updated.
*
* @param event the change event
* @deprecated Use {@link #stackChanged(CommandStackEvent)} instead. This method
* will be removed after the 2027-03 release.
*/
@Override
@Deprecated(since = "3.21", forRemoval = true)
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
*/
@Override
public void stackChanged(CommandStackEvent event) {
if (event.isPostChangeEvent()) {
commandStackChanged(event);
}
}

/**
* Called to configure the graphical viewer before it receives its contents.
* This is where the root editpart should be configured. Subclasses should
Expand Down

0 comments on commit 2a9227d

Please sign in to comment.