KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > wizard > WizardSelectionPage


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.jface.wizard;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  * An abstract implementation of a wizard page that manages a
18  * set of embedded wizards.
19  * <p>
20  * A wizard selection page should present a list of wizard nodes
21  * corresponding to other wizards. When the end user selects one of
22  * them from the list, the first page of the selected wizard becomes
23  * the next page. The only new methods introduced by this class are
24  * <code>getSelectedNode</code> and <code>setSelectedNode</code>.
25  * Otherwise, the subclass contract is the same as <code>WizardPage</code>.
26  * </p>
27  */

28 public abstract class WizardSelectionPage extends WizardPage {
29
30     /**
31      * The selected node; <code>null</code> if none.
32      */

33     private IWizardNode selectedNode = null;
34
35     /**
36      * List of wizard nodes that have cropped up in the past
37      * (element type: <code>IWizardNode</code>).
38      */

39     private List JavaDoc selectedWizardNodes = new ArrayList JavaDoc();
40
41     /**
42      * Creates a new wizard selection page with the given name, and
43      * with no title or image.
44      *
45      * @param pageName the name of the page
46      */

47     protected WizardSelectionPage(String JavaDoc pageName) {
48         super(pageName);
49         // Cannot finish from this page
50
setPageComplete(false);
51     }
52
53     /**
54      * Adds the given wizard node to the list of selected nodes if
55      * it is not already in the list.
56      *
57      * @param node the wizard node, or <code>null</code>
58      */

59     private void addSelectedNode(IWizardNode node) {
60         if (node == null) {
61             return;
62         }
63
64         if (selectedWizardNodes.contains(node)) {
65             return;
66         }
67
68         selectedWizardNodes.add(node);
69     }
70
71     /**
72      * The <code>WizardSelectionPage</code> implementation of
73      * this <code>IWizardPage</code> method returns <code>true</code>
74      * if there is a selected node.
75      */

76     public boolean canFlipToNextPage() {
77         return selectedNode != null;
78     }
79
80     /**
81      * The <code>WizardSelectionPage</code> implementation of an <code>IDialogPage</code>
82      * method disposes of all nested wizards. Subclasses may extend.
83      */

84     public void dispose() {
85         super.dispose();
86         // notify nested wizards
87
for (int i = 0; i < selectedWizardNodes.size(); i++) {
88             ((IWizardNode) selectedWizardNodes.get(i)).dispose();
89         }
90     }
91
92     /**
93      * The <code>WizardSelectionPage</code> implementation of
94      * this <code>IWizardPage</code> method returns the first page
95      * of the currently selected wizard if there is one.
96      */

97     public IWizardPage getNextPage() {
98         if (selectedNode == null) {
99             return null;
100         }
101
102         boolean isCreated = selectedNode.isContentCreated();
103
104         IWizard wizard = selectedNode.getWizard();
105
106         if (wizard == null) {
107             setSelectedNode(null);
108             return null;
109         }
110
111         if (!isCreated) {
112             // Allow the wizard to create its pages
113
wizard.addPages();
114         }
115
116         return wizard.getStartingPage();
117     }
118
119     /**
120      * Returns the currently selected wizard node within this page.
121      *
122      * @return the wizard node, or <code>null</code> if no node is selected
123      */

124     public IWizardNode getSelectedNode() {
125         return selectedNode;
126     }
127
128     /**
129      * Sets or clears the currently selected wizard node within this page.
130      *
131      * @param node the wizard node, or <code>null</code> to clear
132      */

133     protected void setSelectedNode(IWizardNode node) {
134         addSelectedNode(node);
135         selectedNode = node;
136         if (isCurrentPage()) {
137             getContainer().updateButtons();
138         }
139     }
140 }
141
Popular Tags