Revision 573841a9
Added by Patrick Plitzner almost 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermContentProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.editor.definedterm; |
|
10 |
|
|
11 |
import java.util.Collection; |
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.Set; |
|
14 |
import java.util.SortedSet; |
|
15 |
|
|
16 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
|
17 |
import org.eclipse.jface.viewers.Viewer; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
20 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
21 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author l.morris |
|
25 |
* @date 8 Dec 2011 |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class TermContentProvider implements ITreeContentProvider { |
|
29 |
|
|
30 |
@Override |
|
31 |
public void dispose() { |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object[] getElements(Object inputElement) { |
|
40 |
Collection<TermVocabulary> inputElements = (Collection<TermVocabulary>) inputElement; |
|
41 |
return inputElements.toArray(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public Object[] getChildren(Object parentElement) { |
|
46 |
Collection<Object> children = new HashSet<>(); |
|
47 |
if(parentElement instanceof TermVocabulary){ |
|
48 |
return getTopLevelElements((TermVocabulary)parentElement); |
|
49 |
} else if (parentElement instanceof DefinedTermBase) { |
|
50 |
Set<Object> includes = ((DefinedTermBase) parentElement).getIncludes(); |
|
51 |
Set<Object> generalizationOfs = ((DefinedTermBase) parentElement).getGeneralizationOf(); |
|
52 |
children.addAll(includes); |
|
53 |
children.addAll(generalizationOfs); |
|
54 |
return children.toArray(); |
|
55 |
} |
|
56 |
return null; |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* |
|
61 |
* @param vocabulary |
|
62 |
* @return An array of DefinedTermBase objects that do not have parents |
|
63 |
* |
|
64 |
* TODO: Needs to be implemented in cdmlib |
|
65 |
*/ |
|
66 |
private Object[] getTopLevelElements(TermVocabulary vocabulary) { |
|
67 |
SortedSet<DefinedTermBase> terms = vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage()); |
|
68 |
Set<DefinedTermBase> topLevelTerms = new HashSet<DefinedTermBase>(); |
|
69 |
|
|
70 |
for (DefinedTermBase term : terms){ |
|
71 |
if (term.getPartOf() == null && term.getKindOf() == null){ |
|
72 |
topLevelTerms.add(term); |
|
73 |
} |
|
74 |
} |
|
75 |
return topLevelTerms.toArray(); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public Object getParent(Object element) { |
|
80 |
if(element instanceof DefinedTermBase){ |
|
81 |
DefinedTermBase definedTermBase = (DefinedTermBase)element; |
|
82 |
if (definedTermBase.getPartOf() != null) { |
|
83 |
return definedTermBase.getPartOf(); |
|
84 |
}else if (definedTermBase.getKindOf() != null) { |
|
85 |
return definedTermBase.getKindOf(); |
|
86 |
} else { |
|
87 |
return definedTermBase.getVocabulary(); |
|
88 |
} |
|
89 |
} |
|
90 |
return null; |
|
91 |
|
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public boolean hasChildren(Object element) { |
|
96 |
if (getChildren(element) != null){ |
|
97 |
return getChildren(element).length > 0; |
|
98 |
} |
|
99 |
return false; |
|
100 |
} |
|
101 |
|
|
102 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.editor.definedterm; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
|
|
13 |
import org.eclipse.jface.viewers.StyledCellLabelProvider; |
|
14 |
import org.eclipse.jface.viewers.StyledString; |
|
15 |
import org.eclipse.jface.viewers.StyledString.Styler; |
|
16 |
import org.eclipse.jface.viewers.ViewerCell; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.swt.custom.StyleRange; |
|
19 |
import org.eclipse.swt.graphics.Color; |
|
20 |
import org.eclipse.swt.graphics.TextStyle; |
|
21 |
import org.eclipse.swt.widgets.Display; |
|
22 |
|
|
23 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
24 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
25 |
import eu.etaxonomy.cdm.model.common.Language; |
|
26 |
import eu.etaxonomy.cdm.model.common.Representation; |
|
27 |
import eu.etaxonomy.cdm.model.common.TermBase; |
|
28 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
29 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author l.morris |
|
33 |
* @date 9 Dec 2011 |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class TermLabelProvider extends StyledCellLabelProvider { |
|
37 |
|
|
38 |
private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); |
|
39 |
private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); |
|
40 |
private Styler vocStyler; |
|
41 |
private Styler kindOfStyler; |
|
42 |
|
|
43 |
public TermLabelProvider() { |
|
44 |
this.vocStyler = new Styler() { |
|
45 |
@Override |
|
46 |
public void applyStyles(TextStyle textStyle) { |
|
47 |
textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK); |
|
48 |
} |
|
49 |
}; |
|
50 |
} |
|
51 |
|
|
52 |
public TermLabelProvider(Styler vocStyler){ |
|
53 |
this.vocStyler = vocStyler; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public void update(ViewerCell cell) { |
|
58 |
Object element = cell.getElement(); |
|
59 |
|
|
60 |
String text = getText(element); |
|
61 |
cell.setText(text); |
|
62 |
|
|
63 |
Styler styler = null; |
|
64 |
if (element instanceof TermVocabulary && text != null) { |
|
65 |
styler = getVocabularyStyler(); |
|
66 |
} |
|
67 |
else if(element instanceof DefinedTermBase && ((DefinedTermBase) element).getKindOf()!=null){ |
|
68 |
styler = getKindOfStyler(); |
|
69 |
} |
|
70 |
if(styler!=null){ |
|
71 |
StyledString styledString = new StyledString(text, styler); |
|
72 |
StyleRange[] styleRanges; |
|
73 |
styleRanges = styledString.getStyleRanges(); |
|
74 |
cell.setStyleRanges(styleRanges); |
|
75 |
} |
|
76 |
super.update(cell); |
|
77 |
} |
|
78 |
|
|
79 |
// public StyledString getStyledText(Object element) { |
|
80 |
// if (element instanceof TermVocabulary) { |
|
81 |
// new StyledString(getText(element), getVocabularyStyler()); |
|
82 |
// } |
|
83 |
// else if (element instanceof DefinedTermBase && ((DefinedTermBase) element).getKindOf()!=null) { |
|
84 |
// new StyledString(getText(element), getKindOfStyler()); |
|
85 |
// } |
|
86 |
// return new StyledString(getText(element), StyledString.QUALIFIER_STYLER); |
|
87 |
// } |
|
88 |
|
|
89 |
public String getText(Object element) { |
|
90 |
String label = null; |
|
91 |
if(element instanceof TermBase){ |
|
92 |
TermBase termBase = (TermBase)element; |
|
93 |
Representation rep = termBase.getRepresentation(PreferencesUtil.getGlobalLanguage()); |
|
94 |
if (rep == null){ |
|
95 |
rep = termBase.getPreferredRepresentation(new ArrayList<Language>()); |
|
96 |
} |
|
97 |
label = rep != null? rep.getLabel() : termBase.generateTitle(); |
|
98 |
if (element instanceof DefinedTermBase && label!=null) { |
|
99 |
DefinedTermBase<?> dtb = (DefinedTermBase<?>) element; |
|
100 |
label = CdmUtils.concat(" : ", dtb.getIdInVocabulary(), label); |
|
101 |
} |
|
102 |
if(label==null){ |
|
103 |
label = ((TermBase) element).generateTitle(); |
|
104 |
} |
|
105 |
} |
|
106 |
// FIXME : must throw an exception here |
|
107 |
if(label==null){ |
|
108 |
label = element.toString(); |
|
109 |
} |
|
110 |
return label; |
|
111 |
} |
|
112 |
|
|
113 |
protected Styler getVocabularyStyler() { |
|
114 |
if (vocStyler == null) { |
|
115 |
vocStyler = new Styler() { |
|
116 |
@Override |
|
117 |
public void applyStyles(TextStyle textStyle) { |
|
118 |
textStyle.foreground = vocColor; |
|
119 |
} |
|
120 |
}; |
|
121 |
} |
|
122 |
return vocStyler; |
|
123 |
} |
|
124 |
|
|
125 |
protected Styler getKindOfStyler() { |
|
126 |
if (kindOfStyler == null) { |
|
127 |
kindOfStyler = new Styler() { |
|
128 |
@Override |
|
129 |
public void applyStyles(TextStyle textStyle) { |
|
130 |
textStyle.foreground = kindOfColor; |
|
131 |
} |
|
132 |
}; |
|
133 |
} |
|
134 |
return kindOfStyler; |
|
135 |
} |
|
136 |
|
|
137 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/VocabularyLabelProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2009 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.editor.definedterm; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
|
|
13 |
import org.eclipse.jface.viewers.StyledCellLabelProvider; |
|
14 |
import org.eclipse.jface.viewers.StyledString; |
|
15 |
import org.eclipse.jface.viewers.StyledString.Styler; |
|
16 |
import org.eclipse.jface.viewers.ViewerCell; |
|
17 |
import org.eclipse.swt.SWT; |
|
18 |
import org.eclipse.swt.custom.StyleRange; |
|
19 |
import org.eclipse.swt.graphics.Color; |
|
20 |
import org.eclipse.swt.graphics.TextStyle; |
|
21 |
import org.eclipse.swt.widgets.Display; |
|
22 |
|
|
23 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
24 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
25 |
import eu.etaxonomy.cdm.model.common.Language; |
|
26 |
import eu.etaxonomy.cdm.model.common.Representation; |
|
27 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
28 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
29 |
|
|
30 |
/** |
|
31 |
* @author l.morris |
|
32 |
* @date 9 Dec 2011 |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class VocabularyLabelProvider extends StyledCellLabelProvider { |
|
36 |
|
|
37 |
private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); |
|
38 |
private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); |
|
39 |
private Styler vocStyler; |
|
40 |
private Styler kindOfStyler; |
|
41 |
|
|
42 |
public VocabularyLabelProvider() { |
|
43 |
} |
|
44 |
|
|
45 |
public VocabularyLabelProvider(Styler vocStyler){ |
|
46 |
this.vocStyler = vocStyler; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void update(ViewerCell cell) { |
|
51 |
Object element = cell.getElement(); |
|
52 |
|
|
53 |
String text = getText(element); |
|
54 |
cell.setText(text); |
|
55 |
|
|
56 |
Styler styler = null; |
|
57 |
if (element instanceof TermVocabulary && text != null) { |
|
58 |
styler = getVocabularyStyler(); |
|
59 |
} |
|
60 |
|
|
61 |
if(styler!=null){ |
|
62 |
StyledString styledString = new StyledString(text, styler); |
|
63 |
StyleRange[] styleRanges; |
|
64 |
styleRanges = styledString.getStyleRanges(); |
|
65 |
cell.setStyleRanges(styleRanges); |
|
66 |
} |
|
67 |
super.update(cell); |
|
68 |
} |
|
69 |
|
|
70 |
// public StyledString getStyledText(Object element) { |
|
71 |
// if (element instanceof TermVocabulary) { |
|
72 |
// new StyledString(getText(element), getVocabularyStyler()); |
|
73 |
// } |
|
74 |
// else if (element instanceof DefinedTermBase && ((DefinedTermBase) element).getKindOf()!=null) { |
|
75 |
// new StyledString(getText(element), getKindOfStyler()); |
|
76 |
// } |
|
77 |
// return new StyledString(getText(element), StyledString.QUALIFIER_STYLER); |
|
78 |
// } |
|
79 |
|
|
80 |
public String getText(Object element) { |
|
81 |
String label = null; |
|
82 |
if(element instanceof TermVocabulary){ |
|
83 |
TermVocabulary termBase = (TermVocabulary)element; |
|
84 |
Representation rep = termBase.getRepresentation(PreferencesUtil.getGlobalLanguage()); |
|
85 |
if (rep == null){ |
|
86 |
rep = termBase.getPreferredRepresentation(new ArrayList<Language>()); |
|
87 |
} |
|
88 |
label = rep != null? rep.getLabel() : termBase.getTitleCache(); |
|
89 |
if (element instanceof DefinedTermBase && label!=null) { |
|
90 |
DefinedTermBase<?> dtb = (DefinedTermBase<?>) element; |
|
91 |
label = CdmUtils.concat(" : ", dtb.getIdInVocabulary(), label); |
|
92 |
} |
|
93 |
} |
|
94 |
// FIXME : must throw an exception here |
|
95 |
if(label==null){ |
|
96 |
label = element.toString(); |
|
97 |
} |
|
98 |
return label; |
|
99 |
} |
|
100 |
|
|
101 |
private Styler getVocabularyStyler() { |
|
102 |
if (vocStyler == null) { |
|
103 |
vocStyler = new Styler() { |
|
104 |
@Override |
|
105 |
public void applyStyles(TextStyle textStyle) { |
|
106 |
textStyle.foreground = vocColor; |
|
107 |
} |
|
108 |
}; |
|
109 |
} |
|
110 |
return vocStyler; |
|
111 |
} |
|
112 |
|
|
113 |
|
|
114 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AreaLabelProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.preference.wizard; |
|
10 |
|
|
11 |
import org.eclipse.jface.viewers.ILabelProvider; |
|
12 |
import org.eclipse.jface.viewers.StyledString; |
|
13 |
import org.eclipse.jface.viewers.StyledString.Styler; |
|
14 |
import org.eclipse.jface.viewers.ViewerCell; |
|
15 |
import org.eclipse.swt.custom.StyleRange; |
|
16 |
import org.eclipse.swt.graphics.Image; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
19 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
20 |
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author k.luther |
|
24 |
* @since 04.10.2018 |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class AreaLabelProvider extends TermLabelProvider implements ILabelProvider{ |
|
28 |
|
|
29 |
public AreaLabelProvider(){ |
|
30 |
super(); |
|
31 |
} |
|
32 |
|
|
33 |
public AreaLabelProvider(Styler vocStyler){ |
|
34 |
super(vocStyler); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
@Override |
|
39 |
public void update(ViewerCell cell) { |
|
40 |
Object element = cell.getElement(); |
|
41 |
|
|
42 |
String text = getText(element); |
|
43 |
cell.setText(text); |
|
44 |
|
|
45 |
Styler styler = null; |
|
46 |
if (element instanceof TermVocabulary && text != null) { |
|
47 |
styler = getVocabularyStyler(); |
|
48 |
} |
|
49 |
else if(element instanceof NamedAreaWrapper && ((NamedAreaWrapper) element).getNamedArea().getKindOf()!=null){ |
|
50 |
styler = getKindOfStyler(); |
|
51 |
} |
|
52 |
if(styler!=null){ |
|
53 |
StyledString styledString = new StyledString(text, styler); |
|
54 |
StyleRange[] styleRanges; |
|
55 |
styleRanges = styledString.getStyleRanges(); |
|
56 |
cell.setStyleRanges(styleRanges); |
|
57 |
} |
|
58 |
super.update(cell); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public String getText(Object element) { |
|
63 |
String label = null; |
|
64 |
if(element instanceof NamedAreaWrapper){ |
|
65 |
NamedAreaWrapper wrapper = (NamedAreaWrapper)element; |
|
66 |
DefinedTermBase termBase = wrapper.getNamedArea(); |
|
67 |
label = super.getText(termBase); |
|
68 |
if (wrapper.isBaseElement){ |
|
69 |
label = label +""; //+ " (Base)" //$NON-NLS-1$ |
|
70 |
} |
|
71 |
return label; |
|
72 |
|
|
73 |
} |
|
74 |
return super.getText(element); |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
/** |
|
79 |
* {@inheritDoc} |
|
80 |
*/ |
|
81 |
@Override |
|
82 |
public Image getImage(Object element) { |
|
83 |
// TODO Auto-generated method stub |
|
84 |
return null; |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/DistributionContentProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.taxeditor.preference.wizard; |
|
10 |
|
|
11 |
import java.util.HashSet; |
|
12 |
import java.util.Set; |
|
13 |
import java.util.SortedSet; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
16 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
17 |
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider; |
|
18 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author k.luther |
|
22 |
* @since 04.10.2018 |
|
23 |
* |
|
24 |
*/ |
|
25 |
public class DistributionContentProvider extends TermContentProvider { |
|
26 |
|
|
27 |
@Override |
|
28 |
public Object[] getChildren(Object parentElement) { |
|
29 |
Set<NamedAreaWrapper> allChildrenWrapper = new HashSet(); |
|
30 |
if(parentElement instanceof TermVocabulary){ |
|
31 |
return getTopLevelElements((TermVocabulary)parentElement); |
|
32 |
} else if (parentElement instanceof NamedAreaWrapper && !((NamedAreaWrapper)parentElement).isBaseElement) { |
|
33 |
NamedAreaWrapper wrapper = (NamedAreaWrapper)parentElement; |
|
34 |
if (wrapper.children == null){ |
|
35 |
DefinedTermBase term = wrapper.getNamedArea(); |
|
36 |
Set<DefinedTermBase> includes = term.getIncludes(); |
|
37 |
for (DefinedTermBase termBase: includes){ |
|
38 |
allChildrenWrapper.add(new NamedAreaWrapper(termBase, false, wrapper)); |
|
39 |
} |
|
40 |
Set<DefinedTermBase> generalizationOfs = term.getGeneralizationOf(); |
|
41 |
for (DefinedTermBase termBase: generalizationOfs){ |
|
42 |
allChildrenWrapper.add(new NamedAreaWrapper(termBase, false, wrapper)); |
|
43 |
} |
|
44 |
if(allChildrenWrapper.size()>0){ |
|
45 |
allChildrenWrapper.add(new NamedAreaWrapper(term, true, wrapper)); |
|
46 |
} |
|
47 |
wrapper.children = allChildrenWrapper; |
|
48 |
return allChildrenWrapper.toArray(); |
|
49 |
}else{ |
|
50 |
return wrapper.children.toArray(); |
|
51 |
} |
|
52 |
} |
|
53 |
return null; |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* |
|
58 |
* @param vocabulary |
|
59 |
* @return An array of DefinedTermBase objects that do not have parents |
|
60 |
* |
|
61 |
* TODO: Needs to be implemented in cdmlib |
|
62 |
*/ |
|
63 |
|
|
64 |
private Object[] getTopLevelElements(TermVocabulary vocabulary) { |
|
65 |
|
|
66 |
SortedSet<DefinedTermBase> terms = vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage()); |
|
67 |
Set<NamedAreaWrapper> topLevelTerms = new HashSet(); |
|
68 |
NamedAreaWrapper wrapper; |
|
69 |
for (DefinedTermBase term : terms){ |
|
70 |
if (term.getPartOf() == null && term.getKindOf() == null){ |
|
71 |
wrapper = new NamedAreaWrapper(term, false, vocabulary); |
|
72 |
topLevelTerms.add(wrapper); |
|
73 |
} |
|
74 |
} |
|
75 |
return topLevelTerms.toArray(); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public Object getParent(Object element) { |
|
80 |
if(element instanceof NamedAreaWrapper){ |
|
81 |
if (((NamedAreaWrapper)element).parent!= null){ |
|
82 |
return ((NamedAreaWrapper)element).parent; |
|
83 |
}else{ |
|
84 |
NamedAreaWrapper child = (NamedAreaWrapper)element; |
|
85 |
DefinedTermBase parent = child.getNamedArea().getKindOf(); |
|
86 |
if (parent == null){ |
|
87 |
return child.getNamedArea().getVocabulary(); |
|
88 |
} |
|
89 |
return new NamedAreaWrapper(parent, false, null); |
|
90 |
} |
|
91 |
} |
|
92 |
return null; |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public boolean hasChildren(Object element) { |
|
98 |
if (element instanceof TermVocabulary){ |
|
99 |
if (((TermVocabulary)element).getTerms() != null){ |
|
100 |
return((TermVocabulary)element).getTerms().size()>0; |
|
101 |
}else{ |
|
102 |
return false; |
|
103 |
} |
|
104 |
}else if (element instanceof DefinedTermBase){ |
|
105 |
boolean hasChildren = false; |
|
106 |
if (((DefinedTermBase)element).getGeneralizationOf()!= null){ |
|
107 |
if (((DefinedTermBase)element).getGeneralizationOf().size()>0){ |
|
108 |
return true; |
|
109 |
} |
|
110 |
} |
|
111 |
if (((DefinedTermBase)element).getIncludes()!= null){ |
|
112 |
if (((DefinedTermBase)element).getIncludes().size()>0){ |
|
113 |
return true; |
|
114 |
} |
|
115 |
} |
|
116 |
return false; |
|
117 |
}else if (element instanceof NamedAreaWrapper){ |
|
118 |
NamedAreaWrapper wrapper = (NamedAreaWrapper)element; |
|
119 |
if (wrapper.isBaseElement){ |
|
120 |
return false; |
|
121 |
} |
|
122 |
|
|
123 |
if (wrapper.getNamedArea().getGeneralizationOf()!= null){ |
|
124 |
if (wrapper.getNamedArea().getGeneralizationOf().size()>0){ |
|
125 |
return true; |
|
126 |
} |
|
127 |
} |
|
128 |
if (wrapper.getNamedArea().getIncludes()!= null){ |
|
129 |
if (wrapper.getNamedArea().getIncludes().size()>0){ |
|
130 |
return true; |
|
131 |
} |
|
132 |
} |
|
133 |
return false; |
|
134 |
|
|
135 |
} |
|
136 |
return false; |
|
137 |
} |
|
138 |
} |
Also available in: Unified diff
ref #7887 Remove unused classes