KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.core.runtime.Assert;
14 import org.eclipse.jface.wizard.IWizardPage;
15 import org.eclipse.jface.wizard.Wizard;
16 import org.eclipse.ui.IWorkingSet;
17 import org.eclipse.ui.dialogs.IWorkingSetNewWizard;
18 import org.eclipse.ui.dialogs.IWorkingSetPage;
19 import org.eclipse.ui.internal.WorkbenchMessages;
20 import org.eclipse.ui.internal.WorkbenchPlugin;
21 import org.eclipse.ui.internal.registry.WorkingSetDescriptor;
22 import org.eclipse.ui.internal.registry.WorkingSetRegistry;
23
24 /**
25  * A new working set wizard allows the user to create a
26  * new working set using a plugin specified working set page.
27  *
28  * @since 2.0
29  * @see org.eclipse.ui.dialog.IWorkingSetPage
30  */

31 public class WorkingSetNewWizard extends Wizard implements IWorkingSetNewWizard {
32     private WorkingSetTypePage workingSetTypePage;
33
34     private IWorkingSetPage workingSetEditPage;
35
36     private String JavaDoc editPageId;
37
38     private IWorkingSet workingSet;
39     
40     private WorkingSetDescriptor[] descriptors;
41     
42     /**
43      * Creates a new instance of the receiver.
44      *
45      * @param descriptors the choice of descriptors
46      */

47     public WorkingSetNewWizard(WorkingSetDescriptor[] descriptors) {
48         super();
49         Assert.isTrue(descriptors != null && descriptors.length > 0);
50         this.descriptors= descriptors;
51         setWindowTitle(WorkbenchMessages.WorkingSetNewWizard_title);
52     }
53
54     /**
55      * Overrides method in Wizard.
56      * Adds a page listing the available kinds of working sets.
57      * The second wizard page will depend on the selected working set
58      * type.
59      *
60      * @see org.eclipse.jface.wizard.Wizard#addPages()
61      */

62     public void addPages() {
63         super.addPages();
64
65         IWizardPage page;
66         WorkingSetRegistry registry = WorkbenchPlugin.getDefault().getWorkingSetRegistry();
67         
68         if (descriptors.length > 1) {
69             page = workingSetTypePage = new WorkingSetTypePage(this.descriptors);
70         } else {
71             editPageId = descriptors[0].getId();
72             page = workingSetEditPage = registry.getWorkingSetPage(editPageId);
73         }
74         page.setWizard(this);
75         addPage(page);
76         setForcePreviousAndNextButtons(descriptors.length > 1);
77     }
78
79     /**
80      * Overrides method in Wizard.
81      *
82      * @see org.eclipse.jface.wizard.Wizard#canFinish()
83      */

84     public boolean canFinish() {
85         return (workingSetEditPage != null && workingSetEditPage
86                 .isPageComplete());
87     }
88
89     /**
90      * Overrides method in Wizard.
91      * Returns a working set page for creating the new working set.
92      * This second page is loaded from the plugin that defined the
93      * selected working set type.
94      *
95      * @see org.eclipse.jface.wizard.Wizard#getNextPage(IWizardPage)
96      */

97     public IWizardPage getNextPage(IWizardPage page) {
98         if (workingSetTypePage != null && page == workingSetTypePage) {
99             String JavaDoc pageId = workingSetTypePage.getSelection();
100             if (pageId != null) {
101                 if (workingSetEditPage == null || pageId != editPageId) {
102                     WorkingSetRegistry registry = WorkbenchPlugin.getDefault()
103                             .getWorkingSetRegistry();
104                     workingSetEditPage = registry.getWorkingSetPage(pageId);
105                     addPage(workingSetEditPage);
106                     editPageId = pageId;
107                 }
108                 return workingSetEditPage;
109             }
110         }
111         return null;
112     }
113
114     /**
115      * Returns the new working set. Returns null if the wizard has
116      * been cancelled.
117      *
118      * @return the new working set or null if the wizard has been
119      * cancelled.
120      */

121     public IWorkingSet getSelection() {
122         return workingSet;
123     }
124
125     /**
126      * Overrides method in Wizard.
127      * Stores the newly created working set and the id of the page
128      * used to create it.
129      *
130      * @see org.eclipse.jface.wizard.Wizard#performFinish()
131      */

132     public boolean performFinish() {
133         workingSetEditPage.finish();
134         workingSet = workingSetEditPage.getSelection();
135         workingSet.setId(editPageId);
136         return true;
137     }
138 }
139
Popular Tags