KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > deployer > AntDeployInputTemplatesPanel


1 package org.enhydra.kelp.ant.deployer;
2
3 import java.awt.*;
4 import org.enhydra.tool.swing.layout.*;
5 //import com.borland.jbcl.layout.*;
6
import javax.swing.*;
7 import java.util.ResourceBundle JavaDoc;
8 import org.enhydra.kelp.common.node.OtterFileNode;
9 import java.awt.event.ActionListener JavaDoc;
10 import java.awt.event.ActionEvent JavaDoc;
11 import java.io.File JavaDoc;
12 import org.enhydra.kelp.common.node.OtterProject;
13 import org.enhydra.kelp.ant.node.AntProject;
14
15 /**
16  * <p>Title: </p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author unascribed
21  * @version 1.0
22  */

23
24 public class AntDeployInputTemplatesPanel extends JPanel {
25   static ResourceBundle JavaDoc res = ResourceBundle.getBundle(
26                             "org.enhydra.kelp.common.Res");
27
28     XYLayout xYLayout1 = new XYLayout();
29     JLabel jLabelAreaHeader = new JLabel();
30     JScrollPane jScrollDocuments = new JScrollPane();
31     JList jListDocuments = new JList();
32     JCheckBox jCheckFullPath = new JCheckBox();
33     JLabel jLabelRoot = new JLabel();
34     JTextField jTextFieldRoot = new JTextField();
35     JButton jButtonBrowse = new JButton();
36     private LocalCheckListener checkListener = null;
37     private DefaultListModel modelAvailable = new DefaultListModel();
38     private OtterFileNode[] nodes = new OtterFileNode[0];
39     private AntProject project = null;
40
41     public AntDeployInputTemplatesPanel() {
42         try {
43             jbInit();
44             pmInit();
45         }
46         catch(Exception JavaDoc ex) {
47             ex.printStackTrace();
48         }
49     }
50     void jbInit() throws Exception JavaDoc {
51         jLabelAreaHeader.setText(res.getString("Input_documents"));
52         this.setLayout(xYLayout1);
53         jCheckFullPath.setToolTipText("");
54         jCheckFullPath.setText(res.getString("Show_full"));
55         xYLayout1.setWidth(472);
56         xYLayout1.setHeight(287);
57         jLabelRoot.setText(res.getString("Input_root"));
58         jButtonBrowse.setText(res.getString("Browse"));
59         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
60             public void actionPerformed(ActionEvent JavaDoc e) {
61                 jButtonBrowse_actionPerformed(e);
62             }
63         });
64         this.add(jLabelAreaHeader, new XYConstraints(12, 7, 107, 22));
65         this.add(jScrollDocuments, new XYConstraints(12, 37, 448, 119));
66         this.add(jCheckFullPath, new XYConstraints(12, 171, 129, -1));
67         this.add(jLabelRoot, new XYConstraints(12, 206, 65, -1));
68         this.add(jTextFieldRoot, new XYConstraints(75, 204, 288, -1));
69         this.add(jButtonBrowse, new XYConstraints(374, 203, 83, 23));
70         jScrollDocuments.getViewport().add(jListDocuments, null);
71     }
72
73     private void pmInit() {
74         checkListener = new LocalCheckListener();
75         jTextFieldRoot.setEditable(false); //Do not allow manual changes, use browse button only
76
jCheckFullPath.addActionListener(checkListener);
77         jCheckFullPath.setSelected(false);
78         jListDocuments.setModel(getModelAvailable());
79     }
80
81     protected DefaultListModel getModelAvailable() {
82         return modelAvailable;
83     }
84
85     protected void fillLists() {
86         int count = getNodes().length;
87         OtterFileNode source = null;
88
89         if (getModelAvailable().getSize() > 0) {
90             getModelAvailable().clear();
91         }
92
93         for (int i = 0; i < count; i++) {
94             LocalListNode listNode = null;
95             source = getNodes()[i];
96             listNode = new LocalListNode(source.getFilePath());
97             getModelAvailable().addElement(listNode);
98         }
99     }
100
101     public OtterFileNode[] getNodes() {
102         return nodes;
103     }
104
105     public void setNodes(OtterFileNode[] n) {
106         nodes = n;
107         fillLists();
108     }
109
110     public void setProject(OtterProject otterProject){
111         if(otterProject instanceof AntProject) {
112             project = (AntProject) otterProject;
113             initOptions();
114         }
115         else
116             System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
117
}
118
119     private void initOptions(){
120         this.setNodes(project.getAllInput());
121         jTextFieldRoot.setText(project.getProperty(AntProject.INPUT_DIR));
122
123 // HashMap replacementsMap = project.getReplacements();
124
// Iterator replacementsIterator = replacementsMap.entrySet().iterator();
125
// defaultTable = new String[replacementsMap.size()][2];
126
// int i = 0;
127
// Map.Entry mapEntry = null;
128
// while (replacementsIterator.hasNext()) {
129
// mapEntry = (Map.Entry)replacementsIterator.next();
130
// defaultTable[i][0] = (String)mapEntry.getKey();
131
// defaultTable[i][1] = (String)mapEntry.getValue();
132
// i++;
133
// }
134
// setReplacementTable(defaultTable);
135
}
136
137     void jButtonBrowse_actionPerformed(ActionEvent JavaDoc e) {
138         browseForDir();
139     }
140
141     private void browseForDir() {
142         JFileChooser chooser;
143         String JavaDoc fileDir = new String JavaDoc();
144         File JavaDoc file = null;
145         chooser = new JFileChooser();
146         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
147         file = new File JavaDoc(project.getProperty(AntProject.INPUT_DIR));
148         if (!file.isAbsolute()) {
149             file = new File JavaDoc(project.getWorkingPath(), file.getPath());
150         }
151         chooser.setCurrentDirectory(file);
152         chooser.setDialogTitle(res.getString("chooser_InputRoot_DialogTitle"));
153         chooser.setApproveButtonText(res.getString("OK"));
154         int v = chooser.showOpenDialog(this);
155
156         this.requestFocus();
157         jButtonBrowse.requestFocus();
158         if (v == JFileChooser.APPROVE_OPTION) {
159             if (!(chooser.getCurrentDirectory() == null)) {
160                 fileDir = chooser.getSelectedFile().toString();
161                 jTextFieldRoot.setText(fileDir);
162                 project.setProperty(AntProject.INPUT_DIR, fileDir);
163                 this.setNodes(project.getAllInput()); //Reload files from new input directory
164
}
165         }
166         chooser.removeAll();
167         chooser = null;
168     }
169
170
171     private class LocalCheckListener implements ActionListener JavaDoc {
172         public void actionPerformed(ActionEvent JavaDoc event) {
173             Object JavaDoc source = event.getSource();
174
175             if (source == jCheckFullPath) {
176                 
177                 fillLists();
178             }
179         }
180
181     }
182
183     private class LocalListNode {
184         private String JavaDoc full = new String JavaDoc();
185
186         public LocalListNode(String JavaDoc fullName) {
187             full = fullName;
188         }
189
190         public String JavaDoc toString() {
191             String JavaDoc s = full;
192
193             if (!jCheckFullPath.isSelected()) {
194                 File JavaDoc f = new File JavaDoc(full);
195
196                 s = f.getName();
197             }
198             return s;
199         }
200
201         public String JavaDoc getFullname() {
202             return full;
203         }
204
205     }
206 }
207
208
Popular Tags