Revision 695a18b1
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet.matrix; |
10 | 10 |
|
11 |
import java.util.Date; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Set; |
|
12 | 15 |
|
13 | 16 |
import javax.annotation.PostConstruct; |
17 |
import javax.annotation.PreDestroy; |
|
18 |
import javax.inject.Inject; |
|
14 | 19 |
|
20 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
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.jface.layout.GridDataFactory; |
16 | 25 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
17 | 26 |
import org.eclipse.nebula.widgets.nattable.data.IDataProvider; |
... | ... | |
30 | 39 |
import org.eclipse.swt.layout.GridLayout; |
31 | 40 |
import org.eclipse.swt.widgets.Composite; |
32 | 41 |
|
42 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
43 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
44 |
import eu.etaxonomy.cdm.api.service.IWorkingSetService; |
|
45 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
33 | 46 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
34 | 47 |
import eu.etaxonomy.cdm.model.description.WorkingSet; |
48 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
|
49 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
50 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
51 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
52 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
|
35 | 53 |
|
36 | 54 |
/** |
37 | 55 |
* @author pplitzner |
38 | 56 |
* @since Nov 26, 2017 |
39 | 57 |
* |
40 | 58 |
*/ |
41 |
public class CharacterMatrix { |
|
59 |
public class CharacterMatrix implements IE4SavablePart{
|
|
42 | 60 |
|
43 | 61 |
private WorkingSet workingSet; |
44 | 62 |
|
63 |
private Composite parent; |
|
64 |
|
|
65 |
private ConversationHolder conversation; |
|
66 |
|
|
67 |
@Inject |
|
68 |
private MDirtyable dirty; |
|
69 |
|
|
45 | 70 |
@PostConstruct |
46 | 71 |
public void create(Composite parent) { |
72 |
if(CdmStore.isActive() && conversation==null){ |
|
73 |
conversation = CdmStore.createConversation(); |
|
74 |
} |
|
75 |
else{ |
|
76 |
return; |
|
77 |
} |
|
47 | 78 |
parent.setLayout(new GridLayout()); |
79 |
this.parent = parent; |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
public void init(WorkingSet workingSet) { |
|
84 |
this.workingSet = workingSet; |
|
48 | 85 |
|
49 | 86 |
// create the data provider |
50 |
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(DataSource.getWorkingSet());
|
|
51 |
IDataProvider bodyDataProvider = new ListDataProvider<SpecimenDescription>(DataSource.getDescriptions(), columnPropertyAccessor);
|
|
87 |
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(workingSet);
|
|
88 |
IDataProvider bodyDataProvider = new ListDataProvider<SpecimenDescription>(getDescriptions(workingSet), columnPropertyAccessor);
|
|
52 | 89 |
|
53 | 90 |
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider); |
54 | 91 |
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer); |
... | ... | |
77 | 114 |
|
78 | 115 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable); |
79 | 116 |
|
117 |
parent.layout(); |
|
80 | 118 |
} |
81 | 119 |
|
82 |
public void init(WorkingSet workingSet) { |
|
83 |
this.workingSet = workingSet; |
|
84 |
} |
|
85 |
|
|
86 |
public class Person { |
|
87 |
private int id; |
|
88 |
private String name; |
|
89 |
private Date birthDate; |
|
90 |
|
|
91 |
public Person(int id, String name, Date birthDate) { |
|
92 |
this.id = id; |
|
93 |
this.name = name; |
|
94 |
this.birthDate = birthDate; |
|
95 |
} |
|
96 |
|
|
97 |
public int getId() { |
|
98 |
return id; |
|
120 |
private List<SpecimenDescription> getDescriptions(WorkingSet workingSet) { |
|
121 |
List<SpecimenDescription> descriptions = new ArrayList<>(); |
|
122 |
Set<TaxonNode> taxonSubtreeFilter = workingSet.getTaxonSubtreeFilter(); |
|
123 |
for (TaxonNode taxonNode : taxonSubtreeFilter) { |
|
124 |
Taxon taxon = taxonNode.getTaxon(); |
|
125 |
if(taxon!=null){ |
|
126 |
taxon = HibernateProxyHelper.deproxy(taxon, Taxon.class); |
|
127 |
Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null); |
|
128 |
for (SpecimenOrObservationBase specimen : specimens) { |
|
129 |
descriptions.addAll(specimen.getSpecimenDescriptions()); |
|
130 |
} |
|
131 |
} |
|
99 | 132 |
} |
133 |
return descriptions; |
|
134 |
} |
|
100 | 135 |
|
101 |
public void setId(int id) { |
|
102 |
this.id = id; |
|
103 |
} |
|
104 | 136 |
|
105 |
public String getName() { |
|
106 |
return name; |
|
107 |
} |
|
137 |
@Persist |
|
138 |
@Override |
|
139 |
public void save(IProgressMonitor monitor) { |
|
140 |
conversation.commit(); |
|
141 |
CdmStore.getService(IWorkingSetService.class).merge(workingSet, true); |
|
108 | 142 |
|
109 |
public void setName(String name) { |
|
110 |
this.name = name; |
|
111 |
} |
|
143 |
dirty.setDirty(false); |
|
144 |
} |
|
112 | 145 |
|
113 |
public Date getBirthDate() { |
|
114 |
return birthDate; |
|
146 |
@Focus |
|
147 |
public void setFocus(){ |
|
148 |
if(conversation!=null){ |
|
149 |
conversation.bind(); |
|
115 | 150 |
} |
151 |
} |
|
116 | 152 |
|
117 |
public void setBirthDate(Date birthDate) { |
|
118 |
this.birthDate = birthDate; |
|
153 |
@PreDestroy |
|
154 |
public void dispose(){ |
|
155 |
if(conversation!=null){ |
|
156 |
conversation.close(); |
|
157 |
conversation = null; |
|
119 | 158 |
} |
120 |
|
|
121 | 159 |
} |
160 |
|
|
122 | 161 |
} |
Also available in: Unified diff
ref #7095 Add editor capabilities to character matrix editor