summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorLars Vogel2013-07-22 05:49:38 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-09-09 15:34:18 (EDT)
commit6ed22368c998819037ea66c71a396f90d85487ce (patch)
tree05dd9eded3498173d9fb1465e7a994a8ab783862
parent9db76a062b421f3bc3540e3a9f0bc113e194f861 (diff)
downloadeclipse.platform.ui-6ed22368c998819037ea66c71a396f90d85487ce.zip
eclipse.platform.ui-6ed22368c998819037ea66c71a396f90d85487ce.tar.gz
eclipse.platform.ui-6ed22368c998819037ea66c71a396f90d85487ce.tar.bz2
Bug 413427 - JFace snippets cleanup, removes unnecessary imports andI20130909-2000refs/changes/36/14736/6
casts Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=413427 Change-Id: Id01952004578ea855c2bae6736ae18435397cac7 Signed-off-by: Lars Vogel <Lars.Vogel@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet060DialogWithURLImageButtons.java9
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java100
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java37
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java47
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet058CellNavigationIn34.java51
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java15
6 files changed, 132 insertions, 127 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet060DialogWithURLImageButtons.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet060DialogWithURLImageButtons.java
index a39da91..7968290 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet060DialogWithURLImageButtons.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet060DialogWithURLImageButtons.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Lars Vogel (lars.vogel@gmail.com) - Bug 413427
*******************************************************************************/
package org.eclipse.jface.snippets.dialogs;
@@ -25,7 +26,7 @@ import org.eclipse.swt.widgets.Shell;
/**
* A snippet to demonstrate a dialog with image buttons.
- *
+ *
*/
public class Snippet060DialogWithURLImageButtons {
private ImageRegistry registry;
@@ -58,9 +59,9 @@ public class Snippet060DialogWithURLImageButtons {
URL url;
try {
url = new URL(
- "http://www.eclipse.org/home/images/enterprise.gif");
+ "http://www.eclipse.org/home/images/enterprise.gif"); //$NON-NLS-N$
b.setImage(ImageDescriptor.createFromURL(url)
- .createImage()); //$NON-NLS-1$
+ .createImage());
} catch (MalformedURLException e) {
e.printStackTrace();
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java
index 7589284..59dc1e2 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet033CellEditorPerRowPre33.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Tom Schindl and others.
+ * Copyright (c) 2007 - 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Lars Vogel (lars.vogel@gmail.com) - Bug 413427
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -39,16 +40,15 @@ import org.eclipse.swt.widgets.TableItem;
/**
* Snippet to present editor different CellEditors within one column in 3.2
* for 3.3 and above please use the new EditingSupport class
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
+ *
*/
public class Snippet033CellEditorPerRowPre33 {
private class MyCellModifier implements ICellModifier {
-
+
private TableViewer viewer;
-
- private boolean enabled = true;
public void setViewer(TableViewer viewer) {
this.viewer = viewer;
@@ -56,7 +56,7 @@ public class Snippet033CellEditorPerRowPre33 {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object,
* java.lang.String)
*/
@@ -66,7 +66,7 @@ public class Snippet033CellEditorPerRowPre33 {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object,
* java.lang.String)
*/
@@ -82,29 +82,29 @@ public class Snippet033CellEditorPerRowPre33 {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object,
* java.lang.String, java.lang.Object)
*/
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
-
+
if( item.getData() instanceof MyModel3 ) {
((MyModel3) item.getData()).checked=((Boolean)value).booleanValue();
} else {
((MyModel) item.getData()).counter = Integer.parseInt(value
.toString());
}
-
+
viewer.update(item.getData(), null);
}
}
-
+
private class MyContentProvider implements IStructuredContentProvider {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
@@ -113,7 +113,7 @@ public class Snippet033CellEditorPerRowPre33 {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
@@ -122,7 +122,7 @@ public class Snippet033CellEditorPerRowPre33 {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
@@ -154,10 +154,10 @@ public class Snippet033CellEditorPerRowPre33 {
return "Special Item " + this.counter;
}
}
-
+
public class MyModel3 extends MyModel {
public boolean checked;
-
+
public MyModel3(int counter) {
super(counter);
}
@@ -166,20 +166,20 @@ public class Snippet033CellEditorPerRowPre33 {
return "Special Item " + this.counter;
}
}
-
-
+
+
public class DelegatingEditor extends CellEditor {
-
- private StructuredViewer viewer;
-
- private CellEditor delegatingTextEditor;
-
- private CellEditor delegatingDropDownEditor;
-
+
+ private final StructuredViewer viewer;
+
+ private final CellEditor delegatingTextEditor;
+
+ private final CellEditor delegatingDropDownEditor;
+
private CellEditor activeEditor;
-
- private CellEditor delegatingCheckBoxEditor;
-
+
+ private final CellEditor delegatingCheckBoxEditor;
+
private class DelegatingListener implements ICellEditorListener {
public void applyEditorValue() {
@@ -194,29 +194,29 @@ public class Snippet033CellEditorPerRowPre33 {
boolean newValidState) {
fireEditorValueChanged(oldValidState, newValidState);
}
-
+
}
-
+
public DelegatingEditor(StructuredViewer viewer, Composite parent) {
super(parent);
this.viewer = viewer;
DelegatingListener l = new DelegatingListener();
this.delegatingTextEditor = new TextCellEditor(parent);
this.delegatingTextEditor.addListener(l);
-
+
String[] elements = new String[10];
-
+
for (int i = 0; i < 10; i++) {
elements[i] = i+"";
}
-
+
this.delegatingDropDownEditor = new ComboBoxCellEditor(parent,elements);
this.delegatingDropDownEditor.addListener(l);
-
+
this.delegatingCheckBoxEditor = new CheckboxCellEditor(parent);
this.delegatingCheckBoxEditor.addListener(l);
}
-
+
protected Control createControl(Composite parent) {
return null;
}
@@ -236,7 +236,7 @@ public class Snippet033CellEditorPerRowPre33 {
}
protected void doSetValue(Object value) {
-
+
if( ((IStructuredSelection)this.viewer.getSelection()).getFirstElement() instanceof MyModel3 ) {
activeEditor = delegatingCheckBoxEditor;
} else if( ((IStructuredSelection)this.viewer.getSelection()).getFirstElement() instanceof MyModel2 ) {
@@ -244,10 +244,10 @@ public class Snippet033CellEditorPerRowPre33 {
} else {
activeEditor = delegatingTextEditor;
}
-
+
activeEditor.setValue(value);
}
-
+
public void deactivate() {
if( activeEditor != null ) {
Control control = activeEditor.getControl();
@@ -256,23 +256,23 @@ public class Snippet033CellEditorPerRowPre33 {
}
}
}
-
+
public void dispose() {
-
+
}
-
+
public Control getControl() {
return activeEditor.getControl();
}
}
-
+
public Snippet033CellEditorPerRowPre33(Shell shell) {
final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
final MyCellModifier modifier = new MyCellModifier();
-
+
final TableViewer v = new TableViewer(table);
modifier.setViewer(v);
-
+
TableColumn column = new TableColumn(table, SWT.NONE);
column.setWidth(200);
@@ -295,20 +295,20 @@ public class Snippet033CellEditorPerRowPre33 {
} else {
return JFaceResources.getImage("IMG_2");
}
-
+
}
return super.getImage(element);
}
-
+
}
-
+
private MyModel[] createModel() {
MyModel[] elements = new MyModel[30];
for (int i = 0; i < 10; i++) {
elements[i] = new MyModel3(i);
}
-
+
for (int i = 0; i < 10; i++) {
elements[i+10] = new MyModel(i);
}
@@ -316,7 +316,7 @@ public class Snippet033CellEditorPerRowPre33 {
for (int i = 0; i < 10; i++) {
elements[i+20] = new MyModel2(i);
}
-
+
return elements;
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java
index 09cd55d..ec786f4 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet049StyledCellLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Michael Krkoska - initial API and implementation (bug 188333)
+ * Lars Vogel (lars.vogel@gmail.com) - Bug 413427
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -19,10 +20,10 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
@@ -43,8 +44,8 @@ import org.eclipse.swt.widgets.Shell;
*/
public class Snippet049StyledCellLabelProvider {
-
-
+
+
private static final int SHELL_WIDTH= 400;
private static final Display DISPLAY= Display.getDefault();
@@ -52,7 +53,7 @@ public class Snippet049StyledCellLabelProvider {
public static void main(String[] args) {
JFaceResources.getColorRegistry().put(JFacePreferences.COUNTER_COLOR, new RGB(0,127,174));
-
+
Shell shell= new Shell(DISPLAY, SWT.CLOSE | SWT.RESIZE);
shell.setSize(SHELL_WIDTH, 400);
shell.setLayout(new GridLayout(1, false));
@@ -60,7 +61,7 @@ public class Snippet049StyledCellLabelProvider {
Snippet049StyledCellLabelProvider example= new Snippet049StyledCellLabelProvider();
Control composite= example.createPartControl(shell);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
-
+
shell.open();
while (!shell.isDisposed()) {
@@ -82,7 +83,7 @@ public class Snippet049StyledCellLabelProvider {
Label label= new Label(composite, SWT.NONE);
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
label.setText("Viewer with a StyledCellLabelProvider:"); //$NON-NLS-1$
-
+
final TableViewer tableViewer= new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
// Multi-font support only works in JFace 3.5 and above (specifically, 3.5 M4 and above).
@@ -92,7 +93,7 @@ public class Snippet049StyledCellLabelProvider {
Font boldFont = new Font(Display.getCurrent(), boldFontData);
ExampleLabelProvider labelProvider= new ExampleLabelProvider(boldFont);
FileSystemContentProvider contentProvider= new FileSystemContentProvider();
-
+
tableViewer.setContentProvider(contentProvider);
tableViewer.setLabelProvider(labelProvider);
@@ -102,7 +103,7 @@ public class Snippet049StyledCellLabelProvider {
return composite;
}
-
+
private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) {
FontData[] styleData = new FontData[originalData.length];
for (int i = 0; i < styleData.length; i++) {
@@ -111,15 +112,15 @@ public class Snippet049StyledCellLabelProvider {
}
return styleData;
}
-
+
private static class ExampleLabelProvider extends StyledCellLabelProvider {
private static int IMAGE_SIZE= 16;
private static final Image IMAGE1= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_WARNING).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
private static final Image IMAGE2= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_ERROR).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
- private final Styler fBoldStyler;
-
+ private final Styler fBoldStyler;
+
public ExampleLabelProvider(final Font boldFont) {
fBoldStyler= new Styler() {
public void applyStyles(TextStyle textStyle) {
@@ -127,23 +128,23 @@ public class Snippet049StyledCellLabelProvider {
}
};
}
-
+
public void update(ViewerCell cell) {
Object element= cell.getElement();
-
+
if (element instanceof File) {
File file= (File) element;
-
+
// Multi-font support only works in JFace 3.5 and above (specifically, 3.5 M4 and above).
// With JFace 3.4, the font information (bold in this example) will be ignored.
Styler style= file.isDirectory() ? fBoldStyler: null;
StyledString styledString= new StyledString(file.getName(), style);
String decoration = MessageFormat.format(" ({0} bytes)", new Object[] { new Long(file.length()) }); //$NON-NLS-1$
styledString.append(decoration, StyledString.COUNTER_STYLER);
-
+
cell.setText(styledString.toString());
cell.setStyleRanges(styledString.getStyleRanges());
-
+
if (file.isDirectory()) {
cell.setImage(IMAGE1);
} else {
@@ -155,7 +156,7 @@ public class Snippet049StyledCellLabelProvider {
super.update(cell);
}
-
+
protected void measure(Event event, Object element) {
super.measure(event, element);
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java
index 35e8f13..8f4f2ba 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet050DelegatingStyledCellLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Michael Krkoska - initial API and implementation (bug 188333)
+ * Lars Vogel (lars.vogel@gmail.com) - Bug 413427
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -22,12 +23,12 @@ import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -46,17 +47,17 @@ import org.eclipse.swt.widgets.Shell;
* Using a {@link DelegatingStyledCellLabelProvider} on tree viewer with multiple columns. Compare the result with a native tree viewer.
*/
public class Snippet050DelegatingStyledCellLabelProvider {
-
-
+
+
private static final int SHELL_WIDTH= 640;
private static final Display DISPLAY= Display.getDefault();
public static void main(String[] args) {
-
+
JFaceResources.getColorRegistry().put(JFacePreferences.COUNTER_COLOR, new RGB(0,127,174));
-
-
+
+
Shell shell= new Shell(DISPLAY, SWT.CLOSE | SWT.RESIZE);
shell.setSize(SHELL_WIDTH, 300);
@@ -82,7 +83,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
Composite composite= new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
composite.setLayout(new GridLayout(2, true));
-
+
final DelegatingStyledCellLabelProvider styledCellLP1= new DelegatingStyledCellLabelProvider(new NameAndSizeLabelProvider());
final DelegatingStyledCellLabelProvider styledCellLP2= new DelegatingStyledCellLabelProvider(new ModifiedDateLabelProvider());
final ColumnViewer ownerDrawViewer= createViewer("Owner draw viewer:", composite, styledCellLP1, styledCellLP2); //$NON-NLS-1$
@@ -94,8 +95,8 @@ public class Snippet050DelegatingStyledCellLabelProvider {
Composite buttons= new Composite(parent, SWT.NONE);
buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
buttons.setLayout(new GridLayout(3, false));
-
-
+
+
Button button1= new Button(buttons, SWT.PUSH);
button1.setText("Refresh Viewers"); //$NON-NLS-1$
button1.addSelectionListener(new SelectionAdapter() {
@@ -105,7 +106,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
normalViewer.refresh();
}
});
-
+
final Button button2= new Button(buttons, SWT.CHECK);
button2.setText("Owner draw on column 1"); //$NON-NLS-1$
button2.setSelection(true);
@@ -117,7 +118,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
ownerDrawViewer.refresh();
}
});
-
+
final Button button3= new Button(buttons, SWT.CHECK);
button3.setText("Owner draw on column 2"); //$NON-NLS-1$
button3.setSelection(true);
@@ -130,7 +131,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
}
});
}
-
+
private static class FileSystemRoot {
public File[] getRoots() {
return File.listRoots();
@@ -150,7 +151,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
TreeViewer treeViewer= new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.setContentProvider(new FileSystemContentProvider());
-
+
TreeViewerColumn tvc1 = new TreeViewerColumn(treeViewer, SWT.NONE);
tvc1.getColumn().setText("Name"); //$NON-NLS-1$
tvc1.getColumn().setWidth(200);
@@ -160,7 +161,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
tvc2.getColumn().setText("Date Modified"); //$NON-NLS-1$
tvc2.getColumn().setWidth(200);
tvc2.setLabelProvider(labelProvider2);
-
+
GridData data= new GridData(GridData.FILL, GridData.FILL, true, true);
treeViewer.getControl().setLayoutData(data);
@@ -173,7 +174,7 @@ public class Snippet050DelegatingStyledCellLabelProvider {
* A simple label provider
*/
private static class NameAndSizeLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {
-
+
private static int IMAGE_SIZE= 16;
private static final Image IMAGE1= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_WARNING).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
private static final Image IMAGE2= new Image(DISPLAY, DISPLAY.getSystemImage(SWT.ICON_ERROR).getImageData().scaledTo(IMAGE_SIZE, IMAGE_SIZE));
@@ -207,33 +208,33 @@ public class Snippet050DelegatingStyledCellLabelProvider {
String decoration= MessageFormat.format(" ({0} bytes)", new Object[] { new Long(file.length()) }); //$NON-NLS-1$
styledString.append(decoration, StyledString.COUNTER_STYLER);
}
- }
+ }
return styledString;
}
}
-
+
private static class ModifiedDateLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider {
public String getText(Object element) {
return getStyledText(element).toString();
}
-
+
public StyledString getStyledText(Object element) {
StyledString styledString= new StyledString();
if (element instanceof File) {
File file= (File) element;
-
+
String date= DateFormat.getDateInstance().format(new Date(file.lastModified()));
styledString.append(date);
-
+
styledString.append(' ');
-
+
String time = DateFormat.getTimeInstance(3).format(new Date(file.lastModified()));
styledString.append(time, StyledString.COUNTER_STYLER);
}
return styledString;
}
}
-
+
private static class FileSystemContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object element) {
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 df7e1f1..ad220d2 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Niels Lippke - initial API and implementation
+ * Lars Vogel (lars.vogel@gmail.com) - Bug 413427
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -40,9 +41,9 @@ 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>
- *
+ *
*/
public class Snippet058CellNavigationIn34 {
@@ -76,13 +77,13 @@ public class Snippet058CellNavigationIn34 {
}
protected abstract class AbstractEditingSupport extends EditingSupport {
- private CellEditor editor;
+ private final CellEditor editor;
public AbstractEditingSupport(TableViewer viewer) {
super(viewer);
this.editor = new TextCellEditor(viewer.getTable());
}
-
+
public AbstractEditingSupport(TableViewer viewer, CellEditor editor) {
super(viewer);
this.editor = editor;
@@ -167,11 +168,11 @@ public class Snippet058CellNavigationIn34 {
});
-
+
column.setEditingSupport(new AbstractEditingSupport(v) {
- protected Object getValue(Object element) {
- return ((Person) element).email;
+ protected Object getValue(Object element) {
+ return ((Person) element).email;
}
protected void doSetValue(Object element, Object value) {
@@ -192,13 +193,13 @@ public class Snippet058CellNavigationIn34 {
}
});
-
- ComboBoxCellEditor editor = new ComboBoxCellEditor(((TableViewer) v).getTable(), new String[] {"M","F"});
- editor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION |
+
+ 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);
-
+
column.setEditingSupport(new AbstractEditingSupport(v, editor) {
protected Object getValue(Object element) {
@@ -216,24 +217,24 @@ public class Snippet058CellNavigationIn34 {
}
});
-
+
CellNavigationStrategy naviStrat = new CellNavigationStrategy() {
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()));
}
-
+
return cell;
}
-
+
};
-
+
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v),naviStrat);
-
+
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
@@ -243,21 +244,21 @@ public class Snippet058CellNavigationIn34 {
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
-
+
TableViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
-
+
v.getColumnViewerEditor().addEditorActivationListener(new ColumnViewerEditorActivationListener() {
public void afterEditorActivated(
ColumnViewerEditorActivationEvent event) {
-
+
}
public void afterEditorDeactivated(
ColumnViewerEditorDeactivationEvent event) {
-
+
}
public void beforeEditorActivated(
@@ -268,11 +269,11 @@ public class Snippet058CellNavigationIn34 {
public void beforeEditorDeactivated(
ColumnViewerEditorDeactivationEvent event) {
-
+
}
-
+
});
-
+
Person[] model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java
index e9b1630..f4c9198 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet059CellNavigationIn33.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Tom Schindl and others.
+ * Copyright (c) 2006, 2013 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Lars Vogel (lars.vogel@gmail.com) - Bug 413427
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
@@ -18,6 +19,7 @@ import java.util.List;
import org.eclipse.jface.viewers.AbstractTableViewer;
import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CellEditor.LayoutData;
import org.eclipse.jface.viewers.CellNavigationStrategy;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
@@ -39,7 +41,6 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.viewers.ViewerColumn;
import org.eclipse.jface.viewers.ViewerRow;
-import org.eclipse.jface.viewers.CellEditor.LayoutData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
@@ -98,7 +99,7 @@ public class Snippet059CellNavigationIn33 {
}
protected abstract class AbstractEditingSupport extends EditingSupport {
- private CellEditor editor;
+ private final CellEditor editor;
public AbstractEditingSupport(TableViewer viewer) {
super(viewer);
@@ -214,7 +215,7 @@ public class Snippet059CellNavigationIn33 {
});
- ComboBoxCellEditor editor = new ComboBoxCellEditor(((TableViewer) v)
+ ComboBoxCellEditor editor = new ComboBoxCellEditor(v
.getTable(), new String[] { "M", "F" });
column.setEditingSupport(new AbstractEditingSupport(v, editor) {
@@ -404,11 +405,11 @@ public class Snippet059CellNavigationIn33 {
/**
* This viewer's table editor.
*/
- private TableEditor tableEditor;
+ private final TableEditor tableEditor;
- private TableViewerFocusCellManager focusCellManager;
+ private final TableViewerFocusCellManager focusCellManager;
- private int feature;
+ private final int feature;
/**
* @param viewer