Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2007-11-12 18:49:18 +0000
committerbvosburgh2007-11-12 18:49:18 +0000
commitca919f99a274efd6b68e7bdbccabe49bc45dbc76 (patch)
tree8900bb9723adb387685958fcf80c62f45bd4fe55
parent9696e7465479dacc2529e2e78450507c583ecd53 (diff)
downloadwebtools.dali-ca919f99a274efd6b68e7bdbccabe49bc45dbc76.tar.gz
webtools.dali-ca919f99a274efd6b68e7bdbccabe49bc45dbc76.tar.xz
webtools.dali-ca919f99a274efd6b68e7bdbccabe49bc45dbc76.zip
[201159] model rework: TreeValueModel
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/AbstractTreeNodeValueModel.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeAspectAdapter.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeNodeValueModel.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeValueModel.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/swing/TreeModelAdapter.java20
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java127
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java12
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java6
8 files changed, 138 insertions, 120 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/AbstractTreeNodeValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/AbstractTreeNodeValueModel.java
index d36cbf4fa6..d327fc5c14 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/AbstractTreeNodeValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/AbstractTreeNodeValueModel.java
@@ -30,11 +30,11 @@ import org.eclipse.jpt.utility.internal.model.listener.StateChangeListener;
* i.e. the object "wrapped" by the node;
* typically only overridden for nodes with "primitive" values
*
- * #getParent()
+ * #parent()
* return the parent of the node, which should be another
* TreeNodeValueModel
*
- * #getChildrenModel()
+ * #childrenModel()
* return a ListValueModel for the node's children
*
* #engageValue() and #disengageValue()
@@ -107,8 +107,8 @@ public abstract class AbstractTreeNodeValueModel
// ********** TreeNodeValueModel implementation **********
public TreeNodeValueModel[] path() {
- List path = CollectionTools.reverseList(this.backPath());
- return (TreeNodeValueModel[]) path.toArray(new TreeNodeValueModel[path.size()]);
+ List<TreeNodeValueModel> path = CollectionTools.reverseList(this.backPath());
+ return path.toArray(new TreeNodeValueModel[path.size()]);
}
/**
@@ -116,25 +116,25 @@ public abstract class AbstractTreeNodeValueModel
* starting with, and including, the node
* and up to, and including, the root node.
*/
- protected Iterator backPath() {
- return new ChainIterator(this) {
+ protected Iterator<TreeNodeValueModel> backPath() {
+ return new ChainIterator<TreeNodeValueModel>(this) {
@Override
- protected Object nextLink(Object currentLink) {
- return ((TreeNodeValueModel) currentLink).getParent();
+ protected TreeNodeValueModel nextLink(TreeNodeValueModel currentLink) {
+ return currentLink.parent();
}
};
}
- public TreeNodeValueModel getChild(int index) {
- return (TreeNodeValueModel) this.getChildrenModel().get(index);
+ public TreeNodeValueModel child(int index) {
+ return (TreeNodeValueModel) this.childrenModel().get(index);
}
public int childrenSize() {
- return this.getChildrenModel().size();
+ return this.childrenModel().size();
}
public int indexOfChild(TreeNodeValueModel child) {
- ListValueModel children = this.getChildrenModel();
+ ListValueModel children = this.childrenModel();
int size = children.size();
for (int i = 0; i < size; i++) {
if (children.get(i) == child) {
@@ -145,7 +145,7 @@ public abstract class AbstractTreeNodeValueModel
}
public boolean isLeaf() {
- return this.getChildrenModel().size() == 0;
+ return this.childrenModel().size() == 0;
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeAspectAdapter.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeAspectAdapter.java
index f3fe043e42..c985e9bdf9 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeAspectAdapter.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeAspectAdapter.java
@@ -25,11 +25,11 @@ import org.eclipse.jpt.utility.internal.model.listener.TreeChangeListener;
* at the very minimum, override this method to return an iterator
* on the subject's tree aspect; it does not need to be overridden if
* #value() is overridden and its behavior changed
- * #addNode(Object[], Object) and #removeNode(Object[])
+ * #add(Object[], Object) and #remove(Object[])
* override these methods if the client code needs to *change* the contents of
* the subject's tree aspect; oftentimes, though, the client code
- * (e.g. UI) will need only to *get* the value
- * #value()
+ * (e.g. UI) will need only to *get* the nodes
+ * #nodes()
* override this method only if returning an empty iterator when the
* subject is null is unacceptable
*/
@@ -95,13 +95,13 @@ public abstract class TreeAspectAdapter
}
- // ********** ValueModel implementation **********
+ // ********** TreeValueModel implementation **********
/**
* Return the value of the subject's tree aspect.
* This should be an *iterator* on the tree.
*/
- public Object value() {
+ public Iterator nodes() {
if (this.subject == null) {
return EmptyIterator.instance();
}
@@ -118,20 +118,17 @@ public abstract class TreeAspectAdapter
throw new UnsupportedOperationException();
}
-
- // ********** TreeValueModel implementation **********
-
/**
* Insert the specified node in the subject's tree aspect.
*/
- public void addNode(Object[] parentPath, Object node) {
+ public void add(Object[] parentPath, Object node) {
throw new UnsupportedOperationException();
}
/**
* Remove the specified node from the subject's tree aspect.
*/
- public void removeNode(Object[] path) {
+ public void remove(Object[] path) {
throw new UnsupportedOperationException();
}
@@ -139,23 +136,28 @@ public abstract class TreeAspectAdapter
// ********** AspectAdapter implementation **********
@Override
+ protected Object value() {
+ return this.nodes();
+ }
+
+ @Override
protected Class<? extends ChangeListener> listenerClass() {
return TreeChangeListener.class;
}
@Override
protected String listenerAspectName() {
- return VALUE;
+ return NODES;
}
@Override
protected boolean hasListeners() {
- return this.hasAnyTreeChangeListeners(VALUE);
+ return this.hasAnyTreeChangeListeners(NODES);
}
@Override
protected void fireAspectChange(Object oldValue, Object newValue) {
- this.fireTreeChanged(VALUE);
+ this.fireTreeChanged(NODES);
}
@Override
@@ -177,19 +179,19 @@ public abstract class TreeAspectAdapter
// ********** behavior **********
protected void nodeAdded(TreeChangeEvent e) {
- this.fireNodeAdded(VALUE, e.path());
+ this.fireNodeAdded(NODES, e.path());
}
protected void nodeRemoved(TreeChangeEvent e) {
- this.fireNodeRemoved(VALUE, e.path());
+ this.fireNodeRemoved(NODES, e.path());
}
protected void treeCleared(TreeChangeEvent e) {
- this.fireTreeCleared(VALUE);
+ this.fireTreeCleared(NODES);
}
protected void treeChanged(TreeChangeEvent e) {
- this.fireTreeChanged(VALUE, e.path());
+ this.fireTreeChanged(NODES, e.path());
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeNodeValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeNodeValueModel.java
index 749d54ccd1..418e73769d 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeNodeValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeNodeValueModel.java
@@ -30,7 +30,7 @@ public interface TreeNodeValueModel
* Return the node's parent node; null if the node
* is the root.
*/
- TreeNodeValueModel getParent();
+ TreeNodeValueModel parent();
/**
* Return the path to the node.
@@ -40,12 +40,12 @@ public interface TreeNodeValueModel
/**
* Return a list value model of the node's child nodes.
*/
- ListValueModel getChildrenModel();
+ ListValueModel childrenModel();
/**
* Return the node's child at the specified index.
*/
- TreeNodeValueModel getChild(int index);
+ TreeNodeValueModel child(int index);
/**
* Return the size of the node's list of children.
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeValueModel.java
index 5fba893d06..b2b2912a37 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TreeValueModel.java
@@ -9,24 +9,31 @@
******************************************************************************/
package org.eclipse.jpt.utility.internal.model.value;
+import java.util.Iterator;
+
+import org.eclipse.jpt.utility.internal.model.Model;
+
/**
- * Extend ValueModel to allow the adding and
- * removing of nodes in a tree value.
- * Typically the value returned from #value()
- * will be an Iterator.
+ * Interface used to abstract tree accessing and
+ * change notification and make it more pluggable.
*/
public interface TreeValueModel
- extends ValueModel
+ extends Model
{
+ /**
+ * Return the tree's nodes.
+ */
+ Iterator nodes();
+ String NODES = "nodes";
/**
- * Add the specified node to the tree value.
+ * Add the specified node to the tree.
*/
- void addNode(Object[] parentPath, Object node);
+ void add(Object[] parentPath, Object node);
/**
- * Remove the specified node from the tree value.
+ * Remove the specified node from the tree.
*/
- void removeNode(Object[] path);
+ void remove(Object[] path);
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/swing/TreeModelAdapter.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/swing/TreeModelAdapter.java
index c1a8e1c6ea..ecd8e592fe 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/swing/TreeModelAdapter.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/swing/TreeModelAdapter.java
@@ -203,7 +203,7 @@ public class TreeModelAdapter
}
public Object getChild(Object parent, int index) {
- return ((TreeNodeValueModel) parent).getChild(index);
+ return ((TreeNodeValueModel) parent).child(index);
}
public int getChildCount(Object parent) {
@@ -322,7 +322,7 @@ public class TreeModelAdapter
* forward notification to our listeners.
*/
void nodeChanged(TreeNodeValueModel node) {
- TreeNodeValueModel parent = node.getParent();
+ TreeNodeValueModel parent = node.parent();
if (parent == null) {
this.fireTreeRootChanged(node);
} else {
@@ -353,7 +353,7 @@ public class TreeModelAdapter
private void engageNode(TreeNodeValueModel node) {
node.addStateChangeListener(this.nodeStateListener);
node.addPropertyChangeListener(ValueModel.VALUE, this.nodeValueListener);
- node.getChildrenModel().addListChangeListener(ListValueModel.LIST_VALUES, this.childrenListener);
+ node.childrenModel().addListChangeListener(ListValueModel.LIST_VALUES, this.childrenListener);
}
/**
@@ -362,7 +362,7 @@ public class TreeModelAdapter
* adding them to the internal tree also.
*/
private void addNode(int index, TreeNodeValueModel node) {
- this.addNodeToInternalTree(node.getParent(), index, node, node.getChildrenModel());
+ this.addNodeToInternalTree(node.parent(), index, node, node.childrenModel());
new NodeChangePolicy(node).addChildren();
}
@@ -405,7 +405,7 @@ public class TreeModelAdapter
*/
private void removeNode(int index, TreeNodeValueModel node) {
new NodeChangePolicy(node).removeChildren();
- this.removeNodeFromInternalTree(node.getParent(), index, node, node.getChildrenModel());
+ this.removeNodeFromInternalTree(node.parent(), index, node, node.childrenModel());
}
/**
@@ -425,7 +425,7 @@ public class TreeModelAdapter
* Stop listening to the node and its children model.
*/
private void disengageNode(TreeNodeValueModel node) {
- node.getChildrenModel().removeListChangeListener(ListValueModel.LIST_VALUES, this.childrenListener);
+ node.childrenModel().removeListChangeListener(ListValueModel.LIST_VALUES, this.childrenListener);
node.removePropertyChangeListener(ValueModel.VALUE, this.nodeValueListener);
node.removeStateChangeListener(this.nodeStateListener);
}
@@ -629,8 +629,8 @@ public class TreeModelAdapter
Object[] childArray = this.buildArray(childrenList.iterator(), childrenList.size());
TreeModelAdapter.this.removeChildren(parentPath, childIndices, childArray);
- childIndices = this.buildIndices(parent.getChildrenModel().size());
- childArray = this.buildArray((Iterator) parent.getChildrenModel().values(), parent.childrenSize());
+ childIndices = this.buildIndices(parent.childrenModel().size());
+ childArray = this.buildArray((Iterator) parent.childrenModel().values(), parent.childrenSize());
TreeModelAdapter.this.addChildren(parentPath, childIndices, childArray);
}
@@ -678,7 +678,7 @@ public class TreeModelAdapter
*/
@Override
int childrenSize() {
- return this.node.getChildrenModel().size();
+ return this.node.childrenModel().size();
}
/**
@@ -688,7 +688,7 @@ public class TreeModelAdapter
*/
@Override
Iterator children() {
- return (Iterator) this.node.getChildrenModel().values();
+ return (Iterator) this.node.childrenModel().values();
}
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java
index 7a08366cf6..1d9860a9ea 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java
@@ -24,6 +24,7 @@ import org.eclipse.jpt.utility.internal.model.listener.TreeChangeListener;
import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.TreeAspectAdapter;
+import org.eclipse.jpt.utility.internal.model.value.TreeValueModel;
import org.eclipse.jpt.utility.internal.model.value.ValueModel;
import org.eclipse.jpt.utility.tests.internal.TestTools;
@@ -68,7 +69,7 @@ public class TreeAspectAdapterTests extends TestCase {
this.subjectHolder1 = new SimplePropertyValueModel(this.subject1);
this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
this.listener1 = this.buildValueChangeListener1();
- this.aa1.addTreeChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.addTreeChangeListener(TreeValueModel.NODES, this.listener1);
this.event1 = null;
this.subject2 = new TestSubject();
@@ -93,16 +94,18 @@ public class TreeAspectAdapterTests extends TestCase {
private TreeAspectAdapter buildAspectAdapter(ValueModel subjectHolder) {
return new TreeAspectAdapter(subjectHolder, TestSubject.NAMES_TREE) {
// this is not a typical aspect adapter - the value is determined by the aspect name
+ @Override
protected Iterator getValueFromSubject() {
if (this.treeName == TestSubject.NAMES_TREE) {
return ((TestSubject) this.subject).namePaths();
- } else if (this.treeName == TestSubject.DESCRIPTIONS_TREE) {
+ }
+ if (this.treeName == TestSubject.DESCRIPTIONS_TREE) {
return ((TestSubject) this.subject).descriptionPaths();
- } else {
- throw new IllegalStateException("invalid aspect name: " + this.treeName);
}
+ throw new IllegalStateException("invalid aspect name: " + this.treeName);
}
- public void addNode(Object[] parentPath, Object node) {
+ @Override
+ public void add(Object[] parentPath, Object node) {
TestNode parent = (TestNode) parentPath[parentPath.length - 1];
if (this.treeName == TestSubject.NAMES_TREE) {
((TestSubject) this.subject).addName(parent, (String) node);
@@ -112,7 +115,8 @@ public class TreeAspectAdapterTests extends TestCase {
throw new IllegalStateException("invalid aspect name: " + this.treeName);
}
}
- public void removeNode(Object[] path) {
+ @Override
+ public void remove(Object[] path) {
TestNode node = (TestNode) path[path.length - 1];
if (this.treeName == TestSubject.NAMES_TREE) {
((TestSubject) this.subject).removeNameNode(node);
@@ -158,21 +162,21 @@ public class TreeAspectAdapterTests extends TestCase {
this.subjectHolder1.setValue(this.subject2);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
assertEquals(0, this.event1.path().length);
this.event1 = null;
this.subjectHolder1.setValue(null);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
assertEquals(0, this.event1.path().length);
this.event1 = null;
this.subjectHolder1.setValue(this.subject1);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
assertEquals(0, this.event1.path().length);
}
@@ -182,62 +186,62 @@ public class TreeAspectAdapterTests extends TestCase {
this.subject1.addTwoNames(this.subject1.getRootNameNode(), "jam", "jaz");
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
Object[] path = this.event1.path();
assertEquals(this.subject1.getRootNameNode(), path[path.length - 1]);
assertTrue(this.subject1.containsNameNode("jam"));
assertTrue(this.subject1.containsNameNode("jaz"));
}
- public void testAddNode() {
+ public void testAdd() {
assertNull(this.event1);
TestNode node = this.subject1.nameNode("name 1.1.2");
this.subject1.addName(node, "jam");
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
Object[] path = this.event1.path();
assertEquals("jam", ((TestNode) path[path.length - 1]).getText());
this.event1 = null;
- this.aa1.addNode(node.path(), "jaz");
+ this.aa1.add(node.path(), "jaz");
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
path = this.event1.path();
assertEquals("jaz", ((TestNode) path[path.length - 1]).getText());
}
- public void testRemoveNode() {
+ public void testRemove() {
assertNull(this.event1);
TestNode node = this.subject1.nameNode("name 1.1.2");
this.subject1.removeNameNode(node);
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
Object[] path = this.event1.path();
assertEquals("name 1.1.2", ((TestNode) path[path.length - 1]).getText());
this.event1 = null;
node = this.subject1.nameNode("name 1.3");
- this.aa1.removeNode(node.path());
+ this.aa1.remove(node.path());
assertNotNull(this.event1);
assertEquals(this.aa1, this.event1.getSource());
- assertEquals(ValueModel.VALUE, this.event1.treeName());
+ assertEquals(TreeValueModel.NODES, this.event1.treeName());
path = this.event1.path();
assertEquals("name 1.3", ((TestNode) path[path.length - 1]).getText());
}
- public void testValue() {
- assertEquals(this.convertToNames(this.subject1.namePaths()), this.convertToNames((Iterator) this.aa1.value()));
+ public void testNodes() {
+ assertEquals(this.convertToNames(this.subject1.namePaths()), this.convertToNames(this.aa1.nodes()));
}
- private Collection convertToNames(Iterator namePaths) {
- Collection result = new HashBag();
+ private Collection<String> convertToNames(Iterator<TestNode[]> namePaths) {
+ Collection<String> result = new HashBag<String>();
while (namePaths.hasNext()) {
- Object[] path = (Object[]) namePaths.next();
+ Object[] path = namePaths.next();
StringBuffer sb = new StringBuffer();
sb.append('[');
for (int i = 0; i < path.length; i++) {
@@ -253,19 +257,19 @@ public class TreeAspectAdapterTests extends TestCase {
}
public void testHasListeners() {
- assertTrue(this.aa1.hasAnyTreeChangeListeners(ValueModel.VALUE));
+ assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- this.aa1.removeTreeChangeListener(ValueModel.VALUE, this.listener1);
+ this.aa1.removeTreeChangeListener(TreeValueModel.NODES, this.listener1);
assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- assertFalse(this.aa1.hasAnyTreeChangeListeners(ValueModel.VALUE));
+ assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
TreeChangeListener listener2 = this.buildValueChangeListener1();
this.aa1.addTreeChangeListener(listener2);
- assertTrue(this.aa1.hasAnyTreeChangeListeners(ValueModel.VALUE));
+ assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
this.aa1.removeTreeChangeListener(listener2);
assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- assertFalse(this.aa1.hasAnyTreeChangeListeners(ValueModel.VALUE));
+ assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
}
// ********** inner classes **********
@@ -283,17 +287,19 @@ public class TreeAspectAdapterTests extends TestCase {
public TestNode getRootNameNode() {
return this.rootNameNode;
}
- public Iterator nameNodes() {
- return new TreeIterator(this.rootNameNode) {
- public Iterator children(Object next) {
- return ((TestNode) next).children();
+ public Iterator<TestNode> nameNodes() {
+ return new TreeIterator<TestNode>(this.rootNameNode) {
+ @Override
+ public Iterator<TestNode> children(TestNode next) {
+ return next.children();
}
};
}
- public Iterator namePaths() {
- return new TransformationIterator(this.nameNodes()) {
- protected Object transform(Object next) {
- return ((TestNode) next).path();
+ public Iterator<TestNode[]> namePaths() {
+ return new TransformationIterator<TestNode, TestNode[]>(this.nameNodes()) {
+ @Override
+ protected TestNode[] transform(TestNode next) {
+ return next.path();
}
};
}
@@ -316,8 +322,8 @@ public class TreeAspectAdapterTests extends TestCase {
return this.nameNode(name) != null;
}
public TestNode nameNode(String name) {
- for (Iterator stream = this.nameNodes(); stream.hasNext(); ) {
- TestNode node = (TestNode) stream.next();
+ for (Iterator<TestNode> stream = this.nameNodes(); stream.hasNext(); ) {
+ TestNode node = stream.next();
if (node.getText().equals(name)) {
return node;
}
@@ -327,17 +333,19 @@ public class TreeAspectAdapterTests extends TestCase {
public TestNode getRootDescriptionNode() {
return this.rootDescriptionNode;
}
- public Iterator descriptionNodes() {
- return new TreeIterator(this.rootDescriptionNode) {
- public Iterator children(Object next) {
- return ((TestNode) next).children();
+ public Iterator<TestNode> descriptionNodes() {
+ return new TreeIterator<TestNode>(this.rootDescriptionNode) {
+ @Override
+ public Iterator<TestNode> children(TestNode next) {
+ return next.children();
}
};
}
- public Iterator descriptionPaths() {
- return new TransformationIterator(this.descriptionNodes()) {
- protected Object transform(Object next) {
- return ((TestNode) next).path();
+ public Iterator<TestNode[]> descriptionPaths() {
+ return new TransformationIterator<TestNode, TestNode[]>(this.descriptionNodes()) {
+ @Override
+ protected TestNode[] transform(TestNode next) {
+ return next.path();
}
};
}
@@ -352,8 +360,8 @@ public class TreeAspectAdapterTests extends TestCase {
this.fireNodeRemoved(DESCRIPTIONS_TREE, descriptionNode.path());
}
public boolean containsDescriptionNode(String name) {
- for (Iterator stream = this.descriptionNodes(); stream.hasNext(); ) {
- TestNode node = (TestNode) stream.next();
+ for (Iterator<TestNode> stream = this.descriptionNodes(); stream.hasNext(); ) {
+ TestNode node = stream.next();
if (node.getText().equals(name)) {
return true;
}
@@ -363,13 +371,13 @@ public class TreeAspectAdapterTests extends TestCase {
}
private class TestNode {
- private String text;
+ private final String text;
private TestNode parent;
- private Collection children;
+ private final Collection<TestNode> children;
public TestNode(String text) {
this.text = text;
- this.children = new HashBag();
+ this.children = new HashBag<TestNode>();
}
public String getText() {
return this.text;
@@ -380,8 +388,8 @@ public class TreeAspectAdapterTests extends TestCase {
private void setParent(TestNode parent) {
this.parent = parent;
}
- public Iterator children() {
- return new ReadOnlyIterator(this.children);
+ public Iterator<TestNode> children() {
+ return new ReadOnlyIterator<TestNode>(this.children);
}
public void addChild(TestNode child) {
this.children.add(child);
@@ -390,13 +398,14 @@ public class TreeAspectAdapterTests extends TestCase {
public void removeChild(TestNode child) {
this.children.remove(child);
}
- public Object[] path() {
- return CollectionTools.reverseList(this.buildAntiPath()).toArray();
+ public TestNode[] path() {
+ return CollectionTools.reverseList(this.buildAntiPath()).toArray(new TestNode[0]);
}
- private Iterator buildAntiPath() {
- return new ChainIterator(this) {
- protected Object nextLink(Object currentLink) {
- return ((TestNode) currentLink).getParent();
+ private Iterator<TestNode> buildAntiPath() {
+ return new ChainIterator<TestNode>(this) {
+ @Override
+ protected TestNode nextLink(TestNode currentLink) {
+ return currentLink.getParent();
}
};
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java
index 353133c515..7d207e2414 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java
@@ -519,11 +519,11 @@ public class TreeModelAdapterTests extends TestCase {
this.firePropertyChanged(VALUE, old, this.testModel);
}
- public TreeNodeValueModel getParent() {
+ public TreeNodeValueModel parent() {
return this.parent;
}
- public ListValueModel getChildrenModel() {
+ public ListValueModel childrenModel() {
return this.childrenModel;
}
@@ -564,7 +564,7 @@ public class TreeModelAdapterTests extends TestCase {
public void dumpOn(IndentingPrintWriter writer) {
writer.println(this);
writer.indent();
- for (Iterator stream = (Iterator) this.childrenModel.values(); stream.hasNext(); ) {
+ for (Iterator stream = this.childrenModel.values(); stream.hasNext(); ) {
((TestNode) stream.next()).dumpOn(writer);
}
writer.undent();
@@ -604,7 +604,7 @@ public class TreeModelAdapterTests extends TestCase {
* testing convenience method
*/
public TestNode childNamed(String name) {
- for (Iterator stream = (Iterator) this.childrenModel.values(); stream.hasNext(); ) {
+ for (Iterator stream = this.childrenModel.values(); stream.hasNext(); ) {
TestNode childNode = (TestNode) stream.next();
if (childNode.getTestModel().getName().equals(name)) {
return childNode;
@@ -781,10 +781,10 @@ public class TreeModelAdapterTests extends TestCase {
public void setValue(Object value) {
this.nameAdapter.setValue(value);
}
- public TreeNodeValueModel getParent() {
+ public TreeNodeValueModel parent() {
return this.specialNode;
}
- public ListValueModel getChildrenModel() {
+ public ListValueModel childrenModel() {
return NullListValueModel.instance();
}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
index 104915edfc..70420d6be3 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java
@@ -314,7 +314,7 @@ public class TreeModelAdapterUITest {
if ((selectedTestModel != null) && (selectedTestModel != this.root())) {
// save the parent and index, so we can select another, nearby, node
// once the selected node is removed
- TestNode parentNode = (TestNode) this.selectedNode().getParent();
+ TestNode parentNode = (TestNode) this.selectedNode().parent();
int childIndex = parentNode.indexOfChild(this.selectedNode());
selectedTestModel.getParent().removeChild(selectedTestModel);
@@ -322,14 +322,14 @@ public class TreeModelAdapterUITest {
int childrenSize = parentNode.childrenSize();
if (childIndex < childrenSize) {
// select the child that moved up and replaced the just-deleted child
- this.setSelectedNode((TestNode) parentNode.getChild(childIndex));
+ this.setSelectedNode((TestNode) parentNode.child(childIndex));
} else {
if (childrenSize == 0) {
// if there are no more children, select the parent
this.setSelectedNode(parentNode);
} else {
// if the child at the bottom of the list was deleted, select the next child up
- this.setSelectedNode((TestNode) parentNode.getChild(childIndex - 1));
+ this.setSelectedNode((TestNode) parentNode.child(childIndex - 1));
}
}
}

Back to the top