1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.jface.dialogs.IDialogSettings; 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.TableViewer; 21 import org.eclipse.jface.wizard.IWizardNode; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.graphics.Font; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.swt.widgets.Table; 30 import org.eclipse.ui.IWorkbench; 31 import org.eclipse.ui.internal.WorkbenchMessages; 32 import org.eclipse.ui.model.AdaptableList; 33 import org.eclipse.ui.model.WorkbenchLabelProvider; 34 import org.eclipse.ui.model.WorkbenchViewerComparator; 35 36 42 public abstract class WorkbenchWizardListSelectionPage extends 43 WorkbenchWizardSelectionPage implements ISelectionChangedListener, 44 IDoubleClickListener { 45 46 private static final String DIALOG_SETTING_SECTION_NAME = "WizardListSelectionPage."; 49 private final static int SIZING_LISTS_HEIGHT = 200; 50 51 private static final String STORE_SELECTED_WIZARD_ID = DIALOG_SETTING_SECTION_NAME 52 + "STORE_SELECTED_WIZARD_ID"; 54 private TableViewer viewer; 55 56 private String message; 57 58 68 protected WorkbenchWizardListSelectionPage(IWorkbench aWorkbench, 69 IStructuredSelection currentSelection, 70 AdaptableList wizardElements, String message, String triggerPointId) { 71 super( 72 "singleWizardSelectionPage", aWorkbench, currentSelection, wizardElements, triggerPointId); setDescription(WorkbenchMessages.WizardList_description); 74 this.message = message; 75 } 76 77 82 public void createControl(Composite parent) { 83 84 Font font = parent.getFont(); 85 86 Composite outerContainer = new Composite(parent, SWT.NONE); 88 outerContainer.setLayout(new GridLayout()); 89 outerContainer.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL 90 | GridData.HORIZONTAL_ALIGN_FILL)); 91 outerContainer.setFont(font); 92 93 Label messageLabel = new Label(outerContainer, SWT.NONE); 94 messageLabel.setText(message); 95 messageLabel.setFont(font); 96 97 createViewer(outerContainer); 98 layoutTopControl(viewer.getControl()); 99 100 restoreWidgetValues(); 101 102 setControl(outerContainer); 103 } 104 105 110 private void createViewer(Composite parent) { 111 Table table = new Table(parent, SWT.BORDER); 113 table.setFont(parent.getFont()); 114 115 viewer = new TableViewer(table); 117 viewer.setContentProvider(new WizardContentProvider()); 118 viewer.setLabelProvider(new WorkbenchLabelProvider()); 119 viewer.setComparator(new WorkbenchViewerComparator()); 120 viewer.addSelectionChangedListener(this); 121 viewer.addDoubleClickListener(this); 122 viewer.setInput(wizardElements); 123 } 124 125 134 protected abstract IWizardNode createWizardNode( 135 WorkbenchWizardElement element); 136 137 140 public void doubleClick(DoubleClickEvent event) { 141 selectionChanged(new SelectionChangedEvent(event.getViewer(), event 142 .getViewer().getSelection())); 143 getContainer().showPage(getNextPage()); 144 } 145 146 152 private void layoutTopControl(Control control) { 153 GridData data = new GridData(GridData.FILL_BOTH); 154 155 int availableRows = DialogUtil.availableRows(control.getParent()); 156 157 if (availableRows > 50) { 159 data.heightHint = SIZING_LISTS_HEIGHT; 160 } else { 161 data.heightHint = availableRows * 3; 162 } 163 164 control.setLayoutData(data); 165 166 } 167 168 172 private void restoreWidgetValues() { 173 174 IDialogSettings settings = getDialogSettings(); 175 if (settings == null) { 176 return; 177 } 178 179 String wizardId = settings.get(STORE_SELECTED_WIZARD_ID); 180 WorkbenchWizardElement wizard = findWizard(wizardId); 181 if (wizard == null) { 182 return; 183 } 184 185 StructuredSelection selection = new StructuredSelection(wizard); 186 viewer.setSelection(selection); 187 } 188 189 193 public void saveWidgetValues() { 194 IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); 195 if (sel.size() > 0) { 196 WorkbenchWizardElement selectedWizard = (WorkbenchWizardElement) sel 197 .getFirstElement(); 198 getDialogSettings().put(STORE_SELECTED_WIZARD_ID, 199 selectedWizard.getId()); 200 } 201 } 202 203 209 public void selectionChanged(SelectionChangedEvent event) { 210 setErrorMessage(null); 211 IStructuredSelection selection = (IStructuredSelection) event 212 .getSelection(); 213 WorkbenchWizardElement currentWizardSelection = (WorkbenchWizardElement) selection 214 .getFirstElement(); 215 if (currentWizardSelection == null) { 216 setMessage(null); 217 setSelectedNode(null); 218 return; 219 } 220 221 setSelectedNode(createWizardNode(currentWizardSelection)); 222 setMessage(currentWizardSelection.getDescription()); 223 } 224 } 225 | Popular Tags |