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
.IMemento
;
17 import org
.eclipse
.ui
.IPersistable
;
18 import org
.eclipse
.ui
.IPersistableElement
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
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
.taxeditor
.editor
.EditorUtil
;
25 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
30 * the derivate hierarchy should be shown in the DerivateView.<br>
31 * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
36 public class DerivateViewEditorInput
implements IEditorInput
, IPersistable
{
39 * Key used for saving the {@link UUID} to a memento
41 public static final String UUID_MEMENTO_KEY
= "UUID";
43 * The selected derivate
45 private final SpecimenOrObservationBase
<?
> derivate
;
47 * The root of the hierarchy (may be the same object as the derivate)
49 private SpecimenOrObservationBase
<?
> root
;
51 private final ConversationHolder conversationHolder
;
54 * Creates an editor input for the {@link DerivateView} with the currently selected derivate and the
55 * corresponding {@link FieldUnit} (both may be the same object).
56 * @param derivateUuid the {@link UUID} of the derivate for which the derivate hierarchy should be shown
57 * @param root the root of the hierarchy
59 public DerivateViewEditorInput(UUID derivateUuid
) {
61 this.conversationHolder
= CdmStore
.createConversation();
62 this.derivate
= CdmStore
.getCurrentApplicationConfiguration().getOccurrenceService().load(derivateUuid
);
63 if(derivate
instanceof FieldUnit
){
66 else if(derivate
instanceof DerivedUnit
){
67 root
= EditorUtil
.getTopMostDerivate(derivate
);
73 MessagingUtils
.messageDialog("Failed initializing editor", DerivateViewEditorInput
.class, "No root element found!");
78 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
81 public Object
getAdapter(Class adapter
) {
82 // TODO Auto-generated method stub
87 * @see org.eclipse.ui.IEditorInput#exists()
90 public boolean exists() {
95 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
98 public ImageDescriptor
getImageDescriptor() {
99 // TODO Auto-generated method stub
104 * @see org.eclipse.ui.IEditorInput#getName()
107 public String
getName() {
108 return derivate
.toString();
112 * @see org.eclipse.ui.IEditorInput#getPersistable()
115 public IPersistableElement
getPersistable() {
120 * @see org.eclipse.ui.IEditorInput#getToolTipText()
123 public String
getToolTipText() {
124 return derivate
.toString();
129 * @return the specimen
131 public SpecimenOrObservationBase
<?
> getDerivate() {
136 * @return the fieldUnit
138 public SpecimenOrObservationBase
<?
> getRootElement() {
143 * @return the conversationHolder
145 public ConversationHolder
getConversationHolder() {
146 return conversationHolder
;
150 * @see java.lang.Object#hashCode()
153 public int hashCode() {
154 final int prime
= 31;
156 result
= prime
* result
+ ((root
== null) ?
0 : root
.hashCode());
161 * @see java.lang.Object#equals(java.lang.Object)
164 public boolean equals(Object obj
) {
171 if (getClass() != obj
.getClass()) {
174 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
176 if (other
.root
!= null) {
179 } else if (!root
.equals(other
.root
)) {
186 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
189 public void saveState(IMemento memento
) {
190 UUID uuid
= derivate
.getUuid();
191 memento
.putString(UUID_MEMENTO_KEY
, uuid
.toString());