Revision 1c0edee5
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
10 | 10 |
|
11 |
import java.util.HashSet; |
|
12 |
import java.util.Set; |
|
13 |
|
|
11 | 14 |
import javax.annotation.PostConstruct; |
15 |
import javax.annotation.PreDestroy; |
|
16 |
import javax.inject.Inject; |
|
12 | 17 |
|
18 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
13 | 19 |
import org.eclipse.e4.core.contexts.ContextInjectionFactory; |
14 | 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; |
|
15 | 24 |
import org.eclipse.swt.SWT; |
16 | 25 |
import org.eclipse.swt.widgets.Composite; |
17 | 26 |
import org.eclipse.swt.widgets.Display; |
18 | 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; |
|
19 | 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; |
|
20 | 37 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
38 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
|
21 | 39 |
|
22 | 40 |
/** |
23 | 41 |
* @author pplitzner |
24 | 42 |
* @since Nov 21, 2017 |
25 | 43 |
* |
26 | 44 |
*/ |
27 |
public class WorkingSetEditor { |
|
45 |
public class WorkingSetEditor implements IE4SavablePart{
|
|
28 | 46 |
|
29 | 47 |
private WorkingSetComposite composite; |
30 | 48 |
|
49 |
private ConversationHolder conversation; |
|
50 |
|
|
51 |
private WorkingSet workingSet; |
|
52 |
|
|
53 |
@Inject |
|
54 |
private MDirtyable dirty; |
|
55 |
|
|
31 | 56 |
@PostConstruct |
32 | 57 |
public void create(Composite parent, IEclipseContext context){ |
58 |
if(CdmStore.isActive() && conversation==null){ |
|
59 |
conversation = CdmStore.createConversation(); |
|
60 |
} |
|
61 |
else{ |
|
62 |
return; |
|
63 |
} |
|
33 | 64 |
CdmFormFactory cdmFormFactory = new CdmFormFactory(Display.getCurrent()); |
34 | 65 |
ContextInjectionFactory.inject(cdmFormFactory, context); |
35 | 66 |
composite = new WorkingSetComposite(parent, SWT.NONE); |
67 |
dirty.setDirty(true); |
|
36 | 68 |
} |
37 | 69 |
|
38 | 70 |
public void init(WorkingSet workingSet) { |
71 |
this.workingSet = workingSet; |
|
39 | 72 |
composite.getTxt_label().setText(workingSet.getLabel()); |
40 | 73 |
} |
41 | 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 |
|
|
42 | 126 |
} |
Also available in: Unified diff
ref #7086 Add lifecycle methods to WS editor