Java Code Examples for org.eclipse.core.databinding.UpdateValueStrategy#setAfterGetValidator()

The following examples show how to use org.eclipse.core.databinding.UpdateValueStrategy#setAfterGetValidator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectJarsDialog.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
    Control control = super.createDialogArea(parent);

    UpdateValueStrategy selectionStartegy = new UpdateValueStrategy() ;
    selectionStartegy.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if( value == null){
                return ValidationStatus.error("Selection is empty") ;
            }
            return Status.OK_STATUS;
        }
    }) ;

    context.bindList(ViewersObservables.observeMultiSelection(tableViewer), PojoProperties.list(SelectJarsDialog.class,"selectedJars").observe(this)) ;
    context.bindValue(ViewersObservables.observeSingleSelection(tableViewer), PojoProperties.value(SelectJarsDialog.class,"selectedJar").observe(this), selectionStartegy, null) ;

    return control ;
}
 
Example 2
Source File: VersionGridPropertySectionContribution.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createControl(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, ExtensibleGridPropertySection page) {
    context = new EMFDataBindingContext();

    UpdateValueStrategy versionUpdate = new UpdateValueStrategy();
    versionUpdate.setAfterGetValidator(new EmptyInputValidator(Messages.GeneralSection_Version));
    versionUpdate.setBeforeSetValidator(new UTF8InputValidator(Messages.GeneralSection_Version));

    Text text = new Text(composite, GTKStyleHandler.removeBorderFlag(SWT.BORDER));
    text.setLayoutData(GridDataFactory.swtDefaults().hint(160, SWT.DEFAULT).grab(false, false).create());
    if (!GTKStyleHandler.isGTK3()) {
        widgetFactory.adapt(text, true, true);
    }
    text.setEnabled(false);
    
    context.bindValue(WidgetProperties.text(SWT.Modify).observe(text),
    	EMFEditObservables.observeValue(editingDomain, process, ProcessPackage.Literals.ABSTRACT_PROCESS__VERSION), 
    	versionUpdate, 
    	null);
}
 
Example 3
Source File: ManageConnectorJarDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	context = new DataBindingContext() ;
	Composite composite = (Composite) super.createDialogArea(parent);
	composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(15, 15).create());
	if(infoLabel != null){
		addLabel(composite);
	}
	
	createTree(composite);

	UpdateValueStrategy selectionStartegy = new UpdateValueStrategy() ;
	selectionStartegy.setAfterGetValidator(new IValidator() {

		@Override
		public IStatus validate(Object value) {
			if( value == null){
				return ValidationStatus.error("Selection is empty") ;
			}
			return Status.OK_STATUS;
		}
	}) ;

	context.bindSet(ViewersObservables.observeCheckedElements(languageViewer, IRepositoryFileStore.class.getName()), PojoProperties.set(ManageConnectorJarDialog.class,"selectedJars").observe(this)) ;


	return composite;
}
 
Example 4
Source File: CronEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createMinutesTab(TabFolder tablFolder) {
    final TabItem item = new TabItem(tablFolder, SWT.NONE);
    item.setText(Messages.minutes);
    final Composite minuteContent = new Composite(tablFolder, SWT.NONE);
    minuteContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    minuteContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(15, 10).create());

    final Label everyLabel = new Label(minuteContent, SWT.NONE);
    everyLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
    everyLabel.setText(Messages.every);

    final Text minuteText = new Text(minuteContent, SWT.BORDER | SWT.SINGLE);
    minuteText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create());

    UpdateValueStrategy strategy = new UpdateValueStrategy();
    strategy.setAfterGetValidator(dotValidator);
    strategy.setConverter(StringToNumberConverter.toInteger(true));
    strategy.setBeforeSetValidator(new FrequencyValidator());
    context.bindValue(SWTObservables.observeText(minuteText, SWT.Modify),
            PojoProperties.value("minuteFrequencyForMinute").observe(cronExpression), strategy, null);

    final Label minuteLabel = new Label(minuteContent, SWT.NONE);
    minuteLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    minuteLabel.setText(Messages.minuteLabel);

    item.setControl(minuteContent);
    cronExpression.setMode(item.getText());
}
 
Example 5
Source File: MoveDataWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public void createControl(Composite parent) {
	context = new DataBindingContext();
	Composite mainComposite = new Composite(parent, SWT.NONE);
	GridLayout gl = new GridLayout(1, false);
	mainComposite.setLayout(gl);
	
	new Label(mainComposite, SWT.NONE).setText(Messages.chooseTargetStepOrProcess);
	
	
	modelTree = new FilteredTree(mainComposite, SWT.BORDER | SWT.SINGLE, new PatternFilter(), true);
	modelTree.getViewer().setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
	modelTree.getViewer().setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
	DataAwareElementViewerFilter filter = new DataAwareElementViewerFilter(sourceContainer) ;
	modelTree.getViewer().setFilters(new ViewerFilter[]{filter,modelTree.getViewer().getFilters()[0]});
	modelTree.getViewer().setInput(sourceProcess);
	modelTree.getViewer().expandAll() ;

	UpdateValueStrategy selectionStrategy = new UpdateValueStrategy();
	selectionStrategy.setAfterGetValidator(new IValidator() {
		
		@Override
		public IStatus validate(Object value) {
		
			
			if(value==null){
				return ValidationStatus.error(Messages.dataMoveErrorTargetSelected);
			}
			if(!(value instanceof DataAware)){
				return ValidationStatus.error(Messages.datamoveErrorWrongTarget);
			}
			if(value.equals(sourceContainer)){
				return ValidationStatus.error(Messages.dataMoveErrorTargetCantBeSource);
			}
			return ValidationStatus.ok();
		}
	});
	context.bindValue(ViewersObservables.observeSingleSelection(modelTree.getViewer()), PojoProperties.value(MoveDataWizardPage.class, "selectedDataAwareElement").observe(this),selectionStrategy,null);
	
	WizardPageSupport.create(this, context);
	setControl(mainComposite);
}
 
Example 6
Source File: SamplePart.java    From codeexamples-eclipse with Eclipse Public License 1.0 4 votes vote down vote up
@PostConstruct
@SuppressWarnings("unchecked")
public void createPartControl(Composite parent) {
	// create the Person model with programming skills
	Person person = new Person();
	person.setName("John");
	person.setProgrammingSkills(new String[] { "Java", "JavaScript", "Groovy" });
	GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);
	Label programmingSkillsLabel = new Label(parent, SWT.NONE);
	programmingSkillsLabel.setText("Programming Skills");
	GridDataFactory.swtDefaults().applyTo(programmingSkillsLabel);
	Text programmingSkillsText = new Text(parent, SWT.BORDER);
	GridDataFactory.fillDefaults().grab(true, false).applyTo(programmingSkillsText);
	// Do the actual binding and conversion
	DataBindingContext dbc = new DataBindingContext();

	// define converters
	IConverter convertToStringArray = IConverter.create(String.class, String[].class,
			(o1) -> ((String) o1).split(","));
	IConverter convertToString = IConverter.create(String[].class, String.class, (o1) -> convert((String[]) o1));
	;

	// create the observables, which should be bound
	IObservableValue<Text> programmingSkillsTarget = WidgetProperties.text(SWT.Modify)
			.observe(programmingSkillsText);
	IObservableValue<Person> programmingSkillsModel = BeanProperties.value("programmingSkills").observe(person);

	UpdateValueStrategy updateStrategy = UpdateValueStrategy.create(convertToStringArray);
	updateStrategy.setAfterGetValidator((o1) -> {
		String s = (String) o1;
		if (!s.contains("Perl")) {
			return ValidationStatus.ok();
		}
		return ValidationStatus.error("Perl is not a programming language");

	});

	// bind observables together with the appropriate UpdateValueStrategies
	dbc.bindValue(programmingSkillsTarget, programmingSkillsModel,
			updateStrategy,
			UpdateValueStrategy.create(convertToString));

	// button to check the data model
	Button button = new Button(parent, SWT.PUSH);
	button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
	button.setText("Show data model");
	button.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			for (String string : person.getProgrammingSkills()) {
				System.out.println(string);

			}
		}
	});

}
 
Example 7
Source File: CronEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createHourlyTab(TabFolder tablFolder) {
    final TabItem item = new TabItem(tablFolder, SWT.NONE);
    item.setText(Messages.hourly);

    final Composite hourlyContent = new Composite(tablFolder, SWT.NONE);
    hourlyContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    hourlyContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).create());

    final Button everyRadio = new Button(hourlyContent, SWT.RADIO);
    everyRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    everyRadio.setText(Messages.every);

    context.bindValue(SWTObservables.observeSelection(everyRadio),
            PojoProperties.value("useEveryHour").observe(cronExpression));

    final Composite everyComposite = new Composite(hourlyContent, SWT.NONE);
    everyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    everyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final Text minuteText = new Text(everyComposite, SWT.BORDER | SWT.SINGLE);
    minuteText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create());

    UpdateValueStrategy hourFrequencyStrategy = new UpdateValueStrategy();
    hourFrequencyStrategy.setAfterGetValidator(dotValidator);
    hourFrequencyStrategy.setConverter(StringToNumberConverter.toInteger(true));
    hourFrequencyStrategy.setBeforeSetValidator(new FrequencyValidator());

    context.bindValue(SWTObservables.observeText(minuteText, SWT.Modify),
            PojoProperties.value("hourFrequencyForHourly").observe(cronExpression), hourFrequencyStrategy, null);

    final Label minuteLabel = new Label(everyComposite, SWT.NONE);
    minuteLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    minuteLabel.setText(Messages.hourLabel);

    final Button atRadio = new Button(hourlyContent, SWT.RADIO);
    atRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    atRadio.setText(Messages.at);

    final Composite atComposite = new Composite(hourlyContent, SWT.NONE);
    atComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    atComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(0, 0).create());

    final Combo hourCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER);
    hourCombo.setItems(HOURS_IN_DAY);

    UpdateValueStrategy hourStrategy = new UpdateValueStrategy();
    hourStrategy.setConverter(StringToNumberConverter.toInteger(true));
    UpdateValueStrategy hourStrategy2 = new UpdateValueStrategy();

    NumberFormat formatter = new DecimalFormat("#00");
    hourStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true));
    context.bindValue(SWTObservables.observeText(hourCombo),
            PojoProperties.value("atHour").observe(cronExpression), hourStrategy, hourStrategy2);

    final Combo minuteCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER);
    minuteCombo.setItems(MINUTES_IN_HOURS);

    UpdateValueStrategy minuteStrategy = new UpdateValueStrategy();
    minuteStrategy.setConverter(StringToNumberConverter.toInteger(true));
    UpdateValueStrategy minuteStrategy2 = new UpdateValueStrategy();
    minuteStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true));
    context.bindValue(SWTObservables.observeText(minuteCombo),
            PojoProperties.value("atMinute").observe(cronExpression), minuteStrategy, minuteStrategy2);

    final Combo secondCombo = new Combo(atComposite, SWT.READ_ONLY | SWT.BORDER);
    secondCombo.setItems(MINUTES_IN_HOURS);

    final IObservableValue secondObservable = PojoProperties.value("atSecond").observe(cronExpression);
    UpdateValueStrategy secondStrategy = new UpdateValueStrategy();
    secondStrategy.setConverter(StringToNumberConverter.toInteger(true));
    UpdateValueStrategy secondStrategy2 = new UpdateValueStrategy();
    secondStrategy2.setConverter(NumberToStringConverter.fromInteger(formatter, true));
    context.bindValue(SWTObservables.observeText(secondCombo), secondObservable, secondStrategy, secondStrategy2);

    item.setControl(hourlyContent);
}
 
Example 8
Source File: CronEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createDailyTab(TabFolder tablFolder) {
    final TabItem item = new TabItem(tablFolder, SWT.NONE);
    item.setText(Messages.daily);

    final Composite dailyContent = new Composite(tablFolder, SWT.NONE);
    dailyContent.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    dailyContent.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 10).create());

    final Button everyRadio = new Button(dailyContent, SWT.RADIO);
    everyRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    everyRadio.setText(Messages.every);

    context.bindValue(SWTObservables.observeSelection(everyRadio),
            PojoProperties.value("useEveryDayForDaily").observe(cronExpression));

    final Composite everyComposite = new Composite(dailyContent, SWT.NONE);
    everyComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(-65, 0).create());
    everyComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).create());

    final Text dayText = new Text(everyComposite, SWT.BORDER | SWT.SINGLE);
    dayText.setLayoutData(GridDataFactory.fillDefaults().hint(70, SWT.DEFAULT).create());

    UpdateValueStrategy dayFrequencyStrategy = new UpdateValueStrategy();
    dayFrequencyStrategy.setAfterGetValidator(dotValidator);
    dayFrequencyStrategy.setConverter(StringToNumberConverter.toInteger(true));
    dayFrequencyStrategy.setBeforeSetValidator(new FrequencyValidator());
    context.bindValue(SWTObservables.observeText(dayText, SWT.Modify),
            PojoProperties.value("dayFrequencyForDaily").observe(cronExpression), dayFrequencyStrategy, null);

    final Label dayLabel = new Label(everyComposite, SWT.NONE);
    dayLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    dayLabel.setText(Messages.dayLabel);

    final Button everyWeekDayRadio = new Button(dailyContent, SWT.RADIO);
    everyWeekDayRadio.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    everyWeekDayRadio.setText(Messages.everyWeekDay);

    final Label filler = new Label(dailyContent, SWT.NONE);
    filler.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final IObservableValue hourObservable = PojoProperties.value("atHourInDay").observe(cronExpression);
    final IObservableValue minuteObservable = PojoProperties.value("atMinuteInDay").observe(cronExpression);
    final IObservableValue secondObservable = PojoProperties.value("atSecondInDay").observe(cronExpression);
    createStartTimeComposite(dailyContent, hourObservable, minuteObservable, secondObservable);

    item.setControl(dailyContent);
}
 
Example 9
Source File: ExportRepositoryWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createDestination(final Composite group) {
    final Label destPath = new Label(group, SWT.NONE);
    destPath.setText(Messages.destinationPath + " *");
    destPath.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    // destination name entry field
    destinationCombo = new Combo(group, SWT.SINGLE | SWT.BORDER);
    destinationCombo
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).create());

    restoreWidgetValues();
    final UpdateValueStrategy pathStrategy = new UpdateValueStrategy();
    pathStrategy.setAfterGetValidator(new EmptyInputValidator(Messages.destinationPath));
    pathStrategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object input) {
            if (!isZip) {
                if (!new File(input.toString()).isDirectory()) {
                    return ValidationStatus.error(Messages.destinationPathMustBeADirectory);
                }
            } else {
                if (!input.toString().endsWith(".bos")) {
                    return ValidationStatus.error(Messages.invalidFileFormat);
                }
                if (new File(input.toString()).isDirectory()) {
                    return ValidationStatus.error(Messages.invalidFileFormat);
                }
            }
            return ValidationStatus.ok();
        }
    });

    dbc.bindValue(SWTObservables.observeText(destinationCombo),
            PojoProperties.value(ExportRepositoryWizardPage.class, "detinationPath").observe(this),
            pathStrategy, null);

    // destination browse button
    destinationBrowseButton = new Button(group, SWT.PUSH);
    destinationBrowseButton.setText(Messages.browse);
    destinationBrowseButton.setLayoutData(GridDataFactory.fillDefaults().hint(85, SWT.DEFAULT).create());
    destinationBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            handleDestinationBrowseButtonPressed();
        }
    });
}
 
Example 10
Source File: ExportBusinessDataModelWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createDestinationTextAndLabel(Composite mainComposite,
        DataBindingContext context) {
    final Composite composite = new Composite(mainComposite, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(0, 0).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final Label destinationLabel = new Label(composite, SWT.NONE);
    destinationLabel.setText(Messages.destinationPath + " *");
    destinationLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).grab(false, false).create());

    final Text destinationText = new Text(composite, SWT.BORDER);
    destinationText.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());

    UpdateValueStrategy targetToModelStrategy = new UpdateValueStrategy();
    targetToModelStrategy.setAfterGetValidator(new EmptyInputValidator(Messages.destinationPath));
    targetToModelStrategy.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            return validateFilePath(value);
        }
    });
    context.bindValue(SWTObservables.observeText(destinationText, SWT.Modify), PojoObservables.observeValue(this, "destinationPath"),
            targetToModelStrategy, null);

    final Button browseButton = new Button(composite, SWT.PUSH);
    browseButton.setText(Messages.browse);
    browseButton.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).create());
    browseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog directoryDialog = new DirectoryDialog(Display.getDefault().getActiveShell(), SWT.SAVE);
            String path = directoryDialog.open();
            if (path != null) {
                destinationText.setText(path);
            }
        }
    });

}
 
Example 11
Source File: GroovyScriptConfigurationWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private UpdateValueStrategy mandatoryScriptContentStrategy(final String fieldLabel) {
    final UpdateValueStrategy startegy = new UpdateValueStrategy();
    startegy.setAfterGetValidator(new EmptyInputValidator(fieldLabel));
    return startegy;
}
 
Example 12
Source File: ExpressionCollectionViewer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public void setSelection(final AbstractExpression input) {
    if (validationContext != null) {
        if (bindValue != null) {
            validationContext.removeBinding(bindValue);
            bindValue.dispose();
            bindValue = null;
        }
        if (expressionEditor != null) {
            expressionEditor.setMandatoryField(null, validationContext);
        }
    }

    if (input instanceof Expression) {
        initializeTableOrExpression(false);
        expressionEditor.setMandatoryField(mandatoryLabel, validationContext);
        expressionEditor.setSelection(new StructuredSelection(input));
    } else if (input instanceof ListExpression
            || input instanceof TableExpression) {
        if (expressionEditor != null) {
            expressionEditor.setSelection(new StructuredSelection(ExpressionFactory.eINSTANCE.createExpression()));
        }
        initializeTableOrExpression(true);
        viewer.setInput(input);
        if (input instanceof TableExpression) {
            if (!((TableExpression) input).getExpressions().isEmpty()) {
                updateColumns();
            }
        }
        if (validationContext != null) {
            IObservableValue observeValue = null;
            if (input instanceof ListExpression) {
                observeValue = EMFObservables.observeValue(input,
                        ExpressionPackage.Literals.LIST_EXPRESSION__EXPRESSIONS);
            } else {
                observeValue = EMFObservables.observeValue(input,
                        ExpressionPackage.Literals.TABLE_EXPRESSION__EXPRESSIONS);
            }
            final UpdateValueStrategy strategy = new UpdateValueStrategy();
            strategy.setAfterGetValidator(new IValidator() {

                @Override
                public IStatus validate(final Object value) {
                    if (isTableMode()) {
                        final AbstractExpression expression = getValue();
                        if (expression instanceof ListExpression) {
                            if (((ListExpression) expression).getExpressions() == null
                                    || ((ListExpression) expression).getExpressions().isEmpty()) {
                                return ValidationStatus
                                        .error(Messages.bind(Messages.AtLeastOneRowShouldBeAddedFor, mandatoryLabel));
                            }
                        }
                        if (expression instanceof TableExpression) {
                            if (((TableExpression) expression).getExpressions() == null
                                    || ((TableExpression) expression).getExpressions().isEmpty()) {
                                return ValidationStatus
                                        .error(Messages.bind(Messages.AtLeastOneRowShouldBeAddedFor, mandatoryLabel));
                            }
                        }
                    }
                    return ValidationStatus.ok();
                }
            });
            bindValue = validationContext.bindValue(new WritableValue(), observeValue, strategy, strategy);
        }
    }
}
 
Example 13
Source File: DocumentWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createLocalFileComposite(final Composite parent, final EMFDataBindingContext emfDataBindingContext) {
    internalCompo = new Composite(parent, SWT.NONE);
    internalCompo.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(5, 5).create());
    internalCompo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    final Label documentBrowserLabel = new Label(internalCompo, SWT.NONE);
    documentBrowserLabel.setLayoutData(GridDataFactory.swtDefaults().create());
    documentBrowserLabel.setText(mandatoryFieldLabel(Messages.documentInternalLabel));

    final Text documentTextId = new Text(internalCompo, SWT.BORDER);
    documentTextId.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
            .grab(true, false).indent(10, 0).create());

    final UpdateValueStrategy uvsInternal = new UpdateValueStrategy();
    uvsInternal.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {
            return validateInternalDocumentId(value);
        }

    });

    ControlDecorationSupport.create(emfDataBindingContext.bindValue(
            SWTObservables.observeText(documentTextId, SWT.Modify),
            EMFObservables.observeValue(document,
                    ProcessPackage.Literals.DOCUMENT__DEFAULT_VALUE_ID_OF_DOCUMENT_STORE),
            uvsInternal, null), SWT.LEFT);

    final Button browseButton = new Button(internalCompo, SWT.FLAT);
    browseButton.setText(Messages.Browse);
    browseButton.setLayoutData(GridDataFactory.swtDefaults().create());
    browseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final SelectResourceDialog selectDocumentInBonitaStudioRepository = new SelectResourceDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow());
            if (IDialogConstants.OK_ID == selectDocumentInBonitaStudioRepository.open()) {
                documentTextId.setText(selectDocumentInBonitaStudioRepository.getSelectedDocument().getDisplayName());
            }
        }
    });
}
 
Example 14
Source File: UsersWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected Control createCustomControl(final Composite parent) {

        final Composite otherInfoComposite = new Composite(parent, SWT.NONE);
        otherInfoComposite
                .setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).equalWidth(false).create());
        otherInfoComposite
                .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, SWT.DEFAULT).create());

        final User selectedUser = (User) userSingleSelectionObservable.getValue();
        if (selectedUser != null) {

            if (selectedUser.getCustomUserInfoValues() == null) {
                selectedUser.setCustomUserInfoValues(OrganizationFactory.eINSTANCE.createCustomUserInfoValuesType());
            }

            final IObservableValue customUserInfoValuesValue = EMFObservables.observeDetailValue(Realm.getDefault(),
                    userSingleSelectionObservable,
                    OrganizationPackage.Literals.USER__CUSTOM_USER_INFO_VALUES);

            final IObservableList customUserInfoListValue = EMFObservables.observeDetailList(Realm.getDefault(),
                    customUserInfoValuesValue,
                    OrganizationPackage.Literals.CUSTOM_USER_INFO_VALUES_TYPE__CUSTOM_USER_INFO_VALUE);

            final EList<CustomUserInfoValue> customUserInfoValueList = sortCustomUserInfoValues(selectedUser);
            for (final CustomUserInfoValue infoValue : customUserInfoValueList) {

                final UpdateValueStrategy strategy = new UpdateValueStrategy();
                strategy.setAfterGetValidator(new IValidator() {

                    @Override
                    public IStatus validate(final Object arg0) {
                        final String value = (String) arg0;
                        if (value.length() > CUSTOM_USER_DEFINITION_VALUE_LIMIT_SIZE) {
                            return ValidationStatus.error(Messages.customUserInfoValueLimitSize);
                        }
                        return ValidationStatus.ok();
                    }
                });

                final Label labelName = new Label(otherInfoComposite, SWT.LEFT | SWT.WRAP);
                labelName.setLayoutData(GridDataFactory.fillDefaults().hint(150, SWT.DEFAULT).create());
                labelName.setText(infoValue.getName());

                final Text textValue = new Text(otherInfoComposite, SWT.BORDER);
                textValue.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

                context.bindValue(SWTObservables.observeText(textValue, SWT.Modify),
                        EMFObservables.observeValue(infoValue,
                                OrganizationPackage.Literals.CUSTOM_USER_INFO_VALUE__VALUE),
                        strategy, null);

            }
        }

        // LINK
        final Link addInfoLink = new Link(otherInfoComposite, SWT.NONE);
        addInfoLink.setText("<A>" + Messages.customUserInfoOtherTabLink + "</A>");
        addInfoLink.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                tabFolder.setSelection(infoTab);
                getViewer().refresh(infoTab);
            }

        });
        addInfoLink.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, false).create());

        return otherInfoComposite;
    }
 
Example 15
Source File: UsersWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createUserNameField(final Composite rightColumnComposite) {
    final Label userName = new Label(rightColumnComposite, SWT.NONE);
    userName.setLayoutData(GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).create());
    userName.setText(Messages.userName + " *");

    final Text usernameText = new Text(rightColumnComposite, SWT.BORDER);
    usernameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(5, 0).create());
    usernameText.setMessage(Messages.userNameHint);

    final UpdateValueStrategy stategy = new UpdateValueStrategy();
    stategy.setConverter(new Converter(String.class, String.class) {

        @Override
        public Object convert(final Object from) {
            if (from != null && userSingleSelectionObservable != null
                    && userSingleSelectionObservable.getValue() != null) {
                final User user = (User) userSingleSelectionObservable.getValue();
                updateDelegueeMembership(user.getUserName(), from.toString());
            }
            return from;
        }
    });
    stategy.setAfterGetValidator(new IValidator() {

        @Override
        public IStatus validate(final Object value) {

            if (isNotUserSelected()) {
                return Status.OK_STATUS;
            }

            if (value.toString().isEmpty()) {
                return ValidationStatus.error(Messages.userNameIsEmpty);
            }

            if (value.toString().length() > NAME_SIZE) {
                return ValidationStatus.error(Messages.nameLimitSize);
            }

            final User currentUser = (User) userSingleSelectionObservable.getValue();
            for (final User u : userList) {
                if (!u.equals(currentUser)) {
                    if (u.getUserName().equals(value)) {
                        return ValidationStatus.error(Messages.userNameAlreadyExists);
                    }
                }
            }
            return Status.OK_STATUS;
        }
    });

    final IObservableValue userNameValue = EMFObservables.observeDetailValue(Realm.getDefault(),
            userSingleSelectionObservable,
            OrganizationPackage.Literals.USER__USER_NAME);
    final Binding binding = context.bindValue(SWTObservables.observeText(usernameText, SWT.Modify), userNameValue,
            stategy, null);
    ControlDecorationSupport.create(binding, SWT.LEFT, rightColumnComposite, new ControlDecorationUpdater() {

        @Override
        protected void update(final ControlDecoration decoration, final IStatus status) {
            if (userSingleSelectionObservable.getValue() != null) {
                super.update(decoration, status);
            }
        }
    });

    userNameValue.addValueChangeListener(new IValueChangeListener() {

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            handleUserNameChange(event);
        }

    });
}
 
Example 16
Source File: CustomerUserInformationDefinitionDescriptionEditingSupport.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Binding createBinding(IObservableValue target, IObservableValue model) {
       UpdateValueStrategy targetToModel = new UpdateValueStrategy();
       targetToModel.setAfterGetValidator(new CustomerUserInformationDefinitionDescriptionValidator());
       return dbc.bindValue(target, model, targetToModel, null);
   }
 
Example 17
Source File: CustomUserInformationDefinitionNameEditingSupport.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Binding createBinding(final IObservableValue target, final IObservableValue model) {
    final UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setAfterGetValidator(new CustomerUserInformationDefinitionNameValidator(organization, viewer));
    return dbc.bindValue(target, model, targetToModel, null);
}