aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-05-13 13:22:27 (EDT)
committerLars Vogel2014-05-13 23:32:00 (EDT)
commite5524df50f148dea4262b507fa9db024d11cd0d1 (patch)
tree13345ed6b2986ebb973bddbddc5d8474f2b53704
parent4f3bc6e3c42b37e197035c9b372c1907e2f3f917 (diff)
downloadeclipse.platform.ui-e5524df50f148dea4262b507fa9db024d11cd0d1.zip
eclipse.platform.ui-e5524df50f148dea4262b507fa9db024d11cd0d1.tar.gz
eclipse.platform.ui-e5524df50f148dea4262b507fa9db024d11cd0d1.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanuprefs/changes/70/26470/2
Cleanings for snippet 19, 21, and 24. Change-Id: I9bbf7d25efc1813d06678d9128fc3be14533e7f5 Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI.java121
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java90
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet024TableViewerExploreNewAPI.java74
3 files changed, 93 insertions, 192 deletions
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 46f701b..bb409d1 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, 2014 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,24 +7,23 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
-
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.util.ConfigureColumns;
+import org.eclipse.jface.viewers.ArrayContentProvider;
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.window.SameShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
@@ -36,7 +35,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
*/
@@ -44,9 +43,7 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
public class Person {
public String givenname;
-
public String surname;
-
public String email;
public Person(String givenname, String surname, String email) {
@@ -56,46 +53,26 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
}
}
- private class MyContentProvider implements IStructuredContentProvider {
-
- @Override
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
- }
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- }
-
-
-
private class GivenNameLabelProvider extends ColumnLabelProvider {
@Override
public String getText(Object element) {
return ((Person) element).givenname;
}
}
-
+
private class GivenNameEditing extends EditingSupport {
private TextCellEditor cellEditor;
-
+
public GivenNameEditing(TableViewer viewer) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getTable());
}
-
+
@Override
protected boolean canEdit(Object element) {
return true;
}
-
+
@Override
protected CellEditor getCellEditor(Object element) {
return cellEditor;
@@ -112,27 +89,27 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
getViewer().update(element, null);
}
}
-
+
private class SurNameLabelProvider extends ColumnLabelProvider {
@Override
public String getText(Object element) {
return ((Person) element).surname;
}
}
-
+
private class SurNameEditing extends EditingSupport {
private TextCellEditor cellEditor;
-
- public SurNameEditing( TableViewer viewer ) {
+
+ public SurNameEditing(TableViewer viewer) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getTable());
}
-
+
@Override
protected boolean canEdit(Object element) {
return true;
}
-
+
@Override
protected CellEditor getCellEditor(Object element) {
return cellEditor;
@@ -149,27 +126,27 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
getViewer().update(element, null);
}
}
-
+
private class EmailLabelProvider extends ColumnLabelProvider {
@Override
public String getText(Object element) {
return ((Person) element).email;
}
}
-
+
private class EmailEditing extends EditingSupport {
private TextCellEditor cellEditor;
-
- public EmailEditing( TableViewer viewer ) {
+
+ public EmailEditing(TableViewer viewer) {
super(viewer);
cellEditor = new TextCellEditor(viewer.getTable());
}
-
+
@Override
protected boolean canEdit(Object element) {
return true;
}
-
+
@Override
protected CellEditor getCellEditor(Object element) {
return cellEditor;
@@ -186,34 +163,25 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
getViewer().update(element, null);
}
}
-
+
private int activeColumn = -1;
-
+
private TableViewerColumn column;
-
+
public Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI(Shell shell) {
final TableViewer v = new TableViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION);
- TableViewerColumn column = new TableViewerColumn(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.setLabelProvider(new SurNameLabelProvider());
- column.setEditingSupport(new SurNameEditing(v));
- column.getColumn().setWidth(200);
- column.getColumn().setText("Surname");
- column.getColumn().setMoveable(true);
+ TableViewerColumn column1 = createColumnFor(v, "Givenname");
+ column1.setLabelProvider(new GivenNameLabelProvider());
+ column1.setEditingSupport(new GivenNameEditing(v));
- Person[] model = createModel();
+ TableViewerColumn column2 = createColumnFor(v, "Surname");
+ column2.setLabelProvider(new SurNameLabelProvider());
+ column2.setEditingSupport(new SurNameEditing(v));
- v.setContentProvider(new MyContentProvider());
- v.setInput(model);
+ v.setContentProvider(ArrayContentProvider.getInstance());
+ v.setInput(createModel());
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
@@ -221,6 +189,14 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
triggerColumnSelectedColumn(v);
}
+ private TableViewerColumn createColumnFor(TableViewer viewer, String label) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText(label);
+ column.getColumn().setMoveable(true);
+ return column;
+ }
+
private void triggerColumnSelectedColumn(final TableViewer v) {
v.getTable().addMouseListener(new MouseAdapter() {
@@ -284,10 +260,11 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
final Action configureColumns = new Action("Configure Columns...") {
@Override
public void run() {
- ConfigureColumns.forTable(v.getTable(), new SameShellProvider(v.getControl()));
+ ConfigureColumns.forTable(v.getTable(),
+ new SameShellProvider(v.getControl()));
}
};
-
+
mgr.setRemoveAllWhenShown(true);
mgr.addMenuListener(new IMenuListener() {
@@ -308,13 +285,13 @@ public class Snippet019TableViewerAddRemoveColumnsWithEditingNewAPI {
}
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");
-
- return persons;
+ return new Person[] {
+ new Person("Tom", "Schindl", "tom.schindl@bestsolution.at"),
+ new Person("Boris", "Bokowski", "boris_bokowski@ca.ibm.com"),
+ new Person("Tod", "Creasey", "tod_creasey@ca.ibm.com"),
+ new Person("Lars", "Vogel", "lars.vogel@gmail.com"),
+ new Person("Hendrik", "Still", "hendrik.still@vogella.com"),
+ new Person("Jeanderson", "Candido", "jeandersonbc@gmail.com") };
}
/**
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 cef5e0a..001d968 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, 2014 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,17 +8,20 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Dinko Ivanov - bug 164365
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
@@ -31,17 +34,17 @@ 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 boolean enabled;
-
+
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@@ -51,34 +54,16 @@ public class Snippet021CellEditorsOnDoubleClick {
this.viewer = viewer;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object,
- * java.lang.String)
- */
@Override
public boolean canModify(Object element, String property) {
return enabled && ((MyModel) element).counter % 2 == 0;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object,
- * java.lang.String)
- */
@Override
public Object getValue(Object element, String property) {
return ((MyModel) element).counter + "";
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object,
- * java.lang.String, java.lang.Object)
- */
@Override
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
@@ -87,41 +72,6 @@ public class Snippet021CellEditorsOnDoubleClick {
viewer.update(item.getData(), null);
}
}
-
- private class MyContentProvider implements IStructuredContentProvider {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- @Override
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- @Override
- public void dispose() {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- }
public class MyModel {
public int counter;
@@ -139,7 +89,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() {
@Override
@@ -176,28 +126,26 @@ public class Snippet021CellEditorsOnDoubleClick {
});
modifier.setViewer(v);
-
+
TableColumn column = new TableColumn(table, SWT.NONE);
column.setWidth(200);
v.setLabelProvider(new LabelProvider());
- v.setContentProvider(new MyContentProvider());
+ v.setContentProvider(ArrayContentProvider.getInstance());
v.setCellModifier(modifier);
v.setColumnProperties(new String[] { "column1" });
v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()) });
- MyModel[] model = createModel();
- v.setInput(model);
+ v.setInput(createModel());
v.getTable().setLinesVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>();
for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
+ elements.add(new MyModel(i));
}
-
return elements;
}
@@ -215,9 +163,7 @@ public class Snippet021CellEditorsOnDoubleClick {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
-
}
}
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 204d946..08d8a13 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, 2014 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,18 +7,18 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import org.eclipse.jface.viewers.ArrayContentProvider;
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.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
@@ -26,29 +26,12 @@ 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 {
-
- @Override
- public Object[] getElements(Object inputElement) {
- return (Person[]) inputElement;
- }
-
- @Override
- public void dispose() {
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- }
-
public class Person {
public String givenname;
public String surname;
@@ -91,12 +74,9 @@ public class Snippet024TableViewerExploreNewAPI {
public Snippet024TableViewerExploreNewAPI(Shell shell) {
TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
- v.setContentProvider(new MyContentProvider());
+ v.setContentProvider(ArrayContentProvider.getInstance());
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("Givenname");
- column.getColumn().setMoveable(true);
+ TableViewerColumn column = createColumnFor(v, "Givenname");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
@@ -119,10 +99,7 @@ public class Snippet024TableViewerExploreNewAPI {
});
- column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("Surname");
- column.getColumn().setMoveable(true);
+ column = createColumnFor(v, "Surname");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
@@ -146,10 +123,7 @@ public class Snippet024TableViewerExploreNewAPI {
});
- column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("E-Mail");
- column.getColumn().setMoveable(true);
+ column = createColumnFor(v, "E-Mail");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
@@ -173,22 +147,28 @@ public class Snippet024TableViewerExploreNewAPI {
});
- Person[] model = createModel();
- v.setInput(model);
+ v.setInput(createModel());
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
}
+ private TableViewerColumn createColumnFor(TableViewer viewer, String label) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setText(label);
+ column.getColumn().setMoveable(true);
+ return column;
+ }
+
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;
+ return new Person[] {
+ new Person("Tom", "Schindl", "tom.schindl@bestsolution.at"),
+ new Person("Boris", "Bokowski", "Boris_Bokowski@ca.ibm.com"),
+ new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com"),
+ new Person("Wayne", "Beaton", "wayne@eclipse.org"),
+ new Person("Lars", "Vogel", "lars.vogel@gmail.com"),
+ new Person("Hendrik", "Still", "hendrik.still@vogella.com"),
+ new Person("Jeanderson", "Candido", "jeandersonbc@gmail.com") };
}
/**
@@ -206,9 +186,7 @@ public class Snippet024TableViewerExploreNewAPI {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
-
}
}