2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.operation
;
11 import java
.util
.Collection
;
12 import java
.util
.HashSet
;
15 import org
.eclipse
.core
.runtime
.IAdaptable
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.MultiStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
21 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
.Action
;
22 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
29 public abstract class RemotingCdmUpdateOperation
extends RemotingCdmOperation
{
31 private UpdateResult updateResult
;
32 public static boolean throwExceptions
= false;
37 public RemotingCdmUpdateOperation(String label
, Action action
, Object source
, boolean async
) {
38 super(label
, action
, source
, async
);
42 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
45 protected boolean doExecute(IProgressMonitor monitor
, IAdaptable info
) {
47 updateResult
= doUpdateExecute(monitor
, info
);
48 } catch (Exception e
) {
50 throw new RuntimeException(e
);
52 UpdateResult exceptionResult
= new UpdateResult();
53 exceptionResult
.addException(e
);
54 exceptionResult
.setAbort();
55 updateResult
= exceptionResult
;
58 return updateResult
.isOk();
61 protected abstract UpdateResult
doUpdateExecute(IProgressMonitor monitor
, IAdaptable info
) throws Exception
;
64 protected void postExecute(boolean success
) {
65 if(success
&& updateResult
!= null) {
66 fireDataChangeEvent(updateResult
);
72 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmOperation#onComplete(boolean)
75 protected IStatus
onComplete(boolean success
) {
77 if(updateResult
!= null) {
78 int statusFlag
= IStatus
.OK
;
80 Collection
<Exception
> exceptions
= updateResult
.getExceptions();
81 StringBuffer statusMsg
= new StringBuffer();
82 if(success
&& updateResult
.isOk()) {
83 if(exceptions
.isEmpty()) {
84 return Status
.OK_STATUS
;
86 statusFlag
= IStatus
.WARNING
;
87 statusMsg
.append(getLabel() + " executed sucessfully but with warnings." + System
.lineSeparator());
89 } else if (updateResult
.isError()) {
90 statusFlag
= IStatus
.ERROR
;
91 statusMsg
.append(getLabel() + " failed." + System
.lineSeparator());
92 } else if (updateResult
.isAbort()) {
93 statusFlag
= IStatus
.ERROR
;
94 statusMsg
.append(getLabel() + " aborted." + System
.lineSeparator());
97 Status
[] childStatus
= new Status
[exceptions
.size()];
99 Set
<String
> messages
= new HashSet
<String
>();
100 for(Exception ex
: exceptions
) {
101 Status status
= new Status(statusFlag
,
104 ex
.getLocalizedMessage(),
106 messages
.add(ex
.getLocalizedMessage());
107 childStatus
[count
] = status
;
111 statusMsg
.append("Please click on the 'Details' button to see all the errors / warnings");
113 MultiStatus multiStatus
= new MultiStatus("unknown",
116 statusMsg
.toString(),