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
.editor
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 import eu
.etaxonomy
.taxeditor
.view
.derivateSearch
.DerivateLabelProvider
;
32 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
33 * the derivate hierarchy should be shown in the DerivateView.<br>
34 * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
39 public class DerivateViewEditorInput
implements IEditorInput
{
42 * The selected derivate {@link UUID}s
44 private final Set
<UUID
> derivateUUIDs
;
46 * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
48 private Set
<UUID
> rootUUIDs
;
50 private final ConversationHolder conversationHolder
;
53 * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
54 * corresponding {@link FieldUnit}s (both may be the same object).
55 * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
56 * @param rootUUIDs the root of the hierarchy
58 public DerivateViewEditorInput(Set
<UUID
> derivateUuids
) {
60 this.conversationHolder
= CdmStore
.createConversation();
61 this.derivateUUIDs
= derivateUuids
;
62 this.rootUUIDs
= new HashSet
<UUID
>();
63 for (UUID uuid
: derivateUuids
) {
64 SpecimenOrObservationBase
<?
> derivate
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
);
65 if(derivate
instanceof FieldUnit
){
68 else if(derivate
instanceof DerivedUnit
){
69 SpecimenOrObservationBase
<?
> topMostDerivate
= EditorUtil
.getTopMostDerivate(derivate
);
70 if(topMostDerivate
!=null){
71 rootUUIDs
.add(topMostDerivate
.getUuid());
75 if(rootUUIDs
.isEmpty()){
76 rootUUIDs
= derivateUUIDs
;
78 if(rootUUIDs
.isEmpty()){
79 MessagingUtils
.messageDialog(Messages
.DerivateViewEditorInput_FAIL_INIT
, DerivateViewEditorInput
.class, Messages
.DerivateViewEditorInput_NO_ROOT
);
84 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
87 public Object
getAdapter(Class adapter
) {
88 // TODO Auto-generated method stub
93 * @see org.eclipse.ui.IEditorInput#exists()
96 public boolean exists() {
101 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
104 public ImageDescriptor
getImageDescriptor() {
105 // TODO Auto-generated method stub
110 * @see org.eclipse.ui.IEditorInput#getName()
113 public String
getName() {
114 return getEditorName();
118 * @see org.eclipse.ui.IEditorInput#getPersistable()
121 public IPersistableElement
getPersistable() {
126 * @see org.eclipse.ui.IEditorInput#getToolTipText()
129 public String
getToolTipText() {
130 return getEditorName();
133 private String
getEditorName() {
135 for(UUID uuid
:rootUUIDs
){
136 SpecimenOrObservationBase
<?
> specimen
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
);
139 name
= DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
);
142 name
+= " + "+DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
); //$NON-NLS-1$
149 public Set
<UUID
> getRootUUIDs() {
153 public Set
<UUID
> getDerivateUUIDs() {
154 return derivateUUIDs
;
157 public void addRootUuid(UUID root
){
162 public ConversationHolder
getConversationHolder() {
163 return conversationHolder
;
167 * @see java.lang.Object#hashCode()
170 public int hashCode() {
171 final int prime
= 31;
173 result
= prime
* result
+ ((rootUUIDs
== null) ?
0 : rootUUIDs
.hashCode());
178 * @see java.lang.Object#equals(java.lang.Object)
181 public boolean equals(Object obj
) {
188 if (getClass() != obj
.getClass()) {
191 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
192 if (rootUUIDs
== null) {
193 if (other
.rootUUIDs
!= null) {
196 } else if (!rootUUIDs
.equals(other
.rootUUIDs
)) {