Author: rob.stryker(a)jboss.com
Date: 2012-07-31 06:48:22 -0400 (Tue, 31 Jul 2012)
New Revision: 42804
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
Log:
JBIDE-12385 to trunk
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java 2012-07-31
10:43:13 UTC (rev 42803)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeDeltaImpl.java 2012-07-31
10:48:22 UTC (rev 42804)
@@ -212,9 +212,9 @@
// Using a different delta constructor here to force
// whether this child is added or removed.
return new ArchiveNodeDeltaImpl(this, impl, addedOrRemoved,
- (HashMap)impl.attributeChanges.clone(),
- (HashMap)impl.propertyChanges.clone(),
- (HashMap)impl.childChanges.clone());
+ impl.getAttributeChanges(),
+ impl.getPropertyChanges(),
+ impl.getChildChanges());
}
return child.getDelta();
}
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2012-07-31
10:43:13 UTC (rev 42803)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2012-07-31
10:48:22 UTC (rev 42804)
@@ -41,11 +41,24 @@
protected ArrayList<ArchiveNodeImpl> children;
// cached data for deltas
- protected HashMap<String, NodeDelta> attributeChanges;
- protected HashMap<String, NodeDelta> propertyChanges;
- protected HashMap<IArchiveNode, Integer> childChanges;
+ private HashMap<String, NodeDelta> attributeChanges;
+ public synchronized HashMap<String, NodeDelta> getAttributeChanges() {
+ return (HashMap<String, NodeDelta>)attributeChanges.clone();
+ }
+ public synchronized HashMap<String, NodeDelta> getPropertyChanges() {
+ return (HashMap<String, NodeDelta>)propertyChanges.clone();
+ }
+ public synchronized HashMap<IArchiveNode, Integer> getChildChanges() {
+ return (HashMap<IArchiveNode, Integer>)childChanges.clone();
+ }
+
+
+ private HashMap<String, NodeDelta> propertyChanges;
+ private HashMap<IArchiveNode, Integer> childChanges;
+
+
public ArchiveNodeImpl (XbPackageNodeWithProperties delegate) {
nodeDelegate = delegate;
children = new ArrayList<ArchiveNodeImpl>();
@@ -260,7 +273,7 @@
* @param child
* @param addInDelegate
*/
- public final void addChild(IArchiveNode child, boolean addInDelegate) throws
ArchivesModelException {
+ public synchronized final void addChild(IArchiveNode child, boolean addInDelegate)
throws ArchivesModelException {
Assert.isNotNull(child);
ArchiveNodeImpl childImpl = (ArchiveNodeImpl) child;
children.add(childImpl);
@@ -302,7 +315,7 @@
* (non-Javadoc)
* @see
org.jboss.ide.eclipse.archives.core.model.IArchiveNode#removeChild(org.jboss.ide.eclipse.archives.core.model.IArchiveNode)
*/
- public void removeChild(IArchiveNode node) {
+ public synchronized void removeChild(IArchiveNode node) {
Assert.isNotNull(node);
ArchiveNodeImpl impl = (ArchiveNodeImpl) node;
boolean removed = false;
@@ -322,64 +335,62 @@
/**
* An attribute has changed. Save the change so it can be represented in a delta
*/
- protected void attributeChanged(String key, Object beforeValue, Object afterValue) {
+ protected synchronized void attributeChanged(String key, Object beforeValue, Object
afterValue) {
int kind = IArchiveNodeDelta.ATTRIBUTE_CHANGED;
- HashMap<String, NodeDelta> map = attributeChanges;
// short circuit if no change has REALLY occurred
if( beforeValue != null && beforeValue.equals(afterValue)) return;
- if( map.containsKey(key)) {
- Object original = map.get(key).getBefore();
+ if( attributeChanges.containsKey(key)) {
+ Object original = attributeChanges.get(key).getBefore();
if( original == null && afterValue == null )
- map.remove(key);
+ attributeChanges.remove(key);
else if( original == null )
- map.put(key, new NodeDelta(original, afterValue, kind));
+ attributeChanges.put(key, new NodeDelta(original, afterValue, kind));
else if( original.equals(afterValue))
// value was changed from x to y, then back to x. Therefore, no change
- map.remove(key);
+ attributeChanges.remove(key);
else
// value was changed from x to y to z.
// Before should remain x, after should become z
- map.put(key, new NodeDelta(original, afterValue, kind));
+ attributeChanges.put(key, new NodeDelta(original, afterValue, kind));
} else {
// added
- map.put(key, new NodeDelta(beforeValue, afterValue, kind));
+ attributeChanges.put(key, new NodeDelta(beforeValue, afterValue, kind));
}
}
/**
* A property has changed. Save the change so it can be represented in a delta
*/
- protected void propertyChanged(String key, Object beforeValue, Object afterValue) {
- HashMap<String, NodeDelta> changeMap = propertyChanges;
+ protected synchronized void propertyChanged(String key, Object beforeValue, Object
afterValue) {
// short circuit if no change has REALLY occurred
if( beforeValue != null && beforeValue.equals(afterValue)) return;
- if( changeMap.containsKey(key)) {
+ if( propertyChanges.containsKey(key)) {
// element has already been added, removed, or changed since last save
- Object original = changeMap.get(key).getBefore();
+ Object original = propertyChanges.get(key).getBefore();
if( original == null && afterValue == null )
- changeMap.remove(key);
+ propertyChanges.remove(key);
else if( original == null )
- changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_ADDED));
+ propertyChanges.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_ADDED));
else if( original.equals(afterValue))
// value was changed from x to y, then back to x. Therefore, no change
- changeMap.remove(key);
+ propertyChanges.remove(key);
else if( afterValue == null ) {
// changed from x to y to null, so removed
- changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_REMOVED));
+ propertyChanges.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_REMOVED));
} else {
// changed from x to y to z, so changed
- changeMap.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_CHANGED));
+ propertyChanges.put(key, new NodeDelta(original, afterValue,
IArchiveNodeDelta.PROPERTY_CHANGED));
}
} else {
int kind;
if( beforeValue == null ) kind = IArchiveNodeDelta.PROPERTY_ADDED;
else if( afterValue == null ) kind = IArchiveNodeDelta.PROPERTY_REMOVED;
else kind = IArchiveNodeDelta.PROPERTY_CHANGED;
- changeMap.put(key, new NodeDelta(beforeValue, afterValue, kind));
+ propertyChanges.put(key, new NodeDelta(beforeValue, afterValue, kind));
}
}
@@ -388,7 +399,7 @@
* @param node
* @param changeType
*/
- protected void childChanges(IArchiveNode node, int changeType) {
+ protected synchronized void childChanges(IArchiveNode node, int changeType) {
if( childChanges.containsKey(node)) {
int lastChange = childChanges.get(node).intValue();
if( lastChange == IArchiveNodeDelta.CHILD_ADDED && changeType ==
IArchiveNodeDelta.CHILD_REMOVED) {
@@ -406,14 +417,15 @@
* @see org.jboss.ide.eclipse.archives.core.model.IArchiveNode#getDelta()
*/
public IArchiveNodeDelta getDelta() {
- return new ArchiveNodeDeltaImpl(null, this, (HashMap<String,
NodeDelta>)attributeChanges.clone(),
- (HashMap<String, NodeDelta>)propertyChanges.clone(), (HashMap<IArchiveNode,
Integer>)childChanges.clone());
+ return new ArchiveNodeDeltaImpl(null, this, getAttributeChanges(),
+ getPropertyChanges(), getChildChanges());
}
+
/**
* Forget all past state
*/
- public void clearDelta() {
+ public synchronized void clearDelta() {
attributeChanges.clear();
propertyChanges.clear();
childChanges.clear();