Skip to content

Commit c6ae223

Browse files
committed
[GEF] Replace executeCommand() in EditDomain with CommandStack
The special handling of commands done in the executeCommand() method should instead be done via a custom CommandStack.
1 parent 0bdec56 commit c6ae223

11 files changed

Lines changed: 39 additions & 34 deletions

File tree

org.eclipse.wb.core.java/src/org/eclipse/wb/internal/core/editor/actions/CutAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 Google, Inc. 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
@@ -71,7 +71,7 @@ public void run() throws Exception {
7171
CopyAction.doCopy(m_mementos);
7272
}
7373
// delete
74-
m_viewer.getEditDomain().executeCommand(m_command);
74+
m_viewer.getEditDomain().getCommandStack().execute(m_command);
7575
}
7676
});
7777
}

org.eclipse.wb.core.java/src/org/eclipse/wb/internal/core/gef/tools/TabOrderTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private void deactivateTabContainerPolicy() {
250250
if (m_containerPolicy != null) {
251251
m_containerPolicy.eraseTargetFeedback(m_containerRequest);
252252
if (m_saveTabOrder && m_containerRequest.getCommand() != null) {
253-
getDomain().executeCommand(m_containerRequest.getCommand());
253+
getDomain().getCommandStack().execute(m_containerRequest.getCommand());
254254
}
255255
}
256256
}

org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/Tool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected final void executeCommand() {
169169
if (m_command != null) {
170170
Command command = m_command;
171171
setCommand(null);
172-
getDomain().executeCommand(command);
172+
getDomain().getCommandStack().execute(command);
173173
}
174174
}
175175

org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/core/EditDomain.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.eclipse.draw2d.EventListenerList;
2020
import org.eclipse.gef.EditPartViewer;
2121
import org.eclipse.gef.commands.Command;
22+
import org.eclipse.gef.commands.CommandStack;
2223
import org.eclipse.swt.events.MouseEvent;
2324

2425
/**
@@ -32,31 +33,35 @@ public class EditDomain extends org.eclipse.gef.EditDomain {
3233
private MouseEvent m_currentMouseEvent;
3334
private ICommandExceptionHandler m_exceptionHandler;
3435

36+
public EditDomain() {
37+
setCommandStack(new DesignerCommandStack());
38+
}
39+
3540
////////////////////////////////////////////////////////////////////////////
3641
//
3742
// Commands/Exceptions
3843
//
3944
////////////////////////////////////////////////////////////////////////////
4045
private Tool m_inCommandTool;
4146

42-
/**
43-
* Execute given {@link Command} and handle all exceptions.
44-
*/
45-
public void executeCommand(Command command) {
46-
clearToolDuringCommandExecution();
47-
try {
48-
if (System.getProperty("wbp.EditDomain.simulateCommandException") != null) {
49-
throw new Error("Simulated exception.");
50-
}
51-
command.execute();
52-
} catch (Throwable e) {
53-
if (m_exceptionHandler != null) {
54-
m_exceptionHandler.handleException(e);
55-
// exception handler usually recreates viewer, so we should cancel execution on current viewer
56-
throw new CancelOperationError();
47+
private class DesignerCommandStack extends CommandStack {
48+
@Override
49+
public void execute(Command command) {
50+
clearToolDuringCommandExecution();
51+
try {
52+
if (System.getProperty("wbp.EditDomain.simulateCommandException") != null) {
53+
throw new Error("Simulated exception.");
54+
}
55+
super.execute(command);
56+
} catch (Throwable e) {
57+
if (m_exceptionHandler != null) {
58+
m_exceptionHandler.handleException(e);
59+
// exception handler usually recreates viewer, so we should cancel execution on current viewer
60+
throw new CancelOperationError();
61+
}
62+
} finally {
63+
restoreToolAfterCommandExecution();
5764
}
58-
} finally {
59-
restoreToolAfterCommandExecution();
6065
}
6166
}
6267

org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/dnd/TreeDropListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private static Set<? extends EditPart> includeChildren(List<? extends EditPart>
271271
private void executeCommand() {
272272
if (m_command != null) {
273273
try {
274-
m_viewer.getEditDomain().executeCommand(m_command);
274+
m_viewer.getEditDomain().getCommandStack().execute(m_command);
275275
} finally {
276276
setCommand(null);
277277
}

org.eclipse.wb.core/src/org/eclipse/wb/internal/core/editor/actions/DeleteAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 Google, Inc. 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
@@ -63,7 +63,7 @@ public void selectionChanged(SelectionChangedEvent event) {
6363

6464
@Override
6565
public void run() {
66-
m_viewer.getEditDomain().executeCommand(m_command);
66+
m_viewer.getEditDomain().getCommandStack().execute(m_command);
6767
}
6868

6969
@Override

org.eclipse.wb.core/src/org/eclipse/wb/internal/core/gef/policy/layout/absolute/KeyboardMovingLayoutEditPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 Google, Inc. 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
@@ -186,7 +186,7 @@ public void run() {
186186
}
187187
}
188188
// run command
189-
getViewer().getEditDomain().executeCommand(command);
189+
getViewer().getEditDomain().getCommandStack().execute(command);
190190
}
191191
} finally {
192192
m_isKeyboardMoving = false;

org.eclipse.wb.rcp/src/org/eclipse/wb/internal/rcp/gef/policy/forms/layout/grid/TableWrapSelectionEditPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2023 Google, Inc.
2+
* Copyright (c) 2011, 2025 Google, Inc. 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
@@ -255,7 +255,7 @@ public void run() throws Exception {
255255
* Executes given {@link RunnableEx} as edit operation.
256256
*/
257257
private void execute(final RunnableEx runnable) {
258-
getHost().getViewer().getEditDomain().executeCommand(new EditCommand(m_component) {
258+
getHost().getViewer().getEditDomain().getCommandStack().execute(new EditCommand(m_component) {
259259
@Override
260260
protected void executeEdit() throws Exception {
261261
runnable.run();

org.eclipse.wb.swing.FormLayout/src/org/eclipse/wb/internal/swing/FormLayout/gef/header/selection/DimensionSelectionEditPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2023 Google, Inc.
2+
* Copyright (c) 2011, 2025 Google, Inc. 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
@@ -147,7 +147,7 @@ public Command getCommand(Request request) {
147147
return new Command() {
148148
@Override
149149
public void execute() {
150-
getHost().getViewer().getEditDomain().executeCommand(m_resizeCommand);
150+
getHost().getViewer().getEditDomain().getCommandStack().execute(m_resizeCommand);
151151
}
152152
};
153153
}

org.eclipse.wb.swing.MigLayout/src/org/eclipse/wb/internal/swing/MigLayout/gef/header/selection/DimensionSelectionEditPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2023 Google, Inc.
2+
* Copyright (c) 2011, 2025 Google, Inc. 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
@@ -152,7 +152,7 @@ public Command getCommand(Request request) {
152152
return new Command() {
153153
@Override
154154
public void execute() {
155-
getHost().getViewer().getEditDomain().executeCommand(m_resizeCommand);
155+
getHost().getViewer().getEditDomain().getCommandStack().execute(m_resizeCommand);
156156
}
157157
};
158158
}

0 commit comments

Comments
 (0)