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 org.eclipse.swt.SWT;
13: import org.eclipse.swt.custom.TableTree;
14: import org.eclipse.swt.custom.TableTreeItem;
15: import org.eclipse.swt.widgets.Event;
16: import org.eclipse.swt.widgets.Table;
17: import org.eclipse.swt.widgets.TableItem;
18: import org.eclipse.swt.widgets.Tree;
19: import org.eclipse.swt.widgets.TreeItem;
20: import org.eclipse.swt.widgets.Widget;
21:
22: public class ExpansionCommand extends ToggleStructuredCommand {
23: public static final String TYPE = "item-expand";
24:
25: /**
26: * @param wid
27: */
28: public ExpansionCommand(WidgetIdentifier wid) {
29: super (wid);
30: }
31:
32: public void processEvent(Event event) {
33: super .processEvent(event);
34: Widget item = event.item;
35:
36: if (item instanceof TreeItem)
37: value = !((TreeItem) item).getExpanded();
38: else if (item instanceof TableTreeItem)
39: value = !((TableTreeItem) item).getExpanded();
40: }
41:
42: protected void playTreeCommand(Tree tree, TreeItem[] matches) {
43: for (int i = 0; i < matches.length; i++) {
44: matches[i].setExpanded(getValue());
45: fireEvent(tree, matches[i]);
46: }
47: }
48:
49: private void fireEvent(Widget widget, Widget item) {
50: Event event = new Event();
51: event.type = getValue() ? SWT.Expand : SWT.Collapse;
52: event.widget = widget;
53: event.item = item;
54: widget.notifyListeners(event.type, event);
55: }
56:
57: protected void playTableCommand(Table table, TableItem[] matches) {
58: }
59:
60: protected void playTableTreeCommand(TableTree tableTree,
61: TableTreeItem[] matches) {
62: for (int i = 0; i < matches.length; i++) {
63: matches[i].setExpanded(getValue());
64: fireEvent(tableTree, matches[i]);
65: }
66: }
67:
68: /* (non-Javadoc)
69: * @see org.eclipse.ui.macro.SelectionCommand#getKind()
70: */
71: public String getType() {
72: return TYPE;
73: }
74: }
|