001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.core.runtime.Assert;
013: import org.eclipse.jface.wizard.IWizardPage;
014: import org.eclipse.jface.wizard.Wizard;
015: import org.eclipse.ui.IWorkingSet;
016: import org.eclipse.ui.dialogs.IWorkingSetNewWizard;
017: import org.eclipse.ui.dialogs.IWorkingSetPage;
018: import org.eclipse.ui.internal.WorkbenchMessages;
019: import org.eclipse.ui.internal.WorkbenchPlugin;
020: import org.eclipse.ui.internal.registry.WorkingSetDescriptor;
021: import org.eclipse.ui.internal.registry.WorkingSetRegistry;
022:
023: /**
024: * A new working set wizard allows the user to create a
025: * new working set using a plugin specified working set page.
026: *
027: * @since 2.0
028: * @see org.eclipse.ui.dialog.IWorkingSetPage
029: */
030: public class WorkingSetNewWizard extends Wizard implements
031: IWorkingSetNewWizard {
032: private WorkingSetTypePage workingSetTypePage;
033:
034: private IWorkingSetPage workingSetEditPage;
035:
036: private String editPageId;
037:
038: private IWorkingSet workingSet;
039:
040: private WorkingSetDescriptor[] descriptors;
041:
042: /**
043: * Creates a new instance of the receiver.
044: *
045: * @param descriptors the choice of descriptors
046: */
047: public WorkingSetNewWizard(WorkingSetDescriptor[] descriptors) {
048: super ();
049: Assert.isTrue(descriptors != null && descriptors.length > 0);
050: this .descriptors = descriptors;
051: setWindowTitle(WorkbenchMessages.WorkingSetNewWizard_title);
052: }
053:
054: /**
055: * Overrides method in Wizard.
056: * Adds a page listing the available kinds of working sets.
057: * The second wizard page will depend on the selected working set
058: * type.
059: *
060: * @see org.eclipse.jface.wizard.Wizard#addPages()
061: */
062: public void addPages() {
063: super .addPages();
064:
065: IWizardPage page;
066: WorkingSetRegistry registry = WorkbenchPlugin.getDefault()
067: .getWorkingSetRegistry();
068:
069: if (descriptors.length > 1) {
070: page = workingSetTypePage = new WorkingSetTypePage(
071: this .descriptors);
072: } else {
073: editPageId = descriptors[0].getId();
074: page = workingSetEditPage = registry
075: .getWorkingSetPage(editPageId);
076: }
077: page.setWizard(this );
078: addPage(page);
079: setForcePreviousAndNextButtons(descriptors.length > 1);
080: }
081:
082: /**
083: * Overrides method in Wizard.
084: *
085: * @see org.eclipse.jface.wizard.Wizard#canFinish()
086: */
087: public boolean canFinish() {
088: return (workingSetEditPage != null && workingSetEditPage
089: .isPageComplete());
090: }
091:
092: /**
093: * Overrides method in Wizard.
094: * Returns a working set page for creating the new working set.
095: * This second page is loaded from the plugin that defined the
096: * selected working set type.
097: *
098: * @see org.eclipse.jface.wizard.Wizard#getNextPage(IWizardPage)
099: */
100: public IWizardPage getNextPage(IWizardPage page) {
101: if (workingSetTypePage != null && page == workingSetTypePage) {
102: String pageId = workingSetTypePage.getSelection();
103: if (pageId != null) {
104: if (workingSetEditPage == null || pageId != editPageId) {
105: WorkingSetRegistry registry = WorkbenchPlugin
106: .getDefault().getWorkingSetRegistry();
107: workingSetEditPage = registry
108: .getWorkingSetPage(pageId);
109: addPage(workingSetEditPage);
110: editPageId = pageId;
111: }
112: return workingSetEditPage;
113: }
114: }
115: return null;
116: }
117:
118: /**
119: * Returns the new working set. Returns null if the wizard has
120: * been cancelled.
121: *
122: * @return the new working set or null if the wizard has been
123: * cancelled.
124: */
125: public IWorkingSet getSelection() {
126: return workingSet;
127: }
128:
129: /**
130: * Overrides method in Wizard.
131: * Stores the newly created working set and the id of the page
132: * used to create it.
133: *
134: * @see org.eclipse.jface.wizard.Wizard#performFinish()
135: */
136: public boolean performFinish() {
137: workingSetEditPage.finish();
138: workingSet = workingSetEditPage.getSelection();
139: workingSet.setId(editPageId);
140: return true;
141: }
142: }
|