Search in sources :

Example 6 with Realm

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectObservableValue(org.eclipse.core.databinding.observable.value.SelectObservableValue) Listener(org.eclipse.swt.widgets.Listener) Button(org.eclipse.swt.widgets.Button) Event(org.eclipse.swt.widgets.Event) Realm(org.eclipse.core.databinding.observable.Realm)

Example 7 with Realm

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;
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Event(org.eclipse.swt.widgets.Event) Point(org.eclipse.swt.graphics.Point) Realm(org.eclipse.core.databinding.observable.Realm)

Example 8 with Realm

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) ComputedValue(org.eclipse.core.databinding.observable.value.ComputedValue) Listener(org.eclipse.swt.widgets.Listener) PrintDialog(org.eclipse.swt.printing.PrintDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Button(org.eclipse.swt.widgets.Button) PrinterData(org.eclipse.swt.printing.PrinterData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Realm(org.eclipse.core.databinding.observable.Realm)

Example 9 with Realm

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) ComputedValue(org.eclipse.core.databinding.observable.value.ComputedValue) Listener(org.eclipse.swt.widgets.Listener) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Event(org.eclipse.swt.widgets.Event) Realm(org.eclipse.core.databinding.observable.Realm)

Example 10 with Realm

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;
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) Button(org.eclipse.swt.widgets.Button) Event(org.eclipse.swt.widgets.Event) Realm(org.eclipse.core.databinding.observable.Realm)

Aggregations

Realm (org.eclipse.core.databinding.observable.Realm)22 Test (org.junit.Test)10 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)8 Event (org.eclipse.swt.widgets.Event)7 Listener (org.eclipse.swt.widgets.Listener)7 DisplayRealm (org.eclipse.jface.databinding.swt.DisplayRealm)6 Button (org.eclipse.swt.widgets.Button)6 Group (org.eclipse.swt.widgets.Group)6 Text (org.eclipse.swt.widgets.Text)3 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)2 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)2 ComputedValue (org.eclipse.core.databinding.observable.value.ComputedValue)2 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)2 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)2 ThreadRealm (org.eclipse.core.tests.databinding.observable.ThreadRealm)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2