Project

General

Profile

Download (3.43 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 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));
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
	public String getFactoryId() {
82
		return null;
83
	}
84

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

    
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
94
	 */
95
	/** {@inheritDoc} */
96
	public IAdaptable createElement(IMemento memento) {
97
		return null;
98
	}
99

    
100
	/* (non-Javadoc)
101
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
102
	 */
103
	@Override
104
	public void update(CdmDataChangeMap changeEvents) {}
105

    
106
	/* (non-Javadoc)
107
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
108
	 */
109
	@Override
110
	public ConversationHolder getConversationHolder() {
111
		return conversation;
112
	}
113
}
(5-5/15)