Revision ddb0eef3
Added by pplitzner over 4 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixBottomToolbar.java | ||
---|---|---|
13 | 13 |
import java.util.List; |
14 | 14 |
import java.util.Map; |
15 | 15 |
import java.util.UUID; |
16 |
import java.util.stream.Collectors; |
|
16 | 17 |
|
17 | 18 |
import org.eclipse.core.runtime.ICoreRunnable; |
18 | 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
... | ... | |
39 | 40 |
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl; |
40 | 41 |
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO; |
41 | 42 |
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO; |
42 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
43 | 43 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
44 | 44 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
45 | 45 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
... | ... | |
100 | 100 |
+ "Do you want to create this association?")){ |
101 | 101 |
return; |
102 | 102 |
} |
103 |
String error = ""; //$NON-NLS-1$ |
|
104 |
for (SpecimenNodeWrapper wrapper : wrappers) { |
|
105 |
SpecimenRowWrapperDTO rowWrapper = CdmStore.getService(IDescriptiveDataSetService.class) |
|
106 |
.addRowWrapperToDataset(wrapper, matrix.getDescriptiveDataSet().getUuid()); |
|
107 |
if(rowWrapper==null){ |
|
108 |
error += wrapper.getUuidAndTitleCache().getTitleCache(); |
|
109 |
error += "\n"; |
|
110 |
continue; |
|
111 |
} |
|
112 |
|
|
113 |
//add wrapper to matrix |
|
114 |
matrix.getDescriptions().add(rowWrapper); |
|
115 |
// matrix.getCdmEntitiySession().load(specimenDescription, true); |
|
116 |
// matrix.getCdmEntitiySession().load(taxonDescription, true); |
|
117 |
|
|
118 |
matrix.setDirty(); |
|
119 |
matrix.getSpecimenCache().remove(wrapper); |
|
120 |
} |
|
121 |
if(CdmUtils.isNotBlank(error)){ |
|
122 |
MessagingUtils.warningDialog(Messages.CharacterMatrixBottomToolbar_ERROR_ROW_CREATION_TITLE, this, |
|
123 |
String.format(Messages.CharacterMatrixBottomToolbar_ERROR_ROW_CREATION_MESSAGE, error)); |
|
124 |
} |
|
103 |
addRowsToMatrix(wrappers, matrix.getDescriptiveDataSet().getUuid()); |
|
104 |
wrappers.forEach(wrapper->matrix.getSpecimenCache().remove(wrapper)); |
|
125 | 105 |
} |
126 | 106 |
} |
127 | 107 |
}); |
... | ... | |
243 | 223 |
job.schedule(); |
244 | 224 |
} |
245 | 225 |
|
226 |
private void addRowsToMatrix(Collection<SpecimenNodeWrapper> wrappers, UUID descriptiveDataSetUuid){ |
|
227 |
UUID monitorUuid = CdmApplicationState.getLongRunningTasksService().addRowWrapperToDataset(wrappers, descriptiveDataSetUuid); |
|
228 |
|
|
229 |
String jobLabel = "Add specimens to matrix"; |
|
230 |
Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> { |
|
231 |
SubMonitor subMonitor = SubMonitor.convert(monitor); |
|
232 |
subMonitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN); |
|
233 |
IRemotingProgressMonitor remotingMonitor; |
|
234 |
try { |
|
235 |
remotingMonitor = CdmStore.getProgressMonitorClientManager() |
|
236 |
.pollMonitor(jobLabel, |
|
237 |
monitorUuid, |
|
238 |
50, |
|
239 |
null, |
|
240 |
(List)null, |
|
241 |
subMonitor); |
|
242 |
Object resultObject = remotingMonitor.getResult(); |
|
243 |
if(resultObject instanceof Exception){ |
|
244 |
MessagingUtils.errorDialog("Adding specimens failed", this, "Adding specimens was not successfull", TaxeditorEditorPlugin.PLUGIN_ID, (Exception)resultObject, true, true); |
|
245 |
} |
|
246 |
else if(resultObject instanceof UpdateResult){ |
|
247 |
UpdateResult result = (UpdateResult)resultObject; |
|
248 |
if(!result.getExceptions().isEmpty()){ |
|
249 |
MessagingUtils.warningDialog(Messages.CharacterMatrixBottomToolbar_ERROR_ROW_CREATION_TITLE, this, |
|
250 |
String.format(Messages.CharacterMatrixBottomToolbar_ERROR_ROW_CREATION_MESSAGE, result.getExceptions() |
|
251 |
.stream().map(ex->ex.toString()) |
|
252 |
.collect(Collectors.joining("\n")))); |
|
253 |
} |
|
254 |
matrix.loadDescriptions(descriptiveDataSetUuid); |
|
255 |
} |
|
256 |
} catch (InterruptedException e) { |
|
257 |
return; |
|
258 |
} |
|
259 |
monitor.done(); |
|
260 |
}); |
|
261 |
job.addJobChangeListener(new JobChangeAdapter(){ |
|
262 |
@Override |
|
263 |
public void done(IJobChangeEvent event) { |
|
264 |
CharacterMatrixBottomToolbar.this.getDisplay().asyncExec(()->{ |
|
265 |
matrix.redraw(); |
|
266 |
}); |
|
267 |
} |
|
268 |
}); |
|
269 |
job.schedule(); |
|
270 |
} |
|
271 |
|
|
246 | 272 |
private void aggregateCharts() { |
247 | 273 |
new Job("aggregate charts") { |
248 | 274 |
|
Also available in: Unified diff
ref #8539 Add specimens to matrix as long running task