aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-05-06 23:27:35 (EDT)
committerLars Vogel2014-05-08 05:25:34 (EDT)
commite2c23633b1f8ebcd26906fa9685c417d32e6511e (patch)
tree2a2a17661724991224569fa1e354440e3a230755
parent9ad2c3d502297ea40ba62f339111f786970e29b8 (diff)
downloadeclipse.platform.ui-e2c23633b1f8ebcd26906fa9685c417d32e6511e.zip
eclipse.platform.ui-e2c23633b1f8ebcd26906fa9685c417d32e6511e.tar.gz
eclipse.platform.ui-e2c23633b1f8ebcd26906fa9685c417d32e6511e.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanuprefs/changes/85/26085/3
Removed unnecessary comments and nested classes. Some refactorings to avoid duplicated code. Change-Id: Ifa92c297f0f2f92eaad725785129f213d8d1b583 Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet031TableStaticTooltip.java154
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/wizard/Snippet047WizardWithLongRunningOperation.java45
2 files changed, 88 insertions, 111 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet031TableStaticTooltip.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet031TableStaticTooltip.java
index b3ba771..7e43021 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet031TableStaticTooltip.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/window/Snippet031TableStaticTooltip.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,15 +7,18 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.window;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.DefaultToolTip;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
@@ -31,45 +34,13 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* Example how one can create a tooltip which is not recreated for every table
* cell
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet031TableStaticTooltip {
private static Image[] images;
- private class MyContentProvider implements IStructuredContentProvider {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return (MyModel[]) inputElement;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- public void dispose() {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- }
-
public class MyModel {
public int counter;
@@ -77,6 +48,7 @@ public class Snippet031TableStaticTooltip {
this.counter = counter;
}
+ @Override
public String toString() {
return "Item " + this.counter;
}
@@ -85,67 +57,35 @@ public class Snippet031TableStaticTooltip {
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 Snippet031TableStaticTooltip(Shell shell) {
- final TableViewer v = new TableViewer(shell, SWT.BORDER
+ final TableViewer viewer = new TableViewer(shell, SWT.BORDER
| SWT.FULL_SELECTION);
- v.setLabelProvider(new MyLabelProvider());
- v.setContentProvider(new MyContentProvider());
-
- 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);
- v.getTable().setLinesVisible(true);
- v.getTable().setHeaderVisible(true);
-
- DefaultToolTip toolTip = new DefaultToolTip(v.getControl(),
- ToolTip.NO_RECREATE, false);
- toolTip.setText("Hello World\nHello World");
- toolTip.setBackgroundColor(v.getTable().getDisplay().getSystemColor(
- SWT.COLOR_RED));
- toolTip.setShift(new Point(10, 5));
- }
- private MyModel[] createModel() {
- MyModel[] elements = new MyModel[10];
+ viewer.setLabelProvider(new MyLabelProvider());
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
- for (int i = 0; i < 10; i++) {
- elements[i] = new MyModel(i);
- }
+ createColumnFor(viewer, "Column 1");
+ createColumnFor(viewer, "Column 2");
- return elements;
+ viewer.setInput(createModel());
+ viewer.getTable().setLinesVisible(true);
+ viewer.getTable().setHeaderVisible(true);
+ createToolTipFor(viewer);
}
/**
@@ -154,11 +94,10 @@ public class Snippet031TableStaticTooltip {
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);
+ images = new Image[] { createImage(display, 0, 0, 255),
+ createImage(display, 0, 255, 255),
+ createImage(display, 0, 255, 0),
+ createImage(display, 255, 0, 255) };
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
@@ -169,13 +108,50 @@ public class Snippet031TableStaticTooltip {
if (!display.readAndDispatch())
display.sleep();
}
-
- for (int i = 0; i < images.length; i++) {
- images[i].dispose();
+ for (Image img : images) {
+ img.dispose();
}
-
display.dispose();
}
+ 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;
+ }
+
+ private void createToolTipFor(final TableViewer viewer) {
+ DefaultToolTip toolTip = new DefaultToolTip(viewer.getControl(),
+ ToolTip.NO_RECREATE, false);
+
+ toolTip.setText("Hello World\nHello World");
+ toolTip.setBackgroundColor(viewer.getTable().getDisplay()
+ .getSystemColor(SWT.COLOR_RED));
+
+ toolTip.setShift(new Point(10, 5));
+ }
+
+ private TableColumn createColumnFor(TableViewer viewer, String label) {
+ TableColumn column = new TableColumn(viewer.getTable(), SWT.NONE);
+ column.setWidth(200);
+ column.setText(label);
+ return column;
+ }
+
+ private List<MyModel> createModel() {
+ List<MyModel> elements = new ArrayList<MyModel>();
+
+ for (int i = 0; i < 10; i++) {
+ elements.add(new MyModel(i));
+ }
+ return elements;
+ }
+
}
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/wizard/Snippet047WizardWithLongRunningOperation.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/wizard/Snippet047WizardWithLongRunningOperation.java
index 20b649c..927a70e 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/wizard/Snippet047WizardWithLongRunningOperation.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/wizard/Snippet047WizardWithLongRunningOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 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
@@ -7,10 +7,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.wizard;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -49,33 +51,25 @@ public class Snippet047WizardWithLongRunningOperation {
this.loadingType = loadingType;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#addPages()
- */
+ @Override
public void addPages() {
addPage(new MyWizardPage("Standard Page"));
addPage(new MyWizardPageThread("Thread Page", loadingType));
}
+ @Override
public boolean performFinish() {
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#canFinish()
- */
+ @Override
public boolean canFinish() {
IWizardPage[] pages = getPages();
- for (int i = 0; i < pages.length; i++) {
- if (!pages[i].isPageComplete()) {
+ for (IWizardPage page : pages) {
+ if (!page.isPageComplete()) {
return false;
}
}
-
return true;
}
@@ -88,6 +82,7 @@ public class Snippet047WizardWithLongRunningOperation {
setTitle(pageName);
}
+ @Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
@@ -105,6 +100,7 @@ public class Snippet047WizardWithLongRunningOperation {
setTitle(pageName);
}
+ @Override
public void createControl(final Composite parent) {
final Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout(1, false));
@@ -114,6 +110,7 @@ public class Snippet047WizardWithLongRunningOperation {
v.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
v.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
public void selectionChanged(SelectionChangedEvent event) {
getWizard().getContainer().updateButtons();
}
@@ -139,21 +136,21 @@ public class Snippet047WizardWithLongRunningOperation {
Thread t = new Thread() {
+ @Override
public void run() {
+ final List<MyModel> ms = new ArrayList<MyModel>();
if (loadingType == 1) {
try {
Thread.sleep(10000);
- final ArrayList ms = new ArrayList();
for (int i = 0; i < 10; i++) {
ms.add(new MyModel(i));
}
-
if (v.getTable().isDisposed()) {
return;
}
-
parent.getDisplay().asyncExec(new Runnable() {
+ @Override
public void run() {
v.setInput(ms);
((GridData) barContainer.getLayoutData()).exclude = true;
@@ -162,13 +159,13 @@ public class Snippet047WizardWithLongRunningOperation {
});
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
+
} else {
- final ArrayList ms = new ArrayList();
parent.getDisplay().syncExec(new Runnable() {
+ @Override
public void run() {
v.setInput(ms);
}
@@ -182,6 +179,7 @@ public class Snippet047WizardWithLongRunningOperation {
}
parent.getDisplay().asyncExec(new Runnable() {
+ @Override
public void run() {
MyModel tmp = new MyModel(j);
v.add(tmp);
@@ -193,13 +191,13 @@ public class Snippet047WizardWithLongRunningOperation {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
parent.getDisplay().asyncExec(new Runnable() {
+ @Override
public void run() {
((GridData) barContainer.getLayoutData()).exclude = true;
comp.layout(true);
@@ -210,6 +208,7 @@ public class Snippet047WizardWithLongRunningOperation {
parent.getDisplay().syncExec(new Runnable() {
+ @Override
public void run() {
loading = false;
getWizard().getContainer().updateButtons();
@@ -219,10 +218,10 @@ public class Snippet047WizardWithLongRunningOperation {
}
};
-
t.start();
}
+ @Override
public boolean isPageComplete() {
return !loading && !v.getSelection().isEmpty();
}
@@ -236,6 +235,7 @@ public class Snippet047WizardWithLongRunningOperation {
this.index = index;
}
+ @Override
public String toString() {
return "Item-" + index;
}
@@ -251,6 +251,7 @@ public class Snippet047WizardWithLongRunningOperation {
b.setText("Load in one Chunk");
b.addSelectionListener(new SelectionAdapter() {
+ @Override
public void widgetSelected(SelectionEvent e) {
WizardDialog dialog = new WizardDialog(shell, new MyWizard(1));
dialog.open();
@@ -262,6 +263,7 @@ public class Snippet047WizardWithLongRunningOperation {
b.setText("Load Item by Item");
b.addSelectionListener(new SelectionAdapter() {
+ @Override
public void widgetSelected(SelectionEvent e) {
WizardDialog dialog = new WizardDialog(shell, new MyWizard(2));
dialog.open();
@@ -275,7 +277,6 @@ public class Snippet047WizardWithLongRunningOperation {
if (!display.readAndDispatch())
display.sleep();
}
-
display.dispose();
}
}