merge
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / Root.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.navigation.navigator;
12
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.taxon.Classification;
26 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
27 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
28 import eu.etaxonomy.taxeditor.navigation.operation.CreateClassification;
29 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31
32 /**
33 * <p>Root class.</p>
34 *
35 * @author p.ciardelli
36 * @created 02.06.2009
37 * @version 1.0
38 */
39 public class Root extends PlatformObject implements IAdaptable, IPersistableElement, IElementFactory, IConversationEnabled {
40
41 private final ConversationHolder conversation;
42
43 /**
44 * <p>Constructor for Root.</p>
45 *
46 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
47 */
48 public Root (ConversationHolder conversation){
49 this.conversation = conversation;
50 }
51
52 /**
53 * <p>getParentBeans</p>
54 *
55 * @return a {@link java.util.List} object.
56 */
57 public List<Classification> getParentBeans() {
58 List<String> propertyPaths = Arrays.asList(new String[]{"name"});
59
60 List<Classification> classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
61
62 if(classifications.size() == 0){
63 Classification classification = Classification.NewInstance("My Classification");
64 AbstractPostOperation operation = new CreateClassification("Creating initial classification", NavigationUtil.getUndoContext(), classification, NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
65 NavigationUtil.executeOperation(operation);
66
67 classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
68 }
69
70 return classifications;
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.ui.IPersistableElement#getFactoryId()
75 */
76 /**
77 * <p>getFactoryId</p>
78 *
79 * @return a {@link java.lang.String} object.
80 */
81 @Override
82 public String getFactoryId() {
83 return null;
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
88 */
89 /** {@inheritDoc} */
90 @Override
91 public void saveState(IMemento memento) {
92 }
93
94 /* (non-Javadoc)
95 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
96 */
97 /** {@inheritDoc} */
98 @Override
99 public IAdaptable createElement(IMemento memento) {
100 return null;
101 }
102
103 /* (non-Javadoc)
104 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
105 */
106 @Override
107 public void update(CdmDataChangeMap changeEvents) {}
108
109 /* (non-Javadoc)
110 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
111 */
112 @Override
113 public ConversationHolder getConversationHolder() {
114 return conversation;
115 }
116 }