1 12 package org.eclipse.jface.wizard; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.Map ; 18 19 import org.eclipse.core.runtime.Assert; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.ListenerList; 23 import org.eclipse.jface.dialogs.ControlEnableState; 24 import org.eclipse.jface.dialogs.IDialogConstants; 25 import org.eclipse.jface.dialogs.IMessageProvider; 26 import org.eclipse.jface.dialogs.IPageChangeProvider; 27 import org.eclipse.jface.dialogs.IPageChangedListener; 28 import org.eclipse.jface.dialogs.IPageChangingListener; 29 import org.eclipse.jface.dialogs.MessageDialog; 30 import org.eclipse.jface.dialogs.PageChangedEvent; 31 import org.eclipse.jface.dialogs.PageChangingEvent; 32 import org.eclipse.jface.dialogs.TitleAreaDialog; 33 import org.eclipse.jface.operation.IRunnableWithProgress; 34 import org.eclipse.jface.operation.ModalContext; 35 import org.eclipse.jface.resource.JFaceResources; 36 import org.eclipse.jface.util.SafeRunnable; 37 import org.eclipse.swt.SWT; 38 import org.eclipse.swt.custom.BusyIndicator; 39 import org.eclipse.swt.events.HelpEvent; 40 import org.eclipse.swt.events.HelpListener; 41 import org.eclipse.swt.events.SelectionAdapter; 42 import org.eclipse.swt.events.SelectionEvent; 43 import org.eclipse.swt.graphics.Cursor; 44 import org.eclipse.swt.graphics.Point; 45 import org.eclipse.swt.graphics.Rectangle; 46 import org.eclipse.swt.layout.GridData; 47 import org.eclipse.swt.layout.GridLayout; 48 import org.eclipse.swt.widgets.Button; 49 import org.eclipse.swt.widgets.Composite; 50 import org.eclipse.swt.widgets.Control; 51 import org.eclipse.swt.widgets.Display; 52 import org.eclipse.swt.widgets.Label; 53 import org.eclipse.swt.widgets.Layout; 54 import org.eclipse.swt.widgets.Shell; 55 56 75 public class WizardDialog extends TitleAreaDialog implements IWizardContainer2, 76 IPageChangeProvider { 77 81 public static final String WIZ_IMG_ERROR = "dialog_title_error_image"; 83 private IWizard wizard; 85 86 private ArrayList createdWizards = new ArrayList (); 88 89 private ArrayList nestedWizards = new ArrayList (); 91 92 private IWizardPage currentPage = null; 94 95 private long activeRunningOperations = 0; 97 98 private String pageMessage; 100 101 private int pageMessageType = IMessageProvider.NONE; 102 103 private String pageDescription; 104 105 private ProgressMonitorPart progressMonitorPart; 107 108 private Cursor waitCursor; 109 110 private Cursor arrowCursor; 111 112 private MessageDialog windowClosingDialog; 113 114 private Button backButton; 116 117 private Button nextButton; 118 119 private Button finishButton; 120 121 private Button cancelButton; 122 123 private Button helpButton; 124 125 private SelectionAdapter cancelListener; 126 127 private boolean isMovingToPreviousPage = false; 128 129 private Composite pageContainer; 130 131 private PageContainerFillLayout pageContainerLayout = new PageContainerFillLayout( 132 5, 5, 300, 225); 133 134 private int pageWidth = SWT.DEFAULT; 135 136 private int pageHeight = SWT.DEFAULT; 137 138 private static final String FOCUS_CONTROL = "focusControl"; 140 private boolean lockedUI = false; 141 142 private ListenerList pageChangedListeners = new ListenerList(); 143 144 private ListenerList pageChangingListeners = new ListenerList(); 145 146 152 protected class PageContainerFillLayout extends Layout { 153 156 public int marginWidth = 5; 157 158 161 public int marginHeight = 5; 162 163 166 public int minimumWidth = 0; 167 168 171 public int minimumHeight = 0; 172 173 185 public PageContainerFillLayout(int mw, int mh, int minW, int minH) { 186 marginWidth = mw; 187 marginHeight = mh; 188 minimumWidth = minW; 189 minimumHeight = minH; 190 } 191 192 195 public Point computeSize(Composite composite, int wHint, int hHint, 196 boolean force) { 197 if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) { 198 return new Point(wHint, hHint); 199 } 200 Point result = null; 201 Control[] children = composite.getChildren(); 202 if (children.length > 0) { 203 result = new Point(0, 0); 204 for (int i = 0; i < children.length; i++) { 205 Point cp = children[i].computeSize(wHint, hHint, force); 206 result.x = Math.max(result.x, cp.x); 207 result.y = Math.max(result.y, cp.y); 208 } 209 result.x = result.x + 2 * marginWidth; 210 result.y = result.y + 2 * marginHeight; 211 } else { 212 Rectangle rect = composite.getClientArea(); 213 result = new Point(rect.width, rect.height); 214 } 215 result.x = Math.max(result.x, minimumWidth); 216 result.y = Math.max(result.y, minimumHeight); 217 if (wHint != SWT.DEFAULT) { 218 result.x = wHint; 219 } 220 if (hHint != SWT.DEFAULT) { 221 result.y = hHint; 222 } 223 return result; 224 } 225 226 234 public Rectangle getClientArea(Composite c) { 235 Rectangle rect = c.getClientArea(); 236 rect.x = rect.x + marginWidth; 237 rect.y = rect.y + marginHeight; 238 rect.width = rect.width - 2 * marginWidth; 239 rect.height = rect.height - 2 * marginHeight; 240 return rect; 241 } 242 243 246 public void layout(Composite composite, boolean force) { 247 Rectangle rect = getClientArea(composite); 248 Control[] children = composite.getChildren(); 249 for (int i = 0; i < children.length; i++) { 250 children[i].setBounds(rect); 251 } 252 } 253 254 260 public void layoutPage(Control w) { 261 w.setBounds(getClientArea(w.getParent())); 262 } 263 264 271 public void setPageLocation(Control w) { 272 w.setLocation(marginWidth, marginHeight); 273 } 274 } 275 276 284 public WizardDialog(Shell parentShell, IWizard newWizard) { 285 super(parentShell); 286 setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER 287 | SWT.APPLICATION_MODAL | SWT.RESIZE | getDefaultOrientation()); 288 setWizard(newWizard); 289 cancelListener = new SelectionAdapter() { 292 public void widgetSelected(SelectionEvent e) { 293 cancelPressed(); 294 } 295 }; 296 } 297 298 308 private Object aboutToStart(boolean enableCancelButton) { 309 Map savedState = null; 310 if (getShell() != null) { 311 Control focusControl = getShell().getDisplay().getFocusControl(); 313 if (focusControl != null && focusControl.getShell() != getShell()) { 314 focusControl = null; 315 } 316 boolean needsProgressMonitor = wizard.needsProgressMonitor(); 317 cancelButton.removeSelectionListener(cancelListener); 318 Display d = getShell().getDisplay(); 320 waitCursor = new Cursor(d, SWT.CURSOR_WAIT); 321 setDisplayCursor(waitCursor); 322 arrowCursor = new Cursor(d, SWT.CURSOR_ARROW); 324 cancelButton.setCursor(arrowCursor); 325 savedState = saveUIState(needsProgressMonitor && enableCancelButton); 327 if (focusControl != null) { 328 savedState.put(FOCUS_CONTROL, focusControl); 329 } 330 if (needsProgressMonitor) { 332 progressMonitorPart.attachToCancelComponent(cancelButton); 333 progressMonitorPart.setVisible(true); 334 } 335 } 336 return savedState; 337 } 338 339 342 protected void backPressed() { 343 IWizardPage page = currentPage.getPreviousPage(); 344 if (page == null) { 345 return; 347 } 348 349 isMovingToPreviousPage = true; 351 showPage(page); 353 } 354 355 358 protected void buttonPressed(int buttonId) { 359 switch (buttonId) { 360 case IDialogConstants.HELP_ID: { 361 helpPressed(); 362 break; 363 } 364 case IDialogConstants.BACK_ID: { 365 backPressed(); 366 break; 367 } 368 case IDialogConstants.NEXT_ID: { 369 nextPressed(); 370 break; 371 } 372 case IDialogConstants.FINISH_ID: { 373 finishPressed(); 374 break; 375 } 376 } 379 } 380 381 390 private Point calculatePageSizeDelta(IWizardPage page) { 391 Control pageControl = page.getControl(); 392 if (pageControl == null) { 393 return new Point(0, 0); 395 } 396 Point contentSize = pageControl.computeSize(SWT.DEFAULT, SWT.DEFAULT, 397 true); 398 Rectangle rect = pageContainerLayout.getClientArea(pageContainer); 399 Point containerSize = new Point(rect.width, rect.height); 400 return new Point(Math.max(0, contentSize.x - containerSize.x), Math 401 .max(0, contentSize.y - containerSize.y)); 402 } 403 404 407 protected void cancelPressed() { 408 if (activeRunningOperations <= 0) { 409 setReturnCode(CANCEL); 414 close(); 415 } else { 416 cancelButton.setEnabled(false); 417 } 418 } 419 420 425 public boolean close() { 426 if (okToClose()) { 427 return hardClose(); 428 } 429 return false; 430 } 431 432 435 protected void configureShell(Shell newShell) { 436 super.configureShell(newShell); 437 newShell.addHelpListener(new HelpListener() { 439 public void helpRequested(HelpEvent event) { 440 if (currentPage != null) { 442 currentPage.performHelp(); 443 } 444 } 445 }); 446 } 447 448 459 protected void createButtonsForButtonBar(Composite parent) { 460 ((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; 461 if (wizard.isHelpAvailable()) { 462 helpButton = createButton(parent, IDialogConstants.HELP_ID, 463 IDialogConstants.HELP_LABEL, false); 464 } 465 if (wizard.needsPreviousAndNextButtons()) { 466 createPreviousAndNextButtons(parent); 467 } 468 finishButton = createButton(parent, IDialogConstants.FINISH_ID, 469 IDialogConstants.FINISH_LABEL, true); 470 cancelButton = createCancelButton(parent); 471 } 472 473 478 protected void setButtonLayoutData(Button button) { 479 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 480 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 481 482 widthHint = Math.min(widthHint, 484 button.getDisplay().getBounds().width / 5); 485 Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); 486 data.widthHint = Math.max(widthHint, minSize.x); 487 488 button.setLayoutData(data); 489 } 490 491 501 private Button createCancelButton(Composite parent) { 502 ((GridLayout) parent.getLayout()).numColumns++; 504 Button button = new Button(parent, SWT.PUSH); 505 button.setText(IDialogConstants.CANCEL_LABEL); 506 setButtonLayoutData(button); 507 button.setFont(parent.getFont()); 508 button.setData(new Integer (IDialogConstants.CANCEL_ID)); 509 button.addSelectionListener(cancelListener); 510 return button; 511 } 512 513 520 protected Button getButton(int id) { 521 if (id == IDialogConstants.CANCEL_ID) { 522 return cancelButton; 523 } 524 return super.getButton(id); 525 } 526 527 536 protected Control createContents(Composite parent) { 537 wizard.addPages(); 541 Control contents = super.createContents(parent); 542 createPageControls(); 544 showStartingPage(); 546 return contents; 547 } 548 549 552 protected Control createDialogArea(Composite parent) { 553 Composite composite = (Composite) super.createDialogArea(parent); 554 pageContainer = createPageContainer(composite); 556 GridData gd = new GridData(GridData.FILL_BOTH); 557 gd.widthHint = pageWidth; 558 gd.heightHint = pageHeight; 559 pageContainer.setLayoutData(gd); 560 pageContainer.setFont(parent.getFont()); 561 GridLayout pmlayout = new GridLayout(); 563 pmlayout.numColumns = 1; 564 progressMonitorPart = createProgressMonitorPart(composite, pmlayout); 565 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); 566 progressMonitorPart.setLayoutData(gridData); 567 progressMonitorPart.setVisible(false); 568 Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR); 570 separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 571 572 applyDialogFont(progressMonitorPart); 573 return composite; 574 } 575 576 583 protected ProgressMonitorPart createProgressMonitorPart( 584 Composite composite, GridLayout pmlayout) { 585 return new ProgressMonitorPart(composite, pmlayout, SWT.DEFAULT) { 586 String currentTask = null; 587 588 593 public void setBlocked(IStatus reason) { 594 super.setBlocked(reason); 595 if (!lockedUI) { 596 getBlockedHandler().showBlocked(getShell(), this, reason, 597 currentTask); 598 } 599 } 600 601 606 public void clearBlocked() { 607 super.clearBlocked(); 608 if (!lockedUI) { 609 getBlockedHandler().clearBlocked(); 610 } 611 } 612 613 619 public void beginTask(String name, int totalWork) { 620 super.beginTask(name, totalWork); 621 currentTask = name; 622 } 623 624 629 public void setTaskName(String name) { 630 super.setTaskName(name); 631 currentTask = name; 632 } 633 634 639 public void subTask(String name) { 640 super.subTask(name); 641 if (currentTask == null) { 644 currentTask = name; 645 } 646 } 647 }; 648 } 649 650 656 private Composite createPageContainer(Composite parent) { 657 Composite result = new Composite(parent, SWT.NULL); 658 result.setLayout(pageContainerLayout); 659 return result; 660 } 661 662 666 private void createPageControls() { 667 wizard.createPageControls(pageContainer); 670 IWizardPage[] pages = wizard.getPages(); 672 for (int i = 0; i < pages.length; i++) { 673 IWizardPage page = pages[i]; 674 if (page.getControl() != null) { 675 page.getControl().setVisible(false); 676 } 677 } 678 } 679 680 691 private Composite createPreviousAndNextButtons(Composite parent) { 692 ((GridLayout) parent.getLayout()).numColumns++; 694 Composite composite = new Composite(parent, SWT.NONE); 695 GridLayout layout = new GridLayout(); 698 layout.numColumns = 0; layout.marginWidth = 0; 700 layout.marginHeight = 0; 701 layout.horizontalSpacing = 0; 702 layout.verticalSpacing = 0; 703 composite.setLayout(layout); 704 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER 705 | GridData.VERTICAL_ALIGN_CENTER); 706 composite.setLayoutData(data); 707 composite.setFont(parent.getFont()); 708 backButton = createButton(composite, IDialogConstants.BACK_ID, 709 IDialogConstants.BACK_LABEL, false); 710 nextButton = createButton(composite, IDialogConstants.NEXT_ID, 711 IDialogConstants.NEXT_LABEL, false); 712 return composite; 713 } 714 715 720 private MessageDialog createWizardClosingDialog() { 721 MessageDialog result = new MessageDialog(getShell(), 722 JFaceResources.getString("WizardClosingDialog.title"), null, 724 JFaceResources.getString("WizardClosingDialog.message"), MessageDialog.QUESTION, 726 new String [] { IDialogConstants.OK_LABEL }, 0); 727 return result; 728 } 729 730 733 protected void finishPressed() { 734 if (wizard.performFinish()) { 743 for (int i = 0; i < nestedWizards.size() - 1; i++) { 746 ((IWizard) nestedWizards.get(i)).performFinish(); 747 } 748 setReturnCode(OK); 750 hardClose(); 751 } 752 } 753 754 757 public IWizardPage getCurrentPage() { 758 return currentPage; 759 } 760 761 767 protected IProgressMonitor getProgressMonitor() { 768 return progressMonitorPart; 769 } 770 771 776 protected IWizard getWizard() { 777 return wizard; 778 } 779 780 786 private boolean hardClose() { 787 for (int i = 0; i < createdWizards.size(); i++) { 789 IWizard createdWizard = (IWizard) createdWizards.get(i); 790 createdWizard.dispose(); 791 createdWizard.setContainer(null); 796 } 797 return super.close(); 798 } 799 800 803 protected void helpPressed() { 804 if (currentPage != null) { 805 currentPage.performHelp(); 806 } 807 } 808 809 812 protected void nextPressed() { 813 IWizardPage page = currentPage.getNextPage(); 814 if (page == null) { 815 return; 817 } 818 819 showPage(page); 821 } 822 823 831 private boolean doPageChanging(IWizardPage targetPage) { 832 PageChangingEvent e = new PageChangingEvent(this, getCurrentPage(), 833 targetPage); 834 firePageChanging(e); 835 return e.doit; 837 } 838 839 848 private boolean okToClose() { 849 if (activeRunningOperations > 0) { 850 synchronized (this) { 851 windowClosingDialog = createWizardClosingDialog(); 852 } 853 windowClosingDialog.open(); 854 synchronized (this) { 855 windowClosingDialog = null; 856 } 857 return false; 858 } 859 return wizard.performCancel(); 860 } 861 862 874 private void restoreEnableState(Control w, Map h, String key) { 875 if (w != null) { 876 Boolean b = (Boolean ) h.get(key); 877 if (b != null) { 878 w.setEnabled(b.booleanValue()); 879 } 880 } 881 } 882 883 892 private void restoreUIState(Map state) { 893 restoreEnableState(backButton, state, "back"); restoreEnableState(nextButton, state, "next"); restoreEnableState(finishButton, state, "finish"); restoreEnableState(cancelButton, state, "cancel"); restoreEnableState(helpButton, state, "help"); Object pageValue = state.get("page"); if (pageValue != null) { 900 ((ControlEnableState) pageValue).restore(); 901 } 902 } 903 904 919 public void run(boolean fork, boolean cancelable, 920 IRunnableWithProgress runnable) throws InvocationTargetException , 921 InterruptedException { 922 Object state = null; 926 if (activeRunningOperations == 0) { 927 state = aboutToStart(fork && cancelable); 928 } 929 activeRunningOperations++; 930 try { 931 if (!fork) { 932 lockedUI = true; 933 } 934 ModalContext.run(runnable, fork, getProgressMonitor(), getShell() 935 .getDisplay()); 936 lockedUI = false; 937 } finally { 938 activeRunningOperations--; 939 if (state != null) { 941 stopped(state); 942 } 943 } 944 } 945 946 962 private void saveEnableStateAndSet(Control w, Map h, String key, 963 boolean enabled) { 964 if (w != null) { 965 h.put(key, w.getEnabled() ? Boolean.TRUE : Boolean.FALSE); 966 w.setEnabled(enabled); 967 } 968 } 969 970 983 private Map saveUIState(boolean keepCancelEnabled) { 984 Map savedState = new HashMap (10); 985 saveEnableStateAndSet(backButton, savedState, "back", false); saveEnableStateAndSet(nextButton, savedState, "next", false); saveEnableStateAndSet(finishButton, savedState, "finish", false); saveEnableStateAndSet(cancelButton, savedState, 989 "cancel", keepCancelEnabled); saveEnableStateAndSet(helpButton, savedState, "help", false); if (currentPage != null) { 992 savedState 993 .put( 994 "page", ControlEnableState.disable(currentPage.getControl())); } 996 return savedState; 997 } 998 999 1006 private void setDisplayCursor(Cursor c) { 1007 Shell[] shells = getShell().getDisplay().getShells(); 1008 for (int i = 0; i < shells.length; i++) { 1009 shells[i].setCursor(c); 1010 } 1011 } 1012 1013 1022 public void setMinimumPageSize(int minWidth, int minHeight) { 1023 Assert.isTrue(minWidth >= 0 && minHeight >= 0); 1024 pageContainerLayout.minimumWidth = minWidth; 1025 pageContainerLayout.minimumHeight = minHeight; 1026 } 1027 1028 1035 public void setMinimumPageSize(Point size) { 1036 setMinimumPageSize(size.x, size.y); 1037 } 1038 1039 1049 public void setPageSize(int width, int height) { 1050 pageWidth = width; 1051 pageHeight = height; 1052 } 1053 1054 1062 public void setPageSize(Point size) { 1063 setPageSize(size.x, size.y); 1064 } 1065 1066 1072 protected void setWizard(IWizard newWizard) { 1073 wizard = newWizard; 1074 wizard.setContainer(this); 1075 if (!createdWizards.contains(wizard)) { 1076 createdWizards.add(wizard); 1077 nestedWizards.add(wizard); 1079 if (pageContainer != null) { 1080 createPageControls(); 1084 updateSizeForWizard(wizard); 1086 pageContainer.layout(true); 1087 } 1088 } else { 1089 int size = nestedWizards.size(); 1093 if (size >= 2 && nestedWizards.get(size - 2) == wizard) { 1094 nestedWizards.remove(size - 1); 1095 } else { 1096 nestedWizards.add(wizard); 1098 } 1099 } 1100 } 1101 1102 1105 public void showPage(IWizardPage page) { 1106 if (page == null || page == currentPage) { 1107 return; 1108 } 1109 1110 if (!isMovingToPreviousPage) { 1111 page.setPreviousPage(currentPage); 1113 } else { 1114 isMovingToPreviousPage = false; 1115 } 1116 1117 if (!doPageChanging(page)) 1119 return; 1120 1121 if (getContents() == null) { 1123 updateForPage(page); 1124 } else { 1125 final IWizardPage finalPage = page; 1126 BusyIndicator.showWhile(getContents().getDisplay(), new Runnable () { 1127 public void run() { 1128 updateForPage(finalPage); 1129 } 1130 }); 1131 } 1132 } 1133 1134 1139 private void updateForPage(IWizardPage page) { 1140 if (wizard != page.getWizard()) { 1142 setWizard(page.getWizard()); 1143 } 1144 if (page.getControl() == null) { 1147 page.createControl(pageContainer); 1148 Assert.isNotNull(page.getControl(), JFaceResources.format( 1152 JFaceResources.getString("WizardDialog.missingSetControl"), new Object [] { page.getName() })); 1154 updateSize(page); 1156 } 1157 IWizardPage oldPage = currentPage; 1159 currentPage = page; 1160 1161 currentPage.setVisible(true); 1162 if (oldPage != null) { 1163 oldPage.setVisible(false); 1164 } 1165 update(); 1167 } 1168 1169 1172 private void showStartingPage() { 1173 currentPage = wizard.getStartingPage(); 1174 if (currentPage == null) { 1175 return; 1177 } 1178 if (currentPage.getControl() == null) { 1180 currentPage.createControl(pageContainer); 1181 Assert.isNotNull(currentPage.getControl()); 1185 } 1188 currentPage.setVisible(true); 1190 update(); 1192 } 1193 1194 1203 private void stopped(Object savedState) { 1204 if (getShell() != null) { 1205 if (wizard.needsProgressMonitor()) { 1206 progressMonitorPart.setVisible(false); 1207 progressMonitorPart.removeFromCancelComponent(cancelButton); 1208 } 1209 Map state = (Map ) savedState; 1210 restoreUIState(state); 1211 cancelButton.addSelectionListener(cancelListener); 1212 setDisplayCursor(null); 1213 cancelButton.setCursor(null); 1214 waitCursor.dispose(); 1215 waitCursor = null; 1216 arrowCursor.dispose(); 1217 arrowCursor = null; 1218 Control focusControl = (Control) state.get(FOCUS_CONTROL); 1219 if (focusControl != null) { 1220 focusControl.setFocus(); 1221 } 1222 } 1223 } 1224 1225 1228 protected void update() { 1229 updateWindowTitle(); 1231 updateTitleBar(); 1233 updateButtons(); 1235 1236 firePageChanged(new PageChangedEvent(this, getCurrentPage())); 1238 } 1239 1240 1243 public void updateButtons() { 1244 boolean canFlipToNextPage = false; 1245 boolean canFinish = wizard.canFinish(); 1246 if (backButton != null) { 1247 backButton.setEnabled(currentPage.getPreviousPage() != null); 1248 } 1249 if (nextButton != null) { 1250 canFlipToNextPage = currentPage.canFlipToNextPage(); 1251 nextButton.setEnabled(canFlipToNextPage); 1252 } 1253 finishButton.setEnabled(canFinish); 1254 if (canFlipToNextPage && !canFinish) { 1256 getShell().setDefaultButton(nextButton); 1257 } else { 1258 getShell().setDefaultButton(finishButton); 1259 } 1260 } 1261 1262 1268 private void updateDescriptionMessage() { 1269 pageDescription = currentPage.getDescription(); 1270 setMessage(pageDescription); 1271 } 1272 1273 1276 public void updateMessage() { 1277 1278 if (currentPage == null) { 1279 return; 1280 } 1281 1282 pageMessage = currentPage.getMessage(); 1283 if (pageMessage != null && currentPage instanceof IMessageProvider) { 1284 pageMessageType = ((IMessageProvider) currentPage).getMessageType(); 1285 } else { 1286 pageMessageType = IMessageProvider.NONE; 1287 } 1288 if (pageMessage == null) { 1289 setMessage(pageDescription); 1290 } else { 1291 setMessage(pageMessage, pageMessageType); 1292 } 1293 setErrorMessage(currentPage.getErrorMessage()); 1294 } 1295 1296 1305 private void setShellSize(int width, int height) { 1306 Rectangle size = getShell().getBounds(); 1307 size.height = height; 1308 size.width = width; 1309 getShell().setBounds(getConstrainedShellBounds(size)); 1310 } 1311 1312 1320 protected void updateSize(IWizardPage page) { 1321 if (page == null || page.getControl() == null) { 1322 return; 1323 } 1324 updateSizeForPage(page); 1325 pageContainerLayout.layoutPage(page.getControl()); 1326 } 1327 1328 1333 public void updateSize() { 1334 updateSize(currentPage); 1335 } 1336 1337 1344 private void updateSizeForPage(IWizardPage page) { 1345 Point delta = calculatePageSizeDelta(page); 1347 if (delta.x > 0 || delta.y > 0) { 1348 Shell shell = getShell(); 1350 Point shellSize = shell.getSize(); 1351 setShellSize(shellSize.x + delta.x, shellSize.y + delta.y); 1352 constrainShellSize(); 1353 } 1354 } 1355 1356 1363 private void updateSizeForWizard(IWizard sizingWizard) { 1364 Point delta = new Point(0, 0); 1365 IWizardPage[] pages = sizingWizard.getPages(); 1366 for (int i = 0; i < pages.length; i++) { 1367 Point pageDelta = calculatePageSizeDelta(pages[i]); 1369 delta.x = Math.max(delta.x, pageDelta.x); 1370 delta.y = Math.max(delta.y, pageDelta.y); 1371 } 1372 if (delta.x > 0 || delta.y > 0) { 1373 Shell shell = getShell(); 1375 Point shellSize = shell.getSize(); 1376 setShellSize(shellSize.x + delta.x, shellSize.y + delta.y); 1377 } 1378 } 1379 1380 1383 public void updateTitleBar() { 1384 String s = null; 1385 if (currentPage != null) { 1386 s = currentPage.getTitle(); 1387 } 1388 if (s == null) { 1389 s = ""; } 1391 setTitle(s); 1392 if (currentPage != null) { 1393 setTitleImage(currentPage.getImage()); 1394 updateDescriptionMessage(); 1395 } 1396 updateMessage(); 1397 } 1398 1399 1402 public void updateWindowTitle() { 1403 if (getShell() == null) { 1404 return; 1406 } 1407 String title = wizard.getWindowTitle(); 1408 if (title == null) { 1409 title = ""; } 1411 getShell().setText(title); 1412 } 1413 1414 1419 public Object getSelectedPage() { 1420 return getCurrentPage(); 1421 } 1422 1423 1428 public void addPageChangedListener(IPageChangedListener listener) { 1429 pageChangedListeners.add(listener); 1430 } 1431 1432 1437 public void removePageChangedListener(IPageChangedListener listener) { 1438 pageChangedListeners.remove(listener); 1439 } 1440 1441 1453 protected void firePageChanged(final PageChangedEvent event) { 1454 Object [] listeners = pageChangedListeners.getListeners(); 1455 for (int i = 0; i < listeners.length; ++i) { 1456 final IPageChangedListener l = (IPageChangedListener) listeners[i]; 1457 SafeRunnable.run(new SafeRunnable() { 1458 public void run() { 1459 l.pageChanged(event); 1460 } 1461 }); 1462 } 1463 } 1464 1465 1474 public void addPageChangingListener(IPageChangingListener listener) { 1475 pageChangingListeners.add(listener); 1476 } 1477 1478 1486 public void removePageChangingListener(IPageChangingListener listener) { 1487 pageChangingListeners.remove(listener); 1488 } 1489 1490 1501 protected void firePageChanging(final PageChangingEvent event) { 1502 Object [] listeners = pageChangingListeners.getListeners(); 1503 for (int i = 0; i < listeners.length; ++i) { 1504 final IPageChangingListener l = (IPageChangingListener) listeners[i]; 1505 SafeRunnable.run(new SafeRunnable() { 1506 public void run() { 1507 l.handlePageChanging(event); 1508 } 1509 }); 1510 } 1511 } 1512} 1513 | Popular Tags |