001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards;
011:
012: import org.eclipse.jface.viewers.ColumnWeightData;
013: import org.eclipse.jface.viewers.DoubleClickEvent;
014: import org.eclipse.jface.viewers.IDoubleClickListener;
015: import org.eclipse.jface.viewers.ISelectionChangedListener;
016: import org.eclipse.jface.viewers.IStructuredSelection;
017: import org.eclipse.jface.viewers.SelectionChangedEvent;
018: import org.eclipse.jface.viewers.StructuredSelection;
019: import org.eclipse.jface.viewers.TableLayout;
020: import org.eclipse.jface.viewers.TableViewer;
021: import org.eclipse.jface.viewers.TreeViewer;
022: import org.eclipse.jface.wizard.IWizardNode;
023: import org.eclipse.pde.internal.ui.elements.ElementLabelProvider;
024: import org.eclipse.pde.internal.ui.elements.ListContentProvider;
025: import org.eclipse.pde.internal.ui.elements.TreeContentProvider;
026: import org.eclipse.swt.SWT;
027: import org.eclipse.swt.custom.BusyIndicator;
028: import org.eclipse.swt.custom.SashForm;
029: import org.eclipse.swt.layout.FillLayout;
030: import org.eclipse.swt.layout.GridLayout;
031: import org.eclipse.swt.widgets.Composite;
032: import org.eclipse.swt.widgets.Table;
033: import org.eclipse.swt.widgets.TableColumn;
034: import org.eclipse.swt.widgets.Tree;
035:
036: public abstract class WizardTreeSelectionPage extends
037: BaseWizardSelectionPage implements ISelectionChangedListener {
038: private TreeViewer categoryTreeViewer;
039: private String baseCategory;
040: protected TableViewer wizardSelectionViewer;
041:
042: private WizardCollectionElement wizardCategories;
043:
044: public WizardTreeSelectionPage(WizardCollectionElement categories,
045: String baseCategory, String message) {
046: super ("NewExtension", message); //$NON-NLS-1$
047: this .wizardCategories = categories;
048: this .baseCategory = baseCategory;
049: }
050:
051: public void advanceToNextPage() {
052: getContainer().showPage(getNextPage());
053: }
054:
055: public void createControl(Composite parent) {
056: // top level group
057: Composite container = new Composite(parent, SWT.NULL);
058: FillLayout flayout = new FillLayout();
059: flayout.marginWidth = 5;
060: flayout.marginHeight = 5;
061: container.setLayout(flayout);
062: SashForm rootSash = new SashForm(container, SWT.VERTICAL);
063: SashForm outerSash = new SashForm(rootSash, SWT.HORIZONTAL);
064: GridLayout layout = new GridLayout();
065: layout.numColumns = 2;
066:
067: // tree pane
068: Tree tree = new Tree(outerSash, SWT.BORDER);
069: categoryTreeViewer = new TreeViewer(tree);
070: categoryTreeViewer
071: .setContentProvider(new TreeContentProvider());
072: categoryTreeViewer
073: .setLabelProvider(ElementLabelProvider.INSTANCE);
074:
075: categoryTreeViewer
076: .setComparator(new WizardCollectionComparator(
077: baseCategory));
078: categoryTreeViewer.addSelectionChangedListener(this );
079:
080: // wizard actions pane
081: Table table = new Table(outerSash, SWT.BORDER);
082: new TableColumn(table, SWT.NONE);
083: TableLayout tlayout = new TableLayout();
084: tlayout.addColumnData(new ColumnWeightData(100));
085: table.setLayout(tlayout);
086:
087: wizardSelectionViewer = new TableViewer(table);
088: wizardSelectionViewer
089: .setContentProvider(new ListContentProvider());
090: wizardSelectionViewer
091: .setLabelProvider(ListUtil.TABLE_LABEL_PROVIDER);
092: wizardSelectionViewer.setComparator(ListUtil.NAME_COMPARATOR);
093: wizardSelectionViewer.addSelectionChangedListener(this );
094: wizardSelectionViewer
095: .addDoubleClickListener(new IDoubleClickListener() {
096: public void doubleClick(DoubleClickEvent event) {
097: BusyIndicator.showWhile(wizardSelectionViewer
098: .getControl().getDisplay(),
099: new Runnable() {
100: public void run() {
101: selectionChanged(new SelectionChangedEvent(
102: wizardSelectionViewer,
103: wizardSelectionViewer
104: .getSelection()));
105: advanceToNextPage();
106: }
107: });
108: }
109: });
110:
111: // the new composite below is needed in order to make the label span the two
112: // defined columns of outerContainer
113: Composite descriptionComposite = new Composite(rootSash,
114: SWT.NONE);
115: layout = new GridLayout();
116: layout.marginHeight = 0;
117: layout.marginWidth = 0;
118: descriptionComposite.setLayout(layout);
119: createDescriptionIn(descriptionComposite);
120:
121: initializeViewers();
122: rootSash.setWeights(new int[] { 70, 30 });
123: setControl(container);
124: }
125:
126: protected Object getSingleSelection(IStructuredSelection selection) {
127: Object selectedObject = selection.getFirstElement();
128: if (selection.size() > 1)
129: selectedObject = null; // ie.- a multi-selection
130: return selectedObject;
131: }
132:
133: private void handleCategorySelection(
134: SelectionChangedEvent selectionEvent) {
135: setErrorMessage(null);
136: setDescriptionText(""); //$NON-NLS-1$
137: setSelectedNode(null);
138:
139: WizardCollectionElement selectedCategory = (WizardCollectionElement) getSingleSelection((IStructuredSelection) selectionEvent
140: .getSelection());
141:
142: if (selectedCategory == null)
143: wizardSelectionViewer.setInput(null);
144: else
145: wizardSelectionViewer.setInput(selectedCategory
146: .getWizards());
147: }
148:
149: private void handleWizardSelection(
150: SelectionChangedEvent selectionEvent) {
151: setErrorMessage(null);
152:
153: WizardElement currentSelection = (WizardElement) getSingleSelection((IStructuredSelection) selectionEvent
154: .getSelection());
155:
156: // If no single selection, clear and return
157: if (currentSelection == null) {
158: setDescriptionText(""); //$NON-NLS-1$
159: setSelectedNode(null);
160: return;
161: }
162: final WizardElement finalSelection = currentSelection;
163: /*
164: BusyIndicator.showWhile(categoryTreeViewer.getControl().getDisplay(), new Runnable() {
165: public void run() {
166: */
167: setSelectedNode(createWizardNode(finalSelection));
168: setDescriptionText(finalSelection.getDescription());
169: /*
170: }
171: });
172: */
173: }
174:
175: protected void initializeViewers() {
176: categoryTreeViewer.setInput(wizardCategories);
177: wizardSelectionViewer.addSelectionChangedListener(this );
178: Object[] categories = wizardCategories.getChildren();
179: if (categories.length > 0)
180: categoryTreeViewer.setSelection(new StructuredSelection(
181: categories[0]));
182: categoryTreeViewer.getTree().setFocus();
183: }
184:
185: public void selectionChanged(SelectionChangedEvent selectionEvent) {
186: if (selectionEvent.getSelectionProvider().equals(
187: categoryTreeViewer))
188: handleCategorySelection(selectionEvent);
189: else
190: handleWizardSelection(selectionEvent);
191: }
192:
193: public void setSelectedNode(IWizardNode node) {
194: super.setSelectedNode(node);
195: }
196: }
|