Project

General

Profile

Download (3.01 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2013 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10
package eu.etaxonomy.taxeditor.operation;
11

    
12
import org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17

    
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>, D extends DescriptionBase<?>> extends AbstractPostOperation<T> {
30

    
31
    protected D description;
32

    
33
    private final boolean isImageGallery;
34

    
35
    /**
36
     *
37
     */
38
    public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
39
            T describable, IPostOperationEnabled postOperationEnabled) {
40
        this(label, undoContext, describable, postOperationEnabled, false);
41
    }
42

    
43
    /**
44
     *
45
     */
46
    public AbstractDescriptionPostOperation(String label, IUndoContext undoContext,
47
            T describable, IPostOperationEnabled postOperationEnabled,  boolean isImageGallery) {
48
        super(label, undoContext, describable, postOperationEnabled);
49
        this.isImageGallery = isImageGallery;
50
    }
51

    
52
    /* (non-Javadoc)
53
     * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
54
     */
55
    /** {@inheritDoc} */
56
    @Override
57
    public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58
            throws ExecutionException {
59

    
60
        initDescription();
61
        monitor.worked(20);
62

    
63
        if(isImageGallery){
64
            description.setImageGallery(isImageGallery);
65
            // add the description element to hold the media elements for this image gallery
66
            TextData element = TextData.NewInstance(Feature.IMAGE());
67
            element.addMedia(Media.NewInstance());
68
            description.addElement(element);
69
        }
70
        monitor.worked(40);
71

    
72
        return postExecute(description);
73
    }
74

    
75
    /**
76
     * Creates the description and attaches it to the operated element.
77
     */
78
    protected abstract void initDescription();
79

    
80
    /** {@inheritDoc} */
81
    @Override
82
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
83

    
84
    	element.addDescription(description);
85

    
86
    	return postExecute(description);
87
    }
88

    
89
    /** {@inheritDoc} */
90
    @Override
91
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
92

    
93
    	element.removeDescription(description);
94

    
95
    	return postExecute(null);
96
    }
97

    
98
}
(1-1/5)