Project

General

Profile

Download (4.05 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.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.taxon.Classification;
26
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
27
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

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

    
39
	private final ConversationHolder conversation;
40
	private List<TaxonNodeDto> rootNodes = new ArrayList<>();
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<TaxonNodeDto> getParentBeans() {
57
		List<String> propertyPaths = Arrays.asList(new String[]{
58
		        "name", //$NON-NLS-1$
59
		        "rootNode.childNodes"}); //$NON-NLS-1$
60
		if (rootNodes.isEmpty()){
61
    		List<Classification> classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
62

    
63
    		if(classifications.size() == 0){
64
    		    //FIXME E4 migrate or delete; when does this happen and SHOULD this happen?
65
    //			Classification classification = Classification.NewInstance(Messages.Root_MY_CLASSIFICATION);
66
    //			AbstractPostOperation operation = new CreateClassification(Messages.Root_CREATE_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
    		for (Classification classification: classifications){
73
    			rootNodes.add(new TaxonNodeDto(classification.getRootNode()));
74
    		}
75
		}
76
		return rootNodes;
77
	}
78

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

    
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
94
	 */
95
	/** {@inheritDoc} */
96
	@Override
97
    public void saveState(IMemento memento) {
98
	}
99

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

    
109
	/* (non-Javadoc)
110
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
111
	 */
112
	@Override
113
	public void update(CdmDataChangeMap changeEvents) {}
114

    
115
	/* (non-Javadoc)
116
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
117
	 */
118
	@Override
119
	public ConversationHolder getConversationHolder() {
120
		return conversation;
121
	}
122

    
123
	public void addRootNode(Classification newClassification){
124
	    newClassification = CdmStore.getService(IClassificationService.class).load(newClassification.getUuid());
125
	    rootNodes.add(new TaxonNodeDto(newClassification.getRootNode()));
126

    
127
	}
128
}
(5-5/21)