Changeset 6152


Ignore:
Timestamp:
2003-12-08T14:29:18+13:00 (20 years ago)
Author:
jmt12
Message:

Not only is a title clash now detected (albeit when you shift focus off the general settings screen) but the frame title now updates properly, and the shorter collection filename is shown - in a noneditable fashion of course

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/GeneralManager.java

    r6088 r6152  
    4242import org.greenstone.gatherer.cdm.Control;
    4343import org.greenstone.gatherer.gui.EmailField;
     44import org.greenstone.gatherer.gui.NewCollectionDetailsPrompt;
    4445import org.greenstone.gatherer.gui.OpenCollectionDialog;
     46import org.greenstone.gatherer.gui.WarningDialog;
    4547import org.greenstone.gatherer.util.StaticStrings;
    4648import org.greenstone.gatherer.util.Utility;
     
    220222        name_textfield = new JTextField("CDM.General.Collection_Name");
    221223        Dictionary.registerTooltip(name_textfield, "CDM.General.Collection_Name_Tooltip");
     224        JPanel short_name_panel = new JPanel();
     225        JLabel short_name_label = new JLabel();
     226        short_name_label.setPreferredSize(LABEL_SIZE);
     227        Dictionary.registerText(short_name_label, "NewCollectionPrompt.Collection_Name");
     228        JTextField short_name_textfield = new JTextField(Gatherer.c_man.getCollection().getName());
     229        short_name_textfield.setEditable(false);
     230        short_name_textfield.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
    222231        JPanel icon_panel = new JPanel();
    223232        icon_label = new JLabel();
     
    245254        // Connection
    246255        beta_checkbox.addActionListener(CollectionDesignManager.change_listener);
    247         browse_about_icon_button.addActionListener(new BrowseListener(StaticStrings.IMAGES_PATH_RELATIVE_TO_COLLECTION_PREFIX));
    248         browse_home_icon_button.addActionListener(new BrowseListener(StaticStrings.IMAGES_PATH_RELATIVE_TO_GSDL_PREFIX));
     256        BrowseListener browse_listener = new BrowseListener(StaticStrings.IMAGES_PATH_RELATIVE_TO_GSDL_PREFIX);
     257        browse_about_icon_button.addActionListener(browse_listener);
     258        browse_home_icon_button.addActionListener(browse_listener);
     259        browse_listener = null;
    249260        public_checkbox.addActionListener(CollectionDesignManager.change_listener);
    250261        creator_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
     
    253264        maintainer_emailfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
    254265        name_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
     266        name_textfield.getDocument().addDocumentListener(new CollectionTitleUpdater());
    255267        small_icon_textfield.getDocument().addDocumentListener(CollectionDesignManager.change_listener);
    256268
     
    273285        name_panel.add(name_textfield, BorderLayout.CENTER);
    274286
     287        short_name_panel.setLayout(new BorderLayout());
     288        short_name_panel.add(short_name_label, BorderLayout.WEST);
     289        short_name_panel.add(short_name_textfield, BorderLayout.CENTER);
     290
    275291        icon_panel.setLayout(new BorderLayout());
    276292        icon_panel.add(icon_label, BorderLayout.WEST);
     
    283299        small_icon_panel.add(browse_home_icon_button, BorderLayout.EAST);
    284300
    285         details_panel.setLayout(new GridLayout(7,1,5,0));
     301        details_panel.setLayout(new GridLayout(8,1,5,2));
    286302        details_panel.add(creator_panel);
    287303        details_panel.add(maintainer_panel);
     
    289305        details_panel.add(beta_checkbox);
    290306        details_panel.add(name_panel);
     307        details_panel.add(short_name_panel);
    291308        details_panel.add(icon_panel);
    292309        details_panel.add(small_icon_panel);
     
    350367        icon_collection_collectionmeta.setValue(icon_textfield.getText());
    351368        maintainer_collectionmeta.setValue(maintainer_emailfield.getText());
    352         collection_name_collectionmeta.setValue(name_textfield.getText());
    353369        icon_collection_small_collectionmeta.setValue(small_icon_textfield.getText());
     370
     371        // Oh, and if the collection title is already in use warn them about it
     372        String title = name_textfield.getText();
     373        // I just happen to have a handy method in the new details prompt to detect this very thing
     374        if(NewCollectionDetailsPrompt.titleClashes(title)) {
     375            // Determine if the user wants to be warned about this
     376            WarningDialog dialog = new WarningDialog("warning.TitleClashes", true);
     377            if(dialog.display() == JOptionPane.OK_OPTION) {
     378            // If they have said yes, then carry on with the assignement
     379            collection_name_collectionmeta.setValue(title);
     380            }
     381            // Otherwise we don't assign anything. In fact we have to restore the frame title back to its original value
     382            else {
     383            String collection_title = collection_name_collectionmeta.getValue(CollectionMeta.TEXT);
     384            String collection_name = Gatherer.c_man.getCollection().getName();
     385            Gatherer.g_man.setTitle(collection_title, collection_name);
     386            collection_name = null;
     387            collection_title = null;
     388            }
     389            dialog.dispose();
     390            dialog = null;
     391        }
     392        // No clash, no worries.
     393        else {
     394            collection_name_collectionmeta.setValue(title);
     395        }
     396        title = null;
     397
    354398        ready = false;
    355         }
     399        } 
    356400    }
    357401
     
    362406        private String prefix;
    363407
    364         public BrowseListener(String prefix) {
    365         this.prefix = prefix;
     408        public BrowseListener(String prefix_raw) {
     409        this.prefix = prefix_raw.replaceAll(StaticStrings.COLNAME_PATTERN, Gatherer.c_man.getCollection().getName());
    366410        }
    367411
     
    438482        }
    439483    }
     484
     485    private class CollectionTitleUpdater
     486        implements DocumentListener {
     487        /** Gives notification that an attribute or set of attributes changed. */
     488        public void changedUpdate(DocumentEvent e) {
     489        setTitle();
     490        }
     491        /** Gives notification that there was an insert into the document. */
     492        public void insertUpdate(DocumentEvent e) {
     493        setTitle();
     494        }
     495        /** Gives notification that a portion of the document has been removed. */
     496        public void removeUpdate(DocumentEvent e) {
     497        setTitle();
     498        }
     499       
     500        private void setTitle() {
     501        // Set the title
     502        String collection_title = name_textfield.getText();
     503        String collection_name = Gatherer.c_man.getCollection().getName();
     504        Gatherer.g_man.setTitle(collection_title, collection_name);
     505        collection_title = null;
     506        collection_name = null;
     507        }
     508    }
    440509    }
    441510
Note: See TracChangeset for help on using the changeset viewer.