1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.view.media.operation;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.core.commands.operations.IUndoContext;
|
17
|
import org.eclipse.core.runtime.IAdaptable;
|
18
|
import org.eclipse.core.runtime.IProgressMonitor;
|
19
|
import org.eclipse.core.runtime.IStatus;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
22
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
23
|
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
|
24
|
import eu.etaxonomy.cdm.api.utility.ImagesUtility;
|
25
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
26
|
import eu.etaxonomy.cdm.model.media.Media;
|
27
|
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
|
28
|
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
|
29
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
30
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
|
33
|
/**
|
34
|
* <p>DeleteMediaOperation class.</p>
|
35
|
*
|
36
|
* @author p.ciardelli
|
37
|
* @created 31.03.2009
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
public class DeleteMediaOperation extends AbstractPostTaxonOperation {
|
41
|
|
42
|
private final Media media;
|
43
|
|
44
|
private final DescriptionBase<?> description;
|
45
|
|
46
|
private final MediaDeletionConfigurator config;
|
47
|
|
48
|
/**
|
49
|
* <p>Constructor for DeleteMediaOperation.</p>
|
50
|
*
|
51
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
52
|
* @param label a {@link java.lang.String} object.
|
53
|
* @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
|
54
|
* @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
|
55
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
56
|
*/
|
57
|
public DeleteMediaOperation(String label, IUndoContext undoContext,
|
58
|
DescriptionBase<?> description, Media media, MediaDeletionConfigurator config, IPostOperationEnabled postOperationEnabled) {
|
59
|
super(label, undoContext, postOperationEnabled);
|
60
|
this.config = config;
|
61
|
this.media = media;
|
62
|
this.description = description;
|
63
|
}
|
64
|
|
65
|
/* (non-Javadoc)
|
66
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
67
|
*/
|
68
|
/** {@inheritDoc} */
|
69
|
@Override
|
70
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
71
|
throws ExecutionException {
|
72
|
|
73
|
// ImagesUtility.removeMediaFromGallery(description, media);
|
74
|
if (monitor != null) {
|
75
|
monitor.worked(20);
|
76
|
}
|
77
|
if (!config.isOnlyRemoveFromGallery() && media.getId() != 0){
|
78
|
DeleteResult result = CdmStore.getService(IMediaService.class).delete(media.getUuid(), config);
|
79
|
String errorMessage = "The media ";
|
80
|
|
81
|
if (!result.isOk()){
|
82
|
List<String> messages = new ArrayList<String>();
|
83
|
int i = result.getExceptions().size();
|
84
|
for (Exception e:result.getExceptions()){
|
85
|
messages.add(e.getMessage());
|
86
|
}
|
87
|
errorMessage += "could not be deleted from database. ";
|
88
|
//MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
|
89
|
DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
|
90
|
// if (config.isDeleteFromDescription()){
|
91
|
// ImagesUtility.removeMediaFromGallery(description, media);
|
92
|
// }
|
93
|
}else{
|
94
|
// ImagesUtility.removeMediaFromGallery(description, media);
|
95
|
}
|
96
|
} else{
|
97
|
// ImagesUtility.removeMediaFromGallery(description, media);
|
98
|
}
|
99
|
if (monitor != null){
|
100
|
monitor.worked(40);
|
101
|
}
|
102
|
|
103
|
return postExecute(media);
|
104
|
}
|
105
|
|
106
|
/* (non-Javadoc)
|
107
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
108
|
*/
|
109
|
/** {@inheritDoc} */
|
110
|
@Override
|
111
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
112
|
throws ExecutionException {
|
113
|
return execute(monitor, info);
|
114
|
}
|
115
|
|
116
|
/* (non-Javadoc)
|
117
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
118
|
*/
|
119
|
/** {@inheritDoc} */
|
120
|
@Override
|
121
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
122
|
throws ExecutionException {
|
123
|
|
124
|
ImagesUtility.addMediaToGallery(description, media);
|
125
|
|
126
|
return postExecute(null);
|
127
|
}
|
128
|
|
129
|
|
130
|
}
|