1
|
/**
|
2
|
* Copyright (C) 2017 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.workingSet;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
|
14
|
import javax.annotation.PostConstruct;
|
15
|
import javax.annotation.PreDestroy;
|
16
|
import javax.inject.Inject;
|
17
|
|
18
|
import org.eclipse.core.runtime.IProgressMonitor;
|
19
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
20
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
21
|
import org.eclipse.e4.ui.di.Focus;
|
22
|
import org.eclipse.e4.ui.di.Persist;
|
23
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
24
|
import org.eclipse.swt.SWT;
|
25
|
import org.eclipse.swt.widgets.Composite;
|
26
|
import org.eclipse.swt.widgets.Display;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
29
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
30
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
31
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
32
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
33
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
36
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
37
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
38
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
39
|
|
40
|
/**
|
41
|
* @author pplitzner
|
42
|
* @since Nov 21, 2017
|
43
|
*
|
44
|
*/
|
45
|
public class WorkingSetEditor implements IE4SavablePart{
|
46
|
|
47
|
private WorkingSetComposite composite;
|
48
|
|
49
|
private ConversationHolder conversation;
|
50
|
|
51
|
private WorkingSet workingSet;
|
52
|
|
53
|
@Inject
|
54
|
private MDirtyable dirty;
|
55
|
|
56
|
@PostConstruct
|
57
|
public void create(Composite parent, IEclipseContext context){
|
58
|
if(CdmStore.isActive() && conversation==null){
|
59
|
conversation = CdmStore.createConversation();
|
60
|
}
|
61
|
else{
|
62
|
return;
|
63
|
}
|
64
|
CdmFormFactory cdmFormFactory = new CdmFormFactory(Display.getCurrent());
|
65
|
ContextInjectionFactory.inject(cdmFormFactory, context);
|
66
|
composite = new WorkingSetComposite(parent, SWT.NONE);
|
67
|
dirty.setDirty(true);
|
68
|
}
|
69
|
|
70
|
public void init(WorkingSet workingSet) {
|
71
|
this.workingSet = workingSet;
|
72
|
composite.getTxt_label().setText(workingSet.getLabel());
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* {@inheritDoc}
|
77
|
*/
|
78
|
@Persist
|
79
|
@Override
|
80
|
public void save(IProgressMonitor monitor) {
|
81
|
NamedArea area = composite.getArea();
|
82
|
Set<NamedArea> areas = new HashSet<>();
|
83
|
if(area!=null){
|
84
|
areas.add(area);
|
85
|
}
|
86
|
TaxonNode taxonNode = composite.getTaxonNode();
|
87
|
FeatureTree characters = composite.getCharacters();
|
88
|
DefinedTermBase rankMaxSelection = composite.getComboRankMax().getSelection();
|
89
|
Rank rankMax = null;
|
90
|
if(rankMaxSelection instanceof Rank){
|
91
|
rankMax = (Rank) rankMaxSelection;
|
92
|
}
|
93
|
DefinedTermBase rankMinSelection = composite.getComboRankMin().getSelection();
|
94
|
Rank rankMin = null;
|
95
|
if(rankMinSelection instanceof Rank){
|
96
|
rankMin = (Rank) rankMinSelection;
|
97
|
}
|
98
|
|
99
|
workingSet.setMaxRank(rankMax);
|
100
|
workingSet.setMinRank(rankMin);
|
101
|
workingSet.setDescriptiveSystem(characters);
|
102
|
workingSet.addTaxonSubtree(taxonNode);
|
103
|
workingSet.setGeoFilter(areas);
|
104
|
|
105
|
conversation.commit();
|
106
|
CdmStore.getService(IWorkingSetService.class).merge(workingSet, true);
|
107
|
|
108
|
dirty.setDirty(false);
|
109
|
}
|
110
|
|
111
|
@Focus
|
112
|
public void setFocus(){
|
113
|
if(conversation!=null){
|
114
|
conversation.bind();
|
115
|
}
|
116
|
}
|
117
|
|
118
|
@PreDestroy
|
119
|
public void dispose(){
|
120
|
if(conversation!=null){
|
121
|
conversation.close();
|
122
|
conversation = null;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
}
|