protected void bindSection() { if (context != null) { context.dispose(); } context = new EMFDataBindingContext(); if (getEObject() != null && dataTableViewer != null) { final IObservableList dataObservableList = EMFEditObservables.observeList(getEditingDomain(), getEObject(), getDataFeature()); dataTableViewer.setInput(dataObservableList); final UpdateValueStrategy enableStrategy = new UpdateValueStrategy(); enableStrategy.setConverter( new Converter(Data.class, Boolean.class) { @Override public Object convert(final Object fromObject) { return fromObject != null; } }); context.bindValue( SWTObservables.observeEnabled(updateDataButton), ViewersObservables.observeSingleSelection(dataTableViewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableStrategy); context.bindValue( SWTObservables.observeEnabled(removeDataButton), ViewersObservables.observeSingleSelection(dataTableViewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableStrategy); if (promoteDataButton != null) { final UpdateValueStrategy enableMoveStrategy = new UpdateValueStrategy(); enableMoveStrategy.setConverter( new Converter(Data.class, Boolean.class) { @Override public Object convert(final Object fromObject) { return fromObject != null && ModelHelper.getParentProcess(getEObject()) != null && !((Data) fromObject).isTransient(); } }); context.bindValue( SWTObservables.observeEnabled(promoteDataButton), ViewersObservables.observeSingleSelection(dataTableViewer), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), enableMoveStrategy); } } }
protected void bindInputExpressionViewer() { if (element.getInputType() == FileWidgetInputType.URL || element.getInputType() == FileWidgetInputType.DOCUMENT) { if (inputExpressionViewer != null && !inputExpressionViewer.getControl().isDisposed()) { Expression input = element.getInputExpression(); if (input == null) { input = ExpressionFactory.eINSTANCE.createExpression(); editingDomain .getCommandStack() .execute( SetCommand.create( editingDomain, element, FormPackage.Literals.WIDGET__INPUT_EXPRESSION, input)); } inputExpressionViewer.setEditingDomain(editingDomain); inputExpressionViewer.setInput(element); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(inputExpressionViewer), EMFEditObservables.observeValue( editingDomain, element, FormPackage.Literals.WIDGET__INPUT_EXPRESSION)); } } }
protected void init() { prefs = ConfigurationScope.INSTANCE.getNode("org.bbaw.bts.ui.corpus"); IEclipsePreferences defaultpref = DefaultScope.INSTANCE.getNode("org.bbaw.bts.ui.corpus"); default_visibility = prefs.get(BTSCorpusConstants.PREF_LEMMA_DEFAULT_VISIBILITY, null); default_reviewState = prefs.get(BTSCorpusConstants.PREF_LEMMA_DEFAULT_REVIEWSTATE, null); object = BtsCorpusModelFactory.eINSTANCE.createBTSTCObject(); object.setVisibility(default_visibility); object.setRevisionState(default_reviewState); DataBindingContext bindingContext = new DataBindingContext(); // visibility EMFUpdateValueStrategy targetToModel_vis = new EMFUpdateValueStrategy(); targetToModel_vis.setConverter(new BTSConfigItemToStringConverter()); EMFUpdateValueStrategy modelToTarget_vis = new EMFUpdateValueStrategy(); modelToTarget_vis.setConverter(new BTSStringToConfigItemConverter(visibility_viewer)); IObservableValue target_vis_viewer = ViewersObservables.observeSingleSelection(visibility_viewer); Binding binding_vis = bindingContext.bindValue( target_vis_viewer, EMFProperties.value(BtsmodelPackage.Literals.ADMINISTRATIV_DATA_OBJECT__VISIBILITY) .observe(object), targetToModel_vis, modelToTarget_vis); // review status EMFUpdateValueStrategy targetToModel_rev = new EMFUpdateValueStrategy(); targetToModel_rev.setConverter(new BTSConfigItemToStringConverter()); EMFUpdateValueStrategy modelToTarget_rev = new EMFUpdateValueStrategy(); modelToTarget_rev.setConverter(new BTSStringToConfigItemConverter(reviewState_viewer)); IObservableValue target_rev_viewer = ViewersObservables.observeSingleSelection(reviewState_viewer); Binding binding_rev = bindingContext.bindValue( target_rev_viewer, EMFProperties.value(BtsmodelPackage.Literals.ADMINISTRATIV_DATA_OBJECT__REVISION_STATE) .observe(object), targetToModel_rev, modelToTarget_rev); super.initialize(); }
protected void bindGUI(DataBindingContext bindingContext) { // Since we're using a JFace Viewer, we do first wrap our Table... TableViewer peopleViewer = new TableViewer(duckFamily); peopleViewer.addFilter( new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return element != UNKNOWN; } }); // Bind viewers to model ViewerSupport.bind( peopleViewer, viewModel.getPeople(), BeanProperties.values( new String[] {"name", "mother.name", "father.name", "mother.mother.name"})); // Bind viewer selection to detail fields IObservableValue selection = ViewersObservables.observeSingleSelection(peopleViewer); bindingContext.bindValue( WidgetProperties.text().observe(nameText), BeanProperties.value((Class) selection.getValueType(), "name", String.class) .observeDetail(selection)); ComboViewer mothercomboViewer = new ComboViewer(motherCombo); ViewerSupport.bind(mothercomboViewer, viewModel.getPeople(), BeanProperties.value("name")); bindingContext.bindValue( ViewersObservables.observeSingleSelection(mothercomboViewer), BeanProperties.value((Class) selection.getValueType(), "mother", Person.class) .observeDetail(selection)); ComboViewer fatherComboViewer = new ComboViewer(fatherCombo); ViewerSupport.bind(fatherComboViewer, viewModel.getPeople(), BeanProperties.value("name")); bindingContext.bindValue( ViewersObservables.observeSingleSelection(fatherComboViewer), BeanProperties.value((Class) selection.getValueType(), "father", Person.class) .observeDetail(selection)); }
protected void addBindings(final DataBindingSupport databinding) { if (fSameTargetControl != null) { fSameTargetValue = new WritableValue(databinding.getRealm(), Boolean.FALSE, Boolean.class); databinding .getContext() .bindValue( SWTObservables.observeSelection(fSameTargetControl), fSameTargetValue, null, null); } fTargetLibraryValue = new WritableValue(databinding.getRealm(), null, IRLibraryLocation.class); databinding .getContext() .bindValue( ViewersObservables.observeSingleSelection(fSelectTargetControl.getSelectionViewer()), fTargetLibraryValue, new UpdateValueStrategy().setAfterGetValidator(fSelectTargetControl.getValidator()), null); }
protected void bind(DataBindingContext bindingContext) { // Name bindingContext.bindValue( WidgetProperties.text(SWT.FocusOut).observe(propertyComposite.getTextName()), EMFEditProperties.value(getEditingDomain(), ScrPackage.eINSTANCE.getProperty_Name()) .observeDetail(getCurrentSelection())); // Type bindingContext.bindValue( ViewersObservables.observeSingleSelection(propertyComposite.getComboType()), EMFEditProperties.value(getEditingDomain(), ScrPackage.eINSTANCE.getProperty_Type()) .observeDetail(getCurrentSelection())); // Value bindingContext.bindValue( WidgetProperties.text(SWT.FocusOut).observe(propertyComposite.getTextValue()), EMFEditProperties.value(getEditingDomain(), ScrPackage.eINSTANCE.getProperty_Value()) .observeDetail(getCurrentSelection())); }
private void bindControls(final DataBindingContext context) { final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(getTargetObject()); final Realm realm = SWTObservables.getRealm(_nameText.getDisplay()); _bindingValue = new WritableValue(realm, null, CamelMailBindingType.class); org.eclipse.core.databinding.Binding binding = context.bindValue( SWTObservables.observeText(_nameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, ScaPackage.eINSTANCE.getBinding_Name()), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new StringEmptyValidator( "Mail binding name should not be empty", Status.WARNING)), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); /* * we also want to bind the name field to the binding name. note that * the model to target updater is configured to NEVER update. we want * the camel binding name to be the definitive source for this field. */ binding = context.bindValue( SWTObservables.observeText(_nameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, ScaPackage.eINSTANCE.getBinding_Name()), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new StringEmptyValidator( "Mail binding name should not be empty", Status.WARNING)), new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_hostText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__HOST), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator(new StringEmptyValidator(Messages.error_emptyHost)), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_portText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__PORT), new EMFUpdateValueStrategyNullForEmptyString( "Port must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').", UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new EscapedPropertyIntegerValidator( "Port must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').")), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); FeaturePath path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__FETCH_SIZE); binding = context.bindValue( SWTObservables.observeText(_fetchSizeText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString( "Fetch Size must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').", UpdateValueStrategy.POLICY_CONVERT) .setAfterConvertValidator( new EscapedPropertyIntegerValidator( "Fetch Size must be a valid numeric value or follow the pattern for escaped properties (i.e. '${propName}').")), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__ACCOUNT_TYPE); binding = context.bindValue( ViewersObservables.observeSingleSelection(_accountTypeCombo), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_usernameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__USERNAME), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeText(_passwordText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__PASSWORD), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__FOLDER_NAME); binding = context.bindValue( SWTObservables.observeText(_folderNameText, new int[] {SWT.Modify}), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString("", UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__UNSEEN); binding = context.bindValue( SWTObservables.observeSelection(_unseenCheckbox), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); binding = context.bindValue( SWTObservables.observeSelection(_securedCheckbox), ObservablesUtil.observeDetailValue( domain, _bindingValue, MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__SECURE), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); path = FeaturePath.fromList( MailPackage.Literals.CAMEL_MAIL_BINDING_TYPE__CONSUME, MailPackage.Literals.CAMEL_MAIL_CONSUMER_TYPE__DELETE); binding = context.bindValue( SWTObservables.observeSelection(_deleteCheckbox), ObservablesUtil.observeDetailValue(domain, _bindingValue, path), new EMFUpdateValueStrategyNullForEmptyString(null, UpdateValueStrategy.POLICY_CONVERT), null); ControlDecorationSupport.create(SWTValueUpdater.attach(binding), SWT.TOP | SWT.LEFT); _opSelectorComposite.bindControls(domain, context); }
@Override public void createPartControl(Composite parent) { detailsViewerFlyout = new FlyoutControlComposite(parent, SWT.NONE, detailsViewerFlyoutPreferences); detailsViewerFlyout.setTitleText("Details / Filters"); detailsViewerFlyout.setValidDockLocations(IFlyoutPreferences.DOCK_EAST); patternsViewerFlyout = new FlyoutControlComposite( detailsViewerFlyout.getClientParent(), SWT.NONE, patternsViewerFlyoutPreferences); patternsViewerFlyout.setTitleText("Pattern registry"); patternsViewerFlyout.setValidDockLocations(IFlyoutPreferences.DOCK_WEST); matcherTreeViewer = new TreeViewer(patternsViewerFlyout.getClientParent()); detailsTableViewer = new TableViewer(detailsViewerFlyout.getFlyoutParent(), SWT.FULL_SELECTION); // matcherTreeViewer configuration matcherTreeViewer.setContentProvider( new ObservableListTreeContentProvider( new QueryExplorerObservableFactory(), new QueryExplorerTreeStructureAdvisor())); matcherTreeViewer.setLabelProvider(new QueryExplorerLabelProvider()); matcherTreeViewer.setInput(treeViewerRootContent); treeViewerRootContent.setViewer(matcherTreeViewer); ColumnViewerToolTipSupport.enableFor(matcherTreeViewer); matcherTreeViewer.setComparator(null); IObservableValue selection = ViewersObservables.observeSingleSelection(matcherTreeViewer); selection.addValueChangeListener(new RootContentSelectionChangeListener()); DoubleClickListener listener = new DoubleClickListener(); injector.injectMembers(listener); matcherTreeViewer.addDoubleClickListener(listener); // patternsViewer configuration patternsTreeViewer = new CheckboxTreeViewer( patternsViewerFlyout.getFlyoutParent(), SWT.CHECK | SWT.BORDER | SWT.MULTI); patternsTreeViewer.addCheckStateListener(new CheckStateListener()); setPackagePresentation(mementoPackagePresentation, false); patternsTreeViewer.setInput(patternsViewerInput); // Create menu manager. MenuManager matcherTreeViewerMenuManager = new MenuManager(); matcherTreeViewerMenuManager.setRemoveAllWhenShown(true); matcherTreeViewerMenuManager.addMenuListener( new IMenuListener() { @Override public void menuAboutToShow(IMenuManager mgr) { fillContextMenu(mgr); } }); // Create menu for tree viewer Menu matcherTreeViewerMenu = matcherTreeViewerMenuManager.createContextMenu(matcherTreeViewer.getControl()); matcherTreeViewer.getControl().setMenu(matcherTreeViewerMenu); getSite() .registerContextMenu( "org.eclipse.incquery.tooling.ui.queryexplorer.QueryExplorer.treeViewerMenu", matcherTreeViewerMenuManager, matcherTreeViewer); MenuManager patternsViewerMenuManager = new MenuManager(); patternsViewerMenuManager.setRemoveAllWhenShown(true); patternsViewerMenuManager.addMenuListener( new IMenuListener() { @Override public void menuAboutToShow(IMenuManager mgr) { fillContextMenu(mgr); } }); // Create menu for patterns viewer Menu patternsViewerMenu = patternsViewerMenuManager.createContextMenu(patternsTreeViewer.getControl()); patternsTreeViewer.getControl().setMenu(patternsViewerMenu); getSite() .registerContextMenu( "org.eclipse.incquery.tooling.ui.queryexplorer.QueryExplorer.patternsViewerMenu", patternsViewerMenuManager, patternsTreeViewer); // tableView configuration Table table = detailsTableViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); GridData gridData = new GridData(); gridData.verticalAlignment = GridData.FILL; gridData.horizontalSpan = 2; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; detailsTableViewer.getControl().setLayoutData(gridData); // Focus listening and selection providing getSite().setSelectionProvider(matcherTreeViewer); // removed listener due to new attach feature in // https://bugs.eclipse.org/bugs/show_bug.cgi?id=429858 // initFileListener(); initPatternsViewerWithGeneratedPatterns(); }
protected void bindNestedPojoProperty( FormToolkit toolkit, final IMessageManager mmng, final IPropertyDescriptor complexProperty, Composite parent, Object value, PropertyDescriptor property, Class<?> complexType) { String labelText; String propertyName = property.getName(); Class<?> propertyType = property.getPropertyType(); labelText = capitalize(splitCamelCase(propertyName)); if (complexProperty instanceof ComplexUnionPropertyDescriptor) { // lets fix up the background colour! Label label = new Label(parent, SWT.NONE); label.setText(labelText); } else { Label label = toolkit.createLabel(parent, labelText); } Control widget; Class refType = isBeanRef(value, propertyName); IObservable observable; if (boolean.class.isAssignableFrom(propertyType) || Boolean.class.isAssignableFrom(propertyType)) { Button checkbox = new Button(parent, SWT.CHECK | SWT.BORDER); widget = checkbox; ISWTObservableValue textValue = Forms.observe(checkbox); observable = textValue; Forms.bindPojoProperty( bindingContext, mmng, value, propertyName, isMandatory(value, propertyName), labelText, textValue, checkbox); } else if (refType != null) { Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER); String[] beanRefs = getBeanRefs(refType); combo.setItems(beanRefs); toolkit.adapt(combo, true, true); widget = combo; ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo); observable = comboValue; Forms.bindPojoProperty( bindingContext, mmng, value, propertyName, isMandatory(value, propertyName), labelText, comboValue, combo); } else if (isEndpointUri(value, propertyName)) { Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER); combo.setItems(getEndpointUris()); toolkit.adapt(combo, true, true); widget = combo; ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo); observable = comboValue; Forms.bindPojoProperty( bindingContext, mmng, value, propertyName, isMandatory(value, propertyName), labelText, comboValue, combo); } else if (Enum.class.isAssignableFrom(propertyType)) { ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY | SWT.BORDER); combo.setContentProvider(ArrayContentProvider.getInstance()); combo.setInput(getEnumValues((Class<? extends Enum>) propertyType)); IViewerObservableValue comboValue = ViewersObservables.observeSingleSelection(combo); observable = comboValue; Control control = combo.getControl(); Forms.bindPojoProperty( bindingContext, mmng, value, propertyName, isMandatory(value, propertyName), labelText, comboValue, control); toolkit.adapt(control, true, true); widget = control; } else { Text text = toolkit.createText(parent, ""); widget = text; // text.setToolTipText(tooltip); ISWTObservableValue textValue = Forms.observe(text); observable = textValue; Forms.bindPojoProperty( bindingContext, mmng, value, propertyName, isMandatory(value, propertyName), labelText, textValue, text); } widget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); if (observable != null && node != null) { observable.addChangeListener( new IChangeListener() { @Override public void handleChange(ChangeEvent event) { // lets notify the node that its changed String id = complexProperty.getId().toString(); fireNodePropertyChangedEvent(id); } }); } }
private void createDecoratedTextField( final IPropertyDescriptor descriptor, FormToolkit toolkit, Composite parent, final IMessageManager mmng) { final Object id = descriptor.getId(); String labelText = descriptor.getDisplayName(); String tooltip = Tooltips.tooltip(id.toString()); GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); boolean isDescription = NODE_DESCRIPTION.equals(id); Control widget; boolean isComplexProperty = descriptor instanceof ComplexPropertyDescriptor; boolean isUnionProperty = descriptor instanceof ComplexUnionPropertyDescriptor; if (isComplexProperty) { widget = bindNestedComplexProperties( toolkit, parent, mmng, (ComplexPropertyDescriptor) descriptor, id, labelText, tooltip); } else { Label label = toolkit.createLabel(parent, labelText); label.setToolTipText(tooltip); if (isDescription) { label.setLayoutData(gd); } if (isUnionProperty) { widget = bindNestedComplexUnionProperties( toolkit, parent, mmng, id, labelText, tooltip, (ComplexUnionPropertyDescriptor) descriptor); } else if (descriptor instanceof ExpressionPropertyDescriptor) { // lets create a composite and add a text are and a combo box // ExpandableComposite composite = // toolkit.createExpandableComposite(parent, SWT.HORIZONTAL); Composite composite = toolkit.createComposite(parent); GridLayout layout = new GridLayout(3, false); zeroMargins(layout); composite.setLayout(layout); widget = composite; Text text = toolkit.createText(composite, "", SWT.BORDER); text.setToolTipText(tooltip); gd = new GridData(GridData.FILL_HORIZONTAL); // gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; // gd.horizontalAlignment = SWT.LEFT; // gd.verticalIndent = 0; // gd.verticalAlignment = GridData.FILL; text.setLayoutData(gd); ISWTObservableValue textValue = Forms.observe(text); // NOTE this code only works if the LanguageExpressionBean is // not // replaced under our feet! final LanguageExpressionBean expression = LanguageExpressionBean.bindToNodeProperty(node, id); final String expressionPropertyName = "expression"; Forms.bindBeanProperty( bindingContext, mmng, expression, expressionPropertyName, isMandatory(expression, expressionPropertyName), expressionPropertyName, textValue, text); String languageLabel = EditorMessages.propertiesLanguageTitle; toolkit.createLabel(composite, languageLabel); // toolkit.createSeparator(composite, SWT.SEPARATOR); Combo combo = new Combo(composite, SWT.NONE | SWT.BORDER); combo.setItems(new Languages().languageArray()); toolkit.adapt(combo, true, true); ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo); Forms.bindBeanProperty( bindingContext, mmng, expression, "language", isMandatory(expression, "language"), languageLabel, comboValue, combo); String language = expression.getLanguage(); if (language == null) { language = CamelModelHelper.getDefaultLanguageName(); expression.setLanguage(language); } // now lets forward property events to the node expression.addPropertyChangeListener( new PropertyChangeListener() { /* * (non-Javadoc) * * @see * java.beans.PropertyChangeListener#propertyChange(java * .beans .PropertyChangeEvent) */ @Override public void propertyChange(PropertyChangeEvent event) { node.firePropertyChange(id.toString(), null, expression); } }); } else { String propertyName = getPropertyName(id); Class refType = isBeanRef(node, propertyName); if (refType != null) { Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER); String[] beanRefs = getBeanRefs(refType); combo.setItems(beanRefs); toolkit.adapt(combo, true, true); widget = combo; ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo); Forms.bindBeanProperty( bindingContext, mmng, node, propertyName, isMandatory(node, propertyName), labelText, comboValue, combo); } else if (isEndpointUri(node, propertyName)) { Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER); combo.setItems(getEndpointUris()); toolkit.adapt(combo, true, true); widget = combo; ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo); Forms.bindBeanProperty( bindingContext, mmng, node, propertyName, isMandatory(node, propertyName), labelText, comboValue, combo); } else if (descriptor instanceof BooleanPropertyDescriptor) { Button checkbox = new Button(parent, SWT.CHECK); widget = checkbox; ISWTObservableValue textValue = Forms.observe(checkbox); Forms.bindBeanProperty( bindingContext, mmng, node, propertyName, isMandatory(node, propertyName), labelText, textValue, checkbox); } else if (descriptor instanceof ListPropertyDescriptor) { if (CamelModelHelper.isPropertyListOFSetHeaders(id)) { Control control = bindSetHeaderTable(toolkit, parent, id); widget = control; } else { Control control = bindListOfValues(toolkit, parent, id); widget = control; } } else if (descriptor instanceof EnumPropertyDescriptor) { EnumPropertyDescriptor enumProperty = (EnumPropertyDescriptor) descriptor; ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY | SWT.BORDER); combo.setContentProvider(ArrayContentProvider.getInstance()); combo.setInput(getEnumValues(enumProperty.getEnumType())); IViewerObservableValue comboValue = ViewersObservables.observeSingleSelection(combo); Control control = combo.getControl(); Forms.bindBeanProperty( bindingContext, mmng, node, propertyName, isMandatory(node, propertyName), labelText, comboValue, control); toolkit.adapt(control, true, true); widget = control; } else { Text text; if (isDescription) { text = toolkit.createText( parent, "", SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); } else { text = toolkit.createText(parent, "", SWT.BORDER); } text.setToolTipText(tooltip); widget = text; ISWTObservableValue textValue = Forms.observe(text); Forms.bindBeanProperty( bindingContext, mmng, node, propertyName, isMandatory(node, propertyName), labelText, textValue, text); } } } boolean isComplexOrUnion = isComplexProperty || isUnionProperty; if (isDescription || isComplexOrUnion) { gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 90; gd.grabExcessVerticalSpace = true; gd.grabExcessHorizontalSpace = true; if (isComplexOrUnion) { gd.heightHint = -1; } if (isComplexProperty) { gd.horizontalSpan = 2; } } else { gd = new GridData(GridData.FILL_HORIZONTAL); } gd.widthHint = 250; widget.setLayoutData(gd); }
@Override public void bindExpression( final EMFDataBindingContext dataBindingContext, final EObject context, final Expression inputExpression, final ViewerFilter[] filters, final ExpressionViewer expressionViewer) { final EObject finalContext = context; addExpressionButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { super.widgetSelected(e); expressionButtonListener(finalContext); } }); editorInputExpression = inputExpression; fillViewerInput(context); final IObservableValue contentObservable = EMFObservables.observeValue( inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT); final IObservableValue nameObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME); final IObservableValue returnTypeObservable = EMFObservables.observeValue( inputExpression, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); final IObservableValue referenceObservable = EMFObservables.observeValue( inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS); final UpdateValueStrategy selectionToName = new UpdateValueStrategy(); final IConverter nameConverter = new Converter(Parameter.class, String.class) { @Override public Object convert(final Object parameter) { return ((Parameter) parameter).getName(); } }; selectionToName.setConverter(nameConverter); final UpdateValueStrategy selectionToContent = new UpdateValueStrategy(); final IConverter contentConverter = new Converter(Parameter.class, String.class) { @Override public Object convert(final Object parameter) { return ((Parameter) parameter).getName(); } }; selectionToContent.setConverter(contentConverter); final UpdateValueStrategy selectionToReturnType = new UpdateValueStrategy(); final IConverter returnTypeConverter = new Converter(Parameter.class, String.class) { @Override public Object convert(final Object parameter) { return ((Parameter) parameter).getTypeClassname(); } }; selectionToReturnType.setConverter(returnTypeConverter); final UpdateValueStrategy selectionToReferencedData = new UpdateValueStrategy(); final IConverter referenceConverter = new Converter(Parameter.class, List.class) { @Override public Object convert(final Object parameter) { return Collections.singletonList(parameter); } }; selectionToReferencedData.setConverter(referenceConverter); final UpdateValueStrategy referencedDataToSelection = new UpdateValueStrategy(); final IConverter referencetoDataConverter = new Converter(List.class, Parameter.class) { @SuppressWarnings("unchecked") @Override public Object convert(final Object parameterList) { if (!((List<Parameter>) parameterList).isEmpty()) { final Parameter p = ((List<Parameter>) parameterList).get(0); final Collection<Parameter> inputParameters = (Collection<Parameter>) viewer.getInput(); for (final Parameter param : inputParameters) { if (param.getName().equals(p.getName()) && param.getTypeClassname().equals(p.getTypeClassname())) { return param; } } } return null; } }; referencedDataToSelection.setConverter(referencetoDataConverter); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), nameObservable, selectionToName, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), contentObservable, selectionToContent, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), returnTypeObservable, selectionToReturnType, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(viewer), referenceObservable, selectionToReferencedData, referencedDataToSelection); dataBindingContext.bindValue( SWTObservables.observeText(typeText, SWT.Modify), returnTypeObservable); }