Lines 9-18
Link Here
|
9 |
******************************************************************************/ |
9 |
******************************************************************************/ |
10 |
package org.eclipse.jpt.core.internal; |
10 |
package org.eclipse.jpt.core.internal; |
11 |
|
11 |
|
12 |
import java.util.HashMap; |
12 |
import java.util.Hashtable; |
13 |
import java.util.Iterator; |
13 |
import java.util.Iterator; |
14 |
import java.util.Map; |
|
|
15 |
import java.util.Set; |
14 |
import java.util.Set; |
|
|
15 |
|
16 |
import org.eclipse.core.resources.IFile; |
16 |
import org.eclipse.core.resources.IFile; |
17 |
import org.eclipse.jdt.core.ElementChangedEvent; |
17 |
import org.eclipse.jdt.core.ElementChangedEvent; |
18 |
import org.eclipse.jpt.core.JpaFile; |
18 |
import org.eclipse.jpt.core.JpaFile; |
Lines 35-49
Link Here
|
35 |
protected final ResourceModel resourceModel; |
35 |
protected final ResourceModel resourceModel; |
36 |
|
36 |
|
37 |
/** |
37 |
/** |
38 |
* The context model root node represented by this JPA file |
38 |
* The context model root nodes represented by this JPA file |
39 |
*/ |
39 |
*/ |
40 |
protected final Map<Object, JpaStructureNode> rootStructureNodes; |
40 |
protected final Hashtable<Object, JpaStructureNode> rootStructureNodes; |
41 |
|
41 |
|
42 |
public GenericJpaFile(JpaProject jpaProject, IFile file, ResourceModel resourceModel) { |
42 |
public GenericJpaFile(JpaProject jpaProject, IFile file, ResourceModel resourceModel) { |
43 |
super(jpaProject); |
43 |
super(jpaProject); |
44 |
this.file = file; |
44 |
this.file = file; |
45 |
this.resourceModel = resourceModel; |
45 |
this.resourceModel = resourceModel; |
46 |
this.rootStructureNodes = new HashMap<Object, JpaStructureNode>(); |
46 |
this.rootStructureNodes = new Hashtable<Object, JpaStructureNode>(); |
47 |
} |
47 |
} |
48 |
|
48 |
|
49 |
@Override |
49 |
@Override |
Lines 71-87
Link Here
|
71 |
public int rootStructureNodesSize() { |
71 |
public int rootStructureNodesSize() { |
72 |
return this.rootStructureNodes.size(); |
72 |
return this.rootStructureNodes.size(); |
73 |
} |
73 |
} |
74 |
|
74 |
|
|
|
75 |
// TODO move events outside of 'synchronized' block? |
76 |
// need fireItemReplaced(String, Object, Object) for Collection? |
75 |
public void addRootStructureNode(Object key, JpaStructureNode rootStructureNode) { |
77 |
public void addRootStructureNode(Object key, JpaStructureNode rootStructureNode) { |
76 |
if (this.rootStructureNodes.get(key) == rootStructureNode) { |
78 |
synchronized (this.rootStructureNodes) { |
77 |
return; |
79 |
JpaStructureNode node = this.rootStructureNodes.get(key); |
78 |
} |
80 |
if (node == rootStructureNode) { |
79 |
if (this.rootStructureNodes.containsKey(key)) { |
81 |
return; // no duplicates |
80 |
JpaStructureNode removedStructureNode = this.rootStructureNodes.remove(key); |
82 |
} |
81 |
fireItemRemoved(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, removedStructureNode); |
83 |
if (node != null) { |
|
|
84 |
this.rootStructureNodes.remove(key); |
85 |
this.fireItemRemoved(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, node); |
86 |
} |
87 |
this.rootStructureNodes.put(key, rootStructureNode); |
88 |
this.fireItemAdded(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode); |
82 |
} |
89 |
} |
83 |
this.rootStructureNodes.put(key, rootStructureNode); |
|
|
84 |
fireItemAdded(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, rootStructureNode); |
85 |
} |
90 |
} |
86 |
|
91 |
|
87 |
public void removeRootStructureNode(Object key) { |
92 |
public void removeRootStructureNode(Object key) { |
Lines 99-114
Link Here
|
99 |
return null; |
104 |
return null; |
100 |
} |
105 |
} |
101 |
|
106 |
|
|
|
107 |
protected Iterator<Object> rootStructureNodeKeys() { |
108 |
return new CloneIterator<Object>(this.rootStructureNodes.keySet()); |
109 |
} |
110 |
|
102 |
public String getResourceType() { |
111 |
public String getResourceType() { |
103 |
return getResourceModel().getResourceType(); |
112 |
return getResourceModel().getResourceType(); |
104 |
} |
113 |
} |
105 |
|
114 |
|
106 |
public void dispose() { |
115 |
public void dispose() { |
107 |
getResourceModel().dispose(); |
116 |
getResourceModel().dispose(); |
108 |
|
117 |
|
109 |
Set<Object> keys = this.rootStructureNodes.keySet(); |
118 |
for (Iterator<Object> stream = this.rootStructureNodeKeys(); stream.hasNext(); ) { |
110 |
for (Object key : keys) { |
119 |
this.removeRootStructureNode(stream.next()); |
111 |
removeRootStructureNode(key); |
|
|
112 |
} |
120 |
} |
113 |
} |
121 |
} |
114 |
|
122 |
|
Lines 123-126
Link Here
|
123 |
sb.append(getResourceType()); |
131 |
sb.append(getResourceType()); |
124 |
sb.append(")"); |
132 |
sb.append(")"); |
125 |
} |
133 |
} |
|
|
134 |
|
126 |
} |
135 |
} |