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.bbaw.pdr.ae.view.main.editors.SourceEditorDialog.java

License:Open Source License

/**
 * Load names./* ww w  .j a  v  a 2  s  .  com*/
 * @param contentComp the content comp
 */
private void loadNames(final Composite contentComp) {
    Composite namesComp = new Composite(contentComp, SWT.NONE);
    namesComp.setLayoutData(new GridData());
    ((GridData) namesComp.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) namesComp.getLayoutData()).grabExcessHorizontalSpace = true;
    namesComp.setLayout(new GridLayout());
    ((GridLayout) namesComp.getLayout()).numColumns = 5;
    ((GridLayout) namesComp.getLayout()).makeColumnsEqualWidth = false;
    ((GridLayout) namesComp.getLayout()).marginHeight = 0;
    ((GridLayout) namesComp.getLayout()).marginWidth = 0;
    for (int i = 0; i < _currentReference.getNameMods().size(); i++) {
        final NameMods n = _currentReference.getNameMods().get(i);

        Label label5 = new Label(namesComp, SWT.NONE);
        label5.setText(NLMessages.getString("Editor_name") + NLMessages.getString("Editor_reference_role")); //$NON-NLS-1$

        final Combo roleC = new Combo(namesComp, SWT.READ_ONLY);
        roleC.setData("name", i); //$NON-NLS-1$
        roleC.setEnabled(_mayWrite);
        roleC.setBackground(WHITE_COLOR);
        ComboViewer comboViewer = new ComboViewer(roleC);
        comboViewer.setContentProvider(ArrayContentProvider.getInstance());
        comboViewer.setLabelProvider(new LabelProvider() {

            @Override
            public String getText(final Object element) {
                String str = (String) element;
                return NLMessages.getString("Editor_role_" + str); //$NON-NLS-1$
            }

        });

        comboViewer.setInput(AEConstants.REF_ROLETERM_CODE);
        comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(final SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
                Object obj = ((IStructuredSelection) selection).getFirstElement();
                String s = (String) obj;
                _currentReference.getNameMods().get((Integer) roleC.getData("name")) //$NON-NLS-1$
                        .getRoleMods().setRoleTerm(s);
            }

        });

        if (n.getRoleMods() != null && n.getRoleMods().getRoleTerm() != null) {
            StructuredSelection selection = new StructuredSelection(n.getRoleMods().getRoleTerm());
            comboViewer.setSelection(selection);
        } else {
            StructuredSelection selection = new StructuredSelection("aut"); //$NON-NLS-1$
            comboViewer.setSelection(selection);
            n.getRoleMods().setRoleTerm("aut"); //$NON-NLS-1$

        }
        Composite namepartsComp = new Composite(namesComp, SWT.NONE);
        namepartsComp.setLayoutData(new GridData());
        ((GridData) namepartsComp.getLayoutData()).horizontalAlignment = SWT.FILL;
        ((GridData) namepartsComp.getLayoutData()).grabExcessHorizontalSpace = true;
        namepartsComp.setLayout(new GridLayout());
        ((GridLayout) namepartsComp.getLayout()).numColumns = n.getNameParts().size() * 2;
        ((GridLayout) namepartsComp.getLayout()).makeColumnsEqualWidth = false;
        ((GridLayout) namepartsComp.getLayout()).marginHeight = 0;

        int num = n.getNameParts().size();
        for (int j = 0; j < num; j++) {
            final NamePart namePart = n.getNameParts().get(j);

            if (namePart.getType() != null) {
                Label label5d = new Label(namepartsComp, SWT.NONE);
                label5d.setText(NLMessages.getString("Editor_name_" + namePart.getType()) + ":"); //$NON-NLS-1$
                label5d.pack();
            }
            final Text name = new Text(namepartsComp, SWT.BORDER);
            name.setData("name", i); //$NON-NLS-1$
            name.setData("nPart", j); //$NON-NLS-1$
            name.setEditable(_mayWrite);
            name.setBackground(WHITE_COLOR);
            final ControlDecoration decoValName = new ControlDecoration(name, SWT.LEFT | SWT.TOP);

            name.setLayoutData(new GridData());
            ((GridData) name.getLayoutData()).grabExcessHorizontalSpace = true;
            ((GridData) name.getLayoutData()).horizontalAlignment = SWT.FILL;

            name.addFocusListener(new FocusListener() {
                @Override
                public void focusGained(final FocusEvent e) {
                    String[] vals = new String[] { "test", "test2" }; //$NON-NLS-1$ //$NON-NLS-2$
                    try {
                        vals = _mainSearcher.getFacets("reference", "namePart", namePart.getType(), null, null); //$NON-NLS-1$ //$NON-NLS-2$
                    } catch (Exception e1) {

                        e1.printStackTrace();
                    }
                    new AutoCompleteField(name, new TextContentAdapter(), vals);
                    validate();

                }

                @Override
                public void focusLost(final FocusEvent e) {
                    namePart.setNamePart(name.getText());
                    validate();
                }
            });
            name.addKeyListener(new KeyListener() {

                @Override
                public void keyPressed(final KeyEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void keyReleased(final KeyEvent e) {
                    namePart.setNamePart(name.getText());
                    validate();

                }
            });
            if (namePart.getNamePart() != null) {
                name.setText(namePart.getNamePart().trim());
            }
            if (_currentReference.getTitleInfo() != null && _currentReference.getTitleInfo().isValid()
                    && _currentReference.getNameMods() != null && !_currentReference.getNameMods().isEmpty()) {

                decoValName.setImage(null);
            } else {
                decoValName.setImage(FieldDecorationRegistry.getDefault()
                        .getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED).getImage());
            }
            // max 3 nameparts
            if (j == 2) {
                break;
            }
        }
        namepartsComp.layout();

        final Button addExtra = new Button(namesComp, SWT.PUSH);
        addExtra.setText("<+>"); //$NON-NLS-1$
        addExtra.setToolTipText(NLMessages.getString("Editor_add_extra_person"));
        addExtra.setLayoutData(_gridData);
        addExtra.setData("name", i); //$NON-NLS-1$
        addExtra.setEnabled((n.getAffiliation() == null && n.getDescription() == null) && _mayWrite);
        addExtra.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent event) {
                _currentReference.getNameMods().get((Integer) addExtra.getData("name")).setType(" "); //$NON-NLS-1$ //$NON-NLS-2$
                _currentReference.getNameMods().get((Integer) addExtra.getData("name")).setAffiliation(" "); //$NON-NLS-1$ //$NON-NLS-2$
                _currentReference.getNameMods().get((Integer) addExtra.getData("name")).setDescription(" "); //$NON-NLS-1$ //$NON-NLS-2$

                loadValues(_currentReference);

            }
        });
        addExtra.setLayoutData(new GridData());

        final Button deleteName = new Button(namesComp, SWT.PUSH);
        deleteName.setText("-"); //$NON-NLS-1$
        deleteName.setToolTipText(NLMessages.getString("Editor_remove_field"));
        // deleteName.setEnabled(_mayWrite && _currentReference.isValid());
        deleteName.setLayoutData(_gridData);
        deleteName.setData("name", i); //$NON-NLS-1$
        deleteName.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent event) {

                _currentReference.getNameMods().removeElementAt((Integer) deleteName.getData("name")); //$NON-NLS-1$
                loadValues(_currentReference);

            }
        });
        if ((_currentReference.getTitleInfo() != null && _currentReference.getTitleInfo().getTitle() != null)
                || (_currentReference.getNameMods() != null && _currentReference.getNameMods().size() > 1)) {
            deleteName.setEnabled(_mayWrite);
        } else {
            deleteName.setEnabled(false);
        }
        deleteName.setLayoutData(new GridData());

        // if (i == _currentReference.getNameMods().size() -1)
        // {
        // final Button addName = new Button(namesComp, SWT.PUSH);
        //            addName.setText("+"); //$NON-NLS-1$
        // addName.setToolTipText(NLMessages.getString("Editor_add_name"));
        // addName.setEnabled(_mayWrite);
        // addName.setLayoutData(_gridData);
        // addName.addSelectionListener(new SelectionAdapter()
        // {
        // public void widgetSelected(final SelectionEvent event)
        // {
        // _currentReference.getNameMods().add(new NameMods(2));
        // loadValues(_currentReference);
        //
        //
        // } });
        // addName.setLayoutData(new GridData());
        // }
        // else{
        // new Label(namesComp, SWT.NONE);
        // }

        if (n.getType() != null && n.getAffiliation() != null && n.getDescription() != null) {
            Composite namesComp2 = new Composite(namesComp, SWT.NONE);
            namesComp2.setLayoutData(new GridData());
            ((GridData) namesComp2.getLayoutData()).horizontalAlignment = SWT.FILL;
            ((GridData) namesComp2.getLayoutData()).grabExcessHorizontalSpace = true;
            ((GridData) namesComp2.getLayoutData()).horizontalSpan = 9;

            namesComp2.setLayout(new GridLayout());
            ((GridLayout) namesComp2.getLayout()).numColumns = 9;
            ((GridLayout) namesComp2.getLayout()).makeColumnsEqualWidth = false;
            int span = 0;
            if (n.getType() != null) {
                Label label6 = new Label(namesComp2, SWT.NONE);
                label6.setText(NLMessages.getString("Editor_type")); //$NON-NLS-1$
                final Combo typeCombo = new Combo(namesComp2, SWT.READ_ONLY);
                typeCombo.setData("name", i); //$NON-NLS-1$
                typeCombo.setEnabled(_mayWrite);
                typeCombo.setBackground(WHITE_COLOR);
                typeCombo.setText(n.getType().trim());
                typeCombo.setLayoutData(new GridData());
                // ((GridData)
                // typeCombo.getLayoutData()).horizontalAlignment =
                // SWT.FILL;
                // ((GridData)
                // typeCombo.getLayoutData()).grabExcessHorizontalSpace =
                // true;
                ((GridData) typeCombo.getLayoutData()).horizontalSpan = 1;
                ComboViewer typeComboViewer = new ComboViewer(typeCombo);
                typeComboViewer.setContentProvider(ArrayContentProvider.getInstance());
                typeComboViewer.setLabelProvider(new LabelProvider() {

                    @Override
                    public String getText(final Object element) {
                        String str = (String) element;
                        return NLMessages.getString("Editor_name_type_" + str); //$NON-NLS-1$
                    }

                });

                typeComboViewer.setInput(AEConstants.REF_NAME_TYPE);
                typeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

                    @Override
                    public void selectionChanged(final SelectionChangedEvent event) {
                        ISelection selection = event.getSelection();
                        Object obj = ((IStructuredSelection) selection).getFirstElement();
                        String s = (String) obj;
                        _currentReference.getNameMods().get((Integer) typeCombo.getData("name")) //$NON-NLS-1$
                                .setType(s);
                    }

                });
                if (n.getType().trim().length() > 0) {
                    StructuredSelection selection = new StructuredSelection(n.getType());
                    typeComboViewer.setSelection(selection);
                } else {
                    StructuredSelection selection = new StructuredSelection("personal"); //$NON-NLS-1$
                    typeComboViewer.setSelection(selection);
                    _currentReference.getNameMods().get((Integer) typeCombo.getData("name")) //$NON-NLS-1$
                            .setType("personal"); //$NON-NLS-1$
                }
                span = 2;
            }
            if (n.getAffiliation() != null) {
                Label label7 = new Label(namesComp2, SWT.NONE);
                label7.setText(NLMessages.getString("Editor_affiliation")); //$NON-NLS-1$
                final Text aff = new Text(namesComp2, SWT.BORDER);
                aff.setData("name", i); //$NON-NLS-1$
                aff.setEditable(_mayWrite);
                aff.setBackground(WHITE_COLOR);
                aff.setText(n.getAffiliation().trim());
                aff.setLayoutData(new GridData());
                ((GridData) aff.getLayoutData()).horizontalAlignment = SWT.FILL;
                ((GridData) aff.getLayoutData()).grabExcessHorizontalSpace = true;
                ((GridData) aff.getLayoutData()).horizontalSpan = 2;

                aff.addFocusListener(new FocusListener() {
                    @Override
                    public void focusGained(final FocusEvent e) {
                        String[] vals = new String[] { "test2" }; //$NON-NLS-2$
                        try {
                            vals = _mainSearcher.getFacets("reference", "affiliation", null, null, null); //$NON-NLS-1$ //$NON-NLS-2$
                        } catch (Exception e1) {

                            e1.printStackTrace();
                        }
                        new AutoCompleteField(aff, new TextContentAdapter(), vals);
                    }

                    @Override
                    public void focusLost(final FocusEvent e) {
                        _currentReference.getNameMods().get((Integer) aff.getData("name")) //$NON-NLS-1$
                                .setAffiliation(aff.getText());
                    }
                });
                span = span + 3;

            }
            if (n.getDescription() != null) {
                Label label8 = new Label(namesComp2, SWT.NONE);
                label8.setText(NLMessages.getString("Editor_description")); //$NON-NLS-1$
                final Text desc = new Text(namesComp2, SWT.BORDER);
                desc.setData("name", i); //$NON-NLS-1$
                desc.setEditable(_mayWrite);
                desc.setBackground(WHITE_COLOR);
                desc.setText(n.getDescription().trim());
                desc.setLayoutData(new GridData());
                ((GridData) desc.getLayoutData()).horizontalAlignment = SWT.FILL;
                ((GridData) desc.getLayoutData()).grabExcessHorizontalSpace = true;
                ((GridData) desc.getLayoutData()).horizontalSpan = 2;
                desc.addFocusListener(new FocusListener() {
                    @Override
                    public void focusGained(final FocusEvent e) {
                        String[] vals = new String[] { "test", "test2" }; //$NON-NLS-1$ //$NON-NLS-2$
                        try {
                            vals = _mainSearcher.getFacets("reference", "description", null, null, null); //$NON-NLS-1$ //$NON-NLS-2$
                        } catch (Exception e1) {

                            e1.printStackTrace();
                        }
                        new AutoCompleteField(desc, new TextContentAdapter(), vals);
                    }

                    @Override
                    public void focusLost(final FocusEvent e) {
                        _currentReference.getNameMods().get((Integer) desc.getData("name")) //$NON-NLS-1$
                                .setDescription(desc.getText());
                    }
                });
                span = span + 3;

            }
            if (span % 8 != 0) {
                Label bl = new Label(namesComp2, SWT.NONE);
                bl.setLayoutData(new GridData());
                ((GridData) bl.getLayoutData()).horizontalAlignment = SWT.FILL;
                ((GridData) bl.getLayoutData()).grabExcessHorizontalSpace = true;
                ((GridData) bl.getLayoutData()).horizontalSpan = 8 - span;
            }
            final Button delExtra = new Button(namesComp2, SWT.PUSH);
            delExtra.setText("-"); //$NON-NLS-1$
            delExtra.setToolTipText(NLMessages.getString("Editor_remove_name_extra"));
            delExtra.setEnabled(_mayWrite);
            delExtra.setLayoutData(_gridData);
            delExtra.setData("name", i); //$NON-NLS-1$

            delExtra.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(final SelectionEvent event) {
                    _currentReference.getNameMods().get((Integer) addExtra.getData("name")).setType(null); //$NON-NLS-1$ //$NON-NLS-2$
                    _currentReference.getNameMods().get((Integer) addExtra.getData("name")) //$NON-NLS-1$
                            .setAffiliation(null); //$NON-NLS-2$
                    _currentReference.getNameMods().get((Integer) addExtra.getData("name")) //$NON-NLS-1$
                            .setDescription(null); //$NON-NLS-2$

                    loadValues(_currentReference);

                }
            });
            delExtra.setLayoutData(new GridData());
        }

    }

}

From source file:org.bonitasoft.studio.actors.ui.wizard.page.SelectOrganizationWizardPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite/* www  .j a v  a  2s.  c o  m*/
            .setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(5, 5).equalWidth(false).create());

    Label organizationLabel = new Label(mainComposite, SWT.NONE);
    organizationLabel.setText(Messages.selectOrganization);

    final ComboViewer organizationCombo = new ComboViewer(mainComposite, SWT.READ_ONLY | SWT.BORDER);
    organizationCombo.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    organizationCombo.setContentProvider(new ArrayContentProvider());
    organizationCombo.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Organization) ((IRepositoryFileStore) element).getContent()).getName();
        }
    });

    organizationCombo.addSelectionChangedListener(this);
    organizationCombo.setInput(organizationStore.getChildren());
    String id = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
            .getString(ActorsPreferenceConstants.DEFAULT_ORGANIZATION);
    IRepositoryFileStore defaultOrganization = organizationStore
            .getChild(id + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
    if (defaultOrganization == null) {
        List<OrganizationFileStore> orga = organizationStore.getChildren();
        if (!orga.isEmpty()) {
            defaultOrganization = orga.get(0);
        }
    }
    if (defaultOrganization != null) {
        organizationCombo.setSelection(new StructuredSelection(defaultOrganization));
        refreshOrganization((Organization) defaultOrganization.getContent());
    }
    Label separator = new Label(mainComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    setControl(mainComposite);
}

From source file:org.bonitasoft.studio.businessobject.ui.expression.QueryExpressionEditor.java

License:Open Source License

private void createQueryComboViewer(final Composite composite, final IObservableList observeQueryList) {
    final Composite queryComposite = new Composite(composite, SWT.NONE);
    queryComposite.setLayoutData(GridDataFactory.fillDefaults().create());
    queryComposite/*from  www.j a v a  2 s  .  c  o m*/
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 2).create());

    final Label queryLabel = new Label(queryComposite, SWT.NONE);
    queryLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
    queryLabel.setText(Messages.queries);

    final ComboViewer queryCombo = new ComboViewer(queryComposite, SWT.READ_ONLY | SWT.BORDER);
    queryCombo.getControl()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).create());
    queryCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof Expression) {
                String name = ((Expression) element).getName();
                if (name.indexOf(".") != -1) {
                    name = name.substring(name.indexOf(".") + 1, name.length());
                }
                return name;
            }
            return super.getText(element);
        }
    });
    queryCombo.setContentProvider(new ObservableListContentProvider());

    queryCombo.setInput(observeQueryList);

    observeQuerySingleSelection = ViewersObservables.observeSingleSelection(queryCombo);
    observeBOSingleSelection.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            if (event.diff.getOldValue() != null && observeQuerySingleSelection.getValue() == null) {
                observeQuerySingleSelection.setValue(observeQueryList.get(0));
            }
        }
    });
}

From source file:org.bonitasoft.studio.businessobject.ui.expression.QueryExpressionEditor.java

License:Open Source License

private void createBusinessObjectComboViewer(final Composite composite, final IObservableList observeBoList) {
    final Composite boComposite = new Composite(composite, SWT.NONE);
    boComposite.setLayoutData(GridDataFactory.fillDefaults().create());
    boComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 2).create());

    final Label boLabel = new Label(boComposite, SWT.NONE);
    boLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
    boLabel.setText(Messages.businessObject);

    final ComboViewer boCombo = new ComboViewer(boComposite, SWT.READ_ONLY | SWT.BORDER);
    boCombo.getControl()//www  .j a  v  a 2  s.  c  o  m
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).minSize(100, SWT.DEFAULT).create());
    boCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof BusinessObjectExpressionQuery) {
                return NamingUtils.getSimpleName(((BusinessObjectExpressionQuery) element).getQualifiedName());
            }
            return super.getText(element);
        }
    });
    boCombo.setContentProvider(new ObservableListContentProvider());

    boCombo.setInput(observeBoList);

    observeBOSingleSelection = ViewersObservables.observeSingleSelection(boCombo);
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.BusinessObjectDataWizardPage.java

License:Open Source License

protected void createBusinessObjectTypeControl(final Composite mainComposite, final EMFDataBindingContext ctx) {
    final Label businessObjectLabel = new Label(mainComposite, SWT.NONE);
    businessObjectLabel.setLayoutData(fillDefaults().align(SWT.END, SWT.CENTER).create());
    businessObjectLabel.setText(Messages.businessObject + " *");

    final Composite comboComposite = new Composite(mainComposite, SWT.NONE);
    comboComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());
    comboComposite.setLayoutData(fillDefaults().grab(true, false).create());

    final ComboViewer businessObjectComboViewer = new ComboViewer(comboComposite, SWT.READ_ONLY | SWT.BORDER);
    businessObjectComboViewer.getControl().setLayoutData(fillDefaults().grab(true, false).create());
    businessObjectComboViewer.setContentProvider(new ObservableListContentProvider());
    businessObjectComboViewer.setLabelProvider(businessObjectLabelProvider());

    final WritableList businessObjectsObservableList = new WritableList(getAllBusinessObjects(),
            BusinessObject.class);

    final IViewerObservableValue observeSingleSelection = ViewersObservables
            .observeSingleSelection(businessObjectComboViewer);
    createNewBusinessObjectLink(comboComposite, businessObjectsObservableList, observeSingleSelection);
    businessObjectComboViewer.setInput(businessObjectsObservableList);

    classNameObservable = EMFObservables.observeValue(businessObjectData,
            ProcessPackage.Literals.JAVA_OBJECT_DATA__CLASS_NAME);
    ctx.bindValue(observeSingleSelection, classNameObservable,
            updateValueStrategy().withConverter(businessObjectToFQN())
                    .withValidator(mandatoryValidator(Messages.businessObject)).create(),
            updateValueStrategy().withConverter(fqnToBusinessObject()).create());

    defaultValueReturnTypeObservable = EMFObservables.observeValue(businessObjectData.getDefaultValue(),
            ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE);

    final String className = businessObjectData.getClassName();
    if ((className == null || className.isEmpty()) && !businessObjectsObservableList.isEmpty()) {
        observeSingleSelection.setValue(businessObjectsObservableList.get(0));
    }/*from   w  w w.  j av  a2s .  c o m*/
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.control.AttributesTabItemControl.java

License:Open Source License

private Composite createRelationFieldDetailContent(final Group detailGroup, final DataBindingContext ctx,
        final IViewerObservableValue attributeSelectionObservable,
        final IViewerObservableValue viewerObservableValue) {
    final Composite composite = new Composite(detailGroup, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    composite/* ww w.  j  av  a  2  s .c  om*/
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).spacing(15, 10).create());

    final Label relationKindLabel = new Label(composite, SWT.NONE);
    relationKindLabel.setLayoutData(GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).create());
    relationKindLabel.setText(Messages.relation);

    final ControlDecoration controlDecoration = new ControlDecoration(relationKindLabel, SWT.RIGHT);
    controlDecoration.setDescriptionText(Messages.realtionTooltip);
    controlDecoration.setImage(Pics.getImage(PicsConstants.hint));
    controlDecoration.setMarginWidth(-2);

    final ComboViewer relationComboViewer = new ComboViewer(composite, SWT.BORDER | SWT.READ_ONLY);
    relationComboViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    relationComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    relationComboViewer.setLabelProvider(new RelationKindLabelProvider());
    relationComboViewer.setInput(RelationField.Type.values());

    ctx.bindValue(ViewersObservables.observeSingleSelection(relationComboViewer),
            PojoObservables.observeDetailValue(attributeSelectionObservable, "type", Type.class));

    new Label(composite, SWT.NONE);

    final Composite lazyRadioComposite = new Composite(composite, SWT.NONE);
    lazyRadioComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    lazyRadioComposite
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(25, 0).create());

    final Button lazyRadio = new Button(lazyRadioComposite, SWT.RADIO);
    lazyRadio.setLayoutData(GridDataFactory.swtDefaults().grab(false, false).create());
    lazyRadio.setText(Messages.loadOnDemand);

    final ControlDecoration lazyDecorator = new ControlDecoration(lazyRadio, SWT.RIGHT);
    lazyDecorator.setImage(Pics.getImage(PicsConstants.hint));
    lazyDecorator.setDescriptionText(Messages.loadOnDemandHint);
    lazyDecorator.setMarginWidth(-5);

    final Button eagerRadio = new Button(lazyRadioComposite, SWT.RADIO);
    eagerRadio.setLayoutData(GridDataFactory.swtDefaults().grab(false, false).create());
    eagerRadio.setText(Messages.alwaysLoad);

    final ControlDecoration eagerDecorator = new ControlDecoration(eagerRadio, SWT.RIGHT);
    eagerDecorator.setImage(Pics.getImage(PicsConstants.hint));
    eagerDecorator.setMarginWidth(-5);
    viewerObservableValue.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            final BusinessObject bo = (BusinessObject) event.diff.getNewValue();
            if (bo != null) {
                eagerDecorator.setDescriptionText(Messages.bind(Messages.alwaysLoadHint,
                        NamingUtils.getSimpleName(bo.getQualifiedName())));
            }
        }
    });

    final SelectObservableValue radioGroupObservable = new SelectObservableValue(FetchType.class);
    radioGroupObservable.addOption(FetchType.LAZY, SWTObservables.observeSelection(lazyRadio));
    radioGroupObservable.addOption(FetchType.EAGER, SWTObservables.observeSelection(eagerRadio));
    ctx.bindValue(radioGroupObservable,
            PojoObservables.observeDetailValue(attributeSelectionObservable, "fetchType", FetchType.class));

    return composite;
}

From source file:org.bonitasoft.studio.businessobject.ui.wizard.QueryWizardPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    final DataBindingContext ctx = new DataBindingContext();

    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(10, 10).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    final Link queryLabel = new Link(composite, SWT.NO_FOCUS);
    queryLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
    queryLabel.setText(Messages.queryLink);
    queryLabel.addSelectionListener(new SelectionAdapter() {

        @Override//from w w  w .  j a v  a 2  s.com
        public void widgetSelected(final SelectionEvent e) {
            performHelp();
        }
    });

    final StyledText queryText = createQueryText(composite);
    queryText.setFont(getMonospaceFont());
    queryText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 120).create());

    if (query.getContent() == null || query.getContent().isEmpty()) {
        final String queryExample = createQueryExample(businessObject);
        query.setContent(queryExample);
        if (query.getQueryParameters().isEmpty()) {
            for (final Field f : businessObject.getFields()) {
                if (f instanceof SimpleField) {
                    query.addQueryParameter(f.getName(), ((SimpleField) f).getType().getClazz().getName());
                }
            }
        }
    }

    final UpdateValueStrategy targetStrategy = new UpdateValueStrategy();
    targetStrategy.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            if (value == null || value.toString().trim().isEmpty()) {
                return ValidationStatus.error(Messages.emptyQueryError);
            }
            return checkParametersUsage(value.toString());
        }
    });
    final UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            return checkParametersUsage(value.toString());
        }
    });

    queryBinding = ctx.bindValue(SWTObservables.observeText(queryText, SWT.Modify),
            PojoObservables.observeValue(getQuery(), "content"), targetStrategy, strategy);

    final Label queryParamLabel = new Label(composite, SWT.NONE);
    queryParamLabel
            .setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.FILL).indent(0, 10).create());
    queryParamLabel.setText(Messages.parameters);

    final ControlDecoration controlDecoration = new ControlDecoration(queryParamLabel, SWT.RIGHT);
    controlDecoration.setImage(Pics.getImage(PicsConstants.hint));
    controlDecoration.setDescriptionText(Messages.jpqlParametersHint);
    controlDecoration.setShowOnlyOnFocus(false);

    createQueryParametersTable(composite, ctx);

    final Label queryResultTypeLabel = new Label(composite, SWT.NONE);
    queryResultTypeLabel
            .setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).indent(0, 5).create());
    queryResultTypeLabel.setText(Messages.queryResultType);

    final ComboViewer resultTypeViewer = createReturnTypeComboViewer(composite);
    resultTypeViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    resultTypeViewer.setContentProvider(ArrayContentProvider.getInstance());
    resultTypeViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(final Object element) {
            final String className = element.toString();
            if (List.class.getName().equals(className)) {
                return Messages.multipleReturnType;
            } else if (Long.class.getName().equals(className)) {
                return className + " (COUNT,SUM...etc)";
            } else if (Double.class.getName().equals(className)) {
                return className + " (AVG...etc)";
            } else if (businessObject.getQualifiedName().equals(className)) {
                return Messages.bind(Messages.single, businessObject.getQualifiedName());
            }
            return super.getText(element);
        }
    });
    resultTypeViewer.setInput(getSupportedReturnTypes(businessObject));
    final IViewerObservableValue returnTypeSelectionObservable = ViewersObservables
            .observeSingleSelection(resultTypeViewer);
    ctx.bindValue(returnTypeSelectionObservable, PojoObservables.observeValue(getQuery(), "returnType"));
    returnTypeSelectionObservable.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            queryBinding.validateTargetToModel();
        }
    });
    WizardPageSupport.create(this, ctx);
    setControl(composite);
}

From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite//from w w w .j ava  2s.c  o m
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(400, SWT.DEFAULT).create());
    mainComposite
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).spacing(15, 5).create());

    context = new DataBindingContext();
    if (component == null) {
        component = ConnectorDefinitionFactory.eINSTANCE.createText();
    }
    final Label idLabel = new Label(mainComposite, SWT.NONE);
    idLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    idLabel.setText(Messages.widgetId + "*");

    final Text idText = new Text(mainComposite, SWT.BORDER);
    idText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    idTextObservable = SWTObservables.observeText(idText, SWT.Modify);
    bindComponentId(idText);

    final Label widgetTypeLabel = new Label(mainComposite, SWT.NONE);
    widgetTypeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    widgetTypeLabel.setText(Messages.widgetType);

    final ComboViewer typeViewer = new ComboViewer(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    typeViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    typeViewer.setContentProvider(new ArrayContentProvider());
    typeViewer.setLabelProvider(new WidgetLabelProvider());
    typeViewer.setInput(widgetTypes);

    typeViewer.setSelection(new StructuredSelection(component.eClass()));

    final Label inputLabel = new Label(mainComposite, SWT.NONE);
    inputLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    inputLabel.setText(Messages.input + " *");

    final ComboViewer inputViewer = new ComboViewer(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    inputViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    inputViewer.setContentProvider(new ArrayContentProvider());
    inputViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            Input input = (Input) element;
            return super.getText(input.getName() + " (" + input.getType() + ")");
        }
    });
    inputViewer.setInput(inputs);
    inputSelectionObservable = ViewersObservables.observeSingleSelection(inputViewer);
    bindComponentInput(inputViewer);

    final Label displayNameLabel = new Label(mainComposite, SWT.NONE);
    displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    displayNameLabel.setText(Messages.displayName);

    final Text displayNameText = new Text(mainComposite, SWT.BORDER);
    displayNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    context.bindValue(SWTObservables.observeText(displayNameText, SWT.Modify),
            PojoProperties.value(SelectPageWidgetDialog.class, "displayName").observe(this));

    final Label descriptionLabel = new Label(mainComposite, SWT.NONE);
    descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());
    descriptionLabel.setText(Messages.description);

    final Text descriptionText = new Text(mainComposite, SWT.BORDER | SWT.MULTI);
    descriptionText
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 60).create());

    context.bindValue(SWTObservables.observeText(descriptionText, SWT.Modify),
            PojoProperties.value(SelectPageWidgetDialog.class, "description").observe(this));

    section = new Section(parent, Section.NO_TITLE);
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).create());
    section.setClient(createSectionClient(component));
    section.setExpanded(isExpanded(component));

    typeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            EClass eClass = (EClass) ((IStructuredSelection) event.getSelection()).getFirstElement();
            String id = null;
            if (component != null) {
                id = component.getId();
            }
            String input = null;
            if (component instanceof WidgetComponent) {
                input = ((WidgetComponent) component).getInputName();
            }
            component = (Component) ConnectorDefinitionFactory.eINSTANCE.create(eClass);
            component.setId(id);
            if (component instanceof WidgetComponent) {
                ((WidgetComponent) component).setInputName(input);
            }
            bindComponentId(idText);
            bindComponentInput(inputViewer);

            section.setClient(createSectionClient(component));
            section.setExpanded(isExpanded(component));
            Shell shell = section.getShell();
            Point defaultSize = shell.getSize();
            Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
            shell.setSize(defaultSize.x, size.y);
            shell.layout(true, true);
        }
    });

    dialogSupport = DialogSupport.create(this, context);

    return mainComposite;
}

From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java

License:Open Source License

private Control createScriptEditorComposite(ScriptEditor widget) {
    final Composite mainComposite = new Composite(section, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 0).create());

    final Label interpreterLabel = new Label(mainComposite, SWT.NONE);
    interpreterLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    interpreterLabel.setText(Messages.interpreter + " *");

    final ComboViewer interpreterViewer = new ComboViewer(mainComposite, SWT.BORDER | SWT.READ_ONLY);
    interpreterViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    interpreterViewer.setContentProvider(new ArrayContentProvider());
    interpreterViewer.setLabelProvider(new LabelProvider());
    List<String> interpreters = new ArrayList<String>();
    for (IScriptLanguageProvider provider : ScriptLanguageService.getInstance().getScriptLanguageProviders()) {
        interpreters.add(provider.getLanguageName());
    }/*ww w.  j  a v a 2 s.  c o  m*/
    interpreterViewer.setInput(interpreters);
    context.bindValue(ViewersObservables.observeSingleSelection(interpreterViewer), EMFObservables
            .observeValue(widget, ConnectorDefinitionPackage.Literals.SCRIPT_EDITOR__INTERPRETER));

    return mainComposite;
}

From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java

License:Open Source License

private Control createRadioGroupComposite(final RadioGroup widget) {
    final Composite mainComposite = new Composite(section, SWT.NONE);
    mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 0).create());

    final Label orientationLabel = new Label(mainComposite, SWT.NONE);
    orientationLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    orientationLabel.setText(Messages.orientation);

    final ComboViewer orientationCombo = new ComboViewer(mainComposite, SWT.READ_ONLY | SWT.BORDER);
    orientationCombo.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    orientationCombo.setContentProvider(new ArrayContentProvider());
    orientationCombo.setLabelProvider(new LabelProvider());
    context.bindValue(ViewersObservables.observeInput(orientationCombo),
            PojoProperties.value(SelectPageWidgetDialog.class, "orientations").observe(this));
    context.bindValue(ViewersObservables.observeSingleSelection(orientationCombo),
            EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.RADIO_GROUP__ORIENTATION));

    final Label itemsLabel = new Label(mainComposite, SWT.NONE);
    itemsLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create());
    itemsLabel.setText(Messages.items);/*w ww  .  java 2 s. c  om*/

    final Composite itemComposite = new Composite(mainComposite, SWT.NONE);
    itemComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    itemComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final TableViewer itemViewer = new TableViewer(itemComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    itemViewer.getTable()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).create());
    itemViewer.setContentProvider(new ArrayContentProvider());
    final TableLayout layout = new TableLayout();
    layout.addColumnData(new ColumnWeightData(100));
    itemViewer.getTable().setLayout(layout);

    final TableViewerColumn inputNameColumn = new TableViewerColumn(itemViewer, SWT.FILL);
    inputNameColumn.getColumn().setText(Messages.input);
    inputNameColumn.setEditingSupport(new RadioGroupItemEditingSupport(itemViewer, widget));
    inputNameColumn.setLabelProvider(new ColumnLabelProvider());

    context.bindValue(ViewersObservables.observeInput(itemViewer),
            EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.RADIO_GROUP__CHOICES));

    final Composite buttonComposite = new Composite(itemComposite, SWT.NONE);
    buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
    buttonComposite
            .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create());

    final Button addButton = new Button(buttonComposite, SWT.FLAT);
    addButton.setText(Messages.Add);
    addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String item = generateRadioChoice(widget);
            widget.getChoices().add(item);
            itemViewer.editElement(item, 0);
        }

    });

    final Button upButton = new Button(buttonComposite, SWT.FLAT);
    upButton.setText(Messages.up);
    upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    upButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement();
            int i = widget.getChoices().indexOf(selected);
            if (i > 0) {
                widget.getChoices().move(i - 1, selected);
                itemViewer.refresh();
            }
        }
    });

    final Button downButton = new Button(buttonComposite, SWT.FLAT);
    downButton.setText(Messages.down);
    downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    downButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement();
            int i = widget.getChoices().indexOf(selected);
            if (i < widget.getChoices().size() - 1) {
                widget.getChoices().move(i + 1, selected);
                itemViewer.refresh();
            }
        }
    });

    final Button removeButton = new Button(buttonComposite, SWT.FLAT);
    removeButton.setText(Messages.remove);
    removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            widget.getChoices().removeAll(((IStructuredSelection) itemViewer.getSelection()).toList());
            itemViewer.refresh();
        }
    });

    return mainComposite;
}