aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-05-12 23:42:05 (EDT)
committerLars Vogel2014-05-13 23:36:10 (EDT)
commit7ea3d826a45b3b678c3ba33ba63e8b1d367a0c8d (patch)
treee4587830ee69b0d5de541defdc7630f92757264f
parente5524df50f148dea4262b507fa9db024d11cd0d1 (diff)
downloadeclipse.platform.ui-7ea3d826a45b3b678c3ba33ba63e8b1d367a0c8d.zip
eclipse.platform.ui-7ea3d826a45b3b678c3ba33ba63e8b1d367a0c8d.tar.gz
eclipse.platform.ui-7ea3d826a45b3b678c3ba33ba63e8b1d367a0c8d.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanuprefs/changes/15/26415/2
General cleaning for snippets 25, 26, 27, 29, 31, 34, 36, and 38. Change-Id: Id1c22326edcbb6a04131f4308494b247783c41ed Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet025TabEditing.java148
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java148
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet027ComboBoxCellEditors.java80
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java15
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java16
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRow.java61
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet036FocusBorderCellHighlighter.java102
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet038TreeViewerInlinelEditingOldAPI.java91
8 files changed, 210 insertions, 451 deletions
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 9cf12c9..7dbd247 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, 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,20 +7,23 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * 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.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
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.TableViewerEditor;
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;
@@ -30,128 +33,103 @@ 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 {
-
- /* (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;
-
+
public MyModel(int counter) {
this.counter = counter;
}
-
+
@Override
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() {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
- */
+ final TableViewer viewer = new TableViewer(shell, SWT.BORDER
+ | SWT.FULL_SELECTION);
+
+ createColumnFor(viewer, "Column 1", 100);
+ createColumnFor(viewer, "Column 2", 200);
+
+ viewer.setLabelProvider(new LabelProvider());
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ viewer.setCellModifier(new ICellModifier() {
+
@Override
public boolean canModify(Object element, String property) {
- return ((MyModel)element).counter % 2 == 0;
+ return ((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 + "";
+ 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;
- ((MyModel)item.getData()).counter = Integer.parseInt(value.toString());
- v.update(item.getData(), null);
+ TableItem item = (TableItem) element;
+ ((MyModel) item.getData()).counter = Integer.parseInt(value
+ .toString());
+ viewer.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();
- v.setInput(model);
- v.getTable().setLinesVisible(true);
+
+ viewer.setColumnProperties(new String[] { "column1", "column2" });
+ viewer.setCellEditors(new CellEditor[] {
+ new TextCellEditor(viewer.getTable()),
+ new TextCellEditor(viewer.getTable()) });
+
+ TableViewerEditor.create(viewer,
+ new ColumnViewerEditorActivationStrategy(viewer),
+ ColumnViewerEditor.TABBING_HORIZONTAL
+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
+ | ColumnViewerEditor.TABBING_VERTICAL);
+
+ viewer.setInput(createModel());
+ viewer.getTable().setLinesVisible(true);
+ }
+
+ private void createColumnFor(TableViewer viewer, String label, int width) {
+ TableColumn tc = new TableColumn(viewer.getTable(), SWT.NONE);
+ tc.setWidth(width);
+ tc.setText(label);
+
}
-
- 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>();
+
+ for (int i = 0; i < 10; i++) {
+ elements.add(new MyModel(i));
}
-
return elements;
}
-
+
/**
* @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 Snippet025TabEditing(shell);
- shell.open ();
-
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
+ shell.open();
+
+ 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/Snippet026TreeViewerTabEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet026TreeViewerTabEditing.java
index 6a6596d..6002c7e 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, 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,11 +7,13 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * 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.ColumnLabelProvider;
@@ -37,13 +39,13 @@ 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);
+ Button b = new Button(shell, SWT.PUSH);
b.setText("Remove column");
final TreeViewer v = new TreeViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION);
@@ -53,18 +55,20 @@ public class Snippet026TreeViewerTabEditing {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
-
+
}
@Override
public void widgetSelected(SelectionEvent e) {
v.getTree().getColumn(1).dispose();
}
-
+
});
-
- TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));
- ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
+
+ TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(
+ v, new FocusCellOwnerDrawHighlighter(v));
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
+ v) {
@Override
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
@@ -74,101 +78,47 @@ 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);
- column.getColumn().setWidth(200);
- column.getColumn().setMoveable(true);
- column.getColumn().setText("Column 1");
- column.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- return "Column 1 => " + element.toString();
- }
- });
- column.setEditingSupport(new EditingSupport(v) {
- @Override
- protected boolean canEdit(Object element) {
- return false;
- }
+ int feature = ColumnViewerEditor.TABBING_HORIZONTAL
+ | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
+ | ColumnViewerEditor.TABBING_VERTICAL
+ | ColumnViewerEditor.KEYBOARD_ACTIVATION;
- @Override
- protected CellEditor getCellEditor(Object element) {
- return textCellEditor;
- }
+ TreeViewerEditor.create(v, focusCellManager, actSupport, feature);
+ final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
- @Override
- protected Object getValue(Object element) {
- return ((MyModel) element).counter + "";
- }
+ String[] columLabels = { "Column 1", "Column 2", "Column 3" };
+ String[] labelPrefix = { "Column 1 => ", "Column 2 => ", "Column 3 => " };
- @Override
- protected void setValue(Object element, Object value) {
- ((MyModel) element).counter = Integer
- .parseInt(value.toString());
- v.update(element, null);
- }
- });
+ for (int i = 0; i < columLabels.length; i++) {
+ TreeViewerColumn column = new TreeViewerColumn(v, SWT.NONE);
+ column.getColumn().setWidth(200);
+ column.getColumn().setMoveable(true);
+ column.getColumn().setText(columLabels[i]);
+ column.setLabelProvider(createColumnLabelProvider(labelPrefix[i]));
+ column.setEditingSupport(createEditingSupportFor(v, textCellEditor));
+ }
+ v.setContentProvider(new MyContentProvider());
+ v.setInput(createModel());
+ }
- column = new TreeViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setMoveable(true);
- column.getColumn().setText("Column 2");
- column.setLabelProvider(new ColumnLabelProvider() {
+ private ColumnLabelProvider createColumnLabelProvider(final String prefix) {
+ return new ColumnLabelProvider() {
@Override
public String getText(Object element) {
- return "Column 2 => " + element.toString();
+ return prefix + element.toString();
}
- });
- column.setEditingSupport(new EditingSupport(v) {
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- return textCellEditor;
- }
-
- @Override
- protected Object getValue(Object element) {
- return ((MyModel) element).counter + "";
- }
-
- @Override
- protected void setValue(Object element, Object value) {
- ((MyModel) element).counter = Integer
- .parseInt(value.toString());
- v.update(element, null);
- }
- });
-
- column = new TreeViewerColumn(v, SWT.NONE);
- column.getColumn().setWidth(200);
- column.getColumn().setMoveable(true);
- column.getColumn().setText("Column 3");
- column.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- return "Column 3 => " + element.toString();
- }
+ };
+ }
- });
- column.setEditingSupport(new EditingSupport(v) {
+ private EditingSupport createEditingSupportFor(final TreeViewer viewer,
+ final TextCellEditor textCellEditor) {
+ return new EditingSupport(viewer) {
@Override
protected boolean canEdit(Object element) {
- return true;
+ return false;
}
@Override
@@ -185,17 +135,12 @@ public class Snippet026TreeViewerTabEditing {
protected void setValue(Object element, Object value) {
((MyModel) element).counter = Integer
.parseInt(value.toString());
- v.update(element, null);
+ viewer.update(element, null);
}
- });
-
- v.setContentProvider(new MyContentProvider());
-
- v.setInput(createModel());
+ };
}
private MyModel createModel() {
-
MyModel root = new MyModel(0, null);
root.counter = 0;
@@ -210,7 +155,6 @@ public class Snippet026TreeViewerTabEditing {
tmp.child.add(subItem);
}
}
-
return root;
}
@@ -225,7 +169,6 @@ public class Snippet026TreeViewerTabEditing {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
}
@@ -266,9 +209,7 @@ public class Snippet026TreeViewerTabEditing {
public class MyModel {
public MyModel parent;
-
- public ArrayList child = new ArrayList();
-
+ public List<MyModel> child = new ArrayList<MyModel>();
public int counter;
public MyModel(int counter, MyModel parent) {
@@ -282,7 +223,6 @@ public class Snippet026TreeViewerTabEditing {
if (parent != null) {
rv = parent.toString() + ".";
}
-
rv += counter;
return rv;
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 a12dbe9..9d6eb83 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, 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.ComboBoxCellEditor;
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.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
@@ -29,9 +32,9 @@ 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 {
@@ -42,35 +45,17 @@ public class Snippet027ComboBoxCellEditors {
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 true;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object,
- * java.lang.String)
- */
@Override
public Object getValue(Object element, String property) {
// We need to calculate back to the index
return new Integer(((MyModel) element).counter / 10);
}
- /*
- * (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;
@@ -80,41 +65,6 @@ public class Snippet027ComboBoxCellEditors {
}
}
- 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;
@@ -137,7 +87,7 @@ public class Snippet027ComboBoxCellEditors {
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 ComboBoxCellEditor(
@@ -145,18 +95,16 @@ public class Snippet027ComboBoxCellEditors {
"Fourty", "Fifty", "Sixty", "Seventy", "Eighty",
"Ninety" }) });
- 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 * 10);
+ elements.add(new MyModel(i * 10));
}
-
return elements;
}
@@ -174,9 +122,7 @@ public class Snippet027ComboBoxCellEditors {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
-
}
}
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 fcca93b..1b22a33 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
@@ -8,10 +8,14 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 414565
+ * Jeanderson Candido <http://jeandersonbc.github.io> - 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.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
@@ -46,19 +50,16 @@ public class Snippet029VirtualTableViewer {
v.setLabelProvider(new LabelProvider());
v.setContentProvider(ArrayContentProvider.getInstance());
v.setUseHashlookup(true);
- MyModel[] model = createModel();
- v.setInput(model);
-
+ v.setInput(createModel());
v.getTable().setLinesVisible(true);
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10000];
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>();
for (int i = 0; i < 10000; i++) {
- elements[i] = new MyModel(i);
+ elements.add(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 f92c46a..4d9c314 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
@@ -8,6 +8,7 @@
* Contributors:
* Adam Neal - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 414565
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -134,10 +135,6 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
Shell tooltip = null;
Label label = null;
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
- */
@Override
public void handleEvent (Event event) {
switch (event.type) {
@@ -212,11 +209,8 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
private boolean isCTRLDown(Event e) {
return (e.stateMask & SWT.CTRL) != 0;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
- */
- @Override
+
+ @Override
public void handleEvent (Event event) {
Label label = (Label)event.widget;
Shell shell = label.getShell ();
@@ -275,8 +269,8 @@ public class Snippet031TableViewerCustomTooltipsMultiSelection {
- private List createModel() {
- ArrayList list = new ArrayList();
+ private List<MyModel> createModel() {
+ List<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/Snippet034CellEditorPerRow.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRow.java
index a3c6afd..e9175b9 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRow.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet034CellEditorPerRow.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Tom Schindl and others.
+ * Copyright (c) 2007, 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
@@ -9,19 +9,22 @@
* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation
* Wayne Beaton - bug 185540
* 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.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
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;
@@ -85,41 +88,6 @@ public class Snippet034CellEditorPerRow {
}
- 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;
@@ -163,24 +131,19 @@ public class Snippet034CellEditorPerRow {
});
column.setEditingSupport(new MyEditingSupport(v));
-
- v.setContentProvider(new MyContentProvider());
-
- MyModel[] model = createModel();
- v.setInput(model);
+ v.setContentProvider(ArrayContentProvider.getInstance());
+ v.setInput(createModel());
}
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[20];
+ 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));
}
-
for (int i = 0; i < 10; i++) {
- elements[i+10] = new MyModel2(i);
+ elements.add(new MyModel2(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 29edf83..57f83db 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
@@ -8,17 +8,21 @@
* 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.resource.FontRegistry;
+import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewerEditor;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.ICellModifier;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
@@ -27,7 +31,6 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerEditor;
import org.eclipse.jface.viewers.TableViewerFocusCellManager;
import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
@@ -43,41 +46,6 @@ import org.eclipse.swt.widgets.TableColumn;
*/
public class Snippet036FocusBorderCellHighlighter {
- 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 static boolean flag = true;
public class MyModel {
@@ -125,11 +93,14 @@ public class Snippet036FocusBorderCellHighlighter {
}
public Snippet036FocusBorderCellHighlighter(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER|SWT.FULL_SELECTION);
+ final TableViewer v = new TableViewer(shell, SWT.BORDER
+ | SWT.FULL_SELECTION);
v.setLabelProvider(new MyLabelProvider());
- v.setContentProvider(new MyContentProvider());
+ v.setContentProvider(ArrayContentProvider.getInstance());
- v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
+ v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()),
+ new TextCellEditor(v.getTable()),
+ new TextCellEditor(v.getTable()) });
v.setCellModifier(new ICellModifier() {
@Override
@@ -149,10 +120,12 @@ public class Snippet036FocusBorderCellHighlighter {
});
- v.setColumnProperties(new String[] {"1","2","3"});
+ v.setColumnProperties(new String[] { "1", "2", "3" });
- TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new FocusBorderCellHighlighter(v));
- ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
+ TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(
+ v, new FocusBorderCellHighlighter(v));
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
+ v) {
@Override
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
@@ -163,40 +136,35 @@ public class Snippet036FocusBorderCellHighlighter {
}
};
- TableViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
+ int feature = ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
- | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
+ | ColumnViewerEditor.TABBING_VERTICAL
+ | ColumnViewerEditor.KEYBOARD_ACTIVATION;
+ TableViewerEditor.create(v, focusCellManager, actSupport, feature);
- TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
- column.setWidth(200);
- column.setMoveable(true);
- column.setText("Column 1");
-
- column = new TableColumn(v.getTable(), SWT.NONE);
- column.setWidth(200);
- column.setMoveable(true);
- column.setText("Column 2");
+ String[] columLabels = { "Column 1", "Column 2", "Column 3" };
+ for (String label : columLabels) {
+ createColumnFor(v, label);
+ }
+ v.setInput(createModel());
+ v.getTable().setLinesVisible(true);
+ v.getTable().setHeaderVisible(true);
+ }
- column = new TableColumn(v.getTable(), SWT.NONE);
+ private void createColumnFor(TableViewer v, String label) {
+ TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setMoveable(true);
- column.setText("Column 3");
-
-
- MyModel[] model = createModel();
- v.setInput(model);
- v.getTable().setLinesVisible(true);
- v.getTable().setHeaderVisible(true);
+ column.setText(label);
}
- 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 +183,7 @@ public class Snippet036FocusBorderCellHighlighter {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
-
}
}
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 5bdc89b..08ed57d 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, 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,11 +7,13 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * 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.resource.FontRegistry;
import org.eclipse.jface.viewers.CellEditor;
@@ -32,59 +34,33 @@ 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 {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
@Override
public Object[] getElements(Object inputElement) {
return ((MyModel) inputElement).child.toArray();
}
- /*
- * (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) {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- */
@Override
public Object[] getChildren(Object parentElement) {
return getElements(parentElement);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
@Override
public Object getParent(Object element) {
if (element == null) {
@@ -94,11 +70,6 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
return ((MyModel) element).parent;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- */
@Override
public boolean hasChildren(Object element) {
return ((MyModel) element).child.size() > 0;
@@ -108,9 +79,7 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
public class MyModel {
public MyModel parent;
-
- public ArrayList child = new ArrayList();
-
+ public List<MyModel> child = new ArrayList<MyModel>();
public int counter;
public MyModel(int counter, MyModel parent) {
@@ -124,7 +93,6 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
if (parent != null) {
rv = parent.toString() + ".";
}
-
rv += counter;
return rv;
@@ -147,19 +115,17 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
}
public Snippet038TreeViewerInlinelEditingOldAPI(Shell shell) {
- final TreeViewer v = new TreeViewer(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() {
+ final TreeViewer viewer = new TreeViewer(shell, SWT.FULL_SELECTION);
+
+ createColumnFor(viewer, "Column 1");
+ createColumnFor(viewer, "Column 2");
+
+ viewer.setCellEditors(new CellEditor[] {
+ new TextCellEditor(viewer.getTree()),
+ new TextCellEditor(viewer.getTree()) });
+
+ viewer.setColumnProperties(new String[] { "col1", "col2" });
+ viewer.setCellModifier(new ICellModifier() {
@Override
public boolean canModify(Object element, String property) {
@@ -168,23 +134,29 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
@Override
public Object getValue(Object element, String property) {
- return ((MyModel)element).counter+"";
+ return ((MyModel) element).counter + "";
}
@Override
public void modify(Object element, String property, Object value) {
- ((MyModel)((TreeItem)element).getData()).counter = Integer.parseInt(value.toString());
- v.update(((TreeItem)element).getData(), null);
+ ((MyModel) ((TreeItem) element).getData()).counter = Integer
+ .parseInt(value.toString());
+ viewer.update(((TreeItem) element).getData(), null);
}
-
+
});
- v.setLabelProvider(new MyLabelProvider());
- v.setContentProvider(new MyContentProvider());
- v.setInput(createModel());
+ viewer.setLabelProvider(new MyLabelProvider());
+ viewer.setContentProvider(new MyContentProvider());
+ viewer.setInput(createModel());
}
- private MyModel createModel() {
+ private void createColumnFor(TreeViewer viewer, String label) {
+ TreeColumn column = new TreeColumn(viewer.getTree(), SWT.NONE);
+ column.setWidth(200);
+ column.setText(label);
+ }
+ private MyModel createModel() {
MyModel root = new MyModel(0, null);
root.counter = 0;
@@ -196,7 +168,6 @@ public class Snippet038TreeViewerInlinelEditingOldAPI {
tmp.child.add(new MyModel(j, tmp));
}
}
-
return root;
}