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.descriptive.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
|
import org.eclipse.core.runtime.Status;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
20
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
22
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
23
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
25
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
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 static final String ONLY_ONE_IMAGE_GALLERY_IS_POSSIBLE = Messages.AddDerivedUnitFacadeMediaOperation_CREATE_FAILED_MESSAGE;
|
38
|
private static final String IMAGE_GALLERY_CREATION_FAILED = Messages.AddDerivedUnitFacadeMediaOperation_CREATE_FAILED;
|
39
|
private final SpecimenOrObservationBase<?> specimen;
|
40
|
|
41
|
/**
|
42
|
* @param label
|
43
|
* @param undoContext
|
44
|
* @param postOperationEnabled
|
45
|
*/
|
46
|
public AddDerivedUnitFacadeMediaOperation(String label, IUndoContext undoContext, SpecimenOrObservationBase<?> specimen,
|
47
|
IPostOperationEnabled postOperationEnabled) {
|
48
|
super(label, undoContext, postOperationEnabled);
|
49
|
|
50
|
this.specimen = specimen;
|
51
|
}
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
55
|
*/
|
56
|
@Override
|
57
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
|
58
|
DerivedUnitFacade facade;
|
59
|
try {
|
60
|
if(specimen instanceof FieldUnit){
|
61
|
facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit, (FieldUnit) specimen);
|
62
|
if(facade.hasFieldObjectImageGallery()){
|
63
|
MessagingUtils.informationDialog(IMAGE_GALLERY_CREATION_FAILED, ONLY_ONE_IMAGE_GALLERY_IS_POSSIBLE);
|
64
|
return Status.CANCEL_STATUS;
|
65
|
}
|
66
|
else{
|
67
|
facade.getFieldObjectImageGallery(true);
|
68
|
}
|
69
|
}
|
70
|
else if(specimen instanceof DerivedUnit){
|
71
|
facade = DerivedUnitFacade.NewInstance((DerivedUnit)specimen);
|
72
|
if(facade.hasDerivedUnitImageGallery()){
|
73
|
MessagingUtils.informationDialog(IMAGE_GALLERY_CREATION_FAILED, ONLY_ONE_IMAGE_GALLERY_IS_POSSIBLE);
|
74
|
return Status.CANCEL_STATUS;
|
75
|
}
|
76
|
else{
|
77
|
facade.getDerivedUnitImageGallery(true);
|
78
|
}
|
79
|
}
|
80
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
81
|
MessagingUtils.error(getClass(), e);
|
82
|
}
|
83
|
|
84
|
return postExecute(specimen);
|
85
|
}
|
86
|
|
87
|
|
88
|
/* (non-Javadoc)
|
89
|
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
90
|
*/
|
91
|
@Override
|
92
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
93
|
throws ExecutionException {
|
94
|
// TODO Auto-generated method stub
|
95
|
return null;
|
96
|
}
|
97
|
|
98
|
/* (non-Javadoc)
|
99
|
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
100
|
*/
|
101
|
@Override
|
102
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
103
|
throws ExecutionException {
|
104
|
// TODO Auto-generated method stub
|
105
|
return null;
|
106
|
}
|
107
|
|
108
|
}
|