List of usage examples for org.eclipse.jface.databinding.swt SWTObservables observeText
@Deprecated public static ISWTObservableValue observeText(Control control, int event)
control
. From source file:com.netxforge.netxstudio.screens.f4.AbstractFileBasedMapping.java
License:Open Source License
protected void initGeneralBinding(EMFDataBindingContext context) { IObservableValue intervalObservableValue = SWTObservables.observeText(txtInterval, SWT.Modify); IEMFValueProperty intervalHintProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING__INTERVAL_HINT); context.bindValue(intervalObservableValue, intervalHintProperty.observe(mapping)); IObservableValue filePatternObservable = SWTObservables.observeText(this.txtFilePattern, SWT.Modify); IEMFValueProperty filePatternProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.METRIC_SOURCE__FILTER_PATTERN); context.bindValue(filePatternObservable, filePatternProperty.observe(metricSource)); }
From source file:com.netxforge.netxstudio.screens.f4.AbstractFileBasedMapping.java
License:Open Source License
protected void initHeaderMappingBinding(EMFDataBindingContext context) { // HEADER MAPPING COLUMN setHeaderMappingEnabledState();//from w w w . jav a2 s . c o m setHeaderMappingStateVisible(); // header row mapping. IObservableValue headerRowObservableValue = SWTObservables.observeText(txtFirstHeaderRow, SWT.Modify); IEMFValueProperty headerRowProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING__HEADER_ROW); context.bindValue(headerRowObservableValue, headerRowProperty.observe(mapping), null, null); // header columns mapping. { ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); this.tblViewerHeaderColumnMapping.setContentProvider(listContentProvider); IObservableSet set = listContentProvider.getKnownElements(); List<IObservableMap> mapList = Lists.newArrayList(); mapList.add( EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__METRIC_REF)) .observeDetail(set)); mapList.add( EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__VALUE_KIND)) .observeDetail(set)); mapList.add(EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__FORMAT)) .observeDetail(set)); mapList.add(EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.IDENTIFIER_DATA_KIND__OBJECT_PROPERTY)) .observeDetail(set)); mapList.add(EMFEditProperties .value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING_COLUMN__COLUMN) .observeDetail(set)); IObservableMap[] map = new IObservableMap[mapList.size()]; mapList.toArray(map); tblViewerHeaderColumnMapping.setLabelProvider(new ColumnObservableMapLabelProvider(map)); IEMFListProperty l = EMFEditProperties.list(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING__HEADER_MAPPING_COLUMNS); IObservableList dataColumnMappingObservableList = l.observe(mapping); dataColumnMappingObservableList.addChangeListener(new IChangeListener() { public void handleChange(ChangeEvent event) { // We have a special change listener, to know if the // header mapping visual // can be disabled. setHeaderMappingEnabledState(); setHeaderMappingStateVisible(); } }); // obm.addObservable(dataColumnMappingObservableList); tblViewerHeaderColumnMapping.setInput(dataColumnMappingObservableList); } }
From source file:com.netxforge.netxstudio.screens.f4.AbstractFileBasedMapping.java
License:Open Source License
protected void initDataMappingBinding(EMFDataBindingContext context) { // DATA MAPPING COLUMN // data row mapping IObservableValue firstDataRowObservableValue = SWTObservables.observeText(txtFirstDataRow, SWT.Modify); IEMFValueProperty firstDataRowProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING__FIRST_DATA_ROW); context.bindValue(firstDataRowObservableValue, firstDataRowProperty.observe(mapping), null, null); // data columns mapping. {//from ww w . j a va 2 s .c o m ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); this.tblViewerDataColumnMapping.setContentProvider(listContentProvider); IObservableSet set = listContentProvider.getKnownElements(); List<IObservableMap> mapList = Lists.newArrayList(); mapList.add( EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__METRIC_REF)) .observeDetail(set)); mapList.add( EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__KIND_HINT)) .observeDetail(set)); mapList.add( EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__VALUE_KIND)) .observeDetail(set)); mapList.add(EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__FORMAT)) .observeDetail(set)); mapList.add(EMFEditProperties .value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.IDENTIFIER_DATA_KIND__OBJECT_PROPERTY)) .observeDetail(set)); mapList.add(EMFEditProperties .value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING_COLUMN__COLUMN) .observeDetail(set)); IObservableMap[] map = new IObservableMap[mapList.size()]; mapList.toArray(map); this.tblViewerDataColumnMapping.setLabelProvider(new ColumnObservableMapLabelProvider(map)); IEMFListProperty l = EMFEditProperties.list(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING__DATA_MAPPING_COLUMNS); IObservableList dataColumnMappingObservableList = l.observe(mapping); this.tblViewerDataColumnMapping.setInput(dataColumnMappingObservableList); } IViewerObservableValue observeSingleSelection = ViewersObservables .observeSingleSelection(tblViewerDataColumnMapping); ISWTObservableValue observeEnabled = SWTObservables.observeEnabled(dataMappingUpButton); context.bindValue(observeSingleSelection, observeEnabled, new UpdateValueStrategy() { @Override protected IStatus doSet(IObservableValue observableValue, Object value) { if (value instanceof MappingColumn) { // Find the index of our object on the parent @SuppressWarnings("unchecked") List<MappingColumn> dataMappingColumns = (List<MappingColumn>) ((MappingColumn) value) .eContainer().eGet(MetricsPackage.Literals.MAPPING__DATA_MAPPING_COLUMNS); int indexOf = dataMappingColumns.indexOf(value); DataKind dataType = ((MappingColumn) value).getDataType(); if (dataType instanceof IdentifierDataKind && indexOf > 0) { return super.doSet(observableValue, true); } } return super.doSet(observableValue, false); } }, null); ISWTObservableValue observeEnabledDown = SWTObservables.observeEnabled(dataMappingDownButton); context.bindValue(observeSingleSelection, observeEnabledDown, new UpdateValueStrategy() { @Override protected IStatus doSet(IObservableValue observableValue, Object value) { if (value instanceof MappingColumn) { // Find the index of our object on the parent @SuppressWarnings("unchecked") List<MappingColumn> dataMappingColumns = (List<MappingColumn>) ((MappingColumn) value) .eContainer().eGet(MetricsPackage.Literals.MAPPING__DATA_MAPPING_COLUMNS); int indexOf = dataMappingColumns.indexOf(value); DataKind dataType = ((MappingColumn) value).getDataType(); if (dataType instanceof IdentifierDataKind && indexOf < dataMappingColumns.size() - 1) { return super.doSet(observableValue, true); } } return super.doSet(observableValue, false); } }, null); }
From source file:com.netxforge.netxstudio.screens.f4.MappingStatistics.java
License:Open Source License
public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext bindingContext = new EMFDataBindingContext(); ObservableListTreeContentProvider treeContentProvider = new ObservableListTreeContentProvider( new IObservableFactory() { private IEMFListProperty subStatisticsObservableProperty = EMFEditProperties.list( editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING_STATISTIC__SUB_STATISTICS); public IObservable createObservable(Object target) { IObservable ol = null; if (target instanceof IObservableList) { ol = (IObservable) target; } else if (target instanceof MappingStatistic) { ol = subStatisticsObservableProperty.observe(target); }//ww w.j a v a2 s . c o m return ol; } }, new TreeStructureAdvisor() { @Override public Object getParent(Object element) { if (element instanceof EObject) { EObject eo = (EObject) element; if (eo.eContainer() != null) { return eo.eContainer(); } } return null; } @Override public Boolean hasChildren(Object element) { if (element instanceof MappingStatistic) { return ((MappingStatistic) element).getSubStatistics().size() > 0 ? Boolean.TRUE : null; } return super.hasChildren(element); } }); statisticsTreeViewer.setContentProvider(treeContentProvider); IObservableMap[] observeMaps = EMFObservables.observeMaps(treeContentProvider.getKnownElements(), new EStructuralFeature[] { MetricsPackage.Literals.MAPPING_STATISTIC__MESSAGE }); statisticsTreeViewer.setLabelProvider(new StatisticObservableMapLabelProvider(observeMaps)); // Cool, observer the whole resource. IEMFListProperty l = EMFProperties.list(MetricsPackage.Literals.METRIC_SOURCE__STATISTICS); IObservableList metricSourceObservableList = l.observe(metricSource); statisticsTreeViewer.setInput(metricSourceObservableList); /** * Set a comparator to sort our columns, only sort the objects of type * */ statisticsTreeViewer.setComparator(new ViewerComparator() { /* * (non-Javadoc) * * @see * org.eclipse.jface.viewers.ViewerComparator#category(java.lang * .Object) */ @Override public int category(Object element) { // Set categories for our objects, only interrested in Service // flows for now. if (element instanceof MappingStatistic) return 1; return super.category(element); } /* * (non-Javadoc) * * @see * org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse * .jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ @Override public int compare(Viewer viewer, Object e1, Object e2) { int cat1 = category(e1); int cat2 = category(e2); if (cat1 != cat2) { return cat1 - cat2; } if (e1 instanceof MappingStatistic && e2 instanceof MappingStatistic) { MappingStatistic ms1 = (MappingStatistic) e1; MappingStatistic ms2 = (MappingStatistic) e2; if (ms1.eIsSet(MetricsPackage.Literals.MAPPING_STATISTIC__MAPPING_DURATION) && ms2.eIsSet(MetricsPackage.Literals.MAPPING_STATISTIC__MAPPING_DURATION)) { return ms2.getMappingDuration().getBegin().compare(ms1.getMappingDuration().getBegin()); } } return 0; // Do not compare other types. // return super.compare(viewer, e1, e2); } }); final IObservableValue selectionObservable = ViewerProperties.singleSelection() .observe(statisticsTreeViewer); // Observables for a single selection. IObservableValue messageObservable = SWTObservables.observeText(this.txtMessage, SWT.None); IObservableValue totalRecordsObservable = SWTObservables.observeText(this.txtTotalRecords, SWT.None); IObservableValue startTimeObservable = SWTObservables.observeText(this.txtStartDateTime, SWT.None); IObservableValue endTimeObservable = SWTObservables.observeText(this.txtEndDateTime, SWT.None); IObservableValue metricStartTimeObservable = SWTObservables.observeText(this.txtMetricStartDateTime, SWT.None); IObservableValue metricEndTimeObservable = SWTObservables.observeText(this.txtMetricEndDateTime, SWT.None); IObservableValue totalExpectedValuesObservable = SWTObservables.observeText(this.txtTotalValues, SWT.None); IObservableValue totalFailedValuesObservable = SWTObservables.observeText(this.txtTotalFailedValues, SWT.None); IEMFValueProperty messageProperty = EMFProperties.value(MetricsPackage.Literals.MAPPING_STATISTIC__MESSAGE); final IEMFValueProperty totalRecordsProperty = EMFProperties .value(MetricsPackage.Literals.MAPPING_STATISTIC__TOTAL_RECORDS); IEMFValueProperty startDateTimeProperty = EMFProperties .value(FeaturePath.fromList(MetricsPackage.Literals.MAPPING_STATISTIC__MAPPING_DURATION, GenericsPackage.Literals.DATE_TIME_RANGE__BEGIN)); IEMFValueProperty endDateTimeProperty = EMFProperties .value(FeaturePath.fromList(MetricsPackage.Literals.MAPPING_STATISTIC__MAPPING_DURATION, GenericsPackage.Literals.DATE_TIME_RANGE__END)); IEMFValueProperty metricStartDateTimeProperty = EMFProperties .value(FeaturePath.fromList(MetricsPackage.Literals.MAPPING_STATISTIC__PERIOD_ESTIMATE, GenericsPackage.Literals.DATE_TIME_RANGE__BEGIN)); IEMFValueProperty metricEndDateTimeProperty = EMFProperties .value(FeaturePath.fromList(MetricsPackage.Literals.MAPPING_STATISTIC__PERIOD_ESTIMATE, GenericsPackage.Literals.DATE_TIME_RANGE__END)); ComputedValue computedTotalExpectedValue = new ComputedValue() { @Override protected Object calculate() { Object value = totalRecordsProperty.observeDetail(selectionObservable).getValue(); if (value instanceof Integer) { return new Integer(StudioUtils.metricsInMetricSource(metricSource).size() * (Integer) value) .toString(); } return 0; } }; ComputedValue computedTotalFailedValue = new ComputedValue() { @Override protected Object calculate() { Object selectedObject = selectionObservable.getValue(); // recursively compute for sub-statistics. if (selectedObject instanceof MappingStatistic) { return new Integer(StudioUtils.mappingFailedCount((MappingStatistic) selectedObject)) .toString(); } return 0; } }; EMFUpdateValueStrategy modelToTargetStrategy = new EMFUpdateValueStrategy(); modelToTargetStrategy.setConverter(new ModelDateConverter()); bindingContext.bindValue(messageObservable, messageProperty.observeDetail(selectionObservable)); bindingContext.bindValue(totalRecordsObservable, totalRecordsProperty.observeDetail(selectionObservable)); bindingContext.bindValue(startTimeObservable, startDateTimeProperty.observeDetail(selectionObservable), null, modelToTargetStrategy); bindingContext.bindValue(endTimeObservable, endDateTimeProperty.observeDetail(selectionObservable), null, modelToTargetStrategy); bindingContext.bindValue(metricStartTimeObservable, metricStartDateTimeProperty.observeDetail(selectionObservable), null, modelToTargetStrategy); bindingContext.bindValue(metricEndTimeObservable, metricEndDateTimeProperty.observeDetail(selectionObservable), null, modelToTargetStrategy); bindingContext.bindValue(totalExpectedValuesObservable, computedTotalExpectedValue); bindingContext.bindValue(totalFailedValuesObservable, computedTotalFailedValue); // bindingContext.bindValue(totalExpectedValuesObservable, // computedTotalExpectedValue, new UpdateValueStrategy(false, // UpdateValueStrategy.POLICY_NEVER), null); // // bindingContext.bindValue(totalFailedValuesObservable, // computedTotalFailedValue, new UpdateValueStrategy(false, // UpdateValueStrategy.POLICY_NEVER), null); ObservableListContentProvider recordsContentProvider = new ObservableListContentProvider(); tblViewerRecords.setContentProvider(recordsContentProvider); // IObservableMap[] recordsObserveMaps = EMFObservables.observeMaps( // listContentProvider.getKnownElements(), // new EStructuralFeature[] { // MetricsPackage.Literals.MAPPING_RECORD__ROW, // MetricsPackage.Literals.MAPPING_RECORD__COLUMN, // MetricsPackage.Literals.MAPPING_RECORD__MESSAGE, }); tblViewerRecords.setLabelProvider(new RecordsObservableMapLabelProvider()); IEMFListProperty recordsProperty = EMFProperties .list(MetricsPackage.Literals.MAPPING_STATISTIC__FAILED_RECORDS); tblViewerRecords.setInput(recordsProperty.observeDetail(selectionObservable)); return bindingContext; }
From source file:com.netxforge.netxstudio.screens.f4.NewEditJob.java
License:Open Source License
public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext bindingContext = new EMFDataBindingContext(); // JOB_STATE//from ww w.j a v a 2 s .c o m EMFUpdateValueStrategy jobStateModelToTargetStrategy = new EMFUpdateValueStrategy(); jobStateModelToTargetStrategy.setConverter(new IConverter() { public Object getFromType() { return JobState.class; } public Object getToType() { return Boolean.class; } public Object convert(Object fromObject) { JobState current = (JobState) fromObject; if (current.getValue() == JobState.ACTIVE_VALUE) { return Boolean.TRUE; } else { return Boolean.FALSE; } } }); EMFUpdateValueStrategy jobStateTargetToModelStrategy = new EMFUpdateValueStrategy(); jobStateTargetToModelStrategy.setConverter(new IConverter() { public Object getFromType() { return Boolean.class; } public Object getToType() { return JobState.class; } public Object convert(Object fromObject) { Boolean current = (Boolean) fromObject; if (current) { return JobState.ACTIVE; } else { return JobState.IN_ACTIVE; } } }); IObservableValue jobStateObservable = SWTObservables.observeSelection(btnActive); IEMFValueProperty jobStateProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__JOB_STATE); bindingContext.bindValue(jobStateObservable, jobStateProperty.observe(job), jobStateTargetToModelStrategy, jobStateModelToTargetStrategy); // JOB_NAME EMFUpdateValueStrategy nameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Name is required"); IObservableValue textObserveJobName = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(this.txtJobName, SWT.Modify)); IEMFValueProperty textJobNameValue = EMFProperties.value(SchedulingPackage.Literals.JOB__NAME); bindingContext.bindValue(textObserveJobName, textJobNameValue.observe(job), nameStrategy, null); // //////////////////////////////////////////////////////// // WRITABLE OBSERVABLES // All these widgets, do not directly through the model and are // therefore bound // separately for each sync direction through a WritableValue // //////////////////////////////////////////////////////// comboViewerOn.setContentProvider(new ArrayContentProvider()); comboViewerOn.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return NonModelUtils.weekDay((Integer) element); } }); comboViewerOn.setInput(NonModelUtils.weekDaysAsInteger().toArray()); comboViewerEvery.setContentProvider(new ArrayContentProvider()); comboViewerEvery.setInput(ComboStartInput); // //////////////////////////// // OBSERVABLES THROUGH AN AGGREGATOR // ////////////////////////////// comboViewerOnWritableValue = new WritableValue(); comboViewerEveryWritableValue = new WritableValue(); cdateTimeStartTimeWritableValue = new WritableValue(); dateChooserStartsOnWritableValue = new WritableValue(); dateChooserEndsOnWritableValue = new WritableValue(); btnOnWritableValue = new WritableValue(); btnAfterWritableValue = new WritableValue(); btnNeverWritableValue = new WritableValue(); txtOccurencesWritableValue = new WritableValue(); comboViewerOnObserveSingleSelection = ViewersObservables.observeSingleSelection(comboViewerOn); comboViewerEveryObserveSingleSelection = ViewersObservables.observeSingleSelection(comboViewerEvery); comboViewerEveryObserveText = SWTObservables.observeText(comboViewerEvery.getCombo()); comboObserveStartTime = new CDateTimeObservableValue(this.cdateTimeStartTime); dateChooseObserveStartDate = new DateChooserComboObservableValue(dateChooserStartsOn, SWT.Modify); dateChooseObserveEndDate = new DateChooserComboObservableValue(dateChooserEndsOn, SWT.Modify); endOnObservable = SWTObservables.observeSelection(btnOn); endOccurencesObservable = SWTObservables.observeSelection(btnAfter); endNeverObservable = SWTObservables.observeSelection(btnNever); occurenceObservable = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(this.txtOccurences, SWT.Modify)); // //////////////////////////// // OPPOSITE BINDING // /////////////////////////// bindingContext.bindValue(comboViewerOnObserveSingleSelection, comboViewerOnWritableValue, null, null); bindingContext.bindValue(comboViewerEveryObserveSingleSelection, comboViewerEveryWritableValue, null, null); bindingContext.bindValue(comboObserveStartTime, cdateTimeStartTimeWritableValue, null, null); bindingContext.bindValue(dateChooseObserveStartDate, dateChooserStartsOnWritableValue, null, null); bindingContext.bindValue(dateChooseObserveEndDate, dateChooserEndsOnWritableValue, null, null); bindingContext.bindValue(endNeverObservable, btnNeverWritableValue, null, null); bindingContext.bindValue(endOccurencesObservable, btnAfterWritableValue, null, null); bindingContext.bindValue(endOnObservable, btnOnWritableValue, null, null); EMFUpdateValueStrategy occurencesModelToTargetStrategy = new EMFUpdateValueStrategy(); occurencesModelToTargetStrategy.setConverter(new IConverter() { public Object getFromType() { return Integer.class; } public Object getToType() { return String.class; } public Object convert(Object fromObject) { if (fromObject != null) { return ((Integer) fromObject).toString(); } else { return ""; } } }); EMFUpdateValueStrategy occurencesTargetToModelStrategy = new EMFUpdateValueStrategy(); occurencesTargetToModelStrategy.setConverter(new IConverter() { public Object getFromType() { return String.class; } public Object getToType() { return Integer.class; } public Object convert(Object fromObject) { try { String from = (String) fromObject; if (from.length() == 0) { return 0; } return new Integer(from); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } return 0; } }); bindingContext.bindValue(occurenceObservable, this.txtOccurencesWritableValue, occurencesTargetToModelStrategy, occurencesModelToTargetStrategy); // ///////////////////////////////////////////////// // ACTUAL MODEL BINDING // //////////////////////////////////////////////// // The following binding is indirect through a series of writableValues. // / The writables, which will be deduced from various widgets by our // aggregator. IObservableValue startTimeWritableValue = new WritableValue(); IObservableValue endTimeWritableValue = new WritableValue(); IObservableValue intervalWritableValue = new WritableValue(); IObservableValue repeatWritableValue = new WritableValue(); // The aggregator. JobInfoAggregate aggregate = new JobInfoAggregate(startTimeWritableValue, endTimeWritableValue, intervalWritableValue, repeatWritableValue); IEMFValueProperty startTimeProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__START_TIME); IEMFValueProperty endTimeProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__END_TIME); IEMFValueProperty intervalProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__INTERVAL); IEMFValueProperty repeatProperty = EMFEditProperties.value(editingService.getEditingDomain(), SchedulingPackage.Literals.JOB__REPEAT); // TODO, add converters and validators. IObservableValue startTimeObservableValue = startTimeProperty.observe(job); IObservableValue endTimeObservableValue = endTimeProperty.observe(job); IObservableValue intervalObservableValue = intervalProperty.observe(job); IObservableValue repeatObservableValue = repeatProperty.observe(job); // ////////////////////// // BIND OUR WRITABLES. // //////////////////// EMFUpdateValueStrategy targetToModelStrategy = new EMFUpdateValueStrategy(); targetToModelStrategy.setConverter(new DateToXMLConverter()); bindingContext.bindValue(startTimeWritableValue, startTimeObservableValue, targetToModelStrategy, null); bindingContext.bindValue(endTimeWritableValue, endTimeObservableValue, targetToModelStrategy, null); bindingContext.bindValue(intervalWritableValue, intervalObservableValue, targetToModelStrategy, null); bindingContext.bindValue(repeatWritableValue, repeatObservableValue, targetToModelStrategy, null); // Set initial values of the widgets. , without having the aggregator // activated yet. this.setInitial(startTimeObservableValue.getValue(), endTimeObservableValue.getValue(), repeatObservableValue.getValue(), intervalObservableValue.getValue()); // Set the initial values of the aggregator. aggregate.setInitialValues(job); this.enableAggregate(aggregate); // bindingContext.updateTargets(); return bindingContext; }
From source file:com.netxforge.netxstudio.screens.f4.NewEditMappingColumn.java
License:Open Source License
public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext context = new EMFDataBindingContext(); IObservableValue columnObservable = SWTObservables.observeText(txtColumn, SWT.Modify); IEMFValueProperty columnProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING_COLUMN__COLUMN); context.bindValue(columnObservable, columnProperty.observe(mxlsColumn)); // /////////////////////////////////////////////////////////// // AGGREGATOR // /////////////////////////////////////////////////////////// IObservableValue dataKindWritableValue = new WritableValue(); IEMFValueProperty dataKindProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE); // Should occure before the aggregator is created. IObservableValue dataKindObservable = dataKindProperty.observe(mxlsColumn); // Validation Strategies EMFUpdateValueStrategy dataKindStrategy = new EMFUpdateValueStrategy(); dataKindStrategy.setBeforeSetValidator(new IValidator() { public IStatus validate(Object value) { boolean isInvalid = false; if (value == null) { isInvalid = true;//from ww w . j a v a 2 s . c om } else { // Always valid here.... } if (isInvalid) { return new Status(IStatus.WARNING, ScreensActivator.PLUGIN_ID, "Mapping Issue:"); } return Status.OK_STATUS; } }); context.bindValue(dataKindWritableValue, dataKindObservable, dataKindStrategy, null); // Aggregates all mutations on the current DataKind. // If none exists, a new one will be created based on the selected // button. DatakindAggregate aggregate = new DatakindAggregate(dataKindWritableValue); initDataBindingHeaderMappingColumn(context); if (showDataMapping) { initDataBindingDataMappingColumn(context, dataKindProperty); } setInitialHeaderMapping(dataKindObservable.getValue()); this.enableHeaderAggregate(aggregate); if (showDataMapping) { setInitialDataMapping(dataKindObservable.getValue()); this.enableDataAggregate(aggregate); } context.updateTargets(); return context; }
From source file:com.netxforge.netxstudio.screens.f4.NewEditMappingColumn.java
License:Open Source License
private void initDataBindingDataMappingColumn(EMFDataBindingContext context, IEMFValueProperty dataKindProperty) { // Metric option selected. btnMetricWritableValue = new WritableValue(); metricObservable = SWTObservables.observeSelection(btnMetricValue); context.bindValue(metricObservable, btnMetricWritableValue, null, null); // We should really observe the button. metricValueObservable = SWTObservables.observeText(txtMetric, SWT.Modify); // valuePatternObservable = SWTObservables.observeText( // this.txtMetricValuePattern, SWT.Modify); EMFUpdateValueStrategy metricModelToTargetStrategy = new EMFUpdateValueStrategy(); metricModelToTargetStrategy.setConverter(new DataKindModelToTargetConverter() { public Object convert(Object fromObject) { if (fromObject instanceof ValueDataKind) { Metric metric = ((ValueDataKind) fromObject).getMetricRef(); if (metric != null) { return metric.getName(); }/*ww w .j a va2 s. c o m*/ } return null; } }); context.bindValue(metricValueObservable, dataKindProperty.observe(mxlsColumn), null, metricModelToTargetStrategy); cmbViewrMetricKindHint.setContentProvider(new ArrayContentProvider()); cmbViewrMetricKindHint.setLabelProvider(new LabelProvider()); cmbViewrMetricKindHint.setInput(KindHintType.VALUES); metricKindHintObservable = ViewerProperties.singleSelection().observe(cmbViewrMetricKindHint); IEMFEditValueProperty KindHintProperty = EMFEditProperties.value(editingService.getEditingDomain(), FeaturePath.fromList(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE, MetricsPackage.Literals.VALUE_DATA_KIND__KIND_HINT)); context.bindValue(metricKindHintObservable, KindHintProperty.observe(mxlsColumn), null, null); }
From source file:com.netxforge.netxstudio.screens.f4.NewEditMetricSource.java
License:Open Source License
public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext context = new EMFDataBindingContext(); // Validation Strategies EMFUpdateValueStrategy nameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Name is required"); EMFUpdateValueStrategy locationStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Metric Source Location URL is required"); IObservableValue nameObservable = SWTObservables.observeText(txtName, SWT.Modify); IObservableValue locationObservable = SWTObservables.observeText(this.txtLocationUrl, SWT.Modify); IEMFValueProperty nameProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.METRIC_SOURCE__NAME); IEMFValueProperty locationProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.METRIC_SOURCE__METRIC_LOCATION); context.bindValue(nameObservable, nameProperty.observe(metricSource), nameStrategy, null); context.bindValue(locationObservable, locationProperty.observe(metricSource), locationStrategy, null); return context; }
From source file:com.netxforge.netxstudio.screens.nf3.Retention.java
License:Open Source License
private void addCustomUIRule(final Composite cmpRules, final MetricRetentionRule rule, EMFDataBindingContext context, IEMFValueProperty retentionPeriodProperty, IValueProperty cmbSelectionProperty) { // Edit the name of the rule. final Text nameText = toolkit.createText(cmpRules, ""); GridData textLayoutData = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1); textLayoutData.widthHint = 100;/*from w w w . ja v a 2 s . c o m*/ nameText.setLayoutData(textLayoutData); nameText.setFocus(); final ISWTObservableValue observeTextName = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(nameText, SWT.Modify)); final IEMFEditValueProperty nameProperty = EMFEditProperties.value(editingService.getEditingDomain(), MetricsPackage.Literals.METRIC_RETENTION_RULE__NAME); context.bindValue(observeTextName, nameProperty.observe(rule)); // Edit the interval. final Text intervalText = toolkit.createText(cmpRules, ""); final GridData intervalGridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1); intervalText.setLayoutData(intervalGridData); final ISWTObservableValue observeTextInterval = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(intervalText, SWT.Modify)); final IEMFEditValueProperty intervalModelProperty = EMFEditProperties.value( editingService.getEditingDomain(), MetricsPackage.Literals.METRIC_RETENTION_RULE__INTERVAL_HINT); context.bindValue(observeTextInterval, intervalModelProperty.observe(rule)); // Edit the retention period. final ComboViewer cmbViewerTarget = new ComboViewer(cmpRules, SWT.NONE); final Combo cmbRetentionPeriod = cmbViewerTarget.getCombo(); final GridData gridDataRetentionPeriod = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1); gridDataRetentionPeriod.widthHint = 150; cmbRetentionPeriod.setLayoutData(gridDataRetentionPeriod); toolkit.paintBordersFor(cmbRetentionPeriod); final ImageHyperlink mghprlnkEditRetentionExpression = toolkit.createImageHyperlink(cmpRules, SWT.NONE); mghprlnkEditRetentionExpression.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); mghprlnkEditRetentionExpression.addHyperlinkListener(new HyperlinkAdapter() { public void linkActivated(HyperlinkEvent e) { launchExpressionScreen(rule); } }); toolkit.paintBordersFor(mghprlnkEditRetentionExpression); mghprlnkEditRetentionExpression.setText("Edit retention expression"); final ImageHyperlink removeObjectHyperLink = toolkit.createImageHyperlink(cmpRules, SWT.NONE); removeObjectHyperLink.addHyperlinkListener(new HyperlinkAdapter() { public void linkActivated(HyperlinkEvent e) { final CompoundCommand cc = new CompoundCommand(); if (rule.eIsSet(MetricsPackage.Literals.METRIC_RETENTION_RULE__RETENTION_EXPRESSION)) { final Expression retentionExpression = rule.getRetentionExpression(); final Command deleteExpressionCommand = DeleteCommand.create(editingService.getEditingDomain(), retentionExpression); cc.append(deleteExpressionCommand); } final Command deleteRuleCommand = DeleteCommand.create(editingService.getEditingDomain(), rule); cc.append(deleteRuleCommand); editingService.getEditingDomain().getCommandStack().execute(cc); } }); final GridData removeObjectGridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); removeObjectGridData.widthHint = 18; removeObjectHyperLink.setLayoutData(removeObjectGridData); removeObjectHyperLink .setImage(ResourceManager.getPluginImage("org.eclipse.ui", "/icons/full/etool16/delete.gif")); toolkit.paintBordersFor(removeObjectHyperLink); removeObjectHyperLink.setText(""); cmbViewerTarget.setContentProvider(new ArrayContentProvider()); cmbViewerTarget.setLabelProvider(new LabelProvider()); cmbViewerTarget.setInput(MetricRetentionPeriod.values()); context.bindValue(cmbSelectionProperty.observe(cmbViewerTarget), retentionPeriodProperty.observe(rule)); }
From source file:com.netxforge.netxstudio.screens.nf4.NewEditUser.java
License:Open Source License
/** * Converted to new EMF API.// w w w . ja va 2 s . c om * * @return */ public EMFDataBindingContext initDataBindings_() { EMFDataBindingContext bindingContext = new EMFDataBindingContext(); validationService.registerBindingContext(bindingContext); // Validation Strategies EMFUpdateValueStrategy loginStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Login is required"); EMFUpdateValueStrategy firstNameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("First name is required"); EMFUpdateValueStrategy lastNameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Last name is required"); EMFUpdateValueStrategy emailNameStrategy = ValidationService.getStrategyfactory() .strategyBeforeSetStringNotEmpty("Email is required"); // The active strategy is merely a warning. EMFUpdateValueStrategy activeStrategy = ValidationService.getStrategyfactory() .strategyAfterGet(new IValidator() { public IStatus validate(Object value) { if (value instanceof Boolean) { if (!((Boolean) value).booleanValue()) { // Not active, issue warning. return new Status(IStatus.WARNING, ScreensActivator.PLUGIN_ID, "Person not active, are you sure"); } else { return Status.OK_STATUS; } } else { return new Status(IStatus.ERROR, ScreensActivator.PLUGIN_ID, "Should and will not occure"); } } }); EMFUpdateValueStrategy roleStrategy = ValidationService.getStrategyfactory() .strategyAfterGet(new IValidator() { public IStatus validate(Object value) { if (value == null) { return new Status(IStatus.WARNING, ScreensActivator.PLUGIN_ID, "A role should be selected"); } else { // Any other value should do. return Status.OK_STATUS; } } }); // Bindings IObservableValue textObserveTextObserveWidget_1 = SWTObservables.observeDelayedValue(100, SWTObservables.observeText(txtLogin, SWT.Modify)); IEMFValueProperty userLoginObserveValue_1 = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__LOGIN); bindingContext.bindValue(textObserveTextObserveWidget_1, userLoginObserveValue_1.observe(user), loginStrategy, null); IObservableValue txtFirstNameObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtFirstName, SWT.Modify)); // IObservableValue userFirstNameObserveValue = // EMFObservables.observeValue(user, Literals.PERSON__FIRST_NAME); IEMFValueProperty userFirstNameObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__FIRST_NAME); bindingContext.bindValue(txtFirstNameObserveTextObserveWidget, userFirstNameObserveValue.observe(user), firstNameStrategy, null); IObservableValue txtLastNameObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtLastName, SWT.Modify)); // IObservableValue userLastNameObserveValue = EMFObservables // .observeValue(user, Literals.PERSON__LAST_NAME); IEMFValueProperty userLastNameObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__LAST_NAME); bindingContext.bindValue(txtLastNameObserveTextObserveWidget, userLastNameObserveValue.observe(user), lastNameStrategy, null); IObservableValue txtEmailObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtEmail, SWT.Modify)); // IObservableValue userEmailObserveValue = EMFObservables.observeValue( // user, Literals.PERSON__EMAIL); IEMFValueProperty userEmailObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__EMAIL); bindingContext.bindValue(txtEmailObserveTextObserveWidget, userEmailObserveValue.observe(user), emailNameStrategy, null); IObservableValue btnCheckObserveSelectionObserveWidget = SWTObservables.observeSelection(btnCheck); IEMFValueProperty userActiveObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__ACTIVE); bindingContext.bindValue(btnCheckObserveSelectionObserveWidget, userActiveObserveValue.observe(user), activeStrategy, null); IObservableValue passwordObservableValue = new WritableValue(); IObservableValue txtPasswordObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtPass, SWT.Modify)); IObservableValue txtConfirmObserveTextObserveWidget = SWTObservables.observeDelayedValue(400, SWTObservables.observeText(txtConfirm, SWT.Modify)); // NEW CODE, Use a custom MultiValidator, it produces NewPasswordConfirmed newPasswordConfirmed = new NewPasswordConfirmed(bindingContext, new IObservableValue[] { txtPasswordObserveTextObserveWidget, txtConfirmObserveTextObserveWidget }); passwordObservableValue = newPasswordConfirmed .observeValidatedValue(newPasswordConfirmed.getMiddletons().get(0)); // OLD CODE. // Special writable case for password and confirmation, // both share the value changed listener, which only sets the model. // when both passwords are the same. 2 x widgets -> model // PasswordConfirmed confirmedHandler = new PasswordConfirmed( // passwordObservableValue); // txtPasswordObserveTextObserveWidget // .addValueChangeListener(confirmedHandler); // txtConfirmObserveTextObserveWidget // .addValueChangeListener(confirmedHandler); // EMFUpdateValueStrategy passStrategy = ValidationService // .getStrategyfactory().strategyAfterGet(confirmedHandler); EMFUpdateValueStrategy passStrategy = new EMFUpdateValueStrategy(); passStrategy.setConverter(new PasswordConverter()); IEMFValueProperty passwordObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__PASSWORD); // Password, can not be presented (Ok it can but we don't want to), so only target to model. bindingContext.bindValue(passwordObservableValue, passwordObserveValue.observe(user), passStrategy, null); newPasswordConfirmed.revalidateExternal(); // Hand coded binding for a combo. ObservableListContentProvider listContentProvider = new ObservableListContentProvider(); this.getComboViewerWidget().setContentProvider(listContentProvider); IObservableMap observeMap = EMFObservables.observeMap(listContentProvider.getKnownElements(), Literals.ROLE__NAME); this.getComboViewerWidget().setLabelProvider(new ObservableMapLabelProvider(observeMap)); rolesResource = editingService.getData(GenericsPackage.Literals.ROLE); IEMFListProperty l = EMFEditProperties.resource(editingService.getEditingDomain()); IObservableList rolesObservableList = l.observe(rolesResource); // obm.addObservable(rolesObservableList); this.getComboViewerWidget().setInput(rolesObservableList); IObservableValue comboObserveProxy = ViewerProperties.singleSelection().observe(comboViewer); IEMFValueProperty roleObserveValue = EMFEditProperties.value(editingService.getEditingDomain(), Literals.PERSON__ROLES); bindingContext.bindValue(comboObserveProxy, roleObserveValue.observe(user), roleStrategy, null); return bindingContext; }