001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.dialogs;
011:
012: import org.eclipse.jface.dialogs.IDialogSettings;
013: import org.eclipse.jface.viewers.IStructuredSelection;
014: import org.eclipse.jface.wizard.WizardDialog;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.Control;
017: import org.eclipse.ui.IWorkbench;
018: import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
019: import org.eclipse.ui.internal.WorkbenchMessages;
020: import org.eclipse.ui.internal.activities.ws.WorkbenchTriggerPoints;
021: import org.eclipse.ui.wizards.IWizardCategory;
022: import org.eclipse.ui.wizards.IWizardDescriptor;
023:
024: /**
025: * New wizard selection tab that allows the user to either select a
026: * registered 'New' wizard to be launched, or to select a solution or
027: * projects to be retrieved from an available server. This page
028: * contains two visual tabs that allow the user to perform these tasks.
029: *
030: * Temporarily has two inner pages. The new format page is used if the system
031: * is currently aware of activity categories.
032: */
033: class NewWizardSelectionPage extends WorkbenchWizardSelectionPage {
034: private IWizardCategory wizardCategories;
035:
036: // widgets
037: private NewWizardNewPage newResourcePage;
038:
039: private IWizardDescriptor[] primaryWizards;
040:
041: private boolean projectsOnly;
042:
043: private boolean canFinishEarly = false, hasPages = true;
044:
045: /**
046: * Create an instance of this class.
047: *
048: * @param workbench the workbench
049: * @param selection the current selection
050: * @param root the wizard root element
051: * @param primary the primary wizard elements
052: * @param projectsOnly if only projects should be shown
053: */
054: public NewWizardSelectionPage(IWorkbench workbench,
055: IStructuredSelection selection, IWizardCategory root,
056: IWizardDescriptor[] primary, boolean projectsOnly) {
057: super (
058: "newWizardSelectionPage", workbench, selection, null, WorkbenchTriggerPoints.NEW_WIZARDS);//$NON-NLS-1$
059:
060: setTitle(WorkbenchMessages.NewWizardSelectionPage_description);
061: wizardCategories = root;
062: primaryWizards = primary;
063: this .projectsOnly = projectsOnly;
064: }
065:
066: /**
067: * Makes the next page visible.
068: */
069: public void advanceToNextPageOrFinish() {
070: if (canFlipToNextPage()) {
071: getContainer().showPage(getNextPage());
072: } else if (canFinishEarly()) {
073: if (getWizard().performFinish()) {
074: ((WizardDialog) getContainer()).close();
075: }
076: }
077: }
078:
079: /** (non-Javadoc)
080: * Method declared on IDialogPage.
081: */
082: public void createControl(Composite parent) {
083: IDialogSettings settings = getDialogSettings();
084: newResourcePage = new NewWizardNewPage(this , wizardCategories,
085: primaryWizards, projectsOnly);
086: newResourcePage.setDialogSettings(settings);
087:
088: Control control = newResourcePage.createControl(parent);
089: getWorkbench()
090: .getHelpSystem()
091: .setHelp(
092: control,
093: IWorkbenchHelpContextIds.NEW_WIZARD_SELECTION_WIZARD_PAGE);
094: setControl(control);
095: }
096:
097: /**
098: * Since Finish was pressed, write widget values to the dialog store so that they
099: *will persist into the next invocation of this wizard page
100: */
101: protected void saveWidgetValues() {
102: newResourcePage.saveWidgetValues();
103: }
104:
105: /* (non-Javadoc)
106: * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
107: */
108: public boolean canFlipToNextPage() {
109: // if the current page advertises that it does have pages then ask it via the super call
110: if (hasPages) {
111: return super .canFlipToNextPage();
112: }
113: return false;
114: }
115:
116: /**
117: * Sets whether the selected wizard advertises that it does provide pages.
118: *
119: * @param newValue whether the selected wizard has pages
120: * @since 3.1
121: */
122: public void setHasPages(boolean newValue) {
123: hasPages = newValue;
124: }
125:
126: /**
127: * Sets whether the selected wizard advertises that it can finish early.
128: *
129: * @param newValue whether the selected wizard can finish early
130: * @since 3.1
131: */
132: public void setCanFinishEarly(boolean newValue) {
133: canFinishEarly = newValue;
134: }
135:
136: /**
137: * Answers whether the currently selected page, if any, advertises that it may finish early.
138: *
139: * @return whether the page can finish early
140: * @since 3.1
141: */
142: public boolean canFinishEarly() {
143: return canFinishEarly;
144: }
145: }
|