KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > ArchiveDeck


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.archive.wizard;
25
26 // ToolBox
27
import org.enhydra.tool.archive.ArchiveException;
28 import org.enhydra.tool.archive.JarPlan;
29 import org.enhydra.tool.common.ToolException;
30 import org.enhydra.tool.common.wizard.TBWizardDeck;
31
32 // JDK
33
import java.awt.Component JavaDoc;
34 import java.lang.ref.WeakReference JavaDoc;
35
36 //
37
public class ArchiveDeck extends TBWizardDeck {
38     private ArchiveType selection = null;
39     private boolean selectionHidden = false;
40     private WeakReference JavaDoc wizardRef = null;
41
42     public ArchiveDeck(ArchiveWizard wizard) {
43         super();
44         wizardRef = new WeakReference JavaDoc(wizard);
45     }
46
47     protected void setSelectionPageHidden(boolean b) {
48         selectionHidden = b && (selection != null);
49         if (selectionHidden && (getPageIndex() == 0)) {
50             next();
51         }
52     }
53
54     protected boolean isSelectionPageHidden() {
55         return selectionHidden;
56     }
57
58     /**
59      * Method declaration
60      *
61      *
62      * @param selection
63      */

64     protected void setSelection(ArchiveType select) throws ArchiveException {
65         selection = select;
66         if (selection == null) {
67
68             // do no more
69
} else {
70             while (getPages().length > 1) {
71                 removeWizardPage(getPages()[1]);
72             }
73             for (int i = 0; i < selection.getWizardPanels().length; i++) {
74                 ArchivePage newPage = new ArchivePage();
75                 ArchivePanel panel = selection.getWizardPanels()[i];
76
77                 panel.setWizard(getWizard());
78                 newPage.add(panel);
79                 newPage.setPageTitle(panel.getPageTitle());
80                 newPage.setInstructions(panel.getInstructions());
81                 addWizardPage(newPage);
82             }
83         }
84     }
85
86     protected ArchiveType getSelection() {
87         return selection;
88     }
89
90     protected boolean isSelectionPageShowing() {
91         return getPageIndex() == 0;
92     }
93
94     // override TBWizardDeck
95
protected boolean isFirstPageShowing() {
96         boolean atFirst = super.isFirstPageShowing();
97
98         if (isSelectionPageHidden()) {
99             atFirst = (getPageIndex() == 1);
100         }
101         return (atFirst);
102     }
103
104     // Override TBWizardDeck
105
protected boolean isLastPageShowing() {
106         boolean atLast = super.isLastPageShowing();
107
108         if (!isSelectionPageHidden()) {
109             if (isSelectionPageShowing()) {
110                 atLast = false;
111             }
112         }
113         return (atLast);
114     }
115
116     protected void readPlan() throws ArchiveException {
117         ArchivePage page = null;
118
119         for (int i = 0; i < getPages().length; i++) {
120             page = (ArchivePage) getPages()[i];
121             page.readPlan(selection.getPlan());
122         }
123     }
124
125     protected void validatePlan() throws ArchiveException {
126         ArchivePage page = null;
127
128         // validate all pages before writing any
129
try {
130             for (int i = 0; i < getPages().length; i++) {
131                 page = (ArchivePage) getPages()[i];
132                 page.validatePage();
133             }
134         } catch (ToolException e) {
135             throw new ArchiveException(e, e.getMessage());
136         }
137     }
138
139     protected void writePlan() throws ArchiveException {
140         ArchivePage page = null;
141
142         for (int i = 0; i < getPages().length; i++) {
143             page = (ArchivePage) getPages()[i];
144             page.writePlan(selection.getPlan());
145         }
146     }
147
148     private ArchiveWizard getWizard() {
149         ArchiveWizard wizard = null;
150
151         if (wizardRef != null) {
152             wizard = (ArchiveWizard) wizardRef.get();
153         }
154         return wizard;
155     }
156
157 }
158
Popular Tags