source: trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java@ 5302

Last change on this file since 5302 was 5302, checked in by jmt12, 21 years ago

Fixed 203B112 - similar open collection dialog

  • Property svn:keywords set to Author Date Id Revision
File size: 36.6 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.datatransfer.*;
40import java.awt.event.*;
41import java.io.*;
42import java.lang.*;
43import java.net.*;
44import java.util.*;
45import javax.swing.*;
46import javax.swing.event.*;
47import javax.swing.plaf.*;
48import javax.swing.text.*;
49import org.greenstone.gatherer.Configuration;
50import org.greenstone.gatherer.Gatherer;
51import org.greenstone.gatherer.collection.Collection;
52import org.greenstone.gatherer.collection.DeleteCollectionPrompt;
53import org.greenstone.gatherer.collection.LoadCollectionBox;
54import org.greenstone.gatherer.collection.SaveCollectionBox;
55import org.greenstone.gatherer.file.FileNode;
56import org.greenstone.gatherer.file.FileOpenActionListener;
57import org.greenstone.gatherer.gui.AboutDialog;
58import org.greenstone.gatherer.gui.BrowsingPane;
59import org.greenstone.gatherer.gui.CollectionPane;
60import org.greenstone.gatherer.gui.CreatePane;
61import org.greenstone.gatherer.gui.Filter;
62import org.greenstone.gatherer.gui.GConfigPane;
63import org.greenstone.gatherer.gui.MenuBar;
64import org.greenstone.gatherer.gui.MetaEditPane;
65import org.greenstone.gatherer.gui.MirrorPane;
66import org.greenstone.gatherer.gui.OpenCollectionDialog;
67import org.greenstone.gatherer.gui.OptionsBox;
68import org.greenstone.gatherer.gui.Preferences;
69import org.greenstone.gatherer.gui.PreviewPane;
70import org.greenstone.gatherer.gui.SimpleOpenCollectionDialog;
71import org.greenstone.gatherer.gui.messages.MessagePane;
72import org.greenstone.gatherer.gui.metaaudit.MetaAuditFrame;
73import org.greenstone.gatherer.gui.tree.DragTree;
74import org.greenstone.gatherer.help.HelpFrame;
75import org.greenstone.gatherer.msm.ElementWrapper;
76import org.greenstone.gatherer.msm.Metadata;
77import org.greenstone.gatherer.sarm.SearchAndReplace;
78import org.greenstone.gatherer.shell.GShell;
79import org.greenstone.gatherer.util.TreeSynchronizer;
80import org.greenstone.gatherer.util.Utility;
81import org.greenstone.gatherer.valuetree.GValueNode;
82/** The GUIManager is in charge of creating the Gatherer window frame then filling it with the goodness of the view panes. GUIManager not only creates these panes, but allows some messaging between them. Furthermore GUIManager includes functionality from menu driven choices, simply as it was easier to put it here once and have it accessible from all pane children. */
83public class GUIManager
84 extends JFrame
85 implements ActionListener, ChangeListener {
86 /** The browsing pane behaves much like an internet browser, or at least will some day. */
87 public BrowsingPane browser_pane = null;
88 /** The collection pane is more like a file manager where you drag files from one tree to another. */
89 public CollectionPane collection_pane = null;
90 /** The create pane contains scripting options for importing and building collections into libraries. */
91 public CreatePane create_pane = null;
92
93 public FileOpenActionListener foa_listener = new FileOpenActionListener();
94
95 /** The configuration pane allows you to edit the design of the library in terms of the collection configuration file. */
96 public GConfigPane config_pane = null;
97 /** A reference to the currently instantiated help window, if any. */
98 public HelpFrame help = null;
99 /** The menu bar. */
100 public MenuBar menu_bar = null;
101 /** The message pane is optional and contains the log of messages sent. */
102 public MessagePane message_pane = null;
103
104 public MetaAuditFrame meta_audit;
105 /** The metaedit pane is used to assign, edit and remove metadata from files within the collection. */
106 public MetaEditPane metaedit_pane = null;
107 /** The mirror pane contains controls for mirroring interent sites. */
108 public MirrorPane mirror_pane = null;
109 /** The preview pane contains a preview of your build collection. */
110 public PreviewPane preview_pane = null;
111 /** Are certain panes currently locked? */
112 private boolean locked = false;
113 /** The size of the Gatherer window. */
114 private Dimension size = null;
115 /** The filters used to dynamically filter the trees at user request. */
116 private HashMap filters = new HashMap();
117 /** The panel within the window that other components are placed on. */
118 private JPanel content_pane = null;
119 /** The dummy export pane. */
120 private JPanel export_pane = new JPanel();
121 /** The last view pane selected. */
122 private JPanel previous_pane;
123 /** The main tab pane containing the different views, available here to trap view change events. */
124 private JTabbedPane tab_pane = null;
125 /** A reference to any existing search and replace module/dialog. */
126 private SearchAndReplace sar = null;
127 /** A threaded tab changer to try and avoid NPE on exit. */
128 private TabUpdater tab_updater = null;
129 /** The thread group this manager, and hence its child graphical rendering threads, belong to. In a vain attempts to make the Dictionary work across threads.
130 * @see org.greenstone.gatherer.Dictionary
131 */
132 private ThreadGroup thread_group = null;
133 /** Ensures that expansion events between like collection trees are synchronized. */
134 private TreeSynchronizer collection_tree_sync = null;
135 /** Ensures that expansion events between like workspace trees are synchronized. */
136 private TreeSynchronizer workspace_tree_sync = null;
137 /**Constructor. Enable window events and arranges all other components.
138 * @param size The intial <strong>Dimension</strong> of the screen.
139 * @param graphic The default <strong>GraphicsConfiguration</strong> for this platform.
140 */
141 public GUIManager(Dimension size) {
142 super();
143 // Initialization
144 this.help = new HelpFrame();
145 this.size = size;
146 this.collection_tree_sync = new TreeSynchronizer();
147 this.meta_audit = new MetaAuditFrame(collection_tree_sync, null);
148 this.workspace_tree_sync = new TreeSynchronizer();
149 // Make the Tool tip hang around for a rediculous amount of time.
150 ToolTipManager.sharedInstance().setDismissDelay(10000);
151 // Get a reference to the main thread group. Create a new thread, which defaults into the same thread group, then get its thread group. Easy.
152 Thread bob = new Thread();
153 thread_group = bob.getThreadGroup();
154 // Set up some other UI stuff. (fonts handled in Gatherer.main())
155 UIManager.put("FileChooser.lookInLabelText", Gatherer.dictionary.get("SaveCollectionBox.Look_In"));
156 UIManager.put("FileChooser.filesOfTypeLabelText", Gatherer.dictionary.get("SaveCollectionBox.Files_Of_Type"));
157 UIManager.put("FileChooser.fileNameLabelText", Gatherer.dictionary.get("SaveCollectionBox.File_Name"));
158 }
159 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured. In this case we are listening to actions from the menu-bar, and should react appropriately.
160 * @param event An <strong>ActionEvent</strong> containing information about the action that has occured.
161 */
162 public void actionPerformed(ActionEvent event) {
163 boolean cont = true;
164 Object esrc = event.getSource();
165 // *************
166 // File Options.
167 // *************
168 if(esrc == menu_bar.file_associations) {
169 Gatherer.assoc_man.edit();
170 }
171 else if(esrc == menu_bar.file_close) {
172 // if(!Gatherer.c_man.saved()) {
173 cont = showSaveCollectionBox(true, false);
174 // }
175 if(cont) {
176 tab_pane.setSelectedComponent(collection_pane);
177 }
178 }
179 else if(esrc == menu_bar.file_delete) {
180 DeleteCollectionPrompt dcp = new DeleteCollectionPrompt();
181 if(dcp.display()) {
182 Gatherer.c_man.closeCollection();
183 }
184 dcp.destroy();
185 dcp = null;
186 System.gc();
187 }
188 else if(esrc == menu_bar.file_exit) {
189 menu_bar.exit();
190 exit();
191 }
192 else if(esrc == menu_bar.file_new) {
193 showNewCollectionPrompt();
194 }
195 else if(esrc == menu_bar.file_open) {
196 if (showLoadCollectionBox()) {
197 tab_pane.setSelectedComponent(collection_pane);
198 }
199 }
200 else if(esrc == menu_bar.file_options) {
201 new Preferences();
202 }
203 else if(esrc == menu_bar.file_save) {
204 Gatherer.c_man.saveCollection(false, false);
205 }
206 else if(esrc == menu_bar.file_save_as) {
207 String name = JOptionPane.showInputDialog(this, "Enter new collection filename.");
208 if(name != null) {
209 Gatherer.c_man.saveCollectionAs(name);
210 }
211 }
212 // *************
213 // Edit Options.
214 // *************
215 else if(esrc == menu_bar.edit_copy) {
216 try {
217 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
218 // Get the component with selected text as a JTextComponent
219 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();//getFocusOwner();
220 text.copy();
221 }
222 catch (Exception cce) {
223 // If the component is not a text component ignore the copy command
224 Gatherer.println(cce.toString());
225 }
226 }
227 else if(esrc == menu_bar.edit_cut) {
228 try {
229 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
230 // Get the component with selected text as a JTextComponent
231 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
232 // Cut the text to the clipboard
233 text.cut();
234 }
235 catch (ClassCastException cce) {
236 // If the component is not a text component ignore the cut command
237 Gatherer.println(cce.toString());
238 }
239 }
240 else if(esrc == menu_bar.edit_paste) {
241 try {
242 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
243 // Get the component with selected text as a JTextComponent
244 JTextComponent text = (JTextComponent) kfm.getPermanentFocusOwner();
245 // Cut the text to the clipboard
246 text.paste();
247 }
248 catch (ClassCastException cce) {
249 // If the component is not a text component ignore the paste command
250 Gatherer.println(cce.toString());
251 }
252 }
253 else if(esrc == menu_bar.edit_search) {
254 if(sar != null) {
255 sar.dispose();
256 }
257 sar = new SearchAndReplace(false);
258 }
259 else if(esrc == menu_bar.edit_replace) {
260 if(sar != null) {
261 sar.dispose();
262 }
263 sar = new SearchAndReplace(true);
264 }
265 // *************
266 // Tools Options.
267 // *************
268 else if(esrc == menu_bar.tools_size) {
269 FileNode records[] = metaedit_pane.getSelectedNode();
270 if(records != null && records.length > 0) {
271 ArrayList metadatum = Gatherer.c_man.getCollection().gdm.getMetadata(records[0].getFile());
272 if(metadatum.size() >= 4) {
273 Metadata metadata = (Metadata) metadatum.get(0);
274 ElementWrapper ew = metadata.getElement();
275
276 int SIZE = 5000;
277 Object[] array = new Object[SIZE];
278 Runtime.getRuntime().gc();
279 long start = Runtime.getRuntime().freeMemory();
280 for (int i = 0; i < SIZE; i++) {
281 array[i] = ew.copy();
282 }
283 Runtime.getRuntime().gc();
284 long end = Runtime.getRuntime().freeMemory();
285 long difference = (( start - end ) / SIZE);
286 ///ystem.out.println(difference + " bytes used." );
287 }
288 }
289 }
290 // *************
291 // Help Options.
292 // *************
293 else if(esrc == menu_bar.help_about) {
294 new AboutDialog(this);
295 }
296 else if(esrc == menu_bar.help_browse) {
297 help.setView("3.0");
298 }
299 else if(esrc == menu_bar.help_build) {
300 help.setView("8.0");
301 }
302 else if(esrc == menu_bar.help_collect) {
303 help.setView("5.0");
304 }
305 else if(esrc == menu_bar.help_design) {
306 help.setView("7.0");
307 }
308 else if(esrc == menu_bar.help_general) {
309 help.setView("");
310 }
311 else if(esrc == menu_bar.help_metaedit) {
312 help.setView("6.0");
313 }
314 else if(esrc == menu_bar.help_mirror) {
315 help.setView("4.0");
316 }
317 else if(esrc == menu_bar.help_preview) {
318 help.setView("9.0");
319 }
320 // *****************
321 // Metadata Options.
322 // *****************
323 else if(esrc == menu_bar.metadata_add) {
324 Gatherer.c_man.getCollection().msm.importMDS();
325 }
326 else if(esrc == menu_bar.metadata_edit) {
327 showEditMetadataBox();
328 }
329 else if(esrc == menu_bar.metadata_export) {
330 Gatherer.c_man.getCollection().msm.exportMDS();
331 }
332 else if(esrc == menu_bar.metadata_view) {
333 showMetaAuditBox();
334 }
335 else if(esrc == menu_bar.tools_log) {
336 showLogBox();
337 }
338 }
339 /** Any actions that should happen after the display of the Gatherer window can be called here. Currently only updates the browser pane if it is active to work around bug in Mozilla renderer implementation.
340 */
341 public void afterDisplay() {
342 if(Gatherer.config.get("workflow.mirror", true)) {
343 browser_pane.afterDisplay();
344 }
345 metaedit_pane.afterDisplay();
346 }
347 /** Once a collection has been made available to Gatherer, either by its creation or by it being reloaded, we need to inform all the visual components to update necessary data components (such as tree models), enable certain controls that depend on a collection being accessible, and refresh themselves.
348 * @param ready <i>true</i> if the collection is ready for editing, <i>false</i> otherwise.
349 */
350 public void collectionChanged(final boolean ready) {
351 if(Gatherer.config.get("workflow.mirror", true)) {
352 mirror_pane.collectionChanged(ready);
353 }
354 menu_bar.collectionChanged(ready); // Inform the menu bar that the collections changed.
355 collection_pane.collectionChanged(ready); // Used to update the collection workspace.
356 metaedit_pane.collectionChanged(ready); // Very important that metaedit pane shows current collection and is listening to latest msm.
357 config_pane.collectionChanged(ready); // Also important config pane is listening to latest msm.
358 create_pane.collectionChanged(ready); // Used to indicate a new BuildOptions model should be loaded.
359 preview_pane.collectionChanged(ready); // preview should know when teh coll has changed so it can reload the home page
360 // Force tree model updates.
361 Gatherer.c_man.refreshTrees();
362 if(!locked) {
363 // Now enable tabs as necessary. Do this on event queue to prevent crazy NPEs
364 if(tab_updater == null) {
365 tab_updater = new TabUpdater(tab_pane, ready);
366 }
367 else {
368 tab_updater.setReady(ready);
369 }
370 SwingUtilities.invokeLater(tab_updater);
371 }
372 // Finally display the collection name in the title bar.
373 if(ready) {
374 this.setTitle(Utility.PROGRAM_NAME + ":\"" + Gatherer.c_man.getCollection().getTitle() + "\"");
375 }
376 else {
377 this.setTitle(Utility.PROGRAM_NAME + ": " + get("Collection.No_Collection"));
378 }
379 // Now is a good time to force a garbage collect.
380 ///ystem.err.println("Calling garbage collection.");
381 System.gc();
382 }
383 /** Enabled events on the window to be trapped, creates all the visual components, then builds the tab and other layouts.
384 */
385 public void display() {
386 content_pane = (JPanel) this.getContentPane();
387 // Enable window-type events to be fired.
388 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
389 // Initialise and layout sub-components, plus other window dressing.
390 try {
391 this.setSize(size);
392 if(Gatherer.c_man.ready()) {
393 this.setTitle(Utility.PROGRAM_NAME + ":\"" + Gatherer.c_man.getCollection().getTitle() + "\"");
394 }
395 else {
396 this.setTitle(Utility.PROGRAM_NAME + ": " + get("Collection.No_Collection"));
397 }
398 // Pretty corner icon
399 this.setIconImage(Utility.getImage("gatherer_small.gif").getImage());
400 // BorderLayout for the main screen. I'll try my best to avoid t
401 // hese in subcomponents as they're space greedy.
402 content_pane.setLayout(new BorderLayout());
403 // Create the menu-bar and stick it up the top.
404 menu_bar = new MenuBar(new MenuListenerImpl());
405 content_pane.add(menu_bar, BorderLayout.NORTH);
406 // Create the tabbed pane and plop it in the center where it will
407 // expand to consume all available space like any good gas would.
408 tab_pane = new JTabbedPane();
409 tab_pane.addChangeListener(this);
410 tab_pane.setFont(Gatherer.config.getFont("general.font", false));
411
412 // May have to play with the order in which tabs are added.
413 if(Gatherer.config.get("workflow.browse", true)) {
414 browser_pane = new BrowsingPane();
415 tab_pane.addTab(get("Browser"), Utility.getImage("browsing.gif"), browser_pane);
416 tab_pane.setEnabledAt(tab_pane.indexOfComponent(browser_pane), Gatherer.config.get("workflow.browse", false));
417 }
418
419 if(Gatherer.config.get("workflow.mirror", true)) {
420 mirror_pane = new MirrorPane();
421 tab_pane.addTab(get("Mirroring"), Utility.getImage("mirroring.gif"), mirror_pane);
422 tab_pane.setEnabledAt(tab_pane.indexOfComponent(mirror_pane), Gatherer.config.get("workflow.mirror", false));
423 }
424
425 if(Gatherer.config.get("workflow.gather", true)) {
426 collection_pane = new CollectionPane(workspace_tree_sync, collection_tree_sync);
427 collection_pane.display();
428 tab_pane.addTab(get("Collection"), Utility.getImage("collection.gif"), collection_pane);
429 tab_pane.setEnabledAt(tab_pane.indexOfComponent(collection_pane), Gatherer.config.get("workflow.gather", false));
430 }
431
432 if(Gatherer.config.get("workflow.enrich", true)) {
433 metaedit_pane = new MetaEditPane(collection_tree_sync);
434 metaedit_pane.display();
435 tab_pane.addTab(get("MetaEdit"), Utility.getImage("metaedit.gif"), metaedit_pane);
436 tab_pane.setEnabledAt(tab_pane.indexOfComponent(metaedit_pane), false);
437 }
438
439 if(Gatherer.config.get("workflow.design", true)) {
440 config_pane = new GConfigPane();
441 config_pane.display();
442 tab_pane.addTab(get("Build"), Utility.getImage("build.gif"), config_pane);
443 tab_pane.setEnabledAt(tab_pane.indexOfComponent(config_pane), false);
444 }
445
446 if(Gatherer.config.get("workflow.export", true)) {
447 tab_pane.addTab(get("Export"), Utility.getImage("export.gif"), export_pane);
448 tab_pane.setEnabledAt(tab_pane.indexOfComponent(export_pane), false);
449 }
450
451 if(Gatherer.config.get("workflow.create", true)) {
452 create_pane = new CreatePane();
453 create_pane.display();
454 tab_pane.addTab(get("Create"), Utility.getImage("build session.gif"), create_pane);
455 tab_pane.setEnabledAt(tab_pane.indexOfComponent(create_pane), false);
456 }
457
458 if(Gatherer.config.get("workflow.preview", true)) {
459 preview_pane = new PreviewPane();
460 preview_pane.display();
461 tab_pane.addTab(get("Preview"), Utility.getImage("final.gif"), preview_pane);
462 tab_pane.setEnabledAt(tab_pane.indexOfComponent(preview_pane), false);
463 }
464
465 // Find the first tab that is enabled and select that.
466 boolean found = false;
467 for(int i = 0; !found && i < tab_pane.getTabCount(); i++) {
468 if(tab_pane.isEnabledAt(i)) {
469 tab_pane.setSelectedIndex(i);
470 found = true;
471 }
472 }
473
474 content_pane.add(tab_pane, BorderLayout.CENTER);
475 // Drive a sessionReady event to update all controls to reflect current collection status.
476 collectionChanged(Gatherer.c_man.ready());
477 }
478 catch (Exception e) {
479 Gatherer.printStackTrace(e);
480 // The GUI failing to build is a app killer
481 e.printStackTrace();
482 System.exit(1);
483 }
484 }
485 /** When called this method ensures that all the things needing saving are saved before Gatherer.exit() is called. This includes a save collection prompt if necessary.
486 */
487 public void exit() {
488 boolean cont = true;
489 if(Gatherer.c_man.ready() && !Gatherer.c_man.saved()) {
490 cont = showSaveCollectionBox(false, true);
491 }
492 else {
493 help.destroy();
494 help = null;
495 Gatherer.self.exit();
496 }
497 }
498 /** Retrieve the filter, or if one already exists, spawn a linked copy. */
499 public Filter getFilter(DragTree tree) {
500 Filter filter = (Filter) filters.get(tree.getModel());
501 if(filter == null) {
502 filter = new Filter(tree, null);
503 filters.put(tree.getModel(), filter);
504 return filter;
505 }
506 return filter.spawn(tree);
507 }
508
509 public Component getSelectedView() {
510 return tab_pane.getSelectedComponent();
511 }
512 /** This method is called when the collection is being built, and is used to disable all controls in all pane which could change the state of the collection.
513 */
514 public void lockCollection(boolean import_stage, boolean lock) {
515 locked = lock;
516 if(import_stage) {
517 int collection_pos = tab_pane.indexOfComponent(collection_pane);
518 int metaedit_pos = tab_pane.indexOfComponent(metaedit_pane);
519 int config_pos = tab_pane.indexOfComponent(config_pane);
520 tab_pane.setEnabledAt(collection_pos, !lock);
521 tab_pane.setEnabledAt(metaedit_pos, !lock);
522 tab_pane.setEnabledAt(config_pos, !lock);
523 }
524 else {
525 int config_pos = tab_pane.indexOfComponent(config_pane);
526 tab_pane.setEnabledAt(config_pos, !lock);
527 }
528 }
529
530 public void refreshTrees() {
531 collection_pane.refreshTrees();
532 //metaedit_pane.refreshTrees();
533 }
534
535 /** Allows the system to programatically set the selected tab.
536 * @param component The view you wish to make visable in the tab pane as a <strong>Component</strong>.
537 */
538 public void setSelectedView(Component component) {
539 tab_pane.setSelectedComponent(component);
540 }
541
542 /** Specifies whether a certain tab is enabled or not. */
543 public void setTabEnabled(String rawname, boolean state) {
544 // Retrieve the dictionary based name.
545 String name = get(rawname);
546 int index = tab_pane.indexOfTab(name);
547 // Of course we may not have this tab available.
548 if(index != -1) {
549 // Some tabs are also dependant on if a collection is ready
550 Component component = tab_pane.getComponentAt(index);
551 if(component == preview_pane) {
552 tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready() && Gatherer.c_man.built());
553 }
554 else if(component == metaedit_pane || component == config_pane || component == export_pane || component == create_pane) {
555 tab_pane.setEnabledAt(index, state && Gatherer.c_man != null && Gatherer.c_man.ready());
556 }
557 else {
558 tab_pane.setEnabledAt(index, state);
559 }
560 // If this was the currently selected tab and it is now disabled, change the view to the first enabled tab.
561 if(tab_pane.getSelectedIndex() == index && !state) {
562 boolean found = false;
563 for(int i = 0; !found && i < tab_pane.getTabCount(); i++) {
564 if(tab_pane.isEnabledAt(i)) {
565 tab_pane.setSelectedIndex(i);
566 found = true;
567 }
568 }
569 // If there are no tabs enabled, which should be impossible, then select the first tab
570 if(!found) {
571 tab_pane.setSelectedIndex(0);
572 }
573 }
574 }
575 // If the rawname was mirror then rebuild workspace tree to remove caches.
576 if(rawname.equals("Mirroring")) {
577 collection_pane.refreshWorkspace();
578 }
579 }
580
581 /** When the edit metadata option is choosen from the menu, this method is called to ensure we only edit the metadata if there is metadata loaded.
582 */
583 public void showEditMetadataBox() {
584 if(Gatherer.c_man.getCollection() != null) {
585 Gatherer.c_man.getCollection().msm.editMDS();
586 }
587 }
588 /** When the load collection option is choosen this method is called to produce the modal file load prompt.
589 */
590 public boolean showLoadCollectionBox() {
591 boolean result = false;
592 // We first try the simple open collection dialog
593 SimpleOpenCollectionDialog dialog = new SimpleOpenCollectionDialog();
594 int user_choice = dialog.display();
595 String filename = null;
596 // The user may choose to go to the advanced 'browse' dialog
597 if(user_choice == SimpleOpenCollectionDialog.OK_OPTION) {
598 filename = dialog.getFileName();
599 }
600 else if(user_choice == SimpleOpenCollectionDialog.BROWSE_OPTION) {
601 File file;
602 if(Gatherer.config.gsdl_path != null) {
603 file = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
604 }
605 else {
606 file = new File(Utility.BASE_DIR);
607 }
608 OpenCollectionDialog chooser = new OpenCollectionDialog(file);
609 file = null;
610 filename = chooser.getFileName();
611 chooser.destroy();
612 chooser = null;
613 }
614 dialog.destroy();
615 dialog = null;
616 // User can cancel action.
617 if(filename != null) {
618 // If there is already a collection open, save and close it.
619 if(Gatherer.c_man.ready()) {
620 showSaveCollectionBox(true, false);
621 // Wait until it is closed.
622 try {
623 synchronized(this) {
624 while(Gatherer.c_man.reallyReady()) {
625 wait(10);
626 }
627 }
628 }
629 catch(Exception error) {
630 Gatherer.println("Exception: " + error);
631 Gatherer.printStackTrace(error);
632 }
633 }
634 result = Gatherer.c_man.loadCollection(filename);
635 filename = null;
636 }
637 return result;
638 }
639 /** When called this method causes the Log class in Gatherer to display a nice dialog box which contains the log.
640 */
641 public void showLogBox() {
642 Gatherer.log.display();
643 }
644 /** When called this method causes the MetaAuditBox class in CollectionManager to display a nice dialog box which contains all the metadata assigned in the collection.
645 */
646 public void showMetaAuditBox() {
647 wait(true);
648 meta_audit.display();
649 wait(false);
650 }
651 /** This method is used to open the new collection box on the screen.
652 */
653 public void showNewCollectionPrompt() {
654 NewCollectionMetadataPrompt ncm_prompt = null;
655 // Create the collection details prompt from new collection prompt
656 NewCollectionDetailsPrompt ncd_prompt = new NewCollectionDetailsPrompt();
657 // If no previous collection was indicated as a model design, then show the metadata selection prompt from new collection prompt
658 if(!ncd_prompt.isCancelled() && (ncd_prompt.getBase() == null)) {
659 ncm_prompt = new NewCollectionMetadataPrompt();
660 }
661 // Create the new collection (if not cancelled) in a new thread.
662 if(!ncd_prompt.isCancelled() && (ncm_prompt == null || !ncm_prompt.isCancelled())) {
663 // If there is already a collection open, save and close it.
664 if(Gatherer.c_man.ready()) {
665 showSaveCollectionBox(true, false);
666 // Wait until it is closed.
667 try {
668 synchronized(this) {
669 while(Gatherer.c_man.reallyReady()) {
670 wait(10);
671 }
672 }
673 }
674 catch(Exception error) {
675 Gatherer.println("Exception: " + error);
676 Gatherer.printStackTrace(error);
677 }
678 }
679
680 // Create new collection.
681 CreationTask task = new CreationTask(ncd_prompt, ncm_prompt);
682 // SwingUtilities.invokeLater(task);
683 task.start();
684 // Close prompt.
685 }
686 // Done
687 ncd_prompt = null;
688 ncm_prompt = null;
689 }
690 private class CreationTask
691 extends Thread {
692 private NewCollectionDetailsPrompt ncd_prompt = null;
693 private NewCollectionMetadataPrompt ncm_prompt = null;
694 public CreationTask(NewCollectionDetailsPrompt ncd_prompt, NewCollectionMetadataPrompt ncm_prompt) {
695 this.ncd_prompt = ncd_prompt;
696 this.ncm_prompt = ncm_prompt;
697 }
698
699 public void run() {
700 ///ystem.err.println("Running CreationTask...");
701 if(ncm_prompt == null) {
702 Gatherer.c_man.createCollection(ncd_prompt.getDescription(), ncd_prompt.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), ncd_prompt.getBase(), null);
703 }
704 else {
705 Gatherer.c_man.createCollection(ncd_prompt.getDescription(), ncd_prompt.getEmail(), ncd_prompt.getName(), ncd_prompt.getTitle(), null, ncm_prompt.getSets());
706 }
707 // Now that the collection specific settings are loaded we can set the 'view extracted metadata' property
708 Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, ncd_prompt.viewExtractedMetadata());
709
710 ncd_prompt.dispose();
711 ncd_prompt = null;
712 if(ncm_prompt != null) {
713 ncm_prompt.dispose();
714 ncm_prompt = null;
715 }
716 }
717 }
718
719 /** This method is used to open the options box on the screen.
720 */
721 public void showOptionsBox() {
722 new OptionsBox();
723 }
724 /** This method is used to open the save collection box/prompt on the screen.
725 * @return A <i>boolean</i> which is <i>true</i> if the collection was saved successfully, <i>false</i> otherwise.
726 */
727 public boolean showSaveCollectionBox(boolean close_after, boolean exit_after) {
728 //SaveCollectionBox save_collection_box = new SaveCollectionBox();
729 //Rectangle bounds = save_collection_box.getBounds();
730 //int result = save_collection_box.getUserOption(Gatherer.c_man.getCollection().getName());
731 //switch(result) {
732 //case SaveCollectionBox.SAVE_YES:
733 Gatherer.c_man.saveCollection(close_after, exit_after);
734 // Wait until it is closed.
735 try {
736 synchronized(this) {
737 while(Gatherer.c_man.reallyReady()) {
738 wait(10);
739 }
740 }
741 }
742 catch(Exception error) {
743 Gatherer.println("Exception: " + error);
744 Gatherer.printStackTrace(error);
745 }
746
747 //content_pane.paintImmediately(bounds);
748 return true;
749 //case SaveCollectionBox.SAVE_NO:
750 // Close collection.
751 // if(close_after) {
752 // tab_pane.setSelectedComponent(collection_pane);
753 // Gatherer.c_man.closeCollection();
754 // }
755 // if(exit_after) {
756 // Gatherer.self.exit();
757 // }
758 // return true;
759 //default:
760 // return false;
761 //}
762 }
763 /** Any implementation of ChangeListener must include this method so we can be informed when the state of one of the registered objects changes. In this case we are listening to view changes within the tabbed pane.
764 * @param event A ChangeEvent containing information about the event that fired this call.
765 */
766 public void stateChanged(ChangeEvent event) {
767 if(previous_pane != null) {
768 if(previous_pane == create_pane) {
769 create_pane.loseFocus();
770 }
771 }
772 // "View assigned metadata" menu item is disabled by default
773 menu_bar.metadata_view.setCanEnable(false);
774 menu_bar.setMetaAuditSuffix(null);
775
776 menu_bar.tabSelected(tab_pane.getSelectedIndex());
777 if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(collection_pane)) {
778 collection_pane.gainFocus();
779 // "View assigned metadata" menu item is enabled for the "Gather" pane
780 menu_bar.metadata_view.setCanEnable(true);
781 }
782 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(metaedit_pane)) {
783 metaedit_pane.gainFocus();
784 // "View assigned metadata" menu item is enabled for the "Enrich" pane
785 menu_bar.metadata_view.setCanEnable(true);
786 }
787 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(config_pane)) {
788 config_pane.gainFocus();
789 }
790 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(create_pane)) {
791 create_pane.gainFocus();
792 }
793 else if(tab_pane.getSelectedIndex() == tab_pane.indexOfComponent(preview_pane)) {
794 config_pane.saveConfiguration();
795 preview_pane.gainFocus();
796 }
797
798 previous_pane = (JPanel) tab_pane.getSelectedComponent();
799 }
800
801 private MouseListener mouse_blocker_listener = new MouseAdapter() {};
802
803 public void wait(boolean waiting) {
804 Component glass_pane = getGlassPane();
805 if(waiting) {
806 // Show wait cursor.
807 glass_pane.addMouseListener(mouse_blocker_listener);
808 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
809 glass_pane.setVisible(true);
810 }
811 else {
812 // Hide wait cursor.
813 glass_pane.setVisible(false);
814 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
815 glass_pane.removeMouseListener(mouse_blocker_listener);
816 }
817 glass_pane = null;
818 }
819
820 public void workflowUpdate(String raw, boolean state) {
821 WorkflowUpdater task = new WorkflowUpdater(raw, state);
822 SwingUtilities.invokeLater(task);
823 task = null;
824 }
825
826 /** Retrieves a phrase from the Dictionary based on the key.
827 * @param key A <strong>String</strong> uniquely identifying a phrase from the Dictionary.
828 * @return The desired phrase as a <strong>String</strong>.
829 * @see org.greenstone.gatherer.Dictionary
830 */
831 private String get(String key) {
832 return get(key, null);
833 }
834 /** Retrieves a phrase from the Dictionary based on the key and including the arguments.
835 * @param key A <strong>String</strong> uniquely identifying a phrase from the Dictionary.
836 * @param args A <strong>String[]</strong> of arguments available to be inserted into the phrase.
837 * @return The desired phrase as a <strong>String</strong>.
838 * @see org.greenstone.gatherer.Dictionary
839 */
840 private String get(String key, String args[]) {
841 if(key.indexOf('.') == -1) {
842 key = "GUI." + key;
843 }
844 return Gatherer.dictionary.get(key, args);
845 }
846 /** Called to determine if we should wait for a thread to finish before continuing. We wait for threads if they are named: GSHELL_BUILD, GSHELL_IMPORT, or GSHELL_NEW.
847 * @return <i>true</i> if we should wait for a thread, <i>false</i> if it is safe to continue.
848 */
849 private boolean waitForThread() {
850 Thread active[] = new Thread[thread_group.activeCount()];
851 int size = thread_group.enumerate(active);
852 for(int i = 0; i < size; i++) {
853 if(active[i].getName().equals(GShell.GSHELL_BUILD) ||
854 active[i].getName().equals(GShell.GSHELL_IMPORT) ||
855 active[i].getName().equals(GShell.GSHELL_NEW)) {
856 return true;
857 }
858 }
859 return false;
860 }
861
862
863 /**Overridden from JFrame so we can exit safely when window is closed (or destroyed).
864 * @param event A <strong>WindowEvent</strong> containing information about the event that fred this call.
865 */
866 protected void processWindowEvent(WindowEvent event) {
867 if(event.getID() == WindowEvent.WINDOW_CLOSING) {
868 exit();
869 }
870 }
871 /** Listens to actions upon the menu bar, and if it detects a click over the help menu brings the help window to the front if it has become hidden.
872 */
873 private class MenuListenerImpl
874 implements MenuListener {
875 /** Called whenever a popup menu is hidden, but we don't care.
876 * @param e Some <strong>MenuEvent</strong> that we could care less about.
877 */
878 public void menuCanceled(MenuEvent e) {
879 }
880 /** Called whenever a menu header (ie button) becomes unselected, but we don't care.
881 * @param e Some <strong>MenuEvent</strong> that we could care less about.
882 */
883 public void menuDeselected(MenuEvent e) {
884 }
885 /** This method, when a menu is first opened, is the only one we respond to by bringing the help window to the front if possible, but only if there is a help window and the help menu is the one opening.
886 * @param e The <strong>MenuEvent</strong> whose source is checked.
887 */
888 public void menuSelected(MenuEvent e) {
889 if(e.getSource() == menu_bar.help) {
890 if(menu_bar.help.isSelected()) {
891 menu_bar.help.doClick(10);
892 }
893 }
894 }
895 }
896 private class TabUpdater
897 implements Runnable {
898 private boolean ready = false;
899 private int browse_pos = -1;
900 private int mirror_pos = -1;
901 private int config_pos = -1;
902 private int create_pos = -1;
903 private int export_pos = -1;
904 private int metaedit_pos = -1;
905 private int preview_pos = -1;
906 private JTabbedPane tab_pane = null;
907 public TabUpdater(JTabbedPane tab_pane, boolean ready) {
908 this.ready = ready;
909 this.tab_pane = tab_pane;
910 browse_pos = tab_pane.indexOfComponent(browser_pane);
911 mirror_pos = tab_pane.indexOfComponent(mirror_pane);
912 metaedit_pos = tab_pane.indexOfComponent(metaedit_pane);
913 config_pos = tab_pane.indexOfComponent(config_pane);
914 export_pos = tab_pane.indexOfComponent(export_pane);
915 create_pos = tab_pane.indexOfComponent(create_pane);
916 preview_pos = tab_pane.indexOfComponent(preview_pane);
917 }
918 public void run() {
919 if(browse_pos != -1) {
920 if(ready) {
921 tab_pane.setEnabledAt(browse_pos, Gatherer.config.get("workflow.browse", false));
922 }
923 else {
924 tab_pane.setEnabledAt(browse_pos, Gatherer.config.get("workflow.browse", true));
925 }
926 }
927 if(mirror_pos != -1) {
928 if(ready) {
929 tab_pane.setEnabledAt(mirror_pos, Gatherer.config.get("workflow.mirror", false));
930 }
931 else {
932 tab_pane.setEnabledAt(mirror_pos, Gatherer.config.get("workflow.mirror", true));
933 }
934 }
935 if(metaedit_pos != -1) {
936 tab_pane.setEnabledAt(metaedit_pos, ready && Gatherer.config.get("workflow.enrich", false));
937 }
938 if(config_pos != -1) {
939 tab_pane.setEnabledAt(config_pos, ready && Gatherer.config.get("workflow.design", false));
940 }
941 if(export_pos != -1) {
942 tab_pane.setEnabledAt(export_pos, ready && Gatherer.config.get("workflow.export", false));
943 }
944 if(create_pos != -1) {
945 tab_pane.setEnabledAt(create_pos, ready && Gatherer.config.get("workflow.create", false));
946 }
947 if(preview_pos != -1) {
948 tab_pane.setEnabledAt(preview_pos, Gatherer.c_man != null && Gatherer.c_man.built() && Gatherer.config.get("workflow.preview", false));
949 }
950 }
951 public void setReady(boolean ready) {
952 this.ready = ready;
953 }
954 }
955
956 private class WorkflowUpdater
957 implements Runnable {
958 private boolean state;
959 private String raw;
960 public WorkflowUpdater(String raw, boolean state) {
961 this.raw = raw;
962 this.state = state;
963 }
964 public void run() {
965 setTabEnabled(raw, state);
966 }
967 }
968}
Note: See TracBrowser for help on using the repository browser.