📄 wizarddialog.java
字号:
/* (non-Javadoc) * Method declared on Dialog. */ protected void buttonPressed(int buttonId) { switch (buttonId) { case IDialogConstants.HELP_ID: { helpPressed(); break; } case IDialogConstants.BACK_ID: { backPressed(); break; } case IDialogConstants.NEXT_ID: { nextPressed(); break; } case IDialogConstants.FINISH_ID: { finishPressed(); break; } // The Cancel button has a listener which calls cancelPressed directly } } /** * Calculates the difference in size between the given * page and the page container. A larger page results * in a positive delta. * * @param page the page * @return the size difference encoded * as a <code>new Point(deltaWidth,deltaHeight)</code> */ private Point calculatePageSizeDelta(IWizardPage page) { Control pageControl = page.getControl(); if (pageControl == null) { // control not created yet return new Point(0, 0); } Point contentSize = pageControl.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); Rectangle rect = pageContainerLayout.getClientArea(pageContainer); Point containerSize = new Point(rect.width, rect.height); return new Point(Math.max(0, contentSize.x - containerSize.x), Math .max(0, contentSize.y - containerSize.y)); } /* (non-Javadoc) * Method declared on Dialog. */ protected void cancelPressed() { if (activeRunningOperations <= 0) { // Close the dialog. The check whether the dialog can be // closed or not is done in <code>okToClose</code>. // This ensures that the check is also evaluated when the user // presses the window's close button. setReturnCode(CANCEL); close(); } else { cancelButton.setEnabled(false); } } /* * (non-Javadoc) * @see org.eclipse.jface.window.Window#close() */ public boolean close() { if (okToClose()) { return hardClose(); } return false; } /* (non-Javadoc) * Method declared on Window. */ protected void configureShell(Shell newShell) { super.configureShell(newShell); // Register help listener on the shell newShell.addHelpListener(new HelpListener() { public void helpRequested(HelpEvent event) { // call perform help on the current page if (currentPage != null) { currentPage.performHelp(); } } }); } /** * Creates the buttons for this dialog's button bar. * <p> * The <code>WizardDialog</code> implementation of this framework method * prevents the parent composite's columns from being made equal width in * order to remove the margin between the Back and Next buttons. * </p> * * @param parent the parent composite to contain the buttons */ protected void createButtonsForButtonBar(Composite parent) { ((GridLayout) parent.getLayout()).makeColumnsEqualWidth = false; if (wizard.isHelpAvailable()) { helpButton = createButton(parent, IDialogConstants.HELP_ID, IDialogConstants.HELP_LABEL, false); } if (wizard.needsPreviousAndNextButtons()) { createPreviousAndNextButtons(parent); } finishButton = createButton(parent, IDialogConstants.FINISH_ID, IDialogConstants.FINISH_LABEL, true); cancelButton = createCancelButton(parent); } /** * Creates the Cancel button for this wizard dialog. * Creates a standard (<code>SWT.PUSH</code>) button and registers for its * selection events. Note that the number of columns in the button bar composite * is incremented. The Cancel button is created specially to give it a * removeable listener. * * @param parent the parent button bar * @return the new Cancel button */ private Button createCancelButton(Composite parent) { // increment the number of columns in the button bar ((GridLayout) parent.getLayout()).numColumns++; Button button = new Button(parent, SWT.PUSH); button.setText(IDialogConstants.CANCEL_LABEL); setButtonLayoutData(button); button.setFont(parent.getFont()); button.setData(new Integer(IDialogConstants.CANCEL_ID)); button.addSelectionListener(cancelListener); return button; } /** * Return the cancel button if the id is a the cancel id. * @param id the button id * @return the button corresponding to the button id */ protected Button getButton(int id) { if (id == IDialogConstants.CANCEL_ID) { return cancelButton; } return super.getButton(id); } /** * The <code>WizardDialog</code> implementation of this <code>Window</code> * method calls call <code>IWizard.addPages</code> to allow the current * wizard to add extra pages, then <code>super.createContents</code> to create * the controls. It then calls <code>IWizard.createPageControls</code> * to allow the wizard to pre-create their page controls prior to opening, * so that the wizard opens to the correct size. And finally it * shows the first page. */ protected Control createContents(Composite parent) { // Allow the wizard to add pages to itself // Need to call this now so page count is correct // for determining if next/previous buttons are needed wizard.addPages(); Control contents = super.createContents(parent); // Allow the wizard pages to precreate their page controls createPageControls(); // Show the first page showStartingPage(); return contents; } /* (non-Javadoc) * Method declared on Dialog. */ protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); // Build the Page container pageContainer = createPageContainer(composite); GridData gd = new GridData(GridData.FILL_BOTH); gd.widthHint = pageWidth; gd.heightHint = pageHeight; pageContainer.setLayoutData(gd); pageContainer.setFont(parent.getFont()); // Insert a progress monitor GridLayout pmlayout = new GridLayout(); pmlayout.numColumns = 1; progressMonitorPart = createProgressMonitorPart(composite, pmlayout); progressMonitorPart .setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); progressMonitorPart.setVisible(false); // Build the separator line Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); applyDialogFont(progressMonitorPart); return composite; } /** * Create the progress monitor part in the receiver. * @param composite * @param pmlayout * @return ProgressMonitorPart */ protected ProgressMonitorPart createProgressMonitorPart( Composite composite, GridLayout pmlayout) { return new ProgressMonitorPart(composite, pmlayout, SWT.DEFAULT) { String currentTask = null; /* (non-Javadoc) * @see org.eclipse.jface.wizard.ProgressMonitorPart#setBlocked(org.eclipse.core.runtime.IStatus) */ public void setBlocked(IStatus reason) { super.setBlocked(reason); if (!lockedUI) { getBlockedHandler().showBlocked(getShell(), this, reason, currentTask); } } /* (non-Javadoc) * @see org.eclipse.jface.wizard.ProgressMonitorPart#clearBlocked() */ public void clearBlocked() { super.clearBlocked(); if (!lockedUI) { getBlockedHandler().clearBlocked(); } } /* (non-Javadoc) * @see org.eclipse.jface.wizard.ProgressMonitorPart#beginTask(java.lang.String, int) */ public void beginTask(String name, int totalWork) { super.beginTask(name, totalWork); currentTask = name; } /* (non-Javadoc) * @see org.eclipse.jface.wizard.ProgressMonitorPart#setTaskName(java.lang.String) */ public void setTaskName(String name) { super.setTaskName(name); currentTask = name; } /* (non-Javadoc) * @see org.eclipse.jface.wizard.ProgressMonitorPart#subTask(java.lang.String) */ public void subTask(String name) { super.subTask(name); //If we haven't got anything yet use this value for more context if (currentTask == null) { currentTask = name; } } }; } /** * Creates the container that holds all pages. * @param parent * @return Composite */ private Composite createPageContainer(Composite parent) { Composite result = new Composite(parent, SWT.NULL); result.setLayout(pageContainerLayout); return result; } /** * Allow the wizard's pages to pre-create their page controls. * This allows the wizard dialog to open to the correct size. */ private void createPageControls() { // Allow the wizard pages to precreate their page controls // This allows the wizard to open to the correct size wizard.createPageControls(pageContainer); // Ensure that all of the created pages are initially not visible IWizardPage[] pages = wizard.getPages(); for (int i = 0; i < pages.length; i++) { IWizardPage page = pages[i]; if (page.getControl() != null) { page.getControl().setVisible(false); } } } /** * Creates the Previous and Next buttons for this wizard dialog. * Creates standard (<code>SWT.PUSH</code>) buttons and registers for their * selection events. Note that the number of columns in the button bar composite * is incremented. These buttons are created specially to prevent any space * between them. * * @param parent the parent button bar * @return a composite containing the new buttons */ private Composite createPreviousAndNextButtons(Composite parent) { // increment the number of columns in the button bar ((GridLayout) parent.getLayout()).numColumns++; Composite composite = new Composite(parent, SWT.NONE); // create a layout with spacing and margins appropriate for the font size. GridLayout layout = new GridLayout(); layout.numColumns = 0; // will be incremented by createButton layout.marginWidth = 0; layout.marginHeight = 0; layout.horizontalSpacing = 0; layout.verticalSpacing = 0; composite.setLayout(layout); GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER); composite.setLayoutData(data); composite.setFont(parent.getFont()); backButton = createButton(composite, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false); nextButton = createButton(composite, IDialogConstants.NEXT_ID, IDialogConstants.NEXT_LABEL, false); return composite; } /** * Creates and return a new wizard closing dialog without openiong it. * @return MessageDalog */ private MessageDialog createWizardClosingDialog() { MessageDialog result = new MessageDialog(getShell(), JFaceResources .getString("WizardClosingDialog.title"), //$NON-NLS-1$ null, JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$ MessageDialog.QUESTION, new String[] { IDialogConstants.OK_LABEL }, 0); return result; } /** * The Finish button has been pressed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -