KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > properties > TemplateNodePropertyPanel


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

23 package org.enhydra.kelp.common.properties;
24
25 // ToolBox
26
import org.enhydra.tool.ToolBoxInfo;
27 import org.enhydra.tool.common.DataValidationException;
28 import org.enhydra.tool.common.IconSet;
29 import org.enhydra.tool.common.PathHandle;
30 import org.enhydra.tool.common.ToolException;
31 import org.enhydra.tool.configure.ConfigTool;
32
33 // AddinCore
34
import org.enhydra.kelp.common.Backward;
35 import org.enhydra.kelp.common.PathUtil;
36 import org.enhydra.kelp.common.node.OtterTemplateNode;
37 import org.enhydra.kelp.common.node.OtterNode;
38 import org.enhydra.kelp.common.node.OtterProject;
39 import org.enhydra.kelp.common.event.SwingTableSelectionEvent;
40 import org.enhydra.kelp.common.event.SwingTableSelectionListener;
41 import org.enhydra.kelp.common.deployer.ReplacementTablePanel;
42 import org.enhydra.kelp.common.swing.AddinInnerPanel;
43
44 // JDK
45
import java.awt.*;
46 import java.awt.event.ActionEvent JavaDoc;
47 import java.awt.event.ActionListener JavaDoc;
48 import java.awt.event.ItemEvent JavaDoc;
49 import java.awt.event.ItemListener JavaDoc;
50 import java.beans.*;
51 import java.io.File JavaDoc;
52 import java.util.ResourceBundle JavaDoc;
53 import javax.swing.*;
54 import javax.swing.border.TitledBorder JavaDoc;
55
56 //
57
public class TemplateNodePropertyPanel extends AddinInnerPanel {
58     static ResourceBundle JavaDoc res =
59         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
60
private LocalRadioListener radioListener = null;
61     private GridBagLayout layoutMain;
62     private JCheckBox checkOutput;
63     private JCheckBox checkOverwrite;
64     private ReplacementTablePanel table;
65     private JCheckBox checkBootstrap;
66     private JPanel panelDeploy;
67     private JRadioButton radioFilter;
68     private JRadioButton radioAll;
69     private GridBagLayout layoutDeploy;
70
71     public TemplateNodePropertyPanel() {
72         try {
73             jbInit();
74             pmInit();
75         } catch (Exception JavaDoc e) {
76             e.printStackTrace();
77         }
78     }
79
80     public synchronized void addSwingTableSelectionListener(SwingTableSelectionListener l) {
81         table.addSwingTableSelectionListener(l);
82     }
83
84     public synchronized void removeSwingTableSelectionListener(SwingTableSelectionListener l) {
85         table.removeSwingTableSelectionListener(l);
86     }
87
88     public void setIconView(boolean b) {
89         table.setIconView(b);
90     }
91
92     public boolean isIconView() {
93         return table.isIconView();
94     }
95
96     // override AddinCoreNode
97
public void read(OtterNode node) {
98         super.read(node);
99         String JavaDoc stringIn = null;
100         File JavaDoc fileIn = null;
101         PathHandle phBoot = null;
102         OtterProject project = null;
103
104         table.setNode(node);
105         project = getProject();
106         phBoot =
107             PathHandle.createPathHandle(project.getDeployBootstrapPath());
108         if (node instanceof OtterTemplateNode) {
109             OtterTemplateNode template = (OtterTemplateNode) node;
110
111             panelDeploy.setVisible(false);
112             checkOutput.setSelected(template.isSelected());
113             if (phBoot.equals(template.getOutputPath())) {
114                 checkBootstrap.setSelected(true);
115             } else {
116                 checkBootstrap.setSelected(false);
117             }
118             remove(panelDeploy);
119             enableUI(checkOutput.isSelected());
120         } else {
121             panelDeploy.setVisible(true);
122             checkOutput.setVisible(false);
123             checkBootstrap.setVisible(false);
124             remove(checkOutput);
125             remove(checkBootstrap);
126             readFilter();
127             enableUI(true);
128         }
129         checkOverwrite.setSelected(project.isDeployOverwrite());
130         table.readProperties();
131         invalidate();
132     }
133
134     // override AddinCoreNode
135
public void write(OtterNode node) throws DataValidationException {
136         super.write(node);
137         OtterProject project = getProject();
138
139         if (node instanceof OtterTemplateNode) {
140             OtterTemplateNode template = (OtterTemplateNode) node;
141
142             template.setSelected(checkOutput.isSelected());
143             if (checkBootstrap.isSelected()) {
144                 project.setDeployBootstrapPath(template.getOutputPath());
145             }
146         } else {
147             if (radioFilter.isEnabled()) {
148                 project.setDeployInputFilter(radioFilter.isSelected());
149             }
150         }
151         project.setDeployOverwrite(checkOverwrite.isSelected());
152         table.writeProperties();
153     }
154
155     // override AddinInnerPanel
156
public Component[] getFirstFocusComponents() {
157         Component[] comps = new Component[7];
158
159         comps[0] = checkOutput;
160         comps[1] = checkOverwrite;
161         comps[2] = table;
162         comps[3] = checkBootstrap;
163         comps[4] = panelDeploy;
164         comps[5] = radioFilter;
165         comps[6] = radioAll;
166         return comps;
167     }
168
169     //
170
//
171
protected void readFilter() {
172         boolean inFilter = false;
173
174         inFilter = PathUtil.isInputInSource(getProject());
175         if (inFilter) {
176             radioAll.setEnabled(false);
177             radioFilter.setEnabled(false);
178         } else {
179             radioAll.setEnabled(true);
180             radioFilter.setEnabled(true);
181             inFilter = getProject().isDeployInputFilter();
182         }
183         if (inFilter) {
184             radioAll.setSelected(false);
185             radioFilter.setSelected(true);
186         } else {
187             radioAll.setSelected(true);
188             radioFilter.setSelected(false);
189         }
190         updateUI();
191     }
192
193     //
194
//
195
private void refreshSelections() {
196         getProject().setDeployInputFilter(radioFilter.isSelected());
197     }
198
199     private void enableUI(boolean enable) {
200         checkOverwrite.setEnabled(enable);
201         checkBootstrap.setEnabled(enable);
202         table.enableUI(enable);
203     }
204
205     private void pmInit() throws Exception JavaDoc {
206         ButtonGroup group = null;
207
208         group = new ButtonGroup();
209         group.add(radioAll);
210         group.add(radioFilter);
211         radioListener = new LocalRadioListener();
212         radioAll.addItemListener(radioListener);
213         radioFilter.addItemListener(radioListener);
214         setIconView(false);
215     }
216
217     private void jbInit() throws Exception JavaDoc {
218         checkOutput =
219             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
220                                           JCheckBox.class.getName());
221         checkOverwrite =
222             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
223                                           JCheckBox.class.getName());
224         checkBootstrap =
225             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
226                                           JCheckBox.class.getName());
227         layoutMain =
228             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
229                                               GridBagLayout.class.getName());
230         table =
231             (ReplacementTablePanel) Beans.instantiate(getClass().getClassLoader(),
232                 ReplacementTablePanel.class.getName());
233         panelDeploy = (JPanel) Beans.instantiate(getClass().getClassLoader(),
234                                                  JPanel.class.getName());
235         radioFilter =
236             (JRadioButton) Beans.instantiate(getClass().getClassLoader(),
237                                              JRadioButton.class.getName());
238         radioAll =
239             (JRadioButton) Beans.instantiate(getClass().getClassLoader(),
240                                              JRadioButton.class.getName());
241         layoutDeploy =
242             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
243                                               GridBagLayout.class.getName());
244         checkOutput.setText(res.getString("Deploy"));
245         checkOutput.addActionListener(new java.awt.event.ActionListener JavaDoc() {
246             public void actionPerformed(ActionEvent JavaDoc e) {
247                 enableUI(checkOutput.isSelected());
248             }
249
250         });
251         checkOverwrite.setText(res.getString("checkOverwrite_Text"));
252         checkBootstrap.setText(res.getString("checkBootstrap_Text"));
253         radioFilter.setText(res.getString("radioFilter_Text"));
254         radioAll.setSelected(true);
255         radioAll.setText(res.getString("radioAll_Text"));
256
257         //
258
//
259
panelDeploy.setBorder(BorderFactory.createTitledBorder(res.getString("panelDeploy_Border")));
260         panelDeploy.setLayout(layoutDeploy);
261         panelDeploy.add(radioFilter,
262                         new GridBagConstraints(1, 0, 1, 1, 0.1, 0.0,
263                                                GridBagConstraints.CENTER,
264                                                GridBagConstraints.HORIZONTAL,
265                                                new Insets(1, 5, 1, 10), 10,
266                                                0));
267         panelDeploy.add(radioAll,
268                         new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0,
269                                                GridBagConstraints.CENTER,
270                                                GridBagConstraints.HORIZONTAL,
271                                                new Insets(1, 10, 1, 5), 10,
272                                                0));
273         table.setBorder(BorderFactory.createTitledBorder("Template Replacements"));
274
275         //
276
this.setLayout(layoutMain);
277         this.add(checkOutput,
278                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
279                                         GridBagConstraints.WEST,
280                                         GridBagConstraints.HORIZONTAL,
281                                         new Insets(10, 5, 5, 5), 0, 0));
282         this.add(checkOverwrite,
283                  new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1,
284                                         GridBagConstraints.WEST,
285                                         GridBagConstraints.HORIZONTAL,
286                                         new Insets(3, 20, 2, 5), 0, 0));
287         this.add(panelDeploy,
288                  new GridBagConstraints(0, 2, 1, 1, 0.1, 0.1,
289                                         GridBagConstraints.CENTER,
290                                         GridBagConstraints.BOTH,
291                                         new Insets(4, 15, 4, 5), 0, 1));
292         this.add(checkBootstrap,
293                  new GridBagConstraints(0, 3, 1, 1, 0.1, 0.1,
294                                         GridBagConstraints.WEST,
295                                         GridBagConstraints.HORIZONTAL,
296                                         new Insets(2, 20, 3, 5), 0, 0));
297         this.add(table,
298                  new GridBagConstraints(0, 4, 1, 1, 0.4, 0.1,
299                                         GridBagConstraints.CENTER,
300                                         GridBagConstraints.BOTH,
301                                         new Insets(3, 15, 3, 5), 10, 20));
302     }
303
304     //
305
private class LocalRadioListener implements ItemListener JavaDoc {
306         public void itemStateChanged(ItemEvent JavaDoc e) {
307             if (e.getStateChange() == ItemEvent.SELECTED) {
308                 refreshSelections();
309             }
310         }
311
312     }
313
314     //
315
}
316
Popular Tags