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
|
package eu.etaxonomy.taxeditor.navigation.navigator;
|
10
|
|
11
|
import java.util.ArrayList;
|
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.service.IClassificationService;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
23
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
24
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
25
|
|
26
|
/**
|
27
|
* @author p.ciardelli
|
28
|
* @created 02.06.2009
|
29
|
*/
|
30
|
public class Root extends PlatformObject
|
31
|
implements IPersistableElement, IElementFactory {
|
32
|
|
33
|
private List<TaxonNodeDto> rootNodes = new ArrayList<>();
|
34
|
|
35
|
public Root () {}
|
36
|
|
37
|
public List<TaxonNodeDto> getParentBeans() {
|
38
|
List<String> propertyPaths = Arrays.asList(new String[]{
|
39
|
"name", //$NON-NLS-1$
|
40
|
"rootNode.statusNote",//$NON-NLS-1$
|
41
|
"rootNode.childNodes",//$NON-NLS-1$
|
42
|
"rootNode.childNodes.statusNote"}); //$NON-NLS-1$
|
43
|
if (rootNodes.isEmpty()){
|
44
|
List<Classification> classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
|
45
|
|
46
|
if(classifications.size() == 0){
|
47
|
//FIXME E4 migrate or delete; when does this happen and SHOULD this happen?
|
48
|
// Classification classification = Classification.NewInstance(Messages.Root_MY_CLASSIFICATION);
|
49
|
// AbstractPostOperation operation = new CreateClassification(Messages.Root_CREATE_CLASSIFICATION, NavigationUtil.getUndoContext(), classification, NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false), NavigationUtil.getNavigator(false));
|
50
|
// NavigationUtil.executeOperation(operation);
|
51
|
//
|
52
|
// classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, propertyPaths);
|
53
|
}
|
54
|
|
55
|
for (Classification classification: classifications){
|
56
|
rootNodes.add(new TaxonNodeDto(classification.getRootNode()));
|
57
|
}
|
58
|
}
|
59
|
return rootNodes;
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public String getFactoryId() {
|
64
|
return null;
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public void saveState(IMemento memento) {
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public IAdaptable createElement(IMemento memento) {
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
public void addRootNode(Classification newClassification){
|
77
|
newClassification = CdmStore.getService(IClassificationService.class).load(newClassification.getUuid());
|
78
|
boolean exist = false;
|
79
|
for (TaxonNodeDto rootNode: rootNodes){
|
80
|
if (rootNode.getUuid().equals(newClassification.getRootNode().getUuid())){
|
81
|
exist = true;
|
82
|
break;
|
83
|
}
|
84
|
}
|
85
|
if (!exist){
|
86
|
rootNodes.add(new TaxonNodeDto(newClassification.getRootNode()));
|
87
|
}
|
88
|
}
|
89
|
|
90
|
public void removeRootNode(Classification cb) {
|
91
|
int index = -1;
|
92
|
for (TaxonNodeDto dto: rootNodes){
|
93
|
if (dto.getClassificationUUID().equals(cb.getUuid())){
|
94
|
index = rootNodes.indexOf(dto);
|
95
|
break;
|
96
|
}
|
97
|
}
|
98
|
if (index > 0){
|
99
|
rootNodes.remove(index);
|
100
|
}
|
101
|
}
|
102
|
}
|