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
.Collection
;
15 import java
.util
.HashMap
;
16 import java
.util
.HashSet
;
17 import java
.util
.List
;
20 import java
.util
.UUID
;
22 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.IPersistableElement
;
26 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
27 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
28 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
32 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
33 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 import eu
.etaxonomy
.taxeditor
.view
.derivateSearch
.DerivateLabelProvider
;
38 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
39 * the derivate hierarchy should be shown in the DerivateView.<br>
40 * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
45 public class DerivateViewEditorInput
extends CdmEntitySessionInput
implements IEditorInput
{
48 * The selected derivate {@link UUID}s
50 private Set
<SpecimenOrObservationBase
<?
>> derivateEntities
;
52 * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
54 private Set
<SpecimenOrObservationBase
<?
>> rootEntities
;
55 private Set
<UUID
> rootUUIDs
;
57 private final ConversationHolder conversationHolder
;
59 private static final List
<String
> SPECIMEN_INIT_STRATEGY
= Arrays
.asList(new String
[] {
67 "derivationEvents.derivatives.annotations",
68 "derivationEvents.derivatives.markers",
69 "derivationEvents.derivatives.credits",
70 "derivationEvents.derivatives.extensions",
71 "derivationEvents.derivatives.rights",
72 "derivationEvents.derivatives.sources"
76 * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
77 * corresponding {@link FieldUnit}s (both may be the same object).
78 * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
79 * @param rootUUIDs the root of the hierarchy
81 public DerivateViewEditorInput(Set
<UUID
> derivateUuids
) {
83 rootUUIDs
= derivateUuids
;
84 //FIXME:Remoting temporary hack for making the sessions work
85 //This should ideally be changed to initializing the
86 //super class with a collection of (id) objects which can
87 //then be used for the hashCode, equals methods
89 this.conversationHolder
= CdmStore
.createConversation();
90 updateRootEntities(derivateUuids
);
95 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
98 public Object
getAdapter(Class adapter
) {
99 // TODO Auto-generated method stub
104 * @see org.eclipse.ui.IEditorInput#exists()
107 public boolean exists() {
112 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
115 public ImageDescriptor
getImageDescriptor() {
116 // TODO Auto-generated method stub
121 * @see org.eclipse.ui.IEditorInput#getName()
124 public String
getName() {
125 return getEditorName();
129 * @see org.eclipse.ui.IEditorInput#getPersistable()
132 public IPersistableElement
getPersistable() {
137 * @see org.eclipse.ui.IEditorInput#getToolTipText()
140 public String
getToolTipText() {
141 return getEditorName();
144 private String
getEditorName() {
146 for( SpecimenOrObservationBase
<?
> specimen
: rootEntities
){
149 name
= DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
);
152 name
+= " + "+DerivateLabelProvider
.getDerivateText(specimen
, conversationHolder
); //$NON-NLS-1$
157 name
= "Derivative Editor";
163 public Set
<SpecimenOrObservationBase
<?
>> getRootEntities() {
167 public Set
<SpecimenOrObservationBase
<?
>> getDerivateEntities() {
168 return derivateEntities
;
171 public void addRootEntity(SpecimenOrObservationBase
<?
> root
){
172 rootEntities
.add(root
);
176 public ConversationHolder
getConversationHolder() {
177 return conversationHolder
;
181 public int hashCode() {
182 final int prime
= 31;
184 result
= prime
* result
+ ((rootUUIDs
== null) ?
0 : rootUUIDs
.hashCode());
189 public boolean equals(Object obj
) {
196 if (getClass() != obj
.getClass()) {
199 DerivateViewEditorInput other
= (DerivateViewEditorInput
) obj
;
200 if (rootUUIDs
== null) {
201 if (other
.rootUUIDs
!= null) {
204 } else if (!rootUUIDs
.equals(other
.rootUUIDs
)) {
211 public void merge() {
212 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
213 List
<SpecimenOrObservationBase
> mergedEntities
= CdmApplicationState
.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
219 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
220 List
<String
> specimenPropertyPaths
= Arrays
.asList(new String
[] {
222 "derivationEvents.derivates",
230 Map
<Object
, List
<String
>> specimenPropertyPathMap
=
231 new HashMap
<Object
, List
<String
>>();
232 specimenPropertyPathMap
.put(SpecimenOrObservationBase
.class,specimenPropertyPaths
);
233 return specimenPropertyPathMap
;
236 public void updateRootEntities(Collection
<UUID
> derivateUuids
) {
237 this.derivateEntities
= new HashSet
<SpecimenOrObservationBase
<?
>>();
238 this.rootEntities
= new HashSet
<SpecimenOrObservationBase
<?
>>();
239 for (UUID uuid
: derivateUuids
) {
240 SpecimenOrObservationBase
<?
> derivate
= CdmStore
.getService(IOccurrenceService
.class).load(uuid
, SPECIMEN_INIT_STRATEGY
);
241 derivateEntities
.add(derivate
);
242 if(derivate
instanceof FieldUnit
){
243 rootEntities
.add(derivate
);
245 else if(derivate
instanceof DerivedUnit
){
246 SpecimenOrObservationBase
<?
> topMostDerivate
= EditorUtil
.getTopMostDerivate(derivate
);
247 if(topMostDerivate
!=null){
248 rootEntities
.add(topMostDerivate
);
252 if(rootEntities
.isEmpty()){
253 rootEntities
= derivateEntities
;