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.view.descriptive.operation;
|
12
|
|
13
|
import org.eclipse.core.commands.ExecutionException;
|
14
|
import org.eclipse.core.commands.operations.IUndoContext;
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.core.runtime.Status;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
21
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
22
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
23
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
25
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
26
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
27
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
28
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
29
|
|
30
|
/**
|
31
|
* @author n.hoffmann
|
32
|
* @created Feb 11, 2011
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class AddDerivedUnitFacadeMediaOperation extends AbstractPostTaxonOperation {
|
36
|
|
37
|
private final SpecimenOrObservationBase<?> specimen;
|
38
|
|
39
|
/**
|
40
|
* @param label
|
41
|
* @param undoContext
|
42
|
* @param postOperationEnabled
|
43
|
*/
|
44
|
public AddDerivedUnitFacadeMediaOperation(String label, IUndoContext undoContext, SpecimenOrObservationBase<?> specimen,
|
45
|
IPostOperationEnabled postOperationEnabled) {
|
46
|
super(label, undoContext, postOperationEnabled);
|
47
|
|
48
|
this.specimen = specimen;
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
53
|
*/
|
54
|
@Override
|
55
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
56
|
DerivedUnitFacade facade;
|
57
|
try {
|
58
|
if(specimen instanceof FieldUnit){
|
59
|
facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit) specimen);
|
60
|
if(facade.hasFieldObjectImageGallery()){
|
61
|
MessagingUtils.informationDialog("Image gallery creation failed", "Only one image gallery is possible.");
|
62
|
return Status.CANCEL_STATUS;
|
63
|
}
|
64
|
else{
|
65
|
facade.getFieldObjectImageGallery(true);
|
66
|
}
|
67
|
}
|
68
|
else if(specimen instanceof DerivedUnit){
|
69
|
facade = DerivedUnitFacade.NewInstance((DerivedUnit)specimen);
|
70
|
if(facade.hasDerivedUnitImageGallery()){
|
71
|
MessagingUtils.informationDialog("Image gallery creation failed", "Only one image gallery is possible.");
|
72
|
return Status.CANCEL_STATUS;
|
73
|
}
|
74
|
else{
|
75
|
facade.getDerivedUnitImageGallery(true);
|
76
|
}
|
77
|
}
|
78
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
79
|
MessagingUtils.error(getClass(), e);
|
80
|
}
|
81
|
|
82
|
return postExecute(specimen);
|
83
|
}
|
84
|
|
85
|
|
86
|
/* (non-Javadoc)
|
87
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
88
|
*/
|
89
|
@Override
|
90
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
91
|
throws ExecutionException {
|
92
|
// TODO Auto-generated method stub
|
93
|
return null;
|
94
|
}
|
95
|
|
96
|
/* (non-Javadoc)
|
97
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
98
|
*/
|
99
|
@Override
|
100
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
101
|
throws ExecutionException {
|
102
|
// TODO Auto-generated method stub
|
103
|
return null;
|
104
|
}
|
105
|
|
106
|
}
|