blob: 574504602fe84d562b3c69d2d299206d97fedbe6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*******************************************************************************
* Copyright (c) 2008 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.core.internal;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.ResourceModel;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
public abstract class AbstractResourceModel
extends AbstractModel
implements ResourceModel
{
private final List<JpaStructureNode> rootStructureNodes;
protected AbstractResourceModel() {
this.rootStructureNodes = new ArrayList<JpaStructureNode>();
}
public abstract Object resource();
public ListIterator<JpaStructureNode> rootStructureNodes() {
return new CloneListIterator<JpaStructureNode>(rootStructureNodes);
}
public int rootStructureNodesSize() {
return rootStructureNodes.size();
}
/**
* Add the new node to the end of the list.
*/
public void addRootStructureNode(JpaStructureNode structureNode) {
this.addRootStructureNode(rootStructureNodes.size(), structureNode);
}
public void addRootStructureNode(int index, JpaStructureNode structureNode) {
if ( ! rootStructureNodes.contains(structureNode)) {
this.addItemToList(index, structureNode, this.rootStructureNodes, ROOT_STRUCTURE_NODES_LIST);
}
}
public void removeRootStructureNode(JpaStructureNode structureNode) {
this.removeItemFromList(structureNode, rootStructureNodes, ROOT_STRUCTURE_NODES_LIST);
}
public void removeRootStructureNode(int index) {
this.removeItemFromList(index, rootStructureNodes, ROOT_STRUCTURE_NODES_LIST);
}
public JpaStructureNode structureNode(int textOffset) {
synchronized (rootStructureNodes) {
for (JpaStructureNode rootNode : rootStructureNodes) {
JpaStructureNode node = rootNode.structureNode(textOffset);
if (node != null) {
return node;
}
}
}
return null;
}
public void dispose() {
this.clearList(this.rootStructureNodes, ROOT_STRUCTURE_NODES_LIST);
}
}
|