Revision 0fa0610e
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/NaturalLanguageDetailElement.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 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 |
*/ |
... | ... | |
16 | 16 |
import org.eclipse.core.runtime.IStatus; |
17 | 17 |
import org.eclipse.core.runtime.Status; |
18 | 18 |
import org.eclipse.core.runtime.jobs.Job; |
19 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
|
19 | 20 |
import org.eclipse.swt.widgets.Display; |
20 | 21 |
|
21 | 22 |
import eu.etaxonomy.cdm.api.service.NaturalLanguageGenerator; |
22 | 23 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
23 | 24 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
24 | 25 |
import eu.etaxonomy.cdm.model.description.TextData; |
26 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
25 | 27 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
26 | 28 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
27 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
|
28 | 29 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
29 | 30 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; |
30 | 31 |
import eu.etaxonomy.taxeditor.ui.element.LabelElement; |
... | ... | |
38 | 39 |
* @version 1.0 |
39 | 40 |
*/ |
40 | 41 |
public class NaturalLanguageDetailElement extends AbstractCdmDetailElement<TaxonDescription> { |
41 |
|
|
42 |
|
|
42 | 43 |
|
43 | 44 |
private static final Logger logger = Logger |
44 | 45 |
.getLogger(NaturalLanguageDetailElement.class); |
... | ... | |
54 | 55 |
ICdmFormElement formElement) { |
55 | 56 |
super(formFactory, formElement); |
56 | 57 |
} |
57 |
|
|
58 |
|
|
58 | 59 |
/** {@inheritDoc} */ |
59 | 60 |
@Override |
60 | 61 |
protected void createControls(ICdmFormElement formElement, |
61 | 62 |
TaxonDescription entity, int style) { |
62 | 63 |
label = formFactory.createLabel(formElement, "Generating Natural Language Description ..."); |
63 |
|
|
64 |
|
|
64 | 65 |
if(entity.hasStructuredData()){ |
65 | 66 |
FetchNaturalLanguageDescriptionJob job = new FetchNaturalLanguageDescriptionJob("Retrieving Natural Language Description", entity); |
66 | 67 |
job.schedule(); |
... | ... | |
68 | 69 |
label.setText("Taxon Description does not contain structured data."); |
69 | 70 |
} |
70 | 71 |
} |
71 |
|
|
72 |
|
|
72 | 73 |
/* (non-Javadoc) |
73 | 74 |
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java.lang.Object) |
74 | 75 |
*/ |
... | ... | |
77 | 78 |
public void handleEvent(Object eventSource) { |
78 | 79 |
// nothing gets edited, nothing gets updated |
79 | 80 |
} |
80 |
|
|
81 |
|
|
81 | 82 |
private class FetchNaturalLanguageDescriptionJob extends Job { |
82 | 83 |
|
83 | 84 |
private TaxonDescription entity; |
84 | 85 |
private NaturalLanguageGenerator generator = new NaturalLanguageGenerator(); |
85 | 86 |
private FeatureTree featureTree = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription(); |
86 | 87 |
private Display display = Display.getCurrent(); |
87 |
|
|
88 |
|
|
88 | 89 |
public FetchNaturalLanguageDescriptionJob(String jobName, TaxonDescription entity){ |
89 | 90 |
super(jobName); |
90 | 91 |
this.entity = entity; |
91 | 92 |
} |
92 |
|
|
93 |
|
|
93 | 94 |
@Override |
94 | 95 |
protected IStatus run(IProgressMonitor monitor) { |
95 | 96 |
String text = ""; |
96 |
|
|
97 |
|
|
97 | 98 |
if(featureTree != null){ |
98 | 99 |
CdmStore.createConversation(); |
99 | 100 |
try{ |
100 | 101 |
List<TextData> naturalLanguageDescription = generator.generateNaturalLanguageDescription(featureTree, entity, CdmStore.getDefaultLanguage()); |
101 |
|
|
102 |
|
|
102 | 103 |
for(TextData element : naturalLanguageDescription){ |
103 | 104 |
text += element.getText(CdmStore.getDefaultLanguage()) + " "; |
104 | 105 |
} |
... | ... | |
109 | 110 |
else{ |
110 | 111 |
text = "Could not generate natural language description, because no Feature Tree was set."; |
111 | 112 |
} |
112 |
|
|
113 |
|
|
113 | 114 |
final String aggregatedText = text; |
114 |
|
|
115 |
|
|
115 | 116 |
display.asyncExec(new Runnable(){ |
116 | 117 |
|
117 | 118 |
@Override |
118 | 119 |
public void run() { |
119 | 120 |
label.setText(aggregatedText); |
120 |
StoreUtil.reflowDetailsViewer();
|
|
121 |
AbstractUtility.reflowDetailsViewer(formFactory.getContext().get(EPartService.class));
|
|
121 | 122 |
} |
122 |
|
|
123 |
|
|
123 | 124 |
}); |
124 |
|
|
125 |
|
|
125 | 126 |
return Status.OK_STATUS; |
126 | 127 |
} |
127 |
|
|
128 |
|
|
128 | 129 |
} |
129 | 130 |
} |
Also available in: Unified diff
ref #6913 Remove org.eclipse.ui dependency from AbstractUtility