Example usage for org.eclipse.jface.databinding.swt SWTObservables getRealm

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables getRealm

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables getRealm.

Prototype

@Deprecated
public static Realm getRealm(final Display display) 

Source Link

Document

Returns the realm representing the UI thread for the given display.

Usage

From source file:org.eclipse.emf.ecp.makeithappen.application.sample.rap.j2ee.RealmSetter.java

License:Open Source License

/**
 * Initialize the RealmSetter.//from   ww  w.  jav  a 2 s.c  o m
 */
public static void initialize() {
    final UISession uiSession = RWT.getUISession();
    ApplicationContextImpl.class.cast(RWT.getApplicationContext()).getPhaseListenerManager()
            .addPhaseListener(new DataBindingPhaseListener());
    if (uiSession.getAttribute("realm") == null) { //$NON-NLS-1$
        final Realm realm = SWTObservables.getRealm(Display.getCurrent());
        RealmSetter.setRealm(realm);
        RWT.getUISession().setAttribute("realm", realm); //$NON-NLS-1$
    }
}

From source file:org.eclipse.emf.ecp.view.demo.rap.internal.MainUi.java

License:Open Source License

protected void setupRealm(Display display) {
    final UISession uiSession = RWT.getUISession();
    if (uiSession.getAttribute("realm") == null) {
        final Realm realm = SWTObservables.getRealm(display);
        RealmSetter.setRealm(realm);/*from  ww  w.  ja  v a  2s . c o m*/
        RWT.getUISession().setAttribute("realm", realm);
    }
}

From source file:org.eclipse.emf.ecp.view.test.common.swt.DatabindingClassRunner.java

License:Open Source License

@Override
public void run(final RunNotifier notifier) {
    final Display display = Display.getDefault();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            DatabindingClassRunner.super.run(notifier);
        }/*from w w  w  .j a  v a 2s  . c om*/
    });
}

From source file:org.eclipse.gmf.runtime.diagram.ui.printing.render.dialogs.JPSPrintDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    bindings = new DataBindingContext(SWTObservables.getRealm(parent.getDisplay()));

    Composite result = new Composite(parent, SWT.NONE);
    DialogBlock.layout(result, 2);//  www . ja  v  a 2s  .  c  o m

    createPrinterBlockArea(result);
    createDiagramPrintRangeBlockArea(result);
    createScalingBlockArea(result);
    createRangeBlockArea(result);
    createCopiesBlockArea(result);
    createActionsBlockArea(result);
    createExtensibleBlockArea(result);

    return result;
}

From source file:org.eclipse.nebula.snippets.radiogroup.RadioGroupViewerSnippet01.java

License:Open Source License

public static void main(String[] arrrrgs) {
    final Display display = new Display();

    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            Shell shell = createShell();

            shell.open();//from  w ww  .  j a v  a2 s  . c om
            while (!shell.isDisposed())
                if (!display.readAndDispatch())
                    display.sleep();

            display.dispose();
        }
    });
}

From source file:org.eclipse.papyrus.xwt.XWTLoader.java

License:Open Source License

public Realm getRealm() {
    if (realm != null) {
        return realm;
    }//from  w ww .j a  v  a  2  s. com
    Display display = Display.getCurrent();
    if (display == null) {
        display = Display.getDefault();
    }
    return SWTObservables.getRealm(display);
}

From source file:org.eclipse.rap.demo.databinding.nestedselection.TestMasterDetailView.java

License:Open Source License

private void bind(final Control parent) {
    Realm realm = SWTObservables.getRealm(parent.getDisplay());
    TableViewer peopleViewer = new TableViewer(personsTable);
    ObservableListContentProvider peopleViewerContent = new ObservableListContentProvider();
    peopleViewer.setContentProvider(peopleViewerContent);

    String[] attrSimplePerson = new String[] { "name", "state" };
    IObservableMap[] attributeMaps = BeansObservables.observeMaps(peopleViewerContent.getKnownElements(),
            SimplePerson.class, attrSimplePerson);
    ObservableMapLabelProvider omlProvider = new ObservableMapLabelProvider(attributeMaps);
    peopleViewer.setLabelProvider(omlProvider);
    peopleViewer.setInput(new WritableList(realm, model.getPersonList(), SimpleModel.class));
    IObservableValue selectedPerson = ViewersObservables.observeSingleSelection(peopleViewer);
    DataBindingContext dbc = new DataBindingContext(realm) {
        protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(IObservableValue fromValue,
                IObservableValue toValue) {
            return new CustomUpdateValueStrategy();
        }/*from  www  . j  a  v  a  2  s  .  c o m*/
    };
    IConverter upperCaseConverter = new IConverter() {
        public Object convert(Object fromObject) {
            return ((String) fromObject).toUpperCase();
        }

        public Object getFromType() {
            return String.class;
        }

        public Object getToType() {
            return String.class;
        }
    };
    IValidator vowelValidator = new IValidator() {
        public IStatus validate(Object value) {
            String s = (String) value;
            if (!s.matches("[aeiouAEIOU]*")) {
                return ValidationStatus.error("only vowels allowed");
            }
            return Status.OK_STATUS;
        }
    };

    IObservableValue modelObservableValue = BeansObservables.observeDetailValue(realm, selectedPerson, "name",
            String.class);
    ISWTObservableValue targetObservableValue = SWTObservables.observeText(name, SWT.Modify);
    CustomUpdateValueStrategy customUpdateValueStrategy = new CustomUpdateValueStrategy();
    customUpdateValueStrategy.setConverter(upperCaseConverter);
    UpdateValueStrategy targetToModel = customUpdateValueStrategy.setAfterGetValidator(vowelValidator);
    Binding binding = dbc.bindValue(targetObservableValue, modelObservableValue, targetToModel, null);

    UpdateValueStrategy updateValueStrategy = new UpdateValueStrategy();
    updateValueStrategy.setConverter(new ObjectToStringConverter());
    dbc.bindValue(SWTObservables.observeText(validationStatus, SWT.NONE), binding.getValidationStatus(), null,
            updateValueStrategy);
    dbc.bindValue(SWTObservables.observeText(address, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "address", String.class), null, null);
    dbc.bindValue(SWTObservables.observeText(city, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "city", String.class), null, null);
    dbc.bindValue(SWTObservables.observeText(state, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "state", String.class), null, null);
    TableViewer ordersViewer = new TableViewer(ordersTable);
    ObservableListContentProvider ordersViewerContent = new ObservableListContentProvider();
    ordersViewer.setContentProvider(ordersViewerContent);
    String[] propertyNames = new String[] { "orderNumber", "date" };
    IObservableMap[] observeMaps = BeansObservables.observeMaps(ordersViewerContent.getKnownElements(),
            SimpleOrder.class, propertyNames);
    ObservableMapLabelProvider observableMapLabelProvider = new ObservableMapLabelProvider(observeMaps);
    ordersViewer.setLabelProvider(observableMapLabelProvider);
    IObservableList orders = BeansObservables.observeDetailList(realm, selectedPerson, "orders",
            SimpleOrder.class);
    ordersViewer.setInput(orders);
}

From source file:org.eclipse.rap.demo.databinding.Snippet000HelloWorld.java

License:Open Source License

public void createPartControl() {
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = DatabindingSnippetsView.GROUP_MARGIN_HEIGHT;
    formLayout.marginWidth = DatabindingSnippetsView.GROUP_MARGIN_WIDTH;
    setLayout(formLayout);/*from  ww  w .ja  v  a  2 s. com*/
    setText("Hello World Snippet 0001 - Binding Example");
    // Info Label
    Label info1 = new Label(this, SWT.NONE);
    info1.setText("This Textbox is linked to the Model (Person/Name). "
            + "If you type in a text, it automatically updates " + "the name property of the model");
    FormData data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info1.setLayoutData(data);
    name = new Text(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(info1, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    name.setLayoutData(data);
    Label info2 = new Label(this, SWT.NONE);
    info2.setText("This Label is also linked (readonly) to the Model." + " It gets updated on all changes");
    data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(name, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info2.setLayoutData(data);
    labelName = new Label(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(info2, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    labelName.setLayoutData(data);
    labelName.setText("not changed yet...");

    Realm realm = SWTObservables.getRealm(Display.getCurrent());
    DataBindingContext bindingContext = new DataBindingContext(realm);
    Person person = viewModel.getPerson();
    bindingContext.bindValue(SWTObservables.observeText(name, SWT.Modify),
            BeansObservables.observeValue(realm, person, "name"), null, null);
    bindingContext.bindValue(SWTObservables.observeText(labelName),
            BeansObservables.observeValue(realm, person, "name"), null, null);
}

From source file:org.eclipse.rap.demo.databinding.Snippet001NestedSelectionWithCombo.java

License:Open Source License

public void createPartControl() {
    // Initiating the realm
    Realm realm = SWTObservables.getRealm(Display.getCurrent());

    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = DatabindingSnippetsView.GROUP_MARGIN_HEIGHT;
    formLayout.marginWidth = DatabindingSnippetsView.GROUP_MARGIN_WIDTH;
    setLayout(formLayout);//from ww w  .  j  a v  a  2 s. c o  m
    setText("Nested Selection Snippet 001 - Binding Example");
    // Info Label
    Label info1 = new Label(this, SWT.NONE);
    info1.setText("This snippet demonstrates the databinding" + " using a Lists and Combos");
    FormData data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info1.setLayoutData(data);
    Label info2 = new Label(this, SWT.NONE);
    info2.setText("Modifications in the TextBox and the" + " Combobox will update the model "
            + "(for the selection in the list).");
    data = new FormData(DatabindingSnippetsView.UNDEFINDED, SWT.DEFAULT);
    data.top = new FormAttachment(info1, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info2.setLayoutData(data);
    List peopleList = new List(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH, SWT.DEFAULT);
    data.top = new FormAttachment(info2, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    peopleList.setLayoutData(data);
    ListViewer peopleListViewer = new ListViewer(peopleList);
    IObservableSet staticObservableSet = Observables.staticObservableSet(realm,
            new HashSet(viewModel.getPeople()));
    IObservableMap attributeMap = BeansObservables.observeMap(staticObservableSet, Person.class, "name");
    ObservableMapLabelProvider omlProvider = new ObservableMapLabelProvider(attributeMap);
    peopleListViewer.setLabelProvider(omlProvider);
    peopleListViewer.setContentProvider(new ArrayContentProvider());
    peopleListViewer.setInput(viewModel.getPeople());
    Text name = new Text(this, SWT.BORDER);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH, SWT.DEFAULT);
    data.top = new FormAttachment(peopleList, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    name.setLayoutData(data);
    Combo city = new Combo(this, SWT.BORDER | SWT.READ_ONLY);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH, SWT.DEFAULT);
    data.top = new FormAttachment(name, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    city.setLayoutData(data);

    DataBindingContext dbc = new DataBindingContext(realm);
    IObservableValue selectedPerson = ViewersObservables.observeSingleSelection(peopleListViewer);
    dbc.bindValue(SWTObservables.observeText(name, SWT.Modify),
            BeansObservables.observeDetailValue(realm, selectedPerson, "name", String.class), null, null);
    ComboViewer cityViewer = new ComboViewer(city);
    cityViewer.setContentProvider(new ArrayContentProvider());
    cityViewer.setInput(viewModel.getCities());
    IObservableValue citySelection = ViewersObservables.observeSingleSelection(cityViewer);
    dbc.bindValue(citySelection,
            BeansObservables.observeDetailValue(realm, selectedPerson, "city", String.class), null, null);
}

From source file:org.eclipse.rap.demo.databinding.Snippet004DataBindingContextErrorLabel.java

License:Open Source License

public void createPartControl() {
    // Initiating the realm
    Realm realm = SWTObservables.getRealm(Display.getCurrent());
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = DatabindingSnippetsView.GROUP_MARGIN_HEIGHT;
    formLayout.marginWidth = DatabindingSnippetsView.GROUP_MARGIN_WIDTH;
    setLayout(formLayout);/*from w  ww  .  j a  va2s  .c o m*/
    setText("Context Error Label Snippet 004 - Binding Example");
    Label info1 = new Label(this, SWT.NONE);
    info1.setText("Enter '5' to be valid:");
    FormData data = new FormData(DatabindingSnippetsView.STD_LABEL_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info1.setLayoutData(data);
    Text text = new Text(this, SWT.BORDER);
    WritableValue value = new WritableValue(realm, null, String.class);
    data = new FormData(DatabindingSnippetsView.STD_LABEL_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(0, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(info1, 0);
    text.setLayoutData(data);
    Label info2 = new Label(this, SWT.NONE);
    info2.setText("Error/Validation:");
    data = new FormData(DatabindingSnippetsView.STD_LABEL_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(info1, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(0, 0);
    info2.setLayoutData(data);
    Label errorLabel = new Label(this, SWT.BORDER);
    Color color = Graphics.getColor(255, 0, 0);
    errorLabel.setForeground(color);
    data = new FormData(DatabindingSnippetsView.STD_TEXT_WIDTH_LARGE, SWT.DEFAULT);
    data.top = new FormAttachment(text, DatabindingSnippetsView.TOP_MARGIN);
    data.left = new FormAttachment(info2, 0);
    errorLabel.setLayoutData(data);
    errorLabel.setText("hallo");
    DataBindingContext dbc = new DataBindingContext(realm);
    // Bind the text to the value.
    UpdateValueStrategy updateValueStrategy = new UpdateValueStrategy();
    updateValueStrategy.setAfterConvertValidator(new FiveValidator());
    dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), value, updateValueStrategy, null);
    // Bind the error label to the validation error on the dbc.
    int severity = AggregateValidationStatus.MAX_SEVERITY;
    AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(realm,
            dbc.getBindings(), severity);
    dbc.bindValue(SWTObservables.observeText(errorLabel), aggregateValidationStatus, null, null);
}