aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHendrik Still2013-07-29 10:31:39 (EDT)
committerJohn Arthorne2013-09-04 09:58:17 (EDT)
commit6d9bc3ca322eb39f837b2e629b86df70f3866c5b (patch)
treec5a6a93fd9deb866457e85b549c46f9eb85e2500
parent802a06936f930fcd76a680b6a3ad9af7f1494e55 (diff)
downloadeclipse.platform.ui-6d9bc3ca322eb39f837b2e629b86df70f3866c5b.zip
eclipse.platform.ui-6d9bc3ca322eb39f837b2e629b86df70f3866c5b.tar.gz
eclipse.platform.ui-6d9bc3ca322eb39f837b2e629b86df70f3866c5b.tar.bz2
Bug 412273 - [Viewers] Add generics to the ComboViewer
Generics are added to the ComboViewer to provide a type safty use of this viewer This change provides also the base implementation for the conversion of other viewers Change-Id: Idff3492a4f8eb54762b3e0ce54d635d5cbfff282 Signed-off-by: Hendrik Still <hendrik.still@gammas.de>
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java97
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/BaseLabelProvider.java8
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java5
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java35
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IBaseLabelProvider.java8
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IContentProvider.java8
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputProvider.java8
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputSelectionProvider.java6
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILabelProvider.java10
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IStructuredContentProvider.java9
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/LabelProvider.java10
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java132
-rw-r--r--bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/Viewer.java12
13 files changed, 196 insertions, 152 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java
index 61d155e..1b84e7d 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java
@@ -10,6 +10,7 @@
* Chris Longfield <clongfield@internap.com> - Fix for Bug 70856
* Tom Schindl - fix for bug 157309
* Brad Reynolds - bug 141435
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -25,18 +26,20 @@ import org.eclipse.swt.widgets.Widget;
* Abstract base class for viewers that contain lists of items (such as a combo or list).
* Most of the viewer implementation is in this base class, except for the minimal code that
* actually communicates with the underlying widget.
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
*
* @see org.eclipse.jface.viewers.ListViewer
* @see org.eclipse.jface.viewers.ComboViewer
*
* @since 3.0
*/
-public abstract class AbstractListViewer extends StructuredViewer {
+public abstract class AbstractListViewer<E,I> extends StructuredViewer<E,I> {
/**
- * A list of viewer elements (element type: <code>Object</code>).
+ * A list of viewer elements.
*/
- private java.util.List listMap = new ArrayList();
+ private java.util.List<E> listMap = new ArrayList<E>();
/**
* Adds the given string to the underlying widget at the given index
@@ -129,18 +132,18 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @param elements the elements to add
*/
- public void add(Object[] elements) {
+ public void add(E[] elements) {
assertElementsNotNull(elements);
- Object[] filtered = filter(elements);
- ILabelProvider labelProvider = (ILabelProvider) getLabelProvider();
+ E[] filtered = filter(elements);
+ ILabelProvider<E> labelProvider = (ILabelProvider<E>) getLabelProvider();
for (int i = 0; i < filtered.length; i++) {
- Object element = filtered[i];
+ E element = filtered[i];
int ix = indexForElement(element);
insertItem(labelProvider, element, ix);
}
}
- private void insertItem(ILabelProvider labelProvider, Object element, int index) {
+ private void insertItem(ILabelProvider<E> labelProvider, E element, int index) {
listAdd(getLabelProviderText(labelProvider, element), index);
listMap.add(index, element);
mapElement(element, getControl()); // must map it, since findItem only looks in map, if enabled
@@ -163,13 +166,13 @@ public abstract class AbstractListViewer extends StructuredViewer {
* the last position
* @since 3.3
*/
- public void insert(Object element, int position) {
+ public void insert(E element, int position) {
if (getComparator() != null || hasFilters()) {
add(element);
return;
}
- insertItem((ILabelProvider) getLabelProvider(), element, position);
+ insertItem((ILabelProvider<E>) getLabelProvider(), element, position);
}
@@ -183,7 +186,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @since 3.1
*/
- private String getLabelProviderText(ILabelProvider labelProvider, Object element){
+ private String getLabelProviderText(ILabelProvider<E> labelProvider, E element){
String text = labelProvider.getText(element);
if(text == null) {
return "";//$NON-NLS-1$
@@ -205,8 +208,10 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @param element the element
*/
- public void add(Object element) {
- add(new Object[] { element });
+ public void add(E element) {
+ @SuppressWarnings("unchecked")
+ E[] newElementArray = (E[]) new Object[] { element };
+ add(newElementArray);
}
/* (non-Javadoc)
@@ -214,7 +219,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* Since SWT.List doesn't use items we always return the List itself.
*/
@Override
- protected Widget doFindInputItem(Object element) {
+ protected Widget doFindInputItem(E element) {
if (element != null && equals(element, getRoot())) {
return getControl();
}
@@ -226,7 +231,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* Since SWT.List doesn't use items we always return the List itself.
*/
@Override
- protected Widget doFindItem(Object element) {
+ protected Widget doFindItem(E element) {
if (element != null) {
if (listMapContains(element)) {
return getControl();
@@ -239,11 +244,11 @@ public abstract class AbstractListViewer extends StructuredViewer {
* Method declared on StructuredViewer.
*/
@Override
- protected void doUpdateItem(Widget data, Object element, boolean fullMap) {
+ protected void doUpdateItem(Widget data, E element, boolean fullMap) {
if (element != null) {
int ix = getElementIndex(element);
if (ix >= 0) {
- ILabelProvider labelProvider = (ILabelProvider) getLabelProvider();
+ ILabelProvider<E> labelProvider = (ILabelProvider<E>) getLabelProvider();
listSetItem(ix, getLabelProviderText(labelProvider,element));
}
}
@@ -257,7 +262,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* @return the element at the given index, or <code>null</code> if the
* index is out of range
*/
- public Object getElementAt(int index) {
+ public E getElementAt(int index) {
if (index >= 0 && index < listMap.size()) {
return listMap.get(index);
}
@@ -270,22 +275,19 @@ public abstract class AbstractListViewer extends StructuredViewer {
* viewers will be an instance of <code>ILabelProvider</code>.
*/
@Override
- public IBaseLabelProvider getLabelProvider() {
+ public IBaseLabelProvider<E> getLabelProvider() {
return super.getLabelProvider();
}
/* (non-Javadoc)
- * Method declared on Viewer.
- */
- /* (non-Javadoc)
* Method declared on StructuredViewer.
*/
@Override
- protected List getSelectionFromWidget() {
+ protected List<E> getSelectionFromWidget() {
int[] ixs = listGetSelectionIndices();
- ArrayList list = new ArrayList(ixs.length);
+ ArrayList<E> list = new ArrayList<E>(ixs.length);
for (int i = 0; i < ixs.length; i++) {
- Object e = getElementAt(ixs[i]);
+ E e = getElementAt(ixs[i]);
if (e != null) {
list.add(e);
}
@@ -297,7 +299,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* @param element the element to insert
* @return the index where the item should be inserted.
*/
- protected int indexForElement(Object element) {
+ protected int indexForElement(E element) {
ViewerComparator comparator = getComparator();
if (comparator == null) {
return listGetItemCount();
@@ -333,16 +335,16 @@ public abstract class AbstractListViewer extends StructuredViewer {
* Method declared on Viewer.
*/
@Override
- protected void inputChanged(Object input, Object oldInput) {
+ protected void inputChanged(I input, I oldInput) {
listMap.clear();
- Object[] children = getSortedChildren(getRoot());
+ E[] children = getSortedChildren(getRoot());
int size = children.length;
listRemoveAll();
String[] labels = new String[size];
for (int i = 0; i < size; i++) {
- Object el = children[i];
- labels[i] = getLabelProviderText((ILabelProvider) getLabelProvider(),el);
+ E el = children[i];
+ labels[i] = getLabelProviderText((ILabelProvider<E>) getLabelProvider(),el);
listMap.add(el);
mapElement(el, getControl()); // must map it, since findItem only looks in map, if enabled
}
@@ -361,14 +363,14 @@ public abstract class AbstractListViewer extends StructuredViewer {
listMap.clear();
}
unmapAllElements();
- List selection = getSelectionFromWidget();
+ List<E> selection = getSelectionFromWidget();
int topIndex = -1;
if (selection == null || selection.isEmpty()) {
topIndex = listGetTopIndex();
}
- Object[] children = null;
+ E[] children = null;
list.setRedraw(false);
try {
listRemoveAll();
@@ -376,10 +378,10 @@ public abstract class AbstractListViewer extends StructuredViewer {
children = getSortedChildren(getRoot());
String[] items = new String[children.length];
- ILabelProvider labelProvider = (ILabelProvider) getLabelProvider();
+ ILabelProvider<E> labelProvider = (ILabelProvider<E>) getLabelProvider();
for (int i = 0; i < items.length; i++) {
- Object el = children[i];
+ E el = children[i];
items[i] = getLabelProviderText(labelProvider, el);
listMap.add(el);
mapElement(el, list); // must map it, since findItem only looks in map, if enabled
@@ -396,7 +398,10 @@ public abstract class AbstractListViewer extends StructuredViewer {
listSetTopIndex(Math.min(topIndex, children.length));
}
} else {
- doUpdateItem(list, element, true);
+ // updating a child/single element
+ @SuppressWarnings("unchecked")
+ E singleElement = (E) element;
+ doUpdateItem(list, singleElement, true);
}
}
@@ -428,8 +433,8 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @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)) {
setInput(null);
@@ -455,7 +460,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @param elements the elements to remove
*/
- public void remove(final Object[] elements) {
+ public void remove(final E[] elements) {
assertElementsNotNull(elements);
if (elements.length == 0) {
return;
@@ -480,8 +485,10 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @param element the element
*/
- public void remove(Object element) {
- remove(new Object[] { element });
+ public void remove(E element) {
+ @SuppressWarnings("unchecked")
+ E[] newElementArray = (E[]) new Object[] { element };
+ remove(newElementArray);
}
/**
@@ -493,7 +500,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* {@link IFontProvider} have no effect for this type of viewer</b>
*/
@Override
- public void setLabelProvider(IBaseLabelProvider labelProvider) {
+ public void setLabelProvider(IBaseLabelProvider<E> labelProvider) {
Assert.isTrue(labelProvider instanceof ILabelProvider);
super.setLabelProvider(labelProvider);
}
@@ -502,7 +509,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* Method declared on StructuredViewer.
*/
@Override
- protected void setSelectionToWidget(List in, boolean reveal) {
+ protected void setSelectionToWidget(List<E> in, boolean reveal) {
if (in == null || in.size() == 0) { // clear selection
listDeselectAll();
} else {
@@ -510,7 +517,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
int[] ixs = new int[n];
int count = 0;
for (int i = 0; i < n; ++i) {
- Object el = in.get(i);
+ E el = in.get(i);
int ix = getElementIndex(el);
if (ix >= 0) {
ixs[count++] = ix;
@@ -533,7 +540,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
* @param element
* @return the index
*/
- int getElementIndex(Object element) {
+ int getElementIndex(E element) {
IElementComparer comparer = getComparer();
if (comparer == null) {
return listMap.indexOf(element);
@@ -552,7 +559,7 @@ public abstract class AbstractListViewer extends StructuredViewer {
*
* @since 3.3
*/
- private boolean listMapContains(Object element) {
+ private boolean listMapContains(E element) {
return getElementIndex(element) != -1;
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/BaseLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/BaseLabelProvider.java
index d610aa4..d377ee1 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/BaseLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/BaseLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -17,11 +18,12 @@ import org.eclipse.jface.util.SafeRunnable;
/**
* BaseLabelProvider is a default concrete implementation of
* {@link IBaseLabelProvider}
+ * @param <E> Type of an element of the model
*
* @since 3.3
*
*/
-public class BaseLabelProvider extends EventManager implements IBaseLabelProvider {
+public class BaseLabelProvider<E> extends EventManager implements IBaseLabelProvider<E> {
/* (non-Javadoc)
* Method declared on IBaseLabelProvider.
@@ -44,7 +46,7 @@ public class BaseLabelProvider extends EventManager implements IBaseLabelProvide
* <code>IBaseLabelProvider</code> method returns <code>true</code>. Subclasses may
* override.
*/
- public boolean isLabelProperty(Object element, String property) {
+ public boolean isLabelProperty(E element, String property) {
return true;
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java
index 07a3b93..0b98ad0 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ComboViewer.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Sebastian Davids - bug 69254
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -29,11 +30,13 @@ import org.eclipse.swt.widgets.Control;
* and configured with a domain-specific content provider, label provider, element
* filter (optional), and element sorter (optional).
* </p>
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
*
* @see org.eclipse.jface.viewers.ListViewer
* @since 3.0 (made non-final in 3.4)
*/
-public class ComboViewer extends AbstractListViewer {
+public class ComboViewer<E,I> extends AbstractListViewer<E,I> {
/**
* This viewer's list control if this viewer is instantiated with a combo control; otherwise
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java
index df99592..76b8f81 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -47,25 +48,27 @@ import org.eclipse.swt.widgets.Control;
* support selections (<code>setSelection</code>, <code>getSelection</code>)
* </ul>
* </p>
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
*/
-public abstract class ContentViewer extends Viewer {
+public abstract class ContentViewer<E,I> extends Viewer<I>{
/**
* This viewer's content provider, or <code>null</code> if none.
*/
- private IContentProvider contentProvider = null;
+ private IContentProvider<I> contentProvider = null;
/**
* This viewer's input, or <code>null</code> if none.
* The viewer's input provides the "model" for the viewer's content.
*/
- private Object input = null;
+ private I input = null;
/**
* This viewer's label provider. Initially <code>null</code>, but
* lazily initialized (to a <code>SimpleLabelProvider</code>).
*/
- private IBaseLabelProvider labelProvider = null;
+ private IBaseLabelProvider<E> labelProvider = null;
/**
* This viewer's label provider listener.
@@ -119,7 +122,7 @@ public abstract class ContentViewer extends Viewer {
*
* @return the content provider, or <code>null</code> if none
*/
- public IContentProvider getContentProvider() {
+ public IContentProvider<I> getContentProvider() {
return contentProvider;
}
@@ -130,7 +133,7 @@ public abstract class ContentViewer extends Viewer {
* content.
*/
@Override
- public Object getInput() {
+ public I getInput() {
return input;
}
@@ -148,9 +151,9 @@ public abstract class ContentViewer extends Viewer {
*
* @return a label provider
*/
- public IBaseLabelProvider getLabelProvider() {
+ public IBaseLabelProvider<E> getLabelProvider() {
if (labelProvider == null) {
- labelProvider = new LabelProvider();
+ labelProvider = new LabelProvider<E>();
}
return labelProvider;
}
@@ -241,12 +244,12 @@ public abstract class ContentViewer extends Viewer {
* @param contentProvider the content provider
* @see #getContentProvider
*/
- public void setContentProvider(IContentProvider contentProvider) {
+ public void setContentProvider(IContentProvider<I> contentProvider) {
Assert.isNotNull(contentProvider);
- IContentProvider oldContentProvider = this.contentProvider;
+ IContentProvider<I> oldContentProvider = this.contentProvider;
this.contentProvider = contentProvider;
if (oldContentProvider != null) {
- Object currentInput = getInput();
+ I currentInput = getInput();
oldContentProvider.inputChanged(this, currentInput, null);
oldContentProvider.dispose();
contentProvider.inputChanged(this, null, currentInput);
@@ -263,7 +266,7 @@ public abstract class ContentViewer extends Viewer {
* if required.
*/
@Override
- public void setInput(Object input) {
+ public void setInput(I input) {
Control control = getControl();
if (control == null || control.isDisposed()) {
throw new IllegalStateException(
@@ -274,7 +277,7 @@ public abstract class ContentViewer extends Viewer {
.isTrue(getContentProvider() != null,
"ContentViewer must have a content provider when input is set."); //$NON-NLS-1$
- Object oldInput = getInput();
+ I oldInput = getInput();
contentProvider.inputChanged(this, oldInput, input);
this.input = input;
@@ -295,8 +298,8 @@ public abstract class ContentViewer extends Viewer {
*
* @param labelProvider the label provider, or <code>null</code> if none
*/
- public void setLabelProvider(IBaseLabelProvider labelProvider) {
- IBaseLabelProvider oldProvider = this.labelProvider;
+ public void setLabelProvider(IBaseLabelProvider<E> labelProvider) {
+ IBaseLabelProvider<E> oldProvider = this.labelProvider;
// If it hasn't changed, do nothing.
// This also ensures that the provider is not disposed
// if set a second time.
@@ -323,7 +326,7 @@ public abstract class ContentViewer extends Viewer {
*
* @since 3.4
*/
- void internalDisposeLabelProvider(IBaseLabelProvider oldProvider) {
+ void internalDisposeLabelProvider(IBaseLabelProvider<E> oldProvider) {
oldProvider.dispose();
}
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IBaseLabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IBaseLabelProvider.java
index 28319b6..401a281 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IBaseLabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IBaseLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -34,11 +35,12 @@ package org.eclipse.jface.viewers;
* it is the responsibility of the user to ensure <code>dispose</code>
* is called when the provider is no longer needed.
* </p>
+ * @param <E> Type of an element of the model
*
* @see ILabelProvider
* @see ITableLabelProvider
*/
-public interface IBaseLabelProvider {
+public interface IBaseLabelProvider<E> {
/**
* Adds a listener to this label provider.
* Has no effect if an identical listener is already registered.
@@ -73,7 +75,7 @@ public interface IBaseLabelProvider {
* @return <code>true</code> if the label would be affected,
* and <code>false</code> if it would be unaffected
*/
- public boolean isLabelProperty(Object element, String property);
+ public boolean isLabelProperty(E element, String property);
/**
* Removes a listener to this label provider.
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IContentProvider.java
index 9a5547a..de6de53 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,16 +7,18 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
/**
* A content provider mediates between the viewer's model
* and the viewer itself.
+ * @param <I> Type of the input for the view
*
* @see org.eclipse.jface.viewers.ContentViewer#setContentProvider(IContentProvider)
*/
-public interface IContentProvider {
+public interface IContentProvider<I> {
/**
* Disposes of this content provider.
* This is called by the viewer when it is disposed.
@@ -47,5 +49,5 @@ public interface IContentProvider {
* @param newInput the new input element, or <code>null</code> if the viewer
* does not have an input
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput);
+ public void inputChanged(Viewer<I> viewer, I oldInput, I newInput);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputProvider.java
index 30fdca0..11d2f9e 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,17 +7,19 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
/**
* Interface common to all objects that provide an input.
+ * @param <I> Type of the input
*/
-public interface IInputProvider {
+public interface IInputProvider<I> {
/**
* Returns the input.
*
* @return the input object
*/
- public Object getInput();
+ public I getInput();
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputSelectionProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputSelectionProvider.java
index b5fdeab..fd1adbd 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputSelectionProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IInputSelectionProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,13 +7,15 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
/**
* Interface common to all objects that provide both an input and
* a selection.
+ * @param <I> Type of the input
*/
-public interface IInputSelectionProvider extends IInputProvider,
+public interface IInputSelectionProvider<I> extends IInputProvider<I>,
ISelectionProvider {
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILabelProvider.java
index 414f159..19dcacf 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ILabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -16,8 +17,9 @@ import org.eclipse.swt.graphics.Image;
* Extends <code>IBaseLabelProvider</code> with the methods
* to provide the text and/or image for the label of a given element.
* Used by most structured viewers, except table viewers.
+ * @param <E> Type of an element of the model
*/
-public interface ILabelProvider extends IBaseLabelProvider {
+public interface ILabelProvider<E> extends IBaseLabelProvider<E> {
/**
* Returns the image for the label of the given element. The image
* is owned by the label provider and must not be disposed directly.
@@ -27,7 +29,7 @@ public interface ILabelProvider extends IBaseLabelProvider {
* @return the image used to label the element, or <code>null</code>
* if there is no image for the given object
*/
- public Image getImage(Object element);
+ public Image getImage(E element);
/**
* Returns the text for the label of the given element.
@@ -36,5 +38,5 @@ public interface ILabelProvider extends IBaseLabelProvider {
* @return the text string used to label the element, or <code>null</code>
* if there is no text label for the given object
*/
- public String getText(Object element);
+ public String getText(E element);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IStructuredContentProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IStructuredContentProvider.java
index 61648aa..e7e5a81 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IStructuredContentProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/IStructuredContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,15 +7,18 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
/**
* An interface to content providers for structured viewers.
+ * @param <E> Type of an element of the model
+ * @param <I> Type of the input
*
* @see StructuredViewer
*/
-public interface IStructuredContentProvider extends IContentProvider {
+public interface IStructuredContentProvider<E,I> extends IContentProvider<I> {
/**
* Returns the elements to display in the viewer
* when its input is set to the given element.
@@ -25,5 +28,5 @@ public interface IStructuredContentProvider extends IContentProvider {
* @param inputElement the input element
* @return the array of elements to display in the viewer
*/
- public Object[] getElements(Object inputElement);
+ public E[] getElements(I inputElement);
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/LabelProvider.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/LabelProvider.java
index b7336c8..0beb338 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/LabelProvider.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/LabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -26,8 +27,9 @@ import org.eclipse.swt.graphics.Image;
* <li><code>dispose</code></li>
* </ul>
* </p>
+ * @param <E> Type of an element of the model
*/
-public class LabelProvider extends BaseLabelProvider implements ILabelProvider {
+public class LabelProvider<E> extends BaseLabelProvider<E> implements ILabelProvider<E> {
/**
* Creates a new label provider.
@@ -41,7 +43,7 @@ public class LabelProvider extends BaseLabelProvider implements ILabelProvider {
* <code>ILabelProvider</code> method returns <code>null</code>.
* Subclasses may override.
*/
- public Image getImage(Object element) {
+ public Image getImage(E element) {
return null;
}
@@ -50,7 +52,7 @@ public class LabelProvider extends BaseLabelProvider implements ILabelProvider {
* <code>ILabelProvider</code> method returns the element's
* <code>toString</code> string. Subclasses may override.
*/
- 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/StructuredViewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java
index 62182f1..0dd7145 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Schindl - bug 151205
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -52,11 +53,13 @@ import org.eclipse.swt.widgets.Widget;
* <code>addFilter</code>). When the viewer receives an update, it asks each
* of its filters if it is out of date, and refilters elements as required.
* </p>
+ * @param <E> Type of an single element of the model
+ * @param <I> Type of the input
*
* @see ViewerFilter
* @see ViewerComparator
*/
-public abstract class StructuredViewer extends ContentViewer implements IPostSelectionProvider {
+public abstract class StructuredViewer<E,I> extends ContentViewer<E,I> implements IPostSelectionProvider {
/**
* A map from the viewer's model elements to SWT widgets. (key type:
@@ -81,7 +84,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* This viewer's filters (element type: <code>ViewerFilter</code>).
* <code>null</code> means there are no filters.
*/
- private List filters;
+ private List<ViewerFilter> filters;
/**
* Indicates whether the viewer should attempt to preserve the selection
@@ -174,7 +177,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @see IColorProvider
* @see IFontProvider
*/
- public ColorAndFontCollectorWithProviders(IBaseLabelProvider provider) {
+ public ColorAndFontCollectorWithProviders(IBaseLabelProvider<E> provider) {
super();
if (provider instanceof IColorProvider) {
colorProvider = (IColorProvider) provider;
@@ -289,6 +292,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @see org.eclipse.jface.viewers.StructuredViewer.ColorAndFontManager#applyFontsAndColors(org.eclipse.swt.custom.TableTreeItem)
*/
@Override
+ @Deprecated
public void applyFontsAndColors(TableTreeItem control) {
if(colorProvider == null){
@@ -426,6 +430,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* required.
* @param control
*/
+ @Deprecated
public void applyFontsAndColors(TableTreeItem control) {
if(usedDecorators){
//If there is no provider only apply set values
@@ -475,11 +480,11 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
class UpdateItemSafeRunnable extends SafeRunnable {
private Widget widget;
- private Object element;
+ private E element;
private boolean fullMap;
- UpdateItemSafeRunnable(Widget widget, Object element, boolean fullMap) {
+ UpdateItemSafeRunnable(Widget widget, E element, boolean fullMap) {
this.widget = widget;
this.element = element;
this.fullMap = fullMap;
@@ -584,7 +589,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
*/
public void addFilter(ViewerFilter filter) {
if (filters == null) {
- filters = new ArrayList();
+ filters = new ArrayList<ViewerFilter>();
}
filters.add(filter);
refresh();
@@ -631,8 +636,8 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param item
* the widget
*/
- protected void associate(Object element, Item item) {
- Object data = item.getData();
+ protected void associate(E element, Item item) {
+ E data = (E) item.getData();
if (data != element) {
if (data != null) {
disassociate(item);
@@ -661,7 +666,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
protected void disassociate(Item item) {
if (associateListener != null)
associateListener.disassociate(item);
- Object element = item.getData();
+ E element = (E) item.getData();
Assert.isNotNull(element);
//Clear the map before we clear the data
unmapElement(element, item);
@@ -679,7 +684,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element
* @return the corresponding widget, or <code>null</code> if none
*/
- protected abstract Widget doFindInputItem(Object element);
+ protected abstract Widget doFindInputItem(E element);
/**
* Returns the widget in this viewer's control which represent the given
@@ -692,7 +697,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element
* @return the corresponding widget, or <code>null</code> if none
*/
- protected abstract Widget doFindItem(Object element);
+ protected abstract Widget doFindItem(E element);
/**
* Copies the attributes of the given element into the given SWT item. The
@@ -713,7 +718,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* <code>true</code> if mappings are added and removed, and
* <code>false</code> if only the new map gets installed
*/
- protected abstract void doUpdateItem(Widget item, Object element, boolean fullMap);
+ protected abstract void doUpdateItem(Widget item, E element, boolean fullMap);
/**
* Compares two elements for equality. Uses the element comparer if one has
@@ -741,14 +746,14 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the elements to filter
* @return only the elements which all filters accept
*/
- protected Object[] filter(Object[] elements) {
+ protected E[] filter(E[] elements) {
if (filters != null) {
- ArrayList filtered = new ArrayList(elements.length);
- Object root = getRoot();
+ ArrayList<E> filtered = new ArrayList<E>(elements.length);
+ I root = getRoot();
for (int i = 0; i < elements.length; i++) {
boolean add = true;
for (int j = 0; j < filters.size(); j++) {
- add = ((ViewerFilter) filters.get(j)).select(this, root, elements[i]);
+ add = filters.get(j).select(this, root, elements[i]);
if (!add) {
break;
}
@@ -760,7 +765,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
associateListener.filteredOut(elements[i]);
}
}
- return filtered.toArray();
+ return (E[]) filtered.toArray();
}
return elements;
}
@@ -780,7 +785,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the element
* @return the corresponding widget, or <code>null</code> if none
*/
- protected final Widget findItem(Object element) {
+ protected final Widget findItem(E element) {
Widget[] result = findItems(element);
return result.length == 0 ? null : result[0];
}
@@ -810,7 +815,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
*
* @since 3.2
*/
- protected final Widget[] findItems(Object element) {
+ protected final Widget[] findItems(E element) {
Widget result = doFindInputItem(element);
if (result != null) {
return new Widget[] { result };
@@ -917,12 +922,12 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the parent element
* @return a filtered array of child elements
*/
- protected Object[] getFilteredChildren(Object parent) {
- Object[] result = getRawChildren(parent);
+ protected E[] getFilteredChildren(I parent) {
+ E[] result = getRawChildren(parent);
if (filters != null) {
- for (Iterator iter = filters.iterator(); iter.hasNext();) {
- ViewerFilter f = (ViewerFilter) iter.next();
- Object[] filteredResult = f.filter(this, parent, result);
+ for (Iterator<ViewerFilter> iter = filters.iterator(); iter.hasNext();) {
+ ViewerFilter f = iter.next();
+ E[] filteredResult = (E[]) f.filter(this, parent, result);
if (associateListener != null && filteredResult.length != result.length) {
notifyFilteredOut(result, filteredResult);
}
@@ -938,7 +943,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param rawResult
* @param filteredResult
*/
- private void notifyFilteredOut(Object[] rawResult, Object[] filteredResult) {
+ private void notifyFilteredOut(E[] rawResult, E[] filteredResult) {
int rawIndex = 0;
int filteredIndex = 0;
for (; filteredIndex < filteredResult.length; ) {
@@ -1007,16 +1012,23 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the parent element
* @return the child elements
*/
- protected Object[] getRawChildren(Object parent) {
- Object[] result = null;
+ protected E[] getRawChildren(I parent) {
+ E[] result = null;
if (parent != null) {
- IStructuredContentProvider cp = (IStructuredContentProvider) getContentProvider();
+ IStructuredContentProvider<E,I> cp = (IStructuredContentProvider<E,I>) getContentProvider();
if (cp != null) {
result = cp.getElements(parent);
assertElementsNotNull(result);
}
}
- return (result != null) ? result : new Object[0];
+
+ if(result == null){
+ @SuppressWarnings("unchecked")
+ E[] emptyResult = (E[]) new Object[0];
+ result = emptyResult;
+ }
+
+ return result;
}
/**
@@ -1029,7 +1041,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
*
* @return the root element, or <code>null</code> if none
*/
- protected Object getRoot() {
+ protected I getRoot() {
return getInput();
}
@@ -1048,7 +1060,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
if (control == null || control.isDisposed()) {
return StructuredSelection.EMPTY;
}
- List list = getSelectionFromWidget();
+ List<E> list = getSelectionFromWidget();
return new StructuredSelection(list, comparer);
}
@@ -1058,7 +1070,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
*
* @return the list of selected elements
*/
- protected abstract List getSelectionFromWidget();
+ protected abstract List<E> getSelectionFromWidget();
/**
* Returns the sorted and filtered set of children of the given element. The
@@ -1069,8 +1081,8 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the parent element
* @return a sorted and filtered array of child elements
*/
- protected Object[] getSortedChildren(Object parent) {
- Object[] result = getFilteredChildren(parent);
+ protected E[] getSortedChildren(I parent) {
+ E[] result = getFilteredChildren(parent);
if (sorter != null) {
// be sure we're not modifying the original array from the model
result = result.clone();
@@ -1193,7 +1205,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
*/
@Override
protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
- Object[] elements = event.getElements();
+ E[] elements = (E[])event.getElements();
if (elements != null) {
update(elements, null);
} else {
@@ -1320,7 +1332,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param item
* the corresponding widget
*/
- protected void mapElement(Object element, Widget item) {
+ protected void mapElement(E element, Widget item) {
if (elementMap != null) {
Object widgetOrWidgets = elementMap.get(element);
if (widgetOrWidgets == null) {
@@ -1366,7 +1378,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
if (filters != null) {
for (int i = 0, n = filters.size(); i < n; ++i) {
- ViewerFilter filter = (ViewerFilter) filters.get(i);
+ ViewerFilter filter = filters.get(i);
if (filter.isFilterProperty(element, property)) {
return true;
}
@@ -1560,7 +1572,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element
* the element
*/
- protected final void refreshItem(Widget widget, Object element) {
+ protected final void refreshItem(Widget widget, E element) {
SafeRunnable.run(new UpdateItemSafeRunnable(widget, element, true));
}
@@ -1608,8 +1620,8 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
if (filters != null) {
// Note: can't use List.remove(Object). Use identity comparison
// instead.
- for (Iterator i = filters.iterator(); i.hasNext();) {
- Object o = i.next();
+ for (Iterator<ViewerFilter> i = filters.iterator(); i.hasNext();) {
+ ViewerFilter o = i.next();
if (o == filter) {
i.remove();
refresh();
@@ -1638,7 +1650,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
if (filters.length == 0) {
resetFilters();
} else {
- this.filters = new ArrayList(Arrays.asList(filters));
+ this.filters = new ArrayList<ViewerFilter>(Arrays.asList(filters));
refresh();
}
}
@@ -1668,7 +1680,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @see org.eclipse.jface.viewers.ContentViewer#setContentProvider(org.eclipse.jface.viewers.IContentProvider)
*/
@Override
- public void setContentProvider(IContentProvider provider) {
+ public void setContentProvider(IContentProvider<I> provider) {
assertContentProviderType(provider);
super.setContentProvider(provider);
}
@@ -1678,7 +1690,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* supported types.
* @param provider
*/
- protected void assertContentProviderType(IContentProvider provider) {
+ protected void assertContentProviderType(IContentProvider<I> provider) {
Assert.isTrue(provider instanceof IStructuredContentProvider);
}
@@ -1687,7 +1699,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @see org.eclipse.jface.viewers.Viewer#setInput(java.lang.Object)
*/
@Override
- public final void setInput(Object input) {
+ public final void setInput(I input) {
Control control = getControl();
if (control == null || control.isDisposed()) {
throw new IllegalStateException(
@@ -1752,13 +1764,13 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* </p>
*
* @param l
- * list of selected elements (element type: <code>Object</code>)
+ * list of selected elements
* or <code>null</code> if the selection is to be cleared
* @param reveal
* <code>true</code> if the selection is to be made visible,
* and <code>false</code> otherwise
*/
- protected abstract void setSelectionToWidget(List l, boolean reveal);
+ protected abstract void setSelectionToWidget(List<E> l, boolean reveal);
/**
* Converts the selection to a <code>List</code> and calls
@@ -1779,7 +1791,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
if (selection instanceof IStructuredSelection) {
setSelectionToWidget(((IStructuredSelection) selection).toList(), reveal);
} else {
- setSelectionToWidget((List) null, reveal);
+ setSelectionToWidget((List<E>) null, reveal);
}
}
@@ -1899,7 +1911,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element
* @return Widget
*/
- public Widget testFindItem(Object element) {
+ public Widget testFindItem(E element) {
return findItem(element);
}
@@ -1909,7 +1921,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @return Widget[]
* @since 3.2
*/
- public Widget[] testFindItems(Object element) {
+ public Widget[] testFindItems(E element) {
return findItems(element);
}
@@ -1958,7 +1970,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param item the item to unmap
* @since 2.0
*/
- protected void unmapElement(Object element, Widget item) {
+ protected void unmapElement(E element, Widget item) {
// double-check that the element actually maps to the given item before
// unmapping it
if (elementMap != null) {
@@ -2038,7 +2050,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the properties that have changed, or <code>null</code> to
* indicate unknown
*/
- public void update(Object[] elements, String[] properties) {
+ public void update(E[] elements, String[] properties) {
boolean previousValue = refreshOccurred;
refreshOccurred = false;
try {
@@ -2093,7 +2105,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the properties that have changed, or <code>null</code> to
* indicate unknown
*/
- public void update(Object element, String[] properties) {
+ public void update(E element, String[] properties) {
Assert.isNotNull(element);
Widget[] items = findItems(element);
@@ -2126,7 +2138,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* the properties that have changed, or <code>null</code> to
* indicate unknown
*/
- protected void internalUpdate(Widget widget, Object element, String[] properties) {
+ protected void internalUpdate(Widget widget, E element, String[] properties) {
boolean needsRefilter = false;
if (properties != null) {
for (int i = 0; i < properties.length; ++i) {
@@ -2151,7 +2163,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
needsUpdate = true;
} else {
needsUpdate = false;
- IBaseLabelProvider labelProvider = getLabelProvider();
+ IBaseLabelProvider<E> labelProvider = getLabelProvider();
for (int i = 0; i < properties.length; ++i) {
needsUpdate = labelProvider.isLabelProperty(element, properties[i]);
if (needsUpdate) {
@@ -2176,7 +2188,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element
* the element
*/
- protected final void updateItem(Widget widget, Object element) {
+ protected final void updateItem(Widget widget, E element) {
SafeRunnable.run(new UpdateItemSafeRunnable(widget, element, true));
}
@@ -2220,7 +2232,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @see org.eclipse.jface.viewers.ContentViewer#setLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider)
*/
@Override
- public void setLabelProvider(IBaseLabelProvider labelProvider) {
+ public void setLabelProvider(IBaseLabelProvider<E> labelProvider) {
if (labelProvider instanceof IColorProvider || labelProvider instanceof IFontProvider) {
colorAndFontCollector = new ColorAndFontCollectorWithProviders(labelProvider);
} else {
@@ -2235,7 +2247,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param updateLabel The ViewerLabel to collect the result in
* @param element The element being decorated.
*/
- protected void buildLabel(ViewerLabel updateLabel, Object element){
+ protected void buildLabel(ViewerLabel updateLabel, E element){
if (getLabelProvider() instanceof IViewerLabelProvider) {
IViewerLabelProvider itemProvider = (IViewerLabelProvider) getLabelProvider();
@@ -2259,7 +2271,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
}
if(getLabelProvider() instanceof ILabelProvider){
- ILabelProvider labelProvider = (ILabelProvider) getLabelProvider();
+ ILabelProvider<E> labelProvider = (ILabelProvider<E>) getLabelProvider();
updateLabel.setText(labelProvider.getText(element));
updateLabel.setImage(labelProvider.getImage(element));
}
@@ -2272,7 +2284,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element The element being decorated.
* @param labelProvider ILabelProvider the labelProvider for the receiver.
*/
- void buildLabel(ViewerLabel updateLabel, Object element,IViewerLabelProvider labelProvider){
+ void buildLabel(ViewerLabel updateLabel, E element,IViewerLabelProvider labelProvider){
labelProvider.updateLabel(updateLabel, element);
@@ -2324,7 +2336,7 @@ public abstract class StructuredViewer extends ContentViewer implements IPostSel
* @param element The element being decorated.
* @param labelProvider ILabelProvider the labelProvider for the receiver.
*/
- void buildLabel(ViewerLabel updateLabel, Object element,ILabelProvider labelProvider){
+ void buildLabel(ViewerLabel updateLabel, E element,ILabelProvider<E> labelProvider){
updateLabel.setText(labelProvider.getText(element));
updateLabel.setImage(labelProvider.getImage(element));
}
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/Viewer.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/Viewer.java
index ee9ffb3..9b893dc 100644
--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/Viewer.java
+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/Viewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 412273
*******************************************************************************/
package org.eclipse.jface.viewers;
@@ -44,8 +45,9 @@ import org.eclipse.jface.util.SafeRunnable;
* </li>
* </ul>
* </p>
+ * @param <I> Type of the input for the view
*/
-public abstract class Viewer implements IInputSelectionProvider {
+public abstract class Viewer<I> implements IInputSelectionProvider<I> {
/**
* List of selection change listeners (element type: <code>ISelectionChangedListener</code>).
@@ -205,7 +207,7 @@ public abstract class Viewer implements IInputSelectionProvider {
/* (non-Javadoc)
* Copy-down of method declared on <code>IInputProvider</code>.
*/
- public abstract Object getInput();
+ public abstract I getInput();
/* (non-Javadoc)
* Copy-down of method declared on <code>ISelectionProvider</code>.
@@ -239,7 +241,7 @@ public abstract class Viewer implements IInputSelectionProvider {
* @param oldInput the old input element or <code>null</code> if there
* was previously no input
*/
- protected void inputChanged(Object input, Object oldInput) {
+ protected void inputChanged(I input, I oldInput) {
}
/**
@@ -377,7 +379,7 @@ public abstract class Viewer implements IInputSelectionProvider {
*
* @param input the input of this viewer, or <code>null</code> if none
*/
- public abstract void setInput(Object input);
+ public abstract void setInput(I input);
/**
* The viewer implementation of this <code>ISelectionProvider</code>