aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-05-06 12:20:19 (EDT)
committerLars Vogel2014-05-06 15:41:08 (EDT)
commit8019a4017d46e103df55d599611a943935c056f2 (patch)
tree407e9b979e04f3ee19b3dc559620b9e28cca16ae
parentd8eeae022b7e7ada61ac7c54a61a837816193fae (diff)
downloadeclipse.platform.ui-8019a4017d46e103df55d599611a943935c056f2.zip
eclipse.platform.ui-8019a4017d46e103df55d599611a943935c056f2.tar.gz
eclipse.platform.ui-8019a4017d46e103df55d599611a943935c056f2.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanupI20140506-2000refs/changes/62/26062/3
Removed some magic numbers and performed minor refactorings to breakup long statements into sequences of smaller statements. Change-Id: I691e47dadfd1eb1f79e6ee1c8ab1d311964005fb Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/AbstractCellCursor.java54
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java66
2 files changed, 51 insertions, 69 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/AbstractCellCursor.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/AbstractCellCursor.java
index 466037d..44f92ce 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/AbstractCellCursor.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/AbstractCellCursor.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - 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;
@@ -29,12 +30,10 @@ import org.eclipse.swt.widgets.Listener;
*
*/
public abstract class AbstractCellCursor extends Canvas {
- private ViewerCell[] cells = new ViewerCell[0];
+ private ViewerCell[] cells = new ViewerCell[0];
private ColumnViewer viewer;
-
private int activationTime = 0;
-
private boolean inFocusRequest = false;
/**
@@ -42,10 +41,21 @@ public abstract class AbstractCellCursor extends Canvas {
* @param style
*/
public AbstractCellCursor(ColumnViewer viewer, int style) {
- super((Composite) viewer.getControl(),style);
+ super((Composite) viewer.getControl(), style);
this.viewer = viewer;
- Listener l = new Listener() {
+ Listener listener = createListener();
+ int[] eventsToListen = { SWT.Paint, SWT.KeyDown, SWT.MouseDown,
+ SWT.MouseDoubleClick };
+
+ for (int event : eventsToListen) {
+ addListener(event, listener);
+ }
+ getParent().addListener(SWT.FocusIn, listener);
+ }
+
+ private Listener createListener() {
+ return new Listener() {
@Override
public void handleEvent(Event event) {
@@ -53,46 +63,48 @@ public abstract class AbstractCellCursor extends Canvas {
case SWT.Paint:
paint(event);
break;
+
case SWT.KeyDown:
getParent().notifyListeners(SWT.KeyDown, event);
ArrayList<Object> list = new ArrayList<Object>();
- for( int i = 0; i < cells.length; i++ ) {
- list.add(cells[i].getElement());
+ for (ViewerCell cell : cells) {
+ list.add(cell.getElement());
}
- AbstractCellCursor.this.viewer.setSelection(new StructuredSelection(list));
-
+ AbstractCellCursor.this.viewer
+ .setSelection(new StructuredSelection(list));
break;
+
case SWT.MouseDown:
- if( event.time < activationTime ) {
+ if (event.time < activationTime) {
Event cEvent = copyEvent(event);
cEvent.type = SWT.MouseDoubleClick;
- getParent().notifyListeners(SWT.MouseDoubleClick, cEvent);
+ getParent().notifyListeners(SWT.MouseDoubleClick,
+ cEvent);
} else {
- getParent().notifyListeners(SWT.MouseDown, copyEvent(event));
+ getParent().notifyListeners(SWT.MouseDown,
+ copyEvent(event));
}
break;
+
case SWT.MouseDoubleClick:
- getParent().notifyListeners(SWT.MouseDoubleClick, copyEvent(event));
+ getParent().notifyListeners(SWT.MouseDoubleClick,
+ copyEvent(event));
break;
+
case SWT.FocusIn:
- if( isVisible() ) {
+ if (isVisible()) {
inFocusRequest = true;
- if( ! inFocusRequest ) {
+ if (!inFocusRequest) {
forceFocus();
}
inFocusRequest = false;
}
+
default:
break;
}
}
};
-
- addListener(SWT.Paint, l);
- addListener(SWT.KeyDown, l);
- addListener(SWT.MouseDown, l);
- addListener(SWT.MouseDoubleClick, l);
- getParent().addListener(SWT.FocusIn,l);
}
/**
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java
index f1f831c..c72b0d8 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/viewers/Snippet035TableCursorCellHighlighter.java
@@ -8,17 +8,18 @@
* Contributors:
* Tom Schindl - initial API and implementation
* Lars Vogel (lars.vogel@gmail.com) - Bug 413427
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.viewers;
import org.eclipse.jface.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 +28,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;
@@ -44,41 +44,6 @@ import org.eclipse.swt.widgets.TableColumn;
*/
public class Snippet035TableCursorCellHighlighter {
- 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 {
@@ -136,11 +101,13 @@ public class Snippet035TableCursorCellHighlighter {
}
public Snippet035TableCursorCellHighlighter(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER|SWT.HIDE_SELECTION|SWT.FULL_SELECTION);
+ int style = SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION;
+ final TableViewer v = new TableViewer(shell, style);
v.setLabelProvider(new MyLabelProvider());
- v.setContentProvider(new MyContentProvider());
+ v.setContentProvider(ArrayContentProvider.getInstance());
- v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()), new TextCellEditor(v.getTable()) });
+ v.setCellEditors(new CellEditor[] { new TextCellEditor(v.getTable()),
+ new TextCellEditor(v.getTable()) });
v.setCellModifier(new ICellModifier() {
@Override
@@ -160,10 +127,13 @@ public class Snippet035TableCursorCellHighlighter {
});
- v.setColumnProperties(new String[] {"1","2"});
+ v.setColumnProperties(new String[] { "1", "2" });
+
+ TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(
+ v, new CursorCellHighlighter(v, new TableCursor(v)));
+ ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
+ v) {
- TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(v,new CursorCellHighlighter(v,new TableCursor(v)));
- ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {
@Override
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
@@ -174,10 +144,12 @@ public class Snippet035TableCursorCellHighlighter {
}
};
- TableViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
+ int features = 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, features);
TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
column.setWidth(200);
@@ -196,10 +168,9 @@ public class Snippet035TableCursorCellHighlighter {
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < elements.length; i++) {
elements[i] = new MyModel(i);
}
-
return elements;
}
@@ -218,7 +189,6 @@ public class Snippet035TableCursorCellHighlighter {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
}