Revision 75dd6927
Added by Patrick Plitzner over 7 years ago
eu.etaxonomy.taxeditor.store/plugin.xml | ||
---|---|---|
415 | 415 |
</command> |
416 | 416 |
</menu> |
417 | 417 |
</menuContribution> |
418 |
<menuContribution |
|
419 |
class="eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermMenuFactory" |
|
420 |
locationURI="menu:org.eclipse.ui.main.menu.window?before=eu.etaxonomy.taxeditor.application.windowMenu.last"> |
|
418 |
<menuContribution |
|
419 |
allPopups="false" |
|
420 |
locationURI="menu:org.eclipse.ui.main.menu.window?before=eu.etaxonomy.taxeditor.application.windowMenu.last"> |
|
421 |
<dynamic |
|
422 |
class="eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermMenu" |
|
423 |
id="eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermMenu"> |
|
424 |
<visibleWhen |
|
425 |
checkEnabled="true"> |
|
426 |
<reference |
|
427 |
definitionId="isCdmStoreConnected"> |
|
428 |
</reference> |
|
429 |
</visibleWhen> |
|
430 |
</dynamic> |
|
421 | 431 |
</menuContribution> |
422 | 432 |
<menuContribution |
423 | 433 |
locationURI="menu:org.eclipse.ui.main.menu.file?after=eu.etaxonomy.taxeditor.application.filemenu.io"> |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenu.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.editor.definedterm; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.Collection; |
|
15 |
import java.util.Collections; |
|
16 |
import java.util.Comparator; |
|
17 |
import java.util.EnumSet; |
|
18 |
import java.util.HashMap; |
|
19 |
import java.util.List; |
|
20 |
import java.util.Map; |
|
21 |
import java.util.Set; |
|
22 |
|
|
23 |
import org.eclipse.jface.action.IContributionItem; |
|
24 |
import org.eclipse.jface.action.MenuManager; |
|
25 |
import org.eclipse.jface.action.Separator; |
|
26 |
import org.eclipse.swt.SWT; |
|
27 |
import org.eclipse.ui.PlatformUI; |
|
28 |
import org.eclipse.ui.actions.CompoundContributionItem; |
|
29 |
import org.eclipse.ui.menus.CommandContributionItem; |
|
30 |
import org.eclipse.ui.menus.CommandContributionItemParameter; |
|
31 |
|
|
32 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
33 |
|
|
34 |
/** |
|
35 |
* Menu used in the store plugin xml to dynamically generate menu (sub-menu) contribution items |
|
36 |
* for term types which when clicked open the defined term editor for the chosen term type |
|
37 |
* |
|
38 |
* @author pplitzner |
|
39 |
* @date 21 Jul 2015 |
|
40 |
* |
|
41 |
*/ |
|
42 |
|
|
43 |
public class DefinedTermMenu extends CompoundContributionItem { |
|
44 |
|
|
45 |
|
|
46 |
@Override |
|
47 |
protected IContributionItem[] getContributionItems() { |
|
48 |
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 |
List<TermType> ttList = new ArrayList<TermType>(EnumSet.allOf(TermType.class)); |
|
56 |
Collections.sort(ttList,new SortByTermTypeMessage()); |
|
57 |
for (TermType tt : ttList) |
|
58 |
{ |
|
59 |
// if term type has a parent, do not add it |
|
60 |
// it will be added in the recursive call |
|
61 |
if(tt.getKindOf() == null) { |
|
62 |
IContributionItem ici = addChildTermsToMenuManager(tt); |
|
63 |
if(ici != null) { |
|
64 |
dtMenuManager.add(ici); |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
return items.toArray(new IContributionItem[]{}); |
|
69 |
} |
|
70 |
|
|
71 |
private IContributionItem addChildTermsToMenuManager(TermType termType) { |
|
72 |
|
|
73 |
//FIXME : need a better way to find out if a term type can be editable (ticket 3853) |
|
74 |
if(termType.getEmptyDefinedTermBase() != null) { |
|
75 |
Set<TermType> children = termType.getGeneralizationOf(); |
|
76 |
// term type has no children, so create menu item |
|
77 |
if(children.isEmpty()) { |
|
78 |
return createMenuItem(termType); |
|
79 |
} |
|
80 |
// term type has children, so create sub menu |
|
81 |
MenuManager dtMenuManager = |
|
82 |
new MenuManager(termType.getMessage(),"eu.etaxonomy.taxeditor.store." + termType.getKey() + "Menu"); |
|
83 |
dtMenuManager.setVisible(true); |
|
84 |
dtMenuManager.add(createDefaultMenuItem(termType)); |
|
85 |
|
|
86 |
Separator sep = new Separator(); |
|
87 |
dtMenuManager.add(sep); |
|
88 |
// add child items to the sub menu |
|
89 |
for(TermType tt : children) { |
|
90 |
IContributionItem item = addChildTermsToMenuManager(tt); |
|
91 |
if(item != null) { |
|
92 |
dtMenuManager.add(item); |
|
93 |
} |
|
94 |
} |
|
95 |
return dtMenuManager; |
|
96 |
} else { |
|
97 |
return null; |
|
98 |
} |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
private CommandContributionItem createMenuItem(TermType termType) { |
|
103 |
|
|
104 |
Map<String, String> params = new HashMap<String, String>(); |
|
105 |
params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", |
|
106 |
termType.getUuid().toString()); |
|
107 |
|
|
108 |
CommandContributionItemParameter p = new CommandContributionItemParameter( |
|
109 |
PlatformUI.getWorkbench(), |
|
110 |
"", |
|
111 |
"eu.etaxonomy.taxeditor.store.openDefinedTermEditor", |
|
112 |
params, |
|
113 |
null, |
|
114 |
null, |
|
115 |
null, |
|
116 |
termType.getMessage(), |
|
117 |
"", |
|
118 |
"", |
|
119 |
SWT.PUSH, |
|
120 |
"", |
|
121 |
true); |
|
122 |
|
|
123 |
CommandContributionItem item = new CommandContributionItem(p); |
|
124 |
return item; |
|
125 |
|
|
126 |
} |
|
127 |
|
|
128 |
private CommandContributionItem createDefaultMenuItem(TermType termType) { |
|
129 |
|
|
130 |
Map<String, String> params = new HashMap<String, String>(); |
|
131 |
params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", |
|
132 |
termType.getUuid().toString()); |
|
133 |
|
|
134 |
CommandContributionItemParameter p = new CommandContributionItemParameter( |
|
135 |
PlatformUI.getWorkbench(), |
|
136 |
"", |
|
137 |
"eu.etaxonomy.taxeditor.store.openDefinedTermEditor", |
|
138 |
params, |
|
139 |
null, |
|
140 |
null, |
|
141 |
null, |
|
142 |
"Other " + termType.getMessage() + "s", |
|
143 |
"", |
|
144 |
"", |
|
145 |
SWT.PUSH, |
|
146 |
"", |
|
147 |
true); |
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
CommandContributionItem item = new CommandContributionItem(p); |
|
152 |
return item; |
|
153 |
|
|
154 |
} |
|
155 |
|
|
156 |
private class SortByTermTypeMessage implements Comparator<TermType> { |
|
157 |
@Override |
|
158 |
public int compare(TermType t1, TermType t2) { |
|
159 |
return t1.getMessage().compareTo(t2.getMessage()); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
|
|
164 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermMenuFactory.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.editor.definedterm; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.Collections; |
|
15 |
import java.util.Comparator; |
|
16 |
import java.util.EnumSet; |
|
17 |
import java.util.HashMap; |
|
18 |
import java.util.List; |
|
19 |
import java.util.Map; |
|
20 |
import java.util.Set; |
|
21 |
|
|
22 |
import org.eclipse.jface.action.IContributionItem; |
|
23 |
import org.eclipse.jface.action.MenuManager; |
|
24 |
import org.eclipse.jface.action.Separator; |
|
25 |
import org.eclipse.swt.SWT; |
|
26 |
import org.eclipse.ui.menus.CommandContributionItem; |
|
27 |
import org.eclipse.ui.menus.CommandContributionItemParameter; |
|
28 |
import org.eclipse.ui.menus.ExtensionContributionFactory; |
|
29 |
import org.eclipse.ui.menus.IContributionRoot; |
|
30 |
import org.eclipse.ui.services.IServiceLocator; |
|
31 |
|
|
32 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
33 |
|
|
34 |
/** |
|
35 |
* Menu factory used in the store plugin xml to dynamically generate menu (sub-menu) contribution items |
|
36 |
* for term types which when clicked open the defined term editor for the chosen term type |
|
37 |
* |
|
38 |
* @author c.mathew |
|
39 |
* @date 18 Jul 2013 |
|
40 |
* |
|
41 |
*/ |
|
42 |
|
|
43 |
public class DefinedTermMenuFactory extends ExtensionContributionFactory { |
|
44 |
|
|
45 |
@Override |
|
46 |
public void createContributionItems(IServiceLocator serviceLocator, |
|
47 |
IContributionRoot additions) { |
|
48 |
|
|
49 |
MenuManager dtMenuManager = |
|
50 |
new MenuManager("Term Editor","eu.etaxonomy.taxeditor.store.definedTermEditorMenu"); |
|
51 |
|
|
52 |
dtMenuManager.setVisible(true); |
|
53 |
|
|
54 |
additions.addContributionItem(dtMenuManager, null); |
|
55 |
List<TermType> ttList = new ArrayList<TermType>(EnumSet.allOf(TermType.class)); |
|
56 |
Collections.sort(ttList,new SortByTermTypeMessage()); |
|
57 |
for (TermType tt : ttList) |
|
58 |
{ |
|
59 |
// if term type has a parent, do not add it |
|
60 |
// it will be added in the recursive call |
|
61 |
if(tt.getKindOf() == null) { |
|
62 |
IContributionItem ici = addChildTermsToMenuManager(tt, serviceLocator); |
|
63 |
if(ici != null) { |
|
64 |
dtMenuManager.add(ici); |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
private IContributionItem addChildTermsToMenuManager(TermType termType, IServiceLocator serviceLocator) { |
|
71 |
|
|
72 |
//FIXME : need a better way to find out if a term type can be editable (ticket 3853) |
|
73 |
if(termType.getEmptyDefinedTermBase() != null) { |
|
74 |
Set<TermType> children = termType.getGeneralizationOf(); |
|
75 |
// term type has no children, so create menu item |
|
76 |
if(children.isEmpty()) { |
|
77 |
return createMenuItem(termType, serviceLocator); |
|
78 |
} |
|
79 |
// term type has children, so create sub menu |
|
80 |
MenuManager dtMenuManager = |
|
81 |
new MenuManager(termType.getMessage(),"eu.etaxonomy.taxeditor.store." + termType.getKey() + "Menu"); |
|
82 |
dtMenuManager.setVisible(true); |
|
83 |
dtMenuManager.add(createDefaultMenuItem(termType, serviceLocator)); |
|
84 |
|
|
85 |
Separator sep = new Separator(); |
|
86 |
dtMenuManager.add(sep); |
|
87 |
// add child items to the sub menu |
|
88 |
for(TermType tt : children) { |
|
89 |
IContributionItem item = addChildTermsToMenuManager(tt,serviceLocator); |
|
90 |
if(item != null) { |
|
91 |
dtMenuManager.add(item); |
|
92 |
} |
|
93 |
} |
|
94 |
return dtMenuManager; |
|
95 |
} else { |
|
96 |
return null; |
|
97 |
} |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
private CommandContributionItem createMenuItem(TermType termType, IServiceLocator serviceLocator) { |
|
102 |
|
|
103 |
Map<String, String> params = new HashMap<String, String>(); |
|
104 |
params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", |
|
105 |
termType.getUuid().toString()); |
|
106 |
|
|
107 |
CommandContributionItemParameter p = new CommandContributionItemParameter( |
|
108 |
serviceLocator, |
|
109 |
"", |
|
110 |
"eu.etaxonomy.taxeditor.store.openDefinedTermEditor", |
|
111 |
params, |
|
112 |
null, |
|
113 |
null, |
|
114 |
null, |
|
115 |
termType.getMessage(), |
|
116 |
"", |
|
117 |
"", |
|
118 |
SWT.PUSH, |
|
119 |
"", |
|
120 |
true); |
|
121 |
|
|
122 |
CommandContributionItem item = new CommandContributionItem(p); |
|
123 |
return item; |
|
124 |
|
|
125 |
} |
|
126 |
|
|
127 |
private CommandContributionItem createDefaultMenuItem(TermType termType, IServiceLocator serviceLocator) { |
|
128 |
|
|
129 |
Map<String, String> params = new HashMap<String, String>(); |
|
130 |
params.put("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid", |
|
131 |
termType.getUuid().toString()); |
|
132 |
|
|
133 |
CommandContributionItemParameter p = new CommandContributionItemParameter( |
|
134 |
serviceLocator, |
|
135 |
"", |
|
136 |
"eu.etaxonomy.taxeditor.store.openDefinedTermEditor", |
|
137 |
params, |
|
138 |
null, |
|
139 |
null, |
|
140 |
null, |
|
141 |
"Other " + termType.getMessage() + "s", |
|
142 |
"", |
|
143 |
"", |
|
144 |
SWT.PUSH, |
|
145 |
"", |
|
146 |
true); |
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
CommandContributionItem item = new CommandContributionItem(p); |
|
151 |
return item; |
|
152 |
|
|
153 |
} |
|
154 |
|
|
155 |
private class SortByTermTypeMessage implements Comparator<TermType> { |
|
156 |
public int compare(TermType t1, TermType t2) { |
|
157 |
return t1.getMessage().compareTo(t2.getMessage()); |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
} |
Also available in: Unified diff
Disable term menu when disconnected (#4901)