KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > WizardTreeSelectionPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.wizards;
12
13 import org.eclipse.jface.viewers.ColumnWeightData;
14 import org.eclipse.jface.viewers.DoubleClickEvent;
15 import org.eclipse.jface.viewers.IDoubleClickListener;
16 import org.eclipse.jface.viewers.ISelectionChangedListener;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.jface.viewers.SelectionChangedEvent;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.jface.viewers.TableLayout;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.jface.viewers.TreeViewer;
23 import org.eclipse.jface.wizard.IWizardNode;
24 import org.eclipse.pde.internal.ui.elements.ElementLabelProvider;
25 import org.eclipse.pde.internal.ui.elements.ListContentProvider;
26 import org.eclipse.pde.internal.ui.elements.TreeContentProvider;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.custom.BusyIndicator;
29 import org.eclipse.swt.custom.SashForm;
30 import org.eclipse.swt.layout.FillLayout;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Table;
34 import org.eclipse.swt.widgets.TableColumn;
35 import org.eclipse.swt.widgets.Tree;
36
37
38 public abstract class WizardTreeSelectionPage
39     extends BaseWizardSelectionPage
40     implements ISelectionChangedListener {
41     private TreeViewer categoryTreeViewer;
42     private String JavaDoc baseCategory;
43     protected TableViewer wizardSelectionViewer;
44
45     private WizardCollectionElement wizardCategories;
46
47     public WizardTreeSelectionPage(
48         WizardCollectionElement categories,
49         String JavaDoc baseCategory,
50         String JavaDoc message) {
51         super("NewExtension", message); //$NON-NLS-1$
52
this.wizardCategories = categories;
53         this.baseCategory = baseCategory;
54     }
55     public void advanceToNextPage() {
56         getContainer().showPage(getNextPage());
57     }
58     public void createControl(Composite parent) {
59         // top level group
60
Composite container = new Composite(parent, SWT.NULL);
61         FillLayout flayout = new FillLayout();
62         flayout.marginWidth = 5;
63         flayout.marginHeight = 5;
64         container.setLayout(flayout);
65         SashForm rootSash = new SashForm(container, SWT.VERTICAL);
66         SashForm outerSash = new SashForm(rootSash, SWT.HORIZONTAL);
67         GridLayout layout = new GridLayout();
68         layout.numColumns = 2;
69
70         // tree pane
71
Tree tree = new Tree(outerSash, SWT.BORDER);
72         categoryTreeViewer = new TreeViewer(tree);
73         categoryTreeViewer.setContentProvider(new TreeContentProvider());
74         categoryTreeViewer.setLabelProvider(ElementLabelProvider.INSTANCE);
75
76         categoryTreeViewer.setComparator(new WizardCollectionComparator(baseCategory));
77         categoryTreeViewer.addSelectionChangedListener(this);
78
79         // wizard actions pane
80
Table table = new Table(outerSash, SWT.BORDER);
81         new TableColumn(table, SWT.NONE);
82         TableLayout tlayout = new TableLayout();
83         tlayout.addColumnData(new ColumnWeightData(100));
84         table.setLayout(tlayout);
85
86         wizardSelectionViewer = new TableViewer(table);
87         wizardSelectionViewer.setContentProvider(new ListContentProvider());
88         wizardSelectionViewer.setLabelProvider(ListUtil.TABLE_LABEL_PROVIDER);
89         wizardSelectionViewer.setComparator(ListUtil.NAME_COMPARATOR);
90         wizardSelectionViewer.addSelectionChangedListener(this);
91         wizardSelectionViewer
92             .addDoubleClickListener(new IDoubleClickListener() {
93             public void doubleClick(DoubleClickEvent event) {
94                 BusyIndicator
95                     .showWhile(
96                         wizardSelectionViewer.getControl().getDisplay(),
97                         new Runnable JavaDoc() {
98                     public void run() {
99                         selectionChanged(
100                             new SelectionChangedEvent(
101                                 wizardSelectionViewer,
102                                 wizardSelectionViewer.getSelection()));
103                         advanceToNextPage();
104                     }
105                 });
106             }
107         });
108
109         // the new composite below is needed in order to make the label span the two
110
// defined columns of outerContainer
111
Composite descriptionComposite =
112             new Composite(rootSash, SWT.NONE);
113         layout = new GridLayout();
114         layout.marginHeight = 0;
115         layout.marginWidth = 0;
116         descriptionComposite.setLayout(layout);
117         createDescriptionIn(descriptionComposite);
118
119         initializeViewers();
120         rootSash.setWeights(new int[] {70, 30});
121         setControl(container);
122     }
123     protected Object JavaDoc getSingleSelection(IStructuredSelection selection) {
124         Object JavaDoc selectedObject = selection.getFirstElement();
125         if (selection.size() > 1)
126             selectedObject = null; // ie.- a multi-selection
127
return selectedObject;
128     }
129     private void handleCategorySelection(SelectionChangedEvent selectionEvent) {
130         setErrorMessage(null);
131         setDescriptionText(""); //$NON-NLS-1$
132
setSelectedNode(null);
133
134         WizardCollectionElement selectedCategory =
135             (WizardCollectionElement) getSingleSelection(
136                 (IStructuredSelection) selectionEvent
137                 .getSelection());
138
139         if (selectedCategory == null)
140             wizardSelectionViewer.setInput(null);
141         else
142             wizardSelectionViewer.setInput(selectedCategory.getWizards());
143     }
144     private void handleWizardSelection(SelectionChangedEvent selectionEvent) {
145         setErrorMessage(null);
146
147         WizardElement currentSelection =
148             (WizardElement) getSingleSelection(
149                 (IStructuredSelection) selectionEvent
150                 .getSelection());
151
152         // If no single selection, clear and return
153
if (currentSelection == null) {
154             setDescriptionText(""); //$NON-NLS-1$
155
setSelectedNode(null);
156             return;
157         }
158         final WizardElement finalSelection = currentSelection;
159         /*
160             BusyIndicator.showWhile(categoryTreeViewer.getControl().getDisplay(), new Runnable() {
161                 public void run() {
162                 */

163         setSelectedNode(createWizardNode(finalSelection));
164         setDescriptionText(finalSelection.getDescription());
165         /*
166                 }
167             });
168         */

169     }
170     protected void initializeViewers() {
171         categoryTreeViewer.setInput(wizardCategories);
172         wizardSelectionViewer.addSelectionChangedListener(this);
173         Object JavaDoc[] categories = wizardCategories.getChildren();
174         if (categories.length > 0)
175             categoryTreeViewer.setSelection(new StructuredSelection(
176                     categories[0]));
177         categoryTreeViewer.getTree().setFocus();
178     }
179     public void selectionChanged(SelectionChangedEvent selectionEvent) {
180         if (selectionEvent.getSelectionProvider().equals(categoryTreeViewer))
181             handleCategorySelection(selectionEvent);
182         else
183             handleWizardSelection(selectionEvent);
184     }
185     public void setSelectedNode(IWizardNode node) {
186         super.setSelectedNode(node);
187     }
188 }
189
Popular Tags