Skip to content

Commit

Permalink
Apply Eclipse formatter on jface databinding examples
Browse files Browse the repository at this point in the history
This make reading and modifiy the examples easier and that is the main
purpose of these examples
  • Loading branch information
vogella committed Dec 9, 2024
1 parent 5c65cbc commit 0449ac3
Show file tree
Hide file tree
Showing 35 changed files with 516 additions and 497 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.core.databinding.observable.set.IObservableSet;


/**
* This object will be given randomly-generated children
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ public class StructuredContentProviderTest {
private WritableValue<Integer> 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<Double> 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;

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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<Integer> model, String string,
final int value) {
Expand All @@ -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());
Expand All @@ -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<Double> inputSet) {
private Control createInputControl(Composite parent, final WritableSet<Double> 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<Double> selectedInt = ViewerProperties.singleSelection(Double.class)
.observe(listOfInts);
final IObservableValue<Double> selectedInt = ViewerProperties.singleSelection(Double.class).observe(listOfInts);

GridData listData = new GridData(GridData.FILL_BOTH);
listData.minimumHeight = 1;
Expand All @@ -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$
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,59 @@
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.
* <p>
* 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
*/
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.
*/
public Object duckType_GetWrappedValue();
}

/**
* 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.<p>
* 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.
* <p>
*
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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)
Expand All @@ -77,13 +76,11 @@ 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.
*/
public Class<?> getType() {
return method.getReturnType();
}
}


Loading

0 comments on commit 0449ac3

Please sign in to comment.