Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b8dea60667b761806eaa27e3e509e50b6876139d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*******************************************************************************
 * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES.
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.diagram.ui.tools.internal.commands;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;

/**
 * ICommand forwarding calls to a wrapped instance, except for the
 * "affected file" which are always returned null.
 * 
 * @author cbrun
 * 
 */
public class WrappingCommandIgnoringAffectedFiles implements ICommand {

    private ICommand original;

    /**
     * Create a new wrapper.
     * 
     * @param wrapped
     *            the wrapped command.
     */
    public WrappingCommandIgnoringAffectedFiles(final ICommand wrapped) {
        this.original = wrapped;
    }

    /**
     * Return the original command wrapped by this command.
     * 
     * @return the original command wrapped by this command.
     */
    public ICommand getOriginalCommand() {
        return original;
    }

    /**
     * {@inheritDoc}
     */
    public IStatus undo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
        IStatus status = null;
        if (original != null) {
            status = original.undo(monitor, info);
        }
        return status;
    }

    /**
     * {@inheritDoc}
     */
    public void removeContext(final IUndoContext context) {
        if (original != null) {
            original.removeContext(context);
        }
    }

    /**
     * {@inheritDoc}
     */
    public IStatus redo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
        IStatus status = null;
        if (original != null) {
            status = original.redo(monitor, info);
        }
        return status;
    }

    /**
     * {@inheritDoc}
     */
    public boolean hasContext(final IUndoContext context) {
        boolean hasContext = false;
        if (original != null) {
            hasContext = original.hasContext(context);
        }
        return hasContext;
    }

    /**
     * {@inheritDoc}
     */
    public String getLabel() {
        String label = null;
        if (original != null) {
            label = original.getLabel();
        }
        return label;
    }

    /**
     * {@inheritDoc}
     */
    public IUndoContext[] getContexts() {
        IUndoContext[] contexts = new IUndoContext[0];
        if (original != null) {
            contexts = original.getContexts();
        }
        return contexts;
    }

    /**
     * {@inheritDoc}
     */
    public IStatus execute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
        return original.execute(monitor, info);
    }

    /**
     * {@inheritDoc}
     */
    public void dispose() {
        if (original != null) {
            original.dispose();
            original = null;
        }
    }

    /**
     * {@inheritDoc}
     */
    public boolean canUndo() {
        boolean canUndo = false;
        if (original != null) {
            canUndo = original.canUndo();
        }
        return canUndo;
    }

    /**
     * {@inheritDoc}
     */
    public boolean canRedo() {
        boolean canRedo = false;
        if (original != null) {
            canRedo = original.canRedo();
        }
        return canRedo;
    }

    /**
     * {@inheritDoc}
     */
    public boolean canExecute() {
        boolean canExecute = false;
        if (original != null) {
            canExecute = original.canExecute();
        }
        return canExecute;
    }

    /**
     * {@inheritDoc}
     */
    public void addContext(final IUndoContext context) {
        if (original != null) {
            original.addContext(context);
        }

    }

    /**
     * {@inheritDoc}
     */
    public void setLabel(final String label) {
        if (original != null) {
            original.setLabel(label);
        }
    }

    /**
     * {@inheritDoc}
     */
    public ICommand reduce() {
        ICommand command = null;
        if (original != null) {
            command = original.reduce();
        }
        return command;
    }

    /**
     * {@inheritDoc}
     */
    public CommandResult getCommandResult() {
        CommandResult commandResult = null;
        if (original != null) {
            commandResult = original.getCommandResult();
        }
        return commandResult;
    }

    /**
     * {@inheritDoc}
     */
    public List getAffectedFiles() {
        return new ArrayList<>();
    }

    /**
     * {@inheritDoc}
     */
    public ICommand compose(final IUndoableOperation operation) {
        ICommand command = null;
        if (original != null) {
            command = original.compose(operation);
        }
        return command;
    }
}

Back to the top