p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / operations / images / AddImageOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.operations.images;
12
13 import java.net.URL;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.operations.IUndoContext;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.jface.window.Window;
23
24 import eu.etaxonomy.cdm.model.taxon.Taxon;
25 import eu.etaxonomy.taxeditor.controller.GlobalController;
26 import eu.etaxonomy.taxeditor.editor.images.ImagesController;
27 import eu.etaxonomy.taxeditor.editor.images.UrlDialog;
28 import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation;
29
30 /**
31 * @author p.ciardelli
32 * @created 31.03.2009
33 * @version 1.0
34 */
35 public class AddImageOperation extends AbstractEditorOperation {
36 private static final Logger logger = Logger
37 .getLogger(AddImageOperation.class);
38
39 private URL url;
40
41 /**
42 * @param text
43 * @param undoContext
44 * @param taxon
45 * @param url
46 */
47 public AddImageOperation(String label, IUndoContext undoContext,
48 Taxon taxon) {
49 super(label, undoContext, taxon);
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 @Override
56 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
57 throws ExecutionException {
58
59 url = UrlDialog.getUrl("Enter image URL", "Enter the new image's URL:");
60 if (url == null) {
61 return Status.CANCEL_STATUS;
62 }
63
64 ImagesController.addTaxonImageUrl(taxon, url);
65
66 return redrawOpenEditor();
67 }
68
69 /* (non-Javadoc)
70 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
71 */
72 @Override
73 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
74 throws ExecutionException {
75
76 ImagesController.addTaxonImageUrl(taxon, url);
77
78 return redrawOpenEditor();
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 */
84 @Override
85 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
86 throws ExecutionException {
87
88 ImagesController.removeTaxonImageUrl(taxon, url);
89
90 return redrawOpenEditor();
91 }
92
93
94 }