aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-05-08 23:10:21 (EDT)
committerLars Vogel2014-05-13 23:58:17 (EDT)
commitec5950daa0f4b262d4e5ba10699b01312269c167 (patch)
tree5d7582ffc9b3bf124887c8104810428cfcd6d118
parent7ea3d826a45b3b678c3ba33ba63e8b1d367a0c8d (diff)
downloadeclipse.platform.ui-ec5950daa0f4b262d4e5ba10699b01312269c167.zip
eclipse.platform.ui-ec5950daa0f4b262d4e5ba10699b01312269c167.tar.gz
eclipse.platform.ui-ec5950daa0f4b262d4e5ba10699b01312269c167.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanuprefs/changes/48/26248/3
Cleanings for snippet 39, 40, 41, and 43. Change-Id: I0bbc783309749ad38d2a38a6e4a26be4a158d648 Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet039ListViewer.java52
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet040TableViewerSorting.java131
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java174
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043NoColumnTreeViewerKeyboardEditing.java58
4 files changed, 167 insertions, 248 deletions
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 0d782e5..b70c183 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
@@ -8,14 +8,17 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Jeanderson Candido (http://jeandersonbc.github.io) - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
@@ -25,24 +28,6 @@ import org.eclipse.swt.widgets.Shell;
* Demonstrate a simple ListViewer
*/
public class Snippet039ListViewer {
- private class MyContentProvider implements IStructuredContentProvider {
-
- @Override
- public Object[] getElements(Object inputElement) {
- return (MyModel[])inputElement;
- }
-
- @Override
- public void dispose() {
-
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- }
public class MyModel {
public int counter;
@@ -58,20 +43,18 @@ public class Snippet039ListViewer {
}
public Snippet039ListViewer(Shell shell) {
- final ListViewer v = new ListViewer(shell,SWT.H_SCROLL|SWT.V_SCROLL);
+ final ListViewer v = new ListViewer(shell, SWT.H_SCROLL | SWT.V_SCROLL);
v.setLabelProvider(new LabelProvider());
- v.setContentProvider(new MyContentProvider());
- MyModel[] model = createModel();
- v.setInput(model);
+ v.setContentProvider(ArrayContentProvider.getInstance());
+ v.setInput(createModel());
}
- 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);
+ for (int i = 0; i < 10; i++) {
+ elements.add(new MyModel(i));
}
-
return elements;
}
@@ -79,17 +62,18 @@ public class Snippet039ListViewer {
* @param args
*/
public static void main(String[] args) {
- Display display = new Display ();
+ Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet039ListViewer(shell);
- shell.open ();
+ shell.open();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
}
- display.dispose ();
+ 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 3ef7627..5d34d00 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
@@ -8,15 +8,16 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * 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.ColumnViewer;
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;
@@ -28,6 +29,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
/**
* Example usage of ViewerComparator in tables to allow sorting
@@ -37,23 +39,6 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet040TableViewerSorting {
- 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;
@@ -64,7 +49,6 @@ public class Snippet040TableViewerSorting {
this.surname = surname;
this.email = email;
}
-
}
protected abstract class AbstractEditingSupport extends EditingSupport {
@@ -95,13 +79,11 @@ public class Snippet040TableViewerSorting {
}
public Snippet040TableViewerSorting(Shell shell) {
- TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
- v.setContentProvider(new MyContentProvider());
+ TableViewer viewer = new TableViewer(shell, SWT.BORDER
+ | SWT.FULL_SELECTION);
+ viewer.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(viewer, "Givenname");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
@@ -110,7 +92,7 @@ public class Snippet040TableViewerSorting {
}
});
- column.setEditingSupport(new AbstractEditingSupport(v) {
+ column.setEditingSupport(new AbstractEditingSupport(viewer) {
@Override
protected Object getValue(Object element) {
@@ -124,7 +106,7 @@ public class Snippet040TableViewerSorting {
});
- ColumnViewerSorter cSorter = new ColumnViewerSorter(v,column) {
+ ColumnViewerSorter cSorter = new ColumnViewerSorter(viewer, column) {
@Override
protected int doCompare(Viewer viewer, Object e1, Object e2) {
@@ -135,10 +117,7 @@ public class Snippet040TableViewerSorting {
};
- column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("Surname");
- column.getColumn().setMoveable(true);
+ column = createColumnFor(viewer, "Surname");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
@@ -148,7 +127,7 @@ public class Snippet040TableViewerSorting {
});
- column.setEditingSupport(new AbstractEditingSupport(v) {
+ column.setEditingSupport(new AbstractEditingSupport(viewer) {
@Override
protected Object getValue(Object element) {
@@ -162,7 +141,7 @@ public class Snippet040TableViewerSorting {
});
- new ColumnViewerSorter(v,column) {
+ new ColumnViewerSorter(viewer, column) {
@Override
protected int doCompare(Viewer viewer, Object e1, Object e2) {
@@ -173,10 +152,7 @@ public class Snippet040TableViewerSorting {
};
- column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("E-Mail");
- column.getColumn().setMoveable(true);
+ column = createColumnFor(viewer, "E-Mail");
column.setLabelProvider(new ColumnLabelProvider() {
@Override
@@ -186,7 +162,7 @@ public class Snippet040TableViewerSorting {
});
- column.setEditingSupport(new AbstractEditingSupport(v) {
+ column.setEditingSupport(new AbstractEditingSupport(viewer) {
@Override
protected Object getValue(Object element) {
@@ -200,7 +176,7 @@ public class Snippet040TableViewerSorting {
});
- new ColumnViewerSorter(v,column) {
+ new ColumnViewerSorter(viewer, column) {
@Override
protected int doCompare(Viewer viewer, Object e1, Object e2) {
@@ -211,52 +187,59 @@ public class Snippet040TableViewerSorting {
};
- Person[] model = createModel();
- v.setInput(model);
- v.getTable().setLinesVisible(true);
- v.getTable().setHeaderVisible(true);
+ viewer.setInput(createModel());
+ viewer.getTable().setLinesVisible(true);
+ viewer.getTable().setHeaderVisible(true);
cSorter.setSorter(cSorter, ColumnViewerSorter.ASC);
}
+ 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("Jeanderson", "Candido", "jeandersonbc@gmail.com"),
+ new Person("Lars", "Vogel", "Lars.Vogel@gmail.com"),
+ new Person("Hendrik", "Still", "hendrik.still@gammas.de") };
}
private static abstract class ColumnViewerSorter extends ViewerComparator {
- public static final int ASC = 1;
+ 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) {
this.column = column;
this.viewer = viewer;
- this.column.getColumn().addSelectionListener(new SelectionAdapter() {
+ SelectionAdapter selectionAdapter = createSelectionAdapter();
+ this.column.getColumn().addSelectionListener(selectionAdapter);
+ }
+
+ private SelectionAdapter createSelectionAdapter() {
+ return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if( ColumnViewerSorter.this.viewer.getComparator() != null ) {
- if( ColumnViewerSorter.this.viewer.getComparator() == ColumnViewerSorter.this ) {
+ if (ColumnViewerSorter.this.viewer.getComparator() != null) {
+ if (ColumnViewerSorter.this.viewer.getComparator() == ColumnViewerSorter.this) {
int tdirection = ColumnViewerSorter.this.direction;
-
- if( tdirection == ASC ) {
+ if (tdirection == ASC) {
setSorter(ColumnViewerSorter.this, DESC);
- } else if( tdirection == DESC ) {
+ } else if (tdirection == DESC) {
setSorter(ColumnViewerSorter.this, NONE);
}
} else {
@@ -266,25 +249,23 @@ public class Snippet040TableViewerSorting {
setSorter(ColumnViewerSorter.this, ASC);
}
}
- });
+ };
}
public void setSorter(ColumnViewerSorter sorter, int direction) {
- if( direction == NONE ) {
- column.getColumn().getParent().setSortColumn(null);
- column.getColumn().getParent().setSortDirection(SWT.NONE);
+ Table columnParent = column.getColumn().getParent();
+ if (direction == NONE) {
+ columnParent.setSortColumn(null);
+ columnParent.setSortDirection(SWT.NONE);
viewer.setComparator(null);
+
} else {
- column.getColumn().getParent().setSortColumn(column.getColumn());
+ columnParent.setSortColumn(column.getColumn());
sorter.direction = direction;
+ columnParent.setSortDirection(direction == ASC ? SWT.DOWN
+ : SWT.UP);
- if( direction == ASC ) {
- column.getColumn().getParent().setSortDirection(SWT.DOWN);
- } else {
- column.getColumn().getParent().setSortDirection(SWT.UP);
- }
-
- if( viewer.getComparator() == sorter ) {
+ if (viewer.getComparator() == sorter) {
viewer.refresh();
} else {
viewer.setComparator(sorter);
@@ -316,9 +297,7 @@ public class Snippet040TableViewerSorting {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
-
}
}
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 b6210fb..5cefe3b 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
@@ -8,12 +8,16 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * 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.ColumnLabelProvider;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
@@ -37,40 +41,6 @@ import org.eclipse.swt.widgets.TableItem;
*/
public class Snippet041TableViewerAlternatingColors {
- 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;
@@ -91,24 +61,24 @@ public class Snippet041TableViewerAlternatingColors {
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 ) {
+ for (int i = lastIndex; i < items.length && lastIndex + 10 > i; i++) {
+ if (items[i] == item) {
lastIndex = i;
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 ) {
+ for (int i = lastIndex; i < items.length && lastIndex - 10 > i; i--) {
+ if (items[i] == item) {
lastIndex = i;
return lastIndex % 2 == 0;
}
}
// 3. Start from the beginning
- for( int i = 0; i < items.length; i++ ) {
- if( items[i] == item ) {
+ for (int i = 0; i < items.length; i++) {
+ if (items[i] == item) {
lastIndex = i;
return lastIndex % 2 == 0;
}
@@ -118,98 +88,89 @@ public class Snippet041TableViewerAlternatingColors {
}
}
+ final private OptimizedIndexSearcher searcher = new OptimizedIndexSearcher();
+
public Snippet041TableViewerAlternatingColors(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
- | SWT.FULL_SELECTION|SWT.VIRTUAL);
- v.setContentProvider(new MyContentProvider());
+ final TableViewer viewer = new TableViewer(shell, SWT.BORDER
+ | SWT.FULL_SELECTION | SWT.VIRTUAL);
+
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ String[] labels = { "Column 1", "Column 2" };
+ for (String label : labels) {
+ createColumnFor(viewer, label);
+ }
+ viewer.setInput(createModel());
+ viewer.getTable().setLinesVisible(true);
+ viewer.getTable().setHeaderVisible(true);
- final OptimizedIndexSearcher searcher = new OptimizedIndexSearcher();
+ Button b = new Button(shell, SWT.PUSH);
+ b.addSelectionListener(createAdapterFor(viewer));
+ }
- TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
- boolean even = true;
+ private SelectionAdapter createAdapterFor(final TableViewer viewer) {
+ return new SelectionAdapter() {
+ boolean b = true;
@Override
- public Color getBackground(Object element) {
- if( even ) {
- return null;
+ public void widgetSelected(SelectionEvent e) {
+ if (b) {
+ viewer.setFilters(new ViewerFilter[] { createFilterForViewer() });
+ b = false;
+
} else {
- return v.getTable().getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ viewer.setFilters(new ViewerFilter[0]);
+ b = true;
}
}
+ };
+ }
+
+ private ViewerFilter createFilterForViewer() {
+ return new ViewerFilter() {
@Override
- public void update(ViewerCell cell) {
- even = searcher.isEven((TableItem)cell.getItem());
- super.update(cell);
+ public boolean select(Viewer viewer, Object parentElement,
+ Object element) {
+
+ return ((MyModel) element).counter % 2 == 0;
}
- });
+ };
+ }
- column = new TableViewerColumn(v, SWT.NONE);
+ private TableViewerColumn createColumnFor(TableViewer viewer, String label) {
+ TableViewerColumn column;
+ column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setWidth(200);
- column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider() {
- boolean even = true;
+ column.getColumn().setText(label);
+ column.setLabelProvider(createLabelProviderFor(viewer));
+ return column;
+ }
+
+ private ColumnLabelProvider createLabelProviderFor(final TableViewer viewer) {
+ return new ColumnLabelProvider() {
+ boolean isEvenIdx = true;
@Override
public Color getBackground(Object element) {
- if( even ) {
- return null;
- } else {
- return v.getTable().getDisplay().getSystemColor(SWT.COLOR_GRAY);
- }
+ Color grayColor = viewer.getTable().getDisplay()
+ .getSystemColor(SWT.COLOR_GRAY);
+
+ return (isEvenIdx ? null : grayColor);
}
@Override
public void update(ViewerCell cell) {
- even = searcher.isEven((TableItem)cell.getItem());
+ isEvenIdx = searcher.isEven((TableItem) cell.getItem());
super.update(cell);
}
-
- });
-
- MyModel[] model = createModel();
- v.setInput(model);
- v.getTable().setLinesVisible(true);
- v.getTable().setHeaderVisible(true);
-
- final ViewerFilter filter = new ViewerFilter() {
-
- @Override
- public boolean select(Viewer viewer, Object parentElement,
- Object element) {
- return ((MyModel)element).counter % 2 == 0;
- }
-
};
-
- Button b = new Button(shell,SWT.PUSH);
- b.addSelectionListener(new SelectionAdapter() {
- boolean b = true;
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- if( b ) {
- v.setFilters(new ViewerFilter[] {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>();
for (int i = 0; i < 100000; i++) {
- elements[i] = new MyModel(i);
+ elements.add(new MyModel(i));
}
-
return elements;
}
@@ -228,7 +189,6 @@ public class Snippet041TableViewerAlternatingColors {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
}
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 b573a31..5aae57d 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
@@ -8,11 +8,13 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * 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.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
@@ -37,7 +39,8 @@ import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Shell;
/**
- * Demonstrates how to use keyboard-editing support in a TreeViewer with no column
+ * Demonstrates how to use keyboard-editing support in a TreeViewer with no
+ * column
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
*
@@ -59,8 +62,7 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
public void widgetSelected(SelectionEvent e) {
MyModel root = (MyModel) 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), root.child.get(1).child.get(0) });
v.editElement(path, 0);
}
@@ -83,8 +85,7 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
@Override
public void modify(Object element, String property, Object value) {
element = ((Item) element).getData();
- ((MyModel) element).counter = Integer
- .parseInt(value.toString());
+ ((MyModel) element).counter = Integer.parseInt(value.toString());
v.update(element, null);
}
@@ -111,30 +112,9 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
| ColumnViewerEditor.KEYBOARD_ACTIVATION);
v.setContentProvider(new MyContentProvider());
-
v.setInput(createModel());
}
- private MyModel createModel() {
-
- MyModel root = new MyModel(0, null);
- root.counter = 0;
-
- MyModel tmp;
- MyModel subItem;
- for (int i = 1; i < 10; i++) {
- tmp = new MyModel(i, root);
- root.child.add(tmp);
- for (int j = 1; j < i; j++) {
- subItem = new MyModel(j, tmp);
- subItem.child.add(new MyModel(j * 100, subItem));
- tmp.child.add(subItem);
- }
- }
-
- return root;
- }
-
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
@@ -146,7 +126,6 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
}
@@ -185,11 +164,29 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
}
- public class MyModel {
- public MyModel parent;
+ private MyModel createModel() {
+ MyModel root = new MyModel(0, null);
+ root.counter = 0;
+
+ MyModel tmp;
+ MyModel subItem;
+ for (int i = 1; i < 10; i++) {
+ tmp = new MyModel(i, root);
+ root.child.add(tmp);
+ for (int j = 1; j < i; j++) {
+ subItem = new MyModel(j, tmp);
+ subItem.child.add(new MyModel(j * 100, subItem));
+ tmp.child.add(subItem);
+ }
+ }
- public ArrayList child = new ArrayList();
+ return root;
+ }
+
+ public class MyModel {
+ public MyModel parent;
+ public List<MyModel> child = new ArrayList<MyModel>();
public int counter;
public MyModel(int counter, MyModel parent) {
@@ -203,7 +200,6 @@ public class Snippet043NoColumnTreeViewerKeyboardEditing {
if (parent != null) {
rv = parent.toString() + ".";
}
-
rv += counter;
return rv;