Project

General

Profile

Download (3.54 KB) Statistics
| Branch: | Tag: | Revision:
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.Arrays;
13
import java.util.List;
14

    
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.PlatformObject;
17
import org.eclipse.ui.IElementFactory;
18
import org.eclipse.ui.IMemento;
19
import org.eclipse.ui.IPersistableElement;
20

    
21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23
import eu.etaxonomy.cdm.api.service.IClassificationService;
24
import eu.etaxonomy.cdm.model.taxon.Classification;
25
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
26
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
27
import eu.etaxonomy.taxeditor.navigation.operation.CreateClassification;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31
/**
32
 * <p>Root class.</p>
33
 *
34
 * @author p.ciardelli
35
 * @created 02.06.2009
36
 * @version 1.0
37
 */
38
public class Root extends PlatformObject implements IAdaptable, IPersistableElement, IElementFactory, IConversationEnabled {
39

    
40
	private final ConversationHolder conversation;
41

    
42
	/**
43
	 * <p>Constructor for Root.</p>
44
	 *
45
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
46
	 */
47
	public Root (ConversationHolder conversation){
48
		this.conversation = conversation;
49
	}
50

    
51
	/**
52
	 * <p>getParentBeans</p>
53
	 *
54
	 * @return a {@link java.util.List} object.
55
	 */
56
	public List<Classification> getParentBeans() {
57
		List<String> propertyPaths = Arrays.asList(new String[]{
58
		        "name",
59
		        "rootNode.childNodes"});
60

    
61
		List<Classification> classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
62

    
63
		if(classifications.size() == 0){
64
			Classification classification = Classification.NewInstance("My Classification");
65
			AbstractPostOperation operation = new CreateClassification("Creating initial classification", NavigationUtil.getUndoContext(), classification, NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
66
			NavigationUtil.executeOperation(operation);
67

    
68
			classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
69
		}
70

    
71
		return classifications;
72
	}
73

    
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.ui.IPersistableElement#getFactoryId()
76
	 */
77
	/**
78
	 * <p>getFactoryId</p>
79
	 *
80
	 * @return a {@link java.lang.String} object.
81
	 */
82
	@Override
83
    public String getFactoryId() {
84
		return null;
85
	}
86

    
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
89
	 */
90
	/** {@inheritDoc} */
91
	@Override
92
    public void saveState(IMemento memento) {
93
	}
94

    
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
97
	 */
98
	/** {@inheritDoc} */
99
	@Override
100
    public IAdaptable createElement(IMemento memento) {
101
		return null;
102
	}
103

    
104
	/* (non-Javadoc)
105
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
106
	 */
107
	@Override
108
	public void update(CdmDataChangeMap changeEvents) {}
109

    
110
	/* (non-Javadoc)
111
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
112
	 */
113
	@Override
114
	public ConversationHolder getConversationHolder() {
115
		return conversation;
116
	}
117
}
(5-5/21)