1 |
88b34876
|
a.theys
|
/**
|
2 |
|
|
* Copyright (C) 2011 EDIT
|
3 |
5a35a97d
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
88b34876
|
a.theys
|
* http://www.e-taxonomy.eu
|
5 |
5a35a97d
|
Patric Plitzner
|
*
|
6 |
88b34876
|
a.theys
|
* 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 |
e6a01da7
|
a.theys
|
package eu.etaxonomy.taxeditor.editor;
|
10 |
|
|
|
11 |
|
|
import java.net.URI;
|
12 |
|
|
import java.net.URISyntaxException;
|
13 |
|
|
|
14 |
|
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15 |
|
|
import org.eclipse.ui.IMemento;
|
16 |
|
|
|
17 |
|
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18 |
52f1ea68
|
a.theys
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
19 |
e6a01da7
|
a.theys
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
20 |
|
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
21 |
49a64920
|
Cherian Mathew
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
22 |
e6a01da7
|
a.theys
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
23 |
a20b4301
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.TermType;
|
24 |
e6a01da7
|
a.theys
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
25 |
|
|
import eu.etaxonomy.cdm.model.description.Feature;
|
26 |
52f1ea68
|
a.theys
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
27 |
|
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
28 |
e6a01da7
|
a.theys
|
import eu.etaxonomy.cdm.model.description.State;
|
29 |
|
|
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
|
30 |
41e2f693
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31 |
e6a01da7
|
a.theys
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32 |
|
|
|
33 |
88b34876
|
a.theys
|
/**
|
34 |
39512f8c
|
a.theys
|
* The context listener will call this class when the uses view is being loaded.
|
35 |
5a35a97d
|
Patric Plitzner
|
* It checks if the uses view's necessary terms are present in the database.
|
36 |
|
|
* It will persist the terms that aren't present, using the CDMLib's services classes.
|
37 |
|
|
* @author a.theys
|
38 |
88b34876
|
a.theys
|
* @created mar 13, 2012
|
39 |
|
|
*/
|
40 |
e6a01da7
|
a.theys
|
public class UseObjectManager extends ContextListenerAdapter{
|
41 |
5a35a97d
|
Patric Plitzner
|
|
42 |
a20b4301
|
Andreas Müller
|
public UseObjectManager() {
|
43 |
|
|
CdmStore.getContextManager().addContextListener(this);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
5a35a97d
|
Patric Plitzner
|
|
47 |
e6a01da7
|
a.theys
|
@Override
|
48 |
|
|
public void contextRefresh(IProgressMonitor monitor) {
|
49 |
|
|
monitor.subTask("Refreshing the Uses View");
|
50 |
41e2f693
|
Cherian Mathew
|
MessagingUtils.warn(getClass(), "Refreshing Uses View warn");
|
51 |
e6a01da7
|
a.theys
|
setupNecessaryItems(monitor);
|
52 |
|
|
}
|
53 |
5a35a97d
|
Patric Plitzner
|
|
54 |
|
|
|
55 |
e6a01da7
|
a.theys
|
@Override
|
56 |
|
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
57 |
|
|
monitor.subTask("Starting the Uses View");
|
58 |
41e2f693
|
Cherian Mathew
|
MessagingUtils.warn(getClass(), "Starting Uses View warn");
|
59 |
e6a01da7
|
a.theys
|
setupNecessaryItems(monitor);
|
60 |
|
|
}
|
61 |
5a35a97d
|
Patric Plitzner
|
|
62 |
e6a01da7
|
a.theys
|
private void setupNecessaryItems(IProgressMonitor monitor) {
|
63 |
5a35a97d
|
Patric Plitzner
|
|
64 |
7ccbcd94
|
Andreas Müller
|
//retrieve terms and vocabularies from db
|
65 |
2ab241cb
|
a.theys
|
Feature featureUseRecord = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseRecordFeature);
|
66 |
|
|
Feature featureUseSummary = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseSummaryFeature);
|
67 |
5a35a97d
|
Patric Plitzner
|
|
68 |
e6a01da7
|
a.theys
|
ConversationHolder conversation = CdmStore.createConversation();
|
69 |
5a35a97d
|
Patric Plitzner
|
|
70 |
|
|
|
71 |
7ccbcd94
|
Andreas Müller
|
//create use marker type if not exists
|
72 |
|
|
createUseMarkerType(conversation);
|
73 |
5a35a97d
|
Patric Plitzner
|
|
74 |
7ccbcd94
|
Andreas Müller
|
//create state vocabulary if not exists
|
75 |
|
|
createStateVocabulary(monitor, conversation);
|
76 |
5a35a97d
|
Patric Plitzner
|
|
77 |
7ccbcd94
|
Andreas Müller
|
//create state vocabulary if not exists
|
78 |
|
|
createCountryVocabulary(monitor, conversation);
|
79 |
5a35a97d
|
Patric Plitzner
|
|
80 |
7ccbcd94
|
Andreas Müller
|
//create plant part vocabulary
|
81 |
|
|
createPlantVocabulary(monitor, conversation);
|
82 |
5a35a97d
|
Patric Plitzner
|
|
83 |
7ccbcd94
|
Andreas Müller
|
//create human group vocabulary
|
84 |
|
|
createHumanGroupVocabulary(monitor, conversation);
|
85 |
5a35a97d
|
Patric Plitzner
|
|
86 |
7ccbcd94
|
Andreas Müller
|
if(featureUseRecord == null || featureUseSummary == null) {
|
87 |
5a35a97d
|
Patric Plitzner
|
TermVocabulary<Feature> featureVocabulary = CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidFeatureVocabulary));
|
88 |
a20b4301
|
Andreas Müller
|
// FeatureTree palmWebFeatureTree = CdmStore.getService(IFeatureTreeService.class).find(UsageTermCollection.uuidPalmWebFeatureTree);
|
89 |
5a35a97d
|
Patric Plitzner
|
|
90 |
7ccbcd94
|
Andreas Müller
|
if (featureUseRecord == null ) {
|
91 |
|
|
featureUseRecord = Feature.NewInstance(UsageTermCollection.useRecordFeatureLabel, UsageTermCollection.useRecordFeatureLabel, null);
|
92 |
|
|
featureUseRecord.setUuid(UsageTermCollection.uuidUseRecordFeature);
|
93 |
|
|
featureUseRecord.setSupportsCategoricalData(true);
|
94 |
|
|
featureVocabulary.addTerm(featureUseRecord);
|
95 |
a20b4301
|
Andreas Müller
|
|
96 |
|
|
// if (palmWebFeatureTree != null){
|
97 |
|
|
// FeatureNode useRecFeatureNode = FeatureNode.NewInstance(featureUseRecord);
|
98 |
|
|
// palmWebFeatureTree.getRoot().addChild(useRecFeatureNode);
|
99 |
|
|
// }else{
|
100 |
|
|
// StoreUtil.warn(getClass(), "No current feature tree available to add useRecord feature");
|
101 |
|
|
// }
|
102 |
7ccbcd94
|
Andreas Müller
|
}
|
103 |
|
|
if (featureUseSummary == null) {
|
104 |
|
|
featureUseSummary = Feature.NewInstance(UsageTermCollection.useSummaryFeatureLabel, UsageTermCollection.useSummaryFeatureLabel, null);
|
105 |
|
|
featureUseSummary.setUuid(UsageTermCollection.uuidUseSummaryFeature);
|
106 |
|
|
featureUseSummary.setSupportsTextData(true);
|
107 |
|
|
featureVocabulary.addTerm(featureUseSummary);
|
108 |
a20b4301
|
Andreas Müller
|
// if (palmWebFeatureTree != null){
|
109 |
|
|
// FeatureNode useSumFeatureNode = FeatureNode.NewInstance(featureUseSummary);
|
110 |
|
|
// palmWebFeatureTree.getRoot().addChild(useSumFeatureNode);
|
111 |
|
|
// }else{
|
112 |
|
|
// StoreUtil.warn(getClass(), "No current feature tree available to add use summary feature");
|
113 |
|
|
// }
|
114 |
7ccbcd94
|
Andreas Müller
|
}
|
115 |
5a35a97d
|
Patric Plitzner
|
|
116 |
7ccbcd94
|
Andreas Müller
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(featureVocabulary);
|
117 |
a20b4301
|
Andreas Müller
|
// if (palmWebFeatureTree != null){
|
118 |
|
|
// CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(palmWebFeatureTree);
|
119 |
|
|
// }
|
120 |
e6a01da7
|
a.theys
|
conversation.commit(true);
|
121 |
5a35a97d
|
Patric Plitzner
|
|
122 |
e6a01da7
|
a.theys
|
}
|
123 |
5a35a97d
|
Patric Plitzner
|
conversation.close();
|
124 |
7ccbcd94
|
Andreas Müller
|
}
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
private void createHumanGroupVocabulary(IProgressMonitor monitor,ConversationHolder conversation) {
|
128 |
5a35a97d
|
Patric Plitzner
|
TermVocabulary<DefinedTerm> humanGroupVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidHumanGroupVocabulary);
|
129 |
7ccbcd94
|
Andreas Müller
|
if (humanGroupVocabulary == null){
|
130 |
|
|
monitor.subTask("create human group vocabulary");
|
131 |
e6a01da7
|
a.theys
|
URI termSourceUri = null;
|
132 |
|
|
try {
|
133 |
49a64920
|
Cherian Mathew
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");
|
134 |
e6a01da7
|
a.theys
|
} catch (URISyntaxException e) {
|
135 |
|
|
e.printStackTrace();
|
136 |
|
|
}
|
137 |
5a35a97d
|
Patric Plitzner
|
|
138 |
a20b4301
|
Andreas Müller
|
humanGroupVocabulary = TermVocabulary.NewInstance(TermType.Modifier, UsageTermCollection.humanGroupLabel, UsageTermCollection.humanGroupLabel, null, termSourceUri);
|
139 |
|
|
humanGroupVocabulary.setUuid(UsageTermCollection.uuidHumanGroupVocabulary);
|
140 |
5a35a97d
|
Patric Plitzner
|
|
141 |
a20b4301
|
Andreas Müller
|
DefinedTerm newDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
142 |
|
|
newDummyModifier.setUuid(UsageTermCollection.uuidHumanGroupDummy);
|
143 |
5a35a97d
|
Patric Plitzner
|
|
144 |
a20b4301
|
Andreas Müller
|
DefinedTerm newSubDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
145 |
|
|
newSubDummyModifier.setUuid(UsageTermCollection.uuidEthnicGroupDummy);
|
146 |
|
|
newDummyModifier.addIncludes(newSubDummyModifier);
|
147 |
|
|
humanGroupVocabulary.addTerm(newDummyModifier);
|
148 |
5a35a97d
|
Patric Plitzner
|
|
149 |
7ccbcd94
|
Andreas Müller
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(humanGroupVocabulary);
|
150 |
e6a01da7
|
a.theys
|
conversation.commit(true);
|
151 |
|
|
}
|
152 |
7ccbcd94
|
Andreas Müller
|
}
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
private void createPlantVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {
|
156 |
5a35a97d
|
Patric Plitzner
|
TermVocabulary<DefinedTerm> plantPartVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidPlantPartVocabulary);
|
157 |
7ccbcd94
|
Andreas Müller
|
if (plantPartVocabulary == null){
|
158 |
|
|
monitor.subTask("create plant part vocabulary");
|
159 |
e6a01da7
|
a.theys
|
URI termSourceUri = null;
|
160 |
|
|
try {
|
161 |
49a64920
|
Cherian Mathew
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");
|
162 |
e6a01da7
|
a.theys
|
} catch (URISyntaxException e) {
|
163 |
|
|
e.printStackTrace();
|
164 |
|
|
}
|
165 |
a20b4301
|
Andreas Müller
|
plantPartVocabulary = TermVocabulary.NewInstance(TermType.Modifier, UsageTermCollection.plantPartLabel, UsageTermCollection.plantPartLabel, null, termSourceUri);
|
166 |
|
|
plantPartVocabulary.setUuid(UsageTermCollection.uuidPlantPartVocabulary);
|
167 |
5a35a97d
|
Patric Plitzner
|
|
168 |
a20b4301
|
Andreas Müller
|
DefinedTerm newDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
169 |
|
|
newDummyModifier.setUuid(UsageTermCollection.uuidPlantPartDummy);
|
170 |
|
|
plantPartVocabulary.addTerm(newDummyModifier);
|
171 |
5a35a97d
|
Patric Plitzner
|
|
172 |
e6a01da7
|
a.theys
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(plantPartVocabulary);
|
173 |
|
|
conversation.commit(true);
|
174 |
|
|
}
|
175 |
7ccbcd94
|
Andreas Müller
|
}
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
private void createCountryVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {
|
179 |
5a35a97d
|
Patric Plitzner
|
TermVocabulary<DefinedTerm> countryVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidCountryVocabulary);
|
180 |
7ccbcd94
|
Andreas Müller
|
if (countryVocabulary == null){
|
181 |
|
|
monitor.subTask("create country vocabulary");
|
182 |
e6a01da7
|
a.theys
|
URI termSourceUri = null;
|
183 |
|
|
try {
|
184 |
49a64920
|
Cherian Mathew
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");
|
185 |
e6a01da7
|
a.theys
|
} catch (URISyntaxException e) {
|
186 |
|
|
e.printStackTrace();
|
187 |
|
|
}
|
188 |
a20b4301
|
Andreas Müller
|
countryVocabulary = TermVocabulary.NewInstance(TermType.Modifier, UsageTermCollection.countryLabel, UsageTermCollection.countryLabel, null, termSourceUri);
|
189 |
|
|
countryVocabulary.setUuid(UsageTermCollection.uuidCountryVocabulary);
|
190 |
|
|
|
191 |
|
|
DefinedTerm newDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
192 |
|
|
newDummyModifier.setUuid(UsageTermCollection.uuidCountryDummy);
|
193 |
|
|
countryVocabulary.addTerm(newDummyModifier);
|
194 |
|
|
|
195 |
7ccbcd94
|
Andreas Müller
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(countryVocabulary);
|
196 |
e6a01da7
|
a.theys
|
conversation.commit(true);
|
197 |
|
|
}
|
198 |
7ccbcd94
|
Andreas Müller
|
}
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
private void createStateVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {
|
202 |
5a35a97d
|
Patric Plitzner
|
TermVocabulary<State> stateVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidUseCategoryVocabulary);
|
203 |
7ccbcd94
|
Andreas Müller
|
if (stateVocabulary == null){
|
204 |
|
|
monitor.subTask("create state vocabulary");
|
205 |
|
|
URI termSourceUri = null;
|
206 |
|
|
try {
|
207 |
|
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.State");
|
208 |
|
|
} catch (URISyntaxException e) {
|
209 |
|
|
e.printStackTrace();
|
210 |
befcd03c
|
a.theys
|
}
|
211 |
a20b4301
|
Andreas Müller
|
|
212 |
|
|
stateVocabulary = TermVocabulary.NewInstance(TermType.State, UsageTermCollection.useCategoryVocabularyLabel, UsageTermCollection.useCategoryVocabularyLabel, null, termSourceUri);
|
213 |
|
|
stateVocabulary.setUuid(UsageTermCollection.uuidUseCategoryVocabulary);
|
214 |
|
|
|
215 |
7ccbcd94
|
Andreas Müller
|
State newDummyState = State.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
216 |
|
|
newDummyState.setUuid(UsageTermCollection.uuidUseCategoryDummy);
|
217 |
|
|
State newDummySubCat = State.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
218 |
|
|
newDummySubCat.setUuid(UsageTermCollection.uuidUseSubCategoryDummy);
|
219 |
|
|
newDummyState.addIncludes(newDummySubCat);
|
220 |
a20b4301
|
Andreas Müller
|
|
221 |
|
|
stateVocabulary.addTerm(newDummyState);
|
222 |
|
|
|
223 |
7ccbcd94
|
Andreas Müller
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(stateVocabulary);
|
224 |
|
|
conversation.commit(true);
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
private void createUseMarkerType(ConversationHolder conversation) {
|
230 |
|
|
MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);
|
231 |
|
|
if (useMarkertype == null){
|
232 |
|
|
useMarkertype = MarkerType.NewInstance(UsageTermCollection.useMakerLabel, UsageTermCollection.useMakerLabel, null);
|
233 |
|
|
useMarkertype.setUuid( UsageTermCollection.uuidUseMarkerType);
|
234 |
5a35a97d
|
Patric Plitzner
|
TermVocabulary<MarkerType> markerTypeVocabulary = CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidMarkersVocabulary));
|
235 |
7ccbcd94
|
Andreas Müller
|
markerTypeVocabulary.addTerm(useMarkertype);
|
236 |
|
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(markerTypeVocabulary);
|
237 |
e6a01da7
|
a.theys
|
conversation.commit(true);
|
238 |
|
|
}
|
239 |
|
|
}
|
240 |
|
|
}
|