01: /*******************************************************************************
02: * Copyright (c) 2000, 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.pde.internal.ui.tests.macro;
11:
12: import java.io.PrintWriter;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IProgressMonitor;
16: import org.eclipse.swt.widgets.Composite;
17: import org.eclipse.swt.widgets.Display;
18: import org.eclipse.swt.widgets.Event;
19:
20: public class FocusCommand extends MacroCommand {
21: public static final String TYPE = "focus";
22:
23: public FocusCommand(WidgetIdentifier wid) {
24: super (wid);
25: }
26:
27: public boolean mergeEvent(Event e) {
28: // we can directly merge repeated focus requests
29: // on the same widget
30: return true;
31: }
32:
33: /* (non-Javadoc)
34: * @see org.eclipse.ui.macro.MacroCommand#getType()
35: */
36: public String getType() {
37: return TYPE;
38: }
39:
40: /* (non-Javadoc)
41: * @see org.eclipse.ui.macro.MacroCommand#processEvent(org.eclipse.swt.widgets.Event)
42: */
43: public void processEvent(Event e) {
44: }
45:
46: /* (non-Javadoc)
47: * @see org.eclipse.ui.macro.IWritable#write(java.lang.String, java.io.PrintWriter)
48: */
49: public void write(String indent, PrintWriter writer) {
50: writer.print(indent);
51: writer.print("<command type=\"");
52: writer.print(getType());
53: writer.print("\" contextId=\"");
54: writer.print(getWidgetId().getContextId());
55: writer.print("\" widgetId=\"");
56: writer.print(getWidgetId().getWidgetId());
57: writer.print("\"");
58: writer.println("/>");
59: }
60:
61: /* (non-Javadoc)
62: * @see org.eclipse.ui.macro.IPlayable#playback(org.eclipse.swt.widgets.Composite)
63: */
64: public boolean playback(Display display, Composite parent,
65: IProgressMonitor monitor) throws CoreException {
66: if (parent.isDisposed())
67: return false;
68: CommandTarget target = MacroUtil.locateCommandTarget(parent,
69: getWidgetId(), getStartLine());
70: if (target != null)
71: target.setFocus();
72: return true;
73: }
74: }
|