1 11 package org.eclipse.pde.internal.ui.wizards; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExecutableExtension; 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.jface.dialogs.Dialog; 20 import org.eclipse.jface.viewers.DoubleClickEvent; 21 import org.eclipse.jface.viewers.IDoubleClickListener; 22 import org.eclipse.jface.viewers.ISelectionChangedListener; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 import org.eclipse.jface.viewers.SelectionChangedEvent; 25 import org.eclipse.jface.viewers.StructuredSelection; 26 import org.eclipse.jface.viewers.TableViewer; 27 import org.eclipse.jface.wizard.IWizard; 28 import org.eclipse.jface.wizard.IWizardNode; 29 import org.eclipse.jface.wizard.IWizardPage; 30 import org.eclipse.pde.internal.ui.elements.ElementList; 31 import org.eclipse.pde.internal.ui.elements.ListContentProvider; 32 import org.eclipse.pde.ui.IPluginContentWizard; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.custom.SashForm; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.layout.GridLayout; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Label; 39 import org.eclipse.swt.widgets.Table; 40 import org.eclipse.swt.widgets.TableItem; 41 42 43 public abstract class WizardListSelectionPage extends BaseWizardSelectionPage 44 implements ISelectionChangedListener, IExecutableExtension { 45 protected TableViewer wizardSelectionViewer; 46 protected ElementList wizardElements; 47 private WizardSelectedAction doubleClickAction = new WizardSelectedAction(); 48 49 private class WizardSelectedAction extends Action { 50 public WizardSelectedAction() { 51 super("wizardSelection"); } 53 public void run() { 54 selectionChanged(new SelectionChangedEvent(wizardSelectionViewer, 55 wizardSelectionViewer.getSelection())); 56 advanceToNextPage(); 57 } 58 } 59 public WizardListSelectionPage(ElementList wizardElements, String message) { 60 super("ListSelection", message); this.wizardElements = wizardElements; 62 } 63 public void advanceToNextPage() { 64 getContainer().showPage(getNextPage()); 65 } 66 public ElementList getWizardElements() { 67 return wizardElements; 68 } 69 70 public void createControl(Composite parent) { 71 Composite container = new Composite(parent, SWT.NONE); 72 GridLayout layout = new GridLayout(); 73 layout.verticalSpacing = 10; 74 container.setLayout(layout); 75 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 76 77 createAbove(container, 1); 78 Label label = new Label(container, SWT.NONE); 79 label.setText(getLabel()); 80 GridData gd = new GridData(); 81 label.setLayoutData(gd); 82 83 SashForm sashForm = new SashForm(container, SWT.HORIZONTAL); 84 gd = new GridData(GridData.FILL_BOTH); 85 gd.widthHint = 300; 90 sashForm.setLayoutData(gd); 91 92 wizardSelectionViewer = new TableViewer(sashForm, SWT.BORDER); 93 wizardSelectionViewer.setContentProvider(new ListContentProvider()); 94 wizardSelectionViewer.setLabelProvider(ListUtil.TABLE_LABEL_PROVIDER); 95 wizardSelectionViewer.setComparator(ListUtil.NAME_COMPARATOR); 96 wizardSelectionViewer.addDoubleClickListener(new IDoubleClickListener() { 97 public void doubleClick(DoubleClickEvent event) { 98 doubleClickAction.run(); 99 } 100 }); 101 createDescriptionIn(sashForm); 102 createBelow(container, 1); 103 initializeViewer(); 104 wizardSelectionViewer.setInput(wizardElements); 105 wizardSelectionViewer.addSelectionChangedListener(this); 106 Dialog.applyDialogFont(container); 107 setControl(container); 108 } 109 110 protected void createAbove(Composite container, int span) { 111 } 112 protected void createBelow(Composite container, int span) { 113 } 114 115 protected void initializeViewer() { 116 } 117 118 public void selectionChanged(SelectionChangedEvent event) { 119 setErrorMessage(null); 120 IStructuredSelection selection = (IStructuredSelection) event.getSelection(); 121 WizardElement currentWizardSelection = null; 122 Iterator iter = selection.iterator(); 123 if (iter.hasNext()) 124 currentWizardSelection = (WizardElement) iter.next(); 125 if (currentWizardSelection == null) { 126 setDescriptionText(""); setSelectedNode(null); 128 return; 129 } 130 final WizardElement finalSelection = currentWizardSelection; 131 setSelectedNode(createWizardNode(finalSelection)); 132 setDescriptionText(finalSelection.getDescription()); 133 getContainer().updateButtons(); 134 } 135 136 public IWizardPage getNextPage(boolean shouldCreate) { 137 if (!shouldCreate) 138 return super.getNextPage(); 139 IWizardNode selectedNode = getSelectedNode(); 140 selectedNode.dispose(); 141 IWizard wizard = selectedNode.getWizard(); 142 if (wizard == null) { 143 super.setSelectedNode(null); 144 return null; 145 } 146 if (shouldCreate) 147 wizard.addPages(); 149 return wizard.getStartingPage(); 150 } 151 152 protected void focusAndSelectFirst() { 153 Table table = wizardSelectionViewer.getTable(); 154 table.setFocus(); 155 TableItem[] items = table.getItems(); 156 if (items.length > 0) { 157 TableItem first = items[0]; 158 Object obj = first.getData(); 159 wizardSelectionViewer.setSelection(new StructuredSelection(obj)); 160 } 161 } 162 163 166 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { 167 } 168 169 public IPluginContentWizard getSelectedWizard() { 170 IWizardNode node = getSelectedNode(); 171 if (node != null) 172 return (IPluginContentWizard)node.getWizard(); 173 return null; 174 } 175 176 179 public boolean canFlipToNextPage() { 180 IStructuredSelection ssel = (IStructuredSelection)wizardSelectionViewer.getSelection(); 181 return ssel != null && !ssel.isEmpty(); 182 } 183 } 184 | Popular Tags |