Changeset 8381


Ignore:
Timestamp:
2004-10-20T10:46:09+13:00 (20 years ago)
Author:
kjdon
Message:

major mods to the mg index controls. added a replace button, enabled selections on the index list and source list at teh same time, and fixed up some other stuff to do with current selections

File:
1 edited

Legend:

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

    r8313 r8381  
    5353
    5454    static final private Dimension FIELD_SIZE = new Dimension(200,30);
     55    static final private Dimension BUTTON_SIZE = new Dimension(100,30);
    5556    static final private String MGINDEXES = "mg indexes";
    5657    static final private String MGPPINDEXES = "mgpp indexes";
     
    9495        Index last_index = (Index)getElementAt(getSize() - 1);
    9596        addAfter(index, last_index);
     97       
    9698        }
    9799        else {
     
    496498    private JButton move_up_button;
    497499    private JButton remove_button;
     500    private JButton replace_button;
    498501    private JButton set_default_button;
    499502    private JComboBox level_combobox;
     
    546549        index_list = new JList(model);
    547550        index_list.setCellRenderer(new IndexListRenderer());
    548 
     551        index_list.setVisibleRowCount(5);
    549552        JPanel movement_pane = new JPanel();
    550553
     
    599602        remove_button.setMnemonic(KeyEvent.VK_R);
    600603        Dictionary.registerBoth(remove_button, "CDM.IndexManager.Remove_Index", "CDM.IndexManager.Remove_Index_Tooltip");
     604        replace_button = new GLIButton();
     605        replace_button.setEnabled(false);
     606        replace_button.setMnemonic(KeyEvent.VK_P);
     607        Dictionary.registerBoth(replace_button, "CDM.IndexManager.MGPP.Replace_Index", "CDM.IndexManager.MGPP.Replace_Index_Tooltip");
    601608
    602609        // This class is getting a little crowded, so I'll generate the many mgpp controls in a inner class.
     
    608615        move_up_button.addActionListener(new MoveListener(true));
    609616        remove_button.addActionListener(new RemoveListener());
     617        replace_button.addActionListener(new ReplaceListener());
    610618        set_default_button.addActionListener(new SetDefaultListener());
    611619        name_textfield.getDocument().addDocumentListener(new NameListener());
     620        level_combobox.addItemListener(new LevelListener());
    612621        index_list.addListSelectionListener(new IndexListListener());
    613622        source_list.addListSelectionListener(new SourceListListener());
    614         ExclusiveListSelectionListener elsl = new ExclusiveListSelectionListener();
    615         elsl.add(index_list);
    616         elsl.add(source_list);
    617         elsl = null; // We don't want to hold a reference to this
    618623
    619624        // Layout
     
    624629
    625630        movement_pane.setBorder(BorderFactory.createEmptyBorder(0,2,0,0));
    626         movement_pane.setLayout(new GridLayout(2,1));
     631        movement_pane.setLayout(new GridLayout(3,1));
    627632        movement_pane.add(move_up_button);
    628633        movement_pane.add(move_down_button);
     634        movement_pane.add(set_default_button);
    629635
    630636        assigned_indexes_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     
    651657        button_pane.setLayout(new GridLayout(1,3));
    652658        button_pane.add(add_button);
    653         button_pane.add(set_default_button);
     659        button_pane.add(replace_button);
    654660        button_pane.add(remove_button);
    655661
     
    692698        source_list.setListData(new_data.toArray());
    693699        new_data = null;
     700        // refresh the indexList
     701        index_list.updateUI();
     702        // if there is one selected, fill in the controls
     703        updateControlsWithSelectedIndex();
    694704        }
    695705        // Bring the appropriate card to the front
     
    705715    }
    706716
     717    private void updateControlsWithSelectedIndex() {
     718       
     719        Index selected_index = (Index)index_list.getSelectedValue();
     720        if (selected_index == null) {
     721        return;
     722        }
     723        String id = selected_index.getID();
     724        if (id == null || id.equals("")) {
     725        return;
     726        }
     727        String name = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER+selected_index.getID()).getValue(true);
     728        name_textfield.setText(name);
     729        level_combobox.setSelectedIndex(selected_index.getLevel());
     730        source_list.clearSelection();
     731        ArrayList sources = selected_index.getSources();
     732        source_list.setSelectedObjects(sources.toArray());
     733       
     734    }
     735   
    707736    private void validateAddButton() {
    708737        boolean add_enabled = false;
     738        boolean replace_enabled = false;
    709739        // Indexes must have a name
    710740        if(name_textfield.getText().length() == 0) {
     
    727757        if(model.contains(index)) {
    728758            add_enabled = false;
     759            // here we need to check if we have changed the name - if so, we can enable the replace button
     760            if (index_list.getSelectedIndex() != -1) {
     761            Index selected_index = (Index)index_list.getSelectedValue();
     762            String name = name_textfield.getText();
     763            String index_name = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER+selected_index.getID()).getValue(true);
     764            if (!index_name.equals(name)){
     765                replace_enabled = true;
     766            }
     767            }
    729768        }
    730769        else {
    731770            add_enabled = true;
     771            // we have a new index, do we have something selected in the index list? if so, enable the replace button
     772            if (index_list.getSelectedIndex() != -1) {
     773            replace_enabled = true;
     774            }
     775           
    732776        }
    733777        }
    734778        // We should now know the add_button state
    735779        add_button.setEnabled(add_enabled);
     780        replace_button.setEnabled(replace_enabled);
    736781    }
    737782
     
    759804            // Finally add index.
    760805            addIndex(index, metadatum);
     806            index_list.setSelectedValue(index, true);
    761807            metadatum = null;
    762808            index = null;
     
    769815    private class IndexListListener
    770816        implements ListSelectionListener {
    771         /** This method is called whenever the source list selection changes. When it does we need to check if the add button should now be enabled.
     817        /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel
    772818         * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
    773819         */
     
    779825
    780826        Object value = index_list.getSelectedValue();
    781         move_down_button.setEnabled(value != null);
    782         move_up_button.setEnabled(value != null);
    783         remove_button.setEnabled(value != null);
    784         set_default_button.setEnabled(value != null && (default_index == null || !default_index.equals(value)));
     827        if (value == null) {
     828            move_down_button.setEnabled(false);
     829            move_up_button.setEnabled(false);
     830            remove_button.setEnabled(false);
     831            replace_button.setEnabled(false);
     832            set_default_button.setEnabled(false);
     833            return;
     834        }
     835        // enable the buttons appropriately
     836        remove_button.setEnabled(true);
     837        set_default_button.setEnabled(default_index == null || !default_index.equals(value));
     838        int i = index_list.getSelectedIndex();
     839        int size = index_list.getModel().getSize();
     840        if (i > 0) {
     841            move_up_button.setEnabled(true);
     842        } else {
     843            move_up_button.setEnabled(false);
     844        }
     845        if (i<size-1){
     846            move_down_button.setEnabled(true);
     847        } else {
     848            move_down_button.setEnabled(false);
     849        }
     850
     851        // need to fill in the rest of the bits
     852        updateControlsWithSelectedIndex();     
    785853        }
    786854    }
     
    798866        }
    799867
     868    }
     869
     870    private class LevelListener
     871        implements ItemListener {
     872        public void itemStateChanged(ItemEvent event) {
     873        if(event.getStateChange() == ItemEvent.SELECTED) {
     874            // just want to validate the add button
     875            validateAddButton();
     876
     877        }
     878        }
    800879    }
    801880
     
    829908         */
    830909        public void actionPerformed(ActionEvent event) {
    831         if(!index_list.isSelectionEmpty()) {
     910        int i = index_list.getSelectedIndex();
     911        if(i != -1) {
    832912            removeIndex((Index)index_list.getSelectedValue());
    833913        }
    834         move_down_button.setEnabled(false);
    835         move_up_button.setEnabled(false);
    836         remove_button.setEnabled(false);
     914        int size = index_list.getModel().getSize();
     915        if (i == size) {
     916            i--;
     917        }
     918       
     919        index_list.setSelectedIndex(i);
     920        // this will produce an event on the list, updating the other buttons
     921        if (size == 0) {
     922            // we have removed the last index, should be able to add whats filled in currently, if valid
     923            validateAddButton();
     924        }       
     925        }
     926    }
     927
     928    /** Listens for actions apon the 'remove' button in the IndexManager controls, and if detected calls the remove method of the manager with the index selected for removal. */
     929    private class ReplaceListener
     930        implements ActionListener {
     931        /** If called when an action occurs on a registered component, we replace the currently selected index, with the new details
     932         * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
     933         * @see org.greenstone.gatherer.cdm.Index
     934         */
     935        public void actionPerformed(ActionEvent event) {
     936        if(index_list.isSelectionEmpty()) {
     937            // this should never happen, but just in case..
     938            replace_button.setEnabled(false);
     939            return;
     940        }
     941        // we'll just remove the old one and add the new one
     942        removeIndex((Index)index_list.getSelectedValue());
     943        replace_button.setEnabled(false);
     944        add_button.setEnabled(true);
     945        add_button.doClick();
     946        add_button.setEnabled(false);
    837947        }
    838948    }
     
    12191329        level = null;
    12201330        }
     1331
     1332        // refresh
     1333        current_indexes_list.updateUI();
    12211334    }
    12221335
     
    13551468         */
    13561469        public void actionPerformed(ActionEvent event) {
    1357         validateAddButton();
     1470        validateAddButtonIndex();
    13581471        }
    13591472
     
    13621475         */
    13631476        public void changedUpdate(DocumentEvent event) {
    1364         validateAddButton();
     1477        validateAddButtonIndex();
    13651478        }
    13661479
     
    13691482         */
    13701483        public void insertUpdate(DocumentEvent event) {
    1371         validateAddButton();
     1484        validateAddButtonIndex();
    13721485        }
    13731486
     
    13761489         */
    13771490        public void removeUpdate(DocumentEvent event) {
    1378         validateAddButton();
     1491        validateAddButtonIndex();
    13791492        }
    13801493
    13811494        /** Change the enable state of the add button depending on the current value in the search type combobox. */
    1382         public void validateAddButton() {
     1495        public void validateAddButtonIndex() {
    13831496        String name = index_name_field.getText();
    13841497        Object selected_object = index_combobox.getSelectedItem();
     
    14171530         */
    14181531        public void actionPerformed(ActionEvent event) {
    1419         validateAddButton();
     1532        validateAddButtonLevel();
    14201533        }
    14211534
     
    14241537         */
    14251538        public void changedUpdate(DocumentEvent event) {
    1426         validateAddButton();
     1539        validateAddButtonLevel();
    14271540        }
    14281541
     
    14311544         */
    14321545        public void insertUpdate(DocumentEvent event) {
    1433         validateAddButton();
     1546        validateAddButtonLevel();
    14341547        }
    14351548
     
    14381551         */
    14391552        public void removeUpdate(DocumentEvent event) {
    1440         validateAddButton();
    1441         }
    1442 
     1553        validateAddButtonLevel();
     1554        }
     1555   
    14431556        /** Change the enable state of the add button depending on the current value in the search type combobox. */
    1444         public void validateAddButton() {
     1557        public void validateAddButtonLevel() {
    14451558        String name = level_name_field.getText();
    14461559        Object selected_object = level_combobox.getSelectedItem();
     
    15461659        remove_index_button.setEnabled(false);
    15471660        // Check if add should be reenabled
    1548         eal.validateAddButton();
     1661        eal.validateAddButtonIndex();
    15491662        }
    15501663    }
     
    15841697        }
    15851698        // Check if add should be reenabled
    1586         eal.validateAddButton();
    1587         }
    1588     }
    1589     }
     1699        eal.validateAddButtonLevel();
     1700        }
     1701    }
     1702    } // MGPPControls
     1703
    15901704}
Note: See TracChangeset for help on using the changeset viewer.