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.editor.images.handler;
|
12
|
|
13
|
import java.net.URI;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.core.commands.AbstractHandler;
|
17
|
import org.eclipse.core.commands.ExecutionEvent;
|
18
|
import org.eclipse.core.commands.ExecutionException;
|
19
|
import org.eclipse.core.commands.IHandler;
|
20
|
import org.eclipse.core.commands.common.NotDefinedException;
|
21
|
import org.eclipse.core.commands.operations.IUndoableOperation;
|
22
|
import org.eclipse.core.runtime.Status;
|
23
|
import org.eclipse.swt.widgets.Shell;
|
24
|
import org.eclipse.ui.handlers.HandlerUtil;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
27
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
29
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
30
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
31
|
import eu.etaxonomy.taxeditor.editor.Page;
|
32
|
import eu.etaxonomy.taxeditor.editor.images.GalleryLabelComposite;
|
33
|
import eu.etaxonomy.taxeditor.editor.images.TaxonImageEditor;
|
34
|
import eu.etaxonomy.taxeditor.store.model.UriDialog;
|
35
|
import eu.etaxonomy.taxeditor.store.operations.CreateImageOperation;
|
36
|
|
37
|
/**
|
38
|
* @author n.hoffmann
|
39
|
* @created 27.04.2009
|
40
|
* @version 1.0
|
41
|
*/
|
42
|
public class CreateImageHandler extends AbstractHandler implements IHandler {
|
43
|
private static final Logger logger = Logger
|
44
|
.getLogger(CreateImageHandler.class);
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
48
|
*/
|
49
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
50
|
// TaxonImageEditor editor = (TaxonImageEditor) EditorUtil.getActiveEditorPage(
|
51
|
// MultiPageTaxonEditor.PAGE.IMAGE);
|
52
|
|
53
|
MultiPageTaxonEditor editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);
|
54
|
|
55
|
TaxonImageEditor page = (TaxonImageEditor) editor.getPage(Page.IMAGE);
|
56
|
|
57
|
Shell shell = HandlerUtil.getActiveShell(event);
|
58
|
Taxon taxon = editor.getTaxon();
|
59
|
|
60
|
|
61
|
// FIXME right now we have only one description per taxon
|
62
|
// this will change in the future and then attaching the feature to
|
63
|
// the firstGroupedComposite will not work anymore
|
64
|
TaxonDescription description = ((GalleryLabelComposite) page.getFirstGroupedComposite()).getDescription();
|
65
|
|
66
|
|
67
|
URI uri = UriDialog.getUri(shell, "Enter image URI", "Enter the new image's URI:");
|
68
|
// TODO check URI for validity
|
69
|
|
70
|
if (uri == null) {
|
71
|
return Status.CANCEL_STATUS;
|
72
|
}
|
73
|
ImageFile imageFile = ImageFile.NewInstance(uri.toString(), null);
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
IUndoableOperation operation;
|
79
|
try {
|
80
|
operation = new CreateImageOperation(event.getCommand().getName(),
|
81
|
editor.getUndoContext(), taxon, description, imageFile, editor);
|
82
|
EditorUtil.executeOperation(operation);
|
83
|
} catch (NotDefinedException e) {
|
84
|
logger.warn("Command name not set");
|
85
|
}
|
86
|
|
87
|
return null;
|
88
|
}
|
89
|
}
|