📄 wizarddialog.java
字号:
*/ protected void finishPressed() { // Wizards are added to the nested wizards list in setWizard. // This means that the current wizard is always the last wizard in the list. // Note that we first call the current wizard directly (to give it a chance to // abort, do work, and save state) then call the remaining n-1 wizards in the // list (to save state). if (wizard.performFinish()) { // Call perform finish on outer wizards in the nested chain // (to allow them to save state for example) for (int i = 0; i < nestedWizards.size() - 1; i++) { ((IWizard) nestedWizards.get(i)).performFinish(); } // Hard close the dialog. setReturnCode(OK); hardClose(); } } /* (non-Javadoc) * Method declared on IWizardContainer. */ public IWizardPage getCurrentPage() { return currentPage; } /** * Returns the progress monitor for this wizard dialog (if it has one). * * @return the progress monitor, or <code>null</code> if * this wizard dialog does not have one */ protected IProgressMonitor getProgressMonitor() { return progressMonitorPart; } /** * Returns the wizard this dialog is currently displaying. * * @return the current wizard */ protected IWizard getWizard() { return wizard; } /** * Closes this window. * * @return <code>true</code> if the window is (or was already) closed, * and <code>false</code> if it is still open */ private boolean hardClose() { // inform wizards for (int i = 0; i < createdWizards.size(); i++) { IWizard createdWizard = (IWizard) createdWizards.get(i); createdWizard.dispose(); // Remove this dialog as a parent from the managed wizard. // Note that we do this after calling dispose as the wizard or // its pages may need access to the container during // dispose code createdWizard.setContainer(null); } return super.close(); } /** * The Help button has been pressed. */ protected void helpPressed() { if (currentPage != null) { currentPage.performHelp(); } } /** * The Next button has been pressed. */ protected void nextPressed() { IWizardPage page = currentPage.getNextPage(); if (page == null) { // something must have happend getting the next page return; } // show the next page showPage(page); } /** * Checks whether it is alright to close this wizard dialog * and performed standard cancel processing. If there is a * long running operation in progress, this method posts an * alert message saying that the wizard cannot be closed. * * @return <code>true</code> if it is alright to close this dialog, and * <code>false</code> if it is not */ private boolean okToClose() { if (activeRunningOperations > 0) { synchronized (this) { windowClosingDialog = createWizardClosingDialog(); } windowClosingDialog.open(); synchronized (this) { windowClosingDialog = null; } return false; } return wizard.performCancel(); } /** * Restores the enabled/disabled state of the given control. * * @param w the control * @param h the map (key type: <code>String</code>, element type: * <code>Boolean</code>) * @param key the key * @see #saveEnableStateAndSet */ private void restoreEnableState(Control w, Map h, String key) { if (w != null) { Boolean b = (Boolean) h.get(key); if (b != null) { w.setEnabled(b.booleanValue()); } } } /** * Restores the enabled/disabled state of the wizard dialog's * buttons and the tree of controls for the currently showing page. * * @param state a map containing the saved state as returned by * <code>saveUIState</code> * @see #saveUIState */ private void restoreUIState(Map state) { restoreEnableState(backButton, state, "back"); //$NON-NLS-1$ restoreEnableState(nextButton, state, "next"); //$NON-NLS-1$ restoreEnableState(finishButton, state, "finish"); //$NON-NLS-1$ restoreEnableState(cancelButton, state, "cancel"); //$NON-NLS-1$ restoreEnableState(helpButton, state, "help"); //$NON-NLS-1$ Object pageValue = state.get("page"); //$NON-NLS-1$ if (pageValue != null) { ((ControlEnableState) pageValue).restore(); } } /** * This implementation of IRunnableContext#run(boolean, boolean, * IRunnableWithProgress) blocks until the runnable has been run, * regardless of the value of <code>fork</code>. * It is recommended that <code>fork</code> is set to * true in most cases. If <code>fork</code> is set to <code>false</code>, * the runnable will run in the UI thread and it is the runnable's * responsibility to call <code>Display.readAndDispatch()</code> * to ensure UI responsiveness. * * UI state is saved prior to executing the long-running operation and is * restored after the long-running operation completes executing. Any attempt * to change the UI state of the wizard in the long-running operation will be * nullified when original UI state is restored. * */ public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { // The operation can only be canceled if it is executed in a separate thread. // Otherwise the UI is blocked anyway. Object state = null; if (activeRunningOperations == 0) { state = aboutToStart(fork && cancelable); } activeRunningOperations++; try { if (!fork) { lockedUI = true; } ModalContext.run(runnable, fork, getProgressMonitor(), getShell() .getDisplay()); lockedUI = false; } finally { activeRunningOperations--; //Stop if this is the last one if (state != null) { stopped(state); } } } /** * Saves the enabled/disabled state of the given control in the * given map, which must be modifiable. * * @param w the control, or <code>null</code> if none * @param h the map (key type: <code>String</code>, element type: * <code>Boolean</code>) * @param key the key * @param enabled <code>true</code> to enable the control, * and <code>false</code> to disable it * @see #restoreEnableState(Control, Map, String) */ private void saveEnableStateAndSet(Control w, Map h, String key, boolean enabled) { if (w != null) { h.put(key, new Boolean(w.getEnabled())); w.setEnabled(enabled); } } /** * Captures and returns the enabled/disabled state of the wizard dialog's * buttons and the tree of controls for the currently showing page. All * these controls are disabled in the process, with the possible excepton of * the Cancel button. * * @param keepCancelEnabled <code>true</code> if the Cancel button should * remain enabled, and <code>false</code> if it should be disabled * @return a map containing the saved state suitable for restoring later * with <code>restoreUIState</code> * @see #restoreUIState */ private Map saveUIState(boolean keepCancelEnabled) { Map savedState = new HashMap(10); saveEnableStateAndSet(backButton, savedState, "back", false); //$NON-NLS-1$ saveEnableStateAndSet(nextButton, savedState, "next", false); //$NON-NLS-1$ saveEnableStateAndSet(finishButton, savedState, "finish", false); //$NON-NLS-1$ saveEnableStateAndSet(cancelButton, savedState, "cancel", keepCancelEnabled); //$NON-NLS-1$ saveEnableStateAndSet(helpButton, savedState, "help", false); //$NON-NLS-1$ if (currentPage != null) { savedState .put( "page", ControlEnableState.disable(currentPage.getControl())); //$NON-NLS-1$ } return savedState; } /** * Sets the given cursor for all shells currently active * for this window's display. * * @param c the cursor */ private void setDisplayCursor(Cursor c) { Shell[] shells = getShell().getDisplay().getShells(); for (int i = 0; i < shells.length; i++) { shells[i].setCursor(c); } } /** * Sets the minimum page size used for the pages. * * @param minWidth the minimum page width * @param minHeight the minimum page height * @see #setMinimumPageSize(Point) */ public void setMinimumPageSize(int minWidth, int minHeight) { Assert.isTrue(minWidth >= 0 && minHeight >= 0); pageContainerLayout.minimumWidth = minWidth; pageContainerLayout.minimumHeight = minHeight; } /** * Sets the minimum page size used for the pages. * * @param size the page size encoded as * <code>new Point(width,height)</code> * @see #setMinimumPageSize(int,int) */ public void setMinimumPageSize(Point size) { setMinimumPageSize(size.x, size.y); } /** * Sets the size of all pages. * The given size takes precedence over computed sizes. * * @param width the page width * @param height the page height * @see #setPageSize(Point) */ public void setPageSize(int width, int height) { pageWidth = width; pageHeight = height; } /** * Sets the size of all pages. * The given size takes precedence over computed sizes. * * @param size the page size encoded as * <code>new Point(width,height)</code> * @see #setPageSize(int,int) */ public void setPageSize(Point size) { setPageSize(size.x, size.y); } /** * Sets the wizard this dialog is currently displaying. * * @param newWizard the wizard */ protected void setWizard(IWizard newWizard) { wizard = newWizard; wizard.setContainer(this); if (!createdWizards.contains(wizard)) { createdWizards.add(wizard); // New wizard so just add it to the end of our nested list nestedWizards.add(wizard); if (pageContainer != null) { // Dialog is already open // Allow the wizard pages to precreate their page controls // This allows the wizard to open to the correct size createPageControls(); // Ensure the dialog is large enough for the wizard updateSizeForWizard(wizard); pageContainer.layout(true); } } else { // We have already seen this wizard, if it is the previous wizard // on the nested list then we assume we have gone back and remove // the last wizard from the list int size = nestedWizards.size(); if (size >= 2 && nestedWizards.get(size - 2) == wizard) { nestedWizards.remove(size - 1); } else { // Assume we are going forward to revisit a wizard nestedWizards.add(wizard); } } } /* (non-Javadoc)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -