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) {
}
}
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);
}
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);
}
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());
}
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;
}
Aggregations