Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
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 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.api.utility.ImagesUtility;
19
import eu.etaxonomy.cdm.model.description.DescriptionBase;
20
import eu.etaxonomy.cdm.model.media.Media;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23
/**
24
 * This operation creates a new {@link Media} and adds it to the currently selected {@link DescriptionBase}.
25
 *
26
 * @author p.ciardelli
27
 * @author n.hoffmann
28
 * @created 05.02.2009
29
 * @version 1.0
30
 */
31
public class AddMediaToImageGalleryOperation extends AbstractPostTaxonOperation {
32

    
33
	private final DescriptionBase<?> description;
34
	private Media media;
35

    
36
	/**
37
	 * <p>Constructor for AddMediaToImageGalleryOperation.</p>
38
	 *
39
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
40
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
41
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
42
	 * @param label a {@link java.lang.String} object.
43
	 * @param description a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
44
	 */
45
	public AddMediaToImageGalleryOperation(String label,
46
			IUndoContext undoContext, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
47
	    this(null, label, undoContext, description, postOperationEnabled);
48
	    media = Media.NewInstance();
49
	}
50

    
51
	protected AddMediaToImageGalleryOperation(Media media, String label,
52
	        IUndoContext undoContext, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
53
	    super(label, undoContext, postOperationEnabled);
54

    
55
	    this.description = description;
56
	    this.media = media;
57
	}
58

    
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
61
	 */
62
	/** {@inheritDoc} */
63
	@Override
64
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
65
			throws ExecutionException {
66

    
67
		monitor.worked(20);
68

    
69
		ImagesUtility.addMediaToGallery(description, media);
70

    
71
		monitor.worked(40);
72

    
73
		return postExecute(media);
74
	}
75

    
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78
	 */
79
	/** {@inheritDoc} */
80
	@Override
81
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
82
			throws ExecutionException {
83
		return execute(monitor, info);
84
	}
85

    
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88
	 */
89
	/** {@inheritDoc} */
90
	@Override
91
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
92
			throws ExecutionException {
93
		ImagesUtility.removeMediaFromGallery(description, media);
94
		return postExecute(description);
95
	}
96
}
(2-2/6)