Changeset 5912
- Timestamp:
- 2003-11-20T10:55:48+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java
r5843 r5912 40 40 import java.awt.event.*; 41 41 import java.io.*; 42 import java.util.ArrayList; 42 43 import javax.swing.*; 43 44 import javax.swing.event.*; 45 import org.greenstone.gatherer.checklist.CheckList; 46 import org.greenstone.gatherer.checklist.Entry; 44 47 import org.greenstone.gatherer.Dictionary; 45 48 import org.greenstone.gatherer.Gatherer; … … 63 66 extends ModalDialog 64 67 implements GShellListener { 68 private ArrayList all_collections = null; 69 private ArrayList selected_collections = null; 70 /** The list of collections to export */ 71 private CheckList list = null; 65 72 /** The currently selected collection for deletion. */ 66 73 private CollectionEntry collection = null; … … 78 85 private JLabel list_label = null; 79 86 /** The list of available collections. */ 80 private JList list = null;87 //private JList list = null; 81 88 /** The text area used to display details about the collection selected. */ 82 89 private JTextArea details_textarea = null; … … 84 91 private JTextArea instructions_textarea; 85 92 /** A string array used to pass arguments to the phrase retrieval method. */ 93 private JTextField title_field = null; 94 private JLabel title_label = null; 86 95 private String args[] = null; 87 96 private String cd_title = null; 88 97 /** whether the exporting was successful or not */ 89 98 private boolean successful = false; … … 120 129 Dictionary.registerText(instructions_textarea, "ExportCollectionPrompt.Instructions"); 121 130 122 list = new JList(); 131 //list = new JList(); 132 //list_model = new DefaultListModel(); 133 all_collections = new ArrayList(); 134 list = new CheckList(true); 123 135 list_label = new JLabel(); 124 136 Dictionary.setText(list_label, "DeleteCollectionPrompt.Collection_List"); 125 list_model = new DefaultListModel();126 137 ok_button = new JButton(); 127 138 ok_button.setMnemonic(KeyEvent.VK_D); 128 139 Dictionary.setBoth(ok_button, "ExportCollectionPrompt.Export", "ExportCollectionPrompt.Export_Tooltip"); 140 141 title_field = new JTextField(); 142 Dictionary.setTooltip(title_field, "ExportCollectionPrompt.CD_Name_Tooltip"); 143 title_label = new JLabel(); 144 Dictionary.setText(title_label, "ExportCollectionPrompt.CD_Name"); 145 //title_label.setPreferredSize(new Dimension(100, 40)); 146 scanForCollections(); 147 list.setListData(all_collections.toArray()); 148 129 149 prompt = this; 130 150 setModal(true); … … 137 157 list.clearSelection(); 138 158 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 139 list.setModel(list_model);140 159 ok_button.addActionListener(new OKButtonListener()); 141 160 ok_button.setEnabled(false); 142 scanForCollections();161 //title.getDocument().addDocumentListener(new DocumentListener()); 143 162 } 144 163 145 164 /** Destructor. */ 146 165 public void destroy() { 147 list_model.clear();148 list_model= null;166 all_collections.clear(); 167 all_collections = null; 149 168 cancel_button = null; 150 169 details_textarea = null; … … 153 172 ok_button = null; 154 173 prompt = null; 174 if (selected_collections!=null) { 175 selected_collections.clear(); 176 selected_collections = null; 177 } 178 title_field = null; 179 title_label = null; 155 180 } 156 181 157 182 /** This method causes the modal prompt to be displayed. 158 * returns true if it has deleted the collection that is currently open*/183 * returns true if it has exported the collections that are currently selected */ 159 184 public boolean display() { 160 185 // Top pane … … 163 188 instructions_pane.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER); 164 189 190 title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15)); 191 192 JPanel title_pane = new JPanel(new BorderLayout()); 193 title_pane.add(title_label, BorderLayout.WEST); 194 title_pane.add(title_field, BorderLayout.CENTER); 195 instructions_pane.add(title_pane, BorderLayout.SOUTH); 196 165 197 // Central pane 166 198 JPanel list_pane = new JPanel(new BorderLayout()); … … 216 248 * @see org.greenstone.gatherer.util.Utility 217 249 */ 218 public void exportCollection () {250 public void exportCollections() { 219 251 Gatherer.println("ExportCollectionPrompt.exportCollection()"); 220 252 253 int num_collections = selected_collections.size(); 254 if (num_collections == 0) return; 255 cd_title = title_field.getText(); 256 cd_title = cd_title.trim(); 257 cd_title = cd_title.replaceAll("\"",""); 258 int num_args = num_collections + 1; 259 boolean has_title = false; 260 if (!cd_title.equals("")) { 261 num_args += 2; 262 has_title = true; 263 } 221 264 String args[]; 265 int next_arg = 0; 222 266 if(Utility.isWindows()) { 223 args = new String[ 4];267 args = new String[num_args+2]; 224 268 args[0] = Gatherer.config.perl_path; 225 269 args[1] = "-S"; 226 args[2] = Gatherer.config.getScriptPath() + "exportcol.pl"; 227 args[3] = collection.getName(); 228 } 229 else { 230 args = new String[2]; 231 args[0] = Gatherer.config.getScriptPath() + "exportcol.pl"; 232 args[1] = collection.getName(); 270 next_arg = 2; 271 } else { 272 args = new String[num_args]; 233 273 } 234 274 275 args[next_arg] = Gatherer.config.getScriptPath() + "exportcol.pl"; 276 next_arg++; 277 if (has_title) { 278 args[next_arg] = "-cdname"; next_arg++; 279 args[next_arg] = cd_title; next_arg++; 280 } 281 for (int i=0; i<num_collections;i++,next_arg++) { 282 args[next_arg] = ((CollectionEntry)selected_collections.get(i)).getName(); 283 } 284 285 Gatherer.print("export command = "); 286 for (int i=0; i<args.length; i++) { 287 Gatherer.print(args[i]+" "); 288 } 289 Gatherer.println(""); 235 290 GShell process = new GShell(args, GShell.EXPORT, 3, this, null, GShell.GSHELL_EXPORT); 236 //process.addGShellListener(this);291 process.addGShellListener(this); 237 292 process.run(); // Don't bother threading this... yet 238 293 Gatherer.println("ExportCollectionPrompt.exportCollection().return"); … … 244 299 */ 245 300 public void resultPrompt(boolean success, String extra) { 301 success = true; 246 302 args = new String[2]; 247 args[0] = collection.getName(); 248 args[1] = "export_"+collection.getName(); 303 StringBuffer coll_names = new StringBuffer(); 304 for (int i=0; i<selected_collections.size();i++) { 305 if (i>0) { 306 coll_names.append(", "); 307 } 308 coll_names.append(((CollectionEntry)selected_collections.get(i)).getName()); 309 } 310 311 args[0] = coll_names.toString(); 312 if(cd_title.equals("")) { 313 args[1] = "exported_collections"; 314 } else { 315 args[1] = "exported_"+cd_title.replaceAll("\\s",""); 316 } 249 317 if (success) { 250 318 JOptionPane.showMessageDialog(prompt,Dictionary.get("ExportCollectionPrompt.Successful_Export", args)+"\n"+extra, Dictionary.get("ExportCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE); … … 277 345 if (config != null) { 278 346 CollectionEntry col = new CollectionEntry(collections[i].getName(), config); 279 list_model.addElement(col); 347 //list_model.addElement(col); 348 all_collections.add(col); 280 349 } 281 350 } … … 295 364 if (message.startsWith("exportcol.pl>")) { 296 365 message = message.substring(13); 297 System.err.println("message = "+event.getMessage());366 Gatherer.println("message = "+event.getMessage()); 298 367 error_message.append(message); 299 368 error_message.append("\n"); … … 342 411 ok_button.setEnabled(false); 343 412 if(!list.isSelectionEmpty()) { 344 collection = (CollectionEntry) list.getSelectedValue();413 collection = (CollectionEntry) ((Entry)list.getSelectedValue()).getObject(); 345 414 args = new String[5]; 346 415 args[0] = collection.getTitle(); … … 370 439 */ 371 440 public void actionPerformed(ActionEvent event) { 441 // make sure there are some colls specified 442 selected_collections = list.getSelected(); 372 443 error_message = new StringBuffer(); 373 444 … … 380 451 381 452 // Export the selected collection. 382 exportCollection ();453 exportCollections(); 383 454 384 455 // unset the cursor
Note:
See TracChangeset
for help on using the changeset viewer.