Project

General

Profile

Download (2.97 KB) Statistics
| Branch: | Tag: | Revision:
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.common.IdentifiableSource;
18
import eu.etaxonomy.cdm.model.description.DescriptionBase;
19
import eu.etaxonomy.cdm.model.description.Feature;
20
import eu.etaxonomy.cdm.model.description.IDescribable;
21
import eu.etaxonomy.cdm.model.description.TextData;
22
import eu.etaxonomy.cdm.model.media.Media;
23

    
24
/**
25
 * @author pplitzner
26
 * @date 04.12.2013
27
 *
28
 */
29
public abstract class AbstractDescriptionPostOperation<T extends IDescribable, D extends DescriptionBase> extends AbstractPostOperation<T> {
30

    
31
    protected D description;
32
    protected IdentifiableSource source;
33

    
34
    private final boolean isImageGallery;
35

    
36
    public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
37
            T describable, IdentifiableSource source, IPostOperationEnabled postOperationEnabled) {
38
        this(label, undoContext, describable, source, postOperationEnabled, false);
39
    }
40

    
41
    public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
42
            T describable, IdentifiableSource source, IPostOperationEnabled postOperationEnabled,  boolean isImageGallery) {
43
        super(label, undoContext, describable, postOperationEnabled);
44
        this.isImageGallery = isImageGallery;
45
        this.source = source;
46
    }
47

    
48
    @Override
49
    public IStatus execute(IProgressMonitor monitor, IAdaptable info)
50
            throws ExecutionException {
51

    
52
        initDescription();
53
        if(source!=null){
54
            description.addSource(source);
55
        }
56
        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
    }
90

    
91
}
(1-1/11)