1 13 package org.eclipse.ui.internal.ide.misc; 14 15 import org.eclipse.jface.resource.ImageDescriptor; 16 import org.eclipse.jface.viewers.IContentProvider; 17 import org.eclipse.jface.viewers.ISelectionChangedListener; 18 import org.eclipse.jface.viewers.LabelProvider; 19 import org.eclipse.jface.viewers.TableViewer; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.DisposeEvent; 22 import org.eclipse.swt.events.DisposeListener; 23 import org.eclipse.swt.graphics.Font; 24 import org.eclipse.swt.graphics.Image; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.layout.GridLayout; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.Control; 29 import org.eclipse.swt.widgets.Label; 30 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 31 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 32 import org.eclipse.ui.internal.ide.dialogs.WizardStep; 33 import org.eclipse.ui.model.WorkbenchContentProvider; 34 35 39 public class WizardStepGroup { 40 41 private Image doneImage; 42 43 private Image currentImage; 44 45 private WizardStep currentStep; 46 47 private Composite parentComposite; 48 49 private TableViewer stepViewer; 50 51 private ISelectionChangedListener selectionListener; 52 53 56 public WizardStepGroup() { 57 super(); 58 } 59 60 64 public Control createContents(Composite parent) { 65 Font font = parent.getFont(); 66 parentComposite = parent; 67 68 Composite composite = new Composite(parent, SWT.NULL); 70 composite.setLayout(new GridLayout()); 71 composite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); 72 composite.setFont(font); 73 composite.addDisposeListener(new DisposeListener() { 74 public void widgetDisposed(DisposeEvent e) { 75 if (doneImage != null) { 76 doneImage.dispose(); 77 doneImage = null; 78 } 79 if (currentImage != null) { 80 currentImage.dispose(); 81 currentImage = null; 82 } 83 } 84 }); 85 86 Label label = new Label(composite, SWT.LEFT); 88 label.setText(IDEWorkbenchMessages.WizardStepGroup_stepsLabel); 89 GridData data = new GridData(); 90 data.verticalAlignment = SWT.TOP; 91 label.setLayoutData(data); 92 label.setFont(font); 93 94 stepViewer = new TableViewer(composite, SWT.SINGLE | SWT.V_SCROLL 96 | SWT.BORDER | SWT.FULL_SELECTION); 97 data = new GridData(GridData.FILL_BOTH); 98 stepViewer.getTable().setLayoutData(data); 99 stepViewer.getTable().setFont(font); 100 stepViewer.setContentProvider(getStepProvider()); 101 stepViewer.setLabelProvider(new StepLabelProvider()); 102 103 if (selectionListener != null) { 104 stepViewer.addSelectionChangedListener(selectionListener); 105 } 106 107 return composite; 108 } 109 110 113 private Image createImage(String iconFileName) { 114 ImageDescriptor desc = 115 IDEWorkbenchPlugin.getIDEImageDescriptor(iconFileName); 116 117 return desc.createImage(); 118 } 119 120 123 private Image getCurrentImage() { 124 if (currentImage == null) { 125 currentImage = createImage("elcl16/step_current.gif"); } 127 return currentImage; 128 } 129 130 133 private Image getDoneImage() { 134 if (doneImage == null) { 135 doneImage = createImage("elcl16/step_done.gif"); } 137 return doneImage; 138 } 139 140 143 private IContentProvider getStepProvider() { 144 return new WorkbenchContentProvider() { 145 public Object [] getChildren(Object parentElement) { 146 if (parentElement instanceof StepRoot) { 147 return ((StepRoot) parentElement).getSteps(); 148 } else { 149 return null; 150 } 151 } 152 153 }; 154 } 155 156 159 public WizardStep[] getSteps() { 160 if (stepViewer != null) { 161 StepRoot root = (StepRoot) stepViewer.getInput(); 162 if (root != null) { 163 return root.getSteps(); 164 } 165 } 166 167 return new WizardStep[0]; 168 } 169 170 173 public void markStepAsDone() { 174 if (currentStep != null) { 175 currentStep.markAsDone(); 176 } 177 } 178 179 186 public void setCurrentStep(WizardStep step) { 187 WizardStep oldStep = currentStep; 188 currentStep = step; 189 if (stepViewer != null) { 190 if (oldStep != null) { 191 stepViewer.update(oldStep, null); 192 } 193 if (currentStep != null) { 194 stepViewer.update(currentStep, null); 195 } 196 197 if (oldStep == null && currentStep != null) { 200 parentComposite.layout(true); 201 } 202 } 203 } 204 205 211 public void setSelectionListener(ISelectionChangedListener listener) { 212 if (selectionListener != null && stepViewer != null) { 213 stepViewer.removeSelectionChangedListener(selectionListener); 214 } 215 selectionListener = listener; 216 if (selectionListener != null && stepViewer != null) { 217 stepViewer.addSelectionChangedListener(selectionListener); 218 } 219 } 220 221 227 public void setSteps(WizardStep[] steps) { 228 if (stepViewer != null) { 229 stepViewer.setInput(new StepRoot(steps)); 230 parentComposite.layout(true); 231 } 232 } 233 234 237 private class StepRoot { 238 private WizardStep[] steps; 239 240 public StepRoot(WizardStep[] steps) { 241 super(); 242 this.steps = steps; 243 } 244 245 public WizardStep[] getSteps() { 246 if (steps == null) { 247 return new WizardStep[0]; 248 } else { 249 return steps; 250 } 251 } 252 } 253 254 257 private class StepLabelProvider extends LabelProvider { 258 public String getText(Object element) { 259 if (element instanceof WizardStep) { 260 WizardStep step = (WizardStep) element; 261 return String.valueOf(step.getNumber()) 262 + ". " + step.getLabel(); } 264 265 return ""; } 267 268 public Image getImage(Object element) { 269 if (element instanceof WizardStep) { 270 WizardStep step = (WizardStep) element; 271 if (step.isDone()) { 272 return getDoneImage(); 273 } 274 if (step == currentStep) { 275 return getCurrentImage(); 276 } 277 } 278 279 return null; 280 } 281 } 282 } 283 | Popular Tags |