summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHendrik Still2013-08-02 10:22:31 (EDT)
committer John Arthorne2013-09-04 09:59:08 (EDT)
commitdfd1f4ce08f16035e6cc80616a5f84495d1dc43f (patch)
tree610cb786397871c37d900519fa0e0bac8c51674e
parentc0123bfc23706552c50a37d8d4fc7ecada965ae4 (diff)
downloadeclipse.platform.ui-dfd1f4ce08f16035e6cc80616a5f84495d1dc43f.zip
eclipse.platform.ui-dfd1f4ce08f16035e6cc80616a5f84495d1dc43f.tar.gz
eclipse.platform.ui-dfd1f4ce08f16035e6cc80616a5f84495d1dc43f.tar.bz2
Bug 413974 - [Viewers] Add generics to the TableViewer
Generics are added to the TableViewer and depending classes to provide a type safty use of this viewer This change depends on the changes from https://git.eclipse.org/r/#/c/14941/ Compiler setting "Ignore unavoidable generic type problems" disabled Change-Id: I69fa293d44f697f02d7effbd0b25872b6c2cb8b5 Signed-off-by: Hendrik Still <hendrik.still@gammas.de>
-rw-r--r--bundles/org.eclipse.jface/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTableViewer.java172
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CellLabelProvider.java91
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnLabelProvider.java24
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnViewer.java180
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IColorProvider.java15
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IFontProvider.java11
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IViewerLabelProvider.java15
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java16
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java55
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerColumn.java10
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerRow.java31
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java115
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerColumn.java44
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java98
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/WrappedViewerLabelProvider.java108
16 files changed, 529 insertions, 458 deletions
diff --git a/bundles/org.eclipse.jface/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.jface/.settings/org.eclipse.jdt.core.prefs
index 616c937..5cf6f5e 100644
--- a/bundles/org.eclipse.jface/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.jface/.settings/org.eclipse.jdt.core.prefs
@@ -93,7 +93,7 @@ org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
-org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
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 a6fdad5..04280ce 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
@@ -26,17 +26,18 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Widget;
-
import org.eclipse.core.runtime.Assert;
/**
* This is a widget independent class implementors of
* {@link org.eclipse.swt.widgets.Table} like widgets can use to provide a
* viewer on top of their widget implementations.
- *
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
+*
* @since 3.3
*/
-public abstract class AbstractTableViewer extends ColumnViewer {
+public abstract class AbstractTableViewer<E,I> extends ColumnViewer<E,I> {
private class VirtualManager {
@@ -46,13 +47,18 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* ILazyStructuredContentProvider as an ILazyStructuredContentProvider
* is only queried on the virtual callback.
*/
- private Object[] cachedElements = new Object[0];
+ private E[] cachedElements;
/**
* Create a new instance of the receiver.
*
*/
public VirtualManager() {
+
+ @SuppressWarnings("unchecked")
+ E[] initialCachedElements = (E[]) new Object[0];
+ cachedElements = initialCachedElements;
+
addTableListener();
}
@@ -69,18 +75,18 @@ public abstract class AbstractTableViewer extends ColumnViewer {
public void handleEvent(Event event) {
Item item = (Item) event.item;
final int index = doIndexOf(item);
-
+
if (index == -1) {
// Should not happen, but the spec for doIndexOf allows returning -1.
// See bug 241117.
return;
}
-
- Object element = resolveElement(index);
+
+ E element = resolveElement(index);
if (element == null) {
// Didn't find it so make a request
// Keep looking if it is not in the cache.
- IContentProvider contentProvider = getContentProvider();
+ IContentProvider<I> contentProvider = getContentProvider();
// If we are building lazily then request lookup now
if (contentProvider instanceof ILazyContentProvider) {
((ILazyContentProvider) contentProvider)
@@ -102,9 +108,9 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param index
* @return Object or <code>null</code> if it could not be found
*/
- protected Object resolveElement(int index) {
+ protected E resolveElement(int index) {
- Object element = null;
+ E element = null;
if (index < cachedElements.length) {
element = cachedElements[index];
}
@@ -118,11 +124,12 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param element
* @param index
*/
- public void notVisibleAdded(Object element, int index) {
+ public void notVisibleAdded(E element, int index) {
int requiredCount = doGetItemCount() + 1;
- Object[] newCache = new Object[requiredCount];
+ @SuppressWarnings("unchecked")
+ E[] newCache = (E[]) new Object[requiredCount];
System.arraycopy(cachedElements, 0, newCache, 0, index);
if (index < cachedElements.length) {
System.arraycopy(cachedElements, index, newCache, index + 1,
@@ -147,7 +154,8 @@ public abstract class AbstractTableViewer extends ColumnViewer {
int requiredCount = doGetItemCount() - indices.length;
Arrays.sort(indices);
- Object[] newCache = new Object[requiredCount];
+ @SuppressWarnings("unchecked")
+ E[] newCache = (E[]) new Object[requiredCount];
int indexInNewCache = 0;
int nextToSkip = 0;
for (int i = 0; i < cachedElements.length; i++) {
@@ -169,7 +177,8 @@ public abstract class AbstractTableViewer extends ColumnViewer {
*/
public void removeIndicesFromTo(int from, int to) {
int indexAfterTo = to + 1;
- Object[] newCache = new Object[cachedElements.length
+ @SuppressWarnings("unchecked")
+ E[] newCache = (E[]) new Object[cachedElements.length
- (indexAfterTo - from)];
System.arraycopy(cachedElements, 0, newCache, 0, from);
if (indexAfterTo < cachedElements.length) {
@@ -182,7 +191,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param element
* @return the index of the element in the cache, or null
*/
- public int find(Object element) {
+ public int find(E element) {
return Arrays.asList(cachedElements).indexOf(element);
}
@@ -193,11 +202,13 @@ public abstract class AbstractTableViewer extends ColumnViewer {
if (count == cachedElements.length) {
return;
} else if (count < cachedElements.length) {
- Object[] newCache = new Object[count];
+ @SuppressWarnings("unchecked")
+ E[] newCache = (E[]) new Object[count];
System.arraycopy(cachedElements, 0, newCache, 0, count);
cachedElements = newCache;
} else {
- Object[] newCache = new Object[count];
+ @SuppressWarnings("unchecked")
+ E[] newCache = (E[]) new Object[count];
System.arraycopy(cachedElements, 0, newCache, 0,
cachedElements.length);
cachedElements = newCache;
@@ -220,7 +231,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
super.hookControl(control);
initializeVirtualManager(getControl().getStyle());
}
-
+
@Override
protected void handleDispose(DisposeEvent event) {
super.handleDispose(event);
@@ -254,14 +265,14 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param elements
* the elements to add
*/
- public void add(Object[] elements) {
+ public void add(E[] elements) {
assertElementsNotNull(elements);
if (checkBusy())
return;
- Object[] filtered = filter(elements);
+ E[] filtered = filter(elements);
for (int i = 0; i < filtered.length; i++) {
- Object element = filtered[i];
+ E element = filtered[i];
int index = indexForElement(element);
createItem(element, index);
}
@@ -275,7 +286,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
*
* @since 3.1
*/
- private void createItem(Object element, int index) {
+ private void createItem(E element, int index) {
if (virtualManager == null) {
updateItem(internalCreateNewRowPart(SWT.NONE, index).getItem(),
element);
@@ -296,7 +307,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* the index of the row or -1 if the row is appended at the end
* @return the newly created row
*/
- protected abstract ViewerRow internalCreateNewRowPart(int style,
+ protected abstract ViewerRow<E> internalCreateNewRowPart(int style,
int rowIndex);
/**
@@ -314,8 +325,10 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param element
* the element to add
*/
- public void add(Object element) {
- add(new Object[] { element });
+ public void add(E element) {
+ @SuppressWarnings("unchecked")
+ E[] newElements = (E[]) new Object[] { element };
+ add(newElements);
}
/*
@@ -324,7 +337,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object)
*/
@Override
- protected Widget doFindInputItem(Object element) {
+ protected Widget doFindInputItem(E element) {
if (equals(element, getRoot())) {
return getControl();
}
@@ -337,7 +350,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object)
*/
@Override
- protected Widget doFindItem(Object element) {
+ protected Widget doFindItem(E element) {
Item[] children = doGetItems();
for (int i = 0; i < children.length; i++) {
@@ -358,7 +371,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* java.lang.Object, boolean)
*/
@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 {
@@ -369,7 +382,8 @@ public abstract class AbstractTableViewer 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);
}
@@ -381,25 +395,27 @@ public abstract class AbstractTableViewer extends ColumnViewer {
if (columnCount == 0)
columnCount = 1;// If there are no columns do the first one
- 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> viewerRowFromItemClone = (ViewerRow<E>) viewerRowFromItem.clone();
+ viewerRowFromItem = viewerRowFromItemClone;
}
// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT -
// TableViewer with 0 columns does not work
for (int column = 0; column < columnCount || column == 0; column++) {
- ViewerColumn columnViewer = getViewerColumn(column);
- ViewerCell cellToUpdate = updateCell(viewerRowFromItem,
+ 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);
@@ -475,7 +491,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* any remaining columns are blank.
*/
@Override
- public IBaseLabelProvider getLabelProvider() {
+ public IBaseLabelProvider<E> getLabelProvider() {
return super.getLabelProvider();
}
@@ -485,15 +501,16 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget()
*/
@Override
- protected List getSelectionFromWidget() {
+ protected List<E> getSelectionFromWidget() {
if (virtualManager != null) {
return getVirtualSelection();
}
Widget[] items = doGetSelection();
- 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);
}
@@ -508,9 +525,9 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @return List of Object
*/
- private List getVirtualSelection() {
+ private List<E> getVirtualSelection() {
- List result = new ArrayList();
+ List<E> result = new ArrayList<E>();
int[] selectionIndices = doGetSelectionIndices();
if (getContentProvider() instanceof ILazyContentProvider) {
ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider();
@@ -519,7 +536,8 @@ public abstract class AbstractTableViewer extends ColumnViewer {
lazy.updateElement(selectionIndex);// Start the update
// check for the case where the content provider changed the number of items
if (selectionIndex < doGetItemCount()) {
- Object element = doGetItem(selectionIndex).getData();
+ @SuppressWarnings("unchecked")
+ E element = (E) doGetItem(selectionIndex).getData();
// Only add the element if it got updated.
// If this is done deferred the selection will
// be incomplete until selection is finished.
@@ -530,7 +548,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
}
} else {
for (int i = 0; i < selectionIndices.length; i++) {
- Object element = null;
+ E element = null;
// See if it is cached
int selectionIndex = selectionIndices[i];
if (selectionIndex < virtualManager.cachedElements.length) {
@@ -539,7 +557,9 @@ public abstract class AbstractTableViewer extends ColumnViewer {
if (element == null) {
// Not cached so try the item's data
Item item = doGetItem(selectionIndex);
- element = item.getData();
+ @SuppressWarnings("unchecked")
+ E itemElement = (E) item.getData();
+ element = itemElement;
}
if (element != null) {
result.add(element);
@@ -623,7 +643,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* a 0-based position relative to the model, or -1 to indicate
* the last position
*/
- public void insert(Object element, int position) {
+ public void insert(E element, int position) {
applyEditorValue();
if (getComparator() != null || hasFilters()) {
add(element);
@@ -663,9 +683,11 @@ public abstract class AbstractTableViewer extends ColumnViewer {
internalVirtualRefreshAll();
}
} else {
- Widget w = findItem(element);
+ @SuppressWarnings("unchecked")
+ E castedElement = (E) element;
+ Widget w = findItem(castedElement);
if (w != null) {
- updateItem(w, element);
+ updateItem(w, castedElement);
}
}
}
@@ -677,8 +699,8 @@ public abstract class AbstractTableViewer extends ColumnViewer {
*/
private void internalVirtualRefreshAll() {
- Object root = getRoot();
- IContentProvider contentProvider = getContentProvider();
+ I root = getRoot();
+ IContentProvider<I> contentProvider = getContentProvider();
// Invalidate for lazy
if (!(contentProvider instanceof ILazyContentProvider)
@@ -710,7 +732,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
// item 1 could undo
// the associate of b to item 0.
- Object[] children = getSortedChildren(getRoot());
+ E[] children = getSortedChildren(getRoot());
Item[] items = doGetItems();
int min = Math.min(children.length, items.length);
for (int i = 0; i < min; ++i) {
@@ -776,8 +798,8 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param elements
* the elements to remove
*/
- private void internalRemove(final Object[] elements) {
- Object input = getInput();
+ private void internalRemove(final E[] elements) {
+ I input = getInput();
for (int i = 0; i < elements.length; ++i) {
if (equals(elements[i], input)) {
boolean oldBusy = isBusy();
@@ -834,7 +856,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param elements
* the elements to remove
*/
- public void remove(final Object[] elements) {
+ public void remove(final E[] elements) {
assertElementsNotNull(elements);
if (checkBusy())
return;
@@ -864,8 +886,10 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param element
* the element
*/
- public void remove(Object element) {
- remove(new Object[] { element });
+ public void remove(E element) {
+ @SuppressWarnings("unchecked")
+ E[] elements = (E[]) new Object[] { element };
+ remove(elements);
}
/*
@@ -874,7 +898,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object)
*/
@Override
- public void reveal(Object element) {
+ public void reveal(E element) {
Assert.isNotNull(element);
Widget w = findItem(element);
if (w instanceof Item) {
@@ -889,7 +913,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* boolean)
*/
@Override
- protected void setSelectionToWidget(List list, boolean reveal) {
+ protected void setSelectionToWidget(List<E> list, boolean reveal) {
if (list == null) {
doDeselectAll();
return;
@@ -907,7 +931,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
Item[] items = new Item[size];
int count = 0;
for (int i = 0; i < size; ++i) {
- Object o = list.get(i);
+ E o = list.get(i);
Widget w = findItem(o);
if (w instanceof Item) {
Item item = (Item) w;
@@ -923,9 +947,9 @@ public abstract class AbstractTableViewer extends ColumnViewer {
if( ! list.isEmpty() ) {
int[] indices = new int[list.size()];
- Iterator it = list.iterator();
+ Iterator<E> it = list.iterator();
Item[] items = doGetItems();
- Object modelElement;
+ E modelElement;
int count = 0;
while( it.hasNext() ) {
@@ -956,15 +980,15 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @param reveal
* Whether or not reveal the first item.
*/
- private void virtualSetSelectionToWidget(List list, boolean reveal) {
+ private void virtualSetSelectionToWidget(List<E> list, boolean reveal) {
int size = list.size();
int[] indices = new int[list.size()];
Item firstItem = null;
int count = 0;
- HashSet virtualElements = new HashSet();
+ HashSet<E> virtualElements = new HashSet<E>();
for (int i = 0; i < size; ++i) {
- Object o = list.get(i);
+ E o = list.get(i);
Widget w = findItem(o);
if (w instanceof Item) {
Item item = (Item) w;
@@ -1002,7 +1026,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
// have been found
// If it is not lazy we can use the cache
for (int i = 0; i < virtualManager.cachedElements.length; i++) {
- Object element = virtualManager.cachedElements[i];
+ E element = virtualManager.cachedElements[i];
if (virtualElements.contains(element)) {
Item item = doGetItem(i);
item.getText();// Be sure to fire the update
@@ -1061,14 +1085,14 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* Replace the element at the given index with the given element. This
* method will not call the content provider to verify. <strong>Note that
* this method will materialize a TableItem the given index.</strong>.
- *
+ *
* @param element
* @param index
* @see ILazyContentProvider
- *
+ *
* @since 3.1
*/
- public void replace(Object element, int index) {
+ public void replace(E element, int index) {
if (checkBusy())
return;
Item item = doGetItem(index);
@@ -1097,7 +1121,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object)
*/
@Override
- protected Object[] getRawChildren(Object parent) {
+ protected E[] getRawChildren(I parent) {
Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),
"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$
@@ -1111,7 +1135,7 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider)
*/
@Override
- protected void assertContentProviderType(IContentProvider provider) {
+ protected void assertContentProviderType(IContentProvider<I> provider) {
Assert.isTrue(provider instanceof IStructuredContentProvider
|| provider instanceof ILazyContentProvider);
}
@@ -1305,11 +1329,11 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* Items that are not in the receiver are ignored. If the receiver is single-select and multiple
* items are specified, then all items are ignored.
* </p>
- *
+ *
* @param items the array of items
- *
+ *
* @exception IllegalArgumentException - if the array of items is null
- *
+ *
* @since 3.3
*/
protected abstract void doSetSelection(Item[] items);
@@ -1331,11 +1355,11 @@ public abstract class AbstractTableViewer extends ColumnViewer {
* Indices that are out of range and duplicate indices are ignored. If the receiver is
* single-select and multiple indices are specified, then all indices are ignored.
* </p>
- *
+ *
* @param indices the indices of the items to select
- *
+ *
* @exception IllegalArgumentException - if the array of indices is null
- *
+ *
* @since 3.3
*/
protected abstract void doSetSelection(int[] indices);
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CellLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CellLabelProvider.java
index 1333f95..6c5c6aa 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CellLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/CellLabelProvider.java
@@ -23,13 +23,15 @@ import org.eclipse.swt.graphics.Point;
/**
* The CellLabelProvider is an abstract implementation of a label provider for
* structured viewers.
- *
+ *
* <p><b>This class is intended to be subclassed</b></p>
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
* @see ColumnLabelProvider as a concrete implementation
*/
-public abstract class CellLabelProvider extends BaseLabelProvider {
+public abstract class CellLabelProvider<E,I> extends BaseLabelProvider<E> {
/**
* Create a new instance of the receiver.
@@ -40,13 +42,13 @@ public abstract class CellLabelProvider extends BaseLabelProvider {
/**
* Create a ViewerLabelProvider for the column at index
- *
+ *
* @param labelProvider
* The labelProvider to convert
* @return ViewerLabelProvider
*/
- /* package */static CellLabelProvider createViewerLabelProvider(
- ColumnViewer viewer, IBaseLabelProvider labelProvider) {
+ /* package */static <E,I> CellLabelProvider<E,I> createViewerLabelProvider(
+ ColumnViewer<E,I> viewer, IBaseLabelProvider<E> labelProvider) {
boolean noColumnTreeViewer = viewer instanceof AbstractTreeViewer && viewer
.doGetColumnCount() == 0;
@@ -54,22 +56,25 @@ public abstract class CellLabelProvider extends BaseLabelProvider {
if (!noColumnTreeViewer
&& (labelProvider instanceof ITableLabelProvider
|| labelProvider instanceof ITableColorProvider || labelProvider instanceof ITableFontProvider))
- return new TableColumnViewerLabelProvider(labelProvider);
- if (labelProvider instanceof CellLabelProvider)
- return (CellLabelProvider) labelProvider;
- return new WrappedViewerLabelProvider(labelProvider);
+ return new TableColumnViewerLabelProvider<E,I>(labelProvider);
+ if (labelProvider instanceof CellLabelProvider) {
+ @SuppressWarnings("unchecked")
+ CellLabelProvider<E, I> cellLabelProvider = (CellLabelProvider<E, I>) labelProvider;
+ return cellLabelProvider;
+ }
+ return new WrappedViewerLabelProvider<E,I>(labelProvider);
}
/**
* Get the image displayed in the tool tip for object.
- *
+ *
* <p>
* <b>If {@link #getToolTipText(Object)} and
* {@link #getToolTipImage(Object)} both return <code>null</code> the
* control is set back to standard behavior</b>
* </p>
- *
+ *
* @param object
* the element for which the tool tip is shown
* @return {@link Image} or <code>null</code> if there is not image.
@@ -81,58 +86,58 @@ public abstract class CellLabelProvider extends BaseLabelProvider {
/**
* Get the text displayed in the tool tip for object.
- *
+ *
* <p>
* <b>If {@link #getToolTipText(Object)} and
* {@link #getToolTipImage(Object)} both return <code>null</code> the
* control is set back to standard behavior</b>
* </p>
- *
+ *
* @param element
* the element for which the tool tip is shown
* @return the {@link String} or <code>null</code> if there is not text to
* display
*/
- public String getToolTipText(Object element) {
+ public String getToolTipText(E element) {
return null;
}
/**
* Return the background color used for the tool tip
- *
+ *
* @param object
* the {@link Object} for which the tool tip is shown
- *
+ *
* @return the {@link Color} used or <code>null</code> if you want to use
* the default color {@link SWT#COLOR_INFO_BACKGROUND}
* @see SWT#COLOR_INFO_BACKGROUND
*/
- public Color getToolTipBackgroundColor(Object object) {
+ public Color getToolTipBackgroundColor(E object) {
return null;
}
/**
* The foreground color used to display the the text in the tool tip
- *
+ *
* @param object
* the {@link Object} for which the tool tip is shown
* @return the {@link Color} used or <code>null</code> if you want to use
* the default color {@link SWT#COLOR_INFO_FOREGROUND}
* @see SWT#COLOR_INFO_FOREGROUND
*/
- public Color getToolTipForegroundColor(Object object) {
+ public Color getToolTipForegroundColor(E object) {
return null;
}
/**
* Get the {@link Font} used to display the tool tip
- *
+ *
* @param object
* the element for which the tool tip is shown
* @return {@link Font} or <code>null</code> if the default font is to be
* used.
*/
- public Font getToolTipFont(Object object) {
+ public Font getToolTipFont(E object) {
return null;
}
@@ -142,13 +147,13 @@ public abstract class CellLabelProvider extends BaseLabelProvider {
* below your mouse cursor. Be aware of the fact that you should at least
* position the tool tip 1px right to your mouse cursor else click events
* may not get propagated properly.
- *
+ *
* @param object
* the element for which the tool tip is shown
* @return {@link Point} to shift of the tool tip or <code>null</code> if the
* default shift should be used.
*/
- public Point getToolTipShift(Object object) {
+ public Point getToolTipShift(E object) {
return null;
}
@@ -156,7 +161,7 @@ public abstract class CellLabelProvider extends BaseLabelProvider {
* Return whether or not to use the native tool tip. If you switch to native
* tool tips only the value from {@link #getToolTipText(Object)} is used all
* other features from custom tool tips are not supported.
- *
+ *
* <p>
* To reset the control to native behavior you should return
* <code>true</code> from this method and <code>null</code> from
@@ -164,90 +169,90 @@ public abstract class CellLabelProvider extends BaseLabelProvider {
* {@link #getToolTipText(Object)} and {@link #getToolTipImage(Object)} at
* the same time
* </p>
- *
+ *
* @param object
* the {@link Object} for which the tool tip is shown
* @return <code>true</code> if native tool tips should be used
*/
- public boolean useNativeToolTip(Object object) {
+ public boolean useNativeToolTip(E object) {
return false;
}
/**
* The time in milliseconds the tool tip is shown for.
- *
+ *
* @param object
* the {@link Object} for which the tool tip is shown
* @return time in milliseconds the tool tip is shown for
*/
- public int getToolTipTimeDisplayed(Object object) {
+ public int getToolTipTimeDisplayed(E object) {
return 0;
}
/**
* The time in milliseconds until the tool tip is displayed.
- *
+ *
* @param object
* the {@link Object} for which the tool tip is shown
* @return time in milliseconds until the tool tip is displayed
*/
- public int getToolTipDisplayDelayTime(Object object) {
+ public int getToolTipDisplayDelayTime(E object) {
return 0;
}
/**
* The {@link SWT} style used to create the {@link CLabel} (see there for
* supported styles). By default {@link SWT#SHADOW_NONE} is used.
- *
+ *
* @param object
* the element for which the tool tip is shown
* @return the style used to create the label
* @see CLabel
*/
- public int getToolTipStyle(Object object) {
+ public int getToolTipStyle(E object) {
return SWT.SHADOW_NONE;
}
/**
* Update the label for cell.
- *
+ *
* @param cell
* {@link ViewerCell}
*/
- public abstract void update(ViewerCell cell);
-
+ public abstract void update(ViewerCell<E> cell);
+
/**
* Initialize this label provider for use with the given column viewer for
* the given column. Subclasses may extend but should call the super
* implementation (which at this time is empty but may be changed in the
* future).
- *
+ *
* @param viewer
* the viewer
* @param column
* the column, or <code>null</code> if a column is not
* available.
- *
+ *
* @since 3.4
*/
- protected void initialize(ColumnViewer viewer, ViewerColumn column) {
+ protected void initialize(ColumnViewer<E,I> viewer, ViewerColumn<E,I> column) {
}
/**
* Dispose of this label provider which was used with the given column
* viewer and column. Subclasses may extend but should call the super
* implementation (which calls {@link #dispose()}).
- *
+ *
* @param viewer
* the viewer
* @param column
* the column, or <code>null</code> if a column is not
* available.
- *
+ *
* @since 3.4
*/
- public void dispose(ColumnViewer viewer, ViewerColumn column) {
+ public void dispose(ColumnViewer<E,I> viewer, ViewerColumn<E,I> column) {
dispose();
}
-
+
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnLabelProvider.java
index bcbf0a1..c4d1d52 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ColumnLabelProvider.java
@@ -19,21 +19,23 @@ import org.eclipse.swt.graphics.Image;
* The ColumnLabelProvider is the label provider for viewers
* that have column support such as {@link TreeViewer} and
* {@link TableViewer}
- *
+ *
* <p><b>This classes is intended to be subclassed</b></p>
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
*
*/
-public class ColumnLabelProvider extends CellLabelProvider implements
- IFontProvider, IColorProvider, ILabelProvider {
+public class ColumnLabelProvider<E,I> extends CellLabelProvider<E,I> implements
+ IFontProvider<E>, IColorProvider<E>, ILabelProvider<E> {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
*/
@Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
+ public void update(ViewerCell<E> cell) {
+ E element = cell.getElement();
cell.setText(getText(element));
Image image = getImage(element);
cell.setImage(image);
@@ -46,21 +48,21 @@ public class ColumnLabelProvider extends CellLabelProvider implements
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
*/
- public Font getFont(Object element) {
+ public Font getFont(E element) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
*/
- public Color getBackground(Object element) {
+ public Color getBackground(E element) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
*/
- public Color getForeground(Object element) {
+ public Color getForeground(E element) {
return null;
}
@@ -68,14 +70,14 @@ public class ColumnLabelProvider extends CellLabelProvider implements
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
- public Image getImage(Object element) {
+ public Image getImage(E element) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
- public String getText(Object element) {
+ public String getText(E element) {
return element == null ? "" : element.toString();//$NON-NLS-1$
}
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 161ff85..68e97ec 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
@@ -21,11 +21,9 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Widget;
-
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-
import org.eclipse.jface.internal.InternalPolicy;
import org.eclipse.jface.util.Policy;
@@ -34,14 +32,16 @@ import org.eclipse.jface.util.Policy;
* (e.g., AbstractTreeViewer and AbstractTableViewer). Concrete subclasses of
* {@link ColumnViewer} should implement a matching concrete subclass of {@link
* ViewerColumn}.
- *
+ *
* <strong> This class is not intended to be subclassed outside of the JFace
* viewers framework.</strong>
- *
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
- *
+ *
*/
-public abstract class ColumnViewer extends StructuredViewer {
+public abstract class ColumnViewer<E,I> extends StructuredViewer<E,I> {
private CellEditor[] cellEditors;
private ICellModifier cellModifier;
@@ -51,7 +51,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* The cell is a cached viewer cell used for refreshing.
*/
- private ViewerCell cell = new ViewerCell(null, 0, null);
+ private ViewerCell<E> cell = new ViewerCell<E>(null, 0, null);
private ColumnViewerEditor viewerEditor;
@@ -79,7 +79,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Hook up the editing support. Subclasses may override.
- *
+ *
* @param control
* the control you want to hook on
*/
@@ -110,7 +110,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Creates the viewer editor used for editing cell contents. To be
* implemented by subclasses.
- *
+ *
* @return the editor, or <code>null</code> if this viewer does not support
* editing cell contents.
*/
@@ -119,16 +119,16 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns the viewer cell at the given widget-relative coordinates, or
* <code>null</code> if there is no cell at that location
- *
+ *
* @param point
* the widget-relative coordinates
* @return the cell or <code>null</code> if no cell is found at the given
* point
- *
+ *
* @since 3.4
*/
- public ViewerCell getCell(Point point) {
- ViewerRow row = getViewerRow(point);
+ public ViewerCell<E> getCell(Point point) {
+ ViewerRow<E> row = getViewerRow(point);
if (row != null) {
return row.getCell(point);
}
@@ -138,13 +138,13 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns the viewer row at the given widget-relative coordinates.
- *
+ *
* @param point
* the widget-relative coordinates of the viewer row
* @return ViewerRow the row or <code>null</code> if no row is found at the
* given coordinates
*/
- protected ViewerRow getViewerRow(Point point) {
+ protected ViewerRow<E> getViewerRow(Point point) {
Item item = getItemAt(point);
if (item != null) {
@@ -159,16 +159,16 @@ public abstract class ColumnViewer extends StructuredViewer {
* Implementations may re-use the same instance for different row widgets;
* callers can only use the viewer row locally and until the next call to
* this method.
- *
+ *
* @param item
* the row widget
* @return ViewerRow a viewer row object
*/
- protected abstract ViewerRow getViewerRowFromItem(Widget item);
+ protected abstract ViewerRow<E> getViewerRowFromItem(Widget item);
/**
* Returns the column widget at the given column index.
- *
+ *
* @param columnIndex
* the column index
* @return Widget the column widget
@@ -177,27 +177,26 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns the viewer column for the given column index.
- *
+ *
* @param columnIndex
* the column index
* @return the viewer column at the given index, or <code>null</code> if
* there is none for the given index
*/
- /* package */ViewerColumn getViewerColumn(final int columnIndex) {
+ /* package */ViewerColumn<E,I> getViewerColumn(final int columnIndex) {
- ViewerColumn viewer;
Widget columnOwner = getColumnViewerOwner(columnIndex);
if (columnOwner == null || columnOwner.isDisposed()) {
return null;
}
-
- viewer = (ViewerColumn) columnOwner
+ @SuppressWarnings("unchecked")
+ ViewerColumn<E, I> viewer = (ViewerColumn<E, I>) columnOwner
.getData(ViewerColumn.COLUMN_VIEWER_KEY);
-
if (viewer == null) {
- viewer = createViewerColumn(columnOwner, CellLabelProvider
- .createViewerLabelProvider(this, getLabelProvider()));
+ viewer = createViewerColumn(columnOwner,
+ CellLabelProvider.createViewerLabelProvider(this,
+ getLabelProvider()));
setupEditingSupport(columnIndex, viewer);
}
@@ -211,17 +210,17 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Sets up editing support for the given column based on the "old" cell
* editor API.
- *
+ *
* @param columnIndex
* @param viewer
*/
- private void setupEditingSupport(final int columnIndex, ViewerColumn viewer) {
+ private void setupEditingSupport(final int columnIndex, ViewerColumn<E,I> viewer) {
if (getCellModifier() != null) {
viewer.setEditingSupport(new EditingSupport(this) {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang
* .Object)
@@ -240,7 +239,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.jface.viewers.EditingSupport#getCellEditor(java
* .lang.Object)
@@ -256,7 +255,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.jface.viewers.EditingSupport#getValue(java.lang
* .Object)
@@ -275,7 +274,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.jface.viewers.EditingSupport#setValue(java.lang
* .Object, java.lang.Object)
@@ -285,7 +284,9 @@ public abstract class ColumnViewer extends StructuredViewer {
Object[] properties = getColumnProperties();
if (columnIndex < properties.length) {
- getCellModifier().modify(findItem(element),
+ @SuppressWarnings("unchecked")
+ E castedElement = (E)element;
+ getCellModifier().modify(findItem(castedElement),
(String) getColumnProperties()[columnIndex],
value);
}
@@ -302,16 +303,16 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Creates a generic viewer column for the given column widget, based on the
* given label provider.
- *
+ *
* @param columnOwner
* the column widget
* @param labelProvider
* the label provider to use for the column
* @return ViewerColumn the viewer column
*/
- private ViewerColumn createViewerColumn(Widget columnOwner,
- CellLabelProvider labelProvider) {
- ViewerColumn column = new ViewerColumn(this, columnOwner) {
+ private ViewerColumn<E,I> createViewerColumn(Widget columnOwner,
+ CellLabelProvider<E,I> labelProvider) {
+ ViewerColumn<E,I> column = new ViewerColumn<E,I>(this, columnOwner) {
};
column.setLabelProvider(labelProvider, false);
return column;
@@ -319,13 +320,13 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Update the cached cell object with the given row and column.
- *
+ *
* @param rowItem
* @param column
* @return ViewerCell
*/
- /* package */ViewerCell updateCell(ViewerRow rowItem, int column,
- Object element) {
+ /* package */ViewerCell<E> updateCell(ViewerRow<E> rowItem, int column,
+ E element) {
cell.update(rowItem, column, element);
return cell;
}
@@ -333,7 +334,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns the {@link Item} at the given widget-relative coordinates, or
* <code>null</code> if there is no item at the given coordinates.
- *
+ *
* @param point
* the widget-relative coordinates
* @return the {@link Item} at the coordinates or <code>null</code> if there
@@ -343,7 +344,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.StructuredViewer#getItem(int, int)
*/
@Override
@@ -370,10 +371,10 @@ public abstract class ColumnViewer extends StructuredViewer {
* may also implement {@link IColorProvider} and/or {@link IFontProvider} to
* provide colors and/or fonts.
* </p>
- *
+ *
*/
@Override
- public void setLabelProvider(IBaseLabelProvider labelProvider) {
+ public void setLabelProvider(IBaseLabelProvider<E> labelProvider) {
Assert.isTrue(labelProvider instanceof ITableLabelProvider
|| labelProvider instanceof ILabelProvider
|| labelProvider instanceof CellLabelProvider);
@@ -381,14 +382,18 @@ public abstract class ColumnViewer extends StructuredViewer {
// columns
super.setLabelProvider(labelProvider);
if (labelProvider instanceof CellLabelProvider) {
- ((CellLabelProvider) labelProvider).initialize(this, null);
+ @SuppressWarnings("unchecked")
+ CellLabelProvider<E,I> cellLabelProvider = (CellLabelProvider<E,I>) labelProvider;
+ cellLabelProvider.initialize(this, null);
}
}
@Override
- void internalDisposeLabelProvider(IBaseLabelProvider oldProvider) {
+ void internalDisposeLabelProvider(IBaseLabelProvider<E> oldProvider) {
if (oldProvider instanceof CellLabelProvider) {
- ((CellLabelProvider) oldProvider).dispose(this, null);
+ @SuppressWarnings("unchecked")
+ CellLabelProvider<E,I> cellLabelProvider = (CellLabelProvider<E,I>) oldProvider;
+ cellLabelProvider.dispose(this, null);
} else {
super.internalDisposeLabelProvider(oldProvider);
}
@@ -397,8 +402,8 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Clear the viewer parts for the columns
*/
- private void updateColumnParts(IBaseLabelProvider labelProvider) {
- ViewerColumn column;
+ private void updateColumnParts(IBaseLabelProvider<E> labelProvider) {
+ ViewerColumn<E,I> column;
int i = 0;
while ((column = getViewerColumn(i++)) != null) {
@@ -410,7 +415,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Cancels a currently active cell editor if one is active. All changes
* already done in the cell editor are lost.
- *
+ *
* @since 3.1 (in subclasses, added in 3.3 to abstract class)
*/
public void cancelEditing() {
@@ -421,7 +426,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Apply the value of the active cell editor if one is active.
- *
+ *
* @since 3.3
*/
protected void applyEditorValue() {
@@ -432,14 +437,14 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Starts editing the given element at the given column index.
- *
+ *
* @param element
* the model element
* @param column
* the column index
* @since 3.1 (in subclasses, added in 3.3 to abstract class)
*/
- public void editElement(Object element, int column) {
+ public void editElement(E element, int column) {
if (viewerEditor != null) {
try {
getControl().setRedraw(false);
@@ -449,9 +454,9 @@ public abstract class ColumnViewer extends StructuredViewer {
Widget item = findItem(element);
if (item != null) {
- ViewerRow row = getViewerRowFromItem(item);
+ ViewerRow<E> row = getViewerRowFromItem(item);
if (row != null) {
- ViewerCell cell = row.getCell(column);
+ ViewerCell<E> cell = row.getCell(column);
if (cell != null) {
triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
cell));
@@ -472,8 +477,8 @@ public abstract class ColumnViewer extends StructuredViewer {
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
* of editing values in a column viewer.
* </p>
- *
- *
+ *
+ *
* @return CellEditor[]
* @since 3.1 (in subclasses, added in 3.3 to abstract class)
* @see ViewerColumn#setEditingSupport(EditingSupport)
@@ -486,13 +491,13 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns the cell modifier of this viewer, or <code>null</code> if none
* has been set.
- *
+ *
* <p>
* Since 3.3, an alternative API is available, see {@link
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
* of editing values in a column viewer.
* </p>
- *
+ *
* @return the cell modifier, or <code>null</code>
* @since 3.1 (in subclasses, added in 3.3 to abstract class)
* @see ViewerColumn#setEditingSupport(EditingSupport)
@@ -506,13 +511,13 @@ public abstract class ColumnViewer extends StructuredViewer {
* Returns the column properties of this table viewer. The properties must
* correspond with the columns of the table control. They are used to
* identify the column in a cell modifier.
- *
+ *
* <p>
* Since 3.3, an alternative API is available, see {@link
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
* of editing values in a column viewer.
* </p>
- *
+ *
* @return the list of column properties
* @since 3.1 (in subclasses, added in 3.3 to abstract class)
* @see ViewerColumn#setEditingSupport(EditingSupport)
@@ -524,13 +529,13 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns whether there is an active cell editor.
- *
+ *
* <p>
* Since 3.3, an alternative API is available, see {@link
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
* of editing values in a column viewer.
* </p>
- *
+ *
* @return <code>true</code> if there is an active cell editor, and
* <code>false</code> otherwise
* @since 3.1 (in subclasses, added in 3.3 to abstract class)
@@ -569,7 +574,7 @@ public abstract class ColumnViewer extends StructuredViewer {
}
@Override
- public void update(Object element, String[] properties) {
+ public void update(E element, String[] properties) {
if (checkBusy())
return;
super.update(element, properties);
@@ -578,7 +583,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Sets the cell editors of this column viewer. If editing is not supported
* by this viewer the call simply has no effect.
- *
+ *
* <p>
* Since 3.3, an alternative API is available, see {@link
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
@@ -601,7 +606,7 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Sets the cell modifier for this column viewer. This method does nothing
* if editing is not supported by this viewer.
- *
+ *
* <p>
* Since 3.3, an alternative API is available, see {@link
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
@@ -626,7 +631,7 @@ public abstract class ColumnViewer extends StructuredViewer {
* correspond with the columns of the control. They are used to identify the
* column in a cell modifier. If editing is not supported by this viewer the
* call simply has no effect.
- *
+ *
* <p>
* Since 3.3, an alternative API is available, see {@link
* ViewerColumn#setEditingSupport(EditingSupport)} for a more flexible way
@@ -652,9 +657,9 @@ public abstract class ColumnViewer extends StructuredViewer {
* visually, one column of items may be visible. This occurs when the
* programmer uses the column viewer like a list, adding elements but never
* creating a column.
- *
+ *
* @return the number of columns
- *
+ *
* @since 3.3
*/
protected abstract int doGetColumnCount();
@@ -662,16 +667,16 @@ public abstract class ColumnViewer extends StructuredViewer {
/**
* Returns the label provider associated with the column at the given index
* or <code>null</code> if no column with this index is known.
- *
+ *
* @param columnIndex
* the column index
* @return the label provider associated with the column or
* <code>null</code> if no column with this index is known
- *
+ *
* @since 3.3
*/
- public CellLabelProvider getLabelProvider(int columnIndex) {
- ViewerColumn column = getViewerColumn(columnIndex);
+ public CellLabelProvider<E,I> getLabelProvider(int columnIndex) {
+ ViewerColumn<E,I> column = getViewerColumn(columnIndex);
if (column != null) {
return column.getLabelProvider();
}
@@ -679,7 +684,7 @@ public abstract class ColumnViewer extends StructuredViewer {
}
private void handleMouseDown(MouseEvent e) {
- ViewerCell cell = getCell(new Point(e.x, e.y));
+ ViewerCell<E> cell = getCell(new Point(e.x, e.y));
if (cell != null) {
triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(
@@ -704,7 +709,7 @@ public abstract class ColumnViewer extends StructuredViewer {
* enable the editor but before this event is passed to {@link
* ColumnViewerEditorActivationStrategy} to see if this event should really
* trigger editor activation
- *
+ *
* @param event
* the activation event
*/
@@ -730,7 +735,7 @@ public abstract class ColumnViewer extends StructuredViewer {
}
@Override
- protected Object[] getRawChildren(Object parent) {
+ protected E[] getRawChildren(I parent) {
boolean oldBusy = isBusy();
setBusy(true);
try {
@@ -747,7 +752,8 @@ public abstract class ColumnViewer extends StructuredViewer {
for (int i = 0; i < count || i == 0; i++) {
Widget owner = getColumnViewerOwner(i);
if (owner != null && !owner.isDisposed()) {
- ViewerColumn column = (ViewerColumn) owner
+ @SuppressWarnings("unchecked")
+ ViewerColumn<E,I> column = (ViewerColumn<E,I>) owner
.getData(ViewerColumn.COLUMN_VIEWER_KEY);
if (column != null) {
EditingSupport e = column.getEditingSupport();
@@ -773,13 +779,13 @@ public abstract class ColumnViewer extends StructuredViewer {
* if the viewer is busy. It is recommended that this method be used by
* subclasses to determine whether the viewer is busy to return early from
* state-changing methods.
- *
+ *
* <p>
* This method is not intended to be overridden by subclasses.
* </p>
- *
+ *
* @return <code>true</code> if the viewer is busy.
- *
+ *
* @since 3.4
*/
protected boolean checkBusy() {
@@ -805,7 +811,7 @@ public abstract class ColumnViewer extends StructuredViewer {
* Sets the busy state of this viewer. Subclasses MUST use <code>try</code>
* ...<code>finally</code> as follows to ensure that the busy flag is reset
* to its original value:
- *
+ *
* <pre>
* boolean oldBusy = isBusy();
* setBusy(true);
@@ -815,14 +821,14 @@ public abstract class ColumnViewer extends StructuredViewer {
* setBusy(oldBusy);
* }
* </pre>
- *
+ *
* <p>
* This method is not intended to be overridden by subclasses.
* </p>
- *
+ *
* @param busy
* the new value of the busy flag
- *
+ *
* @since 3.4
*/
protected void setBusy(boolean busy) {
@@ -838,13 +844,13 @@ public abstract class ColumnViewer extends StructuredViewer {
* method if they can ensure by other means that they will not make
* reentrant calls to methods like the ones listed above. See bug 184991 for
* background discussion.
- *
+ *
* <p>
* This method is not intended to be overridden by subclasses.
* </p>
- *
+ *
* @return Returns whether this viewer is busy.
- *
+ *
* @since 3.4
*/
public boolean isBusy() {
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IColorProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IColorProvider.java
index a58efac..d36bb5d 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IColorProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IColorProvider.java
@@ -15,25 +15,26 @@ import org.eclipse.swt.graphics.Color;
/**
* Interface to provide color representation for a given element.
+ * @param <E> Type of an element of the model
* @see org.eclipse.jface.viewers.IColorDecorator
*/
-public interface IColorProvider {
+public interface IColorProvider<E> {
/**
* Provides a foreground color for the given element.
- *
+ *
* @param element the element
- * @return the foreground color for the element, or <code>null</code>
+ * @return the foreground color for the element, or <code>null</code>
* to use the default foreground color
*/
- Color getForeground(Object element);
+ Color getForeground(E element);
/**
* Provides a background color for the given element.
- *
+ *
* @param element the element
- * @return the background color for the element, or <code>null</code>
+ * @return the background color for the element, or <code>null</code>
* to use the default background color
*/
- Color getBackground(Object element);
+ Color getBackground(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IFontProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IFontProvider.java
index 8e19ab4..48005a2 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IFontProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IFontProvider.java
@@ -14,18 +14,19 @@ import org.eclipse.swt.graphics.Font;
/**
* Interface to provide font representation for a given element.
+ * @param <E> Type of an element of the model
* @see org.eclipse.jface.viewers.IFontDecorator
- *
+ *
* @since 3.0
*/
-public interface IFontProvider {
+public interface IFontProvider<E> {
/**
* Provides a font for the given element.
- *
+ *
* @param element the element
- * @return the font for the element, or <code>null</code>
+ * @return the font for the element, or <code>null</code>
* to use the default font
*/
- public Font getFont(Object element);
+ public Font getFont(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IViewerLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IViewerLabelProvider.java
index 97f9767..f1f6fa8 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IViewerLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IViewerLabelProvider.java
@@ -12,28 +12,29 @@ package org.eclipse.jface.viewers;
/**
* Extends <code>IBaseLabelProvider</code> with the methods
- * to update the label for a given element. The label is represented by a
+ * to update the label for a given element. The label is represented by a
* <code>ViewerLabel</code>.
* Unlike <code>ILabelProvider</code>, this allows the text and image to be
- * set in the same request, rather than via separate requests.
+ * set in the same request, rather than via separate requests.
* <p>
- * It also allows the current values for the text and image to be considered by
+ * It also allows the current values for the text and image to be considered by
* the label provider, allowing for potential optimizations.
* For example, decorating label providers that run in the background can hold off
* applying an update to a previously populated label until the decoration is ready,
* thereby reducing flicker.
* </p>
- *
+ * @param <E> Type of an element of the model
+ *
* @see IDelayedLabelDecorator
* @since 3.0
*/
-public interface IViewerLabelProvider extends IBaseLabelProvider {
+public interface IViewerLabelProvider<E> extends IBaseLabelProvider<E> {
/**
* Updates the label for the given element.
- *
+ *
* @param label the label to update
* @param element the element
*/
- public void updateLabel(ViewerLabel label, Object element);
+ public void updateLabel(ViewerLabel label, E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java
index 7cc98ac..8229e77 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java
@@ -16,14 +16,16 @@ package org.eclipse.jface.viewers;
/**
* TableColumnViewerLabelProvider is the mapping from the table based providers
* to the ViewerLabelProvider.
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
* @see ITableLabelProvider
* @see ITableColorProvider
* @see ITableFontProvider
- *
+ *
*/
-class TableColumnViewerLabelProvider extends WrappedViewerLabelProvider {
+class TableColumnViewerLabelProvider<E,I> extends WrappedViewerLabelProvider<E,I> {
private ITableLabelProvider tableLabelProvider;
@@ -33,14 +35,14 @@ class TableColumnViewerLabelProvider extends WrappedViewerLabelProvider {
/**
* Create a new instance of the receiver.
- *
+ *
* @param labelProvider
* instance of a table based label provider
* @see ITableLabelProvider
* @see ITableColorProvider
* @see ITableFontProvider
*/
- public TableColumnViewerLabelProvider(IBaseLabelProvider labelProvider) {
+ public TableColumnViewerLabelProvider(IBaseLabelProvider<E> labelProvider) {
super(labelProvider);
if (labelProvider instanceof ITableLabelProvider)
@@ -59,9 +61,9 @@ class TableColumnViewerLabelProvider extends WrappedViewerLabelProvider {
* @see org.eclipse.jface.viewers.WrappedViewerLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
*/
@Override
- public void update(ViewerCell cell) {
+ public void update(ViewerCell<E> cell) {
- Object element = cell.getElement();
+ E element = cell.getElement();
int index = cell.getColumnIndex();
if (tableLabelProvider == null) {
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java
index f906a12..18116fa 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java
@@ -56,13 +56,15 @@ import org.eclipse.swt.widgets.Widget;
* Users setting up an editable table 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
+ *
* @see SWT#VIRTUAL
* @see #doFindItem(Object)
* @see #internalRefresh(Object, boolean)
* @noextend This class is not intended to be subclassed by clients.
*/
-public class TableViewer extends AbstractTableViewer {
+public class TableViewer<E,I> extends AbstractTableViewer<E,I> {
/**
* This viewer's table control.
*/
@@ -71,7 +73,7 @@ public class TableViewer extends AbstractTableViewer {
/**
* The cached row which is reused all over
*/
- private TableViewerRow cachedRow;
+ private TableViewerRow<E> cachedRow;
/**
* Creates a table viewer on a newly-created table control under the given
@@ -79,7 +81,7 @@ public class TableViewer extends AbstractTableViewer {
* <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
* viewer has no input, no content provider, a default label provider, no
* sorter, and no filters. The table has no columns.
- *
+ *
* @param parent
* the parent control
*/
@@ -92,7 +94,7 @@ public class TableViewer extends AbstractTableViewer {
* parent. The table control is created using the given style bits. The
* viewer has no input, no content provider, a default label provider, no
* sorter, and no filters. The table has no columns.
- *
+ *
* @param parent
* the parent control
* @param style
@@ -106,7 +108,7 @@ public class TableViewer extends AbstractTableViewer {
* Creates a table viewer on the given table control. The viewer has no
* input, no content provider, a default label provider, no sorter, and no
* filters.
- *
+ *
* @param table
* the table control
*/
@@ -122,7 +124,7 @@ public class TableViewer extends AbstractTableViewer {
/**
* Returns this table viewer's table control.
- *
+ *
* @return the table control
*/
public Table getTable() {
@@ -147,7 +149,7 @@ public class TableViewer extends AbstractTableViewer {
* Use Table#setSelection(int[] indices) and Table#showSelection() if you
* wish to set selection more efficiently when using a ILazyContentProvider.
* </p>
- *
+ *
* @param selection
* the new selection
* @param reveal
@@ -162,9 +164,9 @@ public class TableViewer extends AbstractTableViewer {
}
@Override
- protected ViewerRow getViewerRowFromItem(Widget item) {
+ protected ViewerRow<E> getViewerRowFromItem(Widget item) {
if (cachedRow == null) {
- cachedRow = new TableViewerRow((TableItem) item);
+ cachedRow = new TableViewerRow<E>((TableItem) item);
} else {
cachedRow.setItem((TableItem) item);
}
@@ -174,14 +176,14 @@ public class TableViewer extends AbstractTableViewer {
/**
* Create a new row with style at index
- *
+ *
* @param style
* @param rowIndex
* @return ViewerRow
* @since 3.3
*/
@Override
- protected ViewerRow internalCreateNewRowPart(int style, int rowIndex) {
+ protected ViewerRow<E> internalCreateNewRowPart(int style, int rowIndex) {
TableItem item;
if (rowIndex >= 0) {
@@ -339,12 +341,12 @@ public class TableViewer extends AbstractTableViewer {
* given element needs updating, it is more efficient to use the
* <code>update</code> methods.
* </p>
- *
+ *
* <p>
* Subclasses who can provide this feature can open this method for the
* public
* </p>
- *
+ *
* @param element
* the element
* @param updateLabels
@@ -353,7 +355,7 @@ public class TableViewer extends AbstractTableViewer {
* for existing elements are unchanged.
* @param reveal
* <code>true</code> to make the preserved selection visible afterwards
- *
+ *
* @since 3.3
*/
public void refresh(final Object element, final boolean updateLabels,
@@ -385,25 +387,25 @@ public class TableViewer extends AbstractTableViewer {
* 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.
* @param reveal
* <code>true</code> to make the preserved selection visible afterwards
- *
+ *
* @since 3.3
*/
public void refresh(boolean updateLabels, boolean reveal) {
refresh(getRoot(), updateLabels, reveal);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.AbstractTableViewer#remove(java.lang.Object[])
*/
@Override
- public void remove(Object[] elements) {
+ public void remove(E[] elements) {
assertElementsNotNull(elements);
if (checkBusy())
return;
@@ -414,13 +416,13 @@ public class TableViewer extends AbstractTableViewer {
// deselect any items that are being removed, see bug 97786
boolean deselectedItems = false;
Object elementToBeRemoved = null;
- CustomHashtable elementsToBeRemoved = null;
+ CustomHashtable<E,E> elementsToBeRemoved = null;
if (elements.length == 1) {
elementToBeRemoved = elements[0];
} else {
- elementsToBeRemoved = new CustomHashtable(getComparer());
+ elementsToBeRemoved = new CustomHashtable<E,E>(getComparer());
for (int i = 0; i < elements.length; i++) {
- Object element = elements[i];
+ E element = elements[i];
elementsToBeRemoved.put(element, element);
}
}
@@ -428,7 +430,8 @@ public class TableViewer extends AbstractTableViewer {
for (int i = 0; i < selectionIndices.length; i++) {
int index = selectionIndices[i];
Item item = doGetItem(index);
- Object data = item.getData();
+ @SuppressWarnings("unchecked")
+ E data = (E) item.getData();
if (data != null) {
if ((elementsToBeRemoved != null && elementsToBeRemoved
.containsKey(data))
@@ -446,10 +449,10 @@ public class TableViewer extends AbstractTableViewer {
firePostSelectionChanged(new SelectionChangedEvent(this, sel));
}
}
-
+
@Override
- protected Widget doFindItem(Object element) {
- IContentProvider contentProvider = getContentProvider();
+ protected Widget doFindItem(E element) {
+ IContentProvider<I> contentProvider = getContentProvider();
if (contentProvider instanceof IIndexableLazyContentProvider) {
IIndexableLazyContentProvider indexable = (IIndexableLazyContentProvider) contentProvider;
int idx = indexable.findElement(element);
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerColumn.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerColumn.java
index 814634c..1ce92c0 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerColumn.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerColumn.java
@@ -18,10 +18,12 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* ViewerColumn implementation for TableViewer 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 TableViewerColumn extends ViewerColumn {
+public final class TableViewerColumn<E,I> extends ViewerColumn<E,I> {
private TableColumn column;
/**
@@ -36,7 +38,7 @@ public final class TableViewerColumn extends ViewerColumn {
* see {@link TableColumn}
* @see TableColumn#TableColumn(Table, int)
*/
- public TableViewerColumn(TableViewer viewer, int style) {
+ public TableViewerColumn(TableViewer<E,I> viewer, int style) {
this(viewer, style, -1);
}
@@ -54,7 +56,7 @@ public final class TableViewerColumn extends ViewerColumn {
* the index at which to place the newly created column
* @see TableColumn#TableColumn(Table, int, int)
*/
- public TableViewerColumn(TableViewer viewer, int style, int index) {
+ public TableViewerColumn(TableViewer<E,I> viewer, int style, int index) {
this(viewer, createColumn(viewer.getTable(), style, index));
}
@@ -67,7 +69,7 @@ public final class TableViewerColumn extends ViewerColumn {
* @param column
* the underlying table column
*/
- public TableViewerColumn(TableViewer viewer, TableColumn column) {
+ public TableViewerColumn(TableViewer<E,I> viewer, TableColumn column) {
super(viewer, column);
this.column = column;
}
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 939e847..303cceb 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
@@ -23,10 +23,11 @@ import org.eclipse.swt.widgets.Widget;
/**
* TableViewerRow is the Table specific implementation of ViewerRow
+ * @param <E> Type of an single element of the model
* @since 3.3
*
*/
-public class TableViewerRow extends ViewerRow {
+public class TableViewerRow<E> extends ViewerRow<E> {
private TableItem item;
/**
@@ -165,7 +166,7 @@ public class TableViewerRow extends ViewerRow {
}
@Override
- public ViewerRow getNeighbor(int direction, boolean sameLevel) {
+ public ViewerRow<E> getNeighbor(int direction, boolean sameLevel) {
if( direction == ViewerRow.ABOVE ) {
return getRowAbove();
} else if( direction == ViewerRow.BELOW ) {
@@ -176,24 +177,24 @@ public class TableViewerRow extends ViewerRow {
}
- private ViewerRow getRowAbove() {
+ private ViewerRow<E> getRowAbove() {
int index = item.getParent().indexOf(item) - 1;
if( index >= 0 ) {
- return new TableViewerRow(item.getParent().getItem(index));
+ return new TableViewerRow<E>(item.getParent().getItem(index));
}
return null;
}
- private ViewerRow getRowBelow() {
+ private ViewerRow<E> getRowBelow() {
int index = item.getParent().indexOf(item) + 1;
if( index < item.getParent().getItemCount() ) {
TableItem tmp = item.getParent().getItem(index);
//TODO NULL can happen in case of VIRTUAL => How do we deal with that
if( tmp != null ) {
- return new TableViewerRow(tmp);
+ return new TableViewerRow<E>(tmp);
}
}
@@ -207,12 +208,14 @@ public class TableViewerRow extends ViewerRow {
@Override
public Object clone() {
- return new TableViewerRow(item);
+ return new TableViewerRow<E>(item);
}
@Override
- public Object getElement() {
- return item.getData();
+ public E getElement() {
+ @SuppressWarnings("unchecked")
+ E element = (E)item.getData();
+ return element;
}
@Override
@@ -243,7 +246,7 @@ public class TableViewerRow extends ViewerRow {
public Rectangle getTextBounds(int index) {
return item.getTextBounds(index);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerRow#getImageBounds(int)
*/
@@ -259,19 +262,19 @@ public class TableViewerRow extends ViewerRow {
private boolean isValidOrderIndex(int currentIndex) {
return currentIndex < this.item.getParent().getColumnOrder().length;
}
-
+
@Override
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/ViewerCell.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java
index f2d4a02..f734e7f 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java
@@ -24,16 +24,17 @@ import org.eclipse.swt.widgets.Widget;
/**
* The ViewerCell is the JFace representation of a cell entry in a ViewerRow.
- *
+ * @param <E> Type of an element of the model
+ *
* @since 3.3
- *
+ *
*/
-public class ViewerCell {
+public class ViewerCell<E> {
private int columnIndex;
- private ViewerRow row;
+ private ViewerRow<E> row;
- private Object element;
+ private E element;
/**
* Constant denoting the cell above current one (value is 1).
@@ -57,11 +58,11 @@ public class ViewerCell {
/**
* Create a new instance of the receiver on the row.
- *
+ *
* @param row
* @param columnIndex
*/
- ViewerCell(ViewerRow row, int columnIndex, Object element) {
+ ViewerCell(ViewerRow<E> row, int columnIndex, E element) {
this.row = row;
this.columnIndex = columnIndex;
this.element = element;
@@ -69,7 +70,7 @@ public class ViewerCell {
/**
* Get the index of the cell.
- *
+ *
* @return the index
*/
public int getColumnIndex() {
@@ -78,7 +79,7 @@ public class ViewerCell {
/**
* Get the bounds of the cell.
- *
+ *
* @return {@link Rectangle}
*/
public Rectangle getBounds() {
@@ -87,10 +88,10 @@ public class ViewerCell {
/**
* Get the element this row represents.
- *
+ *
* @return {@link Object}
*/
- public Object getElement() {
+ public E getElement() {
if (element != null) {
return element;
}
@@ -104,7 +105,7 @@ public class ViewerCell {
/**
* Return the text for the cell.
- *
+ *
* @return {@link String}
*/
public String getText() {
@@ -113,7 +114,7 @@ public class ViewerCell {
/**
* Return the Image for the cell.
- *
+ *
* @return {@link Image} or <code>null</code>
*/
public Image getImage() {
@@ -122,7 +123,7 @@ public class ViewerCell {
/**
* Set the background color of the cell.
- *
+ *
* @param background
*/
public void setBackground(Color background) {
@@ -132,7 +133,7 @@ public class ViewerCell {
/**
* Set the foreground color of the cell.
- *
+ *
* @param foreground
*/
public void setForeground(Color foreground) {
@@ -142,7 +143,7 @@ public class ViewerCell {
/**
* Set the font of the cell.
- *
+ *
* @param font
*/
public void setFont(Font font) {
@@ -152,7 +153,7 @@ public class ViewerCell {
/**
* Set the text for the cell.
- *
+ *
* @param text
*/
public void setText(String text) {
@@ -162,7 +163,7 @@ public class ViewerCell {
/**
* Set the Image for the cell.
- *
+ *
* @param image
*/
public void setImage(Image image) {
@@ -173,10 +174,10 @@ public class ViewerCell {
/**
* Set the style ranges to be applied on the text label Note: Requires
* {@link StyledCellLabelProvider} with owner draw enabled.
- *
+ *
* @param styleRanges
* the styled ranges
- *
+ *
* @since 3.4
*/
public void setStyleRanges(StyleRange[] styleRanges) {
@@ -186,9 +187,9 @@ public class ViewerCell {
/**
* Returns the style ranges to be applied on the text label or
* <code>null</code> if no style ranges have been set.
- *
+ *
* @return styleRanges the styled ranges
- *
+ *
* @since 3.4
*/
public StyleRange[] getStyleRanges() {
@@ -197,7 +198,7 @@ public class ViewerCell {
/**
* Set the columnIndex.
- *
+ *
* @param column
*/
void setColumn(int column) {
@@ -207,11 +208,11 @@ public class ViewerCell {
/**
* Set the row to rowItem and the columnIndex to column.
- *
+ *
* @param rowItem
* @param column
*/
- void update(ViewerRow rowItem, int column, Object element) {
+ void update(ViewerRow<E> rowItem, int column, E element) {
row = rowItem;
columnIndex = column;
this.element = element;
@@ -219,7 +220,7 @@ public class ViewerCell {
/**
* Return the item for the receiver.
- *
+ *
* @return {@link Item}
*/
public Widget getItem() {
@@ -228,7 +229,7 @@ public class ViewerCell {
/**
* Get the control for this cell.
- *
+ *
* @return {@link Control}
*/
public Control getControl() {
@@ -238,7 +239,7 @@ public class ViewerCell {
/**
* Get the current index. This can be different from the original index when
* columns are reordered
- *
+ *
* @return the current index (as shown in the UI)
* @since 3.4
*/
@@ -253,7 +254,7 @@ public class ViewerCell {
* the upper-left of the current cell by passing {@link #ABOVE} |
* {@link #LEFT}. If <code>sameLevel</code> is <code>true</code>, only cells
* in sibling rows (under the same parent) will be considered.
- *
+ *
* @param directionMask
* the direction mask used to identify the requested neighbor
* cell
@@ -261,8 +262,8 @@ public class ViewerCell {
* if <code>true</code>, only consider cells from sibling rows
* @return the requested neighbor cell, or <code>null</code> if not found
*/
- public ViewerCell getNeighbor(int directionMask, boolean sameLevel) {
- ViewerRow row;
+ public ViewerCell<E> getNeighbor(int directionMask, boolean sameLevel) {
+ ViewerRow<E> row;
if ((directionMask & ABOVE) == ABOVE) {
row = this.row.getNeighbor(ViewerRow.ABOVE, sameLevel);
@@ -287,20 +288,17 @@ public class ViewerCell {
columnIndex += modifier;
if (columnIndex >= 0 && columnIndex < row.getColumnCount()) {
- ViewerCell cell = row.getCellAtVisualIndex(columnIndex);
- if (cell != null) {
- while (cell != null
- && columnIndex < row.getColumnCount() - 1
- && columnIndex > 0) {
- if (cell.isVisible()) {
- break;
- }
-
- columnIndex += modifier;
- cell = row.getCellAtVisualIndex(columnIndex);
- if (cell == null) {
- break;
- }
+ ViewerCell<E> cell = row.getCellAtVisualIndex(columnIndex);
+ while (cell != null && columnIndex < row.getColumnCount() - 1
+ && columnIndex > 0) {
+ if (cell.isVisible()) {
+ break;
+ }
+
+ columnIndex += modifier;
+ cell = row.getCellAtVisualIndex(columnIndex);
+ if (cell == null) {
+ break;
}
}
@@ -314,14 +312,14 @@ public class ViewerCell {
/**
* @return the row
*/
- public ViewerRow getViewerRow() {
+ public ViewerRow<E> getViewerRow() {
return row;
}
/**
* The location and bounds of the area where the text is drawn depends on
* various things (image displayed, control with SWT.CHECK)
- *
+ *
* @return The bounds of the of the text area. May return <code>null</code>
* if the underlying widget implementation doesn't provide this
* information
@@ -333,7 +331,7 @@ public class ViewerCell {
/**
* Returns the location and bounds of the area where the image is drawn
- *
+ *
* @return The bounds of the of the image area. May return <code>null</code>
* if the underlying widget implementation doesn't provide this
* information
@@ -345,10 +343,10 @@ public class ViewerCell {
/**
* Gets the foreground color of the cell.
- *
+ *
* @return the foreground of the cell or <code>null</code> for the default
* foreground
- *
+ *
* @since 3.4
*/
public Color getForeground() {
@@ -357,10 +355,10 @@ public class ViewerCell {
/**
* Gets the background color of the cell.
- *
+ *
* @return the background of the cell or <code>null</code> for the default
* background
- *
+ *
* @since 3.4
*/
public Color getBackground() {
@@ -369,9 +367,9 @@ public class ViewerCell {
/**
* Gets the font of the cell.
- *
+ *
* @return the font of the cell or <code>null</code> for the default font
- *
+ *
* @since 3.4
*/
public Font getFont() {
@@ -380,7 +378,7 @@ public class ViewerCell {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -394,7 +392,7 @@ public class ViewerCell {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -405,7 +403,8 @@ public class ViewerCell {
return false;
if (getClass() != obj.getClass())
return false;
- final ViewerCell other = (ViewerCell) obj;
+ @SuppressWarnings("unchecked")
+ final ViewerCell<E> other = (ViewerCell<E>) obj;
if (columnIndex != other.columnIndex)
return false;
if (row == null) {
@@ -422,7 +421,7 @@ public class ViewerCell {
/**
* Scroll the cell into view
- *
+ *
* @return true if the cell was scrolled into view
* @since 3.5
*/
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerColumn.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerColumn.java
index dbe10ac..0b790cb 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerColumn.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerColumn.java
@@ -25,13 +25,15 @@ import org.eclipse.swt.widgets.Widget;
* providers and editing support can be configured for each column separately.
* Concrete subclasses of {@link ColumnViewer} should implement a matching
* concrete subclass of {@link ViewerColumn}.
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
- *
+ *
*/
-public abstract class ViewerColumn {
+public abstract class ViewerColumn<E,I> {
- private CellLabelProvider labelProvider;
+ private CellLabelProvider<E,I> labelProvider;
static String COLUMN_VIEWER_KEY = Policy.JFACE + ".columnViewer";//$NON-NLS-1$
@@ -41,18 +43,18 @@ public abstract class ViewerColumn {
private boolean listenerRegistered = false;
- private ColumnViewer viewer;
+ private ColumnViewer<E,I> viewer;
/**
* Create a new instance of the receiver at columnIndex.
- *
+ *
* @param viewer
* the viewer the column is part of
* @param columnOwner
* the widget owning the viewer in case the widget has no columns
* this could be the widget itself
*/
- protected ViewerColumn(final ColumnViewer viewer, Widget columnOwner) {
+ protected ViewerColumn(final ColumnViewer<E,I> viewer, Widget columnOwner) {
this.viewer = viewer;
columnOwner.setData(ViewerColumn.COLUMN_VIEWER_KEY, this);
this.listener = new ILabelProviderListener() {
@@ -71,21 +73,21 @@ public abstract class ViewerColumn {
/**
* Return the label provider for the receiver.
- *
+ *
* @return ViewerLabelProvider
*/
- /* package */CellLabelProvider getLabelProvider() {
+ /* package */CellLabelProvider<E,I> getLabelProvider() {
return labelProvider;
}
/**
* Set the label provider for the column. Subclasses may extend but must
* call the super implementation.
- *
+ *
* @param labelProvider
* the new {@link CellLabelProvider}
*/
- public void setLabelProvider(CellLabelProvider labelProvider) {
+ public void setLabelProvider(CellLabelProvider<E,I> labelProvider) {
setLabelProvider(labelProvider, true);
}
@@ -93,7 +95,7 @@ public abstract class ViewerColumn {
* @param labelProvider
* @param registerListener
*/
- /* package */void setLabelProvider(CellLabelProvider labelProvider,
+ /* package */void setLabelProvider(CellLabelProvider<E,I> labelProvider,
boolean registerListener) {
if (listenerRegistered && this.labelProvider != null) {
this.labelProvider.removeListener(listener);
@@ -114,7 +116,7 @@ public abstract class ViewerColumn {
/**
* Return the editing support for the receiver.
- *
+ *
* @return {@link EditingSupport}
*/
/* package */EditingSupport getEditingSupport() {
@@ -139,12 +141,12 @@ public abstract class ViewerColumn {
* Refresh the cell for the given columnIndex. <strong>NOTE:</strong>the
* {@link ViewerCell} provided to this method is no longer valid after this
* method returns. Do not cache the cell for future use.
- *
+ *
* @param cell
* {@link ViewerCell}
*/
- /* package */void refresh(ViewerCell cell) {
- CellLabelProvider labelProvider = getLabelProvider();
+ /* package */void refresh(ViewerCell<E> cell) {
+ CellLabelProvider<E,I> labelProvider = getLabelProvider();
if (labelProvider == null) {
Assert.isTrue(false, "Column " + cell.getColumnIndex() + //$NON-NLS-1$
" has no label provider."); //$NON-NLS-1$
@@ -160,7 +162,7 @@ public abstract class ViewerColumn {
*/
protected void handleDispose() {
boolean disposeLabelProvider = listenerRegistered;
- CellLabelProvider cellLabelProvider = labelProvider;
+ CellLabelProvider<E,I> cellLabelProvider = labelProvider;
setLabelProvider(null, false);
if (disposeLabelProvider) {
cellLabelProvider.dispose(viewer, this);
@@ -170,19 +172,19 @@ public abstract class ViewerColumn {
viewer = null;
}
- private void handleDispose(ColumnViewer viewer) {
+ private void handleDispose(ColumnViewer<E,I> viewer) {
handleDispose();
viewer.clearLegacyEditingSetup();
}
/**
* Returns the viewer of this viewer column.
- *
+ *
* @return Returns the viewer.
- *
+ *
* @since 3.4
*/
- public ColumnViewer getViewer() {
+ public ColumnViewer<E,I> getViewer() {
return viewer;
}
}
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 d60a48c..fced43d 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
@@ -27,22 +27,23 @@ import org.eclipse.swt.widgets.Widget;
* ViewerRow is the abstract superclass of the part that represents items in a
* Table or Tree. Implementors of {@link ColumnViewer} have to provide a
* concrete implementation for the underlying widget
- *
+ * @param <E> Type of an element of the model
+ *
* @since 3.3
- *
+ *
*/
-public abstract class ViewerRow implements Cloneable {
+public abstract class ViewerRow<E> implements Cloneable {
/**
* Constant denoting the row above the current one (value is 1).
- *
+ *
* @see #getNeighbor(int, boolean)
*/
public static final int ABOVE = 1;
/**
* Constant denoting the row below the current one (value is 2).
- *
+ *
* @see #getNeighbor(int, boolean)
*/
public static final int BELOW = 2;
@@ -55,7 +56,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get the bounds of the entry at the columnIndex,
- *
+ *
* @param columnIndex
* @return {@link Rectangle}
*/
@@ -63,28 +64,28 @@ public abstract class ViewerRow implements Cloneable {
/**
* Return the bounds for the whole item.
- *
+ *
* @return {@link Rectangle}
*/
public abstract Rectangle getBounds();
/**
* Return the item for the receiver.
- *
+ *
* @return {@link Widget}
*/
public abstract Widget getItem();
/**
* Return the number of columns for the receiver.
- *
+ *
* @return the number of columns
*/
public abstract int getColumnCount();
/**
* Return the image at the columnIndex.
- *
+ *
* @param columnIndex
* @return {@link Image} or <code>null</code>
*/
@@ -92,7 +93,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Set the image at the columnIndex
- *
+ *
* @param columnIndex
* @param image
*/
@@ -100,7 +101,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get the text at the columnIndex.
- *
+ *
* @param columnIndex
* @return {@link String}
*/
@@ -108,7 +109,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Set the text at the columnIndex
- *
+ *
* @param columnIndex
* @param text
*/
@@ -116,7 +117,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get the background at the columnIndex,
- *
+ *
* @param columnIndex
* @return {@link Color} or <code>null</code>
*/
@@ -124,7 +125,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Set the background at the columnIndex.
- *
+ *
* @param columnIndex
* @param color
*/
@@ -132,7 +133,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get the foreground at the columnIndex.
- *
+ *
* @param columnIndex
* @return {@link Color} or <code>null</code>
*/
@@ -140,7 +141,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Set the foreground at the columnIndex.
- *
+ *
* @param columnIndex
* @param color
*/
@@ -148,7 +149,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get the font at the columnIndex.
- *
+ *
* @param columnIndex
* @return {@link Font} or <code>null</code>
*/
@@ -156,7 +157,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Set the {@link Font} at the columnIndex.
- *
+ *
* @param columnIndex
* @param font
*/
@@ -164,19 +165,19 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get the ViewerCell at point.
- *
+ *
* @param point
* @return @return {@link ViewerCell} or <code>null</code> if the point is
* not in the bounds of a cell
*/
- public ViewerCell getCell(Point point) {
+ public ViewerCell<E> getCell(Point point) {
int index = getColumnIndex(point);
return getCell(index);
}
/**
* Get the columnIndex of the point.
- *
+ *
* @param point
* @return int or -1 if it cannot be found.
*/
@@ -199,20 +200,22 @@ public abstract class ViewerRow implements Cloneable {
/**
* Get a ViewerCell for the column at index.
- *
+ *
* @param column
* @return {@link ViewerCell} or <code>null</code> if the index is negative.
*/
- public ViewerCell getCell(int column) {
- if (column >= 0)
- return new ViewerCell((ViewerRow) clone(), column, getElement());
-
+ public ViewerCell<E> getCell(int column) {
+ if (column >= 0){
+ @SuppressWarnings("unchecked")
+ ViewerRow<E> viewerRow = (ViewerRow<E>) clone();
+ return new ViewerCell<E>(viewerRow, column, getElement());
+ }
return null;
}
/**
* Get the Control for the receiver.
- *
+ *
* @return {@link Control}
*/
public abstract Control getControl();
@@ -221,19 +224,19 @@ public abstract class ViewerRow implements Cloneable {
* Returns a neighboring row, or <code>null</code> if no neighbor exists in
* the given direction. If <code>sameLevel</code> is <code>true</code>, only
* sibling rows (under the same parent) will be considered.
- *
+ *
* @param direction
* the direction {@link #BELOW} or {@link #ABOVE}
- *
+ *
* @param sameLevel
* if <code>true</code>, search only within sibling rows
* @return the row above/below, or <code>null</code> if not found
*/
- public abstract ViewerRow getNeighbor(int direction, boolean sameLevel);
+ public abstract ViewerRow<E> getNeighbor(int direction, boolean sameLevel);
/**
* The tree path used to identify an element by the unique path
- *
+ *
* @return the path
*/
public abstract TreePath getTreePath();
@@ -244,7 +247,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* @return the model element
*/
- public abstract Object getElement();
+ public abstract E getElement();
@Override
public int hashCode() {
@@ -263,7 +266,8 @@ public abstract class ViewerRow implements Cloneable {
return false;
if (getClass() != obj.getClass())
return false;
- final ViewerRow other = (ViewerRow) obj;
+ @SuppressWarnings("unchecked")
+ final ViewerRow<E> other = (ViewerRow<E>) obj;
if (getItem() == null) {
if (other.getItem() != null)
return false;
@@ -275,12 +279,12 @@ public abstract class ViewerRow implements Cloneable {
/**
* The cell at the current index (as shown in the UI). This can be different
* to the original index when columns are reordered.
- *
+ *
* @param visualIndex
* the current index (as shown in the UI)
* @return the cell at the currently visible index
*/
- ViewerCell getCellAtVisualIndex(int visualIndex) {
+ ViewerCell<E> getCellAtVisualIndex(int visualIndex) {
return getCell(getCreationIndex(visualIndex));
}
@@ -291,7 +295,7 @@ public abstract class ViewerRow implements Cloneable {
* returns the original index. Implementators of {@link ColumnViewer} should
* overwrite this method if their widget supports reordered columns</b>
* </p>
- *
+ *
* @param creationIndex
* the original index
* @return the current index (as shown in the UI)
@@ -309,7 +313,7 @@ public abstract class ViewerRow implements Cloneable {
* returns the original index. Implementators of {@link ColumnViewer} should
* overwrite this method if their widget supports reordered columns</b>
* </p>
- *
+ *
* @param visualIndex
* the current index (as shown in the UI)
* @return the original index
@@ -322,7 +326,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* The location and bounds of the area where the text is drawn depends on
* various things (image displayed, control with SWT.CHECK)
- *
+ *
* @param index
* the column index
* @return the bounds of the of the text area. May return <code>null</code>
@@ -336,7 +340,7 @@ public abstract class ViewerRow implements Cloneable {
/**
* Returns the location and bounds of the area where the image is drawn.
- *
+ *
* @param index
* the column index
* @return the bounds of the of the image area. May return <code>null</code>
@@ -351,12 +355,12 @@ public abstract class ViewerRow implements Cloneable {
/**
* Set the style ranges to be applied on the text label at the column index
* Note: Requires {@link StyledCellLabelProvider} with owner draw enabled.
- *
+ *
* @param columnIndex
* the index of the column
* @param styleRanges
* the styled ranges
- *
+ *
* @since 3.4
*/
public void setStyleRanges(int columnIndex, StyleRange[] styleRanges) {
@@ -387,11 +391,11 @@ public abstract class ViewerRow implements Cloneable {
/**
* Returns the style ranges to be applied on the text label at the column
* index or <code>null</code> if no style ranges have been set.
- *
+ *
* @param columnIndex
* the index of the column
* @return styleRanges the styled ranges
- *
+ *
* @since 3.4
*/
public StyleRange[] getStyleRanges(int columnIndex) {
@@ -409,7 +413,7 @@ public abstract class ViewerRow implements Cloneable {
* no-op. Implementators of {@link ColumnViewer} should overwrite this
* method if their widget supports reordered columns</b>
* </p>
- *
+ *
* @param columnIndex
* the column index
* @return return <code>true</code> when the cell is scrolled into view
@@ -421,10 +425,10 @@ public abstract class ViewerRow implements Cloneable {
/**
* Returns <code>true</code> if the column with the given index is visible
- *
+ *
* @param columnIndex
* the column index
- *
+ *
* @return <code>true</code> if the column is visible
* @since 3.5
*/
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 852baf8..0fb89f4 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
@@ -20,37 +20,41 @@ import org.eclipse.swt.graphics.Image;
* The WrappedViewerLabelProvider is a label provider that allows
* {@link ILabelProvider}, {@link IColorProvider} and {@link IFontProvider} to
* be mapped to a ColumnLabelProvider.
- *
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
+ *
* @since 3.3
- *
+ *
*/
-class WrappedViewerLabelProvider extends ColumnLabelProvider {
+class WrappedViewerLabelProvider<E,I> extends ColumnLabelProvider<E,I> {
+ @SuppressWarnings("rawtypes")
private static ILabelProvider defaultLabelProvider = new LabelProvider();
- private ILabelProvider labelProvider = defaultLabelProvider;
+ @SuppressWarnings("unchecked")
+ private ILabelProvider<E> labelProvider = defaultLabelProvider;
- private IColorProvider colorProvider;
+ private IColorProvider<E> colorProvider;
- private IFontProvider fontProvider;
+ private IFontProvider<E> fontProvider;
- private IViewerLabelProvider viewerLabelProvider;
+ private IViewerLabelProvider<E> viewerLabelProvider;
private ITreePathLabelProvider treePathLabelProvider;
/**
* Create a new instance of the receiver based on labelProvider.
- *
+ *
* @param labelProvider
*/
- public WrappedViewerLabelProvider(IBaseLabelProvider labelProvider) {
+ public WrappedViewerLabelProvider(IBaseLabelProvider<E> labelProvider) {
super();
setProviders(labelProvider);
}
/**
* Set the any providers for the receiver that can be adapted from provider.
- *
+ *
* @param provider
* {@link Object}
*/
@@ -58,27 +62,39 @@ class WrappedViewerLabelProvider extends ColumnLabelProvider {
if (provider instanceof ITreePathLabelProvider)
treePathLabelProvider = ((ITreePathLabelProvider) provider);
- if (provider instanceof IViewerLabelProvider)
- viewerLabelProvider = ((IViewerLabelProvider) provider);
+ if (provider instanceof IViewerLabelProvider){
+ @SuppressWarnings("unchecked")
+ IViewerLabelProvider<E> iViewerLabelProvider = ((IViewerLabelProvider<E>) provider);
+ viewerLabelProvider = iViewerLabelProvider;
+ }
- if (provider instanceof ILabelProvider)
- labelProvider = ((ILabelProvider) provider);
+ if (provider instanceof ILabelProvider){
+ @SuppressWarnings("unchecked")
+ ILabelProvider<E> iLabelProvider = (ILabelProvider<E>) provider;
+ labelProvider = iLabelProvider;
+ }
- if (provider instanceof IColorProvider)
- colorProvider = (IColorProvider) provider;
+ if (provider instanceof IColorProvider){
+ @SuppressWarnings("unchecked")
+ IColorProvider<E> iColorProvider = (IColorProvider<E>) provider;
+ colorProvider = iColorProvider;
+ }
- if (provider instanceof IFontProvider)
- fontProvider = (IFontProvider) provider;
+ if (provider instanceof IFontProvider){
+ @SuppressWarnings("unchecked")
+ IFontProvider<E> iFontProvider = (IFontProvider<E>) provider;
+ fontProvider = iFontProvider;
+ }
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
*/
@Override
- public Font getFont(Object element) {
+ public Font getFont(E element) {
if (fontProvider == null) {
return null;
}
@@ -89,11 +105,11 @@ class WrappedViewerLabelProvider extends ColumnLabelProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
*/
@Override
- public Color getBackground(Object element) {
+ public Color getBackground(E element) {
if (colorProvider == null) {
return null;
}
@@ -103,31 +119,31 @@ class WrappedViewerLabelProvider extends ColumnLabelProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
@Override
- public String getText(Object element) {
+ public String getText(E element) {
return getLabelProvider().getText(element);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
@Override
- public Image getImage(Object element) {
+ public Image getImage(E element) {
return getLabelProvider().getImage(element);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
*/
@Override
- public Color getForeground(Object element) {
+ public Color getForeground(E element) {
if (colorProvider == null) {
return null;
}
@@ -137,34 +153,34 @@ class WrappedViewerLabelProvider extends ColumnLabelProvider {
/**
* Get the label provider
- *
+ *
* @return {@link ILabelProvider}
*/
- ILabelProvider getLabelProvider() {
+ ILabelProvider<E> getLabelProvider() {
return labelProvider;
}
/**
* Get the color provider
- *
+ *
* @return {@link IColorProvider}
*/
- IColorProvider getColorProvider() {
+ IColorProvider<E> getColorProvider() {
return colorProvider;
}
/**
* Get the font provider
- *
+ *
* @return {@link IFontProvider}.
*/
- IFontProvider getFontProvider() {
+ IFontProvider<E> getFontProvider() {
return fontProvider;
}
@Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
+ public void update(ViewerCell<E> cell) {
+ E element = cell.getElement();
if(viewerLabelProvider == null && treePathLabelProvider == null){
// inlined super implementation with performance optimizations
cell.setText(getText(element));
@@ -179,9 +195,9 @@ class WrappedViewerLabelProvider extends ColumnLabelProvider {
}
return;
}
-
+
ViewerLabel label = new ViewerLabel(cell.getText(), cell.getImage());
-
+
if (treePathLabelProvider != null) {
TreePath treePath = cell.getViewerRow().getTreePath();
@@ -189,20 +205,20 @@ class WrappedViewerLabelProvider extends ColumnLabelProvider {
treePathLabelProvider.updateLabel(label, treePath);
} else if (viewerLabelProvider != null) {
viewerLabelProvider.updateLabel(label, element);
- }
- if (!label.hasNewForeground() && colorProvider != null)
+ }
+ if (!label.hasNewForeground() && colorProvider != null)
label.setForeground(getForeground(element));
-
- if (!label.hasNewBackground() && colorProvider != null)
+
+ if (!label.hasNewBackground() && colorProvider != null)
label.setBackground(getBackground(element));
-
- if (!label.hasNewFont() && fontProvider != null)
+
+ if (!label.hasNewFont() && fontProvider != null)
label.setFont(getFont(element));
-
+
applyViewerLabel(cell, label);
}
- private void applyViewerLabel(ViewerCell cell, ViewerLabel label) {
+ private void applyViewerLabel(ViewerCell<E> cell, ViewerLabel label) {
if (label.hasNewText()) {
cell.setText(label.getText());
}