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 Control createInputExpressionComposite( Section section, TabbedPropertySheetWidgetFactory widgetFactory) { final Composite client = widgetFactory.createComposite(section); client.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); client.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create()); inputExpressionViewer = new ExpressionViewer( client, SWT.BORDER, widgetFactory, editingDomain, FormPackage.Literals.WIDGET__INPUT_EXPRESSION); inputExpressionViewer.addFilter( new AvailableExpressionTypeFilter( new String[] { ExpressionConstants.VARIABLE_TYPE, ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.DOCUMENT_REF_TYPE, ExpressionConstants.PARAMETER_TYPE })); inputExpressionViewer.setMessage(getInputExpressionHint(), IStatus.INFO); inputExpressionViewer .getControl() .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); return client; }
private void createNameAndDescription(Composite composite) { Label nameLabel = new Label(composite, SWT.NONE); nameLabel.setText(Messages.dataNameLabel); final Text labelText = new Text(composite, SWT.BORDER); labelText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); // Add an validator so that age can only be a number IValidator validator = new IValidator() { Set<String> existingDataNames = null; @Override public IStatus validate(Object arg0) { if (existingDataNames == null) { existingDataNames = new HashSet<String>(); if (element != null) { for (SimulationData simuData : element.getSimulationData()) { existingDataNames.add(simuData.getName()); } } } if (existingDataNames.contains(labelText.getText())) { return ValidationStatus.error("Data name already exists."); } return ValidationStatus.ok(); } }; UpdateValueStrategy strategy = new UpdateValueStrategy(); strategy.setBeforeSetValidator(validator); Binding bindingDataName = context.bindValue( SWTObservables.observeText(labelText, SWT.Modify), PojoObservables.observeValue(this, "dataName"), strategy, null); ControlDecorationSupport.create(bindingDataName, SWT.TOP | SWT.LEFT); // labelText.addModifyListener(updateButtonModifyListener) ; Label isExpressionLabel = new Label(composite, SWT.NONE); isExpressionLabel.setText(Messages.BasedOn); Composite radioBasedComposite = new Composite(composite, SWT.NONE); radioBasedComposite.setLayout(new GridLayout(2, true)); isExpressionBased = new Button(radioBasedComposite, SWT.RADIO); isExpressionBased.setText(Messages.Expression); isExpressionBased.setSelection(expressionBased); isOtherBased = new Button(radioBasedComposite, SWT.RADIO); isOtherBased.setSelection(!expressionBased); isOtherBased.setText(Messages.AddSimulationDataWizardPage_probability); context.bindValue( SWTObservables.observeSelection(isExpressionBased), PojoObservables.observeValue(this, "expressionBased")); context.bindValue( SWTObservables.observeSelection(isOtherBased), PojoObservables.observeValue(this, "expressionBased"), new UpdateValueStrategy() .setConverter( new Converter(Boolean.class, Boolean.class) { @Override public Object convert(Object fromObject) { return !(Boolean) fromObject; } }), new UpdateValueStrategy() .setConverter( new Converter(Boolean.class, Boolean.class) { @Override public Object convert(Object fromObject) { return !(Boolean) fromObject; } })); Label expressionLabel = new Label(composite, SWT.NONE); expressionLabel.setText(Messages.Expression); ExpressionViewer expressionViewer = new ExpressionViewer(composite, SWT.BORDER, null); // FIXME: Expressionviewer expressionViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); if (element != null) { expressionViewer.setInput(element); } else { expressionViewer.setInput(data.eContainer()); } expressionViewer.addFilter( new AvailableExpressionTypeFilter( new String[] { ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE, ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.SIMULATION_VARIABLE_TYPE })); expressionViewer.setSelection(new StructuredSelection(dataExpression)); context.bindValue( SWTObservables.observeVisible(expressionLabel), SWTObservables.observeSelection(isExpressionBased)); context.bindValue( SWTObservables.observeVisible(expressionViewer.getControl()), SWTObservables.observeSelection(isExpressionBased)); isOtherBased.addSelectionListener(updateButtonSelectionListener); isExpressionBased.addSelectionListener(updateButtonSelectionListener); }