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 org.eclipse.core.commands.operations.IUndoContext;
13: import org.eclipse.core.runtime.IAdaptable;
14: import org.eclipse.core.runtime.IProgressMonitor;
15: import org.eclipse.core.runtime.IStatus;
16: import org.eclipse.core.runtime.Status;
17: import org.eclipse.swt.widgets.Canvas;
18:
19: /**
20: * An operation that adds a box.
21: */
22: public class AddBoxOperation extends BoxOperation {
23:
24: /**
25: * Create a box
26: * @param label
27: * @param context
28: * @param boxes
29: * @param box
30: * @param canvas
31: */
32: public AddBoxOperation(String label, IUndoContext context,
33: Boxes boxes, Box box, Canvas canvas) {
34: super (label, context, boxes, box, canvas);
35: }
36:
37: public IStatus execute(IProgressMonitor monitor, IAdaptable info) {
38: boxes.add(box);
39: canvas.redraw(box.x1, box.y1, box.x2, box.y2, false);
40: return Status.OK_STATUS;
41: }
42:
43: public boolean canUndo() {
44: return boxes.contains(box);
45: }
46:
47: public IStatus undo(IProgressMonitor monitor, IAdaptable info) {
48: boxes.remove(box);
49: canvas.redraw(box.x1, box.y1, box.x2, box.y2, false);
50: return Status.OK_STATUS;
51: }
52:
53: public boolean canRedo() {
54: return !boxes.contains(box);
55: }
56:
57: public IStatus redo(IProgressMonitor monitor, IAdaptable info) {
58: return execute(monitor, info);
59: }
60:
61: }
|