Example usage for org.eclipse.jface.databinding.viewers ObservableListContentProvider ObservableListContentProvider

List of usage examples for org.eclipse.jface.databinding.viewers ObservableListContentProvider ObservableListContentProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.viewers ObservableListContentProvider ObservableListContentProvider.

Prototype

public ObservableListContentProvider() 

Source Link

Document

Constructs an ObservableListContentProvider.

Usage

From source file:net.bioclipse.qsar.ui.editors.InformationPage.java

License:Open Source License

private void createReferenceTab(FormToolkit toolkit) {
    CTabItem item = new CTabItem(tabFolder, SWT.NULL);
    item.setText("References");

    Composite tabContent = toolkit.createComposite(tabFolder);
    item.setControl(tabContent);/*w  w w . ja v a 2s .  co m*/
    tabContent.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    tabContent.setLayout(layout);
    layout.numColumns = 2;
    layout.marginWidth = 0;

    TableViewer refViewer = new TableViewer(tabContent, SWT.BORDER | SWT.MULTI);
    Table refTable = refViewer.getTable();
    toolkit.adapt(refTable, true, true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.verticalSpan = 2;
    refTable.setLayoutData(gd);

    refTable.setHeaderVisible(true);
    //          molTable.setLinesVisible(true);
    toolkit.adapt(refTable, true, true);

    //Add name columns
    TableLayout tableLayout = new TableLayout();
    refTable.setLayout(tableLayout);
    TableViewerColumn ixcol = new TableViewerColumn(refViewer, SWT.BORDER);
    ixcol.getColumn().setText("Title");
    tableLayout.addColumnData(new ColumnPixelData(150));

    TableViewerColumn col = new TableViewerColumn(refViewer, SWT.BORDER);
    col.getColumn().setText("Authors");
    tableLayout.addColumnData(new ColumnPixelData(100));

    col = new TableViewerColumn(refViewer, SWT.BORDER);
    col.getColumn().setText("journal");
    tableLayout.addColumnData(new ColumnPixelData(100));

    col = new TableViewerColumn(refViewer, SWT.BORDER);
    col.getColumn().setText("Year");
    tableLayout.addColumnData(new ColumnPixelData(50));

    col = new TableViewerColumn(refViewer, SWT.BORDER);
    col.getColumn().setText("URL");
    tableLayout.addColumnData(new ColumnPixelData(100));

    Button btnAdd = toolkit.createButton(tabContent, "Add...", SWT.PUSH);
    btnAdd.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            //                addRef();
        }
    });
    GridData gd2 = new GridData();
    gd2.verticalAlignment = SWT.BEGINNING;
    gd2.widthHint = 60;
    btnAdd.setLayoutData(gd2);

    Button btnDel = toolkit.createButton(tabContent, "Remove", SWT.PUSH);
    btnDel.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            //                deleteRef();
        }
    });
    gd2 = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gd2.widthHint = 60;
    btnDel.setLayoutData(gd2);

    // The content provider is responsible to handle add and
    // remove notification for the Person#address EList
    ObservableListContentProvider provider = new ObservableListContentProvider();
    refViewer.setContentProvider(provider);

    // The label provider in turn handles the addresses
    // The EStructuralFeature[] defines which fields get shown
    // in the TableViewer columns
    IObservableSet knownElements = provider.getKnownElements();
    IObservableMap[] observeMaps = EMFEditObservables.observeMaps(editingDomain, knownElements,
            new EStructuralFeature[] { BibtexmlPackage.Literals.ARTICLE_TYPE__AUTHOR,
                    BibtexmlPackage.Literals.BIB_TE_XML_ENTRIES_CLASS__ARTICLE,
                    BibtexmlPackage.Literals.BIB_TE_XML_ENTRY_TYPE__ID,
                    BibtexmlPackage.Literals.ARTICLE_TYPE__YEAR, BibtexmlPackage.Literals.ARTICLE_TYPE__URL });
    ObservableMapLabelProvider labelProvider = new ObservableQSARLabelProvider(observeMaps);
    refViewer.setLabelProvider(labelProvider);

    QsarType qsarModel = ((QsarEditor) getEditor()).getQsarModel();
    EObject entryList = qsarModel.getMetadata();

    // Set the Viewer's input
    refViewer.setInput(EMFEditObservables.observeList(Realm.getDefault(), editingDomain, entryList,
            QsarPackage.Literals.METADATA_TYPE__REFERENCE));

}

From source file:net.bioclipse.qsar.ui.editors.InformationPage.java

License:Open Source License

private void createUnitsTab(FormToolkit toolkit) {
    CTabItem item = new CTabItem(tabFolder, SWT.NULL);
    item.setText("Response units");

    Composite tabContent = toolkit.createComposite(tabFolder);
    item.setControl(tabContent);//from  w ww.j  a va  2  s .  c  o  m
    tabContent.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    tabContent.setLayout(layout);
    layout.numColumns = 2;
    layout.marginWidth = 0;

    unitViewer = new TableViewer(tabContent, SWT.BORDER | SWT.MULTI);
    Table unitTable = unitViewer.getTable();
    toolkit.adapt(unitTable, true, true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.verticalSpan = 2;
    unitTable.setLayoutData(gd);

    unitTable.setHeaderVisible(true);
    //          molTable.setLinesVisible(true);
    toolkit.adapt(unitTable, true, true);

    //Add name columns
    TableLayout tableLayout = new TableLayout();
    unitTable.setLayout(tableLayout);
    TableViewerColumn ixcol = new TableViewerColumn(unitViewer, SWT.BORDER);
    ixcol.getColumn().setText("Name");
    tableLayout.addColumnData(new ColumnPixelData(150));

    TableViewerColumn col = new TableViewerColumn(unitViewer, SWT.BORDER);
    col.getColumn().setText("Shortname");
    tableLayout.addColumnData(new ColumnPixelData(100));

    col = new TableViewerColumn(unitViewer, SWT.BORDER);
    col.getColumn().setText("Description");
    tableLayout.addColumnData(new ColumnPixelData(100));

    col = new TableViewerColumn(unitViewer, SWT.BORDER);
    col.getColumn().setText("URL");
    tableLayout.addColumnData(new ColumnPixelData(150));

    Button btnAdd = toolkit.createButton(tabContent, "Add...", SWT.PUSH);
    btnAdd.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            addUnit();
            unitViewer.refresh();
        }
    });
    GridData gd2 = new GridData();
    gd2.verticalAlignment = SWT.BEGINNING;
    gd2.widthHint = 60;
    btnAdd.setLayoutData(gd2);

    Button btnDel = toolkit.createButton(tabContent, "Remove", SWT.PUSH);
    btnDel.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            //                deleteUnit();
        }
    });
    gd2 = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gd2.widthHint = 60;
    btnDel.setLayoutData(gd2);

    // The content provider is responsible to handle add and
    // remove notification for the Person#address EList
    ObservableListContentProvider provider = new ObservableListContentProvider();
    unitViewer.setContentProvider(provider);

    // The label provider in turn handles the addresses
    // The EStructuralFeature[] defines which fields get shown
    // in the TableViewer columns
    IObservableSet knownElements = provider.getKnownElements();
    IObservableMap[] observeMaps = EMFEditObservables.observeMaps(editingDomain, knownElements,
            new EStructuralFeature[] { QsarPackage.Literals.RESPONSEUNIT_TYPE__NAME,
                    QsarPackage.Literals.RESPONSEUNIT_TYPE__SHORTNAME,
                    QsarPackage.Literals.RESPONSEUNIT_TYPE__DESCRIPTION,
                    QsarPackage.Literals.RESPONSEUNIT_TYPE__URL });
    ObservableMapLabelProvider labelProvider = new ObservableQSARLabelProvider(observeMaps);
    unitViewer.setLabelProvider(labelProvider);

    QsarType qsarModel = ((QsarEditor) getEditor()).getQsarModel();

    // Set the Viewer's input
    unitViewer.setInput(EMFEditObservables.observeList(Realm.getDefault(), editingDomain, qsarModel,
            QsarPackage.Literals.QSAR_TYPE__RESPONSEUNIT));

}

From source file:net.bioclipse.qsar.ui.editors.MoleculesPage.java

License:Open Source License

private void populateMolsViewerFromModel() {

    // The content provider is responsible to handle add and
    // remove notification for the Person#address EList
    ObservableListContentProvider provider = new ObservableListContentProvider();
    molViewer.setContentProvider(provider);

    // The label provider in turn handles the addresses
    // The EStructuralFeature[] defines which fields get shown
    // in the TableViewer columns
    IObservableSet knownElements = provider.getKnownElements();
    IObservableMap[] observeMaps = EMFEditObservables.observeMaps(editingDomain, knownElements,
            new EStructuralFeature[] { QsarPackage.Literals.RESOURCE_TYPE__NAME,
                    QsarPackage.Literals.RESOURCE_TYPE__NO_MOLS, QsarPackage.Literals.RESOURCE_TYPE__NO2D,
                    QsarPackage.Literals.RESOURCE_TYPE__NO3D });
    ObservableMapLabelProvider labelProvider = new ObservableQSARLabelProvider(observeMaps);
    molViewer.setLabelProvider(labelProvider);

    QsarType qsarModel = ((QsarEditor) getEditor()).getQsarModel();
    StructurelistType structList = qsarModel.getStructurelist();

    // Person#addresses is the Viewer's input
    molViewer.setInput(EMFEditObservables.observeList(Realm.getDefault(), editingDomain, structList,
            QsarPackage.Literals.STRUCTURELIST_TYPE__RESOURCES));

}

From source file:net.efano.sandbox.jface.snippets.TableViewerColors.java

License:Open Source License

/**
 * @param args//from  w w  w  . j  av a2s.co m
 */
public static void main(String[] args) {
    final List<Person> persons = new ArrayList<Person>();
    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 gd_table = new GridData(SWT.FILL, SWT.FILL, true, false);
            gd_table.heightHint = 352;
            table.setLayoutData(gd_table);
            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.

            IObservableSet oset = contentProvider.getKnownElements();

            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:
                @Override
                public String getColumnText(Object element, int index) {
                    if (index == 0) {
                        return Integer.toString(persons.indexOf(element) + 1);
                    }
                    return ((Person) element).getName();
                }

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

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

                @Override
                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(380, 713);

            Button btnAddRow = new Button(shell, SWT.NONE);
            btnAddRow.setText("Add Row");

            newRowNameText = new Text(shell, SWT.BORDER);
            newRowNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

            Composite composite = new Composite(shell, SWT.NONE);
            composite.setLayout(new FillLayout(SWT.HORIZONTAL));
            GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
            gd_composite.widthHint = 129;
            gd_composite.heightHint = 26;
            composite.setLayoutData(gd_composite);

            Button maleRadioButton = new Button(composite, SWT.RADIO);
            maleRadioButton.setText("Male");

            Button femaleRadioButton = new Button(composite, SWT.RADIO);
            femaleRadioButton.setText("Female");
            shell.open();

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

From source file:net.sf.rcer.conn.ui.login.LoginDialog.java

License:Open Source License

/**
 * Connects the UI elements to the model elements. 
 *///from  ww  w  .  j  a  va2  s . c o m
private void bindUserInterface() {

    // set the values of the locales combo
    final Collection<Locale> locales = LocaleRegistry.getInstance().getLocales();
    final Iterator<Locale> it = locales.iterator();
    final LocaleToStringConverter converter = new LocaleToStringConverter(true);
    String[] entries = new String[locales.size() + 1];
    for (int i = 0; i < locales.size(); i++) {
        entries[i] = (String) converter.convert(it.next());
    }
    entries[locales.size()] = ""; //$NON-NLS-1$
    localeCombo.setItems(entries);

    context = new DataBindingContext();

    // observe changes in the selection of the connection combo
    IObservableValue selection = ViewersObservables.observeSingleSelection(connectionComboViewer);
    IObservableValue connection = BeansObservables.observeDetailValue(selection, "connection", //$NON-NLS-1$
            IConnection.class);

    // bind the client 
    context.bindValue(SWTObservables.observeText(clientText, SWT.Modify),
            BeansObservables.observeDetailValue(connection, "client", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    context.bindValue(SWTObservables.observeEnabled(clientText),
            BeansObservables.observeDetailValue(connection, "clientEditable", boolean.class), //$NON-NLS-1$
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy());

    // bind the user name
    context.bindValue(SWTObservables.observeText(userText, SWT.Modify),
            BeansObservables.observeDetailValue(connection, "userName", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    context.bindValue(SWTObservables.observeEnabled(userText),
            BeansObservables.observeDetailValue(connection, "userEditable", boolean.class), //$NON-NLS-1$
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy());

    // bind the password
    context.bindValue(SWTObservables.observeText(passwordText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "password", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());

    // bind the locale 
    context.bindValue(SWTObservables.observeSelection(localeCombo),
            BeansObservables.observeDetailValue(connection, "locale", Locale.class), //$NON-NLS-1$
            new UpdateValueStrategy().setConverter(new LocaleFromStringConverter()),
            new UpdateValueStrategy().setConverter(new LocaleToStringConverter(true)));
    context.bindValue(SWTObservables.observeEnabled(localeCombo),
            BeansObservables.observeDetailValue(connection, "localeEditable", boolean.class), //$NON-NLS-1$
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), new UpdateValueStrategy());

    // provide the connection list with input data
    connectionComboViewer.setContentProvider(new ObservableListContentProvider());
    connectionComboViewer.setInput(credentials);

    // select the first entry
    connectionComboViewer.setSelection(new StructuredSelection(credentials.get(0)));

    // only enable the combo box if more than one connection can be chosen
    connectionComboViewer.getCombo().setEnabled(credentials.size() > 1);

}

From source file:net.sf.rcer.conn.ui.preferences.ConnectionsPreferencePage.java

License:Open Source License

/**
 * Initializes the data binding for the user interface components.
 *///from   ww  w . j  av  a2s  . co m
private void bindControls() {

    UpdateValueStrategy targetToModel;

    context = new DataBindingContext();

    // observe changes in the selection of the connection list
    IObservableValue selection = ViewersObservables.observeSingleSelection(connectionViewer);

    // bind the description (String, may not be empty)
    context.bindValue(SWTObservables.observeText(descriptionText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "description", String.class), //$NON-NLS-1$
            new UpdateValueStrategy().setBeforeSetValidator(
                    new NotEmptyValidator(Messages.ConnectionsPreferencePage_DescriptionEmptyError)),
            new UpdateValueStrategy());

    // bind the connection type
    IObservableValue connectionTypeObservable = BeansObservables.observeDetailValue(selection, "connectionType", //$NON-NLS-1$
            ConnectionType.class);
    context.bindValue(SWTObservables.observeSelection(connectionTypeCombo), connectionTypeObservable,
            new UpdateValueStrategy().setConverter(new ConnectionTypeFromStringConverter()),
            new UpdateValueStrategy().setConverter(new ConnectionTypeToStringConverter()));

    // bind the system ID
    context.bindValue(SWTObservables.observeText(sidText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "systemID", String.class), //$NON-NLS-1$
            new UpdateValueStrategy().setBeforeSetValidator(
                    new StringLengthValidator(Messages.ConnectionsPreferencePage_SystemIDValidator, 3, 3)),
            new UpdateValueStrategy());

    // bind the router
    context.bindValue(SWTObservables.observeText(routerText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "router", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());

    // bind the application server
    context.bindValue(SWTObservables.observeText(applicationServerText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "applicationServer", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    new VisibilityUpdater(details, applicationServerText, applicationServerLabel, connectionTypeObservable,
            ConnectionType.DIRECT);
    // TODO #002 ensure that the app server is required for direct connections

    // bind the system number
    targetToModel = new UpdateValueStrategy();
    targetToModel.setConverter(StringToNumberConverter.toInteger(true));
    // TODO #002 ensure that the system number is required for direct connections
    //      targetToModel.setAfterGetValidator(new ConditionalNotEmptyValidator(
    //            connectionTypeObservable, ConnectionType.DIRECT, "System Number must be set for direct connections."));
    targetToModel.setBeforeSetValidator(
            new IntegerRangeValidator(Messages.ConnectionsPreferencePage_SystemNumberValidator, 0, 99));
    context.bindValue(SWTObservables.observeText(systemNumberText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "systemNumber", null), //$NON-NLS-1$
            targetToModel, new UpdateValueStrategy().setConverter(NumberToStringConverter.fromInteger(true)));
    new VisibilityUpdater(details, systemNumberText, systemNumberLabel, connectionTypeObservable,
            ConnectionType.DIRECT);

    // bind the message server 
    context.bindValue(SWTObservables.observeText(messageServerText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "messageServer", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    new VisibilityUpdater(details, messageServerText, messageServerLabel, connectionTypeObservable,
            ConnectionType.LOAD_BALANCED);
    // TODO #002 ensure that the message server is required for lb connections

    // bind the message server port
    context.bindValue(SWTObservables.observeText(messageServerPortText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "messageServerPort", null), //$NON-NLS-1$
            new UpdateValueStrategy().setConverter(StringToNumberConverter.toInteger(true)),
            new UpdateValueStrategy().setConverter(NumberToStringConverter.fromInteger(true)));
    new VisibilityUpdater(details, messageServerPortText, messageServerPortLabel, connectionTypeObservable,
            ConnectionType.LOAD_BALANCED);
    // TODO #002 ensure that the port is required for lb connections

    // bind the logon group 
    context.bindValue(SWTObservables.observeText(logonGroupText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "loadBalancingGroup", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());
    new VisibilityUpdater(details, logonGroupText, logonGroupLabel, connectionTypeObservable,
            ConnectionType.LOAD_BALANCED);
    // TODO #002 ensure that the logon group is required for lb connections

    // bind the default client 
    context.bindValue(SWTObservables.observeText(defaultClientText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "defaultClient", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());

    // bind the default user
    context.bindValue(SWTObservables.observeText(defaultUserText, SWT.Modify),
            BeansObservables.observeDetailValue(selection, "defaultUser", String.class), //$NON-NLS-1$
            new UpdateValueStrategy(), new UpdateValueStrategy());

    // bind the default locale 
    context.bindValue(SWTObservables.observeSelection(defaultLocaleCombo),
            BeansObservables.observeDetailValue(selection, "defaultLocale", Locale.class), //$NON-NLS-1$
            new UpdateValueStrategy().setConverter(new LocaleFromStringConverter()),
            new UpdateValueStrategy().setConverter(new LocaleToStringConverter(false)));

    // supply the error label with the aggregated status
    context.bindValue(SWTObservables.observeText(errorDisplayLabel),
            new AggregateValidationStatus(context.getBindings(), AggregateValidationStatus.MAX_SEVERITY), null,
            null);

    // provide the connection list with input data
    connectionViewer.setContentProvider(new ObservableListContentProvider());
    connectionViewer.setInput(connections);

    // select the first entry, if any exist
    if (connections.size() > 0) {
        connectionViewer.setSelection(new StructuredSelection(connections.get(0)));
    }
}

From source file:net.sf.rcer.example.rfcgen.pojo.call.View.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    GridLayoutFactory.fillDefaults().applyTo(parent);

    Composite query = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(query);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(query);

    @SuppressWarnings("unused")
    Label spacer = new Label(query, SWT.NONE);

    Label countryLabel = new Label(query, SWT.NONE);
    countryLabel.setText("Country");

    Label cityLabel = new Label(query, SWT.NONE);
    cityLabel.setText("City");

    Label fromLabel = new Label(query, SWT.NONE);
    fromLabel.setText("From:");

    fromCountryText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().applyTo(fromCountryText);
    fromCountryText.setText("DE");

    fromCityText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(fromCityText);
    fromCityText.setText("Frankfurt");

    Label toLabel = new Label(query, SWT.NONE);
    toLabel.setText("To:");

    toCountryText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().applyTo(toCountryText);
    toCountryText.setText("DE");

    toCityText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(toCityText);
    toCityText.setText("Berlin");

    Button queryButton = new Button(query, SWT.PUSH);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(queryButton);
    queryButton.setText("Search...");

    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(separator);

    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    IObservableMap[] attributeMaps = BeansObservables.observeMaps(contentProvider.getKnownElements(),
            FlightData.class, new String[] { "carrierID", "connectionID", "flightDate", "origin", "destination",
                    "maximumSeats", "occupiedSeats" });

    viewer = new TableViewer(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);

    Table table = viewer.getTable();/*  w  w  w . j a  va2 s . c  o  m*/
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    addColumn(table, "Carr", 40);
    addColumn(table, "Conn", 50);
    addColumn(table, "Date", 70);
    addColumn(table, "From", 40);
    addColumn(table, "To", 40);
    addColumn(table, "max. Seats", 70);
    addColumn(table, "occ. Seats", 70);

    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps));

    queryButton.addSelectionListener(new SelectionAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            GetFlightListCall call = new GetFlightListCall();
            call.setFromCountry(fromCountryText.getText());
            call.setFromCity(fromCityText.getText());
            call.setToCity(toCityText.getText());
            call.setToCountry(toCountryText.getText());
            try {
                call.execute(ConnectionManager.getInstance().getDestination());
                viewer.setInput(new WritableList(call.getFlights(), FlightData.class));
            } catch (Exception ex) {
                ErrorDialog.openError(getSite().getShell(), getSite().getShell().getText(),
                        "Unable to search for flights.",
                        new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getLocalizedMessage(), ex));

            }
        }
    });
}

From source file:net.sf.rcer.example.rfcgen.pojo.rr.View.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    GridLayoutFactory.fillDefaults().applyTo(parent);

    Composite query = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(query);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(query);

    @SuppressWarnings("unused")
    Label spacer = new Label(query, SWT.NONE);

    Label countryLabel = new Label(query, SWT.NONE);
    countryLabel.setText("Country");

    Label cityLabel = new Label(query, SWT.NONE);
    cityLabel.setText("City");

    Label fromLabel = new Label(query, SWT.NONE);
    fromLabel.setText("From:");

    fromCountryText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().applyTo(fromCountryText);
    fromCountryText.setText("DE");

    fromCityText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(fromCityText);
    fromCityText.setText("Frankfurt");

    Label toLabel = new Label(query, SWT.NONE);
    toLabel.setText("To:");

    toCountryText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().applyTo(toCountryText);
    toCountryText.setText("DE");

    toCityText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(toCityText);
    toCityText.setText("Berlin");

    Button queryButton = new Button(query, SWT.PUSH);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(queryButton);
    queryButton.setText("Search...");

    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(separator);

    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    IObservableMap[] attributeMaps = BeansObservables.observeMaps(contentProvider.getKnownElements(),
            FlightData.class, new String[] { "carrierID", "connectionID", "flightDate", "origin", "destination",
                    "maximumSeats", "occupiedSeats" });

    viewer = new TableViewer(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);

    Table table = viewer.getTable();/*from ww w.j ava  2  s  .  c o m*/
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    addColumn(table, "Carr", 40);
    addColumn(table, "Conn", 50);
    addColumn(table, "Date", 70);
    addColumn(table, "From", 40);
    addColumn(table, "To", 40);
    addColumn(table, "max. Seats", 70);
    addColumn(table, "occ. Seats", 70);

    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps));

    queryButton.addSelectionListener(new SelectionAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            GetFlightListRequest request = new GetFlightListRequest();
            request.setFromCountry(fromCountryText.getText());
            request.setFromCity(fromCityText.getText());
            request.setToCity(toCityText.getText());
            request.setToCountry(toCountryText.getText());
            try {
                GetFlightListResponse response = request
                        .execute(ConnectionManager.getInstance().getDestination());
                viewer.setInput(new WritableList(response.getFlights(), FlightData.class));
            } catch (Exception ex) {
                ErrorDialog.openError(getSite().getShell(), getSite().getShell().getText(),
                        "Unable to search for flights.",
                        new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getLocalizedMessage(), ex));

            }
        }
    });
}

From source file:net.sf.rcer.example.traditional.View.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    GridLayoutFactory.fillDefaults().applyTo(parent);

    Composite query = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(query);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(query);

    @SuppressWarnings("unused")
    Label spacer = new Label(query, SWT.NONE);

    Label countryLabel = new Label(query, SWT.NONE);
    countryLabel.setText("Country");

    Label cityLabel = new Label(query, SWT.NONE);
    cityLabel.setText("City");

    Label fromLabel = new Label(query, SWT.NONE);
    fromLabel.setText("From:");

    fromCountryText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().applyTo(fromCountryText);
    fromCountryText.setText("DE");

    fromCityText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(fromCityText);
    fromCityText.setText("Frankfurt");

    Label toLabel = new Label(query, SWT.NONE);
    toLabel.setText("To:");

    toCountryText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().applyTo(toCountryText);
    toCountryText.setText("DE");

    toCityText = new Text(query, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(toCityText);
    toCityText.setText("Berlin");

    Button queryButton = new Button(query, SWT.PUSH);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(queryButton);
    queryButton.setText("Search...");

    Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().span(3, 1).applyTo(separator);

    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    IObservableMap[] attributeMaps = BeansObservables.observeMaps(contentProvider.getKnownElements(),
            FlightData.class, new String[] { "carrier", "connection", "departure", "airportFrom", "airportTo",
                    "maximumSeats", "occupiedSeats" });

    viewer = new TableViewer(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);

    Table table = viewer.getTable();//from  www  .  jav  a2 s.  com
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    addColumn(table, "Carr", 40);
    addColumn(table, "Conn", 50);
    addColumn(table, "Departure", 210);
    addColumn(table, "From", 40);
    addColumn(table, "To", 40);
    addColumn(table, "max. Seats", 70);
    addColumn(table, "occ. Seats", 70);

    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps));

    queryButton.addSelectionListener(new SelectionAdapter() {
        /* (non-Javadoc)
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            FlightDataReader reader = new FlightDataReader();
            IStatus status = reader.readFlights(fromCountryText.getText(), fromCityText.getText(),
                    toCountryText.getText(), toCityText.getText());
            if (status.isOK()) {
                viewer.setInput(new WritableList(reader.getResult(), FlightData.class));
            } else {
                ErrorDialog.openError(getSite().getShell(), getSite().getShell().getText(),
                        "Unable to search for flights.", status);
            }
        }
    });
}

From source file:oida.model.integration.ui.dialogs.ConflictResolutionDialog.java

License:Open Source License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ///*from   w  w w.  jav  a  2 s.  com*/
    ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
    tableViewerAttributes.setContentProvider(listContentProvider);
    //
    IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(),
            IntegratedAttribute.class,
            new String[] { "attributeName", "myAttributeValue", "theirAttributeValue" });
    tableViewerAttributes.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
    //
    IObservableList mergeModelCurrentIntegratedAttributesintegratedAttributesObserveList = BeansObservables
            .observeList(Realm.getDefault(), mergeModel.getCurrentIntegratedAttributes(),
                    "integratedAttributes");
    tableViewerAttributes.setInput(mergeModelCurrentIntegratedAttributesintegratedAttributesObserveList);
    //
    ObservableListContentProvider listContentProvider_1 = new ObservableListContentProvider();
    tableViewerConflicts.setContentProvider(listContentProvider_1);
    //
    IObservableMap[] observeMaps_1 = PojoObservables.observeMaps(listContentProvider_1.getKnownElements(),
            ReferenceMatching.class, new String[] { "confirmed", "reported", "comment" });
    tableViewerConflicts.setLabelProvider(new ConflictsTableLabelProvider(observeMaps_1));
    //
    IObservableList mergeModelConflictingMatchingsObserveList = BeansObservables.observeList(Realm.getDefault(),
            mergeModel, "conflictingMatchings");
    tableViewerConflicts.setInput(mergeModelConflictingMatchingsObserveList);
    //
    IObservableValue lblConflictsResolvedObserveTextObserveWidget = SWTObservables
            .observeText(lblConflictsResolved);
    IObservableValue mergeModelConfirmationStatusObserveValue = BeansObservables
            .observeValue(mergeModel.getMergeCounters(), "confirmationStatus");
    bindingContext.bindValue(lblConflictsResolvedObserveTextObserveWidget,
            mergeModelConfirmationStatusObserveValue, null, null);
    //
    IObservableValue lblMismatchesObserveTextObserveWidget = SWTObservables.observeText(lblMismatches);
    IObservableValue mergeModelReportingStatusObserveValue = BeansObservables
            .observeValue(mergeModel.getMergeCounters(), "reportingStatus");
    bindingContext.bindValue(lblMismatchesObserveTextObserveWidget, mergeModelReportingStatusObserveValue, null,
            null);
    //
    return bindingContext;
}