01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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.pde.internal.ui.tests.macro;
11:
12: import java.util.Hashtable;
13: import java.util.Map;
14:
15: import org.eclipse.core.runtime.Path;
16: import org.eclipse.swt.widgets.Event;
17: import org.w3c.dom.Node;
18:
19: public abstract class MacroCommand implements IWritable, IPlayable {
20: private WidgetIdentifier widgetId;
21: private int[] range;
22:
23: public MacroCommand(WidgetIdentifier widgetId) {
24: this .widgetId = widgetId;
25: }
26:
27: public abstract String getType();
28:
29: public abstract void processEvent(Event e);
30:
31: protected void load(Node node, Hashtable lineTable) {
32: String cid = MacroUtil.getAttribute(node, "contextId");
33: String wid = MacroUtil.getAttribute(node, "widgetId");
34: if (wid != null && cid != null)
35: widgetId = new WidgetIdentifier(new Path(cid),
36: new Path(wid));
37: bindSourceLocation(node, lineTable);
38: }
39:
40: void bindSourceLocation(Node node, Map lineTable) {
41: Integer[] lines = (Integer[]) lineTable.get(node);
42: if (lines != null) {
43: range = new int[2];
44: range[0] = lines[0].intValue();
45: range[1] = lines[1].intValue();
46: }
47: }
48:
49: public int getStartLine() {
50: if (range == null)
51: return -1;
52: return range[0];
53: }
54:
55: public int getStopLine() {
56: if (range == null)
57: return -1;
58: return range[1];
59: }
60:
61: public boolean mergeEvent(Event e) {
62: return false;
63: }
64:
65: public WidgetIdentifier getWidgetId() {
66: return widgetId;
67: }
68:
69: public String toString() {
70: return "MacroCommand [" + getType() + ", line "
71: + getStartLine() + "]";
72: }
73: }
|