use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.
the class OrientationBlock method createContents.
/**
* Creates the 'Orientation' block contents.
* The bindings are used to bind observable GUI elements to print setting in the given options.
*
* @param parent
* the parent {@link Composite} to use
* @param bindings
* the bindings used for observables
* @param options
* the current print options
* @return the created {@link Group}
*/
public static Group createContents(final Composite parent, final DataBindingContext bindings, final PrintOptions options) {
final int columns = 1;
// create group
final Group result = DialogUtil.group(parent, KlighdUIPrintingMessages.PrintDialog_Orientation_orientation);
DialogUtil.layout(result, columns);
// radio button for portrait
final Button portraitRadio = DialogUtil.radio(result, KlighdUIPrintingMessages.PrintDialog_Orientation_portrait);
DialogUtil.layoutSpanHorizontal(portraitRadio, columns);
// radio button for landscape
final Button landscapeRadio = DialogUtil.radio(result, KlighdUIPrintingMessages.PrintDialog_Orientation_landscape);
DialogUtil.layoutSpanHorizontal(landscapeRadio, columns);
final Realm realm = bindings.getValidationRealm();
final SelectObservableValue<Integer> orientationGroupValue = new SelectObservableValue<>(realm);
ISWTObservableValue<Boolean> observerPortrait = WidgetProperties.selection().observe(portraitRadio);
orientationGroupValue.addOption(PrinterData.PORTRAIT, observerPortrait);
ISWTObservableValue<Boolean> observeLandscape = WidgetProperties.selection().observe(landscapeRadio);
orientationGroupValue.addOption(PrinterData.LANDSCAPE, observeLandscape);
IObservableValue<Object> observeOrientation = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_ORIENTATION).observe(realm, options);
bindings.bindValue(orientationGroupValue, observeOrientation);
result.addListener(SWT.Dispose, new Listener() {
public void handleEvent(final Event event) {
// although the 'option SWTObservables' are automatically disposed via the radio buttons
// the 'SelectObservableValue' is not, so...
orientationGroupValue.dispose();
}
});
return result;
}
use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.
the class PrintPreviewTray method createContents.
/**
* {@inheritDoc}
*/
@Override
public Control createContents(final Composite parent) {
final Realm realm = bindings.getValidationRealm();
body = new Composite(parent, SWT.NONE);
body.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
body.setSize(parent.getSize());
composite = new Composite(body, SWT.NULL);
updateComposite();
final IValueChangeListener<Object> listener = new IValueChangeListener<Object>() {
public void handleValueChange(final ValueChangeEvent<? extends Object> event) {
updateComposite();
}
};
ISWTObservableValue<Point> observedSize = WidgetProperties.size().observe(body);
final IObservableValue<Point> delayedResize = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedSize);
delayedResize.addValueChangeListener(listener);
IObservableValue<Object> observedData = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_PRINTER_DATA).observe(realm, options);
final IObservableValue<Object> delayedPrinterData = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedData);
delayedPrinterData.addValueChangeListener(listener);
IObservableValue<Object> observedScale = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_SCALE_FACTOR).observe(realm, options);
final IObservableValue<Object> delayedScale = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedScale);
delayedScale.addValueChangeListener(listener);
IObservableValue<Object> observedPagesWide = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_PAGES_WIDE).observe(realm, options);
final IObservableValue<Object> delayedPagesWide = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedPagesWide);
delayedPagesWide.addValueChangeListener(listener);
IObservableValue<Object> observedScaleTall = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_PAGES_TALL).observe(realm, options);
final IObservableValue<Object> delayedPagesTall = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedScaleTall);
delayedPagesTall.addValueChangeListener(listener);
IObservableValue<Object> observedHorCenter = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_CENTER_HORIZONTALLY).observe(realm, options);
final IObservableValue<Object> delayedHorCentered = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedHorCenter);
delayedHorCentered.addValueChangeListener(listener);
IObservableValue<Object> observedVertCenter = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_CENTER_VERTICALLY).observe(realm, options);
final IObservableValue<Object> delayedVerCentered = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedVertCenter);
delayedVerCentered.addValueChangeListener(listener);
IObservableValue<Object> observedOrientation = BeanProperties.value(options.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_ORIENTATION).observe(realm, options);
final IObservableValue<Object> delayedOrientation = Observables.observeDelayedValue(OBSERVABLE_DELAY, observedOrientation);
delayedOrientation.addValueChangeListener(listener);
body.addListener(SWT.Dispose, new Listener() {
public void handleEvent(final Event event) {
delayedResize.dispose();
delayedPrinterData.dispose();
delayedScale.dispose();
delayedPagesWide.dispose();
delayedPagesTall.dispose();
delayedHorCentered.dispose();
delayedVerCentered.dispose();
delayedOrientation.dispose();
}
});
return body;
}
use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.
the class PrinterBlock method createContents.
/**
* Creates the 'Printer' block contents.
* The bindings are used to bind observable GUI elements to print setting in the given options.
*
* @param parent
* the parent {@link Composite} to use
* @param bindings
* the {@link DataBindingContext} managing the employed
* {@link org.eclipse.core.databinding.Binding Bindings}
* @param options
* the {@link PrintOptions} to be used
* @param printDialog
* the parent dialog used for the system print dialog
* @return the created {@link Group}
*/
public static Group createContents(final Composite parent, final DataBindingContext bindings, final PrintOptions options, final KlighdPrintDialog printDialog) {
final int columns = 3;
// create group
final Group result = DialogUtil.group(parent, KlighdUIPrintingMessages.PrintDialog_Printer);
DialogUtil.layout(result, columns);
// printer resp. file name label
DialogUtil.label(result, KlighdUIPrintingMessages.PrintDialog_Name);
final Label printerLabel = DialogUtil.label(result, "");
DialogUtil.layoutFillHorizontal(printerLabel, true);
final Realm realm = bindings.getValidationRealm();
// Observable to display the printer resp. file name, if print to file is set.
final ComputedValue<String> computedValue = new ComputedValue<String>(realm) {
@Override
protected String calculate() {
final PrinterData data = (PrinterData) BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_PRINTER_DATA).observe(realm, options).getValue();
if (data.printToFile) {
return data.fileName;
} else {
return data.name;
}
}
};
final ISWTObservableValue<String> labelText = WidgetProperties.text().observe(printerLabel);
bindings.bindValue(labelText, computedValue);
// printer properties button
final Button propertiesButton = DialogUtil.button(result, KlighdUIPrintingMessages.PrintDialog_PrinterSettings);
propertiesButton.setEnabled(true);
propertiesButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
// Open the system's native print dialog to gather printer specific settings.
// If no valid setting are returned (e.g. the user cancels the dialog),
// nothing is changed.
final PrintDialog systemPrintDialog = printDialog.getNativePrintDialog();
systemPrintDialog.setPrinterData(options.getPrinterData());
final PrinterData data = systemPrintDialog.open();
if (data != null) {
options.setPrinterData(data);
}
}
});
result.addListener(SWT.Dispose, new Listener() {
public void handleEvent(final Event event) {
// while the SWTObservableValues are disposed while disposing the corresponding widgets
// the ComputedValue should be disposed explicitly
computedValue.dispose();
}
});
return result;
}
use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.
the class RangeBlock method createContents.
/**
* Creates the 'Range' block contents.
* The bindings are used to bind observable GUI elements to print setting in the given options.
*
* @param parent
* the parent {@link Composite} to use
* @param bindings
* the {@link DataBindingContext} managing the employed
* {@link org.eclipse.core.databinding.Binding Bindings}
* @param options
* the {@link PrintOptions} to be used
* @return the created {@link Group}
*/
public static Group createContents(final Composite parent, final DataBindingContext bindings, final PrintOptions options) {
final int columns = 2;
final int textWidth = 20;
final Realm realm = bindings.getValidationRealm();
// create group
final Group result = DialogUtil.group(parent, KlighdUIPrintingMessages.PrintDialog_PrintRange);
DialogUtil.layout(result, columns);
// radio button for print all
final Button allRadio = DialogUtil.radio(result, KlighdUIPrintingMessages.PrintDialog_All);
DialogUtil.layoutSpanHorizontal(allRadio, columns);
final IObservableValue<Object> allValue = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_ALL_PAGES).observe(realm, options);
ISWTObservableValue<Object> observedAllPages = WidgetProperties.selection().observe(allRadio);
bindings.bindValue(observedAllPages, allValue);
// radio button for defining a print range
final Button rangeRadio = DialogUtil.radio(result, KlighdUIPrintingMessages.PrintDialog_Pages);
DialogUtil.layoutSpanHorizontal(rangeRadio, columns);
// the following ComputedValue is required for properly initializing the selection of
// 'rangeRadio', which won't be done if 'rangeValue' would be initialized with just
// 'SWTObservables.observeSelection(rangeRadio)' (during initialization from preferences
// as well as changes performed in the native print dialog);
// note that the executions of 'calculate' are monitored and calls of 'allValue.getValue()'
// cause the attachment of valueChangeListeners on 'allValue' notifying 'rangeValue'
// interestingly a set operation on 'rangeRadio', which would then cause a set operation
// on 'rangeValue', leads to a (caught) exception in AbstractObservableValue#doSetValue()
// since that method is not overridden by 'ComputedValue';
// the update of 'rangeValue' is than caused by the de-selection of 'allValue' leading to
// a re-computation of rangValue by means of the above mentioned listeners (crazy shit ...);
// the than calculated result is used below for enabling the "from" & "to" text fields.
final IObservableValue<Boolean> rangeValue = new ComputedValue<Boolean>(realm) {
@Override
protected Boolean calculate() {
return ((Boolean) allValue.getValue()).booleanValue() ? Boolean.FALSE : Boolean.TRUE;
}
};
ISWTObservableValue<Object> selection = WidgetProperties.selection().observe(rangeRadio);
bindings.bindValue(selection, rangeValue);
// range from (label & textfield)
DialogUtil.layoutHorizontalIndent(DialogUtil.label(result, KlighdUIPrintingMessages.PrintDialog_From));
final Text textFrom = DialogUtil.text(result, textWidth);
final IObservableValue<Object> rangeFrom = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_RANGE_FROM).observe(realm, options);
ISWTObservableValue<String> observedModifiedTextFrom = WidgetProperties.text(SWT.Modify).observe(textFrom);
bindings.bindValue(observedModifiedTextFrom, rangeFrom);
ISWTObservableValue<Boolean> observedEnabledFrom = WidgetProperties.enabled().observe(textFrom);
bindings.bindValue(observedEnabledFrom, rangeValue);
// range to (label & textfield)
DialogUtil.layoutHorizontalIndent(DialogUtil.label(result, KlighdUIPrintingMessages.PrintDialog_To));
final Text textTo = DialogUtil.text(result, textWidth);
final IObservableValue<Object> rangeTo = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_RANGE_TO).observe(realm, options);
ISWTObservableValue<String> observedModifyTextTo = WidgetProperties.text(SWT.Modify).observe(textTo);
bindings.bindValue(observedModifyTextTo, rangeTo);
ISWTObservableValue<Boolean> observedEnabledTo = WidgetProperties.enabled().observe(textTo);
bindings.bindValue(observedEnabledTo, rangeValue);
result.addListener(SWT.Dispose, new Listener() {
public void handleEvent(final Event event) {
// while the SWTObservableValues are disposed while disposing the corresponding widgets
// the Beans-based ones should be disposed explicitly
allValue.dispose();
rangeValue.dispose();
rangeFrom.dispose();
rangeTo.dispose();
}
});
return result;
}
use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.
the class AlignmentBlock method createContents.
/**
* Creates the 'Alignment' block contents. The bindings are used to bind observable GUI elements
* to print setting in the given options.
*
* @param parent
* the parent {@link Composite} to use
* @param bindings
* the {@link DataBindingContext} managing the employed
* {@link org.eclipse.core.databinding.Binding Bindings}
* @param options
* the {@link PrintOptions} to be used
* @return the created {@link Group}
*/
public static Group createContents(final Composite parent, final DataBindingContext bindings, final PrintOptions options) {
final int columns = 2;
// create group
final Group result = DialogUtil.group(parent, KlighdUIPrintingMessages.PrintDialog_Alignment);
DialogUtil.layout(result, columns);
DialogUtil.label(result, "Center diagram");
final Button centerHorizontally = DialogUtil.check(result, KlighdUIPrintingMessages.PrintDialog_Alignment_centerHorizontally);
// a helper widget filling the 3rd quadrant
DialogUtil.label(result, "").setVisible(false);
final Button centerVertically = DialogUtil.check(result, KlighdUIPrintingMessages.PrintDialog_Alignment_centerVertically);
final Realm realm = bindings.getValidationRealm();
final IObservableValue<Object> centerHorValue = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_CENTER_HORIZONTALLY).observe(realm, options);
ISWTObservableValue<Object> horObservation = WidgetProperties.selection().observe(centerHorizontally);
bindings.bindValue(horObservation, centerHorValue);
final IObservableValue<Object> centerVerValue = BeanProperties.value(options.getClass().asSubclass(PrintOptions.class), PrintOptions.PROPERTY_CENTER_VERTICALLY).observe(realm, options);
ISWTObservableValue<Object> vertObservation = WidgetProperties.selection().observe(centerVertically);
bindings.bindValue(vertObservation, centerVerValue);
result.addListener(SWT.Dispose, new Listener() {
public void handleEvent(final Event event) {
// while the SWTObservableValues are disposed while disposing the corresponding widgets
// the Beans-based ones should be disposed explicitly
centerHorValue.dispose();
centerVerValue.dispose();
}
});
return result;
}
Aggregations