Changeset 5159


Ignore:
Timestamp:
2003-08-18T14:04:16+12:00 (21 years ago)
Author:
jmt12
Message:

Fix 203B012

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
6 edited

Legend:

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

    r5037 r5159  
    7676        Object source_object = sources.get(i);
    7777        if(source_object instanceof ElementWrapper) {
    78         System.err.println("Found ElementWrapper as source: " + ((ElementWrapper)source_object).getName());
     78        ///Gatherer.println("Found ElementWrapper as source: " + ((ElementWrapper)source_object).getName());
    7979        content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, ((ElementWrapper)source_object).getName());
    8080        }
    8181        else {
    82         System.err.println("Found String as source: " + source_object.toString());
     82        ///Gatherer.println("Found String as source: " + source_object.toString());
    8383        content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, source_object.toString());
    8484        }
     
    152152
    153153    public String getID() {
    154     if(id == null) {
     154    if(element == null) {
     155        id="";
     156    }
     157    else if(id == null) {
    155158        StringBuffer id_buffer = new StringBuffer();
    156159        // Write level information, if any.
     
    169172            String full_element_name = ((ElementWrapper)source_object).getName();
    170173            if(full_element_name.startsWith(Utility.EXTRACTED_METADATA_NAMESPACE)) {
    171                id_buffer.append(full_element_name.substring(Utility.EXTRACTED_METADATA_NAMESPACE.length()));
     174               id_buffer.append(full_element_name.substring(Utility.EXTRACTED_METADATA_NAMESPACE.length() + 1));
    172175            }
    173176            else {
     
    197200        Element content_element = (Element) content_elements.item(i);
    198201        String source_str = (String) content_element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
    199         if(source_str.indexOf(MSMUtils.NS_SEP) != -1) {
    200             ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(source_str);
    201             if(element_wrapper != null) {
    202             sources.add(element_wrapper);
    203             }
    204             else {
    205             sources.add(source_str);
    206             }
     202        ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(source_str);
     203        if(element_wrapper != null) {
     204            sources.add(element_wrapper);
    207205        }
    208206        else {
     
    237235     */
    238236    public void setLevel(int new_level) {
     237    System.err.println("SetLevel(" + new_level + ")");
    239238    if(element != null && element.getNodeName().equals(CollectionConfiguration.INDEX_DEFAULT_ELEMENT)) {
    240239        element.setAttribute(CollectionConfiguration.LEVEL_ATTRIBUTE, LEVEL[new_level]);
     
    258257        for(int i = 0; i < size; i++) {
    259258        Element content_element = element.getOwnerDocument().createElement(CollectionConfiguration.CONTENT_ELEMENT);
    260         content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, (String) sources.get(i));
     259        Object source_object = sources.get(i);
     260        if(source_object instanceof ElementWrapper) {
     261            //Gatherer.println("Found ElementWrapper as source: " + ((ElementWrapper)source_object).getName());
     262            String name = ((ElementWrapper)source_object).getName();
     263            content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
     264            name = null;
     265        }
     266        else {
     267            //Gatherer.println("Found String as source: " + source_object.toString());
     268            content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, source_object.toString());
     269        }
     270        source_object = null;
    261271        element.appendChild(content_element);
    262272        content_element = null;
     
    287297    for(int i = 0; i < sources_size; i++) {
    288298        String source_name = (sources.get(i)).toString();
    289         // Sometimes I wish they'd asked me to give extracted metadata a namespace, way back before I programmed so much of GLI to expect "" for extracted metadata, any namespace for normal metadata. That way I could just say 'ex' and be done with it, not add all of these special tests whenever it may come to displaying an extracted element.
    290         if(source_name.indexOf(MSMUtils.NS_SEP) == -1 && !source_name.equals(CollectionConfiguration.TEXT_STR) && !source_name.equals(CollectionConfiguration.ALLFIELDS_STR)) {
    291         text_buffer.append(Utility.EXTRACTED_METADATA_NAMESPACE);
    292         text_buffer.append(MSMUtils.NS_SEP);
    293         }
    294299        text_buffer.append(source_name);
    295300        if(i < sources_size - 1) {
  • trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java

    r5090 r5159  
    3737import org.greenstone.gatherer.cdm.DOMProxyListModel;
    3838import org.greenstone.gatherer.cdm.Index;
     39import org.greenstone.gatherer.checklist.CheckList;
     40import org.greenstone.gatherer.gui.DoubleImageButton;
    3941import org.greenstone.gatherer.gui.GComboBox;
    4042import org.greenstone.gatherer.msm.ElementWrapper;
     
    9496        else {
    9597        add(index);
     98        // Also set this index as the default one, but only if there are levels available (ie mg only)
     99        if(index.getLevel() != -1) {
     100            setDefault(index);
     101        }
    96102        }
    97103        Gatherer.c_man.configurationChanged();
     
    266272        // Check if the index removed happens to be the default index
    267273        if(default_index != null && default_index.equals(index)) {
    268         default_index.setAssigned(false);
     274        // If so our first solution is to set the first index to be default
     275        if(getSize() > 0) {
     276            Index another_index = (Index) getElementAt(0);
     277            setDefault(another_index);
     278            another_index = null;
     279        }
     280        else {
     281            default_index.setAssigned(false);
     282        }
    269283        }
    270284        // Remove the index
     
    496510
    497511    private CardLayout card_layout;
    498 
    499     /** The default size of a label on this control. */
    500     private Dimension LABEL_SIZE = new Dimension(125,25);
    501     /** The button used to add a new index. */
    502     private JButton add = null;
    503     /** The button used to clear the default index. */
    504     private JButton clear_default = null;
    505     /** The button used to remove an index. */
    506     private JButton remove = null;
    507     /** The button used to set the default index. */
    508     private JButton set_default = null;
    509     /** The combobox used to adjust what level the new index will built on. */
    510     private JComboBox level = null;
    511     /** The label denoting the default index to be built for this collection. */
    512     private JLabel default_label = null;
    513     /** The label denoting the list of assigned indexes. */
    514     private JLabel index_label = null;
    515     /** The label denoting the control for choosing index level. */
    516     private JLabel level_label = null;
    517     /** The label denoting the name of the index. */
    518     private JLabel name_label = null;
    519     /** The label denoting the list of possible sources for the index. */
    520     private JLabel source_label = null;
    521     /** The title shown at the top of the index controls. */
    522     private JLabel title = null;
    523     /** The list of assigned indexes. */
    524     private JList index_list = null;
    525     /** The list of possible sources on which the index could be built. */
    526     private JList source_list = null;
    527     /** The panel used to display the list of assigned indexes. */
    528     private JPanel assigned_pane = null;
    529     /** The panel which contains the buttons used to edit indexes. */
    530     private JPanel button_pane = null;
    531     /** The panel on which all other panels are displayed. */
    532     private JPanel central_pane = null;
    533     /** The control pane showing the editable controls. */
    534     private JPanel control_pane = null;
    535     /** The edit pane contains the list of possible sources. */
    536     private JPanel edit_pane = null;
    537     /** A panel used to correctly lay out the default index label. */
    538     private JPanel default_pane = null;
    539     /** The panel containing the title label and instructions. */
    540     private JPanel header_pane = null;
    541     /** The lvel panel contains the control for adjusting index level. */
    542     private JPanel level_pane = null;
    543     /** The pane in which the name control is set. */
    544     private JPanel name_pane = null;
    545     /** The scrollpane containing the instructions text area. */
    546     private JScrollPane instructions_scroll = null;
    547     /** A text area containing inline instructions. */
    548     private JTextArea instructions = null;
    549     /** A text field naming the default index. Non-editable. */
    550     private JTextField default_value = null;
    551     /** A text field for controlling the name of the new index. */
    552     private JTextField name = null;
    553 
    554     private MGPPControl mgppindexes_control = null;
     512    private CheckList source_list;
     513    private JButton add_button;
     514    private JButton move_down_button;
     515    private JButton move_up_button;
     516    private JButton remove_button;
     517    private JButton set_default_button;
     518    private JComboBox level_combobox;
     519    private JList index_list;
     520    private JTextArea instruction_textarea;
     521    private JTextField name_textfield ;
     522
     523    private MGPPControl mgppindexes_control;
    555524
    556525    /** Constructor.
     
    569538    public IndexControl() {
    570539        super();
     540
     541        ArrayList new_data = new ArrayList();
     542        new_data.add(CollectionConfiguration.TEXT_STR);
     543        new_data.addAll(Gatherer.c_man.getCollection().msm.getAssignedElements());
     544
    571545        // Creation
    572546        JPanel mgindexes_panel = new JPanel();
    573547        card_layout = new CardLayout();
    574548
    575         add = new JButton(get("Add"));
    576         add.setEnabled(false);
    577         add.setMnemonic(KeyEvent.VK_A);
    578         assigned_pane = new JPanel();
    579         button_pane = new JPanel();
    580         central_pane = new JPanel();
    581         control_pane = new JPanel();
    582         clear_default = new JButton(get("Clear_Default"));
    583         clear_default.setMnemonic(KeyEvent.VK_C);
    584         if(default_index == null) {
    585         clear_default.setEnabled(false);
    586         }
    587         default_label = new JLabel(get("Default_Index"));
    588         default_pane = new JPanel();
    589         if(default_index != null) {
    590         default_value = new JTextField(default_index.toString());
    591         default_value.setCaretPosition(0);
    592         }
    593         else {
    594         default_value = new JTextField();
    595         }
    596         default_value.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
    597         default_value.setEditable(false);
    598         edit_pane = new JPanel();
    599         header_pane = new JPanel();
    600         index_label = new JLabel(get("Indexes"));
     549        // MG Index Controls
     550
     551        JPanel mg_indexes_pane = new JPanel();
     552
     553        JPanel instruction_pane = new JPanel();
     554        JLabel title_label = new JLabel(get("Title"));
     555        title_label.setHorizontalAlignment(JLabel.CENTER);
     556        instruction_textarea = new JTextArea(get("Instructions"));
     557        instruction_textarea.setEditable(false);
     558        instruction_textarea.setLineWrap(true);
     559        instruction_textarea.setRows(6);
     560        instruction_textarea.setWrapStyleWord(true);
     561
     562        JPanel assigned_indexes_pane = new JPanel();
     563        JLabel index_label = new JLabel(get("Indexes"));
    601564        index_list = new JList(model);
    602         instructions = new JTextArea(get("Instructions"));
    603         instructions.setEditable(false);
    604         instructions.setLineWrap(true);
    605         instructions.setRows(6);
    606         instructions.setWrapStyleWord(true);
    607         level = new JComboBox();
    608         level.addItem(get("Document"));
    609         level.addItem(get("Paragraph"));
    610         level.addItem(get("Section"));
    611         level.setEditable(false);
    612         level_label = new JLabel(get("Level"));
    613         level_label.setPreferredSize(LABEL_SIZE);
    614         level_pane = new JPanel();
    615         name = new JTextField();
    616         name_label = new JLabel(get("Name"));
    617         name_label.setPreferredSize(LABEL_SIZE);
    618         name_pane = new JPanel();
    619         remove = new JButton(get("Remove"));
    620         remove.setEnabled(false);
    621         remove.setMnemonic(KeyEvent.VK_R);
    622         set_default = new JButton(get("Set_Default"));
    623         set_default.setEnabled(false);
    624         set_default.setMnemonic(KeyEvent.VK_S);
    625         source_label = new JLabel(get("Source"));
    626         source_list = new JList();
    627         title = new JLabel(get("Title"));
    628         title.setHorizontalAlignment(JLabel.CENTER);
     565        index_list.setCellRenderer(new IndexListRenderer());
     566
     567        JPanel movement_pane = new JPanel();
     568        move_up_button = new DoubleImageButton(get("CDM.Move.Move_Up"), Utility.getImage("arrow-up.gif"), Utility.getImage("arrow-up-disabled.gif"));
     569        move_up_button.setEnabled(false);
     570        move_up_button.setMnemonic(KeyEvent.VK_U);
     571        move_up_button.setPreferredSize(Utility.BUTTON_SIZE);
     572        move_down_button = new DoubleImageButton(get("CDM.Move.Move_Down"), Utility.getImage("arrow-down.gif"), Utility.getImage("arrow-down-disabled.gif"));
     573        move_down_button.setEnabled(false);
     574        move_down_button.setMnemonic(KeyEvent.VK_D);
     575        move_down_button.setPreferredSize(Utility.BUTTON_SIZE);
     576
     577        JPanel index_pane = new JPanel();
     578
     579        JPanel details_pane = new JPanel();
     580
     581        JPanel name_pane = new JPanel();
     582        JLabel name_label = new JLabel(get("Name"));
     583        name_label.setPreferredSize(Utility.LABEL_SIZE);
     584        name_textfield = new JTextField();
     585
     586        JPanel source_pane = new JPanel();
     587        JLabel source_label = new JLabel(get("Source"));
     588        source_label.setPreferredSize(Utility.LABEL_SIZE);
     589        source_list = new CheckList(new_data, false);
     590
     591        JPanel level_pane = new JPanel();
     592        JLabel level_label = new JLabel(get("Level"));
     593        level_label.setPreferredSize(Utility.LABEL_SIZE);
     594        level_combobox = new JComboBox();
     595        level_combobox.addItem(get("Document"));
     596        level_combobox.addItem(get("Paragraph"));
     597        level_combobox.addItem(get("Section"));
     598        level_combobox.setEditable(false);
     599
     600        JPanel button_pane = new JPanel();
     601        add_button = new JButton(get("Add"));
     602        add_button.setEnabled(false);
     603        add_button.setMnemonic(KeyEvent.VK_A);
     604        set_default_button = new JButton(get("Set_Default"));
     605        set_default_button.setEnabled(false);
     606        set_default_button.setMnemonic(KeyEvent.VK_S);
     607        remove_button = new JButton(get("Remove"));
     608        remove_button.setEnabled(false);
     609        remove_button.setMnemonic(KeyEvent.VK_R);
    629610
    630611        // This class is getting a little crowded, so I'll generate the many mgpp controls in a inner class.
     
    632613
    633614        // Listeners
    634         add.addActionListener(new AddListener());
    635         clear_default.addActionListener(new ClearDefaultListener());
    636         remove.addActionListener(new RemoveListener());
    637         set_default.addActionListener(new SetDefaultListener());
    638         name.addKeyListener(new NameListener());
    639         ListListener ll = new ListListener();
    640         index_list.addListSelectionListener(ll);
    641         source_list.addListSelectionListener(ll);
     615        add_button.addActionListener(new AddListener());
     616        move_down_button.addActionListener(new MoveListener(false));
     617        move_up_button.addActionListener(new MoveListener(true));
     618        remove_button.addActionListener(new RemoveListener());
     619        set_default_button.addActionListener(new SetDefaultListener());
     620        name_textfield.getDocument().addDocumentListener(new NameListener());
     621        index_list.addListSelectionListener(new IndexListListener());
     622        source_list.addListSelectionListener(new SourceListListener());
    642623        ExclusiveListSelectionListener elsl = new ExclusiveListSelectionListener();
    643624        elsl.add(index_list);
    644625        elsl.add(source_list);
     626        elsl = null; // We don't want to hold a reference to this
    645627
    646628        // Layout
    647         title.setBorder(BorderFactory.createEmptyBorder(0,0,2,0));
    648 
    649         instructions.setBorder(BorderFactory.createEmptyBorder(2,5,2,5));
    650 
    651         header_pane.setLayout(new BorderLayout());
    652         header_pane.add(title, BorderLayout.NORTH);
    653         header_pane.add(new JScrollPane(instructions), BorderLayout.CENTER);
    654 
    655         name_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
    656 
    657         name_pane.setBorder(BorderFactory.createEmptyBorder(4,2,4,2));
     629        instruction_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     630        instruction_pane.setLayout(new BorderLayout());
     631        instruction_pane.add(title_label, BorderLayout.NORTH);
     632        instruction_pane.add(new JScrollPane(instruction_textarea), BorderLayout.CENTER);
     633
     634        movement_pane.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
     635        movement_pane.setLayout(new GridLayout(2,1,0,5));
     636        movement_pane.add(move_up_button);
     637        movement_pane.add(move_down_button);
     638
     639        assigned_indexes_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     640        assigned_indexes_pane.setLayout(new BorderLayout());
     641        assigned_indexes_pane.add(index_label, BorderLayout.NORTH);
     642        assigned_indexes_pane.add(new JScrollPane(index_list), BorderLayout.CENTER);
     643        assigned_indexes_pane.add(movement_pane, BorderLayout.EAST);
     644
     645        name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    658646        name_pane.setLayout(new BorderLayout());
    659647        name_pane.add(name_label, BorderLayout.WEST);
    660         name_pane.add(name, BorderLayout.CENTER);
    661 
    662         control_pane.setLayout(new BorderLayout());
    663         control_pane.add(source_label, BorderLayout.NORTH);
    664         control_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
    665 
    666         level_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
    667 
    668         level_pane.setBorder(BorderFactory.createEmptyBorder(4,2,4,2));
     648        name_pane.add(name_textfield, BorderLayout.CENTER);
     649
     650        source_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     651        source_pane.setLayout(new BorderLayout());
     652        source_pane.add(source_label, BorderLayout.WEST);
     653        source_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
     654
     655        level_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    669656        level_pane.setLayout(new BorderLayout());
    670657        level_pane.add(level_label, BorderLayout.WEST);
    671         level_pane.add(level, BorderLayout.CENTER);
    672 
    673         edit_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
    674         edit_pane.setLayout(new BorderLayout());
    675         edit_pane.add(name_pane, BorderLayout.NORTH);
    676         edit_pane.add(control_pane, BorderLayout.CENTER);
    677         edit_pane.add(level_pane, BorderLayout.SOUTH);
    678 
    679         default_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
    680 
    681         default_pane.setBorder
    682         (BorderFactory.createCompoundBorder
    683          (BorderFactory.createCompoundBorder
    684           (BorderFactory.createEmptyBorder(2,2,2,2),
    685            BorderFactory.createRaisedBevelBorder()),
    686           BorderFactory.createEmptyBorder(2,2,2,2)));
    687         default_pane.setLayout(new BorderLayout());
    688         default_pane.add(default_label, BorderLayout.WEST);
    689         default_pane.add(default_value, BorderLayout.CENTER);
    690 
    691         assigned_pane.setLayout(new BorderLayout());
    692         assigned_pane.add(index_label, BorderLayout.NORTH);
    693         assigned_pane.add(new JScrollPane(index_list), BorderLayout.CENTER);
    694         assigned_pane.add(default_pane, BorderLayout.SOUTH);
    695 
    696         central_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
    697         central_pane.setLayout(new GridLayout(1,2));
    698         central_pane.add(edit_pane);
    699         central_pane.add(assigned_pane);
    700 
    701         button_pane.setLayout(new GridLayout(2,2));
    702         button_pane.add(add);
    703         button_pane.add(remove);
    704         button_pane.add(clear_default);
    705         button_pane.add(set_default);
     658        level_pane.add(level_combobox, BorderLayout.CENTER);
     659
     660        details_pane.setLayout(new BorderLayout());
     661        details_pane.add(name_pane, BorderLayout.NORTH);
     662        details_pane.add(source_pane, BorderLayout.CENTER);
     663        details_pane.add(level_pane, BorderLayout.SOUTH);
     664
     665        button_pane.setLayout(new GridLayout(1,3,5,0));
     666        button_pane.add(add_button);
     667        button_pane.add(set_default_button);
     668        button_pane.add(remove_button);
     669
     670        index_pane.setLayout(new BorderLayout());
     671        index_pane.add(details_pane, BorderLayout.CENTER);
     672        index_pane.add(button_pane, BorderLayout.SOUTH);
    706673
    707674        mgindexes_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    708675        mgindexes_panel.setLayout(new BorderLayout());
    709         mgindexes_panel.add(header_pane, BorderLayout.NORTH);
    710         mgindexes_panel.add(central_pane, BorderLayout.CENTER);
    711         mgindexes_panel.add(button_pane, BorderLayout.SOUTH);
     676        mgindexes_panel.add(instruction_pane, BorderLayout.NORTH);
     677        mgindexes_panel.add(assigned_indexes_pane, BorderLayout.CENTER);
     678        mgindexes_panel.add(index_pane, BorderLayout.SOUTH);
    712679
    713680        setLayout(card_layout);
     
    724691    public void gainFocus() {
    725692        boolean mgpp_enabled = CollectionDesignManager.searchtype_manager.isMGPPEnabled();
    726         if(instructions != null) {
    727         instructions.setCaretPosition(0);
     693        if(instruction_textarea != null) {
     694        instruction_textarea.setCaretPosition(0);
    728695        }
    729696        if(mgpp_enabled) {
     
    749716
    750717    public void loseFocus() {
     718    }
     719
     720    private void validateAddButton() {
     721        boolean add_enabled = false;
     722        // Indexes must have a name
     723        if(name_textfield.getText().length() == 0) {
     724        add_enabled = false;
     725        }
     726        // Can't add a new index if no sources are selected
     727        else if(source_list.isSelectionEmpty()) {
     728        add_enabled = false;
     729        }
     730        // If we get this far, create a dummy index and see if its already assigned in the collection
     731        else {
     732        Object object[] = source_list.getSelected().toArray();
     733        ArrayList sources = new ArrayList();
     734        for(int i = 0; i < object.length; i++) {
     735            sources.add(object[i]);
     736        }
     737        object = null;
     738        Index index = new Index(level_combobox.getSelectedIndex(), sources);
     739        sources = null;
     740        if(model.contains(index)) {
     741            add_enabled = false;
     742        }
     743        else {
     744            add_enabled = true;
     745        }
     746        }
     747        // We should now know the add_button state
     748        add_button.setEnabled(add_enabled);
    751749    }
    752750
     
    764762         */
    765763        public void actionPerformed(ActionEvent event) {
    766         if(!source_list.isSelectionEmpty() && name.getText().length() != 0) {
    767             Object object[] = source_list.getSelectedValues();
    768             ArrayList sources = new ArrayList();
    769             for(int i = 0; i < object.length; i++) {
    770             sources.add(object[i]);
    771             }
    772             object = null;
    773             Index index = new Index(level.getSelectedIndex(), sources);
     764        String name = name_textfield.getText();
     765        if(!source_list.isSelectionEmpty() && name.length() != 0) {
     766            ArrayList sources = source_list.getSelected();
     767            Index index = new Index(level_combobox.getSelectedIndex(), sources);
    774768            sources = null;
    775769            // Before we add the index to the model, we have to add the collection metadata for this.
    776770            CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
    777             metadatum.setValue(name.getText());
     771            metadatum.setValue(name);
    778772            // Finally add index.
    779773            addIndex(index, metadatum);
     
    781775            index = null;
    782776        }
    783         }
    784     }
    785     /** Listens for actions apon the 'clear default' button in the IndexManager controls, and if detected calls the setDefault method of the manager with <i>null</i>. */
    786     private class ClearDefaultListener
     777        name = null;
     778        }
     779    }
     780
     781    /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
     782    private class IndexListListener
     783        implements ListSelectionListener {
     784        /** 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.
     785         * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
     786         */
     787        public void valueChanged(ListSelectionEvent event) {
     788        Object value = index_list.getSelectedValue();
     789        move_down_button.setEnabled(value != null);
     790        move_up_button.setEnabled(value != null);
     791        remove_button.setEnabled(value != null);
     792        set_default_button.setEnabled(value != null && (default_index == null || !default_index.equals(value)));
     793        }
     794    }
     795
     796    private class IndexListRenderer
     797        extends DefaultListCellRenderer {
     798
     799        /** Return a component that has been configured to display the specified value. */
     800        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
     801        JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     802        if(default_index != null && default_index.equals(value)) {
     803            component.setText(component.getText() + " " + get("Default_Index_Indicator"));
     804        }
     805        return component;
     806        }
     807         
     808    }
     809
     810    private class MoveListener
    787811        implements ActionListener {
    788         /** If called when an action occurs on a registered component, we clear the default index.
    789          * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
    790          */
     812       
     813        private boolean move_up;
     814
     815        public MoveListener(boolean move_up) {
     816        this.move_up = move_up;
     817        }
     818
    791819        public void actionPerformed(ActionEvent event) {
    792         setDefault(null);
    793         clear_default.setEnabled(false);
    794         default_value.setText("");
    795         }
    796     }
     820        // Retrieve the selected index
     821        Index index = (Index) index_list.getSelectedValue();
     822        if(index != null) {
     823            moveIndex(index, move_up);
     824            // Ensure the index that moved is still selected
     825            index_list.setSelectedValue(index, true);
     826            index = null;
     827        }
     828        }
     829    }
     830
    797831    /** 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. */
    798832    private class RemoveListener
    799833        implements ActionListener {
    800                 /** If called when an action occurs on a registered component, we remove the currently selected index, if there is one.
    801                 * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
    802                 * @see org.greenstone.gatherer.cdm.Index
    803                 */
     834        /** If called when an action occurs on a registered component, we remove the currently selected index, if there is one.
     835        * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
     836        * @see org.greenstone.gatherer.cdm.Index
     837        */
    804838        public void actionPerformed(ActionEvent event) {
    805839        if(!index_list.isSelectionEmpty()) {
    806840            removeIndex((Index)index_list.getSelectedValue());
    807             if(default_index == null) {
    808             clear_default.setEnabled(false);
    809             default_value.setText("");
    810             }
    811         }
     841        }
     842        move_down_button.setEnabled(false);
     843        move_up_button.setEnabled(false);
     844        remove_button.setEnabled(false);
     845        }
     846    }
     847
     848    private class SetDefaultListener
     849        implements ActionListener {
     850       
     851        public void actionPerformed(ActionEvent event) {
     852        Index index = (Index) index_list.getSelectedValue();
     853        if(index != null) {
     854            setDefault(index);
     855            // This should cause a repaint of just the desired row
     856            index_list.setSelectedValue(index, true);
     857        }
     858        set_default_button.setEnabled(false);
    812859        }
    813860    }
    814861
    815862    /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
    816     private class ListListener
     863    private class SourceListListener
    817864        implements ListSelectionListener {
    818                 /** 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.
    819                 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
    820                 */
     865        /** 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.
     866        * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
     867         */
    821868        public void valueChanged(ListSelectionEvent event) {
    822         if(source_list.isSelectionEmpty() || name.getText().length() == 0) {
    823             add.setEnabled(false);
    824         }
    825         else {
    826             add.setEnabled(true);
    827         }
    828         if(index_list.isSelectionEmpty()) {
    829             remove.setEnabled(false);
    830             set_default.setEnabled(false);
    831         }
    832         else {
    833             remove.setEnabled(true);
    834             set_default.setEnabled(true);
    835         }
     869        validateAddButton();
    836870        }
    837871    }
     
    839873    /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
    840874    private class NameListener
    841         extends KeyAdapter {
    842                 /** Called when a key is released, this is the perfect time to enable the add button if the fields are appropriately set.
    843                  * @param event A <strong>KeyEvent</strong> containing information about the key released.
    844                 */
    845         public void keyReleased(KeyEvent event) {
    846         if(source_list.isSelectionEmpty() || name.getText().length() == 0) {
    847             add.setEnabled(false);
    848         }
    849         else {
    850             add.setEnabled(true);
    851         }
    852         if(index_list.isSelectionEmpty()) {
    853             remove.setEnabled(false);
    854             set_default.setEnabled(false);
    855         }
    856         else {
    857             remove.setEnabled(true);
    858             set_default.setEnabled(true);
    859         }
    860         }
    861     }
    862 
    863     /** Listens for actions apon the 'set default' button in the IndexManager controls, and if detected calls the setDefault method of the manager with the index selected for default. */
    864     private class SetDefaultListener
    865         implements ActionListener {
    866                 /** If called when an action occurs on a registered component, we set the default index to the index currently selected.
    867                  * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
    868                  * @see org.greenstone.gatherer.cdm.Index
    869                  */
    870         public void actionPerformed(ActionEvent event) {
    871         setDefault((Index)index_list.getSelectedValue());
    872         if(default_index != null) {
    873             clear_default.setEnabled(true);
    874             default_value.setText(default_index.toString());
    875             default_value.setCaretPosition(0);
    876         }
    877         else {
    878             clear_default.setEnabled(false);
    879             default_value.setText("");
    880         }
     875        implements DocumentListener {
     876        /** Gives notification that an attribute or set of attributes changed. */
     877        public void changedUpdate(DocumentEvent e) {
     878        validateAddButton();
     879        }
     880       
     881        /** Gives notification that there was an insert into the document. */
     882        public void insertUpdate(DocumentEvent e) {
     883        validateAddButton();
     884        }
     885       
     886        /** Gives notification that a portion of the document has been removed. */
     887        public void removeUpdate(DocumentEvent e) {
     888        validateAddButton();
    881889        }
    882890    }
  • trunk/gli/src/org/greenstone/gatherer/cdm/SuperCollectionManager.java

    r5090 r5159  
    146146        instructions.setWrapStyleWord(true);
    147147
    148         collection_checklist = new CheckList(collection_checklist_model);
     148        collection_checklist = new CheckList(collection_checklist_model, false);
    149149
    150150        // Layout
  • trunk/gli/src/org/greenstone/gatherer/checklist/CheckList.java

    r4932 r5159  
    6969    /** The border used when a list row is not in focus. */
    7070    protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
     71   
     72    private boolean show_selected_row = true;
    7173    /** Constructor. */
    72     public CheckList() {
     74    public CheckList(boolean show_selected_row) {
    7375    super();
     76    this.show_selected_row = show_selected_row;
    7477    setCellRenderer(new CellRenderer());
    7578    setModel(new DefaultListModel());
     
    8184     * @see org.greenstone.gatherer.checklist.CheckList.Entry
    8285     */
    83     public CheckList(ArrayList list_data) {
     86    public CheckList(ArrayList list_data, boolean show_selected_row) {
    8487    super();
     88    this.show_selected_row = show_selected_row;
    8589    // Create a new model.
    8690    DefaultListModel model = new DefaultListModel();
     
    117121
    118122    /** Constructor. */
    119     public CheckList(ListModel data_model) {
     123    public CheckList(ListModel data_model, boolean show_selected_row) {
    120124    super(data_model);
     125    this.show_selected_row = show_selected_row;
    121126    setCellRenderer(new CellRenderer());
    122127    addMouseListener(new CheckListListener());
     
    173178    }
    174179
     180    public boolean isSelectionEmpty() {
     181    DefaultListModel model = (DefaultListModel) getModel();
     182    int size = model.size();
     183    for(int i = 0; i < size; i++) {
     184        Entry entry = (Entry) model.get(i);
     185        if(entry.isSelected()) {
     186        entry = null;
     187        model = null;
     188        return false;
     189        }
     190        entry = null;
     191    }
     192    model = null;
     193    return true;
     194    }
     195
    175196    public int getEntryCount() {
    176197    return getModel().getSize();
     198    }
     199
     200    public void setListData(Object[] list_data) {
     201    // Create a new model.
     202    DefaultListModel model = new DefaultListModel();
     203    for(int i = 0; i < list_data.length; i++) {
     204        Entry entry = null;
     205        Object temp = list_data[i];
     206        if(temp instanceof Entry) {
     207        entry = (Entry) temp;
     208        }
     209        else {
     210        entry = new Entry(temp);
     211        }
     212        temp = null;
     213        String name = entry.toString();
     214        int index = 0;
     215        boolean found = false;
     216        while(index < model.size() && !found) {
     217        Object sibling = model.getElementAt(index);
     218        if(name.compareTo(sibling.toString()) <= 0) {
     219            model.add(index, entry);
     220            found = true;
     221        }
     222        index++;
     223        }
     224        if(!found) {
     225        model.addElement(entry);
     226        }
     227    }
     228    setModel(model);
    177229    }
    178230
     
    193245    }         
    194246    }
     247
     248    private void selectionChanged(int index) {
     249    fireSelectionValueChanged(index, index, false);
     250    }
     251
    195252    /** A custom list cell renderer for producing rows which contain clickable check boxes. */
    196253    protected class CellRenderer
     
    206263    public Component getListCellRendererComponent(JList list, Object value, int index, boolean is_selected, boolean cell_has_focus) {
    207264        JCheckBox checkbox = (JCheckBox) value;
    208         checkbox.setBackground(is_selected ? list.getSelectionBackground() : list.getBackground());
    209         checkbox.setForeground(is_selected ? list.getSelectionForeground() : list.getForeground());
     265        if(show_selected_row) {
     266        checkbox.setBackground(is_selected ? list.getSelectionBackground() : list.getBackground());
     267        checkbox.setForeground(is_selected ? list.getSelectionForeground() : list.getForeground());
     268        checkbox.setBorderPainted(true);
     269        }
     270        else {
     271        checkbox.setBackground(list.getBackground());
     272        checkbox.setForeground(list.getForeground());
     273        checkbox.setBorderPainted(false);
     274        }
    210275        checkbox.setEnabled(list.isEnabled());
    211276        checkbox.setFont(list.getFont());
    212277        checkbox.setFocusPainted(false);
    213         checkbox.setBorderPainted(true);
    214278        checkbox.setBorder((is_selected) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
    215279        return checkbox;
     
    232296        }
    233297        checkbox.grabFocus();
     298        // Fire a selection changed event
     299        selectionChanged(index);
    234300    }
    235301    }
  • trunk/gli/src/org/greenstone/gatherer/checklist/Entry.java

    r4496 r5159  
    1313
    1414    /** Is this checkboxes state fixed. */
    15     protected boolean fixed = false;
     15    private boolean fixed = false;
    1616    /** The original object this row is based on, and whose toString() is used to generate the check box label. */
    17     protected Object object = null;
     17    private Object object = null;
    1818    /** A sundry string for storing original values (rather than strings retrieved from dictionary). */
    19     protected String property;
     19    private String property;
    2020    /** Constructor. */
    2121    public Entry(Object object) {
     
    2525    if(object instanceof MetadataSet) {
    2626        MetadataSet set = (MetadataSet) object;
    27                 // Build tooltip
     27        // Build tooltip
    2828        StringBuffer tip = new StringBuffer(Gatherer.dictionary.get("NewCollectionPrompt.Set_Contains"));
    2929        tip.append(":\n");
     
    6464      */
    6565    public Object getObject() {
     66    //Gatherer.println("Retrieving the object for " + toString());
    6667    if(object == null) {
    6768        return getText();
  • trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionMetadataPrompt.java

    r4675 r5159  
    1616import org.greenstone.gatherer.msm.MetadataSet;
    1717import org.greenstone.gatherer.msm.MetadataSetManager;
     18import org.greenstone.gatherer.util.StaticStrings;
    1819import org.greenstone.gatherer.util.Utility;
    1920import org.w3c.dom.*;
     
    4344    for(int i = 0; i < possible_mdses.length; i++) {
    4445        String name = possible_mdses[i].getName();
    45         if(name.endsWith(".mds")) {
     46        if(name.endsWith(StaticStrings.METADATA_SET_EXTENSION) && !name.equals(Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION)) {
    4647        sets.add(new MetadataSet(possible_mdses[i]));
    4748        }
     
    6061    JLabel sets_list_label = new JLabel(get("Select_MDS"));
    6162    sets_list_label.setOpaque(false);
    62     sets_list = new CheckList(sets);
     63    sets_list = new CheckList(sets, true);
    6364
    6465    JPanel elements_list_pane = new JPanel();
Note: See TracChangeset for help on using the changeset viewer.