1 11 package org.eclipse.jface.wizard; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.jface.dialogs.IDialogSettings; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.resource.JFaceResources; 20 import org.eclipse.swt.graphics.Image; 21 import org.eclipse.swt.graphics.RGB; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Shell; 24 25 57 public abstract class Wizard implements IWizard { 58 62 public static final String DEFAULT_IMAGE = "org.eclipse.jface.wizard.Wizard.pageImage"; 64 67 private IWizardContainer container = null; 68 69 72 private List pages = new ArrayList (); 73 74 77 private boolean needsProgressMonitor = false; 78 79 83 private boolean forcePreviousAndNextButtons = false; 84 85 88 private boolean isHelpAvailable = false; 89 90 94 private Image defaultImage = null; 95 96 100 private ImageDescriptor defaultImageDescriptor = JFaceResources.getImageRegistry().getDescriptor(DEFAULT_IMAGE); 101 102 105 private RGB titleBarColor = null; 106 107 110 private String windowTitle = null; 111 112 115 private IDialogSettings dialogSettings = null; 116 117 120 protected Wizard() { 121 super(); 122 } 123 124 131 public void addPage(IWizardPage page) { 132 pages.add(page); 133 page.setWizard(this); 134 } 135 136 142 public void addPages() { 143 } 144 145 148 public boolean canFinish() { 149 for (int i = 0; i < pages.size(); i++) { 151 if (!((IWizardPage) pages.get(i)).isPageComplete()) { 152 return false; 153 } 154 } 155 return true; 156 } 157 158 166 public void createPageControls(Composite pageContainer) { 167 for (int i = 0; i < pages.size(); i++) { 169 IWizardPage page = (IWizardPage) pages.get(i); 170 page.createControl(pageContainer); 171 Assert.isNotNull(page.getControl()); 175 } 176 } 177 178 185 public void dispose() { 186 for (int i = 0; i < pages.size(); i++) { 188 ((IWizardPage) pages.get(i)).dispose(); 189 } 190 if (defaultImage != null) { 192 JFaceResources.getResources().destroyImage(defaultImageDescriptor); 193 defaultImage = null; 194 } 195 } 196 197 200 public IWizardContainer getContainer() { 201 return container; 202 } 203 204 207 public Image getDefaultPageImage() { 208 if (defaultImage == null) { 209 defaultImage = JFaceResources.getResources().createImageWithDefault(defaultImageDescriptor); 210 } 211 return defaultImage; 212 } 213 214 217 public IDialogSettings getDialogSettings() { 218 return dialogSettings; 219 } 220 221 225 public IWizardPage getNextPage(IWizardPage page) { 226 int index = pages.indexOf(page); 227 if (index == pages.size() - 1 || index == -1) { 228 return null; 230 } 231 return (IWizardPage) pages.get(index + 1); 232 } 233 234 237 public IWizardPage getPage(String name) { 238 for (int i = 0; i < pages.size(); i++) { 239 IWizardPage page = (IWizardPage) pages.get(i); 240 String pageName = page.getName(); 241 if (pageName.equals(name)) { 242 return page; 243 } 244 } 245 return null; 246 } 247 248 251 public int getPageCount() { 252 return pages.size(); 253 } 254 255 258 public IWizardPage[] getPages() { 259 return (IWizardPage[]) pages.toArray(new IWizardPage[pages.size()]); 260 } 261 262 266 public IWizardPage getPreviousPage(IWizardPage page) { 267 int index = pages.indexOf(page); 268 if (index == 0 || index == -1) { 269 return null; 271 } 272 return (IWizardPage) pages.get(index - 1); 273 } 274 275 281 public Shell getShell() { 282 if (container == null) { 283 return null; 284 } 285 return container.getShell(); 286 } 287 288 292 public IWizardPage getStartingPage() { 293 if (pages.size() == 0) { 294 return null; 295 } 296 return (IWizardPage) pages.get(0); 297 } 298 299 302 public RGB getTitleBarColor() { 303 return titleBarColor; 304 } 305 306 309 public String getWindowTitle() { 310 return windowTitle; 311 } 312 313 316 public boolean isHelpAvailable() { 317 return isHelpAvailable; 318 } 319 320 323 public boolean needsPreviousAndNextButtons() { 324 return forcePreviousAndNextButtons || pages.size() > 1; 325 } 326 327 330 public boolean needsProgressMonitor() { 331 return needsProgressMonitor; 332 } 333 334 340 public boolean performCancel() { 341 return true; 342 } 343 344 348 public abstract boolean performFinish(); 349 350 353 public void setContainer(IWizardContainer wizardContainer) { 354 container = wizardContainer; 355 } 356 357 367 public void setDefaultPageImageDescriptor(ImageDescriptor imageDescriptor) { 368 defaultImageDescriptor = imageDescriptor; 369 } 370 371 383 public void setDialogSettings(IDialogSettings settings) { 384 dialogSettings = settings; 385 } 386 387 400 public void setForcePreviousAndNextButtons(boolean b) { 401 forcePreviousAndNextButtons = b; 402 } 403 404 416 public void setHelpAvailable(boolean b) { 417 isHelpAvailable = b; 418 } 419 420 428 public void setNeedsProgressMonitor(boolean b) { 429 needsProgressMonitor = b; 430 } 431 432 438 public void setTitleBarColor(RGB color) { 439 titleBarColor = color; 440 } 441 442 449 public void setWindowTitle(String newTitle) { 450 windowTitle = newTitle; 451 if (container != null) { 452 container.updateWindowTitle(); 453 } 454 } 455 } 456 | Popular Tags |