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.viewers.IStructuredSelection;
013: import org.eclipse.jface.viewers.TableViewer;
014: import org.eclipse.jface.wizard.IWizardNode;
015: import org.eclipse.jface.wizard.IWizardPage;
016: import org.eclipse.jface.wizard.WizardSelectionPage;
017: import org.eclipse.ui.IWorkbench;
018: import org.eclipse.ui.activities.ITriggerPoint;
019: import org.eclipse.ui.activities.WorkbenchActivityHelper;
020: import org.eclipse.ui.internal.WorkbenchMessages;
021: import org.eclipse.ui.model.AdaptableList;
022:
023: /**
024: * Page for selecting a wizard from a group of available wizards.
025: */
026: public abstract class WorkbenchWizardSelectionPage extends
027: WizardSelectionPage {
028:
029: // variables
030: protected IWorkbench workbench;
031:
032: protected AdaptableList wizardElements;
033:
034: public TableViewer wizardSelectionViewer;
035:
036: protected IStructuredSelection currentResourceSelection;
037:
038: protected String triggerPointId;
039:
040: /**
041: * Create an instance of this class
042: */
043: public WorkbenchWizardSelectionPage(String name,
044: IWorkbench aWorkbench,
045: IStructuredSelection currentSelection,
046: AdaptableList elements, String triggerPointId) {
047: super (name);
048: this .wizardElements = elements;
049: this .currentResourceSelection = currentSelection;
050: this .workbench = aWorkbench;
051: this .triggerPointId = triggerPointId;
052: setTitle(WorkbenchMessages.Select);
053: }
054:
055: /**
056: * Answer the wizard object corresponding to the passed id, or null
057: * if such an object could not be found
058: *
059: * @return WizardElement
060: * @param searchId the id to search on
061: */
062: protected WorkbenchWizardElement findWizard(String searchId) {
063: Object[] children = wizardElements.getChildren();
064: for (int i = 0; i < children.length; ++i) {
065: WorkbenchWizardElement currentWizard = (WorkbenchWizardElement) children[i];
066: if (currentWizard.getId().equals(searchId)) {
067: return currentWizard;
068: }
069: }
070:
071: return null;
072: }
073:
074: public IStructuredSelection getCurrentResourceSelection() {
075: return currentResourceSelection;
076: }
077:
078: public IWorkbench getWorkbench() {
079: return this .workbench;
080: }
081:
082: /**
083: * Specify the passed wizard node as being selected, meaning that if
084: * it's non-null then the wizard to be displayed when the user next
085: * presses the Next button should be determined by asking the passed
086: * node.
087: *
088: * @param node org.eclipse.jface.wizards.IWizardNode
089: */
090: public void selectWizardNode(IWizardNode node) {
091: setSelectedNode(node);
092: }
093:
094: /* (non-Javadoc)
095: * @see org.eclipse.jface.wizard.IWizardPage#getNextPage()
096: */
097: public IWizardPage getNextPage() {
098: ITriggerPoint triggerPoint = getWorkbench()
099: .getActivitySupport().getTriggerPointManager()
100: .getTriggerPoint(triggerPointId);
101: if (triggerPoint == null
102: || WorkbenchActivityHelper.allowUseOf(triggerPoint,
103: getSelectedNode())) {
104: return super.getNextPage();
105: }
106: return null;
107: }
108: }
|