01: package org.openwfe.gpe.ui;
02:
03: import java.util.EventObject;
04:
05: import org.eclipse.ui.views.contentoutline.*;
06: import org.eclipse.jface.viewers.*;
07: import org.eclipse.swt.widgets.Composite;
08: import org.eclipse.gef.commands.*;
09: import org.eclipse.gef.*;
10:
11: import org.eclipse.gef.ui.actions.*;
12: import org.openwfe.gpe.model.*;
13: import org.openwfe.gpe.parts.*;
14:
15: /**
16: * @author Helena
17: *
18: * This class creates the outline treeview
19: */
20: public class DiagramOutlinePage extends ContentOutlinePage implements
21: CommandStackListener {
22: private EditPart input;
23: private ActionRegistry ar;
24: private CommandStack commandStack;
25: public static TreeViewer treeViewer;
26:
27: public DiagramOutlinePage(CommandStack commandStack,
28: EditPart input, ActionRegistry ar) {
29: this .commandStack = commandStack;
30: commandStack.addCommandStackListener(this );
31: this .input = input;
32: this .ar = ar;
33: }
34:
35: public TreeViewer getOutline() {
36: return treeViewer;
37: }
38:
39: public void createControl(Composite parent) {
40: super .createControl(parent);
41:
42: treeViewer = getTreeViewer();
43: treeViewer.setContentProvider(new MyTreeContentProvider2());
44: treeViewer.setInput(input);
45: treeViewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
46:
47: }
48:
49: public void commandStackChanged(EventObject event) {
50: treeViewer.refresh();
51: }
52:
53: public void dispose() {
54: super .dispose();
55: commandStack.removeCommandStackListener(this );
56: }
57: }
58:
59: class MyTreeContentProvider2 implements ITreeContentProvider {
60: public Object[] getChildren(Object parentElement) {
61: if (parentElement instanceof EditPart)
62: return ((EditPart) parentElement).getChildren().toArray();
63: else
64: return new Object[0];
65: }
66:
67: public Object getParent(Object element) {
68: if (element instanceof EditPart) {
69: return ((EditPart) element).getParent();
70:
71: } else {
72: return new Object[0];
73: }
74: }
75:
76: public boolean hasChildren(Object element) {
77: return !(element instanceof FlowElement);
78: }
79:
80: public Object[] getElements(Object inputElement) {
81: return getChildren(inputElement);
82: }
83:
84: public void dispose() {
85: }
86:
87: public void inputChanged(Viewer viewer, Object oldInput,
88: Object newInput) {
89: }
90:
91: public String getText(Object element) {
92: if (element instanceof EditPart) {
93: Object model = ((EditPart) element).getModel();
94: if (model instanceof FlowElementPart)
95: return model.toString();
96: }
97: return null;
98: }
99: }
|