- Timestamp:
- 2006-07-07T13:15:50+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java
r11491 r12093 34 34 import javax.swing.filechooser.*; 35 35 import javax.swing.event.*; 36 import javax.swing.tree.*;37 36 import org.greenstone.gatherer.Configuration; 38 37 import org.greenstone.gatherer.DebugStream; … … 42 41 import org.greenstone.gatherer.gui.EmailField; 43 42 import org.greenstone.gatherer.gui.GLIButton; 44 import org.greenstone.gatherer.gui.NewCollectionDetailsPrompt; 45 import org.greenstone.gatherer.gui.OpenCollectionDialog; 46 import org.greenstone.gatherer.gui.WarningDialog; 43 import org.greenstone.gatherer.gui.GUIUtils; 47 44 import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 48 45 import org.greenstone.gatherer.util.StaticStrings; 49 46 50 /** This class is responsible for generating the necessary GUI components. It does this by calling the getEditControls() method of the appropriate class (i.e. IndexManager for index related edits). It also is in charge of correctly adding (and removing) listeners, using phrases from the <strong>Dictionary</strong> rather than the text keys inserted in the component classes, and several other aspects of the design page, including the config file section tree. 51 * @author John Thompson, Greenstone Digital Library, University of Waikato 52 * @version 2.3d 47 /** This class provides a graphical interface for editing general metadata for the collection, such as name, description, icons etc. 53 48 */ 54 public class GeneralManager 55 extends JPanel { 56 /** The available subscreens. */ 57 static final private String CONTENTS[] = { "CDM.GUI.General", "CDM.GUI.Plugins", "CDM.GUI.SearchTypes", "CDM.GUI.Indexes", "CDM.GUI.Subcollections", "CDM.GUI.SuperCollection", "CDM.GUI.Classifiers", "CDM.GUI.Formats", "CDM.GUI.Translation", "CDM.GUI.MetadataSets" }; 58 /** The preferred size of the contents tree. */ 59 static final private Dimension TREE_SIZE = new Dimension(200, 500); 49 public class GeneralManager { 50 60 51 /** The controls used to modify the general options. */ 61 52 private Control controls; 62 /** The panel apon which is rendered the currently selected section screen. */63 private Control view = null;64 /** A tree to serve as a 'table of contents' for this design tool. We decided on a tree rather than a list, as it allows us to break sections into subsections if they become to complicated. */65 private DesignTree tree;66 53 /** Constructor. */ 67 54 public GeneralManager() { 68 super();69 DebugStream.println("GeneralManager: Main GUI components created.");70 // Assignments71 this.controls = new GeneralControl();72 73 // Creation74 JPanel tree_pane = new JPanel();75 //JLabel title = new JLabel();76 //Dictionary.registerText(title, "CDM.GUI.Design_Topics");77 tree = new DesignTree();78 view = controls;79 80 // Connect81 tree.addTreeSelectionListener(new TreeListener());82 83 // Layout84 tree_pane.setLayout(new BorderLayout());85 tree_pane.setPreferredSize(TREE_SIZE);86 //tree_pane.add(title, BorderLayout.NORTH);87 tree_pane.add(new JScrollPane(tree), BorderLayout.CENTER);88 89 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));90 setLayout(new BorderLayout());91 add(tree_pane, BorderLayout.WEST);92 add((JPanel)view, BorderLayout.CENTER);93 }94 95 public boolean canSave() {96 return (controls == null || ((GeneralControl)controls).canSave());97 55 } 98 56 99 57 /** Destructor. */ 100 58 public void destroy() { 101 controls.destroy(); 102 controls = null; 103 tree = null; 104 view = null; 105 } 106 107 /** Called whenever the detail mode changes to ensure the contents tree is at an appropriate level (ie with Partitions disabled in lower levels) 108 * Written 1543-07-01-2004, and made obsolete by a new list of requirements 1611-07-01-2004. *sigh* 109 * @param mode the mode level as an int 110 */ 111 /* public void modeChanged(int mode) { 112 tree.resetModel(mode); 113 } */ 114 115 /** Force the display to show a certain pane of controls. 116 * @param type a String giving the name of the information manager or view we wish to display 117 */ 118 public void setSelectedView(String type) { 119 tree.setSelectedView(type); 120 } 121 122 /** Refresh the values on our controls that could be stale due to changes in other components. */ 59 if (controls != null) { 60 controls.destroy(); 61 controls = null; 62 } 63 } 64 65 public void loseFocus() { 66 } 67 123 68 public void gainFocus() { 124 if (view != null) { 125 view.gainFocus(); 126 } 127 } 128 129 /** Saves the state of the controls in the current view. */ 130 public void loseFocus() { 131 if (view != null) { 132 view.loseFocus(); 133 } 134 } 135 69 70 } 136 71 /** This class is resposible for generating the controls for the editing of general options. 137 72 * @return the Control for editing the general options 138 73 */ 139 private Control getControls() { 74 public Control getControls() { 75 if (controls == null) { 76 controls = new GeneralControl(); 77 } 140 78 return controls; 141 79 } 142 80 81 82 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden 83 * @param mode the new mode as an int 84 */ 85 public void modeChanged(int mode) { 86 87 } 88 143 89 /** This class represents the visual component of the general options stored in the CollectionDesignManager. */ 144 90 private class GeneralControl … … 146 92 implements Control { 147 93 148 private boolean has_been_warned = false;94 //private boolean has_been_warned = false; 149 95 private boolean ready = false; 150 96 private CollectionMeta collection_extra_collectionmeta; … … 360 306 } 361 307 362 public boolean canSave() {363 boolean title_clash_warning = true;364 // Oh, and if the collection title is already in use warn them about it365 String title = name_textfield.getText();366 // I just happen to have a handy method in the new details prompt to detect this very thing367 if(NewCollectionDetailsPrompt.titleClashes(title, CollectionDesignManager.collect_config.getFile())) {368 // Determine if the user wants to be warned about this369 WarningDialog dialog = new WarningDialog("warning.TitleClashes", "TitleClashes.Title", Dictionary.get("TitleClashes.Message"), null, true);370 if(dialog.display() == JOptionPane.OK_OPTION) {371 // If they have said yes, then carry on with the assignement372 collection_name_collectionmeta.setValue(title);373 has_been_warned = true;374 }375 // Otherwise we don't assign anything. In fact we have to restore the frame title back to its original value376 else {377 title_clash_warning = false;378 String collection_title = collection_name_collectionmeta.getValue(CollectionMeta.TEXT);379 String collection_name = Gatherer.c_man.getCollection().getName();380 Gatherer.g_man.setTitle(collection_title, collection_name);381 collection_name = null;382 collection_title = null;383 }384 dialog.dispose();385 dialog = null;386 }387 // No clash, no worries.388 else if(collection_name_collectionmeta != null) {389 collection_name_collectionmeta.setValue(title);390 }391 return title_clash_warning;392 }393 394 308 /** Called to store the current value of the components. */ 395 309 public void loseFocus() { … … 408 322 maintainer_collectionmeta.setValue(maintainer_emailfield.getText()); 409 323 icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText()); 410 411 // Oh, and if the collection title is already in use warn them about it 412 String title = name_textfield.getText(); 413 // I just happen to have a handy method in the new details prompt to detect this very thing 414 if(!has_been_warned && NewCollectionDetailsPrompt.titleClashes(title, CollectionDesignManager.collect_config.getFile())) { 415 // Determine if the user wants to be warned about this 416 WarningDialog dialog = new WarningDialog("warning.TitleClashes", "TitleClashes.Title", Dictionary.get("TitleClashes.Message"), null, true); 417 if(dialog.display() == JOptionPane.OK_OPTION) { 418 // If they have said yes, then carry on with the assignement 419 collection_name_collectionmeta.setValue(title); 420 } 421 // Otherwise we don't assign anything. In fact we have to restore the frame title back to its original value 422 else { 423 String collection_title = collection_name_collectionmeta.getValue(CollectionMeta.TEXT); 424 String collection_name = Gatherer.c_man.getCollection().getName(); 425 Gatherer.g_man.setTitle(collection_title, collection_name); 426 collection_name = null; 427 collection_title = null; 428 } 429 dialog.dispose(); 430 dialog = null; 431 } 432 // No clash, no worries. 433 else { 434 collection_name_collectionmeta.setValue(title); 435 } 436 title = null; 437 324 collection_name_collectionmeta.setValue(name_textfield.getText()); 438 325 ready = false; 439 has_been_warned = false;440 326 } 441 327 … … 464 350 file_chooser.setFileFilter(new ImageFilter()); 465 351 file_chooser.setSize(400,300); 466 OpenCollectionDialog.disableRename(file_chooser);352 GUIUtils.disableRename(file_chooser); 467 353 int value = file_chooser.showOpenDialog(Gatherer.g_man); 468 354 // If the user hasn't cancelled, retrieve the file path selected … … 552 438 } 553 439 } 554 555 /** This tree provides a 'table of contents' for the various components of the design process (collection configuration in more technical terms). */556 private class DesignTree557 extends JTree {558 private DesignNode root = null;559 /** Constructor. Automatically generates all of the nodes, in the order of CONTENTS. */560 public DesignTree() {561 super();562 resetModel(Configuration.getMode());563 expandRow(0);564 setRootVisible(false);565 setSelectionRow(0);566 }567 568 /** Reset the model used by the design page contents tree. This is necessary to hide the partitions entry when in lower detail modes569 * @param mode the current detail mode as an int570 */571 public void resetModel(int mode) {572 root = new DesignNode("CDM.GUI.Root");573 // Now add the design categories.574 for(int i = 0; i < CONTENTS.length; i++) {575 root.add(new DesignNode(CONTENTS[i]));576 }577 this.setModel(new DefaultTreeModel(root));578 updateUI();579 }580 /** Set the current view to the one specified.581 * @param type the name of the desired view as a String582 */583 public void setSelectedView(String type) {584 type = Dictionary.get(type);585 for(int i = 0; i < root.getChildCount(); i++) {586 DesignNode child = (DesignNode) root.getChildAt(i);587 if(child.toString().equals(type)) {588 TreePath path = new TreePath(child.getPath());589 setSelectionPath(path);590 }591 }592 }593 }594 /** A tree node that retains a reference to one of the possible design sub-views relating to the different sub-managers. */595 private class DesignNode596 extends DefaultMutableTreeNode {597 /** Constructor.598 * @param object The <strong>Object</strong> assigned to this node.599 */600 public DesignNode(String object) {601 super(object);602 }603 /** Retrieve a textual representation of the object.604 * @return a String605 */606 public String toString() {607 // return Dictionary.get("CDM.GUI." + (String)getUserObject());608 return Dictionary.get((String) getUserObject());609 }610 }611 /** Listens for selection changes in the 'contents' tree, and switches to the appropriate view. */612 private class TreeListener613 implements TreeSelectionListener {614 /** Called whenever the selection changes, we must update the view so it matches the node selected.615 * @param event A <strong>TreeSelectionEvent</strong> containing more information about the tree selection.616 * @see org.greenstone.gatherer.cdm.ClassifierManager617 * @see org.greenstone.gatherer.cdm.CollectionDesignManager618 * @see org.greenstone.gatherer.cdm.CollectionMetaManager619 * @see org.greenstone.gatherer.cdm.FormatManager620 * @see org.greenstone.gatherer.cdm.LanguageManager621 * @see org.greenstone.gatherer.cdm.MetadataSetView622 * @see org.greenstone.gatherer.cdm.SubcollectionManager623 * @see org.greenstone.gatherer.cdm.TranslationView624 * @see org.greenstone.gatherer.cdm.PluginManager625 */626 public void valueChanged(TreeSelectionEvent event) {627 if(!tree.isSelectionEmpty()) {628 TreePath path = tree.getSelectionPath();629 DesignNode node = (DesignNode)path.getLastPathComponent();630 String type = (String)node.getUserObject();631 // Wait begins632 Gatherer.g_man.wait(true);633 // Save information in current view634 view.loseFocus();635 remove((JPanel)view);636 // Change panes.637 if(type == CONTENTS[0]) {638 view = getControls();639 }640 else if(type == CONTENTS[1]) {641 view = CollectionDesignManager.plugin_manager.getControls();642 }643 else if(type == CONTENTS[2]) {644 view = CollectionDesignManager.searchtype_manager.getControls();645 }646 else if(type == CONTENTS[3]) {647 view = CollectionDesignManager.index_manager.getControls();648 }649 else if(type == CONTENTS[4]) {650 view = CollectionDesignManager.subcollection_manager.getControls();651 }652 else if(type == CONTENTS[5]) {653 view = CollectionDesignManager.supercollection_manager.getControls();654 }655 else if(type == CONTENTS[6]) {656 view = CollectionDesignManager.classifier_manager.getControls();657 }658 else if(type == CONTENTS[7]) {659 view = CollectionDesignManager.format_manager.getControls();660 }661 else if(type == CONTENTS[8]) {662 view = CollectionDesignManager.translation_view.getControls();663 }664 else if(type == CONTENTS[9]) {665 view = CollectionDesignManager.metadataset_view.getControls();666 }667 add((JPanel)view, BorderLayout.CENTER);668 // Update information on visible pane669 view.gainFocus();670 repaint();671 // Wait ends672 Gatherer.g_man.wait(false);673 }674 }675 }676 440 }
Note:
See TracChangeset
for help on using the changeset viewer.