Changeset 4468 for trunk/gli


Ignore:
Timestamp:
2003-06-03T17:23:30+12:00 (21 years ago)
Author:
mdewsnip
Message:

Can now add/edit/remove element attributes properly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java

    r4436 r4468  
    635635        Object source = event.getSource();
    636636        if(source == ok_button) {
    637         boolean cont = true;
    638         AttributeTableModel model = null;
     637        boolean success = true;
     638        AttributeTableModel model;
     639
     640        // Add or edit a collect/set/element attribute
    639641        switch(current_attribute_type) {
    640642        case MEMNode.COLLECTION:
    641643            model = (AttributeTableModel) profile_attributes.getModel();
     644            success = addOrEditCollectionAttribute(model);
     645            break;
     646        case MEMNode.SET:
     647            model = (AttributeTableModel) set_attributes.getModel();
     648            success = addOrEditSetAttribute(model);         
    642649            break;
    643650        case MEMNode.ELEMENT:
    644651            model = (AttributeTableModel) element_attributes.getModel();
     652            success = addOrEditElementAttribute(model);
    645653            break;
    646         case MEMNode.SET:
    647             model = (AttributeTableModel) set_attributes.getModel();
    648             break;
    649         }
    650         // Now we add the new or improved values, removing old values if this is an edit.
    651         // Depends on what we are adding the attribute to.
    652         if(model != null) {
    653             if(current_collection_file != null) {
    654             String name_str = name.getSelectedItem().toString();
    655             String value_str = value.getText();
    656             // Remove the existing one if this is an edit.
    657             if(!add_type && current_attribute != -1) {
    658                 String old_source = (String) model.getValueAt(current_attribute, 0);
    659                 Gatherer.c_man.msm.profiler.removeAction(current_collection_file, old_source);
    660                 old_source = null;
    661                 model.removeRow(current_attribute);
    662             }
    663             // First thing we check from profiles is that there isn't already an entry for this name.
    664             if(!model.contains(name_str, 0)) {
    665                 // Add profile
    666                 Gatherer.c_man.msm.profiler.addAction(current_collection_file, name_str, value_str);
    667                 // Update attribute table.
    668                 model.add(new Attribute(name_str, value_str));
    669             }
    670             else {
    671                 // Show an error message and do not proceed.
    672                 cont = false;
    673                 JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
    674             }
    675             value_str = null;
    676             name_str = null;
    677             }
    678             else if(current_element != null) {
    679             // Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today.
    680             String name_str = name.getSelectedItem().toString();
    681             String language_code = ((Language)language_box.getSelectedItem()).getCode();
    682             String value_str = value.getText();
    683             // Remove the existing one if this is an edit.
    684             if(!add_type && current_attribute != -1) {
    685                 model.removeRow(current_attribute);
    686             }
    687             // Add attribute
    688             current_element.addAttribute(name_str, language_code, value_str);
    689             // Update the attribute table
    690             model.add(new Attribute(name_str, language_code, value_str));
    691             value_str = null;
    692             language_code = null;
    693             name_str = null;
    694             }
    695             else if(current_set != null) {
    696             String name_str = name.getSelectedItem().toString();
    697             String value_str = value.getText();                     
    698             // Remove the existing one if this is an edit.
    699             if(!add_type && current_attribute != -1) {
    700                 model.removeRow(current_attribute);
    701             }
    702             // First thing we check from profiles is that there isn't already an entry for this name.
    703             if(!model.contains(name_str, 0)) {
    704                 // Add profile
    705                 current_set.addAttribute(name_str, value_str);
    706                 // Update attribute table.
    707                 model.add(new Attribute(name_str, value_str));
    708             }
    709             // Otherwise provide an error message and do not proceed.
    710             else {
    711                 cont = false;
    712                 JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
    713             }
    714             value_str = null;
    715             name_str = null;
    716             }
    717             // Hide dialog if we are allowed to continue.
    718             if(cont) {
    719             setVisible(false);
    720             }
    721             model = null;
     654        }
     655
     656        if (success) {
     657            // Hide dialog
     658            setVisible(false);
    722659        }
    723660        }
     
    886823        source = null;
    887824    }
    888          
     825
     826
     827    private boolean addOrEditCollectionAttribute(AttributeTableModel model)
     828    {
     829        String name_str = name.getSelectedItem().toString();
     830        String value_str = value.getText();
     831
     832        // Remove the existing attribute if this is an edit
     833        if(!add_type && current_attribute != -1) {
     834        String old_source = (String) model.getValueAt(current_attribute, 0);
     835        Gatherer.c_man.msm.profiler.removeAction(current_collection_file, old_source);
     836        old_source = null;
     837        model.removeRow(current_attribute);
     838        }
     839
     840        boolean cont = true;
     841        // Check that there isn't already an entry for this attribute
     842        if (!model.contains(name_str, 0)) {
     843        // Add profile
     844        Gatherer.c_man.msm.profiler.addAction(current_collection_file, name_str, value_str);
     845        // Update attribute table
     846        model.add(new Attribute(name_str, value_str));
     847        }
     848        // Otherwise show an error message and do not proceed
     849        else {
     850        cont = false;
     851        JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
     852        }
     853
     854        value_str = null;
     855        name_str = null;
     856        return cont;
     857    }
     858
     859
     860    private boolean addOrEditSetAttribute(AttributeTableModel model)
     861    {
     862        String name_str = name.getSelectedItem().toString();
     863        String value_str = value.getText();                     
     864
     865        // Remove the existing attribute if this is an edit
     866        if(!add_type && current_attribute != -1) {
     867        current_set.removeAttribute(name_str);
     868        // Update attribute table
     869        model.removeRow(current_attribute);
     870        }
     871
     872        boolean cont = true;
     873        // Check that there isn't already an entry for this attribute
     874        if (!model.contains(name_str, 0)) {
     875        // Add the new attribute
     876        current_set.addAttribute(name_str, value_str);
     877        // Update the attribute table
     878        model.add(new Attribute(name_str, value_str));
     879        }
     880        // Otherwise show an error message and do not proceed
     881        else {
     882        cont = false;
     883        JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
     884        }
     885
     886        value_str = null;
     887        name_str = null;
     888        return cont;
     889    }
     890
     891
     892    private boolean addOrEditElementAttribute(AttributeTableModel model)
     893    {
     894        // Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today.
     895        String name_str = name.getSelectedItem().toString();
     896        String language_code = ((Language)language_box.getSelectedItem()).getCode();
     897        String value_str = value.getText();
     898
     899        // Remove the existing attribute if this is an edit
     900        if(!add_type && current_attribute != -1) {
     901        String current_value_str = model.getAttribute(current_attribute).value;
     902        current_element.removeAttribute(name_str, language_code, current_value_str);
     903        // Update the attribute table
     904        model.removeRow(current_attribute);
     905        }
     906
     907        // Add the new attribute
     908        current_element.addAttribute(name_str, language_code, value_str);
     909        // Update the attribute table
     910        model.add(new Attribute(name_str, language_code, value_str));
     911
     912        value_str = null;
     913        language_code = null;
     914        name_str = null;
     915        return true;
     916    }
     917
     918
    889919    public void dispose() {
    890920        cancel_button = null;
     
    15371567            // Remove element attribute
    15381568            String name = (String) element_attributes.getValueAt(current_attribute, 0);
    1539             String value = (String) element_attributes.getValueAt(current_attribute, 1);
    1540             current_element.removeAttribute(name, value); // Can be multiple authors for instance
     1569            String language = (String) element_attributes.getValueAt(current_attribute, 1);
     1570            String value = (String) element_attributes.getValueAt(current_attribute, 2);
     1571            current_element.removeAttribute(name, language, value);
     1572
    15411573            // Refresh table
    15421574            ((AttributeTableModel)element_attributes.getModel()).removeRow(current_attribute);
Note: See TracChangeset for help on using the changeset viewer.