aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHendrik Still2013-09-16 18:35:43 (EDT)
committerHendrik Still2013-09-20 05:48:41 (EDT)
commitcbac24440cd63233dbb130f5bfe19943537e6837 (patch)
tree5cefad163a0b1e2782d7aa58b21b0b93e20d617b
parent2ad4c3d023330247038a0a737041b388b9bd9ea6 (diff)
downloadeclipse.platform.ui-cbac24440cd63233dbb130f5bfe19943537e6837.zip
eclipse.platform.ui-cbac24440cd63233dbb130f5bfe19943537e6837.tar.gz
eclipse.platform.ui-cbac24440cd63233dbb130f5bfe19943537e6837.tar.bz2
Updated JFace Snippets to the generic JFace Viewerrefs/changes/85/16585/3
Change-Id: I476a27bda86de5f3a5b906911fea5724c2f7684f Signed-off-by: Hendrik Still <hendrik.still@gammas.de>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet001TableViewer.java62
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet002TreeViewer.java66
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet003TableLabelProvider.java96
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet004HideSelection.java63
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet005TreeCustomMenu.java81
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet007FullSelection.java76
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet008RevealElement.java64
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet009CellEditors.java70
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet010OwnerDraw.java47
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet011CustomTooltips.java29
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java69
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet014TreeViewerNoMandatoryLabelProvider.java85
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java63
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet017TableViewerHideShowColumns.java79
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet018TableViewerAddRemoveColumnsWithEditing.java58
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.java112
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java67
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet022TableViewerRefreshNoScroll.java34
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet024TableViewerExploreNewAPI.java62
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java68
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java91
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet027ComboBoxCellEditors.java63
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java45
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet030VirtualLazyTableViewer.java42
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java89
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet032TableTreeViewer.java22
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java31
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRowNewAPI.java75
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java69
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet036FocusBorderCellHighlighter.java65
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet037FancyCustomTooltips.java47
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet038TreeViewerInlinelEditingOldAPI.java61
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet039ListViewer.java53
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java109
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java97
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java73
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.java41
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet044NoColumnTableViewerKeyboardEditing.java75
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet045TableViewerFillFromBackgroundThread.java60
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet046UpdateViewerFromBackgroundThread.java50
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet047VirtualLazyTreeViewer.java69
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet048TreeViewerTabWithCheckboxFor3_3.java52
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java19
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java105
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet051TableCenteredImage.java59
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet052DouleClickCellEditor.java57
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet053StartEditorWithContextMenu.java30
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet054NativeControlsInViewers.java57
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet055HideShowColumn.java77
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet056BooleanCellEditor.java75
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet057TableViewerSkipHiddenCells.java67
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java68
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java73
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet060TextCellEditorWithContentProposal.java15
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet061FakedNativeCellEditor.java88
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java2
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet62TextAndDialogCellEditor.java427
57 files changed, 1985 insertions, 1964 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet001TableViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet001TableViewer.java
index 017b19a..7a23246 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet001TableViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet001TableViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
@@ -21,67 +25,57 @@ import org.eclipse.swt.widgets.Shell;
/**
* A simple TableViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet001TableViewer {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet001TableViewer(Shell shell) {
- final TableViewer v = new TableViewer(shell);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -91,11 +85,11 @@ public class Snippet001TableViewer {
shell.setLayout(new FillLayout());
new Snippet001TableViewer(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet002TreeViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet002TreeViewer.java
index 68c6fcf..2db132a 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet002TreeViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet002TreeViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -23,95 +24,96 @@ import org.eclipse.swt.widgets.Shell;
/**
* A simple TreeViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet002TreeViewer {
- private class MyContentProvider implements ITreeContentProvider {
-
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
+
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return ((MyModel)inputElement).child.toArray();
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
-
+
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
+
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
- public Object getParent(Object element) {
+ public MyModel getParent(MyModel element) {
if( element == null) {
return null;
}
-
- return ((MyModel)element).parent;
+
+ return element.parent;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
- public boolean hasChildren(Object element) {
- return ((MyModel)element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
-
+
}
-
+
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
-
+
public MyModel(int counter, MyModel parent) {
this.parent = parent;
this.counter = counter;
}
-
+
public String toString() {
String rv = "Item ";
if( parent != null ) {
rv = parent.toString() + ".";
}
-
+
rv += counter;
-
+
return rv;
}
}
-
+
public Snippet002TreeViewer(Shell shell) {
- final TreeViewer v = new TreeViewer(shell);
- v.setLabelProvider(new LabelProvider());
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
}
-
+
private MyModel createModel() {
-
+
MyModel root = new MyModel(0,null);
root.counter = 0;
-
+
MyModel tmp;
for( int i = 1; i < 10; i++ ) {
tmp = new MyModel(i, root);
@@ -120,21 +122,21 @@ public class Snippet002TreeViewer {
tmp.child.add(new MyModel(j,tmp));
}
}
-
+
return root;
}
-
+
public static void main(String[] args) {
Display display = new Display ();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet002TreeViewer(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet003TableLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet003TableLabelProvider.java
index 4dbd122..db16b0e 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet003TableLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet003TableLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -27,66 +31,58 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example usage of ITableLabelProvider using images and labels
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet003TableLabelProvider {
private static Image[] images;
-
- private class MyContentProvider implements IStructuredContentProvider {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
+
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
- public class MyLabelProvider extends LabelProvider implements ITableLabelProvider {
- public Image getColumnImage(Object element, int columnIndex) {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements ITableLabelProvider<MyModel> {
+
+ public Image getColumnImage(MyModel element, int columnIndex) {
if( columnIndex == 1 ) {
- return images[((MyModel)element).counter%4];
+ return images[element.counter%4];
}
-
+
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
-
+
}
-
+
private static Image createImage(Display display, int red, int green, int blue) {
Color color = new Color(display,red,green,blue);
Image image = new Image(display,10,10);
@@ -94,66 +90,64 @@ public class Snippet003TableLabelProvider {
gc.setBackground(color);
gc.fillRectangle(0, 0, 10, 10);
gc.dispose();
-
+
return image;
}
-
+
public Snippet003TableLabelProvider(Shell shell) {
- final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell,SWT.BORDER|SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
-
+
TableColumn column = new TableColumn(v.getTable(),SWT.NONE);
column.setWidth(200);
column.setText("Column 1");
-
+
column = new TableColumn(v.getTable(),SWT.NONE);
column.setWidth(200);
column.setText("Column 2");
-
- MyModel[] model = createModel();
+
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display ();
-
+
images = new Image[4];
images[0] = createImage(display,0,0,255);
images[1] = createImage(display,0,255,255);
images[2] = createImage(display,0,255,0);
images[3] = createImage(display,255,0,255);
-
+
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet003TableLabelProvider(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
for( int i = 0; i < images.length; i++ ) {
images[i].dispose();
}
-
+
display.dispose ();
-
+
}
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet004HideSelection.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet004HideSelection.java
index cfd639b..c127963 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet004HideSelection.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet004HideSelection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -26,52 +30,45 @@ import org.eclipse.swt.widgets.Shell;
/**
* Snippet that hides the selection when nothing is selected.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet004HideSelection {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet004HideSelection(Shell shell) {
- final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell,SWT.BORDER|SWT.FULL_SELECTION);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().addMouseListener(new MouseAdapter() {
@@ -84,20 +81,18 @@ public class Snippet004HideSelection {
v.setSelection(new StructuredSelection());
}
}
-
+
});
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -107,11 +102,11 @@ public class Snippet004HideSelection {
shell.setLayout(new FillLayout());
new Snippet004HideSelection(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet005TreeCustomMenu.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet005TreeCustomMenu.java
index 46fd640..a238539 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet005TreeCustomMenu.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet005TreeCustomMenu.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -28,63 +29,89 @@ import org.eclipse.swt.widgets.Shell;
/**
* Customized context menu based on TreeItem-Selection
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet005TreeCustomMenu {
- private class MyContentProvider implements ITreeContentProvider {
-
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ private class MyContentProvider implements
+ ITreeContentProvider<MyModel, MyModel> {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(
+ * java.lang.Object)
+ */
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
+ * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends MyModel> viewer,
+ MyModel oldInput, MyModel newInput) {
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang
+ * .Object)
*/
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang
+ * .Object)
*/
- public Object getParent(Object element) {
+ public MyModel getParent(MyModel element) {
if (element == null) {
return null;
}
- return ((MyModel) element).parent;
+ return element.parent;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang
+ * .Object)
*/
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
public class MyModel {
public MyModel parent;
-
- public ArrayList child = new ArrayList();
-
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
public MyModel(int counter, MyModel parent) {
@@ -94,7 +121,7 @@ public class Snippet005TreeCustomMenu {
public String toString() {
String rv = "Item ";
- if (parent != null) {
+ if( parent != null ) {
rv = parent.toString() + ".";
}
@@ -105,8 +132,8 @@ public class Snippet005TreeCustomMenu {
}
public Snippet005TreeCustomMenu(Shell shell) {
- final TreeViewer v = new TreeViewer(shell);
- v.setLabelProvider(new LabelProvider());
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet007FullSelection.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet007FullSelection.java
index 97b69d3..d6f0786 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet007FullSelection.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet007FullSelection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -29,51 +33,43 @@ import org.eclipse.swt.widgets.TableItem;
/**
* TableViewer: Hide full selection
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet007FullSelection {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet007FullSelection(Shell shell) {
- final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell,SWT.BORDER|SWT.FULL_SELECTION);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setCellModifier(new ICellModifier() {
@@ -88,26 +84,26 @@ public class Snippet007FullSelection {
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem)element;
((MyModel)item.getData()).counter = Integer.parseInt(value.toString());
- v.update(item.getData(), null);
+ v.update((MyModel)item.getData(), null);
}
-
+
});
v.setColumnProperties(new String[] { "column1", "column2" });
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()),new TextCellEditor(v.getTable()) });
-
+
TableColumn column = new TableColumn(v.getTable(),SWT.NONE);
column.setWidth(100);
column.setText("Column 1");
-
+
column = new TableColumn(v.getTable(),SWT.NONE);
column.setWidth(100);
column.setText("Column 2");
-
- MyModel[] model = createModel();
+
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
-
+
v.getTable().addListener(SWT.EraseItem, new Listener() {
/* (non-Javadoc)
@@ -117,19 +113,17 @@ public class Snippet007FullSelection {
event.detail &= ~SWT.SELECTED;
}
});
-
+
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -139,11 +133,11 @@ public class Snippet007FullSelection {
shell.setLayout(new FillLayout());
new Snippet007FullSelection(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet008RevealElement.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet008RevealElement.java
index b275ed9..9501d31 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet008RevealElement.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet008RevealElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
@@ -21,68 +25,58 @@ import org.eclipse.swt.widgets.Shell;
/**
* Scroll a Viewer 99th element
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet008RevealElement {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet008RevealElement(Shell shell) {
- final TableViewer v = new TableViewer(shell);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
- v.reveal(model[99]);
+ v.reveal(model.get(99));
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[100];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(100);
for( int i = 0; i < 100; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -92,11 +86,11 @@ public class Snippet008RevealElement {
shell.setLayout(new FillLayout());
new Snippet008RevealElement(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet009CellEditors.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet009CellEditors.java
index 46f6549..e310c24 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet009CellEditors.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet009CellEditors.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -26,51 +30,43 @@ import org.eclipse.swt.widgets.TableItem;
/**
* Edit cell values in a table
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet009CellEditors {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet009CellEditors(Shell shell) {
- final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell,SWT.BORDER|SWT.FULL_SELECTION);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setCellModifier(new ICellModifier() {
@@ -94,29 +90,27 @@ public class Snippet009CellEditors {
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem)element;
((MyModel)item.getData()).counter = Integer.parseInt(value.toString());
- v.update(item.getData(), null);
+ v.update((MyModel)item.getData(), null);
}
-
+
});
v.setColumnProperties(new String[] { "column1" });
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()) });
-
-
- MyModel[] model = createModel();
+
+
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -126,11 +120,11 @@ public class Snippet009CellEditors {
shell.setLayout(new FillLayout());
new Snippet009CellEditors(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet010OwnerDraw.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet010OwnerDraw.java
index 0281215..eae31dd 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet010OwnerDraw.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet010OwnerDraw.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 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
@@ -8,7 +8,8 @@
* Contributors:
* IBM Corporation - initial API and implementation
* oliver.schaefer@mbtech-services.com - Fix for Bug 225051 [Snippets] Snippet010OwnerDraw - Wrong german flag
- * Lars Vogel <lars.vogel@gmail.com >- Fix for Bug 387367 - JFace Snippet Snippet010OwnerDraw rework
+ * Lars Vogel <lars.vogel@gmail.com >- Fix for Bug 387367 - JFace Snippet Snippet010OwnerDraw rework
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -63,7 +64,7 @@ public class Snippet010OwnerDraw {
/**
* Create a new instance of the receiver.
- *
+ *
* @param countryName
* @param worldCupYear
*/
@@ -113,7 +114,7 @@ public class Snippet010OwnerDraw {
/**
* Draw the flag in bounds.
- *
+ *
* @param event
*/
protected void drawFlag(Event event) {
@@ -127,7 +128,7 @@ public class Snippet010OwnerDraw {
/**
* Draw the cup year
- *
+ *
* @param event
*/
private void drawCupYear(Event event) {
@@ -137,7 +138,7 @@ public class Snippet010OwnerDraw {
/**
* Draw the name of the receiver.
- *
+ *
* @param event
*/
protected void drawName(Event event) {
@@ -208,7 +209,7 @@ public class Snippet010OwnerDraw {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.tests.viewers.OwnerDrawExample.CountryEntry#drawFlag(org.eclipse.swt.widgets.Event)
*/
protected void drawFlag(Event event) {
@@ -247,7 +248,7 @@ public class Snippet010OwnerDraw {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.tests.viewers.OwnerDrawExample.CountryEntry#drawFlag(org.eclipse.swt.widgets.Event)
*/
protected void drawFlag(Event event) {
@@ -284,7 +285,7 @@ public class Snippet010OwnerDraw {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.tests.viewers.OwnerDrawExample.CountryEntry#drawFlag(org.eclipse.swt.widgets.Event)
*/
protected void drawFlag(Event event) {
@@ -302,7 +303,7 @@ public class Snippet010OwnerDraw {
}
}
- private TableViewer viewer;
+ private TableViewer<CountryEntry,CountryEntry[]> viewer;
private CountryEntry[] entries;
@@ -315,35 +316,33 @@ public class Snippet010OwnerDraw {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
public void createPartControl(Composite parent) {
- viewer = new TableViewer(parent, SWT.FULL_SELECTION);
- viewer.setContentProvider(ArrayContentProvider.getInstance());
-
+ viewer = new TableViewer<CountryEntry,CountryEntry[]>(parent, SWT.FULL_SELECTION);
+ viewer.setContentProvider(ArrayContentProvider.getInstance(CountryEntry.class));
+
createColumns();
- viewer.setLabelProvider(new OwnerDrawLabelProvider() {
- protected void measure(Event event, Object element) {
- CountryEntry country = (CountryEntry) element;
- event.setBounds(new Rectangle(event.x, event.y, country.getWidth(event),
- country.getHeight(event)));
+ viewer.setLabelProvider(new OwnerDrawLabelProvider<CountryEntry,CountryEntry[]>() {
+ protected void measure(Event event, CountryEntry element) {
+ event.setBounds(new Rectangle(event.x, event.y, element.getWidth(event),
+ element.getHeight(event)));
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.OwnerDrawLabelProvider#paint(org.eclipse.swt.widgets.Event,
* java.lang.Object)
*/
- protected void paint(Event event, Object element) {
- CountryEntry entry = (CountryEntry) element;
- entry.draw(event);
+ protected void paint(Event event, CountryEntry element) {
+ element.draw(event);
}
});
-
+
GridData data = new GridData(GridData.GRAB_HORIZONTAL
| GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet011CustomTooltips.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet011CustomTooltips.java
index 9602606..80a7da1 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet011CustomTooltips.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet011CustomTooltips.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl - initial API and implementation
* IBM - Improvement for Bug 159625 [Snippets] Update Snippet011CustomTooltips to reflect new API
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -28,15 +29,15 @@ import org.eclipse.swt.widgets.Shell;
/**
* Explore New API: JFace custom tooltips drawing.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.3
*/
public class Snippet011CustomTooltips {
private static class MyContentProvider implements
- IStructuredContentProvider {
+ IStructuredContentProvider<String,Object> {
- public Object[] getElements(Object inputElement) {
+ public String[] getElements(Object inputElement) {
return new String[] { "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten" };
}
@@ -45,7 +46,7 @@ public class Snippet011CustomTooltips {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends Object> viewer, Object oldInput, Object newInput) {
}
}
@@ -58,37 +59,37 @@ public class Snippet011CustomTooltips {
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
- TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
+ TableViewer<String,Object> v = new TableViewer<String,Object>(shell, SWT.FULL_SELECTION);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
v.setContentProvider(new MyContentProvider());
ColumnViewerToolTipSupport.enableFor(v,ToolTip.NO_RECREATE);
-
- CellLabelProvider labelProvider = new CellLabelProvider() {
- public String getToolTipText(Object element) {
+ CellLabelProvider<String,Object> labelProvider = new CellLabelProvider<String,Object>() {
+
+ public String getToolTipText(String element) {
return "Tooltip (" + element + ")";
}
- public Point getToolTipShift(Object object) {
+ public Point getToolTipShift(String object) {
return new Point(5, 5);
}
- public int getToolTipDisplayDelayTime(Object object) {
+ public int getToolTipDisplayDelayTime(String object) {
return 2000;
}
- public int getToolTipTimeDisplayed(Object object) {
+ public int getToolTipTimeDisplayed(String object) {
return 5000;
}
- public void update(ViewerCell cell) {
+ public void update(ViewerCell<String> cell) {
cell.setText(cell.getElement().toString());
}
};
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<String,Object> column = new TableViewerColumn<String,Object>(v, SWT.NONE);
column.setLabelProvider(labelProvider);
column.getColumn().setText("Column 1");
column.getColumn().setWidth(100);
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java
index 1de89ef..d8095ac 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet013TableViewerNoMandatoryLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableColorProvider;
@@ -31,39 +35,24 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example usage of none mandatory interfaces of ITableFontProvider and
* ITableColorProvider
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet013TableViewerNoMandatoryLabelProvider {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -81,35 +70,35 @@ public class Snippet013TableViewerNoMandatoryLabelProvider {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel>, ITableFontProvider<MyModel>, ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Font getFont(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return registry.getBold(Display.getCurrent().getSystemFont()
.getFontData()[0].getName());
}
return null;
}
- public Color getBackground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Color getBackground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
}
- public Color getForeground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 1) {
+ public Color getForeground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
@@ -118,7 +107,7 @@ public class Snippet013TableViewerNoMandatoryLabelProvider {
}
public Snippet013TableViewerNoMandatoryLabelProvider(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -131,19 +120,17 @@ public class Snippet013TableViewerNoMandatoryLabelProvider {
column.setWidth(200);
column.setText("Column 2");
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet014TreeViewerNoMandatoryLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet014TreeViewerNoMandatoryLabelProvider.java
index e3c8aae..0bc0942 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet014TreeViewerNoMandatoryLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet014TreeViewerNoMandatoryLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -32,70 +33,58 @@ import org.eclipse.swt.widgets.TreeColumn;
/**
* A simple TreeViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet014TreeViewerNoMandatoryLabelProvider {
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
- public Object getParent(Object element) {
- if (element == null) {
+ public MyModel getParent(MyModel element) {
+ if( element == null) {
return null;
}
- return ((MyModel) element).parent;
+ return element.parent;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -103,7 +92,7 @@ public class Snippet014TreeViewerNoMandatoryLabelProvider {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
@@ -124,35 +113,35 @@ public class Snippet014TreeViewerNoMandatoryLabelProvider {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel>, ITableFontProvider<MyModel>, ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Font getFont(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return registry.getBold(Display.getCurrent().getSystemFont()
.getFontData()[0].getName());
}
return null;
}
- public Color getBackground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Color getBackground(MyModel element, int columnIndex) {
+ if ( element.counter % 2 == 0) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
}
- public Color getForeground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 1) {
+ public Color getForeground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
@@ -161,16 +150,16 @@ public class Snippet014TreeViewerNoMandatoryLabelProvider {
}
public Snippet014TreeViewerNoMandatoryLabelProvider(Shell shell) {
- final TreeViewer v = new TreeViewer(shell);
-
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell);
+
TreeColumn column = new TreeColumn(v.getTree(),SWT.NONE);
column.setWidth(200);
column.setText("Column 1");
-
+
column = new TreeColumn(v.getTree(),SWT.NONE);
column.setWidth(200);
column.setText("Column 2");
-
+
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java
index f15d0da..69eb4f4 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet015CustomTooltipsForTree.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -25,43 +26,43 @@ import org.eclipse.swt.widgets.Shell;
/**
* Explore New API: JFace custom tooltips drawing.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.3M2
*/
public class Snippet015CustomTooltipsForTree {
- private static class MyContentProvider implements ITreeContentProvider {
+ private static class MyContentProvider implements ITreeContentProvider<String,Object> {
private static final String ROOT = "Root";
- public Object[] getElements(Object inputElement) {
- return new Object[]{ROOT};
+ public String[] getElements(Object inputElement) {
+ return new String[]{ROOT};
}
public void dispose() {
-
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
-
+ public void inputChanged(Viewer<? extends Object> viewer, Object oldInput, Object newInput) {
+
+
}
- public Object[] getChildren(Object parentElement) {
+ public String[] getChildren(String parentElement) {
if(parentElement.equals(ROOT))
return new String[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
- return new Object[0];
+ return new String[0];
}
- public Object getParent(Object element) {
+ public String getParent(String element) {
return null;
}
- public boolean hasChildren(Object element) {
+ public boolean hasChildren(String element) {
return element.equals(ROOT);
}
}
-
+
/**
* @param args
*/
@@ -69,63 +70,63 @@ public class Snippet015CustomTooltipsForTree {
final Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());
-
- TreeViewer v = new TreeViewer(shell,SWT.FULL_SELECTION);
+
+ TreeViewer<String,Object> v = new TreeViewer<String,Object>(shell,SWT.FULL_SELECTION);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
ColumnViewerToolTipSupport.enableFor(v);
-
+
v.setContentProvider(new MyContentProvider());
-
- CellLabelProvider labelProvider = new CellLabelProvider() {
+
+ CellLabelProvider<String,Object> labelProvider = new CellLabelProvider<String,Object>() {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipText(java.lang.Object)
*/
- public String getToolTipText(Object element) {
+ public String getToolTipText(String element) {
return "Tooltip (" + element + ")";
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipShift(java.lang.Object)
*/
- public Point getToolTipShift(Object object) {
+ public Point getToolTipShift(String object) {
return new Point(5,5);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipDisplayDelayTime(java.lang.Object)
*/
- public int getToolTipDisplayDelayTime(Object object) {
+ public int getToolTipDisplayDelayTime(String object) {
return 2000;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerLabelProvider#getTooltipTimeDisplayed(java.lang.Object)
*/
- public int getToolTipTimeDisplayed(Object object) {
+ public int getToolTipTimeDisplayed(String object) {
return 5000;
}
-
- public void update(ViewerCell cell) {
+
+ public void update(ViewerCell<String> cell) {
cell.setText(cell.getElement().toString());
-
+
}
};
-
-
+
+
v.setLabelProvider(labelProvider);
v.setInput("");
-
+
shell.setSize(200,200);
shell.open ();
-
+
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet017TableViewerHideShowColumns.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet017TableViewerHideShowColumns.java
index 12080b2..ee4578c 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet017TableViewerHideShowColumns.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet017TableViewerHideShowColumns.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,15 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -30,7 +34,7 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example usage of none mandatory interfaces of ITableFontProvider and
* ITableColorProvider
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.2
*/
@@ -38,13 +42,13 @@ public class Snippet017TableViewerHideShowColumns {
private class ShrinkThread extends Thread {
private int width = 0;
private TableColumn column;
-
+
public ShrinkThread(int width, TableColumn column) {
super();
this.width = width;
this.column = column;
}
-
+
public void run() {
column.getDisplay().syncExec(new Runnable() {
@@ -52,7 +56,7 @@ public class Snippet017TableViewerHideShowColumns {
column.setData("restoredWidth", new Integer(width));
}
});
-
+
for( int i = width; i >= 0; i-- ) {
final int index = i;
column.getDisplay().syncExec(new Runnable() {
@@ -60,22 +64,22 @@ public class Snippet017TableViewerHideShowColumns {
public void run() {
column.setWidth(index);
}
-
+
});
}
}
};
-
+
private class ExpandThread extends Thread {
private int width = 0;
private TableColumn column;
-
+
public ExpandThread(int width, TableColumn column) {
super();
this.width = width;
this.column = column;
}
-
+
public void run() {
for( int i = 0; i <= width; i++ ) {
final int index = i;
@@ -84,26 +88,27 @@ public class Snippet017TableViewerHideShowColumns {
public void run() {
column.setWidth(index);
}
-
+
});
}
}
}
-
- private class MyContentProvider implements IStructuredContentProvider {
+
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -112,11 +117,11 @@ public class Snippet017TableViewerHideShowColumns {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -134,20 +139,20 @@ public class Snippet017TableViewerHideShowColumns {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel> {
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
}
public Snippet017TableViewerHideShowColumns(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -159,12 +164,12 @@ public class Snippet017TableViewerHideShowColumns {
column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setText("Column 2");
-
+
column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setText("Column 3");
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
@@ -174,10 +179,10 @@ public class Snippet017TableViewerHideShowColumns {
private void addMenu(TableViewer v) {
final MenuManager mgr = new MenuManager();
Action action;
-
+
for( int i = 0; i < v.getTable().getColumnCount(); i++ ) {
final TableColumn column = v.getTable().getColumn(i);
-
+
action = new Action(v.getTable().getColumn(i).getText(),SWT.CHECK) {
public void runWithEvent(Event event) {
if( ! isChecked() ) {
@@ -188,24 +193,22 @@ public class Snippet017TableViewerHideShowColumns {
t.run();
}
}
-
+
};
action.setChecked(true);
mgr.add(action);
}
-
+
v.getControl().setMenu(mgr.createContextMenu(v.getControl()));
}
-
-
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
- }
+
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
+ }
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet018TableViewerAddRemoveColumnsWithEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet018TableViewerAddRemoveColumnsWithEditing.java
index 5c90d00..9e5a27e 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet018TableViewerAddRemoveColumnsWithEditing.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet018TableViewerAddRemoveColumnsWithEditing.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -14,6 +15,7 @@ package org.eclipse.jface.snippets.viewers;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
@@ -39,7 +41,7 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example of adding and removing columns in conjunction with JFace-Viewers
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.2
*/
@@ -81,38 +83,39 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
}
}
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
+
+ public Person[] getElements(List<Person> inputElement) {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider {
- private TableViewer viewer;
+ public class MyLabelProvider extends LabelProvider<Person> implements
+ ITableLabelProvider<Person> {
+ private TableViewer<Person,List<Person>> viewer;
- public MyLabelProvider(TableViewer viewer) {
+ public MyLabelProvider(TableViewer<Person,List<Person>> viewer) {
this.viewer = viewer;
}
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(Person element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
- return ((Person) element)
- .getValue(viewer.getColumnProperties()[columnIndex]
- .toString());
+ public String getColumnText(Person element, int columnIndex) {
+ return element.getValue(viewer.getColumnProperties()[columnIndex]
+ .toString());
}
}
@@ -142,7 +145,7 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
private int activeColumn = -1;
public Snippet018TableViewerAddRemoveColumnsWithEditing(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider(v));
v.setContentProvider(new MyContentProvider());
@@ -161,7 +164,7 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
column.setWidth(200);
column.setText("Surname");
- Person[] model = createModel();
+ List<Person> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
@@ -171,7 +174,7 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
triggerColumnSelectedColumn(v);
}
- private void triggerColumnSelectedColumn(final TableViewer v) {
+ private void triggerColumnSelectedColumn(final TableViewer<Person,List<Person>> v) {
v.getTable().addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
@@ -188,7 +191,7 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
});
}
- private void addMenu(final TableViewer v) {
+ private void addMenu(final TableViewer<Person,List<Person>> v) {
final MenuManager mgr = new MenuManager();
final Action insertEmailBefore = new Action("Insert E-Mail before") {
@@ -226,7 +229,7 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
v.getControl().setMenu(mgr.createContextMenu(v.getControl()));
}
- private void removeEmailColumn(TableViewer v) {
+ private void removeEmailColumn(TableViewer<Person,List<Person>> v) {
int emailIndex = -1;
for (int i = 0; i < v.getColumnProperties().length; i++) {
if (v.getColumnProperties()[i].toString().equals("email")) {
@@ -252,7 +255,7 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
v.refresh();
}
- private void addEmailColumn(TableViewer v, int columnIndex) {
+ private void addEmailColumn(TableViewer<Person,List<Person>> v, int columnIndex) {
ArrayList list = new ArrayList(Arrays.asList(v.getCellEditors()));
list.add(columnIndex, new TextCellEditor(v.getTable()));
CellEditor[] editors = new CellEditor[list.size()];
@@ -277,12 +280,13 @@ public class Snippet018TableViewerAddRemoveColumnsWithEditing {
column.setWidth(200);
}
- private Person[] createModel() {
- Person[] persons = new Person[3];
- persons[0] = new Person("Tom", "Schindl", "tom.schindl@bestsolution.at");
- persons[1] = new Person("Boris", "Bokowski",
- "boris_bokowski@ca.ibm.com");
- persons[2] = new Person("Tod", "Creasey", "tod_creasey@ca.ibm.com");
+ private List<Person> createModel() {
+
+ List<Person> persons = new ArrayList<Person>();
+ persons.add(new Person("Tom", "Schindl", "tom.schindl@bestsolution.at"));
+ persons.add(new Person("Boris", "Bokowski",
+ "boris_bokowski@ca.ibm.com"));
+ persons.add(new Person("Tod", "Creasey", "tod_creasey@ca.ibm.com"));
return persons;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.java
index 5b2b731..4d7fed8 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,15 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
@@ -36,7 +40,7 @@ import org.eclipse.swt.widgets.Shell;
/**
* Explore the new API added in 3.3 and see how easily you can create reusable
* components
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.2
*/
@@ -56,41 +60,42 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
}
}
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
}
}
-
- private class GivenNameLabelProvider extends ColumnLabelProvider {
- public String getText(Object element) {
- return ((Person) element).givenname;
+
+ private class GivenNameLabelProvider extends ColumnLabelProvider<Person,List<Person>> {
+ public String getText(Person element) {
+ return element.givenname;
}
}
-
+
private class GivenNameEditing extends EditingSupport {
private TextCellEditor cellEditor;
-
- public GivenNameEditing(TableViewer viewer) {
+
+ public GivenNameEditing(TableViewer<Person,List<Person>> viewer) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getTable());
}
-
+
protected boolean canEdit(Object element) {
return true;
}
-
+
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
@@ -104,25 +109,25 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
getViewer().update(element, null);
}
}
-
- private class SurNameLabelProvider extends ColumnLabelProvider {
- public String getText(Object element) {
- return ((Person) element).surname;
+
+ private class SurNameLabelProvider extends ColumnLabelProvider<Person,List<Person>>{
+ public String getText(Person element) {
+ return element.surname;
}
}
-
+
private class SurNameEditing extends EditingSupport {
private TextCellEditor cellEditor;
-
+
public SurNameEditing( TableViewer viewer ) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getTable());
}
-
+
protected boolean canEdit(Object element) {
return true;
}
-
+
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
@@ -136,25 +141,25 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
getViewer().update(element, null);
}
}
-
- private class EmailLabelProvider extends ColumnLabelProvider {
- public String getText(Object element) {
- return ((Person) element).email;
+
+ private class EmailLabelProvider extends ColumnLabelProvider<Person,List<Person>> {
+ public String getText(Person element) {
+ return element.email;
}
}
-
+
private class EmailEditing extends EditingSupport {
private TextCellEditor cellEditor;
-
- public EmailEditing( TableViewer viewer ) {
+
+ public EmailEditing( TableViewer<Person,List<Person>> viewer ) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getTable());
}
-
+
protected boolean canEdit(Object element) {
return true;
}
-
+
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
@@ -168,31 +173,31 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
getViewer().update(element, null);
}
}
-
+
private int activeColumn = -1;
-
- private TableViewerColumn column;
-
+
+ private TableViewerColumn<Person,List<Person>> column;
+
public Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
- TableViewerColumn column = new TableViewerColumn(v,SWT.NONE);
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(v,SWT.NONE);
column.setLabelProvider(new GivenNameLabelProvider());
column.setEditingSupport(new GivenNameEditing(v));
-
+
column.getColumn().setWidth(200);
column.getColumn().setText("Givenname");
column.getColumn().setMoveable(true);
- column = new TableViewerColumn(v,SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v,SWT.NONE);
column.setLabelProvider(new SurNameLabelProvider());
column.setEditingSupport(new SurNameEditing(v));
column.getColumn().setWidth(200);
column.getColumn().setText("Surname");
column.getColumn().setMoveable(true);
- Person[] model = createModel();
+ List<Person> model = createModel();
v.setContentProvider(new MyContentProvider());
v.setInput(model);
@@ -203,7 +208,7 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
triggerColumnSelectedColumn(v);
}
- private void triggerColumnSelectedColumn(final TableViewer v) {
+ private void triggerColumnSelectedColumn(final TableViewer<Person,List<Person>> v) {
v.getTable().addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
@@ -220,13 +225,13 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
});
}
- private void removeEmailColumn(TableViewer v) {
+ private void removeEmailColumn(TableViewer<Person,List<Person>> v) {
column.getColumn().dispose();
v.refresh();
}
- private void addEmailColumn(TableViewer v, int columnIndex) {
- column = new TableViewerColumn(v, SWT.NONE, columnIndex);
+ private void addEmailColumn(TableViewer<Person,List<Person>> v, int columnIndex) {
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE, columnIndex);
column.setLabelProvider(new EmailLabelProvider());
column.setEditingSupport(new EmailEditing(v));
column.getColumn().setText("E-Mail");
@@ -238,7 +243,7 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
}
- private void addMenu(final TableViewer v) {
+ private void addMenu(final TableViewer<Person,List<Person>> v) {
final MenuManager mgr = new MenuManager();
final Action insertEmailBefore = new Action("Insert E-Mail before") {
@@ -264,7 +269,7 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
ConfigureColumns.forTable(v.getTable(), new SameShellProvider(v.getControl()));
}
};
-
+
mgr.setRemoveAllWhenShown(true);
mgr.addMenuListener(new IMenuListener() {
@@ -283,12 +288,13 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
v.getControl().setMenu(mgr.createContextMenu(v.getControl()));
}
- private Person[] createModel() {
- Person[] persons = new Person[3];
- persons[0] = new Person("Tom", "Schindl", "tom.schindl@bestsolution.at");
- persons[1] = new Person("Boris", "Bokowski",
- "boris_bokowski@ca.ibm.com");
- persons[2] = new Person("Tod", "Creasey", "tod_creasey@ca.ibm.com");
+ private List<Person> createModel() {
+
+ List<Person> persons = new ArrayList<Person>();
+ persons.add(new Person("Tom", "Schindl", "tom.schindl@bestsolution.at"));
+ persons.add(new Person("Boris", "Bokowski",
+ "boris_bokowski@ca.ibm.com"));
+ persons.add(new Person("Tod", "Creasey", "tod_creasey@ca.ibm.com"));
return persons;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java
index 66ee74a..335aa9b 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,10 +8,14 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Dinko Ivanov - bug 164365
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -31,29 +35,29 @@ import org.eclipse.swt.widgets.TableItem;
/**
* Editor Activation on DoubleClick instead of single.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet021CellEditorsOnDoubleClick {
private class MyCellModifier implements ICellModifier {
-
- private TableViewer viewer;
-
+
+ private TableViewer<MyModel,List<MyModel>> viewer;
+
private boolean enabled;
-
+
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
- public void setViewer(TableViewer viewer) {
+ public void setViewer(TableViewer<MyModel,List<MyModel>> viewer) {
this.viewer = viewer;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object,
* java.lang.String)
*/
@@ -63,7 +67,7 @@ public class Snippet021CellEditorsOnDoubleClick {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object,
* java.lang.String)
*/
@@ -73,7 +77,7 @@ public class Snippet021CellEditorsOnDoubleClick {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object,
* java.lang.String, java.lang.Object)
*/
@@ -81,24 +85,25 @@ public class Snippet021CellEditorsOnDoubleClick {
TableItem item = (TableItem) element;
((MyModel) item.getData()).counter = Integer.parseInt(value
.toString());
- viewer.update(item.getData(), null);
+ viewer.update((MyModel)item.getData(), null);
}
}
-
- private class MyContentProvider implements IStructuredContentProvider {
+
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -107,11 +112,11 @@ public class Snippet021CellEditorsOnDoubleClick {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -132,7 +137,7 @@ public class Snippet021CellEditorsOnDoubleClick {
public Snippet021CellEditorsOnDoubleClick(Shell shell) {
final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
final MyCellModifier modifier = new MyCellModifier();
-
+
table.addListener(SWT.MouseDown, new Listener() {
public void handleEvent(Event event) {
@@ -141,7 +146,7 @@ public class Snippet021CellEditorsOnDoubleClick {
});
- final TableViewer v = new TableViewer(table);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(table);
table.addListener(SWT.MouseDoubleClick, new Listener() {
@@ -157,7 +162,7 @@ public class Snippet021CellEditorsOnDoubleClick {
for (int i = 0; i < table.getColumnCount(); i++) {
if (item.getBounds(i).contains(event.x, event.y)) {
- v.editElement(item.getData(), i);
+ v.editElement((MyModel)item.getData(), i);
modifier.setEnabled(false);
break;
}
@@ -167,28 +172,26 @@ public class Snippet021CellEditorsOnDoubleClick {
});
modifier.setViewer(v);
-
+
TableColumn column = new TableColumn(table, SWT.NONE);
column.setWidth(200);
- v.setLabelProvider(new LabelProvider());
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setCellModifier(modifier);
v.setColumnProperties(new String[] { "column1" });
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()) });
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet022TableViewerRefreshNoScroll.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet022TableViewerRefreshNoScroll.java
index 744f526..65886f8 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet022TableViewerRefreshNoScroll.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet022TableViewerRefreshNoScroll.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,12 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -35,27 +37,27 @@ import org.eclipse.swt.widgets.TableItem;
* A simple TableViewer to demonstrating how viewers could be refresh and
* scrolling avoided in 3.2. In 3.3 implementors should consider using the
* {@link StructuredViewer#refresh(boolean, boolean)} instead.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet022TableViewerRefreshNoScroll {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- ArrayList list = (ArrayList) inputElement;
- list.add(new MyModel(list.size()));
- return list.toArray();
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ inputElement.add(new MyModel(inputElement.size()));
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -64,11 +66,11 @@ public class Snippet022TableViewerRefreshNoScroll {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -88,13 +90,13 @@ public class Snippet022TableViewerRefreshNoScroll {
public Snippet022TableViewerRefreshNoScroll(Shell shell) {
shell.setLayout(new GridLayout(2, false));
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
- v.setLabelProvider(new LabelProvider());
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel(100));
v.getTable().setLinesVisible(true);
@@ -150,8 +152,8 @@ public class Snippet022TableViewerRefreshNoScroll {
});
}
- private ArrayList createModel(int size) {
- ArrayList elements = new ArrayList();
+ private ArrayList<MyModel> createModel(int size) {
+ ArrayList<MyModel> elements = new ArrayList<MyModel>();
for (int i = 0; i < size; i++) {
elements.add(new MyModel(i));
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet024TableViewerExploreNewAPI.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet024TableViewerExploreNewAPI.java
index c6f1a46..254c608 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet024TableViewerExploreNewAPI.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet024TableViewerExploreNewAPI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
@@ -26,22 +30,23 @@ import org.eclipse.swt.widgets.Shell;
/**
* Example usage of ITableLabelProvider using images and labels
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet024TableViewerExploreNewAPI {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
}
}
@@ -84,17 +89,17 @@ public class Snippet024TableViewerExploreNewAPI {
}
public Snippet024TableViewerExploreNewAPI(Shell shell) {
- TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>>(shell, SWT.BORDER | SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Givenname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).givenname;
+ public String getText(Person element) {
+ return element.givenname;
}
});
@@ -110,14 +115,14 @@ public class Snippet024TableViewerExploreNewAPI {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Surname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).surname;
+ public String getText(Person element) {
+ return element.surname;
}
});
@@ -134,14 +139,14 @@ public class Snippet024TableViewerExploreNewAPI {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("E-Mail");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).email;
+ public String getText(Person element) {
+ return element.email;
}
});
@@ -158,22 +163,19 @@ public class Snippet024TableViewerExploreNewAPI {
});
- Person[] model = createModel();
+ List<Person> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private Person[] createModel() {
- Person[] elements = new Person[4];
- elements[0] = new Person("Tom", "Schindl",
- "tom.schindl@bestsolution.at");
- elements[1] = new Person("Boris", "Bokowski",
- "Boris_Bokowski@ca.ibm.com");
- elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com");
- elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org");
+ private List<Person> createModel() {
- return elements;
+ List<Person> persons = new ArrayList<Person>();
+ persons.add(new Person("Tom", "Schindl", "tom.schindl@bestsolution.at"));
+ persons.add(new Person("Tod", "Creasey", "tod_creasey@ca.ibm.com"));
+ persons.add(new Person("Wayne", "Beaton", "wayne@eclipse.org"));
+ return persons;
}
/**
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java
index 79cb3d1..59e3316 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
@@ -30,58 +34,50 @@ import org.eclipse.swt.widgets.TableItem;
/**
* Edit cell values in a table
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
*/
public class Snippet025TabEditing {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
-
+
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet025TabEditing(Shell shell) {
final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
TableColumn tc = new TableColumn(v.getTable(),SWT.NONE);
tc.setWidth(100);
tc.setText("Column 1");
-
+
tc = new TableColumn(v.getTable(),SWT.NONE);
tc.setWidth(200);
tc.setText("Column 2");
-
+
v.setLabelProvider(new LabelProvider());
v.setContentProvider(new MyContentProvider());
v.setCellModifier(new ICellModifier() {
@@ -108,28 +104,26 @@ public class Snippet025TabEditing {
((MyModel)item.getData()).counter = Integer.parseInt(value.toString());
v.update(item.getData(), null);
}
-
+
});
-
+
v.setColumnProperties(new String[] { "column1", "column2" });
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
TableViewerEditor.create(v,new ColumnViewerEditorActivationStrategy(v),ColumnViewerEditor.TABBING_HORIZONTAL|ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR|ColumnViewerEditor.TABBING_VERTICAL);
-
- MyModel[] model = createModel();
+
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -139,11 +133,11 @@ public class Snippet025TabEditing {
shell.setLayout(new FillLayout());
new Snippet025TabEditing(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java
index 9322e34..241b376 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -37,30 +38,30 @@ import org.eclipse.swt.widgets.Shell;
/**
* A simple TreeViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet026TreeViewerTabEditing {
public Snippet026TreeViewerTabEditing(final Shell shell) {
Button b = new Button(shell,SWT.PUSH);
b.setText("Remove column");
- final TreeViewer v = new TreeViewer(shell, SWT.BORDER
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
b.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
-
+
}
public void widgetSelected(SelectionEvent e) {
v.getTree().getColumn(1).dispose();
}
-
+
});
-
+
TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
@@ -71,20 +72,20 @@ public class Snippet026TreeViewerTabEditing {
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
-
+
TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
-
+
final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
- TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
+ TreeViewerColumn<MyModel,MyModel> column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 1 => " + element.toString();
}
@@ -105,17 +106,17 @@ public class Snippet026TreeViewerTabEditing {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- column = new TreeViewerColumn(v, SWT.NONE);
+ column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 2 => " + element.toString();
}
@@ -136,17 +137,17 @@ public class Snippet026TreeViewerTabEditing {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
-
- column = new TreeViewerColumn(v, SWT.NONE);
+
+ column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 3 => " + element.toString();
}
@@ -167,10 +168,10 @@ public class Snippet026TreeViewerTabEditing {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
-
+
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
@@ -211,31 +212,53 @@ public class Snippet026TreeViewerTabEditing {
display.dispose();
}
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
public void dispose() {
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
+
}
- public Object[] getChildren(Object parentElement) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- public Object getParent(Object element) {
- if (element == null) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public MyModel getParent(MyModel element) {
+ if( element == null) {
return null;
}
- return ((MyModel) element).parent;
+
+ return element.parent;
}
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -243,7 +266,7 @@ public class Snippet026TreeViewerTabEditing {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet027ComboBoxCellEditors.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet027ComboBoxCellEditors.java
index 2363d85..448171e 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet027ComboBoxCellEditors.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet027ComboBoxCellEditors.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,10 +8,14 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Dinko Ivanov - bug 164365
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
@@ -29,22 +33,22 @@ import org.eclipse.swt.widgets.TableItem;
/**
* This snippet represents usage of the ComboBoxCell-Editor
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet027ComboBoxCellEditors {
private class MyCellModifier implements ICellModifier {
- private TableViewer viewer;
+ private TableViewer<MyModel,List<MyModel>> viewer;
- public MyCellModifier(TableViewer viewer) {
+ public MyCellModifier(TableViewer<MyModel,List<MyModel>> viewer) {
this.viewer = viewer;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object,
* java.lang.String)
*/
@@ -54,7 +58,7 @@ public class Snippet027ComboBoxCellEditors {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object,
* java.lang.String)
*/
@@ -65,7 +69,7 @@ public class Snippet027ComboBoxCellEditors {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object,
* java.lang.String, java.lang.Object)
*/
@@ -73,37 +77,22 @@ public class Snippet027ComboBoxCellEditors {
TableItem item = (TableItem) element;
// We get the index and need to calculate the real value
((MyModel) item.getData()).counter = ((Integer) value).intValue() * 10;
- viewer.update(item.getData(), null);
+ viewer.update((MyModel)item.getData(), null);
}
}
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -123,13 +112,13 @@ public class Snippet027ComboBoxCellEditors {
public Snippet027ComboBoxCellEditors(Shell shell) {
final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
- final TableViewer v = new TableViewer(table);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(table);
final MyCellModifier modifier = new MyCellModifier(v);
TableColumn column = new TableColumn(table, SWT.NONE);
column.setWidth(200);
- v.setLabelProvider(new LabelProvider());
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setCellModifier(modifier);
v.setColumnProperties(new String[] { "column1" });
@@ -138,18 +127,16 @@ public class Snippet027ComboBoxCellEditors {
"Fourty", "Fifty", "Sixty", "Seventy", "Eighty",
"Ninety" }) });
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i * 10);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java
index 6b47105..0f525e7 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
@@ -23,26 +27,27 @@ import org.eclipse.swt.widgets.Shell;
/**
* A simple TableViewer to demonstrate the usage of a standard content provider
* with a virtual table
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet029VirtualTableViewer {
- private class MyContentProvider implements IStructuredContentProvider {
- private MyModel[] elements;
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
+ private List<MyModel> elements;
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return elements;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return elements.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -51,12 +56,12 @@ public class Snippet029VirtualTableViewer {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- this.elements = (MyModel[]) newInput;
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+ this.elements = newInput;
}
}
@@ -73,23 +78,21 @@ public class Snippet029VirtualTableViewer {
}
public Snippet029VirtualTableViewer(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.VIRTUAL);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.VIRTUAL);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
v.setUseHashlookup(true);
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10000];
-
- for (int i = 0; i < 10000; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10000);
+ for( int i = 0; i < 10000; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet030VirtualLazyTableViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet030VirtualLazyTableViewer.java
index 7356701..d03421f 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet030VirtualLazyTableViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet030VirtualLazyTableViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.ILazyContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
@@ -24,16 +28,16 @@ import org.eclipse.swt.widgets.Shell;
* A simple TableViewer to demonstrate usage of an ILazyContentProvider. You can
* compare this snippet to the Snippet029VirtualTableViewer to see the small but
* needed difference.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet030VirtualLazyTableViewer {
- private class MyContentProvider implements ILazyContentProvider {
- private TableViewer viewer;
- private MyModel[] elements;
+ private class MyContentProvider implements ILazyContentProvider<List<MyModel>> {
+ private TableViewer<MyModel,List<MyModel>> viewer;
+ private List<MyModel> elements;
- public MyContentProvider(TableViewer viewer) {
+ public MyContentProvider(TableViewer<MyModel,List<MyModel>> viewer) {
this.viewer = viewer;
}
@@ -41,12 +45,12 @@ public class Snippet030VirtualLazyTableViewer {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- this.elements = (MyModel[]) newInput;
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+ this.elements = newInput;
}
public void updateElement(int index) {
- viewer.replace(elements[index], index);
+ viewer.replace(elements.get(index), index);
}
}
@@ -64,25 +68,23 @@ public class Snippet030VirtualLazyTableViewer {
}
public Snippet030VirtualLazyTableViewer(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.VIRTUAL);
- v.setLabelProvider(new LabelProvider());
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.VIRTUAL);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider(v));
v.setUseHashlookup(true);
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
- v.setItemCount(model.length); // This is the difference when using a
+ v.setItemCount(model.size()); // This is the difference when using a
// ILazyContentProvider
v.getTable().setLinesVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10000];
-
- for (int i = 0; i < 10000; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10000);
+ for( int i = 0; i < 10000; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java
index 7425f1f..f2368e9 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Adam Neal and others.
+ * Copyright (c) 2007, 2013 Adam Neal 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:
* Adam Neal - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -34,34 +35,34 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
/**
- * A simple TableViewer to demonstrate how custom tooltips could be created easily while preserving
+ * A simple TableViewer to demonstrate how custom tooltips could be created easily while preserving
* the multiple selection.
- *
+ *
* This is a modified example taken from Tom Schindl's Snippet023TreeViewerCustomTooltips.java
- *
+ *
* This code is for users pre 3.3 others could use newly added tooltip support in {@link CellLabelProvider}
* @author Adam Neal <Adam_Neal@ca.ibm.com>
- *
+ *
*/
public class Snippet031TableViewerCustomTooltipsMultiSelection {
- public class MyLableProvider implements ITableLabelProvider {
+ public class MyLableProvider implements ITableLabelProvider<MyModel> {
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
- if (element instanceof MyModel) {
- switch (columnIndex) {
- case 0: return ((MyModel)element).col1;
- case 1: return ((MyModel)element).col2;
- }
+ public String getColumnText(MyModel element, int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return element.col1;
+ case 1:
+ return element.col2;
}
return "";
}
- public void addListener(ILabelProviderListener listener) {
+ public void addListener(ILabelProviderListener<MyModel> listener) {
/* Ignore */
}
@@ -69,16 +70,16 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
/* Ignore */
}
- public boolean isLabelProperty(Object element, String property) {
+ public boolean isLabelProperty(MyModel element, String property) {
return false;
}
- public void removeListener(ILabelProviderListener listener) {
+ public void removeListener(ILabelProviderListener<MyModel> listener) {
/* Ignore */
}
-
+
}
-
+
public class MyModel {
public String col1, col2;
@@ -86,7 +87,7 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
col1 = c1;
col2 = c2;
}
-
+
public String toString() {
return col1 + col2;
}
@@ -97,23 +98,23 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
final Table table = new Table(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
-
- final TableViewer v = new TableViewer(table);
+
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(table);
TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
TableColumn tableColumn2 = new TableColumn(table, SWT.NONE);
-
+
String column1 = "Column 1", column2 = "Column 2";
/* Setup the table columns */
tableColumn1.setText(column1);
tableColumn2.setText(column2);
tableColumn1.pack();
tableColumn2.pack();
-
+
v.setColumnProperties(new String[] { column1, column2 });
v.setLabelProvider(new MyLableProvider());
- v.setContentProvider(new ArrayContentProvider());
+ v.setContentProvider(new ArrayContentProvider<MyModel>(MyModel.class));
v.setInput(createModel());
-
+
/**
* The listener that gets added to the table. This listener is responsible for creating the tooltips
* when hovering over a cell item. This listener will listen for the following events:
@@ -125,7 +126,7 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
Listener tableListener = new Listener () {
Shell tooltip = null;
Label label = null;
-
+
/*
* (non-Javadoc)
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
@@ -150,7 +151,7 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
if (item.getBounds(columnIndex).contains(coords)) {
/* Dispose of the old tooltip (if one exists */
if (tooltip != null && !tooltip.isDisposed ()) tooltip.dispose ();
-
+
/* Create a new Tooltip */
tooltip = new Shell (table.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
tooltip.setBackground (table.getDisplay().getSystemColor (SWT.COLOR_INFO_BACKGROUND));
@@ -160,23 +161,23 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
label = new Label (tooltip, SWT.NONE);
label.setForeground (table.getDisplay().getSystemColor (SWT.COLOR_INFO_FOREGROUND));
label.setBackground (table.getDisplay().getSystemColor (SWT.COLOR_INFO_BACKGROUND));
-
+
/* Store the TableItem with the label so we can pass the mouse event later */
label.setData ("_TableItem_", item);
-
+
/* Set the tooltip text */
label.setText("Tooltip: " + item.getData() + " : " + columnIndex);
-
+
/* Setup Listeners to remove the tooltip and transfer the received mouse events */
label.addListener (SWT.MouseExit, tooltipLabelListener);
label.addListener (SWT.MouseDown, tooltipLabelListener);
-
+
/* Set the size and position of the tooltip */
Point size = tooltip.computeSize (SWT.DEFAULT, SWT.DEFAULT);
Rectangle rect = item.getBounds (columnIndex);
Point pt = table.toDisplay (rect.x, rect.y);
tooltip.setBounds (pt.x, pt.y, size.x, size.y);
-
+
/* Show it */
tooltip.setVisible (true);
break;
@@ -187,13 +188,13 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
}
}
};
-
+
table.addListener (SWT.Dispose, tableListener);
table.addListener (SWT.KeyDown, tableListener);
table.addListener (SWT.MouseMove, tableListener);
table.addListener (SWT.MouseHover, tableListener);
}
-
+
/**
* This listener is added to the tooltip so that it can either dispose itself if the mouse
* exits the tooltip or so it can pass the selection event through to the table.
@@ -216,11 +217,11 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
Event e = new Event ();
e.item = (TableItem) label.getData ("_TableItem_");
Table table = ((TableItem) e.item).getParent();
-
+
/* Construct the new Selection[] to show */
TableItem [] newSelection = null;
if (isCTRLDown(event)) {
- /* We have 2 scenario's.
+ /* We have 2 scenario's.
* 1) We are selecting an already selected element - so remove it from the selected indices
* 2) We are selecting a non-selected element - so add it to the selected indices
*/
@@ -234,7 +235,7 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
break;
}
}
-
+
/*
* If we haven't created the newSelection[] yet, than we are adding the newly selected element
* into the list of selected indicies
@@ -244,7 +245,7 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
System.arraycopy(sel, 0, newSelection, 0, sel.length);
newSelection[sel.length] = (TableItem) e.item;
}
-
+
} else {
/* CTRL is not down, so we simply select the single element */
newSelection = new TableItem[] { (TableItem) e.item };
@@ -252,7 +253,7 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
/* Set the new selection of the table and notify the listeners */
table.setSelection (newSelection);
table.notifyListeners (SWT.Selection, e);
-
+
/* Remove the Tooltip */
shell.dispose ();
table.setFocus();
@@ -262,11 +263,11 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
break;
}
}};
-
-
-
- private List createModel() {
- ArrayList list = new ArrayList();
+
+
+
+ private List<MyModel> createModel() {
+ ArrayList<MyModel> list = new ArrayList<MyModel>();
list.add(new MyModel("A", "B"));
list.add(new MyModel("C", "D"));
list.add(new MyModel("E", "F"));
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet032TableTreeViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet032TableTreeViewer.java
index 1fab42e..dac9e10 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet032TableTreeViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet032TableTreeViewer.java
@@ -107,7 +107,7 @@ public class Snippet032TableTreeViewer {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
@@ -128,35 +128,35 @@ public class Snippet032TableTreeViewer {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel>, ITableFontProvider<MyModel>, ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Font getFont(MyModel element, int columnIndex) {
+ if ( element.counter % 2 == 0) {
return registry.getBold(Display.getCurrent().getSystemFont()
.getFontData()[0].getName());
}
return null;
}
- public Color getBackground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Color getBackground(MyModel element, int columnIndex) {
+ if ( element.counter % 2 == 0) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
}
- public Color getForeground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 1) {
+ public Color getForeground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java
index 59dc1e2..2bfb3b6 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java
@@ -8,10 +8,14 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CellEditor;
@@ -100,15 +104,16 @@ public class Snippet033CellEditorPerRowPre33 {
}
}
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
@@ -126,7 +131,7 @@ public class Snippet033CellEditorPerRowPre33 {
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -270,7 +275,7 @@ public class Snippet033CellEditorPerRowPre33 {
final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
final MyCellModifier modifier = new MyCellModifier();
- final TableViewer v = new TableViewer(table);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(table);
modifier.setViewer(v);
TableColumn column = new TableColumn(table, SWT.NONE);
@@ -282,13 +287,13 @@ public class Snippet033CellEditorPerRowPre33 {
v.setColumnProperties(new String[] { "column1" });
v.setCellEditors(new CellEditor[] { new DelegatingEditor(v,v.getTable()) });
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
- private class MyLabelProvider extends LabelProvider {
- public Image getImage(Object element) {
+ private class MyLabelProvider extends LabelProvider<MyModel> {
+ public Image getImage(MyModel element) {
if( element instanceof MyModel3 ) {
if( ((MyModel3)element).checked ) {
return JFaceResources.getImage("IMG_1");
@@ -302,19 +307,19 @@ public class Snippet033CellEditorPerRowPre33 {
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[30];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(30);
for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel3(i);
+ elements.add(i,new MyModel3(i));
}
for (int i = 0; i < 10; i++) {
- elements[i+10] = new MyModel(i);
+ elements.add(i+10,new MyModel(i));
}
for (int i = 0; i < 10; i++) {
- elements[i+20] = new MyModel2(i);
+ elements.add(i+20,new MyModel2(i));
}
return elements;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRowNewAPI.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRowNewAPI.java
index 4dfacf2..7146d1c 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRowNewAPI.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRowNewAPI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Tom Schindl and others.
+ * Copyright (c) 2007, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,10 +8,14 @@
* Contributors:
* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
* Wayne Beaton - bug 185540
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
@@ -30,26 +34,26 @@ import org.eclipse.swt.widgets.Table;
/**
* Snippet to present editor different CellEditors within one column in 3.2
* for 3.3 and above please use the new EditingSupport class
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet034CellEditorPerRowNewAPI {
private class MyEditingSupport extends EditingSupport {
private CellEditor textEditor;
-
+
private CellEditor dropDownEditor;
-
- public MyEditingSupport(TableViewer viewer) {
+
+ public MyEditingSupport(TableViewer<MyModel,List<MyModel>> viewer) {
super(viewer);
textEditor = new TextCellEditor(viewer.getTable());
-
+
String[] elements = new String[10];
-
+
for (int i = 0; i < 10; i++) {
elements[i] = i+"";
}
-
+
dropDownEditor = new ComboBoxCellEditor(viewer.getTable(),elements);
}
@@ -77,23 +81,24 @@ public class Snippet034CellEditorPerRowNewAPI {
((MyModel)element).counter = Integer.parseInt(value.toString());
getViewer().update(element, null);
}
-
+
}
-
- private class MyContentProvider implements IStructuredContentProvider {
+
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -102,11 +107,11 @@ public class Snippet034CellEditorPerRowNewAPI {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -134,42 +139,42 @@ public class Snippet034CellEditorPerRowNewAPI {
return "Special Item " + this.counter;
}
}
-
+
public Snippet034CellEditorPerRowNewAPI(Shell shell) {
final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
-
- final TableViewer v = new TableViewer(table);
+
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(table);
v.getTable().setLinesVisible(true);
-
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+
+ TableViewerColumn<MyModel,List<MyModel>> column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return element.toString();
}
-
+
});
-
+
column.setEditingSupport(new MyEditingSupport(v));
-
+
v.setContentProvider(new MyContentProvider());
-
- MyModel[] model = createModel();
+
+ List<MyModel> model = createModel();
v.setInput(model);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[20];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(20);
for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
for (int i = 0; i < 10; i++) {
- elements[i+10] = new MyModel2(i);
+ elements.add(i+10,new MyModel2(i));
}
-
+
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java
index aa7d430..da99e94 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
@@ -39,26 +43,27 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example usage of none mandatory interfaces of ITableFontProvider and
* ITableColorProvider
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet035TableCursorCellHighlighter {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -67,18 +72,18 @@ public class Snippet035TableCursorCellHighlighter {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
}
public static boolean flag = true;
-
+
public class MyModel {
public int counter;
@@ -91,35 +96,35 @@ public class Snippet035TableCursorCellHighlighter {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel>, ITableFontProvider<MyModel>, ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Font getFont(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return registry.getBold(Display.getCurrent().getSystemFont()
.getFontData()[0].getName());
}
return null;
}
- public Color getBackground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Color getBackground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
}
- public Color getForeground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 1) {
+ public Color getForeground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
@@ -128,7 +133,7 @@ public class Snippet035TableCursorCellHighlighter {
}
public Snippet035TableCursorCellHighlighter(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER|SWT.HIDE_SELECTION|SWT.FULL_SELECTION);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER|SWT.HIDE_SELECTION|SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -144,13 +149,13 @@ public class Snippet035TableCursorCellHighlighter {
}
public void modify(Object element, String property, Object value) {
-
+
}
-
+
});
-
+
v.setColumnProperties(new String[] {"1","2"});
-
+
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new CursorCellHighlighter(v,new TableCursor(v)));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
@@ -161,12 +166,12 @@ public class Snippet035TableCursorCellHighlighter {
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
-
+
TableViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
-
+
TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setText("Column 1");
@@ -175,17 +180,17 @@ public class Snippet035TableCursorCellHighlighter {
column.setWidth(200);
column.setText("Column 2");
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
return elements;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet036FocusBorderCellHighlighter.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet036FocusBorderCellHighlighter.java
index 6d0e5fa..1314d01 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet036FocusBorderCellHighlighter.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet036FocusBorderCellHighlighter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
@@ -38,26 +42,27 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example of a different focus cell rendering with a simply focus border
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet036FocusBorderCellHighlighter {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -66,18 +71,18 @@ public class Snippet036FocusBorderCellHighlighter {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
}
public static boolean flag = true;
-
+
public class MyModel {
public int counter;
@@ -90,34 +95,34 @@ public class Snippet036FocusBorderCellHighlighter {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel>, ITableFontProvider<MyModel>, ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
+ public Font getFont(MyModel element, int columnIndex) {
return null;
}
- public Color getBackground(Object element, int columnIndex) {
+ public Color getBackground(MyModel element, int columnIndex) {
return null;
}
- public Color getForeground(Object element, int columnIndex) {
+ public Color getForeground(MyModel element, int columnIndex) {
return null;
}
}
public Snippet036FocusBorderCellHighlighter(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER|SWT.FULL_SELECTION);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER|SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -133,13 +138,13 @@ public class Snippet036FocusBorderCellHighlighter {
}
public void modify(Object element, String property, Object value) {
-
+
}
-
+
});
-
+
v.setColumnProperties(new String[] {"1","2","3"});
-
+
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new FocusBorderCellHighlighter(v));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
@@ -150,12 +155,12 @@ public class Snippet036FocusBorderCellHighlighter {
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
-
+
TableViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
-
+
TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setMoveable(true);
@@ -171,18 +176,18 @@ public class Snippet036FocusBorderCellHighlighter {
column.setMoveable(true);
column.setText("Column 3");
-
- MyModel[] model = createModel();
+
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
return elements;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet037FancyCustomTooltips.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet037FancyCustomTooltips.java
index d47bb2b..d89364c 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet037FancyCustomTooltips.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet037FancyCustomTooltips.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl - initial API and implementation
* IBM - Improvement for Bug 159625 [Snippets] Update Snippet011CustomTooltips to reflect new API
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -34,15 +35,15 @@ import org.eclipse.swt.widgets.Shell;
/**
* Explore New API: JFace custom tooltips drawing.
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.3
*/
public class Snippet037FancyCustomTooltips {
private static class MyContentProvider implements
- IStructuredContentProvider {
+ IStructuredContentProvider<String,Object> {
- public Object[] getElements(Object inputElement) {
+ public String[] getElements(Object inputElement) {
return new String[] { "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten" };
}
@@ -51,19 +52,19 @@ public class Snippet037FancyCustomTooltips {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends Object> viewer, Object oldInput, Object newInput) {
}
}
- private static class FancyToolTipSupport extends ColumnViewerToolTipSupport {
+ private static class FancyToolTipSupport extends ColumnViewerToolTipSupport<String,Object> {
- protected FancyToolTipSupport(ColumnViewer viewer, int style,
+ protected FancyToolTipSupport(ColumnViewer<String,Object> viewer, int style,
boolean manualActivation) {
super(viewer, style, manualActivation);
}
-
-
+
+
protected Composite createToolTipContentArea(Event event,
Composite parent) {
Composite comp = new Composite(parent,SWT.NONE);
@@ -72,13 +73,13 @@ public class Snippet037FancyCustomTooltips {
l.marginWidth=0;
l.marginHeight=0;
l.verticalSpacing=0;
-
+
comp.setLayout(l);
Browser browser = new Browser(comp,SWT.BORDER);
browser.setText(getText(event));
browser.setLayoutData(new GridData(200,150));
-
-
+
+
return comp;
}
@@ -87,11 +88,11 @@ public class Snippet037FancyCustomTooltips {
}
- public static final void enableFor(ColumnViewer viewer, int style) {
+ public static final void enableFor(ColumnViewer<String,Object> viewer, int style) {
new FancyToolTipSupport(viewer,style,false);
}
}
-
+
/**
* @param args
*/
@@ -100,36 +101,36 @@ public class Snippet037FancyCustomTooltips {
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
- TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
+ TableViewer<String,Object> v = new TableViewer<String,Object>(shell, SWT.FULL_SELECTION);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
v.setContentProvider(new MyContentProvider());
FancyToolTipSupport.enableFor(v,ToolTip.NO_RECREATE);
-
- CellLabelProvider labelProvider = new CellLabelProvider() {
- public String getToolTipText(Object element) {
+ CellLabelProvider<String,Object> labelProvider = new CellLabelProvider<String,Object>() {
+
+ public String getToolTipText(String element) {
return "<html><body>Tooltip (" + element + ")<br /><a href='http://www.bestsolution.at' target='_NEW'>www.bestsolution.at</a></body></html>";
}
- public Point getToolTipShift(Object object) {
+ public Point getToolTipShift(String object) {
return new Point(5, 5);
}
- public int getToolTipDisplayDelayTime(Object object) {
+ public int getToolTipDisplayDelayTime(String object) {
return 2000;
}
- public int getToolTipTimeDisplayed(Object object) {
+ public int getToolTipTimeDisplayed(String object) {
return 5000;
}
- public void update(ViewerCell cell) {
+ public void update(ViewerCell<String> cell) {
cell.setText(cell.getElement().toString());
}
};
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<String,Object> column = new TableViewerColumn<String,Object>(v, SWT.NONE);
column.setLabelProvider(labelProvider);
column.getColumn().setText("Column 1");
column.getColumn().setWidth(100);
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet038TreeViewerInlinelEditingOldAPI.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet038TreeViewerInlinelEditingOldAPI.java
index c61c310..ae85855 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet038TreeViewerInlinelEditingOldAPI.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet038TreeViewerInlinelEditingOldAPI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -32,25 +33,27 @@ import org.eclipse.swt.widgets.TreeItem;
/**
* A simple TreeViewer to demonstrate usage of inline editing
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet038TreeViewerInlinelEditingOldAPI {
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ public MyModel[] getElements(MyModel inputElement) {
+
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -59,43 +62,43 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
- public Object getParent(Object element) {
+ public MyModel getParent(MyModel element) {
if (element == null) {
return null;
}
- return ((MyModel) element).parent;
+ return element.parent;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -103,7 +106,7 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
@@ -124,30 +127,30 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
}
public Snippet038TreeViewerInlinelEditingOldAPI(Shell shell) {
- final TreeViewer v = new TreeViewer(shell,SWT.FULL_SELECTION);
-
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell,SWT.FULL_SELECTION);
+
TreeColumn column = new TreeColumn(v.getTree(),SWT.NONE);
column.setWidth(200);
column.setText("Column 1");
-
+
column = new TreeColumn(v.getTree(),SWT.NONE);
column.setWidth(200);
column.setText("Column 2");
-
+
v.setCellEditors(new CellEditor[]{new TextCellEditor(v.getTree()), new TextCellEditor(v.getTree())});
v.setColumnProperties(new String[]{"col1","col2"});
v.setCellModifier(new ICellModifier() {
@@ -162,9 +165,9 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
public void modify(Object element, String property, Object value) {
((MyModel)((TreeItem)element).getData()).counter = Integer.parseInt(value.toString());
- v.update(((TreeItem)element).getData(), null);
+ v.update((MyModel)((TreeItem)element).getData(), null);
}
-
+
});
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet039ListViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet039ListViewer.java
index 463ad2c..224dd94 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet039ListViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet039ListViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
@@ -24,52 +28,51 @@ import org.eclipse.swt.widgets.Shell;
* Demonstrate a simple ListViewer
*/
public class Snippet039ListViewer {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
public void dispose() {
-
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
+
}
-
+
}
-
+
public class MyModel {
public int counter;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
public String toString() {
return "Item " + this.counter;
}
}
-
+
public Snippet039ListViewer(Shell shell) {
- final ListViewer v = new ListViewer(shell,SWT.H_SCROLL|SWT.V_SCROLL);
- v.setLabelProvider(new LabelProvider());
+ final ListViewer<MyModel,List<MyModel>> v = new ListViewer<MyModel,List<MyModel>>(shell,SWT.H_SCROLL|SWT.V_SCROLL);
+ v.setLabelProvider(new LabelProvider<MyModel>());
v.setContentProvider(new MyContentProvider());
- MyModel[] model = createModel();
- v.setInput(model);
+ List<MyModel> model = createModel();
+ v.setInput(model);
}
-
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
-
+
/**
* @param args
*/
@@ -79,11 +82,11 @@ public class Snippet039ListViewer {
shell.setLayout(new FillLayout());
new Snippet039ListViewer(shell);
shell.open ();
-
+
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
-
+
display.dispose ();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java
index 6b271ac..97b8564 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
@@ -30,22 +34,23 @@ import org.eclipse.swt.widgets.Shell;
/**
* Example usage of ViewerComparator in tables to allow sorting
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet040TableViewerSorting {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
}
}
@@ -66,7 +71,7 @@ public class Snippet040TableViewerSorting {
protected abstract class AbstractEditingSupport extends EditingSupport {
private TextCellEditor editor;
- public AbstractEditingSupport(TableViewer viewer) {
+ public AbstractEditingSupport(TableViewer<Person,List<Person>> viewer) {
super(viewer);
this.editor = new TextCellEditor(viewer.getTable());
}
@@ -88,17 +93,17 @@ public class Snippet040TableViewerSorting {
}
public Snippet040TableViewerSorting(Shell shell) {
- TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>>(shell, SWT.BORDER | SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Givenname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).givenname;
+ public String getText(Person element) {
+ return element.givenname;
}
});
@@ -113,7 +118,7 @@ public class Snippet040TableViewerSorting {
}
});
-
+
ColumnViewerSorter cSorter = new ColumnViewerSorter(v,column) {
protected int doCompare(Viewer viewer, Object e1, Object e2) {
@@ -121,17 +126,17 @@ public class Snippet040TableViewerSorting {
Person p2 = (Person) e2;
return p1.givenname.compareToIgnoreCase(p2.givenname);
}
-
+
};
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Surname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).surname;
+ public String getText(Person element) {
+ return element.surname;
}
});
@@ -147,7 +152,7 @@ public class Snippet040TableViewerSorting {
}
});
-
+
new ColumnViewerSorter(v,column) {
protected int doCompare(Viewer viewer, Object e1, Object e2) {
@@ -155,17 +160,17 @@ public class Snippet040TableViewerSorting {
Person p2 = (Person) e2;
return p1.surname.compareToIgnoreCase(p2.surname);
}
-
+
};
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("E-Mail");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).email;
+ public String getText(Person element) {
+ return element.email;
}
});
@@ -181,7 +186,7 @@ public class Snippet040TableViewerSorting {
}
});
-
+
new ColumnViewerSorter(v,column) {
protected int doCompare(Viewer viewer, Object e1, Object e2) {
@@ -189,42 +194,42 @@ public class Snippet040TableViewerSorting {
Person p2 = (Person) e2;
return p1.email.compareToIgnoreCase(p2.email);
}
-
+
};
- Person[] model = createModel();
+ List<Person> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
cSorter.setSorter(cSorter, ColumnViewerSorter.ASC);
}
- private Person[] createModel() {
- Person[] elements = new Person[4];
- elements[0] = new Person("Tom", "Schindl",
- "tom.schindl@bestsolution.at");
- elements[1] = new Person("Boris", "Bokowski",
- "Boris_Bokowski@ca.ibm.com");
- elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com");
- elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org");
+ private List<Person> createModel() {
+ List<Person> elements = new ArrayList<Person>(4);
+ elements.add(new Person("Tom", "Schindl",
+ "tom.schindl@bestsolution.at"));
+ elements.add(new Person("Boris", "Bokowski",
+ "Boris_Bokowski@ca.ibm.com"));
+ elements.add(new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com"));
+ elements.add(new Person("Wayne", "Beaton", "wayne@eclipse.org"));
return elements;
}
private static abstract class ColumnViewerSorter extends ViewerComparator {
public static final int ASC = 1;
-
+
public static final int NONE = 0;
-
+
public static final int DESC = -1;
-
+
private int direction = 0;
-
- private TableViewerColumn column;
-
- private ColumnViewer viewer;
-
- public ColumnViewerSorter(ColumnViewer viewer, TableViewerColumn column) {
+
+ private TableViewerColumn<Person,List<Person>> column;
+
+ private ColumnViewer<Person,List<Person>> viewer;
+
+ public ColumnViewerSorter(ColumnViewer<Person,List<Person>> viewer, TableViewerColumn<Person,List<Person>> column) {
this.column = column;
this.viewer = viewer;
this.column.getColumn().addSelectionListener(new SelectionAdapter() {
@@ -233,7 +238,7 @@ public class Snippet040TableViewerSorting {
if( ColumnViewerSorter.this.viewer.getComparator() != null ) {
if( ColumnViewerSorter.this.viewer.getComparator() == ColumnViewerSorter.this ) {
int tdirection = ColumnViewerSorter.this.direction;
-
+
if( tdirection == ASC ) {
setSorter(ColumnViewerSorter.this, DESC);
} else if( tdirection == DESC ) {
@@ -248,7 +253,7 @@ public class Snippet040TableViewerSorting {
}
});
}
-
+
public void setSorter(ColumnViewerSorter sorter, int direction) {
if( direction == NONE ) {
column.getColumn().getParent().setSortColumn(null);
@@ -257,29 +262,29 @@ public class Snippet040TableViewerSorting {
} else {
column.getColumn().getParent().setSortColumn(column.getColumn());
sorter.direction = direction;
-
+
if( direction == ASC ) {
column.getColumn().getParent().setSortDirection(SWT.DOWN);
} else {
column.getColumn().getParent().setSortDirection(SWT.UP);
}
-
+
if( viewer.getComparator() == sorter ) {
viewer.refresh();
} else {
viewer.setComparator(sorter);
}
-
+
}
}
public int compare(Viewer viewer, Object e1, Object e2) {
return direction * doCompare(viewer, e1, e2);
}
-
+
protected abstract int doCompare(Viewer viewer, Object e1, Object e2);
}
-
+
/**
* @param args
*/
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java
index a6337e4..9969b76 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Tom Schindl and others.
+ * Copyright (c) 2007, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
@@ -29,27 +33,28 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;
/**
- * Demonstrate alternating row colors using new Jace 3.3 API
- *
+ * Demonstrate alternating row colors using new Jace 3.3 API
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet041TableViewerAlternatingColors {
- private class MyContentProvider implements IStructuredContentProvider {
-
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
+
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -58,11 +63,11 @@ public class Snippet041TableViewerAlternatingColors {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
}
@@ -81,10 +86,10 @@ public class Snippet041TableViewerAlternatingColors {
private class OptimizedIndexSearcher {
private int lastIndex = 0;
-
+
public boolean isEven(TableItem item) {
TableItem[] items = item.getParent().getItems();
-
+
// 1. Search the next ten items
for( int i = lastIndex; i < items.length && lastIndex + 10 > i; i++ ) {
if( items[i] == item ) {
@@ -92,7 +97,7 @@ public class Snippet041TableViewerAlternatingColors {
return lastIndex % 2 == 0;
}
}
-
+
// 2. Search the previous ten items
for( int i = lastIndex; i < items.length && lastIndex - 10 > i; i-- ) {
if( items[i] == item ) {
@@ -100,7 +105,7 @@ public class Snippet041TableViewerAlternatingColors {
return lastIndex % 2 == 0;
}
}
-
+
// 3. Start from the beginning
for( int i = 0; i < items.length; i++ ) {
if( items[i] == item ) {
@@ -108,95 +113,95 @@ public class Snippet041TableViewerAlternatingColors {
return lastIndex % 2 == 0;
}
}
-
+
return false;
}
}
-
+
public Snippet041TableViewerAlternatingColors(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION|SWT.VIRTUAL);
v.setContentProvider(new MyContentProvider());
final OptimizedIndexSearcher searcher = new OptimizedIndexSearcher();
-
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+
+ TableViewerColumn<MyModel,List<MyModel>> column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>() {
boolean even = true;
-
- public Color getBackground(Object element) {
+
+ public Color getBackground(MyModel element) {
if( even ) {
return null;
} else {
return v.getTable().getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
}
-
- public void update(ViewerCell cell) {
+
+ public void update(ViewerCell<MyModel> cell) {
even = searcher.isEven((TableItem)cell.getItem());
super.update(cell);
}
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>() {
boolean even = true;
- public Color getBackground(Object element) {
+ public Color getBackground(MyModel element) {
if( even ) {
return null;
} else {
return v.getTable().getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
}
-
- public void update(ViewerCell cell) {
+
+ public void update(ViewerCell<MyModel> cell) {
even = searcher.isEven((TableItem)cell.getItem());
super.update(cell);
}
-
+
});
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
-
- final ViewerFilter filter = new ViewerFilter() {
- public boolean select(Viewer viewer, Object parentElement,
- Object element) {
- return ((MyModel)element).counter % 2 == 0;
+ final ViewerFilter<MyModel,List<MyModel>> filter = new ViewerFilter<MyModel,List<MyModel>>() {
+
+ public boolean select(Viewer<List<MyModel>> viewer, Object parentElement,
+ MyModel element) {
+ return element.counter % 2 == 0;
}
-
+
};
-
+
Button b = new Button(shell,SWT.PUSH);
b.addSelectionListener(new SelectionAdapter() {
boolean b = true;
-
+
public void widgetSelected(SelectionEvent e) {
if( b ) {
- v.setFilters(new ViewerFilter[] {filter});
+ v.addFilter(filter);
b = false;
} else {
v.setFilters(new ViewerFilter[0]);
b = true;
}
}
-
+
});
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[100000];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(100000);
for (int i = 0; i < 100000; i++) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
return elements;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java
index 6e84840..d605191 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Tom Schindl and others.
+ * Copyright (c) 2007, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -39,9 +43,9 @@ import org.eclipse.swt.widgets.TableItem;
/**
* Example usage of ToolTips with the OLD viewer API but similar to
* {@link ColumnViewerToolTipSupport}
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet042ToolTipSupportFor32API {
private static Image[] images;
@@ -89,9 +93,9 @@ public class Snippet042ToolTipSupportFor32API {
private static class ToolTipSupport extends DefaultToolTip {
private Cell cell;
- private ColumnViewer viewer;
+ private ColumnViewer<MyModel,List<MyModel>> viewer;
- protected ToolTipSupport(ColumnViewer viewer, int style,
+ protected ToolTipSupport(ColumnViewer<MyModel,List<MyModel>> viewer, int style,
boolean manualActivation) {
super(viewer.getControl(), style, manualActivation);
this.viewer = viewer;
@@ -120,46 +124,31 @@ public class Snippet042ToolTipSupportFor32API {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new FillLayout());
Button b = new Button(comp, SWT.PUSH);
- b.setText(((ITableLabelProvider) viewer.getLabelProvider())
- .getColumnText(cell.getData(), cell.index));
- b.setImage(((ITableLabelProvider) viewer.getLabelProvider())
- .getColumnImage(cell.getData(), cell.index));
+ b.setText(((ITableLabelProvider<MyModel>) viewer.getLabelProvider())
+ .getColumnText((MyModel)cell.getData(), cell.index));
+ b.setImage(((ITableLabelProvider<MyModel>) viewer.getLabelProvider())
+ .getColumnImage((MyModel)cell.getData(), cell.index));
return comp;
}
- public static void enableFor(ColumnViewer viewer) {
+ public static void enableFor(ColumnViewer<MyModel,List<MyModel>> viewer) {
new ToolTipSupport(viewer, ToolTip.NO_RECREATE, false);
}
}
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -177,18 +166,18 @@ public class Snippet042ToolTipSupportFor32API {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel> {
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
if (columnIndex == 1) {
- return images[((MyModel) element).counter % 4];
+ return images[element.counter % 4];
}
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
@@ -207,7 +196,7 @@ public class Snippet042ToolTipSupportFor32API {
}
public Snippet042ToolTipSupportFor32API(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -220,20 +209,18 @@ public class Snippet042ToolTipSupportFor32API {
column.setWidth(200);
column.setText("Column 2");
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
ToolTipSupport.enableFor(v);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.java
index 990526a..555c2f6 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -37,15 +38,15 @@ import org.eclipse.swt.widgets.Shell;
/**
* Demonstrates how to use keyboard-editing support in a TreeViewer with no column
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet043NoColumnTreeViewerKeyboardEditing {
public Snippet043NoColumnTreeViewerKeyboardEditing(final Shell shell) {
Button b = new Button(shell, SWT.PUSH);
b.setText("BBB");
- final TreeViewer v = new TreeViewer(shell, SWT.BORDER
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
b.addSelectionListener(new SelectionListener() {
@@ -54,10 +55,10 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
}
public void widgetSelected(SelectionEvent e) {
- MyModel root = (MyModel) v.getInput();
+ MyModel root = v.getInput();
TreePath path = new TreePath(new Object[] { root,
root.child.get(1),
- ((MyModel) root.child.get(1)).child.get(0) });
+ root.child.get(1).child.get(0) });
v.editElement(path, 0);
}
@@ -76,10 +77,9 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
}
public void modify(Object element, String property, Object value) {
- element = ((Item) element).getData();
- ((MyModel) element).counter = Integer
- .parseInt(value.toString());
- v.update(element, null);
+ MyModel myModel = (MyModel)((Item) element).getData();
+ myModel.counter = Integer.parseInt(value.toString());
+ v.update(myModel, null);
}
});
@@ -143,31 +143,32 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
display.dispose();
}
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
}
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- public Object getParent(Object element) {
+ public MyModel getParent(MyModel element) {
if (element == null) {
return null;
}
- return ((MyModel) element).parent;
+ return element.parent;
}
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -175,7 +176,7 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet044NoColumnTableViewerKeyboardEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet044NoColumnTableViewerKeyboardEditing.java
index 787aec0..8b54226 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet044NoColumnTableViewerKeyboardEditing.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet044NoColumnTableViewerKeyboardEditing.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
@@ -37,46 +41,31 @@ import org.eclipse.swt.widgets.Shell;
/**
* Demonstrates how to use keyboard-editing support in a TableViewer with no column
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet044NoColumnTableViewerKeyboardEditing {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
}
public static boolean flag = true;
-
+
public class MyModel {
public int counter;
@@ -89,34 +78,34 @@ public class Snippet044NoColumnTableViewerKeyboardEditing {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel> , ITableFontProvider<MyModel> , ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
+ public Font getFont(MyModel element, int columnIndex) {
return null;
}
- public Color getBackground(Object element, int columnIndex) {
+ public Color getBackground(MyModel element, int columnIndex) {
return null;
}
- public Color getForeground(Object element, int columnIndex) {
+ public Color getForeground(MyModel element, int columnIndex) {
return null;
}
}
public Snippet044NoColumnTableViewerKeyboardEditing(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER|SWT.FULL_SELECTION);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER|SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -132,13 +121,13 @@ public class Snippet044NoColumnTableViewerKeyboardEditing {
}
public void modify(Object element, String property, Object value) {
-
+
}
-
+
});
-
+
v.setColumnProperties(new String[] {"1"});
-
+
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new FocusBorderCellHighlighter(v));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
@@ -149,25 +138,23 @@ public class Snippet044NoColumnTableViewerKeyboardEditing {
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
-
+
TableViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet045TableViewerFillFromBackgroundThread.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet045TableViewerFillFromBackgroundThread.java
index 76073f0..1e951bc 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet045TableViewerFillFromBackgroundThread.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet045TableViewerFillFromBackgroundThread.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -44,33 +45,18 @@ import org.eclipse.swt.widgets.TableColumn;
public class Snippet045TableViewerFillFromBackgroundThread {
private static int COUNTER = 0;
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return ((List) inputElement).toArray();
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -88,35 +74,35 @@ public class Snippet045TableViewerFillFromBackgroundThread {
}
}
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider, ITableFontProvider, ITableColorProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements
+ ITableLabelProvider<MyModel>, ITableFontProvider<MyModel>, ITableColorProvider<MyModel> {
FontRegistry registry = new FontRegistry();
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
- public Font getFont(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Font getFont(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return registry.getBold(Display.getCurrent().getSystemFont()
.getFontData()[0].getName());
}
return null;
}
- public Color getBackground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 0) {
+ public Color getBackground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 0) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
}
- public Color getForeground(Object element, int columnIndex) {
- if (((MyModel) element).counter % 2 == 1) {
+ public Color getForeground(MyModel element, int columnIndex) {
+ if (element.counter % 2 == 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
@@ -125,7 +111,7 @@ public class Snippet045TableViewerFillFromBackgroundThread {
}
public Snippet045TableViewerFillFromBackgroundThread(final Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -138,13 +124,11 @@ public class Snippet045TableViewerFillFromBackgroundThread {
column.setWidth(200);
column.setText("Column 2");
- final ArrayList model = new ArrayList();
+ final ArrayList<MyModel> model = new ArrayList<MyModel>();
v.setInput(model);
- v.setComparator(new ViewerComparator() {
- public int compare(Viewer viewer, Object e1, Object e2) {
- MyModel m1 = (MyModel) e1;
- MyModel m2 = (MyModel) e2;
- return m2.counter - m1.counter;
+ v.setComparator(new ViewerComparator<MyModel,List<MyModel>>() {
+ public int compare(Viewer<List<MyModel>> viewer, MyModel e1, MyModel e2) {
+ return e2.counter - e1.counter;
}
});
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet046UpdateViewerFromBackgroundThread.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet046UpdateViewerFromBackgroundThread.java
index b7b32d3..7f3d478 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet046UpdateViewerFromBackgroundThread.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet046UpdateViewerFromBackgroundThread.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -37,26 +41,18 @@ import org.eclipse.swt.widgets.TableColumn;
public class Snippet046UpdateViewerFromBackgroundThread {
private static Image[] images;
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -75,17 +71,17 @@ public class Snippet046UpdateViewerFromBackgroundThread {
}
}
- public class MyLabelProvider extends LabelProvider implements ITableLabelProvider {
+ public class MyLabelProvider extends LabelProvider<MyModel> implements ITableLabelProvider<MyModel> {
- public Image getColumnImage(Object element, int columnIndex) {
+ public Image getColumnImage(MyModel element, int columnIndex) {
if( columnIndex == 0 ) {
- return images[((MyModel)element).finished?0:1];
+ return images[element.finished?0:1];
}
return null;
}
- public String getColumnText(Object element, int columnIndex) {
+ public String getColumnText(MyModel element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
@@ -103,7 +99,7 @@ public class Snippet046UpdateViewerFromBackgroundThread {
}
public Snippet046UpdateViewerFromBackgroundThread(Shell shell) {
- final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell,SWT.BORDER|SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
@@ -115,7 +111,7 @@ public class Snippet046UpdateViewerFromBackgroundThread {
column.setWidth(200);
column.setText("Column 2");
- final MyModel[] model = createModel();
+ final List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
@@ -128,7 +124,7 @@ public class Snippet046UpdateViewerFromBackgroundThread {
final Thread t = new Thread() {
public void run() {
- for( int i = 0; i < model.length; i++ ) {
+ for( int i = 0; i < model.size(); i++ ) {
if( v.getTable().isDisposed()) {
return;
}
@@ -136,8 +132,8 @@ public class Snippet046UpdateViewerFromBackgroundThread {
v.getTable().getDisplay().asyncExec(new Runnable() {
public void run() {
- model[j].finished = true;
- v.update(model[j], null);
+ model.get(j).finished = true;
+ v.update(model.get(j), null);
}
});
@@ -154,13 +150,11 @@ public class Snippet046UpdateViewerFromBackgroundThread {
});
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
for( int i = 0; i < 10; i++ ) {
- elements[i] = new MyModel(i);
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet047VirtualLazyTreeViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet047VirtualLazyTreeViewer.java
index 0dcc4ef..3fdaed1 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet047VirtualLazyTreeViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet047VirtualLazyTreeViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.ILazyTreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
@@ -22,14 +26,14 @@ import org.eclipse.swt.widgets.Shell;
/**
* A simple TreeViewer to demonstrate usage of an ILazyContentProvider.
- *
+ *
*/
public class Snippet047VirtualLazyTreeViewer {
- private class MyContentProvider implements ILazyTreeContentProvider {
- private TreeViewer viewer;
- private IntermediateNode[] elements;
+ private class MyContentProvider implements ILazyTreeContentProvider<Object,List<IntermediateNode>> {
+ private TreeViewer<Object,List<IntermediateNode>> viewer;
+ private List<IntermediateNode> elements;
- public MyContentProvider(TreeViewer viewer) {
+ public MyContentProvider(TreeViewer<Object,List<IntermediateNode>> viewer) {
this.viewer = viewer;
}
@@ -37,13 +41,13 @@ public class Snippet047VirtualLazyTreeViewer {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- this.elements = (IntermediateNode[]) newInput;
+ public void inputChanged(Viewer<? extends List<IntermediateNode>> viewer, List<IntermediateNode> oldInput, List<IntermediateNode> newInput) {
+ this.elements = newInput;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ILazyTreeContentProvider#getParent(java.lang.Object)
*/
public Object getParent(Object element) {
@@ -54,41 +58,41 @@ public class Snippet047VirtualLazyTreeViewer {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ILazyTreeContentProvider#updateChildCount(java.lang.Object,
* int)
*/
public void updateChildCount(Object element, int currentChildCount) {
-
+
int length = 0;
if (element instanceof IntermediateNode) {
IntermediateNode node = (IntermediateNode) element;
- length = node.children.length;
- }
+ length = node.children.size();
+ }
if(element == elements)
- length = elements.length;
+ length = elements.size();
viewer.setChildCount(element, length);
-
+
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ILazyTreeContentProvider#updateElement(java.lang.Object,
* int)
*/
public void updateElement(Object parent, int index) {
-
+
Object element;
- if (parent instanceof IntermediateNode)
- element = ((IntermediateNode) parent).children[index];
-
+ if (parent instanceof IntermediateNode)
+ element = ((IntermediateNode) parent).children.get(index);
+
else
- element = elements[index];
+ element = elements.get(index);
viewer.replace(parent, index, element);
updateChildCount(element, -1);
-
+
}
}
@@ -109,7 +113,7 @@ public class Snippet047VirtualLazyTreeViewer {
public class IntermediateNode {
public int counter;
- public LeafNode[] children = new LeafNode[0];
+ public List<LeafNode> children = new ArrayList<LeafNode>();
public IntermediateNode(int counter) {
this.counter = counter;
@@ -120,31 +124,30 @@ public class Snippet047VirtualLazyTreeViewer {
}
public void generateChildren(int i) {
- children = new LeafNode[i];
for (int j = 0; j < i; j++) {
- children[j] = new LeafNode(j, this);
+ children.add(j, new LeafNode(j, this));
}
}
}
public Snippet047VirtualLazyTreeViewer(Shell shell) {
- final TreeViewer v = new TreeViewer(shell, SWT.VIRTUAL | SWT.BORDER);
- v.setLabelProvider(new LabelProvider());
+ final TreeViewer<Object,List<IntermediateNode>> v = new TreeViewer<Object,List<IntermediateNode>>(shell, SWT.VIRTUAL | SWT.BORDER);
+ v.setLabelProvider(new LabelProvider<Object>());
v.setContentProvider(new MyContentProvider(v));
v.setUseHashlookup(true);
- IntermediateNode[] model = createModel();
+ List<IntermediateNode> model = createModel();
v.setInput(model);
- v.getTree().setItemCount(model.length);
+ v.getTree().setItemCount(model.size());
}
- private IntermediateNode[] createModel() {
- IntermediateNode[] elements = new IntermediateNode[10];
+ private List<IntermediateNode> createModel() {
+ List<IntermediateNode> elements = new ArrayList<IntermediateNode>();
for (int i = 0; i < 10; i++) {
- elements[i] = new IntermediateNode(i);
- elements[i].generateChildren(1000);
+ elements.add(i,new IntermediateNode(i));
+ elements.get(i).generateChildren(1000);
}
return elements;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet048TreeViewerTabWithCheckboxFor3_3.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet048TreeViewerTabWithCheckboxFor3_3.java
index 973dff3..92376b3 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet048TreeViewerTabWithCheckboxFor3_3.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet048TreeViewerTabWithCheckboxFor3_3.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -48,7 +49,7 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
public Snippet048TreeViewerTabWithCheckboxFor3_3(final Shell shell) {
- final TreeViewer v = new TreeViewer(shell, SWT.BORDER
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
@@ -71,13 +72,13 @@ public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
final CheckboxCellEditor checkboxCellEditor = new CheckboxCellEditor(v.getTree());
- TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
+ TreeViewerColumn<MyModel,MyModel> column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 1 => " + element.toString();
}
@@ -98,17 +99,17 @@ public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- column = new TreeViewerColumn(v, SWT.NONE);
+ column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 2 => " + element.toString();
}
@@ -129,18 +130,18 @@ public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- column = new TreeViewerColumn(v, SWT.NONE);
+ column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
- return ((MyModel)element).bool + "";
+ public String getText(MyModel element) {
+ return element.bool + "";
}
});
@@ -159,7 +160,7 @@ public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
protected void setValue(Object element, Object value) {
((MyModel) element).bool = ((Boolean)value).booleanValue();
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
@@ -233,31 +234,32 @@ public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
display.dispose();
}
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
}
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- public Object getParent(Object element) {
+ public MyModel getParent(MyModel element) {
if (element == null) {
return null;
}
- return ((MyModel) element).parent;
+ return element.parent;
}
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -265,7 +267,7 @@ public class Snippet048TreeViewerTabWithCheckboxFor3_3 {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java
index ec786f4..c6f8938 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Michael Krkoska - initial API and implementation (bug 188333)
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -84,7 +85,7 @@ public class Snippet049StyledCellLabelProvider {
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
label.setText("Viewer with a StyledCellLabelProvider:"); //$NON-NLS-1$
- final TableViewer tableViewer= new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ final TableViewer<File,Object> tableViewer= new TableViewer<File,Object>(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
// Multi-font support only works in JFace 3.5 and above (specifically, 3.5 M4 and above).
// With JFace 3.4, the font information (bold in this example) will be ignored.
@@ -113,7 +114,7 @@ public class Snippet049StyledCellLabelProvider {
return styleData;
}
- private static class ExampleLabelProvider extends StyledCellLabelProvider {
+ private static class ExampleLabelProvider extends StyledCellLabelProvider<File,Object> {
private static int IMAGE_SIZE= 16;
private static final Image IMAGE1= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_WARNING).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
@@ -129,11 +130,11 @@ public class Snippet049StyledCellLabelProvider {
};
}
- public void update(ViewerCell cell) {
- Object element= cell.getElement();
+ public void update(ViewerCell<File> cell) {
+ File element= cell.getElement();
if (element instanceof File) {
- File file= (File) element;
+ File file= element;
// Multi-font support only works in JFace 3.5 and above (specifically, 3.5 M4 and above).
// With JFace 3.4, the font information (bold in this example) will be ignored.
@@ -157,14 +158,14 @@ public class Snippet049StyledCellLabelProvider {
super.update(cell);
}
- protected void measure(Event event, Object element) {
+ protected void measure(Event event, File element) {
super.measure(event, element);
}
}
- private static class FileSystemContentProvider implements IStructuredContentProvider {
+ private static class FileSystemContentProvider implements IStructuredContentProvider<File,Object> {
- public Object[] getElements(Object element) {
+ public File[] getElements(Object element) {
File[] roots = File.listRoots();
for (int i = 0; i < roots.length; i++) {
File[] list = roots[i].listFiles();
@@ -178,7 +179,7 @@ public class Snippet049StyledCellLabelProvider {
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends Object> viewer, Object oldInput, Object newInput) {
}
}
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java
index 8f4f2ba..7221ab6 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Michael Krkoska - initial API and implementation (bug 188333)
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -84,13 +85,13 @@ public class Snippet050DelegatingStyledCellLabelProvider {
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
composite.setLayout(new GridLayout(2, true));
- final DelegatingStyledCellLabelProvider styledCellLP1= new DelegatingStyledCellLabelProvider(new NameAndSizeLabelProvider());
- final DelegatingStyledCellLabelProvider styledCellLP2= new DelegatingStyledCellLabelProvider(new ModifiedDateLabelProvider());
- final ColumnViewer ownerDrawViewer= createViewer("Owner draw viewer:", composite, styledCellLP1, styledCellLP2); //$NON-NLS-1$
+ final DelegatingStyledCellLabelProvider<File,FileSystemRoot> styledCellLP1= new DelegatingStyledCellLabelProvider<File,FileSystemRoot>(new NameAndSizeLabelProvider());
+ final DelegatingStyledCellLabelProvider<File,FileSystemRoot> styledCellLP2= new DelegatingStyledCellLabelProvider<File,FileSystemRoot>(new ModifiedDateLabelProvider());
+ final ColumnViewer<File,FileSystemRoot> ownerDrawViewer= createViewer("Owner draw viewer:", composite, styledCellLP1, styledCellLP2); //$NON-NLS-1$
- CellLabelProvider normalLP1= new NameAndSizeLabelProvider();
- CellLabelProvider normalLP2= new ModifiedDateLabelProvider();
- final ColumnViewer normalViewer= createViewer("Normal viewer:", composite, normalLP1, normalLP2); //$NON-NLS-1$
+ CellLabelProvider<File,FileSystemRoot> normalLP1= new NameAndSizeLabelProvider();
+ CellLabelProvider<File,FileSystemRoot> normalLP2= new ModifiedDateLabelProvider();
+ final ColumnViewer<File,FileSystemRoot> normalViewer= createViewer("Normal viewer:", composite, normalLP1, normalLP2); //$NON-NLS-1$
Composite buttons= new Composite(parent, SWT.NONE);
buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -138,7 +139,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
}
}
- private ColumnViewer createViewer(String description, Composite parent, CellLabelProvider labelProvider1, CellLabelProvider labelProvider2) {
+ private ColumnViewer<File,FileSystemRoot> createViewer(String description, Composite parent, CellLabelProvider<File,FileSystemRoot>labelProvider1, CellLabelProvider<File,FileSystemRoot> labelProvider2) {
Composite composite= new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
@@ -148,16 +149,16 @@ public class Snippet050DelegatingStyledCellLabelProvider {
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
label.setText(description);
- TreeViewer treeViewer= new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ TreeViewer<File,FileSystemRoot> treeViewer= new TreeViewer<File,FileSystemRoot>(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.setContentProvider(new FileSystemContentProvider());
- TreeViewerColumn tvc1 = new TreeViewerColumn(treeViewer, SWT.NONE);
+ TreeViewerColumn<File,FileSystemRoot> tvc1 = new TreeViewerColumn<File,FileSystemRoot>(treeViewer, SWT.NONE);
tvc1.getColumn().setText("Name"); //$NON-NLS-1$
tvc1.getColumn().setWidth(200);
tvc1.setLabelProvider(labelProvider1);
- TreeViewerColumn tvc2 = new TreeViewerColumn(treeViewer, SWT.NONE);
+ TreeViewerColumn<File,FileSystemRoot>tvc2 = new TreeViewerColumn<File,FileSystemRoot>(treeViewer, SWT.NONE);
tvc2.getColumn().setText("Date Modified"); //$NON-NLS-1$
tvc2.getColumn().setWidth(200);
tvc2.setLabelProvider(labelProvider2);
@@ -173,32 +174,29 @@ public class Snippet050DelegatingStyledCellLabelProvider {
/**
* A simple label provider
*/
- private static class NameAndSizeLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {
+ private static class NameAndSizeLabelProvider extends ColumnLabelProvider<File,FileSystemRoot> implements IStyledLabelProvider<File> {
private static int IMAGE_SIZE= 16;
private static final Image IMAGE1= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_WARNING).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
private static final Image IMAGE2= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_ERROR).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
- public Image getImage(Object element) {
- if (element instanceof File) {
- File file= (File) element;
- if (file.isDirectory()) {
- return IMAGE1;
- } else {
- return IMAGE2;
- }
+ public Image getImage(File element) {
+ File file = element;
+ if (file.isDirectory()) {
+ return IMAGE1;
+ } else {
+ return IMAGE2;
}
- return null;
}
- public String getText(Object element) {
+ public String getText(File element) {
return getStyledText(element).toString();
}
- public StyledString getStyledText(Object element) {
+ public StyledString getStyledText(File element) {
StyledString styledString= new StyledString();
if (element instanceof File) {
- File file= (File) element;
+ File file= element;
if (file.getName().length() == 0) {
styledString.append(file.getAbsolutePath());
} else {
@@ -213,65 +211,58 @@ public class Snippet050DelegatingStyledCellLabelProvider {
}
}
- private static class ModifiedDateLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {
- public String getText(Object element) {
+ private static class ModifiedDateLabelProvider extends ColumnLabelProvider<File,FileSystemRoot> implements IStyledLabelProvider<File> {
+ public String getText(File element) {
return getStyledText(element).toString();
}
- public StyledString getStyledText(Object element) {
- StyledString styledString= new StyledString();
- if (element instanceof File) {
- File file= (File) element;
+ public StyledString getStyledText(File element) {
+ StyledString styledString = new StyledString();
+ File file = element;
- String date= DateFormat.getDateInstance().format(new Date(file.lastModified()));
- styledString.append(date);
+ String date = DateFormat.getDateInstance().format(
+ new Date(file.lastModified()));
+ styledString.append(date);
- styledString.append(' ');
+ styledString.append(' ');
- String time = DateFormat.getTimeInstance(3).format(new Date(file.lastModified()));
- styledString.append(time, StyledString.COUNTER_STYLER);
- }
+ String time = DateFormat.getTimeInstance(3).format(
+ new Date(file.lastModified()));
+ styledString.append(time, StyledString.COUNTER_STYLER);
return styledString;
}
}
- private static class FileSystemContentProvider implements ITreeContentProvider {
+ private static class FileSystemContentProvider implements ITreeContentProvider<File,FileSystemRoot> {
- public Object[] getChildren(Object element) {
- if (element instanceof File) {
- File file= (File) element;
- if (file.isDirectory()) {
- File[] listFiles= file.listFiles();
- if (listFiles != null) {
- return listFiles;
- }
+ public File[] getChildren(File element) {
+ File file = element;
+ if (file.isDirectory()) {
+ File[] listFiles = file.listFiles();
+ if (listFiles != null) {
+ return listFiles;
}
- } else if (element instanceof FileSystemRoot) {
- return ((FileSystemRoot) element).getRoots();
}
- return new Object[0];
+ return new File[0];
}
- public Object getParent(Object element) {
- if (element instanceof File) {
- File file= (File) element;
- return file.getParentFile();
- }
- return null;
+ public File getParent(File element) {
+ File file = element;
+ return file.getParentFile();
}
- public boolean hasChildren(Object element) {
+ public boolean hasChildren(File element) {
return getChildren(element).length > 0;
}
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
+ public File[] getElements(FileSystemRoot inputElement) {
+ return inputElement.getRoots();
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends FileSystemRoot> viewer, FileSystemRoot oldInput, FileSystemRoot newInput) {
}
}
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet051TableCenteredImage.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet051TableCenteredImage.java
index 095b8fe..edfef24 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet051TableCenteredImage.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet051TableCenteredImage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.OwnerDrawLabelProvider;
@@ -37,45 +41,30 @@ import org.eclipse.swt.widgets.TableItem;
public class Snippet051TableCenteredImage {
private static Image[] images;
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
}
private abstract class CenterImageLabelProvider extends
- OwnerDrawLabelProvider {
+ OwnerDrawLabelProvider<MyModel,List<MyModel>> {
- protected void measure(Event event, Object element) {
+ protected void measure(Event event, MyModel element) {
}
- protected void paint(Event event, Object element) {
+ protected void paint(Event event, MyModel element) {
Image img = getImage(element);
@@ -123,21 +112,21 @@ public class Snippet051TableCenteredImage {
}
public Snippet051TableCenteredImage(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<MyModel,List<MyModel>> column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 1 => " + element.toString();
}
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Column 2");
column.setLabelProvider(new CenterImageLabelProvider() {
@@ -150,19 +139,17 @@ public class Snippet051TableCenteredImage {
// OwnerDrawLabelProvider.setUpOwnerDraw(v);
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet052DouleClickCellEditor.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet052DouleClickCellEditor.java
index 7d3c521..70446f5 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet052DouleClickCellEditor.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet052DouleClickCellEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerEditor;
@@ -36,33 +40,18 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet052DouleClickCellEditor {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -83,7 +72,7 @@ public class Snippet052DouleClickCellEditor {
}
public Snippet052DouleClickCellEditor(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()),
@@ -123,37 +112,35 @@ public class Snippet052DouleClickCellEditor {
| ColumnViewerEditor.TABBING_VERTICAL
| ColumnViewerEditor.KEYBOARD_ACTIVATION);
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<MyModel,List<MyModel>> column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider());
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>());
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider());
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>());
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
- column.setLabelProvider(new ColumnLabelProvider());
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>());
- MyModel[] model = createModel();
+ List<MyModel> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>(10);
+ for( int i = 0; i < 10; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet053StartEditorWithContextMenu.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet053StartEditorWithContextMenu.java
index e4b0eb3..3b1867e 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet053StartEditorWithContextMenu.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet053StartEditorWithContextMenu.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Marcel and others.
+ * Copyright (c) 2007, 2003 Marcel 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:
* Marcel <emmpeegee@gmail.com> - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -38,15 +39,16 @@ import org.eclipse.swt.widgets.TreeItem;
*/
public class Snippet053StartEditorWithContextMenu implements SelectionListener {
- private TreeViewer viewer;
+ private TreeViewer<MyModel,MyModel> viewer;
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
- public Object[] getElements(Object inputElement) {
- return ((MyModel)inputElement).child.toArray();
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
/* (non-Javadoc)
@@ -59,40 +61,40 @@ public class Snippet053StartEditorWithContextMenu implements SelectionListener {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
- public Object[] getChildren(Object parentElement) {
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
- public Object getParent(Object element) {
+ public MyModel getParent(MyModel element) {
if( element == null) {
return null;
}
- return ((MyModel)element).parent;
+ return element.parent;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
- public boolean hasChildren(Object element) {
- return ((MyModel)element).child.size() > 0;
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
public MyModel(int counter, MyModel parent) {
@@ -113,7 +115,7 @@ public class Snippet053StartEditorWithContextMenu implements SelectionListener {
}
public Snippet053StartEditorWithContextMenu(Shell shell) {
- viewer = new TreeViewer(shell, SWT.BORDER);
+ viewer = new TreeViewer<MyModel,MyModel>(shell, SWT.BORDER);
viewer.setContentProvider(new MyContentProvider());
viewer.setCellEditors(new CellEditor[] {new TextCellEditor(viewer.getTree())});
viewer.setColumnProperties(new String[] { "name" });
@@ -139,7 +141,7 @@ public class Snippet053StartEditorWithContextMenu implements SelectionListener {
public void modify(Object element, String property, Object value) {
TreeItem item = (TreeItem)element;
((MyModel)item.getData()).counter = Integer.parseInt(value.toString());
- viewer.update(item.getData(), null);
+ viewer.update((MyModel)item.getData(), null);
}
});
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet054NativeControlsInViewers.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet054NativeControlsInViewers.java
index a548f1b..b0497cb 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet054NativeControlsInViewers.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet054NativeControlsInViewers.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,10 +7,14 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -43,33 +47,18 @@ import org.eclipse.swt.widgets.TableItem;
*/
public class Snippet054NativeControlsInViewers {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<MyModel,List<MyModel>> {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
+ public MyModel[] getElements(List<MyModel> inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.size()];
+ return inputElement.toArray(myModels);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<MyModel>> viewer, List<MyModel> oldInput, List<MyModel> newInput) {
}
@@ -88,28 +77,28 @@ public class Snippet054NativeControlsInViewers {
}
public Snippet054NativeControlsInViewers(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<MyModel,List<MyModel>> v = new TableViewer<MyModel,List<MyModel>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
v.getTable().setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,2,1));
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<MyModel,List<MyModel>> column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,List<MyModel>>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return element.toString();
}
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<MyModel,List<MyModel>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Column 2");
- column.setLabelProvider(new CellLabelProvider() {
+ column.setLabelProvider(new CellLabelProvider<MyModel,List<MyModel>>() {
- public void update(ViewerCell cell) {
+ public void update(ViewerCell<MyModel> cell) {
final TableItem item = (TableItem) cell.getItem();
DisposeListener listener = new DisposeListener() {
@@ -157,7 +146,7 @@ public class Snippet054NativeControlsInViewers {
});
- MyModel[] model = createModel(10);
+ List<MyModel> model = createModel(10);
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
@@ -185,13 +174,11 @@ public class Snippet054NativeControlsInViewers {
});
}
- private MyModel[] createModel(int amount) {
- MyModel[] elements = new MyModel[amount];
-
- for (int i = 0; i < amount; i++) {
- elements[i] = new MyModel(i);
+ private List<MyModel> createModel(int amount) {
+ List<MyModel> elements = new ArrayList<MyModel>(amount);
+ for( int i = 0; i < amount; i++ ) {
+ elements.add(i,new MyModel(i));
}
-
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet055HideShowColumn.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet055HideShowColumn.java
index 783c482..d81030b 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet055HideShowColumn.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet055HideShowColumn.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -45,7 +46,7 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet055HideShowColumn {
public Snippet055HideShowColumn(final Shell shell) {
- final TreeViewer v = new TreeViewer(shell, SWT.BORDER
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.getTree().setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,2,1));
v.getTree().setLinesVisible(true);
@@ -72,13 +73,13 @@ public class Snippet055HideShowColumn {
final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
- TreeViewerColumn column_1 = new TreeViewerColumn(v, SWT.NONE);
+ TreeViewerColumn<MyModel,MyModel> column_1 = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column_1.getColumn().setWidth(200);
column_1.getColumn().setMoveable(true);
column_1.getColumn().setText("Column 1");
- column_1.setLabelProvider(new ColumnLabelProvider() {
+ column_1.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 1 => " + element.toString();
}
@@ -99,17 +100,17 @@ public class Snippet055HideShowColumn {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- final TreeViewerColumn column_2 = new TreeViewerColumn(v, SWT.NONE);
+ final TreeViewerColumn<MyModel,MyModel> column_2 = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column_2.getColumn().setWidth(200);
column_2.getColumn().setMoveable(true);
column_2.getColumn().setText("Column 2");
- column_2.setLabelProvider(new ColumnLabelProvider() {
+ column_2.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 2 => " + element.toString();
}
@@ -130,17 +131,17 @@ public class Snippet055HideShowColumn {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- TreeViewerColumn column_3 = new TreeViewerColumn(v, SWT.NONE);
+ TreeViewerColumn<MyModel,MyModel> column_3 = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column_3.getColumn().setWidth(200);
column_3.getColumn().setMoveable(true);
column_3.getColumn().setText("Column 3");
- column_3.setLabelProvider(new ColumnLabelProvider() {
+ column_3.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 3 => " + element.toString();
}
@@ -161,7 +162,7 @@ public class Snippet055HideShowColumn {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
@@ -175,10 +176,10 @@ public class Snippet055HideShowColumn {
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- MyModel root = (MyModel) v.getInput();
+ MyModel root = v.getInput();
TreePath path = new TreePath(new Object[] { root,
root.child.get(1),
- ((MyModel) root.child.get(1)).child.get(0) });
+ root.child.get(1).child.get(0) });
v.editElement(path, 0);
}
@@ -229,31 +230,53 @@ public class Snippet055HideShowColumn {
display.dispose();
}
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
public void dispose() {
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
+
}
- public Object[] getChildren(Object parentElement) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- public Object getParent(Object element) {
- if (element == null) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public MyModel getParent(MyModel element) {
+ if( element == null) {
return null;
}
- return ((MyModel) element).parent;
+
+ return element.parent;
}
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -261,7 +284,7 @@ public class Snippet055HideShowColumn {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet056BooleanCellEditor.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet056BooleanCellEditor.java
index f59a9bd..534c807 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet056BooleanCellEditor.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet056BooleanCellEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -41,7 +42,7 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet056BooleanCellEditor {
public Snippet056BooleanCellEditor(final Shell shell) {
- final TreeViewer v = new TreeViewer(shell, SWT.BORDER
+ final TreeViewer<MyModel,MyModel> v = new TreeViewer<MyModel,MyModel>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.getTree().setLinesVisible(true);
v.getTree().setHeaderVisible(true);
@@ -69,13 +70,13 @@ public class Snippet056BooleanCellEditor {
final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
final BooleanCellEditor booleanCellEditor = new BooleanCellEditor(v.getTree());
- TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
+ TreeViewerColumn<MyModel,MyModel> column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 1 => " + element.toString();
}
@@ -96,18 +97,18 @@ public class Snippet056BooleanCellEditor {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- column = new TreeViewerColumn(v, SWT.NONE);
+ column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
- return ((MyModel) element).flag+"";
+ public String getText(MyModel element) {
+ return element.flag+"";
}
});
@@ -126,17 +127,17 @@ public class Snippet056BooleanCellEditor {
protected void setValue(Object element, Object value) {
((MyModel) element).flag = ((Boolean)value).booleanValue();
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
- column = new TreeViewerColumn(v, SWT.NONE);
+ column = new TreeViewerColumn<MyModel,MyModel>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Column 3");
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<MyModel,MyModel>() {
- public String getText(Object element) {
+ public String getText(MyModel element) {
return "Column 3 => " + element.toString();
}
@@ -157,7 +158,7 @@ public class Snippet056BooleanCellEditor {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ v.update((MyModel)element, null);
}
});
@@ -202,31 +203,53 @@ public class Snippet056BooleanCellEditor {
display.dispose();
}
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<MyModel,MyModel> {
- public Object[] getElements(Object inputElement) {
- return ((MyModel) inputElement).child.toArray();
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public MyModel[] getElements(MyModel inputElement) {
+ MyModel[] myModels = new MyModel[inputElement.child.size()];
+ return inputElement.child.toArray(myModels);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
public void dispose() {
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer<? extends MyModel> viewer, MyModel oldInput, MyModel newInput) {
+
}
- public Object[] getChildren(Object parentElement) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public MyModel[] getChildren(MyModel parentElement) {
return getElements(parentElement);
}
- public Object getParent(Object element) {
- if (element == null) {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public MyModel getParent(MyModel element) {
+ if( element == null) {
return null;
}
- return ((MyModel) element).parent;
+
+ return element.parent;
}
- public boolean hasChildren(Object element) {
- return ((MyModel) element).child.size() > 0;
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren(MyModel element) {
+ return element.child.size() > 0;
}
}
@@ -234,7 +257,7 @@ public class Snippet056BooleanCellEditor {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet057TableViewerSkipHiddenCells.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet057TableViewerSkipHiddenCells.java
index 0bac686..9a29f29 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet057TableViewerSkipHiddenCells.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet057TableViewerSkipHiddenCells.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,9 +7,13 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.CellEditor;
@@ -33,22 +37,23 @@ import org.eclipse.swt.widgets.Shell;
/**
* Example of showing how easy cell-navigation with hidden cells is in 3.4
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
*/
public class Snippet057TableViewerSkipHiddenCells {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
}
@@ -95,7 +100,7 @@ public class Snippet057TableViewerSkipHiddenCells {
public Snippet057TableViewerSkipHiddenCells(Shell shell) {
- final TableViewer tableviewer = new TableViewer(shell, SWT.BORDER
+ final TableViewer<Person,List<Person>> tableviewer = new TableViewer<Person,List<Person>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
tableviewer.setContentProvider(new MyContentProvider());
MenuManager mgr = new MenuManager();
@@ -105,23 +110,23 @@ public class Snippet057TableViewerSkipHiddenCells {
if( tableviewer.getTable().getColumn(1).getWidth() == 0) {
tableviewer.getTable().getColumn(1).setWidth(200);
} else {
- tableviewer.getTable().getColumn(1).setWidth(0);
+ tableviewer.getTable().getColumn(1).setWidth(0);
}
-
+
}
-
+
});
- tableviewer.getControl().setMenu(mgr.createContextMenu(tableviewer.getControl()));
+ tableviewer.getControl().setMenu(mgr.createContextMenu(tableviewer.getControl()));
// Column 1
- TableViewerColumn column = new TableViewerColumn(tableviewer, SWT.NONE);
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(tableviewer, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Givenname");
column.getColumn().setMoveable(false);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).givenname;
+ public String getText(Person element) {
+ return element.givenname;
}
});
@@ -139,15 +144,15 @@ public class Snippet057TableViewerSkipHiddenCells {
});
// Column 2 is zero-width hidden
- column = new TableViewerColumn(tableviewer, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(tableviewer, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Surname");
column.getColumn().setMoveable(false);
column.getColumn().setResizable(false);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).surname;
+ public String getText(Person element) {
+ return element.surname;
}
});
@@ -165,14 +170,14 @@ public class Snippet057TableViewerSkipHiddenCells {
});
// column 3
- column = new TableViewerColumn(tableviewer, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(tableviewer, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("E-Mail");
column.getColumn().setMoveable(false);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).email;
+ public String getText(Person element) {
+ return element.email;
}
});
@@ -189,7 +194,7 @@ public class Snippet057TableViewerSkipHiddenCells {
});
- Person[] model = this.createModel();
+ List<Person> model = this.createModel();
tableviewer.setInput(model);
tableviewer.getTable().setLinesVisible(true);
tableviewer.getTable().setHeaderVisible(true);
@@ -222,14 +227,12 @@ public class Snippet057TableViewerSkipHiddenCells {
}
- private Person[] createModel() {
- Person[] elements = new Person[4];
- elements[0] = new Person("Tom", "Schindl",
- "tom.schindl@bestsolution.at");
- elements[1] = new Person("Boris", "Bokowski",
- "Boris_Bokowski@ca.ibm.com");
- elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com");
- elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org");
+ private List<Person> createModel() {
+ List<Person> elements = new ArrayList<Person>(4);
+ elements.add(new Person("Tom", "Schindl",
+ "tom.schindl@bestsolution.at"));
+ elements.add(new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com"));
+ elements.add(new Person("Wayne", "Beaton", "wayne@eclipse.org"));
return elements;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java
index ad220d2..5b456f3 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java
@@ -9,10 +9,14 @@
* Tom Schindl - initial API and implementation
* Niels Lippke - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CellNavigationStrategy;
import org.eclipse.jface.viewers.ColumnLabelProvider;
@@ -47,16 +51,19 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet058CellNavigationIn34 {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
+
}
}
@@ -106,17 +113,17 @@ public class Snippet058CellNavigationIn34 {
}
public Snippet058CellNavigationIn34(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ final TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>> (shell, SWT.BORDER | SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Givenname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).givenname;
+ public String getText(Person element) {
+ return element.givenname;
}
});
@@ -132,14 +139,14 @@ public class Snippet058CellNavigationIn34 {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Surname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).surname;
+ public String getText(Person element) {
+ return element.surname;
}
});
@@ -156,14 +163,14 @@ public class Snippet058CellNavigationIn34 {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("E-Mail");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).email;
+ public String getText(Person element) {
+ return element.email;
}
});
@@ -182,14 +189,14 @@ public class Snippet058CellNavigationIn34 {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Gender");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).gender;
+ public String getText(Person element) {
+ return element.gender;
}
});
@@ -274,22 +281,23 @@ public class Snippet058CellNavigationIn34 {
});
- Person[] model = createModel();
+ List<Person> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private Person[] createModel() {
- Person[] elements = new Person[4];
- elements[0] = new Person("Tom", "Schindl",
- "tom.schindl@bestsolution.at", "M");
- elements[1] = new Person("Boris", "Bokowski",
- "Boris_Bokowski@ca.ibm.com","M");
- elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com","M");
- elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org","M");
+ private List<Person> createModel() {
+ List<Person> elements = new ArrayList<Person>(4);
+ elements.add(new Person("Tom", "Schindl",
+ "tom.schindl@bestsolution.at", "M"));
+ elements.add(new Person("Boris", "Bokowski",
+ "Boris_Bokowski@ca.ibm.com", "M"));
+ elements.add(new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com", "M"));
+ elements.add(new Person("Wayne", "Beaton", "wayne@eclipse.org", "M"));
return elements;
+
}
/**
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java
index f4c9198..92d97f7 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -15,6 +16,7 @@ package org.eclipse.jface.snippets.viewers;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.AbstractTableViewer;
@@ -68,16 +70,19 @@ import org.eclipse.swt.widgets.TableItem;
*/
public class Snippet059CellNavigationIn33 {
- private class MyContentProvider implements IStructuredContentProvider {
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
}
public void dispose() {
+
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
+
}
}
@@ -128,18 +133,18 @@ public class Snippet059CellNavigationIn33 {
}
public Snippet059CellNavigationIn33(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.setContentProvider(new MyContentProvider());
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Givenname");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).givenname;
+ public String getText(Person element) {
+ return element.givenname;
}
});
@@ -155,14 +160,14 @@ public class Snippet059CellNavigationIn33 {
});
- final TableViewerColumn columnA = new TableViewerColumn(v, SWT.NONE);
+ final TableViewerColumn<Person,List<Person>> columnA = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
columnA.getColumn().setWidth(200);
columnA.getColumn().setText("Surname");
columnA.getColumn().setMoveable(true);
- columnA.setLabelProvider(new ColumnLabelProvider() {
+ columnA.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).surname;
+ public String getText(Person element) {
+ return element.surname;
}
});
@@ -179,14 +184,14 @@ public class Snippet059CellNavigationIn33 {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("E-Mail");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).email;
+ public String getText(Person element) {
+ return element.email;
}
});
@@ -203,14 +208,14 @@ public class Snippet059CellNavigationIn33 {
});
- column = new TableViewerColumn(v, SWT.NONE);
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setText("Gender");
column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
- public String getText(Object element) {
- return ((Person) element).gender;
+ public String getText(Person element) {
+ return element.gender;
}
});
@@ -362,23 +367,23 @@ public class Snippet059CellNavigationIn33 {
}
});
- Person[] model = createModel();
+ List<Person> model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
- private Person[] createModel() {
- Person[] elements = new Person[4];
- elements[0] = new Person("Tom", "Schindl",
- "tom.schindl@bestsolution.at", "M");
- elements[1] = new Person("Boris", "Bokowski",
- "Boris_Bokowski@ca.ibm.com", "M");
- elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com",
- "M");
- elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org", "M");
+ private List<Person> createModel() {
+ List<Person> elements = new ArrayList<Person>(4);
+ elements.add(new Person("Tom", "Schindl",
+ "tom.schindl@bestsolution.at", "M"));
+ elements.add(new Person("Boris", "Bokowski",
+ "Boris_Bokowski@ca.ibm.com", "M"));
+ elements.add(new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com", "M"));
+ elements.add(new Person("Wayne", "Beaton", "wayne@eclipse.org", "M"));
return elements;
+
}
/**
@@ -421,7 +426,7 @@ public class Snippet059CellNavigationIn33 {
* @param feature
* the feature mask
*/
- TableViewerEditor(TableViewer viewer,
+ TableViewerEditor(TableViewer<Person,List<Person>> viewer,
TableViewerFocusCellManager focusCellManager,
ColumnViewerEditorActivationStrategy editorActivationStrategy,
int feature) {
@@ -452,7 +457,7 @@ public class Snippet059CellNavigationIn33 {
* </ul>
* @see #create(TableViewer, ColumnViewerEditorActivationStrategy, int)
*/
- public static void create(TableViewer viewer,
+ public static void create(TableViewer<Person,List<Person>> viewer,
TableViewerFocusCellManager focusCellManager,
ColumnViewerEditorActivationStrategy editorActivationStrategy,
int feature) {
@@ -497,7 +502,7 @@ public class Snippet059CellNavigationIn33 {
* <li>{@link ColumnViewerEditor#TABBING_VERTICAL}</li>
* </ul>
*/
- public static void create(TableViewer viewer,
+ public static void create(TableViewer<Person,List<Person>> viewer,
ColumnViewerEditorActivationStrategy editorActivationStrategy,
int feature) {
create(viewer, null, editorActivationStrategy, feature);
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet060TextCellEditorWithContentProposal.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet060TextCellEditorWithContentProposal.java
index 365939f..8ae6012 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet060TextCellEditorWithContentProposal.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet060TextCellEditorWithContentProposal.java
@@ -5,6 +5,9 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contibutors
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -39,7 +42,7 @@ import org.eclipse.swt.widgets.Table;
/**
* Shows how to attach content assist to a text cell editor.
- *
+ *
* @author Mario Winterer
*/
public class Snippet060TextCellEditorWithContentProposal {
@@ -87,7 +90,7 @@ public class Snippet060TextCellEditorWithContentProposal {
/**
* Return the {@link ContentProposalAdapter} of this cell editor.
- *
+ *
* @return the {@link ContentProposalAdapter}
*/
public ContentProposalAdapter getContentProposalAdapter() {
@@ -143,18 +146,18 @@ public class Snippet060TextCellEditorWithContentProposal {
}
public Snippet060TextCellEditorWithContentProposal(Shell shell) {
- final TableViewer viewer = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ final TableViewer<Color,Object> viewer = new TableViewer<Color,Object>(shell, SWT.BORDER | SWT.FULL_SELECTION);
final Table table = viewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
- final TableViewerColumn colorColumn = new TableViewerColumn(viewer, SWT.LEFT);
+ final TableViewerColumn<Color,Object> colorColumn = new TableViewerColumn<Color,Object>(viewer, SWT.LEFT);
colorColumn.getColumn().setText("Color name");
colorColumn.getColumn().setWidth(200);
- colorColumn.setLabelProvider(new ColumnLabelProvider());
+ colorColumn.setLabelProvider(new ColumnLabelProvider<Color,Object>());
colorColumn.setEditingSupport(new ColorNameEditingSupport(viewer));
- viewer.setContentProvider(new ArrayContentProvider());
+ viewer.setContentProvider(new ArrayContentProvider<Color>(Color.class));
ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet061FakedNativeCellEditor.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet061FakedNativeCellEditor.java
index b4a3fd9..ad693d0 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet061FakedNativeCellEditor.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet061FakedNativeCellEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
* Florian Potschka<signalrauschen@gmail.com> - in bug 260061
* Alexander Ljungberg<siker@norwinter.com> - in bug 260061
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -50,17 +51,17 @@ import org.eclipse.swt.widgets.TreeItem;
/**
* A simple TreeViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet061FakedNativeCellEditor {
public abstract class EmulatedNativeCheckBoxLabelProvider extends
- OwnerDrawLabelProvider {
+ OwnerDrawLabelProvider<File,File> {
private static final String CHECKED_KEY = "CHECKED";
private static final String UNCHECK_KEY = "UNCHECKED";
- public EmulatedNativeCheckBoxLabelProvider(ColumnViewer viewer) {
+ public EmulatedNativeCheckBoxLabelProvider(ColumnViewer<File,File> viewer) {
if (JFaceResources.getImageRegistry().getDescriptor(CHECKED_KEY) == null) {
JFaceResources.getImageRegistry().put(UNCHECK_KEY,
makeShot(viewer.getControl(), false));
@@ -75,21 +76,21 @@ public class Snippet061FakedNativeCellEditor {
Color greenScreen = new Color(control.getDisplay(), 222, 223, 224);
Shell shell = new Shell(control.getShell(), SWT.NO_TRIM);
-
+
// otherwise we have a default gray color
shell.setBackground(greenScreen);
if( Util.isMac() ) {
Button button2 = new Button(shell, SWT.CHECK);
Point bsize = button2.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-
+
// otherwise an image is stretched by width
bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
button2.setSize(bsize);
- button2.setLocation(100, 100);
+ button2.setLocation(100, 100);
}
-
+
Button button = new Button(shell, SWT.CHECK);
button.setBackground(greenScreen);
button.setSelection(type);
@@ -97,16 +98,16 @@ public class Snippet061FakedNativeCellEditor {
// otherwise an image is located in a corner
button.setLocation(1, 1);
Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-
+
// otherwise an image is stretched by width
bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
button.setSize(bsize);
-
+
shell.setSize(bsize);
shell.open();
-
+
GC gc = new GC(shell);
Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
gc.copyArea(image, 0, 0);
@@ -119,11 +120,11 @@ public class Snippet061FakedNativeCellEditor {
Image img = new Image(control.getDisplay(), imageData);
image.dispose();
-
+
return img;
}
- public Image getImage(Object element) {
+ public Image getImage(File element) {
if (isChecked(element)) {
return JFaceResources.getImageRegistry().get(CHECKED_KEY);
} else {
@@ -131,11 +132,11 @@ public class Snippet061FakedNativeCellEditor {
}
}
- protected void measure(Event event, Object element) {
+ protected void measure(Event event, File element) {
event.height = getImage(element).getBounds().height;
}
- protected void paint(Event event, Object element) {
+ protected void paint(Event event, File element) {
Image img = getImage(element);
@@ -166,11 +167,11 @@ public class Snippet061FakedNativeCellEditor {
}
}
- protected abstract boolean isChecked(Object element);
+ protected abstract boolean isChecked(File element);
}
public Snippet061FakedNativeCellEditor(final Shell shell) {
- final TreeViewer v = new TreeViewer(shell, SWT.BORDER
+ final TreeViewer<File,File> v = new TreeViewer<File,File>(shell, SWT.BORDER
| SWT.FULL_SELECTION);
v.getTree().setLinesVisible(true);
v.getTree().setBackgroundMode(SWT.INHERIT_DEFAULT);
@@ -207,17 +208,17 @@ public class Snippet061FakedNativeCellEditor {
.getTree());
booleanCellEditor.setChangeOnActivation(true);
- TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
+ TreeViewerColumn<File,File> column = new TreeViewerColumn<File,File>(v, SWT.NONE);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("File");
- column.setLabelProvider(new OwnerDrawLabelProvider() {
+ column.setLabelProvider(new OwnerDrawLabelProvider<File,File>() {
- protected void measure(Event event, Object element) {
+ protected void measure(Event event, File element) {
}
- protected void paint(Event event, Object element) {
+ protected void paint(Event event, File element) {
((TreeItem) event.item).setText(element.toString());
}
@@ -237,18 +238,18 @@ public class Snippet061FakedNativeCellEditor {
protected void setValue(Object element, Object value) {
((File) element).counter = Integer.parseInt(value.toString());
- v.update(element, null);
+ v.update((File)element, null);
}
});
- column = new TreeViewerColumn(v, SWT.CENTER);
+ column = new TreeViewerColumn<File,File>(v, SWT.CENTER);
column.getColumn().setWidth(200);
column.getColumn().setMoveable(true);
column.getColumn().setText("Read");
column.setLabelProvider(new EmulatedNativeCheckBoxLabelProvider(v) {
- protected boolean isChecked(Object element) {
- return ((File) element).read;
+ protected boolean isChecked(File element) {
+ return element.read;
}
});
@@ -267,7 +268,7 @@ public class Snippet061FakedNativeCellEditor {
protected void setValue(Object element, Object value) {
((File) element).read = ((Boolean) value).booleanValue();
- v.update(element, null);
+ v.update((File)element, null);
}
});
@@ -277,8 +278,8 @@ public class Snippet061FakedNativeCellEditor {
column.getColumn().setText("Write");
column.setLabelProvider(new EmulatedNativeCheckBoxLabelProvider(v) {
- protected boolean isChecked(Object element) {
- return ((File) element).write;
+ protected boolean isChecked(File element) {
+ return element.write;
}
});
@@ -297,7 +298,7 @@ public class Snippet061FakedNativeCellEditor {
protected void setValue(Object element, Object value) {
((File) element).write = ((Boolean) value).booleanValue();
- v.update(element, null);
+ v.update((File)element, null);
}
});
@@ -307,8 +308,8 @@ public class Snippet061FakedNativeCellEditor {
column.getColumn().setText("Execute");
column.setLabelProvider(new EmulatedNativeCheckBoxLabelProvider(v) {
- protected boolean isChecked(Object element) {
- return ((File) element).execute;
+ protected boolean isChecked(File element) {
+ return element.execute;
}
});
@@ -327,7 +328,7 @@ public class Snippet061FakedNativeCellEditor {
protected void setValue(Object element, Object value) {
((File) element).execute = ((Boolean) value).booleanValue();
- v.update(element, null);
+ v.update((File)element, null);
}
});
@@ -376,31 +377,32 @@ public class Snippet061FakedNativeCellEditor {
}
}
- private class MyContentProvider implements ITreeContentProvider {
+ private class MyContentProvider implements ITreeContentProvider<File,File> {
- public Object[] getElements(Object inputElement) {
- return ((File) inputElement).child.toArray();
+ public File[] getElements(File inputElement) {
+ File[] files = new File[inputElement.child.size()];
+ return inputElement.child.toArray(files);
}
public void dispose() {
}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ public void inputChanged(Viewer<? extends File> viewer, File oldInput, File newInput) {
}
- public Object[] getChildren(Object parentElement) {
+ public File[] getChildren(File parentElement) {
return getElements(parentElement);
}
- public Object getParent(Object element) {
+ public File getParent(File element) {
if (element == null) {
return null;
}
- return ((File) element).parent;
+ return element.parent;
}
- public boolean hasChildren(Object element) {
- return ((File) element).child.size() > 0;
+ public boolean hasChildren(File element) {
+ return element.child.size() > 0;
}
}
@@ -408,7 +410,7 @@ public class Snippet061FakedNativeCellEditor {
public class File {
public File parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<File> child = new ArrayList<File>();
public int counter;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java
index c4bcde0..f94edd3 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Hendrik Still<hendrik.still@gammas.de> - initial implementation
+ * Hendrik Still<hendrik.still@gammas.de> - initial implementation, bug 417676
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet62TextAndDialogCellEditor.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet62TextAndDialogCellEditor.java
index 086def9..4605ceb 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet62TextAndDialogCellEditor.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet62TextAndDialogCellEditor.java
@@ -1,212 +1,215 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Eric Rizzo 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eric Rizzo - initial implementation
- *******************************************************************************/
-
-package org.eclipse.jface.snippets.viewers;
-
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * Demonstrates usage of {@link TextAndDialogCellEditor}. The email column uses the
- * TextAndDialogCellEditor; othe columns use ordinary {@link TextCellEditor}s.
- *
- * @author Eric Rizzo
- *
- */
-public class Snippet62TextAndDialogCellEditor {
-
- private class MyContentProvider implements IStructuredContentProvider {
-
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
- }
-
- public void dispose() {
- // noting to do
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // noting to do
- }
-
- }
-
- public class Person {
- public String givenname;
- public String surname;
- public String email;
-
- public Person(String givenname, String surname, String email) {
- this.givenname = givenname;
- this.surname = surname;
- this.email = email;
- }
-
- public String toString() {
- return '[' + givenname + ' ' + surname + ' ' + email + ']';
- }
- }
-
- protected abstract class AbstractEditingSupport extends EditingSupport {
- private CellEditor editor;
-
- public AbstractEditingSupport(TableViewer viewer, CellEditor anEditor) {
- super(viewer);
- this.editor = anEditor;
- }
-
- protected boolean canEdit(Object element) {
- return editor != null;
- }
-
- protected CellEditor getCellEditor(Object element) {
- return editor;
- }
-
- protected void setValue(Object element, Object value) {
- doSetValue(element, value);
- getViewer().update(element, null);
- }
-
- protected abstract void doSetValue(Object element, Object value);
- }
-
- public Snippet62TextAndDialogCellEditor(Shell shell) {
- TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
- v.setContentProvider(new MyContentProvider());
-
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("Givenname");
- column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
-
- public String getText(Object element) {
- return ((Person) element).givenname;
- }
- });
-
- column.setEditingSupport(new AbstractEditingSupport(v, new TextCellEditor(v.getTable())) {
-
- protected Object getValue(Object element) {
- return ((Person) element).givenname;
- }
-
- protected void doSetValue(Object element, Object value) {
- ((Person) element).givenname = value.toString();
- }
-
- });
-
- column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("Surname");
- column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
-
- public String getText(Object element) {
- return ((Person) element).surname;
- }
-
- });
-
- column.setEditingSupport(new AbstractEditingSupport(v, new TextCellEditor(v.getTable())) {
- protected Object getValue(Object element) {
- return ((Person) element).surname;
- }
-
- protected void doSetValue(Object element, Object value) {
- ((Person) element).surname = value.toString();
- }
-
- });
-
- column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("E-Mail");
- column.getColumn().setMoveable(true);
- column.setLabelProvider(new ColumnLabelProvider() {
- public String getText(Object element) {
- return ((Person) element).email;
- }
-
- });
-
-
- TextAndDialogCellEditor cellEditor = new TextAndDialogCellEditor(v.getTable());
- cellEditor.setDialogMessage("Enter email address");
- column.setEditingSupport(new AbstractEditingSupport(v, cellEditor) {
-
- protected Object getValue(Object element) {
- return ((Person) element).email;
- }
-
- protected void doSetValue(Object element, Object value) {
- ((Person) element).email = value.toString();
- }
-
- // Print out the model after each edit to verify its values are updated correctly
- protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
- super.saveCellEditorValue(cellEditor, cell);
- System.out.println(cell.getElement());
- }
- });
-
- Person[] model = createModel();
- v.setInput(model);
- v.getTable().setLinesVisible(true);
- v.getTable().setHeaderVisible(true);
- }
-
- private Person[] createModel() {
- Person[] elements = new Person[4];
- elements[0] = new Person("Tom", "Schindl",
- "tom.schindl@bestsolution.at");
- elements[1] = new Person("Boris", "Bokowski",
- "Boris_Bokowski@ca.ibm.com");
- elements[2] = new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com");
- elements[3] = new Person("Wayne", "Beaton", "wayne@eclipse.org");
-
- return elements;
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- Display display = new Display();
-
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- new Snippet62TextAndDialogCellEditor(shell);
- shell.open();
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
-
- display.dispose();
-
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2006, 2013 Eric Rizzo 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eric Rizzo - initial implementation
+ * Hendrik Still <hendrik.still@gammas.de> - bug 417676
+ *******************************************************************************/
+
+package org.eclipse.jface.snippets.viewers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Demonstrates usage of {@link TextAndDialogCellEditor}. The email column uses the
+ * TextAndDialogCellEditor; othe columns use ordinary {@link TextCellEditor}s.
+ *
+ * @author Eric Rizzo
+ *
+ */
+public class Snippet62TextAndDialogCellEditor {
+
+ private class MyContentProvider implements IStructuredContentProvider<Person,List<Person>> {
+
+ public Person[] getElements(List<Person> inputElement) {
+ Person[] persons = new Person[inputElement.size()];
+ return inputElement.toArray(persons);
+ }
+
+ public void dispose() {
+ // noting to do
+ }
+
+ public void inputChanged(Viewer<? extends List<Person>> viewer, List<Person> oldInput, List<Person> newInput) {
+ // noting to do
+ }
+
+ }
+
+ public class Person {
+ public String givenname;
+ public String surname;
+ public String email;
+
+ public Person(String givenname, String surname, String email) {
+ this.givenname = givenname;
+ this.surname = surname;
+ this.email = email;
+ }
+
+ public String toString() {
+ return '[' + givenname + ' ' + surname + ' ' + email + ']';
+ }
+ }
+
+ protected abstract class AbstractEditingSupport extends EditingSupport {
+ private CellEditor editor;
+
+ public AbstractEditingSupport(TableViewer viewer, CellEditor anEditor) {
+ super(viewer);
+ this.editor = anEditor;
+ }
+
+ protected boolean canEdit(Object element) {
+ return editor != null;
+ }
+
+ protected CellEditor getCellEditor(Object element) {
+ return editor;
+ }
+
+ protected void setValue(Object element, Object value) {
+ doSetValue(element, value);
+ getViewer().update(element, null);
+ }
+
+ protected abstract void doSetValue(Object element, Object value);
+ }
+
+ public Snippet62TextAndDialogCellEditor(Shell shell) {
+ TableViewer<Person,List<Person>> v = new TableViewer<Person,List<Person>>(shell, SWT.BORDER | SWT.FULL_SELECTION);
+ v.setContentProvider(new MyContentProvider());
+
+ TableViewerColumn<Person,List<Person>> column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText("Givenname");
+ column.getColumn().setMoveable(true);
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
+
+ public String getText(Person element) {
+ return element.givenname;
+ }
+ });
+
+ column.setEditingSupport(new AbstractEditingSupport(v, new TextCellEditor(v.getTable())) {
+
+ protected Object getValue(Object element) {
+ return ((Person) element).givenname;
+ }
+
+ protected void doSetValue(Object element, Object value) {
+ ((Person) element).givenname = value.toString();
+ }
+
+ });
+
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText("Surname");
+ column.getColumn().setMoveable(true);
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
+
+ public String getText(Person element) {
+ return element.surname;
+ }
+
+ });
+
+ column.setEditingSupport(new AbstractEditingSupport(v, new TextCellEditor(v.getTable())) {
+ protected Object getValue(Object element) {
+ return ((Person) element).surname;
+ }
+
+ protected void doSetValue(Object element, Object value) {
+ ((Person) element).surname = value.toString();
+ }
+
+ });
+
+ column = new TableViewerColumn<Person,List<Person>>(v, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText("E-Mail");
+ column.getColumn().setMoveable(true);
+ column.setLabelProvider(new ColumnLabelProvider<Person,List<Person>>() {
+ public String getText(Person element) {
+ return element.email;
+ }
+
+ });
+
+
+ TextAndDialogCellEditor cellEditor = new TextAndDialogCellEditor(v.getTable());
+ cellEditor.setDialogMessage("Enter email address");
+ column.setEditingSupport(new AbstractEditingSupport(v, cellEditor) {
+
+ protected Object getValue(Object element) {
+ return ((Person) element).email;
+ }
+
+ protected void doSetValue(Object element, Object value) {
+ ((Person) element).email = value.toString();
+ }
+
+ // Print out the model after each edit to verify its values are updated correctly
+ protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
+ super.saveCellEditorValue(cellEditor, cell);
+ System.out.println(cell.getElement());
+ }
+ });
+
+ List<Person> model = createModel();
+ v.setInput(model);
+ v.getTable().setLinesVisible(true);
+ v.getTable().setHeaderVisible(true);
+ }
+
+ private List<Person> createModel() {
+ List<Person> elements = new ArrayList<Person>(4);
+ elements.add(new Person("Tom", "Schindl",
+ "tom.schindl@bestsolution.at"));
+ elements.add(new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com"));
+ elements.add(new Person("Wayne", "Beaton", "wayne@eclipse.org"));
+
+ return elements;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Display display = new Display();
+
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ new Snippet62TextAndDialogCellEditor(shell);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+
+ display.dispose();
+
+ }
+
+}