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
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
22 import org
.eclipse
.ui
.IEditorInput
;
23 import org
.eclipse
.ui
.IPersistableElement
;
25 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
26 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
27 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
31 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
32 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
33 import eu
.etaxonomy
.taxeditor
.editor
.Messages
;
34 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 import eu
.etaxonomy
.taxeditor
.view
.derivateSearch
.DerivateLabelProvider
;
39 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
40 * the derivate hierarchy should be shown in the DerivateView.<br>
41 * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
46 public class DerivateViewEditorInput
extends CdmEntitySessionInput
implements IEditorInput
{
49 * The selected derivate {@link UUID}s
51 private final Set
<SpecimenOrObservationBase
<?
>> derivateEntities
;
53 * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
55 private Set
<SpecimenOrObservationBase
<?
>> rootEntities
;
56 private Set
<UUID
> rootUUIDs
;
58 private final ConversationHolder conversationHolder
;
60 private static final List
<String
> SPECIMEN_INIT_STRATEGY
= Arrays
.asList(new String
[] {
68 "derivationEvents.derivatives.annotations",
69 "derivationEvents.derivatives.markers",
70 "derivationEvents.derivatives.credits",
71 "derivationEvents.derivatives.extensions",
72 "derivationEvents.derivatives.rights",
73 "derivationEvents.derivatives.sources"
77 * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
78 * corresponding {@link FieldUnit}s (both may be the same object).
79 * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
80 * @param rootUUIDs the root of the hierarchy
82 public DerivateViewEditorInput(Set
<UUID
> derivateUuids
) {
84 rootUUIDs
= derivateUuids
;
85 //FIXME:Remoting temporary hack for making the sessions work
86 //This should ideally be changed to initializing the
87 //super class with a collection of (id) objects which can
88 //then be used for the hashCode, equals methods
90 this.conversationHolder
= CdmStore
.createConversation();
91 this.derivateEntities
= new HashSet
<SpecimenOrObservationBase
<?
>>();
92 this.rootEntities
= new HashSet
<SpecimenOrObservationBase
<?
>>();
93 for (UUID uuid
: derivateUuids
) {
94 SpecimenOrObservationBase
<?
> derivate
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
, SPECIMEN_INIT_STRATEGY
);
95 derivateEntities
.add(derivate
);
96 if(derivate
instanceof FieldUnit
){
97 rootEntities
.add(derivate
);
99 else if(derivate
instanceof DerivedUnit
){
100 SpecimenOrObservationBase
<?
> topMostDerivate
= EditorUtil
.getTopMostDerivate(derivate
);
101 if(topMostDerivate
!=null){
102 rootEntities
.add(topMostDerivate
);
106 if(rootEntities
.isEmpty()){
107 rootEntities
= derivateEntities
;
109 if(rootEntities
.isEmpty()){
110 MessagingUtils
.messageDialog(Messages
.DerivateViewEditorInput_FAIL_INIT
, DerivateViewEditorInput
.class, Messages
.DerivateViewEditorInput_NO_ROOT
);
117 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
120 public Object
getAdapter(Class adapter
) {
121 // TODO Auto-generated method stub
126 * @see org.eclipse.ui.IEditorInput#exists()
129 public boolean exists() {
134 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
137 public ImageDescriptor
getImageDescriptor() {
138 // TODO Auto-generated method stub
143 * @see org.eclipse.ui.IEditorInput#getName()
146 public String
getName() {
147 return getEditorName();
151 * @see org.eclipse.ui.IEditorInput#getPersistable()
154 public IPersistableElement
getPersistable() {
159 * @see org.eclipse.ui.IEditorInput#getToolTipText()
162 public String
getToolTipText() {
163 return getEditorName();
166 private String
getEditorName() {
168 for( SpecimenOrObservationBase
<?
> specimen
: rootEntities
){
171 name
= DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
);
174 name
+= " + "+DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
); //$NON-NLS-1$
182 public Set
<SpecimenOrObservationBase
<?
>> getRootEntities() {
186 public Set
<SpecimenOrObservationBase
<?
>> getDerivateEntities() {
187 return derivateEntities
;
190 public void addRootEntity(SpecimenOrObservationBase
<?
> root
){
191 rootEntities
.add(root
);
195 public ConversationHolder
getConversationHolder() {
196 return conversationHolder
;
200 * @see java.lang.Object#hashCode()
203 public int hashCode() {
204 final int prime
= 31;
206 result
= prime
* result
+ ((rootUUIDs
== null) ?
0 : rootUUIDs
.hashCode());
211 * @see java.lang.Object#equals(java.lang.Object)
214 public boolean equals(Object obj
) {
221 if (getClass() != obj
.getClass()) {
224 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
225 if (rootUUIDs
== null) {
226 if (other
.rootUUIDs
!= null) {
229 } else if (!rootUUIDs
.equals(other
.rootUUIDs
)) {
236 * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
239 public void merge() {
240 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
241 CdmApplicationState
.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
247 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
250 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
251 List
<String
> specimenPropertyPaths
= Arrays
.asList(new String
[] {
253 "derivationEvents.derivates",
261 Map
<Object
, List
<String
>> specimenPropertyPathMap
=
262 new HashMap
<Object
, List
<String
>>();
263 specimenPropertyPathMap
.put(SpecimenOrObservationBase
.class,specimenPropertyPaths
);
264 return specimenPropertyPathMap
;