Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWim Jongman2018-09-09 12:24:50 +0000
committerWim Jongman2018-09-10 11:41:31 +0000
commitac4c2ea9905cadf4f652220d8476c9237726f603 (patch)
tree3b8bdc1e3a32046da5655d61deb596fbac4f906b
parent241825960811f683bc42d58237da2d3c40a69db8 (diff)
downloadeclipse.platform.ui-ac4c2ea9905cadf4f652220d8476c9237726f603.tar.gz
eclipse.platform.ui-ac4c2ea9905cadf4f652220d8476c9237726f603.tar.xz
eclipse.platform.ui-ac4c2ea9905cadf4f652220d8476c9237726f603.zip
Bug 538821 - [JFace] Give the snippets some love
* Added button text to Snippet041 * Added button text to Snippet043 * Added initial input to Snippet045 * Added some excitement to Snippet046 * Overhaul of lazy treeviewer snippet047 * Added a cool barcode for snippet051 * Prevented crash on wrong input for snippet053 * Javadoc on Snippet058 * Screen size on Snippet058 * Random element selection on snippet063 * Changed text in Snippet020 * Deleted Snippet021. Old 3.1 style madness * Deleted Snippet042. Old API Change-Id: I2d8a73b92b95df4a0d91cd1788418326fbab8fe9 Signed-off-by: Wim Jongman <wim.jongman@remainsoftware.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java173
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java2
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java249
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043TreeViewerKeyboardEditing.java4
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet045TableViewerFillFromBackgroundThread.java13
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet046UpdateViewerFromBackgroundThread.java58
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet047VirtualLazyTreeViewer.java168
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet051TableCenteredImage.java35
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet053StartEditorWithContextMenu.java18
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java121
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet063ComboViewer.java5
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java5
12 files changed, 223 insertions, 628 deletions
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
deleted file mode 100644
index 70ce09d755f..00000000000
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet021CellEditorsOnDoubleClick.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2015 Tom Schindl and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Tom Schindl - initial API and implementation
- * Dinko Ivanov - bug 164365
- * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
- * Simon Scholz <simon.scholz@vogella.com> - Bug 448143
- * Lars Vogel <Lars.Vogel@vogella.com> - Bug 475361
- *******************************************************************************/
-
-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.ColumnViewer;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-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 MyEditingSupport extends EditingSupport {
-
- private boolean enabled;
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public MyEditingSupport(ColumnViewer viewer) {
- super(viewer);
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- return new TextCellEditor((Composite) getViewer().getControl());
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return enabled && ((MyModel) element).counter % 2 == 0;
- }
-
- @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());
- getViewer().update(element, null);
- }
-
- }
-
- public class MyModel {
- public int counter;
-
- public MyModel(int counter) {
- this.counter = counter;
- }
-
- @Override
- public String toString() {
- return "Item " + this.counter;
- }
- }
-
- public Snippet021CellEditorsOnDoubleClick(Shell shell) {
- final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
- final TableViewer v = new TableViewer(table);
- final MyEditingSupport editingSupport = new MyEditingSupport(v);
-
- table.addListener(SWT.MouseDown, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- editingSupport.setEnabled(false);
- }
-
- });
-
- table.addListener(SWT.MouseDoubleClick, new Listener() {
-
- @Override
- public void handleEvent(Event event) {
- editingSupport.setEnabled(true);
- TableItem[] selection = table.getSelection();
-
- if (selection.length != 1) {
- return;
- }
-
- TableItem item = table.getSelection()[0];
-
- for (int i = 0; i < table.getColumnCount(); i++) {
- if (item.getBounds(i).contains(event.x, event.y)) {
- v.editElement(v.getStructuredSelection().getFirstElement(), i);
- editingSupport.setEnabled(false);
- break;
- }
- }
- }
-
- });
-
- TableViewerColumn viewerColumn = new TableViewerColumn(v, SWT.NONE);
- viewerColumn.getColumn().setWidth(200);
- viewerColumn.setLabelProvider(new ColumnLabelProvider());
- viewerColumn.setEditingSupport(editingSupport);
-
- v.setContentProvider(ArrayContentProvider.getInstance());
-
- v.setInput(createModel());
- v.getTable().setLinesVisible(true);
- }
-
- private List<MyModel> createModel() {
- List<MyModel> elements = new ArrayList<>();
-
- 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();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- new Snippet021CellEditorsOnDoubleClick(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/Snippet041TableViewerAlternatingColors.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet041TableViewerAlternatingColors.java
index 67ed14745c3..84b87e0ca0d 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
@@ -95,6 +95,7 @@ public class Snippet041TableViewerAlternatingColors {
final private OptimizedIndexSearcher searcher = new OptimizedIndexSearcher();
public Snippet041TableViewerAlternatingColors(Shell shell) {
+
final TableViewer viewer = new TableViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION | SWT.VIRTUAL);
@@ -108,6 +109,7 @@ public class Snippet041TableViewerAlternatingColors {
viewer.getTable().setHeaderVisible(true);
Button b = new Button(shell, SWT.PUSH);
+ b.setText("Press to toggle filter");
b.addSelectionListener(createAdapterFor(viewer));
}
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
deleted file mode 100644
index 143d595cafb..00000000000
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet042ToolTipSupportFor32API.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2016 Tom Schindl and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Tom Schindl - initial API and implementation
- * Lars Vogel <Lars.Vogel@vogella.com> - Bug 413427, 510301
- * Simon Scholz <simon.scholz@vogella.com> - Bug 442343
- *******************************************************************************/
-
-package org.eclipse.jface.snippets.viewers;
-
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.ColumnViewer;
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.window.DefaultToolTip;
-import org.eclipse.jface.window.ToolTip;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Item;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-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;
-
- private static class Cell {
- private Item item;
- private int index;
-
- public Cell(Item item, int index) {
- this.item = item;
- this.index = index;
- }
-
- public Object getData() {
- return item.getData();
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + index;
- result = prime * result + ((item == null) ? 0 : item.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final Cell other = (Cell) obj;
- if (index != other.index)
- return false;
- if (item == null) {
- if (other.item != null)
- return false;
- } else if (!item.equals(other.item))
- return false;
- return true;
- }
-
- }
-
- private static class ToolTipSupport extends DefaultToolTip {
- private Cell cell;
- private ColumnViewer viewer;
-
- protected ToolTipSupport(ColumnViewer viewer, int style,
- boolean manualActivation) {
- super(viewer.getControl(), style, manualActivation);
- this.viewer = viewer;
- }
-
- @Override
- protected Object getToolTipArea(Event event) {
- Table table = (Table) event.widget;
- int columns = table.getColumnCount();
- Point point = new Point(event.x, event.y);
- TableItem item = table.getItem(point);
-
- if (item != null) {
- for (int i = 0; i < columns; i++) {
- if (item.getBounds(i).contains(point)) {
- this.cell = new Cell(item, i);
- return cell;
- }
- }
- }
-
- return null;
- }
-
- @Override
- protected Composite createToolTipContentArea(Event event,
- Composite parent) {
- 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));
-
- return comp;
- }
-
- public static void enableFor(ColumnViewer viewer) {
- new ToolTipSupport(viewer, ToolTip.NO_RECREATE, false);
- }
- }
-
- public class MyModel {
- public int counter;
-
- public MyModel(int counter) {
- this.counter = counter;
- }
-
- @Override
- public String toString() {
- return "Item " + this.counter;
- }
- }
-
- public class MyLabelProvider extends LabelProvider implements
- ITableLabelProvider {
-
- @Override
- public Image getColumnImage(Object element, int columnIndex) {
- if (columnIndex == 1) {
- return images[((MyModel) element).counter % 4];
- }
-
- return null;
- }
-
- @Override
- public String getColumnText(Object 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);
- GC gc = new GC(image);
- gc.setBackground(color);
- gc.fillRectangle(0, 0, 10, 10);
- gc.dispose();
-
- return image;
- }
-
- public Snippet042ToolTipSupportFor32API(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
- | SWT.FULL_SELECTION);
- v.setLabelProvider(new MyLabelProvider());
- v.setContentProvider(ArrayContentProvider.getInstance());
-
- 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();
- 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);
- }
-
- 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 Snippet042ToolTipSupportFor32API(shell);
- shell.open();
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
-
- for (Image image : images) {
- image.dispose();
- }
-
- display.dispose();
-
- }
-
-}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043TreeViewerKeyboardEditing.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043TreeViewerKeyboardEditing.java
index 5d592217be5..2d7270354bb 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043TreeViewerKeyboardEditing.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet043TreeViewerKeyboardEditing.java
@@ -53,7 +53,7 @@ import org.eclipse.swt.widgets.Shell;
public class Snippet043TreeViewerKeyboardEditing {
public Snippet043TreeViewerKeyboardEditing(final Shell shell) {
Button b = new Button(shell, SWT.PUSH);
- b.setText("BBB");
+ b.setText("Press Tab, or click here to edit first child element");
final TreeViewer v = new TreeViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION);
b.addSelectionListener(new SelectionAdapter() {
@@ -202,4 +202,4 @@ public class Snippet043TreeViewerKeyboardEditing {
}
}
-}
+} \ No newline at end of file
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 ab16976df76..f0e6066cdad 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
@@ -73,7 +73,11 @@ public class Snippet045TableViewerFillFromBackgroundThread {
@Override
public String getColumnText(Object element, int columnIndex) {
- return "Column " + columnIndex + " => " + element.toString();
+ MyModel m = (MyModel) element;
+ if (m.counter == 0) {
+ return "Column " + columnIndex + " => " + "Initial input";
+ }
+ return "Column " + columnIndex + " => thread added " + element.toString();
}
@Override
@@ -118,6 +122,9 @@ public class Snippet045TableViewerFillFromBackgroundThread {
column.setText("Column 2");
final List<MyModel> model = new ArrayList<>();
+ model.add(new MyModel(0));
+ model.add(new MyModel(0));
+ model.add(new MyModel(0));
v.setInput(model);
v.setComparator(new ViewerComparator() {
@Override
@@ -144,7 +151,7 @@ public class Snippet045TableViewerFillFromBackgroundThread {
};
Timer timer = new Timer(true);
- timer.scheduleAtFixedRate(task, 1000, 1000);
+ timer.scheduleAtFixedRate(task, 3000, 1000);
}
/**
@@ -165,4 +172,4 @@ public class Snippet045TableViewerFillFromBackgroundThread {
display.dispose();
}
-}
+} \ No newline at end of file
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 4af8fe76088..6762c7f91cd 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
@@ -16,6 +16,8 @@
package org.eclipse.jface.snippets.viewers;
+import java.util.Random;
+
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -41,9 +43,9 @@ import org.eclipse.swt.widgets.TableColumn;
public class Snippet046UpdateViewerFromBackgroundThread {
private static Image[] images;
-
public class MyModel {
public int counter;
+
public boolean finished;
public MyModel(int counter) {
@@ -60,8 +62,8 @@ public class Snippet046UpdateViewerFromBackgroundThread {
@Override
public Image getColumnImage(Object element, int columnIndex) {
- if( columnIndex == 0 ) {
- return images[((MyModel)element).finished?0:1];
+ if (columnIndex == 0) {
+ return images[((MyModel) element).finished ? 0 : 1];
}
return null;
@@ -75,8 +77,8 @@ public class Snippet046UpdateViewerFromBackgroundThread {
}
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);
+ Color color = new Color(display, red, green, blue);
+ Image image = new Image(display, 10, 10);
GC gc = new GC(image);
gc.setBackground(color);
gc.fillRectangle(0, 0, 10, 10);
@@ -86,15 +88,15 @@ public class Snippet046UpdateViewerFromBackgroundThread {
}
public Snippet046UpdateViewerFromBackgroundThread(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(ArrayContentProvider.getInstance());
- TableColumn column = new TableColumn(v.getTable(),SWT.NONE);
+ TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setText("Column 1");
- column = new TableColumn(v.getTable(),SWT.NONE);
+ column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
column.setText("Column 2");
@@ -103,31 +105,42 @@ public class Snippet046UpdateViewerFromBackgroundThread {
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
- Button b = new Button(shell,SWT.PUSH);
+ Button b = new Button(shell, SWT.PUSH);
b.setText("Start Long Task");
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
+ b.setText("Update running..");
+ b.setEnabled(false);
final Thread t = new Thread() {
@Override
public void run() {
- for( int i = 0; i < model.length; i++ ) {
- if( v.getTable().isDisposed()) {
+ for (int i = 0; i < model.length; i++) {
+ if (v.getTable().isDisposed()) {
return;
}
final int j = i;
v.getTable().getDisplay().asyncExec(() -> {
- model[j].finished = true;
+ if (model[j].finished) {
+ model[j].finished = false;
+ } else {
+ model[j].finished = true;
+ }
v.update(model[j], null);
});
try {
- Thread.sleep(1000);
+ Thread.sleep(new Random().nextInt(1000) + 100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
+
+ v.getTable().getDisplay().asyncExec(() -> {
+ b.setText("Start Long Task");
+ b.setEnabled(true);
+ });
}
};
t.start();
@@ -138,7 +151,7 @@ public class Snippet046UpdateViewerFromBackgroundThread {
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];
- for( int i = 0; i < 10; i++ ) {
+ for (int i = 0; i < 10; i++) {
elements[i] = new MyModel(i);
}
@@ -149,27 +162,28 @@ public class Snippet046UpdateViewerFromBackgroundThread {
* @param args
*/
public static void main(String[] args) {
- Display display = new Display ();
+ Display display = new Display();
images = new Image[2];
- images[0] = createImage(display,0,255,0);
- images[1] = createImage(display,255,0,0);
+ images[0] = createImage(display, 0, 255, 0);
+ images[1] = createImage(display, 255, 0, 0);
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet046UpdateViewerFromBackgroundThread(shell);
- shell.open ();
+ shell.open();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
}
for (Image image : images) {
image.dispose();
}
- display.dispose ();
+ display.dispose();
}
-}
+} \ No newline at end of file
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 a54d2bbe598..ece89e11ad7 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
@@ -11,141 +11,133 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 486603
+ * Wim Jongman <wim.jongman@remainsoftware.com> - Overhaul without preloading model
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.Random;
+
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ILazyTreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
/**
- * A simple TreeViewer example to demonstrate usage of an ILazyContentProvider.
- * Please note that you need to call viewer.setUseHasLoop(true) to enable the
- * lazy lookup in the content provider
+ * A simple TreeViewer example to demonstrate the usage of an
+ * ILazyContentProvider.
*
*/
public class Snippet047VirtualLazyTreeViewer {
- private class MyContentProvider implements ILazyTreeContentProvider {
+ private long fParentsLoaded = 0;
- private TreeViewer viewer;
- private IntermediateNode[] elements;
+ private long fGlobalChildrenLoaded = 0;
- public MyContentProvider(TreeViewer viewer) {
- this.viewer = viewer;
- }
-
- @Override
- public void dispose() {
+ private TreeViewer fViewer;
- }
+ private Text fText;
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- this.elements = (IntermediateNode[]) newInput;
- }
+ private class MyContentProvider implements ILazyTreeContentProvider {
@Override
public Object getParent(Object element) {
- if (element instanceof LeafNode)
- return ((LeafNode) element).parent;
- return elements;
+ return ((Node) element).getParent();
}
@Override
public void updateChildCount(Object element, int currentChildCount) {
-
- int length = 0;
- if (element instanceof IntermediateNode) {
- IntermediateNode node = (IntermediateNode) element;
- length = node.children.length;
- }
- if(element == elements)
- length = elements.length;
- viewer.setChildCount(element, length);
-
-
+ System.out.println(element + " " + ((Node) element).getChildCount());
+ fViewer.setChildCount(element, ((Node) element).getChildCount());
}
@Override
public void updateElement(Object parent, int index) {
+ Node element = ((Node) parent).getChild(index);
+ fViewer.replace(parent, index, element);
+ updateChildCount(element, -1);
+ fText.setText("1 root, " + fParentsLoaded + " nodes and " + fGlobalChildrenLoaded + " leafs in memory...");
+ }
+ }
- Object element;
- if (parent instanceof IntermediateNode)
- element = ((IntermediateNode) parent).children[index];
+ public class Node {
+ private int fChildCount;
- else
- element = elements[index];
- viewer.replace(parent, index, element);
- updateChildCount(element, -1);
+ public int fChildrenLoaded;
- }
+ private Node[] fChildren;
- }
+ private int fCounter;
- public class LeafNode {
- public int counter;
- public IntermediateNode parent;
+ private Node fParent;
- public LeafNode(int counter, IntermediateNode parent) {
- this.counter = counter;
- this.parent = parent;
+ public Node(int counter, int childCount, Node parent) {
+ fCounter = counter;
+ fChildCount = childCount;
+ fParent = parent;
}
- @Override
- public String toString() {
- return "Leaf " + this.counter;
+ public Node getParent() {
+ return fParent;
}
- }
-
- public class IntermediateNode {
- public int counter;
- public LeafNode[] children = new LeafNode[0];
- public IntermediateNode(int counter) {
- this.counter = counter;
+ public int getChildCount() {
+ return fChildCount;
}
- @Override
- public String toString() {
- return "Node " + this.counter;
+ public Node[] getChildren() {
+ if (fChildren == null) {
+ fChildren = new Node[fChildCount];
+ }
+ return fChildren;
}
- public void generateChildren(int i) {
- children = new LeafNode[i];
- for (int j = 0; j < i; j++) {
- children[j] = new LeafNode(j, this);
+ public Node getChild(int index) {
+ if (getChildren()[index] != null) {
+ return getChildren()[index];
}
+ Node leafNode = new Node(index, getRandomChildCount(), this);
+ getChildren()[index] = leafNode;
+ fViewer.update(leafNode.getParent(), null);
+ if (leafNode.getParent().getParent() == null) {
+ fParentsLoaded++;
+ } else {
+ fGlobalChildrenLoaded++;
+ }
+ fChildrenLoaded++;
+ return leafNode;
}
- }
-
- public Snippet047VirtualLazyTreeViewer(Shell shell) {
- final TreeViewer viewer = new TreeViewer(shell, SWT.VIRTUAL | SWT.BORDER);
- viewer.setLabelProvider(new LabelProvider());
- viewer.setContentProvider(new MyContentProvider(viewer));
- viewer.setUseHashlookup(true);
- IntermediateNode[] model = createModel();
- viewer.setInput(model);
- viewer.getTree().setItemCount(model.length);
- }
-
- private IntermediateNode[] createModel() {
- IntermediateNode[] elements = new IntermediateNode[10];
-
- for (int i = 0; i < 10; i++) {
- elements[i] = new IntermediateNode(i);
- elements[i].generateChildren(1000);
+ @Override
+ public String toString() {
+ String type = getParent() == null ? "Root" : getParent().getParent() == null ? "Node" : "Leaf";
+ return type + " " + this.fCounter + " of " + (getParent() == null ? "0" : getParent().getChildCount())
+ + " (" + fChildCount + "/" + fChildrenLoaded + ")";
}
+ }
- return elements;
+ public Snippet047VirtualLazyTreeViewer(Shell shell) {
+ fText = new Text(shell, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ fText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ fText.setEnabled(false);
+
+ fViewer = new TreeViewer(shell, SWT.VIRTUAL | SWT.BORDER);
+ fViewer.setLabelProvider(new LabelProvider());
+ fViewer.setContentProvider(new MyContentProvider());
+ fViewer.setUseHashlookup(true);
+ Node root = new Node(0, getRandomChildCount(), null);
+ fViewer.setInput(root);
+ fViewer.getTree().setLayoutData(GridDataFactory.fillDefaults().create());
+ fViewer.setChildCount(root, root.getChildCount());
+ fViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ // at this point the model only contains what is visible on the screen.
}
/**
@@ -154,17 +146,19 @@ public class Snippet047VirtualLazyTreeViewer {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
+ shell.setLayout(new GridLayout());
new Snippet047VirtualLazyTreeViewer(shell);
+ shell.setSize(800, 600);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
-
}
+ public static int getRandomChildCount() {
+ return new Random().nextInt(1000) + 100;
+ }
} \ No newline at end of file
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 5b585447c90..19d2d2b19b7 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
@@ -12,10 +12,13 @@
* Tom Schindl - initial API and implementation
* Simon Scholz <simon.scholz@vogella.com> - Bug 442343
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 510301
+ * Wim Jongman <wim.jongman@remainsoftware.com> - Added a cool barcode
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
+import java.util.Random;
+
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.OwnerDrawLabelProvider;
@@ -33,14 +36,14 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;
/**
- * Example showing how to center an image using an owner draw label provider
+ * Example showing how to centre an image and use graphics using an owner draw
+ * label provider
*
*/
public class Snippet051TableCenteredImage {
private static Image[] images;
- private abstract class CenterImageLabelProvider extends
- OwnerDrawLabelProvider {
+ private abstract class CenterImageLabelProvider extends OwnerDrawLabelProvider {
@Override
protected void measure(Event event, Object element) {
@@ -52,8 +55,7 @@ public class Snippet051TableCenteredImage {
Image img = getImage(element);
if (img != null) {
- Rectangle bounds = ((TableItem) event.item)
- .getBounds(event.index);
+ Rectangle bounds = ((TableItem) event.item).getBounds(event.index);
Rectangle imgBounds = img.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
@@ -64,6 +66,14 @@ public class Snippet051TableCenteredImage {
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
event.gc.drawImage(img, x, y);
+ } else {
+ Rectangle bounds = ((TableItem) event.item).getBounds(event.index);
+ for (int i = 0; i < bounds.width; i += 4) {
+ int width = new Random().nextInt(4) + 1;
+ event.gc.setForeground(event.display.getSystemColor(SWT.COLOR_BLACK));
+ event.gc.setLineWidth(width);
+ event.gc.drawLine(bounds.x + i, bounds.y, bounds.x + i, bounds.y + bounds.height);
+ }
}
}
@@ -83,8 +93,7 @@ public class Snippet051TableCenteredImage {
}
}
- private static Image createImage(Display display, int red, int green,
- int blue) {
+ 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);
GC gc = new GC(image);
@@ -96,8 +105,7 @@ public class Snippet051TableCenteredImage {
}
public Snippet051TableCenteredImage(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.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
@@ -107,7 +115,7 @@ public class Snippet051TableCenteredImage {
@Override
public String getText(Object element) {
- return "Column 1 => " + element.toString();
+ return "Column 1 => " + element.toString() + ((((MyModel) element).counter % 2 != 0) ? " barcode" : "");
}
});
@@ -118,7 +126,10 @@ public class Snippet051TableCenteredImage {
@Override
protected Image getImage(Object element) {
- return images[((MyModel) element).counter % 4];
+ if (((MyModel) element).counter % 2 == 0) {
+ return images[((MyModel) element).counter / 2 % 4];
+ }
+ return null;
}
});
@@ -171,4 +182,4 @@ public class Snippet051TableCenteredImage {
}
-}
+} \ No newline at end of file
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 7572bea1126..d90bb422478 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
@@ -13,12 +13,14 @@
* Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
* Simon Scholz <simon.scholz@vogella.com> - Bug 442343, 442747
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 442278, 475361
+ * Wim Jongman <wim.jongman@remainsoftware.com> - Added doc and made stable
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
@@ -44,7 +46,7 @@ import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
/**
- *
+ * Demonstrates how you can start editing a cell after selecting a context menu.
*/
public class Snippet053StartEditorWithContextMenu extends SelectionAdapter {
@@ -89,7 +91,9 @@ public class Snippet053StartEditorWithContextMenu extends SelectionAdapter {
public class MyModel {
public MyModel parent;
+
public List<MyModel> child = new ArrayList<>();
+
public int counter;
public MyModel(int counter, MyModel parent) {
@@ -132,10 +136,14 @@ public class Snippet053StartEditorWithContextMenu extends SelectionAdapter {
@Override
protected void setValue(Object element, Object value) {
- ((MyModel) element).counter = Integer.parseInt(value.toString());
- getViewer().update(element, null);
- }
+ try {
+ ((MyModel) element).counter = Integer.parseInt(value.toString());
+ getViewer().update(element, null);
+ } catch (Exception e) {
+ MessageDialog.openError(viewer.getControl().getShell(), "Oops", "We only accept numbers..");
+ }
+ }
}
public Snippet053StartEditorWithContextMenu(Shell shell) {
@@ -203,4 +211,4 @@ public class Snippet053StartEditorWithContextMenu extends SelectionAdapter {
display.dispose();
}
-}
+} \ No newline at end of file
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 4aa0955fd4b..ccc279f8bf3 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
@@ -43,10 +43,7 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
/**
- * Example for full feature cell navigation until bug 230955 is fixed
- *
- * @author Tom Schindl <tom.schindl@bestsolution.at>, Niels Lippke
- * <niels.lippke@airpas.com>
+ * Shows how to reveal columns when they are navigated.
*
*/
public class Snippet058CellNavigationIn34 {
@@ -57,14 +54,13 @@ public class Snippet058CellNavigationIn34 {
public String email;
public String gender;
- public Person(String givenname, String surname, String email,
- String gender) {
+ public Person(String givenname, String surname, String email, String gender) {
this.givenname = givenname;
this.surname = surname;
this.email = email;
this.gender = gender;
}
- }
+ }
protected abstract class AbstractEditingSupport extends EditingSupport {
private final CellEditor editor;
@@ -72,35 +68,34 @@ public class Snippet058CellNavigationIn34 {
public AbstractEditingSupport(TableViewer viewer) {
super(viewer);
this.editor = new TextCellEditor(viewer.getTable());
- }
+ }
public AbstractEditingSupport(TableViewer viewer, CellEditor editor) {
super(viewer);
this.editor = editor;
- }
+ }
- @Override
+ @Override
protected boolean canEdit(Object element) {
return true;
- }
+ }
- @Override
+ @Override
protected CellEditor getCellEditor(Object element) {
return editor;
- }
+ }
- @Override
+ @Override
protected void setValue(Object element, Object value) {
doSetValue(element, value);
getViewer().update(element, null);
- }
+ }
protected abstract void doSetValue(Object element, Object value);
}
public Snippet058CellNavigationIn34(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.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn column = null;
@@ -177,16 +172,14 @@ public class Snippet058CellNavigationIn34 {
@Override
public String getText(Object element) {
return ((Person) element).gender;
- }
+ }
});
- ComboBoxCellEditor editor = new ComboBoxCellEditor(v.getTable(),
- new String[] { "M", "F" });
+ ComboBoxCellEditor editor = new ComboBoxCellEditor(v.getTable(), new String[] { "M", "F" });
editor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION
| ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION
- | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION
- | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION);
+ | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION);
column.setEditingSupport(new AbstractEditingSupport(v, editor) {
@@ -195,7 +188,7 @@ public class Snippet058CellNavigationIn34 {
if (((Person) element).gender.equals("M"))
return Integer.valueOf(0);
return Integer.valueOf(1);
- }
+ }
@Override
protected void doSetValue(Object element, Object value) {
@@ -203,7 +196,7 @@ public class Snippet058CellNavigationIn34 {
((Person) element).gender = "M";
} else {
((Person) element).gender = "F";
- }
+ }
}
});
@@ -211,28 +204,24 @@ public class Snippet058CellNavigationIn34 {
CellNavigationStrategy naviStrat = new CellNavigationStrategy() {
@Override
- public ViewerCell findSelectedCell(ColumnViewer viewer,
- ViewerCell currentSelectedCell, Event event) {
- ViewerCell cell = super.findSelectedCell(viewer,
- currentSelectedCell, event);
+ public ViewerCell findSelectedCell(ColumnViewer viewer, ViewerCell currentSelectedCell, Event event) {
+ ViewerCell cell = super.findSelectedCell(viewer, currentSelectedCell, event);
if (cell != null) {
- v.getTable().showColumn(
- v.getTable().getColumn(cell.getColumnIndex()));
- }
+ v.getTable().showColumn(
+ v.getTable().getColumn(cell.getColumnIndex()));
+ }
return cell;
}
};
- TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(
- v, new FocusCellOwnerDrawHighlighter(v), naviStrat);
+ TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,
+ new FocusCellOwnerDrawHighlighter(v), naviStrat);
- ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
- v) {
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
@Override
- protected boolean isEditorActivationEvent(
- ColumnViewerEditorActivationEvent event) {
+ protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
@@ -240,40 +229,32 @@ public class Snippet058CellNavigationIn34 {
}
};
- int feature = ColumnViewerEditor.TABBING_HORIZONTAL
- | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
- | ColumnViewerEditor.TABBING_VERTICAL
- | ColumnViewerEditor.KEYBOARD_ACTIVATION;
+ int feature = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
+ | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION;
TableViewerEditor.create(v, focusCellManager, actSupport, feature);
- v.getColumnViewerEditor().addEditorActivationListener(
- new ColumnViewerEditorActivationListener() {
+ v.getColumnViewerEditor().addEditorActivationListener(new ColumnViewerEditorActivationListener() {
- @Override
- public void afterEditorActivated(
- ColumnViewerEditorActivationEvent event) {
- }
+ @Override
+ public void afterEditorActivated(ColumnViewerEditorActivationEvent event) {
+ }
- @Override
- public void afterEditorDeactivated(
- ColumnViewerEditorDeactivationEvent event) {
- }
+ @Override
+ public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
+ }
- @Override
- public void beforeEditorActivated(
- ColumnViewerEditorActivationEvent event) {
- ViewerCell cell = (ViewerCell) event.getSource();
- v.getTable().showColumn(
- v.getTable().getColumn(cell.getColumnIndex()));
- }
+ @Override
+ public void beforeEditorActivated(ColumnViewerEditorActivationEvent event) {
+ ViewerCell cell = (ViewerCell) event.getSource();
+ v.getTable().showColumn(v.getTable().getColumn(cell.getColumnIndex()));
+ }
- @Override
- public void beforeEditorDeactivated(
- ColumnViewerEditorDeactivationEvent event) {
- }
+ @Override
+ public void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
+ }
- });
+ });
Person[] model = createModel();
v.setInput(model);
@@ -291,14 +272,11 @@ public class Snippet058CellNavigationIn34 {
}
private Person[] createModel() {
- return new Person[] {
- new Person("Tom", "Schindl", "tom.schindl@bestsolution.at", "M"),
- new Person("Boris", "Bokowski", "Boris_Bokowski@ca.ibm.com",
- "M"),
+ return new Person[] { new Person("Tom", "Schindl", "tom.schindl@bestsolution.at", "M"),
+ new Person("Boris", "Bokowski", "Boris_Bokowski@ca.ibm.com", "M"),
new Person("Tod", "Creasey", "Tod_Creasey@ca.ibm.com", "M"),
new Person("Wayne", "Beaton", "wayne@eclipse.org", "M"),
- new Person("Jeanderson", "Candido", "jeandersonbc@gmail.com",
- "M"),
+ new Person("Jeanderson", "Candido", "jeandersonbc@gmail.com", "M"),
new Person("Lars", "Vogel", "lars.vogel@gmail.com", "M"),
new Person("Hendrik", "Still", "hendrik.still@vogella.com", "M") };
}
@@ -312,6 +290,7 @@ public class Snippet058CellNavigationIn34 {
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new Snippet058CellNavigationIn34(shell);
+ shell.setSize(300, 300);
shell.open();
while (!shell.isDisposed()) {
@@ -321,6 +300,6 @@ public class Snippet058CellNavigationIn34 {
display.dispose();
- }
+ }
-}
+ } \ No newline at end of file
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 4887f26d296..ba27f080c19 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
@@ -18,6 +18,7 @@ package org.eclipse.jface.snippets.viewers;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
@@ -66,7 +67,7 @@ public class Snippet063ComboViewer {
// Select the initial Element
if (model.size() > 0) {
- v.setSelection(new StructuredSelection(model.get(0)));
+ v.setSelection(new StructuredSelection(model.get(new Random().nextInt(model.size()))));
}
}
@@ -96,4 +97,4 @@ public class Snippet063ComboViewer {
}
-}
+} \ No newline at end of file
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java
index 455c09e028f..17064f36261 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet020CustomizedControlTooltips.java
@@ -181,7 +181,8 @@ public class Snippet020CustomizedControlTooltips {
layout.marginWidth=5;
comp.setLayout(layout);
Link l = new Link(comp,SWT.NONE);
- l.setText("This a custom tooltip you can: \n- pop up any control you want\n- define delays\n - ... \nGo and get Eclipse M4 from <a>http://www.eclipse.org</a>");
+ l.setText(
+ "This a custom tooltip you can: \n- pop up any control you want\n- define delays\n - ... \nGo and get Eclipse from <a>http://www.eclipse.org</a>");
l.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
l.addSelectionListener(new SelectionAdapter() {
@Override
@@ -252,4 +253,4 @@ public class Snippet020CustomizedControlTooltips {
display.dispose();
}
-}
+} \ No newline at end of file

Back to the top