Revision 1c9c9562
Added by Patrick Plitzner almost 7 years ago
eu.etaxonomy.taxeditor.store/plugin.xml | ||
---|---|---|
482 | 482 |
</reference> |
483 | 483 |
</visibleWhen> |
484 | 484 |
</command> |
485 |
<command |
|
486 |
commandId="eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm" |
|
487 |
label="Kind Of Term" |
|
488 |
style="push"> |
|
489 |
<visibleWhen |
|
490 |
checkEnabled="true"> |
|
491 |
<reference |
|
492 |
definitionId="isShowExperimentalFeatures"> |
|
493 |
</reference> |
|
494 |
</visibleWhen> |
|
495 |
</command> |
|
485 | 496 |
</menu> |
486 | 497 |
<command |
487 | 498 |
commandId="eu.etaxonomy.taxeditor.editor.definedTerms.delete" |
... | ... | |
633 | 644 |
id="eu.etaxonomy.taxeditor.editor.definedTerms.newDefinedTerm" |
634 | 645 |
name="%command.name.6"> |
635 | 646 |
</command> |
647 |
<command |
|
648 |
defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.CreateDefinedTermHandler" |
|
649 |
id="eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm" |
|
650 |
name="New kind-of term"> |
|
651 |
</command> |
|
636 | 652 |
<command |
637 | 653 |
defaultHandler="eu.etaxonomy.taxeditor.editor.definedterm.handler.CreateTermVocabularyHandler" |
638 | 654 |
id="eu.etaxonomy.taxeditor.editor.definedTerms.newTermVocabulary" |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermContentProvider.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2009 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
50 | 50 |
*/ |
51 | 51 |
@Override |
52 | 52 |
public Object[] getElements(Object inputElement) { |
53 |
|
|
53 |
|
|
54 | 54 |
Collection<TermVocabulary> inputElements = (Collection<TermVocabulary>) inputElement; |
55 | 55 |
return inputElements.toArray(); |
56 | 56 |
|
... | ... | |
61 | 61 |
*/ |
62 | 62 |
@Override |
63 | 63 |
public Object[] getChildren(Object parentElement) { |
64 |
|
|
65 |
if(parentElement instanceof TermVocabulary){
|
|
64 |
|
|
65 |
if(parentElement instanceof TermVocabulary){ |
|
66 | 66 |
return getTopLevelElements((TermVocabulary)parentElement); |
67 | 67 |
} else if (parentElement instanceof DefinedTermBase) { |
68 |
return ((DefinedTermBase) parentElement).getIncludes().toArray(); |
|
68 |
Set<Object> includes = ((DefinedTermBase) parentElement).getIncludes(); |
|
69 |
Set<Object> generalizationOfs = ((DefinedTermBase) parentElement).getGeneralizationOf(); |
|
70 |
generalizationOfs.addAll(includes); |
|
71 |
return generalizationOfs.toArray(); |
|
69 | 72 |
} |
70 | 73 |
return null; |
71 | 74 |
} |
72 |
|
|
75 |
|
|
73 | 76 |
/** |
74 |
*
|
|
77 |
* |
|
75 | 78 |
* @param vocabulary |
76 | 79 |
* @return An array of DefinedTermBase objects that do not have parents |
77 |
*
|
|
80 |
* |
|
78 | 81 |
* TODO: Needs to be implemented in cdmlib |
79 | 82 |
*/ |
80 | 83 |
private Object[] getTopLevelElements(TermVocabulary vocabulary) { |
81 |
|
|
84 |
|
|
82 | 85 |
SortedSet<DefinedTermBase> terms = vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage()); |
83 |
Set<DefinedTermBase> topLevelTerms = new HashSet<DefinedTermBase>();
|
|
84 |
|
|
86 |
Set<DefinedTermBase> topLevelTerms = new HashSet<DefinedTermBase>(); |
|
87 |
|
|
85 | 88 |
for (DefinedTermBase term : terms){ |
86 |
if (term.getPartOf() == null){ |
|
89 |
if (term.getPartOf() == null && term.getKindOf() == null){
|
|
87 | 90 |
topLevelTerms.add(term); |
88 |
}
|
|
89 |
}
|
|
91 |
} |
|
92 |
} |
|
90 | 93 |
return topLevelTerms.toArray(); |
91 | 94 |
} |
92 | 95 |
|
... | ... | |
98 | 101 |
|
99 | 102 |
if(element instanceof DefinedTermBase){ |
100 | 103 |
DefinedTermBase definedTermBase = (DefinedTermBase)element; |
101 |
if (definedTermBase.getPartOf() == null) { |
|
102 |
return definedTermBase.getVocabulary(); |
|
103 |
} else { |
|
104 |
return definedTermBase.getPartOf(); |
|
105 |
} |
|
104 |
if (definedTermBase.getPartOf() != null) { |
|
105 |
return definedTermBase.getPartOf(); |
|
106 |
}else if (definedTermBase.getKindOf() != null) { |
|
107 |
return definedTermBase.getKindOf(); |
|
108 |
} else { |
|
109 |
return definedTermBase.getVocabulary(); |
|
110 |
} |
|
106 | 111 |
} |
107 | 112 |
return null; |
108 | 113 |
|
... | ... | |
112 | 117 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
113 | 118 |
*/ |
114 | 119 |
@Override |
115 |
public boolean hasChildren(Object element) {
|
|
116 |
if (getChildren(element) != null){
|
|
120 |
public boolean hasChildren(Object element) { |
|
121 |
if (getChildren(element) != null){ |
|
117 | 122 |
return getChildren(element).length > 0; |
118 | 123 |
} |
119 | 124 |
return false; |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java | ||
---|---|---|
36 | 36 |
public class TermLabelProvider extends StyledCellLabelProvider { |
37 | 37 |
|
38 | 38 |
private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); |
39 |
private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); |
|
39 | 40 |
private Styler vocStyler; |
41 |
private Styler kindOfStyler; |
|
40 | 42 |
|
41 | 43 |
public TermLabelProvider() { |
42 | 44 |
} |
... | ... | |
48 | 50 |
@Override |
49 | 51 |
public void update(ViewerCell cell) { |
50 | 52 |
Object element = cell.getElement(); |
51 |
int columnIndex = cell.getColumnIndex(); |
|
52 | 53 |
|
53 | 54 |
String text = getText(element); |
54 | 55 |
cell.setText(text); |
55 | 56 |
|
57 |
Styler styler = null; |
|
56 | 58 |
if (element instanceof TermVocabulary && text != null) { |
57 |
StyledString styledString = new StyledString(text, getVocabularyStyler()); |
|
59 |
styler = getVocabularyStyler(); |
|
60 |
} |
|
61 |
else if(element instanceof DefinedTermBase && ((DefinedTermBase) element).getKindOf()!=null){ |
|
62 |
styler = getKindOfStyler(); |
|
63 |
} |
|
64 |
if(styler!=null){ |
|
65 |
StyledString styledString = new StyledString(text, styler); |
|
58 | 66 |
StyleRange[] styleRanges; |
59 | 67 |
styleRanges = styledString.getStyleRanges(); |
60 | 68 |
cell.setStyleRanges(styleRanges); |
... | ... | |
62 | 70 |
super.update(cell); |
63 | 71 |
} |
64 | 72 |
|
65 |
public StyledString getStyledText(Object element) { |
|
66 |
|
|
67 |
if (element instanceof TermVocabulary) { |
|
68 |
new StyledString(getText(element), getVocabularyStyler()); |
|
69 |
} |
|
70 |
return new StyledString(getText(element), StyledString.QUALIFIER_STYLER); |
|
71 |
} |
|
73 |
// public StyledString getStyledText(Object element) { |
|
74 |
// if (element instanceof TermVocabulary) { |
|
75 |
// new StyledString(getText(element), getVocabularyStyler()); |
|
76 |
// } |
|
77 |
// else if (element instanceof DefinedTermBase && ((DefinedTermBase) element).getKindOf()!=null) { |
|
78 |
// new StyledString(getText(element), getKindOfStyler()); |
|
79 |
// } |
|
80 |
// return new StyledString(getText(element), StyledString.QUALIFIER_STYLER); |
|
81 |
// } |
|
72 | 82 |
|
73 | 83 |
public String getText(Object element) { |
74 | 84 |
if(element instanceof TermBase){ |
... | ... | |
103 | 113 |
return vocStyler; |
104 | 114 |
} |
105 | 115 |
|
116 |
private Styler getKindOfStyler() { |
|
117 |
if (kindOfStyler == null) { |
|
118 |
kindOfStyler = new Styler() { |
|
119 |
@Override |
|
120 |
public void applyStyles(TextStyle textStyle) { |
|
121 |
textStyle.foreground = kindOfColor; |
|
122 |
} |
|
123 |
}; |
|
124 |
} |
|
125 |
return kindOfStyler; |
|
126 |
} |
|
127 |
|
|
106 | 128 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/CreateDefinedTermHandler.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2009 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
11 | 11 |
import org.eclipse.core.commands.AbstractHandler; |
12 | 12 |
import org.eclipse.core.commands.ExecutionEvent; |
13 | 13 |
import org.eclipse.core.commands.ExecutionException; |
14 |
import org.eclipse.core.commands.IHandler; |
|
15 | 14 |
import org.eclipse.core.commands.common.NotDefinedException; |
16 | 15 |
import org.eclipse.core.commands.operations.IUndoContext; |
17 | 16 |
import org.eclipse.jface.viewers.IStructuredSelection; |
... | ... | |
28 | 27 |
/** |
29 | 28 |
* @author l.morris |
30 | 29 |
* @date 21 Dec 2011 |
31 |
*
|
|
30 |
* |
|
32 | 31 |
*/ |
33 |
public class CreateDefinedTermHandler extends AbstractHandler implements IHandler {
|
|
32 |
public class CreateDefinedTermHandler extends AbstractHandler { |
|
34 | 33 |
|
35 |
/* |
|
36 |
* (non-Javadoc) |
|
37 |
* |
|
38 |
* @see |
|
39 |
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands. |
|
40 |
* ExecutionEvent) |
|
41 |
*/ |
|
42 | 34 |
@Override |
43 | 35 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
36 |
boolean addTermAsKindOf = |
|
37 |
event.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false; |
|
38 |
|
|
44 | 39 |
IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil |
45 | 40 |
.getActiveEditor(event); |
46 | 41 |
|
... | ... | |
55 | 50 |
|
56 | 51 |
TermBase termBase = (TermBase) selection.getFirstElement(); |
57 | 52 |
|
58 |
AbstractPostOperation operation =
|
|
59 |
new CreateDefinedTermOperation(label,
|
|
60 |
undoContext,
|
|
61 |
termBase,
|
|
53 |
AbstractPostOperation operation = |
|
54 |
new CreateDefinedTermOperation(label, |
|
55 |
undoContext, |
|
56 |
termBase, |
|
62 | 57 |
dfe.getDefinedTermEditorInput(), |
63 |
editor); |
|
58 |
editor, addTermAsKindOf);
|
|
64 | 59 |
StoreUtil.executeOperation(operation); |
65 | 60 |
|
66 | 61 |
} catch (NotDefinedException e) { |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/CreateDefinedTermOperation.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
private final TermBase parentTermBase; |
38 | 38 |
private final TermEditorInput definedTermInput; |
39 |
private boolean addTermAsKindOf; |
|
40 |
|
|
39 | 41 |
|
40 | 42 |
/** |
41 | 43 |
* @param label |
42 | 44 |
* @param undoContext |
43 | 45 |
* @param postOperationEnabled |
46 |
* @param addTermAsKindOf |
|
44 | 47 |
*/ |
45 | 48 |
public CreateDefinedTermOperation(String label, |
46 | 49 |
IUndoContext undoContext, |
47 | 50 |
TermBase termBase, |
48 | 51 |
TermEditorInput definedTermInput, |
49 |
IPostOperationEnabled postOperationEnabled) { |
|
52 |
IPostOperationEnabled postOperationEnabled, boolean addTermAsKindOf) {
|
|
50 | 53 |
super(label, undoContext, postOperationEnabled); |
51 | 54 |
this.parentTermBase = termBase; |
52 | 55 |
this.definedTermInput = definedTermInput; |
56 |
this.addTermAsKindOf = addTermAsKindOf; |
|
53 | 57 |
} |
54 | 58 |
|
55 | 59 |
/* (non-Javadoc) |
... | ... | |
75 | 79 |
vocabulary.addTerm(newTerm); |
76 | 80 |
} else if (parentTermBase instanceof DefinedTermBase) { |
77 | 81 |
DefinedTermBase parent = (DefinedTermBase) parentTermBase; |
78 |
parent.addIncludes(newTerm); |
|
82 |
if(addTermAsKindOf){ |
|
83 |
parent.addGeneralizationOf(newTerm); |
|
84 |
} |
|
85 |
else{ |
|
86 |
parent.addIncludes(newTerm); |
|
87 |
} |
|
79 | 88 |
TermVocabulary vocabulary = parent.getVocabulary(); |
80 | 89 |
vocabulary.addTerm(newTerm); |
81 | 90 |
} |
Also available in: Unified diff
ref #6762 Implement option to add kindOf related terms in term editor