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.jface.wizard;
011:
012: import java.util.ArrayList;
013: import java.util.List;
014:
015: /**
016: * An abstract implementation of a wizard page that manages a
017: * set of embedded wizards.
018: * <p>
019: * A wizard selection page should present a list of wizard nodes
020: * corresponding to other wizards. When the end user selects one of
021: * them from the list, the first page of the selected wizard becomes
022: * the next page. The only new methods introduced by this class are
023: * <code>getSelectedNode</code> and <code>setSelectedNode</code>.
024: * Otherwise, the subclass contract is the same as <code>WizardPage</code>.
025: * </p>
026: */
027: public abstract class WizardSelectionPage extends WizardPage {
028:
029: /**
030: * The selected node; <code>null</code> if none.
031: */
032: private IWizardNode selectedNode = null;
033:
034: /**
035: * List of wizard nodes that have cropped up in the past
036: * (element type: <code>IWizardNode</code>).
037: */
038: private List selectedWizardNodes = new ArrayList();
039:
040: /**
041: * Creates a new wizard selection page with the given name, and
042: * with no title or image.
043: *
044: * @param pageName the name of the page
045: */
046: protected WizardSelectionPage(String pageName) {
047: super (pageName);
048: // Cannot finish from this page
049: setPageComplete(false);
050: }
051:
052: /**
053: * Adds the given wizard node to the list of selected nodes if
054: * it is not already in the list.
055: *
056: * @param node the wizard node, or <code>null</code>
057: */
058: private void addSelectedNode(IWizardNode node) {
059: if (node == null) {
060: return;
061: }
062:
063: if (selectedWizardNodes.contains(node)) {
064: return;
065: }
066:
067: selectedWizardNodes.add(node);
068: }
069:
070: /**
071: * The <code>WizardSelectionPage</code> implementation of
072: * this <code>IWizardPage</code> method returns <code>true</code>
073: * if there is a selected node.
074: */
075: public boolean canFlipToNextPage() {
076: return selectedNode != null;
077: }
078:
079: /**
080: * The <code>WizardSelectionPage</code> implementation of an <code>IDialogPage</code>
081: * method disposes of all nested wizards. Subclasses may extend.
082: */
083: public void dispose() {
084: super .dispose();
085: // notify nested wizards
086: for (int i = 0; i < selectedWizardNodes.size(); i++) {
087: ((IWizardNode) selectedWizardNodes.get(i)).dispose();
088: }
089: }
090:
091: /**
092: * The <code>WizardSelectionPage</code> implementation of
093: * this <code>IWizardPage</code> method returns the first page
094: * of the currently selected wizard if there is one.
095: */
096: public IWizardPage getNextPage() {
097: if (selectedNode == null) {
098: return null;
099: }
100:
101: boolean isCreated = selectedNode.isContentCreated();
102:
103: IWizard wizard = selectedNode.getWizard();
104:
105: if (wizard == null) {
106: setSelectedNode(null);
107: return null;
108: }
109:
110: if (!isCreated) {
111: // Allow the wizard to create its pages
112: wizard.addPages();
113: }
114:
115: return wizard.getStartingPage();
116: }
117:
118: /**
119: * Returns the currently selected wizard node within this page.
120: *
121: * @return the wizard node, or <code>null</code> if no node is selected
122: */
123: public IWizardNode getSelectedNode() {
124: return selectedNode;
125: }
126:
127: /**
128: * Sets or clears the currently selected wizard node within this page.
129: *
130: * @param node the wizard node, or <code>null</code> to clear
131: */
132: protected void setSelectedNode(IWizardNode node) {
133: addSelectedNode(node);
134: selectedNode = node;
135: if (isCurrentPage()) {
136: getContainer().updateButtons();
137: }
138: }
139: }
|