1 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 baseCategory; 43 protected TableViewer wizardSelectionViewer; 44 45 private WizardCollectionElement wizardCategories; 46 47 public WizardTreeSelectionPage( 48 WizardCollectionElement categories, 49 String baseCategory, 50 String message) { 51 super("NewExtension", message); this.wizardCategories = categories; 53 this.baseCategory = baseCategory; 54 } 55 public void advanceToNextPage() { 56 getContainer().showPage(getNextPage()); 57 } 58 public void createControl(Composite parent) { 59 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 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 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 () { 98 public void run() { 99 selectionChanged( 100 new SelectionChangedEvent( 101 wizardSelectionViewer, 102 wizardSelectionViewer.getSelection())); 103 advanceToNextPage(); 104 } 105 }); 106 } 107 }); 108 109 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 getSingleSelection(IStructuredSelection selection) { 124 Object selectedObject = selection.getFirstElement(); 125 if (selection.size() > 1) 126 selectedObject = null; return selectedObject; 128 } 129 private void handleCategorySelection(SelectionChangedEvent selectionEvent) { 130 setErrorMessage(null); 131 setDescriptionText(""); 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 (currentSelection == null) { 154 setDescriptionText(""); setSelectedNode(null); 156 return; 157 } 158 final WizardElement finalSelection = currentSelection; 159 163 setSelectedNode(createWizardNode(finalSelection)); 164 setDescriptionText(finalSelection.getDescription()); 165 169 } 170 protected void initializeViewers() { 171 categoryTreeViewer.setInput(wizardCategories); 172 wizardSelectionViewer.addSelectionChangedListener(this); 173 Object [] 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 |