Example usage for org.eclipse.jface.viewers ComboViewer setLabelProvider

List of usage examples for org.eclipse.jface.viewers ComboViewer setLabelProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ComboViewer setLabelProvider.

Prototype

@Override
public void setLabelProvider(IBaseLabelProvider labelProvider) 

Source Link

Document

The list viewer implementation of this Viewer framework method ensures that the given label provider is an instance of ILabelProvider.

Usage

From source file:org.bonitasoft.studio.decision.ui.DecisionTableWizardPage.java

License:Open Source License

/**
 * @param gridPlaceholder //from   www.ja v a  2  s .  c o  m
 * @param gridPlaceHolder
 * @return 
 */
public Composite createGrid(final Composite gridPlaceholder) {
    gridPlaceholder.setBackgroundMode(SWT.INHERIT_FORCE);
    int nbColumns = 7; // Edit, delete, up, down, space (on the left) +  arrow & Action (on the right);
    int nbMaxConditions = 0;
    for (DecisionTableLine line : decisionTable.getLines()) {
        nbMaxConditions = Math.max(line.getConditions().size(), nbMaxConditions);
    }
    if (nbMaxConditions > 0) {
        nbColumns += 2 * nbMaxConditions - 1;
    }
    final GridLayout layout = new GridLayout(nbColumns, false);
    gridPlaceholder.setLayout(layout);
    gridPlaceholder.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false));

    {
        Composite filler = new Composite(gridPlaceholder, SWT.NONE);
        GridData fillerLayoutData = new GridData(0, 0);
        fillerLayoutData.horizontalSpan = 5;
        filler.setLayoutData(fillerLayoutData);
        // TITLE
        if (nbMaxConditions > 0) {
            Label conditionsLabel = new Label(gridPlaceholder, SWT.NONE);
            conditionsLabel.setText(Messages.conditions);
            conditionsLabel
                    .setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, conditionsLabel));
            conditionsLabel.setLayoutData(
                    new GridData(SWT.CENTER, SWT.NONE, false, false, 2 * nbMaxConditions - 1, 1));
        }

        new Composite(gridPlaceholder, SWT.NONE).setLayoutData(new GridData(0, 0));

        Label decisionLabel = new Label(gridPlaceholder, SWT.NONE);
        decisionLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.FILL)
                .grab(false, false).span(1, 1).create());
        decisionLabel.setText(Messages.decision);
        decisionLabel.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, decisionLabel));
    }

    final GridData iconButtonLayoutData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
    iconButtonLayoutData.heightHint = DELETE_SIZE;
    iconButtonLayoutData.widthHint = DELETE_SIZE;
    final GridData oneCellFillerLayoutData = new GridData(0, 0);
    final GridData andLayoutData = new GridData(SWT.FILL, SWT.CENTER, false, false);

    for (int i = 0; i < decisionTable.getLines().size(); i++) {
        final int index = i;
        final DecisionTableLine line = decisionTable.getLines().get(i);

        if (line != toEditLine) {
            Composite editLineComposite = createImageButton(gridPlaceholder, Pics.getImage(PicsConstants.edit));
            editLineComposite.setBackground(
                    zebraGridPaintListener.getColorForControl(gridPlaceholder, editLineComposite));
            editLineComposite.setLayoutData(iconButtonLayoutData);
            editLineComposite.setToolTipText(Messages.editRow);
            editLineComposite.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
                    toEditLine = line;
                    lineWorkingCopy = EcoreUtil.copy(toEditLine);
                    updateLineButton.setEnabled(true);
                    zebraGridPaintListener.setSelectedRow(index);
                    refresh(true, true);
                }
            });
        } else {
            new Composite(gridPlaceholder, SWT.NONE).setLayoutData(new GridData(0, 0));
        }

        Composite deleteLineComposite = createImageButton(gridPlaceholder, Pics.getImage(PicsConstants.remove));
        deleteLineComposite
                .setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, deleteLineComposite));
        deleteLineComposite.setLayoutData(iconButtonLayoutData);
        deleteLineComposite.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseDown(MouseEvent e) {
                if (MessageDialog.openConfirm(gridPlaceholder.getShell(), Messages.deleteLineTitle,
                        Messages.deleteLineMessage)) {
                    deleteLine(line);
                }
            }
        });

        if (index != 0) {
            Composite lineUpComposite = createImageButton(gridPlaceholder,
                    Pics.getImage(PicsConstants.arrowUp));
            lineUpComposite
                    .setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, lineUpComposite));
            lineUpComposite.setLayoutData(iconButtonLayoutData);
            lineUpComposite.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
                    decisionTable.getLines().remove(index);
                    decisionTable.getLines().add(index - 1, line);
                    zebraGridPaintListener.setSelectedRow(decisionTable.getLines().indexOf(line));
                    refreshGrid();
                }
            });
        } else {
            new Composite(gridPlaceholder, SWT.NONE).setLayoutData(oneCellFillerLayoutData);
        }

        if (i != decisionTable.getLines().size() - 1) {
            Composite lineDownComposite = createImageButton(gridPlaceholder,
                    Pics.getImage(PicsConstants.arrowDown));
            lineDownComposite.setBackground(
                    zebraGridPaintListener.getColorForControl(gridPlaceholder, lineDownComposite));
            lineDownComposite.setLayoutData(iconButtonLayoutData);
            lineDownComposite.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
                    decisionTable.getLines().remove(index);
                    decisionTable.getLines().add(index + 1, line);
                    zebraGridPaintListener.setSelectedRow(decisionTable.getLines().indexOf(line));
                    refreshGrid();
                }
            });
        } else {
            new Composite(gridPlaceholder, SWT.NONE).setLayoutData(oneCellFillerLayoutData);
        }

        if (!line.getConditions().isEmpty()) {
            new Composite(gridPlaceholder, SWT.NONE).setLayoutData(new GridData(0, 20));
        }

        Label andLabel = null;
        for (Expression cond : line.getConditions()) {
            Label condLabel = new Label(gridPlaceholder, SWT.NONE);
            condLabel.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, condLabel));
            String stringCondition = cond.getContent();
            if (stringCondition.length() > 15) {
                condLabel.setToolTipText(stringCondition);
                stringCondition = stringCondition.substring(0, 12) + "...";
            }
            condLabel.setText(stringCondition);
            andLabel = new Label(gridPlaceholder, SWT.NONE);
            andLabel.setText(Messages.and);
            andLabel.setForeground(GRAY);
            andLabel.setLayoutData(andLayoutData);
            andLabel.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, andLabel));
        }
        if (andLabel != null) {
            andLabel.dispose();
        }

        if (line.getConditions().size() < nbMaxConditions) {
            Composite filler = new Composite(gridPlaceholder, SWT.NONE);
            int nbColumnsToFill = 0;
            if (line.getConditions().isEmpty()) {
                nbColumnsToFill = 2 * (nbMaxConditions - line.getConditions().size()) - 1;
            } else {
                nbColumnsToFill = 2 * (nbMaxConditions - line.getConditions().size());
            }
            GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, nbColumnsToFill, 1);
            gd.widthHint = gd.heightHint = 0;
            filler.setLayoutData(gd);
        }

        if (line.getConditions().isEmpty()) {
            Label condLabel = new Label(gridPlaceholder, SWT.NONE);
            condLabel.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, condLabel));
            condLabel.setText(Messages.noConditionDefined);
            condLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
        }

        Composite arrow = createImageButton(gridPlaceHolder, Pics.getImage(PicsConstants.arrowRight));
        arrow.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, arrow));
        final GridData arrowlayoutData = new GridData(16, 16);
        arrowlayoutData.horizontalAlignment = SWT.RIGHT;
        arrowlayoutData.grabExcessHorizontalSpace = true;
        arrow.setLayoutData(arrowlayoutData);

        final ComboViewer lineValueCombo = new ComboViewer(gridPlaceholder, SWT.READ_ONLY);
        lineValueCombo.setContentProvider(new ArrayContentProvider());
        if (wizard.getActionsComparer() != null) {
            lineValueCombo.setComparer(wizard.getActionsComparer());
        }
        lineValueCombo.setLabelProvider(wizard.getActionLabelProvider());
        lineValueCombo.setInput(wizard.getPossibleLineActions());
        lineValueCombo.setSelection(new StructuredSelection(line.getAction()));
        lineValueCombo.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent arg0) {
                final DecisionTableAction action = EcoreUtil
                        .copy((DecisionTableAction) ((IStructuredSelection) lineValueCombo.getSelection())
                                .getFirstElement());
                line.setAction(action);
            }
        });
        lineValueCombo.getControl().setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    }

    { // ADD LINE
        Link addRowLink = new Link(gridPlaceholder, SWT.TRANSPARENT);
        addRowLink.setText("<A>" + Messages.addRow + "</A>");
        addRowLink.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, addRowLink));
        addRowLink.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 5, 1)); // Edit, up, down, delete
        addRowLink.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                DecisionTableLine newRow = DecisionFactory.eINSTANCE.createDecisionTableLine();
                newRow.setAction(EcoreUtil.copy(wizard.getPossibleLineActions()[0]));
                decisionTable.getLines().add(newRow);
                toEditLine = newRow;
                lineWorkingCopy = EcoreUtil.copy(newRow);
                updateLineButton.setEnabled(true);
                zebraGridPaintListener.setSelectedRow(decisionTable.getLines().indexOf(newRow));
                refresh(true, true);
            }
        });
        Composite filler = new Composite(gridPlaceholder, SWT.NONE);
        final GridData layoutData = new GridData(SWT.FILL, SWT.NONE, false, false, 2 * nbMaxConditions + 1, 1);
        layoutData.heightHint = layoutData.heightHint = 0;
        filler.setLayoutData(layoutData);
    }

    { // DEFAULT
        Label defaultLabel = new Label(gridPlaceholder, SWT.NONE);
        defaultLabel.setText(Messages.defaultLine);
        defaultLabel.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, defaultLabel));
        defaultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 5, 1)); // Edit, up, down, delete
        if (nbMaxConditions > 0) {
            Composite filler = new Composite(gridPlaceholder, SWT.NONE);
            final GridData layoutData = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false,
                    2 * nbMaxConditions - 1, 1);
            layoutData.heightHint = layoutData.widthHint = 0;
            filler.setLayoutData(layoutData);
        }
        Composite arrow = createImageButton(gridPlaceHolder, Pics.getImage(PicsConstants.arrowRight));
        arrow.setBackground(zebraGridPaintListener.getColorForControl(gridPlaceholder, arrow));
        final GridData arrowlayoutData = new GridData(16, 16);
        arrowlayoutData.horizontalAlignment = SWT.END;
        arrowlayoutData.grabExcessHorizontalSpace = true;
        arrow.setLayoutData(arrowlayoutData);

        final ComboViewer defaultValueCombo = new ComboViewer(gridPlaceholder, SWT.READ_ONLY);
        defaultValueCombo.setContentProvider(new ArrayContentProvider());
        if (wizard.getActionsComparer() != null) {
            defaultValueCombo.setComparer(wizard.getActionsComparer());
        }
        defaultValueCombo.setLabelProvider(wizard.getActionLabelProvider());
        defaultValueCombo.setInput(wizard.getPossibleDefaultTableActions());
        if (decisionTable.getDefaultAction() != null) {
            defaultValueCombo.setSelection(new StructuredSelection(decisionTable.getDefaultAction()));
        }
        defaultValueCombo.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent arg0) {
                final DecisionTableAction action = EcoreUtil.copy(
                        (DecisionTableAction) ((IStructuredSelection) arg0.getSelection()).getFirstElement());
                decisionTable.setDefaultAction(action);
            }
        });
        defaultValueCombo.getControl().setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    }

    return gridPlaceholder;
}

From source file:org.bonitasoft.studio.expression.editor.operation.OperatorSelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite//from w  ww . j  a  v  a 2  s.c o  m
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, SWT.DEFAULT).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).create());
    final Label operatorType = new Label(mainComposite, SWT.NONE);
    operatorType.setText(Messages.operatorType);

    final ComboViewer operatorViewer = new ComboViewer(mainComposite, SWT.READ_ONLY | SWT.BORDER);
    operatorViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    operatorViewer.setContentProvider(new ArrayContentProvider());
    operatorViewer.setLabelProvider(new OperatorLabelProvider());
    operatorViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            Expression exp = operation.getLeftOperand();
            if (exp != null && !exp.getReferencedElements().isEmpty()
                    && ExpressionConstants.VARIABLE_TYPE.equals(exp.getType())) {
                EObject data = exp.getReferencedElements().get(0);
                if (data instanceof BusinessObjectData) {
                    return element.equals(ExpressionConstants.CREATE_BUSINESS_DATA_OPERATOR)
                            || element.equals(ExpressionConstants.JAVA_METHOD_OPERATOR);
                } else if (data instanceof JavaObjectData) {
                    return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR)
                            || element.equals(ExpressionConstants.JAVA_METHOD_OPERATOR);
                } else if (data instanceof XMLData) {
                    return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR)
                            || element.equals(ExpressionConstants.XPATH_UPDATE_OPERATOR);
                } else {
                    return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR);
                }
            } else if (exp != null && !exp.getReferencedElements().isEmpty()
                    && ExpressionConstants.DOCUMENT_REF_TYPE.equals(exp.getType())) {
                return element.equals(ExpressionConstants.SET_DOCUMENT_OPERATOR);
            }
            return element.equals(ExpressionConstants.ASSIGNMENT_OPERATOR);
        }
    });

    operatorViewer.setInput(operatorTypeList);

    section = new Section(mainComposite, Section.NO_TITLE);
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    Expression exp = operation.getLeftOperand();
    for (IOperatorEditor opEditor : operatorEditors) {
        if (!opEditor.appliesTo(exp) && opEditor.appliesTo(operator.getType())) {
            operator.setType(ExpressionConstants.ASSIGNMENT_OPERATOR);
        }
    }
    createOperatorEditorFor(section, operator.getType(), operator, exp);

    context.bindValue(ViewersObservables.observeSingleSelection(operatorViewer),
            EMFObservables.observeValue(operator, ExpressionPackage.Literals.OPERATOR__TYPE));
    operatorViewer.addSelectionChangedListener(this);

    return mainComposite;
}

From source file:org.bonitasoft.studio.properties.form.sections.actions.contributions.WidgetModifierContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    dataBindingContext = new EMFDataBindingContext();
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
    final ComboViewer modifiersCombo = new ComboViewer(composite, SWT.READ_ONLY | SWT.BORDER);
    modifiersCombo.getControl().setLayoutData(GridDataFactory.fillDefaults().indent(5, 0).create());
    modifiersCombo.setLabelProvider(new LabelProvider());
    modifiersCombo.setContentProvider(new ArrayContentProvider());
    modifiersCombo.setSorter(new ViewerSorter());
    modifiersCombo.setInput(getAvailableModifiersFor(widget));
    modifiersCombo.addSelectionChangedListener(this);

    final ControlDecoration deco = new ControlDecoration(modifiersCombo.getControl(), SWT.LEFT);
    deco.setDescriptionText(Messages.modifierDescription);
    deco.setImage(Pics.getImage(PicsConstants.hint));
    deco.setMarginWidth(2);/*from w w  w .ja v a  2  s.  c  o  m*/
    deco.setShowOnlyOnFocus(false);

    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(modifiersCombo), EMFEditObservables
            .observeValue(editingDomain, widget, FormPackage.Literals.WIDGET__RETURN_TYPE_MODIFIER));
}

From source file:org.bonitasoft.studio.properties.form.sections.useraids.contributions.ExamplePropertySectionContribution.java

License:Open Source License

public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory,
        ExtensibleGridPropertySection extensibleGridPropertySection) {
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(20, 0).create());
    if (dataBindingContext != null) {
        dataBindingContext.dispose();/*from  w  w  w .j  a  va 2s. co m*/
    }

    dataBindingContext = new EMFDataBindingContext();
    ExpressionViewer exampleMessageViewer = new ExpressionViewer(composite, SWT.BORDER, widgetFactory,
            editingDomain, FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE);
    exampleMessageViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Expression exampleMessageExpression = element.getExampleMessage();
    if (exampleMessageExpression == null) {
        exampleMessageExpression = ExpressionFactory.eINSTANCE.createExpression();
        editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, element,
                FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE, exampleMessageExpression));
    }
    exampleMessageViewer.setMessage(Messages.UserAidsSection_Example_Tooltip, IStatus.INFO);
    dataBindingContext.bindValue(ViewerProperties.singleSelection().observe(exampleMessageViewer),
            EMFEditProperties.value(editingDomain, FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE)
                    .observe(element));

    exampleMessageViewer.addFilter(new AvailableExpressionTypeFilter(
            new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
                    ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.SCRIPT_TYPE }));

    exampleMessageViewer.setInput(element);

    ComboViewer positionViewer = new ComboViewer(composite);
    positionViewer.setContentProvider(new ArrayContentProvider());
    positionViewer.setLabelProvider(new LabelPositionLabelProvider());
    positionViewer.setInput(new LabelPosition[] { LabelPosition.DOWN, LabelPosition.UP });
    dataBindingContext.bindValue(ViewersObservables.observeSingleSelection(positionViewer), EMFEditObservables
            .observeValue(editingDomain, element, FormPackage.Literals.FORM_FIELD__EXAMPLE_MESSAGE_POSITION));
}

From source file:org.bonitasoft.studio.properties.sections.iteration.IterationPropertySection.java

License:Open Source License

protected ComboViewer createComboViewer(final TabbedPropertySheetWidgetFactory widgetFactory,
        final Composite composite, final ObservableListContentProviderWithProposalListeners contentProvider) {
    final ComboViewer comboViewer = new ComboViewer(composite, SWT.BORDER | SWT.READ_ONLY);

    comboViewer.setContentProvider(contentProvider);
    final IObservableSet knownElements = contentProvider.getKnownElements();
    final IObservableMap[] labelMaps = EMFObservables.observeMaps(knownElements,
            new EStructuralFeature[] { ProcessPackage.Literals.ELEMENT__NAME,
                    ProcessPackage.Literals.DATA__DATA_TYPE, ProcessPackage.Literals.DATA__MULTIPLE });
    comboViewer.setLabelProvider(new DataLabelProvider(labelMaps));

    final ToolBar toolBar = new ToolBar(composite, SWT.FLAT);
    widgetFactory.adapt(toolBar);//from   w  w  w .  jav  a  2 s.  c  o  m
    final ToolItem toolItem = new ToolItem(toolBar, SWT.FLAT);
    toolItem.setImage(Pics.getImage(PicsConstants.clear));
    toolItem.setToolTipText(Messages.clearSelection);
    toolItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            comboViewer.setSelection(new StructuredSelection());
        }
    });

    return comboViewer;
}

From source file:org.bonitasoft.studio.properties.sections.loop.MultiInstantiationPropertyContribution.java

License:Open Source License

protected ComboViewer createChooser(TabbedPropertySheetWidgetFactory widgetFactory,
        Composite inputOutputDataComposite) {
    final ComboViewer comboViewer = new ComboViewer(
            new Combo(inputOutputDataComposite, SWT.BORDER | SWT.READ_ONLY));
    comboViewer.setContentProvider(new ObservableListContentProvider());
    comboViewer.setLabelProvider(new DataLabelProvider());
    comboViewer.getControl()//from  w w w  .  jav a  2  s.com
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).create());
    ToolBar toolBar = new ToolBar(inputOutputDataComposite, SWT.FLAT);
    widgetFactory.adapt(toolBar);
    ToolItem toolItem = new ToolItem(toolBar, SWT.FLAT);
    toolItem.setImage(Pics.getImage(PicsConstants.clear));
    toolItem.setToolTipText(Messages.clearSelection);
    toolItem.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            comboViewer.setSelection(new StructuredSelection());
        }
    });
    return comboViewer;
}

From source file:org.bonitasoft.studio.properties.sections.subprocess.ParametersMappingSection.java

License:Open Source License

private ComboViewer createProcessTargetCombo(final Composite outputMappingControl,
        final OutputMapping mapping) {
    final ComboViewer processTargetCombo = new ComboViewer(
            getWidgetFactory().createCCombo(outputMappingControl, SWT.READ_ONLY | SWT.BORDER));
    processTargetCombo.setContentProvider(new IStructuredContentProvider() {
        @Override//from   ww  w  . j  a  va 2 s  .com
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ModelHelper.getAccessibleData(getSubProcess()).toArray();
        }
    });
    processTargetCombo.setLabelProvider(new EMFFeatureLabelProvider(ProcessPackage.Literals.ELEMENT__NAME));
    processTargetCombo.addPostSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            getEditingDomain().getCommandStack()
                    .execute(new SetCommand(getEditingDomain(), mapping,
                            ProcessPackage.Literals.OUTPUT_MAPPING__PROCESS_TARGET,
                            ((IStructuredSelection) event.getSelection()).getFirstElement()));
        }
    });
    processTargetCombo.setInput(getSubProcess());
    processTargetCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    if (mapping.getProcessTarget() != null) {
        processTargetCombo.setSelection(new StructuredSelection(mapping.getProcessTarget()));
    }
    return processTargetCombo;
}

From source file:org.bonitasoft.studio.properties.sections.subprocess.ParametersMappingSection.java

License:Open Source License

private ComboViewer createInputMappingSourceCombo(final Composite outputMappingControl,
        final InputMapping mapping) {
    final ComboViewer srcCombo = new ComboViewer(
            getWidgetFactory().createCCombo(outputMappingControl, SWT.READ_ONLY | SWT.BORDER));
    srcCombo.setContentProvider(new IStructuredContentProvider() {
        @Override/*from www.j av a2s .c om*/
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return ModelHelper.getAccessibleData(getSubProcess()).toArray();
        }
    });
    srcCombo.setLabelProvider(new EMFFeatureLabelProvider(ProcessPackage.Literals.ELEMENT__NAME));
    srcCombo.addPostSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            getEditingDomain().getCommandStack()
                    .execute(new SetCommand(getEditingDomain(), mapping,
                            ProcessPackage.Literals.INPUT_MAPPING__PROCESS_SOURCE,
                            ((IStructuredSelection) event.getSelection()).getFirstElement()));
        }
    });
    srcCombo.setInput(getSubProcess());
    srcCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
    if (mapping.getProcessSource() != null) {
        srcCombo.setSelection(new StructuredSelection(mapping.getProcessSource()));
    }
    return srcCombo;
}

From source file:org.bonitasoft.studio.simulation.properties.contributions.DataChangesContribution.java

License:Open Source License

@Override
public void createControl(final Composite composite, final TabbedPropertySheetWidgetFactory widgetFactory,
        final ExtensibleGridPropertySection extensibleGridPropertySection) {

    composite.setLayout(new GridLayout(1, false));

    context = new EMFDataBindingContext();
    dynamicComposite = new DynamicAddRemoveLineComposite(composite, SWT.NONE) {

        @Override//from  w  w  w. ja va  2 s.  com
        protected org.eclipse.swt.widgets.Button createAddButton(Composite parent) {
            org.eclipse.swt.widgets.Button addButton = new Button(parent, SWT.FLAT);
            addButton.setText(Messages.add);
            return addButton;
        };

        @Override
        protected Control createLineComposite(Composite parent, Object object) {
            final DataChange dataChange;
            if (object instanceof DataChange) {
                dataChange = (DataChange) object;
            } else {
                dataChange = SimulationFactory.eINSTANCE.createDataChange();
                AddCommand addCommand = new AddCommand(editingDomain, eObject,
                        SimulationPackage.Literals.SIMULATION_ACTIVITY__DATA_CHANGE, dataChange);
                editingDomain.getCommandStack().execute(addCommand);
            }
            Composite lineComposite = getWidgetFactory().createComposite(parent);
            composites.add(lineComposite);
            lineComposite.setLayout(new GridLayout(5, false));

            getWidgetFactory().createLabel(lineComposite, Messages.Data);

            final Combo combo = new Combo(lineComposite, SWT.READ_ONLY);
            combo.setLayoutData(GridDataFactory.swtDefaults().hint(85, SWT.DEFAULT).create());
            final ComboViewer viewer = new ComboViewer(combo);
            viewer.setLabelProvider(new LabelProvider() {
                @Override
                public String getText(Object element) {
                    return ((SimulationData) element).getName();
                };
            });
            viewer.setContentProvider(ArrayContentProvider.getInstance());
            viewer.setInput(ModelHelper.getParentProcess(eObject).getSimulationData());
            if (dataChange.getData() != null) {
                viewer.setSelection(new StructuredSelection(dataChange.getData()));
            }
            getWidgetFactory().createLabel(lineComposite, Messages.Expression);

            final ExpressionViewer expressionText = new ExpressionViewer(lineComposite, SWT.BORDER,
                    widgetFactory, editingDomain, SimulationPackage.Literals.DATA_CHANGE__VALUE);
            expressionText.addFilter(
                    new AvailableExpressionTypeFilter(new String[] { ExpressionConstants.CONSTANT_TYPE,
                            ExpressionConstants.SIMULATION_VARIABLE_TYPE, ExpressionConstants.SCRIPT_TYPE }));
            expressionText.getControl()
                    .setLayoutData(GridDataFactory.swtDefaults().hint(250, SWT.DEFAULT).create());

            Expression selection = dataChange.getValue();
            if (selection == null) {
                selection = ExpressionFactory.eINSTANCE.createExpression();
                editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, dataChange,
                        SimulationPackage.Literals.DATA_CHANGE__VALUE, selection));
            }
            context.bindValue(ViewerProperties.singleSelection().observe(expressionText), EMFEditProperties
                    .value(editingDomain, SimulationPackage.Literals.DATA_CHANGE__VALUE).observe(dataChange));
            expressionText.setInput(dataChange);
            //expressionText.setSelection(new StructuredSelection(selection)) ;

            Button createDataButton = new Button(lineComposite, SWT.FLAT);
            createDataButton.setText(Messages.createSimulationData);
            createDataButton.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    AddSimulationDataWizard wiz = new AddSimulationDataWizard(
                            ModelHelper.getParentProcess(eObject), editingDomain);
                    if (new WizardDialog(Display.getDefault().getActiveShell(), wiz)
                            .open() == WizardDialog.OK) {
                        viewer.setInput(ModelHelper.getParentProcess(eObject).getSimulationData());
                        viewer.setSelection(new StructuredSelection(wiz.getCreatedData()));
                        //                            expressionText.reset() ;
                        //                            expressionText.setText(GroovyUtil.GROOVY_PREFIX + wiz.getCreatedData().getName() + GroovyUtil.GROOVY_SUFFIX);
                    }

                }

            });

            createButtons.add(createDataButton);
            combos.add(combo);
            dataChanges.add(dataChange);
            bindings.add(context.bindValue(ViewersObservables.observeSingleSelection(viewer), EMFEditObservables
                    .observeValue(editingDomain, dataChange, SimulationPackage.Literals.DATA_CHANGE__DATA)));

            return lineComposite;
        }

        @Override
        protected void lineRemoved(int i) {
            composites.remove(i);
            createButtons.remove(i);
            combos.remove(i);
            context.removeBinding(bindings.get(i));
            bindings.remove(i);
            DataChange dataChange = dataChanges.get(i);
            RemoveCommand removeCommand = new RemoveCommand(editingDomain, eObject,
                    SimulationPackage.Literals.SIMULATION_ACTIVITY__DATA_CHANGE, dataChange);
            editingDomain.getCommandStack().execute(removeCommand);
            dataChanges.remove(i);
            extensibleGridPropertySection.getTabbedPropertySheetPage().resizeScrolledComposite();
        }

        @Override
        protected void lineAdded(int i) {
            extensibleGridPropertySection.getTabbedPropertySheetPage().resizeScrolledComposite();
        }

        @Override
        protected TabbedPropertySheetWidgetFactory getWidgetFactory() {
            return widgetFactory;
        }

        @Override
        protected Composite getTopComposite() {
            return (Composite) extensibleGridPropertySection.getTabbedPropertySheetPage().getControl();
        }

    };
    dynamicComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    fillDynamicWidget();

}

From source file:org.bonitasoft.studio.validators.ui.wizard.ValidatorWizardPage.java

License:Open Source License

protected void createTypeCombo(Composite mainComposite) {
    Label typeLabel = new Label(mainComposite, SWT.NONE);
    typeLabel.setText(Messages.validatorType);
    typeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    final ComboViewer typeViewer = new ComboViewer(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    typeViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    typeViewer.setContentProvider(new ArrayContentProvider());
    typeViewer.setLabelProvider(new LabelProvider() {
        @Override//w  ww .  j  ava  2  s  .  c om
        public String getText(Object element) {
            if (element == ValidatorType.FILED_VALIDATOR) {
                return Messages.fieldValidator;
            } else if (element == ValidatorType.PAGE_VALIDATOR) {
                return Messages.pageValidator;
            }
            return super.getText(element);
        }
    });
    typeViewer.setInput(ValidatorType.values());
    typeViewer.getCombo().setEnabled(!editMode);
    context.bindValue(ViewersObservables.observeSingleSelection(typeViewer),
            EMFObservables.observeValue(validator, ValidatorPackage.Literals.VALIDATOR_DESCRIPTOR__TYPE));
}