Search in sources :

Example 16 with Realm

use of org.eclipse.core.databinding.observable.Realm in project eclipse.platform.ui by eclipse-platform.

the class MultiValidatorTest method testObserveValidatedValue_WrongRealm.

@Test
public void testObserveValidatedValue_WrongRealm() {
    Realm otherRealm = new CurrentRealm(true);
    try {
        validator.observeValidatedValue(new WritableValue<>(otherRealm));
        fail("Expected AssertionFailedException");
    } catch (AssertionFailedException expected) {
    }
}
Also used : Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) Test(org.junit.Test)

Example 17 with Realm

use of org.eclipse.core.databinding.observable.Realm in project eclipse.platform.ui by eclipse-platform.

the class AbstractObservableValueTest method testSetValueInvokesDoSetValue.

@Test
public void testSetValueInvokesDoSetValue() throws Exception {
    class ValueStub extends ObservableValueStub {

        int doSetValue;

        ValueStub(Realm realm) {
            super(realm);
        }

        @Override
        protected void doSetValue(Object value) {
            doSetValue++;
        }
    }
    Realm realm = new CurrentRealm(true);
    ValueStub stub = new ValueStub(realm);
    assertEquals(0, stub.doSetValue);
    stub.setValue(new Object());
    assertEquals("doSetValue should have been invoked", 1, stub.doSetValue);
}
Also used : Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 18 with Realm

use of org.eclipse.core.databinding.observable.Realm in project eclipse.platform.ui by eclipse-platform.

the class AbstractVetoableValueTest method testSetValueInvokesDoSetApprovedValue.

@Test
public void testSetValueInvokesDoSetApprovedValue() throws Exception {
    class VetoableValue extends VetoableValueStub {

        int count;

        Object value;

        VetoableValue(Realm realm) {
            super(realm);
        }

        @Override
        protected void doSetApprovedValue(Object value) {
            count++;
            this.value = value;
        }
    }
    Realm realm = new CurrentRealm(true);
    VetoableValue vetoableValue = new VetoableValue(realm);
    assertEquals(0, vetoableValue.count);
    assertEquals(null, vetoableValue.value);
    Object value = new Object();
    vetoableValue.setValue(value);
    assertEquals(1, vetoableValue.count);
    assertEquals(value, vetoableValue.value);
}
Also used : AbstractVetoableValue(org.eclipse.core.databinding.observable.value.AbstractVetoableValue) Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 19 with Realm

use of org.eclipse.core.databinding.observable.Realm in project eclipse.platform.ui by eclipse-platform.

the class RealmTest method testSetDefaultWithRunnable.

@Test
public void testSetDefaultWithRunnable() throws Exception {
    Realm oldRealm = new CurrentRealm(true);
    final Realm newRealm = new CurrentRealm(true);
    RealmTester.setDefault(oldRealm);
    Realm.runWithDefault(newRealm, () -> assertEquals("new realm should be default", newRealm, Realm.getDefault()));
    assertEquals("old realm should have been restored", oldRealm, Realm.getDefault());
}
Also used : Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 20 with Realm

use of org.eclipse.core.databinding.observable.Realm in project KLighD by kieler.

the class ScalingBlock method createContents.

/**
 * Creates the 'Scaling' 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) {
    // create the scaling group
    final Group result = DialogUtil.group(parent, KlighdUIPrintingMessages.PrintDialog_Scaling);
    DialogUtil.layout(result, 1);
    // This group contains three composites to be independent from the gridlayout's columns in
    // each row.
    // Group containing 3 buttons:
    // - scale to 100%
    // - scale to fit pages
    // - adjust number of pages to fit diagram
    final Composite buttonsGroup = new Composite(result, SWT.NONE);
    DialogUtil.layoutFillHorizontal(buttonsGroup, true);
    buttonsGroup.setLayout(new GridLayout(BUTTONS_GROUP_COLUMNS, false));
    final Button oneToOneBtn = DialogUtil.button(buttonsGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_to100);
    final Button fitToPagesBtn = DialogUtil.button(buttonsGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_fitPages);
    final Button adjustPagesBtn = DialogUtil.button(buttonsGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_adjustPages);
    // Group containing a spinner and some text labels for scale settings.
    final Composite scalingGroup = new Composite(result, SWT.NONE);
    DialogUtil.layoutFillHorizontal(scalingGroup, true);
    scalingGroup.setLayout(new GridLayout(SCALING_GROUP_COLUMNS, false));
    DialogUtil.label(scalingGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_lbl_scaleTo);
    final Spinner scaleSpinner = DialogUtil.spinner(scalingGroup, 1, Integer.MAX_VALUE);
    DialogUtil.layoutFillHorizontal(scaleSpinner, true);
    DialogUtil.label(scalingGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_lbl_percent);
    // Group containing two spinners (and describing labels)
    // to set the number of pages tall and wide to print on.
    final Composite pagesGroup = new Composite(result, SWT.NONE);
    DialogUtil.layoutFillHorizontal(pagesGroup, true);
    pagesGroup.setLayout(new GridLayout(PAGES_GROUP_COLUMNS, false));
    DialogUtil.label(pagesGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_lbl_printTo);
    final Spinner spinnerWide = DialogUtil.spinner(pagesGroup, 1, MAX_PAGES);
    DialogUtil.layoutWidth(spinnerWide, spinnerWide.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    DialogUtil.label(pagesGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_lbl_pagesWide);
    final Spinner spinnerTall = DialogUtil.spinner(pagesGroup, 1, MAX_PAGES);
    DialogUtil.layoutWidth(spinnerTall, spinnerTall.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
    DialogUtil.label(pagesGroup, KlighdUIPrintingMessages.PrintDialog_Scaling_lbl_pagesTall);
    final DiagramPrintOptions dOptions;
    if (options instanceof DiagramPrintOptions) {
        dOptions = (DiagramPrintOptions) options;
        oneToOneBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                scaleOneToOne(dOptions);
            }
        });
        fitToPagesBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                fitToPages(dOptions);
            }
        });
        adjustPagesBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                // Calculate for both horizontal and vertical directions
                // how many pages are necessary to fit the diagram in.
                final PrintExporter exporter = dOptions.getExporter();
                final Dimension2D trimmedPrinterBounds = exporter.getTrimmedTileBounds(dOptions);
                final Dimension2D diagramBounds = exporter.getDiagramBoundsIncludingTrim();
                dOptions.setPagesWide((int) Math.ceil(diagramBounds.getWidth() * dOptions.getScaleFactor() / trimmedPrinterBounds.getWidth()));
                dOptions.setPagesTall((int) Math.ceil(diagramBounds.getHeight() * dOptions.getScaleFactor() / trimmedPrinterBounds.getHeight()));
            }
        });
        final Realm realm = bindings.getValidationRealm();
        final IObservableValue<Object> scalePercent = BeanProperties.value(dOptions.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_SCALE_PERCENT).observe(realm, dOptions);
        ISWTObservableValue<Object> observerScaleSpinner = WidgetProperties.selection().observe(scaleSpinner);
        bindings.bindValue(observerScaleSpinner, scalePercent);
        final IObservableValue<Object> pagesWide = BeanProperties.value(dOptions.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_PAGES_WIDE).observe(realm, dOptions);
        ISWTObservableValue<Object> observerWideSpinner = WidgetProperties.selection().observe(spinnerWide);
        bindings.bindValue(observerWideSpinner, pagesWide);
        final IObservableValue<Object> pagesTall = BeanProperties.value(dOptions.getClass().asSubclass(DiagramPrintOptions.class), PrintOptions.PROPERTY_PAGES_TALL).observe(realm, dOptions);
        ISWTObservableValue<Object> observerTallSpinner = WidgetProperties.selection().observe(spinnerTall);
        bindings.bindValue(observerTallSpinner, pagesTall);
        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
                scalePercent.dispose();
                pagesWide.dispose();
                pagesTall.dispose();
            }
        });
    } else {
        // in case the 'options' field is null, i.e. this instance is not linked to an instance of
        // 'DiagramPrintOptions',
        // deactivate all the controls as they do not make sense for printing non-diagram content
        // (some customers asked for this feature in order to provide consistent print dialogs
        // for all kinds of printable content)
        result.setEnabled(false);
        for (final Control c : result.getChildren()) {
            c.setEnabled(false);
            if (c instanceof Composite) {
                for (final Control d : ((Composite) c).getChildren()) {
                    d.setEnabled(false);
                }
            }
        }
    }
    return result;
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Dimension2D(java.awt.geom.Dimension2D) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) DiagramPrintOptions(de.cau.cs.kieler.klighd.ui.printing.DiagramPrintOptions) Button(org.eclipse.swt.widgets.Button) PrintExporter(de.cau.cs.kieler.klighd.ui.printing.PrintExporter) 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)

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