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.e4.xwt.tests.snipppets.Snippet007ColorLabelProvider.java

License:Open Source License

/**
 * @param args/*from ww w.  j  av a 2  s .c o m*/
 */
public static void main(String[] args) {
    final List persons = new ArrayList();
    persons.add(new Person("Fiona Apple", Person.FEMALE));
    persons.add(new Person("Elliot Smith", Person.MALE));
    persons.add(new Person("Diana Krall", Person.FEMALE));
    persons.add(new Person("David Gilmour", Person.MALE));

    final Display display = new Display();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            Shell shell = new Shell(display);
            shell.setText("Gender Bender");
            shell.setLayout(new GridLayout());

            Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
            GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
            table.setLayoutData(gridData);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn column = new TableColumn(table, SWT.NONE);
            column.setText("No");
            column.setWidth(20);
            column = new TableColumn(table, SWT.NONE);
            column.setText("Name");
            column.setWidth(100);
            final TableViewer viewer = new TableViewer(table);

            IObservableList observableList = Observables.staticObservableList(persons);
            ObservableListContentProvider contentProvider = new ObservableListContentProvider();

            viewer.setContentProvider(contentProvider);

            // this does not have to correspond to the columns in the table,
            // we just list all attributes that affect the table content.
            IObservableMap[] attributes = BeansObservables.observeMaps(contentProvider.getKnownElements(),
                    Person.class, new String[] { "name", "gender" });

            class ColorLabelProvider extends ObservableMapLabelProvider implements ITableColorProvider {
                Color male = display.getSystemColor(SWT.COLOR_BLUE);

                Color female = new Color(display, 255, 192, 203);

                ColorLabelProvider(IObservableMap[] attributes) {
                    super(attributes);
                }

                // to drive home the point that attributes does not have to
                // match
                // the columns
                // in the table, we change the column text as follows:
                public String getColumnText(Object element, int index) {
                    if (index == 0) {
                        return Integer.toString(persons.indexOf(element) + 1);
                    }
                    return ((Person) element).getName();
                }

                public Color getBackground(Object element, int index) {
                    return null;
                }

                public Color getForeground(Object element, int index) {
                    if (index == 0)
                        return null;
                    Person person = (Person) element;
                    return (person.getGender() == Person.MALE) ? male : female;
                }

                public void dispose() {
                    super.dispose();
                    female.dispose();
                }
            }
            viewer.setLabelProvider(new ColorLabelProvider(attributes));

            viewer.setInput(observableList);

            table.getColumn(0).pack();

            Button button = new Button(shell, SWT.PUSH);
            button.setText("Toggle Gender");
            button.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent arg0) {
                    StructuredSelection selection = (StructuredSelection) viewer.getSelection();
                    if (selection != null && !selection.isEmpty()) {
                        Person person = (Person) selection.getFirstElement();
                        person.setGender((person.getGender() == Person.MALE) ? Person.FEMALE : Person.MALE);
                    }
                }
            });

            shell.setSize(300, 400);
            shell.open();

            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
    });
    display.dispose();
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet013TableViewerEditing.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            ViewModel viewModel = new ViewModel();
            Shell shell = new View(viewModel).createShell();

            // The SWT event loop
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();/*w  ww  .ja v a2 s  .c  o m*/
                }
            }
        }
    });
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet015DelayTextModifyEvents.java

License:Open Source License

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

    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            Shell shell = new Shell();
            shell.setLayout(new GridLayout(3, false));

            createControls(shell);//  w w w  .j  a v a 2  s .  c  om

            shell.pack();
            shell.open();
            while (!shell.isDisposed())
                if (!display.readAndDispatch())
                    display.sleep();
        }

    });

    display.dispose();
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet018CheckboxTableViewerCheckedSelection.java

License:Open Source License

public static void main(String[] args) {
    // The SWT event loop
    final Display display = Display.getDefault();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            ViewModel viewModel = createSampleModel();

            Shell shell = new View(viewModel).createShell();
            shell.open();//from  w  w w.  ja  v  a 2s.  com
            while (!shell.isDisposed())
                if (!display.readAndDispatch())
                    display.sleep();
        }
    });
    display.dispose();
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet019TreeViewerWithListFactory.java

License:Open Source License

/**
 * Launch the application//from  w  w w  . ja va 2  s  . c om
 * 
 * @param args
 */
public static void main(String[] args) {
    Display display = Display.getDefault();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                Snippet019TreeViewerWithListFactory window = new Snippet019TreeViewerWithListFactory();
                window.open();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet020TreeViewerWithSetFactory.java

License:Open Source License

/**
 * Launch the application/*from w  ww.  j  a  v  a  2  s  .c  o m*/
 * 
 * @param args
 */
public static void main(String[] args) {
    Display display = Display.getDefault();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                Snippet020TreeViewerWithSetFactory window = new Snippet020TreeViewerWithSetFactory();
                window.open();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet021MultiFieldValidation.java

License:Open Source License

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

    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            IWizard wizard = new MultiFieldValidationWizard();
            WizardDialog dialog = new WizardDialog(null, wizard);
            dialog.open();/*w w w . j a va2  s  .  c o  m*/

            // The SWT event loop
            Display display = Display.getCurrent();
            while (dialog.getShell() != null && !dialog.getShell().isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
        }
    });

    display.dispose();
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet024SelectObservableValue.java

License:Open Source License

public static void main(String[] args) {
    final Display display = Display.getDefault();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                Snippet024SelectObservableValue window = new Snippet024SelectObservableValue();
                window.open();//from  w ww.j a v a 2s.com
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:org.eclipse.e4.xwt.tests.snipppets.Snippet026AnonymousBeanProperties.java

License:Open Source License

public static void main(String[] args) {
    Display display = new Display();
    Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
        public void run() {
            try {
                Snippet026AnonymousBeanProperties window = new Snippet026AnonymousBeanProperties();
                window.open();/*www .  java2 s  . c  o m*/
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

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

License:Open Source License

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