Example usage for org.eclipse.jface.databinding.viewers IViewerValueProperty observe

List of usage examples for org.eclipse.jface.databinding.viewers IViewerValueProperty observe

Introduction

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

Prototype

@Override
public IObservableValue<T> observe(S viewer);

Source Link

Document

This method is redeclared to trigger ambiguous method errors that are hidden by a suspected Eclipse compiler bug 536911.

Usage

From source file:at.bestsolution.e4.addressbook.ui.swt.AddressForm.java

License:Open Source License

public void bindControls(DataBindingContext dbc, IObservableValue master) {
    this.dbc = dbc;
    this.master = master;

    IWidgetValueProperty tProp = WidgetProperties.text(SWT.Modify);
    IViewerValueProperty sProp = ViewerProperties.singleSelection();

    {/*from  www  .  j  a v  a2 s.c o m*/
        IEMFValueProperty mProp = EMFProperties.value(AddressbookPackage.Literals.ADDRESS__STREET);
        dbc.bindValue(tProp.observe(w_street), mProp.observeDetail(master));
    }

    {
        IEMFValueProperty mProp = EMFProperties.value(AddressbookPackage.Literals.ADDRESS__ZIP);
        dbc.bindValue(tProp.observe(w_zip), mProp.observeDetail(master));
    }

    {
        IEMFValueProperty mProp = EMFProperties.value(AddressbookPackage.Literals.ADDRESS__CITY);
        dbc.bindValue(tProp.observe(w_city), mProp.observeDetail(master));
    }

    {
        IEMFValueProperty mProp = EMFProperties
                .value(FeaturePath.fromList(AddressbookPackage.Literals.ADDRESS__COUNTRY));
        dbc.bindValue(sProp.observe(v_country), mProp.observeDetail(master));
    }

    bindState();

    IWidgetValueProperty eProp = WidgetProperties.enabled();

    for (Control c : getChildren()) {
        EMFUpdateValueStrategy modelToTarget = new EMFUpdateValueStrategy();
        modelToTarget.setConverter(new Converter(Address.class, boolean.class) {

            @Override
            public Object convert(Object fromObject) {
                return fromObject != null;
            }
        });

        final Binding b = dbc.bindValue(eProp.observe(c), master,
                new EMFUpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), modelToTarget);
        master.addValueChangeListener(new IValueChangeListener() {

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                if (event.diff.getNewValue() == null)
                    b.updateModelToTarget();
            }
        });
    }
}

From source file:at.bestsolution.e4.addressbook.ui.swt.AddressForm.java

License:Open Source License

public void bindControls(EditingDomain editingDomain, DataBindingContext dbc, IObservableValue master) {
    this.dbc = dbc;
    this.master = master;
    this.editingDomain = editingDomain;

    IWidgetValueProperty tProp = WidgetProperties.text(SWT.Modify);
    IViewerValueProperty sProp = ViewerProperties.singleSelection();

    {/*from  www .  j a  v  a  2  s.  c o  m*/
        IEMFValueProperty mProp = EMFEditProperties.value(editingDomain,
                AddressbookPackage.Literals.ADDRESS__STREET);
        dbc.bindValue(tProp.observeDelayed(PersonForm.DELAY, w_street), mProp.observeDetail(master));
    }

    {
        IEMFValueProperty mProp = EMFEditProperties.value(editingDomain,
                AddressbookPackage.Literals.ADDRESS__ZIP);
        dbc.bindValue(tProp.observeDelayed(PersonForm.DELAY, w_zip), mProp.observeDetail(master));
    }

    {
        IEMFValueProperty mProp = EMFEditProperties.value(editingDomain,
                AddressbookPackage.Literals.ADDRESS__CITY);
        dbc.bindValue(tProp.observeDelayed(PersonForm.DELAY, w_city), mProp.observeDetail(master));
    }

    {
        IEMFValueProperty mProp = EMFEditProperties.value(editingDomain,
                FeaturePath.fromList(AddressbookPackage.Literals.ADDRESS__COUNTRY));
        dbc.bindValue(sProp.observe(v_country), mProp.observeDetail(master));
    }

    bindState();

    IWidgetValueProperty eProp = WidgetProperties.enabled();

    for (Control c : getChildren()) {
        EMFUpdateValueStrategy modelToTarget = new EMFUpdateValueStrategy();
        modelToTarget.setConverter(new Converter(Address.class, boolean.class) {

            @Override
            public Object convert(Object fromObject) {
                return fromObject != null;
            }
        });

        final Binding b = dbc.bindValue(eProp.observe(c), master,
                new EMFUpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), modelToTarget);
        master.addValueChangeListener(new IValueChangeListener() {

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                if (event.diff.getNewValue() == null)
                    b.updateModelToTarget();
            }
        });
    }
}

From source file:at.bestsolution.e4.addressbook.ui.swt.AddressForm.java

License:Open Source License

private void bindState() {
    IViewerValueProperty sProp = ViewerProperties.singleSelection();
    IEMFValueProperty prop;//w  ww  .j a  va2s.  c o  m

    if (editingDomain == null) {
        prop = EMFProperties.value(AddressbookPackage.Literals.ADDRESS__FEDERAL_STATE);
    } else {
        prop = EMFEditProperties.value(editingDomain, AddressbookPackage.Literals.ADDRESS__FEDERAL_STATE);
    }
    stateBinding = dbc.bindValue(sProp.observe(v_state), prop.observeDetail(master));
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.AddIconDialog.java

License:Open Source License

@Override
protected Control createDialogContent(final Composite parent) {
    o = ParametersFactory.eINSTANCE.createIcon();
    Composite area = new Composite(parent, SWT.NONE);
    area.setLayout(new GridLayout(1, false));
    area.setLayoutData(new GridData(GridData.FILL_BOTH));

    getShell().setText("Add icon");
    setTitle("Add icon");
    setMessage("Enter informations about the icon to add");

    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    IViewerValueProperty selProp = ViewerProperties.singleSelection();
    IWidgetValueProperty tProp = WidgetProperties.text(SWT.Modify);

    {// w ww .j a v  a2  s .c  o m
        Label l = new Label(container, SWT.NONE);
        l.setText("Kind:");

        ComboViewer v = new ComboViewer(container, SWT.READ_ONLY);
        v.setLabelProvider(new LabelProvider());
        v.setContentProvider(ArrayContentProvider.getInstance());
        v.setInput(IconType.VALUES);
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, ICON__KIND);
        dbContext.bindValue(selProp.observe(v), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    {
        Label l = new Label(container, SWT.NONE);
        l.setText("URL*:");

        tUrl = new Text(container, SWT.BORDER);
        tUrl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, ICON__HREF);
        dbContext.bindValue(tProp.observeDelayed(DELAY, tUrl), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    {
        Label l = new Label(container, SWT.NONE);
        l.setText("Depth:");

        ComboViewer v = new ComboViewer(container, SWT.READ_ONLY);
        v.setLabelProvider(new LabelProvider());
        v.setContentProvider(ArrayContentProvider.getInstance());
        // TODO not hard coded here
        v.setInput(new String[] { "8", "24", "32" });
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, ICON__DEPTH);
        dbContext.bindValue(selProp.observe(v), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    {
        Label l = new Label(container, SWT.NONE);
        l.setText("Width:");

        tWidth = new Text(container, SWT.BORDER);
        tWidth.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, ICON__WIDTH);
        dbContext.bindValue(tProp.observeDelayed(DELAY, tWidth), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    {
        Label l = new Label(container, SWT.NONE);
        l.setText("Height:");

        tHeight = new Text(container, SWT.BORDER);
        tHeight.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, ICON__HEIGHT);
        dbContext.bindValue(tProp.observeDelayed(DELAY, tHeight), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    return area;
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.editors.AddSplashDialog.java

License:Open Source License

@Override
protected Control createDialogContent(final Composite parent) {
    o = ParametersFactory.eINSTANCE.createSplash();
    Composite area = new Composite(parent, SWT.NONE);
    area.setLayout(new GridLayout(1, false));
    area.setLayoutData(new GridData(GridData.FILL_BOTH));

    getShell().setText("Add splash icon");
    setTitle("Add splash");
    setMessage("Enter informations about the splash to add");

    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    IViewerValueProperty selProp = ViewerProperties.singleSelection();
    IWidgetValueProperty tProp = WidgetProperties.text(SWT.Modify);

    {//from  w ww. j  a  va2 s . c  om
        Label l = new Label(container, SWT.NONE);
        l.setText("Mode*:");

        ComboViewer v = new ComboViewer(container, SWT.READ_ONLY);
        v.setLabelProvider(new LabelProvider());
        v.setContentProvider(ArrayContentProvider.getInstance());
        v.setInput(SplashMode.values());
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, SPLASH__MODE);
        dbContext.bindValue(selProp.observe(v), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }

    {
        Label l = new Label(container, SWT.NONE);
        l.setText("URL*:");

        tUrl = new Text(container, SWT.BORDER);
        tUrl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        IEMFValueProperty prop = EMFEditProperties.value(editingDomain, SPLASH__HREF);
        dbContext.bindValue(tProp.observeDelayed(DELAY, tUrl), prop.observe(o),
                new EMFUpdateValueStrategy(EMFUpdateValueStrategy.POLICY_ON_REQUEST),
                new EMFUpdateValueStrategy());
    }
    return area;
}

From source file:com.rcpcompany.uibindings.internal.ViewerBindingImpl.java

License:Open Source License

/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * /* w w  w .ja v  a 2s  .c  o m*/
 * @generated NOT
 */
@Override
public IObservableValue getSingleSelection() {
    // TODO SWTB
    if (super.getSingleSelection() == null) {
        final IViewerValueProperty property = new MySelectionProviderSingleSelectionProperty() {
            @Override
            public Object getValueType() {
                return getList().getElementType();
            }
        };
        singleSelection = property.observe(viewer);
    }
    return super.getSingleSelection();
}

From source file:com.xse.optstack.persconftool.ui.configuration.ConfigurationPart.java

License:Open Source License

@Inject
public void setInput(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) final EResource resource,
        final MPart part) {
    if ((resource != null) && (this.activeResource != resource)) {
        this.activeResource = resource;

        final EConfiguration configuration = resource.getConfiguration();
        this.clearBindings();

        configuration.eAdapters().add(new AdapterImpl() {
            @Override/*from   ww  w .  ja  v a 2s  .co m*/
            public void notifyChanged(final Notification msg) {
                part.setDirty(true);
            }
        });

        final IViewerValueProperty singleSelection = ViewerProperties.singleSelection();
        this.bindingContext.bindValue(singleSelection.observe(this.policyWidget.getViewer()),
                EMFProperties.value(PersconfPackage.Literals.ECONFIGURATION__POLICY).observe(configuration));
        this.bindingContext.bindValue(singleSelection.observe(this.permissionWidget.getViewer()), EMFProperties
                .value(PersconfPackage.Literals.ECONFIGURATION__PERMISSION).observe(configuration));
        this.bindingContext.bindValue(singleSelection.observe(this.storageWidget.getViewer()),
                EMFProperties.value(PersconfPackage.Literals.ECONFIGURATION__STORAGE).observe(configuration));

        this.bindingContext.bindValue(
                WidgetProperties.text(SWT.Modify).observe(this.maxSizeText.getTextControl()),
                EMFProperties.value(PersconfPackage.Literals.ECONFIGURATION__MAX_SIZE).observe(configuration));
        this.bindingContext.bindValue(
                WidgetProperties.text(SWT.Modify).observe(this.responsibleText.getTextControl()), EMFProperties
                        .value(PersconfPackage.Literals.ECONFIGURATION__RESPONSIBLE).observe(configuration));
        this.bindingContext.bindValue(
                WidgetProperties.text(SWT.Modify).observe(this.customNameText.getTextControl()), EMFProperties
                        .value(PersconfPackage.Literals.ECONFIGURATION__CUSTOM_NAME).observe(configuration));
        this.bindingContext.bindValue(singleSelection.observe(this.typeWidget.getViewer()),
                EMFProperties.value(PersconfPackage.Literals.ECONFIGURATION__TYPE).observe(configuration));
        this.bindingContext.bindValue(
                WidgetProperties.text(SWT.Modify).observe(this.customIdText.getTextControl()),
                EMFProperties.value(PersconfPackage.Literals.ECONFIGURATION__CUSTOM_ID).observe(configuration));

        this.setEnabledState(true);

        this.customIdText.isValid();
        this.customNameText.isValid();
        this.maxSizeText.isValid();
        this.responsibleText.isValid();
    } else {
        this.clearBindings();
        this.setEnabledState(false);
        this.clearValues();
    }
}

From source file:de.metadocks.lambdaui.swt.ViewerUI.java

License:Open Source License

private void bind(IViewerValueProperty prop, String expr) {
    Object dataContext = findTagged(DATA_CONTEXT, null);
    Binder dbc = findTagged(Binder.class);
    IViewerObservableValue observeValue = prop.observe(viewer);
    org.eclipse.core.databinding.Binding binding = dbc.bind(observeValue, dataContext, expr);

    if (binding == null) {
        // no observables have been parsed, just use the value
        prop.setValue(viewer, expr);/*w ww  . j  a  v a 2 s .c  o  m*/
    }
}

From source file:org.eclipse.e4.tools.emf.ui.internal.common.component.AreaEditor.java

License:Open Source License

private Composite createForm(Composite parent, final EMFDataBindingContext context, WritableValue master,
        boolean isImport) {
    CTabFolder folder = new CTabFolder(parent, SWT.BOTTOM);

    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.ModelTooling_Common_TabDefault);

    parent = createScrollableContainer(folder);
    item.setControl(parent.getParent());

    if (getEditor().isShowXMIId() || getEditor().isLiveModel()) {
        ControlFactory.createXMIId(parent, this);
    }//from ww w.  jav a 2 s . co  m

    IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);

    if (isImport) {
        ControlFactory.createFindImport(parent, Messages, this, context);
        folder.setSelection(0);
        return folder;
    }

    ControlFactory.createTextField(parent, Messages.ModelTooling_Common_Id, getMaster(), context, textProp,
            EMFEditProperties.value(getEditingDomain(),
                    ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID));
    ControlFactory.createTextField(parent, Messages.AreaEditor_LabelLabel, master, context, textProp,
            EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_LABEL__LABEL));
    ControlFactory.createTextField(parent, Messages.AreaEditor_Tooltip, master, context, textProp,
            EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_LABEL__TOOLTIP));

    // ------------------------------------------------------------
    {
        Label l = new Label(parent, SWT.NONE);
        l.setText(Messages.AreaEditor_IconURI);
        l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

        final Text t = new Text(parent, SWT.BORDER);
        TextPasteHandler.createFor(t);
        t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        context.bindValue(textProp.observeDelayed(200, t), EMFEditProperties
                .value(getEditingDomain(), UiPackageImpl.Literals.UI_LABEL__ICON_URI).observeDetail(master));

        new ImageTooltip(t, Messages) {

            @Override
            protected URI getImageURI() {
                MUILabel part = (MUILabel) getMaster().getValue();
                String uri = part.getIconURI();
                if (uri == null || uri.trim().length() == 0) {
                    return null;
                }
                return URI.createURI(part.getIconURI());
            }
        };

        final Button b = new Button(parent, SWT.PUSH | SWT.FLAT);
        b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
        b.setImage(createImage(ResourceProvider.IMG_Obj16_zoom));
        b.setText(Messages.ModelTooling_Common_FindEllipsis);
        b.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                AreaIconDialogEditor dialog = new AreaIconDialogEditor(b.getShell(), eclipseContext, project,
                        getEditingDomain(), (MApplicationElement) getMaster().getValue(), Messages);
                dialog.open();
            }
        });
    }

    // ------------------------------------------------------------
    {
        Label l = new Label(parent, SWT.NONE);
        l.setText(Messages.AreaEditor_Orientation);
        l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

        ComboViewer viewer = new ComboViewer(parent);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        viewer.getControl().setLayoutData(gd);
        viewer.setContentProvider(new ArrayContentProvider());
        viewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                return ((Boolean) element).booleanValue() ? Messages.AreaEditor_Horizontal
                        : Messages.AreaEditor_Vertical;
            }
        });
        viewer.setInput(new Boolean[] { Boolean.TRUE, Boolean.FALSE });
        IViewerValueProperty vProp = ViewerProperties.singleSelection();
        context.bindValue(vProp.observe(viewer),
                EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.GENERIC_TILE__HORIZONTAL)
                        .observeDetail(getMaster()));
    }

    ControlFactory.createSelectedElement(parent, this, context, Messages.AreaEditor_SelectedElement);
    ControlFactory.createTextField(parent, Messages.AreaEditor_ContainerData, getMaster(), context, textProp,
            EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__CONTAINER_DATA));

    {
        Label l = new Label(parent, SWT.NONE);
        l.setText(Messages.AreaEditor_Controls);
        l.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));

        final TableViewer viewer = new TableViewer(parent);
        GridData gd = new GridData(GridData.FILL_BOTH);
        viewer.getControl().setLayoutData(gd);
        ObservableListContentProvider cp = new ObservableListContentProvider();
        viewer.setContentProvider(cp);
        viewer.setLabelProvider(new ComponentLabelProvider(getEditor(), Messages));

        IEMFListProperty prop = EMFProperties.list(UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
        viewer.setInput(prop.observeDetail(getMaster()));

        Composite buttonComp = new Composite(parent, SWT.NONE);
        buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
        GridLayout gl = new GridLayout(2, false);
        gl.marginLeft = 0;
        gl.marginRight = 0;
        gl.marginWidth = 0;
        gl.marginHeight = 0;
        buttonComp.setLayout(gl);

        Button b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
        b.setText(Messages.ModelTooling_Common_Up);
        b.setImage(createImage(ResourceProvider.IMG_Obj16_arrow_up));
        b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
        b.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!viewer.getSelection().isEmpty()) {
                    IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
                    if (s.size() == 1) {
                        Object obj = s.getFirstElement();
                        MElementContainer<?> container = (MElementContainer<?>) getMaster().getValue();
                        int idx = container.getChildren().indexOf(obj) - 1;
                        if (idx >= 0) {
                            if (Util.moveElementByIndex(getEditingDomain(), (MUIElement) obj,
                                    getEditor().isLiveModel(), idx)) {
                                viewer.setSelection(new StructuredSelection(obj));
                            }
                        }

                    }
                }
            }
        });

        b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
        b.setText(Messages.ModelTooling_Common_Down);
        b.setImage(createImage(ResourceProvider.IMG_Obj16_arrow_down));
        b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
        b.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!viewer.getSelection().isEmpty()) {
                    IStructuredSelection s = (IStructuredSelection) viewer.getSelection();
                    if (s.size() == 1) {
                        Object obj = s.getFirstElement();
                        MElementContainer<?> container = (MElementContainer<?>) getMaster().getValue();
                        int idx = container.getChildren().indexOf(obj) + 1;
                        if (idx < container.getChildren().size()) {
                            if (Util.moveElementByIndex(getEditingDomain(), (MUIElement) obj,
                                    getEditor().isLiveModel(), idx)) {
                                viewer.setSelection(new StructuredSelection(obj));
                            }
                        }

                    }
                }
            }
        });

        final ComboViewer childrenDropDown = new ComboViewer(buttonComp);
        childrenDropDown.getControl().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
        childrenDropDown.setContentProvider(new ArrayContentProvider());
        childrenDropDown.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                EClass eclass = (EClass) element;
                return eclass.getName();
            }
        });
        childrenDropDown.setInput(new EClass[] { BasicPackageImpl.Literals.PART_SASH_CONTAINER,
                BasicPackageImpl.Literals.PART_STACK, BasicPackageImpl.Literals.PART,
                BasicPackageImpl.Literals.INPUT_PART, AdvancedPackageImpl.Literals.AREA,
                AdvancedPackageImpl.Literals.PLACEHOLDER });
        childrenDropDown.setSelection(new StructuredSelection(BasicPackageImpl.Literals.PART_SASH_CONTAINER));

        b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
        b.setImage(createImage(ResourceProvider.IMG_Obj16_table_add));
        b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
        b.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!childrenDropDown.getSelection().isEmpty()) {
                    EClass eClass = (EClass) ((IStructuredSelection) childrenDropDown.getSelection())
                            .getFirstElement();
                    handleAddChild(eClass);
                }
            }
        });

        b = new Button(buttonComp, SWT.PUSH | SWT.FLAT);
        b.setText(Messages.ModelTooling_Common_Remove);
        b.setImage(createImage(ResourceProvider.IMG_Obj16_table_delete));
        b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
        b.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!viewer.getSelection().isEmpty()) {
                    List<?> elements = ((IStructuredSelection) viewer.getSelection()).toList();

                    Command cmd = RemoveCommand.create(getEditingDomain(), getMaster().getValue(),
                            UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN, elements);
                    if (cmd.canExecute()) {
                        getEditingDomain().getCommandStack().execute(cmd);
                    }
                }
            }
        });
    }

    ControlFactory.createCheckBox(parent, Messages.ModelTooling_UIElement_ToBeRendered, getMaster(), context,
            WidgetProperties.selection(),
            EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__TO_BE_RENDERED));
    ControlFactory.createCheckBox(parent, Messages.ModelTooling_UIElement_Visible, getMaster(), context,
            WidgetProperties.selection(),
            EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_ELEMENT__VISIBLE));

    item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.ModelTooling_Common_TabSupplementary);

    parent = createScrollableContainer(folder);
    item.setControl(parent.getParent());

    ControlFactory.createTextField(parent, Messages.ModelTooling_UIElement_AccessibilityPhrase, getMaster(),
            context, textProp, EMFEditProperties.value(getEditingDomain(),
                    UiPackageImpl.Literals.UI_ELEMENT__ACCESSIBILITY_PHRASE));
    ControlFactory.createStringListWidget(parent, Messages, this, Messages.ModelTooling_ApplicationElement_Tags,
            ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__TAGS, VERTICAL_LIST_WIDGET_INDENT);
    ControlFactory.createMapProperties(parent, Messages, this,
            Messages.ModelTooling_Contribution_PersistedState,
            ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__PERSISTED_STATE, VERTICAL_LIST_WIDGET_INDENT);

    if (project == null) {
        createUITreeInspection(folder);
    }

    createContributedEditorTabs(folder, context, getMaster(), MArea.class);

    folder.setSelection(0);

    return folder;
}

From source file:org.eclipse.e4.tools.emf.ui.internal.common.component.ControlFactory.java

License:Open Source License

public static void createSelectedElement(Composite parent, final AbstractComponentEditor editor,
        final EMFDataBindingContext context, String label) {
    Label l = new Label(parent, SWT.NONE);
    l.setText(label);/*from w  w w  .  j  a  va 2 s  .c  o m*/
    l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));

    ComboViewer viewer = new ComboViewer(parent);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    viewer.getControl().setLayoutData(gd);
    IEMFEditListProperty listProp = EMFEditProperties.list(editor.getEditingDomain(),
            UiPackageImpl.Literals.ELEMENT_CONTAINER__CHILDREN);
    IEMFEditValueProperty labelProp = EMFEditProperties.value(editor.getEditingDomain(),
            UiPackageImpl.Literals.UI_LABEL__LABEL);
    IEMFEditValueProperty idProp = EMFEditProperties.value(editor.getEditingDomain(),
            ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID);

    IViewerValueProperty vProp = ViewerProperties.singleSelection();

    final Binding[] binding = new Binding[1];
    final IObservableValue uiObs = vProp.observe(viewer);
    final IObservableValue mObs = EMFEditProperties
            .value(editor.getEditingDomain(), UiPackageImpl.Literals.ELEMENT_CONTAINER__SELECTED_ELEMENT)
            .observeDetail(editor.getMaster());
    editor.getMaster().addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            if (binding[0] != null) {
                binding[0].dispose();
            }

        }
    });

    final IObservableList list = listProp.observeDetail(editor.getMaster());
    ObservableListContentProvider cp = new ObservableListContentProvider();
    viewer.setContentProvider(cp);
    IObservableMap[] attributeMaps = { labelProp.observeDetail(cp.getKnownElements()),
            idProp.observeDetail(cp.getKnownElements()) };
    viewer.setLabelProvider(new ObservableMapLabelProvider(attributeMaps) {
        @Override
        public String getText(Object element) {
            EObject o = (EObject) element;
            String rv = o.eClass().getName();

            if (element instanceof MUILabel) {
                MUILabel label = (MUILabel) element;
                if (!Util.isNullOrEmpty(label.getLabel())) {
                    return rv + " - " + label.getLabel().trim(); //$NON-NLS-1$
                }

            }

            if (element instanceof MApplicationElement) {
                MApplicationElement appEl = (MApplicationElement) element;
                if (!Util.isNullOrEmpty(appEl.getElementId())) {
                    return rv + " - " + appEl.getElementId(); //$NON-NLS-1$
                }
            }

            return rv + "[" + list.indexOf(element) + "]"; //$NON-NLS-1$//$NON-NLS-2$
        }
    });
    viewer.setInput(list);

    editor.getMaster().addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(ValueChangeEvent event) {
            binding[0] = context.bindValue(uiObs, mObs);
        }
    });
}