1
|
/**
|
2
|
* Copyright (C) 2013 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
|
package eu.etaxonomy.taxeditor.operation;
|
10
|
|
11
|
import org.eclipse.core.commands.ExecutionException;
|
12
|
import org.eclipse.core.commands.operations.IUndoContext;
|
13
|
import org.eclipse.core.runtime.IAdaptable;
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
18
|
import eu.etaxonomy.cdm.model.description.Feature;
|
19
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
20
|
import eu.etaxonomy.cdm.model.description.TextData;
|
21
|
import eu.etaxonomy.cdm.model.media.Media;
|
22
|
|
23
|
/**
|
24
|
* @author pplitzner
|
25
|
* @date 04.12.2013
|
26
|
*
|
27
|
*/
|
28
|
public abstract class AbstractDescriptionPostOperation<T extends IDescribable, D extends DescriptionBase> extends AbstractPostOperation<T> {
|
29
|
|
30
|
protected D description;
|
31
|
|
32
|
private final boolean isImageGallery;
|
33
|
|
34
|
/**
|
35
|
*
|
36
|
*/
|
37
|
public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
|
38
|
T describable, IPostOperationEnabled postOperationEnabled) {
|
39
|
this(label, undoContext, describable, postOperationEnabled, false);
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
*
|
44
|
*/
|
45
|
public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
|
46
|
T describable, IPostOperationEnabled postOperationEnabled, boolean isImageGallery) {
|
47
|
super(label, undoContext, describable, postOperationEnabled);
|
48
|
this.isImageGallery = isImageGallery;
|
49
|
}
|
50
|
|
51
|
/** {@inheritDoc} */
|
52
|
@Override
|
53
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
54
|
throws ExecutionException {
|
55
|
|
56
|
initDescription();
|
57
|
monitor.worked(20);
|
58
|
|
59
|
if(isImageGallery){
|
60
|
description.setImageGallery(isImageGallery);
|
61
|
// add the description element to hold the media elements for this image gallery
|
62
|
TextData element = TextData.NewInstance(Feature.IMAGE());
|
63
|
element.addMedia(Media.NewInstance());
|
64
|
description.addElement(element);
|
65
|
}
|
66
|
monitor.worked(40);
|
67
|
|
68
|
return postExecute(description);
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Creates the description and attaches it to the operated element.
|
73
|
*/
|
74
|
protected abstract void initDescription();
|
75
|
|
76
|
/** {@inheritDoc} */
|
77
|
@Override
|
78
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
79
|
|
80
|
element.addDescription(description);
|
81
|
|
82
|
return postExecute(description);
|
83
|
}
|
84
|
|
85
|
/** {@inheritDoc} */
|
86
|
@Override
|
87
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
88
|
|
89
|
element.removeDescription(description);
|
90
|
|
91
|
return postExecute(null);
|
92
|
}
|
93
|
|
94
|
}
|