Example usage for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection

List of usage examples for org.eclipse.jface.databinding.viewers ViewerProperties singleSelection

Introduction

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

Prototype

public static IViewerValueProperty singleSelection() 

Source Link

Document

Returns a value property for observing the single selection of a ISelectionProvider .

Usage

From source file:phasereditor.assetpack.ui.preview.SpritesheetAssetPreviewComp.java

License:Open Source License

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    ////from w  ww .  j  a  v  a 2s.c  om
    IObservableValue observeSingleSelection_comboViewer = ViewerProperties.singleSelection()
            .observe(_comboViewer);
    IObservableValue fps_selfObserveValue = BeanProperties.value("fps").observe(_self);
    bindingContext.bindValue(observeSingleSelection_comboViewer, fps_selfObserveValue, null, null);
    //
    return bindingContext;
}

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 . jav  a2s.  co  m*/
 * @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.co.saiman.eclipse.model.ui.provider.editor.CellEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void createVisibleWhenControl(Composite parent, EMFDataBindingContext context) {
    final Label l = new Label(parent, SWT.NONE);
    l.setText(Messages.ModelTooling_UIElement_VisibleWhen);
    l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    final ComboViewer combo = new ComboViewer(parent);
    combo.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
    combo.setContentProvider(new ArrayContentProvider());
    combo.setLabelProvider(new LabelProvider() {
        @Override/*from  w ww.j  a v  a2  s . co  m*/
        public String getText(Object element) {
            if (element instanceof EClass) {
                final EClass eClass = (EClass) element;
                return eClass.getName();
            }

            return super.getText(element);
        }
    });
    final List<Object> list = new ArrayList<>();
    list.add(Messages.MenuItemEditor_NoExpression);
    list.add(UiPackageImpl.Literals.CORE_EXPRESSION);
    list.add(UiPackageImpl.Literals.IMPERATIVE_EXPRESSION);
    list.addAll(getEditor().getFeatureClasses(UiPackageImpl.Literals.EXPRESSION,
            UiPackageImpl.Literals.UI_ELEMENT__VISIBLE_WHEN));
    combo.setInput(list);
    context.bindValue(ViewerProperties.singleSelection().observe(combo),
            EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__VISIBLE_WHEN)
                    .observeDetail(getMaster()),
            new UpdateValueStrategy<>().setConverter(new EClass2EObject()),
            new UpdateValueStrategy<>().setConverter(new EObject2EClass()));
}