List of usage examples for org.eclipse.jface.databinding.swt WidgetProperties items
public static IWidgetListProperty items()
From source file:de.prozesskraft.pradar.parts.PradarPartUi3.java
/** * binds arrays to combo-boxes 'processes', 'users' */// ww w .jav a 2 s.co m protected DataBindingContext initDataBindingsComboItems() { DataBindingContext bindingContextComboItems = new DataBindingContext(); // IObservableList targetObservableProcesses = WidgetProperties.items().observe(combo_processes); IObservableList modelObservableProcesses = BeanProperties.list("processes").observe(einstellungen); bindingContextComboItems.bindList(targetObservableProcesses, modelObservableProcesses, null, null); // // IObservableList targetObservableUsers = WidgetProperties.items().observe(combo_users); // IObservableList modelObservableUsers = BeanProperties.list("users").observe(einstellungen); // bindingContextComboItems.bindList(targetObservableUsers, modelObservableUsers, null, null); // IObservableList targetObservableExitcodes = WidgetProperties.items().observe(combo_exitcodes); IObservableList modelObservableExitcodes = BeanProperties.list("exitcodes").observe(einstellungen); bindingContextComboItems.bindList(targetObservableExitcodes, modelObservableExitcodes, null, null); // return bindingContextComboItems; }
From source file:de.prozesskraft.pramp.parts.PrampPartUi1.java
/** * binds array of domainnames to combo-box 'domains' *//* ww w . j a v a 2 s . co m*/ protected DataBindingContext initDataBindingsDomains() { DataBindingContext bindingContextDomains = new DataBindingContext(); // IObservableList targetObservableDomains = WidgetProperties.items().observe(combo_domains); IObservableList modelObservableDomains = BeanProperties.list("domains").observe(einstellungen); bindingContextDomains.bindList(targetObservableDomains, modelObservableDomains, null, null); // return bindingContextDomains; }
From source file:de.prozesskraft.pramp.parts.PrampPartUi1.java
/** * binds array of processnames to combo-box 'processes' *///ww w. j a va2 s . co m protected DataBindingContext initDataBindingsProcesses() { DataBindingContext bindingContextProcesses = new DataBindingContext(); // IObservableList targetObservableProcesses = WidgetProperties.items().observe(combo_processes); IObservableList modelObservableProcesses = BeanProperties.list("processes").observe(einstellungen); bindingContextProcesses.bindList(targetObservableProcesses, modelObservableProcesses, null, null); // return bindingContextProcesses; }
From source file:de.prozesskraft.pramp.parts.PrampPartUi1.java
/** * binds array of versions to combo-box 'versions' */// w w w. j a v a2 s . c om protected DataBindingContext initDataBindingsVersions() { DataBindingContext bindingContextVersions = new DataBindingContext(); // IObservableList targetObservableVersions = WidgetProperties.items().observe(combo_versions); IObservableList modelObservableVersions = BeanProperties.list("versions").observe(einstellungen); bindingContextVersions.bindList(targetObservableVersions, modelObservableVersions, null, null); // return bindingContextVersions; }
From source file:org.bonitasoft.studio.properties.sections.document.DocumentPropertySection.java
License:Open Source License
protected void bindList() { final IObservableList documentsListObserved = EMFEditProperties .list(getEditingDomain(), ProcessPackage.Literals.POOL__DOCUMENTS).observe(getPool()); emfDataBindingContext.bindList(WidgetProperties.items().observe(documentListViewer.getList()), documentsListObserved);// www. jav a 2s. c o m documentListViewer.setInput(documentsListObserved); }
From source file:org.bonitasoft.studio.properties.sections.transitionordering.TransitionOrderingPropertySection.java
License:Open Source License
protected void bindList() { SourceElement sourceElement = getSourceElement(); final IObservableList outgoingListObserved = EMFEditProperties .list(getEditingDomain(), ProcessPackage.Literals.SOURCE_ELEMENT__OUTGOING).observe(sourceElement); databindingContext.bindList(WidgetProperties.items().observe(listViewer.getList()), outgoingListObserved); listViewer.setInput(outgoingListObserved); }
From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageMainTab.java
License:Open Source License
/** * Creates the {@link Composite} container that will display widgets to * select an {@link IDockerImage}, name it and specify the command to run. * * @param container/*from ww w .j a va 2 s.c o m*/ * the parent {@link Composite} */ private void createImageSettingsSection(final Composite container) { GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(3, 1) .applyTo(new Label(container, SWT.NONE)); final Label connectionSelectionLabel = new Label(container, SWT.NONE); connectionSelectionLabel.setText(WizardMessages.getString("Connection.label")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false) .applyTo(connectionSelectionLabel); final Combo connectionSelectionCombo = new Combo(container, SWT.BORDER); connectionSelectionCombo.setToolTipText(LaunchMessages.getString("RunMainTabSelectConnection.tooltip")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(connectionSelectionCombo); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); new ControlDecoration(connectionSelectionCombo, SWT.TOP | SWT.LEFT); final ComboViewer connectionSelectionComboViewer = new ComboViewer(connectionSelectionCombo); connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider()); connectionSelectionComboViewer.setInput(getConnectionNames()); dbc.bindValue(WidgetProperties.selection().observe(connectionSelectionCombo), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_CONNECTION_NAME) .observe(model)); // Image selection name final Label imageSelectionLabel = new Label(container, SWT.NONE); imageSelectionLabel.setText(WizardMessages.getString("Image.label")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); final Combo imageSelectionCombo = new Combo(container, SWT.BORDER); final ComboViewer imageSelectionComboViewer = new ComboViewer(imageSelectionCombo); imageSelectionCombo.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.selectTooltip")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(imageSelectionCombo); new ControlDecoration(imageSelectionCombo, SWT.TOP | SWT.LEFT); new ContentProposalAdapter(imageSelectionCombo, new ComboContentAdapter() { @Override public void insertControlContents(Control control, String text, int cursorPosition) { final Combo combo = (Combo) control; final Point selection = combo.getSelection(); combo.setText(text); selection.x = text.length(); selection.y = selection.x; combo.setSelection(selection); } }, getImageNameContentProposalProvider(imageSelectionCombo), null, null); // image search final Button searchImageButton = new Button(container, SWT.NONE); searchImageButton.setText(WizardMessages.getString("ImageRunSelectionPage.search")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .hint(LaunchConfigurationUtils.getButtonWidthHint(searchImageButton), SWT.DEFAULT) .applyTo(searchImageButton); searchImageButton.addSelectionListener(onSearchImage()); imageSelectionComboViewer.setContentProvider(new ObservableListContentProvider()); dbc.bindList(WidgetProperties.items().observe(imageSelectionCombo), BeanProperties .list(ImageRunSelectionModel.class, ImageRunSelectionModel.IMAGE_NAMES).observe(model)); dbc.bindValue(WidgetProperties.selection().observe(imageSelectionCombo), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NAME).observe(model)); // Container name (optional) final Label containerNameLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); containerNameLabel.setText("Name:"); //$NON-NLS-1$ final Text containerNameText = new Text(container, SWT.BORDER); containerNameText.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.containerTooltip")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(containerNameText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerNameText), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.CONTAINER_NAME).observe(model)); // EntryPoint (optional) final Label entrypointLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); entrypointLabel.setText(WizardMessages.getString("ImageRunSelectionPage.entrypoint")); //$NON-NLS-1$ // TODO: include SWT.SEARCH | SWT.ICON_SEARCH to support value reset final Text entrypointText = new Text(container, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(entrypointText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(entrypointText), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.ENTRYPOINT).observe(model)); // Command (optional) final Label commandLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); commandLabel.setText(WizardMessages.getString("ImageRunSelectionPage.command")); //$NON-NLS-1$ final Text commandText = new Text(container, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(commandText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(commandText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.COMMAND).observe(model)); }
From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionPage.java
License:Open Source License
/** * Creates the {@link Composite} container that will display widgets to * select an {@link IDockerImage}, name it and specify the command to run. * // w w w .java2 s . c om * @param container * the parent {@link Composite} */ private void createImageSettingsSection(final Composite container) { // Image selection name final Label imageSelectionLabel = new Label(container, SWT.NONE); imageSelectionLabel.setText(WizardMessages.getString("ImageRunSelectionPage.imageName")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); final Combo imageSelectionCombo = new Combo(container, SWT.BORDER); final ComboViewer imageSelectionComboViewer = new ComboViewer(imageSelectionCombo); imageSelectionCombo.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.selectTooltip")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(imageSelectionCombo); new ControlDecoration(imageSelectionCombo, SWT.TOP | SWT.LEFT); new ContentProposalAdapter(imageSelectionCombo, new ComboContentAdapter() { @Override public void insertControlContents(Control control, String text, int cursorPosition) { final Combo combo = (Combo) control; final Point selection = combo.getSelection(); combo.setText(text); selection.x = text.length(); selection.y = selection.x; combo.setSelection(selection); } }, getImageNameContentProposalProvider(imageSelectionCombo), null, null); // image search final Button searchImageButton = new Button(container, SWT.NONE); searchImageButton.setText(WizardMessages.getString("ImageRunSelectionPage.search")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(searchImageButton); searchImageButton.addSelectionListener(onSearchImage()); // link to pull image final Label fillerLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(fillerLabel); final Link pullImageLink = new Link(container, SWT.NONE); pullImageLink.setText(WizardMessages.getString("ImageRunSelectionPage.pullImage")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS - 1, 1) .applyTo(pullImageLink); pullImageLink.addSelectionListener(onPullImage()); dbc.bindValue(WidgetProperties.enabled().observe(pullImageLink), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NEEDS_PULLING) .observe(model)); // bind combo with model (for values and selection) imageSelectionComboViewer.setContentProvider(new ObservableListContentProvider()); dbc.bindList(WidgetProperties.items().observe(imageSelectionCombo), BeanProperties .list(ImageRunSelectionModel.class, ImageRunSelectionModel.IMAGE_NAMES).observe(model)); dbc.bindValue(WidgetProperties.selection().observe(imageSelectionCombo), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NAME).observe(model)); // Container name (optional) final Label containerNameLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); containerNameLabel.setText(WizardMessages.getString("ImageRunSelectionPage.containerName")); //$NON-NLS-1$ final Text containerNameText = new Text(container, SWT.BORDER); containerNameText.setToolTipText(WizardMessages.getString("ImageRunSelectionPage.containerTooltip")); //$NON-NLS-1$ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(containerNameText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerNameText), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.CONTAINER_NAME).observe(model)); // EntryPoint (optional) final Label entrypointLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); entrypointLabel.setText(WizardMessages.getString("ImageRunSelectionPage.entrypoint")); //$NON-NLS-1$ // TODO: include SWT.SEARCH | SWT.ICON_SEARCH to support value reset final Text entrypointText = new Text(container, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(entrypointText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(entrypointText), BeanProperties .value(ImageRunSelectionModel.class, ImageRunSelectionModel.ENTRYPOINT).observe(model)); // Command (optional) final Label commandLabel = new Label(container, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel); commandLabel.setText(WizardMessages.getString("ImageRunSelectionPage.command")); //$NON-NLS-1$ final Text commandText = new Text(container, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1) .applyTo(commandText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1) .applyTo(new Label(container, SWT.NONE)); dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(commandText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.COMMAND).observe(model)); }
From source file:org.fusesource.ide.camel.editor.properties.DetailsSection.java
License:Open Source License
/** * /*from w ww . j a va2s .co m*/ * @param props * @param page * @param ignorePathProperties * @param group */ protected void generateTabContents(List<Parameter> props, final Composite page, boolean ignorePathProperties, final String group) { props.sort(new ParameterPriorityComparator()); for (Parameter p : props) { final Parameter prop = p; String currentPropertyGroup = prop.getGroup(); if (shouldHidePropertyFromGroup(group, p, currentPropertyGroup)) { continue; } ISWTObservableValue uiObservable = null; IObservableList<Object> uiListObservable = null; IObservableValue<Object> modelObservable; IObservableList<Object> modelListObservable; IValidator validator = null; createPropertyLabel(toolkit, page, p); Control c = null; // DESCRIPTION PROPERTIES if (CamelComponentUtils.isDescriptionProperty(prop)) { new DescriptionParameterPropertyUICreator(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()).create(); } else if (CamelComponentUtils.isBooleanProperty(prop)) { new BooleanParameterPropertyUICreatorForDetails(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()).create(); } else if (CamelComponentUtils.isTextProperty(prop) || CamelComponentUtils.isCharProperty(prop)) { new TextParameterPropertyUICreator(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()) .create(); } else if (CamelComponentUtils.isNumberProperty(prop)) { new NumberParameterPropertyUICreatorForDetails(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()).create(); } else if (CamelComponentUtils.isChoiceProperty(prop)) { CCombo choiceCombo = new CCombo(page, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY | SWT.SINGLE); getWidgetFactory().adapt(choiceCombo, true, true); choiceCombo.setEditable(false); choiceCombo.setItems(CamelComponentUtils.getChoices(prop)); String value = (String) (this.selectedEP.getParameter(p.getName()) != null ? this.selectedEP.getParameter(p.getName()) : this.eip.getParameter(p.getName()).getDefaultValue()); for (int i = 0; i < choiceCombo.getItems().length; i++) { if (choiceCombo.getItem(i).equalsIgnoreCase(value)) { choiceCombo.select(i); break; } } choiceCombo.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { CCombo choice = (CCombo) e.getSource(); selectedEP.setParameter(prop.getName(), choice.getText()); } }); choiceCombo.setLayoutData(createPropertyFieldLayoutData()); c = choiceCombo; //initialize the map entry modelMap.put(p.getName(), choiceCombo.getText()); // create observables for the control uiObservable = WidgetProperties.selection().observe(choiceCombo); if (PropertiesUtils.isRequired(p)) { validator = new IValidator() { /* * (non-Javadoc) * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object) */ @Override public IStatus validate(Object value) { if (value != null && value instanceof String && value.toString().trim().length() > 0) { return ValidationStatus.ok(); } return ValidationStatus.error( "Parameter " + prop.getName() + " is a mandatory field and cannot be empty."); } }; } // REF PROPERTIES } else if (CamelComponentUtils.isRefProperty(prop)) { CCombo choiceCombo = new CCombo(page, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY | SWT.SINGLE); getWidgetFactory().adapt(choiceCombo, true, true); choiceCombo.setEditable(true); choiceCombo.setItems(CamelComponentUtils.getRefs(this.selectedEP.getCamelFile())); String value = (String) (this.selectedEP.getParameter(p.getName()) != null ? this.selectedEP.getParameter(p.getName()) : this.eip.getParameter(p.getName()).getDefaultValue()); boolean selected = false; for (int i = 0; i < choiceCombo.getItems().length; i++) { if (choiceCombo.getItem(i).equalsIgnoreCase(value)) { choiceCombo.select(i); selected = true; break; } } if (!selected && value != null) { choiceCombo.setText(value); } choiceCombo.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { CCombo choice = (CCombo) e.getSource(); selectedEP.setParameter(prop.getName(), choice.getText()); } }); choiceCombo.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { CCombo choice = (CCombo) e.getSource(); selectedEP.setParameter(prop.getName(), choice.getText()); } }); choiceCombo.setLayoutData(createPropertyFieldLayoutData()); c = choiceCombo; //initialize the map entry modelMap.put(p.getName(), choiceCombo.getText()); // create observables for the control uiObservable = WidgetProperties.selection().observe(choiceCombo); validator = new IValidator() { @Override public IStatus validate(Object value) { // check if value has content if (PropertiesUtils.isRequired(prop)) { if (value == null || !(value instanceof String) || value.toString().trim().length() < 1) { return ValidationStatus.error("Parameter " + prop.getName() + " is a mandatory field and cannot be empty."); } } else { if (isNotEmptyString(value) && selectedEP.getRouteContainer().findNode((String) value) == null && !selectedEP.getCamelFile().getGlobalDefinitions() .containsKey((String) value)) { // no ref found - could be something the server provides return ValidationStatus.warning("Parameter " + prop.getName() + " does not point to an existing reference inside the context."); } } return new RefOrDataFormatUnicityChoiceValidator(selectedEP, prop).validate(value); } private boolean isNotEmptyString(Object value) { return value != null && value instanceof String && value.toString().trim().length() > 0; } }; // FILE PROPERTIES } else if (CamelComponentUtils.isFileProperty(prop)) { new FileParameterPropertyUICreatorForDetails(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()).create(); } else if (CamelComponentUtils.isListProperty(prop)) { org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(page, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY | SWT.SINGLE); getWidgetFactory().adapt(list, true, true); list.setLayoutData(createPropertyFieldLayoutData()); ArrayList<String> listElements = this.selectedEP.getParameter(prop.getName()) != null ? (ArrayList<String>) this.selectedEP.getParameter(prop.getName()) : new ArrayList<String>(); list.setItems(listElements.toArray(new String[listElements.size()])); c = list; //initialize the map entry modelMap.put(p.getName(), Arrays.asList(list.getItems())); // create observables for the control uiListObservable = WidgetProperties.items().observe(list); if (PropertiesUtils.isRequired(p)) { validator = new IValidator() { @Override public IStatus validate(Object value) { if (value != null && value instanceof List && !((List<?>) value).isEmpty()) { return ValidationStatus.ok(); } return ValidationStatus.error( "Parameter " + prop.getName() + " is a mandatory field and cannot be empty."); } }; } // EXPRESSION PROPERTIES } else if (CamelComponentUtils.isExpressionProperty(prop)) { CCombo choiceCombo = new CCombo(page, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY | SWT.SINGLE); getWidgetFactory().adapt(choiceCombo, true, true); choiceCombo.setEditable(false); choiceCombo.setLayoutData(createPropertyFieldLayoutData()); final AbstractCamelModelElement expressionElement = this.selectedEP .getParameter(prop.getName()) != null ? (AbstractCamelModelElement) this.selectedEP.getParameter(prop.getName()) : null; choiceCombo.setItems(CamelComponentUtils.getOneOfList(prop)); final Composite eform = getWidgetFactory().createFlatFormComposite(page); eform.setLayoutData( GridDataFactory.fillDefaults().indent(5, 0).span(4, 1).grab(true, false).create()); eform.setLayout(new GridLayout(1, true)); choiceCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { CCombo choice = (CCombo) e.getSource(); String language = choice.getText(); languageChanged(language, eform, selectedEP.getParameter(prop.getName()) != null ? (AbstractCamelModelElement) selectedEP.getParameter(prop.getName()) : null, page, prop); } }); if (expressionElement != null) { String value = expressionElement.getNodeTypeId(); Object expressionParameterValue = expressionElement.getParameter("expression"); if (expressionParameterValue != null && expressionParameterValue instanceof AbstractCamelModelElement) { AbstractCamelModelElement ex = (AbstractCamelModelElement) expressionParameterValue; value = ex.getTranslatedNodeName(); } choiceCombo.deselectAll(); for (int i = 0; i < choiceCombo.getItems().length; i++) { if (choiceCombo.getItem(i).equalsIgnoreCase(value)) { choiceCombo.select(i); languageChanged(value, eform, expressionElement, page, prop); break; } } } c = choiceCombo; //initialize the map entry modelMap.put(p.getName(), choiceCombo.getText()); // create observables for the control uiObservable = WidgetProperties.selection().observe(choiceCombo); if (PropertiesUtils.isRequired(p)) { validator = new IValidator() { @Override public IStatus validate(Object value) { if (value != null && value instanceof String && value.toString().trim().length() > 0) { return ValidationStatus.ok(); } return ValidationStatus.error( "Parameter " + prop.getName() + " is a mandatory field and cannot be empty."); } }; } // DATAFORMAT PROPERTIES } else if (CamelComponentUtils.isDataFormatProperty(prop)) { CCombo choiceCombo = new CCombo(page, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY | SWT.SINGLE); getWidgetFactory().adapt(choiceCombo, true, true); choiceCombo.setEditable(false); choiceCombo.setLayoutData(createPropertyFieldLayoutData()); final AbstractCamelModelElement dataformatElement = selectedEP.getParameter(prop.getName()) != null ? (AbstractCamelModelElement) selectedEP.getParameter(prop.getName()) : null; choiceCombo.setItems(CamelComponentUtils.getOneOfList(prop)); final Composite eform = getWidgetFactory().createFlatFormComposite(page); eform.setLayoutData( GridDataFactory.fillDefaults().indent(5, 0).span(4, 1).grab(true, false).create()); eform.setLayout(new GridLayout(1, true)); choiceCombo.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { CCombo choice = (CCombo) e.getSource(); String dataformat = choice.getText(); dataFormatChanged(dataformat, eform, selectedEP.getParameter(prop.getName()) != null ? (AbstractCamelModelElement) selectedEP.getParameter(prop.getName()) : null, page, prop); } }); if (dataformatElement != null) { String value = dataformatElement.getNodeTypeId(); choiceCombo.deselectAll(); for (int i = 0; i < choiceCombo.getItems().length; i++) { if (choiceCombo.getItem(i).equalsIgnoreCase(value)) { choiceCombo.select(i); dataFormatChanged(value, eform, dataformatElement, page, prop); break; } } } c = choiceCombo; //initialize the map entry modelMap.put(p.getName(), choiceCombo.getText()); // create observables for the control uiObservable = WidgetProperties.selection().observe(choiceCombo); if (PropertiesUtils.isRequired(p)) { validator = new IValidator() { @Override public IStatus validate(Object value) { if (value != null && value instanceof String && value.toString().trim().length() > 0) { return new RefOrDataFormatUnicityChoiceValidator(selectedEP, prop).validate(value); } return ValidationStatus.error( "Parameter " + prop.getName() + " is a mandatory field and cannot be empty."); } }; } // UNSUPPORTED PROPERTIES / REFS } else if (CamelComponentUtils.isUnsupportedProperty(prop)) { new UnsupportedParameterPropertyUICreatorForDetails(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()).create(); } else if ("redeliveryPolicy".equals(prop.getName())) { Object valueToDisplay = (this.selectedEP.getParameter(p.getName()) != null ? this.selectedEP.getParameter(p.getName()) : this.eip.getParameter(p.getName()).getDefaultValue()); if (valueToDisplay instanceof AbstractCamelModelElement) { Group objectGroup = getWidgetFactory().createGroup(page, ""); objectGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(4).create()); objectGroup.setLayoutData( GridDataFactory.fillDefaults().indent(5, 0).span(4, 1).grab(true, false).create()); CamelModel camelModel = getCamelModel((AbstractCamelModelElement) valueToDisplay); final Eip eip = camelModel.getEipModel().getEIPByName(prop.getName()); for (Parameter childParameter : eip.getParameters()) { createPropertyLabel(toolkit, objectGroup, childParameter); // Field Control field = getControlForParameter(childParameter, objectGroup, (AbstractCamelModelElement) valueToDisplay, eip); field.setToolTipText(childParameter.getDescription()); } c = objectGroup; } // CLASS BASED PROPERTIES - REF OR CLASSNAMES AS STRINGS } else { new TextParameterPropertyUICreator(dbc, modelMap, eip, selectedEP, p, page, getWidgetFactory()) .create(); } // bind the observables Binding bindValue = null; if (uiObservable != null) { // create observables for the Map entries modelObservable = Observables.observeMapEntry(modelMap, p.getName()); // create UpdateValueStrategy and assign to the binding UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(validator); bindValue = dbc.bindValue(uiObservable, modelObservable, strategy, null); } else if (uiListObservable != null) { modelListObservable = Observables.staticObservableList((List) modelMap.get(p.getName()), String.class); UpdateListStrategy listStrategy = new UpdateListStrategy() { @Override protected IStatus doAdd(IObservableList observableList, Object element, int index) { super.doAdd(observableList, element, index); return validateMandatoryBehavior(prop, observableList); } @Override protected IStatus doRemove(IObservableList observableList, int index) { super.doRemove(observableList, index); return validateMandatoryBehavior(prop, observableList); } private IStatus validateMandatoryBehavior(final Parameter prop, IObservableList observableList) { if (prop.getRequired() != null && "true".equalsIgnoreCase(prop.getRequired()) && observableList.isEmpty()) { return ValidationStatus.error( "Parameter " + prop.getName() + " is a mandatory field and cannot be empty."); } return ValidationStatus.ok(); } }; bindValue = dbc.bindList(uiListObservable, modelListObservable, listStrategy, null); } if (bindValue != null) { ControlDecorationSupport.create(bindValue, SWT.TOP | SWT.LEFT); } if (c != null) { createHelpDecoration(p, c); } } page.layout(); }
From source file:org.goko.common.bindings.AbstractController.java
License:Open Source License
/** * Binding between an object and a property, based on items list * @param source the UI object//from w ww. j a v a 2s . com * @param property the name of the property * @throws GkException GkException */ public void addItemsBinding(Object source, String property) throws GkException { verifyGetter(dataModel, property); verifySetter(dataModel, property); IObservableList itemsComboSerialPortObserveWidget = WidgetProperties.items().observe(source); IObservableList comPortListBindingsObserveList = BeanProperties.list(property).observe(dataModel); Binding binding = bindingContext.bindList(itemsComboSerialPortObserveWidget, comPortListBindingsObserveList, null, null); bindings.add(binding); }