KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > codegen > wizard > CodeGenDeck


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
25 package org.enhydra.tool.codegen.wizard;
26
27 //
28
// ToolBox imports
29
//
30
import org.enhydra.tool.common.wizard.TBWizardDeck;
31 import org.enhydra.tool.codegen.Generator;
32 import org.enhydra.tool.codegen.GeneratorException;
33 import org.enhydra.tool.codegen.ValidationException;
34
35 // Standard imports
36
import java.awt.Component JavaDoc;
37
38 /**
39  * Class declaration
40  *
41  *
42  * @author Paul Mahar
43  */

44 public class CodeGenDeck extends TBWizardDeck implements RootEditor {
45     private Generator selection = null;
46     private boolean selectionHidden = false;
47     private boolean allowRootEdit = true;
48
49     public CodeGenDeck() {
50       super();
51     }
52
53     public boolean isAllowRootEdit() {
54        return allowRootEdit;
55     }
56
57     public void setAllowRootEdit(boolean edit) {
58        allowRootEdit = edit;
59     }
60
61     protected void setSelectionPageHidden(boolean b) {
62         selectionHidden = b && (selection != null);
63         if (selectionHidden && getPageIndex() == 0) {
64             next();
65         }
66     }
67
68     protected boolean isSelectionPageHidden() {
69         return selectionHidden;
70     }
71
72     /**
73      * Method declaration
74      *
75      *
76      * @param selection
77      */

78     protected void setSelection(Generator sel)
79             throws GeneratorException {
80         selection = sel;
81         if (selection == null) {
82           System.err.println("GodeGenDeck.setSelect(): null selection");
83         } else {
84             while (getPages().length > 1) {
85                 removeWizardPage(getPages()[1]);
86             }
87             selection.setSwing(true);
88             for (int i = 0; i < selection.getWizardPanels().length; i++) {
89                 CodeGenPage newPage = new CodeGenPage();
90                 CodeGenPanel panel = selection.getWizardPanels()[i];
91                 if (panel instanceof RootEditor) {
92                   RootEditor editor = (RootEditor) panel;
93                   editor.setAllowRootEdit(isAllowRootEdit());
94                 }
95
96                 newPage.add(panel);
97                 newPage.setPageTitle(panel.getPageTitle());
98                 newPage.setInstructions(panel.getInstructions());
99                 addWizardPage(newPage);
100             }
101         }
102     }
103
104     /**
105      * Method declaration
106      *
107      *
108      * @return
109      *
110      * @see
111      */

112     protected Generator getSelection() {
113         return selection;
114     }
115
116     protected boolean isSelectionPageShowing() {
117         return getPageIndex() == 0;
118     }
119
120     // override TBWizardDeck
121
protected boolean isFirstPageShowing() {
122         boolean atFirst = super.isFirstPageShowing();
123
124         if (isSelectionPageHidden()) {
125             atFirst = (getPageIndex() == 1);
126         }
127         return (atFirst);
128     }
129
130     protected boolean isLastPageShowing() {
131         boolean atLast = super.isLastPageShowing();
132
133         if (! isSelectionPageHidden()) {
134             if (isSelectionPageShowing()) {
135               atLast = false;
136             }
137         }
138         return (atLast);
139     }
140
141
142
143     /**
144      * Method declaration
145      *
146      *
147      * @exception GeneratorException
148      * @exception ValidationException
149      *
150      * @see
151      */

152     protected void writeOptionSet()
153             throws ValidationException, GeneratorException {
154         CodeGenPage page = null;
155
156         // validate all pages before writing any
157
for (int i = 0; i < getPages().length; i++) {
158             page = (CodeGenPage) getPages()[i];
159             page.validateOptionSet();
160         }
161         for (int i = 0; i < getPages().length; i++) {
162             page = (CodeGenPage) getPages()[i];
163             page.writeOptionSet();
164         }
165     }
166
167 }
168
Popular Tags