Project

General

Profile

« Previous | Next » 

Revision dbe4fe94

Added by Patrick Plitzner over 5 years ago

ref #6566 Avoid NPE when initializing term preference menu (e4 specific)

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenu.java
30 30

  
31 31
import eu.etaxonomy.cdm.model.common.TermType;
32 32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
33 34

  
34 35
/**
35 36
 * Menu used in the store plugin xml to dynamically generate menu (sub-menu) contribution items
......
46 47
    @Override
47 48
    protected IContributionItem[] getContributionItems() {
48 49
        Collection<IContributionItem> items = new ArrayList<IContributionItem>();
49
	    MenuManager dtMenuManager =
50
	            new MenuManager("Term Editor","eu.etaxonomy.taxeditor.store.definedTermEditorMenu");
51

  
52
	    dtMenuManager.setVisible(true);
53

  
54
	    items.add(dtMenuManager);
55
	    //add Feature and NamedArea to top level
56
	    dtMenuManager.add(addChildTermsToMenuManager(TermType.Feature));
57
	    dtMenuManager.add(addChildTermsToMenuManager(TermType.NamedArea));
58
	    dtMenuManager.add(new Separator());
59

  
60
	    MenuManager otherMenuManager =
61
                new MenuManager("Others","eu.etaxonomy.taxeditor.store.term.other.menu");
62
	    otherMenuManager.setVisible(true);
63
	    dtMenuManager.add(otherMenuManager);
64

  
65
	    List<TermType> ttList = new ArrayList<TermType>(EnumSet.allOf(TermType.class));
66
	    Collections.sort(ttList,new SortByTermTypeMessage());
67
	    for (TermType tt : ttList)
68
	    {
69
	        //skip Feature and NamedArea as they have already been added to top level
70
	        if(tt.equals(TermType.Feature) || tt.equals(TermType.NamedArea)){
71
	            continue;
72
	        }
73
	        // if term type has a parent, do not add it
74
	        // it will be added in the recursive call
75
	        if(tt.getKindOf() == null) {
76
	            IContributionItem ici = addChildTermsToMenuManager(tt);
77
	            if(ici != null) {
78
	                otherMenuManager.add(ici);
79
	            }
80
	        }
81
	    }
50
        if(CdmStore.isActive()){
51
            MenuManager dtMenuManager =
52
                    new MenuManager("Term Editor","eu.etaxonomy.taxeditor.store.definedTermEditorMenu");
53

  
54
            dtMenuManager.setVisible(true);
55

  
56
            items.add(dtMenuManager);
57
            //add Feature and NamedArea to top level
58
            dtMenuManager.add(addChildTermsToMenuManager(TermType.Feature));
59
            dtMenuManager.add(addChildTermsToMenuManager(TermType.NamedArea));
60
            dtMenuManager.add(new Separator());
61

  
62
            MenuManager otherMenuManager =
63
                    new MenuManager("Others","eu.etaxonomy.taxeditor.store.term.other.menu");
64
            otherMenuManager.setVisible(true);
65
            dtMenuManager.add(otherMenuManager);
66

  
67
            List<TermType> ttList = new ArrayList<TermType>(EnumSet.allOf(TermType.class));
68
            Collections.sort(ttList,new SortByTermTypeMessage());
69
            for (TermType tt : ttList)
70
            {
71
                //skip Feature and NamedArea as they have already been added to top level
72
                if(tt.equals(TermType.Feature) || tt.equals(TermType.NamedArea)){
73
                    continue;
74
                }
75
                // if term type has a parent, do not add it
76
                // it will be added in the recursive call
77
                if(tt.getKindOf() == null) {
78
                    IContributionItem ici = addChildTermsToMenuManager(tt);
79
                    if(ici != null) {
80
                        otherMenuManager.add(ici);
81
                    }
82
                }
83
            }
84
        }
82 85
	    return items.toArray(new IContributionItem[]{});
83 86
	}
84 87

  

Also available in: Unified diff