summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHendrik Still2013-09-10 14:20:13 (EDT)
committer Hendrik Still2013-09-12 17:50:57 (EDT)
commitc4d69dfb1433c698a532482c7c70d66cc06d4a6b (patch)
tree792b06d499f57aa8af2ac6d6e0621f35cc58920e
parentb7edb96e40b286414c64b55fa55ca83159bc12ac (diff)
downloadeclipse.platform.ui-c4d69dfb1433c698a532482c7c70d66cc06d4a6b.zip
eclipse.platform.ui-c4d69dfb1433c698a532482c7c70d66cc06d4a6b.tar.gz
eclipse.platform.ui-c4d69dfb1433c698a532482c7c70d66cc06d4a6b.tar.bz2
Bug 413973 - [Viewers] Add generics to the TreeViewerrefs/changes/08/16308/3
Generics are added to the TreeViewer to provide a type safty use of this viewer Change-Id: I21bb51ccca4625455e56d59766cc687f306bef97 Signed-off-by: Hendrik Still <hendrik.still@gammas.de>
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java11
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java573
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java3
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyContentProvider.java8
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreeContentProvider.java31
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreePathContentProvider.java32
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeContentProvider.java23
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathContentProvider.java25
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathLabelProvider.java14
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeViewerListener.java13
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java448
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java8
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java43
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeExpansionEvent.java21
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNode.java44
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNodeContentProvider.java14
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreePath.java71
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java164
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerColumn.java25
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerRow.java46
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerFilter.java27
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java2
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/WrappedViewerLabelProvider.java13
23 files changed, 942 insertions, 717 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java
index bf5a4cc..acf1eb1 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation bug 154329
* - fixes in bug 170381, 198665, 200731
+ * * Hendrik Still <hendrik.still@gammas.de> - b * Hendrik Still <hendrik.still@gammas.de> - bug 413973, bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -89,8 +90,8 @@ public abstract class AbstractTableViewer<E,I> extends ColumnViewer<E,I> {
IContentProvider<I> contentProvider = getContentProvider();
// If we are building lazily then request lookup now
if (contentProvider instanceof ILazyContentProvider) {
- ((ILazyContentProvider<I>) contentProvider)
- .updateElement(index);
+ ILazyContentProvider<I> lazyContentProvider = ((ILazyContentProvider<I>) contentProvider);
+ lazyContentProvider.updateElement(index);
return;
}
}
@@ -1124,11 +1125,13 @@ public abstract class AbstractTableViewer<E,I> extends ColumnViewer<E,I> {
* @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object)
*/
@Override
- protected E[] getRawChildren(I parent) {
+ protected E[] getRawChildren(Object parent) {
Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),
"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$
- return super.getRawChildren(parent);
+ @SuppressWarnings("unchecked")
+ I input = (I) parent;
+ return super.getRawChildren(input);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java
index af1aebd..831406f 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java
@@ -14,6 +14,7 @@
* Bruce Sutton, bug 221768
* Matthew Hall, bug 221988
* Julien Desgats, bug 203950
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -61,10 +62,12 @@ import org.eclipse.swt.widgets.Widget;
* interfaces <code>ITreeContentProvider</code> or (as of 3.2, to support
* multiple equal elements) <code>ITreePathContentProvider</code>.
* </p>
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
*
* @see TreeViewer
*/
-public abstract class AbstractTreeViewer extends ColumnViewer {
+public abstract class AbstractTreeViewer<E,I> extends ColumnViewer<E,I> {
/**
* Constant indicating that all levels of the tree should be expanded or
@@ -89,10 +92,10 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @see #setAutoExpandLevel
*/
private int expandToLevel = 0;
-
+
/**
* Indicates if filters should be checked to determine expandability of
- * a tree node.
+ * a tree node.
*/
private boolean isExpandableCheckFilters = false;
@@ -100,11 +103,11 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* Safe runnable used to update an item.
*/
class UpdateItemSafeRunnable extends SafeRunnable {
- private Object element;
+ private E element;
private Item item;
- UpdateItemSafeRunnable(Item item, Object element) {
+ UpdateItemSafeRunnable(Item item, E element) {
this.item = item;
this.element = element;
}
@@ -140,7 +143,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param childElements
* the child elements to add
*/
- public void add(Object parentElementOrTreePath, Object[] childElements) {
+ public void add(Object parentElementOrTreePath, E[] childElements) {
Assert.isNotNull(parentElementOrTreePath);
assertElementsNotNull(childElements);
if (checkBusy())
@@ -168,7 +171,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
final protected Widget[] internalFindItems(Object parentElementOrTreePath) {
Widget[] widgets;
if (parentElementOrTreePath instanceof TreePath) {
- TreePath path = (TreePath) parentElementOrTreePath;
+ @SuppressWarnings("unchecked")
+ TreePath<E> path = (TreePath<E>) parentElementOrTreePath;
Widget w = internalFindItem(path);
if (w == null) {
widgets = new Widget[] {};
@@ -176,7 +180,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
widgets = new Widget[] { w };
}
} else {
- widgets = findItems(parentElementOrTreePath);
+ @SuppressWarnings("unchecked")
+ E element = (E)parentElementOrTreePath;
+ widgets = findItems(element);
}
return widgets;
}
@@ -188,13 +194,13 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the path
* @return {@link Widget} the item at that path
*/
- private Widget internalFindItem(TreePath path) {
+ private Widget internalFindItem(TreePath<E> path) {
Widget[] widgets = findItems(path.getLastSegment());
for (int i = 0; i < widgets.length; i++) {
Widget widget = widgets[i];
if (widget instanceof Item) {
Item item = (Item) widget;
- TreePath p = getTreePathFromItem(item);
+ TreePath<E> p = getTreePathFromItem(item);
if (p.equals(path)) {
return widget;
}
@@ -222,14 +228,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @since 3.1
*/
protected void internalAdd(Widget widget, Object parentElementOrTreePath,
- Object[] childElements) {
- Object parent;
- TreePath path;
+ E[] childElements) {
+ E parent;
+ TreePath<E> path;
if (parentElementOrTreePath instanceof TreePath) {
- path = (TreePath) parentElementOrTreePath;
+ path = castObjectToTreePath(parentElementOrTreePath);
parent = path.getLastSegment();
} else {
- parent = parentElementOrTreePath;
+ parent = castObjectToElement(parentElementOrTreePath);
path = null;
}
@@ -264,8 +270,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (childElements.length > 0) {
// TODO: Add filtering back?
- Object[] filtered = filter(parentElementOrTreePath, childElements);
- ViewerComparator comparator = getComparator();
+ E[] filtered = filter(parentElementOrTreePath, childElements);
+ ViewerComparator<E,I> comparator = getComparator();
if (comparator != null) {
if (comparator instanceof TreePathViewerSorter) {
TreePathViewerSorter tpvs = (TreePathViewerSorter) comparator;
@@ -298,10 +304,10 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the child elements
* @return the filter list of children
*/
- private Object[] filter(Object parentElementOrTreePath, Object[] elements) {
- ViewerFilter[] filters = getFilters();
+ private E[] filter(Object parentElementOrTreePath, E[] elements) {
+ ViewerFilter<E,I>[] filters = getFilters();
if (filters != null) {
- ArrayList filtered = new ArrayList(elements.length);
+ ArrayList<E> filtered = new ArrayList<E>(elements.length);
for (int i = 0; i < elements.length; i++) {
boolean add = true;
for (int j = 0; j < filters.length; j++) {
@@ -315,7 +321,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
filtered.add(elements[i]);
}
}
- return filtered.toArray();
+ @SuppressWarnings("unchecked")
+ E[] result = (E[])filtered.toArray();
+ return result;
}
return elements;
}
@@ -328,7 +336,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param elements
* Sorted list of elements to add.
*/
- private void createAddedElements(Widget widget, Object[] elements) {
+ private void createAddedElements(Widget widget, E[] elements) {
if (elements.length == 1) {
if (equals(elements[0], widget.getData())) {
@@ -336,8 +344,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
}
- ViewerComparator comparator = getComparator();
- TreePath parentPath = internalGetSorterParentPath(widget, comparator);
+ ViewerComparator<E,I> comparator = getComparator();
+ TreePath<E> parentPath = internalGetSorterParentPath(widget, comparator);
Item[] items = getChildren(widget);
// Optimize for the empty case
@@ -351,7 +359,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// Optimize for no comparator
if (comparator == null) {
for (int i = 0; i < elements.length; i++) {
- Object element = elements[i];
+ E element = elements[i];
if (itemExists(items, element)) {
internalRefresh(element);
} else {
@@ -364,12 +372,12 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// start position. This is the insertion position relative to the
// original item array.
int indexInItems = 0;
-
+
// Count of elements we have added. See bug 205700 for why this is needed.
int newItems = 0;
-
+
elementloop: for (int i = 0; i < elements.length; i++) {
- Object element = elements[i];
+ E element = elements[i];
// update the index relative to the original item array
indexInItems = insertionPosition(items, comparator,
indexInItems, element, parentPath);
@@ -386,7 +394,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
int insertionIndexInItems = indexInItems;
while( insertionIndexInItems < items.length
&& internalCompare(comparator, parentPath, element,
- items[insertionIndexInItems].getData()) == 0) {
+ castObjectToElement(items[insertionIndexInItems].getData())) == 0) {
// As we cannot assume the sorter is consistent with
// equals() - therefore we can
// just check against the item prior to this index (if
@@ -422,7 +430,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param element
* @return <code>true</code> if the element matches.
*/
- private boolean itemExists(Item[] items, Object element) {
+ private boolean itemExists(Item[] items, E element) {
if (usingElementMap()) {
Widget[] existingItems = findItems(element);
// optimization for two common cases
@@ -466,8 +474,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
*/
- private int insertionPosition(Item[] items, ViewerComparator comparator,
- int lastInsertion, Object element, TreePath parentPath) {
+ private int insertionPosition(Item[] items, ViewerComparator<E,I> comparator,
+ int lastInsertion, E element, TreePath<E> parentPath) {
int size = items.length;
if (comparator == null) {
@@ -477,7 +485,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
while (min <= max) {
int mid = (min + max) / 2;
- Object data = items[mid].getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) items[mid].getData();
int compare = internalCompare(comparator, parentPath, data, element);
if (compare == 0) {
return mid;// Return if we already match
@@ -522,9 +531,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* The element to insert.
* @return the index of the element
*/
- protected int indexForElement(Widget parent, Object element) {
- ViewerComparator comparator = getComparator();
- TreePath parentPath = internalGetSorterParentPath(parent, comparator);
+ protected int indexForElement(Widget parent, E element) {
+ ViewerComparator<E,I> comparator = getComparator();
+ TreePath<E> parentPath = internalGetSorterParentPath(parent, comparator);
Item[] items = getChildren(parent);
int count = items.length;
@@ -536,7 +545,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
while (min <= max) {
int mid = (min + max) / 2;
- Object data = items[mid].getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) items[mid].getData();
int compare = internalCompare(comparator, parentPath, data, element);
if (compare == 0) {
// find first item > element
@@ -545,8 +555,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (mid >= count) {
break;
}
- data = items[mid].getData();
- compare = internalCompare(comparator, parentPath, data,
+ @SuppressWarnings("unchecked")
+ E itemElement = (E) items[mid].getData();
+ compare = internalCompare(comparator, parentPath, itemElement,
element);
}
return mid;
@@ -573,9 +584,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @return the tree path that should be used as the parent path for the
* given widget and sorter
*/
- private TreePath internalGetSorterParentPath(Widget parent,
- ViewerComparator comparator) {
- TreePath path;
+ private TreePath<E> internalGetSorterParentPath(Widget parent,
+ ViewerComparator<E,I> comparator) {
+ TreePath<E> path;
if (comparator instanceof TreePathViewerSorter
&& parent instanceof Item) {
Item item = (Item) parent;
@@ -602,8 +613,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the second element
* @return the result of comparing the two elements
*/
- private int internalCompare(ViewerComparator comparator,
- TreePath parentPath, Object e1, Object e2) {
+ private int internalCompare(ViewerComparator<E,I> comparator,
+ TreePath<E> parentPath, E e1, E e2) {
if (comparator instanceof TreePathViewerSorter) {
TreePathViewerSorter tpvs = (TreePathViewerSorter) comparator;
return tpvs.compare(this, parentPath, e1, e2);
@@ -617,9 +628,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#getSortedChildren(java.lang.Object)
*/
@Override
- protected Object[] getSortedChildren(Object parentElementOrTreePath) {
- Object[] result = getFilteredChildren(parentElementOrTreePath);
- ViewerComparator comparator = getComparator();
+ protected E[] getSortedChildren(Object parentElementOrTreePath) {
+ E[] result = getFilteredChildren(parentElementOrTreePath);
+ ViewerComparator<E,I> comparator = getComparator();
if (parentElementOrTreePath != null
&& comparator instanceof TreePathViewerSorter) {
TreePathViewerSorter tpvs = (TreePathViewerSorter) comparator;
@@ -627,9 +638,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// be sure we're not modifying the original array from the model
result = result.clone();
- TreePath path = null;
+ TreePath<E> path = null;
if (parentElementOrTreePath instanceof TreePath) {
- path = (TreePath) parentElementOrTreePath;
+ path = castObjectToTreePath(parentElementOrTreePath);
} else {
Object parent = parentElementOrTreePath;
Widget w = internalGetWidgetToSelect(parent);
@@ -664,8 +675,10 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param childElement
* the child element
*/
- public void add(Object parentElementOrTreePath, Object childElement) {
- add(parentElementOrTreePath, new Object[] { childElement });
+ public void add(Object parentElementOrTreePath, E childElement) {
+ @SuppressWarnings("unchecked")
+ E[] childElements = (E[])new Object[] { childElement };
+ add(parentElementOrTreePath, childElements);
}
/**
@@ -690,7 +703,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param listener
* a tree viewer listener
*/
- public void addTreeListener(ITreeViewerListener listener) {
+ public void addTreeListener(ITreeViewerListener<E,I> listener) {
treeListeners.add(listener);
}
@@ -711,8 +724,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @see StructuredViewer#associate(Object, Item)
*/
@Override
- protected void associate(Object element, Item item) {
- Object data = item.getData();
+ protected void associate(E element, Item item) {
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (data != null && data != element && equals(data, element)) {
// workaround for PR 1FV62BT
// assumption: elements are equal but not identical
@@ -770,7 +784,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
protected void createChildren(final Widget widget) {
createChildren(widget, true);
}
-
+
/**
* Creates all children for the given widget.
* <p>
@@ -782,7 +796,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @param widget
* the widget
- * @param materialize
+ * @param materialize
* true if children are expected to be fully materialized
*/
void createChildren(final Widget widget, boolean materialize) {
@@ -815,9 +829,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
Object d = widget.getData();
if (d != null) {
Object parentElement = d;
- Object[] children;
+ E[] children;
if (isTreePathContentProvider() && widget instanceof Item) {
- TreePath path = getTreePathFromItem((Item) widget);
+ TreePath<E> path = getTreePathFromItem((Item) widget);
children = getSortedChildren(path);
} else {
children = getSortedChildren(parentElement);
@@ -846,7 +860,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* if non-negative, indicates the position to insert the item
* into its parent
*/
- protected void createTreeItem(Widget parent, Object element, int index) {
+ protected void createTreeItem(Widget parent, E element, int index) {
Item item = newItem(parent, SWT.NULL, index);
updateItem(item, element);
updatePlus(item, element);
@@ -927,7 +941,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param element
* the element
*/
- protected void doUpdateItem(final Item item, Object element) {
+ protected void doUpdateItem(final Item item, E element) {
if (item.isDisposed()) {
unmapElement(element, item);
return;
@@ -937,23 +951,25 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (columnCount == 0)// If no columns are created then fake one
columnCount = 1;
- ViewerRow viewerRowFromItem = getViewerRowFromItem(item);
+ ViewerRow<E> viewerRowFromItem = getViewerRowFromItem(item);
boolean isVirtual = (getControl().getStyle() & SWT.VIRTUAL) != 0;
// If the control is virtual, we cannot use the cached viewer row object. See bug 188663.
if (isVirtual) {
- viewerRowFromItem = (ViewerRow) viewerRowFromItem.clone();
+ @SuppressWarnings("unchecked")
+ ViewerRow<E> clonedViewRowFrontItem = (ViewerRow<E>) viewerRowFromItem.clone();
+ viewerRowFromItem = clonedViewRowFrontItem;
}
for (int column = 0; column < columnCount; column++) {
- ViewerColumn columnViewer = getViewerColumn(column);
- ViewerCell cellToUpdate = updateCell(viewerRowFromItem, column,
+ ViewerColumn<E,I> columnViewer = getViewerColumn(column);
+ ViewerCell<E> cellToUpdate = updateCell(viewerRowFromItem, column,
element);
// If the control is virtual, we cannot use the cached cell object. See bug 188663.
if (isVirtual) {
- cellToUpdate = new ViewerCell(cellToUpdate.getViewerRow(), cellToUpdate.getColumnIndex(), element);
+ cellToUpdate = new ViewerCell<E>(cellToUpdate.getViewerRow(), cellToUpdate.getColumnIndex(), element);
}
columnViewer.refresh(cellToUpdate);
@@ -987,25 +1003,28 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @since 3.1 in TreeViewer, moved to AbstractTreeViewer in 3.3
*/
- protected boolean isSameSelection(List items, Item[] current) {
+ protected boolean isSameSelection(List<Item> items, Item[] current) {
// If they are not the same size then they are not equivalent
int n = items.size();
if (n != current.length) {
return false;
}
- CustomHashtable itemSet = newHashtable(n * 2 + 1);
- for (Iterator i = items.iterator(); i.hasNext();) {
- Item item = (Item) i.next();
- Object element = item.getData();
+ CustomHashtable<E,E> itemSet = newHashtable(n * 2 + 1);
+ for (Iterator<Item> i = items.iterator(); i.hasNext();) {
+ Item item = i.next();
+ @SuppressWarnings("unchecked")
+ E element = (E)item.getData();
itemSet.put(element, element);
}
// Go through the items of the current collection
// If there is a mismatch return false
for (int i = 0; i < current.length; i++) {
+ @SuppressWarnings("unchecked")
+ E element = (E) current[i].getData();
if (current[i].getData() == null
- || !itemSet.containsKey(current[i].getData())) {
+ || !itemSet.containsKey(element)) {
return false;
}
}
@@ -1017,7 +1036,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
/* (non-Javadoc) Method declared on StructuredViewer. */
@Override
- protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
+ protected void doUpdateItem(Widget widget, E element, boolean fullMap) {
boolean oldBusy = isBusy();
setBusy(true);
try {
@@ -1028,7 +1047,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (fullMap) {
associate(element, item);
} else {
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E)item.getData();
if (data != null) {
unmapElement(data, item);
}
@@ -1091,13 +1111,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the tree expansion event
* @see ITreeViewerListener#treeCollapsed
*/
- protected void fireTreeCollapsed(final TreeExpansionEvent event) {
+ protected void fireTreeCollapsed(final TreeExpansionEvent<E,I> event) {
Object[] listeners = treeListeners.getListeners();
boolean oldBusy = isBusy();
setBusy(true);
try {
for (int i = 0; i < listeners.length; ++i) {
- final ITreeViewerListener l = (ITreeViewerListener) listeners[i];
+ @SuppressWarnings("unchecked")
+ final ITreeViewerListener<E,I> l = (ITreeViewerListener<E,I>) listeners[i];
SafeRunnable.run(new SafeRunnable() {
public void run() {
l.treeCollapsed(event);
@@ -1117,13 +1138,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the tree expansion event
* @see ITreeViewerListener#treeExpanded
*/
- protected void fireTreeExpanded(final TreeExpansionEvent event) {
+ protected void fireTreeExpanded(final TreeExpansionEvent<E,I> event) {
Object[] listeners = treeListeners.getListeners();
boolean oldBusy = isBusy();
setBusy(true);
try {
for (int i = 0; i < listeners.length; ++i) {
- final ITreeViewerListener l = (ITreeViewerListener) listeners[i];
+ @SuppressWarnings("unchecked")
+ final ITreeViewerListener<E,I> l = (ITreeViewerListener<E,I>) listeners[i];
SafeRunnable.run(new SafeRunnable() {
public void run() {
l.treeExpanded(event);
@@ -1197,18 +1219,21 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @return the array of expanded elements
* @see #setExpandedElements
*/
- public Object[] getExpandedElements() {
- ArrayList items = new ArrayList();
+ public E[] getExpandedElements() {
+ ArrayList<Item> items = new ArrayList<Item>();
internalCollectExpandedItems(items, getControl());
- ArrayList result = new ArrayList(items.size());
- for (Iterator it = items.iterator(); it.hasNext();) {
- Item item = (Item) it.next();
- Object data = item.getData();
+ ArrayList<E> result = new ArrayList<E>(items.size());
+ for (Iterator<Item> it = items.iterator(); it.hasNext();) {
+ Item item = it.next();
+ @SuppressWarnings("unchecked")
+ E data = (E)item.getData();
if (data != null) {
result.add(data);
}
}
- return result.toArray();
+ @SuppressWarnings("unchecked")
+ E[] expendedElements = (E[]) result.toArray();
+ return expendedElements;
}
/**
@@ -1341,14 +1366,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
/* (non-Javadoc) Method declared on StructuredViewer. */
@Override
- protected Object[] getRawChildren(Object parentElementOrTreePath) {
+ protected E[] getRawChildren(Object parentElementOrTreePath) {
boolean oldBusy = isBusy();
setBusy(true);
try {
Object parent;
- TreePath path;
+ TreePath<E> path;
if (parentElementOrTreePath instanceof TreePath) {
- path = (TreePath) parentElementOrTreePath;
+ path = castObjectToTreePath(parentElementOrTreePath);
parent = path.getLastSegment();
} else {
parent = parentElementOrTreePath;
@@ -1356,37 +1381,49 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
if (parent != null) {
if (equals(parent, getRoot())) {
- return super.getRawChildren(parent);
+ @SuppressWarnings("unchecked")
+ I inputParent = (I) parent;
+ return super.getRawChildren(inputParent);
}
- IContentProvider cp = getContentProvider();
+ IContentProvider<I> cp = getContentProvider();
if (cp instanceof ITreePathContentProvider) {
- ITreePathContentProvider tpcp = (ITreePathContentProvider) cp;
+ @SuppressWarnings("unchecked")
+ ITreePathContentProvider<E,I> tpcp = (ITreePathContentProvider<E,I>) cp;
if (path == null) {
// A path was not provided so try and find one
- Widget w = findItem(parent);
+ @SuppressWarnings("unchecked")
+ E elementParent = (E) parent;
+ Widget w = findItem(elementParent);
if (w instanceof Item) {
Item item = (Item) w;
path = getTreePathFromItem(item);
}
if (path == null) {
- path = new TreePath(new Object[] { parent });
+ @SuppressWarnings("unchecked")
+ E[] segments = (E[]) new Object[] { parent };
+ path = new TreePath<E>(segments);
}
}
- Object[] result = tpcp.getChildren(path);
+ E[] result = tpcp.getChildren(path);
if (result != null) {
assertElementsNotNull(parent, result);
return result;
}
} else if (cp instanceof ITreeContentProvider) {
- ITreeContentProvider tcp = (ITreeContentProvider) cp;
- Object[] result = tcp.getChildren(parent);
+ @SuppressWarnings("unchecked")
+ E elementParent = (E) parent;
+ @SuppressWarnings("unchecked")
+ ITreeContentProvider<E,I> tcp = (ITreeContentProvider<E,I>) cp;
+ E[] result = tcp.getChildren(elementParent);
if (result != null) {
assertElementsNotNull(parent, result);
return result;
}
}
}
- return new Object[0];
+ @SuppressWarnings("unchecked")
+ E[] emptyElementList = (E[]) new Object[0];
+ return emptyElementList;
} finally {
setBusy(oldBusy);
}
@@ -1395,12 +1432,12 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
/**
* Asserts that the given array of elements is itself non- <code>null</code>
* and contains no <code>null</code> elements.
- *
+ *
* @param parent
* the parent element
* @param elements
* the array to check
- *
+ *
* @see #assertElementsNotNull(Object[])
*/
private void assertElementsNotNull(Object parent, Object[] elements) {
@@ -1408,10 +1445,10 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
for (int i = 0, n = elements.length; i < n; ++i) {
Assert.isNotNull(elements[i]);
}
-
+
if (InternalPolicy.DEBUG_LOG_EQUAL_VIEWER_ELEMENTS
&& elements.length > 1) {
- CustomHashtable elementSet = newHashtable(elements.length * 2);
+ CustomHashtable<Object,Object> elementSet = newHashtable(elements.length * 2);
for (int i = 0; i < elements.length; i++) {
Object element = elements[i];
Object old = elementSet.put(element, element);
@@ -1426,7 +1463,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
}
}
-
+
/**
* Returns all selected items for the given SWT control.
*
@@ -1442,12 +1479,13 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget()
*/
@Override
- protected List getSelectionFromWidget() {
+ protected List<E> getSelectionFromWidget() {
Widget[] items = getSelection(getControl());
- ArrayList list = new ArrayList(items.length);
+ ArrayList<E> list = new ArrayList<E>(items.length);
for (int i = 0; i < items.length; i++) {
Widget item = items[i];
- Object e = item.getData();
+ @SuppressWarnings("unchecked")
+ E e = (E) item.getData();
if (e != null) {
list.add(e);
}
@@ -1476,7 +1514,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (event.item != null && event.item.getData() != null) {
// changes to fix bug 108102 follow
- TreePath treePath = getTreePathFromItem((Item) event.item);
+ TreePath<E> treePath = getTreePathFromItem((Item) event.item);
selection = new TreeSelection(treePath);
// end of changes
@@ -1496,7 +1534,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*/
protected void handleTreeCollapse(TreeEvent event) {
if (event.item.getData() != null) {
- fireTreeCollapsed(new TreeExpansionEvent(this, event.item.getData()));
+ @SuppressWarnings("unchecked")
+ E element = (E) event.item.getData();
+ fireTreeCollapsed(new TreeExpansionEvent<E,I>(this, element));
}
}
@@ -1509,7 +1549,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
protected void handleTreeExpand(TreeEvent event) {
createChildren(event.item);
if (event.item.getData() != null) {
- fireTreeExpanded(new TreeExpansionEvent(this, event.item.getData()));
+ @SuppressWarnings("unchecked")
+ E element = (E) event.item.getData();
+ fireTreeExpanded(new TreeExpansionEvent<E,I>(this, element));
}
}
@@ -1533,7 +1575,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* tree and handles the automatic expand feature.
*/
@Override
- protected void inputChanged(Object input, Object oldInput) {
+ protected void inputChanged(I input, I oldInput) {
preservingSelection(new Runnable() {
public void run() {
Control tree = getControl();
@@ -1581,7 +1623,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (widget instanceof Item) {
Item item = (Item) widget;
setExpanded(item, false);
- Object element = item.getData();
+ @SuppressWarnings("unchecked")
+ E element = (E) item.getData();
if (element != null && level == ALL_LEVELS) {
if (optionallyPruneChildren(item, element)) {
return;
@@ -1611,7 +1654,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param widget
* the widget
*/
- private void internalCollectExpandedItems(List result, Widget widget) {
+ private void internalCollectExpandedItems(List<Item> result, Widget widget) {
Item[] items = getChildren(widget);
for (int i = 0; i < items.length; i++) {
Item item = items[i];
@@ -1661,14 +1704,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (expand && pw instanceof Item) {
// expand parent items top-down
Item item = (Item) pw;
- LinkedList toExpandList = new LinkedList();
+ LinkedList<Item> toExpandList = new LinkedList<Item>();
while (item != null && !getExpanded(item)) {
toExpandList.addFirst(item);
item = getParentItem(item);
}
- for (Iterator it = toExpandList.iterator(); it
+ for (Iterator<Item> it = toExpandList.iterator(); it
.hasNext();) {
- Item toExpand = (Item) it.next();
+ Item toExpand = it.next();
setExpanded(toExpand, true);
}
}
@@ -1688,7 +1731,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*/
private Object internalToElement(Object elementOrPath) {
if (elementOrPath instanceof TreePath) {
- return ((TreePath) elementOrPath).getLastSegment();
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) elementOrPath;
+ return treePath.getLastSegment();
}
return elementOrPath;
}
@@ -1707,13 +1752,17 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*/
protected Object getParentElement(Object elementOrTreePath) {
if (elementOrTreePath instanceof TreePath) {
- TreePath treePath = (TreePath) elementOrTreePath;
- return (treePath).getParentPath();
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) elementOrTreePath;
+ return treePath.getParentPath();
}
- IContentProvider cp = getContentProvider();
+ IContentProvider<I> cp = getContentProvider();
if (cp instanceof ITreePathContentProvider) {
- ITreePathContentProvider tpcp = (ITreePathContentProvider) cp;
- TreePath[] paths = tpcp.getParents(elementOrTreePath);
+ @SuppressWarnings("unchecked")
+ ITreePathContentProvider<E,I> tpcp = (ITreePathContentProvider<E,I>) cp;
+ @SuppressWarnings("unchecked")
+ E element = (E) elementOrTreePath;
+ TreePath<E>[] paths = tpcp.getParents(element);
if (paths.length > 0) {
if (paths[0].getSegmentCount() == 0) {
return getRoot();
@@ -1722,8 +1771,11 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
}
if (cp instanceof ITreeContentProvider) {
- ITreeContentProvider tcp = (ITreeContentProvider) cp;
- return tcp.getParent(elementOrTreePath);
+ @SuppressWarnings("unchecked")
+ ITreeContentProvider<E,I> tcp = (ITreeContentProvider<E,I>) cp;
+ @SuppressWarnings("unchecked")
+ E element = (E)elementOrTreePath;
+ return tcp.getParent(element);
}
return null;
}
@@ -1739,7 +1791,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*/
protected Widget internalGetWidgetToSelect(Object elementOrTreePath) {
if (elementOrTreePath instanceof TreePath) {
- TreePath treePath = (TreePath) elementOrTreePath;
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) elementOrTreePath;
if (treePath.getSegmentCount() == 0) {
return getControl();
}
@@ -1756,7 +1809,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
return null;
}
- return findItem(elementOrTreePath);
+ @SuppressWarnings("unchecked")
+ E element = (E) elementOrTreePath;
+ return findItem(element);
}
/**
@@ -1776,7 +1831,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
protected void internalExpandToLevel(Widget widget, int level) {
if (level == ALL_LEVELS || level > 0) {
if (widget instanceof Item && widget.getData() != null
- && !isExpandable((Item) widget, null, widget.getData())) {
+ && !isExpandable((Item) widget, null, castObjectToElement(widget.getData()))) {
return;
}
createChildren(widget, false);
@@ -1862,7 +1917,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
internalRefresh(getControl(), getRoot(), true, updateLabels);
return;
}
- Widget[] items = findItems(element);
+ Widget[] items = findItems(castObjectToElement(element));
if (items.length != 0) {
for (int i = 0; i < items.length; i++) {
// pick up structure changes too
@@ -1899,12 +1954,12 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (widget instanceof Item) {
if (doStruct) {
- updatePlus((Item) widget, element);
+ updatePlus((Item) widget, castObjectToElement(element));
}
if (updateLabels || !equals(element, widget.getData())) {
- doUpdateItem(widget, element, true);
+ doUpdateItem(widget, castObjectToElement(element), true);
} else {
- associate(element, (Item) widget);
+ associate(castObjectToElement(element), (Item) widget);
}
}
@@ -1915,7 +1970,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
if (children != null) {
for (int i = 0; i < children.length; i++) {
Widget item = children[i];
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (data != null) {
internalRefresh(item, data, doStruct, updateLabels);
}
@@ -1934,7 +1990,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*/
/* package */void internalRefreshStruct(Widget widget, Object element,
boolean updateLabels) {
- updateChildren(widget, element, null, updateLabels);
+ updateChildren(widget, castObjectToElement(element), null, updateLabels);
Item[] children = getChildren(widget);
if (children != null) {
for (int i = 0; i < children.length; i++) {
@@ -1961,7 +2017,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @since 3.1
*/
protected void internalRemove(Object[] elementsOrPaths) {
- Object input = getInput();
+ I input = getInput();
for (int i = 0; i < elementsOrPaths.length; ++i) {
Object element = elementsOrPaths[i];
if (equals(element, input)) {
@@ -1982,13 +2038,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
Object parent = getParentElement(element);
if (parent != null
&& !equals(parent, getRoot())
- && !(parent instanceof TreePath && ((TreePath) parent)
- .getSegmentCount() == 0)) {
+ && !(parent instanceof TreePath && castObjectToTreePath(
+ parent).getSegmentCount() == 0)) {
Widget[] parentItems = internalFindItems(parent);
for (int j = 0; j < parentItems.length; j++) {
Widget parentItem = parentItems[j];
if (parentItem instanceof Item) {
- updatePlus((Item) parentItem, parent);
+ updatePlus((Item) parentItem,
+ castObjectToElement(parent));
}
}
}
@@ -2005,9 +2062,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the elements to remove
* @since 3.1
*/
- protected void internalRemove(Object parent, Object[] elements) {
+ protected void internalRemove(E parent, E[] elements) {
- CustomHashtable toRemove = new CustomHashtable(getComparer());
+ CustomHashtable<E,E> toRemove = new CustomHashtable<E,E>(getComparer());
for (int i = 0; i < elements.length; i++) {
toRemove.put(elements[i], elements[i]);
}
@@ -2033,7 +2090,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
for (int j = 0; j < children.length; j++) {
Item child = children[j];
- Object data = child.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) child.getData();
if (data != null && toRemove.containsKey(data)) {
disassociate(child);
child.dispose();
@@ -2053,12 +2111,13 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param widget
* the widget
*/
- private void internalSetExpanded(CustomHashtable expandedElements,
+ private void internalSetExpanded(CustomHashtable<E,E> expandedElements,
Widget widget) {
Item[] items = getChildren(widget);
for (int i = 0; i < items.length; i++) {
Item item = items[i];
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (data != null) {
// remove the element to avoid an infinite loop
// if the same element appears on a child item
@@ -2087,13 +2146,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the widget
*/
private void internalSetExpandedTreePaths(
- CustomHashtable expandedTreePaths, Widget widget,
- TreePath currentPath) {
+ CustomHashtable<TreePath<E>,TreePath<E>> expandedTreePaths, Widget widget,
+ TreePath<E> currentPath) {
Item[] items = getChildren(widget);
for (int i = 0; i < items.length; i++) {
Item item = items[i];
- Object data = item.getData();
- TreePath childPath = data == null ? null : currentPath
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
+ TreePath<E> childPath = data == null ? null : currentPath
.createChildPath(data);
if (data != null && childPath != null) {
// remove the element to avoid an infinite loop
@@ -2126,18 +2186,19 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* element can be expanded, or <code>false</code> if not
*/
public boolean isExpandable(Object elementOrTreePath) {
- Object element;
- TreePath path;
+ E element;
+ TreePath<E> path;
if (elementOrTreePath instanceof TreePath) {
- path = (TreePath) elementOrTreePath;
+ path = castObjectToTreePath(elementOrTreePath);
element = path.getLastSegment();
} else {
- element = elementOrTreePath;
+ element = castObjectToElement(elementOrTreePath);
path = null;
}
- IContentProvider cp = getContentProvider();
+ IContentProvider<I> cp = getContentProvider();
if (cp instanceof ITreePathContentProvider) {
- ITreePathContentProvider tpcp = (ITreePathContentProvider) cp;
+ @SuppressWarnings("unchecked")
+ ITreePathContentProvider<E,I> tpcp = (ITreePathContentProvider<E,I>) cp;
if (path == null) {
// A path was not provided so try and find one
Widget w = findItem(element);
@@ -2146,7 +2207,9 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
path = getTreePathFromItem(item);
}
if (path == null) {
- path = new TreePath(new Object[] { element });
+ @SuppressWarnings("unchecked")
+ E[] elements = (E[]) new Object[] { element };
+ path = new TreePath<E>(elements);
}
}
boolean hasChildren = tpcp.hasChildren(path);
@@ -2156,7 +2219,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
return hasChildren;
}
if (cp instanceof ITreeContentProvider) {
- ITreeContentProvider tcp = (ITreeContentProvider) cp;
+ @SuppressWarnings("unchecked")
+ ITreeContentProvider<E,I> tcp = (ITreeContentProvider<E,I>) cp;
boolean hasChildren = tcp.hasChildren(element);
if (hasChildren && isExpandableCheckFilters && hasFilters()) {
return getFilteredChildren(element).length > 0;
@@ -2166,6 +2230,15 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
return false;
}
+// /* (non-Javadoc)
+// * @see org.eclipse.jface.viewers.StructuredViewer#getFilteredChildren(java.lang.Object)
+// */
+// @Override
+// protected E[] getFilteredChildren(Object parent) {
+// E[] result = getRawChildren(parent);
+// return internalFilter(result, parent);
+// }
+
/**
* Return whether the given element is expandable.
*
@@ -2178,7 +2251,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the element
* @return whether the given element is expandable
*/
- private boolean isExpandable(Item item, TreePath parentPath, Object element) {
+ private boolean isExpandable(Item item, TreePath<E> parentPath, E element) {
Object elementOrTreePath = element;
if (isTreePathContentProvider()) {
if (parentPath != null) {
@@ -2259,7 +2332,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @since 3.2
*/
- public void remove(final Object parent, final Object[] elements) {
+ public void remove(final E parent, final E[] elements) {
assertElementsNotNull(elements);
if (elements.length == 0) {
return;
@@ -2306,7 +2379,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param listener
* a tree viewer listener
*/
- public void removeTreeListener(ITreeViewerListener listener) {
+ public void removeTreeListener(ITreeViewerListener<E,I> listener) {
treeListeners.remove(listener);
}
@@ -2380,7 +2453,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* Note that in previous releases, the Javadoc for this method had an off-by
* one error. See bug 177669 for details.
* </p>
- *
+ *
* @param level
* non-negative level, or <code>ALL_LEVELS</code> to expand all
* levels of the tree
@@ -2395,13 +2468,13 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* <code>ITreeContentProvider</code>.
*/
@Override
- public void setContentProvider(IContentProvider provider) {
+ public void setContentProvider(IContentProvider<I> provider) {
// the actual check is in assertContentProviderType
super.setContentProvider(provider);
}
@Override
- protected void assertContentProviderType(IContentProvider provider) {
+ protected void assertContentProviderType(IContentProvider<I> provider) {
Assert.isTrue(provider instanceof ITreeContentProvider
|| provider instanceof ITreePathContentProvider);
}
@@ -2429,14 +2502,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the array of expanded elements
* @see #getExpandedElements
*/
- public void setExpandedElements(Object[] elements) {
+ public void setExpandedElements(E[] elements) {
assertElementsNotNull(elements);
if (checkBusy()) {
return;
}
- CustomHashtable expandedElements = newHashtable(elements.length * 2 + 1);
+ CustomHashtable<E,E> expandedElements = newHashtable(elements.length * 2 + 1);
for (int i = 0; i < elements.length; ++i) {
- Object element = elements[i];
+ E element = elements[i];
// Ensure item exists for element. This will materialize items for
// each element and their parents, if possible. This is important
// to support expanding of inner tree nodes without necessarily
@@ -2466,7 +2539,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @since 3.2
*/
- public void setExpandedTreePaths(TreePath[] treePaths) {
+ public void setExpandedTreePaths(TreePath<E>[] treePaths) {
assertElementsNotNull(treePaths);
if (checkBusy())
return;
@@ -2474,17 +2547,23 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
IElementComparer treePathComparer = new IElementComparer() {
public boolean equals(Object a, Object b) {
- return ((TreePath) a).equals(((TreePath) b), comparer);
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePathA = (TreePath<E>) a;
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePathB = (TreePath<E>) b;
+ return treePathA.equals(treePathB, comparer);
}
public int hashCode(Object element) {
- return ((TreePath) element).hashCode(comparer);
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) element;
+ return treePath.hashCode(comparer);
}
};
- CustomHashtable expandedTreePaths = new CustomHashtable(
+ CustomHashtable<TreePath<E>,TreePath<E>> expandedTreePaths = new CustomHashtable<TreePath<E>,TreePath<E>>(
treePaths.length * 2 + 1, treePathComparer);
for (int i = 0; i < treePaths.length; ++i) {
- TreePath treePath = treePaths[i];
+ TreePath<E> treePath = treePaths[i];
// Ensure item exists for element. This will materialize items for
// each element and their parents, if possible. This is important
// to support expanding of inner tree nodes without necessarily
@@ -2496,8 +2575,10 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// elements that need to be expanded. If the tree contains multiple
// equal elements, and those are in the set of elements to be expanded,
// only the first item found for each element will be expanded.
+ @SuppressWarnings("unchecked")
+ E[] emptyElements = (E[]) new Object[0];
internalSetExpandedTreePaths(expandedTreePaths, getControl(),
- new TreePath(new Object[0]));
+ new TreePath<E>(emptyElements));
}
/**
@@ -2530,34 +2611,35 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* list of items (element type:
* <code>org.eclipse.swt.widgets.Item</code>)
*/
- protected abstract void setSelection(List items);
+ protected abstract void setSelection(List<Item> items);
/**
* This implementation of setSelectionToWidget accepts a list of elements or
* a list of tree paths.
*/
@Override
- protected void setSelectionToWidget(List v, boolean reveal) {
+ protected void setSelectionToWidget(@SuppressWarnings("rawtypes") List v, boolean reveal) {
if (v == null) {
- setSelection(new ArrayList(0));
+ setSelection(new ArrayList<Item>(0));
return;
}
int size = v.size();
- List newSelection = new ArrayList(size);
+ List<Item> newSelection = new ArrayList<Item>(size);
for (int i = 0; i < size; ++i) {
Object elementOrTreePath = v.get(i);
// Use internalExpand since item may not yet be created. See
// 1G6B1AR.
Widget w = internalExpand(elementOrTreePath, false);
if (w instanceof Item) {
- newSelection.add(w);
+ newSelection.add((Item) w);
} else if (w == null && elementOrTreePath instanceof TreePath) {
- TreePath treePath = (TreePath) elementOrTreePath;
- Object element = treePath.getLastSegment();
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) elementOrTreePath;
+ E element = treePath.getLastSegment();
if (element != null) {
w = internalExpand(element, false);
if (w instanceof Item) {
- newSelection.add(w);
+ newSelection.add((Item) w);
}
}
}
@@ -2572,7 +2654,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// Iterate backwards so the first item in the list
// is the one guaranteed to be visible
for (int i = (newSelection.size()-1); i >= 0; i--) {
- showItem((Item) newSelection.get(i));
+ showItem(newSelection.get(i));
}
}
}
@@ -2598,10 +2680,11 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* the child elements, or null
* @deprecated this is no longer called by the framework
*/
+ @SuppressWarnings("unchecked")
@Deprecated
protected void updateChildren(Widget widget, Object parent,
Object[] elementChildren) {
- updateChildren(widget, parent, elementChildren, true);
+ updateChildren(widget, (E)parent, (E[])elementChildren, true);
}
/**
@@ -2621,8 +2704,8 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* that labels for existing elements are unchanged.
* @since 2.1
*/
- private void updateChildren(Widget widget, Object parent,
- Object[] elementChildren, boolean updateLabels) {
+ private void updateChildren(Widget widget, E parent,
+ E[] elementChildren, boolean updateLabels) {
// optimization! prune collapsed subtrees
if (widget instanceof Item) {
Item ti = (Item) widget;
@@ -2661,7 +2744,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// below.
if (elementChildren == null) {
if (isTreePathContentProvider() && widget instanceof Item) {
- TreePath path = getTreePathFromItem((Item) widget);
+ TreePath<E> path = getTreePathFromItem((Item) widget);
elementChildren = getSortedChildren(path);
} else {
elementChildren = getSortedChildren(parent);
@@ -2677,16 +2760,17 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
Item[] items = getChildren(widget);
-
+
// save the expanded elements
- CustomHashtable expanded = newHashtable(CustomHashtable.DEFAULT_CAPACITY); // assume
+ CustomHashtable<E,E> expanded = newHashtable(CustomHashtable.DEFAULT_CAPACITY); // assume
// num
// expanded
// is
// small
for (int i = 0; i < items.length; ++i) {
if (getExpanded(items[i])) {
- Object element = items[i].getData();
+ @SuppressWarnings("unchecked")
+ E element = (E) items[i].getData();
if (element != null) {
expanded.put(element, element);
}
@@ -2699,14 +2783,15 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// been deleted but not reordered, or all elements have been removed.
int numItemsToDispose = items.length - min;
if (numItemsToDispose > 0) {
- CustomHashtable children = newHashtable(elementChildren.length * 2);
+ CustomHashtable<E,E> children = newHashtable(elementChildren.length * 2);
for (int i = 0; i < elementChildren.length; i++) {
- Object elementChild = elementChildren[i];
+ E elementChild = elementChildren[i];
children.put(elementChild, elementChild);
}
int i = 0;
while (numItemsToDispose > 0 && i < items.length) {
- Object data = items[i].getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) items[i].getData();
if (data == null || !children.containsKey(data)) {
if (data != null) {
disassociate(items[i]);
@@ -2736,14 +2821,15 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
Item item = items[i];
Object oldElement = item.getData();
if (oldElement != null) {
- Object newElement = elementChildren[i];
+ E newElement = elementChildren[i];
if (newElement != oldElement) {
if (equals(newElement, oldElement)) {
// update the data to be the new element, since
// although the elements
// may be equal, they may still have different labels
// or children
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (data != null) {
unmapElement(data, item);
}
@@ -2762,7 +2848,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
for (int i = 0; i < min; ++i) {
Item item = items[i];
- Object newElement = elementChildren[i];
+ E newElement = elementChildren[i];
if (item.getData() == null) {
// old and new elements are not equal
associate(newElement, item);
@@ -2785,7 +2871,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
// This needs to be done in a second loop, see bug 148025.
for (int i = 0; i < min; ++i) {
Item item = items[i];
- Object newElement = elementChildren[i];
+ E newElement = elementChildren[i];
setExpanded(item, expanded.containsKey(newElement));
}
@@ -2824,7 +2910,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
/** Returns true if children were pruned */
- /*package*/ boolean optionallyPruneChildren(Item item, Object element) {
+ /*package*/ boolean optionallyPruneChildren(Item item, E element) {
// need a dummy node if element is expandable;
// but try to avoid recreating the dummy node
boolean needDummy = isExpandable(item, null, element);
@@ -2852,12 +2938,12 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
/**
* Not to be called by clients. Return the items to be refreshed as part of
* an update. elementChildren are the new elements.
- *
+ *
* @param widget
* @param elementChildren
* @since 3.4
* @return Item[]
- *
+ *
* @deprecated This method was inadvertently released as API but is not
* intended to be called by clients.
*/
@@ -2876,7 +2962,7 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @param element
* the element
*/
- protected void updatePlus(Item item, Object element) {
+ protected void updatePlus(Item item, E element) {
boolean hasPlus = getItemCount(item) > 0;
boolean needsPlus = isExpandable(item, null, element);
boolean removeAll = false;
@@ -2921,18 +3007,21 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @return the visible expanded elements
* @since 2.0
*/
- public Object[] getVisibleExpandedElements() {
- ArrayList v = new ArrayList();
+ public E[] getVisibleExpandedElements() {
+ ArrayList<E> v = new ArrayList<E>();
internalCollectVisibleExpanded(v, getControl());
- return v.toArray();
+ @SuppressWarnings("unchecked")
+ E[] elements = (E[]) v.toArray();
+ return elements;
}
- private void internalCollectVisibleExpanded(ArrayList result, Widget widget) {
+ private void internalCollectVisibleExpanded(ArrayList<E> result, Widget widget) {
Item[] items = getChildren(widget);
for (int i = 0; i < items.length; i++) {
Item item = items[i];
if (getExpanded(item)) {
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (data != null) {
result.add(data);
}
@@ -2950,15 +3039,18 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @since 3.2
*/
- protected TreePath getTreePathFromItem(Item item) {
- LinkedList segments = new LinkedList();
+ protected TreePath<E> getTreePathFromItem(Item item) {
+ LinkedList<E> segments = new LinkedList<E>();
while (item != null) {
- Object segment = item.getData();
+ @SuppressWarnings("unchecked")
+ E segment = (E) item.getData();
Assert.isNotNull(segment);
segments.addFirst(segment);
item = getParentItem(item);
}
- return new TreePath(segments.toArray());
+ @SuppressWarnings("unchecked")
+ E[] elements = (E[]) segments.toArray();
+ return new TreePath<E>(elements);
}
/**
@@ -2974,14 +3066,14 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
return TreeSelection.EMPTY;
}
Widget[] items = getSelection(getControl());
- ArrayList list = new ArrayList(items.length);
+ ArrayList<TreePath<E>> list = new ArrayList<TreePath<E>>(items.length);
for (int i = 0; i < items.length; i++) {
Widget item = items[i];
if (item.getData() != null) {
list.add(getTreePathFromItem((Item) item));
}
}
- return new TreeSelection((TreePath[]) list.toArray(new TreePath[list
+ return new TreeSelection(list.toArray(new TreePath[list
.size()]), getComparer());
}
@@ -3010,18 +3102,20 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @since 3.2
*/
- public TreePath[] getExpandedTreePaths() {
- ArrayList items = new ArrayList();
+ public TreePath<E>[] getExpandedTreePaths() {
+ ArrayList<Item> items = new ArrayList<Item>();
internalCollectExpandedItems(items, getControl());
- ArrayList result = new ArrayList(items.size());
- for (Iterator it = items.iterator(); it.hasNext();) {
- Item item = (Item) it.next();
- TreePath treePath = getTreePathFromItem(item);
+ ArrayList<TreePath<E>> result = new ArrayList<TreePath<E>>(items.size());
+ for (Iterator<Item> it = items.iterator(); it.hasNext();) {
+ Item item = it.next();
+ TreePath<E> treePath = getTreePathFromItem(item);
if (treePath != null) {
result.add(treePath);
}
}
- return (TreePath[]) result.toArray(new TreePath[items.size()]);
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E>[] treePaths = (TreePath<E>[]) result.toArray(new TreePath[items.size()]);
+ return treePaths;
}
private boolean isTreePathContentProvider() {
@@ -3049,14 +3143,16 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*
* @since 3.2
*/
- public void insert(Object parentElementOrTreePath, Object element,
+ public void insert(Object parentElementOrTreePath, E element,
int position) {
Assert.isNotNull(parentElementOrTreePath);
Assert.isNotNull(element);
if (checkBusy())
return;
if (getComparator() != null || hasFilters()) {
- add(parentElementOrTreePath, new Object[] { element });
+ @SuppressWarnings("unchecked")
+ E[] children = (E[]) new Object[] { element };
+ add(parentElementOrTreePath, children);
return;
}
Widget[] items;
@@ -3082,10 +3178,16 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
createTreeItem(item, element, insertionPosition);
} else {
- Object parentElement = parentElementOrTreePath;
- if (element instanceof TreePath)
- parentElement = ((TreePath) parentElement).getLastSegment();
- updatePlus(item, parentElement);
+ if (element instanceof TreePath) {
+ @SuppressWarnings("unchecked")
+ TreePath<E> parentTreePath = (TreePath<E>) parentElementOrTreePath;
+ E parentElement = parentTreePath.getLastSegment();
+ updatePlus(item, parentElement);
+ } else {
+ @SuppressWarnings("unchecked")
+ E parentElement = (E) parentElementOrTreePath;
+ updatePlus(item, parentElement);
+ }
}
} else {
int insertionPosition = position;
@@ -3159,18 +3261,19 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
*/
@Override
protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) {
- Object element;
+ E element;
if (elementOrPath instanceof TreePath) {
- TreePath path = (TreePath) elementOrPath;
- IBaseLabelProvider provider = getLabelProvider();
+ @SuppressWarnings("unchecked")
+ TreePath<E> path = (TreePath<E>) elementOrPath;
+ IBaseLabelProvider<E> provider = getLabelProvider();
if (provider instanceof ITreePathLabelProvider) {
- ITreePathLabelProvider pprov = (ITreePathLabelProvider) provider;
+ ITreePathLabelProvider<E> pprov = (ITreePathLabelProvider<E>) provider;
buildLabel(updateLabel, path, pprov);
return;
}
element = path.getLastSegment();
} else {
- element = elementOrPath;
+ element = castObjectToElement(elementOrPath);
}
super.buildLabel(updateLabel, element);
}
@@ -3185,18 +3288,21 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* @since 3.3
*/
final protected boolean internalIsInputOrEmptyPath(final Object elementOrTreePath) {
- if (elementOrTreePath.equals(getRoot()))
+ if (elementOrTreePath.equals(getRoot())) //elementOrTreePath is input
return true;
- if (!(elementOrTreePath instanceof TreePath))
+ if (!(elementOrTreePath instanceof TreePath)) //elementOrTreePath is element
return false;
- return ((TreePath) elementOrTreePath).getSegmentCount() == 0;
+ //elementOrTreePath is TreePath
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) elementOrTreePath;
+ return treePath.getSegmentCount() == 0;
}
/*
* Subclasses should implement
*/
@Override
- protected ViewerRow getViewerRowFromItem(Widget item) {
+ protected ViewerRow<E> getViewerRowFromItem(Widget item) {
return null;
}
@@ -3207,10 +3313,10 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
* Setting this value to <code>true</code> will affect performance of the tree
* viewer.
* </p><p>
- * To improve performance, by default the tree viewer does not consult filters when
+ * To improve performance, by default the tree viewer does not consult filters when
* determining if a tree node could be expanded.
* </p>
- * @param checkFilters <code>true</code> to instruct tree viewer to consult filters
+ * @param checkFilters <code>true</code> to instruct tree viewer to consult filters
* @see #isExpandable(Object)
* @since 3.8
*/
@@ -3221,4 +3327,15 @@ public abstract class AbstractTreeViewer extends ColumnViewer {
}
}
+ private E castObjectToElement(Object object){
+ @SuppressWarnings("unchecked")
+ E element = (E) object;
+ return element;
+ }
+
+ private TreePath<E> castObjectToTreePath(Object object){
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) object;
+ return treePath;
+ }
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java
index 68e97ec..9ec0bfd 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation; bug 153993
* fix in bug 163317, 151295, 167323, 167858, 184346, 187826, 201905
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -735,7 +736,7 @@ public abstract class ColumnViewer<E,I> extends StructuredViewer<E,I> {
}
@Override
- protected E[] getRawChildren(I parent) {
+ protected E[] getRawChildren(Object parent) {
boolean oldBusy = isBusy();
setBusy(true);
try {
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyContentProvider.java
index 821ba3e..7ae961a 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyContentProvider.java
@@ -7,7 +7,11 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+<<<<<<< HEAD
* Hendrik Still <hendrik.still@gammas.de> - bug 415573
+=======
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
+>>>>>>> 6d6b20c... Bug 413973 - [Viewers] Add generics to the TreeViewer
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -22,6 +26,10 @@ package org.eclipse.jface.viewers;
* require a call to <code>#setItemCount</code> on the
* viewer that uses it.
* @param <I> Type of the input for the view
+<<<<<<< HEAD
+=======
+ *
+>>>>>>> 6d6b20c... Bug 413973 - [Viewers] Add generics to the TreeViewer
*/
public interface ILazyContentProvider<I> extends IContentProvider<I> {
/**
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreeContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreeContentProvider.java
index 21cb79b..ffcf6e0 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreeContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreeContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* John Cortell, Freescale - bug 289409
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -15,10 +16,12 @@ package org.eclipse.jface.viewers;
* The ILazyTreeContentProvider is the content provider for tree viewers created
* using the SWT.VIRTUAL flag that only wish to return their contents as they
* are queried.
- *
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
+ *
* @since 3.2
*/
-public interface ILazyTreeContentProvider extends IContentProvider {
+public interface ILazyTreeContentProvider<E,I> extends IContentProvider<I> {
/**
* Called when a previously-blank item becomes visible in the TreeViewer. If
* the content provider knows the child element for the given parent at this
@@ -31,21 +34,21 @@ public interface ILazyTreeContentProvider extends IContentProvider {
* provider doesn't know the child count at this point, and can more
* efficiently determine if the element has <i>any</i> children, then it can
* instead call {@link TreeViewer#setHasChildren(Object, boolean)}.
- *
+ *
* <p>
* <strong>NOTE</strong> #updateElement(int index) can be used to determine
* selection values. If TableViewer#replace(Object, int) is not called
* before returning from this method, selections may have missing or stale
* elements. In this situation it is suggested that the selection is asked
* for again after replace() has been called.
- *
+ *
* @param parent
* The parent of the element, or the viewer's input if the
* element to update is a root element
* @param index
* The index of the element to update in the tree
*/
- public void updateElement(Object parent, int index);
+ public void updateElement(E parent, int index);
/**
* Called when the TreeViewer needs an up-to-date child count for the given
@@ -55,18 +58,18 @@ public interface ILazyTreeContentProvider extends IContentProvider {
* {@link TreeViewer#setChildCount(Object, int)}. If the given current
* child count is already correct, no action has to be taken by this content
* provider.
- *
+ *
* @param element
* The element for which an up-to-date child count is needed, or
- * the viewer's input if the number of root elements is requested
- * @param currentChildCount
+ * the viewer's input if the number of root elements is requested
+ * @param currentChildCount
* The current child count for the element that needs updating
*/
- public void updateChildCount(Object element, int currentChildCount);
-
+ public void updateChildCount(E element, int currentChildCount);
+
/**
- * Returns the parent for the given element, or <code>null</code>
- * indicating that the parent can't be computed.
+ * Returns the parent for the given element, or <code>null</code>
+ * indicating that the parent can't be computed.
* In this case the tree-structured viewer can't expand
* a given node correctly if requested.
*
@@ -74,5 +77,5 @@ public interface ILazyTreeContentProvider extends IContentProvider {
* @return the parent element, or <code>null</code> if it
* has none or if the parent cannot be computed
*/
- public Object getParent(Object element);
+ public E getParent(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreePathContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreePathContentProvider.java
index 20965a7..ba7c3db 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreePathContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILazyTreePathContentProvider.java
@@ -15,10 +15,12 @@ package org.eclipse.jface.viewers;
* The ILazyTreePathContentProvider is a tree path-based content provider for
* tree viewers created using the SWT.VIRTUAL flag that only wish to return
* their contents as they are queried.
- *
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
*/
-public interface ILazyTreePathContentProvider extends IContentProvider {
+public interface ILazyTreePathContentProvider<E,I> extends IContentProvider<I> {
/**
* Called when a previously-blank item becomes visible in the TreeViewer. If
* the content provider knows the child element for the given parent at this
@@ -32,20 +34,20 @@ public interface ILazyTreePathContentProvider extends IContentProvider {
* efficiently determine if the element has <i>any</i> children, then it can
* instead call {@link TreeViewer#setHasChildren(Object, boolean)}.
* <p>
- *
+ *
* <strong>NOTE</strong> #updateElement(int index) can be used to determine
* selection values. If TableViewer#replace(Object, int) is not called
* before returning from this method, selections may have missing or stale
* elements. In this situation it is suggested that the selection is asked
* for again after replace() has been called.
- *
+ *
* @param parentPath
* The tree path of parent of the element, or if the element to
* update is a root element, an empty tree path
* @param index
* The index of the element to update in the tree
*/
- public void updateElement(TreePath parentPath, int index);
+ public void updateElement(TreePath<E> parentPath, int index);
/**
* Called when the TreeViewer needs an up-to-date child count for the given
@@ -55,15 +57,15 @@ public interface ILazyTreePathContentProvider extends IContentProvider {
* {@link TreeViewer#setChildCount(Object, int)}. If the given current
* child count is already correct, no action has to be taken by this content
* provider.
- *
+ *
* @param treePath
* The tree path for which an up-to-date child count is needed, or
- * if the number of root elements is requested, the empty tree path
- * @param currentChildCount
+ * if the number of root elements is requested, the empty tree path
+ * @param currentChildCount
* The current child count for the element that needs updating
*/
- public void updateChildCount(TreePath treePath, int currentChildCount);
-
+ public void updateChildCount(TreePath<E> treePath, int currentChildCount);
+
/**
* Called when the TreeViewer needs up-to-date information whether the node
* at the given tree path can be expanded. If the content provider knows the
@@ -71,18 +73,18 @@ public interface ILazyTreePathContentProvider extends IContentProvider {
* {@link TreeViewer#setHasChildren(Object, boolean)}. The content provider
* may also choose to call {@link TreeViewer#setChildCount(Object, int)}
* instead if it knows the number of children.
- *
+ *
* <p>
* Intended as an optimization for when the viewer does not need the actual
* children. Clients may be able to implement this more efficiently than
* <code>updateChildCount</code>.
* </p>
- *
+ *
* @param path
* The tree path for which up-to-date information about children
* is needed
*/
- public void updateHasChildren(TreePath path);
+ public void updateHasChildren(TreePath<E> path);
/**
* Return the possible parent paths for the given element. An empty array
@@ -90,10 +92,10 @@ public interface ILazyTreePathContentProvider extends IContentProvider {
* tree-structured viewer can't expand a given node correctly if requested.
* If the element is a potential child of the input of the viewer, an empty
* tree path should be an entry in the returned array.
- *
+ *
* @param element
* the element
* @return the possible parent paths for the given element
*/
- public TreePath[] getParents(Object element);
+ public TreePath<E>[] getParents(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeContentProvider.java
index ae66fe5..11f558b 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -14,9 +15,11 @@ package org.eclipse.jface.viewers;
* An interface to content providers for tree-structure-oriented
* viewers.
*
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
* @see AbstractTreeViewer
*/
-public interface ITreeContentProvider extends IStructuredContentProvider {
+public interface ITreeContentProvider<E,I> extends IStructuredContentProvider<E,I> {
/**
* {@inheritDoc}
@@ -27,13 +30,13 @@ public interface ITreeContentProvider extends IStructuredContentProvider {
* <a href="https://bugs.eclipse.org/9262">bug 9262</a>).
* </p>
*/
- public Object[] getElements(Object inputElement);
+ public E[] getElements(I inputElement);
/**
* Returns the child elements of the given parent element.
* <p>
- * The difference between this method and <code>IStructuredContentProvider.getElements</code>
- * is that <code>getElements</code> is called to obtain the
+ * The difference between this method and <code>IStructuredContentProvider.getElements</code>
+ * is that <code>getElements</code> is called to obtain the
* tree viewer's root elements, whereas <code>getChildren</code> is used
* to obtain the children of a given parent element in the tree (including a root).
* </p>
@@ -42,11 +45,11 @@ public interface ITreeContentProvider extends IStructuredContentProvider {
* @param parentElement the parent element
* @return an array of child elements
*/
- public Object[] getChildren(Object parentElement);
+ public E[] getChildren(E parentElement);
/**
- * Returns the parent for the given element, or <code>null</code>
- * indicating that the parent can't be computed.
+ * Returns the parent for the given element, or <code>null</code>
+ * indicating that the parent can't be computed.
* In this case the tree-structured viewer can't expand
* a given node correctly if requested.
*
@@ -54,7 +57,7 @@ public interface ITreeContentProvider extends IStructuredContentProvider {
* @return the parent element, or <code>null</code> if it
* has none or if the parent cannot be computed
*/
- public Object getParent(Object element);
+ public E getParent(E element);
/**
* Returns whether the given element has children.
@@ -68,5 +71,5 @@ public interface ITreeContentProvider extends IStructuredContentProvider {
* @return <code>true</code> if the given element has children,
* and <code>false</code> if it has no children
*/
- public boolean hasChildren(Object element);
+ public boolean hasChildren(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathContentProvider.java
index 6d13f97..4a3765c 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
******************************************************************************/
package org.eclipse.jface.viewers;
@@ -14,11 +15,13 @@ package org.eclipse.jface.viewers;
/**
* An interface to content providers for tree-structure-oriented viewers that
* provides content based on the path of elements in the tree viewer.
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @see AbstractTreeViewer
* @since 3.2
*/
-public interface ITreePathContentProvider extends IStructuredContentProvider {
+public interface ITreePathContentProvider<E,I> extends IStructuredContentProvider<E,I> {
/**
* {@inheritDoc}
@@ -29,7 +32,7 @@ public interface ITreePathContentProvider extends IStructuredContentProvider {
* <a href="https://bugs.eclipse.org/9262">bug 9262</a>).
* </p>
*/
- public Object[] getElements(Object inputElement);
+ public E[] getElements(I inputElement);
/**
* Returns the child elements of the last element in the given path.
@@ -41,12 +44,12 @@ public interface ITreePathContentProvider extends IStructuredContentProvider {
* {@link IStructuredContentProvider#getElements(Object)}.
* </p>
* The result is not modified by the viewer.
- *
+ *
* @param parentPath
* the path of the parent element
* @return an array of child elements
*/
- public Object[] getChildren(TreePath parentPath);
+ public E[] getChildren(TreePath<E> parentPath);
/**
* Returns whether the last element of the given path has children.
@@ -55,23 +58,23 @@ public interface ITreePathContentProvider extends IStructuredContentProvider {
* children. Clients may be able to implement this more efficiently than
* <code>getChildren</code>.
* </p>
- *
+ *
* @param path
* the path
* @return <code>true</code> if the lat element of the path has children,
* and <code>false</code> if it has no children
*/
- public boolean hasChildren(TreePath path);
+ public boolean hasChildren(TreePath<E> path);
/**
* Return the possible parent paths for the given element. An empty array
- * can be returned if the paths cannot be computed. If the element is
+ * can be returned if the paths cannot be computed. If the element is
* a potential child of the input of the viewer, an empty tree path
* should be an entry in the returned array.
- *
+ *
* @param element
* the element
* @return the possible parent paths for the given element
*/
- public TreePath[] getParents(Object element);
+ public TreePath<E>[] getParents(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathLabelProvider.java
index ac2abd1..a3ba6fa 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreePathLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 IBM Corporation and others.
* 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
@@ -7,22 +7,24 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
******************************************************************************/
package org.eclipse.jface.viewers;
/**
- * An extension to {@link ILabelProvider} that is given the
+ * An extension to {@link ILabelProvider} that is given the
* path of the element being decorated, when it is available.
* @since 3.2
+ * @param <E> Type of an element of the model
*/
-public interface ITreePathLabelProvider extends IBaseLabelProvider {
-
+public interface ITreePathLabelProvider<E> extends IBaseLabelProvider<E> {
+
/**
* Updates the label for the given element.
- *
+ *
* @param label the label to update
* @param elementPath the path of the element being decorated
*/
- public void updateLabel(ViewerLabel label, TreePath elementPath);
+ public void updateLabel(ViewerLabel label, TreePath<E> elementPath);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeViewerListener.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeViewerListener.java
index eadf9cf..804f79e 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeViewerListener.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ITreeViewerListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* 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
@@ -7,25 +7,28 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
-/**
+/**
* A listener which is notified when a tree viewer expands or collapses
* a node.
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
*/
-public interface ITreeViewerListener {
+public interface ITreeViewerListener<E,I> {
/**
* Notifies that a node in the tree has been collapsed.
*
* @param event event object describing details
*/
- public void treeCollapsed(TreeExpansionEvent event);
+ public void treeCollapsed(TreeExpansionEvent<E,I> event);
/**
* Notifies that a node in the tree has been expanded.
*
* @param event event object describing details
*/
- public void treeExpanded(TreeExpansionEvent event);
+ public void treeExpanded(TreeExpansionEvent<E,I> event);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java
index 90cf1bd..8385112 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Schindl - bug 151205
- * Hendrik Still <hendrik.still@gammas.de> - bug 412273
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273, bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -55,7 +55,7 @@ import org.eclipse.swt.widgets.Widget;
* </p>
* @param <E> Type of an single element of the model
* @param <I> Type of the input
- *
+ *
* @see ViewerFilter
* @see ViewerComparator
*/
@@ -66,7 +66,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* <code>Object</code>, value type: <code>Widget</code>, or <code>Widget[]</code>).
* <code>null</code> means that the element map is disabled.
*/
- private CustomHashtable elementMap;
+ private CustomHashtable<Object,Object> elementMap;
/**
* The comparer to use for comparing elements, or <code>null</code> to use
@@ -89,22 +89,22 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Indicates whether the viewer should attempt to preserve the selection
* across update operations.
- *
+ *
* @see #setSelection(ISelection, boolean)
*/
private boolean preserveSelection = true;
/**
* Indicates whether a selection change is in progress on this viewer.
- *
+ *
* @see #setSelection(ISelection, boolean)
*/
private boolean inChange;
-
+
/**
* Used while a selection change is in progress on this viewer to indicates
* whether the selection should be restored.
- *
+ *
* @see #setSelection(ISelection, boolean)
*/
private boolean restoreSelection;
@@ -112,7 +112,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* List of double-click state listeners (element type:
* <code>IDoubleClickListener</code>).
- *
+ *
* @see #fireDoubleClick
*/
private ListenerList doubleClickListeners = new ListenerList();
@@ -120,7 +120,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* List of open listeners (element type:
* <code>ISelectionActivateListener</code>).
- *
+ *
* @see #fireOpen
*/
private ListenerList openListeners = new ListenerList();
@@ -128,27 +128,27 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* List of post selection listeners (element type:
* <code>ISelectionActivateListener</code>).
- *
+ *
* @see #firePostSelectionChanged
*/
private ListenerList postSelectionChangedListeners = new ListenerList();
/**
* The colorAndFontCollector is an object used by viewers that
- * support the IColorProvider, the IFontProvider and/or the
+ * support the IColorProvider, the IFontProvider and/or the
* IViewerLabelProvider for color and font updates.
* Initialize it to have no color or font providing
* initially.
* @since 3.1
*/
private ColorAndFontCollector colorAndFontCollector = new ColorAndFontCollector();
-
-
- /**
+
+
+ /**
* Calls when associate() and disassociate() are called
*/
private StructuredViewerInternals.AssociateListener associateListener;
-
+
/**
* Empty array of widgets.
*/
@@ -165,10 +165,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
*/
protected class ColorAndFontCollectorWithProviders extends ColorAndFontCollector{
- IColorProvider colorProvider;
+ IColorProvider<E> colorProvider;
+
+ IFontProvider<E> fontProvider;
- IFontProvider fontProvider;
-
/**
* Create a new instance of the receiver using the supplied
* label provider. If it is an IColorProvider or IFontProvider
@@ -180,39 +180,43 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
public ColorAndFontCollectorWithProviders(IBaseLabelProvider<E> provider) {
super();
if (provider instanceof IColorProvider) {
- colorProvider = (IColorProvider) provider;
+ @SuppressWarnings("unchecked")
+ IColorProvider<E> setColorProvider = (IColorProvider<E>) provider;
+ colorProvider = setColorProvider;
}
if (provider instanceof IFontProvider) {
- fontProvider = (IFontProvider) provider;
+ @SuppressWarnings("unchecked")
+ IFontProvider<E> setFontProvider = (IFontProvider<E>) provider;
+ fontProvider = setFontProvider;
}
}
-
-
+
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#setFontsAndColors(java.lang.Object)
*/
@Override
- public void setFontsAndColors(Object element){
-
+ public void setFontsAndColors(E element){
+
if(fontProvider != null){
if(font == null) {
font = fontProvider.getFont(element);
- }
+ }
}
-
+
if(colorProvider == null) {
return;
- }
+ }
//Set the colors if they are not set yet
if(background == null) {
background = colorProvider.getBackground(element);
}
-
+
if(foreground == null) {
foreground = colorProvider.getForeground(element);
- }
+ }
}
-
+
/**
* Apply the fonts and colors to the control if
* required.
@@ -220,14 +224,14 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
*/
@Override
public void applyFontsAndColors(TableItem control) {
-
+
if(colorProvider == null){
if(usedDecorators){
//If there is no provider only apply set values
if(background != null) {
control.setBackground(background);
}
-
+
if(foreground != null) {
control.setForeground(foreground);
}
@@ -238,7 +242,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
control.setBackground(background);
control.setForeground(foreground);
}
-
+
if(fontProvider == null){
if(usedDecorators && font != null) {
control.setFont(font);
@@ -246,25 +250,25 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
} else {
control.setFont(font);
}
-
+
clear();
}
-
-
+
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#applyFontsAndColors(org.eclipse.swt.widgets.TreeItem)
*/
@Override
public void applyFontsAndColors(TreeItem control) {
-
+
if(colorProvider == null){
if(usedDecorators){
//If there is no provider only apply set values
if(background != null) {
control.setBackground(background);
}
-
+
if(foreground != null) {
control.setForeground(foreground);
}
@@ -275,7 +279,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
control.setBackground(background);
control.setForeground(foreground);
}
-
+
if(fontProvider == null){
if(usedDecorators && font != null) {
control.setFont(font);
@@ -283,25 +287,25 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
} else {
control.setFont(font);
}
-
+
clear();
}
-
-
+
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#applyFontsAndColors(org.eclipse.swt.custom.TableTreeItem)
*/
@Override
@Deprecated
public void applyFontsAndColors(TableTreeItem control) {
-
+
if(colorProvider == null){
if(usedDecorators){
//If there is no provider only apply set values
if(background != null) {
control.setBackground(background);
}
-
+
if(foreground != null) {
control.setForeground(foreground);
}
@@ -312,7 +316,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
control.setBackground(background);
control.setForeground(foreground);
}
-
+
if(fontProvider == null){
if(usedDecorators && font != null) {
control.setFont(font);
@@ -320,13 +324,13 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
} else {
control.setFont(font);
}
-
+
clear();
}
-
-
+
+
}
-
+
/**
* The ColorAndFontCollector collects fonts and colors without a
* a color or font provider.
@@ -344,12 +348,12 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Create a new instance of the receiver with
- * no color and font provider.
+ * no color and font provider.
*/
public ColorAndFontCollector(){
super();
}
-
+
/**
* Clear all of the results.
@@ -361,13 +365,13 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
usedDecorators = false;
}
-
+
/**
* Set the initial fonts and colors for the element from the
* content providers.
* @param element Object
*/
- public void setFontsAndColors(Object element){
+ public void setFontsAndColors(E element){
//Do nothing if there are no providers
}
@@ -384,24 +388,24 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* @param control
*/
public void applyFontsAndColors(TableItem control) {
-
+
if(usedDecorators){
//If there is no provider only apply set values
if(background != null) {
control.setBackground(background);
}
-
+
if(foreground != null) {
control.setForeground(foreground);
}
-
+
if(font != null) {
control.setFont(font);
}
}
clear();
}
-
+
/**
* Apply the fonts and colors to the control if
* required.
@@ -413,18 +417,18 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
if(background != null) {
control.setBackground(background);
}
-
+
if(foreground != null) {
control.setForeground(foreground);
}
-
+
if(font != null) {
control.setFont(font);
}
}
clear();
}
-
+
/**
* Apply the fonts and colors to the control if
* required.
@@ -437,28 +441,28 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
if(background != null) {
control.setBackground(background);
}
-
+
if(foreground != null) {
control.setForeground(foreground);
}
-
+
if(font != null) {
control.setFont(font);
}
}
clear();
}
-
+
/**
* Set the background color.
- * @param background
+ * @param background
*/
public void setBackground(Color background) {
this.background = background;
}
/**
* Set the font.
- * @param font
+ * @param font
*/
public void setFont(Font font) {
this.font = font;
@@ -470,8 +474,8 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
public void setForeground(Color foreground) {
this.foreground = foreground;
}
-
-
+
+
}
/**
@@ -494,7 +498,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
doUpdateItem(widget, element, fullMap);
}
}
-
+
/**
* Creates a structured element viewer. The viewer has no input, no content
* provider, a default label provider, no sorter, and no filters.
@@ -506,7 +510,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Adds a listener for double-clicks in this viewer. Has no effect if an
* identical listener is already registered.
- *
+ *
* @param listener
* a double-click listener
*/
@@ -517,7 +521,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Adds a listener for selection-open in this viewer. Has no effect if an
* identical listener is already registered.
- *
+ *
* @param listener
* an open listener
*/
@@ -535,7 +539,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Adds support for dragging items out of this viewer via a user
* drag-and-drop operation.
- *
+ *
* @param operations
* a bitwise OR of the supported drag and drop operation types (
* <code>DROP_COPY</code>,<code>DROP_LINK</code>, and
@@ -558,7 +562,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Adds support for dropping items into this viewer via a user drag-and-drop
* operation.
- *
+ *
* @param operations
* a bitwise OR of the supported drag and drop operation types (
* <code>DROP_COPY</code>,<code>DROP_LINK</code>, and
@@ -582,7 +586,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Adds the given filter to this viewer, and triggers refiltering and
* resorting of the elements. If you want to add more than one filter
* consider using {@link StructuredViewer#setFilters(ViewerFilter[])}.
- *
+ *
* @param filter
* a viewer filter
* @see StructuredViewer#setFilters(ViewerFilter[])
@@ -598,7 +602,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Asserts that the given array of elements is itself non- <code>null</code>
* and contains no <code>null</code> elements.
- *
+ *
* @param elements
* the array to check
*/
@@ -607,10 +611,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
for (int i = 0, n = elements.length; i < n; ++i) {
Assert.isNotNull(elements[i]);
}
-
+
if (InternalPolicy.DEBUG_LOG_EQUAL_VIEWER_ELEMENTS
&& elements.length > 1) {
- CustomHashtable elementSet = newHashtable(elements.length * 2);
+ CustomHashtable<Object,Object> elementSet = newHashtable(elements.length * 2);
for (int i = 0; i < elements.length; i++) {
Object element = elements[i];
Object old = elementSet.put(element, element);
@@ -630,13 +634,14 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Associates the given element with the given widget. Sets the given item's
* data to be the element, and maps the element to the item in the element
* map (if enabled).
- *
+ *
* @param element
* the element
* @param item
* the widget
*/
protected void associate(E element, Item item) {
+ @SuppressWarnings("unchecked")
E data = (E) item.getData();
if (data != element) {
if (data != null) {
@@ -654,18 +659,19 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
associateListener.associate(element, item);
}
-
+
/**
* Disassociates the given SWT item from its corresponding element. Sets the
* item's data to <code>null</code> and removes the element from the
* element map (if enabled).
- *
+ *
* @param item
* the widget
*/
protected void disassociate(Item item) {
if (associateListener != null)
associateListener.disassociate(item);
+ @SuppressWarnings("unchecked")
E element = (E) item.getData();
Assert.isNotNull(element);
//Clear the map before we clear the data
@@ -680,7 +686,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param element
* @return the corresponding widget, or <code>null</code> if none
*/
@@ -693,7 +699,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param element
* @return the corresponding widget, or <code>null</code> if none
*/
@@ -711,7 +717,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param item
* @param element element
* @param fullMap
@@ -724,7 +730,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Compares two elements for equality. Uses the element comparer if one has
* been set, otherwise uses the default <code>equals</code> method on the
* elements themselves.
- *
+ *
* @param elementA
* the first element
* @param elementB
@@ -734,14 +740,13 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
protected boolean equals(Object elementA, Object elementB) {
if (comparer == null) {
return elementA == null ? elementB == null : elementA.equals(elementB);
- } else {
- return elementA == null ? elementB == null : comparer.equals(elementA, elementB);
}
+ return elementA == null ? elementB == null : comparer.equals(elementA, elementB);
}
/**
* Returns the result of running the given elements through the filters.
- *
+ *
* @param elements
* the elements to filter
* @return only the elements which all filters accept
@@ -765,7 +770,9 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
associateListener.filteredOut(elements[i]);
}
}
- return (E[]) filtered.toArray();
+ @SuppressWarnings("unchecked")
+ E[] result = (E[]) filtered.toArray();
+ return result;
}
return elements;
}
@@ -780,7 +787,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* feature has been enabled. If the element map is disabled, the widget is
* found via <code>doFindInputItem</code>.
* </p>
- *
+ *
* @param element
* the element
* @return the corresponding widget, or <code>null</code> if none
@@ -808,11 +815,11 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* that this feature has been enabled. If the element map is disabled, the
* widget is found via <code>doFindItem</code>.
* </p>
- *
+ *
* @param element
* the element
* @return the corresponding widgets
- *
+ *
* @since 3.2
*/
protected final Widget[] findItems(E element) {
@@ -839,10 +846,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Notifies any double-click listeners that a double-click has been
* received. Only listeners registered at the time this method is called are
* notified.
- *
+ *
* @param event
* a double-click event
- *
+ *
* @see IDoubleClickListener#doubleClick
*/
protected void fireDoubleClick(final DoubleClickEvent event) {
@@ -860,10 +867,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Notifies any open event listeners that a open event has been received.
* Only listeners registered at the time this method is called are notified.
- *
+ *
* @param event
* a double-click event
- *
+ *
* @see IOpenListener#open(OpenEvent)
*/
protected void fireOpen(final OpenEvent event) {
@@ -882,10 +889,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Notifies any post selection listeners that a post selection event has
* been received. Only listeners registered at the time this method is
* called are notified.
- *
+ *
* @param event
* a selection changed event
- *
+ *
* @see #addPostSelectionChangedListener(ISelectionChangedListener)
*/
protected void firePostSelectionChanged(final SelectionChangedEvent event) {
@@ -905,7 +912,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* <code>null</code> if none has been set. If specified,
* the viewer uses this to compare and hash elements rather
* than the elements' own equals and hashCode methods.
- *
+ *
* @return the comparer to use for comparing elements or
* <code>null</code>
*/
@@ -917,12 +924,12 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Returns the filtered array of children of the given element. The
* resulting array must not be modified, as it may come directly from the
* model's internal state.
- *
+ *
* @param parent
* the parent element
* @return a filtered array of child elements
*/
- protected E[] getFilteredChildren(I parent) {
+ protected E[] getFilteredChildren(Object parent) {
E[] result = getRawChildren(parent);
if (filters != null) {
for (Iterator<ViewerFilter<E,I>> iter = filters.iterator(); iter.hasNext();) {
@@ -939,9 +946,9 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Notifies an AssociateListener of the elements that have been filtered out.
- *
- * @param rawResult
- * @param filteredResult
+ *
+ * @param rawResult
+ * @param filteredResult
*/
private void notifyFilteredOut(E[] rawResult, E[] filteredResult) {
int rawIndex = 0;
@@ -958,48 +965,48 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
associateListener.filteredOut(rawResult[rawIndex]);
}
}
-
-
+
+
/**
* Returns this viewer's filters.
- *
+ *
* @return an array of viewer filters
* @see StructuredViewer#setFilters(ViewerFilter[])
*/
- public ViewerFilter[] getFilters() {
+ public ViewerFilter<E,I>[] getFilters() {
if (filters == null) {
return new ViewerFilter[0];
}
- ViewerFilter[] result = new ViewerFilter[filters.size()];
- filters.toArray(result);
+ ViewerFilter<E,I>[] result = new ViewerFilter[filters.size()];
+ result = filters.toArray(result);
return result;
}
/**
* Returns the item at the given display-relative coordinates, or
- * <code>null</code> if there is no item at that location or
- * the underlying SWT-Control is not made up of {@link Item}
- * (e.g {@link ListViewer})
+ * <code>null</code> if there is no item at that location or
+ * the underlying SWT-Control is not made up of {@link Item}
+ * (e.g {@link ListViewer})
* <p>
* The default implementation of this method returns <code>null</code>.
* </p>
- *
+ *
* @param x
* horizontal coordinate
* @param y
* vertical coordinate
* @return the item, or <code>null</code> if there is no item at the given
* coordinates
- * @deprecated This method is deprecated in 3.3 in favor of {@link ColumnViewer#getItemAt(org.eclipse.swt.graphics.Point)}.
+ * @deprecated This method is deprecated in 3.3 in favor of {@link ColumnViewer#getItemAt(org.eclipse.swt.graphics.Point)}.
* Viewers who are not subclasses of {@link ColumnViewer} should consider using a
* widget relative implementation like {@link ColumnViewer#getItemAt(org.eclipse.swt.graphics.Point)}.
- *
+ *
*/
@Deprecated
protected Item getItem(int x, int y) {
return null;
}
-
+
/**
* Returns the children of the given parent without sorting and filtering
* them. The resulting array must not be modified, as it may come directly
@@ -1007,27 +1014,30 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* <p>
* Returns an empty array if the given parent is <code>null</code>.
* </p>
- *
+ *
* @param parent
* the parent element
* @return the child elements
*/
- protected E[] getRawChildren(I parent) {
+ protected E[] getRawChildren(Object parent) {
E[] result = null;
if (parent != null) {
+ @SuppressWarnings("unchecked")
IStructuredContentProvider<E,I> cp = (IStructuredContentProvider<E,I>) getContentProvider();
if (cp != null) {
- result = cp.getElements(parent);
+ @SuppressWarnings("unchecked")
+ I input = (I) parent;
+ result = cp.getElements(input);
assertElementsNotNull(result);
}
}
-
+
if(result == null){
@SuppressWarnings("unchecked")
E[] emptyResult = (E[]) new Object[0];
result = emptyResult;
}
-
+
return result;
}
@@ -1038,7 +1048,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* <code>getInput</code>. Override if the root element is different from
* the viewer's input element.
* </p>
- *
+ *
* @return the root element, or <code>null</code> if none
*/
protected I getRoot() {
@@ -1067,7 +1077,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Retrieves the selection, as a <code>List</code>, from the underlying
* widget.
- *
+ *
* @return the list of selected elements
*/
protected abstract List<E> getSelectionFromWidget();
@@ -1076,12 +1086,12 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Returns the sorted and filtered set of children of the given element. The
* resulting array must not be modified, as it may come directly from the
* model's internal state.
- *
+ *
* @param parent
* the parent element
* @return a sorted and filtered array of child elements
*/
- protected E[] getSortedChildren(I parent) {
+ protected E[] getSortedChildren(Object parent) {
E[] result = getFilteredChildren(parent);
if (sorter != null) {
// be sure we're not modifying the original array from the model
@@ -1093,14 +1103,14 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Returns this viewer's sorter, or <code>null</code> if it does not have
- * one. If this viewer has a comparator that was set via
- * <code>setComparator(ViewerComparator)</code> then this method will return
+ * one. If this viewer has a comparator that was set via
+ * <code>setComparator(ViewerComparator)</code> then this method will return
* <code>null</code> if the comparator is not an instance of ViewerSorter.
* <p>
* It is recommended to use <code>getComparator()</code> instead.
* </p>
- *
- * @return a viewer sorter, or <code>null</code> if none or if the comparator is
+ *
+ * @return a viewer sorter, or <code>null</code> if none or if the comparator is
* not an instance of ViewerSorter
*/
public ViewerSorter getSorter() {
@@ -1112,7 +1122,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Return this viewer's comparator used to sort elements.
* This method should be used instead of <code>getSorter()</code>.
- *
+ *
* @return a viewer comparator, or <code>null</code> if none
*
* @since 3.2
@@ -1120,20 +1130,20 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
public ViewerComparator<E,I> getComparator(){
return sorter;
}
-
+
/**
* Handles a double-click select event from the widget.
* <p>
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param event
* the SWT selection event
*/
protected void handleDoubleSelect(SelectionEvent event) {
// This method is reimplemented in AbstractTreeViewer to fix bug 108102.
-
+
// handle case where an earlier selection listener disposed the control.
Control control = getControl();
if (control != null && !control.isDisposed()) {
@@ -1159,7 +1169,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param event
* the SWT selection event
*/
@@ -1183,7 +1193,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* a different strategy for picking a new selection when the old selection
* becomes invalid.
* </p>
- *
+ *
* @param invalidSelection
* the selection before the viewer was updated
* @param newSelection
@@ -1205,6 +1215,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
*/
@Override
protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
+ @SuppressWarnings("unchecked")
E[] elements = (E[])event.getElements();
if (elements != null) {
update(elements, null);
@@ -1219,7 +1230,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param event
* the SWT selection event
*/
@@ -1237,7 +1248,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param e the SWT selection event
*/
protected void handlePostSelect(SelectionEvent e) {
@@ -1289,7 +1300,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Refreshes this viewer starting at the given element.
- *
+ *
* @param element
* the element
*/
@@ -1306,14 +1317,14 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* If this method is overridden to do the actual refresh, then
* <code>internalRefresh(Object element)</code> should simply call
* <code>internalRefresh(element, true)</code>.
- *
+ *
* @param element
* the element
* @param updateLabels
* <code>true</code> to update labels for existing elements,
* <code>false</code> to only update labels as needed, assuming
* that labels for existing elements are unchanged.
- *
+ *
* @since 2.0
*/
protected void internalRefresh(Object element, boolean updateLabels) {
@@ -1326,7 +1337,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param element
* the element
* @param item
@@ -1363,7 +1374,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param element
* the element
* @param property
@@ -1389,14 +1400,14 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Returns a new hashtable using the given capacity and this viewer's element comparer.
- *
+ *
* @param capacity the initial capacity of the hashtable
* @return a new hashtable
- *
+ *
* @since 3.0
*/
- CustomHashtable newHashtable(int capacity) {
- return new CustomHashtable(capacity, getComparer());
+ <K,V> CustomHashtable<K,V> newHashtable(int capacity) {
+ return new CustomHashtable<K,V>(capacity, getComparer());
}
/**
@@ -1415,10 +1426,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* is different from the old selection</li>
* </ul>
* </p>
- *
+ *
* @param updateCode
* the code to run
- *
+ *
* see #getPreserveSelection()
*/
protected void preservingSelection(Runnable updateCode) {
@@ -1441,7 +1452,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* take</li>
* </ul>
* </p>
- *
+ *
* @param updateCode
* the code to run
* @param reveal
@@ -1453,7 +1464,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
if (!preserveSelection) {
return;
}
-
+
ISelection oldSelection = null;
try {
// preserve selection
@@ -1478,7 +1489,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
}
}
}
-
+
/*
* Non-Javadoc. Method declared on Viewer.
*/
@@ -1500,12 +1511,12 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Note that the implementation may still obtain labels for existing
* elements even if <code>updateLabels</code> is false. The intent is
* simply to allow optimization where possible.
- *
+ *
* @param updateLabels
* <code>true</code> to update labels for existing elements,
* <code>false</code> to only update labels as needed, assuming
* that labels for existing elements are unchanged.
- *
+ *
* @since 2.0
*/
public void refresh(boolean updateLabels) {
@@ -1520,7 +1531,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* given element needs updating, it is more efficient to use the
* <code>update</code> methods.
* </p>
- *
+ *
* @param element
* the element
*/
@@ -1541,14 +1552,14 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* given element needs updating, it is more efficient to use the
* <code>update</code> methods.
* </p>
- *
+ *
* @param element
* the element
* @param updateLabels
* <code>true</code> to update labels for existing elements,
* <code>false</code> to only update labels as needed, assuming
* that labels for existing elements are unchanged.
- *
+ *
* @since 2.0
*/
public void refresh(final Object element, final boolean updateLabels) {
@@ -1560,7 +1571,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
}
/**
- *
+ *
* Refreshes the given item with the given element. Calls
* <code>doUpdateItem(..., false)</code>.
* <p>
@@ -1579,7 +1590,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Removes the given open listener from this viewer. Has no effect if an
* identical listener is not registered.
- *
+ *
* @param listener
* an open listener
*/
@@ -1597,7 +1608,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Removes the given double-click listener from this viewer. Has no effect
* if an identical listener is not registered.
- *
+ *
* @param listener
* a double-click listener
*/
@@ -1610,7 +1621,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* resorting of the elements if required. Has no effect if the identical
* filter is not registered. If you want to remove more than one filter
* consider using {@link StructuredViewer#setFilters(ViewerFilter[])}.
- *
+ *
* @param filter
* a viewer filter
* @see StructuredViewer#setFilters(ViewerFilter[])
@@ -1637,11 +1648,11 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
void setAssociateListener(StructuredViewerInternals.AssociateListener l) {
associateListener = l;
}
-
+
/**
* Sets the filters, replacing any previous filters, and triggers
* refiltering and resorting of the elements.
- *
+ *
* @param filters
* an array of viewer filters
* @since 3.3
@@ -1654,7 +1665,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
refresh();
}
}
-
+
/**
* Discards this viewer's filters and triggers refiltering and resorting of
* the elements.
@@ -1669,7 +1680,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Ensures that the given element is visible, scrolling the viewer if
* necessary. The selection is unchanged.
- *
+ *
* @param element
* the element to reveal
*/
@@ -1762,7 +1773,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Subclasses should override to set their selection based on the given list
* of elements.
* </p>
- *
+ *
* @param l
* list of selected elements
* or <code>null</code> if the selection is to be cleared
@@ -1780,7 +1791,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* <p>
* Subclasses do not typically override this method, but implement
* <code>setSelectionToWidget(List, boolean)</code> instead.
- *
+ *
* @param selection
* an IStructuredSelection of elements
* @param reveal
@@ -1789,7 +1800,9 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
*/
protected void setSelectionToWidget(ISelection selection, boolean reveal) {
if (selection instanceof IStructuredSelection) {
- setSelectionToWidget(((IStructuredSelection) selection).toList(), reveal);
+ @SuppressWarnings("unchecked")
+ List<E> selectedElements = ((IStructuredSelection) selection).toList();
+ setSelectionToWidget(selectedElements, reveal);
} else {
setSelectionToWidget((List<E>) null, reveal);
}
@@ -1797,14 +1810,15 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Sets this viewer's sorter and triggers refiltering and resorting of this
- * viewer's element. Passing <code>null</code> turns sorting off.
+ * viewer's element. Passing <code>null</code> turns sorting off.
* <p>
* It is recommended to use <code>setComparator()</code> instead.
* </p>
- *
+ *
* @param sorter
* a viewer sorter, or <code>null</code> if none
*/
+ @SuppressWarnings("unchecked")
public void setSorter(ViewerSorter sorter) {
if (this.sorter != sorter) {
this.sorter = sorter;
@@ -1813,16 +1827,16 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
}
/**
- * Sets this viewer's comparator to be used for sorting elements, and triggers refiltering and
+ * Sets this viewer's comparator to be used for sorting elements, and triggers refiltering and
* resorting of this viewer's element. <code>null</code> turns sorting off.
* To get the viewer's comparator, call <code>getComparator()</code>.
* <p>
- * IMPORTANT: This method was introduced in 3.2. If a reference to this viewer object
+ * IMPORTANT: This method was introduced in 3.2. If a reference to this viewer object
* is passed to clients who call <code>getSorter()<code>, null may be returned from
* from that method even though the viewer is sorting its elements using the
* viewer's comparator.
* </p>
- *
+ *
* @param comparator a viewer comparator, or <code>null</code> if none
*
* @since 3.2
@@ -1833,12 +1847,12 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
refresh();
}
}
-
+
/**
* Configures whether this structured viewer uses an internal hash table to
* speeds up the mapping between elements and SWT items. This must be called
* before the viewer is given an input (via <code>setInput</code>).
- *
+ *
* @param enable
* <code>true</code> to enable hash lookup, and
* <code>false</code> to disable it
@@ -1857,7 +1871,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Sets the comparer to use for comparing elements, or <code>null</code>
* to use the default <code>equals</code> and <code>hashCode</code>
* methods on the elements themselves.
- *
+ *
* @param comparer
* the comparer to use for comparing elements or
* <code>null</code>
@@ -1865,7 +1879,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
public void setComparer(IElementComparer comparer) {
this.comparer = comparer;
if (elementMap != null) {
- elementMap = new CustomHashtable(elementMap, comparer);
+ elementMap = new CustomHashtable<Object,Object>(elementMap, comparer);
}
}
@@ -1884,7 +1898,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* {@link CheckboxTreeViewer}, and {@link ComboViewer}, but no promises are
* made for other subclasses of StructuredViewer, or subclasses of the
* listed viewer classes.
- *
+ *
* @param preserve
* <code>true</code> if selection should be preserved,
* <code>false</code> otherwise
@@ -1898,7 +1912,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* Returns whether an attempt should be made to preserve selection across
* update operations. To be used by subclasses that override
* {@link #preservingSelection(Runnable)}.
- *
+ *
* @return <code>true</code> if selection should be preserved,
* <code>false</code> otherwise
*/
@@ -1924,7 +1938,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
public Widget[] testFindItems(E element) {
return findItems(element);
}
-
+
/**
* Removes all elements from the map.
* <p>
@@ -1946,7 +1960,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param element
* the element
*/
@@ -1964,7 +1978,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
- *
+ *
* @param element
* the element
* @param item the item to unmap
@@ -2009,7 +2023,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
// flag to indicate that a full refresh took place. See bug 102440.
private boolean refreshOccurred;
-
+
/**
* Updates the given elements' presentation when one or more of their
* properties change. Only the given elements are updated.
@@ -2043,7 +2057,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* whether or not they are filtered out. Note that resorting may not happen
* if <code>properties</code> is <code>null</code>.
* </p>
- *
+ *
* @param elements
* the elements
* @param properties
@@ -2098,7 +2112,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* whether or not the element is filtered out. Note that filtering may not
* happen if <code>properties</code> is <code>null</code>.
* </p>
- *
+ *
* @param element
* the element
* @param properties
@@ -2113,10 +2127,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
for (int i = 0; i < items.length; i++) {
internalUpdate(items[i], element, properties);
if (mayExitEarly && refreshOccurred) {
- // detected a change from refreshOccurred==false to refreshOccurred==true
+ // detected a change from refreshOccurred==false to refreshOccurred==true
return;
}
- }
+ }
}
/**
@@ -2125,10 +2139,10 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* <p>
* EXPERIMENTAL. Not to be used except by JDT.
* This method was added to support JDT's explorations
- * into grouping by working sets, which requires viewers to support multiple
+ * into grouping by working sets, which requires viewers to support multiple
* equal elements. See bug 76482 for more details. This support will
* likely be removed in Eclipse 3.3 in favor of proper support for
- * multiple equal elements (which was implemented for AbtractTreeViewer in 3.2).
+ * multiple equal elements (which was implemented for AbtractTreeViewer in 3.2).
* </p>
* @param widget
* the widget for the element
@@ -2182,7 +2196,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* This method is internal to the framework; subclassers should not call
* this method. Calls <code>doUpdateItem(widget, element, true)</code>.
* </p>
- *
+ *
* @param widget
* the widget
* @param element
@@ -2204,7 +2218,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* is generally not required; however, if overriding in a subclass,
* <code>super.updateSelection</code> must be invoked.
* </p>
- *
+ *
* @param selection
* the selection, or <code>null</code> if none
*/
@@ -2220,7 +2234,7 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
* The default implementation of this framework method checks whether the
* internal map has been initialized.
* </p>
- *
+ *
* @return <code>true</code> if the element map is enabled, and
* <code>false</code> if disabled
*/
@@ -2239,9 +2253,9 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
colorAndFontCollector = new ColorAndFontCollector();
}
super.setLabelProvider(labelProvider);
-
+
}
-
+
/**
* Build a label up for the element using the supplied label provider.
* @param updateLabel The ViewerLabel to collect the result in
@@ -2250,86 +2264,86 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
protected void buildLabel(ViewerLabel updateLabel, E element){
if (getLabelProvider() instanceof IViewerLabelProvider) {
- IViewerLabelProvider itemProvider = (IViewerLabelProvider) getLabelProvider();
+ IViewerLabelProvider<E> itemProvider = (IViewerLabelProvider<E>) getLabelProvider();
itemProvider.updateLabel(updateLabel, element);
-
+
colorAndFontCollector.setUsedDecorators();
-
+
if(updateLabel.hasNewBackground()) {
colorAndFontCollector.setBackground(updateLabel.getBackground());
}
-
+
if(updateLabel.hasNewForeground()) {
colorAndFontCollector.setForeground(updateLabel.getForeground());
}
-
+
if(updateLabel.hasNewFont()) {
colorAndFontCollector.setFont(updateLabel.getFont());
}
return;
- }
-
+ }
+
if(getLabelProvider() instanceof ILabelProvider){
ILabelProvider<E> labelProvider = (ILabelProvider<E>) getLabelProvider();
updateLabel.setText(labelProvider.getText(element));
updateLabel.setImage(labelProvider.getImage(element));
}
-
+
}
-
+
/**
* Build a label up for the element using the supplied label provider.
* @param updateLabel The ViewerLabel to collect the result in
* @param element The element being decorated.
* @param labelProvider ILabelProvider the labelProvider for the receiver.
*/
- void buildLabel(ViewerLabel updateLabel, E element,IViewerLabelProvider labelProvider){
+ void buildLabel(ViewerLabel updateLabel, E element,IViewerLabelProvider<E> labelProvider){
labelProvider.updateLabel(updateLabel, element);
-
+
colorAndFontCollector.setUsedDecorators();
-
+
if(updateLabel.hasNewBackground()) {
colorAndFontCollector.setBackground(updateLabel.getBackground());
}
-
+
if(updateLabel.hasNewForeground()) {
colorAndFontCollector.setForeground(updateLabel.getForeground());
}
-
+
if(updateLabel.hasNewFont()) {
colorAndFontCollector.setFont(updateLabel.getFont());
}
-
+
}
-
+
/**
* Build a label up for the element using the supplied label provider.
* @param updateLabel The ViewerLabel to collect the result in
* @param elementPath The path of the element being decorated.
* @param labelProvider ILabelProvider the labelProvider for the receiver.
*/
- void buildLabel(ViewerLabel updateLabel, TreePath elementPath,ITreePathLabelProvider labelProvider){
+ void buildLabel(ViewerLabel updateLabel, TreePath<E> elementPath,ITreePathLabelProvider<E> labelProvider){
labelProvider.updateLabel(updateLabel, elementPath);
-
+
colorAndFontCollector.setUsedDecorators();
-
+
if(updateLabel.hasNewBackground()) {
colorAndFontCollector.setBackground(updateLabel.getBackground());
}
-
+
if(updateLabel.hasNewForeground()) {
colorAndFontCollector.setForeground(updateLabel.getForeground());
}
-
+
if(updateLabel.hasNewFont()) {
colorAndFontCollector.setFont(updateLabel.getFont());
}
-
+
}
-
+
/**
* Build a label up for the element using the supplied label provider.
* @param updateLabel The ViewerLabel to collect the result in
@@ -2343,13 +2357,13 @@ public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implement
/**
* Get the ColorAndFontCollector for the receiver.
- * @return ColorAndFontCollector
+ * @return ColorAndFontCollector
* @since 3.1
*/
protected ColorAndFontCollector getColorAndFontCollector() {
return colorAndFontCollector;
}
-
+
@Override
protected void handleDispose(DisposeEvent event) {
super.handleDispose(event);
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java
index 303cceb..15425bb 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java
@@ -13,6 +13,8 @@
package org.eclipse.jface.viewers;
+import java.lang.reflect.Array;
+
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
@@ -202,8 +204,10 @@ public class TableViewerRow<E> extends ViewerRow<E> {
}
@Override
- public TreePath getTreePath() {
- return new TreePath(new Object[] {item.getData()});
+ public TreePath<E> getTreePath() {
+ @SuppressWarnings("unchecked")
+ E[] segments = (E[]) Array.newInstance(item.getData().getClass(), 1);
+ return new TreePath<E>(segments);
}
@Override
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java
index fa6c2eb..e6dfc91 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java
@@ -8,33 +8,36 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
/**
* TreeViewerLabelProvider is the ViewerLabelProvider that handles TreePaths.
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
- *
+ *
*/
-public class TreeColumnViewerLabelProvider extends
- TableColumnViewerLabelProvider {
- private ITreePathLabelProvider treePathProvider = new ITreePathLabelProvider() {
+public class TreeColumnViewerLabelProvider<E,I> extends
+ TableColumnViewerLabelProvider<E,I> {
+ private ITreePathLabelProvider<E> treePathProvider = new ITreePathLabelProvider<E>() {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreePathLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel,
* org.eclipse.jface.viewers.TreePath)
*/
- public void updateLabel(ViewerLabel label, TreePath elementPath) {
+ public void updateLabel(ViewerLabel label, TreePath<E> elementPath) {
// Do nothing by default
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
*/
public void dispose() {
@@ -44,7 +47,7 @@ public class TreeColumnViewerLabelProvider extends
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void addListener(ILabelProviderListener listener) {
@@ -54,18 +57,18 @@ public class TreeColumnViewerLabelProvider extends
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void removeListener(ILabelProviderListener listener) {
// Do nothing by default
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
*/
- public boolean isLabelProperty(Object element, String property) {
+ public boolean isLabelProperty(E element, String property) {
return false;
}
@@ -73,42 +76,42 @@ public class TreeColumnViewerLabelProvider extends
/**
* Create a new instance of the receiver with the supplied labelProvider.
- *
+ *
* @param labelProvider
*/
- public TreeColumnViewerLabelProvider(IBaseLabelProvider labelProvider) {
+ public TreeColumnViewerLabelProvider(IBaseLabelProvider<E> labelProvider) {
super(labelProvider);
}
/**
* Update the label for the element with TreePath.
- *
+ *
* @param label
* @param elementPath
*/
- public void updateLabel(ViewerLabel label, TreePath elementPath) {
+ public void updateLabel(ViewerLabel label, TreePath<E> elementPath) {
treePathProvider.updateLabel(label, elementPath);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ViewerLabelProvider#setProviders(java.lang.Object)
*/
@Override
public void setProviders(Object provider) {
super.setProviders(provider);
if (provider instanceof ITreePathLabelProvider)
- treePathProvider = (ITreePathLabelProvider) provider;
+ treePathProvider = (ITreePathLabelProvider<E>) provider;
}
/**
* Return the ITreePathLabelProvider for the receiver.
- *
+ *
* @return Returns the treePathProvider.
*/
- public ITreePathLabelProvider getTreePathProvider() {
+ public ITreePathLabelProvider<E> getTreePathProvider() {
return treePathProvider;
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeExpansionEvent.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeExpansionEvent.java
index 0726ec6..73cb97e 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeExpansionEvent.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeExpansionEvent.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -15,21 +16,23 @@ import java.util.EventObject;
/**
* Event object describing a tree node being expanded
* or collapsed. The source of these events is the tree viewer.
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
*
* @see ITreeViewerListener
*/
-public class TreeExpansionEvent extends EventObject {
+public class TreeExpansionEvent<E,I> extends EventObject {
/**
* Generated serial version UID for this class.
* @since 3.1
*/
private static final long serialVersionUID = 3618414930227835185L;
-
+
/**
* The element that was expanded or collapsed.
*/
- private Object element;
+ private E element;
/**
* Creates a new event for the given source and element.
@@ -37,7 +40,7 @@ public class TreeExpansionEvent extends EventObject {
* @param source the tree viewer
* @param element the element
*/
- public TreeExpansionEvent(AbstractTreeViewer source, Object element) {
+ public TreeExpansionEvent(AbstractTreeViewer<E,I> source, E element) {
super(source);
this.element = element;
}
@@ -47,7 +50,7 @@ public class TreeExpansionEvent extends EventObject {
*
* @return the element
*/
- public Object getElement() {
+ public E getElement() {
return element;
}
@@ -56,7 +59,9 @@ public class TreeExpansionEvent extends EventObject {
*
* @return the originating tree viewer
*/
- public AbstractTreeViewer getTreeViewer() {
- return (AbstractTreeViewer) source;
+ public AbstractTreeViewer<E,I> getTreeViewer() {
+ @SuppressWarnings("unchecked")
+ AbstractTreeViewer<E,I> abstractTreeViewer = (AbstractTreeViewer<E,I>) source;
+ return abstractTreeViewer;
}
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNode.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNode.java
index dbff7f8..b2ca329 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNode.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNode.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -22,10 +23,11 @@ import org.eclipse.jface.util.Util;
* {@link org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object)},
* {@link org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object)} and
* {@link org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object)}
- *
+ * @param <E> Type of an element of the model
+ *
* @since 3.2
*/
-public class TreeNode {
+public class TreeNode<E> {
/**
* The array of child tree nodes for this tree node. If there are no
@@ -33,33 +35,35 @@ public class TreeNode {
* <code>null</code>. There should be no <code>null</code> children in
* the array.
*/
- private TreeNode[] children;
+ private TreeNode<E>[] children;
/**
* The parent tree node for this tree node. This value may be
* <code>null</code> if there is no parent.
*/
- private TreeNode parent;
+ private TreeNode<E> parent;
/**
* The value contained in this node. This value may be anything.
*/
- protected Object value;
+ protected E value;
/**
* Constructs a new instance of <code>TreeNode</code>.
- *
+ *
* @param value
* The value held by this node; may be anything.
*/
- public TreeNode(final Object value) {
+ public TreeNode(final E value) {
this.value = value;
}
-
+
@Override
public boolean equals(final Object object) {
if (object instanceof TreeNode) {
- return Util.equals(this.value, ((TreeNode) object).value);
+ @SuppressWarnings("unchecked")
+ TreeNode<E> treeNode = (TreeNode<E>) object;
+ return Util.equals(this.value, treeNode.value);
}
return false;
@@ -68,11 +72,11 @@ public class TreeNode {
/**
* Returns the child nodes. Empty arrays are converted to <code>null</code>
* before being returned.
- *
+ *
* @return The child nodes; may be <code>null</code>, but never empty.
* There should be no <code>null</code> children in the array.
*/
- public TreeNode[] getChildren() {
+ public TreeNode<E>[] getChildren() {
if (children != null && children.length == 0) {
return null;
}
@@ -81,17 +85,17 @@ public class TreeNode {
/**
* Returns the parent node.
- *
+ *
* @return The parent node; may be <code>null</code> if there are no
* parent nodes.
*/
- public TreeNode getParent() {
+ public TreeNode<E> getParent() {
return parent;
}
/**
* Returns the value held by this node.
- *
+ *
* @return The value; may be anything.
*/
public Object getValue() {
@@ -100,7 +104,7 @@ public class TreeNode {
/**
* Returns whether the tree has any children.
- *
+ *
* @return <code>true</code> if its array of children is not
* <code>null</code> and is non-empty; <code>false</code>
* otherwise.
@@ -108,7 +112,7 @@ public class TreeNode {
public boolean hasChildren() {
return children != null && children.length > 0;
}
-
+
@Override
public int hashCode() {
return Util.hashCode(value);
@@ -116,22 +120,22 @@ public class TreeNode {
/**
* Sets the children for this node.
- *
+ *
* @param children
* The child nodes; may be <code>null</code> or empty. There
* should be no <code>null</code> children in the array.
*/
- public void setChildren(final TreeNode[] children) {
+ public void setChildren(final TreeNode<E>[] children) {
this.children = children;
}
/**
* Sets the parent for this node.
- *
+ *
* @param parent
* The parent node; may be <code>null</code>.
*/
- public void setParent(final TreeNode parent) {
+ public void setParent(final TreeNode<E> parent) {
this.parent = parent;
}
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNodeContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNodeContentProvider.java
index 9fa1ebc..ad9341f 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNodeContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeNodeContentProvider.java
@@ -21,14 +21,14 @@ package org.eclipse.jface.viewers;
* <p>
* This class and all of its methods may be overridden or extended.
* </p>
- *
+ *
* @since 3.2
* @see org.eclipse.jface.viewers.TreeNode
*/
public class TreeNodeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -37,7 +37,7 @@ public class TreeNodeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
public Object[] getChildren(final Object parentElement) {
@@ -47,7 +47,7 @@ public class TreeNodeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(final Object inputElement) {
@@ -59,7 +59,7 @@ public class TreeNodeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
public Object getParent(final Object element) {
@@ -69,7 +69,7 @@ public class TreeNodeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
public boolean hasChildren(final Object element) {
@@ -79,7 +79,7 @@ public class TreeNodeContentProvider implements ITreeContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreePath.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreePath.java
index 5987505..0b099ce 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreePath.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreePath.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -19,28 +20,30 @@ import org.eclipse.core.runtime.Assert;
* <p>
* Clients may instantiate this class. Not intended to be subclassed.
* </p>
- *
+ * @param <E> Type of an single element of the model
+ *
* @since 3.2
*/
-public final class TreePath {
-
+public final class TreePath<E> {
+
/**
* Constant for representing an empty tree path.
*/
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public static final TreePath EMPTY = new TreePath(new Object[0]);
-
- private Object[] segments;
+
+ private E[] segments;
private int hash;
/**
* Constructs a path identifying a leaf node in a tree.
- *
+ *
* @param segments
* path of elements to a leaf node in a tree, starting with the
* root element
*/
- public TreePath(Object[] segments) {
+ public TreePath(E[] segments) {
Assert.isNotNull(segments);
for (int i = 0; i < segments.length; i++) {
Assert.isNotNull(segments[i]);
@@ -50,18 +53,18 @@ public final class TreePath {
/**
* Returns the element at the specified index in this path.
- *
+ *
* @param index
* index of element to return
* @return element at the specified index
*/
- public Object getSegment(int index) {
+ public E getSegment(int index) {
return segments[index];
}
/**
* Returns the number of elements in this path.
- *
+ *
* @return the number of elements in this path
*/
public int getSegmentCount() {
@@ -71,10 +74,10 @@ public final class TreePath {
/**
* Returns the first element in this path, or <code>null</code> if this
* path has no segments.
- *
+ *
* @return the first element in this path
*/
- public Object getFirstSegment() {
+ public E getFirstSegment() {
if (segments.length == 0) {
return null;
}
@@ -84,10 +87,10 @@ public final class TreePath {
/**
* Returns the last element in this path, or <code>null</code> if this
* path has no segments.
- *
+ *
* @return the last element in this path
*/
- public Object getLastSegment() {
+ public E getLastSegment() {
if (segments.length == 0) {
return null;
}
@@ -96,7 +99,7 @@ public final class TreePath {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -104,12 +107,14 @@ public final class TreePath {
if (!(other instanceof TreePath)) {
return false;
}
- return equals((TreePath) other, null);
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) other;
+ return equals(treePath, null);
}
/**
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -123,7 +128,7 @@ public final class TreePath {
/**
* Returns a hash code computed from the hash codes of the segments, using
* the given comparer to compute the hash codes of the segments.
- *
+ *
* @param comparer
* comparer to use or <code>null</code> if the segments' hash
* codes should be computed by calling their hashCode() methods.
@@ -144,7 +149,7 @@ public final class TreePath {
/**
* Returns whether this path is equivalent to the given path using the
* specified comparer to compare individual elements.
- *
+ *
* @param otherPath
* tree path to compare to
* @param comparer
@@ -152,7 +157,7 @@ public final class TreePath {
* compared using equals()
* @return whether the paths are equal
*/
- public boolean equals(TreePath otherPath, IElementComparer comparer) {
+ public boolean equals(TreePath<E> otherPath, IElementComparer comparer) {
if (otherPath == null) {
return false;
}
@@ -176,7 +181,7 @@ public final class TreePath {
/**
* Returns whether this path starts with the same segments as the given
* path, using the given comparer to compare segments.
- *
+ *
* @param treePath
* path to compare to
* @param comparer
@@ -185,7 +190,7 @@ public final class TreePath {
* @return whether the given path is a prefix of this path, or the same as
* this path
*/
- public boolean startsWith(TreePath treePath, IElementComparer comparer) {
+ public boolean startsWith(TreePath<E> treePath, IElementComparer comparer) {
int thisSegmentCount = getSegmentCount();
int otherSegmentCount = treePath.getSegmentCount();
if (otherSegmentCount == thisSegmentCount) {
@@ -195,7 +200,7 @@ public final class TreePath {
return false;
}
for (int i = 0; i < otherSegmentCount; i++) {
- Object otherSegment = treePath.getSegment(i);
+ E otherSegment = treePath.getSegment(i);
if (comparer == null) {
if (!otherSegment.equals(segments[i])) {
return false;
@@ -214,30 +219,34 @@ public final class TreePath {
* or <code>null</code> if this tree path has no segments.
* @return a tree path
*/
- public TreePath getParentPath() {
+ public TreePath<E> getParentPath() {
int segmentCount = getSegmentCount();
if (segmentCount < 1) {
return null;
} else if (segmentCount == 1) {
- return EMPTY;
+ @SuppressWarnings("unchecked")
+ TreePath<E> emptyTreePath = EMPTY;
+ return emptyTreePath;
}
- Object[] parentSegments = new Object[segmentCount - 1];
+ @SuppressWarnings("unchecked")
+ E[] parentSegments = (E[]) new Object[segmentCount - 1];
System.arraycopy(segments, 0, parentSegments, 0, segmentCount - 1);
- return new TreePath(parentSegments);
+ return new TreePath<E>(parentSegments);
}
/**
* Returns a copy of this tree path with the given segment added at the end.
- * @param newSegment
+ * @param newSegment
* @return a tree path
*/
- public TreePath createChildPath(Object newSegment) {
+ public TreePath<E> createChildPath(E newSegment) {
int segmentCount = getSegmentCount();
- Object[] childSegments = new Object[segmentCount + 1];
+ @SuppressWarnings("unchecked")
+ E[] childSegments = (E[]) new Object[segmentCount + 1];
if(segmentCount>0) {
System.arraycopy(segments, 0, childSegments, 0, segmentCount);
}
childSegments[segmentCount] = newSegment;
- return new TreePath(childSegments);
+ return new TreePath<E>(childSegments);
}
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java
index 4c4ffb9..fa399d2 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java
@@ -11,6 +11,7 @@
* refactoring (bug 153993), bug 167323, 191468, 205419
* Matthew Hall - bug 221988
* Pawel Piech, WindRiver - bug 296573
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -64,9 +65,11 @@ import org.eclipse.swt.widgets.Widget;
* Users setting up an editable tree with more than 1 column <b>have</b> to pass the
* SWT.FULL_SELECTION style bit
* </p>
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
* @noextend This class is not intended to be subclassed by clients.
*/
-public class TreeViewer extends AbstractTreeViewer {
+public class TreeViewer<E,I> extends AbstractTreeViewer<E, I> {
private static final String VIRTUAL_DISPOSE_KEY = Policy.JFACE
+ ".DISPOSE_LISTENER"; //$NON-NLS-1$
@@ -88,7 +91,7 @@ public class TreeViewer extends AbstractTreeViewer {
/**
* The row object reused
*/
- private TreeViewerRow cachedRow;
+ private TreeViewerRow<E> cachedRow;
/**
* true if we are inside a preservingSelection() call
@@ -248,7 +251,7 @@ public class TreeViewer extends AbstractTreeViewer {
* image for the first column, and any remaining columns are blank.
*/
@Override
- public IBaseLabelProvider getLabelProvider() {
+ public IBaseLabelProvider<E> getLabelProvider() {
return super.getLabelProvider();
}
@@ -357,7 +360,7 @@ public class TreeViewer extends AbstractTreeViewer {
* (non-Javadoc) Method declared in AbstractTreeViewer.
*/
@Override
- protected void setSelection(List items) {
+ protected void setSelection(List<Item> items) {
Item[] current = getSelection(getTree());
@@ -397,7 +400,7 @@ public class TreeViewer extends AbstractTreeViewer {
}
@Override
- protected void assertContentProviderType(IContentProvider provider) {
+ protected void assertContentProviderType(IContentProvider<I> provider) {
if (provider instanceof ILazyTreeContentProvider
|| provider instanceof ILazyTreePathContentProvider) {
return;
@@ -406,9 +409,11 @@ public class TreeViewer extends AbstractTreeViewer {
}
@Override
- protected Object[] getRawChildren(Object parent) {
+ protected E[] getRawChildren(Object parent) {
if (contentProviderIsLazy) {
- return new Object[0];
+ @SuppressWarnings("unchecked")
+ E[] elements = (E[]) new Object[0];
+ return elements;
}
return super.getRawChildren(parent);
}
@@ -484,14 +489,15 @@ public class TreeViewer extends AbstractTreeViewer {
* @since 3.2
*/
public void replace(final Object parentElementOrTreePath, final int index,
- final Object element) {
+ final E element) {
if (checkBusy())
return;
Item[] selectedItems = getSelection(getControl());
TreeSelection selection = (TreeSelection) getSelection();
Widget[] itemsToDisassociate;
if (parentElementOrTreePath instanceof TreePath) {
- TreePath elementPath = ((TreePath) parentElementOrTreePath)
+ @SuppressWarnings("unchecked")
+ TreePath<E> elementPath = ((TreePath<E>) parentElementOrTreePath)
.createChildPath(element);
itemsToDisassociate = internalFindItems(elementPath);
} else {
@@ -584,9 +590,11 @@ public class TreeViewer extends AbstractTreeViewer {
// The current item was selected, but its data is null.
// The data will be replaced by the given element, so to keep
// it selected, we have to add it to the selection.
- TreePath[] originalPaths = selection.getPaths();
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E>[] originalPaths = (TreePath<E>[]) selection.getPaths();
int length = originalPaths.length;
- TreePath[] paths = new TreePath[length + 1];
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E>[] paths = (TreePath<E>[]) new TreePath[length + 1];
System.arraycopy(originalPaths, 0, paths, 0, length);
// set the element temporarily so that we can call getTreePathFromItem
item.setData(element);
@@ -618,13 +626,19 @@ public class TreeViewer extends AbstractTreeViewer {
setBusy(true);
try {
if (contentProviderIsLazy && !contentProviderIsTreeBased && !(element instanceof TreePath)) {
- ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
- return lazyTreeContentProvider.getParent(element);
+ @SuppressWarnings("unchecked")
+ ILazyTreeContentProvider<E,I> lazyTreeContentProvider = (ILazyTreeContentProvider<E,I>) getContentProvider();
+ @SuppressWarnings("unchecked")
+ E currentElement = (E)element;
+ return lazyTreeContentProvider.getParent(currentElement);
}
if (contentProviderIsLazy && contentProviderIsTreeBased && !(element instanceof TreePath)) {
- ILazyTreePathContentProvider lazyTreePathContentProvider = (ILazyTreePathContentProvider) getContentProvider();
- TreePath[] parents = lazyTreePathContentProvider
- .getParents(element);
+ @SuppressWarnings("unchecked")
+ ILazyTreePathContentProvider<E, I> lazyTreePathContentProvider = (ILazyTreePathContentProvider<E, I>) getContentProvider();
+ @SuppressWarnings("unchecked")
+ E currentElement = (E) element;
+ TreePath<E>[] parents = lazyTreePathContentProvider
+ .getParents(currentElement);
if (parents != null && parents.length > 0) {
return parents[0];
}
@@ -672,7 +686,7 @@ public class TreeViewer extends AbstractTreeViewer {
@Override
protected void internalAdd(Widget widget, Object parentElement,
- Object[] childElements) {
+ E[] childElements) {
if (contentProviderIsLazy) {
if (widget instanceof TreeItem) {
TreeItem ti = (TreeItem) widget;
@@ -785,7 +799,7 @@ public class TreeViewer extends AbstractTreeViewer {
* the item if the tree is virtual.
*/
@Override
- protected void mapElement(Object element, final Widget item) {
+ protected void mapElement(E element, final Widget item) {
super.mapElement(element, item);
// make sure to unmap elements if the tree is virtual
if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
@@ -796,7 +810,8 @@ public class TreeViewer extends AbstractTreeViewer {
item.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (!treeIsDisposed) {
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (usingElementMap() && data != null) {
unmapElement(data, item);
}
@@ -813,9 +828,9 @@ public class TreeViewer extends AbstractTreeViewer {
* @see org.eclipse.jface.viewers.ColumnViewer#getRowPartFromItem(org.eclipse.swt.widgets.Widget)
*/
@Override
- protected ViewerRow getViewerRowFromItem(Widget item) {
+ protected ViewerRow<E> getViewerRowFromItem(Widget item) {
if( cachedRow == null ) {
- cachedRow = new TreeViewerRow((TreeItem) item);
+ cachedRow = new TreeViewerRow<E>((TreeItem) item);
} else {
cachedRow.setItem((TreeItem) item);
}
@@ -831,7 +846,7 @@ public class TreeViewer extends AbstractTreeViewer {
* @param rowIndex
* @return ViewerRow
*/
- private ViewerRow createNewRowPart(ViewerRow parent, int style, int rowIndex) {
+ private ViewerRow<E> createNewRowPart(ViewerRow<E> parent, int style, int rowIndex) {
if (parent == null) {
if (rowIndex >= 0) {
return getViewerRowFromItem(new TreeItem(tree, style, rowIndex));
@@ -871,7 +886,7 @@ public class TreeViewer extends AbstractTreeViewer {
* java.lang.Object)
*/
@Override
- protected void updatePlus(Item item, Object element) {
+ protected void updatePlus(Item item, E element) {
if (contentProviderIsLazy) {
Object data = item.getData();
int itemCount = 0;
@@ -895,11 +910,12 @@ public class TreeViewer extends AbstractTreeViewer {
public void remove(final Object parentOrTreePath, final int index) {
if (checkBusy())
return;
- final List oldSelection = new LinkedList(Arrays
+ @SuppressWarnings("rawtypes")
+ final List<TreePath> oldSelection = new LinkedList<TreePath>(Arrays
.asList(((TreeSelection) getSelection()).getPaths()));
preservingSelection(new Runnable() {
public void run() {
- TreePath removedPath = null;
+ TreePath<E> removedPath = null;
if (internalIsInputOrEmptyPath(parentOrTreePath)) {
Tree tree = (Tree) getControl();
if (index < tree.getItemCount()) {
@@ -918,9 +934,9 @@ public class TreeViewer extends AbstractTreeViewer {
continue;
if (index < parentItem.getItemCount()) {
TreeItem item = parentItem.getItem(index);
-
+
if (item.getData() == null) {
- // If getData()==null and index == 0, and the
+ // If getData()==null and index == 0, and the
// parent item is collapsed, then we are
// being asked to remove the dummy node. We'll
// just ignore the request to remove the dummy
@@ -938,20 +954,23 @@ public class TreeViewer extends AbstractTreeViewer {
}
if (removedPath != null) {
boolean removed = false;
- for (Iterator it = oldSelection.iterator(); it
+ for (@SuppressWarnings("rawtypes")
+ Iterator<TreePath> it = oldSelection.iterator(); it
.hasNext();) {
- TreePath path = (TreePath) it.next();
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E> path = (TreePath<E>) it.next();
if (path.startsWith(removedPath, getComparer())) {
it.remove();
removed = true;
}
}
if (removed) {
- setSelection(new TreeSelection(
- (TreePath[]) oldSelection
- .toArray(new TreePath[oldSelection
- .size()]), getComparer()),
- false);
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E>[] oldTreePathSelection = (TreePath<E>[]) oldSelection
+ .toArray(new TreePath[oldSelection.size()]);
+
+ setSelection(new TreeSelection(oldTreePathSelection,
+ getComparer()), false);
}
}
@@ -968,7 +987,7 @@ public class TreeViewer extends AbstractTreeViewer {
if( isCellEditorActive() ) {
applyEditorValue();
}
-
+
if (contentProviderIsLazy) {
if (event.item.getData() != null) {
Item[] children = getChildren(event.item);
@@ -977,14 +996,15 @@ public class TreeViewer extends AbstractTreeViewer {
// count
virtualLazyUpdateChildCount(event.item, children.length);
}
- fireTreeExpanded(new TreeExpansionEvent(this, event.item
- .getData()));
+ @SuppressWarnings("unchecked")
+ E element = (E) event.item.getData();
+ fireTreeExpanded(new TreeExpansionEvent<E,I>(this, element));
}
return;
}
super.handleTreeExpand(event);
}
-
+
@Override
protected void handleTreeCollapse(TreeEvent event) {
// Fix for Bug 271744 because windows is firing collapse before
@@ -992,7 +1012,7 @@ public class TreeViewer extends AbstractTreeViewer {
if( isCellEditorActive() ) {
applyEditorValue();
}
-
+
super.handleTreeCollapse(event);
}
@@ -1000,7 +1020,7 @@ public class TreeViewer extends AbstractTreeViewer {
* @see org.eclipse.jface.viewers.AbstractTreeViewer#setContentProvider(org.eclipse.jface.viewers.IContentProvider)
*/
@Override
- public void setContentProvider(IContentProvider provider) {
+ public void setContentProvider(IContentProvider<I> provider) {
contentProviderIsLazy = (provider instanceof ILazyTreeContentProvider)
|| (provider instanceof ILazyTreePathContentProvider);
contentProviderIsTreeBased = provider instanceof ILazyTreePathContentProvider;
@@ -1064,7 +1084,9 @@ public class TreeViewer extends AbstractTreeViewer {
setBusy(false);
try {
if (contentProviderIsTreeBased) {
- TreePath treePath;
+ TreePath<E> treePath;
+ @SuppressWarnings("unchecked")
+ ILazyTreePathContentProvider<E, I> lazyTreePathContentProvider = (ILazyTreePathContentProvider<E, I>) getContentProvider();
if (widget instanceof Item) {
if (widget.getData() == null) {
// we need to materialize the parent first
@@ -1072,18 +1094,23 @@ public class TreeViewer extends AbstractTreeViewer {
// however, that would be too risky
// see bug 182782 and bug 182598
// so we just ignore this call altogether
- // and don't do this: virtualMaterializeItem((TreeItem) widget);
+ // and don't do this: virtualMaterializeItem((TreeItem)
+ // widget);
return;
}
treePath = getTreePathFromItem((Item) widget);
} else {
- treePath = TreePath.EMPTY;
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E> emptyTreePath = (TreePath<E>) TreePath.EMPTY;
+ treePath = emptyTreePath;
}
- ((ILazyTreePathContentProvider) getContentProvider())
- .updateElement(treePath, index);
+ lazyTreePathContentProvider.updateElement(treePath, index);
} else {
- ((ILazyTreeContentProvider) getContentProvider()).updateElement(
- widget.getData(), index);
+ @SuppressWarnings("unchecked")
+ ILazyTreeContentProvider<E, I> lazyTreeContentProvider = (ILazyTreeContentProvider<E, I>) getContentProvider();
+ @SuppressWarnings("unchecked")
+ E element = (E) widget.getData();
+ lazyTreeContentProvider.updateElement(element, index);
}
} finally {
setBusy(oldBusy);
@@ -1100,16 +1127,23 @@ public class TreeViewer extends AbstractTreeViewer {
setBusy(false);
try {
if (contentProviderIsTreeBased) {
- TreePath treePath;
+ TreePath<E> treePath;
+ @SuppressWarnings("unchecked")
+ ILazyTreePathContentProvider<E,I> lazyTreePathContentProvider = (ILazyTreePathContentProvider<E,I>) getContentProvider();
if (widget instanceof Item) {
treePath = getTreePathFromItem((Item) widget);
} else {
- treePath = TreePath.EMPTY;
+ @SuppressWarnings({ "unchecked", "cast" })
+ TreePath<E> emptyTreePath = (TreePath<E>) TreePath.EMPTY;
+ treePath = emptyTreePath;
}
- ((ILazyTreePathContentProvider) getContentProvider())
- .updateChildCount(treePath, currentChildCount);
+ lazyTreePathContentProvider.updateChildCount(treePath, currentChildCount);
} else {
- ((ILazyTreeContentProvider) getContentProvider()).updateChildCount(widget.getData(), currentChildCount);
+ @SuppressWarnings("unchecked")
+ E element = (E)widget.getData();
+ @SuppressWarnings("unchecked")
+ ILazyTreeContentProvider<E,I> lazyTreeContentProvider = (ILazyTreeContentProvider<E,I>) getContentProvider();
+ lazyTreeContentProvider.updateChildCount(element, currentChildCount);
}
} finally {
setBusy(oldBusy);
@@ -1126,18 +1160,22 @@ public class TreeViewer extends AbstractTreeViewer {
setBusy(false);
try {
if (contentProviderIsTreeBased) {
- TreePath treePath;
+ TreePath<E> treePath;
treePath = getTreePathFromItem(item);
+ @SuppressWarnings("unchecked")
+ ILazyTreePathContentProvider<E,I> lazyTreePathContentProvider = (ILazyTreePathContentProvider<E,I>) getContentProvider();
if (currentChildCount == 0 || !((TreeItem)item).getExpanded()) {
// item is not expanded (but may have a plus currently)
- ((ILazyTreePathContentProvider) getContentProvider())
- .updateHasChildren(treePath);
+ lazyTreePathContentProvider.updateHasChildren(treePath);
} else {
- ((ILazyTreePathContentProvider) getContentProvider())
- .updateChildCount(treePath, currentChildCount);
+ lazyTreePathContentProvider.updateChildCount(treePath, currentChildCount);
}
} else {
- ((ILazyTreeContentProvider) getContentProvider()).updateChildCount(item.getData(), currentChildCount);
+ @SuppressWarnings("unchecked")
+ E element = (E)item.getData();
+ @SuppressWarnings("unchecked")
+ ILazyTreeContentProvider<E,I> lazyTreeContentProvider = (ILazyTreeContentProvider<E,I>) getContentProvider();
+ lazyTreeContentProvider.updateChildCount(element, currentChildCount);
}
} finally {
setBusy(oldBusy);
@@ -1178,18 +1216,20 @@ public class TreeViewer extends AbstractTreeViewer {
}
@Override
- public void editElement(Object element, int column) {
+ public void editElement(E element, int column) {
if( element instanceof TreePath ) {
try {
getControl().setRedraw(false);
- setSelection(new TreeSelection((TreePath) element));
+ @SuppressWarnings("unchecked")
+ TreePath<E> treePath = (TreePath<E>) element;
+ setSelection(new TreeSelection(treePath));
TreeItem[] items = tree.getSelection();
if( items.length == 1 ) {
- ViewerRow row = getViewerRowFromItem(items[0]);
+ ViewerRow<E> row = getViewerRowFromItem(items[0]);
if (row != null) {
- ViewerCell cell = row.getCell(column);
+ ViewerCell<E> cell = row.getCell(column);
if (cell != null) {
triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerColumn.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerColumn.java
index 3da3987..3b60e21 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerColumn.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerColumn.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
******************************************************************************/
package org.eclipse.jface.viewers;
@@ -17,18 +18,20 @@ import org.eclipse.swt.widgets.TreeColumn;
/**
* ViewerColumn implementation for TreeViewer to enable column-specific label
* providers and editing support.
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
- *
+ *
*/
-public final class TreeViewerColumn extends ViewerColumn {
+public final class TreeViewerColumn<E,I> extends ViewerColumn<E,I> {
private TreeColumn column;
/**
* Creates a new viewer column for the given {@link TreeViewer} on a new
* {@link TreeColumn} with the given style bits. The column is inserted at
* the given index into the list of columns.
- *
+ *
* @param viewer
* the tree viewer to which this column belongs
* @param style
@@ -36,7 +39,7 @@ public final class TreeViewerColumn extends ViewerColumn {
* see {@link TreeColumn}
* @see TreeColumn#TreeColumn(Tree, int)
*/
- public TreeViewerColumn(TreeViewer viewer, int style) {
+ public TreeViewerColumn(TreeViewer<E,I> viewer, int style) {
this(viewer, style, -1);
}
@@ -44,7 +47,7 @@ public final class TreeViewerColumn extends ViewerColumn {
* Creates a new viewer column for the given {@link TreeViewer} on a new
* {@link TreeColumn} with the given style bits. The column is added at the
* end of the list of columns.
- *
+ *
* @param viewer
* the tree viewer to which this column belongs
* @param style
@@ -54,24 +57,24 @@ public final class TreeViewerColumn extends ViewerColumn {
* the index at which to place the newly created column
* @see TreeColumn#TreeColumn(Tree, int, int)
*/
- public TreeViewerColumn(TreeViewer viewer, int style, int index) {
+ public TreeViewerColumn(TreeViewer<E,I> viewer, int style, int index) {
this(viewer, createColumn(viewer.getTree(), style, index));
}
/**
* Creates a new viewer column for the given {@link TreeViewer} on the given
* {@link TreeColumn}.
- *
+ *
* @param viewer
* the tree viewer to which this column belongs
* @param column
* the underlying tree column
*/
- public TreeViewerColumn(TreeViewer viewer, TreeColumn column) {
+ public TreeViewerColumn(TreeViewer<E,I> viewer, TreeColumn column) {
super(viewer, column);
this.column = column;
}
-
+
private static TreeColumn createColumn(Tree table, int style, int index) {
if (index >= 0) {
return new TreeColumn(table, style, index);
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerRow.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerRow.java
index f428010..b3e6503 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerRow.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewerRow.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* - fix in bug: 174355,171126,,195908,198035,215069,227421
+ * Hendrik Still <hendrik.still@gammas.de> - bug 413973
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -27,11 +28,12 @@ import org.eclipse.swt.widgets.Widget;
/**
* TreeViewerRow is the Tree implementation of ViewerRow.
+ * @param <E> Type of an element of the model
*
* @since 3.3
*
*/
-public class TreeViewerRow extends ViewerRow {
+public class TreeViewerRow<E> extends ViewerRow<E> {
private TreeItem item;
/**
@@ -201,7 +203,7 @@ public class TreeViewerRow extends ViewerRow {
}
@Override
- public ViewerRow getNeighbor(int direction, boolean sameLevel) {
+ public ViewerRow<E> getNeighbor(int direction, boolean sameLevel) {
if (direction == ViewerRow.ABOVE) {
return getRowAbove(sameLevel);
} else if (direction == ViewerRow.BELOW) {
@@ -212,7 +214,7 @@ public class TreeViewerRow extends ViewerRow {
}
}
- private ViewerRow getRowBelow(boolean sameLevel) {
+ private ViewerRow<E> getRowBelow(boolean sameLevel) {
Tree tree = item.getParent();
// This means we have top-level item
@@ -221,10 +223,10 @@ public class TreeViewerRow extends ViewerRow {
int index = tree.indexOf(item) + 1;
if (index < tree.getItemCount()) {
- return new TreeViewerRow(tree.getItem(index));
+ return new TreeViewerRow<E>(tree.getItem(index));
}
} else if (item.getExpanded() && item.getItemCount() > 0) {
- return new TreeViewerRow(item.getItem(0));
+ return new TreeViewerRow<E>(item.getItem(0));
}
} else {
if (sameLevel || !item.getExpanded()) {
@@ -243,18 +245,18 @@ public class TreeViewerRow extends ViewerRow {
}
if (itemAfter != null) {
- return new TreeViewerRow(itemAfter);
+ return new TreeViewerRow<E>(itemAfter);
}
} else if (item.getExpanded() && item.getItemCount() > 0) {
- return new TreeViewerRow(item.getItem(0));
+ return new TreeViewerRow<E>(item.getItem(0));
}
}
return null;
}
- private ViewerRow getRowAbove(boolean sameLevel) {
+ private ViewerRow<E> getRowAbove(boolean sameLevel) {
Tree tree = item.getParent();
// This means we have top-level item
@@ -268,10 +270,10 @@ public class TreeViewerRow extends ViewerRow {
if (nextTopItem != null) {
if (sameLevel) {
- return new TreeViewerRow(nextTopItem);
+ return new TreeViewerRow<E>(nextTopItem);
}
- return new TreeViewerRow(findLastVisibleItem(nextTopItem));
+ return new TreeViewerRow<E>(findLastVisibleItem(nextTopItem));
}
} else {
TreeItem parentItem = item.getParentItem();
@@ -290,7 +292,7 @@ public class TreeViewerRow extends ViewerRow {
}
if (itemBefore != null) {
- return new TreeViewerRow(itemBefore);
+ return new TreeViewerRow<E>(itemBefore);
}
}
@@ -343,15 +345,15 @@ public class TreeViewerRow extends ViewerRow {
@Override
public TreePath getTreePath() {
TreeItem tItem = item;
- LinkedList segments = new LinkedList();
+ LinkedList<E> segments = new LinkedList<E>();
while (tItem != null) {
- Object segment = tItem.getData();
+ E segment = (E) tItem.getData();
Assert.isNotNull(segment);
segments.addFirst(segment);
tItem = tItem.getParentItem();
}
- return new TreePath(segments.toArray());
+ return new TreePath<E>((E[]) segments.toArray());
}
void setItem(TreeItem item) {
@@ -360,12 +362,12 @@ public class TreeViewerRow extends ViewerRow {
@Override
public Object clone() {
- return new TreeViewerRow(item);
+ return new TreeViewerRow<E>(item);
}
@Override
- public Object getElement() {
- return item.getData();
+ public E getElement() {
+ return (E) item.getData();
}
@Override
@@ -396,15 +398,15 @@ public class TreeViewerRow extends ViewerRow {
public Rectangle getTextBounds(int index) {
return item.getTextBounds(index);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerRow#getImageBounds(int)
*/
@Override
public Rectangle getImageBounds(int index) {
return item.getImageBounds(index);
- }
-
+ }
+
private boolean hasColumns() {
return this.item.getParent().getColumnCount() != 0;
}
@@ -417,12 +419,12 @@ public class TreeViewerRow extends ViewerRow {
int getWidth(int columnIndex) {
return item.getParent().getColumn(columnIndex).getWidth();
}
-
+
@Override
protected boolean scrollCellIntoView(int columnIndex) {
item.getParent().showItem(item);
if( hasColumns() ) {
- item.getParent().showColumn(item.getParent().getColumn(columnIndex));
+ item.getParent().showColumn(item.getParent().getColumn(columnIndex));
}
return true;
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerFilter.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerFilter.java
index 50b30d8..33ea180 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerFilter.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerFilter.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.jface.viewers;
-import java.lang.reflect.Array;
import java.util.ArrayList;
/**
@@ -20,8 +19,8 @@ import java.util.ArrayList;
* Subclasses must implement the <code>select</code> method
* and may implement the <code>isFilterProperty</code> method.
* </p>
- * @param <E>
- * @param <I>
+ * @param <E>
+ * @param <I>
* @see IStructuredContentProvider
* @see StructuredViewer
*/
@@ -36,8 +35,8 @@ public abstract class ViewerFilter<E,I> {
* Filters the given elements for the given viewer.
* The input array is not modified.
* <p>
- * The default implementation of this method calls
- * <code>select</code> on each element in the array,
+ * The default implementation of this method calls
+ * <code>select</code> on each element in the array,
* and returns only those elements for which <code>select</code>
* returns <code>true</code>.
* </p>
@@ -56,13 +55,7 @@ public abstract class ViewerFilter<E,I> {
out.add(element);
}
}
- if (out.size() > 0) {
- @SuppressWarnings("unchecked")
- E[] newArrayInstance = (E[]) Array.newInstance(element.getClass(),
- out.size());
- return out.toArray(newArrayInstance);
- }
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
E[] result = (E[]) out.toArray();
return result;
}
@@ -71,8 +64,8 @@ public abstract class ViewerFilter<E,I> {
* Filters the given elements for the given viewer.
* The input array is not modified.
* <p>
- * The default implementation of this method calls
- * {@link #filter(Viewer, Object, Object[])} with the
+ * The default implementation of this method calls
+ * {@link #filter(Viewer, Object, Object[])} with the
* parent from the path. Subclasses may override
* </p>
* @param viewer the viewer
@@ -81,12 +74,12 @@ public abstract class ViewerFilter<E,I> {
* @return the filtered elements
* @since 3.2
*/
- public Object[] filter(Viewer<I> viewer, TreePath parentPath, E[] elements) {
+ public Object[] filter(Viewer<I> viewer, TreePath<E> parentPath, E[] elements) {
return filter(viewer, parentPath.getLastSegment(), elements);
}
-
+
/**
- * Returns whether this viewer filter would be affected
+ * Returns whether this viewer filter would be affected
* by a change to the given property of the given element.
* <p>
* The default implementation of this method returns <code>false</code>.
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java
index fced43d..5060fc1 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java
@@ -239,7 +239,7 @@ public abstract class ViewerRow<E> implements Cloneable {
*
* @return the path
*/
- public abstract TreePath getTreePath();
+ public abstract TreePath<E> getTreePath();
@Override
public abstract Object clone();
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/WrappedViewerLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/WrappedViewerLabelProvider.java
index 0fb89f4..92fd569 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/WrappedViewerLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/WrappedViewerLabelProvider.java
@@ -40,7 +40,7 @@ class WrappedViewerLabelProvider<E,I> extends ColumnLabelProvider<E,I> {
private IViewerLabelProvider<E> viewerLabelProvider;
- private ITreePathLabelProvider treePathLabelProvider;
+ private ITreePathLabelProvider<E> treePathLabelProvider;
/**
* Create a new instance of the receiver based on labelProvider.
@@ -59,9 +59,12 @@ class WrappedViewerLabelProvider<E,I> extends ColumnLabelProvider<E,I> {
* {@link Object}
*/
public void setProviders(Object provider) {
- if (provider instanceof ITreePathLabelProvider)
- treePathLabelProvider = ((ITreePathLabelProvider) provider);
-
+ if (provider instanceof ITreePathLabelProvider){
+ @SuppressWarnings("unchecked")
+ ITreePathLabelProvider<E> iTreePathLabelProvider = (ITreePathLabelProvider<E>) provider;
+ treePathLabelProvider = iTreePathLabelProvider;
+ }
+
if (provider instanceof IViewerLabelProvider){
@SuppressWarnings("unchecked")
IViewerLabelProvider<E> iViewerLabelProvider = ((IViewerLabelProvider<E>) provider);
@@ -199,7 +202,7 @@ class WrappedViewerLabelProvider<E,I> extends ColumnLabelProvider<E,I> {
ViewerLabel label = new ViewerLabel(cell.getText(), cell.getImage());
if (treePathLabelProvider != null) {
- TreePath treePath = cell.getViewerRow().getTreePath();
+ TreePath<E> treePath = cell.getViewerRow().getTreePath();
Assert.isNotNull(treePath);
treePathLabelProvider.updateLabel(label, treePath);