Example usage for org.eclipse.jface.databinding.swt SWTObservables getRealm

List of usage examples for org.eclipse.jface.databinding.swt SWTObservables getRealm

Introduction

In this page you can find the example usage for org.eclipse.jface.databinding.swt SWTObservables getRealm.

Prototype

@Deprecated
public static Realm getRealm(final Display display) 

Source Link

Document

Returns the realm representing the UI thread for the given display.

Usage

From source file:org.switchyard.tools.ui.editor.components.soap.SOAPProxyComposite.java

License:Open Source License

private void bindControls(final DataBindingContext context) {
    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(getTargetObject());
    final Realm realm = SWTObservables.getRealm(_proxyHostText.getDisplay());

    _bindingValue = new WritableValue(realm, null, SOAPBindingType.class);
    final IObservableValue proxyTypeValue = new WritableValue(realm, null, String.class);
    final IObservableValue hostValue = new WritableValue(realm, null, String.class);
    final IObservableValue passwordValue = new WritableValue(realm, null, String.class);
    final IObservableValue portValue = new WritableValue(realm, null, String.class);
    final IObservableValue userValue = new WritableValue(realm, null, String.class);

    org.eclipse.core.databinding.Binding binding = context.bindValue(
            SWTObservables.observeText(_proxyHostText, SWT.Modify), hostValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(ViewersObservables.observeSingleSelection(_proxyTypeCombo), proxyTypeValue);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeText(_proxyPasswordText, SWT.Modify), passwordValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeText(_proxyPortText, SWT.Modify), portValue,
            new EMFUpdateValueStrategyNullForEmptyString("", UpdateValueStrategy.POLICY_CONVERT)
                    .setAfterConvertValidator(new EscapedPropertyIntegerValidator(
                            "Port must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').")),
            null);//w ww . ja  v a 2s  .  c  om
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeText(_proxyUserText, SWT.Modify), userValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    ComputedValue computedProxy = new ComputedValue() {
        @Override
        protected Object calculate() {
            final String proxyType = (String) proxyTypeValue.getValue();
            final String host = (String) hostValue.getValue();
            final String pwd = (String) passwordValue.getValue();
            final String port = (String) portValue.getValue();
            final String user = (String) userValue.getValue();
            if (host != null || pwd != null || port != null || user != null) {
                final ProxyType proxy = SOAPFactory.eINSTANCE.createProxyType();
                proxy.setHost(host);
                proxy.setPassword(pwd);
                proxy.setPort(port);
                proxy.setUser(user);
                proxy.setType(proxyType);
                return proxy;
            }
            return null;
        }

        protected void doSetValue(Object value) {
            if (value instanceof ProxyType) {
                final ProxyType proxy = (ProxyType) value;
                hostValue.setValue(proxy.getHost());
                passwordValue.setValue(proxy.getPassword());
                portValue.setValue(proxy.getPort());
                userValue.setValue(proxy.getUser());
                proxyTypeValue.setValue(proxy.getType());
            } else {
                hostValue.setValue(null);
                passwordValue.setValue(null);
                portValue.setValue(null);
                userValue.setValue(null);
                proxyTypeValue.setValue("HTTP");
            }
            getValue();
        }
    };

    // now bind the proxy into the binding
    binding = context.bindValue(computedProxy, ObservablesUtil.observeDetailValue(domain, _bindingValue,
            SOAPPackage.Literals.SOAP_BINDING_TYPE__PROXY));

}

From source file:org.switchyard.tools.ui.editor.diagram.binding.CamelAdditionalURIPropertyTable.java

License:Open Source License

CamelAdditionalURIPropertyTable(Composite parent, int style, boolean isReadOnly,
        EReference additionalUriParametersFeature, EReference parameterFeature, EClass parameterType,
        DataBindingContext context) {// w w w . ja  v a2 s.  co m
    super(parent, style);
    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(getTargetObject());
    this._isReadOnly = isReadOnly;
    this._changeListeners = new ListenerList();
    _additionalUriParametersFeature = additionalUriParametersFeature;
    _parameterFeature = parameterFeature;
    _parameterType = parameterType;

    int additionalStyles = SWT.NONE;
    if (isReadOnly) {
        additionalStyles = SWT.READ_ONLY;
    }

    final GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.numColumns = 2;
    setLayout(gridLayout);

    Composite tableComposite = new Composite(this, additionalStyles);
    GridData gd11 = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2);
    gd11.heightHint = 100;
    tableComposite.setLayoutData(gd11);

    _propertyTreeTable = new TableViewer(tableComposite,
            SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.FULL_SELECTION | additionalStyles);
    _propertyTreeTable.getTable().setHeaderVisible(true);

    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComposite.setLayout(tableLayout);

    TableViewerColumn nameColumn = new TableViewerColumn(_propertyTreeTable, SWT.LEFT);
    nameColumn.getColumn().setText(Messages.label_name);
    tableLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100, 150, true));

    TableViewerColumn valueColumn = new TableViewerColumn(_propertyTreeTable, SWT.LEFT);
    valueColumn.getColumn().setText(Messages.label_value);
    tableLayout.setColumnData(valueColumn.getColumn(), new ColumnWeightData(100, 150, true));

    // TODO: need to use EMFEditProperties if we're in an editing context
    IValueProperty nameProperty = domain == null
            ? EMFProperties.value(_parameterType.getEStructuralFeature("name"))
            : EMFEditProperties.value(domain, _parameterType.getEStructuralFeature("name"));
    IValueProperty valueProperty = domain == null
            ? EMFProperties.value(_parameterType.getEStructuralFeature("value"))
            : EMFEditProperties.value(domain, _parameterType.getEStructuralFeature("value"));
    IValueProperty cellEditorTextProperty = CellEditorProperties.control()
            .value(WidgetProperties.text(SWT.Modify));

    final ObservableListContentProvider contentProvider;
    ObservableTracker.setIgnore(true);
    try {
        // ignore any observers created internally
        contentProvider = new ObservableListContentProvider();
    } finally {
        ObservableTracker.setIgnore(false);
    }

    nameColumn.setEditingSupport(ObservableValueEditingSupport.create(_propertyTreeTable, context,
            new TextCellEditor(_propertyTreeTable.getTable()), cellEditorTextProperty, nameProperty));
    nameColumn.setLabelProvider(
            new ObservableMapCellLabelProvider(nameProperty.observeDetail(contentProvider.getKnownElements())));

    valueColumn.setEditingSupport(ObservableValueEditingSupport.create(_propertyTreeTable, context,
            new TextCellEditor(_propertyTreeTable.getTable()), cellEditorTextProperty, valueProperty));
    valueColumn.setLabelProvider(new ObservableMapCellLabelProvider(
            valueProperty.observeDetail(contentProvider.getKnownElements())));

    _propertyTreeTable.setContentProvider(contentProvider);

    _mAddButton = new Button(this, SWT.NONE);
    _mAddButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    _mAddButton.setText(Messages.button_add);
    _mAddButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            addPropertyToList();
            fireChangedEvent(e.getSource());
        }
    });

    _mAddButton.setEnabled(false);

    _propertyTreeTable.getTable().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            updatePropertyButtons();
        }
    });

    _mRemoveButton = new Button(this, SWT.NONE);
    _mRemoveButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    _mRemoveButton.setText(Messages.button_remove);
    _mRemoveButton.setEnabled(false);
    _mRemoveButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeFromList();
            fireChangedEvent(e.getSource());
        }
    });

    // set the input. we're observing a list on the binding value
    _bindingValue = new WritableValue(SWTObservables.getRealm(getDisplay()), null, Binding.class);
    _propertyTreeTable.setInput(
            EMFProperties.list(FeaturePath.fromList(_additionalUriParametersFeature, _parameterFeature))
                    .observeDetail(_bindingValue));

    updatePropertyButtons();
}

From source file:org.switchyard.tools.ui.editor.diagram.binding.MessageComposerComposite.java

License:Open Source License

private void bindControls(DataBindingContext context) {
    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(getTargetObject());
    final Realm realm = SWTObservables.getRealm(_panel.getDisplay());

    _bindingValue = new WritableValue(realm, null, Binding.class);

    // bind the controls
    final FeaturePath messageComposerClassFeature = FeaturePath.fromList(_messageComposerFeature,
            SwitchyardPackage.Literals.MESSAGE_COMPOSER_TYPE__CLASS);
    final IObservableValue composerClassValue = EMFProperties.value(messageComposerClassFeature)
            .observeDetail(_bindingValue);
    org.eclipse.core.databinding.Binding binding = context.bindValue(
            SWTObservables.observeText(_composerClassText, new int[] { SWT.Modify }), composerClassValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT, domain,
                    _bindingValue, messageComposerClassFeature, true).setAfterConvertValidator(
                            new AccessibleClassValidator(BeanProperties.value("targetObject").observe(this))),
            null);/*  ww w .ja  v a2s. c  o m*/
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    final FeaturePath contextMapperClassFeature = FeaturePath.fromList(_contextMapperFeature,
            SwitchyardPackage.Literals.CONTEXT_MAPPER_TYPE__CLASS);
    final IObservableValue mapperClassTextValue = SWTObservables.observeText(_mapperClassText,
            new int[] { SWT.Modify });
    final IObservableValue mapperClassValue = EMFProperties.value(contextMapperClassFeature)
            .observeDetail(_bindingValue);
    final org.eclipse.core.databinding.Binding mapperClassBinding = context.bindValue(mapperClassTextValue,
            mapperClassValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT, domain,
                    _bindingValue, contextMapperClassFeature, true).setAfterConvertValidator(
                            new AccessibleClassValidator(BeanProperties.value("targetObject").observe(this))),
            null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(mapperClassBinding), SWT.TOP | SWT.LEFT);

    final FeaturePath contextMapperIncludesFeature = FeaturePath.fromList(_contextMapperFeature,
            SwitchyardPackage.Literals.CONTEXT_MAPPER_TYPE__INCLUDES);
    final IObservableValue includesTextValue = SWTObservables.observeText(_includesText,
            new int[] { SWT.Modify });
    final IObservableValue includesValue = EMFProperties.value(contextMapperIncludesFeature)
            .observeDetail(_bindingValue);
    binding = context.bindValue(includesTextValue, includesValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT, domain,
                    _bindingValue, contextMapperIncludesFeature, true)
                            .setAfterConvertValidator(new RegexListValidator()),
            null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    final FeaturePath contextMapperExcludesFeature = FeaturePath.fromList(_contextMapperFeature,
            SwitchyardPackage.Literals.CONTEXT_MAPPER_TYPE__EXCLUDES);
    final IObservableValue excludesTextValue = SWTObservables.observeText(_excludesText,
            new int[] { SWT.Modify });
    final IObservableValue excludesValue = EMFProperties.value(contextMapperExcludesFeature)
            .observeDetail(_bindingValue);
    binding = context.bindValue(excludesTextValue, excludesValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT, domain,
                    _bindingValue, contextMapperExcludesFeature, true)
                            .setAfterConvertValidator(new RegexListValidator()),
            null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    final FeaturePath contextMapperIncludesNSFeature = FeaturePath.fromList(_contextMapperFeature,
            SwitchyardPackage.Literals.CONTEXT_MAPPER_TYPE__INCLUDE_NAMESPACES);
    final IObservableValue includesNSTextValue = SWTObservables.observeText(_includesNSText,
            new int[] { SWT.Modify });
    final IObservableValue includesNSValue = EMFProperties.value(contextMapperIncludesNSFeature)
            .observeDetail(_bindingValue);
    binding = context.bindValue(includesNSTextValue, includesNSValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT, domain,
                    _bindingValue, contextMapperIncludesNSFeature, true)
                            .setAfterConvertValidator(new RegexListValidator()),
            null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    final FeaturePath contextMapperExcludesNSFeature = FeaturePath.fromList(_contextMapperFeature,
            SwitchyardPackage.Literals.CONTEXT_MAPPER_TYPE__EXCLUDE_NAMESPACES);
    final IObservableValue excludesNSTextValue = SWTObservables.observeText(_excludesNSText,
            new int[] { SWT.Modify });
    final IObservableValue excludesNSValue = EMFProperties.value(contextMapperExcludesNSFeature)
            .observeDetail(_bindingValue);
    binding = context.bindValue(excludesNSTextValue, excludesNSValue,
            new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT, domain,
                    _bindingValue, contextMapperExcludesNSFeature, true)
                            .setAfterConvertValidator(new RegexListValidator()),
            null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    /*
     * add a warning if there are regex patterns set, but the specified
     * context mapper class doesn't support them
     */
    context.addValidationStatusProvider(new MultiValidator() {
        @Override
        protected IStatus validate() {
            final IStatus mapperClassStatus;
            ObservableTracker.setIgnore(true);
            try {
                // we don't want to track status updates
                mapperClassStatus = (IStatus) mapperClassBinding.getValidationStatus().getValue();
            } finally {
                ObservableTracker.setIgnore(false);
            }
            /*
             * read from everything we require (ensures we get called when
             * any of these get updated)
             */
            final String mapperClass = (String) mapperClassTextValue.getValue();
            final String includes = (String) includesTextValue.getValue();
            final String excludes = (String) excludesTextValue.getValue();
            final String includesNS = (String) includesNSTextValue.getValue();
            final String excludesNS = (String) excludesNSTextValue.getValue();

            // do the actual validation
            if ((mapperClassStatus != null && !mapperClassStatus.isOK()) || cmClassSupportsRegEx(mapperClass)) {
                return Status.OK_STATUS;
            }
            if (isNullOrEmpty(mapperClass) || (isNullOrEmpty(includes) && isNullOrEmpty(excludes)
                    && isNullOrEmpty(includesNS) && isNullOrEmpty(excludesNS))) {
                return Status.OK_STATUS;
            }
            return new Status(Status.WARNING, Activator.PLUGIN_ID,
                    "Selected context mapper class does not support regular expressions.");
        }
    });
}

From source file:org.switchyard.tools.ui.editor.diagram.binding.OperationSelectorComposite.java

License:Open Source License

/**
 * Bind the controls.//  ww w.ja v a  2s.co m
 * 
 * @param domain the editing domain, may be null
 * @param context the data binding context
 */
public void bindControls(EditingDomain domain, DataBindingContext context) {
    final Realm realm = SWTObservables.getRealm(getDisplay());

    _bindingValue = new WritableValue(realm, null, Binding.class);

    /*
     * intermediate values, used to separate control changes from value
     * changes (i.e. the bindings for these are wrapped with
     * SWTValueUpdater).
     */
    final IObservableValue selectorTypeValue = new WritableValue(realm, null, SelectorType.class);
    final IObservableValue staticValue = new WritableValue(realm, null, String.class);
    final IObservableValue regexValue = new WritableValue(realm, null, String.class);
    final IObservableValue xpathValue = new WritableValue(realm, null, String.class);
    final IObservableValue javaValue = new WritableValue(realm, null, String.class);

    // bind intermediate values to controls
    org.eclipse.core.databinding.Binding binding = context.bindValue(
            ViewersObservables.observeSingleSelection(_typeCombo), selectorTypeValue, new UpdateValueStrategy(),
            null);
    ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeSelection(_operationSelectionCombo), staticValue,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeText(_regexText, SWT.Modify), regexValue,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT)
                    .setAfterConvertValidator(new RegexValidator()),
            null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeText(_xpathText, SWT.Modify), xpathValue,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    binding = context.bindValue(SWTObservables.observeText(_javaText, SWT.Modify), javaValue,
            new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);
    ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT);

    /*
     * computed value. creates an operation selector based on the current
     * state of the controls.
     */
    _selectorValue = new ComputedValue(realm, OperationSelectorType.class) {
        @Override
        protected Object calculate() {
            // we need to interrogate all values, or we'll miss events
            final SelectorType selectedType = (SelectorType) selectorTypeValue.getValue();
            final String operationText = (String) staticValue.getValue();
            final String xpathText = (String) xpathValue.getValue();
            final String regexText = (String) regexValue.getValue();
            final String javaText = (String) javaValue.getValue();
            if (selectedType == null) {
                return null;
            }
            switch (selectedType) {
            case STATIC_TYPE:
                return selectedType.createOperationSelector(operationText);
            case XPATH_TYPE:
                return selectedType.createOperationSelector(xpathText);
            case REGEX_TYPE:
                return selectedType.createOperationSelector(regexText);
            case JAVA_TYPE:
                return selectedType.createOperationSelector(javaText);
            }
            return null;
        }

        @Override
        protected void doSetValue(Object value) {
            if (value == null) {
                selectorTypeValue.setValue(SelectorType.STATIC_TYPE);
                staticValue.setValue("");
            } else if (value instanceof OperationSelectorType) {
                final SelectorType selectorType = SelectorType.valueOf((OperationSelectorType) value);
                selectorTypeValue.setValue(selectorType);
                switch (selectorType) {
                case STATIC_TYPE:
                    staticValue.setValue(((StaticOperationSelectorType) value).getOperationName());
                    break;
                case XPATH_TYPE:
                    xpathValue.setValue(((XPathOperationSelectorType) value).getExpression());
                    break;
                case REGEX_TYPE:
                    regexValue.setValue(((RegexOperationSelectorType) value).getExpression());
                    break;
                case JAVA_TYPE:
                    javaValue.setValue(((JavaOperationSelectorType) value).getClass_());
                    break;
                }
            } else {
                throw new IllegalArgumentException(
                        "Unknown selector type: " + value.getClass().getCanonicalName());
            }
            // update our cached value
            getValue();
        }
    };

    // now bind the selector into the binding
    context.bindValue(_selectorValue, ObservablesUtil.observeDetailValue(domain, _bindingValue,
            ScaPackage.eINSTANCE.getBinding_OperationSelector()));

    // propagate changes to the old binding composites
    _selectorValue.addValueChangeListener(new IValueChangeListener() {
        @Override
        public void handleValueChange(ValueChangeEvent event) {
            fireChangedEvent(OperationSelectorComposite.this);
        }
    });
}

From source file:synergyviewcore.collections.ui.MediaPreviewControl.java

License:Open Source License

/**
 * Instantiates a new media preview control.
 * /*w  w w .  ja v  a2  s . c o m*/
 * @param parent
 *            the parent
 * @param style
 *            the style
 */
public MediaPreviewControl(Composite parent, int style) {
    super(parent, style);
    this.setLayout(new FillLayout(SWT.HORIZONTAL));
    this.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            disposeResourse();
        }

    });
    _observableMediaPreviewList = new WritableMap(SWTObservables.getRealm(parent.getDisplay()), String.class,
            AbstractMedia.class);
    _mapChangedListener = new IMapChangeListener() {

        public void handleMapChange(MapChangeEvent arg0) {
            for (Object key : arg0.diff.getAddedKeys()) {
                MediaSwtAwtComposite mediaComposite = new MediaSwtAwtComposite(MediaPreviewControl.this,
                        SWT.None);
                mediaComposite.addMedia((AbstractMedia) _observableMediaPreviewList.get(key));
                mediaSwtAwtCompositeList.put((AbstractMedia) _observableMediaPreviewList.get(key),
                        mediaComposite);
            }
            for (Object key : arg0.diff.getRemovedKeys()) {
                AbstractMedia media = (AbstractMedia) arg0.diff.getOldValue(key);
                mediaSwtAwtCompositeList.get(media).dispose();
                mediaSwtAwtCompositeList.remove(media);
            }
            MediaPreviewControl.this.layout(true);

        }

    };

    _observableMediaPreviewList.addMapChangeListener(_mapChangedListener);
}

From source file:synergyviewcore.media.ui.MediaPreviewControl.java

License:Open Source License

/**
 * Instantiates a new media preview control.
 * /*from   w  w  w  . j  a va 2s .c  o m*/
 * @param parent
 *            the parent
 * @param style
 *            the style
 */
public MediaPreviewControl(Composite parent, int style) {
    super(parent, style);
    this.setLayout(new FillLayout(SWT.HORIZONTAL));
    this.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            disposeResourse();
        }

    });
    _observableMediaPreviewList = new WritableMap(SWTObservables.getRealm(parent.getDisplay()), String.class,
            AbstractMedia.class);
    _mapChangedListener = new IMapChangeListener() {

        public void handleMapChange(MapChangeEvent arg0) {
            for (Object key : arg0.diff.getAddedKeys()) {
                MediaSwtAwtComposite mediaComposite = new MediaSwtAwtComposite(MediaPreviewControl.this,
                        SWT.None);
                mediaComposite.addMedia((AbstractMedia) _observableMediaPreviewList.get(key));
                mediaSwtAwtCompositeList.put((AbstractMedia) _observableMediaPreviewList.get(key),
                        mediaComposite);
            }
            for (Object key : arg0.diff.getRemovedKeys()) {
                AbstractMedia media = (AbstractMedia) arg0.diff.getOldValue(key);
                if (media != null) {
                    mediaSwtAwtCompositeList.get(media).dispose();
                    mediaSwtAwtCompositeList.remove(media);
                }
            }
            MediaPreviewControl.this.layout(true);

        }

    };

    _observableMediaPreviewList.addMapChangeListener(_mapChangedListener);
}

From source file:synergyviewmvc.media.ui.MediaPreviewControl.java

License:Open Source License

/**
 * @param parent/*from  w  w w.j  a v a 2s .co m*/
 * @param style
 */
public MediaPreviewControl(Composite parent, int style) {
    super(parent, style);
    this.setLayout(new FillLayout(SWT.HORIZONTAL));
    this.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            disposeResourse();
        }

    });
    observableMediaPreviewMap = new WritableMap(SWTObservables.getRealm(parent.getDisplay()), String.class,
            AbstractMedia.class);
    mapChangedListener = new IMapChangeListener() {

        public void handleMapChange(MapChangeEvent arg0) {
            for (Object key : arg0.diff.getAddedKeys()) {
                MediaSwtAwtComposite mediaComposite = new MediaSwtAwtComposite(MediaPreviewControl.this,
                        SWT.None);
                mediaComposite.addMedia((AbstractMedia) observableMediaPreviewMap.get(key));
                mediaSwtAwtCompositeList.put((AbstractMedia) observableMediaPreviewMap.get(key),
                        mediaComposite);
            }
            for (Object key : arg0.diff.getRemovedKeys()) {
                AbstractMedia media = (AbstractMedia) arg0.diff.getOldValue(key);
                mediaSwtAwtCompositeList.get(media).dispose();
                mediaSwtAwtCompositeList.remove(media);
            }
            MediaPreviewControl.this.layout(true);

        }

    };

    observableMediaPreviewMap.addMapChangeListener(mapChangedListener);
}

From source file:thinkinside.tangle.views.details.DetailsView.java

License:Open Source License

@Inject
public DetailsView(Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    composite.setLayout(new GridLayout(2, false));
    Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {

        @Override/*  ww  w  .j  a  v a  2  s .  c o m*/
        public void run() {
            dbc = new DataBindingContext();
            contactValue = new WritableValue();
            firstNameText = createText(composite, "First Name:", "firstName");
            lastNameText = createText(composite, "Last Name:", "lastName");
            emailText = createText(composite, "Email:", "email");
        }
    });
}