KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > NewWizardSelectionPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.dialogs;
12
13 import org.eclipse.jface.dialogs.IDialogSettings;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.jface.wizard.WizardDialog;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.ui.IWorkbench;
19 import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
20 import org.eclipse.ui.internal.WorkbenchMessages;
21 import org.eclipse.ui.internal.activities.ws.WorkbenchTriggerPoints;
22 import org.eclipse.ui.wizards.IWizardCategory;
23 import org.eclipse.ui.wizards.IWizardDescriptor;
24
25 /**
26  * New wizard selection tab that allows the user to either select a
27  * registered 'New' wizard to be launched, or to select a solution or
28  * projects to be retrieved from an available server. This page
29  * contains two visual tabs that allow the user to perform these tasks.
30  *
31  * Temporarily has two inner pages. The new format page is used if the system
32  * is currently aware of activity categories.
33  */

34 class NewWizardSelectionPage extends WorkbenchWizardSelectionPage {
35     private IWizardCategory wizardCategories;
36
37     // widgets
38
private NewWizardNewPage newResourcePage;
39
40     private IWizardDescriptor [] primaryWizards;
41
42     private boolean projectsOnly;
43     
44     private boolean canFinishEarly = false, hasPages = true;
45     
46     /**
47      * Create an instance of this class.
48      *
49      * @param workbench the workbench
50      * @param selection the current selection
51      * @param root the wizard root element
52      * @param primary the primary wizard elements
53      * @param projectsOnly if only projects should be shown
54      */

55     public NewWizardSelectionPage(IWorkbench workbench,
56             IStructuredSelection selection, IWizardCategory root,
57             IWizardDescriptor[] primary, boolean projectsOnly) {
58         super("newWizardSelectionPage", workbench, selection, null, WorkbenchTriggerPoints.NEW_WIZARDS);//$NON-NLS-1$
59

60         setTitle(WorkbenchMessages.NewWizardSelectionPage_description);
61         wizardCategories = root;
62         primaryWizards = primary;
63         this.projectsOnly = projectsOnly;
64     }
65
66     /**
67      * Makes the next page visible.
68      */

69     public void advanceToNextPageOrFinish() {
70             if (canFlipToNextPage()) {
71                 getContainer().showPage(getNextPage());
72             } else if (canFinishEarly()) {
73                 if (getWizard().performFinish()) {
74                     ((WizardDialog)getContainer()).close();
75                 }
76             }
77     }
78
79     /** (non-Javadoc)
80      * Method declared on IDialogPage.
81      */

82     public void createControl(Composite parent) {
83         IDialogSettings settings = getDialogSettings();
84         newResourcePage = new NewWizardNewPage(this, wizardCategories,
85                 primaryWizards, projectsOnly);
86         newResourcePage.setDialogSettings(settings);
87
88         Control control = newResourcePage.createControl(parent);
89         getWorkbench().getHelpSystem().setHelp(control,
90                 IWorkbenchHelpContextIds.NEW_WIZARD_SELECTION_WIZARD_PAGE);
91         setControl(control);
92     }
93
94     /**
95      * Since Finish was pressed, write widget values to the dialog store so that they
96      *will persist into the next invocation of this wizard page
97      */

98     protected void saveWidgetValues() {
99         newResourcePage.saveWidgetValues();
100     }
101         
102     /* (non-Javadoc)
103      * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
104      */

105     public boolean canFlipToNextPage() {
106         // if the current page advertises that it does have pages then ask it via the super call
107
if (hasPages) {
108                 return super.canFlipToNextPage();
109             }
110             return false;
111     }
112
113     /**
114      * Sets whether the selected wizard advertises that it does provide pages.
115      *
116      * @param newValue whether the selected wizard has pages
117      * @since 3.1
118      */

119     public void setHasPages(boolean newValue) {
120         hasPages = newValue;
121     }
122
123     /**
124      * Sets whether the selected wizard advertises that it can finish early.
125      *
126      * @param newValue whether the selected wizard can finish early
127      * @since 3.1
128      */

129     public void setCanFinishEarly(boolean newValue) {
130         canFinishEarly = newValue;
131     }
132
133     /**
134      * Answers whether the currently selected page, if any, advertises that it may finish early.
135      *
136      * @return whether the page can finish early
137      * @since 3.1
138      */

139     public boolean canFinishEarly() {
140         return canFinishEarly;
141     }
142 }
143
Popular Tags