001: package org.enhydra.kelp.ant.deployer;
002:
003: import org.enhydra.tool.swing.layout.*;
004: import javax.swing.*;
005: import java.util.ResourceBundle;
006: import org.enhydra.kelp.common.node.OtterFileNode;
007: import java.awt.event.ActionListener;
008: import java.awt.event.ActionEvent;
009: import java.io.File;
010: import org.enhydra.kelp.common.node.OtterProject;
011: import org.enhydra.kelp.ant.node.AntProject;
012:
013: /**
014: * <p>Title: </p>
015: * <p>Description: </p>
016: * <p>Copyright: Copyright (c) 2003</p>
017: * <p>Company: </p>
018: * @author unascribed
019: * @version 1.0
020: */
021:
022: public class AntDeployInputTemplatesPanel extends JPanel {
023: static ResourceBundle res = ResourceBundle
024: .getBundle("org.enhydra.kelp.common.Res");
025:
026: XYLayout xYLayout1 = new XYLayout();
027: JLabel jLabelAreaHeader = new JLabel();
028: JScrollPane jScrollDocuments = new JScrollPane();
029: JList jListDocuments = new JList();
030: JCheckBox jCheckFullPath = new JCheckBox();
031: JLabel jLabelRoot = new JLabel();
032: JTextField jTextFieldRoot = new JTextField();
033: JButton jButtonBrowse = new JButton();
034: private LocalCheckListener checkListener = null;
035: private DefaultListModel modelAvailable = new DefaultListModel();
036: private OtterFileNode[] nodes = new OtterFileNode[0];
037: private AntProject project = null;
038:
039: public AntDeployInputTemplatesPanel() {
040: try {
041: jbInit();
042: pmInit();
043: } catch (Exception ex) {
044: ex.printStackTrace();
045: }
046: }
047:
048: void jbInit() throws Exception {
049: jLabelAreaHeader.setText(res.getString("Input_documents"));
050: this .setLayout(xYLayout1);
051: jCheckFullPath.setToolTipText("");
052: jCheckFullPath.setText(res.getString("Show_full"));
053: xYLayout1.setWidth(472);
054: xYLayout1.setHeight(287);
055: jLabelRoot.setText(res.getString("Input_root"));
056: jButtonBrowse.setText(res.getString("Browse"));
057: jButtonBrowse
058: .addActionListener(new java.awt.event.ActionListener() {
059: public void actionPerformed(ActionEvent e) {
060: jButtonBrowse_actionPerformed(e);
061: }
062: });
063: this .add(jLabelAreaHeader, new XYConstraints(12, 7, 107, 22));
064: this .add(jScrollDocuments, new XYConstraints(12, 37, 448, 119));
065: this .add(jCheckFullPath, new XYConstraints(12, 171, 129, -1));
066: this .add(jLabelRoot, new XYConstraints(12, 206, 65, -1));
067: this .add(jTextFieldRoot, new XYConstraints(75, 204, 288, -1));
068: this .add(jButtonBrowse, new XYConstraints(374, 203, 83, 23));
069: jScrollDocuments.getViewport().add(jListDocuments, null);
070: }
071:
072: private void pmInit() {
073: checkListener = new LocalCheckListener();
074: jTextFieldRoot.setEditable(false); //Do not allow manual changes, use browse button only
075: jCheckFullPath.addActionListener(checkListener);
076: jCheckFullPath.setSelected(false);
077: jListDocuments.setModel(getModelAvailable());
078: }
079:
080: protected DefaultListModel getModelAvailable() {
081: return modelAvailable;
082: }
083:
084: protected void fillLists() {
085: int count = getNodes().length;
086: OtterFileNode source = null;
087:
088: if (getModelAvailable().getSize() > 0) {
089: getModelAvailable().clear();
090: }
091:
092: for (int i = 0; i < count; i++) {
093: LocalListNode listNode = null;
094: source = getNodes()[i];
095: listNode = new LocalListNode(source.getFilePath());
096: getModelAvailable().addElement(listNode);
097: }
098: }
099:
100: public OtterFileNode[] getNodes() {
101: return nodes;
102: }
103:
104: public void setNodes(OtterFileNode[] n) {
105: nodes = n;
106: fillLists();
107: }
108:
109: public void setProject(OtterProject otterProject) {
110: if (otterProject instanceof AntProject) {
111: project = (AntProject) otterProject;
112: initOptions();
113: } else
114: System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
115: }
116:
117: private void initOptions() {
118: this .setNodes(project.getAllInput());
119: jTextFieldRoot.setText(project
120: .getProperty(AntProject.INPUT_DIR));
121:
122: // HashMap replacementsMap = project.getReplacements();
123: // Iterator replacementsIterator = replacementsMap.entrySet().iterator();
124: // defaultTable = new String[replacementsMap.size()][2];
125: // int i = 0;
126: // Map.Entry mapEntry = null;
127: // while (replacementsIterator.hasNext()) {
128: // mapEntry = (Map.Entry)replacementsIterator.next();
129: // defaultTable[i][0] = (String)mapEntry.getKey();
130: // defaultTable[i][1] = (String)mapEntry.getValue();
131: // i++;
132: // }
133: // setReplacementTable(defaultTable);
134: }
135:
136: void jButtonBrowse_actionPerformed(ActionEvent e) {
137: browseForDir();
138: }
139:
140: private void browseForDir() {
141: JFileChooser chooser;
142: String fileDir = new String();
143: File file = null;
144: chooser = new JFileChooser();
145: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
146: file = new File(project.getProperty(AntProject.INPUT_DIR));
147: if (!file.isAbsolute()) {
148: file = new File(project.getWorkingPath(), file.getPath());
149: }
150: chooser.setCurrentDirectory(file);
151: chooser.setDialogTitle(res
152: .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: private class LocalCheckListener implements ActionListener {
171: public void actionPerformed(ActionEvent event) {
172: Object source = event.getSource();
173:
174: if (source == jCheckFullPath) {
175:
176: fillLists();
177: }
178: }
179:
180: }
181:
182: private class LocalListNode {
183: private String full = new String();
184:
185: public LocalListNode(String fullName) {
186: full = fullName;
187: }
188:
189: public String toString() {
190: String s = full;
191:
192: if (!jCheckFullPath.isSelected()) {
193: File f = new File(full);
194:
195: s = f.getName();
196: }
197: return s;
198: }
199:
200: public String getFullname() {
201: return full;
202: }
203:
204: }
205: }
|