01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.undo;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.core.commands.operations.IUndoContext;
16: import org.eclipse.core.runtime.IAdaptable;
17: import org.eclipse.core.runtime.IProgressMonitor;
18: import org.eclipse.core.runtime.IStatus;
19: import org.eclipse.core.runtime.Status;
20: import org.eclipse.swt.widgets.Canvas;
21:
22: /**
23: * An operation that adds a box.
24: */
25: public class ClearBoxesOperation extends BoxOperation {
26:
27: /*
28: * The boxes that are saved after clearing
29: */
30: private List savedBoxes = new ArrayList();
31:
32: public ClearBoxesOperation(String label, IUndoContext context,
33: Boxes boxes, Canvas canvas) {
34: super (label, context, boxes, null, canvas);
35: }
36:
37: /*
38: * (non-Javadoc)
39: * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
40: */
41: public IStatus execute(IProgressMonitor monitor, IAdaptable info) {
42: savedBoxes = boxes.getBoxes();
43: boxes.clear();
44: canvas.redraw();
45: return Status.OK_STATUS;
46: }
47:
48: /*
49: * (non-Javadoc)
50: * @see org.eclipse.core.commands.operations.IUndoableOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
51: */
52: public IStatus redo(IProgressMonitor monitor, IAdaptable info) {
53: return execute(monitor, info);
54: }
55:
56: /*
57: * (non-Javadoc)
58: * @see org.eclipse.core.commands.operations.IUndoableOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59: */
60: public IStatus undo(IProgressMonitor monitor, IAdaptable info) {
61: boxes.setBoxes(savedBoxes);
62: canvas.redraw();
63: return Status.OK_STATUS;
64: }
65:
66: }
|