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

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

Introduction

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

Prototype

public ComboViewer(Composite parent, int style) 

Source Link

Document

Creates a combo viewer on a newly-created combo control under the given parent.

Usage

From source file:net.texo.USDLSecurityEditor.PageBuilder.java

License:Open Source License

/**
 * Creates the auth z mechanism group.//  w ww.j  a  v a2s  .  co  m
 *
 * @param parent the parent
 * @param aspect the aspect
 * @param action the action
 * @return the group
 */
public Group createAuthZMechanismGroup(final Composite parent, final SecurityAspect aspect,
        final AuthorizationMechanism action) {

    if (parent == null)
        return null;
    if (aspect == null)
        return null;
    if (action == null)
        return null;

    Group gAction = new Group(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(gAction);
    GridDataFactory.swtDefaults().span(2, 1).applyTo(gAction);
    gAction.setText(action.getType().getLiteral());

    toolkit.createLabel(gAction, "Authorization Method: ");
    ComboViewer cvAuthZMethod = new ComboViewer(gAction, SWT.READ_ONLY);
    cvAuthZMethod.setContentProvider(ArrayContentProvider.getInstance());
    ArrayList<String> list = new ArrayList<String>();
    for (Iterator<AuthorizationMechanismType> j = AuthorizationMechanismType.VALUES.iterator(); j.hasNext();) {
        list.add(j.next().getLiteral());
    }
    cvAuthZMethod.setInput(list);

    toolkit.createLabel(gAction, "Authorization Expression: ");
    final Text tExpression = toolkit.createText(gAction, "", SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    GridDataFactory.swtDefaults().hint(300, 45).applyTo(tExpression);

    toolkit.createLabel(gAction, "Authorization Language: ");
    final ComboViewer cvExprLang = new ComboViewer(gAction, SWT.READ_ONLY);
    cvExprLang.setContentProvider(ArrayContentProvider.getInstance());
    cvExprLang.setInput(secProfile.retrieveExpressionLanguages());
    cvExprLang.getCombo().setEnabled(false);

    /** TODO **/
    AuthZMechanismProxy pAction = new AuthZMechanismProxy(editor, aspect, action, gAction, cvAuthZMethod,
            tExpression, cvExprLang);
    editor.ActionProxies.put(action, pAction);
    /****/

    cvAuthZMethod.addSelectionChangedListener(new AuthZMechanismListener(editor, aspect, action));
    cvAuthZMethod.setSelection(new StructuredSelection(pAction.getAuthZType()), true);

    tExpression.addModifyListener(new AuthZExpressionListener(editor, aspect, action));
    tExpression.setText(pAction.getExpression());

    cvExprLang.addSelectionChangedListener(new AuthZExprLangListener(editor, aspect, action));
    cvExprLang.setSelection(new StructuredSelection(pAction.getExprLang()));

    return gAction;
}

From source file:net.texo.USDLSecurityEditor.PageBuilder.java

License:Open Source License

/**
 * Creates the security aspect composite.
 *
 * @param parent the parent/*from   w ww .  j  a  v a 2s . c o m*/
 * @param aspect the aspect
 * @return the composite
 */
public Composite createSecurityAspectComposite(final Composite parent, final SecurityAspect aspect) {

    ComboViewer cvReqLevel;
    ArrayList<String> list;

    final Composite cAspect = toolkit.createComposite(parent);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(cAspect);

    toolkit.createLabel(cAspect, "Requirement Level: ");
    cvReqLevel = new ComboViewer(cAspect, SWT.READ_ONLY);
    cvReqLevel.setContentProvider(ArrayContentProvider.getInstance());
    list = new ArrayList<String>();
    for (Iterator<SecurityRequirementLevel> i = SecurityRequirementLevel.VALUES.iterator(); i.hasNext();) {
        list.add(i.next().getLiteral());
    }
    cvReqLevel.setInput(list);

    /** TODO **/
    SecurityAspectProxy pAspect = new SecurityAspectProxy(editor, aspect, cvReqLevel);
    editor.AspectProxies.put(aspect, pAspect);
    /****/

    cvReqLevel.setSelection(new StructuredSelection(aspect.getLevel().getName()));
    cvReqLevel.addSelectionChangedListener(new ReqLevelForAspectListener(editor, aspect));

    java.util.List<SecurityActionType> mechTypes = secOnt.getSupportingSecurityActionTypes(aspect.getType());
    for (Iterator<SecurityActionType> i = mechTypes.iterator(); i.hasNext();) {

        SecurityActionType actionType = i.next();
        SecurityAction action = editor.model.getRealizingAction(aspect.getType(), actionType);

        Group gAction;
        if (action instanceof AuthorizationMechanism) {
            gAction = createAuthZMechanismGroup(cAspect, aspect, (AuthorizationMechanism) action);
        } else {
            gAction = createSecurityMechanismGroup(cAspect, aspect, (SecurityMechanism) action);
        }
        GridDataFactory.swtDefaults().span(2, 1).applyTo(gAction);

        /** TODO **/
        pAspect.addAction(action);
        /****/
    }

    return cAspect;
}

From source file:org.bbaw.pdr.ae.export.swt.FileSelectionGroup.java

License:Open Source License

/**
 * Initializes the embedded widgets serving as the components of this
 * file selector template.//  www.ja v  a2s  .c  o m
 * <p>The arrangement of the template components will be more or less like 
 * this:
 * <blockquote>
 * <table style="border:1px solid;"><tr>
 * <td style="border:1px solid;">label</td>
 * <td style="border:1px solid;">combo viewer</td>
 * <td style="border:1px solid;">button</td></tr></table>
 * </blockquote>
 * </p>
 * @param label Descriptive text label
 * @param colspan Number of columns the template is desired to cover within
 * its parent's layout
 * @see #init(String, String, int)
 */
public void init(String label, int colspan) {
    // initialize connection to central export functionalities
    provider = AeExportCoreProvider.getInstance();

    ((GridData) container.getLayoutData()).horizontalSpan = colspan;

    if ((container.getStyle() & SWT.CHECK) == SWT.CHECK) {
        checkEnable = new Button(container, SWT.CHECK);
        checkEnable.setText(label);
        //TODO: enabler listener
    } else {
        dsclabel = new Label(container, SWT.LEFT);
        dsclabel.setText(label);
    }

    filenameCombo = new ComboViewer(container, SWT.ALL);
    Combo combo = filenameCombo.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    combo.setEnabled(true);
    filenameCombo.setLabelProvider(new LabelProvider());
    filenameCombo.setContentProvider(ArrayContentProvider.getInstance());

    default_filename = provider.getWizardProvider(wizardPage.getWizard()).getDefaultFilename(configuration);
    log.log(new Status(IStatus.INFO, CommonActivator.PLUGIN_ID,
            " Default file name for configuration '" + configuration + "': " + default_filename));

    String[] recent = provider.getHistoryAsArray(pluginId, configuration);
    log.log(new Status(IStatus.INFO, CommonActivator.PLUGIN_ID,
            "  Recent file list for configuration '" + configuration + "': " + recent.length));
    // if history could be restored
    if (recent.length > 0)
        filenameCombo.setInput(recent);
    else if (default_filename != null)
        filenameCombo.setInput(new String[] { default_filename });
    if (combo.getItemCount() > 0)
        combo.setText(combo.getItem(0));
    //validate();
    new FilenameChangedListener();

    //TODO: listener on losing focus!!!

    browseButton = new Button(container, SWT.PUSH);
    browseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    browseButton.setText(NLMessages.getString("export.fileselector.browse.button"));
    browseButton.addSelectionListener(new SelectButtonListener());
    // check if everything is correct.
    validate();
}

From source file:org.bbaw.pdr.ae.view.identifiers.view.IdentifierSearchView.java

License:Open Source License

/**
 * Create contents of the view part.// w  ww.j  a v  a2s. c  o m
 */
@Override
public void createPartControl(Composite parent) {
    createSelectionListener();
    IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    ISelectionService selService = ww.getSelectionService();
    selService.addSelectionListener(AEPluginIDs.VIEW_TREEVIEW, _mainSelectionListener);
    _facade.addObserver(this);
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    _resultMap = new HashMap<PdrId, ConcurrenceDataHead>();
    Composite compositeHead = new Composite(container, SWT.NONE);
    compositeHead.setLayout(new GridLayout(5, false));
    compositeHead.setLayoutData(new GridData());
    ((GridData) compositeHead.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) compositeHead.getLayoutData()).grabExcessHorizontalSpace = true;
    SelectionAdapter radioSelAdapter = new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            _searchTarget = (Integer) ((Button) e.getSource()).getData();
        }
    };
    Label lblPersonsToProcess = new Label(compositeHead, SWT.NONE);
    lblPersonsToProcess.setText("Persons:");

    Button btnRadioButton = new Button(compositeHead, SWT.RADIO);
    btnRadioButton.setData(0);

    btnRadioButton.addSelectionListener(radioSelAdapter);
    btnRadioButton.setText("All Persons");

    Button btnRadioButton_1 = new Button(compositeHead, SWT.RADIO);
    btnRadioButton_1.setText("Selected Tree");
    btnRadioButton_1.setData(1);
    btnRadioButton_1.addSelectionListener(radioSelAdapter);

    Button btnRadioButton_2 = new Button(compositeHead, SWT.RADIO);
    btnRadioButton_2.setText("Selected Persons");
    btnRadioButton_2.setData(2);
    btnRadioButton_2.addSelectionListener(radioSelAdapter);
    btnRadioButton_2.setSelection(_searchTarget == 2);

    Button chaine2Selection = new Button(compositeHead, SWT.CHECK);
    chaine2Selection.setText("Chain2Selection");
    chaine2Selection.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            _chain2Selection = !_chain2Selection;
        }

    });
    chaine2Selection.setSelection(_chain2Selection);

    Composite composite_2 = new Composite(compositeHead, SWT.NONE);
    composite_2.setLayout(new GridLayout(4, false));
    composite_2.setLayoutData(new GridData());
    ((GridData) composite_2.getLayoutData()).horizontalSpan = 5;
    ((GridData) composite_2.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) composite_2.getLayoutData()).grabExcessHorizontalSpace = true;

    Label lblWebservice = new Label(composite_2, SWT.NONE);
    lblWebservice.setText("Webservice");

    ComboViewer comboViewer = new ComboViewer(composite_2, SWT.READ_ONLY);
    Combo combo_1 = comboViewer.getCombo();
    combo_1.setLayoutData(new GridData());
    ((GridData) combo_1.getLayoutData()).horizontalSpan = 2;
    ((GridData) combo_1.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) combo_1.getLayoutData()).grabExcessHorizontalSpace = true;
    comboViewer.setContentProvider(new AEConfigPresentableContentProvider());
    comboViewer.setLabelProvider(new AEConfigPresentableLabelProvider());
    if (IdentifiersExtension.getConcurrenceSearchServices() != null) {
        comboViewer.setInput(IdentifiersExtension.getConcurrenceSearchServices());
    }
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            ISelection iSelection = event.getSelection();
            Object obj = ((IStructuredSelection) iSelection).getFirstElement();
            _concurrenceSearchService = (IConcurrenceSearchService) obj;

        }
    });

    Object in = comboViewer.getInput();
    if (in instanceof Map<?, ?>) {
        Map<String, IConcurrenceSearchService> map = (Map<String, IConcurrenceSearchService>) in;
        String pdrKey = null;
        for (String s : map.keySet()) {
            if (s.toLowerCase().contains("pdr")) {
                pdrKey = s;
                break;
            }
        }
        if (pdrKey != null) {
            IConcurrenceSearchService service = map.get(pdrKey);
            comboViewer.setSelection(new StructuredSelection(service));
        } else if (comboViewer.getElementAt(0) != null) {
            comboViewer.setSelection(new StructuredSelection(comboViewer.getElementAt(0)));
        }
    }

    Button btnGo = new Button(composite_2, SWT.NONE);
    btnGo.setText("GO");
    btnGo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (_selectedPerson != null) {
                if (_resultMap == null) {
                    _resultMap = new HashMap<PdrId, ConcurrenceDataHead>();
                }
                if (!_resultMap.containsKey(_selectedPerson.getPdrId())) {
                    searchConcurringPersons(_searchTarget, _concurrenceSearchService);
                } else if (_resultMap.containsKey(_selectedPerson.getPdrId())
                        && !_resultMap.get(_selectedPerson.getPdrId()).getServices()
                                .contains(_concurrenceSearchService.getLabel())) {
                    searchConcurringPersons(_searchTarget, _concurrenceSearchService);
                } else {
                    loadConcurrenceData(_selectedPerson, _resultMap.get(_selectedPerson.getPdrId()));
                }
            } else if (_searchTarget < 2) {
                searchConcurringPersons(_searchTarget, _concurrenceSearchService);
            }
        }

    });

    _scrolledComposite = new ScrolledComposite(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    _scrolledComposite.setLayoutData(new GridData());
    ((GridData) _scrolledComposite.getLayoutData()).horizontalSpan = 1;
    ((GridData) _scrolledComposite.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) _scrolledComposite.getLayoutData()).grabExcessHorizontalSpace = true;
    ((GridData) _scrolledComposite.getLayoutData()).verticalAlignment = SWT.FILL;
    ((GridData) _scrolledComposite.getLayoutData()).grabExcessVerticalSpace = true;
    _scrolledComposite.setExpandHorizontal(true);
    _scrolledComposite.setExpandVertical(true);
    _scrolledComposite.setBackground(AEVIEWConstants.VIEW_BACKGROUND_SELECTED_COLOR);

    _contentComposite = new Composite(_scrolledComposite, SWT.NONE);
    _contentComposite.setLayout(new GridLayout(1, false));
    _scrolledComposite.setContent(_contentComposite);
    _contentComposite.setLayoutData(new GridData());
    ((GridData) _contentComposite.getLayoutData()).horizontalSpan = 1;
    ((GridData) _contentComposite.getLayoutData()).horizontalAlignment = SWT.FILL;
    ((GridData) _contentComposite.getLayoutData()).grabExcessHorizontalSpace = true;
    ((GridData) _contentComposite.getLayoutData()).verticalAlignment = SWT.FILL;
    ((GridData) _contentComposite.getLayoutData()).grabExcessVerticalSpace = true;
    _contentComposite.setBackground(AEVIEWConstants.VIEW_BACKGROUND_DESELECTED_COLOR);

}

From source file:org.bonitasoft.studio.actors.ui.section.AbstractActorsPropertySection.java

License:Open Source License

private void createActorComboViewer(Composite mainComposite) {
    actorComboViewer = new ComboViewer(mainComposite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
    actorComboViewer.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    actorComboViewer.setContentProvider(new ArrayContentProvider());
    actorComboViewer.setLabelProvider(new LabelProvider() {
        @Override// w w  w  . j ava 2 s  .c o  m
        public String getText(Object element) {
            if (element instanceof Actor) {
                String doc = ((Actor) element).getDocumentation();
                if (doc != null && !doc.isEmpty()) {
                    doc = " -- " + doc;
                } else {
                    doc = "";
                }
                return ((Actor) element).getName() + doc;
            }
            return super.getText(element);
        }
    });
}

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//  w  ww .j  a  v  a 2 s  . c om
            .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   w  w  w . j  a v a2  s  .co 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()// w w  w .j  a v  a2  s .  com
            .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  ww  .ja v a  2 s . com
}

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// w ww.ja  v  a 2  s .  co  m
            .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;
}