List of usage examples for org.eclipse.jface.databinding.viewers ViewersObservables observeInput
@Deprecated public static IObservableValue observeInput(Viewer viewer)
From source file:com.ebmwebsourcing.petals.services.su.editor.SuEditionComposite.java
License:Open Source License
/** * Initializes the widgets on the left side. *//*from w w w .jav a 2 s. c o m*/ protected void createLeftWidgets() { Composite servicesComposite = getFormToolkit().createComposite(this); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; servicesComposite.setLayout(layout); // Provides Form providesForm = getFormToolkit().createForm(servicesComposite); providesForm.setLayoutData(new GridData(GridData.FILL_BOTH)); providesForm.setText(Messages.provides); layout = new GridLayout(2, false); layout.marginHeight = 0; providesForm.getBody().setLayout(layout); this.providesViewer = new TableViewer(providesForm.getBody()); this.providesViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); this.providesViewer.setLabelProvider(this.labelProvider); this.providesViewer.setContentProvider(new ArrayContentProvider()); Composite providesButtons = getFormToolkit().createComposite(providesForm.getBody()); layout = new GridLayout(); layout.marginHeight = 0; providesButtons.setLayout(layout); providesButtons.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, true)); Button newProvidesButton = getFormToolkit().createButton(providesButtons, "New...", SWT.NONE); newProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); newProvidesButton.setImage(PetalsImages.INSTANCE.getAdd()); final IWizard providesWizard = findNewWizard(PetalsMode.provides); if (providesWizard == null) { newProvidesButton.setEnabled(false); newProvidesButton.setToolTipText("The component is not supported."); } else { newProvidesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (new WizardDialog(getShell(), providesWizard).open() == Dialog.OK) SuEditionComposite.this.providesViewer.refresh(); } }); } final Button removeProvidesButton = getFormToolkit().createButton(providesButtons, "Remove", SWT.NONE); removeProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); removeProvidesButton.setImage(PetalsImages.INSTANCE.getDelete()); removeProvidesButton.addSelectionListener(new EListRemoveSelectionListener(this.providesViewer)); final Button upProvidesButton = getFormToolkit().createButton(providesButtons, "", SWT.NONE); upProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); upProvidesButton.setText("&Up"); upProvidesButton.addSelectionListener(new EListUpSelectionListener()); final Button downProvidesButton = getFormToolkit().createButton(providesButtons, "", SWT.NONE); downProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); downProvidesButton.setText("&Down"); downProvidesButton.addSelectionListener(new EListDownSelectionListener()); getDataBindingContext().bindValue(ViewersObservables.observeInput(this.providesViewer), EMFEditObservables.observeValue(getEditingDomain(), getJbiModel().getServices(), JbiPackage.Literals.SERVICES__PROVIDES)); // Consumes Form consumesForm = getFormToolkit().createForm(servicesComposite); consumesForm.setLayoutData(new GridData(GridData.FILL_BOTH)); consumesForm.setText(Messages.consumes); layout = new GridLayout(2, false); layout.marginHeight = 0; consumesForm.getBody().setLayout(layout); this.consumesViewer = new TableViewer(consumesForm.getBody()); this.consumesViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); this.consumesViewer.setLabelProvider(this.labelProvider); this.consumesViewer.setContentProvider(new ArrayContentProvider()); Composite consumesButtons = getFormToolkit().createComposite(consumesForm.getBody()); layout = new GridLayout(); layout.marginHeight = 0; consumesButtons.setLayout(layout); consumesButtons.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, true)); Button newConsumesButton = getFormToolkit().createButton(consumesButtons, "New...", SWT.NONE); newConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); newConsumesButton.setImage(PetalsImages.INSTANCE.getAdd()); final IWizard consumesWizard = findNewWizard(PetalsMode.consumes); if (consumesWizard == null) { newConsumesButton.setEnabled(false); newConsumesButton.setToolTipText("The component is not supported."); } else { newConsumesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (new WizardDialog(getShell(), consumesWizard).open() == Dialog.OK) SuEditionComposite.this.consumesViewer.refresh(); } }); } final Button removeConsumesButton = getFormToolkit().createButton(consumesButtons, "Remove", SWT.NONE); removeConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); removeConsumesButton.setImage(PetalsImages.INSTANCE.getDelete()); removeConsumesButton.addSelectionListener(new EListRemoveSelectionListener(this.consumesViewer)); final Button upConsumesButton = getFormToolkit().createButton(consumesButtons, "", SWT.NONE); upConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); upConsumesButton.setText("&Up"); upConsumesButton.addSelectionListener(new EListUpSelectionListener()); final Button downConsumesButton = getFormToolkit().createButton(consumesButtons, "", SWT.NONE); downConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); downConsumesButton.setText("&Down"); downConsumesButton.addSelectionListener(new EListDownSelectionListener()); getDataBindingContext().bindValue(ViewersObservables.observeInput(this.consumesViewer), EMFEditObservables.observeValue(getEditingDomain(), getJbiModel().getServices(), JbiPackage.Literals.SERVICES__CONSUMES)); this.providesViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = ((IStructuredSelection) SuEditionComposite.this.providesViewer .getSelection()); if (selection.isEmpty()) { SuEditionComposite.this.selectedEndpoint = null; upProvidesButton.setEnabled(false); downProvidesButton.setEnabled(false); } else { SuEditionComposite.this.consumesViewer.setSelection(new StructuredSelection()); SuEditionComposite.this.selectedEndpoint = (Provides) selection.getFirstElement(); SuEditionComposite.this.containmentList = getJbiModel().getServices().getProvides(); upProvidesButton.setEnabled(SuEditionComposite.this.containmentList .indexOf(SuEditionComposite.this.selectedEndpoint) > 0); downProvidesButton.setEnabled(SuEditionComposite.this.containmentList.indexOf( SuEditionComposite.this.selectedEndpoint) != SuEditionComposite.this.containmentList .size() - 1); refreshDetails(); } removeProvidesButton.setEnabled(SuEditionComposite.this.selectedEndpoint != null); } }); this.consumesViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = ((IStructuredSelection) SuEditionComposite.this.consumesViewer .getSelection()); if (selection.isEmpty()) { SuEditionComposite.this.selectedEndpoint = null; upConsumesButton.setEnabled(false); downConsumesButton.setEnabled(false); } else { SuEditionComposite.this.providesViewer.setSelection(new StructuredSelection()); SuEditionComposite.this.selectedEndpoint = (Consumes) selection.getFirstElement(); SuEditionComposite.this.containmentList = getJbiModel().getServices().getConsumes(); upConsumesButton.setEnabled(SuEditionComposite.this.containmentList .indexOf(SuEditionComposite.this.selectedEndpoint) > 0); downConsumesButton.setEnabled(SuEditionComposite.this.containmentList.indexOf( SuEditionComposite.this.selectedEndpoint) != SuEditionComposite.this.containmentList .size() - 1); refreshDetails(); } removeConsumesButton.setEnabled(SuEditionComposite.this.selectedEndpoint != null); } }); }
From source file:gov.redhawk.ide.dcd.internal.ui.editor.DevicesSection.java
License:Open Source License
/** * {@inheritDoc}// w w w . ja v a 2s . c o m */ @Override public void refresh(final Resource resource) { if (isDisposed()) { return; } this.dcdResource = resource; if (this.dcdResource == null) { return; } if (this.fExtensionTree != null) { if (this.context != null) { this.context.dispose(); } this.context = new EMFDataBindingContext(); final DeviceConfiguration dcd = getDeviceConfiguration(); this.context.bindValue(ViewersObservables.observeInput(this.fExtensionTree), EMFEditObservables .observeValue(getEditingDomain(), dcd, DcdPackage.Literals.DEVICE_CONFIGURATION__PARTITIONING)); if (!this.dcdResource.eAdapters().contains(this.refreshAdapter)) { this.refreshAdapter.setTarget(this.dcdResource); } } this.fireSelection(); this.setEditable(); }
From source file:gov.redhawk.ide.sad.internal.ui.section.ExternalPortsSection.java
License:Open Source License
@Override public void refresh(final Resource resource) { super.refresh(resource); this.sadResource = resource; for (final Binding binding : this.bindings) { binding.dispose();/* w w w. j av a 2 s. co m*/ } this.bindings.clear(); final IEMFEditValueProperty inputValue = EMFEditProperties.value(getPage().getEditingDomain(), SadPackage.Literals.SOFTWARE_ASSEMBLY__EXTERNAL_PORTS); final DataBindingContext context = this.getPage().getEditor().getDataBindingContext(); this.bindings.add(context.bindValue(ViewersObservables.observeInput(this.client.getPortViewer()), inputValue.observe(getWaveform()))); }
From source file:gov.redhawk.prf.internal.ui.editor.detailspart.SimplePropertyDetailsPage.java
License:Open Source License
/** * {@inheritDoc}/*from w ww.ja v a2s . com*/ */ @Override protected List<Binding> bind(final DataBindingContext dataBindingContext, final EObject input) { final List<Binding> retVal = super.bind(dataBindingContext, input); final EditingDomain domain = getEditingDomain(); // Value if (getComposite().getValueEntry() != null) { EMFEmptyStringToNullUpdateValueStrategy targetToModel = new EMFEmptyStringToNullUpdateValueStrategy(); targetToModel.setConverter(new EmptyStringValueToStringConverter()); EMFUpdateValueStrategy modelToTarget = new EMFUpdateValueStrategy(); modelToTarget.setConverter(new StringToEmptyStringValueConverter()); retVal.add(dataBindingContext.bindValue( WidgetProperties.text(SWT.Modify).observeDelayed(SCAFormEditor.getFieldBindingDelay(), getComposite().getValueEntry().getText()), EMFEditObservables.observeValue(domain, input, PrfPackage.Literals.SIMPLE__VALUE), targetToModel, modelToTarget)); } //Enumerations if (getComposite().getEnumerationViewer() != null) { final IEMFEditValueProperty enumProperty = EMFEditProperties.value(getEditingDomain(), FeaturePath.fromList(PrfPackage.Literals.SIMPLE__ENUMERATIONS)); retVal.add(dataBindingContext.bindValue( ViewersObservables.observeInput(getComposite().getEnumerationViewer()), enumProperty.observe(input))); } return retVal; }
From source file:gov.redhawk.prf.internal.ui.editor.detailspart.SimpleSequencePropertyDetailsPage.java
License:Open Source License
/** * {@inheritDoc}// ww w . j av a 2 s . c o m */ @Override protected List<Binding> bind(final DataBindingContext context, final EObject input) { final List<Binding> retVal = super.bind(context, input); this.input = (SimpleSequence) input; // Values final IEMFEditValueProperty valueProp = EMFEditProperties.value(getEditingDomain(), FeaturePath.fromList(PrfPackage.Literals.SIMPLE_SEQUENCE__VALUES)); final TableViewer valuesViewer = this.composite.getValuesViewer(); retVal.add(context.bindValue(ViewersObservables.observeInput(valuesViewer), valueProp.observe(input))); this.composite.getValueColumn().setEditingSupport( new SimpleSequenceValueEditingSupport(this.input.getType(), this.input.isComplex(), valuesViewer)); return retVal; }
From source file:org.bonitasoft.studio.actors.ui.section.AbstractActorsPropertySection.java
License:Open Source License
protected void updateDatabinding() { Assignable assignable = (Assignable) getEObject(); if (assignable != null) { if (emfDatabindingContext != null) { emfDatabindingContext.dispose(); }//from ww w. jav a2 s . c o m emfDatabindingContext = new EMFDataBindingContext(); AbstractProcess process = ModelHelper.getParentProcess(assignable); emfDatabindingContext.bindValue(ViewersObservables.observeInput(actorComboViewer), EMFObservables.observeValue(process, ProcessPackage.Literals.ABSTRACT_PROCESS__ACTORS)); emfDatabindingContext.bindValue(ViewersObservables.observeSingleSelection(actorComboViewer), EMFEditObservables.observeValue(getEditingDomain(), assignable, ProcessPackage.Literals.ASSIGNABLE__ACTOR)); } }
From source file:org.bonitasoft.studio.condition.ui.expression.ComparisonExpressionEditor.java
License:Open Source License
@Override public void bindExpression(EMFDataBindingContext dataBindingContext, EObject context, Expression inputExpression, ViewerFilter[] viewerTypeFilters, ExpressionViewer expressionViewer) { this.inputExpression = inputExpression; final IObservableValue contentModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__CONTENT); final IObservableValue nameModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__NAME); final IObservableValue dependenciesModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__REFERENCED_ELEMENTS); final IObservableValue autoDepsModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__AUTOMATIC_DEPENDENCIES); final IObservableValue returnTypeModelObservable = EMFObservables.observeValue(inputExpression, ExpressionPackage.Literals.EXPRESSION__RETURN_TYPE); final ISWTObservableValue observeText = SWTObservables .observeText(comparisonEditor.getViewer().getControl(), SWT.Modify); dataBindingContext.bindValue(observeText, contentModelObservable); observeText.addValueChangeListener(new IValueChangeListener() { @Override/* www. java 2 s . co m*/ public void handleValueChange(ValueChangeEvent event) { if (ComparisonExpressionEditor.this.inputExpression.isAutomaticDependencies()) { updateDependencies(); } } }); dataBindingContext.bindValue(observeText, nameModelObservable); dataBindingContext.bindValue(ViewersObservables.observeInput(dependenciesViewer), dependenciesModelObservable); UpdateValueStrategy opposite = new UpdateValueStrategy(); opposite.setConverter(new Converter(Boolean.class, Boolean.class) { @Override public Object convert(Object fromObject) { return !((Boolean) fromObject); } }); dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton), autoDepsModelObservable); dataBindingContext.bindValue(SWTObservables.observeSelection(automaticResolutionButton), SWTObservables.observeEnabled(addDependencyButton), opposite, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); dependencySection.setExpanded(!automaticResolutionButton.getSelection()); addDependencyButton.setEnabled(!inputExpression.isAutomaticDependencies()); ControlDecorationSupport.create(dataBindingContext.bindValue( ViewersObservables.observeSingleSelection(typeCombo), returnTypeModelObservable), SWT.LEFT); typeCombo.getCombo().setEnabled(!inputExpression.isReturnTypeFixed()); final ExpressionContentProvider provider = new ExpressionContentProvider(); provider.setContext(context); final Set<Expression> filteredExpressions = new HashSet<Expression>(); Expression[] expressions = provider.getExpressions(); EObject input = provider.getContext(); if (expressions != null) { filteredExpressions.addAll(Arrays.asList(expressions)); if (input != null && viewerTypeFilters != null) { for (Expression exp : expressions) { for (ViewerFilter filter : viewerTypeFilters) { if (filter != null && !filter.select(comparisonEditor.getViewer(), input, exp)) { filteredExpressions.remove(exp); } } } } } addDependencyButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { SelectDependencyDialog dialog = new SelectDependencyDialog(Display.getDefault().getActiveShell(), filteredExpressions, ComparisonExpressionEditor.this.inputExpression.getReferencedElements()); dialog.open(); } }); }
From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java
License:Open Source License
private Control createSelectComposite(final Select widget) { final Composite mainComposite = new Composite(section, SWT.NONE); mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 0).create()); final Label itemsLabel = new Label(mainComposite, SWT.NONE); itemsLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create()); itemsLabel.setText(Messages.items);/* w w w. j a v a2 s .co m*/ final Composite itemComposite = new Composite(mainComposite, SWT.NONE); itemComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); itemComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); final TableViewer itemViewer = new TableViewer(itemComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); itemViewer.getTable() .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).create()); itemViewer.setContentProvider(new ArrayContentProvider()); final TableLayout layout = new TableLayout(); layout.addColumnData(new ColumnWeightData(100)); itemViewer.getTable().setLayout(layout); final TableViewerColumn inputNameColumn = new TableViewerColumn(itemViewer, SWT.FILL); inputNameColumn.getColumn().setText(Messages.input); inputNameColumn.setEditingSupport(new SelectItemEditingSupport(itemViewer, widget)); inputNameColumn.setLabelProvider(new ColumnLabelProvider()); context.bindValue(ViewersObservables.observeInput(itemViewer), EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.SELECT__ITEMS)); final Composite buttonComposite = new Composite(itemComposite, SWT.NONE); buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create()); buttonComposite .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create()); final Button addButton = new Button(buttonComposite, SWT.FLAT); addButton.setText(Messages.Add); addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String item = generateItem(widget); widget.getItems().add(item); itemViewer.editElement(item, 0); } }); final Button upButton = new Button(buttonComposite, SWT.FLAT); upButton.setText(Messages.up); upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); upButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement(); int i = widget.getItems().indexOf(selected); if (i > 0) { widget.getItems().move(i - 1, selected); itemViewer.refresh(); } } }); final Button downButton = new Button(buttonComposite, SWT.FLAT); downButton.setText(Messages.down); downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); downButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement(); int i = widget.getItems().indexOf(selected); if (i < widget.getItems().size() - 1) { widget.getItems().move(i + 1, selected); itemViewer.refresh(); } } }); final Button removeButton = new Button(buttonComposite, SWT.FLAT); removeButton.setText(Messages.remove); removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { widget.getItems().removeAll(((IStructuredSelection) itemViewer.getSelection()).toList()); itemViewer.refresh(); } }); return mainComposite; }
From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java
License:Open Source License
private Control createArrayComposite(final Array widget) { final Composite mainComposite = new Composite(section, SWT.NONE); mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 0).create()); final Label nbColLabel = new Label(mainComposite, SWT.NONE); nbColLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create()); nbColLabel.setText(Messages.nbColumn); final Combo columnCombo = new Combo(mainComposite, SWT.BORDER | SWT.READ_ONLY); columnCombo.setLayoutData(GridDataFactory.fillDefaults().create()); for (int i = 1; i < 11; i++) { columnCombo.add(String.valueOf(i)); }/*from w ww .ja v a 2 s. c o m*/ if (widget.getCols() == null) { widget.setCols(new BigInteger("1")); } UpdateValueStrategy targetToModel = new UpdateValueStrategy(); targetToModel.setConverter(new Converter(String.class, BigInteger.class) { @Override public Object convert(Object from) { return new BigInteger((String) from); } }); UpdateValueStrategy modelToTarget = new UpdateValueStrategy(); modelToTarget.setConverter(new Converter(BigInteger.class, String.class) { @Override public Object convert(Object from) { return String.valueOf(((BigInteger) from).intValue()); } }); context.bindValue(SWTObservables.observeText(columnCombo), EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.ARRAY__COLS), targetToModel, modelToTarget); final Label fixedColLabel = new Label(mainComposite, SWT.NONE); fixedColLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create()); final Button fixedColButton = new Button(mainComposite, SWT.CHECK); fixedColButton.setLayoutData(GridDataFactory.fillDefaults().create()); fixedColButton.setText(Messages.fixedColumn); context.bindValue(SWTObservables.observeSelection(fixedColButton), EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.ARRAY__FIXED_COLS)); final Label colHeadersLabel = new Label(mainComposite, SWT.NONE); colHeadersLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create()); colHeadersLabel.setText(Messages.columnHeaders); final Composite itemComposite = new Composite(mainComposite, SWT.NONE); itemComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); itemComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); final TableViewer itemViewer = new TableViewer(itemComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); itemViewer.getTable() .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).create()); itemViewer.setContentProvider(new ArrayContentProvider()); final TableLayout layout = new TableLayout(); layout.addColumnData(new ColumnWeightData(100)); itemViewer.getTable().setLayout(layout); final TableViewerColumn inputNameColumn = new TableViewerColumn(itemViewer, SWT.FILL); inputNameColumn.getColumn().setText(Messages.input); inputNameColumn.setEditingSupport(new CaptionEditingSupport(itemViewer, widget)); inputNameColumn.setLabelProvider(new ColumnLabelProvider()); context.bindValue(ViewersObservables.observeInput(itemViewer), EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.ARRAY__COLS_CAPTION)); final Composite buttonComposite = new Composite(itemComposite, SWT.NONE); buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create()); buttonComposite .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create()); final Button addButton = new Button(buttonComposite, SWT.FLAT); addButton.setText(Messages.Add); addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String item = generateCaption(widget); widget.getColsCaption().add(item); itemViewer.editElement(item, 0); } }); final Button upButton = new Button(buttonComposite, SWT.FLAT); upButton.setText(Messages.up); upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); upButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement(); int i = widget.getColsCaption().indexOf(selected); if (i > 0) { widget.getColsCaption().move(i - 1, selected); itemViewer.refresh(); } } }); final Button downButton = new Button(buttonComposite, SWT.FLAT); downButton.setText(Messages.down); downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); downButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement(); int i = widget.getColsCaption().indexOf(selected); if (i < widget.getColsCaption().size() - 1) { widget.getColsCaption().move(i + 1, selected); itemViewer.refresh(); } } }); final Button removeButton = new Button(buttonComposite, SWT.FLAT); removeButton.setText(Messages.remove); removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { widget.getColsCaption().removeAll(((IStructuredSelection) itemViewer.getSelection()).toList()); itemViewer.refresh(); } }); return mainComposite; }
From source file:org.bonitasoft.studio.connector.model.definition.dialog.SelectPageWidgetDialog.java
License:Open Source License
private Control createRadioGroupComposite(final RadioGroup widget) { final Composite mainComposite = new Composite(section, SWT.NONE); mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 0).create()); final Label orientationLabel = new Label(mainComposite, SWT.NONE); orientationLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create()); orientationLabel.setText(Messages.orientation); final ComboViewer orientationCombo = new ComboViewer(mainComposite, SWT.READ_ONLY | SWT.BORDER); orientationCombo.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); orientationCombo.setContentProvider(new ArrayContentProvider()); orientationCombo.setLabelProvider(new LabelProvider()); context.bindValue(ViewersObservables.observeInput(orientationCombo), PojoProperties.value(SelectPageWidgetDialog.class, "orientations").observe(this)); context.bindValue(ViewersObservables.observeSingleSelection(orientationCombo), EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.RADIO_GROUP__ORIENTATION)); final Label itemsLabel = new Label(mainComposite, SWT.NONE); itemsLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).create()); itemsLabel.setText(Messages.items);// w ww . ja va 2s . c o m final Composite itemComposite = new Composite(mainComposite, SWT.NONE); itemComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); itemComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create()); final TableViewer itemViewer = new TableViewer(itemComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); itemViewer.getTable() .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).create()); itemViewer.setContentProvider(new ArrayContentProvider()); final TableLayout layout = new TableLayout(); layout.addColumnData(new ColumnWeightData(100)); itemViewer.getTable().setLayout(layout); final TableViewerColumn inputNameColumn = new TableViewerColumn(itemViewer, SWT.FILL); inputNameColumn.getColumn().setText(Messages.input); inputNameColumn.setEditingSupport(new RadioGroupItemEditingSupport(itemViewer, widget)); inputNameColumn.setLabelProvider(new ColumnLabelProvider()); context.bindValue(ViewersObservables.observeInput(itemViewer), EMFObservables.observeValue(widget, ConnectorDefinitionPackage.Literals.RADIO_GROUP__CHOICES)); final Composite buttonComposite = new Composite(itemComposite, SWT.NONE); buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create()); buttonComposite .setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create()); final Button addButton = new Button(buttonComposite, SWT.FLAT); addButton.setText(Messages.Add); addButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String item = generateRadioChoice(widget); widget.getChoices().add(item); itemViewer.editElement(item, 0); } }); final Button upButton = new Button(buttonComposite, SWT.FLAT); upButton.setText(Messages.up); upButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); upButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement(); int i = widget.getChoices().indexOf(selected); if (i > 0) { widget.getChoices().move(i - 1, selected); itemViewer.refresh(); } } }); final Button downButton = new Button(buttonComposite, SWT.FLAT); downButton.setText(Messages.down); downButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); downButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { String selected = (String) ((IStructuredSelection) itemViewer.getSelection()).getFirstElement(); int i = widget.getChoices().indexOf(selected); if (i < widget.getChoices().size() - 1) { widget.getChoices().move(i + 1, selected); itemViewer.refresh(); } } }); final Button removeButton = new Button(buttonComposite, SWT.FLAT); removeButton.setText(Messages.remove); removeButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { widget.getChoices().removeAll(((IStructuredSelection) itemViewer.getSelection()).toList()); itemViewer.refresh(); } }); return mainComposite; }