aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-04-29 17:35:35 (EDT)
committerLars Vogel2014-05-06 00:34:19 (EDT)
commitff0c4061d5e4ca4cf9a0cd02f8beb55c25060f67 (patch)
tree15ec2e7e9d0868ea4c3eb7b567811b4fde852ab1
parent97cd8edf53792b5e6142ae90b93ed85b195259ab (diff)
downloadeclipse.platform.ui-ff0c4061d5e4ca4cf9a0cd02f8beb55c25060f67.zip
eclipse.platform.ui-ff0c4061d5e4ca4cf9a0cd02f8beb55c25060f67.tar.gz
eclipse.platform.ui-ff0c4061d5e4ca4cf9a0cd02f8beb55c25060f67.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanuprefs/changes/59/25759/5
Removed warnings and performed some refactorings to make the code easier to understand. Change-Id: I696ae710bedfaa17128b9b14bd192074bd595601 Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java19
-rwxr-xr-xexamples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet016TableLayout.java53
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet027TreeLayout.java80
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/resources/Snippet057FileImageDescriptors.java39
4 files changed, 81 insertions, 110 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java
index e6eb0d6..937dbb8 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 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,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Jeanderson Candidi <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.dialogs;
@@ -24,7 +25,7 @@ public class Snippet058VistaProgressBars {
/**
* Open a progress monitor dialog and switch the blocking.
- *
+ *
* @param args
*/
public static void main(String[] args) {
@@ -35,11 +36,8 @@ public class Snippet058VistaProgressBars {
try {
dialog.run(true, true, new IRunnableWithProgress() {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
- */
+
+ @Override
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
@@ -71,11 +69,8 @@ public class Snippet058VistaProgressBars {
private static void spin(final Display display) {
display.syncExec(new Runnable() {
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Runnable#run()
- */
+
+ @Override
public void run() {
long endTime = System.currentTimeMillis() + 1000;
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet016TableLayout.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet016TableLayout.java
index 9be6c21..d1d90e7 100755
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet016TableLayout.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet016TableLayout.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Tom Schindl and others.
+ * Copyright (c) 2006, 2014 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,11 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.layout;
-
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -30,37 +30,24 @@ import org.eclipse.swt.widgets.TableColumn;
/**
* A simple TableViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 3.3M3
*/
public class Snippet016TableLayout {
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) {
}
@@ -70,10 +57,12 @@ public class Snippet016TableLayout {
private class MyLabelProvider extends LabelProvider implements
ITableLabelProvider {
+ @Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
+ @Override
public String getColumnText(Object element, int columnIndex) {
return columnIndex + " - " + element;
}
@@ -87,6 +76,7 @@ public class Snippet016TableLayout {
this.counter = counter;
}
+ @Override
public String toString() {
return "Item " + this.counter;
}
@@ -100,22 +90,25 @@ public class Snippet016TableLayout {
TableColumnLayout ad = new TableColumnLayout();
comp.setLayout(ad);
-
- TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
- column.setText("Column 1");
- column.setMoveable(true);
- ad.setColumnData(column, new ColumnWeightData(90, 290));
- column = new TableColumn(v.getTable(), SWT.NONE);
- column.setText("Column 2");
- column.setMoveable(true);
- ad.setColumnData(column, new ColumnWeightData(10, 200));
+ TableColumn column1 = createTableColumn(v.getTable(), "Column 1");
+ TableColumn column2 = createTableColumn(v.getTable(), "Column 2");
+
+ ad.setColumnData(column1, new ColumnWeightData(90, 290));
+ ad.setColumnData(column2, new ColumnWeightData(10, 200));
MyModel[] model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
}
+ private TableColumn createTableColumn(Table table, String textColumn) {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(textColumn);
+ column.setMoveable(true);
+ return column;
+ }
+
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];
@@ -132,9 +125,9 @@ public class Snippet016TableLayout {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
- //shell.setSize(400, 150);
+ // shell.setSize(400, 150);
shell.setLayout(new FillLayout());
-
+
new Snippet016TableLayout(shell);
shell.open();
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet027TreeLayout.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet027TreeLayout.java
index e58705b..e4f73fc 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet027TreeLayout.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/layout/Snippet027TreeLayout.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2014 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.layout;
@@ -30,59 +31,39 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
/**
* A simple TreeViewer to demonstrate usage
- *
+ *
* @author Tom Schindl <tom.schindl@bestsolution.at>
- *
+ *
*/
public class Snippet027TreeLayout {
private class MyContentProvider implements ITreeContentProvider {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
+ @Override
public Object[] getElements(Object inputElement) {
return ((MyModel) inputElement).child.toArray();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
+ @Override
public void dispose() {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- */
+ @Override
public Object[] getChildren(Object parentElement) {
return getElements(parentElement);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
+ @Override
public Object getParent(Object element) {
if (element == null) {
return null;
@@ -91,11 +72,7 @@ public class Snippet027TreeLayout {
return ((MyModel) element).parent;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- */
+ @Override
public boolean hasChildren(Object element) {
return ((MyModel) element).child.size() > 0;
}
@@ -105,7 +82,7 @@ public class Snippet027TreeLayout {
public class MyModel {
public MyModel parent;
- public ArrayList child = new ArrayList();
+ public ArrayList<MyModel> child = new ArrayList<MyModel>();
public int counter;
@@ -114,6 +91,7 @@ public class Snippet027TreeLayout {
this.counter = counter;
}
+ @Override
public String toString() {
String rv = "Item ";
if (parent != null) {
@@ -130,14 +108,17 @@ public class Snippet027TreeLayout {
ITableLabelProvider, ITableFontProvider, ITableColorProvider {
FontRegistry registry = new FontRegistry();
+ @Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
+ @Override
public String getColumnText(Object element, int columnIndex) {
return "Column " + columnIndex + " => " + element.toString();
}
+ @Override
public Font getFont(Object element, int columnIndex) {
if (((MyModel) element).counter % 2 == 0) {
return registry.getBold(Display.getCurrent().getSystemFont()
@@ -146,6 +127,7 @@ public class Snippet027TreeLayout {
return null;
}
+ @Override
public Color getBackground(Object element, int columnIndex) {
if (((MyModel) element).counter % 2 == 0) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
@@ -153,6 +135,7 @@ public class Snippet027TreeLayout {
return null;
}
+ @Override
public Color getForeground(Object element, int columnIndex) {
if (((MyModel) element).counter % 2 == 1) {
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
@@ -166,27 +149,28 @@ public class Snippet027TreeLayout {
final TreeViewer v = new TreeViewer(shell);
v.getTree().setHeaderVisible(true);
v.getTree().setLinesVisible(true);
-
+
TreeColumnLayout ad = new TreeColumnLayout();
shell.setLayout(ad);
-
- TreeColumn column = new TreeColumn(v.getTree(),SWT.NONE);
- column.setWidth(200);
- column.setText("Column 1");
- ad.setColumnData(column, new ColumnWeightData(50, 100));
-
- column = new TreeColumn(v.getTree(),SWT.NONE);
- column.setWidth(200);
- column.setText("Column 2");
- ad.setColumnData(column,new ColumnWeightData(50, 100));
-
-
+ TreeColumn column1 = createTreeColumn(v.getTree(), "Column 1");
+ TreeColumn column2 = createTreeColumn(v.getTree(), "Column 2");
+
+ ad.setColumnData(column1, new ColumnWeightData(50, 100));
+ ad.setColumnData(column2, new ColumnWeightData(50, 100));
+
v.setLabelProvider(new MyLabelProvider());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
}
+ private TreeColumn createTreeColumn(Tree tree, String textColumn) {
+ TreeColumn column = new TreeColumn(tree, SWT.NONE);
+ column.setText(textColumn);
+ column.setWidth(200);
+ return column;
+ }
+
private MyModel createModel() {
MyModel root = new MyModel(0, null);
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/resources/Snippet057FileImageDescriptors.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/resources/Snippet057FileImageDescriptors.java
index 76c4536..5dd02bd 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/resources/Snippet057FileImageDescriptors.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/resources/Snippet057FileImageDescriptors.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Tom Schindl and others.
+ * Copyright (c) 2006, 2014 Tom Schindl and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.resources;
@@ -24,7 +25,7 @@ import org.eclipse.swt.widgets.Shell;
/**
* A snippet to demonstrate a dialog with image buttons.
- *
+ *
*/
public class Snippet057FileImageDescriptors {
private ImageRegistry registry;
@@ -33,11 +34,7 @@ public class Snippet057FileImageDescriptors {
Dialog dia = new Dialog(shell) {
private ImageDescriptor getImageDescriptorFromClass(String path) {
- if (registry == null) {
- registry = new ImageRegistry(shell.getDisplay());
- }
-
- ImageDescriptor desc = registry.getDescriptor(path);
+ ImageDescriptor desc = getDescriptorBasedOn(shell, path);
if (desc == null) {
desc = ImageDescriptor.createFromFile(
Snippet057FileImageDescriptors.class, path);
@@ -48,36 +45,38 @@ public class Snippet057FileImageDescriptors {
}
private ImageDescriptor getImageDescriptorFromFile(String path) {
- if (registry == null) {
- registry = new ImageRegistry(shell.getDisplay());
- }
-
- ImageDescriptor desc = registry.getDescriptor(path);
+ ImageDescriptor desc = getDescriptorBasedOn(shell, path);
if (desc == null) {
URL classPath = Snippet057FileImageDescriptors.class
.getResource(path);
- Class bogus = null;
- desc = ImageDescriptor.createFromFile(bogus, classPath
- .getFile());
+ Class<?> bogus = null;
+ desc = ImageDescriptor.createFromFile(bogus,
+ classPath.getFile());
registry.put(path, desc);
}
+ return desc;
+ }
+ private ImageDescriptor getDescriptorBasedOn(final Shell shell,
+ String path) {
+ if (registry == null) {
+ registry = new ImageRegistry(shell.getDisplay());
+ }
+ ImageDescriptor desc = registry.getDescriptor(path);
return desc;
}
+ @Override
protected Button createButton(Composite parent, int id,
String label, boolean defaultButton) {
Button b = super.createButton(parent, id, label, defaultButton);
if (id == IDialogConstants.OK_ID) {
- b
- .setImage(getImageDescriptorFromClass(
- "filesave.png").createImage()); //$NON-NLS-1$
+ b.setImage(getImageDescriptorFromClass("filesave.png").createImage()); //$NON-NLS-1$
// reset the button layout
setButtonLayoutData(b);
} else {
- b
- .setImage(getImageDescriptorFromFile("cancel.png").createImage()); //$NON-NLS-1$
+ b.setImage(getImageDescriptorFromFile("cancel.png").createImage()); //$NON-NLS-1$
// reset the button layout
setButtonLayoutData(b);
return b;