Merge branch 'develop' into wset
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / Root.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.navigation.navigator;
11
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.PlatformObject;
18 import org.eclipse.ui.IElementFactory;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.IPersistableElement;
21
22 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
23 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24 import eu.etaxonomy.cdm.api.service.IClassificationService;
25 import eu.etaxonomy.cdm.model.common.ITreeNode;
26 import eu.etaxonomy.cdm.model.taxon.Classification;
27 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * <p>Root class.</p>
32 *
33 * @author p.ciardelli
34 * @created 02.06.2009
35 * @version 1.0
36 */
37 public class Root extends PlatformObject implements IAdaptable, IPersistableElement, IElementFactory, IConversationEnabled {
38
39 private final ConversationHolder conversation;
40
41 /**
42 * <p>Constructor for Root.</p>
43 *
44 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
45 */
46 public Root (ConversationHolder conversation){
47 this.conversation = conversation;
48 }
49
50 /**
51 * <p>getParentBeans</p>
52 *
53 * @return a {@link java.util.List} object.
54 */
55 public List<ITreeNode> getParentBeans() {
56 List<String> propertyPaths = Arrays.asList(new String[]{
57 "name", //$NON-NLS-1$
58 "rootNode.childNodes"}); //$NON-NLS-1$
59
60 List<Classification> classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
61 List<ITreeNode> rootNodes = new ArrayList<>();
62
63 if(classifications.size() == 0){
64 //FIXME E4 migrate or delete; when does this happen and SHOULD this happen?
65 // Classification classification = Classification.NewInstance(Messages.Root_MY_CLASSIFICATION);
66 // AbstractPostOperation operation = new CreateClassification(Messages.Root_CREATE_CLASSIFICATION, NavigationUtil.getUndoContext(), classification, NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
67 // NavigationUtil.executeOperation(operation);
68 //
69 // classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
70 }
71 for (Classification classification: classifications){
72 rootNodes.add(classification.getRootNode());
73 }
74 return rootNodes;
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.ui.IPersistableElement#getFactoryId()
79 */
80 /**
81 * <p>getFactoryId</p>
82 *
83 * @return a {@link java.lang.String} object.
84 */
85 @Override
86 public String getFactoryId() {
87 return null;
88 }
89
90 /* (non-Javadoc)
91 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
92 */
93 /** {@inheritDoc} */
94 @Override
95 public void saveState(IMemento memento) {
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
100 */
101 /** {@inheritDoc} */
102 @Override
103 public IAdaptable createElement(IMemento memento) {
104 return null;
105 }
106
107 /* (non-Javadoc)
108 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
109 */
110 @Override
111 public void update(CdmDataChangeMap changeEvents) {}
112
113 /* (non-Javadoc)
114 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
115 */
116 @Override
117 public ConversationHolder getConversationHolder() {
118 return conversation;
119 }
120 }