Changeset 12087


Ignore:
Timestamp:
2006-07-07T13:04:41+12:00 (18 years ago)
Author:
kjdon
Message:

indented the file properly

File:
1 edited

Legend:

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

    r12083 r12087  
    644644   
    645645
    646     private class NewIndexPrompt
    647     extends ModalDialog {
    648 
    649     NewIndexPrompt new_index_prompt = null;
    650    
    651     private CheckList source_list;
    652     // mg uses a level box
    653     private JComboBox level_combobox;
    654     // mgpp has a allfields selector
    655     private JCheckBox allfields_box;
    656 
    657     private JButton add_button;
    658     private JButton replace_button;
    659     private JButton add_all_button;
    660     private JButton cancel_button;
    661 
    662     // some panels that we need to manipulate later on
    663     private JPanel boxes_pane;
    664     private JPanel labels_pane;
    665     private JLabel level_label;
    666     private JPanel allfields_pane;
    667 
    668     private boolean mgpp_enabled = false;
    669     private boolean editing = false;
    670    
    671     public NewIndexPrompt(String build_type, Index existing_index) {
    672         super(Gatherer.g_man, true);
    673         new_index_prompt = this;
    674 
    675         setModal(true);
    676         setSize(PROMPT_SIZE);
    677         if (existing_index != null) {
    678         setTitle (Dictionary.get("CDM.IndexManager.Edit_Index"));
    679         editing = true;
    680         } else {
    681         setTitle(Dictionary.get("CDM.IndexManager.New_Index"));
    682         }
    683        
    684         if (build_type.equals(BuildTypeManager.BUILD_TYPE_MGPP) || build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
    685         mgpp_enabled = true;
    686         }
    687         JPanel content_pane = (JPanel)this.getContentPane();
    688         ArrayList new_data = new ArrayList();
    689         new_data.add(CollectionConfiguration.TEXT_STR);
    690         new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
    691 
    692         JPanel details_pane = new JPanel();
    693         labels_pane = new JPanel();
    694         boxes_pane = new JPanel();
    695 
    696         JPanel main_index_pane = new JPanel();
    697 
    698         JLabel source_label = new JLabel();
    699         Dictionary.registerText(source_label, "CDM.IndexManager.Source");
    700         source_list = new CheckList(false);
    701         source_list.setListData(new_data);
    702         Dictionary.registerTooltip(source_list, "CDM.IndexManager.Source_Tooltip");
    703         source_list.addListSelectionListener(new SourceListListener());
    704 
    705         JPanel button_pane = new JPanel();
    706         if (existing_index != null) {
    707         button_pane.setLayout(new GridLayout(1,2,5,0));
    708         replace_button = new GLIButton();
    709         replace_button.setEnabled(false);
    710         Dictionary.registerBoth(replace_button, "CDM.IndexManager.Replace_Index", "CDM.IndexManager.Replace_Index_Tooltip");
    711         button_pane.add(replace_button);
    712         replace_button.addActionListener(new ReplaceIndexListener());
    713         } else {
    714         button_pane.setLayout(new GridLayout(1,3,5,0));
    715         add_button = new GLIButton();
    716         add_button.setEnabled(false);
    717         add_button.setMnemonic(KeyEvent.VK_A);
    718         Dictionary.registerBoth(add_button, "CDM.IndexManager.Add_Index", "CDM.IndexManager.Add_Index_Tooltip");
    719         add_button.addActionListener(new AddIndexListener());
    720 
    721        
    722         add_all_button = new GLIButton();
    723         add_all_button.setEnabled(true);
    724         add_all_button.setMnemonic(KeyEvent.VK_L);
    725         Dictionary.registerBoth(add_all_button, "CDM.IndexManager.Add_All", "CDM.IndexManager.Add_All_Tooltip");
    726         add_all_button.addActionListener(new AddAllIndexActionListener());     
    727         button_pane.add(add_button);
    728         button_pane.add(add_all_button);
    729 
    730         }
    731         cancel_button = new GLIButton();
    732         cancel_button.setEnabled(true);
    733         Dictionary.registerBoth(cancel_button, "General.Cancel", "General.Cancel");
    734         cancel_button.addActionListener(new ActionListener() {
    735         public void actionPerformed(ActionEvent event) {
    736             new_index_prompt.dispose();
    737         }
    738         });
    739         button_pane.add(cancel_button);
    740 
    741         // Layout
    742         labels_pane.setLayout(new BorderLayout());
    743         labels_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5));
    744         labels_pane.add(source_label, BorderLayout.CENTER);
    745        
    746         boxes_pane.setLayout(new BorderLayout());
    747         boxes_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
    748        
    749         details_pane.setLayout(new BorderLayout());
    750         details_pane.add(labels_pane, BorderLayout.WEST);
    751         details_pane.add(boxes_pane, BorderLayout.CENTER);
    752 
    753 
    754         // do type specific stuff
    755         if (!mgpp_enabled) {
    756 
    757         level_label = new JLabel();
    758         Dictionary.registerText(level_label, "CDM.IndexManager.Level");
    759         level_combobox = new JComboBox();
    760         level_combobox.setPreferredSize(FIELD_SIZE);
    761         level_combobox.addItem(CollectionConfiguration.DOCUMENT_STR);//Dictionary.get("CDM.IndexManager.Document"));
    762         level_combobox.addItem(CollectionConfiguration.PARAGRAPH_STR);//Dictionary.get("CDM.IndexManager.Paragraph"));
    763         level_combobox.addItem(CollectionConfiguration.SECTION_STR);//Dictionary.get("CDM.IndexManager.Section"));
    764         level_combobox.setEditable(false);
    765         Dictionary.registerTooltip(level_combobox, "CDM.IndexManager.Level_Tooltip");
    766         labels_pane.add(level_label, BorderLayout.SOUTH);
    767         boxes_pane.add(level_combobox, BorderLayout.SOUTH);
    768 
    769         } else {
    770         allfields_pane = new JPanel();
    771         allfields_box = new JCheckBox();
    772         JLabel allfields_label = new JLabel();
    773         Dictionary.registerText(allfields_label, "CDM.IndexManager.Allfields_Index");
    774         allfields_pane.setLayout(new BorderLayout());
    775         allfields_pane.add(allfields_box, BorderLayout.WEST);
    776         allfields_pane.add(allfields_label, BorderLayout.CENTER);
    777        
    778 
    779         }
    780         // if we are editing, fill in the controls
    781         if (existing_index !=null) {
    782         ArrayList sources = existing_index.getSources();
    783         if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) {
    784             source_list.setEnabled(false);
    785             allfields_box.setSelected(true);
     646    private class NewIndexPrompt
     647        extends ModalDialog {
     648
     649        NewIndexPrompt new_index_prompt = null;
     650   
     651        private CheckList source_list;
     652        // mg uses a level box
     653        private JComboBox level_combobox;
     654        // mgpp has a allfields selector
     655        private JCheckBox allfields_box;
     656
     657        private JButton add_button;
     658        private JButton replace_button;
     659        private JButton add_all_button;
     660        private JButton cancel_button;
     661
     662        // some panels that we need to manipulate later on
     663        private JPanel boxes_pane;
     664        private JPanel labels_pane;
     665        private JLabel level_label;
     666        private JPanel allfields_pane;
     667
     668        private boolean mgpp_enabled = false;
     669        private boolean editing = false;
     670   
     671        public NewIndexPrompt(String build_type, Index existing_index) {
     672        super(Gatherer.g_man, true);
     673        new_index_prompt = this;
     674
     675        setModal(true);
     676        setSize(PROMPT_SIZE);
     677        if (existing_index != null) {
     678            setTitle (Dictionary.get("CDM.IndexManager.Edit_Index"));
     679            editing = true;
    786680        } else {
    787             source_list.setTickedObjects(sources.toArray());
    788             source_list.setEnabled(true);
    789         }
     681            setTitle(Dictionary.get("CDM.IndexManager.New_Index"));
     682        }
     683       
     684        if (build_type.equals(BuildTypeManager.BUILD_TYPE_MGPP) || build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
     685            mgpp_enabled = true;
     686        }
     687        JPanel content_pane = (JPanel)this.getContentPane();
     688        ArrayList new_data = new ArrayList();
     689        new_data.add(CollectionConfiguration.TEXT_STR);
     690        new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
     691
     692        JPanel details_pane = new JPanel();
     693        labels_pane = new JPanel();
     694        boxes_pane = new JPanel();
     695
     696        JPanel main_index_pane = new JPanel();
     697
     698        JLabel source_label = new JLabel();
     699        Dictionary.registerText(source_label, "CDM.IndexManager.Source");
     700        source_list = new CheckList(false);
     701        source_list.setListData(new_data);
     702        Dictionary.registerTooltip(source_list, "CDM.IndexManager.Source_Tooltip");
     703        source_list.addListSelectionListener(new SourceListListener());
     704
     705        JPanel button_pane = new JPanel();
     706        if (existing_index != null) {
     707            button_pane.setLayout(new GridLayout(1,2,5,0));
     708            replace_button = new GLIButton();
     709            replace_button.setEnabled(false);
     710            Dictionary.registerBoth(replace_button, "CDM.IndexManager.Replace_Index", "CDM.IndexManager.Replace_Index_Tooltip");
     711            button_pane.add(replace_button);
     712            replace_button.addActionListener(new ReplaceIndexListener());
     713        } else {
     714            button_pane.setLayout(new GridLayout(1,3,5,0));
     715            add_button = new GLIButton();
     716            add_button.setEnabled(false);
     717            add_button.setMnemonic(KeyEvent.VK_A);
     718            Dictionary.registerBoth(add_button, "CDM.IndexManager.Add_Index", "CDM.IndexManager.Add_Index_Tooltip");
     719            add_button.addActionListener(new AddIndexListener());
     720
     721       
     722            add_all_button = new GLIButton();
     723            add_all_button.setEnabled(true);
     724            add_all_button.setMnemonic(KeyEvent.VK_L);
     725            Dictionary.registerBoth(add_all_button, "CDM.IndexManager.Add_All", "CDM.IndexManager.Add_All_Tooltip");
     726            add_all_button.addActionListener(new AddAllIndexActionListener());     
     727            button_pane.add(add_button);
     728            button_pane.add(add_all_button);
     729
     730        }
     731        cancel_button = new GLIButton();
     732        cancel_button.setEnabled(true);
     733        Dictionary.registerBoth(cancel_button, "General.Cancel", "General.Cancel");
     734        cancel_button.addActionListener(new ActionListener() {
     735            public void actionPerformed(ActionEvent event) {
     736                new_index_prompt.dispose();
     737            }
     738            });
     739        button_pane.add(cancel_button);
     740
     741        // Layout
     742        labels_pane.setLayout(new BorderLayout());
     743        labels_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5));
     744        labels_pane.add(source_label, BorderLayout.CENTER);
     745       
     746        boxes_pane.setLayout(new BorderLayout());
     747        boxes_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
     748       
     749        details_pane.setLayout(new BorderLayout());
     750        details_pane.add(labels_pane, BorderLayout.WEST);
     751        details_pane.add(boxes_pane, BorderLayout.CENTER);
     752
     753
     754        // do type specific stuff
    790755        if (!mgpp_enabled) {
    791             level_combobox.setSelectedIndex(existing_index.getLevel());
    792         }
    793        
    794         }
    795         content_pane.setLayout(new BorderLayout());
    796         content_pane.add(details_pane, BorderLayout.CENTER);
    797         content_pane.add(button_pane, BorderLayout.SOUTH);
    798        
    799         // Display on screen.
    800         Dimension screen_size = Configuration.screen_size;
    801         setLocation((screen_size.width - PROMPT_SIZE.width) / 2, (screen_size.height - PROMPT_SIZE.height) / 2);
    802         screen_size = null;
    803         setVisible(true);
    804        
    805     }
    806 
    807     /** Method which actually forces the dialog to be shown on screen.
    808      * @return <i>true</i> if the user completed configuration and pressed ok, <i>false</i> otherwise.
    809      */
    810     public boolean display() {
    811         setVisible(true);
    812         return true;
    813         //    return success;
    814     }
    815    
    816     public void destroy() {
    817     }
    818 
    819         private class AddIndexListener
    820         implements ActionListener
    821     {
    822         public void actionPerformed(ActionEvent event)
     756
     757            level_label = new JLabel();
     758            Dictionary.registerText(level_label, "CDM.IndexManager.Level");
     759            level_combobox = new JComboBox();
     760            level_combobox.setPreferredSize(FIELD_SIZE);
     761            level_combobox.addItem(CollectionConfiguration.DOCUMENT_STR);//Dictionary.get("CDM.IndexManager.Document"));
     762            level_combobox.addItem(CollectionConfiguration.PARAGRAPH_STR);//Dictionary.get("CDM.IndexManager.Paragraph"));
     763            level_combobox.addItem(CollectionConfiguration.SECTION_STR);//Dictionary.get("CDM.IndexManager.Section"));
     764            level_combobox.setEditable(false);
     765            Dictionary.registerTooltip(level_combobox, "CDM.IndexManager.Level_Tooltip");
     766            labels_pane.add(level_label, BorderLayout.SOUTH);
     767            boxes_pane.add(level_combobox, BorderLayout.SOUTH);
     768
     769        } else {
     770            allfields_pane = new JPanel();
     771            allfields_box = new JCheckBox();
     772            JLabel allfields_label = new JLabel();
     773            Dictionary.registerText(allfields_label, "CDM.IndexManager.Allfields_Index");
     774            allfields_pane.setLayout(new BorderLayout());
     775            allfields_pane.add(allfields_box, BorderLayout.WEST);
     776            allfields_pane.add(allfields_label, BorderLayout.CENTER);
     777       
     778
     779        }
     780        // if we are editing, fill in the controls
     781        if (existing_index !=null) {
     782            ArrayList sources = existing_index.getSources();
     783            if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) {
     784            source_list.setEnabled(false);
     785            allfields_box.setSelected(true);
     786            } else {
     787            source_list.setTickedObjects(sources.toArray());
     788            source_list.setEnabled(true);
     789            }
     790            if (!mgpp_enabled) {
     791            level_combobox.setSelectedIndex(existing_index.getLevel());
     792            }
     793       
     794        }
     795        content_pane.setLayout(new BorderLayout());
     796        content_pane.add(details_pane, BorderLayout.CENTER);
     797        content_pane.add(button_pane, BorderLayout.SOUTH);
     798       
     799        // Display on screen.
     800        Dimension screen_size = Configuration.screen_size;
     801        setLocation((screen_size.width - PROMPT_SIZE.width) / 2, (screen_size.height - PROMPT_SIZE.height) / 2);
     802        screen_size = null;
     803        setVisible(true);
     804       
     805        }
     806
     807        /** Method which actually forces the dialog to be shown on screen.
     808         * @return <i>true</i> if the user completed configuration and pressed ok, <i>false</i> otherwise.
     809         */
     810        public boolean display() {
     811        setVisible(true);
     812        return true;
     813        //    return success;
     814        }
     815   
     816        public void destroy() {
     817        }
     818
     819        private class AddIndexListener
     820        implements ActionListener
    823821        {
    824         Index index;
    825         if (mgpp_enabled && allfields_box.isSelected()) {
    826             ArrayList sources = new ArrayList();
    827             sources.add(ALLFIELDS);
    828             index = new Index(sources);
    829         }
    830         else if (!source_list.isNothingTicked()) {
    831             ArrayList sources = source_list.getTicked();
    832             if(mgpp_enabled) {
     822        public void actionPerformed(ActionEvent event)
     823        {
     824            Index index;
     825            if (mgpp_enabled && allfields_box.isSelected()) {
     826            ArrayList sources = new ArrayList();
     827            sources.add(ALLFIELDS);
    833828            index = new Index(sources);
     829            }
     830            else if (!source_list.isNothingTicked()) {
     831            ArrayList sources = source_list.getTicked();
     832            if(mgpp_enabled) {
     833                index = new Index(sources);
     834            } else {
     835                index = new Index(level_combobox.getSelectedIndex(), sources);
     836            }
    834837            } else {
    835             index = new Index(level_combobox.getSelectedIndex(), sources);
    836             }
    837         } else {
    838             return;
    839         }
     838            return;
     839            }
    840840         
    841         // Before we add the index to the model, we have to add a default collection metadata for this
    842         CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
    843         metadatum.setValue(index.getID());
    844        
    845         // Finally, add the index
    846         addIndex(index, metadatum);
    847         index_list.setSelectedValue(index, true);
    848         new_index_prompt.dispose();
    849         }
    850     }
    851 
    852     /** add all sources as indexes. for MG, this adds them in one combined
    853         index, for MGPP this adds them as individual indexes (fields) */
    854     private class AddAllIndexActionListener
    855         implements ActionListener {
    856 
    857         public void actionPerformed(ActionEvent event) {
    858         ArrayList all_sources = source_list.getAll();
    859         if (!mgpp_enabled) {
    860             Index index = new Index(level_combobox.getSelectedIndex(), all_sources);
    861             if (!index_model.contains(index)) {
    862             CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
    863             metadatum.setValue("all fields"); // need a good name
    864             addIndex(index, metadatum);
    865             }
    866             all_sources = null;
    867             index = null;
    868             return;
    869         }
    870        
    871         ArrayList new_sources = new ArrayList();
    872         for(int i = 0; i < all_sources.size(); i++) {
    873             Object source = all_sources.get(i);
    874 
    875             // Create new index
    876             new_sources.clear();
    877             new_sources.add(source);
    878             Index index = new Index(new_sources);
    879             if(!index_model.contains(index)) {
    880             // Determine the metadatum value
    881             String name = source.toString();
    882             if(name.startsWith(StaticStrings.EXTRACTED_NAMESPACE)) {
    883                 name = name.substring(StaticStrings.EXTRACTED_NAMESPACE.length());
    884             }
    885             // Create new metadatum
    886             CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
    887             metadatum.setValue(name);
    888             name = null;
    889             // Assign new index
    890             addIndex(index, metadatum);
    891             }
    892             source = null;
    893             index = null;
    894         }
    895         new_sources = null;
    896         new_index_prompt.dispose();
    897        
    898         }
    899     }
    900    
    901     private class SourceListListener
    902         implements ListSelectionListener {
    903        
    904         public void valueChanged(ListSelectionEvent event) {
    905         if (event.getValueIsAdjusting()) {
    906             return;
    907         }
    908         boolean enabled = !source_list.isNothingTicked();
    909         if (editing) {
    910             replace_button.setEnabled(enabled);
    911         } else {
    912             add_button.setEnabled(enabled);
    913         }
    914        
    915         }
    916     }
    917    
    918 
    919     private class ReplaceIndexListener
    920         implements ActionListener {
    921        
    922         public void actionPerformed(ActionEvent event) {
    923        
    924         ArrayList sources;
    925         Index index = null;
    926         if (mgpp_enabled && allfields_box.isSelected()) {
    927             sources = new ArrayList();
    928             sources.add(ALLFIELDS);
    929             index = new Index(sources);
    930         }
    931         else if (!source_list.isNothingTicked()) {
    932             sources = source_list.getTicked();
    933             if (mgpp_enabled) {
    934             index = new Index(sources);
    935             } else {
    936             index = new Index(level_combobox.getSelectedIndex(), sources);
    937             }
    938         }
    939         if (index != null) {
    940             // Create the new collection meta
     841            // Before we add the index to the model, we have to add a default collection metadata for this
    941842            CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
    942843            metadatum.setValue(index.getID());
     844       
     845            // Finally, add the index
     846            addIndex(index, metadatum);
     847            index_list.setSelectedValue(index, true);
     848            new_index_prompt.dispose();
     849        }
     850        }
     851
     852        /** add all sources as indexes. for MG, this adds them in one combined
     853        index, for MGPP this adds them as individual indexes (fields) */
     854        private class AddAllIndexActionListener
     855        implements ActionListener {
     856
     857        public void actionPerformed(ActionEvent event) {
     858            ArrayList all_sources = source_list.getAll();
     859            if (!mgpp_enabled) {
     860            Index index = new Index(level_combobox.getSelectedIndex(), all_sources);
     861            if (!index_model.contains(index)) {
     862                CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
     863                metadatum.setValue("all fields"); // need a good name
     864                addIndex(index, metadatum);
     865            }
     866            all_sources = null;
     867            index = null;
     868            return;
     869            }
     870       
     871            ArrayList new_sources = new ArrayList();
     872            for(int i = 0; i < all_sources.size(); i++) {
     873            Object source = all_sources.get(i);
     874
     875            // Create new index
     876            new_sources.clear();
     877            new_sources.add(source);
     878            Index index = new Index(new_sources);
     879            if(!index_model.contains(index)) {
     880                // Determine the metadatum value
     881                String name = source.toString();
     882                if(name.startsWith(StaticStrings.EXTRACTED_NAMESPACE)) {
     883                name = name.substring(StaticStrings.EXTRACTED_NAMESPACE.length());
     884                }
     885                // Create new metadatum
     886                CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
     887                metadatum.setValue(name);
     888                name = null;
     889                // Assign new index
     890                addIndex(index, metadatum);
     891            }
     892            source = null;
     893            index = null;
     894            }
     895            new_sources = null;
     896            new_index_prompt.dispose();
     897       
     898        }
     899        }
     900   
     901        private class SourceListListener
     902        implements ListSelectionListener {
     903       
     904        public void valueChanged(ListSelectionEvent event) {
     905            if (event.getValueIsAdjusting()) {
     906            return;
     907            }
     908            boolean enabled = !source_list.isNothingTicked();
     909            if (editing) {
     910            replace_button.setEnabled(enabled);
     911            } else {
     912            add_button.setEnabled(enabled);
     913            }
     914       
     915        }
     916        }
     917   
     918
     919        private class ReplaceIndexListener
     920        implements ActionListener {
     921       
     922        public void actionPerformed(ActionEvent event) {
     923       
     924            ArrayList sources;
     925            Index index = null;
     926            if (mgpp_enabled && allfields_box.isSelected()) {
     927            sources = new ArrayList();
     928            sources.add(ALLFIELDS);
     929            index = new Index(sources);
     930            }
     931            else if (!source_list.isNothingTicked()) {
     932            sources = source_list.getTicked();
     933            if (mgpp_enabled) {
     934                index = new Index(sources);
     935            } else {
     936                index = new Index(level_combobox.getSelectedIndex(), sources);
     937            }
     938            }
     939            if (index != null) {
     940            // Create the new collection meta
     941            CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
     942            metadatum.setValue(index.getID());
    943943           
    944             // replace the index
    945             replaceIndex((Index) index_list.getSelectedValue(), index, metadatum);
    946             index_list.setSelectedValue(index, true);
     944            // replace the index
     945            replaceIndex((Index) index_list.getSelectedValue(), index, metadatum);
     946            index_list.setSelectedValue(index, true);
    947947           
    948         }
    949         new_index_prompt.dispose();
    950        
    951         }
    952     }
    953    
    954     }
    955    
    956    
     948            }
     949            new_index_prompt.dispose();
     950       
     951        }
     952        }
     953    }
     954    }
    957955}
    958 
    959 }
Note: See TracChangeset for help on using the changeset viewer.