missed to commit changes in Root class
[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.navigation.NavigationUtil;
29 import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
30 import eu.etaxonomy.taxeditor.navigation.operation.CreateClassification;
31 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
32 import eu.etaxonomy.taxeditor.store.CdmStore;
33
34 /**
35 * <p>Root class.</p>
36 *
37 * @author p.ciardelli
38 * @created 02.06.2009
39 * @version 1.0
40 */
41 public class Root extends PlatformObject implements IAdaptable, IPersistableElement, IElementFactory, IConversationEnabled {
42
43 private final ConversationHolder conversation;
44
45 /**
46 * <p>Constructor for Root.</p>
47 *
48 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
49 */
50 public Root (ConversationHolder conversation){
51 this.conversation = conversation;
52 }
53
54 /**
55 * <p>getParentBeans</p>
56 *
57 * @return a {@link java.util.List} object.
58 */
59 public List<ITreeNode> getParentBeans() {
60 List<String> propertyPaths = Arrays.asList(new String[]{
61 "name", //$NON-NLS-1$
62 "rootNode.childNodes"}); //$NON-NLS-1$
63
64 List<Classification> classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
65 List<ITreeNode> rootNodes = new ArrayList<>();
66
67 if(classifications.size() == 0){
68 Classification classification = Classification.NewInstance(Messages.Root_MY_CLASSIFICATION);
69 AbstractPostOperation operation = new CreateClassification(Messages.Root_CREATE_CLASSIFICATION, NavigationUtil.getUndoContext(), classification, NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
70 NavigationUtil.executeOperation(operation);
71
72 classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
73 }
74 for (Classification classification: classifications){
75 rootNodes.add(classification.getRootNode());
76 }
77 return rootNodes;
78 }
79
80 /* (non-Javadoc)
81 * @see org.eclipse.ui.IPersistableElement#getFactoryId()
82 */
83 /**
84 * <p>getFactoryId</p>
85 *
86 * @return a {@link java.lang.String} object.
87 */
88 @Override
89 public String getFactoryId() {
90 return null;
91 }
92
93 /* (non-Javadoc)
94 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
95 */
96 /** {@inheritDoc} */
97 @Override
98 public void saveState(IMemento memento) {
99 }
100
101 /* (non-Javadoc)
102 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
103 */
104 /** {@inheritDoc} */
105 @Override
106 public IAdaptable createElement(IMemento memento) {
107 return null;
108 }
109
110 /* (non-Javadoc)
111 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
112 */
113 @Override
114 public void update(CdmDataChangeMap changeEvents) {}
115
116 /* (non-Javadoc)
117 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
118 */
119 @Override
120 public ConversationHolder getConversationHolder() {
121 return conversation;
122 }
123 }