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
.HashSet
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IPersistableElement
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
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
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 import eu
.etaxonomy
.taxeditor
.view
.derivateSearch
.DerivateLabelProvider
;
31 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
32 * the derivate hierarchy should be shown in the DerivateView.<br>
33 * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
38 public class DerivateViewEditorInput
implements IEditorInput
{
41 * The selected derivate {@link UUID}s
43 private final Set
<UUID
> derivateUUIDs
;
45 * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
47 private Set
<UUID
> rootUUIDs
;
49 private final ConversationHolder conversationHolder
;
52 * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
53 * corresponding {@link FieldUnit}s (both may be the same object).
54 * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
55 * @param rootUUIDs the root of the hierarchy
57 public DerivateViewEditorInput(Set
<UUID
> derivateUuids
) {
59 this.conversationHolder
= CdmStore
.createConversation();
60 this.derivateUUIDs
= derivateUuids
;
61 this.rootUUIDs
= new HashSet
<UUID
>();
62 for (UUID uuid
: derivateUuids
) {
63 SpecimenOrObservationBase
<?
> derivate
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
);
64 if(derivate
instanceof FieldUnit
){
67 else if(derivate
instanceof DerivedUnit
){
68 SpecimenOrObservationBase
<?
> topMostDerivate
= EditorUtil
.getTopMostDerivate(derivate
);
69 if(topMostDerivate
!=null){
70 rootUUIDs
.add(topMostDerivate
.getUuid());
74 if(rootUUIDs
.isEmpty()){
75 rootUUIDs
= derivateUUIDs
;
77 if(rootUUIDs
.isEmpty()){
78 MessagingUtils
.messageDialog("Failed initializing editor", DerivateViewEditorInput
.class, "No root element found!");
83 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
86 public Object
getAdapter(Class adapter
) {
87 // TODO Auto-generated method stub
92 * @see org.eclipse.ui.IEditorInput#exists()
95 public boolean exists() {
100 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
103 public ImageDescriptor
getImageDescriptor() {
104 // TODO Auto-generated method stub
109 * @see org.eclipse.ui.IEditorInput#getName()
112 public String
getName() {
113 return getEditorName();
117 * @see org.eclipse.ui.IEditorInput#getPersistable()
120 public IPersistableElement
getPersistable() {
125 * @see org.eclipse.ui.IEditorInput#getToolTipText()
128 public String
getToolTipText() {
129 return getEditorName();
132 private String
getEditorName() {
134 for(UUID uuid
:rootUUIDs
){
135 SpecimenOrObservationBase
<?
> specimen
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
);
138 name
= DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
);
141 name
+= " + "+DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
);
148 public Set
<UUID
> getRootUUIDs() {
152 public Set
<UUID
> getDerivateUUIDs() {
153 return derivateUUIDs
;
156 public void addRootUuid(UUID root
){
161 public ConversationHolder
getConversationHolder() {
162 return conversationHolder
;
166 * @see java.lang.Object#hashCode()
169 public int hashCode() {
170 final int prime
= 31;
172 result
= prime
* result
+ ((rootUUIDs
== null) ?
0 : rootUUIDs
.hashCode());
177 * @see java.lang.Object#equals(java.lang.Object)
180 public boolean equals(Object obj
) {
187 if (getClass() != obj
.getClass()) {
190 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
191 if (rootUUIDs
== null) {
192 if (other
.rootUUIDs
!= null) {
195 } else if (!rootUUIDs
.equals(other
.rootUUIDs
)) {