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