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
.UUID
;
14 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
15 import org
.eclipse
.ui
.IEditorInput
;
16 import org
.eclipse
.ui
.IPersistableElement
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
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
.editor
.EditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
29 * the derivate hierarchy should be shown in the DerivateView.<br>
30 * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
35 public class DerivateViewEditorInput
implements IEditorInput
{
38 * The selected derivate {@link UUID}
40 private UUID derivateUUID
;
42 * The {@link UUID} of the root of the hierarchy (may be the same object as the derivate)
44 private UUID rootUUID
;
46 private final ConversationHolder conversationHolder
;
49 * Creates an editor input for the {@link DerivateView} with the currently selected derivate and the
50 * corresponding {@link FieldUnit} (both may be the same object).
51 * @param derivateUuid the {@link UUID} of the derivate for which the derivate hierarchy should be shown
52 * @param rootUUID the root of the hierarchy
54 public DerivateViewEditorInput(UUID derivateUuid
) {
56 this.conversationHolder
= CdmStore
.createConversation();
57 this.derivateUUID
= derivateUuid
;
58 SpecimenOrObservationBase
<?
> derivate
= CdmStore
.getService(IOccurrenceService
.class).load(derivateUuid
);
59 if(derivate
instanceof FieldUnit
){
60 this.rootUUID
= derivateUUID
;
62 else if(derivate
instanceof DerivedUnit
){
63 SpecimenOrObservationBase
<?
> topMostDerivate
= EditorUtil
.getTopMostDerivate(derivate
);
64 rootUUID
= topMostDerivate
==null?
null:topMostDerivate
.getUuid();
66 rootUUID
= derivateUUID
;
70 MessagingUtils
.messageDialog("Failed initializing editor", DerivateViewEditorInput
.class, "No root element found!");
75 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
78 public Object
getAdapter(Class adapter
) {
79 // TODO Auto-generated method stub
84 * @see org.eclipse.ui.IEditorInput#exists()
87 public boolean exists() {
92 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
95 public ImageDescriptor
getImageDescriptor() {
96 // TODO Auto-generated method stub
101 * @see org.eclipse.ui.IEditorInput#getName()
104 public String
getName() {
105 return derivateUUID
.toString();
109 * @see org.eclipse.ui.IEditorInput#getPersistable()
112 public IPersistableElement
getPersistable() {
117 * @see org.eclipse.ui.IEditorInput#getToolTipText()
120 public String
getToolTipText() {
121 return derivateUUID
.toString();
124 public UUID
getDerivateUUID() {
128 public UUID
getRootElementUUID() {
132 public void setRootAsDerivate(){
133 this.derivateUUID
= this.rootUUID
;
136 public ConversationHolder
getConversationHolder() {
137 return conversationHolder
;
141 * @see java.lang.Object#hashCode()
144 public int hashCode() {
145 final int prime
= 31;
147 result
= prime
* result
+ ((rootUUID
== null) ?
0 : rootUUID
.hashCode());
152 * @see java.lang.Object#equals(java.lang.Object)
155 public boolean equals(Object obj
) {
162 if (getClass() != obj
.getClass()) {
165 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
166 if (rootUUID
== null) {
167 if (other
.rootUUID
!= null) {
170 } else if (!rootUUID
.equals(other
.rootUUID
)) {