From 5b588bca93848e6d3665c2a365cdc135db148eb6 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Wed, 27 Nov 2024 18:13:07 +0100 Subject: [PATCH] Apply Eclipse formatter on jface databinding examples This make reading and modifiy the examples easier and that is the main purpose of these examples --- .../test/AsynchronousTestSet.java | 3 +- .../test/LabelProviderTest.java | 19 +- .../test/LabelProviderTest2.java | 8 +- .../contentprovider/test/SimpleNode.java | 1 - .../test/StructuredContentProviderTest.java | 68 +-- .../test/TreeContentProviderTest.java | 3 +- .../examples/databinding/ducks/DuckType.java | 44 +- .../databinding/ducks/ReflectedMethod.java | 25 +- .../databinding/ducks/ReflectedProperty.java | 14 +- .../databinding/ducks/RelaxedDuckType.java | 16 +- .../examples/databinding/mask/EditMask.java | 140 +++--- .../mask/internal/EditMaskLexerAndToken.java | 42 +- .../mask/internal/EditMaskParser.java | 13 +- .../databinding/mask/internal/SWTUtil.java | 55 +-- .../databinding/mask/internal/WorkQueue.java | 17 +- .../examples/databinding/model/Account.java | 3 +- .../examples/databinding/model/Adventure.java | 5 +- .../model/AggregateObservableValue.java | 6 +- .../examples/databinding/model/Catalog.java | 10 +- .../examples/databinding/model/Lodging.java | 4 +- .../databinding/model/PriceModelObject.java | 32 +- .../databinding/model/SampleData.java | 4 +- .../examples/databinding/model/Signon.java | 8 +- .../databinding/model/SimpleModel.java | 1 - .../databinding/model/SimplePerson.java | 5 +- .../databinding/model/Transportation.java | 6 +- .../databinding/radioGroup/RadioGroup.java | 420 +++++++++++------- .../radioGroup/VetoableSelectionListener.java | 15 +- .../Snippet002UpdateComboRetainSelection.java | 4 +- .../snippets/Snippet014WizardDialog.java | 3 +- .../Snippet030DateAndTimeObservableValue.java | 6 +- ...et033CrossValidationControlDecoration.java | 3 +- .../Snippet039SideEffectMigration.java | 3 +- ...42SideEffectAggregateValidationStatus.java | 3 +- .../snippets/Snippet043BindApi.java | 4 +- 35 files changed, 516 insertions(+), 497 deletions(-) diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java index c5bb5b680c9..60d11ee9baa 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/AsynchronousTestSet.java @@ -68,8 +68,7 @@ public AsynchronousTestSet() { super(new HashSet<>(), Object.class); display = Display.getCurrent(); if (display == null) { - throw new IllegalStateException( - "This object can only be created in the UI thread"); //$NON-NLS-1$ + throw new IllegalStateException("This object can only be created in the UI thread"); //$NON-NLS-1$ } recompute(); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java index 2c2f16533a6..03cd9b60985 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest.java @@ -125,24 +125,21 @@ protected void removeListenerFrom(RenamableItem next) { renameButton.addSelectionListener(buttonSelectionListener); renameButton.setText("Rename"); //$NON-NLS-1$ - selectedRenamable - .addValueChangeListener(event -> { - boolean shouldEnable = selectedRenamable.getValue() != null; - removeButton.setEnabled(shouldEnable); - renameButton.setEnabled(shouldEnable); - }); + selectedRenamable.addValueChangeListener(event -> { + boolean shouldEnable = selectedRenamable.getValue() != null; + removeButton.setEnabled(shouldEnable); + renameButton.setEnabled(shouldEnable); + }); removeButton.setEnabled(false); renameButton.setEnabled(false); GridLayoutFactory.fillDefaults().generateLayout(buttonBar); - GridLayoutFactory.fillDefaults().numColumns(2).margins( - LayoutConstants.getMargins()).generateLayout(shell); + GridLayoutFactory.fillDefaults().numColumns(2).margins(LayoutConstants.getMargins()).generateLayout(shell); } protected void rename(final RenamableItem currentSelection) { - InputDialog inputDialog = new InputDialog( - shell, - "Edit name", "Enter the new item name", currentSelection.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ + InputDialog inputDialog = new InputDialog(shell, "Edit name", "Enter the new item name", //$NON-NLS-1$ //$NON-NLS-2$ + currentSelection.getName(), null); if (Window.OK == inputDialog.open()) { currentSelection.setName(inputDialog.getValue()); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java index ab1dd1c4fbe..0706119bf25 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/LabelProviderTest2.java @@ -134,14 +134,12 @@ protected void removeListenerFrom(RenamableItem next) { renameButton.setEnabled(false); GridLayoutFactory.fillDefaults().generateLayout(buttonBar); - GridLayoutFactory.fillDefaults().numColumns(2).margins( - LayoutConstants.getMargins()).generateLayout(shell); + GridLayoutFactory.fillDefaults().numColumns(2).margins(LayoutConstants.getMargins()).generateLayout(shell); } protected void rename(final RenamableItem currentSelection) { - InputDialog inputDialog = new InputDialog( - shell, - "Edit name", "Enter the new item name", currentSelection.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ + InputDialog inputDialog = new InputDialog(shell, "Edit name", "Enter the new item name", //$NON-NLS-1$ //$NON-NLS-2$ + currentSelection.getName(), null); if (Window.OK == inputDialog.open()) { currentSelection.setName(inputDialog.getValue()); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java index 90d3d5996ed..1063eed9a21 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/SimpleNode.java @@ -15,7 +15,6 @@ import org.eclipse.core.databinding.observable.set.IObservableSet; - /** * This object will be given randomly-generated children * diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java index c0730cf378f..25559842bcb 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/StructuredContentProviderTest.java @@ -91,14 +91,13 @@ public class StructuredContentProviderTest { private WritableValue currentFunction; /** - * mathFunction is the transformation. It can multiply by 2, round down to - * the nearest integer, or do nothing (identity) + * mathFunction is the transformation. It can multiply by 2, round down to the + * nearest integer, or do nothing (identity) */ private SomeMathFunction mathFunction; /** - * Set of Doubles. Holds the result of applying mathFunction to the - * inputSet. + * Set of Doubles. Holds the result of applying mathFunction to the inputSet. */ private MappedSet outputSet; @@ -120,9 +119,7 @@ public StructuredContentProviderTest() { // Initialize shell final Label someDoubles = new Label(shell, SWT.NONE); someDoubles.setText("A list of random Doubles"); //$NON-NLS-1$ - someDoubles.setLayoutData(new GridData( - GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); + someDoubles.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); Control addRemoveComposite = createInputControl(shell, inputSet); @@ -146,8 +143,7 @@ public StructuredContentProviderTest() { GridLayout layout = new GridLayout(); layout.numColumns = 1; operation.setLayout(layout); - operation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); + operation.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); Control outputControl = createOutputComposite(shell); GridData outputData = new GridData(GridData.FILL_BOTH); @@ -169,8 +165,7 @@ protected void updateControl() { + " doubles is " + sum); //$NON-NLS-1$ } }; - sumLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); + sumLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); GridLayout shellLayout = new GridLayout(); layout.numColumns = 1; @@ -227,16 +222,12 @@ protected Double calculate() { * Creates a radio button in the given parent composite. When selected, the * button will change the given SettableValue to the given value. * - * @param parent - * parent composite - * @param model - * SettableValue that will hold the value of the - * currently-selected radio button - * @param string - * text to appear in the radio button - * @param value - * value of this radio button (SettableValue will hold this value - * when the radio button is selected) + * @param parent parent composite + * @param model SettableValue that will hold the value of the + * currently-selected radio button + * @param string text to appear in the radio button + * @param value value of this radio button (SettableValue will hold this value + * when the radio button is selected) */ private void createRadioButton(Composite parent, final WritableValue model, String string, final int value) { @@ -255,13 +246,11 @@ protected void updateControl() { button.setSelection(model.getValue().equals(value)); } }; - button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); + button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); } private Control createOutputComposite(Composite parent) { - ListViewer listOfInts = new ListViewer(parent, SWT.BORDER - | SWT.V_SCROLL | SWT.H_SCROLL); + ListViewer listOfInts = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); listOfInts.setContentProvider(new ObservableSetContentProvider<>()); listOfInts.setLabelProvider(new ViewerLabelProvider()); @@ -273,25 +262,20 @@ private Control createOutputComposite(Composite parent) { * Creates and returns a control that will allow the user to add and remove * Doubles from the given input set. * - * @param parent - * parent control - * @param inputSet - * input set - * @return a newly created SWT control that displays Doubles from the input - * set and allows the user to add and remove entries + * @param parent parent control + * @param inputSet input set + * @return a newly created SWT control that displays Doubles from the input set + * and allows the user to add and remove entries */ - private Control createInputControl(Composite parent, - final WritableSet inputSet) { + private Control createInputControl(Composite parent, final WritableSet inputSet) { Composite addRemoveComposite = new Composite(parent, SWT.NONE); - ListViewer listOfInts = new ListViewer(addRemoveComposite, - SWT.BORDER); + ListViewer listOfInts = new ListViewer(addRemoveComposite, SWT.BORDER); listOfInts.setContentProvider(new ObservableSetContentProvider<>()); listOfInts.setLabelProvider(new ViewerLabelProvider()); listOfInts.setInput(inputSet); - final IObservableValue selectedInt = ViewerProperties.singleSelection(Double.class) - .observe(listOfInts); + final IObservableValue selectedInt = ViewerProperties.singleSelection(Double.class).observe(listOfInts); GridData listData = new GridData(GridData.FILL_BOTH); listData.minimumHeight = 1; @@ -310,8 +294,7 @@ public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); } }); - add.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); + add.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); final Button remove = new Button(buttonBar, SWT.PUSH); remove.setText("Remove"); //$NON-NLS-1$ @@ -347,15 +330,12 @@ public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); } }); - remove.setLayoutData(new GridData( - GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL)); + remove.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); GridLayout buttonLayout = new GridLayout(); buttonLayout.numColumns = 1; buttonBar.setLayout(buttonLayout); // End button bar - buttonBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_BEGINNING)); + buttonBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING)); GridLayout addRemoveLayout = new GridLayout(); addRemoveLayout.numColumns = 2; diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java index fed11719e8f..1dbdd6aa8a3 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/contentprovider/test/TreeContentProviderTest.java @@ -92,8 +92,7 @@ public void widgetSelected(SelectionEvent e) { GridLayoutFactory.fillDefaults().generateLayout(buttonBar); } - GridLayoutFactory.fillDefaults().margins(LayoutConstants.getMargins()) - .generateLayout(shell); + GridLayoutFactory.fillDefaults().margins(LayoutConstants.getMargins()).generateLayout(shell); shell.addDisposeListener(e -> dispose()); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java index d3da1282d01..352030e2bf0 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/DuckType.java @@ -19,12 +19,12 @@ import java.lang.reflect.Proxy; /** - * DuckType. Implements Duck Typing for Java. ("If it walks like a duck, - * quacks like a duck, it..."). Essentially allows programs to treat - * objects from separate hierarchies as if they were designed with common - * interfaces as long as they adhere to common naming conventions. + * DuckType. Implements Duck Typing for Java. ("If it walks like a duck, quacks + * like a duck, it..."). Essentially allows programs to treat objects from + * separate hierarchies as if they were designed with common interfaces as long + * as they adhere to common naming conventions. *

- * This version is the strict DuckType. All methods present in + * This version is the strict DuckType. All methods present in * interfaceToImplement must be present on the target object. * * @author djo @@ -32,13 +32,13 @@ public class DuckType implements InvocationHandler { /** - * Interface DuckType#Wrapper. An interface for DuckType proxies that - * allows clients to access the proxied value. The value returned by - * calling DuckType#implement always implements this interface. + * Interface DuckType#Wrapper. An interface for DuckType proxies that allows + * clients to access the proxied value. The value returned by calling + * DuckType#implement always implements this interface. */ public static interface Wrapper { /** - * Method duckType_GetWrappedValue. Returns the proxied value. + * Method duckType_GetWrappedValue. Returns the proxied value. * * @return The proxied value. */ @@ -46,30 +46,32 @@ public static interface Wrapper { } /** - * Causes object to implement the interfaceToImplement and returns - * an instance of the object implementing interfaceToImplement even - * if interfaceToImplement was not declared in object.getClass()'s - * implements declaration.

+ * Causes object to implement the interfaceToImplement and returns an instance + * of the object implementing interfaceToImplement even if interfaceToImplement + * was not declared in object.getClass()'s implements declaration. + *

* - * This works as long as all methods declared in interfaceToImplement - * are present on object. + * This works as long as all methods declared in interfaceToImplement are + * present on object. * * @param interfaceToImplement The Java class of the interface to implement - * @param object The object to force to implement interfaceToImplement + * @param object The object to force to implement + * interfaceToImplement * @return object, but now implementing interfaceToImplement */ public static Object implement(Class interfaceToImplement, Object object) { return Proxy.newProxyInstance(interfaceToImplement.getClassLoader(), - new Class[] {interfaceToImplement, Wrapper.class}, new DuckType(object)); + new Class[] { interfaceToImplement, Wrapper.class }, new DuckType(object)); } /** - * Indicates if object is a (DuckType) instace of intrface. That is, - * is every method in intrface present on object. + * Indicates if object is a (DuckType) instace of intrface. That is, is every + * method in intrface present on object. * * @param intrface The interface to implement - * @param object The object to test - * @return true if every method in intrface is present on object. false otherwise + * @param object The object to test + * @return true if every method in intrface is present on object. false + * otherwise */ public static boolean instanceOf(Class intrface, Object object) { final Method[] methods = intrface.getMethods(); diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java index 9342b561949..dbd725a6dd3 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedMethod.java @@ -17,9 +17,9 @@ import java.lang.reflect.Method; /** - * ReflectedMethod. Encapsulates a method that may or may not exist on - * some receiver. Invocation policy is that if the method can be invoked, - * it is. On failure, returns null. + * ReflectedMethod. Encapsulates a method that may or may not exist on some + * receiver. Invocation policy is that if the method can be invoked, it is. On + * failure, returns null. * * @author djo */ @@ -29,9 +29,9 @@ public class ReflectedMethod { private Method method; /** - * Constructor ReflectedMethod. Create a ReflectedMethod object. + * Constructor ReflectedMethod. Create a ReflectedMethod object. * - * @param subject The object on which the method lives. + * @param subject The object on which the method lives. * @param methodName The name of the method. * @param paramTypes The method's parameter types. */ @@ -46,8 +46,7 @@ public ReflectedMethod(Object subject, String methodName, Class[] paramTypes) } /** - * Method exists. Returns true if the underlying method exists, false - * otherwise. + * Method exists. Returns true if the underlying method exists, false otherwise. * * @return true if the underlying method exists, false otherwise. */ @@ -56,12 +55,12 @@ public boolean exists() { } /** - * Method invoke. If possible, invoke the encapsulated method with the - * specified parameters. + * Method invoke. If possible, invoke the encapsulated method with the specified + * parameters. * * @param params An Object[] containing the parameters to pass. - * @return any return value or null if there was no return value or an - * error occured. + * @return any return value or null if there was no return value or an error + * occured. */ public Object invoke(Object[] params) { if (method == null) @@ -77,7 +76,7 @@ public Object invoke(Object[] params) { } /** - * Method getType. Returns the return type of the method. + * Method getType. Returns the return type of the method. * * @return The return type or null if none. */ @@ -85,5 +84,3 @@ public Class getType() { return method.getReturnType(); } } - - diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java index 94e110279a4..6cf2f77bbe0 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/ReflectedProperty.java @@ -27,7 +27,7 @@ public class ReflectedProperty { /** * Construct a ReflectedProperty on some object, given the property name. * - * @param object The object + * @param object The object * @param propertyName The property name */ public ReflectedProperty(Object object, String propertyName) { @@ -39,7 +39,7 @@ public ReflectedProperty(Object object, String propertyName) { throw new IllegalArgumentException("Cannot find getter for " + propertyName); } } - setter = new ReflectedMethod(object, makeSetterName(propertyName), new Class[] {getter.getType()}); + setter = new ReflectedMethod(object, makeSetterName(propertyName), new Class[] { getter.getType() }); } private String makeBooleanGetterName(String propertyName) { @@ -59,8 +59,8 @@ private String capitalize(String string) { } /** - * Return the property's type. This is the same as the type returned by - * the getter. + * Return the property's type. This is the same as the type returned by the + * getter. * * @return The property's data type. */ @@ -78,13 +78,13 @@ public Object get() { } /** - * Set the property's value. If the property is read-only, the request - * is ignored. + * Set the property's value. If the property is read-only, the request is + * ignored. * * @param newValue The value to set. */ public void set(Object newValue) { - setter.invoke(new Object[] {newValue}); + setter.invoke(new Object[] { newValue }); } /** diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java index 1c7ca1aa5e8..49d0aa43007 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/ducks/RelaxedDuckType.java @@ -21,21 +21,21 @@ import java.util.Map; /** - * RelaxedDuckType. Implements Duck Typing for Java. ("If it walks like a duck, - * quacks like a duck, it..."). Essentially allows programs to treat - * objects from separate hierarchies as if they were designed with common - * interfaces as long as they adhere to common naming conventions. + * RelaxedDuckType. Implements Duck Typing for Java. ("If it walks like a duck, + * quacks like a duck, it..."). Essentially allows programs to treat objects + * from separate hierarchies as if they were designed with common interfaces as + * long as they adhere to common naming conventions. *

- * This version is the relaxed DuckType. If a method in the interface is - * not present on the underlying object, the proxy simply returns null. + * This version is the relaxed DuckType. If a method in the interface is not + * present on the underlying object, the proxy simply returns null. * * @author djo */ public class RelaxedDuckType extends DuckType implements InvocationHandler { public static Object implement(Class interfaceToImplement, Object object) { - return Proxy.newProxyInstance(interfaceToImplement.getClassLoader(), - new Class[] {interfaceToImplement}, new RelaxedDuckType(object)); + return Proxy.newProxyInstance(interfaceToImplement.getClassLoader(), new Class[] { interfaceToImplement }, + new RelaxedDuckType(object)); } public static boolean includes(Object object, String method, Class[] args) { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java index 0dd41e50d56..bc1bfad898c 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/EditMask.java @@ -29,60 +29,55 @@ import org.eclipse.swt.widgets.Text; /** - * Ensures text widget has the format specified by the edit mask. Edit masks - * are currently defined as follows: + * Ensures text widget has the format specified by the edit mask. Edit masks are + * currently defined as follows: * * The following characters are reserved words that match specific kinds of * characters: * - * # - digits 0-9 - * A - uppercase A-Z - * a - upper or lowercase a-z, A-Z - * n - alphanumeric 0-9, a-z, A-Z + * # - digits 0-9 A - uppercase A-Z a - upper or lowercase a-z, A-Z n - + * alphanumeric 0-9, a-z, A-Z * - * All other characters are literals. The above characters may be turned into - * literals by preceeding them with a backslash. Use two backslashes to - * denote a backslash. + * All other characters are literals. The above characters may be turned into + * literals by preceeding them with a backslash. Use two backslashes to denote a + * backslash. * * Examples: * - * (###) ###-#### U.S. phone number - * ###-##-#### U.S. Social Security number - * \\\### A literal backslash followed by a literal pound symbol followed by two digits + * (###) ###-#### U.S. phone number ###-##-#### U.S. Social Security number + * \\\### A literal backslash followed by a literal pound symbol followed by two + * digits * * Ideas for future expansion: * - * Quantifiers as postfix modifiers to a token. ie: + * Quantifiers as postfix modifiers to a token. ie: * - * #{1, 2}/#{1,2}/#### MM/DD/YYYY date format allowing 1 or 2 digit month or day + * #{1, 2}/#{1,2}/#### MM/DD/YYYY date format allowing 1 or 2 digit month or day * - * Literals may only be quantified as {0,1} which means that they only appear - * if placeholders on both sides of the literal have data. This will be used - * along with: + * Literals may only be quantified as {0,1} which means that they only appear if + * placeholders on both sides of the literal have data. This will be used along + * with: * - * Right-to-left support for numeric entry. When digits are being entered and - * a decimal point is present in the mask, digits to the left of the decimal - * are entered right-to-left but digits to the right of the decimal left-to-right. + * Right-to-left support for numeric entry. When digits are being entered and a + * decimal point is present in the mask, digits to the left of the decimal are + * entered right-to-left but digits to the right of the decimal left-to-right. * This might need to be a separate type of edit mask. (NumericMask, maybe?) * * Example: * - * $#{0,3},{0,1}#{0,3}.#{0,2} ie: $123,456.12 or $12.12 or $1,234.12 or $123.12 + * $#{0,3},{0,1}#{0,3}.#{0,2} ie: $123,456.12 or $12.12 or $1,234.12 or $123.12 * * * Here's the basic idea of how the current implementation works (the actual * implementation is slightly more abstracted and complicated than this): * - * We always let the verify event pass if the user typed a new character or selected/deleted anything. - * During the verify event, we post an async runnable. - * Inside that async runnable, we: - * - Remember the selection position - * - getText(), then - * - Strip out all literal characters from text - * - Truncate the resulting string to raw length of edit mask without literals - * - Insert literal characters back in the correct positions - * - setText() the resulting string - * - reset the selection to the correct location + * We always let the verify event pass if the user typed a new character or + * selected/deleted anything. During the verify event, we post an async + * runnable. Inside that async runnable, we: - Remember the selection position - + * getText(), then - Strip out all literal characters from text - Truncate the + * resulting string to raw length of edit mask without literals - Insert literal + * characters back in the correct positions - setText() the resulting string - + * reset the selection to the correct location * * @since 3.3 */ @@ -158,12 +153,12 @@ public String getText() { } /** - * setRawText takes raw text as a parameter but formats it before - * setting the text in the Text control. + * setRawText takes raw text as a parameter but formats it before setting the + * text in the Text control. * * @param string the raw (unformatted) text */ - public void setRawText(String string) { + public void setRawText(String string) { if (string == null) { string = ""; } @@ -202,11 +197,11 @@ public boolean isComplete() { } /** - * Returns the placeholder character. The placeholder - * character must be a different character than any character that is - * allowed as input anywhere in the edit mask. For example, if the edit - * mask permits spaces to be used as input anywhere, the placeholder - * character must be something other than a space character. + * Returns the placeholder character. The placeholder character must be a + * different character than any character that is allowed as input anywhere in + * the edit mask. For example, if the edit mask permits spaces to be used as + * input anywhere, the placeholder character must be something other than a + * space character. *

* The space character is the default placeholder character. * @@ -220,11 +215,11 @@ public char getPlaceholder() { } /** - * Sets the placeholder character for the edit mask. The placeholder - * character must be a different character than any character that is - * allowed as input anywhere in the edit mask. For example, if the edit - * mask permits spaces to be used as input anywhere, the placeholder - * character must be something other than a space character. + * Sets the placeholder character for the edit mask. The placeholder character + * must be a different character than any character that is allowed as input + * anywhere in the edit mask. For example, if the edit mask permits spaces to be + * used as input anywhere, the placeholder character must be something other + * than a space character. *

* The space character is the default placeholder character. * @@ -240,27 +235,26 @@ public void setPlaceholder(char placeholder) { } /** - * Indicates if change notifications will be fired after every keystroke - * that affects the value of the rawText or only when the value is either - * complete or empty. + * Indicates if change notifications will be fired after every keystroke that + * affects the value of the rawText or only when the value is either complete or + * empty. * * @return true if every change (including changes from one invalid state to - * another) triggers a change event; false if only empty or valid - * values trigger a change event. Defaults to false. + * another) triggers a change event; false if only empty or valid values + * trigger a change event. Defaults to false. */ public boolean isFireChangeOnKeystroke() { return fireChangeOnKeystroke; } /** - * Sets if change notifications will be fired after every keystroke that - * affects the value of the rawText or only when the value is either - * complete or empty. + * Sets if change notifications will be fired after every keystroke that affects + * the value of the rawText or only when the value is either complete or empty. * - * @param fireChangeOnKeystroke - * true if every change (including changes from one invalid state - * to another) triggers a change event; false if only empty or - * valid values trigger a change event. Defaults to false. + * @param fireChangeOnKeystroke true if every change (including changes from one + * invalid state to another) triggers a change + * event; false if only empty or valid values + * trigger a change event. Defaults to false. */ public void setFireChangeOnKeystroke(boolean fireChangeOnKeystroke) { this.fireChangeOnKeystroke = fireChangeOnKeystroke; @@ -276,8 +270,7 @@ public void addPropertyChangeListener(PropertyChangeListener listener) { /** * JavaBeans boilerplate code... */ - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) { + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { propertyChangeSupport.addPropertyChangeListener(propertyName, listener); } @@ -291,21 +284,17 @@ public void removePropertyChangeListener(PropertyChangeListener listener) { /** * JavaBeans boilerplate code... */ - public void removePropertyChangeListener(String propertyName, - PropertyChangeListener listener) { - propertyChangeSupport.removePropertyChangeListener(propertyName, - listener); + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + propertyChangeSupport.removePropertyChangeListener(propertyName, listener); } private boolean isEitherValueNotNull(Object oldValue, Object newValue) { return oldValue != null || newValue != null; } - private void firePropertyChange(String propertyName, Object oldValue, - Object newValue) { + private void firePropertyChange(String propertyName, Object oldValue, Object newValue) { if (isEitherValueNotNull(oldValue, newValue)) { - propertyChangeSupport.firePropertyChange(propertyName, - oldValue, newValue); + propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); } } @@ -320,10 +309,8 @@ private void firePropertyChange(String propertyName, Object oldValue, // If the edit mask is already full, don't let the user type // any new characters if (editMaskParser.isComplete() && // should eventually be .isFull() to account for optional characters - e.start == e.end && - e.text.length() > 0) - { - e.doit=false; + e.start == e.end && e.text.length() > 0) { + e.doit = false; return; } @@ -369,12 +356,9 @@ private void updateSelectionPosition(String newRawText) { // Adjust the selection if (isInsertingNewCharacter(newRawText) || replacedSelectedText) { // Find the position after where the new character was actually inserted - int selectionDelta = - editMaskParser.getNextInputPosition(oldSelection) - - oldSelection; + int selectionDelta = editMaskParser.getNextInputPosition(oldSelection) - oldSelection; if (selectionDelta == 0) { - selectionDelta = editMaskParser.getNextInputPosition(selection) - - selection; + selectionDelta = editMaskParser.getNextInputPosition(selection) - selection; } selection += selectionDelta; } @@ -382,7 +366,7 @@ private void updateSelectionPosition(String newRawText) { // Did we just type something that was accepted by the mask? if (!newRawText.equals(oldRawText)) { // yep - // If the user hits , bounce them back to the end of their actual input + // If the user hits , bounce them back to the end of their actual input int firstIncompletePosition = editMaskParser.getFirstIncompleteInputPosition(); if (firstIncompletePosition > 0 && selection > firstIncompletePosition) selection = firstIncompletePosition; @@ -390,7 +374,7 @@ private void updateSelectionPosition(String newRawText) { } else // Either we backspaced over a literal or we typed an illegal character if (selection > oldSelection) { // typed an illegal character; backup - text.setSelection(new Point(selection-1, selection-1)); + text.setSelection(new Point(selection - 1, selection - 1)); } else { // backspaced over a literal; don't interfere with selection position text.setSelection(new Point(selection, selection)); } @@ -407,7 +391,7 @@ private void firePropertyChangeEvents(Boolean oldIsComplete, String newRawText) firePropertyChange(FIELD_COMPLETE, oldIsComplete, newIsComplete); } if (!newRawText.equals(oldValidRawText)) { - if ( newIsComplete.booleanValue() || "".equals(newRawText) || fireChangeOnKeystroke) { + if (newIsComplete.booleanValue() || "".equals(newRawText) || fireChangeOnKeystroke) { firePropertyChange(FIELD_RAW_TEXT, oldValidRawText, newRawText); firePropertyChange(FIELD_TEXT, oldValidText, text.getText()); oldValidText = text.getText(); diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java index 48a309bf07d..1af9cff75e4 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskLexerAndToken.java @@ -20,7 +20,7 @@ import org.eclipse.jface.examples.databinding.mask.EditMaskParseException; /** - * Lexical analyzer and token for an input mask. Since input masks have exactly + * Lexical analyzer and token for an input mask. Since input masks have exactly * one token type, we use the same class to be the recognizer and the token * itself. * @@ -51,13 +51,13 @@ public class EditMaskLexerAndToken { inputRegexes.add("^[0-9a-zA-Z]$"); } - private String charRegex = null; // A regex for matching input characters or null - private String literal = null; // The literal character if charRegex is null + private String charRegex = null; // A regex for matching input characters or null + private String literal = null; // The literal character if charRegex is null private boolean readOnly; - private String input = null; // The user's input + private String input = null; // The user's input private boolean recognizeReservedWord(String inputMask, int position) { - String input = inputMask.substring(position, position+1); + String input = inputMask.substring(position, position + 1); for (int reservedWord = 0; reservedWord < reservedWords.size(); reservedWord++) { if (input.equals(reservedWords.get(reservedWord))) { charRegex = inputRegexes.get(reservedWord); @@ -71,10 +71,10 @@ private boolean recognizeReservedWord(String inputMask, int position) { } private boolean recognizeBackslashLiteral(String inputMask, int position) throws EditMaskParseException { - String input = inputMask.substring(position, position+1); + String input = inputMask.substring(position, position + 1); if (input.equals("\\")) { try { - input = inputMask.substring(position+1, position+2); + input = inputMask.substring(position + 1, position + 2); charRegex = null; this.input = input; literal = input; @@ -88,7 +88,7 @@ private boolean recognizeBackslashLiteral(String inputMask, int position) throws } private boolean recognizeLiteral(String inputMask, int position) { - literal = inputMask.substring(position, position+1); + literal = inputMask.substring(position, position + 1); this.input = literal; charRegex = null; readOnly = true; @@ -100,9 +100,10 @@ private boolean recognizeLiteral(String inputMask, int position) { * returns number of chars consumed * * @param inputMask The entire edit mask - * @param position The position to begin parsing + * @param position The position to begin parsing * @return The number of characters consumed - * @throws EditMaskParseException If it encountered a syntax error during the parse + * @throws EditMaskParseException If it encountered a syntax error during the + * parse */ public int initializeEditMask(String inputMask, int position) throws EditMaskParseException { clear(); @@ -140,9 +141,10 @@ public boolean accept(String inputCharacter) { } /** - * @return Returns the characters it has accepted. In the current implementation, - * this is exactly one character. Once quantifiers are implemented, this could - * be many characters. If no characters have been accepted, returns null. + * @return Returns the characters it has accepted. In the current + * implementation, this is exactly one character. Once quantifiers are + * implemented, this could be many characters. If no characters have + * been accepted, returns null. */ public String getInput() { return input; @@ -164,8 +166,8 @@ public boolean isReadOnly() { } /** - * @return true if it is a literal or if it has accepted the minimum - * required number of characters + * @return true if it is a literal or if it has accepted the minimum required + * number of characters */ public boolean isComplete() { if (input != null) { @@ -176,17 +178,17 @@ public boolean isComplete() { /** * @return A position may be complete and yet able to accept more characters if - * the position includes optional characters via a quantifier of some type. - * Not implemented right now. + * the position includes optional characters via a quantifier of some + * type. Not implemented right now. */ public boolean canAcceptMoreCharacters() { return !isComplete(); } /** - * @return the minimum number of characters this RegexLexer must accept - * in order to be complete. Because we don't yet support quantifiers, this - * is currently always 1. + * @return the minimum number of characters this RegexLexer must accept in order + * to be complete. Because we don't yet support quantifiers, this is + * currently always 1. */ public int getMinimumLength() { return 1; diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java index 6f3db883a08..542fd8136ac 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/EditMaskParser.java @@ -50,15 +50,13 @@ public void setInput(String input) { int tokenPosition = 0; int inputPosition = 0; while (inputPosition < input.length() && tokenPosition < expectedTokens.length) { - while (tokenPosition < expectedTokens.length && - (expectedTokens[tokenPosition].isComplete() || - expectedTokens[tokenPosition].isReadOnly())) - { + while (tokenPosition < expectedTokens.length + && (expectedTokens[tokenPosition].isComplete() || expectedTokens[tokenPosition].isReadOnly())) { ++tokenPosition; } if (tokenPosition < expectedTokens.length) { while (inputPosition < input.length() && !expectedTokens[tokenPosition].isComplete()) { - String inputChar = input.substring(inputPosition, inputPosition+1); + String inputChar = input.substring(inputPosition, inputPosition + 1); expectedTokens[tokenPosition].accept(inputChar); ++inputPosition; } @@ -116,14 +114,15 @@ public boolean isComplete() { * @return The first non-read-only index greater than or equal to startingAt */ public int getNextInputPosition(int startingAt) { - while (startingAt < expectedTokens.length-1 && expectedTokens[startingAt].isReadOnly()) { + while (startingAt < expectedTokens.length - 1 && expectedTokens[startingAt].isReadOnly()) { ++startingAt; } return startingAt; } /** - * @return the first input position whose token is not marked as complete. Returns -1 if all are complete + * @return the first input position whose token is not marked as complete. + * Returns -1 if all are complete */ public int getFirstIncompleteInputPosition() { for (int position = 0; position < expectedTokens.length; position++) { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java index 9f83b1778f4..99606861348 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/SWTUtil.java @@ -33,18 +33,16 @@ private SWTUtil() { /** * Runs the given runnable on the given display as soon as possible. If - * possible, the runnable will be executed before the next widget is - * repainted, but this behavior is not guaranteed. Use this method to - * schedule work will affect the way one or more widgets are drawn. + * possible, the runnable will be executed before the next widget is repainted, + * but this behavior is not guaranteed. Use this method to schedule work will + * affect the way one or more widgets are drawn. * *

* This is threadsafe. *

* - * @param d - * display - * @param r - * runnable to execute in the UI thread. + * @param d display + * @param r runnable to execute in the UI thread. */ public static void greedyExec(Display d, Runnable r) { if (d.isDisposed()) { @@ -62,19 +60,16 @@ public static void greedyExec(Display d, Runnable r) { /** * Runs the given runnable on the given display as soon as possible. Unlike * greedyExec, this has no effect if the given runnable has already been - * scheduled for execution. Use this method to schedule work that will - * affect the way one or more wigdets are drawn, but that should only happen - * once. + * scheduled for execution. Use this method to schedule work that will affect + * the way one or more wigdets are drawn, but that should only happen once. * *

* This is threadsafe. *

* - * @param d - * display - * @param r - * runnable to execute in the UI thread. Has no effect if the - * given runnable has already been scheduled but has not yet run. + * @param d display + * @param r runnable to execute in the UI thread. Has no effect if the given + * runnable has already been scheduled but has not yet run. */ public static void runOnce(Display d, Runnable r) { if (d.isDisposed()) { @@ -85,14 +80,12 @@ public static void runOnce(Display d, Runnable r) { } /** - * Cancels a greedyExec or runOnce that was previously scheduled on the - * given display. Has no effect if the given runnable is not in the queue - * for the given display + * Cancels a greedyExec or runOnce that was previously scheduled on the given + * display. Has no effect if the given runnable is not in the queue for the + * given display * - * @param d - * target display - * @param r - * runnable to execute + * @param d target display + * @param r runnable to execute */ public static void cancelExec(Display d, Runnable r) { if (d.isDisposed()) { @@ -103,11 +96,10 @@ public static void cancelExec(Display d, Runnable r) { } /** - * Returns the work queue for the given display. Creates a work queue if - * none exists yet. + * Returns the work queue for the given display. Creates a work queue if none + * exists yet. * - * @param d - * display to return queue for + * @param d display to return queue for * @return a work queue (never null) */ private static WorkQueue getQueueFor(final Display d) { @@ -136,15 +128,16 @@ private static WorkQueue getQueueFor(final Display d) { * @return the RGB object */ public static RGB mix(RGB rgb1, RGB rgb2, double ratio) { - return new RGB(interp(rgb1.red, rgb2.red, ratio), - interp(rgb1.green, rgb2.green, ratio), + return new RGB(interp(rgb1.red, rgb2.red, ratio), interp(rgb1.green, rgb2.green, ratio), interp(rgb1.blue, rgb2.blue, ratio)); } private static int interp(int i1, int i2, double ratio) { - int result = (int)(i1 * ratio + i2 * (1.0d - ratio)); - if (result < 0) result = 0; - if (result > 255) result = 255; + int result = (int) (i1 * ratio + i2 * (1.0d - ratio)); + if (result < 0) + result = 0; + if (result > 255) + result = 255; return result; } } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java index 9b393766492..2b2ee40bbef 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/mask/internal/WorkQueue.java @@ -75,11 +75,10 @@ private void doUpdate() { /** * Schedules some work to happen in the UI thread as soon as possible. If * possible, the work will happen before the next control redraws. The given - * runnable will only be run once. Has no effect if this runnable has - * already been queued for execution. + * runnable will only be run once. Has no effect if this runnable has already + * been queued for execution. * - * @param work - * runnable to execute + * @param work runnable to execute */ public void runOnce(Runnable work) { synchronized (pendingWork) { @@ -99,8 +98,7 @@ public void runOnce(Runnable work) { * runOnce, calling asyncExec twice with the same runnable will cause that * runnable to run twice. * - * @param work - * runnable to execute + * @param work runnable to execute */ public void asyncExec(Runnable work) { synchronized (pendingWork) { @@ -122,11 +120,10 @@ public void asyncExec(Runnable work) { } /** - * Cancels a previously-scheduled runnable. Has no effect if the given - * runnable was not previously scheduled or has already executed. + * Cancels a previously-scheduled runnable. Has no effect if the given runnable + * was not previously scheduled or has already executed. * - * @param toCancel - * runnable to cancel + * @param toCancel runnable to cancel */ public void cancelExec(Runnable toCancel) { synchronized (pendingWork) { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java index a789170ff79..8d38cc67272 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Account.java @@ -81,8 +81,7 @@ public Date getExpiryDate() { } public void setExpiryDate(Date expiryDate) { - firePropertyChange("expiryDate", this.expiryDate, - this.expiryDate = expiryDate); + firePropertyChange("expiryDate", this.expiryDate, this.expiryDate = expiryDate); } } \ No newline at end of file diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java index 2813e99851e..a1241546e47 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Adventure.java @@ -43,7 +43,7 @@ public void setName(String string) { firePropertyChange("name", oldValue, name); } - public int getMaxNumberOfPeople(){ + public int getMaxNumberOfPeople() { return maxNumberOfPeople; } @@ -85,8 +85,7 @@ public double getPrice() { public void setPetsAllowed(boolean b) { boolean oldValue = petsAllowed; petsAllowed = b; - firePropertyChange("petsAllowed", Boolean.valueOf(oldValue), Boolean.valueOf( - petsAllowed)); + firePropertyChange("petsAllowed", Boolean.valueOf(oldValue), Boolean.valueOf(petsAllowed)); } public boolean isPetsAllowed() { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java index 6a21d43935b..af7b36466fd 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/AggregateObservableValue.java @@ -40,8 +40,7 @@ public class AggregateObservableValue extends AbstractObservableValue { } }; - public AggregateObservableValue(IObservableValue[] observableValues, - String delimiter) { + public AggregateObservableValue(IObservableValue[] observableValues, String delimiter) { this.observableValues = observableValues; this.delimiter = delimiter; for (IObservableValue observableValue : observableValues) { @@ -53,8 +52,7 @@ public AggregateObservableValue(IObservableValue[] observableValues, @Override public void doSetValue(Object value) { Object oldValue = doGetValue(); - StringTokenizer tokenizer = new StringTokenizer((String) value, - delimiter); + StringTokenizer tokenizer = new StringTokenizer((String) value, delimiter); try { updating = true; for (IObservableValue observableValue : observableValues) { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java index 56da30bc4be..dc7c7494011 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Catalog.java @@ -34,14 +34,14 @@ public List getSignons() { return signons; } - public void addSignon(Signon aSignon){ + public void addSignon(Signon aSignon) { signons.add(aSignon); - firePropertyChange("signons",null,null); + firePropertyChange("signons", null, null); } - public void removeSignon(Signon aSignon){ + public void removeSignon(Signon aSignon) { signons.remove(aSignon); - firePropertyChange("signons",null,null); + firePropertyChange("signons", null, null); } public Category[] getCategories() { @@ -86,7 +86,7 @@ public Account[] getAccounts() { return accounts; } - public Transportation[] getTransporations(){ + public Transportation[] getTransporations() { return transportations; } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java index 12908015d14..c5142d72ba1 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Lodging.java @@ -27,13 +27,13 @@ public String getDescription() { public void setDescription(String string) { Object oldValue = description; description = string; - firePropertyChange("description",oldValue,description); + firePropertyChange("description", oldValue, description); } public void setName(String string) { Object oldValue = name; name = string; - firePropertyChange("name",oldValue,name); + firePropertyChange("name", oldValue, name); } public String getName() { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java index b03021c09ca..bacfa465e10 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/PriceModelObject.java @@ -15,49 +15,49 @@ import org.eclipse.jface.examples.databinding.ModelObject; - public class PriceModelObject extends ModelObject { private double price; - public double getDouble(){ + public double getDouble() { return price; } - public void setPrice(double aPrice){ + + public void setPrice(double aPrice) { int oldDollars = getDollars(); int oldCents = getCents(); double oldValue = price; price = aPrice; - firePropertyChange("dollars",oldDollars,getDollars()); - firePropertyChange("cents",oldCents,getCents()); - firePropertyChange("price",Double.valueOf(oldValue), Double.valueOf(price)); + firePropertyChange("dollars", oldDollars, getDollars()); + firePropertyChange("cents", oldCents, getCents()); + firePropertyChange("price", Double.valueOf(oldValue), Double.valueOf(price)); } - public double getPrice(){ + public double getPrice() { return price; } - public int getCents(){ - return (int) (100*price - 100*Math.floor(price)); + public int getCents() { + return (int) (100 * price - 100 * Math.floor(price)); } - public void setCents(int cents){ + public void setCents(int cents) { double oldPrice = getPrice(); int oldCents = getCents(); - price = getDollars() + cents *.01; - firePropertyChange("cents",oldCents,getCents()); + price = getDollars() + cents * .01; + firePropertyChange("cents", oldCents, getCents()); firePropertyChange("price", Double.valueOf(oldPrice), Double.valueOf(price)); } - public int getDollars(){ + public int getDollars() { return Double.valueOf(price).intValue(); } - public void setDollars(int dollars){ + public void setDollars(int dollars) { double oldPrice = getPrice(); int oldDollars = getDollars(); - price = dollars + getCents() *.01; - firePropertyChange("dollars",oldDollars,getDollars()); + price = dollars + getCents() * .01; + firePropertyChange("dollars", oldDollars, getDollars()); firePropertyChange("price", Double.valueOf(oldPrice), Double.valueOf(price)); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java index 39b22219547..5c42ec15c9e 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SampleData.java @@ -14,7 +14,6 @@ *******************************************************************************/ package org.eclipse.jface.examples.databinding.model; - public class SampleData { public static Category WINTER_CATEGORY; @@ -106,8 +105,7 @@ public static void initializeData() { SUMMER_CATEGORY.addAdventure(BEACH_HOLIDAY); RAFTING_HOLIDAY = FACTORY.createAdventure(); - RAFTING_HOLIDAY - .setDescription("White water rafting on the Ottawa river"); + RAFTING_HOLIDAY.setDescription("White water rafting on the Ottawa river"); RAFTING_HOLIDAY.setName("Whitewater"); RAFTING_HOLIDAY.setLocation("Ottawa"); RAFTING_HOLIDAY.setPrice(8000.52d); diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java index 407a659063f..990f3e5e72d 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Signon.java @@ -24,21 +24,25 @@ public Signon(String aUserId, String aPassword) { userId = aUserId; password = aPassword; } + public String getPassword() { return password; } + public void setPassword(String aPassword) { String oldValue = password; password = aPassword; - firePropertyChange("password",oldValue,password); + firePropertyChange("password", oldValue, password); } + public String getUserId() { return userId; } + public void setUserId(String aUserId) { String oldValue = userId; userId = aUserId; - firePropertyChange("userId",oldValue,userId); + firePropertyChange("userId", oldValue, userId); } } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java index b59d88e4640..bbf31ad7202 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimpleModel.java @@ -17,7 +17,6 @@ import java.util.LinkedList; import java.util.List; - public class SimpleModel { public SimpleModel() { // Add some sample data to our personList... diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java index a56ea9bdf62..b59c6706305 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/SimplePerson.java @@ -38,12 +38,13 @@ public SimplePerson(String name, String address, String city, String state) { this.state = state; int numOrders = (int) (Math.random() * 5); - for (int i=0; i < numOrders; ++i) { + for (int i = 0; i < numOrders; ++i) { orders.add(new SimpleOrder(i, new Date())); } } - public SimplePerson() {} + public SimplePerson() { + } /** * @return Returns the address. diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java index 2cec94b8a8e..a1b1025f7d4 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/model/Transportation.java @@ -23,10 +23,10 @@ public class Transportation extends ModelObject { public void setArrivalTime(String string) { String oldValue = arrivalTime; arrivalTime = string; - firePropertyChange("arrivaltime",oldValue,string); + firePropertyChange("arrivaltime", oldValue, string); } - public String getArrivalTime(){ + public String getArrivalTime() { return arrivalTime; } @@ -37,7 +37,7 @@ public double getPrice() { public void setPrice(double aPrice) { double oldPrice = price; price = aPrice; - firePropertyChange("price",Double.valueOf(oldPrice),Double.valueOf(price)); + firePropertyChange("price", Double.valueOf(oldPrice), Double.valueOf(price)); } } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java index 33142afce0f..eeca4574df8 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/RadioGroup.java @@ -40,28 +40,36 @@ public class RadioGroup { IRadioButton selectedButton = null; IRadioButton potentialNewSelection = null; - /** (Non-API) - * Interface IRadioButton. A duck interface that is used internally by RadioGroup - * and by RadioGroup's unit tests. + /** + * (Non-API) Interface IRadioButton. A duck interface that is used internally by + * RadioGroup and by RadioGroup's unit tests. */ public static interface IRadioButton { void setData(String string, Object object); + void addSelectionListener(SelectionListener selectionListener); + void setSelection(boolean b); + boolean getSelection(); + boolean isFocusControl(); + String getText(); + void setText(String string); + void notifyListeners(int eventType, Event object); } /** - * Constructs an instance of this widget given an array of Button objects to wrap. - * The Button objects must have been created with the SWT.RADIO style bit set, - * and they must all be in the same Composite. + * Constructs an instance of this widget given an array of Button objects to + * wrap. The Button objects must have been created with the SWT.RADIO style bit + * set, and they must all be in the same Composite. * * @param radioButtons Object[] an array of radio buttons to wrap. - * @param values Object[] an array of objects corresponding to the value of each radio button. + * @param values Object[] an array of objects corresponding to the value + * of each radio button. */ public RadioGroup(Object[] radioButtons, Object[] values) { IRadioButton[] buttons = new IRadioButton[radioButtons.length]; @@ -81,11 +89,11 @@ public RadioGroup(Object[] radioButtons, Object[] values) { } /** - * Returns the object corresponding to the currently-selected radio button - * or null if no radio button is selected. + * Returns the object corresponding to the currently-selected radio button or + * null if no radio button is selected. * - * @return the object corresponding to the currently-selected radio button - * or null if no radio button is selected. + * @return the object corresponding to the currently-selected radio button or + * null if no radio button is selected. */ public Object getSelection() { int selectionIndex = getSelectionIndex(); @@ -96,11 +104,11 @@ public Object getSelection() { /** * Sets the selected radio button to the radio button whose model object - * equals() the object specified by newSelection. If !newSelection.equals() - * any model object managed by this radio group, deselects all radio buttons. + * equals() the object specified by newSelection. If !newSelection.equals() any + * model object managed by this radio group, deselects all radio buttons. * - * @param newSelection A model object corresponding to one of the model - * objects associated with one of the radio buttons. + * @param newSelection A model object corresponding to one of the model objects + * associated with one of the radio buttons. */ public void setSelection(Object newSelection) { deselectAll(); @@ -114,14 +122,14 @@ public void setSelection(Object newSelection) { private final SelectionListener selectionListener = new SelectionListener() { @Override - public void widgetDefaultSelected(SelectionEvent e) { + public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @Override - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent e) { potentialNewSelection = getButton(e); - if (! potentialNewSelection.getSelection()) { + if (!potentialNewSelection.getSelection()) { return; } if (potentialNewSelection.equals(selectedButton)) { @@ -171,26 +179,31 @@ private void rollbackSelection() { }); } - /** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection is about to change, by sending - * it one of the messages defined in the VetoableSelectionListener - * interface. + * Adds the listener to the collection of listeners who will be notified when + * the receiver's selection is about to change, by sending it one of the + * messages defined in the VetoableSelectionListener interface. *

* widgetSelected is called when the selection changes. - * widgetDefaultSelected is typically called when an item is double-clicked. + * widgetDefaultSelected is typically called when an item is + * double-clicked. *

* * @param listener the listener which should be notified * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_NULL_ARGUMENT - if the listener + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
* * @see VetoableSelectionListener * @see #removeVetoableSelectionListener @@ -201,18 +214,24 @@ public void addVetoableSelectionListener(VetoableSelectionListener listener) { } /** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection is about to change. + * Removes the listener from the collection of listeners who will be notified + * when the receiver's selection is about to change. * * @param listener the listener which should no longer be notified * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_NULL_ARGUMENT - if the listener + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
* * @see VetoableSelectionListener * @see #addVetoableSelectionListener @@ -221,7 +240,6 @@ public void removeVetoableSelectionListener(VetoableSelectionListener listener) widgetChangeListeners.remove(listener); } - private final List widgetSelectedListeners = new ArrayList<>(); protected void fireWidgetSelectedEvent(SelectionEvent e) { @@ -235,24 +253,30 @@ protected void fireWidgetDefaultSelectedEvent(SelectionEvent e) { } /** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, by sending - * it one of the messages defined in the SelectionListener - * interface. + * Adds the listener to the collection of listeners who will be notified when + * the receiver's selection changes, by sending it one of the messages defined + * in the SelectionListener interface. *

* widgetSelected is called when the selection changes. - * widgetDefaultSelected is typically called when an item is double-clicked. + * widgetDefaultSelected is typically called when an item is + * double-clicked. *

* * @param listener the listener which should be notified * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_NULL_ARGUMENT - if the listener + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
* * @see SelectionListener * @see #removeSelectionListener @@ -263,18 +287,24 @@ public void addSelectionListener(SelectionListener listener) { } /** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. + * Removes the listener from the collection of listeners who will be notified + * when the receiver's selection changes. * * @param listener the listener which should no longer be notified * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the listener is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_NULL_ARGUMENT - if the listener + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
* * @see SelectionListener * @see #addSelectionListener @@ -284,18 +314,21 @@ public void removeSelectionListener(SelectionListener listener) { } /** - * Deselects the item at the given zero-relative index in the receiver. - * If the item at the index was already deselected, it remains - * deselected. Indices that are out of range are ignored. + * Deselects the item at the given zero-relative index in the receiver. If the + * item at the index was already deselected, it remains deselected. Indices that + * are out of range are ignored. * * @param index the index of the item to deselect * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public void deselect (int index) { + public void deselect(int index) { if (index < 0 || index >= buttons.length) return; buttons[index].setSelection(false); @@ -304,10 +337,13 @@ public void deselect (int index) { /** * Deselects all selected items in the receiver. * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ public void deselectAll() { for (IRadioButton button : buttons) { @@ -316,17 +352,20 @@ public void deselectAll() { } /** - * Returns the zero-relative index of the item which currently - * has the focus in the receiver, or -1 if no item has focus. + * Returns the zero-relative index of the item which currently has the focus in + * the receiver, or -1 if no item has focus. * * @return the index of the selected item * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public int getFocusIndex () { + public int getFocusIndex() { for (int i = 0; i < buttons.length; i++) { if (buttons[i].isFocusControl()) { return i; @@ -336,23 +375,31 @@ public int getFocusIndex () { } /** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. + * Returns the item at the given, zero-relative index in the receiver. Throws an + * exception if the index is out of range. * * @param index the index of the item to return * @return the item at the given index * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
- * - * FIXME: tck - this should be renamed to getItemText() + * @exception IllegalArgumentException + *
    + *
  • ERROR_INVALID_RANGE - if the index is + * not between 0 and the number of elements + * in the list minus 1 (inclusive)
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
+ * + * FIXME: tck - this should be renamed to + * getItemText() */ - public String getItem (int index) { + public String getItem(int index) { if (index < 0 || index >= buttons.length) SWT.error(SWT.ERROR_INVALID_RANGE, null, "getItem for a nonexistant item"); return buttons[index].getText(); @@ -363,32 +410,37 @@ public String getItem (int index) { * * @return the number of items * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public int getItemCount () { + public int getItemCount() { return buttons.length; } /** - * Returns a (possibly empty) array of Strings which - * are the items in the receiver. + * Returns a (possibly empty) array of Strings which are the items + * in the receiver. *

- * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. + * Note: This is not the actual structure used by the receiver to maintain its + * list of items, so modifying the array will not affect the receiver. *

* * @return the items in the receiver's list * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public String[] getItems () { + public String[] getItems() { List itemStrings = new ArrayList<>(); for (IRadioButton button : buttons) { itemStrings.add(button.getText()); @@ -401,17 +453,20 @@ public Object[] getButtons() { } /** - * Returns the zero-relative index of the item which is currently - * selected in the receiver, or -1 if no item is selected. + * Returns the zero-relative index of the item which is currently selected in + * the receiver, or -1 if no item is selected. * * @return the index of the selected item or -1 * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public int getSelectionIndex () { + public int getSelectionIndex() { for (int i = 0; i < buttons.length; i++) { if (buttons[i].getSelection()) { return i; @@ -423,23 +478,27 @@ public int getSelectionIndex () { /** * Gets the index of an item. *

- * The list is searched starting at 0 until an - * item is found that is equal to the search item. - * If no item is found, -1 is returned. Indexing - * is zero based. + * The list is searched starting at 0 until an item is found that is equal to + * the search item. If no item is found, -1 is returned. Indexing is zero based. * * @param string the search item * @return the index of the item * - * @exception IllegalArgumentException

    - *
  • ERROR_NULL_ARGUMENT - if the string is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_NULL_ARGUMENT - if the string + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
*/ - public int indexOf (String string) { + public int indexOf(String string) { for (int i = 0; i < buttons.length; i++) { if (buttons[i].getText().equals(string)) { return i; @@ -449,25 +508,29 @@ public int indexOf (String string) { } /** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. + * Searches the receiver's list starting at the given, zero-relative index until + * an item is found that is equal to the argument, and returns the index of that + * item. If no item is found or the starting index is out of range, returns -1. * * @param string the search item - * @param start the zero-relative index at which to start the search + * @param start the zero-relative index at which to start the search * @return the index of the item * - * @exception IllegalArgumentException
    - *
  • ERROR_NULL_ARGUMENT - if the string is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_NULL_ARGUMENT - if the string + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
*/ - public int indexOf (String string, int start) { + public int indexOf(String string, int start) { for (int i = start; i < buttons.length; i++) { if (buttons[i].getText().equals(string)) { return i; @@ -477,59 +540,72 @@ public int indexOf (String string, int start) { } /** - * Returns true if the item is selected, - * and false otherwise. Indices out of - * range are ignored. + * Returns true if the item is selected, and false + * otherwise. Indices out of range are ignored. * * @param index the index of the item * @return the visibility state of the item at the index * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public boolean isSelected (int index) { + public boolean isSelected(int index) { return buttons[index].getSelection(); } /** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. + * Selects the item at the given zero-relative index in the receiver's list. If + * the item at the index was already selected, it remains selected. Indices that + * are out of range are ignored. * * @param index the index of the item to select * - * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the receiver has been + * disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not called from + * the thread that created the receiver
  • + *
*/ - public void select (int index) { + public void select(int index) { if (index < 0 || index >= buttons.length) return; buttons[index].setSelection(true); } /** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. This is equivalent - * to remove'ing the old item at the index, and then - * add'ing the new item at that index. + * Sets the text of the item in the receiver's list at the given zero-relative + * index to the string argument. This is equivalent to remove'ing + * the old item at the index, and then add'ing the new item at that + * index. * - * @param index the index for the item + * @param index the index for the item * @param string the new text for the item * - * @exception IllegalArgumentException
    - *
  • ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)
  • - *
  • ERROR_NULL_ARGUMENT - if the string is null
  • - *
- * @exception SWTException
    - *
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • - *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • - *
+ * @exception IllegalArgumentException + *
    + *
  • ERROR_INVALID_RANGE - if the index is + * not between 0 and the number of elements + * in the list minus 1 (inclusive)
  • + *
  • ERROR_NULL_ARGUMENT - if the string + * is null
  • + *
+ * @exception SWTException + *
    + *
  • ERROR_WIDGET_DISPOSED - if the + * receiver has been disposed
  • + *
  • ERROR_THREAD_INVALID_ACCESS - if not + * called from the thread that created the + * receiver
  • + *
*/ - public void setItem (int index, String string) { + public void setItem(int index, String string) { if (index < 0 || index >= buttons.length) SWT.error(SWT.ERROR_INVALID_RANGE, null, "setItem for a nonexistant item"); buttons[index].setText(string); @@ -553,7 +629,7 @@ public void setItem (int index, String string) { * @see org.eclipse.swt.widgets.List#deselectAll() * @see org.eclipse.swt.widgets.List#select(int) */ - public void setSelection (int index) { + public void setSelection(int index) { if (index < 0 || index > buttons.length - 1) { return; } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java index 54f5344a432..ade82bc59c6 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/radioGroup/VetoableSelectionListener.java @@ -16,18 +16,17 @@ import org.eclipse.swt.events.SelectionEvent; /** - * Interface VetoableSelectionListener. An interface for SelectionListeners - * that permit the new selection to be vetoed before widgetSelected or + * Interface VetoableSelectionListener. An interface for SelectionListeners that + * permit the new selection to be vetoed before widgetSelected or * widgetDefaultSelected is called. */ @FunctionalInterface public interface VetoableSelectionListener { /** - * Method widgetCanChangeSelection. Indicates that the selection is - * about to be changed. Setting e.doit to false will prevent the - * selection from changing. - * - * @param e The SelectionEvent that is being processed. - */ + * Method widgetCanChangeSelection. Indicates that the selection is about to be + * changed. Setting e.doit to false will prevent the selection from changing. + * + * @param e The SelectionEvent that is being processed. + */ public void canWidgetChangeSelection(SelectionEvent e); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java index 0fd4971e50b..6124fe17d0d 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet002UpdateComboRetainSelection.java @@ -170,8 +170,8 @@ public void widgetSelected(SelectionEvent e) { // This demonstrates a problem with Java generics: // It is hard to produce a class object with type List @SuppressWarnings("unchecked") - IBeanValueProperty> choices = BeanProperties - .value(ViewModel.class, "choices", (Class>) (Object) List.class); + IBeanValueProperty> choices = BeanProperties.value(ViewModel.class, "choices", + (Class>) (Object) List.class); IObservableList list = MasterDetailObservables.detailList(choices.observe(viewModel), createListDetailFactory(), String.class); diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java index a38bee917d3..845c3a1eb3f 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java @@ -108,7 +108,8 @@ public void createControl(Composite parent) { label.setText("Enter a date:"); Text text = new Text(composite, SWT.BORDER); - bindingContext.bindValue(WidgetProperties.text().observe(text), ((SampleWizard) getWizard()).getModel().dateValue); + bindingContext.bindValue(WidgetProperties.text().observe(text), + ((SampleWizard) getWizard()).getModel().dateValue); GridLayoutFactory.swtDefaults().numColumns(2).generateLayout(composite); setControl(composite); diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.java index 448a7a00f30..6004af14535 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet030DateAndTimeObservableValue.java @@ -106,10 +106,8 @@ private void bindUI() { new LocalDateTimeObservableValue(WidgetProperties.localDateSelection().observe(date), timeSelection), model); - bindingContext.bindValue( - new LocalDateTimeObservableValue(WidgetProperties.localDateSelection().observe(calendar), - timeSelection), - model); + bindingContext.bindValue(new LocalDateTimeObservableValue( + WidgetProperties.localDateSelection().observe(calendar), timeSelection), model); syncTime.addListener(SWT.Selection, event -> { Runnable runnable = new Runnable() { diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java index 5800619ec0d..f891a65ac4d 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet033CrossValidationControlDecoration.java @@ -117,7 +117,8 @@ private static class DateRangeValidator extends MultiValidator { private final IObservableValue end; private final String errorMessage; - public DateRangeValidator(IObservableValue start, IObservableValue end, String errorMessage) { + public DateRangeValidator(IObservableValue start, IObservableValue end, + String errorMessage) { this.start = start; this.end = end; this.errorMessage = errorMessage; diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet039SideEffectMigration.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet039SideEffectMigration.java index 6717dca3b98..54b14757f23 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet039SideEffectMigration.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet039SideEffectMigration.java @@ -182,7 +182,8 @@ private void bindData() { return Status.OK_STATUS; }), null); - IObservableList validationStatusProviders = bindingContext.getValidationStatusProviders(); + IObservableList validationStatusProviders = bindingContext + .getValidationStatusProviders(); for (ValidationStatusProvider statusProvider : validationStatusProviders) { ControlDecorationSupport.create(statusProvider, SWT.TOP | SWT.LEFT); } diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet042SideEffectAggregateValidationStatus.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet042SideEffectAggregateValidationStatus.java index 2dc8448a2d9..7e88eb4f635 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet042SideEffectAggregateValidationStatus.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet042SideEffectAggregateValidationStatus.java @@ -60,8 +60,7 @@ private static void run(final Display display) { IValidator validator = textValue -> "5".equals(textValue) ? Status.OK_STATUS : ValidationStatus.error("The value was '" + value + "', not '5'"); bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(text), value, - new UpdateValueStrategy().setAfterConvertValidator(validator), - null); + new UpdateValueStrategy().setAfterConvertValidator(validator), null); // Track the max severity of all bindings AggregateValidationStatus validationStatus = new AggregateValidationStatus(bindingContext.getBindings(), diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet043BindApi.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet043BindApi.java index 1d2b30de5b5..103146a6407 100644 --- a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet043BindApi.java +++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet043BindApi.java @@ -108,8 +108,8 @@ private static Shell createShell() { // can get a validation result without blocking the value being updated. Bind.oneWay() // .from(value) // - .validateAfterGet(fiveValidator) - .defaultConvert() // This triggers default converters in DataBindingContext + .validateAfterGet(fiveValidator).defaultConvert() // This triggers default converters in + // DataBindingContext .to(Observables.constantObservableValue(null)) // Dummy value for convert only binding .convertOnly() // .bind(bindingContext);