1 package org.enhydra.kelp.ant.deployer; 2 3 import java.awt.*; 4 import org.enhydra.tool.swing.layout.*; 5 import javax.swing.*; 7 import java.util.ResourceBundle ; 8 import org.enhydra.kelp.common.node.OtterFileNode; 9 import java.awt.event.ActionListener ; 10 import java.awt.event.ActionEvent ; 11 import java.io.File ; 12 import org.enhydra.kelp.common.node.OtterProject; 13 import org.enhydra.kelp.ant.node.AntProject; 14 15 23 24 public class AntDeployInputTemplatesPanel extends JPanel { 25 static ResourceBundle 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 ex) { 47 ex.printStackTrace(); 48 } 49 } 50 void jbInit() throws Exception { 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 () { 60 public void actionPerformed(ActionEvent 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); 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"); } 118 119 private void initOptions(){ 120 this.setNodes(project.getAllInput()); 121 jTextFieldRoot.setText(project.getProperty(AntProject.INPUT_DIR)); 122 123 } 136 137 void jButtonBrowse_actionPerformed(ActionEvent e) { 138 browseForDir(); 139 } 140 141 private void browseForDir() { 142 JFileChooser chooser; 143 String fileDir = new String (); 144 File file = null; 145 chooser = new JFileChooser(); 146 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 147 file = new File (project.getProperty(AntProject.INPUT_DIR)); 148 if (!file.isAbsolute()) { 149 file = new File (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()); } 165 } 166 chooser.removeAll(); 167 chooser = null; 168 } 169 170 171 private class LocalCheckListener implements ActionListener { 172 public void actionPerformed(ActionEvent event) { 173 Object source = event.getSource(); 174 175 if (source == jCheckFullPath) { 176 177 fillLists(); 178 } 179 } 180 181 } 182 183 private class LocalListNode { 184 private String full = new String (); 185 186 public LocalListNode(String fullName) { 187 full = fullName; 188 } 189 190 public String toString() { 191 String s = full; 192 193 if (!jCheckFullPath.isSelected()) { 194 File f = new File (full); 195 196 s = f.getName(); 197 } 198 return s; 199 } 200 201 public String getFullname() { 202 return full; 203 } 204 205 } 206 } 207 208 | Popular Tags |