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:ts.eclipse.ide.json.ui.internal.tsconfig.PluginsPage.java

License:Open Source License

/**
 * Create Files section.// w w w  .ja v a 2s . co  m
 * 
 * @param parent
 */
private void createPluginsSection(Composite parent) {
    final IFile tsconfigFile = getTsconfigFile();
    FormToolkit toolkit = super.getToolkit();
    Section section = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR);
    section.setDescription(TsconfigEditorMessages.FilesPage_FilesSection_desc);
    section.setText(TsconfigEditorMessages.FilesPage_FilesSection_title);

    Composite client = toolkit.createComposite(section);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 2;
    layout.marginHeight = 2;
    client.setLayout(layout);

    Table table = toolkit.createTable(client, SWT.MULTI);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.minimumHeight = 100;
    gd.widthHint = 100;
    table.setLayoutData(gd);

    // Buttons
    Composite buttonsComposite = toolkit.createComposite(client);
    buttonsComposite.setLayout(new GridLayout());
    buttonsComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    final Button pluginsAddButton = toolkit.createButton(buttonsComposite, TsconfigEditorMessages.Button_add,
            SWT.PUSH);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    pluginsAddButton.setLayoutData(gd);

    pluginsRemoveButton = toolkit.createButton(buttonsComposite, TsconfigEditorMessages.Button_remove,
            SWT.PUSH);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    pluginsRemoveButton.setLayoutData(gd);
    pluginsRemoveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // removeSelectedItems(filesViewer);
        }
    });

    // Files table
    pluginsViewer = new TableViewer(table);
    pluginsViewer.setLabelProvider(new DecoratingLabelProvider(PluginsLabelProvider.getInstance(),
            PluginsLabelProvider.getInstance()));
    // open file when row is double clicked
    //      pluginsViewer.addDoubleClickListener(new IDoubleClickListener() {
    //
    //         @Override
    //         public void doubleClick(DoubleClickEvent e) {
    //            openFile(pluginsViewer.getSelection());
    //         }
    //      });
    //      // update enable/disable of buttons when selection changed
    //      pluginsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
    //
    //         @Override
    //         public void selectionChanged(SelectionChangedEvent event) {
    //            updateFilesOpenButton(event.getSelection());
    //            filesRemoveButton.setEnabled(!event.getSelection().isEmpty());
    //         }
    //      });
    //      pluginsViewer.getTable().addKeyListener(new KeyAdapter() {
    //         @Override
    //         public void keyPressed(KeyEvent e) {
    //            if (e.keyCode == SWT.DEL) {
    //               removeSelectedItems(pluginsViewer);
    //            }
    //         }
    //      });
    toolkit.paintBordersFor(client);
    section.setClient(client);
    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    section.setLayoutData(new GridData(GridData.FILL_BOTH));

    IObservableList files = JSONProperties.list(new ExtendedJSONPath("compilerOptions.plugins[*]"))
            .observe(getEditor().getDocument());
    pluginsViewer.setContentProvider(new ObservableListContentProvider());
    pluginsViewer.setInput(files);

}

From source file:uk.ac.gda.client.logpanel.view.Logpanel.java

License:Open Source License

public Logpanel(Composite parent, int style) {
    super(parent, style);

    connectToLogServer();/*w  w w  .  j a v a 2  s  .  co m*/

    // display copyable path to gda logs dir
    String logsDir = LocalProperties.get(LocalProperties.GDA_LOGS_DIR/*, "/tmp/gda/i23/logs"*/);
    if (logsDir != null) {
        Composite logDirComposite = new Composite(this, SWT.NONE);

        Label logDirLabel = new Label(logDirComposite, SWT.NONE);
        logDirLabel.setText("Highlights of log file(s) in:");
        GridDataFactory.swtDefaults().applyTo(logDirLabel);

        final Text logFileText = new Text(logDirComposite, SWT.SINGLE | SWT.READ_ONLY);
        logFileText.setText(logsDir);
        logFileText.setToolTipText(String.format("'%s' in java.properties", LocalProperties.GDA_LOGS_DIR));

        GridDataFactory.swtDefaults().span(3, 1).applyTo(logDirComposite);
        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(logDirComposite);
        GridDataFactory.fillDefaults().applyTo(logFileText);
    }

    // filter using substrings
    Label filterLabel = new Label(this, SWT.NONE);
    filterLabel.setText("Filter:");

    final Text filterText = new Text(this, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
    filterText.setToolTipText("Hide log entries not matching filter text or regex, e.g. EPICS|G?DA(WN)?");
    filterText.setFont(getFont());
    filterText.setMessage("*case-insensitive matches*");
    filterText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent keyEvent) {
            matchingFilter.setMatching(filterText.getText());
            viewer.refresh();
        }
    });
    filterText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (e.detail == SWT.ICON_CANCEL) {
                matchingFilter.setMatching(""/*filterText.getText()*/);
                viewer.refresh();
            }
        }
    });
    filterText.setFocus();

    //TODO exclusion filter as well as matching filter

    Button button = createSwitchPatternButton();

    // 1-column table of log messages
    viewer = new TableViewer(this, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setLabelProvider(new ILoggingEventLabelProvider());
    viewer.setContentProvider(new ObservableListContentProvider());
    //      viewer.setUseHashlookup(true); //TODO test for possible speedup and increased memory usage
    viewer.setInput(input);

    matchingFilter = new MatchingFilter();
    viewer.addFilter(matchingFilter);

    minLogLevelFilter = new MinLogLevelFilter();
    viewer.addFilter(minLogLevelFilter);

    // copy selection to X buffer when Copy command not explicitly invocation by user
    // do not copy to clipboard automatically as this can overwrite it's contents
    final Text invisibleSelectionText = new Text(this, SWT.READ_ONLY);
    // widget must be visible and not .exclude(true) to enable automatic copying to X cut buffer
    GridDataFactory.swtDefaults().span(3, 1).hint(0, 0).applyTo(invisibleSelectionText);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() > 0) {
                String selectedMessagesJoined = getSelectedMessagesJoined();
                invisibleSelectionText.setText(selectedMessagesJoined);
                invisibleSelectionText.setSelection(0, selectedMessagesJoined.length());
            }
        }
    });

    GridLayoutFactory.swtDefaults().numColumns(4).applyTo(this);
    GridDataFactory.swtDefaults().span(1, 1).applyTo(filterLabel);
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(filterText);
    GridDataFactory.swtDefaults().span(1, 1).grab(false, false).applyTo(button);
    GridDataFactory.fillDefaults().span(4, 1).grab(true, true).applyTo(viewer.getControl());

    // former controls supplanted by command buttons in LogpanelView toolbar
    // methods still useful for other Composites embedding Logpanel 
    //createScrollLockCheckBox(this);
    //createClearButton(this);
    //createCopyButton(this);
}

From source file:uk.ac.gda.example.mvcexample.MvcExampleView.java

License:Open Source License

/**
 * Creates a table viewer of the model using ObservableListContentProvider and Observable label providers to bind to
 * the model/*from   w ww  .j a  v a  2 s.  com*/
 */
private void createTable1(Composite cmpRoot, IObservableList input) {
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    viewer = new TableViewer(cmpRoot);
    Table table = viewer.getTable();
    table.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
    table.setLinesVisible(true);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setWidth(100);
    column0.getColumn().setText(MvcExampleItem.NAME_PROPERTY_NAME);

    IObservableSet knownElements0 = contentProvider.getKnownElements();

    final IObservableMap values0 = BeanProperties.value(MvcExampleItem.class, MvcExampleItem.NAME_PROPERTY_NAME)
            .observeDetail(knownElements0);

    column0.setLabelProvider(new ObservableMapColumnLabelProvider(values0));

    TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setWidth(100);
    column1.getColumn().setText(MvcExampleItem.VALUE_PROPERTY_NAME);

    IObservableSet knownElements = contentProvider.getKnownElements();

    final IObservableMap values = BeanProperties.value(MvcExampleItem.class, MvcExampleItem.VALUE_PROPERTY_NAME)
            .observeDetail(knownElements);

    column1.setLabelProvider(new ObservableMapColumnLabelProvider(values));

    TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
    column2.getColumn().setText("Progress");
    column2.getColumn().setWidth(52);
    ControlFactoryAndUpdater factory = new ObservableMapCellControlProvider.ControlFactoryAndUpdater() {

        @Override
        public Control createControl(Composite parent) {
            ProgressBar progressBar = new ProgressBar(parent, SWT.NONE);
            progressBar.setMaximum(100);
            return progressBar;
        }

        @Override
        public void updateControl(Control control, Object value) {
            ((ProgressBar) control).setSelection(((Double) value).intValue());

        }
    };
    column2.setLabelProvider(new ObservableMapCellControlProvider(values, factory, "Column2"));

    TableViewerColumn column3 = new TableViewerColumn(viewer, SWT.NONE);
    column3.getColumn().setText("Done");
    column3.getColumn().setWidth(20);
    ControlFactoryAndUpdater factory2 = new ObservableMapCellControlProvider.ControlFactoryAndUpdater() {

        org.eclipse.swt.graphics.Color green = null;
        org.eclipse.swt.graphics.Color yellow = null;

        @Override
        public Control createControl(Composite parent) {
            Button button = new Button(parent, SWT.CHECK | SWT.FLAT);
            button.setVisible(true);
            button.setSelection(false);
            button.setAlignment(SWT.CENTER);
            button.setEnabled(false);
            return button;
        }

        @Override
        public void updateControl(Control control, Object value) {
            if (green == null) {
                green = control.getDisplay().getSystemColor(SWT.COLOR_GREEN);
                yellow = control.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
            }
            boolean complete = ((Double) value).intValue() > 10;
            Button button = (Button) control;
            button.setSelection(complete);
            button.setBackground(complete ? green : yellow);
        }
    };
    column3.setLabelProvider(new ObservableMapCellControlProvider(values, factory2, "Column3"));

    TableViewerColumn column4 = new TableViewerColumn(viewer, SWT.NONE);
    column4.getColumn().setText("Done");
    column4.getColumn().setWidth(20);
    column4.setLabelProvider(new ObservableMapOwnerDrawProvider(values) {
        org.eclipse.swt.graphics.Color green = null;
        org.eclipse.swt.graphics.Color yellow = null;
        org.eclipse.swt.graphics.Color original = null;

        @Override
        protected void measure(Event event, Object element) {
            event.setBounds(new Rectangle(event.x, event.y, 20, 10));
        }

        @Override
        protected void erase(Event event, Object element) {
            if (original != null) {
                event.gc.setBackground(original);
                event.gc.fillRectangle(event.getBounds());
            }
            super.erase(event, element);
        }

        @Override
        protected void paint(Event event, Object element) {
            if (green == null) {
                original = event.gc.getBackground();
                green = event.display.getSystemColor(SWT.COLOR_GREEN);
                yellow = event.display.getSystemColor(SWT.COLOR_YELLOW);
            }
            Object value = attributeMaps[0].get(element);
            boolean complete = ((Double) value).intValue() > 10;
            event.gc.setBackground(complete ? green : yellow);
            event.gc.fillRectangle(event.getBounds());
        }
    });

    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(contentProvider);
    viewer.setInput(input);
}

From source file:uk.ac.stfc.isis.ibex.ui.configserver.editing.DoubleListEditor.java

License:Open Source License

private void configureViewer(ListViewer viewer, String observedProperty) {
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new ObservableMapLabelProvider(BeansObservables
            .observeMaps(contentProvider.getKnownElements(), new String[] { observedProperty })));
}

From source file:uk.ac.stfc.isis.ibex.ui.configserver.editing.groups.GroupsEditorPanel.java

License:Open Source License

/**
 * Instantiates a new groups editor panel.
 *
 * @param parent the parent/*from  ww  w  . ja v a2 s  .c om*/
 * @param style the style
 * @param messageDisplayer a way of displaying messages to the user
 * @param configurationViewModels the configuration view models
 */
public GroupsEditorPanel(Composite parent, int style, final MessageDisplayer messageDisplayer,
        final ConfigurationViewModels configurationViewModels) {
    super(parent, style);

    final GroupEditorViewModel groupEditorViewModel = configurationViewModels.groupEditorViewModel();

    setLayout(new GridLayout(2, false));

    Group grpGroups = new Group(this, SWT.NONE);
    grpGroups.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    grpGroups.setText("Groups");
    grpGroups.setLayout(new GridLayout(3, false));

    groupsViewer = new ListViewer(grpGroups, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE);
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    groupsViewer.setContentProvider(contentProvider);
    groupsViewer.setInput(BeanProperties.list(EditableConfiguration.EDITABLE_GROUPS)
            .observe(configurationViewModels.getConfigModel().getValue()));

    groupList = groupsViewer.getList();
    GridData gd_viewer = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 6);
    gd_viewer.widthHint = 125;
    groupList.setLayoutData(gd_viewer);
    groupList.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL) {
                groupEditorViewModel.removeGroup(groupList.getSelectionIndex());
            }
        }
    });
    new Label(grpGroups, SWT.NONE);
    new Label(grpGroups, SWT.NONE);
    new Label(grpGroups, SWT.NONE);

    Group grpSelectedGroup = new Group(this, SWT.NONE);
    grpSelectedGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpSelectedGroup.setText("Selected group");
    grpSelectedGroup.setLayout(new GridLayout(3, false));

    Label lblEditName = new Label(grpSelectedGroup, SWT.NONE);
    GridData gd_lblEditName = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblEditName.horizontalIndent = 10;
    lblEditName.setLayoutData(gd_lblEditName);
    lblEditName.setText("Name:");

    name = new Text(grpSelectedGroup, SWT.BORDER);
    GridData gd_name = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_name.widthHint = 125;
    name.setLayoutData(gd_name);
    name.setEnabled(false);

    componentDetails = new Label(grpSelectedGroup, SWT.NONE);
    componentDetails.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.ITALIC));
    componentDetails.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    Group grpBlocks = new Group(grpSelectedGroup, SWT.NONE);
    grpBlocks.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    grpBlocks.setLayout(new GridLayout(1, false));
    grpBlocks.setText("Blocks");

    blocksEditor = new DoubleListEditor(grpBlocks, SWT.NONE, "name", true);
    blocksEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    blocksEditor.addSelectionListenerForSelecting(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            EditableGroup group = groupEditorViewModel.getSelectedGroup(groupList.getSelectionIndex());
            if (group != null) {
                group.toggleSelection(blocksEditor.unselectedItems());
            }
        }
    });

    blocksEditor.addSelectionListenerForUnselecting(new SelectionAdapter() {
        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            EditableGroup group = groupEditorViewModel.getSelectedGroup(groupList.getSelectionIndex());
            if (group != null) {
                group.toggleSelection(blocksEditor.selectedItems());
            }
        }
    });

    blocksEditor.addSelectionListenerForMovingUp(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            EditableGroup group = groupEditorViewModel.getSelectedGroup(groupList.getSelectionIndex());
            if (group != null) {
                group.moveBlockUp(blocksEditor.selectedItem());
                blocksEditor.refreshViewer();
            }
        }
    });

    blocksEditor.addSelectionListenerForMovingDown(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            EditableGroup group = groupEditorViewModel.getSelectedGroup(groupList.getSelectionIndex());
            if (group != null) {
                group.moveBlockDown(blocksEditor.selectedItem());
                blocksEditor.refreshViewer();
            }
        }
    });

    // bind group name change box to selected group name with validation
    BlockServerNameValidator groupRules = Configurations.getInstance().variables().groupRules.getValue();
    final GroupNameValidator groupNamesValidator = new GroupNameValidator(
            configurationViewModels.getConfigModel().getValue(), messageDisplayer, groupRules);
    strategy.setBeforeSetValidator(groupNamesValidator);
    bindingContext.bindValue(
            WidgetProperties.text(SWT.Modify).observe(name), ViewerProperties.singleSelection()
                    .value(BeanProperties.value("name", EditableGroup.class)).observe(groupsViewer),
            strategy, null);

    name.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent arg0) {
            groupsViewer.refresh();
        }
    });

    IObservableList selectedBlocks = ViewerProperties.singleSelection()
            .list(BeanProperties.list("selectedBlocks", EditableGroup.class)).observe(groupsViewer);
    IObservableList unselectedBlocks = ViewerProperties.singleSelection()
            .list(BeanProperties.list("unselectedBlocks", EditableGroup.class)).observe(groupsViewer);

    Button spacerButton = new Button(grpGroups, SWT.NONE);
    GridData gd_spacerButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_spacerButton.heightHint = 201;
    spacerButton.setLayoutData(gd_spacerButton);
    spacerButton.setVisible(false);

    Button btnUp = new Button(grpGroups, SWT.NONE);
    GridData gd_btnUp = new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1);
    gd_btnUp.widthHint = 25;
    btnUp.setLayoutData(gd_btnUp);
    btnUp.setImage(ResourceManager.getPluginImage("uk.ac.stfc.isis.ibex.ui", "icons/move_up.png"));
    btnUp.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            groupEditorViewModel.moveGroupUp(groupList.getSelectionIndex());
        }
    });

    Button btnDown = new Button(grpGroups, SWT.NONE);
    GridData gd_btnDown = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
    gd_btnDown.widthHint = 25;
    btnDown.setLayoutData(gd_btnDown);
    btnDown.setImage(ResourceManager.getPluginImage("uk.ac.stfc.isis.ibex.ui", "icons/move_down.png"));
    btnDown.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            groupEditorViewModel.moveGroupDown(groupList.getSelectionIndex());
        }
    });

    Button btnAdd = new Button(grpGroups, SWT.NONE);
    GridData gd_btnAdd = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_btnAdd.widthHint = 70;
    btnAdd.setLayoutData(gd_btnAdd);
    btnAdd.setText("Add");

    btnAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            groupEditorViewModel.addNewGroup();
        }
    });

    final Button btnRemove = new Button(grpGroups, SWT.NONE);
    btnRemove.setEnabled(false);
    GridData gd_btnRemove = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
    gd_btnRemove.widthHint = 70;
    btnRemove.setLayoutData(gd_btnRemove);
    btnRemove.setText("Remove");

    btnRemove.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            groupEditorViewModel.removeGroup(groupList.getSelectionIndex());
        }
    });
    new Label(grpGroups, SWT.NONE);

    groupsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent arg0) {
            int selectionIndex = groupList.getSelectionIndex();
            groupNamesValidator.setSelectedIndex(selectionIndex);
            if (selectionIndex == -1) {
                groupNamesValidator.validate("");
            } else {
                groupNamesValidator.validate(groupList.getSelection()[0]);
            }
            boolean canEditSelected = groupEditorViewModel.canEditSelected(selectionIndex);

            btnRemove.setEnabled(canEditSelected);
            name.setEnabled(canEditSelected);
            blocksEditor.setEnabled(canEditSelected);

        }
    });

    blocksEditor.bind(unselectedBlocks, selectedBlocks);
}

From source file:uk.ac.stfc.isis.ibex.ui.devicescreens.dialogs.ConfigureDeviceScreensListPanel.java

License:Open Source License

/**
 * Creates the screens list part of the display.
 * //  ww w. j av a2s. co  m
 * @param mainComposite the parent composite
 */
private void createListGroup(Composite mainComposite) {
    Group grpList = new Group(mainComposite, SWT.NONE);
    grpList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    grpList.setText("Device Screens");
    grpList.setLayout(new GridLayout(2, false));

    screensViewer = new ListViewer(grpList, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    screensViewer.setContentProvider(new ObservableListContentProvider());
    screensViewer.setInput(BeanProperties.list("screens").observe(viewModel));

    viewModel.addPropertyChangeListener("name", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            screensViewer.refresh();
        }
    });

    List devicesList = screensViewer.getList();
    GridData gdViewer = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    devicesList.setLayoutData(gdViewer);
    devicesList.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL) {
                viewModel.deleteSelectedScreens();
            }
        }
    });

    Composite orderComposite = new Composite(grpList, SWT.NONE);
    orderComposite.setLayout(new GridLayout(1, false));
    orderComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));

    Composite btnsComposite = new Composite(grpList, SWT.NONE);
    btnsComposite.setLayout(new GridLayout(2, false));
    btnsComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));

    Button btnAdd = new Button(btnsComposite, SWT.NONE);
    btnAdd.setText("Add");
    GridData gdBtnAdd = new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1);
    gdBtnAdd.widthHint = 100;
    btnAdd.setLayoutData(gdBtnAdd);
    btnAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewModel.addScreen();
        }
    });

    Button btnDelete = new Button(btnsComposite, SWT.NONE);
    btnDelete.setText("Delete");
    GridData gdBtnDelete = new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1);
    gdBtnDelete.widthHint = 100;
    btnDelete.setLayoutData(gdBtnDelete);
    btnDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewModel.deleteSelectedScreens();
        }
    });

    bindingContext.bindList(ViewersObservables.observeMultiSelection(screensViewer),
            BeanProperties.list("selectedScreens").observe(viewModel));
}

From source file:uk.ac.stfc.isis.ibex.ui.nicos.NicosView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout glParent = new GridLayout(2, true);
    glParent.marginRight = 10;// ww w . j a va  2s  .  com
    glParent.marginHeight = 10;
    glParent.marginWidth = 10;
    parent.setLayout(glParent);

    // Connection info
    Composite connectionGrp = new Composite(parent, SWT.NONE);
    connectionGrp.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 2, 1));
    GridLayout connLayout = new GridLayout(2, false);
    connLayout.marginRight = 10;
    connLayout.marginHeight = 10;
    connLayout.marginWidth = 10;
    connectionGrp.setLayout(connLayout);

    Label lblConnectionStatus = new Label(connectionGrp, SWT.NONE);
    GridData connStatusLayoutData = new GridData(SWT.BEGINNING, SWT.FILL, false, true, 1, 1);
    connStatusLayoutData.widthHint = 100;
    lblConnectionStatus.setLayoutData(connStatusLayoutData);
    bindingContext.bindValue(WidgetProperties.text().observe(lblConnectionStatus),
            BeanProperties.value("connectionStatus").observe(model), null, new ConnectionStatusConverter());

    Label lblConnectionError = new Label(connectionGrp, SWT.NONE);
    lblConnectionError.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    bindingContext.bindValue(WidgetProperties.text().observe(lblConnectionError),
            BeanProperties.value("connectionErrorMessage").observe(model));

    Composite currentScriptInfoContainer = new Composite(parent, SWT.NONE);
    currentScriptInfoContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    currentScriptInfoContainer.setLayout(new GridLayout(2, false));

    lblCurrentScriptStatus = new Label(currentScriptInfoContainer, SWT.NONE);
    lblCurrentScriptStatus.setText("Current script status: ");

    Label lineNumberIndicator = new Label(currentScriptInfoContainer, SWT.NONE);
    lineNumberIndicator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    bindingContext.bindValue(WidgetProperties.text().observe(lineNumberIndicator),
            BeanProperties.value("lineNumber").observe(scriptStatusViewModel));

    Label lblOutput = new Label(parent, SWT.NONE);
    lblOutput.setText("Output");

    StyledText txtCurrentScript = new StyledText(parent, SWT.BORDER);
    txtCurrentScript.setEditable(false);
    txtCurrentScript.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    final StyledText txtOutput = new StyledText(parent, SWT.V_SCROLL | SWT.BORDER);
    txtOutput.setEditable(false);
    txtOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));

    bindingContext.bindValue(WidgetProperties.text().observe(txtCurrentScript),
            BeanProperties.value("currentlyExecutingScript").observe(model));

    bindingContext.bindValue(WidgetProperties.text().observe(txtOutput),
            BeanProperties.value("log").observe(outputLogViewModel));

    txtOutput.addListener(SWT.Modify, new Listener() {
        @Override
        public void handleEvent(Event e) {
            txtOutput.setTopIndex(txtOutput.getLineCount() - 1);
        }
    });

    Label lblQueuedScripts = new Label(parent, SWT.NONE);
    lblQueuedScripts.setText("Queued scripts (double click to see contents):");

    ListViewer queuedScriptsViewer = new ListViewer(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    List list = queuedScriptsViewer.getList();
    list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    queuedScriptsViewer.setContentProvider(new ObservableListContentProvider());
    queuedScriptsViewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            QueuedScript code = (QueuedScript) element;
            return code.getName();
        }
    });

    queuedScriptsViewer.setInput(BeanProperties.list("queuedScripts").observe(model));

    queuedScriptsViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            QueuedScript selection = (QueuedScript) ((IStructuredSelection) event.getSelection())
                    .getFirstElement();
            ExistingScriptDialog dialog = new ExistingScriptDialog(shell, selection);
            dialog.open();
        }
    });

    Composite scriptSendGrp = new Composite(parent, SWT.NONE);
    scriptSendGrp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout ssgLayout = new GridLayout(3, false);
    ssgLayout.marginHeight = 10;
    ssgLayout.marginWidth = 10;
    scriptSendGrp.setLayout(ssgLayout);

    Button btnCreateScript = new Button(scriptSendGrp, SWT.NONE);
    btnCreateScript.setText("Create Script");
    btnCreateScript.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));

    Label lblQueueScriptStatus = new Label(scriptSendGrp, SWT.NONE);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
    layoutData.widthHint = 80;
    lblQueueScriptStatus.setLayoutData(layoutData);
    bindingContext.bindValue(WidgetProperties.text().observe(lblQueueScriptStatus),
            BeanProperties.value("scriptSendStatus").observe(queueScriptViewModel), null,
            new ScriptSendStatusConverter());

    Label lblQueueScriptError = new Label(scriptSendGrp, SWT.NONE);
    lblQueueScriptError.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    bindingContext.bindValue(WidgetProperties.text().observe(lblQueueScriptError),
            BeanProperties.value("scriptSendErrorMessage").observe(queueScriptViewModel));

    btnCreateScript.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            QueueScriptDialog dialog = new QueueScriptDialog(shell, queueScriptViewModel);
            dialog.open();
        }
    });

    NicosControlButtonPanel controlPanel = new NicosControlButtonPanel(parent, SWT.NONE, scriptStatusViewModel);
    controlPanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

}