3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.operation
;
12 import java
.util
.Collection
;
13 import java
.util
.HashSet
;
16 import org
.eclipse
.core
.runtime
.IAdaptable
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.MultiStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
22 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
.Action
;
23 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
30 public abstract class RemotingCdmUpdateOperation
extends RemotingCdmOperation
{
32 private UpdateResult updateResult
;
33 public static boolean throwExceptions
= false;
38 public RemotingCdmUpdateOperation(String label
, Action action
, Object source
, boolean async
) {
39 super(label
, action
, source
, async
);
43 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
46 protected boolean doExecute(IProgressMonitor monitor
, IAdaptable info
) {
48 updateResult
= doUpdateExecute(monitor
, info
);
49 } catch (Exception e
) {
51 throw new RuntimeException(e
);
53 UpdateResult exceptionResult
= new UpdateResult();
54 exceptionResult
.addException(e
);
55 exceptionResult
.setAbort();
56 updateResult
= exceptionResult
;
59 return updateResult
.isOk();
62 protected abstract UpdateResult
doUpdateExecute(IProgressMonitor monitor
, IAdaptable info
) throws Exception
;
65 protected void postExecute(boolean success
) {
66 if(success
&& updateResult
!= null) {
67 fireDataChangeEvent(updateResult
);
73 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmOperation#onComplete(boolean)
76 protected IStatus
onComplete(boolean success
) {
78 if(updateResult
!= null) {
79 int statusFlag
= IStatus
.OK
;
81 Collection
<Exception
> exceptions
= updateResult
.getExceptions();
82 StringBuffer statusMsg
= new StringBuffer();
83 if(success
&& updateResult
.isOk()) {
84 if(exceptions
.isEmpty()) {
85 return Status
.OK_STATUS
;
87 statusFlag
= IStatus
.WARNING
;
88 statusMsg
.append(getLabel() + " executed sucessfully but with warnings." + System
.lineSeparator());
90 } else if (updateResult
.isError()) {
91 statusFlag
= IStatus
.ERROR
;
92 statusMsg
.append(getLabel() + " failed." + System
.lineSeparator());
93 } else if (updateResult
.isAbort()) {
94 statusFlag
= IStatus
.ERROR
;
95 statusMsg
.append(getLabel() + " aborted." + System
.lineSeparator());
98 Status
[] childStatus
= new Status
[exceptions
.size()];
100 Set
<String
> messages
= new HashSet
<String
>();
101 for(Exception ex
: exceptions
) {
102 Status status
= new Status(statusFlag
,
105 ex
.getLocalizedMessage(),
107 messages
.add(ex
.getLocalizedMessage());
108 childStatus
[count
] = status
;
112 statusMsg
.append("Please click on the 'Details' button to see all the errors / warnings");
114 MultiStatus multiStatus
= new MultiStatus("unknown",
117 statusMsg
.toString(),