Project

General

Profile

Download (3.54 KB) Statistics
| Branch: | Tag: | Revision:
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[]{
59
		        "name",
60
		        "rootNode.childNodes"});
61

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

    
64
		if(classifications.size() == 0){
65
			Classification classification = Classification.NewInstance("My Classification");
66
			AbstractPostOperation operation = new CreateClassification("Creating initial 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

    
72
		return classifications;
73
	}
74

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

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

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

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

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