3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
;
12 import java
.util
.Collection
;
13 import java
.util
.UUID
;
15 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
16 import org
.eclipse
.ui
.IEditorInput
;
17 import org
.eclipse
.ui
.IPersistableElement
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
20 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
21 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
22 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
23 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
28 * the derivate hierarchy should be shown in the DerivateView.<br>
29 * It also holds a {@link FieldUnit} which is the root of the hierarchy. (both may be the same object)
34 public class DerivateViewEditorInput
implements IEditorInput
{
37 * The selected derivate
39 private final SpecimenOrObservationBase
<?
> derivate
;
41 * The root of the hierarchy (may be the same object as the derivate)
43 private FieldUnit fieldUnit
;
45 private ConversationHolder conversationHolder
;
48 * Creates an editor input for the {@link DerivateView} with the currently selected derivate and the
49 * corresponding {@link FieldUnit} (both may be the same object).
50 * @param derivateUuid the {@link UUID} of the derivate for which the derivate hierarchy should be shown
51 * @param fieldUnit the root of the hierarchy
53 public DerivateViewEditorInput(UUID derivateUuid
) {
55 this.conversationHolder
= CdmStore
.createConversation();
56 this.derivate
= CdmStore
.getCurrentApplicationConfiguration().getOccurrenceService().load(derivateUuid
);
57 if(derivate
instanceof FieldUnit
){
58 this.fieldUnit
= (FieldUnit
) derivate
;
60 else if(derivate
instanceof DerivedUnit
){
61 Collection
<FieldUnit
> fieldUnits
= CdmStore
.getCurrentApplicationConfiguration().getOccurrenceService().getFieldUnits(derivateUuid
);
62 if(!fieldUnits
.isEmpty()){
63 // TODO think about handling multiple parent FieldUnits
64 this.fieldUnit
= fieldUnits
.iterator().next();
68 AbstractUtility
.errorDialog("Failed initializing editor", DerivateViewEditorInput
.class, "No FieldUnit found!");
73 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
76 public Object
getAdapter(Class adapter
) {
77 // TODO Auto-generated method stub
82 * @see org.eclipse.ui.IEditorInput#exists()
85 public boolean exists() {
90 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
93 public ImageDescriptor
getImageDescriptor() {
94 // TODO Auto-generated method stub
99 * @see org.eclipse.ui.IEditorInput#getName()
102 public String
getName() {
103 return derivate
.toString();
107 * @see org.eclipse.ui.IEditorInput#getPersistable()
110 public IPersistableElement
getPersistable() {
115 * @see org.eclipse.ui.IEditorInput#getToolTipText()
118 public String
getToolTipText() {
119 return derivate
.toString();
124 * @return the specimen
126 public SpecimenOrObservationBase
<?
> getDerivate() {
131 * @return the fieldUnit
133 public FieldUnit
getFieldUnit() {
138 * @return the conversationHolder
140 public ConversationHolder
getConversationHolder() {
141 return conversationHolder
;
145 * @see java.lang.Object#hashCode()
148 public int hashCode() {
149 final int prime
= 31;
151 result
= prime
* result
+ ((fieldUnit
== null) ?
0 : fieldUnit
.hashCode());
156 * @see java.lang.Object#equals(java.lang.Object)
159 public boolean equals(Object obj
) {
166 if (getClass() != obj
.getClass()) {
169 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
170 if (fieldUnit
== null) {
171 if (other
.fieldUnit
!= null) {
174 } else if (!fieldUnit
.equals(other
.fieldUnit
)) {