Changeset 10877


Ignore:
Timestamp:
2005-11-09T15:11:09+13:00 (18 years ago)
Author:
kjdon
Message:

tidied up the if/elses in AddSetListener:actionPerformed()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java

    r10462 r10877  
    14081408        private JComboBox existingSetJComboBox = new JComboBox();
    14091409           
     1410    private String DO_NOT_INHERIT = Dictionary.get("GEMS.Add_Set.No_Inherit");
     1411   
    14101412    public AddSetActionListener() {
    14111413        super(self);
     
    14881490            Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
    14891491           
    1490             existingSetJComboBox.addItem("Do not inherit");
     1492        existingSetJComboBox.addItem(DO_NOT_INHERIT);
    14911493            existingSetJComboBox.setSelectedIndex(getSetsLen);
    14921494            boxes_pane.add(existingSetJComboBox);
     
    15351537        String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
    15361538       
    1537                 if (existingSetJComboBox.getSelectedItem().toString().trim().compareTo("Do not inherit") == 0){
    1538 
    1539         // Ensure the set doesn't already exist
    1540                 if(a_set_exists_with_this_namespace(namespace_str) == false){
    1541        
     1539        // first check whether the namespace is valid, i.e. hasn't been used before
     1540        if(a_set_exists_with_this_namespace(namespace_str)) {
     1541            JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     1542            return; // return back to the dialog
     1543        }
     1544       
     1545        //not based on another set
     1546        if (existingSetJComboBox.getSelectedItem().toString().equals(DO_NOT_INHERIT)){         
    15421547            MetadataSet set = msm.addSet(namespace_str, name_str);
    1543                    
    1544                     //mark as set changed = true
    1545                     set.setSetChanged(true);
    1546                     atLeastOneSetChanged = true;
    1547                    
     1548           
     1549            //mark as set changed = true
     1550            set.setSetChanged(true);
     1551            atLeastOneSetChanged = true;
     1552           
    15481553            // Update tree.
    15491554            model.add(null, set, GEMSNode.SET);
     
    15511556            set = null;
    15521557            setVisible(false);
    1553                    
    1554         }
    1555                 else{
    1556                        JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    1557                 }
    1558                
    1559         name_str = null;
    1560         namespace_str = null;
    1561                 }//end do not inherit
     1558           
     1559        }
    15621560                else {
    15631561            //Should change this to use XML parsing utilites --Matthew
     
    15651563                    String anitem = existingSetJComboBox.getSelectedItem().toString();
    15661564                   
    1567                     if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
    1568                         //setup to read the filename from mds file
    1569             String [] items = anitem.split("#%");
    1570                         try {
    1571                 FileInputStream fstream = new FileInputStream(items[1].trim());
    1572                 BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF8"));
     1565            //setup to read the filename from mds file
     1566            String [] items = anitem.split("#%");
     1567            try {
     1568            FileInputStream fstream = new FileInputStream(items[1].trim());
     1569            BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF8"));
    15731570               
    1574                 FileOutputStream out;
    1575                 PrintWriter p;
    1576                 //setup to write to filename from existing file
    1577                 try {
    1578                 out = new FileOutputStream(getGLIMetadataDirectoryPath() + namespace_str + ".mds");
    1579                 OutputStreamWriter pout = new OutputStreamWriter(out, "UTF8");
    1580                 p = new PrintWriter(pout);
     1571            FileOutputStream out;
     1572            PrintWriter p;
     1573            //setup to write to filename from existing file
     1574            try {
     1575                out = new FileOutputStream(getGLIMetadataDirectoryPath() + namespace_str + ".mds");
     1576                OutputStreamWriter pout = new OutputStreamWriter(out, "UTF8");
     1577                p = new PrintWriter(pout);
     1578               
     1579                while(in.ready()){
     1580                String nextline = in.readLine();
    15811581               
    1582                 while(in.ready()){
    1583                     String nextline = in.readLine();
    1584                    
    1585                     if(nextline.matches(".+namespace=\".+\".*") == true) {
    1586                     nextline = nextline.replaceFirst("namespace=\".+\"","namespace=\"" + namespace_str+ "\"");                         
    1587                     }
    1588                     else {
    1589                     nextline = nextline.replaceFirst(">.+</Name>",">" + name_str + "</Name>");
    1590                     }
    1591                     p.print(nextline + "\n");
     1582                if(nextline.matches(".+namespace=\".+\".*") == true) {
     1583                    nextline = nextline.replaceFirst("namespace=\".+\"","namespace=\"" + namespace_str+ "\"");                         
    15921584                }
    1593                 p.close();
    1594                
    1595                 MetadataSet loadedset = msm.loadMetadataSet(new File(getGLIMetadataDirectoryPath() + namespace_str + ".mds"));
    1596                 model.add(null, loadedset, GEMSNode.SET);
     1585                else {
     1586                    nextline = nextline.replaceFirst(">.+</Name>",">" + name_str + "</Name>");
     1587                }
     1588                p.print(nextline + "\n");
    15971589                }
    1598                 catch(Exception e){
    1599                 System.out.println("Print file error");
    1600                 }
    1601                         }
    1602                         catch(Exception e){
    1603                             System.out.println("File Input error");
    1604                         }
    1605                    
    1606                     }//msm.getset(namespacE) == null
    1607                     else{
    1608             JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    1609                     }
    1610             setVisible(false);
    1611                 }
     1590                p.close();
     1591               
     1592                MetadataSet loadedset = msm.loadMetadataSet(new File(getGLIMetadataDirectoryPath() + namespace_str + ".mds"));
     1593                model.add(null, loadedset, GEMSNode.SET);
     1594            }
     1595            catch(Exception e){
     1596                System.out.println("Print file error");
     1597            }
     1598            }
     1599            catch(Exception e){
     1600            System.out.println("File Input error");
     1601            }
     1602           
     1603        }
     1604       
     1605        name_str = null;
     1606        namespace_str = null;
     1607        setVisible(false);
    16121608        } //if(source == ok_button)
    16131609        else if(source == cancel_button) {
Note: See TracChangeset for help on using the changeset viewer.