Changeset 36193


Ignore:
Timestamp:
2022-05-16T14:47:40+12:00 (5 months ago)
Author:
kjdon
Message:

initial work - not yet finished - on updating translations to handle new searchmeta types

File:
1 edited

Legend:

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

    r19798 r36193  
    5252    static final private Dimension COMPONENT_SIZE = new Dimension(225,25);
    5353    static final private int LANGUAGE_WIDTH = 75;
    54     static final private String GENERAL_STR = "General:";
    55     static final private String INDEX_STR = "Index:";
    56     static final private String LEVEL_STR = "Level:";
    57     static final private String PARTITION_STR = "Partitions:";
     54    // static final private String GENERAL_STR = "General:";
     55    // static final private String INDEX_STR = "Index:";
     56    // static final private String LEVEL_STR = "Level:";
     57    // static final private String PARTITION_STR = "Partitions:";
    5858
    5959    public TranslationView() {
     
    8282    }
    8383
     84    private CollectionMeta newCollOrSearchMeta(String name, String type, String language) {
     85    return newCollOrSearchMeta(name, type, language, false);
     86    }
     87
     88    private CollectionMeta newCollOrSearchMeta(String name, String type, String language, boolean dummy) {
     89    CollectionMeta meta;
     90    if (type != null) {
     91        meta = new SearchMeta(name, type, language, dummy);
     92    } else {
     93        meta = new CollectionMeta(name, language, dummy);
     94    }
     95    return meta;
     96
     97
     98    }
     99    private TreeSet getLanguages() {
     100    TreeSet lang_set = CollectionDesignManager.collectionmeta_manager.getLanguages();
     101        System.err.println("coll lang set = "+lang_set);
     102        System.err.println("search lang_set = "+CollectionDesignManager.searchmeta_manager.getLanguages());
     103    lang_set.addAll(CollectionDesignManager.searchmeta_manager.getLanguages());
     104        System.err.println("all lang set = "+lang_set);
     105    return lang_set;
     106    }
    84107    private Object[] getFeaturesList() {
    85108    ArrayList features_model = new ArrayList();
     109
     110    // add general metadata
     111    ArrayList general_metadata = CollectionDesignManager.collectionmeta_manager.getMetadata();
     112    for(int i = 0; i < general_metadata.size(); i++) {
     113        CollectionMeta metadata = (CollectionMeta) general_metadata.get(i);
     114        if(!metadata.isSpecial()) {
     115        Object bob = new BobTheMagicalComparableWrapper(metadata.getName(), null);
     116        if(!features_model.contains(bob)) {
     117            features_model.add(bob);
     118        }
     119        }
     120    }
    86121
    87122    // Add the indexes
     
    89124    int indexes_size = indexes.size();
    90125    for(int j = 0; j < indexes_size; j++) {
    91         Object bob = new BobTheMagicalComparableWrapper(indexes.get(j));
     126        Object bob = new BobTheMagicalComparableWrapper(indexes.get(j), SearchMeta.TYPE_INDEX);
    92127        if(!features_model.contains(bob)) {
    93128        features_model.add(bob);
     
    99134      int levels_size = levels.size();
    100135      for (int j=0; j<levels.size(); j++) {
    101         Object bob = new BobTheMagicalComparableWrapper(levels.get(j));
     136          Object bob = new BobTheMagicalComparableWrapper(levels.get(j), SearchMeta.TYPE_LEVEL);
     137        if(!features_model.contains(bob)) {
     138          features_model.add(bob);
     139        }
     140      }
     141    }
     142    // Add the sortfields, if any
     143    ArrayList sortfields = CollectionDesignManager.index_manager.getSortFields();
     144    if (sortfields !=null) {
     145      int sort_size = sortfields.size();
     146      for (int j=0; j<sort_size; j++) {
     147          Object bob = new BobTheMagicalComparableWrapper(sortfields.get(j), SearchMeta.TYPE_SORT);
     148        if(!features_model.contains(bob)) {
     149          features_model.add(bob);
     150        }
     151      }
     152    }
     153    // Add the facets, if any
     154    ArrayList facets = CollectionDesignManager.index_manager.getFacets();
     155    if (facets !=null) {
     156      int facet_size = facets.size();
     157      for (int j=0; j<facet_size; j++) {
     158          Object bob = new BobTheMagicalComparableWrapper(facets.get(j), SearchMeta.TYPE_FACET);
    102159        if(!features_model.contains(bob)) {
    103160          features_model.add(bob);
     
    109166    int subindexes_size = subindexes.size();
    110167    for(int j = 0; j < subindexes_size; j++) {
    111         Object bob = new BobTheMagicalComparableWrapper(subindexes.get(j));
     168        Object bob = new BobTheMagicalComparableWrapper(subindexes.get(j), SearchMeta.TYPE_PARTITION);
    112169        if(!features_model.contains(bob)) {
    113170        features_model.add(bob);
     
    115172    }
    116173
    117     // Finally we add any remaining metadata as general
    118     ArrayList general_metadata = CollectionDesignManager.collectionmeta_manager.getMetadata();
    119     for(int i = 0; i < general_metadata.size(); i++) {
    120         CollectionMeta metadata = (CollectionMeta) general_metadata.get(i);
    121         if(!metadata.isSpecial()) {
    122         Object bob = new BobTheMagicalComparableWrapper(metadata.getName());
    123         if(!features_model.contains(bob)) {
    124             features_model.add(bob);
    125         }
    126         }
    127     }
    128 
    129     Collections.sort(features_model);
     174    ArrayList languages = CollectionDesignManager.language_manager.getLanguages();
     175    int languages_size = languages.size();
     176    for(int j = 0; j < languages_size; j++) {
     177        Object bob = new BobTheMagicalComparableWrapper(languages.get(j), SearchMeta.TYPE_LANGUAGE);
     178        if(!features_model.contains(bob)) {
     179        features_model.add(bob);
     180        }
     181    }
     182   
     183    //Collections.sort(features_model); we want them in this order I reckon
    130184
    131185    return features_model.toArray();
     
    136190    private Object content;
    137191    private String text;
    138     BobTheMagicalComparableWrapper(Object content) {
     192    private String type;
     193    BobTheMagicalComparableWrapper(Object content, String type) {
    139194        this.content = content;
     195        this.type = type;
    140196    }
    141197    public int compareTo(Object object) {
     
    151207    /** Equals is used by contains and since we want to prevent double up of metadata we compare differently than in compareTo. */
    152208    public boolean equals(Object object) {
    153         return (object != null && content.toString().equals(((BobTheMagicalComparableWrapper)object).getContent().toString()));
     209        BobTheMagicalComparableWrapper bob = (BobTheMagicalComparableWrapper)object;
     210        return (object != null && content.toString().equals(bob.getContent().toString()) && ((type == null && bob.getType()==null) || type.equals(bob.getType())));
    154211    }
    155212
     
    158215    }
    159216
    160     public String getName() {
     217        public String getName() {
     218        if (content instanceof IndexOption) {
     219           return ((IndexOption)content).getName();
     220        }
     221        if (content instanceof Index) {
     222            return ((Index)content).getID();
     223        }
     224        if (content instanceof SubcollectionIndex) {
     225            return ((SubcollectionIndex)content).getID();
     226        }
     227        return content.toString();
     228        }
     229
     230        public String getType() {
     231        return type;
     232        }
     233    public String getNameOld() {
    161234        if(content instanceof Index) {
    162235        return StaticStrings.STOP_CHARACTER + ((Index)content).getID();
     
    175248
    176249    public String toString() {
     250
    177251        if(text == null) {
    178252        String temp = content.toString();
    179         if(temp.indexOf(StaticStrings.SPACE_CHARACTER) != -1) {
    180             temp = temp.substring(0, temp.indexOf(StaticStrings.SPACE_CHARACTER));
    181         }
    182         if(content instanceof Index) {
    183             text = INDEX_STR + temp;
    184         }
    185         else if (content instanceof IndexOption) {
    186           text = LEVEL_STR + temp;
    187         }
    188         else if(content instanceof SubcollectionIndex) {
    189             text = PARTITION_STR + temp;
    190         }
    191         else {
    192             text = GENERAL_STR + temp;
    193         }
     253        if (type != null) {
     254            text = Dictionary.get("CDM.SearchMetadataManager.Type_"+type)+": "+temp;
     255        } else {
     256            text = Dictionary.get("CDM.TranslationManager.Type_general")+": "+temp;
     257        }
     258        // if(temp.indexOf(StaticStrings.SPACE_CHARACTER) != -1) {
     259        //     temp = temp.substring(0, temp.indexOf(StaticStrings.SPACE_CHARACTER));
     260        // }
     261        // if(content instanceof Index) {
     262        //     text = INDEX_STR + temp;
     263        // }
     264        // else if (content instanceof IndexOption) {
     265        //   text = LEVEL_STR + temp;
     266        // }
     267        // else if(content instanceof SubcollectionIndex) {
     268        //     text = PARTITION_STR + temp;
     269        // }
     270        // else {
     271        //     text = GENERAL_STR + temp;
     272        // }
    194273        }
    195274        return text;
     
    214293    TranslationControl() {
    215294            this.setComponentOrientation(Dictionary.getOrientation());
    216         fragment_table_model = new FragmentTableModel("", new TreeSet(), new ArrayList());
     295        fragment_table_model = new FragmentTableModel("", "", new TreeSet(), new ArrayList());
    217296        // Creation
    218297        JPanel header_panel = new DesignPaneHeader("CDM.GUI.Translation", "translatetext");
     
    396475            BobTheMagicalComparableWrapper selected_feature = (BobTheMagicalComparableWrapper)features_list.getSelectedValue();
    397476            String language = (String) language_combobox.getSelectedItem();
    398             CollectionMeta metadatum = new CollectionMeta(selected_feature.getName(), language);
     477            CollectionMeta metadatum = newCollOrSearchMeta(selected_feature.getName(), selected_feature.getType(), language); //new CollectionMeta(selected_feature.getName(), language);
    399478            metadatum.setValue(translation_text);
    400             CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
    401479            fragment_table.clearSelection();
    402             ArrayList metadata = CollectionDesignManager.collectionmeta_manager.getMetadata(selected_feature.getName());
    403             fragment_table_model.setData(selected_feature.getName(), CollectionDesignManager.collectionmeta_manager.getLanguages(), metadata);
     480            ArrayList metadata;
     481            if (metadatum instanceof SearchMeta) {
     482            System.err.println("adding meta to search" + metadatum);
     483            CollectionDesignManager.searchmeta_manager.addMetadatum(metadatum);
     484           
     485            metadata = CollectionDesignManager.searchmeta_manager.getMetadata(selected_feature.getName(), selected_feature.getType());
     486                        System.err.println("metadata = "+metadata);
     487            } else {
     488            // just a general metadata
     489            System.err.println("adding meta to general");
     490            CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
     491           
     492            metadata = CollectionDesignManager.collectionmeta_manager.getMetadata(selected_feature.getName());
     493            }
     494                    System.err.println("new langues = "+getLanguages());
     495            fragment_table_model.setData(selected_feature.getName(), selected_feature.getType(), getLanguages(), metadata);
    404496            int index = fragment_table_model.getMetadataIndexByLanguage(language);
    405             ///ystem.err.println("I want to select the row " + index + " out of " + metadata.size());
     497           System.err.println("I want to select the row " + index + " out of " + metadata.size());
    406498            fragment_table.setRowSelectionInterval(index, index);
    407499            metadatum = null;
     
    425517        if((index = fragment_table.getSelectedRow()) != -1) {
    426518            CollectionMeta metadata = fragment_table_model.getMetadata(index);
    427             CollectionDesignManager.collectionmeta_manager.removeMetadata(metadata);
     519            if (metadata instanceof SearchMeta) {
     520            CollectionDesignManager.searchmeta_manager.removeMetadata(metadata);     
     521            } else {
     522            CollectionDesignManager.collectionmeta_manager.removeMetadata(metadata);
     523            }
    428524            fragment_table_model.remove(index);
    429525            // If a remove occured then enable add
     
    469565            BobTheMagicalComparableWrapper selected_feature = (BobTheMagicalComparableWrapper)features_list.getSelectedValue();
    470566            // Retrieve the default language translation, or otherwise the first match, to be default text.
    471             CollectionMeta default_metadata = CollectionDesignManager.collectionmeta_manager.getMetadatum(selected_feature.getName());
     567            CollectionMeta default_metadata;
     568            // Update the text fragment table.
     569            fragment_table.clearSelection();
     570            if (selected_feature.getType() != null) {
     571                default_metadata = CollectionDesignManager.searchmeta_manager.getMetadatum(selected_feature.getName(), selected_feature.getType());
     572                fragment_table_model.setData(selected_feature.getName(), selected_feature.getType(), getLanguages(), CollectionDesignManager.searchmeta_manager.getMetadata(selected_feature.getName()));
     573            } else {
     574                default_metadata = CollectionDesignManager.collectionmeta_manager.getMetadatum(selected_feature.getName());
     575                fragment_table_model.setData(selected_feature.getName(), selected_feature.getType(), getLanguages(), CollectionDesignManager.collectionmeta_manager.getMetadata(selected_feature.getName()));
     576            }
    472577            if(default_metadata != null) {
    473578                default_area.setText(default_metadata.getValue(CollectionMeta.TEXT));
    474579            }
    475             // Update the text fragment table.
    476             fragment_table.clearSelection();
    477             fragment_table_model.setData(selected_feature.getName(), CollectionDesignManager.collectionmeta_manager.getLanguages(), CollectionDesignManager.collectionmeta_manager.getMetadata(selected_feature.getName()));
     580           
    478581            selected_feature = null;
    479582            // Now we check whatever value is currently selected in the combobox to see if it is valid to add.
     
    501604            default_area.setText("");
    502605            fragment_table.clearSelection();
    503             fragment_table_model.setData("", new TreeSet(), new ArrayList());
     606            fragment_table_model.setData("", "", new TreeSet(), new ArrayList());
    504607            translation_area.setText("");
    505608            // Update and disable the text area
     
    552655        private ArrayList metadata;
    553656        private String feature_name;
     657        private String feature_type;
    554658        private TreeSet languages;
    555659
    556         FragmentTableModel(String feature_name, TreeSet languages, ArrayList metadata) {
     660        FragmentTableModel(String feature_name, String feature_type, TreeSet languages, ArrayList metadata) {
    557661        this.feature_name = feature_name;
     662        this.feature_type = feature_type;
    558663        this.languages = languages;
    559664        this.metadata = metadata;
     
    606711            }
    607712        }
    608         return new CollectionMeta(feature_name, language, true);
     713        //return new CollectionMeta(feature_name, language, true);
     714        return newCollOrSearchMeta(feature_name, feature_type, language, true);
    609715        }
    610716
     
    658764        }
    659765
    660         public void setData(String feature_name, TreeSet languages, ArrayList metadata) {
     766        public void setData(String feature_name, String feature_type, TreeSet languages, ArrayList metadata) {
    661767        this.feature_name = feature_name;
     768        this.feature_type = feature_type;
    662769        this.languages = languages;
    663770        this.metadata = metadata;
Note: See TracChangeset for help on using the changeset viewer.