Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-04-10 11:35:21 -0400
committercletavernie2012-04-10 11:35:21 -0400
commit18b0ff7c9e903b9dcdbfab25d217941cdd4dd1cd (patch)
tree52571d5d7a291862368aba54543b3cf417f69f73 /plugins/xwt
parent4a4fe2cc4871aa8e41a7f781cd08a728181a287e (diff)
downloadorg.eclipse.papyrus-18b0ff7c9e903b9dcdbfab25d217941cdd4dd1cd.tar.gz
org.eclipse.papyrus-18b0ff7c9e903b9dcdbfab25d217941cdd4dd1cd.tar.xz
org.eclipse.papyrus-18b0ff7c9e903b9dcdbfab25d217941cdd4dd1cd.zip
373708: Integration of XWT for Simultaneous Release
https://bugs.eclipse.org/bugs/show_bug.cgi?id=373708
Diffstat (limited to 'plugins/xwt')
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/.classpath7
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/.project28
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/META-INF/MANIFEST.MF42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/about.html28
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/build.properties16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/plugin.properties22
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/DefaultLoadingContext.java71
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ICLRFactory.java29
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IConstants.java126
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBinding.java27
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBindingInfo.java24
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProvider.java100
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProviderFactory.java32
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventConstants.java228
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventGroup.java39
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventHandler.java24
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventInvoker.java18
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IIndexedElement.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILoadingContext.java22
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILogger.java37
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMetaclassFactory.java26
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMultiValueConverter.java24
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/INamespaceHandler.java23
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IObservableValueListener.java26
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IStyle.java25
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIExtensionProvider.java21
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIResource.java15
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValidationRule.java59
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValueConverter.java24
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTInitializer.java8
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTLoader.java767
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/InverseValueConverter.java42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ResourceDictionary.java21
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/Tracking.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWT.java1080
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTException.java34
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoader.java1796
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoaderManager.java70
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTMaps.java691
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/animation/Drawing.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/Containment.java26
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UI.java23
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UIBounds.java21
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/IBeforeParsingCallback.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ICreatedCallback.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ILoadedCallback.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionView.java115
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionViewSource.java119
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/GroupDescription.java42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/ListSortDirection.java20
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/SortDescription.java47
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/AbstractMultiValueConverter.java28
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/BindingToObject.java37
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToBoolean.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToInteger.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/DateToString.java45
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/EnumToString.java47
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToBoolean.java44
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToString.java47
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToIObservableCollection.java41
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToSet.java40
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToBoolean.java35
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToISelection.java67
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToObject.java35
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToString.java70
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SelectionToBoolean.java37
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SetToIObservableCollection.java41
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringMultiValueConerter.java68
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToBoolean.java44
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToColor.java52
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToDoubleArray.java71
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToEnum.java64
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFont.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFormAttachment.java90
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValidationRule.java59
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValueConverter.java59
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToImage.java53
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIntArray.java71
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToInteger.java158
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToPoint.java47
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToRectangle.java51
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToType.java50
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToURL.java56
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ValueConverterAdapter.java61
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/AbstractEventGroup.java30
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Condition.java220
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/DataTrigger.java227
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/EventTrigger.java223
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IBinding.java27
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/ICollectionView.java104
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicBinding.java52
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicValueBinding.java24
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IElementLoaderFactory.java18
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IRenderingContext.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IUserDataConstants.java52
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IVisualElementLoader.java20
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiDataTrigger.java118
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiTrigger.java97
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Operator.java225
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/RadioEventGroup.java78
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Setter.java110
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/SetterBase.java20
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Style.java69
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Trigger.java155
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerAction.java24
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerBase.java89
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AbstractDataBinding.java149
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AggregateObservableValue.java108
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingContext.java317
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingMode.java19
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ControlDataBinding.java101
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/DataBinding.java186
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/Event.java93
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventListener.java19
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventManager.java72
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventPropertyObservableValue.java56
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/IBindingContext.java212
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/JFaceXWTDataBinding.java475
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ListToArrayObservableValue.java95
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/TypedViewerObservableValueDecorator.java65
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/XWTObservableValue.java147
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/AbstractDataProvider.java150
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/IObjectDataProvider.java37
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/ObjectDataProvider.java345
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Color.java82
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Point.java64
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Rect.java123
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CanExecuteChangedListener.java21
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CommandBinding.java66
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ICommand.java26
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/InputBinding.java58
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyBinding.java18
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyGesture.java48
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ModifierKeys.java19
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/MouseAction.java19
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/RoutedCommand.java42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/Activator.java33
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Binding.java310
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingExpressionPath.java197
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingGate.java406
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Core.java917
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DataBindingTrack.java202
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicBinding.java226
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicValueBinding.java64
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/IEventController.java33
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassManager.java162
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassService.java150
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MultiBinding.java222
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeKeeper.java263
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeManager.java485
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UIResource.java26
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UpdateSourceTrigger.java45
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/AbstractMenuItemObservableValue.java63
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemEnabledObservableValue.java42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemSelectionObservableValue.java42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ClassLoaderUtil.java143
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/DocumentObjectSorter.java93
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/LoggerManager.java40
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/NamespaceHelper.java44
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObjectUtil.java399
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObservableValueManager.java85
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/TableEditorHelper.java63
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/UserData.java699
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Attribute.java55
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentObject.java240
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentRoot.java463
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Element.java261
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementHandler.java797
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementManager.java413
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/XDataHandler.java95
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/Controller.java345
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoader.java1728
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoaderFactory.java26
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/StaticResourceBinding.java49
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ValueConvertorRegister.java77
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/AbstractMetaclass.java742
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BeanEvent.java28
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Behavior.java40
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BindingMetaclass.java53
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ComboBoxCellEditorMetaclass.java72
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ExpandItemHeightAction.java31
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/LoadedEvent.java33
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Metaclass.java68
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableEditorMetaclass.java46
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableViewerColumnMetaClass.java69
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TypedEvent.java49
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/AbstractProperty.java119
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/BeanProperty.java125
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/ColumnViewerColumnsProperty.java52
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DataProperty.java57
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicBeanProperty.java42
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicProperty.java80
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/EventProperty.java32
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/FieldProperty.java69
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/InputBeanProperty.java152
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/MultiSelectionBeanProperty.java63
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/PropertiesConstants.java58
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/SingleSelectionBeanProperty.java53
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/StyleProperty.java40
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableColumnEditorProperty.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableEditorDynamicProperty.java323
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemEditorProperty.java66
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemProperty.java87
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnDynamicProperty.java45
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnImageProperty.java39
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnTextProperty.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnWidthProperty.java38
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TriggersProperty.java40
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/AbstractDialog.java79
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/CellEditorHelper.java56
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ComboBoxCellEditor.java89
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultCellModifier.java92
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultListContentProvider.java37
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultViewerLabelProvider.java116
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFaceInitializer.java28
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFacesHelper.java237
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableMapLabelProvider.java96
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableTreeContentProvider.java116
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/TextCellEditor.java74
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ViewerFilter.java41
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTDialog.java44
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTObservableWrapper.java222
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTTitleAreaDialog.java118
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DefaultLoadingType.java31
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DelegateProperty.java99
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IBehavior.java28
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IEvent.java19
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ILoadingType.java45
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IMetaclass.java67
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IObjectInitializer.java22
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IProperty.java55
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ISetPostAction.java16
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IValueLoading.java35
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ModelUtils.java34
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java84
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/OperatorExceptionMessage.java23
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/PathHelper.java152
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/ResourceManager.java246
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/colors.properties150
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/AbstractValidationRule.java47
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/InverseValidationRule.java70
242 files changed, 28781 insertions, 0 deletions
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/.classpath b/plugins/xwt/org.eclipse.papyrus.xwt/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/.project b/plugins/xwt/org.eclipse.papyrus.xwt/.project
new file mode 100644
index 00000000000..a6b1cfd36a7
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.xwt</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/.settings/org.eclipse.jdt.core.prefs b/plugins/xwt/org.eclipse.papyrus.xwt/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..74de2131e4f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Thu Jan 08 14:18:44 EST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/META-INF/MANIFEST.MF b/plugins/xwt/org.eclipse.papyrus.xwt/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..33763c86aa8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/META-INF/MANIFEST.MF
@@ -0,0 +1,42 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.eclipse.papyrus.xwt;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+DynamicImport-Package: *
+Require-Bundle:
+ org.eclipse.jface.databinding;bundle-version="1.2.0",
+ org.eclipse.core.databinding.beans;bundle-version="1.1.0",
+ org.eclipse.swt;bundle-version="3.4.0",
+ org.eclipse.core.databinding;bundle-version="1.1.0",
+ org.eclipse.jface;bundle-version="3.4.0",
+ org.eclipse.core.databinding.property;bundle-version="1.1.0",
+ org.eclipse.equinox.common;bundle-version="3.4.0"
+Export-Package: org.eclipse.papyrus.xwt,
+ org.eclipse.papyrus.xwt.animation,
+ org.eclipse.papyrus.xwt.annotation,
+ org.eclipse.papyrus.xwt.callback,
+ org.eclipse.papyrus.xwt.collection,
+ org.eclipse.papyrus.xwt.converters,
+ org.eclipse.papyrus.xwt.core,
+ org.eclipse.papyrus.xwt.databinding,
+ org.eclipse.papyrus.xwt.dataproviders,
+ org.eclipse.papyrus.xwt.graphics,
+ org.eclipse.papyrus.xwt.input,
+ org.eclipse.papyrus.xwt.internal.core,
+ org.eclipse.papyrus.xwt.internal.databinding.menuitem,
+ org.eclipse.papyrus.xwt.internal.utils,
+ org.eclipse.papyrus.xwt.internal.xml,
+ org.eclipse.papyrus.xwt.javabean,
+ org.eclipse.papyrus.xwt.javabean.metadata,
+ org.eclipse.papyrus.xwt.javabean.metadata.properties,
+ org.eclipse.papyrus.xwt.jface,
+ org.eclipse.papyrus.xwt.metadata,
+ org.eclipse.papyrus.xwt.utils,
+ org.eclipse.papyrus.xwt.validation
+Bundle-Vendor: %Bundle-Vendor.0
+Bundle-Localization: plugin
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Activator: org.eclipse.papyrus.xwt.internal.Activator
+Import-Package: org.osgi.framework;version="1.5.0"
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/about.html b/plugins/xwt/org.eclipse.papyrus.xwt/about.html
new file mode 100644
index 00000000000..5ddc72c177f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>November 20, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/build.properties b/plugins/xwt/org.eclipse.papyrus.xwt/build.properties
new file mode 100644
index 00000000000..ec7cba6ea1d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/build.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2010, 2011 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+source.. = src/
+bin.includes = META-INF/,\
+ .,\
+ plugin.properties,\
+ about.html
+src.includes = about.html
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/plugin.properties b/plugins/xwt/org.eclipse.papyrus.xwt/plugin.properties
new file mode 100644
index 00000000000..4f8fcd64ad8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/plugin.properties
@@ -0,0 +1,22 @@
+###############################################################################
+# Copyright (c) 2010 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+#******************************************************************************
+# Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Soyatec - initial API and implementation
+#******************************************************************************/
+Bundle-Vendor.0 = Eclipse.org
+Bundle-Name.0 = XWT (Incubation) \ No newline at end of file
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/DefaultLoadingContext.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/DefaultLoadingContext.java
new file mode 100644
index 00000000000..8676be2e340
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/DefaultLoadingContext.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.net.URL;
+
+public class DefaultLoadingContext implements ILoadingContext {
+
+ public static final DefaultLoadingContext defaultLoadingContext = new DefaultLoadingContext();
+
+ protected ClassLoader classLoader;
+
+ public DefaultLoadingContext() {
+ }
+
+ public DefaultLoadingContext(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ public ClassLoader getClassLoader() {
+ if(classLoader == null) {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ public String getNamespace() {
+ return IConstants.XWT_NAMESPACE;
+ }
+
+ public Class<?> loadClass(String name) {
+ Class<?> type = doLoadClass(name);
+ if(type != null) {
+ return type;
+ }
+ int index = name.lastIndexOf('.');
+ while(index != -1) {
+ name = name.substring(0, index) + "$" + name.substring(index + 1);
+ type = doLoadClass(name);
+ if(type != null) {
+ return type;
+ }
+ index = name.lastIndexOf('.');
+ }
+ return null;
+ }
+
+ protected Class<?> doLoadClass(String name) {
+ try {
+ return getClassLoader().loadClass(name);
+ } catch (ClassNotFoundException e) {
+ }
+ return null;
+ }
+
+ public URL getResource(String name) {
+ return getClassLoader().getResource(name);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ICLRFactory.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ICLRFactory.java
new file mode 100644
index 00000000000..1cbdac9c618
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ICLRFactory.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ * Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.util.Map;
+
+public interface ICLRFactory {
+
+ /**
+ * This method is used to create a CLR instance to handle events.
+ *
+ * @param args
+ * null if the default CLRFactory comes from XWT.getCLRFactory()
+ * or CLASS_FACTORY. Otherwise, it is the value x:ClassFactory
+ * @options contains structures used by XWT (ex : URL, DataContext). Keys of
+ * this Map come from {@link IXWTLoader}.
+ * @return
+ */
+ Object createCLR(String args, Map<String, Object> options);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IConstants.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IConstants.java
new file mode 100644
index 00000000000..85878984d63
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IConstants.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.ListResourceBundle;
+import java.util.ResourceBundle;
+
+import org.eclipse.papyrus.xwt.internal.xml.DocumentObject;
+
+/**
+ * Shared constants
+ *
+ * @author yyang
+ */
+public interface IConstants {
+
+ public final String XAML_X_KEY = "Key";
+
+ public final String XAML_X_TYPE = "Type";
+
+ public final String XAML_X_TARGET_TYPE = "TargetType";
+
+ public final String XAML_X_TYPE_NAME = "TypeName";
+
+ public final String XAML_CLR_ASSEMBLY = "assembly=";
+
+ public final String XAML_X_STATIC = "Static";
+
+ public final String XAML_X_STATIC_MEMBER = "Member";
+
+ public final String XAML_X_ARRAY = "Array";
+
+ public final String XAML_X_CLASS = "Class";
+
+ public final String XAML_X_CLASS_FACTORY = "ClassFactory";
+
+ public final String XAML_X_NAME = "Name";
+
+ public final String XAML_X_NULL = "Null";
+
+ public final String XAML_X_SHARED = "Shared";
+
+ public final String XAML_DATA_CONTEXT = "DataContext";
+
+ public final String XAML_BINDING_CONTEXT = "BindingContext";
+
+ public final String XAML_RENDER_TRANSFORM = "RenderTransform";
+
+ public final String XAML_RENDER_TRANSFORM_ORIGIN = "RenderTransformOrigin";
+
+ public final String XAML_TRIGGERS = "Triggers";
+
+ public final String XAML_STYLE = "Style";
+
+ public final String XAML_COMMAND = "Command";
+
+ public final String XAML_CLR_NAMESPACE_PROTO = "clr-namespace:";
+
+ public final String XAML_RESOURCES = "Resources";
+
+ public final String XAML_STATICRESOURCES = "StaticResource";
+
+ public final String XAML_DYNAMICRESOURCES = "DynamicResource";
+
+ public final String XAML_BINDING = "Binding";
+
+ public final String XML_NS = "xmlns";
+
+ public static final String XWT_NAMESPACE = "http://www.eclipse.org/xwt/presentation";
+
+ public static final String XWT_X_NAMESPACE = "http://www.eclipse.org/xwt";
+
+ public static final String XWT_EXTENSION = "xwt";
+
+ public static final String XWT_EXTENSION_SUFFIX = "." + XWT_EXTENSION;
+
+ public static final Enumeration<URL> EMPTY_ENUMERATION = new Enumeration<URL>() {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Enumeration#hasMoreElements()
+ */
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Enumeration#nextElement()
+ */
+ public URL nextElement() {
+ return null;
+ }
+ };
+
+ public static final ResourceBundle EMPTY_RESOURCE_BUNDLE = new ListResourceBundle() {
+
+ private Object[][] EMPTY = new Object[0][0];
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.ListResourceBundle#getContents()
+ */
+ @Override
+ protected Object[][] getContents() {
+ return EMPTY;
+ }
+ };
+
+ public static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ public static final DocumentObject[] EMPTY_DOCOBJ_ARRAY = new DocumentObject[0];
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBinding.java
new file mode 100644
index 00000000000..eff21832e8a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBinding.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface IDataBinding extends IDataBindingInfo {
+
+ /**
+ * The argument is used to determine the filtering. If type is null, no filtering
+ *
+ * @return
+ */
+ public Object getValue(Class<?> targetType);
+
+ public Object getControl();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBindingInfo.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBindingInfo.java
new file mode 100644
index 00000000000..0464fab681c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataBindingInfo.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.papyrus.xwt.databinding.BindingMode;
+
+public interface IDataBindingInfo {
+
+ public IDataProvider getDataProvider();
+
+ BindingMode getMode();
+
+ IValueConverter getConverter();
+
+ IValidationRule[] getValidators();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProvider.java
new file mode 100644
index 00000000000..81b0dab980c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProvider.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.property.value.IValueProperty;
+
+/**
+ * A Data Binding provider defines the nature of Data Binding such as Bean Object Binding, EMF Object Binding, XML data Binding or Data Base binding
+ *
+ * @author yyang
+ */
+public interface IDataProvider {
+
+ /**
+ * Return the data of the provider, this value can be not used for databindings.
+ *
+ * @param path
+ * @return
+ */
+ Object getData(String path);
+
+ /**
+ * Return the data of the provider, this value can be not used for databindings.
+ *
+ * @param path
+ * @return
+ */
+ Object getData(Object target, String path);
+
+ /**
+ * Return the data of the provider, this value can be not used for databindings.
+ *
+ * @param path
+ * @return
+ */
+ void setData(String path, Object value);
+
+ /**
+ * Return the data of the provider, this value can be not used for databindings.
+ *
+ * @param path
+ * @return
+ */
+ void setData(Object target, String path, Object value);
+
+ /**
+ * Return the data type of the provider.lue
+ *
+ * @param path
+ * @return
+ */
+ Object getDataType(String path);
+
+ /**
+ * check if the property is read only.
+ *
+ * @param path
+ * @return
+ */
+ boolean isPropertyReadOnly(String path);
+
+ Object getProperty(String property);
+
+ void setProperty(String property, Object object);
+
+ boolean hasProperty(String property);
+
+ void removeProperty(String property);
+
+ IObservable observe(Object data, String path, Object targetType, int observeKind);
+
+ IValueProperty createValueProperty(Object type, String fullPath);
+
+ interface DataModelService {
+
+ /**
+ * get the type of this object
+ *
+ * @param object
+ * @return
+ */
+ Object toModelType(Object object);
+
+ Object loadModelType(String typeName);
+
+ Object toModelPropertyType(Object object, String propertyName);
+ }
+
+ DataModelService getModelService();
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProviderFactory.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProviderFactory.java
new file mode 100644
index 00000000000..b46e470ea83
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IDataProviderFactory.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface IDataProviderFactory {
+
+ /**
+ * The type of the Data provider
+ *
+ * @return
+ */
+ Class<?> getType();
+
+ /**
+ *
+ * @param dataContext
+ * @return null if this factory doesn't match with the data context
+ */
+ IDataProvider create(Object dataContext);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventConstants.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventConstants.java
new file mode 100644
index 00000000000..e1de975dd5c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventConstants.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+public final class IEventConstants {
+
+ public static final String DATA_PREFIX = "_event.";
+
+ public static final String SUFFIX = "Event";
+
+ public static final String SUFFIX_KEY = "event";
+
+ public static final String PREFIX = "is";
+
+ public static final String KEY_DOWN = "KeyDown";
+
+ public static final String KEY_UP = "KeyUp";
+
+ public static final String[] KEY_GROUP = new String[]{ KEY_DOWN, KEY_UP };
+
+ public static final String XWT_KEY_DOWN = "KeyDown" + SUFFIX;
+
+ public static final String XWT_KEY_UP = "KeyUp" + SUFFIX;
+
+ public static final String MOUSE_DOWN = "MouseDown";
+
+ public static final String MOUSE_UP = "MouseUp";
+
+ public static final String[] MOUSE_GROUP = new String[]{ MOUSE_DOWN, MOUSE_UP };
+
+ public static final String XWT_MOUSE_DOWN = "MouseDown" + SUFFIX;
+
+ public static final String XWT_MOUSE_UP = "MouseUp" + SUFFIX;
+
+ public static final String MOUSE_MOVE = "MouseMove";
+
+ public static final String MOUSE_ENTER = "MouseEnter";
+
+ public static final String MOUSE_EXIT = "MouseExit";
+
+ public static final String MOUSE_HOVER = "MouseHover";
+
+ public static final String[] MOUSE_MOVING_GROUP = new String[]{ MOUSE_ENTER, MOUSE_EXIT };
+
+ public static final String XWT_MOUSE_MOVE = "MouseMove" + SUFFIX;
+
+ public static final String XWT_MOUSE_ENTER = "MouseEnter" + SUFFIX;
+
+ public static final String XWT_MOUSE_EXIT = "MouseExit" + SUFFIX;
+
+ public static final String XWT_MOUSE_HOVER = "MouseHover" + SUFFIX;
+
+ public static final String MOUSE_DOUBLE_CLICK = "MouseDoubleClick";
+
+ public static final String XWT_MOUSE_DOUBLE_CLICK = MOUSE_DOUBLE_CLICK + SUFFIX;
+
+ public static final String PAINT = "Paint";
+
+ public static final String MOVE = "Move";
+
+ public static final String RESIZE = "Resize";
+
+ public static final String DISPOSE = "Dispose";
+
+ public static final String XWT_PAINT = "Paint" + SUFFIX;
+
+ public static final String XWT_MOVE = "Move" + SUFFIX;
+
+ public static final String XWT_RESIZE = "Resize" + SUFFIX;
+
+ public static final String XWT_DISPOSE = "Dispose" + SUFFIX;
+
+ public static final String SELECTION = "Selection";
+
+ public static final String DEFAULT_SELECTION = "DefaultSelection";
+
+ public static final String XWT_SELECTION = "Selection" + SUFFIX;
+
+ public static final String XWT_DEFAULT_SELECTION = "DefaultSelection" + SUFFIX;
+
+ public static final String FOCUS_IN = "FocusIn";
+
+ public static final String FOCUS_OUT = "FocusOut";
+
+ public static final String[] FOCUS_GROUP = new String[]{ FOCUS_IN, FOCUS_OUT };
+
+ public static final String XWT_FOCUS_IN = "FocusIn" + SUFFIX;
+
+ public static final String XWT_FOCUS_OUT = "FocusOut" + SUFFIX;
+
+ public static final String EXPAND = "Expand";
+
+ public static final String COLLAPSE = "Collapse";
+
+ public static final String[] EXPAND_GROUP = new String[]{ EXPAND, COLLAPSE };
+
+ public static final String XWT_EXPAND = "Expand" + SUFFIX;
+
+ public static final String XWT_COLLAPSE = "Collapse" + SUFFIX;
+
+ public static final String ICONIFY = "Iconify";
+
+ public static final String DEICONIFY = "Deiconify";
+
+ public static final String CLOSE = "Close";
+
+ public static final String SHOW = "Show";
+
+ public static final String HIDE = "Hide";
+
+ public static final String[] WINDOW_GROUP = new String[]{ ICONIFY, DEICONIFY, CLOSE, SHOW, HIDE };
+
+ public static final String XWT_ICONIFY = "Iconify" + SUFFIX;
+
+ public static final String XWT_DEICONIFY = "Deiconify" + SUFFIX;
+
+ public static final String XWT_CLOSE = "Close" + SUFFIX;
+
+ public static final String XWT_SHOW = "Show" + SUFFIX;
+
+ public static final String XWT_HIDE = "Hide" + SUFFIX;
+
+ public static final String MODIFY = "Modify";
+
+ public static final String VERIFY = "Verify";
+
+ public static final String XWT_MODIFY = "Modify" + SUFFIX;
+
+ public static final String XWT_VERIFY = "Verify" + SUFFIX;
+
+ public static final String ACTIVATE = "Activate";
+
+ public static final String DEACTIVATE = "Deactivate";
+
+ public static final String[] ACTIVATION_GROUP = new String[]{ ACTIVATE, DEACTIVATE };
+
+ public static final String XWT_ACTIVATE = "Activate" + SUFFIX;
+
+ public static final String XWT_DEACTIVATE = "Deactivate" + SUFFIX;
+
+ public static final String HELP = "Help";
+
+ public static final String XWT_HELP = "Help" + SUFFIX;
+
+ public static final String DRAG_SELECT = "DragDetect";
+
+ public static final String XWT_DRAG_SELECT = "DragDetect" + SUFFIX;
+
+ public static final String ARM = "Arm";
+
+ public static final String XWT_ARM = "Arm" + SUFFIX;
+
+ public static final String TRAVERSE = "Traverse";
+
+ public static final String XWT_TRAVERSE = "Traverse" + SUFFIX;
+
+ public static final String HARD_KEY_DOWN = "HardKeyDown";
+
+ public static final String HARD_KEY_UP = "HardKeyUp";
+
+ public static final String[] HARD_KEY = new String[]{ HARD_KEY_DOWN, HARD_KEY_UP };
+
+ public static final String XWT_HARD_KEY_DOWN = "HardKeyDown" + SUFFIX;
+
+ public static final String XWT_HARD_KEY_UP = "HardKeyUp" + SUFFIX;
+
+ public static final String MENU_DETECT = "MenuDetect";
+
+ public static final String XWT_MENU_DETECT = "MenuDetect" + SUFFIX;
+
+ public static final String MOUSE_WHEEL = "MouseWheel";
+
+ public static final String XWT_MOUSE_WHEEL = "MouseWheel" + SUFFIX;
+
+ public static final String SETTINGS = "Settings";
+
+ public static final String XWT_SETTINGS = "Settings" + SUFFIX;
+
+ public static final String ERASE_ITEM = "EraseItem";
+
+ public static final String MEASURE_ITEM = "MeasureItem";
+
+ public static final String XWT_ERASE_ITEM = "EraseItem" + SUFFIX;
+
+ public static final String XWT_MEASURE_ITEM = "MeasureItem" + SUFFIX;
+
+ public static final String PAINT_ITEM = "PaintItem";
+
+ public static final String SET_DATA = "SetData";
+
+ public static final String IME_COMPOSITION = "ImeComposition";
+
+ public static final String XWT_PAINT_ITEM = "PaintItem" + SUFFIX;
+
+ public static final String XWT_SET_DATA = "SetData" + SUFFIX;
+
+ public static final String XWT_IME_COMPOSITION = "ImeComposition" + SUFFIX;
+
+ public static final int XWT_SWT_LOADED = 1025; // SWT custom event
+
+ public static final String XWT_LOADED = "Loaded"; // deprecated
+
+ public static final String XWT_LOADED_EVENT = XWT_LOADED + SUFFIX;
+
+ static public String getEventName(String swtEventName) {
+ return normalize(swtEventName + SUFFIX);
+ }
+
+ static public String normalize(String name) {
+ return name.toLowerCase();
+ }
+
+ static public String getEventPropertyName(String name) {
+ return PREFIX + name + SUFFIX;
+ }
+
+ static public String getEventPropertyDataName(String name) {
+ return DATA_PREFIX + PREFIX + name + SUFFIX;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventGroup.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventGroup.java
new file mode 100644
index 00000000000..3335d307f13
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventGroup.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+/**
+ * This class manages the coordination between events' state
+ *
+ * @author yyang
+ */
+public interface IEventGroup {
+
+ String[] getEventNames();
+
+ /**
+ * Fire the event to update other when an event occurs
+ *
+ * @param object
+ * @param property
+ */
+ void fireEvent(IObservableValueListener manager, IProperty property);
+
+ /**
+ * Register the event
+ *
+ * @param manager
+ * @param property
+ */
+ void registerEvent(IObservableValueListener manager, IProperty property);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventHandler.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventHandler.java
new file mode 100644
index 00000000000..8fe58150c82
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventHandler.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ * This class provides an open solution to manage the events. By default,
+ * XWT uses Java reflection to find the method to handle an event. If the class
+ * specified by <code>x:Class</code> implements this interface, this class can provide
+ * the IEventInvoker for each event.
+ *
+ * @author yyang
+ */
+public interface IEventHandler {
+
+ IEventInvoker getEventInvoker(String name, Class<?> elementType, Class<?> eventType);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventInvoker.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventInvoker.java
new file mode 100644
index 00000000000..84191187fed
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IEventInvoker.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.swt.widgets.Event;
+
+public interface IEventInvoker {
+
+ void invoke(Object sender, Event event);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IIndexedElement.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IIndexedElement.java
new file mode 100644
index 00000000000..c382da8c2ce
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IIndexedElement.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+public interface IIndexedElement {
+
+ void setIndex(Object parent, int index);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILoadingContext.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILoadingContext.java
new file mode 100644
index 00000000000..5544ad0aa06
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILoadingContext.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.net.URL;
+
+public interface ILoadingContext {
+
+ URL getResource(String name);
+
+ String getNamespace();
+
+ Class<?> loadClass(String name);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILogger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILogger.java
new file mode 100644
index 00000000000..1110c2a0fe5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ILogger.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.util.Set;
+
+/**
+ * Looger interface
+ *
+ * @author yyang
+ */
+public interface ILogger {
+
+ void error(Throwable e);
+
+ void error(Throwable e, String message);
+
+ void warning(String message);
+
+ void message(String message);
+
+ // print messages into console view
+ void printInfo(String message, Tracking tracking, Set<Tracking> trackType);
+
+ // add messages
+ void addMessage(String message, Tracking tracking);
+
+ void removeMessage(Tracking tracking);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMetaclassFactory.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMetaclassFactory.java
new file mode 100644
index 00000000000..ed1dab8bbe8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMetaclassFactory.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+
+/**
+ * Metaclass factory provides a customizable Metaclass creation mechanism.
+ *
+ * @author yyang
+ *
+ */
+public interface IMetaclassFactory {
+
+ boolean isFactoryOf(Class<?> type);
+
+ IMetaclass create(Class<?> type, IMetaclass superMetaclass, IXWTLoader xwtLoader);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMultiValueConverter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMultiValueConverter.java
new file mode 100644
index 00000000000..3f0457e4479
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IMultiValueConverter.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ * Data converter used in MultiBinding
+ *
+ * @author yyang
+ *
+ */
+public interface IMultiValueConverter extends IValueConverter {
+
+ Object[] convertBack(Object value);
+
+ Object convert(Object[] value);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/INamespaceHandler.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/INamespaceHandler.java
new file mode 100644
index 00000000000..564132c26bd
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/INamespaceHandler.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * This class defines the public behavior to handle the foreigner namespace
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface INamespaceHandler {
+
+ void handleAttribute(Widget widget, Object target, String name, String value);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IObservableValueListener.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IObservableValueListener.java
new file mode 100644
index 00000000000..bc9591928ee
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IObservableValueListener.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.widgets.Event;
+
+public interface IObservableValueListener {
+
+ void registerValue(IProperty property, IObservableValue observableValue);
+
+ IObservableValue getValue(IProperty property);
+
+ void changeValueHandle(Object object, Event event);
+
+ Object getHost();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IStyle.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IStyle.java
new file mode 100644
index 00000000000..4cc6197feec
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IStyle.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface IStyle {
+
+ /**
+ * The element to apply the style. The argument is an instance created through XML. It can be a Widget, or others such as TableViewer.
+ *
+ * @param target
+ */
+ void applyStyle(Object target);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIExtensionProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIExtensionProvider.java
new file mode 100644
index 00000000000..7cd368fbdc2
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIExtensionProvider.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ * In some UI elements, property data may not be provided in the element it-self.
+ *
+ * @author yyang
+ */
+public interface IUIExtensionProvider {
+
+ Object getExtensionValue(Object item, String propertyName);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIResource.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIResource.java
new file mode 100644
index 00000000000..10a5c2044b9
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IUIResource.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+public interface IUIResource {
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValidationRule.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValidationRule.java
new file mode 100644
index 00000000000..d70cd207823
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValidationRule.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * @author hceylan
+ *
+ */
+public interface IValidationRule extends IValidator {
+
+ public static IValidationRule[] EMPTY_ARRAY = new IValidationRule[0];
+
+ public enum Phase {
+ AfterGet, //
+ AfterConvert, //
+ BeforeSet
+ }
+
+ public enum Direction {
+ SourceToTarget, //
+ TargetToSource, //
+ Both
+ }
+
+ /**
+ * Returns the direction of the validation
+ *
+ * @return {@link Direction} indicating the direction of the validation.
+ * Never null
+ */
+ public Direction getBindingMode();
+
+ /**
+ * Returns the phase this validator applies to
+ *
+ * @return {@link Phase} to indicate the phase of the validation. Never null
+ */
+ public Phase getPhase();
+
+ /**
+ * Determines if the given value is valid.
+ *
+ * @param value
+ * the value to validate
+ * @return a status object indicating whether the validation succeeded {@link IStatus#isOK()} or not. Never null.
+ */
+ public IStatus validateBack(Object value);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValueConverter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValueConverter.java
new file mode 100644
index 00000000000..05ef460142b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IValueConverter.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * For a data binding, the conversion could be bidirectional. The standard IConverter is not enough. This class is designed to meet this requirement.
+ *
+ * @author yyang
+ *
+ */
+public interface IValueConverter extends IConverter {
+
+ Object convertBack(Object value);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTInitializer.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTInitializer.java
new file mode 100644
index 00000000000..9171407caa8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTInitializer.java
@@ -0,0 +1,8 @@
+package org.eclipse.papyrus.xwt;
+
+public interface IXWTInitializer {
+
+ void initialize(IXWTLoader loader);
+
+ boolean isInitialized();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTLoader.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTLoader.java
new file mode 100644
index 00000000000..48154aeb3e9
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/IXWTLoader.java
@@ -0,0 +1,767 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.callback.IBeforeParsingCallback;
+import org.eclipse.papyrus.xwt.callback.ICreatedCallback;
+import org.eclipse.papyrus.xwt.callback.ILoadedCallback;
+import org.eclipse.papyrus.xwt.core.TriggerBase;
+import org.eclipse.papyrus.xwt.databinding.BindingContext;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+import org.eclipse.papyrus.xwt.input.ICommand;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * XWT loader interface
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface IXWTLoader {
+
+ // Properties
+
+ /**
+ * The URL which open XWT file
+ *
+ */
+ String URL_PROPERTY = "XWT.URL";
+
+ /**
+ * style of type int is used to create SWT element
+ */
+ String CONTAINER_PROPERTY = "XWT.Container";
+
+ String INIT_STYLE_PROPERTY = "XWT.Style";
+
+ /**
+ * Used for editor/designer to pass design mode
+ */
+ String DESIGN_MODE_PROPERTY = "XWT.DesignMode";
+
+ /**
+ * Default styles to apply. The value should be a collection or Array of
+ * IStyle
+ *
+ */
+ String DEFAULT_STYLES_PROPERTY = "XWT.DefaultStyles";
+
+ /**
+ * Enabled or disabled the styles. By default, it is enabled
+ *
+ */
+ String DISABLE_STYLES_PROPERTY = "XWT.DisabledStyles";
+
+ /**
+ * The DataContext to setup in root element
+ *
+ */
+ String DATACONTEXT_PROPERTY = "XWT.DataContext";
+
+ /**
+ * The BindingContext to setup in root element
+ *
+ */
+ String BINDING_CONTEXT_PROPERTY = "XWT.BindingContext";
+
+ /**
+ * The CLR class
+ *
+ */
+ String CLASS_PROPERTY = "XWT.Class";
+
+ /**
+ * The CLR class factory
+ *
+ */
+ String CLASS_FACTORY_PROPERTY = "XWT.ClassFactory";
+
+ /**
+ * Resources to associate to root element
+ *
+ */
+ String RESOURCE_DICTIONARY_PROPERTY = "XWT.Resources";
+
+ /**
+ * Resources to associate to root element
+ *
+ */
+ String LOADED_CALLBACK = ILoadedCallback.class.getName();
+
+ /**
+ * Action to invoke after the creation of each UI element before the properties setting
+ *
+ */
+ String CREATED_CALLBACK = ICreatedCallback.class.getName();
+
+ /**
+ * Action to invoke before parsing the XML file
+ *
+ */
+ String BEFORE_PARSING_CALLBACK = IBeforeParsingCallback.class.getName();
+
+ String[] ALL_PROPERTIES = { URL_PROPERTY, CONTAINER_PROPERTY, INIT_STYLE_PROPERTY, DATACONTEXT_PROPERTY, BINDING_CONTEXT_PROPERTY, RESOURCE_DICTIONARY_PROPERTY, CLASS_PROPERTY, CLASS_FACTORY_PROPERTY, LOADED_CALLBACK, CREATED_CALLBACK, BEFORE_PARSING_CALLBACK, DESIGN_MODE_PROPERTY };
+
+ /**
+ * Register an Observable IChangeListener for a given UI element. The second
+ * registration of the same listener on the same UI Element has no effect.
+ *
+ * @param control
+ * @param listener
+ * @return
+ */
+ boolean addObservableChangeListener(Object control, IChangeListener listener);
+
+ /**
+ * Undo the registration of the Observable IChangeListener for a given UI
+ * element.
+ *
+ * @param context
+ * @param listener
+ */
+ void removeObservableChangeListener(Object context, IChangeListener listener);
+
+ /**
+ * Find the used IObservable value for given data.
+ *
+ * @param nsmapace
+ * @return
+ */
+ IObservable observe(Object context, Object data, String propertyName, UpdateSourceTrigger updateSourceTrigger);
+
+ /**
+ * Find the used IObservableFactory value for given data.
+ *
+ * @param nsmapace
+ * @return
+ */
+ IObservableFactory observableFactory(Object context, String propertyName, UpdateSourceTrigger updateSourceTrigger);
+
+ /**
+ * Find the used IObservableValue value for given data.
+ *
+ * @param nsmapace
+ * @return
+ */
+ IObservableValue observableValue(Object context, Object data, String propertyName, UpdateSourceTrigger updateSourceTrigger);
+
+ /**
+ * Find the used IObservableList value for given data.
+ *
+ * @param nsmapace
+ * @return
+ */
+ IObservableList findObservableList(Object context, Object data, String propertyName);
+
+ /**
+ * Find the used IObservableList value for given data.
+ *
+ * @param nsmapace
+ * @return
+ */
+ IObservableSet findObservableSet(Object context, Object data, String propertyName);
+
+ /**
+ * Find the used IObservableValue value for given data.
+ *
+ * @param context
+ * @param data
+ * @param propertyName
+ * @return
+ */
+ IObservableValue findObservableValue(Object context, Object data, String propertyName);
+
+ /**
+ * Find the resource in Resources Dictionary attached in the UI Element.
+ * If the key isn't found, the research will be propagated in its parent.
+ *
+ * @param object
+ * @param key
+ * @return
+ */
+ Object findResource(Object object, String key);
+
+ /**
+ * Get the Resources Dictionary attached in the UI Element.
+ *
+ * @param object
+ * @return
+ */
+ Map<String, Object> getResources(Object object);
+
+ /**
+ *
+ * @param nsmapace
+ * @param handler
+ */
+ void registerNamespaceHandler(String nsmapace, INamespaceHandler handler);
+
+ /**
+ *
+ * @param nsmapace
+ */
+ void unregisterNamespaceHandler(String nsmapace);
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ INamespaceHandler getNamespaceHandler(String nsmapace);
+
+ /**
+ *
+ * @return
+ */
+ Realm getRealm();
+
+ /**
+ * Get the system logger.
+ *
+ * @return
+ */
+ ILogger getLogger();
+
+ /**
+ * Change the system logger
+ *
+ * @param logger
+ */
+ void setLogger(ILogger log);
+
+ /**
+ * This namespace service returns the associated or declared namespace for a
+ * given class.
+ *
+ * @param javaclass
+ * @return
+ */
+ String getNamespace(Class<?> javaclass);
+
+ /**
+ * Get the name of the element, which is defined by <code>Name</code> or <code>x:Name</code>. Return <code>null</code>
+ *
+ * @param object
+ * @return
+ */
+ String getElementName(Object object);
+
+ /**
+ * Find a named UI element.
+ *
+ * @param context
+ * the start point of research.
+ * @param name
+ * @return
+ */
+ Object findElementByName(Object context, String name);
+
+ /**
+ * Get the DataContext of given element
+ *
+ * @param context
+ * @return
+ */
+ Object getDataContext(Object element);
+
+ /**
+ * Get the Triggers of given element
+ *
+ * @param context
+ * @return
+ */
+ TriggerBase[] getTriggers(Object element);
+
+ /**
+ * Change the DataContext of given element
+ *
+ * @param context
+ * @return
+ */
+ void setDataContext(Object widget, Object dataContext);
+
+ /**
+ * Changes the default data context of given element
+ *
+ * @param widget
+ * @param dataBindingContext
+ */
+ void setDataBindingContext(Object widget, Object dataBindingContext);
+
+ /**
+ * Change the Triggers of given element
+ *
+ * @param context
+ * @return
+ */
+ void setTriggers(Object widget, TriggerBase[] triggers);
+
+ /**
+ * Find the closet parent of type Composite
+ *
+ * @param context
+ * @return
+ */
+ Composite findCompositeParent(Object context);
+
+ /**
+ * Get the Metaclass of the given object
+ *
+ * @param context
+ * @return
+ */
+ IMetaclass getMetaclass(Object object);
+
+ /**
+ * Load the file content. All widget will be created but they are showed.
+ * This method return the root element.
+ *
+ */
+ Object load(URL file) throws Exception;
+
+ /**
+ * Load the file content with a DataContext. All widget will be created but
+ * they are showed. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ Object load(URL file, Object dataContext) throws Exception;
+
+ Object load(IUIResource resource, Object dataContext) throws Exception;
+
+ /**
+ * Load the file content under a UI Object. All widget will be created. This
+ * method returns the root element. The DataContext will be associated to
+ * the root element.
+ */
+ Object load(Object parent, URL file) throws Exception;
+
+ /**
+ * Load the file content under a UI Object. All widget will be created. This
+ * method returns the root element. The DataContext will be associated to
+ * the root element.
+ */
+ Object load(Object parent, IUIResource resource) throws Exception;
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ Object load(Object parent, URL file, Object dataContext) throws Exception;
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ Object load(Object parent, IUIResource resource, Object dataContext) throws Exception;
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ Object load(Object parent, IUIResource resource, Map<String, Object> options) throws Exception;
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ Object load(Object parent, Class<?> viewType, Object dataContext) throws Exception;
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ Object loadWithOptions(Class<?> viewType, Map<String, Object> options) throws Exception;
+
+ /**
+ * Open and show the file content in a new Shell.
+ */
+ void open(Class<?> type) throws Exception;
+
+ /**
+ * Open and show the file content in a new Shell.
+ */
+ void open(URL url) throws Exception;
+
+ void open(IUIResource resource) throws Exception;
+
+ /**
+ * load the content from a stream with a style, a DataContext and a
+ * ResourceDictionary. The root elements will be hold by UI Object parent
+ */
+ Object load(Object parent, InputStream stream, URL file, Object dataContext) throws Exception;
+
+ /**
+ * load the file content. The corresponding UI element is not yet created
+ */
+ void open(URL url, Object dataContext) throws Exception;
+
+ void open(IUIResource resource, Object dataContext) throws Exception;
+
+ /**
+ * load the file content. The corresponding UI element is not yet created
+ */
+ void open(Class<?> type, Object dataContext) throws Exception;
+
+ /**
+ * load the file content. The corresponding UI element is not yet created
+ */
+ void open(URL url, Map<String, Object> options) throws Exception;
+
+ void open(IUIResource resource, final Map<String, Object> options) throws Exception;
+
+ /**
+ * Data conversion service from String to a given type
+ *
+ * @param type
+ * @param string
+ * @return
+ */
+ Object convertFrom(IMetaclass type, String string);
+
+ /**
+ * Data conversion service from String to a given type
+ *
+ * @param targetType
+ * @param string
+ * @return
+ */
+ Object convertFrom(Class<?> targetType, String string);
+
+ Object loadWithOptions(URL url, Map<String, Object> options) throws Exception;
+
+ /**
+ *
+ * @param stream
+ * @param url
+ * @param options
+ * @return
+ * @throws Exception
+ */
+ Object load(InputStream stream, URL url) throws Exception;
+
+ Object load(IUIResource resource) throws Exception;
+
+ public IUIResource loadAsResource(InputStream stream, URL input) throws Exception;
+
+ public IUIResource loadAsResource(InputStream stream, URL input, IBeforeParsingCallback parsingCallback) throws Exception;
+
+ public IUIResource loadAsResource(URL input) throws Exception;
+
+ public IUIResource loadAsResource(URL input, IBeforeParsingCallback parsingCallback) throws Exception;
+
+ /**
+ * Generic load method
+ *
+ * @param stream
+ * @param url
+ * @param loadData
+ * @return
+ * @throws Exception
+ */
+ Object loadWithOptions(InputStream stream, URL url, Map<String, Object> options) throws Exception;
+
+ Object loadWithOptions(IUIResource resource, Map<String, Object> options) throws Exception;
+
+ /**
+ * Metaclass services to return all registered Metaclasses.
+ *
+ * @param stream
+ * @param url
+ * @param loadData
+ * @return
+ * @throws Exception
+ */
+ IMetaclass[] getAllMetaclasses();
+
+ /**
+ * Get the corresponding Metaclass
+ *
+ * @param tagName
+ * @param ns
+ * The namespace
+ * @return
+ */
+ IMetaclass getMetaclass(String tagName, String ns);
+
+ /**
+ * Register UI type
+ *
+ * @param javaclass
+ */
+ IMetaclass registerMetaclass(Class<?> type);
+
+ /**
+ * Register UI type
+ *
+ * @param javaclass
+ */
+ void registerMetaclass(IMetaclass type);
+
+ /**
+ * Get the dynamic property value
+ *
+ * @param javaclass
+ */
+ Object getPropertyValue(Object uiElement, IProperty property);
+
+ /**
+ * Set the dynamic property value
+ *
+ * @param javaclass
+ */
+ void setPropertyValue(Object uiElement, IProperty property, Object value);
+
+ /**
+ * Remove the dynamic property value
+ *
+ * @param javaclass
+ */
+ void removePropertyValue(Object uiElement, IProperty property);
+
+ /**
+ * Remove the dynamic property value
+ *
+ * @param javaclass
+ */
+ boolean hasPropertyValue(Object uiElement, IProperty property);
+
+ /**
+ * Register Metaclass factory
+ *
+ * @param javaclass
+ */
+ void registerMetaclassFactory(IMetaclassFactory metaclassFactory);
+
+ /**
+ * Find a Data converter
+ *
+ * @param converter
+ * @param type
+ */
+ IConverter findConvertor(Class<?> source, Class<?> target);
+
+ /**
+ * Register a Data converter
+ *
+ * @param converter
+ * @param type
+ */
+ void registerConvertor(IConverter converter);
+
+ /**
+ * Add a tracking option
+ *
+ * @param tracking
+ */
+ void addTracking(Tracking tracking);
+
+ /**
+ * Test if the tracking on argument is enabled.
+ *
+ * @param tracking
+ * @return
+ */
+ boolean isTracking(Tracking tracking);
+
+ /**
+ * Get all tracking options
+ *
+ * @return
+ */
+ Set<Tracking> getTrackings();
+
+ /**
+ * Remove a tracking option.
+ *
+ * @param tracking
+ */
+ void removeTracking(Tracking tracking);
+
+ /**
+ * Register a command to a name
+ *
+ * @param name
+ * @param command
+ */
+ void registerCommand(String name, ICommand command);
+
+ /**
+ * Register a command to a name
+ *
+ * @param name
+ * @param command
+ */
+ void registerEventGroup(Class<?> type, IEventGroup eventGroup);
+
+ /**
+ * Find a command by name
+ *
+ * @param name
+ * @return
+ */
+ ICommand getCommand(String name);
+
+ /**
+ * Return all registered commands
+ *
+ * @return
+ */
+ Map<String, ICommand> getCommands();
+
+ /**
+ * Unregister a command
+ *
+ * @param name
+ */
+ void unregisterCommand(String name);
+
+ /**
+ * Add a default style
+ *
+ * @param style
+ * @return
+ */
+ void addDefaultStyle(IStyle style);
+
+ /**
+ * Remove a default style
+ *
+ * @param style
+ * @return
+ */
+ void removeDefaultStyle(IStyle style);
+
+ Collection<IStyle> getDefaultStyles();
+
+ void addDataProviderFactory(String name, IDataProviderFactory dataProviderFactory);
+
+ void removeDataProviderFactory(String name);
+
+ void removeDataProviderFactory(IDataProviderFactory dataProvider);
+
+ Collection<IDataProviderFactory> getDataProviderFactories();
+
+ IDataProvider findDataProvider(Object dataContext);
+
+ ILoadingContext findLoadingContext(Object container);
+
+ ILoadingContext getLoadingContext(Object object);
+
+ ILoadingContext getLoadingContext();
+
+ void setLoadingContext(ILoadingContext loadingContext);
+
+ /**
+ * Create a UI Profile with the provide data and apply it immediately.
+ *
+ * @param profileData
+ * @return
+ */
+ public Object createUIProfile();
+
+ /**
+ * Put the Profile in place
+ *
+ * @param profile
+ * @return
+ */
+ public boolean applyProfile(Object profile);
+
+ /**
+ * Restore the previous profile
+ *
+ * @return
+ */
+ public Object restoreProfile();
+
+ /**
+ * Set up the default ICLRFactory
+ *
+ * @param factory
+ */
+ public void setCLRFactory(ICLRFactory factory);
+
+ /**
+ * The default CLRFactory.
+ *
+ * @return
+ */
+ public ICLRFactory getCLRFactory();
+
+ /**
+ * Returns the {@link BindingContext} of the element
+ *
+ * @param element
+ * @param contextName
+ * @return
+ */
+ IBindingContext getBindingContext(Object element);
+
+ /**
+ * Check if the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ boolean isFileResolveType(Class<?> type);
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ void registerFileResolveType(Class<?> type);
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ void unregisterFileResolveType(Class<?> type);
+
+ public class Utilities {
+
+ public static boolean isPropertyName(String name) {
+ for(String propertyName : ALL_PROPERTIES) {
+ if(propertyName.equalsIgnoreCase(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/InverseValueConverter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/InverseValueConverter.java
new file mode 100644
index 00000000000..7270d39e7e2
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/InverseValueConverter.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ * The operation to inverse the converter direction.
+ *
+ * @author yyang
+ *
+ */
+public class InverseValueConverter implements IValueConverter {
+
+ private IValueConverter source;
+
+ public InverseValueConverter(IValueConverter source) {
+ this.source = source;
+ }
+
+ public Object convertBack(Object value) {
+ return source.convert(value);
+ }
+
+ public Object convert(Object fromObject) {
+ return source.convertBack(fromObject);
+ }
+
+ public Object getFromType() {
+ return source.getToType();
+ }
+
+ public Object getToType() {
+ return source.getFromType();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ResourceDictionary.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ResourceDictionary.java
new file mode 100644
index 00000000000..f0757517425
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/ResourceDictionary.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.util.HashMap;
+
+public class ResourceDictionary extends HashMap<String, Object> {
+
+ /**
+ * Copyright (c) 2006, 2010 Soyatec
+ */
+ private static final long serialVersionUID = 6913227814340840893L;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/Tracking.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/Tracking.java
new file mode 100644
index 00000000000..a25a3ee9060
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/Tracking.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt;
+
+public enum Tracking {
+ DATABINDING, NAME;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWT.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWT.java
new file mode 100644
index 00000000000..f43296217c7
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWT.java
@@ -0,0 +1,1080 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ * Anyware-tech - add multiple loaders
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.callback.IBeforeParsingCallback;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.core.TriggerBase;
+import org.eclipse.papyrus.xwt.databinding.BindingContext;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+import org.eclipse.papyrus.xwt.input.ICommand;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * XWT is the main class of the XWT framework. It provides most of the services
+ * in API.
+ *
+ * @author yyang
+ */
+public class XWT {
+
+ private static List<IXWTInitializer> initializers = new ArrayList<IXWTInitializer>();
+
+ private static Thread displayThread;
+
+ private static final Object displayLock = new Object();
+
+ /**
+ * Get the system logger.
+ *
+ * @returnF
+ */
+ public static ILogger getLogger() {
+ return XWTLoaderManager.getActive().getLogger();
+ }
+
+ /**
+ * Create a UI Profile with the provide data and apply it immediately.
+ *
+ * @param profileData
+ * @return
+ */
+ public static Object createUIProfile() {
+ return XWTLoaderManager.getActive().createUIProfile();
+ }
+
+ /**
+ * Put the Profile in place
+ *
+ * @param profile
+ * @return
+ */
+ public static boolean applyProfile(Object profile) {
+ return XWTLoaderManager.getActive().applyProfile(profile);
+ }
+
+ /**
+ * Restore the previous profile
+ *
+ * @return
+ */
+ public static Object restoreProfile() {
+ return XWTLoaderManager.getActive().restoreProfile();
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @param handler
+ */
+ public static void registerNamespaceHandler(String nsmapace, INamespaceHandler handler) {
+ XWTLoaderManager.getActive().registerNamespaceHandler(nsmapace, handler);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ */
+ public static void unregisterNamespaceHandler(String nsmapace) {
+ XWTLoaderManager.getActive().unregisterNamespaceHandler(nsmapace);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public static INamespaceHandler getNamespaceHandler(String nsmapace) {
+ return XWTLoaderManager.getActive().getNamespaceHandler(nsmapace);
+ }
+
+ /**
+ * Register an Observable IChangeListener for a given UI element. The second
+ * registration of the same listener on the same UI Element has no effect.
+ *
+ * @param context
+ * @param listener
+ * @return
+ */
+ public static boolean addObservableChangeListener(Object context, IChangeListener listener) {
+ return XWTLoaderManager.getActive().addObservableChangeListener(context, listener);
+ }
+
+ /**
+ * Undo the registration of the Observable IChangeListener for a given UI
+ * element.
+ *
+ * @param context
+ * @param listener
+ */
+ public static void removeObservableChangeListener(Object context, IChangeListener listener) {
+ XWTLoaderManager.getActive().removeObservableChangeListener(context, listener);
+ }
+
+ /**
+ * Find an existing IObservableValue
+ *
+ * @param nsmapace
+ * @return null if it doesn't exist.
+ */
+ public static IObservableValue findObservableValue(Object context, Object data, String propertyName) {
+ return XWTLoaderManager.getActive().findObservableValue(context, data, propertyName);
+ }
+
+ /**
+ * Find an existing IObservableValue
+ *
+ * @param nsmapace
+ * @return null if it doesn't exist.
+ */
+ public static IObservableList findObservableList(Object context, Object data, String propertyName) {
+ return XWTLoaderManager.getActive().findObservableList(context, data, propertyName);
+ }
+
+ /**
+ * Find an existing IObservableValue
+ *
+ * @param nsmapace
+ * @return null if it doesn't exist.
+ */
+ public static IObservableSet findObservableSet(Object context, Object data, String propertyName) {
+ return XWTLoaderManager.getActive().findObservableSet(context, data, propertyName);
+ }
+
+ /**
+ * get or create a IObservableValue
+ *
+ * @param nsmapace
+ * @return return null or raises an exception XWTException if fails
+ */
+ public static IObservableValue observableValue(Object context, Object data, String propertyName, UpdateSourceTrigger updateSourceTrigger) {
+ return XWTLoaderManager.getActive().observableValue(context, data, propertyName, updateSourceTrigger);
+ }
+
+ /**
+ * get or create a IObservable
+ *
+ * @param nsmapace
+ * @return return null or raises an exception XWTException if fails
+ */
+ public static IObservable observe(Object context, Object data, String propertyName, UpdateSourceTrigger updateSourceTrigger) {
+ return XWTLoaderManager.getActive().observe(context, data, propertyName, updateSourceTrigger);
+ }
+
+ /**
+ * get or create a IObservable
+ *
+ * @param nsmapace
+ * @return return null or raises an exception XWTException if fails
+ */
+ public static IObservableFactory observableFactory(Object context, String propertyName, UpdateSourceTrigger updateSourceTrigger) {
+ return XWTLoaderManager.getActive().observableFactory(context, propertyName, updateSourceTrigger);
+ }
+
+ /**
+ * get or create a IObservableValue
+ *
+ * @param nsmapace
+ * @return return null or raises an exception XWTException if fails
+ */
+ public static IObservableValue observableValue(Object context, Object data, String propertyName) {
+ return XWTLoaderManager.getActive().observableValue(context, data, propertyName, UpdateSourceTrigger.Default);
+ }
+
+ /**
+ * Change the system logger
+ *
+ * @param logger
+ */
+ public static void setLogger(ILogger log) {
+ XWTLoaderManager.getActive().setLogger(log);
+ }
+
+ /**
+ * Get the name of the element, which is defined by <code>Name</code> or <code>x:Name</code>. Return <code>null</code>
+ *
+ * @param object
+ * @return
+ */
+ public static String getElementName(Object object) {
+ return XWTLoaderManager.getActive().getElementName(object);
+ }
+
+ /**
+ * Find a named UI element.
+ *
+ * @param context
+ * the start point of research.
+ * @param name
+ * @return
+ */
+ public static Object findElementByName(Object context, String name) {
+ return XWTLoaderManager.getActive().findElementByName(context, name);
+ }
+
+ /**
+ * Get the DataContext of given element
+ *
+ * @param context
+ * @return
+ */
+ public static Object getDataContext(Object element, Class<?> targetType) {
+ Object value = XWTLoaderManager.getActive().getDataContext(element);
+ if(targetType == null || !targetType.isInstance(value)) {
+ if(value instanceof IBinding) {
+ return ((IBinding)value).getValue(targetType);
+ }
+ if(value instanceof IObservableValue) {
+ return ((IObservableValue)value).getValue();
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Returns the {@link BindingContext} within the upper scope of the control.
+ * <p>
+ * Each UI Element may have a local DataBindingContext property. While locating DataBindingContext, if the current UI Element has not the
+ * property, the parent's will be used.
+ * <p>
+ * If none is found, a default one will be created as default for the current scope
+ * <p>
+ * If still not found {@link XWTException} thrown...
+ *
+ * @param element
+ * @return
+ */
+ public static IBindingContext getBindingContext(Object element) {
+ return XWTLoaderManager.getActive().getBindingContext(element);
+ }
+
+ /**
+ * Get the DataContext of given element
+ *
+ * @param context
+ * @return
+ */
+ public static Object getDataContext(Object element) {
+ return getDataContext(element, null);
+ }
+
+ /**
+ * Set the DataContext of given element
+ *
+ * @param context
+ * @return
+ */
+ public static void setDataContext(Object element, Object dataContext) {
+ XWTLoaderManager.getActive().setDataContext(UserData.getWidget(element), dataContext);
+ }
+
+ /**
+ * Get the Triggers of given element
+ *
+ * @param context
+ * @return
+ */
+ public static TriggerBase[] getTriggers(Widget element) {
+ return XWTLoaderManager.getActive().getTriggers(element);
+ }
+
+ /**
+ * Get the Triggers of given element
+ *
+ * @param context
+ * @return
+ */
+ public static void setTriggers(Widget element, TriggerBase[] triggers) {
+ XWTLoaderManager.getActive().setTriggers(element, triggers);
+ }
+
+ /**
+ * Get the CLR (Common Language Runtime) object. If no CLR object is found
+ * in this element, the research will be propagated in it parent.
+ *
+ * @param widget
+ * @return
+ */
+ public static Object getCLR(Object widget) {
+ return UserData.getCLR(widget);
+ }
+
+ /**
+ * Find the root shell
+ *
+ * @param context
+ * @return
+ */
+ public static Shell findShell(Object context) {
+ return UserData.findShell(context);
+ }
+
+ public static IProperty findProperty(Object object, String name) {
+ IMetaclass metaclass = XWTLoaderManager.getActive().getMetaclass(object);
+ return metaclass.findProperty(name);
+ }
+
+ public static Object findResource(Object object, String name) {
+ return XWTLoaderManager.getActive().findResource(object, name);
+ }
+
+ public static Map<String, Object> getResources(Object object) {
+ return XWTLoaderManager.getActive().getResources(object);
+ }
+
+ public static IEvent findEvent(Object object, String name) {
+ IMetaclass metaclass = XWTLoaderManager.getActive().getMetaclass(object);
+ return metaclass.findEvent(name);
+ }
+
+ public static IMetaclass getMetaclass(Object object) {
+ return XWTLoaderManager.getActive().getMetaclass(object);
+ }
+
+ /**
+ * Load the file content. All widget will be created but they are showed.
+ * This method return the root element.
+ *
+ */
+ static public Object load(URL file) throws Exception {
+ XWT.checkInitialization();
+ return XWTLoaderManager.getActive().load(file);
+ }
+
+ /**
+ * Load the content from IUIResource. All widget will be created but they
+ * are showed. This method return the root element.
+ *
+ */
+ static public Object load(IUIResource resource) throws Exception {
+ XWT.checkInitialization();
+ return XWTLoaderManager.getActive().load(resource);
+ }
+
+ /**
+ * Load the file content. All widget will be created but they are showed.
+ * This method return the root element.
+ *
+ */
+ static public Object load(URL file, Object dataContext) throws Exception {
+ XWT.checkInitialization();
+ return XWTLoaderManager.getActive().load(file, dataContext);
+ }
+
+ /**
+ * Load the content from IUIResource. All widget will be created but they
+ * are showed. This method return the root element.
+ *
+ */
+ static public Object load(IUIResource resource, Object dataContext) throws Exception {
+ XWT.checkInitialization();
+ return XWTLoaderManager.getActive().load(resource, dataContext);
+ }
+
+ /**
+ * Load the file content under a UI Object. All widget will be created. This
+ * method returns the root element. The DataContext will be associated to
+ * the root element.
+ */
+ static public Object load(Object parent, URL file) throws Exception {
+ return XWTLoaderManager.getActive().load(parent, file);
+ }
+
+ /**
+ * Load the file content under a UI Object. All widget will be created. This
+ * method returns the root element. The DataContext will be associated to
+ * the root element.
+ *
+ */
+ static public Object load(Object parent, IUIResource resource) throws Exception {
+ return XWTLoaderManager.getActive().load(parent, resource);
+ }
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ static public Object load(Object parent, URL file, Object dataContext) throws Exception {
+ return XWTLoaderManager.getActive().load(parent, file, dataContext);
+ }
+
+ /**
+ * Load the content from IUIResource.
+ *
+ * @param stream
+ * @param input
+ * @param parsingCallback
+ * null if the callback is not necessary
+ * @return
+ * @throws Exception
+ */
+ static public IUIResource loadAsResource(InputStream stream, URL input, IBeforeParsingCallback parsingCallback) throws Exception {
+ return XWTLoaderManager.getActive().loadAsResource(stream, input, parsingCallback);
+ }
+
+ /**
+ * Load the content from IUIResource.
+ *
+ * @param stream
+ * @param input
+ * @param parsingCallback
+ * null if the callback is not necessary
+ * @return
+ * @throws Exception
+ */
+ static public IUIResource loadAsResource(InputStream stream, URL input) throws Exception {
+ return XWTLoaderManager.getActive().loadAsResource(stream, input);
+ }
+
+ /**
+ * Load the content from IUIResource.
+ *
+ * @param input
+ * @param parsingCallback
+ * null if the callback is not necessary
+ * @return
+ * @throws Exception
+ */
+ static public IUIResource loadAsResource(URL input, IBeforeParsingCallback parsingCallback) throws Exception {
+ return XWTLoaderManager.getActive().loadAsResource(null, input, parsingCallback);
+ }
+
+ /**
+ * Load the content from IUIResource.
+ *
+ * @param input
+ * @return
+ * @throws Exception
+ */
+ static public IUIResource loadAsResource(URL input) throws Exception {
+ return XWTLoaderManager.getActive().loadAsResource(null, input);
+ }
+
+ /**
+ * Load the file content under a UI Object with a DataContext. All widget
+ * will be created. This method returns the root element. The DataContext
+ * will be associated to the root element.
+ */
+ static public Object load(Object parent, IUIResource resource, Object dataContext) throws Exception {
+ return XWTLoaderManager.getActive().load(parent, resource, dataContext);
+ }
+
+ static public Object load(Object parent, IUIResource resource, Map<String, Object> options) throws Exception {
+ return XWTLoaderManager.getActive().load(parent, resource, options);
+ }
+
+ /**
+ * Open and show the file content in a new Shell.
+ */
+ static public void open(final URL url) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(url);
+ }
+
+ /**
+ * Open and show the file content in a new Shell.
+ */
+ static public void open(final Class<?> type) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(type);
+ }
+
+ /**
+ * Open and show the file content in a new Shell.
+ */
+ static public void open(final IUIResource resource) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(resource);
+ }
+
+ /**
+ * load the content from a stream with a style, a DataContext and a
+ * ResourceDictionary. The root elements will be hold by UI Object parent
+ */
+ static public Object load(Object parent, InputStream stream, URL file, Object dataContext) throws Exception {
+ return XWTLoaderManager.getActive().load(parent, stream, file, dataContext);
+ }
+
+ /**
+ * load the file content. The corresponding UI element is not yet created
+ */
+ static public void open(URL url, Object dataContext) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(url, dataContext);
+ }
+
+ /**
+ * load the content from IUIResource. The corresponding UI element is not
+ * yet created
+ */
+ static public void open(IUIResource resource, Object dataContext) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(resource, dataContext);
+ }
+
+ /**
+ * load the file content. The corresponding UI element is not yet created
+ */
+ static public void open(Class<?> type, Object dataContext) throws Exception {
+ open(type.getResource(type.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX), dataContext);
+ }
+
+ /**
+ * load the file content. The corresponding UI element is not yet created
+ */
+ static public void open(URL url, Map<String, Object> options) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(url, options);
+ }
+
+ /**
+ * load the content from IUIResource. The corresponding UI element is not
+ * yet created
+ */
+ static public void open(IUIResource resource, Map<String, Object> options) throws Exception {
+ XWT.checkInitialization();
+ XWTLoaderManager.getActive().open(resource, options);
+ }
+
+ static public Object convertFrom(Class<?> targetType, String string) {
+ return XWTLoaderManager.getActive().convertFrom(targetType, string);
+ }
+
+ static public Object loadWithOptions(URL url, Map<String, Object> options) throws Exception {
+ return XWTLoaderManager.getActive().loadWithOptions(url, options);
+ }
+
+ static public Object loadWithOptions(IUIResource resource, Map<String, Object> options) throws Exception {
+ return XWTLoaderManager.getActive().loadWithOptions(resource, options);
+ }
+
+ /**
+ *
+ * @param stream
+ * @param url
+ * @param options
+ * @return
+ * @throws Exception
+ */
+ static public Object load(InputStream stream, URL url) throws Exception {
+ XWT.checkInitialization();
+ return loadWithOptions(stream, url, Collections.<String, Object> emptyMap());
+ }
+
+ /**
+ *
+ * @param stream
+ * @param url
+ * @param options
+ * @return
+ * @throws Exception
+ */
+ static public Object loadWithOptions(InputStream stream, URL url, Map<String, Object> options) throws Exception {
+ XWT.checkInitialization();
+ return XWTLoaderManager.getActive().loadWithOptions(stream, url, options);
+ }
+
+ /**
+ * Metaclass services to return all registered Metaclasses.
+ *
+ * @param stream
+ * @param url
+ * @param loadData
+ * @return
+ * @throws Exception
+ */
+ static public IMetaclass[] getAllMetaclasses() {
+ return XWTLoaderManager.getActive().getAllMetaclasses();
+ }
+
+ /**
+ * Get the corresponding Metaclass
+ *
+ * @param tagName
+ * @param ns
+ * The namespace
+ * @return
+ */
+ static public IMetaclass getMetaclass(String tagName, String ns) {
+ return XWTLoaderManager.getActive().getMetaclass(tagName, ns);
+ }
+
+ /**
+ * Register a Data converter
+ *
+ * @param converter
+ * @param type
+ */
+ public static void registerEventGroup(Class<?> type, IEventGroup eventGroup) {
+ XWTLoaderManager.getActive().registerEventGroup(type, eventGroup);
+ }
+
+ /**
+ * Register a Data converter
+ *
+ * @param converter
+ * @param type
+ */
+ public static void registerConvertor(IConverter converter) {
+ XWTLoaderManager.getActive().registerConvertor(converter);
+ }
+
+ /**
+ * Register a command to a name
+ *
+ * @param name
+ * @param command
+ */
+ public static void registerCommand(String name, ICommand command) {
+ XWTLoaderManager.getActive().registerCommand(name, command);
+ }
+
+ /**
+ * Add a default style
+ *
+ * @param style
+ * @return
+ */
+ public static void addDefaultStyle(IStyle style) {
+ XWTLoaderManager.getActive().addDefaultStyle(style);
+ }
+
+ public static void addDataProviderFactory(String name, IDataProviderFactory dataProviderFactory) {
+ XWTLoaderManager.getActive().addDataProviderFactory(name, dataProviderFactory);
+ }
+
+ public static void removeDataProviderFactory(String name) {
+ XWTLoaderManager.getActive().removeDataProviderFactory(name);
+ }
+
+ public static void removeDataProviderFactory(IDataProviderFactory dataProviderFactory) {
+ XWTLoaderManager.getActive().removeDataProviderFactory(dataProviderFactory);
+ }
+
+ public static Collection<IDataProviderFactory> getDataProviderFactories() {
+ return XWTLoaderManager.getActive().getDataProviderFactories();
+ }
+
+ /**
+ * Register UI type
+ *
+ * @param javaclass
+ */
+ static public IMetaclass registerMetaclass(Class<?> type) {
+ return XWTLoaderManager.getActive().registerMetaclass(type);
+ }
+
+ /**
+ * Register UI type
+ *
+ * @param javaclass
+ */
+ static public void registerMetaclass(IMetaclass type) {
+ XWTLoaderManager.getActive().registerMetaclass(type);
+ }
+
+ /**
+ * Get the dynamic property value
+ *
+ * @param javaclass
+ */
+ static public Object getPropertyValue(Object uiElement, IProperty property) {
+ return XWTLoaderManager.getActive().getPropertyValue(uiElement, property);
+ }
+
+ /**
+ * Get the dynamic property value
+ *
+ * @param javaclass
+ */
+ static public Object getPropertyValue(Object uiElement, String propertyName) {
+ IMetaclass metaclass = XWT.getMetaclass(uiElement);
+ IProperty property = metaclass.findProperty(propertyName);
+ if(property == null) {
+ return null;
+ }
+ return XWTLoaderManager.getActive().getPropertyValue(uiElement, property);
+ }
+
+ /**
+ * Set the dynamic property value
+ *
+ * @param javaclass
+ */
+ static public void setPropertyValue(Object uiElement, IProperty property, Object value) {
+ XWTLoaderManager.getActive().setPropertyValue(uiElement, property, value);
+ }
+
+ /**
+ * Set the dynamic property value
+ *
+ * @param javaclass
+ */
+ static public void setPropertyValue(Object uiElement, String propertyName, Object value) {
+ IMetaclass metaclass = XWT.getMetaclass(uiElement);
+ IProperty property = metaclass.findProperty(propertyName);
+ if(property == null) {
+ throw new XWTException("Property " + propertyName + " not found.");
+ }
+ XWTLoaderManager.getActive().setPropertyValue(uiElement, property, value);
+ }
+
+ /**
+ * Remove the dynamic property value
+ *
+ * @param javaclass
+ */
+ static public void removePropertyValue(Object uiElement, IProperty property) {
+ XWTLoaderManager.getActive().removePropertyValue(uiElement, property);
+ }
+
+ /**
+ * Remove the dynamic property value
+ *
+ * @param javaclass
+ */
+ static public boolean hasPropertyValue(Object uiElement, IProperty property) {
+ return XWTLoaderManager.getActive().hasPropertyValue(uiElement, property);
+ }
+
+ /**
+ * Find a Data converter
+ *
+ * @param converter
+ * @param type
+ */
+ static public IConverter findConvertor(Class<?> source, Class<?> target) {
+ return XWTLoaderManager.getActive().findConvertor(source, target);
+ }
+
+ /**
+ * Switch current loading context
+ *
+ */
+ public static void setLoadingContext(ILoadingContext loadingContext) {
+ XWTLoaderManager.getActive().setLoadingContext(loadingContext);
+ }
+
+ /**
+ * Return current loading context
+ *
+ * @return ILoadingContext
+ */
+ public static ILoadingContext getLoadingContext() {
+ return XWTLoaderManager.getActive().getLoadingContext();
+ }
+
+ /**
+ * Add a tracking option
+ *
+ * @param tracking
+ */
+ static public void addTracking(Tracking tracking) {
+ XWTLoaderManager.getActive().addTracking(tracking);
+ }
+
+ /**
+ * Test if the tracking on argument is enabled.
+ *
+ * @param tracking
+ * @return
+ */
+ static public boolean isTracking(Tracking tracking) {
+ return XWTLoaderManager.getActive().isTracking(tracking);
+ }
+
+ /**
+ * Get all tracking options
+ *
+ * @return
+ */
+ static public Set<Tracking> getTrackings() {
+ return XWTLoaderManager.getActive().getTrackings();
+ }
+
+ /**
+ * Set up the default ICLRFactory
+ *
+ * @param factory
+ */
+ static public void setCLRFactory(ICLRFactory factory) {
+ XWTLoaderManager.getActive().setCLRFactory(factory);
+ }
+
+ static public boolean checkInitialization() {
+ if(isAllInitializersInitialized()) {
+ return false;
+ }
+ return checkInitialization(-1);
+ }
+
+ static public boolean checkInitialization(long timeoutMillis) {
+ long started = System.currentTimeMillis();
+ while(true) {
+ if(timeoutMillis != -1 && System.currentTimeMillis() - started > timeoutMillis) {
+ return false;
+ }
+
+ if(isAllInitializersInitialized()) {
+ return false;
+ }
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ return false;
+ }
+ }
+ }
+
+ private static boolean isAllInitializersInitialized() {
+ synchronized(initializers) {
+ for(IXWTInitializer initializer : initializers) {
+ if(!initializer.isInitialized()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * The default CLRFactory.
+ *
+ * @return
+ */
+ static public ICLRFactory getCLRFactory() {
+ return XWTLoaderManager.getActive().getCLRFactory();
+ }
+
+ /**
+ * Find a command by name
+ *
+ * @param name
+ * @return
+ */
+ static public ICommand getCommand(String name) {
+ return XWTLoaderManager.getActive().getCommand(name);
+ }
+
+ public static IDataProvider findDataProvider(Object dataContext) {
+ return XWTLoaderManager.getActive().findDataProvider(dataContext);
+ }
+
+ static public Realm getRealm() {
+ return XWTLoaderManager.getActive().getRealm();
+ }
+
+ static public boolean isXWTNamespace(String namespace) {
+ return IConstants.XWT_X_NAMESPACE.equals(namespace) || IConstants.XWT_NAMESPACE.equals(namespace) || namespace.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO);
+ }
+
+ /**
+ * Check if the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public static boolean isFileResolveType(Class<?> type) {
+ return XWTLoaderManager.getActive().isFileResolveType(type);
+ }
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public static void registerFileResolveType(Class<?> type) {
+ XWTLoaderManager.getActive().registerFileResolveType(type);
+ }
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public static void unregisterFileResolveType(Class<?> type) {
+ XWTLoaderManager.getActive().unregisterFileResolveType(type);
+ }
+
+ static class DisplayThread extends Thread implements Listener {
+
+ protected long startTime = -1;
+
+ protected boolean toStop = false;
+
+ protected Runnable runnable;
+
+ public DisplayThread(Runnable runnable) {
+ this.runnable = runnable;
+ }
+
+ public void handleEvent(Event event) {
+ }
+ }
+
+ /**
+ * Run in UI context.
+ *
+ * @param runnable
+ */
+ public static void runOnUIThread(final Runnable runnable) {
+ String platform = SWT.getPlatform();
+ if(platform.startsWith("win")) {
+ XWTLoaderManager.getDefault();
+ runnable.run();
+ } else if(platform.startsWith("rap")) {
+ XWTLoaderManager.getDefault();
+ runnable.run();
+ } else if(platform.endsWith("gtk") || platform.endsWith("cocoa")) {
+ synchronized(displayLock) {
+ if(displayThread == null || !displayThread.isAlive()) {
+ try {
+ Field field = Display.class.getDeclaredField("Default");
+ if(field != null) {
+ field.setAccessible(true);
+ Display defaultDisplay = (Display)field.get(null);
+ if(defaultDisplay != null) {
+ displayThread = defaultDisplay.getThread();
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+
+ if(displayThread == null || !displayThread.isAlive()) {
+ displayThread = new Thread() {
+
+ private long startTime = -1;
+
+ private Display display;
+
+ private boolean toStop = false;
+
+ private boolean ignoreNotification = false;
+
+ protected Runnable runnable = new Runnable() {
+
+ public void run() {
+ if(ignoreNotification) {
+ startTime = -1;
+ return;
+ }
+ if(startTime == -1) {
+ startTime = System.currentTimeMillis();
+ } else {
+ if((System.currentTimeMillis() - startTime) > 10000 && display.getActiveShell() == null && display.getShells().length == 0) {
+ toStop = true;
+ display.wake();
+ } else {
+ startTime = System.currentTimeMillis();
+ }
+ }
+ }
+ };
+
+ @Override
+ public void run() {
+ // Set default XWT ICLRFactory
+ XWTLoaderManager.getDefault();
+ display = Display.getDefault();
+ runnable.run();
+ while(true) {
+ if(!display.readAndDispatch()) {
+ display.timerExec(10000, runnable);
+ display.sleep();
+ ignoreNotification = true;
+ }
+ if(toStop) {
+ break;
+ }
+ startTime = -1;
+ }
+ }
+ };
+ displayThread.start();
+ } else {
+ XWTLoaderManager.getDefault();
+ XWT.checkInitialization();
+ Display display = Display.findDisplay(displayThread);
+ if(display != null) {
+ display.syncExec(runnable);
+ }
+ }
+ }
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public static void addInitializer(IXWTInitializer initializer) {
+ synchronized(initializers) {
+ if(!XWTLoaderManager.isStarted()) {
+ initializers.add(initializer);
+ }
+ }
+ }
+
+ static List<IXWTInitializer> getInitializers() {
+ return initializers;
+ }
+
+ public static Object findParent(Object element, Class<?> type) {
+ Widget widget = UserData.getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ return UserData.findParent(widget, type);
+ }
+
+ static void runInitializers(IXWTLoader loader) {
+ synchronized(initializers) {
+ for(IXWTInitializer initializer : XWT.getInitializers()) {
+ initializer.initialize(loader);
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTException.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTException.java
new file mode 100644
index 00000000000..e46b4532f13
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTException.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+public class XWTException extends RuntimeException {
+
+ /**
+ * Copyright (c) 2006, 2010 Soyatec
+ */
+ private static final long serialVersionUID = 7568262060419780948L;
+
+ public XWTException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public XWTException(String message) {
+ super(message);
+ }
+
+ public XWTException(Throwable cause) {
+ super(cause);
+ }
+
+ public XWTException() {
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoader.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoader.java
new file mode 100644
index 00000000000..e354a8e49d5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoader.java
@@ -0,0 +1,1796 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ * Anyware-tech - add multiple loaders
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.conversion.NumberToStringConverter;
+import org.eclipse.core.databinding.conversion.StringToNumberConverter;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.databinding.viewers.ObservableSetContentProvider;
+import org.eclipse.papyrus.xwt.animation.Drawing;
+import org.eclipse.papyrus.xwt.callback.IBeforeParsingCallback;
+import org.eclipse.papyrus.xwt.collection.CollectionViewSource;
+import org.eclipse.papyrus.xwt.converters.BindingToObject;
+import org.eclipse.papyrus.xwt.converters.CollectionToBoolean;
+import org.eclipse.papyrus.xwt.converters.CollectionToInteger;
+import org.eclipse.papyrus.xwt.converters.DateToString;
+import org.eclipse.papyrus.xwt.converters.EnumToString;
+import org.eclipse.papyrus.xwt.converters.IStatusToBoolean;
+import org.eclipse.papyrus.xwt.converters.IStatusToString;
+import org.eclipse.papyrus.xwt.converters.ListToIObservableCollection;
+import org.eclipse.papyrus.xwt.converters.ListToSet;
+import org.eclipse.papyrus.xwt.converters.ObjectToBoolean;
+import org.eclipse.papyrus.xwt.converters.ObjectToISelection;
+import org.eclipse.papyrus.xwt.converters.ObjectToString;
+import org.eclipse.papyrus.xwt.converters.SelectionToBoolean;
+import org.eclipse.papyrus.xwt.converters.SetToIObservableCollection;
+import org.eclipse.papyrus.xwt.converters.StringToBoolean;
+import org.eclipse.papyrus.xwt.converters.StringToColor;
+import org.eclipse.papyrus.xwt.converters.StringToDoubleArray;
+import org.eclipse.papyrus.xwt.converters.StringToFont;
+import org.eclipse.papyrus.xwt.converters.StringToFormAttachment;
+import org.eclipse.papyrus.xwt.converters.StringToIValidationRule;
+import org.eclipse.papyrus.xwt.converters.StringToIValueConverter;
+import org.eclipse.papyrus.xwt.converters.StringToImage;
+import org.eclipse.papyrus.xwt.converters.StringToIntArray;
+import org.eclipse.papyrus.xwt.converters.StringToInteger;
+import org.eclipse.papyrus.xwt.converters.StringToPoint;
+import org.eclipse.papyrus.xwt.converters.StringToRectangle;
+import org.eclipse.papyrus.xwt.converters.StringToType;
+import org.eclipse.papyrus.xwt.converters.StringToURL;
+import org.eclipse.papyrus.xwt.core.Condition;
+import org.eclipse.papyrus.xwt.core.DataTrigger;
+import org.eclipse.papyrus.xwt.core.EventTrigger;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.core.IUserDataConstants;
+import org.eclipse.papyrus.xwt.core.MultiDataTrigger;
+import org.eclipse.papyrus.xwt.core.MultiTrigger;
+import org.eclipse.papyrus.xwt.core.RadioEventGroup;
+import org.eclipse.papyrus.xwt.core.Setter;
+import org.eclipse.papyrus.xwt.core.Style;
+import org.eclipse.papyrus.xwt.core.Trigger;
+import org.eclipse.papyrus.xwt.core.TriggerBase;
+import org.eclipse.papyrus.xwt.databinding.BindingContext;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+import org.eclipse.papyrus.xwt.dataproviders.ObjectDataProvider;
+import org.eclipse.papyrus.xwt.input.ICommand;
+import org.eclipse.papyrus.xwt.internal.core.BindingExpressionPath;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+import org.eclipse.papyrus.xwt.internal.core.MetaclassManager;
+import org.eclipse.papyrus.xwt.internal.core.MultiBinding;
+import org.eclipse.papyrus.xwt.internal.core.ScopeKeeper;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+import org.eclipse.papyrus.xwt.internal.core.UIResource;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.ResourceLoaderFactory;
+import org.eclipse.papyrus.xwt.javabean.ValueConvertorRegister;
+import org.eclipse.papyrus.xwt.javabean.metadata.BindingMetaclass;
+import org.eclipse.papyrus.xwt.javabean.metadata.ComboBoxCellEditorMetaclass;
+import org.eclipse.papyrus.xwt.javabean.metadata.ExpandItemHeightAction;
+import org.eclipse.papyrus.xwt.javabean.metadata.TableEditorMetaclass;
+import org.eclipse.papyrus.xwt.javabean.metadata.TableViewerColumnMetaClass;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.AbstractProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.ColumnViewerColumnsProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.DataProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.DynamicBeanProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.DynamicProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.InputBeanProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.MultiSelectionBeanProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.PropertiesConstants;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.SingleSelectionBeanProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.StyleProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableColumnEditorProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableEditorDynamicProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableItemEditorProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableItemProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableViewerColumnDynamicProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableViewerColumnImageProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableViewerColumnTextProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableViewerColumnWidthProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TriggersProperty;
+import org.eclipse.papyrus.xwt.jface.ComboBoxCellEditor;
+import org.eclipse.papyrus.xwt.jface.DefaultCellModifier;
+import org.eclipse.papyrus.xwt.jface.JFaceInitializer;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.papyrus.xwt.jface.ObservableTreeContentProvider;
+import org.eclipse.papyrus.xwt.jface.ViewerFilter;
+import org.eclipse.papyrus.xwt.metadata.DefaultLoadingType;
+import org.eclipse.papyrus.xwt.metadata.DelegateProperty;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.papyrus.xwt.metadata.IValueLoading;
+import org.eclipse.papyrus.xwt.utils.ResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ControlEditor;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.ExpandItem;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.IME;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.TreeItem;
+
+/**
+ * Default XWT loader
+ *
+ * @author yyang (yves.yang@soyatec.com) jliu (jin.liu@soyatec.com)
+ */
+public class XWTLoader implements IXWTLoader {
+
+ // Declarations
+ private Stack<Core> cores;
+
+ public Realm realm;
+
+ public XWTLoader() {
+ initialize();
+ }
+
+ public Object createUIProfile() {
+ Core core = new Core(new ResourceLoaderFactory(), this);
+ cores.push(core);
+ return core;
+ }
+
+ public boolean applyProfile(Object profile) {
+ if(profile instanceof Core) {
+ if(cores.peek() == profile) {
+ return false;
+ }
+ cores.push((Core)profile);
+ return true;
+ }
+ throw new XWTException("Wrong UI Profile.");
+ }
+
+ public Object restoreProfile() {
+ if(cores.size() > 1) {
+ return cores.pop();
+ }
+ throw new XWTException("No user-defined UI Profile.");
+ }
+
+ public Realm getRealm() {
+ if(realm != null) {
+ return realm;
+ }
+ Display display = Display.getCurrent();
+ if(display == null) {
+ display = Display.getDefault();
+ }
+ return SWTObservables.getRealm(display);
+ }
+
+ protected Core getCurrentCore() {
+ return cores.peek();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getLogger()
+ */
+ public ILogger getLogger() {
+ return getCurrentCore().getLogger();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#setLogger(org.eclipse.papyrus.xwt.ILogger)
+ */
+ public void setLogger(ILogger log) {
+ getCurrentCore().setLogger(log);
+ }
+
+ /**
+ * Get the dynamic property value
+ *
+ * @param javaclass
+ */
+ public Object getPropertyValue(Object uiElement, IProperty property) {
+ return UserData.getLocalData(uiElement, property);
+ }
+
+ /**
+ * Set the dynamic property value
+ *
+ * @param javaclass
+ */
+ public void setPropertyValue(Object uiElement, IProperty property, Object value) {
+ UserData.setLocalData(uiElement, property, value);
+ }
+
+ /**
+ * Remove the dynamic property value
+ *
+ * @param javaclass
+ */
+ public void removePropertyValue(Object uiElement, IProperty property) {
+ UserData.removeLocalData(uiElement, property);
+ }
+
+ /**
+ * Remove the dynamic property value
+ *
+ * @param javaclass
+ */
+ public boolean hasPropertyValue(Object uiElement, IProperty property) {
+ return UserData.hasLocalData(uiElement, property);
+ }
+
+ /**
+ * Register an Observable IChangeListener for a given UI element. The second
+ * registration of the same listener on the same UI Element has no effect.
+ *
+ * @param context
+ * @param listener
+ * @return <code>true</code> the listener is added, <code>false</code> if
+ * the listener already exists
+ */
+ public boolean addObservableChangeListener(Object control, IChangeListener listener) {
+ ScopeKeeper scope = UserData.findScopeKeeper(control);
+ if(scope != null) {
+ return scope.addChangeListener(listener);
+ }
+ return false;
+ }
+
+ /**
+ * Undo the registration of the Observable IChangeListener for a given UI
+ * element.
+ *
+ * @param context
+ * @param listener
+ */
+ public void removeObservableChangeListener(Object control, IChangeListener listener) {
+ ScopeKeeper scope = UserData.findScopeKeeper(control);
+ if(scope != null) {
+ scope.removeChangeListener(listener);
+ }
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public IObservable observe(Object control, Object data, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ return ScopeManager.observe(control, data, new BindingExpressionPath(fullPath), updateSourceTrigger);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public IObservableFactory observableFactory(Object control, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ return ScopeManager.observableFactory(control, new BindingExpressionPath(fullPath), updateSourceTrigger);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public IObservableList findObservableList(Object context, Object data, String fullPath) {
+ return ScopeManager.findObservableList(context, null, data, fullPath);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public IObservableSet findObservableSet(Object context, Object data, String fullPath) {
+ return ScopeManager.findObservableSet(context, null, data, fullPath);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public IObservableValue observableValue(Object control, Object data, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ return ScopeManager.observableValue(control, data, fullPath, updateSourceTrigger);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public IObservableValue findObservableValue(Object context, Object data, String fullPath) {
+ return ScopeManager.findObservableValue(context, null, data, fullPath);
+ }
+
+ /**
+ *
+ */
+ public Object findResource(Object object, String key) {
+ return UserData.findResource(object, key);
+ }
+
+ public Map<String, Object> getResources(Object object) {
+ return UserData.getLocalResources(object);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @param handler
+ */
+ public void registerNamespaceHandler(String nsmapace, INamespaceHandler handler) {
+ getCurrentCore().registerNamespaceHandler(nsmapace, handler);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ */
+ public void unregisterNamespaceHandler(String nsmapace) {
+ getCurrentCore().unregisterNamespaceHandler(nsmapace);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public INamespaceHandler getNamespaceHandler(String nsmapace) {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ INamespaceHandler handler = core.getNamespaceHandler(nsmapace);
+ if(handler != null) {
+ return handler;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getNamespace(java.lang.Class)
+ */
+ public String getNamespace(Class<?> javaclass) {
+ if(getMetaclass(javaclass) != null) {
+ return IConstants.XWT_NAMESPACE;
+ }
+ Package javaPackage = javaclass.getPackage();
+ if(javaPackage == null) {
+ return IConstants.XAML_CLR_NAMESPACE_PROTO;
+ }
+ return IConstants.XAML_CLR_NAMESPACE_PROTO + javaclass.getPackage().getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getElementName(java.lang.Object)
+ */
+ public String getElementName(Object object) {
+ return UserData.getElementName(object);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#findElementByName(org.eclipse.swt.widgets
+ * .Widget, java.lang.String)
+ */
+ public Object findElementByName(Object context, String name) {
+ return UserData.findElementByName(context, name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#getDataBindingContext(java.lang.Object,
+ * java.lang.String)
+ */
+ public IBindingContext getBindingContext(Object element) {
+ IBindingContext dataBindingContext = UserData.getBindingContext(element);
+ if(dataBindingContext == null) {
+ dataBindingContext = UserData.createBindingContext(element);
+ }
+ return dataBindingContext;
+ }
+
+ public ICLRFactory getCLRFactory() {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ ICLRFactory factory = core.getCLRFactory();
+ if(factory != null) {
+ return factory;
+ }
+ }
+ return null;
+ }
+
+ public void setCLRFactory(ICLRFactory clrFactory) {
+ cores.peek().setCLRFactory(clrFactory);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#getDataContext(org.eclipse.swt.widgets.
+ * Widget)
+ */
+ public Object getDataContext(Object element) {
+ return UserData.getDataContext(element);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#getDataContext(org.eclipse.swt.widgets.
+ * Widget)
+ */
+ public TriggerBase[] getTriggers(Object element) {
+ return UserData.getTriggers(element);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#setDataBindingContext(java.lang.Object,
+ * java.lang.Object)
+ */
+ public void setDataBindingContext(Object widget, Object dataBindingContext) {
+ UserData.setBindingContext(widget, dataBindingContext);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#setDataContext(org.eclipse.swt.widgets.
+ * Widget, java.lang.Object)
+ */
+ public void setDataContext(Object widget, Object dataContext) {
+ UserData.setDataContext(widget, dataContext);
+ }
+
+ /**
+ * Get the Triggers of given element
+ *
+ * @param context
+ * @return
+ */
+ public void setTriggers(Object element, TriggerBase[] triggers) {
+ UserData.setTriggers(element, triggers);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#findCompositeParent(org.eclipse.swt.widgets
+ * .Widget)
+ */
+ public Composite findCompositeParent(Object context) {
+ return UserData.findCompositeParent(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getMetaclass(java.lang.Object)
+ */
+ public IMetaclass getMetaclass(Object object) {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ IMetaclass metaclass = core.findMetaclass(object);
+ if(metaclass != null) {
+ return metaclass;
+ }
+ }
+ Class<?> javaClass = null;
+ if(object instanceof Class<?>) {
+ javaClass = (Class<?>)object;
+ } else {
+ javaClass = object.getClass();
+ }
+ Class<?> superclass = javaClass.getSuperclass();
+ IMetaclass superMetaclass = null;
+ if(superclass != null) {
+ superMetaclass = getMetaclass(superclass);
+ }
+ return getCurrentCore().registerMetaclass(javaClass, IConstants.XWT_NAMESPACE, superMetaclass);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#load(java.net.URL)
+ */
+ public Object load(URL file) throws Exception {
+ return loadWithOptions(file, Collections.<String, Object> emptyMap());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#load(java.net.URL, java.lang.Object)
+ */
+ public Object load(URL file, Object dataContext) throws Exception {
+ return load(null, file, dataContext);
+ }
+
+ public Object load(IUIResource resource, Object dataContext) throws Exception {
+ return load(null, resource, dataContext);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#load(org.eclipse.swt.widgets.Composite,
+ * java.net.URL)
+ */
+ public Object load(Object parent, URL file) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(CONTAINER_PROPERTY, parent);
+ return loadWithOptions(file, options);
+ }
+
+ public Object load(Object parent, IUIResource resource) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(CONTAINER_PROPERTY, parent);
+ return loadWithOptions(resource, options);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#load(org.eclipse.swt.widgets.Composite,
+ * java.net.URL, java.lang.Object)
+ */
+ public Object load(Object parent, URL file, Object dataContext) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(CONTAINER_PROPERTY, parent);
+ options.put(DATACONTEXT_PROPERTY, dataContext);
+ return loadWithOptions(file, options);
+ }
+
+ public Object load(Object parent, IUIResource resource, Object dataContext) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(CONTAINER_PROPERTY, parent);
+ options.put(DATACONTEXT_PROPERTY, dataContext);
+ return loadWithOptions(resource, options);
+ }
+
+ public Object load(Object parent, IUIResource resource, Map<String, Object> options) throws Exception {
+ if(options.isEmpty()) {
+ options = new HashMap<String, Object>();
+ }
+ options.put(CONTAINER_PROPERTY, parent);
+ return loadWithOptions(resource, options);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#load(org.eclipse.swt.widgets.Composite,
+ * java.lang.Class, java.lang.Object)
+ */
+ public Object load(Object parent, Class<?> viewType, Object dataContext) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(CONTAINER_PROPERTY, parent);
+ options.put(DATACONTEXT_PROPERTY, dataContext);
+ return loadWithOptions(viewType, options);
+ }
+
+ protected Map<String, Object> prepareOptions(Map<String, Object> options, URL url) {
+ Boolean disabledStyle = (Boolean)options.get(DISABLE_STYLES_PROPERTY);
+ if(!Boolean.TRUE.equals(disabledStyle)) {
+ Collection<IStyle> defaultStyles = getDefaultStyles();
+ Object styles = options.get(DEFAULT_STYLES_PROPERTY);
+ if(styles != null) {
+ if(styles instanceof IStyle) {
+ defaultStyles.add((IStyle)styles);
+ } else if(styles instanceof Collection) {
+ for(Object element : (Collection<?>)styles) {
+ if(element instanceof IStyle) {
+ defaultStyles.add((IStyle)element);
+ } else {
+ throw new XWTException("IStyle is expected in [styles] parameters.");
+ }
+ }
+ } else if(styles instanceof Object[]) {
+ for(Object element : (Object[])styles) {
+ if(element instanceof IStyle) {
+ defaultStyles.add((IStyle)element);
+ } else {
+ throw new XWTException("IStyle is expected in [styles] parameters.");
+ }
+ }
+ }
+ options.remove(DEFAULT_STYLES_PROPERTY);
+ }
+ if(!defaultStyles.isEmpty()) {
+ ResourceDictionary dictionary = (ResourceDictionary)options.get(RESOURCE_DICTIONARY_PROPERTY);
+ if(dictionary == null) {
+ dictionary = new ResourceDictionary();
+ if(options == Collections.EMPTY_MAP) {
+ options = new HashMap<String, Object>();
+ }
+ options.put(RESOURCE_DICTIONARY_PROPERTY, dictionary);
+ }
+ dictionary.put(Core.DEFAULT_STYLES_KEY, defaultStyles);
+ }
+ }
+ // Register URL property
+ if(options == Collections.EMPTY_MAP) {
+ options = new HashMap<String, Object>();
+ }
+ options.put(URL_PROPERTY, url);
+ return options;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#loadWithOptions(java.lang.Class,
+ * java.util.Map)
+ */
+ public Object loadWithOptions(Class<?> viewType, Map<String, Object> options) throws Exception {
+ ILoadingContext context = getLoadingContext();
+ try {
+ setLoadingContext(new DefaultLoadingContext(viewType.getClassLoader()));
+ options = prepareOptions(options, null);
+ return loadWithOptions(viewType.getResource(viewType.getSimpleName() + ".xwt"), options);
+ } finally {
+ setLoadingContext(context);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#open(java.lang.Class)
+ */
+ public void open(Class<?> type) throws Exception {
+ open(type.getResource(type.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX), Collections.emptyMap());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#open(java.net.URL)
+ */
+ public void open(URL url) throws Exception {
+ open(url, Collections.emptyMap());
+ }
+
+ public void open(IUIResource resource) throws Exception {
+ open(resource, Collections.emptyMap());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#load(org.eclipse.swt.widgets.Composite,
+ * java.io.InputStream, java.net.URL, java.lang.Object)
+ */
+ public Object load(Object parent, InputStream stream, URL file, Object dataContext) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(CONTAINER_PROPERTY, parent);
+ options.put(DATACONTEXT_PROPERTY, dataContext);
+ return loadWithOptions(stream, file, options);
+ }
+
+ public IUIResource loadAsResource(InputStream stream, URL input) throws Exception {
+ return loadAsResource(stream, input, null);
+ }
+
+ public IUIResource loadAsResource(InputStream stream, URL input, IBeforeParsingCallback parsingCallback) throws Exception {
+ return getCurrentCore().loadAsResource(stream, input, parsingCallback);
+ }
+
+ public IUIResource loadAsResource(URL input) throws Exception {
+ return loadAsResource(null, input, null);
+ }
+
+ public IUIResource loadAsResource(URL input, IBeforeParsingCallback parsingCallback) throws Exception {
+ return loadAsResource(null, input, parsingCallback);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#open(java.net.URL, java.lang.Object)
+ */
+ public void open(URL url, Object dataContext) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(DATACONTEXT_PROPERTY, dataContext);
+ open(url, options);
+ }
+
+ public void open(IUIResource resource, Object dataContext) throws Exception {
+ HashMap<String, Object> options = new HashMap<String, Object>();
+ options.put(DATACONTEXT_PROPERTY, dataContext);
+ open(resource, options);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#open(java.lang.Class,
+ * java.lang.Object)
+ */
+ public void open(Class<?> type, Object dataContext) throws Exception {
+ open(type.getResource(type.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX), dataContext);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#open(java.net.URL, java.util.Map)
+ */
+ public void open(final URL url, final Map<String, Object> options) throws Exception {
+ if(SWT.getPlatform().startsWith("win")) {
+ if(Display.getCurrent() == null) {
+ new Display();
+ }
+ Realm.runWithDefault(getRealm(), new Runnable() {
+
+ public void run() {
+ try {
+ if(url == null) {
+ throw new XWTException("UI Resource is not found.");
+ }
+ Object element = loadWithOptions(url, options);
+ Shell shell = XWT.findShell(element);
+ if(shell == null) {
+ throw new XWTException("Root element must be a control.");
+ }
+ shell.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ Shell[] shells = Display.getCurrent().getShells();
+ if(shells.length == 0) {
+ ResourceManager.resources.dispose();
+ }
+ }
+ });
+ shell.open();
+ while(!shell.isDisposed()) {
+ if(!shell.getDisplay().readAndDispatch()) {
+ shell.getDisplay().sleep();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ return;
+ }
+ Display defaultDisplay = Display.getDefault();
+ if(Thread.currentThread() == defaultDisplay.getThread()) {
+ Realm.runWithDefault(getRealm(), new Runnable() {
+
+ public void run() {
+ try {
+ if(url == null) {
+ throw new XWTException("UI Resource is not found.");
+ }
+ Object element = loadWithOptions(url, options);
+ Shell shell = XWT.findShell(element);
+ shell.open();
+ long startTime = -1;
+ while(true) {
+ if(!Display.getDefault().readAndDispatch()) {
+ Display.getDefault().sleep();
+ }
+ Shell[] shells = Display.getDefault().getShells();
+ if(shells.length == 0) {
+ if(startTime == -1) {
+ startTime = System.currentTimeMillis();
+ } else if((System.currentTimeMillis() - startTime) > 1000) {
+ break;
+ }
+ } else {
+ startTime = -1;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ } else {
+ defaultDisplay.asyncExec(new Runnable() {
+
+ public void run() {
+ Realm.runWithDefault(getRealm(), new Runnable() {
+
+ public void run() {
+ try {
+ if(url == null) {
+ throw new XWTException("UI Resource is not found.");
+ }
+ Object element = loadWithOptions(url, options);
+ Shell shell = XWT.findShell(element);
+ if(shell == null) {
+ throw new XWTException("Root element must be a control.");
+ }
+ shell.open();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+
+ public void open(final IUIResource resource, final Map<String, Object> options) throws Exception {
+ if(SWT.getPlatform().startsWith("win")) {
+ if(Display.getCurrent() == null) {
+ new Display();
+ }
+ Realm.runWithDefault(getRealm(), new Runnable() {
+
+ public void run() {
+ try {
+ Object element = loadWithOptions(resource, options);
+ Shell shell = XWT.findShell(element);
+ if(shell == null) {
+ throw new XWTException("Root element must be a control.");
+ }
+ shell.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ Shell[] shells = Display.getCurrent().getShells();
+ if(shells.length == 0) {
+ ResourceManager.resources.dispose();
+ }
+ }
+ });
+ shell.open();
+ while(!shell.isDisposed()) {
+ if(!shell.getDisplay().readAndDispatch()) {
+ shell.getDisplay().sleep();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ return;
+ }
+ Display defaultDisplay = Display.getDefault();
+ if(Thread.currentThread() == defaultDisplay.getThread()) {
+ Realm.runWithDefault(getRealm(), new Runnable() {
+
+ public void run() {
+ try {
+ Object element = loadWithOptions(resource, options);
+ Shell shell = XWT.findShell(element);
+ if(shell == null) {
+ throw new XWTException("Root element must be a control.");
+ }
+ shell.open();
+ long startTime = -1;
+ while(true) {
+ if(!Display.getDefault().readAndDispatch()) {
+ Display.getDefault().sleep();
+ }
+ Shell[] shells = Display.getDefault().getShells();
+ if(shells.length == 0) {
+ if(startTime == -1) {
+ startTime = System.currentTimeMillis();
+ } else if((System.currentTimeMillis() - startTime) > 1000) {
+ break;
+ }
+ } else {
+ startTime = -1;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ } else {
+ defaultDisplay.asyncExec(new Runnable() {
+
+ public void run() {
+ Realm.runWithDefault(getRealm(), new Runnable() {
+
+ public void run() {
+ try {
+ Object element = loadWithOptions(resource, options);
+ Shell shell = XWT.findShell(element);
+ if(shell == null) {
+ throw new XWTException("Root element must be a control.");
+ }
+ shell.open();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#convertFrom(org.eclipse.papyrus.xwt.metadata
+ * .IMetaclass, java.lang.String)
+ */
+ public Object convertFrom(IMetaclass type, String string) {
+ Class<?> targetType = type.getType();
+ return convertFrom(targetType, string);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#convertFrom(java.lang.Class,
+ * java.lang.String)
+ */
+ public Object convertFrom(Class<?> targetType, String string) {
+ if(targetType == String.class) {
+ return string;
+ }
+ IConverter converter = findConvertor(String.class, targetType);
+ if(converter != null) {
+ return converter.convert(string);
+ }
+ if(targetType == Object.class) {
+ return string;
+ }
+ throw new XWTException("Converter is missing of type: " + targetType.getName() + " from String");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#loadWithOptions(java.net.URL,
+ * java.util.Map)
+ */
+ public Object loadWithOptions(URL url, Map<String, Object> options) throws Exception {
+ if(url == null) {
+ throw new XWTException("UI Resource is not found.");
+ }
+ Composite object = (Composite)options.get(CONTAINER_PROPERTY);
+ ILoadingContext loadingContext = (object != null ? getLoadingContext(object) : getLoadingContext());
+ options = prepareOptions(options, url);
+ Object visualObject = getCurrentCore().load(loadingContext, url, options);
+ return visualObject;
+ }
+
+ public Object loadWithOptions(IUIResource resource, Map<String, Object> options) throws Exception {
+ UIResource uiResource = (UIResource)resource;
+ Object object = options.get(CONTAINER_PROPERTY);
+ ILoadingContext loadingContext = (object != null ? getLoadingContext(object) : getLoadingContext());
+ options = prepareOptions(options, uiResource.getURL());
+ Object visualObject = getCurrentCore().load(loadingContext, resource, options);
+ return visualObject;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#load(java.io.InputStream,
+ * java.net.URL)
+ */
+ public Object load(InputStream stream, URL url) throws Exception {
+ return loadWithOptions(stream, url, Collections.<String, Object> emptyMap());
+ }
+
+ public Object load(IUIResource resource) throws Exception {
+ return loadWithOptions(resource, Collections.<String, Object> emptyMap());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#loadWithOptions(java.io.InputStream,
+ * java.net.URL, java.util.Map)
+ */
+ public Object loadWithOptions(InputStream stream, URL base, Map<String, Object> options) throws Exception {
+ Composite object = (Composite)options.get(CONTAINER_PROPERTY);
+ ILoadingContext loadingContext = (object != null ? getLoadingContext(object) : getLoadingContext());
+ options = prepareOptions(options, base);
+ Control visualObject = getCurrentCore().load(loadingContext, stream, base, options);
+ return visualObject;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getAllMetaclasses()
+ */
+ public IMetaclass[] getAllMetaclasses() {
+ Collection<IMetaclass> collector = new ArrayList<IMetaclass>();
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ Collection<IMetaclass> metaclasses = core.getAllMetaclasses(IConstants.XWT_NAMESPACE);
+ collector.addAll(metaclasses);
+ }
+ return collector.toArray(new IMetaclass[collector.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getMetaclass(java.lang.String,
+ * java.lang.String)
+ */
+ public IMetaclass getMetaclass(String tagName, String ns) {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ IMetaclass metaclass = core.getMetaclass(getLoadingContext(), tagName, ns);
+ if(metaclass != null) {
+ return metaclass;
+ }
+ }
+ throw new XWTException("Type " + tagName + " is not found.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#registerMetaclass(java.lang.Class)
+ */
+ public IMetaclass registerMetaclass(Class<?> type) {
+ return getCurrentCore().registerMetaclass(type, IConstants.XWT_NAMESPACE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#registerMetaclass(java.lang.Class)
+ */
+ public void registerMetaclass(IMetaclass type) {
+ getCurrentCore().registerMetaclass(type, IConstants.XWT_NAMESPACE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#registerMetaclassFactory(org.eclipse.e4
+ * .xwt.IMetaclassFactory)
+ */
+ public void registerMetaclassFactory(IMetaclassFactory metaclassFactory) {
+ getCurrentCore().registerMetaclassFactory(metaclassFactory);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#findConvertor(java.lang.Class,
+ * java.lang.Class)
+ */
+ public IConverter findConvertor(Class<?> source, Class<?> target) {
+ source = ObjectUtil.normalizedType(source);
+ target = ObjectUtil.normalizedType(target);
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ IConverter converter = core.findConvertor(source, target);
+ if(converter != null) {
+ return converter;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#registerConvertor(org.eclipse.core.databinding
+ * .conversion.IConverter)
+ */
+ public void registerConvertor(IConverter converter) {
+ getCurrentCore().registerConvertor(converter);
+ }
+
+ protected void registerConvertor(Class<?> converter, String methodName) {
+ getCurrentCore().registerConvertor(converter, methodName);
+ }
+
+ protected void registerConvertor(Class<?> converterType, String methodName, boolean value) {
+ getCurrentCore().registerConvertor(converterType, methodName, value);
+ }
+
+ protected void registerConvertor(ValueConvertorRegister convertorRegister, Class<?> source, Class<?> target, Class<?> converterType, String methodName, boolean value) {
+ getCurrentCore().registerConvertor(convertorRegister, source, target, converterType, methodName, value);
+ }
+
+ protected IConverter loadConvertor(Class<?> converter, String methodName, boolean value) {
+ return getCurrentCore().loadConvertor(converter, methodName, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#addTracking(org.eclipse.papyrus.xwt.Tracking)
+ */
+ public void addTracking(Tracking tracking) {
+ getCurrentCore().addTracking(tracking);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#isTracking(org.eclipse.papyrus.xwt.Tracking)
+ */
+ public boolean isTracking(Tracking tracking) {
+ return getCurrentCore().isTracking(tracking);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getTrackings()
+ */
+ public Set<Tracking> getTrackings() {
+ return getCurrentCore().getTrackings();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeTracking(org.eclipse.papyrus.xwt.Tracking)
+ */
+ public void removeTracking(Tracking tracking) {
+ getCurrentCore().removeTracking(tracking);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#registerCommand(java.lang.String,
+ * org.eclipse.papyrus.xwt.input.ICommand)
+ */
+ public void registerCommand(String name, ICommand command) {
+ getCurrentCore().registerCommand(name, command);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getCommand(java.lang.String)
+ */
+ public ICommand getCommand(String name) {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ ICommand command = core.getCommand(name);
+ if(command != null) {
+ return command;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getCommands()
+ */
+ public Map<String, ICommand> getCommands() {
+ HashMap<String, ICommand> collector = new HashMap<String, ICommand>();
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ Map<String, ICommand> map = core.getCommands();
+ if(map != null) {
+ collector.putAll(map);
+ }
+ }
+ return collector;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#unregisterCommand(java.lang.String)
+ */
+ public void unregisterCommand(String name) {
+ getCurrentCore().unregisterCommand(name);
+ }
+
+ /**
+ * Register a command to a name
+ *
+ * @param name
+ * @param command
+ */
+ public void registerEventGroup(Class<?> type, IEventGroup eventGroup) {
+ IMetaclass metaclass = getMetaclass(type);
+ metaclass.addEventGroup(eventGroup);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#addDefaultStyle(org.eclipse.papyrus.xwt.IStyle)
+ */
+ public void addDefaultStyle(IStyle style) {
+ getCurrentCore().addDefaultStyle(style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeDefaultStyle(org.eclipse.papyrus.xwt.IStyle
+ * )
+ */
+ public void removeDefaultStyle(IStyle style) {
+ getCurrentCore().removeDefaultStyle(style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getDefaultStyles()
+ */
+ public Collection<IStyle> getDefaultStyles() {
+ return getCurrentCore().getDefaultStyles();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#addDataProviderFactory(org.eclipse.papyrus.xwt
+ * .IDataProviderFactory)
+ */
+ public void addDataProviderFactory(String name, IDataProviderFactory dataProviderFactory) {
+ getCurrentCore().addDataProviderFactory(name, dataProviderFactory);
+ registerMetaclass(dataProviderFactory.getType());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeDataProviderFactory(org.eclipse.e4
+ * .xwt.IDataProviderFactory)
+ */
+ public void removeDataProviderFactory(String name) {
+ getCurrentCore().removeDataProviderFactory(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeDataProviderFactory(org.eclipse.e4
+ * .xwt.IDataProviderFactory)
+ */
+ public void removeDataProviderFactory(IDataProviderFactory dataProviderFactory) {
+ getCurrentCore().removeDataProviderFactory(dataProviderFactory);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getDataProviderFactories()
+ */
+ public Collection<IDataProviderFactory> getDataProviderFactories() {
+ ArrayList<IDataProviderFactory> collector = new ArrayList<IDataProviderFactory>();
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ Collection<IDataProviderFactory> factories = core.getDataProviderFactories();
+ if(factories != null) {
+ collector.addAll(factories);
+ }
+ }
+ return collector;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#findDataProvider(java.lang.Object)
+ */
+ public IDataProvider findDataProvider(Object dataContext) {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ IDataProvider provider = core.findDataProvider(dataContext);
+ if(provider != null) {
+ return provider;
+ }
+ }
+ return null;
+ }
+
+ private synchronized void initialize() {
+ cores = new Stack<Core>();
+ Core core = new Core(new ResourceLoaderFactory(), this);
+ cores.push(core);
+
+ core.registerService(ValueConvertorRegister.class, new ValueConvertorRegister());
+
+ core.registerMetaclassManager(IConstants.XWT_NAMESPACE, new MetaclassManager(null, null, this));
+ core.registerMetaclass(new BindingMetaclass(this), IConstants.XWT_NAMESPACE);
+ core.registerMetaclass(new BindingMetaclass(MultiBinding.class, this), IConstants.XWT_NAMESPACE);
+ core.registerMetaclass(new TableEditorMetaclass(core.getMetaclass(ControlEditor.class, IConstants.XWT_NAMESPACE), this), IConstants.XWT_NAMESPACE);
+
+ registerConvertor(ObjectToString.FROM_OBJECT);
+ registerConvertor(DateToString.instance);
+ registerConvertor(EnumToString.instance);
+ registerConvertor(StringToInteger.instance);
+ // It is not supported by eclipse 3.4.1
+ registerConvertor(StringToNumberConverter.class, "toBigDecimal");
+ registerConvertor(StringToNumberConverter.class, "toByte", false);
+
+ registerConvertor(StringToNumberConverter.toLong(false));
+
+ // It is not supported by eclipse 3.4.1
+ registerConvertor(StringToNumberConverter.class, "toShort", false);
+
+ registerConvertor(StringToNumberConverter.toFloat(false));
+ registerConvertor(StringToNumberConverter.toDouble(false));
+
+ registerConvertor(NumberToStringConverter.fromInteger(false));
+
+ // It is not supported by eclipse 3.4.1
+ registerConvertor(NumberToStringConverter.class, "fromBigDecimal");
+ registerConvertor(NumberToStringConverter.class, "fromByte", false);
+
+ registerConvertor(NumberToStringConverter.fromLong(false));
+
+ // It is not supported by eclipse 3.4.1
+ registerConvertor(NumberToStringConverter.class, "fromShort", false);
+
+ registerConvertor(NumberToStringConverter.fromFloat(false));
+ registerConvertor(NumberToStringConverter.fromDouble(false));
+
+ registerConvertor(StringToBoolean.instance);
+ registerConvertor(ObjectToBoolean.instance);
+ registerConvertor(SelectionToBoolean.instance);
+ registerConvertor(CollectionToBoolean.instance);
+ registerConvertor(CollectionToInteger.instance);
+ registerConvertor(StringToIntArray.instance);
+ registerConvertor(StringToDoubleArray.instance);
+ registerConvertor(BindingToObject.instance);
+ registerConvertor(StringToColor.instance);
+ registerConvertor(StringToFont.instance);
+ registerConvertor(StringToImage.instance);
+ registerConvertor(StringToPoint.instance);
+ registerConvertor(StringToRectangle.instance);
+ registerConvertor(StringToURL.instance);
+ registerConvertor(StringToType.instance);
+ registerConvertor(StringToFormAttachment.instance);
+ registerConvertor(StringToIValidationRule.instance);
+ registerConvertor(StringToIValueConverter.instance);
+ registerConvertor(ListToIObservableCollection.instance);
+ registerConvertor(SetToIObservableCollection.instance);
+ registerConvertor(ObjectToISelection.instance);
+ registerConvertor(ListToSet.instance);
+ // registerConvertor(StringToKeyTime.instance);
+ // registerConvertor(StringToKeySpline.instance);
+
+ registerConvertor(IStatusToString.instance);
+ registerConvertor(IStatusToBoolean.instance);
+
+ ValueConvertorRegister convertorRegister = (ValueConvertorRegister)core.getService(ValueConvertorRegister.class);
+ convertorRegister.register(String.class, float.class, StringToNumberConverter.toFloat(true));
+ convertorRegister.register(String.class, int.class, StringToInteger.instance);
+
+ // It is not supported by eclipse 3.4.1
+ // convertorRegister.register(String.class, short.class,
+ // StringToNumberConverter.toShort(true));
+ registerConvertor(convertorRegister, String.class, short.class, StringToNumberConverter.class, "toShort", true);
+
+ convertorRegister.register(String.class, long.class, StringToNumberConverter.toLong(true));
+
+ // It is not supported by eclipse 3.4.1
+ // convertorRegister.register(String.class, byte.class,
+ // StringToNumberConverter.toByte(true));
+ registerConvertor(convertorRegister, String.class, byte.class, StringToNumberConverter.class, "toByte", true);
+
+ convertorRegister.register(String.class, boolean.class, StringToBoolean.instance);
+ convertorRegister.register(String.class, double.class, StringToNumberConverter.toDouble(true));
+
+ convertorRegister.register(float.class, String.class, NumberToStringConverter.fromFloat(true));
+ convertorRegister.register(int.class, String.class, NumberToStringConverter.fromInteger(true));
+
+ // It is not supported by eclipse 3.4.1
+ // convertorRegister.register(short.class, String.class,
+ // NumberToStringConverter.fromShort(true));
+ registerConvertor(convertorRegister, short.class, String.class, NumberToStringConverter.class, "fromShort", true);
+
+ convertorRegister.register(long.class, String.class, NumberToStringConverter.fromLong(true));
+
+ // It is not supported by eclipse 3.4.1
+ // convertorRegister.register(byte.class, String.class,
+ // NumberToStringConverter.fromByte(true));
+ registerConvertor(convertorRegister, byte.class, String.class, NumberToStringConverter.class, "fromByte", true);
+
+ convertorRegister.register(double.class, String.class, NumberToStringConverter.fromDouble(true));
+
+ Class<?> type = org.eclipse.swt.widgets.Widget.class;
+ IMetaclass metaclass = registerMetaclass(type);
+ IProperty drawingProperty = new AbstractProperty(IUserDataConstants.XWT_DRAWING_KEY, Drawing.class) {
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(!ObjectUtil.isAssignableFrom(IBinding.class, getType())) {
+ if(value != null) {
+ value = ObjectUtil.resolveValue(value, getType(), value);
+ }
+ }
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+ };
+ metaclass.addProperty(drawingProperty);
+ IProperty dataContextProperty = new DataProperty(IConstants.XAML_DATA_CONTEXT, IUserDataConstants.XWT_DATACONTEXT_KEY);
+ metaclass.addProperty(dataContextProperty);
+ ILoadingType loadingType = new DefaultLoadingType(IValueLoading.PostChildren, new IProperty[]{ dataContextProperty });
+
+ metaclass.addProperty(new DataProperty(IConstants.XAML_BINDING_CONTEXT, IUserDataConstants.XWT_BINDING_CONTEXT_KEY));
+ metaclass.addProperty(new TriggersProperty(loadingType));
+ metaclass.addProperty(new StyleProperty());
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.KEY_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.MOUSE_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.MOUSE_MOVING_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.FOCUS_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.EXPAND_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.WINDOW_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.ACTIVATION_GROUP));
+ registerEventGroup(type, new RadioEventGroup(IEventConstants.HARD_KEY));
+ type = org.eclipse.swt.browser.Browser.class;
+ IMetaclass browserMetaclass = registerMetaclass(type);
+
+ browserMetaclass.addProperty(new DynamicProperty(type, String.class, PropertiesConstants.PROPERTY_URL, loadingType));
+ browserMetaclass.addProperty(new DynamicProperty(type, String.class, PropertiesConstants.PROPERTY_TEXT, loadingType));
+
+ IMetaclass buttonMetaclass = registerMetaclass(Button.class);
+ buttonMetaclass.addProperty(new DataProperty(IConstants.XAML_COMMAND, IUserDataConstants.XWT_COMMAND_KEY, ICommand.class));
+
+ registerMetaclass(org.eclipse.swt.widgets.Canvas.class);
+ registerMetaclass(org.eclipse.swt.widgets.Caret.class);
+ metaclass = registerMetaclass(org.eclipse.swt.widgets.Combo.class);
+ if(metaclass != null) {
+ IProperty property = metaclass.findProperty("text");
+ IProperty inputProperty = new DelegateProperty(property, loadingType);
+ metaclass.addProperty(inputProperty);
+ }
+
+ registerMetaclass(org.eclipse.swt.widgets.Composite.class);
+ registerMetaclass(org.eclipse.swt.widgets.CoolBar.class);
+ registerMetaclass(org.eclipse.swt.widgets.CoolItem.class);
+ registerMetaclass(org.eclipse.swt.widgets.DateTime.class);
+ registerMetaclass(org.eclipse.swt.widgets.Decorations.class);
+ registerMetaclass(org.eclipse.swt.widgets.ExpandBar.class);
+ IMetaclass expandItemMetaclass = registerMetaclass(ExpandItem.class);
+ expandItemMetaclass.findProperty("control").addSetPostAction(new ExpandItemHeightAction());
+
+ registerMetaclass(Group.class);
+ registerMetaclass(IME.class);
+ registerMetaclass(Label.class);
+ registerMetaclass(Link.class);
+ registerMetaclass(Listener.class);
+ registerMetaclass(List.class);
+ registerMetaclass(Menu.class);
+ IMetaclass menuItemMetaclass = registerMetaclass(MenuItem.class);
+ menuItemMetaclass.addProperty(new DataProperty(IConstants.XAML_COMMAND, IUserDataConstants.XWT_COMMAND_KEY, ICommand.class));
+
+ registerMetaclass(org.eclipse.swt.widgets.MessageBox.class);
+ registerMetaclass(org.eclipse.swt.widgets.ProgressBar.class);
+ registerMetaclass(org.eclipse.swt.widgets.Sash.class);
+
+ registerMetaclass(org.eclipse.swt.widgets.Scale.class);
+ registerMetaclass(org.eclipse.swt.widgets.ScrollBar.class);
+ registerMetaclass(org.eclipse.swt.widgets.Shell.class);
+ registerMetaclass(org.eclipse.swt.widgets.Slider.class);
+ registerMetaclass(org.eclipse.swt.widgets.Spinner.class);
+ registerMetaclass(org.eclipse.swt.widgets.TabFolder.class);
+ registerMetaclass(org.eclipse.swt.widgets.TabItem.class);
+
+ registerMetaclass(org.eclipse.swt.widgets.Table.class);
+ type = org.eclipse.swt.widgets.TableItem.class;
+ metaclass = registerMetaclass(type);
+ metaclass.addProperty(new TableItemProperty());
+ metaclass.addProperty(new TableItemEditorProperty());
+ metaclass.addProperty(new DynamicBeanProperty(TableItem.class, String[].class, PropertiesConstants.PROPERTY_TEXTS, PropertiesConstants.PROPERTY_TEXT));
+
+ registerMetaclass(TableItemProperty.Cell.class);
+ registerMetaclass(ControlEditor.class);
+ registerMetaclass(TableEditor.class);
+
+ IMetaclass TableEditorMetaclass = core.getMetaclass(TableEditor.class, IConstants.XWT_NAMESPACE);
+ TableEditorMetaclass.addProperty(new TableEditorDynamicProperty(loadingType));
+
+ type = org.eclipse.swt.widgets.TableColumn.class;
+ metaclass = registerMetaclass(type);
+ metaclass.addProperty(new TableColumnEditorProperty());
+
+ registerMetaclass(org.eclipse.swt.widgets.Text.class);
+ registerMetaclass(org.eclipse.swt.widgets.ToolBar.class);
+ registerMetaclass(org.eclipse.swt.widgets.ToolItem.class);
+ registerMetaclass(org.eclipse.swt.widgets.ToolTip.class);
+ registerMetaclass(org.eclipse.swt.widgets.Tracker.class);
+ registerMetaclass(org.eclipse.swt.widgets.Tray.class);
+ registerMetaclass(org.eclipse.swt.widgets.Tree.class);
+ registerMetaclass(org.eclipse.swt.widgets.TreeColumn.class);
+ type = org.eclipse.swt.widgets.TreeItem.class;
+ registerMetaclass(type);
+ metaclass = registerMetaclass(type);
+ metaclass.addProperty(new DynamicBeanProperty(TreeItem.class, String[].class, PropertiesConstants.PROPERTY_TEXTS, PropertiesConstants.PROPERTY_TEXT));
+ if(metaclass != null) {
+ IProperty property = metaclass.findProperty("expanded");
+ IProperty expandedProperty = new DelegateProperty(property, loadingType);
+ metaclass.addProperty(expandedProperty);
+ }
+
+ // registerMetaclass(org.eclipse.swt.layout.FillData.class);
+ registerMetaclass(org.eclipse.swt.layout.FillLayout.class);
+ registerMetaclass(org.eclipse.swt.layout.FormAttachment.class);
+ registerMetaclass(org.eclipse.swt.layout.FormData.class);
+ registerMetaclass(org.eclipse.swt.layout.FormLayout.class);
+ registerMetaclass(org.eclipse.swt.layout.GridData.class);
+ registerMetaclass(org.eclipse.swt.layout.GridLayout.class);
+ registerMetaclass(org.eclipse.swt.layout.RowData.class);
+ registerMetaclass(org.eclipse.swt.layout.RowLayout.class);
+ registerMetaclass(org.eclipse.swt.custom.StackLayout.class);
+
+ registerMetaclass(org.eclipse.swt.custom.CLabel.class);
+ metaclass = registerMetaclass(org.eclipse.swt.custom.CCombo.class);
+ if(metaclass != null) {
+ IProperty property = metaclass.findProperty("text");
+ IProperty inputProperty = new DelegateProperty(property, loadingType);
+ metaclass.addProperty(inputProperty);
+ }
+ registerMetaclass(org.eclipse.swt.custom.CTabFolder.class);
+ registerMetaclass(org.eclipse.swt.custom.CTabItem.class);
+ metaclass = registerMetaclass(org.eclipse.swt.custom.SashForm.class);
+ if(metaclass != null) {
+ IProperty property = metaclass.findProperty("weights");
+ IProperty inputProperty = new DelegateProperty(property, loadingType);
+ metaclass.addProperty(inputProperty);
+ }
+
+ registerMetaclass(org.eclipse.swt.custom.StyledText.class);
+ registerMetaclass(org.eclipse.swt.custom.ScrolledComposite.class);
+ registerMetaclass(org.eclipse.swt.custom.TableTree.class);
+ registerMetaclass(org.eclipse.swt.custom.ViewForm.class);
+ registerMetaclass(org.eclipse.swt.custom.CBanner.class);
+ registerMetaclass(org.eclipse.swt.custom.TableCursor.class);
+
+ type = org.eclipse.jface.viewers.Viewer.class;
+ metaclass = core.getMetaclass(type, IConstants.XWT_NAMESPACE);
+ if(metaclass != null) {
+ IProperty property = metaclass.findProperty("Input");
+ IProperty inputProperty = new InputBeanProperty(property, loadingType);
+ metaclass.addProperty(inputProperty);
+ metaclass.addProperty(new DataProperty(IConstants.XAML_DATA_CONTEXT, IUserDataConstants.XWT_DATACONTEXT_KEY));
+
+ metaclass.removeProperty("selection");
+
+ metaclass.addProperty(new DataProperty(PropertiesConstants.PROPERTY_BINDING_PATH, IUserDataConstants.XWT_PROPERTY_DATA_KEY, String.class));
+ metaclass.addProperty(new DataProperty(PropertiesConstants.PROPERTY_ITEM_TEXT, IUserDataConstants.XWT_PROPERTY_ITEM_TEXT_KEY, IBinding.class));
+ metaclass.addProperty(new DataProperty(PropertiesConstants.PROPERTY_ITEM_IMAGE, IUserDataConstants.XWT_PROPERTY_ITEM_IMAGE_KEY, IBinding.class));
+ ILoadingType inputLoadingType = new DefaultLoadingType(IValueLoading.PostChildren, new IProperty[]{ inputProperty });
+ metaclass.addProperty(new SingleSelectionBeanProperty(PropertiesConstants.PROPERTY_SINGLE_SELECTION, inputLoadingType));
+ metaclass.addProperty(new MultiSelectionBeanProperty(PropertiesConstants.PROPERTY_MULTI_SELECTION, inputLoadingType));
+ }
+
+ type = org.eclipse.jface.viewers.AbstractListViewer.class;
+ metaclass = core.getMetaclass(type, IConstants.XWT_NAMESPACE);
+ if(metaclass != null) {
+ metaclass.addInitializer(new JFaceInitializer());
+ }
+
+ type = org.eclipse.jface.viewers.ColumnViewer.class;
+ metaclass = core.getMetaclass(type, IConstants.XWT_NAMESPACE);
+ if(metaclass != null) {
+ metaclass.addProperty(new DynamicBeanProperty(type, String[].class, PropertiesConstants.PROPERTY_COLUMN_PROPERTIES));
+ metaclass.addProperty(new ColumnViewerColumnsProperty());
+
+ metaclass.addInitializer(new JFaceInitializer());
+ }
+
+ for(Class<?> cls : JFacesHelper.getSupportedElements()) {
+ registerMetaclass(cls);
+ }
+ type = org.eclipse.jface.viewers.TableViewer.class;
+ metaclass = core.getMetaclass(type, IConstants.XWT_NAMESPACE);
+ IProperty property = metaclass.findProperty("table");
+ if(property instanceof AbstractProperty) {
+ AbstractProperty abstractProperty = (AbstractProperty)property;
+ abstractProperty.setValueAsParent(true);
+ }
+
+ core.registerMetaclass(new ComboBoxCellEditorMetaclass(core.getMetaclass(ComboBoxCellEditor.class.getSuperclass(), IConstants.XWT_NAMESPACE), this), IConstants.XWT_NAMESPACE);
+
+ type = org.eclipse.jface.viewers.TableViewerColumn.class;
+ core.registerMetaclass(new TableViewerColumnMetaClass(core.getMetaclass(type.getSuperclass(), IConstants.XWT_NAMESPACE), this), IConstants.XWT_NAMESPACE);
+
+ metaclass = core.getMetaclass(type, IConstants.XWT_NAMESPACE);
+ //
+ // PROPERTY_DATA_KEY
+ //
+ metaclass.addProperty(new TableViewerColumnWidthProperty());
+ metaclass.addProperty(new TableViewerColumnTextProperty());
+ metaclass.addProperty(new TableViewerColumnImageProperty());
+ metaclass.addProperty(new TableViewerColumnDynamicProperty(PropertiesConstants.PROPERTY_BINDING_PATH, IUserDataConstants.XWT_PROPERTY_DATA_KEY, String.class));
+ metaclass.addProperty(new TableViewerColumnDynamicProperty(PropertiesConstants.PROPERTY_ITEM_TEXT, IUserDataConstants.XWT_PROPERTY_ITEM_TEXT_KEY, IBinding.class));
+ metaclass.addProperty(new TableViewerColumnDynamicProperty(PropertiesConstants.PROPERTY_ITEM_IMAGE, IUserDataConstants.XWT_PROPERTY_ITEM_IMAGE_KEY, IBinding.class));
+
+ registerMetaclass(DefaultCellModifier.class);
+ registerMetaclass(ViewerFilter.class);
+
+ // DataBinding stuff
+ registerMetaclass(BindingContext.class);
+
+ registerMetaclass(ObjectDataProvider.class);
+
+ registerMetaclass(Style.class);
+ registerMetaclass(Setter.class);
+
+ registerMetaclass(Trigger.class);
+ registerMetaclass(MultiTrigger.class);
+ registerMetaclass(EventTrigger.class);
+ registerMetaclass(DataTrigger.class);
+ registerMetaclass(MultiDataTrigger.class);
+ registerMetaclass(Condition.class);
+
+ // registerConvertor(StringToDuration.instance);
+ // registerConvertor(StringToTimeSpan.instance);
+ // registerConvertor(StringToRepeatBehavior.instance);
+
+ registerMetaclass(CollectionViewSource.class);
+
+ registerMetaclass(ObservableListContentProvider.class);
+ registerMetaclass(ObservableSetContentProvider.class);
+ registerMetaclass(ObservableTreeContentProvider.class);
+
+ registerFileResolveType(Image.class);
+ registerFileResolveType(URL.class);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#findLoadingContext(java.lang.Object)
+ */
+ public ILoadingContext findLoadingContext(Object container) {
+ for(int i = cores.size() - 1; i >= 0; i--) {
+ Core core = cores.get(i);
+ ILoadingContext context = core.findLoadingContext(container);
+ if(context != null) {
+ return context;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#getLoadingContext(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public ILoadingContext getLoadingContext(Object object) {
+ return findLoadingContext(object);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getLoadingContext()
+ */
+ public ILoadingContext getLoadingContext() {
+ return getCurrentCore().getLoadingContext();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.e4.xwt.IXWTLoader#setLoadingContext(org.eclipse.papyrus.xwt.
+ * ILoadingContext)
+ */
+ public void setLoadingContext(ILoadingContext loadingContext) {
+ getCurrentCore().setLoadingContext(loadingContext);
+ }
+
+ /**
+ * Check if the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public boolean isFileResolveType(Class<?> type) {
+ return getCurrentCore().isFileResolveType(type);
+ }
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public void registerFileResolveType(Class<?> type) {
+ getCurrentCore().registerFileResolveType(type);
+ }
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public void unregisterFileResolveType(Class<?> type) {
+ getCurrentCore().unregisterFileResolveType(type);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoaderManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoaderManager.java
new file mode 100644
index 00000000000..365a24b99bc
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTLoaderManager.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ * Anyware-tech - add multiple loaders
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt;
+
+/**
+ * Class allowing to keep the reference on the XWT loader active
+ */
+public class XWTLoaderManager {
+
+ /** Default XWT loader */
+ private static IXWTLoader defaultXWTLoader;
+
+ /** Active XWT loader */
+ private static IXWTLoader activeXWTLoader;
+
+ /**
+ * Returns the default instance of the XWT loader
+ *
+ * @return the default instance of the XWT loader
+ */
+ public static IXWTLoader getDefault() {
+ if(defaultXWTLoader == null) {
+ defaultXWTLoader = new XWTLoader();
+ XWT.runInitializers(defaultXWTLoader);
+ }
+ return defaultXWTLoader;
+ }
+
+ public static boolean isStarted() {
+ return defaultXWTLoader != null;
+ }
+
+ /**
+ * Returns the instance of the XWT loader active. If no XWT loader are active, returns the default XWT loader
+ *
+ * @return the instance of the XWT loader active
+ */
+ public static IXWTLoader getActive() {
+ IXWTLoader xwtLoader = activeXWTLoader;
+ if(xwtLoader == null) {
+ xwtLoader = getDefault();
+ }
+ return xwtLoader;
+ }
+
+ /**
+ * Sets the active XWT loader
+ *
+ * @param xwtLoader
+ * the XWT loader
+ * @param active
+ * true if the XWT loader is active, otherwise false
+ */
+ public static void setActive(IXWTLoader xwtLoader, boolean active) {
+ if(active) {
+ activeXWTLoader = xwtLoader;
+ } else if(xwtLoader != null && xwtLoader.equals(activeXWTLoader)) {
+ activeXWTLoader = null;
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTMaps.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTMaps.java
new file mode 100644
index 00000000000..7a7d870fba6
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/XWTMaps.java
@@ -0,0 +1,691 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+
+/**
+ * @author jliu
+ */
+public class XWTMaps {
+
+ private static final Map<String, Integer> styles = new HashMap<String, Integer>();
+
+ private static final Map<String, Integer> colors = new HashMap<String, Integer>();
+
+ private static final Map<String, Integer> events = new HashMap<String, Integer>();
+
+ private static final Map<String, Integer> accelerators = new HashMap<String, Integer>();
+
+ private XWTMaps() {
+ }
+
+ private static void checkAndInit() {
+ if(styles.isEmpty() || colors.isEmpty() || events.isEmpty() || accelerators.isEmpty()) {
+ init();
+ }
+ }
+
+ private static void init() {
+ // styles
+ styles.put("SWT.NONE", SWT.NONE);
+ styles.put("SWT.FILL", SWT.FILL);
+ styles.put("SWT.BORDER", SWT.BORDER);
+ styles.put("SWT.PUSH", SWT.PUSH);
+ styles.put("SWT.CHECK", SWT.CHECK);
+ styles.put("SWT.RADIO", SWT.RADIO);
+ styles.put("SWT.TOGGLE", SWT.TOGGLE);
+ styles.put("SWT.ARROW", SWT.ARROW);
+ styles.put("SWT.ARROW_DOWN", SWT.ARROW_DOWN);
+ styles.put("SWT.ARROW_LEFT", SWT.ARROW_LEFT);
+ styles.put("SWT.ARROW_RIGHT", SWT.ARROW_RIGHT);
+ styles.put("SWT.ARROW_UP", SWT.ARROW_UP);
+ styles.put("SWT.FLAT", SWT.FLAT);
+ styles.put("SWT.DROP_DOWN", SWT.DROP_DOWN);
+ styles.put("SWT.SIMPLE", SWT.SIMPLE);
+ styles.put("SWT.READ_ONLY", SWT.READ_ONLY);
+ styles.put("SWT.LEFT", SWT.LEFT);
+ styles.put("SWT.UP", SWT.UP);
+ styles.put("SWT.DOWN", SWT.DOWN);
+ styles.put("SWT.CENTER", SWT.CENTER);
+ styles.put("SWT.RIGHT", SWT.RIGHT);
+ styles.put("SWT.H_SCROLL", SWT.H_SCROLL);
+ styles.put("SWT.V_SCROLL", SWT.V_SCROLL);
+ styles.put("SWT.DATE", SWT.DATE);
+ styles.put("SWT.TIME", SWT.TIME);
+ styles.put("SWT.CALENDAR", SWT.CALENDAR);
+ styles.put("SWT.SHORT", SWT.SHORT);
+ styles.put("SWT.MEDIUM", SWT.MEDIUM);
+ styles.put("SWT.LONG", SWT.LONG);
+ styles.put("SWT.WRAP", SWT.WRAP);
+ styles.put("SWT.HORIZONTAL", SWT.HORIZONTAL);
+ styles.put("SWT.VERTICAL", SWT.VERTICAL);
+ styles.put("SWT.SEPARATOR", SWT.SEPARATOR);
+ styles.put("SWT.SHADOW_IN", SWT.SHADOW_IN);
+ styles.put("SWT.SHADOW_NONE", SWT.SHADOW_NONE);
+ styles.put("SWT.SHADOW_OUT", SWT.SHADOW_OUT);
+ styles.put("SWT.NO_TRIM", SWT.NO_TRIM);
+ styles.put("SWT.SHELL_TRIM", SWT.SHELL_TRIM);
+ styles.put("SWT.DIALOG_TRIM", SWT.DIALOG_TRIM);
+
+ styles.put("SWT.CLOSE", SWT.CLOSE);
+ styles.put("SWT.MIN", SWT.MIN);
+ styles.put("SWT.MAX", SWT.MAX);
+ styles.put("SWT.RESIZE", SWT.RESIZE);
+ styles.put("SWT.TOOL", SWT.TOOL);
+ styles.put("SWT.ON_TOP", SWT.ON_TOP);
+ styles.put("SWT.MODELESS", SWT.MODELESS);
+ styles.put("SWT.PRIMARY_MODAL", SWT.PRIMARY_MODAL);
+ styles.put("SWT.APPLICATION_MODAL", SWT.APPLICATION_MODAL);
+ styles.put("SWT.SYSTEM_MODAL", SWT.SYSTEM_MODAL);
+ styles.put("SWT.TITLE", SWT.TITLE);
+ styles.put("SWT.SINGLE", SWT.SINGLE);
+ styles.put("SWT.MULTI", SWT.MULTI);
+ styles.put("SWT.PASSWORD", SWT.PASSWORD);
+ styles.put("SWT.SEARCH", SWT.SEARCH);
+ styles.put("SWT.CANCEL", SWT.CANCEL);
+ // styles: icon
+ tryPut(styles, "SWT.ICON");
+ styles.put("SWT.ICON_ERROR", SWT.ICON_ERROR);
+ styles.put("SWT.ICON_INFORMATION", SWT.ICON_INFORMATION);
+ styles.put("SWT.ICON_QUESTION", SWT.ICON_QUESTION);
+ styles.put("SWT.ICON_WARNING", SWT.ICON_WARNING);
+ styles.put("SWT.ICON_WORKING", SWT.ICON_WORKING);
+ tryPut(styles, "SWT.SHADOW_ETCHED_IN");
+ tryPut(styles, "SWT.SHADOW_ETCHED_OUT");
+ tryPut(styles, "SWT.BALLOON");
+ tryPut(styles, "SWT.NO_BACKGROUND");
+ styles.put("SWT.NO_FOCUS", SWT.NO_FOCUS);
+ tryPut(styles, "SWT.NO_MERGE_PAINTS");
+ tryPut(styles, "SWT.NO_REDRAW_RESIZE");
+ styles.put("SWT.DOUBLE_BUFFERED", SWT.DOUBLE_BUFFERED);
+ styles.put("SWT.SMOOTH", SWT.SMOOTH);
+ styles.put("SWT.INDETERMINATE", SWT.INDETERMINATE);
+ styles.put("SWT.FULL_SELECTION", SWT.FULL_SELECTION);
+ styles.put("SWT.TOP", SWT.TOP);
+ styles.put("SWT.BOTTOM", SWT.BOTTOM);
+ styles.put("SWT.NORMAL", SWT.NORMAL);
+ styles.put("SWT.ITALIC", SWT.ITALIC);
+ styles.put("SWT.BOLD", SWT.BOLD);
+ styles.put("SWT.LEFT_TO_RIGHT", SWT.LEFT_TO_RIGHT);
+ tryPut(styles, "SWT.RIGHT_TO_LEFT");
+ styles.put("SWT.BAR", SWT.BAR);
+ styles.put("SWT.CASCADE", SWT.CASCADE);
+ tryPut(styles, "SWT.NO_RADIO_GROUP");
+ styles.put("SWT.POP_UP", SWT.POP_UP);
+ styles.put("SWT.INHERIT_DEFAULT", SWT.INHERIT_DEFAULT);
+ styles.put("SWT.INHERIT_NONE", SWT.INHERIT_NONE);
+ styles.put("SWT.INHERIT_FORCE", SWT.INHERIT_FORCE);
+
+ // colors
+ colors.put("SWT.COLOR_BLACK", SWT.COLOR_BLACK);
+ colors.put("SWT.COLOR_BLUE", SWT.COLOR_BLUE);
+ colors.put("SWT.COLOR_CYAN", SWT.COLOR_CYAN);
+ colors.put("SWT.COLOR_DARK_BLUE", SWT.COLOR_DARK_BLUE);
+ colors.put("SWT.COLOR_DARK_CYAN", SWT.COLOR_DARK_CYAN);
+ colors.put("SWT.COLOR_DARK_GREEN", SWT.COLOR_DARK_GREEN);
+ colors.put("SWT.COLOR_DARK_MAGENTA", SWT.COLOR_DARK_MAGENTA);
+ colors.put("SWT.COLOR_DARK_RED", SWT.COLOR_DARK_RED);
+ colors.put("SWT.COLOR_DARK_YELLOW", SWT.COLOR_DARK_YELLOW);
+ colors.put("SWT.COLOR_GRAY", SWT.COLOR_GRAY);
+ colors.put("SWT.COLOR_GREEN", SWT.COLOR_GREEN);
+ colors.put("SWT.COLOR_INFO_BACKGROUND", SWT.COLOR_INFO_BACKGROUND);
+ colors.put("SWT.COLOR_INFO_FOREGROUND", SWT.COLOR_INFO_FOREGROUND);
+ colors.put("SWT.COLOR_LIST_BACKGROUND", SWT.COLOR_LIST_BACKGROUND);
+ colors.put("SWT.COLOR_LIST_FOREGROUND", SWT.COLOR_LIST_FOREGROUND);
+ colors.put("SWT.COLOR_LIST_SELECTION", SWT.COLOR_LIST_SELECTION);
+ colors.put("SWT.COLOR_LIST_SELECTION_TEXT", SWT.COLOR_LIST_SELECTION_TEXT);
+ colors.put("SWT.COLOR_MAGENTA", SWT.COLOR_MAGENTA);
+ colors.put("SWT.COLOR_RED", SWT.COLOR_RED);
+ colors.put("SWT.COLOR_TITLE_BACKGROUND", SWT.COLOR_TITLE_BACKGROUND);
+ colors.put("SWT.COLOR_TITLE_BACKGROUND_GRADIENT", SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
+ colors.put("SWT.COLOR_TITLE_FOREGROUND", SWT.COLOR_TITLE_FOREGROUND);
+ colors.put("SWT.COLOR_TITLE_INACTIVE_BACKGROUND", SWT.COLOR_TITLE_INACTIVE_BACKGROUND);
+ colors.put("SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT", SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
+ colors.put("SWT.COLOR_TITLE_INACTIVE_FOREGROUND", SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
+ colors.put("SWT.COLOR_WHITE", SWT.COLOR_WHITE);
+ colors.put("SWT.COLOR_WIDGET_BACKGROUND", SWT.COLOR_WIDGET_BACKGROUND);
+ colors.put("SWT.COLOR_WIDGET_BORDER", SWT.COLOR_WIDGET_BORDER);
+ colors.put("SWT.COLOR_WIDGET_DARK_SHADOW", SWT.COLOR_WIDGET_DARK_SHADOW);
+ colors.put("SWT.COLOR_WIDGET_FOREGROUND", SWT.COLOR_WIDGET_FOREGROUND);
+ colors.put("SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW", SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
+ colors.put("SWT.COLOR_WIDGET_LIGHT_SHADOW", SWT.COLOR_WIDGET_LIGHT_SHADOW);
+ colors.put("SWT.COLOR_WIDGET_NORMAL_SHADOW", SWT.COLOR_WIDGET_NORMAL_SHADOW);
+ colors.put("SWT.COLOR_YELLOW", SWT.COLOR_YELLOW);
+
+ // Events
+ events.put("swt.activate", SWT.Activate);
+ events.put("swt.arm", SWT.Arm);
+ events.put("swt.close", SWT.Close);
+ events.put("swt.collapse", SWT.Collapse);
+ events.put("swt.deactivate", SWT.Deactivate);
+ events.put("swt.defaultselection", SWT.DefaultSelection);
+ tryPut(events, "swt.deiconify", "SWT.Deiconify");
+ events.put("swt.dispose", SWT.Dispose);
+ events.put("swt.dragdetect", SWT.DragDetect);
+ tryPut(events, "swt.eraseitem", "SWT.EraseItem");
+ events.put("swt.expand", SWT.Expand);
+ events.put("swt.focusin", SWT.FocusIn);
+ events.put("swt.focusout", SWT.FocusOut);
+ tryPut(events, "swt.hardkeydown", "SWT.HardKeyDown");
+ tryPut(events, "swt.hardkeyup", "SWT.HardKeyUp");
+ events.put("swt.help", SWT.Help);
+ events.put("swt.hide", SWT.Hide);
+ tryPut(events, "swt.iconify", "SWT.Iconify");
+ events.put("swt.keydown", SWT.KeyDown);
+ events.put("swt.keyup", SWT.KeyUp);
+ tryPut(events, "swt.measureitem", "SWT.MeasureItem");
+ events.put("swt.menudetect", SWT.MenuDetect);
+ events.put("swt.modify", SWT.Modify);
+ events.put("swt.mousedoubleclick", SWT.MouseDoubleClick);
+ events.put("swt.mousedown", SWT.MouseDown);
+ tryPut(events, "swt.mouseenter", "SWT.MouseEnter");
+ tryPut(events, "swt.mouseexit", "SWT.MouseExit");
+ tryPut(events, "swt.mousehover", "SWT.MouseHover");
+ tryPut(events, "swt.mousemove", "SWT.MouseMove");
+ events.put("swt.mouseup", SWT.MouseUp);
+ tryPut(events, "swt.mousewheel", "SWT.MouseWheel");
+ events.put("swt.move", SWT.Move);
+ tryPut(events, "swt.paint", "SWT.Paint");
+ tryPut(events, "swt.paintitem", "SWT.PaintItem");
+ events.put("swt.resize", SWT.Resize);
+ events.put("swt.selection", SWT.Selection);
+ events.put("swt.setdata", SWT.SetData);
+ tryPut(events, "swt.settings", "SWT.Settings");
+ events.put("swt.show", SWT.Show);
+ events.put("swt.traverse", SWT.Traverse);
+ events.put("swt.verify", SWT.Verify);
+ tryPut(events, "swt.imecomposition", "SWT.ImeComposition");
+
+ // accelerators
+ accelerators.put("SWT.ALT", SWT.ALT);
+ accelerators.put("SWT.ARROW_UP", SWT.ARROW_UP);
+ accelerators.put("SWT.ARROW_DOWN", SWT.ARROW_DOWN);
+ accelerators.put("SWT.ARROW_LEFT", SWT.ARROW_LEFT);
+ accelerators.put("SWT.ARROW_RIGHT", SWT.ARROW_RIGHT);
+ accelerators.put("SWT.BREAK", SWT.BREAK);
+ accelerators.put("SWT.CAPS_LOCK", SWT.CAPS_LOCK);
+ accelerators.put("SWT.CENTER", SWT.CENTER);
+ accelerators.put("SWT.CTRL", SWT.CTRL);
+ accelerators.put("SWT.DEFAULT", SWT.DEFAULT);
+ tryPut(accelerators, "SWT.EMBEDDED");
+ accelerators.put("SWT.END", SWT.END);
+ accelerators.put("SWT.F1", SWT.F1);
+ accelerators.put("SWT.F2", SWT.F2);
+ accelerators.put("SWT.F3", SWT.F3);
+ accelerators.put("SWT.F4", SWT.F4);
+ accelerators.put("SWT.F5", SWT.F5);
+ accelerators.put("SWT.F6", SWT.F6);
+ accelerators.put("SWT.F7", SWT.F7);
+ accelerators.put("SWT.F8", SWT.F8);
+ accelerators.put("SWT.F9", SWT.F9);
+ accelerators.put("SWT.F10", SWT.F10);
+ accelerators.put("SWT.F11", SWT.F11);
+ accelerators.put("SWT.F12", SWT.F12);
+ accelerators.put("SWT.HELP", SWT.HELP);
+ accelerators.put("SWT.HOME", SWT.HOME);
+ accelerators.put("SWT.IMAGE_UNDEFINED", SWT.IMAGE_UNDEFINED);
+ accelerators.put("SWT.INSERT", SWT.INSERT);
+ accelerators.put("SWT.KEYPAD_ADD", SWT.KEYPAD_ADD);
+ accelerators.put("SWT.KEYPAD_CR", SWT.KEYPAD_CR);
+ accelerators.put("SWT.KEYPAD_DECIMAL", SWT.KEYPAD_DECIMAL);
+ accelerators.put("SWT.KEYPAD_DIVIDE", SWT.KEYPAD_DIVIDE);
+ accelerators.put("SWT.KEYPAD_EQUAL", SWT.KEYPAD_EQUAL);
+ accelerators.put("SWT.KEYPAD_MULTIPLY", SWT.KEYPAD_MULTIPLY);
+ accelerators.put("SWT.KEYPAD_SUBTRACT", SWT.KEYPAD_SUBTRACT);
+ accelerators.put("SWT.KEYPAD_0", SWT.KEYPAD_0);
+ accelerators.put("SWT.KEYPAD_1", SWT.KEYPAD_1);
+ accelerators.put("SWT.KEYPAD_2", SWT.KEYPAD_2);
+ accelerators.put("SWT.KEYPAD_3", SWT.KEYPAD_3);
+ accelerators.put("SWT.KEYPAD_4", SWT.KEYPAD_4);
+ accelerators.put("SWT.KEYPAD_5", SWT.KEYPAD_5);
+ accelerators.put("SWT.KEYPAD_6", SWT.KEYPAD_6);
+ accelerators.put("SWT.KEYPAD_7", SWT.KEYPAD_7);
+ accelerators.put("SWT.KEYPAD_8", SWT.KEYPAD_8);
+ accelerators.put("SWT.KEYPAD_9", SWT.KEYPAD_9);
+ accelerators.put("SWT.NUM_LOCK", SWT.NUM_LOCK);
+ accelerators.put("SWT.PAUSE", SWT.PAUSE);
+ accelerators.put("SWT.PAGE_DOWN", SWT.PAGE_DOWN);
+ accelerators.put("SWT.PAGE_UP", SWT.PAGE_UP);
+ accelerators.put("SWT.PRINT_SCREEN", SWT.PRINT_SCREEN);
+ accelerators.put("SWT.SCROLL_LOCK", SWT.SCROLL_LOCK);
+ accelerators.put("SWT.SHIFT", SWT.SHIFT);
+
+ }
+
+ public static Collection<String> getStyleKeys() {
+ checkAndInit();
+ return styles.keySet();
+ }
+
+ public static int getStyle(String key) {
+ if(key == null) {
+ return SWT.NONE;
+ }
+ checkAndInit();
+ String mapKey = key.toUpperCase();
+ if(!mapKey.startsWith("SWT.")) {
+ mapKey = "SWT." + mapKey;
+ }
+ Integer style = styles.get(mapKey);
+ return (style == null ? SWT.NONE : style);
+ }
+
+ public static Collection<String> getColorKeys() {
+ checkAndInit();
+ return colors.keySet();
+ }
+
+ public static int getColor(String key) {
+ if(key == null || key.equals("")) {
+ return SWT.NONE;
+ }
+ checkAndInit();
+ String mapKey = key.toUpperCase();
+ if(!mapKey.startsWith("SWT.")) {
+ mapKey = "SWT." + mapKey;
+ }
+ Integer color = colors.get(mapKey);
+ return color == null ? SWT.NONE : color;
+ }
+
+ public static Collection<String> getEventKeys() {
+ checkAndInit();
+ return events.keySet();
+ }
+
+ public static int getEvent(String key) {
+ if(key == null || key.equals("")) {
+ return SWT.None;
+ }
+ checkAndInit();
+ String mapKey = key.toLowerCase();
+ if(!mapKey.startsWith("swt.")) {
+ mapKey = "swt." + mapKey;
+ }
+ Integer event = events.get(mapKey);
+ return event == null ? SWT.None : event;
+ }
+
+ public static Collection<String> getAcceleratorKeys() {
+ checkAndInit();
+ return accelerators.keySet();
+ }
+
+ public static int getAccelerator(String key) {
+ char letter;
+ if(key == null || key.equals("")) {
+ return SWT.NONE;
+ }
+ checkAndInit();
+ if(key.equals("BS")) {
+ Integer accelerator = Integer.valueOf(SWT.BS);
+ return accelerator == null ? SWT.NONE : accelerator;
+ } else if(key.equals("ENTER")) {
+ Integer accelerator = Integer.valueOf(SWT.CR);
+ return accelerator == null ? SWT.NONE : accelerator;
+ } else if(key.equals("DEL")) {
+ Integer accelerator = Integer.valueOf(SWT.DEL);
+ return accelerator == null ? SWT.NONE : accelerator;
+ } else if(key.equals("SPACE")) {
+ Integer accelerator = Integer.valueOf(' ');
+ return accelerator == null ? SWT.NONE : accelerator;
+ } else if(key.length() == 1) {
+ letter = key.charAt(0);
+ if(letter >= 'A' && letter <= 'Z' || letter >= 'a' && letter <= 'z') {
+ Integer accelerator = Integer.valueOf(letter);
+ return accelerator == null ? SWT.NONE : accelerator;
+ }
+ }
+
+ String mapKey = key.toUpperCase();
+ if(!mapKey.startsWith("SWT.")) {
+ mapKey = "SWT." + mapKey;
+ }
+
+ Integer accelerator = accelerators.get(mapKey);
+ return accelerator == null ? SWT.NONE : accelerator;
+ }
+
+ public static int getValue(String key) {
+ int value = getStyle(key);
+ if(value == SWT.NONE) {
+ value = getColor(key);
+ }
+ if(value == SWT.NONE) {
+ value = getEvent(key);
+ }
+ if(value == SWT.NONE) {
+ value = getAccelerator(key);
+ }
+ return value;
+ }
+
+ public static String getCombAccelerator(String content) {
+ if(content.equals("Alt0")) {
+ return "SWT.ALT | SWT.KEYPAD_0";
+ } else if(content.equals("Alt1")) {
+ return "SWT.ALT | SWT.KEYPAD_1";
+ } else if(content.equals("Alt2")) {
+ return "SWT.ALT | SWT.KEYPAD_2";
+ } else if(content.equals("Alt3")) {
+ return "SWT.ALT | SWT.KEYPAD_3";
+ } else if(content.equals("Alt4")) {
+ return "SWT.ALT | SWT.KEYPAD_4";
+ } else if(content.equals("Alt5")) {
+ return "SWT.ALT | SWT.KEYPAD_5";
+ } else if(content.equals("Alt6")) {
+ return "SWT.ALT | SWT.KEYPAD_6";
+ } else if(content.equals("Alt7")) {
+ return "SWT.ALT | SWT.KEYPAD_7";
+ } else if(content.equals("Alt8")) {
+ return "SWT.ALT | SWT.KEYPAD_8";
+ } else if(content.equals("Alt9")) {
+ return "SWT.ALT | SWT.KEYPAD_9";
+ } else if(content.equals("AltBksp")) {
+ return "SWT.ALT | BS";
+ } else if(content.equals("AltDownArrow")) {
+ return "SWT.ALT | SWT.ARROW_DOWN";
+ } else if(content.equals("AltF1")) {
+ return "SWT.ALT | SWT.F1";
+ } else if(content.equals("AltF10")) {
+ return "SWT.ALT | SWT.F10";
+ } else if(content.equals("AltF11")) {
+ return "SWT.ALT | SWT.F11";
+ } else if(content.equals("AltF12")) {
+ return "SWT.ALT | SWT.F12";
+ } else if(content.equals("AltF2")) {
+ return "SWT.ALT | SWT.F2";
+ } else if(content.equals("AltF3")) {
+ return "SWT.ALT | SWT.F3";
+ } else if(content.equals("AltF4")) {
+ return "SWT.ALT | SWT.F4";
+ } else if(content.equals("AltF5")) {
+ return "SWT.ALT | SWT.F5";
+ } else if(content.equals("AltF6")) {
+ return "SWT.ALT | SWT.F6";
+ } else if(content.equals("AltF7")) {
+ return "SWT.ALT | SWT.F7";
+ } else if(content.equals("AltF8")) {
+ return "SWT.ALT | SWT.F8";
+ } else if(content.equals("AltF9")) {
+ return "SWT.ALT | SWT.F9";
+ } else if(content.equals("AltLeftArrow")) {
+ return "SWT.ALT | SWT.ARROW_LEFT";
+ } else if(content.equals("AltRightArrow")) {
+ return "SWT.ALT | SWT.ARROW_RIGHT";
+ } else if(content.equals("AltUpArrow")) {
+ return "SWT.ALT | SWT.ARROW_UP";
+ } else if(content.equals("AltEnter")) {
+ return "SWT.ALT | Enter";
+ } else if(content.equals("AltSpace")) {
+ return "SWT.ALT | Space";
+ } else if(content.equals("Ctrl0")) {
+ return "SWT.CTRL | SWT.KEYPAD_0";
+ } else if(content.equals("Ctrl1")) {
+ return "SWT.CTRL | SWT.KEYPAD_1";
+ } else if(content.equals("Ctrl2")) {
+ return "SWT.CTRL | SWT.KEYPAD_2";
+ } else if(content.equals("Ctrl3")) {
+ return "SWT.CTRL | SWT.KEYPAD_3";
+ } else if(content.equals("Ctrl4")) {
+ return "SWT.CTRL | SWT.KEYPAD_4";
+ } else if(content.equals("Ctrl5")) {
+ return "SWT.CTRL | SWT.KEYPAD_5";
+ } else if(content.equals("Ctrl6")) {
+ return "SWT.CTRL | SWT.KEYPAD_6";
+ } else if(content.equals("Ctrl7")) {
+ return "SWT.CTRL | SWT.KEYPAD_7";
+ } else if(content.equals("Ctrl8")) {
+ return "SWT.CTRL | SWT.KEYPAD_8";
+ } else if(content.equals("Ctrl9")) {
+ return "SWT.CTRL | SWT.KEYPAD_9";
+ } else if(content.equals("CtrlA")) {
+ return "SWT.CTRL | A";
+ } else if(content.equals("CtrlB")) {
+ return "SWT.CTRL | B";
+ } else if(content.equals("CtrlC")) {
+ return "SWT.CTRL | C";
+ } else if(content.equals("CtrlD")) {
+ return "SWT.CTRL | D";
+ } else if(content.equals("CtrlDel")) {
+ return "SWT.CTRL | DEL";
+ } else if(content.equals("CtrlEnter")) {
+ return "SWT.CTRL | Enter";
+ } else if(content.equals("CtrlSpace")) {
+ return "SWT.CTRL | Space";
+ } else if(content.equals("CtrlE")) {
+ return "SWT.CTRL | E";
+ } else if(content.equals("CtrlF")) {
+ return "SWT.CTRL | F";
+ } else if(content.equals("CtrlF1")) {
+ return "SWT.CTRL | SWT.F1";
+ } else if(content.equals("CtrlF10")) {
+ return "SWT.CTRL | SWT.F10";
+ } else if(content.equals("CtrlF11")) {
+ return "SWT.CTRL | SWT.F11";
+ } else if(content.equals("CtrlF12")) {
+ return "SWT.CTRL | SWT.F12";
+ } else if(content.equals("CtrlF2")) {
+ return "SWT.CTRL | SWT.F2";
+ } else if(content.equals("CtrlF3")) {
+ return "SWT.CTRL | SWT.F3";
+ } else if(content.equals("CtrlF4")) {
+ return "SWT.CTRL | SWT.F4";
+ } else if(content.equals("CtrlF5")) {
+ return "SWT.CTRL | SWT.F5";
+ } else if(content.equals("CtrlF6")) {
+ return "SWT.CTRL | SWT.F6";
+ } else if(content.equals("CtrlF7")) {
+ return "SWT.CTRL | SWT.F7";
+ } else if(content.equals("CtrlF8")) {
+ return "SWT.CTRL | SWT.F8";
+ } else if(content.equals("CtrlF9")) {
+ return "SWT.CTRL | SWT.F9";
+ } else if(content.equals("CtrlG")) {
+ return "SWT.CTRL | G";
+ } else if(content.equals("CtrlH")) {
+ return "SWT.CTRL | H";
+ } else if(content.equals("CtrlI")) {
+ return "SWT.CTRL | I";
+ } else if(content.equals("CtrlIns")) {
+ return "SWT.CTRL | SWT.INSERT";
+ } else if(content.equals("CtrlJ")) {
+ return "SWT.CTRL | J";
+ } else if(content.equals("CtrlK")) {
+ return "SWT.CTRL | K";
+ } else if(content.equals("CtrlL")) {
+ return "SWT.CTRL | L";
+ } else if(content.equals("CtrlM")) {
+ return "SWT.CTRL | M";
+ } else if(content.equals("CtrlN")) {
+ return "SWT.CTRL | N";
+ } else if(content.equals("CtrlO")) {
+ return "SWT.CTRL | O";
+ } else if(content.equals("CtrlP")) {
+ return "SWT.CTRL | P";
+ } else if(content.equals("CtrlQ")) {
+ return "SWT.CTRL | Q";
+ } else if(content.equals("CtrlR")) {
+ return "SWT.CTRL | R";
+ } else if(content.equals("CtrlS")) {
+ return "SWT.CTRL | S";
+ } else if(content.equals("CtrlShift0")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_0";
+ } else if(content.equals("CtrlShift1")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_1";
+ } else if(content.equals("CtrlShift2")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_2";
+ } else if(content.equals("CtrlShift3")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_3";
+ } else if(content.equals("CtrlShift4")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_4";
+ } else if(content.equals("CtrlShift5")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_5";
+ } else if(content.equals("CtrlShift6")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_6";
+ } else if(content.equals("CtrlShift7")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_7";
+ } else if(content.equals("CtrlShift8")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_8";
+ } else if(content.equals("CtrlShift9")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.KEYPAD_9";
+ } else if(content.equals("CtrlShiftA")) {
+ return "SWT.CTRL | SWT.SHIFT | A";
+ } else if(content.equals("CtrlShiftB")) {
+ return "SWT.CTRL | SWT.SHIFT | B";
+ } else if(content.equals("CtrlShiftC")) {
+ return "SWT.CTRL | SWT.SHIFT | C";
+ } else if(content.equals("CtrlShiftD")) {
+ return "SWT.CTRL | SWT.SHIFT | D";
+ } else if(content.equals("CtrlShiftE")) {
+ return "SWT.CTRL | SWT.SHIFT | E";
+ } else if(content.equals("CtrlShiftF")) {
+ return "SWT.CTRL | SWT.SHIFT | F";
+ } else if(content.equals("CtrlShiftF1")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F1";
+ } else if(content.equals("CtrlShiftF10")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F10";
+ } else if(content.equals("CtrlShiftF11")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F11";
+ } else if(content.equals("CtrlShiftF12")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F12";
+ } else if(content.equals("CtrlShiftF2")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F2";
+ } else if(content.equals("CtrlShiftF3")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F3";
+ } else if(content.equals("CtrlShiftF4")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F4";
+ } else if(content.equals("CtrlShiftF5")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F5";
+ } else if(content.equals("CtrlShiftF6")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F6";
+ } else if(content.equals("CtrlShiftF7")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F7";
+ } else if(content.equals("CtrlShiftF8")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F8";
+ } else if(content.equals("CtrlShiftF9")) {
+ return "SWT.CTRL | SWT.SHIFT | SWT.F9";
+ } else if(content.equals("CtrlShiftH")) {
+ return "SWT.CTRL | SWT.SHIFT | H";
+ } else if(content.equals("CtrlShiftI")) {
+ return "SWT.CTRL | SWT.SHIFT | I";
+ } else if(content.equals("CtrlShiftJ")) {
+ return "SWT.CTRL | SWT.SHIFT | J";
+ } else if(content.equals("CtrlShiftK")) {
+ return "SWT.CTRL | SWT.SHIFT | K";
+ } else if(content.equals("CtrlShiftL")) {
+ return "SWT.CTRL | SWT.SHIFT | L";
+ } else if(content.equals("CtrlShiftM")) {
+ return "SWT.CTRL | SWT.SHIFT | M";
+ } else if(content.equals("CtrlShiftN")) {
+ return "SWT.CTRL | SWT.SHIFT | N";
+ } else if(content.equals("CtrlShiftO")) {
+ return "SWT.CTRL | SWT.SHIFT | O";
+ } else if(content.equals("CtrlShiftP")) {
+ return "SWT.CTRL | SWT.SHIFT | P";
+ } else if(content.equals("CtrlShiftQ")) {
+ return "SWT.CTRL | SWT.SHIFT | Q";
+ } else if(content.equals("CtrlShiftR")) {
+ return "SWT.CTRL | SWT.SHIFT | R";
+ } else if(content.equals("CtrlShiftS")) {
+ return "SWT.CTRL | SWT.SHIFT | S";
+ } else if(content.equals("CtrlShiftT")) {
+ return "SWT.CTRL | SWT.SHIFT | T";
+ } else if(content.equals("CtrlShiftU")) {
+ return "SWT.CTRL | SWT.SHIFT | U";
+ } else if(content.equals("CtrlShiftV")) {
+ return "SWT.CTRL | SWT.SHIFT | V";
+ } else if(content.equals("CtrlShiftW")) {
+ return "SWT.CTRL | SWT.SHIFT | W";
+ } else if(content.equals("CtrlShiftX")) {
+ return "SWT.CTRL | SWT.SHIFT | X";
+ } else if(content.equals("CtrlShiftY")) {
+ return "SWT.CTRL | SWT.SHIFT | Y";
+ } else if(content.equals("CtrlShiftZ")) {
+ return "SWT.CTRL | SWT.SHIFT | Z";
+ } else if(content.equals("CtrlShiftEnter")) {
+ return "SWT.CTRL | SWT.SHIFT | Enter";
+ } else if(content.equals("CtrlShiftSpace")) {
+ return "SWT.CTRL | SWT.SHIFT | Space";
+ } else if(content.equals("CtrlT")) {
+ return "SWT.CTRL | T";
+ } else if(content.equals("CtrlU")) {
+ return "SWT.CTRL | U";
+ } else if(content.equals("CtrlV")) {
+ return "SWT.CTRL | V";
+ } else if(content.equals("CtrlW")) {
+ return "SWT.CTRL | W";
+ } else if(content.equals("CtrlX")) {
+ return "SWT.CTRL | X";
+ } else if(content.equals("CtrlY")) {
+ return "SWT.CTRL | Y";
+ } else if(content.equals("CtrlZ")) {
+ return "SWT.CTRL | Z";
+ } else if(content.equals("ShiftDel")) {
+ return "SWT.SHIFT | DEL";
+ } else if(content.equals("ShiftF1")) {
+ return "SWT.SHIFT | SWT.F1";
+ } else if(content.equals("ShiftF10")) {
+ return "SWT.SHIFT | SWT.F10";
+ } else if(content.equals("ShiftF11")) {
+ return "SWT.SHIFT | SWT.F11";
+ } else if(content.equals("ShiftF12")) {
+ return "SWT.SHIFT | SWT.F12";
+ } else if(content.equals("ShiftF3")) {
+ return "SWT.SHIFT | SWT.F2";
+ } else if(content.equals("ShiftF3")) {
+ return "SWT.SHIFT | SWT.F3";
+ } else if(content.equals("ShiftF4")) {
+ return "SWT.SHIFT | SWT.F4";
+ } else if(content.equals("ShiftF5")) {
+ return "SWT.SHIFT | SWT.F5";
+ } else if(content.equals("ShiftF6")) {
+ return "SWT.SHIFT | SWT.F6";
+ } else if(content.equals("ShiftF7")) {
+ return "SWT.SHIFT | SWT.F7";
+ } else if(content.equals("ShiftF8")) {
+ return "SWT.SHIFT | SWT.F8";
+ } else if(content.equals("ShiftF9")) {
+ return "SWT.SHIFT | SWT.F9";
+ } else if(content.equals("ShiftIns")) {
+ return "SWT.SHIFT | SWT.INSERT";
+ } else if(content.equals("ShiftEnter")) {
+ return "SWT.SHIFT | Enter";
+ } else if(content.equals("ShiftSpace")) {
+ return "SWT.SHIFT | Space";
+ } else if(content.equals("Enter")) {
+ return "Enter";
+ } else if(content.equals("Space")) {
+ return "Space";
+ } else {
+ return content;
+ }
+ }
+
+ private static void tryPut(Map<String, Integer> map, String swtConst) {
+ tryPut(map, swtConst, swtConst);
+ }
+
+ private static void tryPut(Map<String, Integer> map, String mapKey, String swtConst) {
+ try {
+ map.put(mapKey, SWT.class.getField(swtConst.substring(swtConst.lastIndexOf('.') + 1, swtConst.length())).getInt(null));
+ } catch (Exception e) {
+ String message = "Failed to register SWT Constant " + swtConst + ". Excecption: " + e.getClass().getName() + " - " + e.getMessage();
+ System.out.println(message);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/animation/Drawing.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/animation/Drawing.java
new file mode 100644
index 00000000000..5e2a8855aa6
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/animation/Drawing.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ * Anyware-tech - add multiple loaders
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.animation;
+
+public class Drawing {
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/Containment.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/Containment.java
new file mode 100644
index 00000000000..425dcf1fd21
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/Containment.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * To annotate which field should be containment
+ *
+ * @author yyang
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.METHOD, ElementType.FIELD })
+public @interface Containment {
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UI.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UI.java
new file mode 100644
index 00000000000..3a18d50fd69
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UI.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface UI {
+
+ String value() default "";
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UIBounds.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UIBounds.java
new file mode 100644
index 00000000000..570fa7aaa67
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/annotation/UIBounds.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface UIBounds {
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/IBeforeParsingCallback.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/IBeforeParsingCallback.java
new file mode 100644
index 00000000000..4e62b823779
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/IBeforeParsingCallback.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.callback;
+
+public interface IBeforeParsingCallback {
+
+ String onParsing(String content);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ICreatedCallback.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ICreatedCallback.java
new file mode 100644
index 00000000000..f427d323152
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ICreatedCallback.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.callback;
+
+public interface ICreatedCallback {
+
+ void onCreated(Object sender);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ILoadedCallback.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ILoadedCallback.java
new file mode 100644
index 00000000000..87fe146038e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/callback/ILoadedCallback.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.callback;
+
+public interface ILoadedCallback {
+
+ void onLoaded(Object sender);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionView.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionView.java
new file mode 100644
index 00000000000..e73406f83a0
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionView.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.collection;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Locale;
+
+import org.eclipse.papyrus.xwt.core.ICollectionView;
+
+/**
+ * Represents a view for grouping, sorting, filtering, and navigating a data
+ * collection.`
+ *
+ * @author yyang
+ */
+public class CollectionView<T> implements ICollectionView<T> {
+
+ private T currentItem;
+
+ private int currentPosition = 0;
+
+ private Collection<T> sourceCollection = Collections.emptyList();
+
+ private GroupDescription[] groupDescription = GroupDescription.EMPTY_ARRAY;
+
+ private Collection<T> groups = Collections.emptyList();
+
+ private Locale locale = Locale.getDefault();
+
+ private SortDescription[] sortDescription = SortDescription.EMPTY_ARRAY;
+
+ public GroupDescription[] getGroupDescription() {
+ return groupDescription;
+ }
+
+ public void setGroupDescription(GroupDescription[] groupDescription) {
+ this.groupDescription = groupDescription;
+ }
+
+ public Collection<T> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Collection<T> groups) {
+ this.groups = groups;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ public SortDescription[] getSortDescription() {
+ return sortDescription;
+ }
+
+ public void setSortDescription(SortDescription[] sortDescription) {
+ this.sortDescription = sortDescription;
+ }
+
+ public void setCurrentPosition(int currentPosition) {
+ this.currentPosition = currentPosition;
+ }
+
+ public void setSourceCollection(Collection<T> sourceCollection) {
+ this.sourceCollection = sourceCollection;
+ }
+
+ public boolean canFilter() {
+ return false;
+ }
+
+ public boolean canGroup() {
+ return groupDescription.length > 0;
+ }
+
+ public boolean canSort() {
+ return sortDescription.length > 0;
+ }
+
+ public T getCurrentItem() {
+ return currentItem;
+ }
+
+ public void setCurrentItem(T currentItem) {
+ this.currentItem = currentItem;
+ }
+
+ public int getCurrentPosition() {
+ return currentPosition;
+ }
+
+ public Collection<T> getSourceCollection() {
+ return sourceCollection;
+ }
+
+ public boolean isEmpty() {
+ if(canGroup()) {
+ return groups.isEmpty();
+ }
+ return sourceCollection.isEmpty();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionViewSource.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionViewSource.java
new file mode 100644
index 00000000000..077c5e350b5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/CollectionViewSource.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.collection;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.eclipse.core.databinding.observable.IObservableCollection;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.set.WritableSet;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * The proxy of a CollectionView class.
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class CollectionViewSource {
+
+ /**
+ * Gets or sets the collection object from which to create this view. This is a dependency property.
+ */
+ private Object source;
+
+ /**
+ * Gets the view object that is currently associated with this instance of CollectionViewSource. This is a dependency property.
+ *
+ */
+ private IObservableCollection view;
+
+ private GroupDescription[] groupDescription = GroupDescription.EMPTY_ARRAY;
+
+ private SortDescription[] sortDescription = SortDescription.EMPTY_ARRAY;
+
+ private Locale locale = Locale.getDefault();
+
+ /**
+ * Gets or sets the desired view type.
+ */
+ private Class<?> collectionViewType = Object.class;
+
+ public Object getSource() {
+ if(source == null) {
+ source = new ArrayList<Object>();
+ }
+ return source;
+ }
+
+ public void setSource(Object source) {
+ if(this.source == source) {
+ return;
+ }
+ view = null;
+ this.source = source;
+ }
+
+ public IObservableCollection getView() {
+ if(view == null) {
+ Object source = getSource();
+ if(!(source instanceof IObservableCollection)) {
+ Class<?> elementType = getCollectionViewType();
+ if(source.getClass().isArray()) {
+ Object[] array = (Object[])source;
+ elementType = source.getClass().getComponentType();
+ source = Arrays.asList(array);
+ }
+ if(source instanceof List<?>) {
+ view = new WritableList(XWT.getRealm(), (List<?>)source, elementType);
+ } else if(source instanceof Set<?>) {
+ view = new WritableSet(XWT.getRealm(), (List<?>)source, elementType);
+ }
+ }
+ }
+ return view;
+ }
+
+ public GroupDescription[] getGroupDescription() {
+ return groupDescription;
+ }
+
+ public void setGroupDescription(GroupDescription[] groupDescription) {
+ this.groupDescription = groupDescription;
+ }
+
+ public SortDescription[] getSortDescription() {
+ return sortDescription;
+ }
+
+ public void setSortDescription(SortDescription[] sortDescription) {
+ this.sortDescription = sortDescription;
+ }
+
+ public Class<?> getCollectionViewType() {
+ return collectionViewType;
+ }
+
+ public void setCollectionViewType(Class<?> collectionViewType) {
+ this.collectionViewType = collectionViewType;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/GroupDescription.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/GroupDescription.java
new file mode 100644
index 00000000000..3975bc4bb57
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/GroupDescription.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.collection;
+
+/**
+ * Provides an abstract base class for types that describe how to divide the items in a collection into groups.
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class GroupDescription {
+
+ public static GroupDescription[] EMPTY_ARRAY = new GroupDescription[0];
+
+ /**
+ * Gets the collection of names that are used to initialize a group with a set of subgroups with the given names.
+ */
+ protected String[] groupNames;
+
+ /**
+ *
+ * @return
+ */
+ public String[] getGroupNames() {
+ return groupNames;
+ }
+
+ /**
+ *
+ * @param groupNames
+ */
+ public void setGroupNames(String[] groupNames) {
+ this.groupNames = groupNames;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/ListSortDirection.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/ListSortDirection.java
new file mode 100644
index 00000000000..867f60b2a18
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/ListSortDirection.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.collection;
+
+/**
+ * Specifies the direction of a sort operation.
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public enum ListSortDirection {
+ Ascending, Descending;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/SortDescription.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/SortDescription.java
new file mode 100644
index 00000000000..9eb9331ef16
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/collection/SortDescription.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.collection;
+
+/**
+ * Defines the direction and the property name to be used as the criteria for sorting a collection.
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class SortDescription {
+
+ public static SortDescription[] EMPTY_ARRAY = new SortDescription[0];
+
+ /**
+ * Gets or sets a value that indicates whether to sort in ascending or descending order.
+ */
+ private ListSortDirection direction = ListSortDirection.Ascending;
+
+ /**
+ * Gets or sets the property name being used as the sorting criteria.
+ */
+ private String propertyName;
+
+ public ListSortDirection getDirection() {
+ return direction;
+ }
+
+ public void setDirection(ListSortDirection direction) {
+ this.direction = direction;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void setPropertyName(String propertyName) {
+ this.propertyName = propertyName;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/AbstractMultiValueConverter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/AbstractMultiValueConverter.java
new file mode 100644
index 00000000000..09a07ae6a01
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/AbstractMultiValueConverter.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.papyrus.xwt.IMultiValueConverter;
+
+/**
+ * Default implementation class of IMultiValueConverter
+ *
+ * @author yyang <yesc.yang@soyatec.com>
+ */
+public abstract class AbstractMultiValueConverter implements IMultiValueConverter {
+
+ public Object convert(Object fromObject) {
+ if(!fromObject.getClass().isArray()) {
+ fromObject = new Object[]{ fromObject };
+ }
+ return convert((Object[])fromObject);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/BindingToObject.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/BindingToObject.java
new file mode 100644
index 00000000000..a022425c8be
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/BindingToObject.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.core.IBinding;
+
+/**
+ * Binding to Object covnerter
+ *
+ * @author yyang
+ */
+public class BindingToObject implements IConverter {
+
+ public static BindingToObject instance = new BindingToObject();
+
+ public Object convert(Object fromObject) {
+ IBinding binding = (IBinding)fromObject;
+ return binding.getValue(null);
+ }
+
+ public Object getFromType() {
+ return IBinding.class;
+ }
+
+ public Object getToType() {
+ return Object.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToBoolean.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToBoolean.java
new file mode 100644
index 00000000000..ac8df855a7a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToBoolean.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.Collection;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * String to Boolean converter
+ *
+ * @author yyang
+ */
+public class CollectionToBoolean implements IConverter {
+
+ public static CollectionToBoolean instance = new CollectionToBoolean();
+
+ public Object convert(Object fromObject) {
+ Collection<?> collection = (Collection<?>)fromObject;
+ return !collection.isEmpty();
+ }
+
+ public Object getFromType() {
+ return Collection.class;
+ }
+
+ public Object getToType() {
+ return Boolean.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToInteger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToInteger.java
new file mode 100644
index 00000000000..cc9ce10b764
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/CollectionToInteger.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.Collection;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * String to Boolean converter
+ *
+ * @author yyang
+ */
+public class CollectionToInteger implements IConverter {
+
+ public static CollectionToInteger instance = new CollectionToInteger();
+
+ public Object convert(Object fromObject) {
+ Collection<?> collection = (Collection<?>)fromObject;
+ return collection.size();
+ }
+
+ public Object getFromType() {
+ return Collection.class;
+ }
+
+ public Object getToType() {
+ return Integer.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/DateToString.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/DateToString.java
new file mode 100644
index 00000000000..cdaa1d986b3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/DateToString.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Date to String converter
+ *
+ * @author yyang
+ */
+public class DateToString extends ObjectToString {
+
+ private static final SimpleDateFormat FORMATTER = new SimpleDateFormat();
+
+ public static DateToString instance = new DateToString();
+
+ public DateToString() {
+ this(Date.class);
+ }
+
+ protected DateToString(Class<?> fromType) {
+ super(fromType);
+ }
+
+ public Object convert(Object fromObject) {
+ if(fromObject == null) {
+ return super.convert(null);
+ }
+ return FORMATTER.format((Date)fromObject);
+ }
+
+ public Object getToType() {
+ return String.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/EnumToString.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/EnumToString.java
new file mode 100644
index 00000000000..f80d3209b2d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/EnumToString.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+public class EnumToString implements IConverter {
+
+ public static EnumToString instance = new EnumToString();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ return ((Enum<?>)fromObject).toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return Enum.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return String.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToBoolean.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToBoolean.java
new file mode 100644
index 00000000000..28091df5276
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToBoolean.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Binding to Object covnerter
+ *
+ * @author yyang
+ */
+public class IStatusToBoolean implements IConverter {
+
+ public static IStatusToBoolean instance = new IStatusToBoolean();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
+ */
+ public Object convert(Object fromObject) {
+ IStatus status = (IStatus)fromObject;
+ return status.isOK();
+ }
+
+ public Object getFromType() {
+ return IStatus.class;
+ }
+
+ public Object getToType() {
+ return Boolean.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToString.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToString.java
new file mode 100644
index 00000000000..27086fc73ce
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/IStatusToString.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Binding to Object covnerter
+ *
+ * @author yyang
+ */
+public class IStatusToString implements IConverter {
+
+ public static IStatusToString instance = new IStatusToString();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
+ */
+ public Object convert(Object fromObject) {
+ IStatus status = (IStatus)fromObject;
+ if(status.isOK()) {
+ return "";
+ }
+ return status.getMessage();
+ }
+
+ public Object getFromType() {
+ return IStatus.class;
+ }
+
+ public Object getToType() {
+ return String.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToIObservableCollection.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToIObservableCollection.java
new file mode 100644
index 00000000000..df911898720
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToIObservableCollection.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.List;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.IObservableCollection;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * List to IObservableCollection converter
+ *
+ * @author yyang
+ */
+public class ListToIObservableCollection implements IConverter {
+
+ public static ListToIObservableCollection instance = new ListToIObservableCollection();
+
+ public Object convert(Object fromObject) {
+ List<?> list = (List<?>)fromObject;
+ return new WritableList(XWT.getRealm(), (List<?>)list, Object.class);
+ }
+
+ public Object getFromType() {
+ return List.class;
+ }
+
+ public Object getToType() {
+ return IObservableCollection.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToSet.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToSet.java
new file mode 100644
index 00000000000..e9d673ba305
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ListToSet.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * String to Boolean converter
+ *
+ * @author yyang
+ */
+public class ListToSet implements IConverter {
+
+ public static ListToSet instance = new ListToSet();
+
+ public Object convert(Object fromObject) {
+ List<?> list = (List<?>)fromObject;
+ return new HashSet<Object>(list);
+ }
+
+ public Object getFromType() {
+ return List.class;
+ }
+
+ public Object getToType() {
+ return Set.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToBoolean.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToBoolean.java
new file mode 100644
index 00000000000..4c1e01e5743
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToBoolean.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * String to Boolean converter
+ *
+ * @author yyang
+ */
+public class ObjectToBoolean implements IConverter {
+
+ public static ObjectToBoolean instance = new ObjectToBoolean();
+
+ public Object convert(Object fromObject) {
+ return fromObject != null;
+ }
+
+ public Object getFromType() {
+ return Object.class;
+ }
+
+ public Object getToType() {
+ return Boolean.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToISelection.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToISelection.java
new file mode 100644
index 00000000000..59cd56de292
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToISelection.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.Collection;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * Safely SWT context values, it used to avoid a NullPointerException when set
+ * text values to SWT Widgets.
+ *
+ * @author jliu
+ */
+public class ObjectToISelection implements IConverter {
+
+ public static ObjectToISelection instance = new ObjectToISelection();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
+ */
+ public Object convert(Object fromObject) {
+ if(fromObject == null) {
+ return new StructuredSelection();
+ }
+ if(fromObject instanceof Collection<?>) {
+ return new StructuredSelection(((Collection<?>)fromObject).toArray());
+ } else if(fromObject.getClass().isArray()) {
+ return new StructuredSelection((Object[])fromObject);
+ }
+ return new StructuredSelection(fromObject);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return Object.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return ISelection.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToObject.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToObject.java
new file mode 100644
index 00000000000..02943c56f5f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToObject.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * Object to Object converter: null converter
+ *
+ * @author yyang
+ */
+public class ObjectToObject implements IConverter {
+
+ public static ObjectToObject instance = new ObjectToObject();
+
+ public Object convert(Object fromObject) {
+ return fromObject;
+ }
+
+ public Object getFromType() {
+ return Object.class;
+ }
+
+ public Object getToType() {
+ return Object.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToString.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToString.java
new file mode 100644
index 00000000000..36dbb505f83
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ObjectToString.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * Safely SWT context values, it used to avoid a NullPointerException when set text values to SWT Widgets.
+ *
+ * @author jliu
+ */
+public class ObjectToString implements IConverter {
+
+ public static ObjectToString FROM_OBJECT = new ObjectToString(Object.class);
+
+ public static ObjectToString FROM_INTEGER = new ObjectToString(Integer.class);
+
+ public static ObjectToString FROM_SHORT = new ObjectToString(Short.class);
+
+ public static ObjectToString FROM_LONG = new ObjectToString(Long.class);
+
+ private Class<?> fromType;
+
+ public ObjectToString(Class<?> fromType) {
+ this.fromType = fromType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ if(fromObject == null) {
+ return "";
+ }
+ return fromObject.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ if(fromType == null) {
+ return Object.class;
+ }
+ return fromType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return String.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SelectionToBoolean.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SelectionToBoolean.java
new file mode 100644
index 00000000000..ca3405628d6
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SelectionToBoolean.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.ISelection;
+
+/**
+ * String to Boolean converter
+ *
+ * @author yyang
+ */
+public class SelectionToBoolean implements IConverter {
+
+ public static SelectionToBoolean instance = new SelectionToBoolean();
+
+ public Object convert(Object fromObject) {
+ ISelection selection = (ISelection)fromObject;
+ return !selection.isEmpty();
+ }
+
+ public Object getFromType() {
+ return ISelection.class;
+ }
+
+ public Object getToType() {
+ return Boolean.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SetToIObservableCollection.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SetToIObservableCollection.java
new file mode 100644
index 00000000000..aa694a9ff8b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/SetToIObservableCollection.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.Set;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.IObservableCollection;
+import org.eclipse.core.databinding.observable.set.WritableSet;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * Set to IObservableCollection converter
+ *
+ * @author yyang
+ */
+public class SetToIObservableCollection implements IConverter {
+
+ public static SetToIObservableCollection instance = new SetToIObservableCollection();
+
+ public Object convert(Object fromObject) {
+ Set<?> set = (Set<?>)fromObject;
+ return new WritableSet(XWT.getRealm(), (Set<?>)set, Object.class);
+ }
+
+ public Object getFromType() {
+ return Set.class;
+ }
+
+ public Object getToType() {
+ return IObservableCollection.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringMultiValueConerter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringMultiValueConerter.java
new file mode 100644
index 00000000000..08f558227fd
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringMultiValueConerter.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+/**
+ * Default implementation of MultiValueConverter from a string
+ *
+ * @author yyang <yesc.yang@soyatec.com>
+ *
+ */
+public class StringMultiValueConerter extends AbstractMultiValueConverter {
+
+ private String separatorExpression = null;
+
+ public Object[] convertBack(Object value) {
+ if(value instanceof Object[]) {
+ return (Object[])value;
+ }
+ String valueString = value.toString();
+ return valueString.split(getSeparatorExpression());
+ }
+
+ public String getSeparatorExpression() {
+ if(separatorExpression == null) {
+ return "[ \t\r\n]+";
+ }
+ return separatorExpression;
+ }
+
+ public void setSeparatorExpression(String separatorExpression) {
+ this.separatorExpression = separatorExpression;
+ }
+
+ protected String getSeparator() {
+ if(separatorExpression == null || separatorExpression.length() == 0) {
+ return " ";
+ }
+ return "" + separatorExpression.charAt(0);
+ }
+
+ public Object convert(Object[] value) {
+ StringBuffer buffer = new StringBuffer();
+ String separator = getSeparator();
+ for(int i = 0; i < value.length; i++) {
+ if(i != 0) {
+ buffer.append(separator);
+ }
+ buffer.append(value[i]);
+ }
+ return buffer.toString();
+ }
+
+ public Object getFromType() {
+ return String[].class;
+ }
+
+ public Object getToType() {
+ return String.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToBoolean.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToBoolean.java
new file mode 100644
index 00000000000..3916aede3b1
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToBoolean.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.XWTException;
+
+/**
+ * String to Boolean converter
+ *
+ * @author yyang
+ */
+public class StringToBoolean implements IConverter {
+
+ public static StringToBoolean instance = new StringToBoolean();
+
+ public Object convert(Object fromObject) {
+ String str = (String)fromObject;
+ if(str == null || "".equalsIgnoreCase(str)) {
+ return false;
+ } else if("true".equalsIgnoreCase(str)) {
+ return true;
+ } else if("false".equalsIgnoreCase(str)) {
+ return false;
+ }
+ throw new XWTException(str + " is not a boolean");
+ }
+
+ public Object getFromType() {
+ return String.class;
+ }
+
+ public Object getToType() {
+ return Boolean.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToColor.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToColor.java
new file mode 100644
index 00000000000..a057fa83bd3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToColor.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.utils.ResourceManager;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * String to Color converter
+ *
+ * @author jliu
+ */
+public class StringToColor implements IConverter {
+
+ public static StringToColor instance = new StringToColor();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ return ResourceManager.resources.getColor((String)fromObject);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return Color.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToDoubleArray.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToDoubleArray.java
new file mode 100644
index 00000000000..e46de8a76fe
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToDoubleArray.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.XWTException;
+
+/**
+ * String to double[] converter
+ *
+ * @author jliu
+ */
+public class StringToDoubleArray implements IConverter {
+
+ public static StringToDoubleArray instance = new StringToDoubleArray();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang. Object)
+ */
+ public Object convert(Object fromObject) {
+ String source = (String)fromObject;
+ List<Double> result = new ArrayList<Double>();
+ StringTokenizer stk = new StringTokenizer(source, ", \t\n\r\f");
+ while(stk.hasMoreTokens()) {
+ String nextToken = stk.nextToken();
+ try {
+ result.add(Double.parseDouble(nextToken.trim()));
+ } catch (NumberFormatException e) {
+ throw new XWTException(source + " is not integer array");
+ }
+ }
+ double[] intArray = new double[result.size()];
+ for(int i = 0; i < result.size(); i++) {
+ intArray[i] = result.get(i);
+ }
+ return intArray;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return double[].class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToEnum.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToEnum.java
new file mode 100644
index 00000000000..48bb8b03ffa
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToEnum.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class StringToEnum implements IConverter {
+
+ private Class<?> toType;
+
+ public StringToEnum(Class<?> toType) {
+ this.toType = toType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ if(fromObject == null || "".equals(fromObject)) {
+ Class<?> type = (Class<?>)getToType();
+ Object[] values = type.getEnumConstants();
+ if(values != null && values.length > 0) {
+ return values[0];
+ }
+ }
+
+ return Enum.valueOf((Class)getToType(), (String)fromObject);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return toType;
+ }
+
+ public void setToType(Class<?> toType) {
+ this.toType = toType;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFont.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFont.java
new file mode 100644
index 00000000000..a6701ae7df8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFont.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.utils.ResourceManager;
+import org.eclipse.swt.graphics.Font;
+
+/**
+ * String to Font converter
+ *
+ * @author yyang
+ */
+public class StringToFont implements IConverter {
+
+ public static StringToFont instance = new StringToFont();
+
+ public Object convert(Object fromObject) {
+ return ResourceManager.resources.getFont((String)fromObject);
+ }
+
+ public Object getFromType() {
+ return String.class;
+ }
+
+ public Object getToType() {
+ return Font.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFormAttachment.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFormAttachment.java
new file mode 100644
index 00000000000..4db2206f283
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToFormAttachment.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.swt.layout.FormAttachment;
+
+/**
+ * This converter can easily convert string value to FormAttachment object in these format:
+ * <nl>
+ * <li><FormData top="0"></li> would be parsed to FormAttachment(0).
+ * <li><FormData top="0,20"></li> would be parsed to FormAttachment(0, 20).
+ * <li><FormData top="0,100,20"></li> would be parsed to FormAttachment(0, 100, 20).
+ * <nl>
+ * This converter can not parse some arguments which have Control type.
+ *
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class StringToFormAttachment implements IConverter {
+
+ public static IConverter instance = new StringToFormAttachment();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ if(fromObject == null) {
+ return null;
+ }
+ String strValue = fromObject.toString();
+ int numerator = 0, denominator = 100, offset = 0;
+ List<Integer> intValues = new ArrayList<Integer>();
+ String[] split = strValue.split(",");
+ for(int i = 0; i < split.length; i++) {
+ String trim = split[i].trim();
+ try {
+ int value = Integer.parseInt(trim);
+ intValues.add(value);
+ } catch (NumberFormatException e) {
+ }
+ }
+ FormAttachment result = new FormAttachment();
+ int size = intValues.size();
+ try {
+ numerator = intValues.get(0);
+ if(size == 2) {
+ offset = intValues.get(1);
+ } else if(size == 3) {
+ denominator = intValues.get(1);
+ offset = intValues.get(2);
+ }
+ } catch (Exception e) {
+ }
+ result.denominator = denominator;
+ result.numerator = numerator;
+ result.offset = offset;
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return FormAttachment.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValidationRule.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValidationRule.java
new file mode 100644
index 00000000000..a22563550d4
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValidationRule.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.IValidationRule;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class StringToIValidationRule implements IConverter {
+
+ public static StringToIValidationRule instance = new StringToIValidationRule();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ try {
+ Class<?> type = XWT.getLoadingContext().loadClass(fromObject.toString());
+ if(type == null) {
+ throw new XWTException("Class " + fromObject.toString() + " is not found.");
+ }
+ return type.newInstance();
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return IValidationRule.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValueConverter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValueConverter.java
new file mode 100644
index 00000000000..9ba8d90480f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIValueConverter.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class StringToIValueConverter implements IConverter {
+
+ public static StringToIValueConverter instance = new StringToIValueConverter();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ try {
+ Class<?> type = XWT.getLoadingContext().loadClass(fromObject.toString());
+ if(type == null) {
+ throw new XWTException("Class " + fromObject.toString() + " is not found.");
+ }
+ return type.newInstance();
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return IValueConverter.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToImage.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToImage.java
new file mode 100644
index 00000000000..f9a9466127d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToImage.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.utils.ResourceManager;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * String to Image converter
+ *
+ * @author jliu
+ */
+public class StringToImage implements IConverter {
+
+ public static StringToImage instance = new StringToImage();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ return ResourceManager.resources.getImage((String)fromObject);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return Image.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIntArray.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIntArray.java
new file mode 100644
index 00000000000..a64e0ae440d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToIntArray.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.XWTException;
+
+/**
+ * String to int[] converter
+ *
+ * @author jliu
+ */
+public class StringToIntArray implements IConverter {
+
+ public static StringToIntArray instance = new StringToIntArray();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang. Object)
+ */
+ public Object convert(Object fromObject) {
+ String source = (String)fromObject;
+ List<Integer> result = new ArrayList<Integer>();
+ StringTokenizer stk = new StringTokenizer(source, ",");
+ while(stk.hasMoreTokens()) {
+ String nextToken = stk.nextToken();
+ try {
+ result.add(Integer.parseInt(nextToken.trim()));
+ } catch (NumberFormatException e) {
+ throw new XWTException(source + " is not integer array");
+ }
+ }
+ int[] intArray = new int[result.size()];
+ for(int i = 0; i < result.size(); i++) {
+ intArray[i] = result.get(i);
+ }
+ return intArray;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return int[].class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToInteger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToInteger.java
new file mode 100644
index 00000000000..02be7ae714e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToInteger.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.conversion.StringToNumberConverter;
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.swt.layout.GridData;
+
+/**
+ * String to Integer converter
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class StringToInteger implements IConverter {
+
+ private static final String GRIDDATA_PREFIX = "GRIDDATA.";
+
+ private static final String STYLES_SEP = "|";
+
+ public static StringToInteger instance = new StringToInteger();
+
+ protected StringToNumberConverter toNumberConverter = StringToNumberConverter.toInteger(false);
+
+ public Object convert(Object fromObject) {
+ String str = (String)fromObject;
+ if(str.indexOf(STYLES_SEP) != -1) {
+ List<String> values = new ArrayList<String>();
+ StringTokenizer stk = new StringTokenizer(str, STYLES_SEP);
+ while(stk.hasMoreTokens()) {
+ values.add(stk.nextToken());
+ }
+ int result = 0;
+ for(String value : values) {
+ result |= convertInt(value.trim());
+ }
+ return result;
+ }
+ return convertInt(str);
+ }
+
+ protected int convertInt(String str) {
+ if(str == null || str.equals("")) {
+ return 0;
+ }
+ try {
+ // Quick solution for numbers.
+ return (Integer)toNumberConverter.convert(str);
+ } catch (Exception e) {
+ String normalizedStr = str.toUpperCase().trim();
+ if(normalizedStr.startsWith(GRIDDATA_PREFIX)) {
+ return convertGridDataInt(normalizedStr);
+ }
+ try {
+ int index = str.lastIndexOf('.');
+ if(str.indexOf('.') != -1) {
+ String className = str.substring(0, index);
+ if(className.startsWith("(") && className.endsWith("")) {
+ className = className.substring(1, className.length() - 1);
+ Class<?> type = XWT.getLoadingContext().loadClass(className);
+ if(type != null) {
+ String memberName = str.substring(index + 1);
+ Field field = type.getField(memberName);
+ if(Modifier.isStatic(field.getModifiers())) {
+ return field.getInt(null);
+ }
+ }
+ } else {
+ IMetaclass metaclass = XWT.getMetaclass(className, IConstants.XWT_NAMESPACE);
+ if(metaclass != null) {
+ Class<?> type = metaclass.getType();
+ if(type != null) {
+ String memberName = str.substring(index + 1);
+ Field field = type.getField(memberName);
+ if(Modifier.isStatic(field.getModifiers())) {
+ return field.getInt(null);
+ }
+ }
+ }
+ }
+ }
+ } catch (SecurityException e1) {
+ } catch (IllegalArgumentException e1) {
+ } catch (NoSuchFieldException e1) {
+ } catch (IllegalAccessException e1) {
+ } catch (XWTException e1) {
+ }
+ return defaultConvertInt(str);
+ }
+ }
+
+ protected int convertGridDataInt(String str) {
+ if("GridData.BEGINNING".equalsIgnoreCase(str)) {
+ return GridData.BEGINNING;
+ } else if("GridData.CENTER".equalsIgnoreCase(str)) {
+ return GridData.CENTER;
+ } else if("GridData.END".equalsIgnoreCase(str)) {
+ return GridData.END;
+ } else if("GridData.FILL".equalsIgnoreCase(str)) {
+ return GridData.FILL;
+ } else if("GridData.FILL_BOTH".equalsIgnoreCase(str)) {
+ return GridData.FILL_BOTH;
+ } else if("GridData.FILL_HORIZONTAL".equalsIgnoreCase(str)) {
+ return GridData.FILL_HORIZONTAL;
+ } else if("GridData.GRAB_HORIZONTAL".equalsIgnoreCase(str)) {
+ return GridData.GRAB_HORIZONTAL;
+ } else if("GridData.GRAB_VERTICAL".equalsIgnoreCase(str)) {
+ return GridData.GRAB_VERTICAL;
+ } else if("GridData.HORIZONTAL_ALIGN_BEGINNING".equalsIgnoreCase(str)) {
+ return GridData.HORIZONTAL_ALIGN_BEGINNING;
+ } else if("GridData.HORIZONTAL_ALIGN_CENTER".equalsIgnoreCase(str)) {
+ return GridData.HORIZONTAL_ALIGN_CENTER;
+ } else if("GridData.HORIZONTAL_ALIGN_END".equalsIgnoreCase(str)) {
+ return GridData.HORIZONTAL_ALIGN_END;
+ } else if("GridData.HORIZONTAL_ALIGN_FILL".equalsIgnoreCase(str)) {
+ return GridData.HORIZONTAL_ALIGN_FILL;
+ } else if("GridData.VERTICAL_ALIGN_BEGINNING".equalsIgnoreCase(str)) {
+ return GridData.VERTICAL_ALIGN_BEGINNING;
+ } else if("GridData.VERTICAL_ALIGN_CENTER".equalsIgnoreCase(str)) {
+ return GridData.VERTICAL_ALIGN_CENTER;
+ } else if("GridData.VERTICAL_ALIGN_END".equalsIgnoreCase(str)) {
+ return GridData.VERTICAL_ALIGN_END;
+ } else if("GridData.VERTICAL_ALIGN_FILL".equalsIgnoreCase(str)) {
+ return GridData.VERTICAL_ALIGN_FILL;
+ }
+ return 0;
+ }
+
+ protected int defaultConvertInt(String str) {
+ return XWTMaps.getValue(str);
+ }
+
+ public Object getFromType() {
+ return String.class;
+ }
+
+ public Object getToType() {
+ return Integer.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToPoint.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToPoint.java
new file mode 100644
index 00000000000..acdb36963ec
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToPoint.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * String to Point converter
+ *
+ * @author yyang
+ */
+public class StringToPoint implements IConverter {
+
+ public static StringToPoint instance = new StringToPoint();
+
+ public Object convert(Object fromObject) {
+ int x = 0;
+ int y = 0;
+ if(fromObject != null) {
+ StringToIntArray convArray = new StringToIntArray();
+ int[] array = (int[])convArray.convert(fromObject);
+ if(array.length == 2) {
+ x = array[0];
+ y = array[1];
+ }
+ }
+ return new Point(x, y);
+ }
+
+ public Object getFromType() {
+ return String.class;
+ }
+
+ public Object getToType() {
+ return Point.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToRectangle.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToRectangle.java
new file mode 100644
index 00000000000..dfb68007de0
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToRectangle.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * String to Rectangle converter
+ *
+ * @author yyang
+ */
+public class StringToRectangle implements IConverter {
+
+ public static StringToRectangle instance = new StringToRectangle();
+
+ public Object convert(Object fromObject) {
+ int x = 0;
+ int y = 0;
+ int width = 0;
+ int height = 0;
+ if(fromObject != null) {
+ StringToIntArray arrayConvertor = new StringToIntArray();
+ int[] array = (int[])arrayConvertor.convert(fromObject);
+ if(array.length == 4) {
+ x = array[0];
+ y = array[1];
+ width = array[2];
+ height = array[3];
+ }
+ }
+ return new Rectangle(x, y, width, height);
+ }
+
+ public Object getFromType() {
+ return String.class;
+ }
+
+ public Object getToType() {
+ return Rectangle.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToType.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToType.java
new file mode 100644
index 00000000000..fd84ec08468
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToType.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+
+/**
+ * String to Type converter
+ *
+ * @author yyang
+ */
+public class StringToType implements IConverter {
+
+ public static StringToType instance = new StringToType();
+
+ public Object convert(Object fromObject) {
+ String str = (String)fromObject;
+ String typeName = str;
+ String namespace = IConstants.XWT_NAMESPACE;
+ int index = str.lastIndexOf(':');
+ if(index != -1) {
+ typeName = str.substring(index + 1);
+ namespace = str.substring(0, index);
+ }
+ IMetaclass metaclass = XWT.getMetaclass(typeName, namespace);
+ if(metaclass != null) {
+ return metaclass.getType();
+ }
+ return null;
+ }
+
+ public Object getFromType() {
+ return String.class;
+ }
+
+ public Object getToType() {
+ return Class.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToURL.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToURL.java
new file mode 100644
index 00000000000..8435f87d64b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/StringToURL.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class StringToURL implements IConverter {
+
+ public static StringToURL instance = new StringToURL();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ try {
+ return new URL(fromObject.toString());
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getFromType()
+ */
+ public Object getFromType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#getToType()
+ */
+ public Object getToType() {
+ return URL.class;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ValueConverterAdapter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ValueConverterAdapter.java
new file mode 100644
index 00000000000..9a17df4712d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/converters/ValueConverterAdapter.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.converters;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * The operation to inverse the converter direction.
+ *
+ * @author yyang
+ *
+ */
+public class ValueConverterAdapter implements IValueConverter {
+
+ private IConverter fromConvertor;
+
+ private IConverter toConvertor;
+
+ public ValueConverterAdapter(IConverter fromConvertor, IConverter toConvertor) {
+ this.fromConvertor = fromConvertor;
+ this.toConvertor = toConvertor;
+ }
+
+ public Object convertBack(Object value) {
+ return toConvertor.convert(value);
+ }
+
+ public Object convert(Object fromObject) {
+ return fromConvertor.convert(fromObject);
+ }
+
+ public Object getFromType() {
+ return fromConvertor.getFromType();
+ }
+
+ public Object getToType() {
+ return toConvertor.getFromType();
+ }
+
+ public static ValueConverterAdapter create(Class<?> sourceType, Class<?> targetType) {
+ IConverter fromConvertor = XWT.findConvertor(sourceType, targetType);
+ if(fromConvertor == null) {
+ return null;
+ }
+ IConverter toConvertor = XWT.findConvertor(targetType, sourceType);
+ if(toConvertor == null) {
+ return null;
+ }
+ return new ValueConverterAdapter(fromConvertor, toConvertor);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/AbstractEventGroup.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/AbstractEventGroup.java
new file mode 100644
index 00000000000..643fececb19
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/AbstractEventGroup.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.papyrus.xwt.IEventGroup;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public abstract class AbstractEventGroup implements IEventGroup {
+
+ protected String[] names;
+
+ public AbstractEventGroup(String... names) {
+ this.names = names;
+ }
+
+ public String[] getEventNames() {
+ return names;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Condition.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Condition.java
new file mode 100644
index 00000000000..fd5d4b8897a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Condition.java
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class Condition {
+
+ public static final Condition[] EMPTY_ARRAY = new Condition[0];
+
+ private IBinding binding;
+
+ private String property;
+
+ private Operator operator = Operator.EQ;
+
+ private String sourceName;
+
+ private Object value;
+
+ private CacheData cacheData;
+
+ static class CacheData {
+
+ protected Object value;
+
+ protected IProperty property;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public IBinding getBinding() {
+ return binding;
+ }
+
+ public void setBinding(IBinding binding) {
+ this.binding = binding;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ public void setSourceName(String sourceName) {
+ this.sourceName = sourceName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public boolean evaluate(Object element) {
+ String propertyName = getProperty();
+ String sourceName = getSourceName();
+ IBinding binding = getBinding();
+ Object value = getValue();
+ if(value == null) {
+ return false;
+ }
+ while(value instanceof IObservableValue) {
+ value = ((IObservableValue)value).getValue();
+ }
+
+ Object dataObject = TriggerBase.getElementByName(element, sourceName);
+
+ if(propertyName != null) {
+ if(cacheData != null) {
+ try {
+ Object existingValue = cacheData.property.getValue(dataObject);
+ return Operator.compare(existingValue, operator, cacheData.value);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ }
+ cacheData = new CacheData();
+
+ IMetaclass metaclass = XWT.getMetaclass(dataObject);
+ IProperty prop = metaclass.findProperty(propertyName);
+ if(prop != null && value != null) {
+ cacheData.property = prop;
+ Class<?> valueType = value.getClass();
+ IConverter converter = XWT.findConvertor(valueType, prop.getType());
+ Object trueValue = value;
+ if(converter != null) {
+ trueValue = converter.convert(trueValue);
+ }
+ cacheData.value = trueValue;
+ try {
+ Object existingValue = prop.getValue(dataObject);
+ return Operator.compare(existingValue, operator, trueValue);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ }
+ } else if(binding != null) {
+ Object existingValue = binding.getValue(null);
+ if(existingValue == null) {
+ return false;
+ }
+ while(existingValue instanceof IObservableValue) {
+ existingValue = ((IObservableValue)existingValue).getValue();
+ }
+ Class<?> existingValueType = existingValue.getClass();
+ Class<?> valueType = value.getClass();
+ Object normalizedValue = value;
+ if(!existingValueType.isAssignableFrom(valueType) && !valueType.isAssignableFrom(existingValueType)) {
+ IConverter converter = XWT.findConvertor(valueType, existingValueType);
+ if(converter != null) {
+ normalizedValue = converter.convert(normalizedValue);
+ } else if(value.toString().trim().length() > 0) {
+ boolean found = false;
+ // in case where the value is a boolean
+ converter = XWT.findConvertor(valueType, Boolean.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(existingValueType, Boolean.class);
+ if(converter != null) {
+ existingValue = converter.convert(existingValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (RuntimeException e) {
+ }
+ }
+ if(!found) {
+ converter = XWT.findConvertor(valueType, int.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(existingValueType, int.class);
+ if(converter != null) {
+ existingValue = converter.convert(existingValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ if(!found) {
+ converter = XWT.findConvertor(valueType, double.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(existingValueType, double.class);
+ if(converter != null) {
+ existingValue = converter.convert(existingValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ if(!found) {
+ converter = XWT.findConvertor(valueType, String.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(existingValueType, String.class);
+ if(converter != null) {
+ existingValue = converter.convert(existingValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+ }
+ return Operator.compare(existingValue, operator, normalizedValue);
+ }
+ return false;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/DataTrigger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/DataTrigger.java
new file mode 100644
index 00000000000..7eee717cbde
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/DataTrigger.java
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class DataTrigger extends TriggerBase {
+
+ private Object value;
+
+ private Operator operator = Operator.EQ;
+
+ private IBinding binding;
+
+ private SetterBase[] setters;
+
+ private ValueChangeListener changeListener;
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public IBinding getBinding() {
+ return binding;
+ }
+
+ public void setBinding(IBinding binding) {
+ this.binding = binding;
+ }
+
+ public SetterBase[] getSetters() {
+ if(setters == null) {
+ return Setter.EMPTY_SETTERS;
+ }
+ return setters;
+ }
+
+ public void setSetters(SetterBase[] setters) {
+ this.setters = setters;
+ }
+
+ class ValueChangeListener extends AbstractChangeListener {
+
+ public ValueChangeListener(Object element) {
+ super(element);
+ }
+
+ public void handleChange(ChangeEvent event) {
+ doHandleChange(true);
+ }
+
+ public void doHandleChange(boolean update) {
+ Widget widget = UserData.getWidget(element);
+ if(widget == null) {
+ return;
+ }
+ Object currentValue = binding.getValue(null);
+ if(currentValue == null) {
+ return;
+ }
+ while(currentValue instanceof IObservableValue) {
+ currentValue = ((IObservableValue)currentValue).getValue();
+ }
+
+ Class<?> currentValueType = currentValue.getClass();
+ Class<?> valueType = value.getClass();
+ Object normalizedValue = value;
+ if(!currentValueType.isAssignableFrom(valueType) && !valueType.isAssignableFrom(currentValueType)) {
+ IConverter converter = XWT.findConvertor(valueType, currentValueType);
+ if(converter != null) {
+ normalizedValue = converter.convert(normalizedValue);
+ } else if(value != null && value.toString().trim().length() > 0) {
+ boolean found = false;
+ // in case where the value is a boolean
+ converter = XWT.findConvertor(valueType, Boolean.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(currentValueType, Boolean.class);
+ if(converter != null) {
+ currentValue = converter.convert(currentValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (RuntimeException e) {
+ }
+ }
+ if(!found) {
+ converter = XWT.findConvertor(valueType, Integer.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(currentValueType, Integer.class);
+ if(converter != null) {
+ currentValue = converter.convert(currentValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ if(!found) {
+ converter = XWT.findConvertor(valueType, Double.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(currentValueType, Double.class);
+ if(converter != null) {
+ currentValue = converter.convert(currentValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ if(!found) {
+ converter = XWT.findConvertor(valueType, String.class);
+ if(converter != null) {
+ try {
+ Object booleanValue = converter.convert(value);
+ if(booleanValue != null) {
+ converter = XWT.findConvertor(currentValueType, String.class);
+ if(converter != null) {
+ currentValue = converter.convert(currentValue);
+ normalizedValue = booleanValue;
+ found = true;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+ }
+ if(!Operator.compare(currentValue, operator, normalizedValue) && update) {
+ restoreValues();
+ return;
+ }
+
+ for(SetterBase setter : getSetters()) {
+ try {
+ Object oldValue = setter.applyTo(element, update);
+ if(!update) {
+ if(oldvalues == null) {
+ oldvalues = new HashMap<SetterBase, Object>();
+ }
+ oldvalues.put(setter, oldValue);
+ }
+ } catch (RuntimeException e) {
+ continue;
+ }
+ }
+ }
+ }
+
+ public void prepare(Object target) {
+ if(value == null) {
+ return;
+ }
+ Widget widget = UserData.getWidget(target);
+ if(widget == null) {
+ return;
+ }
+ Object bindingTarget = null;
+ if(binding != null) {
+ if(binding instanceof IDynamicBinding) {
+ IDynamicBinding dynamicBinding = (IDynamicBinding)binding;
+ bindingTarget = dynamicBinding.createBoundSource();
+ } else {
+ bindingTarget = binding.getValue(null);
+ }
+ } else {
+ bindingTarget = XWT.getDataContext(widget);
+ }
+ if(!(bindingTarget instanceof IObservableValue)) {
+ return;
+ }
+ IObservableValue observableValue = (IObservableValue)bindingTarget;
+ changeListener = new ValueChangeListener(target);
+ observableValue.addChangeListener(changeListener);
+ changeListener.doHandleChange(false); // get default value
+ }
+
+ @Override
+ public void on(Object target) {
+ changeListener.doHandleChange(true);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/EventTrigger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/EventTrigger.java
new file mode 100644
index 00000000000..3831e23f17a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/EventTrigger.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.lang.reflect.Method;
+
+import org.eclipse.papyrus.xwt.IEventConstants;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.annotation.Containment;
+import org.eclipse.papyrus.xwt.internal.core.IEventController;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.Controller;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.ModelUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class EventTrigger extends TriggerBase {
+
+ private String sourceName;
+
+ private String routedEvent;
+
+ private TriggerAction[] actions = TriggerAction.EMPTY_ARRAY;
+
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ public void setSourceName(String sourceName) {
+ this.sourceName = sourceName;
+ }
+
+ public String getRoutedEvent() {
+ return routedEvent;
+ }
+
+ public void setRoutedEvent(String routedEvent) {
+ this.routedEvent = routedEvent;
+ }
+
+ @Containment
+ public TriggerAction[] getActions() {
+ return actions;
+ }
+
+ public void setActions(TriggerAction[] actions) {
+ this.actions = actions;
+ }
+
+ @Override
+ public void prepare(Object target) {
+ String routedEvent = getRoutedEvent();
+ if(routedEvent != null) {
+ Object source = getElementByName(target, getSourceName());
+ IMetaclass metaclass = XWT.getMetaclass(source);
+ IEvent event = metaclass.findEvent(ModelUtils.normalizeEventName(routedEvent));
+ if(event == null) {
+ if(routedEvent != null && !routedEvent.toLowerCase().endsWith(IEventConstants.SUFFIX_KEY)) {
+ LoggerManager.log("Event " + routedEvent + " is not found in " + source.getClass().getName() + ". Please add a suffix \"Event\"!");
+ } else {
+ LoggerManager.log("Event " + routedEvent + " is not found in " + source.getClass().getName());
+ }
+ return;
+ }
+
+ for(TriggerAction triggerAction : getActions()) {
+ triggerAction.initialize(target);
+ }
+
+ String name = event.getName();
+ if("loadedevent".equalsIgnoreCase(name)) {
+ Widget widget = UserData.getWidget(source);
+ IEventController eventController = UserData.updateEventController(source);
+ RunablePaintAction paintRunnable = createPaintRunnable(source);
+ try {
+ Method method = paintRunnable.getClass().getDeclaredMethod("run", Object.class, Event.class);
+ eventController.setEvent(event, widget, paintRunnable, this, method);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ } else {
+ RunableAction runnable = createRunnable(source);
+ try {
+ runnable.setEventTrigger(event);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ }
+ }
+ }
+
+ public void on(Object target) {
+ }
+
+ protected RunableAction createRunnable(Object target) {
+ return new RunableAction(target);
+ }
+
+ protected RunablePaintAction createPaintRunnable(Object target) {
+ return new RunablePaintAction(target);
+ }
+
+ class RunablePaintAction {
+
+ protected Object target;
+
+ public RunablePaintAction(Object target) {
+ this.target = target;
+ }
+
+ public void run(Object object, Event event) {
+ for(TriggerAction triggerAction : EventTrigger.this.getActions()) {
+ triggerAction.run(event, target, null);
+ }
+ }
+ }
+
+ class RunableAction implements Listener, Runnable {
+
+ protected Object target;
+
+ private int count = 0;
+
+ boolean started = false;
+
+ boolean transition = false;
+
+ private Event event;
+
+ private int eventType;
+
+ public RunableAction(Object target) {
+ this.target = target;
+ }
+
+ public void run() {
+ count--;
+ if(count == 0 && !event.widget.isDisposed()) {
+ final Display display = event.widget.getDisplay();
+ display.syncExec(new Runnable() {
+
+ public void run() {
+ if(transition) {
+ for(TriggerAction triggerAction : getActions()) {
+ triggerAction.initialize(target);
+ }
+ } else {
+ for(TriggerAction triggerAction : getActions()) {
+ triggerAction.endFinalize(target);
+ }
+ }
+ display.removeFilter(eventType, RunableAction.this);
+ if(!event.widget.isDisposed()) {
+ event.widget.notifyListeners(eventType, event);
+ display.addFilter(eventType, RunableAction.this);
+ }
+ started = false;
+ }
+ });
+ }
+ }
+
+ protected void setEventTrigger(IEvent event) {
+ Widget widget = UserData.getWidget(target);
+ String name = event.getName();
+ this.eventType = Controller.getEventTypeByName(name);
+ if(this.eventType != SWT.None) {
+ widget.getDisplay().addFilter(this.eventType, this);
+ transition = (this.eventType == XWTMaps.getEvent("swt.move") || this.eventType == XWTMaps.getEvent("swt.resize"));
+ }
+ }
+
+ public void handleEvent(Event event) {
+ Widget widget = UserData.getWidget(target);
+ if(event.widget != widget || widget.isDisposed()) {
+ return;
+ }
+ if(started) {
+ event.type = SWT.NONE;
+ return;
+ }
+
+ // execute the animation actions first and then normal events
+ count = EventTrigger.this.getActions().length;
+ started = true;
+ try {
+ this.event = Controller.copy(event);
+
+ if(!transition) {
+ for(TriggerAction triggerAction : getActions()) {
+ triggerAction.initialize(target);
+ }
+ }
+
+ for(TriggerAction triggerAction : EventTrigger.this.getActions()) {
+ triggerAction.run(event, target, this);
+ }
+ } catch (Exception e) {
+ started = false;
+ }
+ event.type = SWT.NONE;
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IBinding.java
new file mode 100644
index 00000000000..53ce68c4fc3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IBinding.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface IBinding {
+
+ /**
+ * The argument is used to determine the filtering. If type is null, no filtering
+ *
+ * @return
+ */
+ Object getValue(Class<?> type);
+
+ void reset();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/ICollectionView.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/ICollectionView.java
new file mode 100644
index 00000000000..2a0bc0a247c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/ICollectionView.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.Collection;
+import java.util.Locale;
+
+import org.eclipse.papyrus.xwt.collection.GroupDescription;
+import org.eclipse.papyrus.xwt.collection.SortDescription;
+
+/**
+ * The interface is implemented by the CollectionView class, which is the base class for Collection
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface ICollectionView<T> {
+
+ /**
+ * Gets a value that indicates whether this view supports filtering via the Filter property.
+ *
+ * @return
+ */
+ boolean canFilter();
+
+ /**
+ * Gets a value that indicates whether this view supports grouping via the GroupDescriptions property.
+ *
+ * @return
+ */
+ boolean canGroup();
+
+
+ /**
+ * Gets a value that indicates whether this view supports sorting via the SortDescriptions property.
+ *
+ * @return
+ */
+ boolean canSort();
+
+ /**
+ * Gets the current item in the view.
+ *
+ * @return
+ */
+ T getCurrentItem();
+
+ /**
+ * Gets the ordinal position of the CurrentItem within the view.
+ *
+ * @return
+ */
+ int getCurrentPosition();
+
+
+ /**
+ * Returns a value that indicates whether the resulting view is empty.
+ *
+ * @return
+ */
+ boolean isEmpty();
+
+ /**
+ * Source collection
+ *
+ * @return
+ */
+ Collection<T> getSourceCollection();
+
+ /**
+ * Gets a collection of GroupDescription objects that describe how the items in the collection are grouped in the view.
+ *
+ * @return
+ */
+ GroupDescription[] getGroupDescription();
+
+ /**
+ * Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view.
+ *
+ * @return
+ */
+ SortDescription[] getSortDescription();
+
+ /**
+ * Gets the top-level groups.
+ *
+ * @return
+ */
+ Collection<T> getGroups();
+
+ /**
+ * Gets or sets the cultural info for any operations of the view that may differ by culture, such as sorting.
+ *
+ * @return
+ */
+ Locale getLocale();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicBinding.java
new file mode 100644
index 00000000000..120cccd6ac5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicBinding.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.papyrus.xwt.databinding.BindingContext;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface IDynamicBinding extends IBinding {
+
+ Object createBoundSource();
+
+ void setControl(Object control);
+
+ Object getControl();
+
+ void setHost(Object control);
+
+ Object getHost();
+
+
+ void setType(String type);
+
+ String getType();
+
+ boolean isSourceControl();
+
+ /**
+ * Returns the {@link BindingContext} associated with this binding
+ *
+ * @return the {@link BindingContext}
+ */
+ IBindingContext getBindingContext();
+
+ /**
+ * Sets the {@link BindingContext} this binding is associated with
+ *
+ * @param dataBindingContext
+ */
+ void setBindingContext(IBindingContext dataBindingContext);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicValueBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicValueBinding.java
new file mode 100644
index 00000000000..eb1b4810da6
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IDynamicValueBinding.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+public interface IDynamicValueBinding extends IDynamicBinding {
+
+ public IProperty getProperty();
+
+ public void setProperty(IProperty property);
+
+ public Object getObject();
+
+ public void setObject(Object object);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IElementLoaderFactory.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IElementLoaderFactory.java
new file mode 100644
index 00000000000..c5af27554e7
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IElementLoaderFactory.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.papyrus.xwt.IXWTLoader;
+
+public interface IElementLoaderFactory {
+
+ IVisualElementLoader createElementLoader(IRenderingContext context, IXWTLoader loader);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IRenderingContext.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IRenderingContext.java
new file mode 100644
index 00000000000..3add2a35aae
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IRenderingContext.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.papyrus.xwt.ILoadingContext;
+
+/**
+ * @author yyang
+ * @version 1.0
+ */
+public interface IRenderingContext {
+
+ public String getNamespace();
+
+ public URL getResourcePath();
+
+ public InputStream openStream(String path) throws IOException;
+
+ public String getEncoding();
+
+ public Object getProperty(String name);
+
+ public void setProperty(String name, Object value);
+
+ public ILoadingContext getLoadingContext();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IUserDataConstants.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IUserDataConstants.java
new file mode 100644
index 00000000000..b81750a5a08
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IUserDataConstants.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+public interface IUserDataConstants {
+
+ public static String XWT_CONTROLLER_KEY = "Controller";
+
+ public static String XWT_RESOURCES_KEY = "Resources";
+
+ public static String XWT_STYLE_KEY = "Style";
+
+ public static String XWT_DRAWING_KEY = "Drawing";
+
+ public static String XWT_DATACONTEXT_KEY = "DataContext";
+
+ public static String XWT_BINDING_CONTEXT_KEY = "DefaultDataBindingContext";
+
+ public static String XWT_RENDER_TRANSFORM_KEY = "RenderTransform";
+
+ public static String XWT_RENDER_TRANSFORM_ORIGIN_KEY = "RenderTransformOrigin";
+
+ public static String XWT_TRIGGERS_KEY = "Triggers";
+
+ public static String XWT_NAME_KEY = "Name";
+
+ public static String XWT_PARENT_KEY = "Parent";
+
+ public static String XWT_VIEWER_KEY = "Viewer";
+
+ public static String XWT_NAMECONTEXT_KEY = "NameContext";
+
+ public static String XWT_COMMAND_KEY = "Command";
+
+ public static String XWT_CLR_KEY = "clr";
+
+ public static String XWT_USER_DATA_KEY = "__XWT.UserData";
+
+ public static String XWT_PROPERTY_DATA_KEY = "_XWT.TableViewerColumnDisplayPath";
+
+ public static String XWT_PROPERTY_ITEM_TEXT_KEY = "_XWT.TableViewerColumnItemText";
+
+ public static String XWT_PROPERTY_ITEM_IMAGE_KEY = "_XWT.TableViewerColumnItemImage";
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IVisualElementLoader.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IVisualElementLoader.java
new file mode 100644
index 00000000000..d17955334ff
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/IVisualElementLoader.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+
+public interface IVisualElementLoader {
+
+ public Object createUIElement(Element element, Map<String, Object> options);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiDataTrigger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiDataTrigger.java
new file mode 100644
index 00000000000..4c62f68ea82
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiDataTrigger.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Widget;
+
+public class MultiDataTrigger extends TriggerBase {
+
+ private Condition[] conditions = Condition.EMPTY_ARRAY;
+
+ private Setter[] setters;
+
+ private ValueChangeListener changeListener;
+
+ public Condition[] getConditions() {
+ return conditions;
+ }
+
+ public void setConditions(Condition[] conditions) {
+ this.conditions = conditions;
+ }
+
+ public Setter[] getSetters() {
+ return setters;
+ }
+
+ public void setSetters(Setter[] setters) {
+ this.setters = setters;
+ }
+
+ class ValueChangeListener extends AbstractChangeListener {
+
+ public ValueChangeListener(Object element) {
+ super(element);
+ }
+
+ public void handleChange(ChangeEvent event) {
+ doHandleChange(true);
+ }
+
+ public void doHandleChange(boolean update) {
+ for(Condition condition : getConditions()) {
+ if(!condition.evaluate(element)) {
+ restoreValues();
+ return;
+ }
+ }
+
+ for(SetterBase setter : getSetters()) {
+ try {
+ Object oldValue = setter.applyTo(element, update);
+ if(oldvalues == null) {
+ oldvalues = new HashMap<SetterBase, Object>();
+ }
+ oldvalues.put(setter, oldValue);
+ } catch (RuntimeException e) {
+ continue;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void prepare(Object target) {
+ if(getConditions().length == 0) {
+ return;
+ }
+ Widget widget = UserData.getWidget(target);
+ if(widget == null) {
+ return;
+ }
+
+ changeListener = new ValueChangeListener(target);
+ for(Condition condition : getConditions()) {
+ String sourceName = condition.getSourceName();
+
+ IBinding binding = condition.getBinding();
+ Object bindingTarget = null;
+ if(binding != null) {
+ if(binding instanceof IDynamicBinding) {
+ IDynamicBinding dynamicBinding = (IDynamicBinding)binding;
+ bindingTarget = dynamicBinding.createBoundSource();
+ } else {
+ bindingTarget = binding.getValue(null);
+ }
+ } else {
+ Object sourceObject = getElementByName(target, sourceName);
+ Widget sourceWidget = UserData.getWidget(sourceObject);
+ bindingTarget = XWT.getDataContext(sourceWidget);
+ }
+
+ if(!(bindingTarget instanceof IObservableValue)) {
+ return;
+ }
+ IObservableValue observableValue = (IObservableValue)bindingTarget;
+ observableValue.addChangeListener(changeListener);
+ }
+ changeListener.doHandleChange(false);
+ }
+
+ public void on(Object target) {
+ changeListener.doHandleChange(true);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiTrigger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiTrigger.java
new file mode 100644
index 00000000000..334f47e31c4
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/MultiTrigger.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+
+public class MultiTrigger extends TriggerBase {
+
+ private Condition[] conditions = Condition.EMPTY_ARRAY;
+
+ private SetterBase[] setters;
+
+ public Condition[] getConditions() {
+ return conditions;
+ }
+
+ public void setConditions(Condition[] conditions) {
+ this.conditions = conditions;
+ }
+
+ public SetterBase[] getSetters() {
+ return setters;
+ }
+
+ public void setSetters(SetterBase[] setters) {
+ this.setters = setters;
+ }
+
+ class ValueChangeListener extends AbstractChangeListener {
+
+ public ValueChangeListener(Object element) {
+ super(element);
+ }
+
+ public void handleChange(ChangeEvent event) {
+ for(Condition condition : getConditions()) {
+ if(!condition.evaluate(element)) {
+ restoreValues();
+ return;
+ }
+ }
+
+ if(oldvalues != null && !oldvalues.isEmpty()) {
+ return;
+ }
+
+ for(SetterBase setter : getSetters()) {
+ try {
+ Object oldValue = setter.applyTo(element, true);
+ if(oldvalues == null) {
+ oldvalues = new HashMap<SetterBase, Object>();
+ }
+ oldvalues.put(setter, oldValue);
+ } catch (RuntimeException e) {
+ continue;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void on(Object target) {
+ }
+
+ @Override
+ public void prepare(Object target) {
+ if(getConditions().length == 0) {
+ return;
+ }
+ ValueChangeListener changeListener = new ValueChangeListener(target);
+ for(Condition condition : getConditions()) {
+ String propertyName = condition.getProperty();
+ String sourceName = condition.getSourceName();
+
+ Object source = getElementByName(target, sourceName);
+ if(source == null) {
+ throw new XWTException("No element is found with the name = " + sourceName);
+ }
+ IObservable observableValue = ScopeManager.observeValue(source, source, propertyName, UpdateSourceTrigger.PropertyChanged);
+ observableValue.addChangeListener(changeListener);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Operator.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Operator.java
new file mode 100644
index 00000000000..baea4d09a00
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Operator.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.math.BigDecimal;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.utils.OperatorExceptionMessage;
+
+public enum Operator {
+ EQ, NE, GT, LT, GE, LE, LIKE, IS_A, IS_KIND_OF;
+
+ /**
+ * The utility helper method, to implement the compare between two objects
+ *
+ * @param operant1
+ * @param operator
+ * @param operant2
+ * @return
+ * @throws XWTException
+ */
+ public static boolean compare(Object operant1, Operator operator, Object operant2) throws XWTException {
+ boolean result = false;
+
+ switch(operator) {
+ case EQ:
+ result = objectCompare(operant1, operant2);
+ break;
+
+ case NE:
+ if(!objectCompare(operant1, operant2))
+ result = true;
+ break;
+
+ case GT:
+ if(numberCompare(operant1, operant2) == 1)
+ return true;
+ break;
+
+ case LT:
+ if(numberCompare(operant1, operant2) == -1) {
+ result = true;
+ }
+ break;
+
+ case GE:
+ if(numberCompare(operant1, operant2) == 1 || numberCompare(operant1, operant2) == 0) {
+ result = true;
+ }
+ break;
+
+ case LE:
+ if(numberCompare(operant1, operant2) == -1 || numberCompare(operant1, operant2) == 0) {
+ result = true;
+ }
+ break;
+
+ case LIKE:
+ return LikeCompare(operant1, operant2);
+
+ case IS_A:
+ if(operant2 instanceof Class<?>) {
+ return ISACompare(operant1, (Class<?>)operant2);
+ } else {
+ throw new XWTException(OperatorExceptionMessage.TYPE_WRONG);
+ }
+
+ case IS_KIND_OF:
+ return isKindOfCompare(operant1, operant2);
+ }
+ return result;
+ }
+
+ private static boolean isKindOfCompare(Object operant1, Object operant2) {
+ return operant2.getClass().isInstance(operant1);
+ }
+
+ /**
+ * @param operant1
+ * @param operant2
+ * @return
+ * @throws XWTException
+ */
+ private static int numberCompare(Object operant1, Object operant2) throws XWTException {
+ if(operant1 == null || operant2 == null) {
+ throw new XWTException(OperatorExceptionMessage.OPRERANR_NULL);
+ }
+ Double longoperant1 = convertToDouble(operant1);
+ Double longoperant2 = convertToDouble(operant2);
+ return DoubleCompare(longoperant1, longoperant2);
+ }
+
+ /**
+ * convert the type of operant to the Double
+ *
+ * @param operant
+ * @return
+ * @throws XWTException
+ */
+ private static Double convertToDouble(Object operant) throws XWTException {
+ if(operant instanceof Double) {
+ return (Double)operant;
+ }
+ if(operant instanceof Float) {
+ Float floatvalue = (Float)operant;
+ return Double.parseDouble(String.valueOf(floatvalue));
+ }
+ if(operant instanceof Integer) {
+ Integer integer = (Integer)operant;
+ return Double.parseDouble(String.valueOf(integer));
+ }
+ if(operant instanceof Character) {
+ Character character = (Character)operant;
+ if(Character.isDigit(character)) {
+ int numericValue = Character.getNumericValue(character);
+ return Double.parseDouble(String.valueOf(numericValue));
+ }
+ }
+ if(operant instanceof Short) {
+ Short shortvalue = (Short)operant;
+ return Double.parseDouble(String.valueOf(shortvalue));
+ }
+ if(operant instanceof Byte) {
+ Byte bytevalue = (Byte)operant;
+ return Double.parseDouble(String.valueOf(bytevalue));
+ }
+ if(operant instanceof Long) {
+ Long floatvalue = (Long)operant;
+ return Double.parseDouble(String.valueOf(floatvalue));
+ }
+ if(operant instanceof BigDecimal) {
+ BigDecimal bigdecimalvalue = (BigDecimal)operant;
+ return Double.parseDouble(String.valueOf(bigdecimalvalue));
+ } else
+ throw new XWTException(OperatorExceptionMessage.TYPE_WRONG);
+ }
+
+ /**
+ * the compare of two object for NE,EQ
+ *
+ * @param operant1
+ * @param operant2
+ * @return
+ */
+ private static boolean objectCompare(Object operant1, Object operant2) {
+ if(operant1 == operant2) {
+ return true;
+ }
+ if(operant1 != null) {
+ return operant1.equals(operant2);
+ } else if(operant1 != null) {
+ return operant2.equals(operant1);
+ }
+ return false;
+ }
+
+ /**
+ * the compare of two object for ISA
+ *
+ * @param operant1
+ * @param operant2
+ * @return
+ * @throws XWTException
+ */
+ private static boolean ISACompare(Object operant1, Class<?> clazz) {
+ return clazz.isInstance(operant1);
+ }
+
+ /**
+ * the compare of two Double
+ *
+ * @param operant1
+ * @param operant2
+ * @return
+ */
+ private static int DoubleCompare(Double operant1, Double operant2) {
+ return (operant1.compareTo(operant2) < 0 ? -1 : (operant1.compareTo(operant2) == 0 ? 0 : 1));
+ }
+
+ /**
+ * the compare of two String for Like
+ *
+ * @param operant1
+ * @param operant2
+ * @return
+ * @throws XWTException
+ */
+ private static boolean LikeCompare(Object operant1, Object operant2) throws XWTException {
+ if(operant1 == null || operant2 == null) {
+ throw new XWTException(OperatorExceptionMessage.OPRERANR_NULL);
+ }
+ if(operant1 instanceof String && operant2 instanceof String) {
+ String operant1String = (String)operant1;
+ String operant2String = (String)operant2;
+ String queryString = parseRegularExpressionString(operant1String);
+ Pattern pattern = Pattern.compile(queryString);
+ Matcher matcher = pattern.matcher(operant2String);
+ return matcher.find();
+ }
+ throw new XWTException(OperatorExceptionMessage.TYPE_WRONG);
+ }
+
+ /**
+ * build the regular expressions
+ *
+ * @param queryString
+ * @return
+ */
+ public static String parseRegularExpressionString(String queryString) {
+ String result = queryString;
+ result = result.replace("?", ".");
+ result = result.replace("*", ".*");
+ return result;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/RadioEventGroup.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/RadioEventGroup.java
new file mode 100644
index 00000000000..b461bc282ce
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/RadioEventGroup.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.IEventConstants;
+import org.eclipse.papyrus.xwt.IObservableValueListener;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.core.IEventController;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.EventProperty;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+public class RadioEventGroup extends AbstractEventGroup {
+
+ public RadioEventGroup(String... names) {
+ super(names);
+ }
+
+ public void fireEvent(IObservableValueListener manager, IProperty property) {
+ Object host = manager.getHost();
+ IMetaclass metaclass = XWT.getMetaclass(host);
+
+ EventProperty reaisedEventProperty = (EventProperty)property;
+ String raisedName = reaisedEventProperty.getEvent().getName();
+ for(String name : getEventNames()) {
+ if(name.equalsIgnoreCase(raisedName)) {
+ continue;
+ }
+ String eventPropertyName = IEventConstants.getEventPropertyName(name);
+ IProperty eventProperty = metaclass.findProperty(eventPropertyName);
+
+ IObservableValue value = manager.getValue(eventProperty);
+ if(value != null) {
+ value.setValue(false);
+ }
+ }
+ }
+
+ public void registerEvent(IObservableValueListener manager, IProperty property) {
+ Object host = manager.getHost();
+ IEventController controller = UserData.findEventController(host);
+ if(controller == null) {
+ controller = UserData.updateEventController(host);
+ }
+ IMetaclass metaclass = XWT.getMetaclass(host);
+
+ EventProperty reaisedEventProperty = (EventProperty)property;
+ String raisedName = reaisedEventProperty.getEvent().getName();
+ for(String name : getEventNames()) {
+ if(name.equalsIgnoreCase(raisedName)) {
+ continue;
+ }
+ String eventPropertyName = IEventConstants.getEventPropertyName(name);
+ String eventName = IEventConstants.getEventName(name);
+ IEvent event = metaclass.findEvent(eventName);
+ IProperty eventProperty = metaclass.findProperty(eventPropertyName);
+
+ try {
+ controller.setEvent(event, UserData.getWidget(host), manager, eventProperty, IObservableValueListener.class.getDeclaredMethod("changeValueHandle", Object.class, org.eclipse.swt.widgets.Event.class));
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ return;
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Setter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Setter.java
new file mode 100644
index 00000000000..4228f20e6d2
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Setter.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+
+/**
+ * Setter of the class Style, which is used to define the in-line XAML style
+ *
+ * @see Style
+ * @author yyang
+ */
+public class Setter extends SetterBase {
+
+ protected String property;
+
+ protected Object value;
+
+ protected String targetName;
+
+ public String getTargetName() {
+ return targetName;
+ }
+
+ public void setTargetName(String targetName) {
+ this.targetName = targetName;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public Object applyTo(Object element, boolean update) {
+ String propName = getProperty();
+ Object propValue = getValue();
+ String targetName = getTargetName();
+ Object setterTarget = element;
+ Object oldValue = null;
+ if(targetName != null) {
+ setterTarget = TriggerBase.getElementByName(element, targetName);
+ }
+ IMetaclass metaclass = XWT.getMetaclass(setterTarget);
+ IProperty prop = metaclass.findProperty(propName);
+ if(prop != null && propValue != null) {
+ Object toValue = propValue;
+ Class<?> valueType = propValue.getClass();
+ Class<?> targetType = prop.getType();
+ if(targetType != null && !targetType.isAssignableFrom(valueType)) {
+ IConverter converter = XWT.findConvertor(valueType, targetType);
+ if(converter != null) {
+ toValue = converter.convert(propValue);
+ } else {
+ throw new XWTException("Converter doesn't exist from \"" + valueType.getName() + "\" to \"" + targetType.getName());
+ }
+ }
+ try {
+ oldValue = prop.getValue(setterTarget);
+ if(update) {
+ prop.setValue(setterTarget, toValue);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return oldValue;
+ }
+
+ public void undo(Object element, Object value) {
+ String propName = getProperty();
+ String targetName = getTargetName();
+ Object setterTarget = element;
+ if(targetName != null) {
+ setterTarget = TriggerBase.getElementByName(element, targetName);
+ }
+ IMetaclass metaclass = XWT.getMetaclass(setterTarget);
+ IProperty prop = metaclass.findProperty(propName);
+ if(prop != null) {
+ try {
+ prop.setValue(setterTarget, value);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/SetterBase.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/SetterBase.java
new file mode 100644
index 00000000000..b530b2c4107
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/SetterBase.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+public abstract class SetterBase {
+
+ public static final SetterBase[] EMPTY_SETTERS = new SetterBase[0];
+
+ public abstract Object applyTo(Object element, boolean update);
+
+ public abstract void undo(Object element, Object value);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Style.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Style.java
new file mode 100644
index 00000000000..9711c0cc5f3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Style.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+/**
+ * The class defines the in-line XAML style
+ *
+ * @author yyang
+ */
+public class Style {
+
+ protected Class<?> targetType;
+
+ protected SetterBase[] setters;
+
+ protected TriggerBase[] triggers;
+
+ public TriggerBase[] getTriggers() {
+ if(triggers == null) {
+ return TriggerBase.EMPTY_ARRAY;
+ }
+ return triggers;
+ }
+
+ public void setTriggers(TriggerBase[] triggers) {
+ this.triggers = triggers;
+ }
+
+ public Class<?> getTargetType() {
+ return targetType;
+ }
+
+ public void setTargetType(Class<?> targetType) {
+ this.targetType = targetType;
+ }
+
+ public SetterBase[] getSetters() {
+ if(setters == null) {
+ return SetterBase.EMPTY_SETTERS;
+ }
+ return setters;
+ }
+
+ public void setSetters(SetterBase[] setters) {
+ this.setters = setters;
+ }
+
+ public void apply(Object target) {
+ for(SetterBase setter : getSetters()) {
+ setter.applyTo(target, true);
+ }
+
+ for(TriggerBase triggerBase : getTriggers()) {
+ triggerBase.prepare(target);
+ }
+
+ for(TriggerBase triggerBase : getTriggers()) {
+ triggerBase.on(target);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Trigger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Trigger.java
new file mode 100644
index 00000000000..42b2b8c4ee5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/Trigger.java
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.databinding.JFaceXWTDataBinding;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Widget;
+
+public class Trigger extends TriggerBase {
+
+ private String property;
+
+ private String sourceName;
+
+ private Operator operator = Operator.EQ;
+
+ private Object value;
+
+ private SetterBase[] setters;
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public String getProperty() {
+ return property;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ public void setSourceName(String sourceName) {
+ this.sourceName = sourceName;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public SetterBase[] getSetters() {
+ if(setters == null) {
+ return SetterBase.EMPTY_SETTERS;
+ }
+ return setters;
+ }
+
+ public void setSetters(SetterBase[] setters) {
+ this.setters = setters;
+ }
+
+ public void on(Object target) {
+ }
+
+ public void prepare(Object target) {
+ if(property != null) {
+ final Object source = getElementByName(target, sourceName);
+ if(source == null) {
+ throw new XWTException("No element is found with the name = " + sourceName);
+ }
+ IObservable observableValue = ScopeManager.observeValue(source, source, property, UpdateSourceTrigger.PropertyChanged);
+ observableValue.addChangeListener(new AbstractChangeListener(target) {
+
+ public void handleChange(ChangeEvent event) {
+ Class<?> valueType = JFaceXWTDataBinding.getValueType(source.getClass(), property);
+ if(valueType == null) {
+ LoggerManager.log("Type of the property " + property + " is not found in " + source.getClass().getName());
+ return;
+ }
+ Widget widget = UserData.getWidget(source);
+ if(widget == null) {
+ return;
+ }
+
+ //
+ // test value ==
+ //
+ Object realValue = value;
+ if(value != null) {
+ IConverter converter = XWT.findConvertor(value.getClass(), valueType);
+ if(converter != null) {
+ realValue = converter.convert(value);
+ }
+ }
+ Object newValue = event.getSource();
+ if(newValue instanceof IObservableValue) {
+ IObservableValue observableValue = (IObservableValue)newValue;
+ newValue = observableValue.getValue();
+ }
+ if(newValue != null) {
+ IConverter newConverter = XWT.findConvertor(newValue.getClass(), valueType);
+ if(newConverter != null) {
+ newValue = newConverter.convert(newValue);
+ }
+ }
+
+ if(!Operator.compare(newValue, operator, realValue)) {
+ restoreValues();
+ if(oldvalues != null) {
+ oldvalues.clear();
+ }
+ return;
+ }
+
+ if(oldvalues != null && !oldvalues.isEmpty()) {
+ return;
+ }
+
+ for(SetterBase setter : getSetters()) {
+ try {
+ Object oldValue = setter.applyTo(element, true);
+ if(oldvalues == null) {
+ oldvalues = new HashMap<SetterBase, Object>();
+ }
+ oldvalues.put(setter, oldValue);
+ } catch (RuntimeException e) {
+ continue;
+ }
+ }
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerAction.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerAction.java
new file mode 100644
index 00000000000..7bc6314af69
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerAction.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import org.eclipse.swt.widgets.Event;
+
+public abstract class TriggerAction {
+
+ public static final TriggerAction[] EMPTY_ARRAY = new TriggerAction[0];
+
+ public abstract void run(Event event, Object target, Runnable stateChangedRunnable);
+
+ public abstract void initialize(Object target);
+
+ public abstract void endFinalize(Object target);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerBase.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerBase.java
new file mode 100644
index 00000000000..70d514518f0
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/core/TriggerBase.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.core;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Widget;
+
+public abstract class TriggerBase {
+
+ public final static TriggerBase[] EMPTY_ARRAY = new TriggerBase[0];
+
+ protected TriggerAction[] entryActions;
+
+ protected TriggerAction[] exitActions;
+
+ public TriggerAction[] getEntryActions() {
+ if(entryActions == null) {
+ return TriggerAction.EMPTY_ARRAY;
+ }
+ return entryActions;
+ }
+
+ public void setEntryActions(TriggerAction[] entryActions) {
+ this.entryActions = entryActions;
+ }
+
+ public TriggerAction[] getExitActions() {
+ if(exitActions == null) {
+ return TriggerAction.EMPTY_ARRAY;
+ }
+ return exitActions;
+ }
+
+ public void setExitActions(TriggerAction[] exitActions) {
+ this.exitActions = exitActions;
+ }
+
+ public abstract void on(Object target);
+
+ public abstract void prepare(Object target);
+
+ abstract class AbstractChangeListener implements IChangeListener {
+
+ protected HashMap<SetterBase, Object> oldvalues = null;
+
+ protected Object element;
+
+ public AbstractChangeListener(Object element) {
+ this.element = element;
+ }
+
+ protected void restoreValues() {
+ if(oldvalues == null) {
+ return;
+ }
+ for(SetterBase setter : oldvalues.keySet()) {
+ setter.undo(element, oldvalues.get(setter));
+ }
+ }
+ }
+
+ public static Object getElementByName(Object target, String elementName) {
+ if(elementName != null && elementName.length() > 0) {
+ Widget widget = UserData.getWidget(target);
+ if(widget != null) {
+ Object element = XWT.findElementByName(widget, elementName);
+ if(element != null) {
+ return element;
+ }
+ LoggerManager.log("EventTrigger: Source \n" + elementName + "\n is not found in " + target.getClass().getName());
+ }
+ }
+ return target;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AbstractDataBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AbstractDataBinding.java
new file mode 100644
index 00000000000..6db1c45ca0a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AbstractDataBinding.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.papyrus.xwt.IDataBinding;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IValidationRule;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.internal.core.Binding;
+import org.eclipse.papyrus.xwt.internal.core.BindingExpressionPath;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public abstract class AbstractDataBinding implements IDataBinding {
+
+ private IDataProvider dataProvider;
+
+ private Binding binding;
+
+ private BindingExpressionPath targetPropertySegments;
+
+ public BindingExpressionPath getSourcePropertyExpression() {
+ return binding.getPathPropertySegments();
+ }
+
+ public BindingExpressionPath getTargetPropertyExpression() {
+ return targetPropertySegments;
+ }
+
+ public AbstractDataBinding(Binding binding, IDataProvider dataProvider) {
+ this.binding = binding;
+ this.dataProvider = dataProvider;
+
+ targetPropertySegments = new BindingExpressionPath(getTargetProperty());
+ }
+
+ /**
+ * @return the dataProvider
+ */
+ public IDataProvider getDataProvider() {
+ return dataProvider;
+ }
+
+ /**
+ * @param dataProvider
+ * the dataProvider to set
+ */
+ public void setDataProvider(IDataProvider dataProvider) {
+ this.dataProvider = dataProvider;
+ }
+
+ /**
+ *
+ */
+ public BindingMode getBindingMode() {
+ return binding.getMode();
+ }
+
+ /**
+ * Returns the name of the data binding context this binding is associated
+ * with
+ *
+ * @return
+ */
+ protected IBindingContext getDataBindingContext() {
+ return binding.getBindingContext();
+ }
+
+ /**
+ *
+ */
+ public IValueConverter getConverter() {
+ return binding.getConverter();
+ }
+
+ /**
+ * @return the target
+ */
+ public Object getControl() {
+ return binding.getControl();
+ }
+
+ /**
+ * @return the target
+ */
+ public Object getHost() {
+ return binding.getHost();
+ }
+
+ /**
+ *
+ * @return
+ */
+ public BindingMode getMode() {
+ return binding.getMode();
+ }
+
+ /**
+ *
+ * @param mode
+ */
+ public void setMode(BindingMode mode) {
+ binding.setMode(mode);
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected String getSourceProperty() {
+ return binding.getPath();
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected String getTargetProperty() {
+ return binding.getType();
+ }
+
+ public IValidationRule[] getValidators() {
+ return binding.getValidationRules();
+ }
+
+ public UpdateSourceTrigger getUpdateSourceTrigger() {
+ return binding.getUpdateSourceTrigger();
+ }
+
+ protected IObservable getObservableSource() {
+ return binding.getObservableSource();
+ }
+
+ protected void setObservableSource(IObservable observableSource) {
+ binding.setObservableSource(observableSource);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AggregateObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AggregateObservableValue.java
new file mode 100644
index 00000000000..c4495b633f3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/AggregateObservableValue.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Brad Reynolds - bug 164653
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.IValueChangeListener;
+import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
+import org.eclipse.papyrus.xwt.IMultiValueConverter;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * @since 3.2
+ *
+ */
+public class AggregateObservableValue extends AbstractObservableValue {
+
+ private IObservableValue[] observableValues;
+
+ private boolean updating = false;
+
+ private IMultiValueConverter converter;
+
+ private Object currentValue;
+
+ private IValueChangeListener listener = new IValueChangeListener() {
+
+ public void handleValueChange(ValueChangeEvent event) {
+ if(!updating) {
+ fireValueChange(Diffs.createValueDiff(currentValue, doGetValue()));
+ }
+ }
+ };
+
+ /**
+ * @param observableValues
+ * @param delimiter
+ */
+ public AggregateObservableValue(IObservableValue[] observableValues, IMultiValueConverter converter) {
+ super(findRealm(observableValues));
+ this.converter = converter;
+
+ this.observableValues = observableValues;
+ for(int i = 0; i < observableValues.length; i++) {
+ observableValues[i].addValueChangeListener(listener);
+ }
+ doGetValue();
+ }
+
+ private static Realm findRealm(IObservableValue[] observableValues) {
+ for(IObservableValue observableValue : observableValues) {
+ return observableValue.getRealm();
+ }
+ return XWT.getRealm();
+ }
+
+ public void doSetValue(Object value) {
+ Object oldValue = doGetValue();
+
+ try {
+ updating = true;
+ Object[] values = converter.convertBack(value);
+ for(int i = 0; i < observableValues.length; i++) {
+ if(i < values.length) {
+ observableValues[i].setValue(values[i]);
+ } else {
+ observableValues[i].setValue(null);
+ }
+ }
+ } finally {
+ updating = false;
+ }
+ doGetValue();
+ currentValue = value;
+ fireValueChange(Diffs.createValueDiff(oldValue, value));
+ }
+
+ public Object doGetValue() {
+ Object[] values = new Object[observableValues.length];
+ for(int i = 0; i < values.length; i++) {
+ values[i] = observableValues[i].getValue();
+ }
+ return converter.convert(values);
+ }
+
+ public Object getValueType() {
+ return String[].class;
+ }
+
+ public synchronized void dispose() {
+ for(int i = 0; i < observableValues.length; i++) {
+ observableValues[i].removeValueChangeListener(listener);
+ }
+ super.dispose();
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingContext.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingContext.java
new file mode 100644
index 00000000000..9ee6e165908
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingContext.java
@@ -0,0 +1,317 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec & hceylan - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.AggregateValidationStatus;
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.UpdateListStrategy;
+import org.eclipse.core.databinding.UpdateSetStrategy;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.ValidationStatusProvider;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.map.IObservableMap;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * @author hceylan
+ */
+public class BindingContext implements IBindingContext {
+
+ private org.eclipse.core.databinding.DataBindingContext context;
+
+ private Realm realm;
+
+ private AggregateValidationStatus status;
+
+ private int statusType = MAX_SEVERITY;
+
+ private final Widget parent;
+
+ public BindingContext(Widget parent) {
+ super();
+ this.parent = parent;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getContext()
+ */
+ public org.eclipse.core.databinding.DataBindingContext getContext() {
+ if(this.context == null) {
+ if(this.realm != null) {
+ this.context = new org.eclipse.core.databinding.DataBindingContext(this.realm);
+ } else {
+ this.context = new org.eclipse.core.databinding.DataBindingContext(XWT.getRealm());
+ }
+
+ if(this.parent != null) {
+ this.parent.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ context.dispose();
+ }
+ });
+ }
+ }
+ return this.context;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getRealm()
+ */
+ public Realm getRealm() {
+ return this.realm;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getStatus()
+ */
+ public AggregateValidationStatus getStatus() {
+ if(this.status == null) {
+ this.status = new AggregateValidationStatus(getContext(), this.statusType);
+ if(this.parent != null) {
+ this.parent.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ status.dispose();
+ }
+ });
+ }
+ }
+ return this.status;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getStatusType()
+ */
+ public int getStatusType() {
+ return statusType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindValue(org.eclipse.core.databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ public final Binding bindValue(IObservableValue targetObservableValue, IObservableValue modelObservableValue) {
+ return getContext().bindValue(targetObservableValue, modelObservableValue);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if(!(obj instanceof BindingContext)) {
+ return false;
+ }
+ org.eclipse.core.databinding.DataBindingContext context = getContext();
+ if(context != null) {
+ return context.equals(((BindingContext)obj).getContext());
+ }
+ if(((BindingContext)obj).getContext() != null) {
+ return false;
+ }
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return getContext().hashCode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindValue(org.eclipse.core.databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue, org.eclipse.core.databinding.UpdateValueStrategy,
+ * org.eclipse.core.databinding.UpdateValueStrategy)
+ */
+ public final Binding bindValue(IObservableValue targetObservableValue, IObservableValue modelObservableValue, UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) {
+ return getContext().bindValue(targetObservableValue, modelObservableValue, targetToModel, modelToTarget);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindList(org.eclipse.core.databinding.observable.list.IObservableList,
+ * org.eclipse.core.databinding.observable.list.IObservableList)
+ */
+ public final Binding bindList(IObservableList targetObservableList, IObservableList modelObservableList) {
+ return getContext().bindList(targetObservableList, modelObservableList);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindList(org.eclipse.core.databinding.observable.list.IObservableList,
+ * org.eclipse.core.databinding.observable.list.IObservableList, org.eclipse.core.databinding.UpdateListStrategy,
+ * org.eclipse.core.databinding.UpdateListStrategy)
+ */
+ public final Binding bindList(IObservableList targetObservableList, IObservableList modelObservableList, UpdateListStrategy targetToModel, UpdateListStrategy modelToTarget) {
+ return getContext().bindList(targetObservableList, modelObservableList, targetToModel, modelToTarget);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindSet(org.eclipse.core.databinding.observable.set.IObservableSet,
+ * org.eclipse.core.databinding.observable.set.IObservableSet)
+ */
+ public final Binding bindSet(IObservableSet targetObservableSet, IObservableSet modelObservableSet) {
+ return getContext().bindSet(targetObservableSet, modelObservableSet);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#bindSet(org.eclipse.core.databinding.observable.set.IObservableSet,
+ * org.eclipse.core.databinding.observable.set.IObservableSet, org.eclipse.core.databinding.UpdateSetStrategy,
+ * org.eclipse.core.databinding.UpdateSetStrategy)
+ */
+ public final Binding bindSet(IObservableSet targetObservableSet, IObservableSet modelObservableSet, UpdateSetStrategy targetToModel, UpdateSetStrategy modelToTarget) {
+ return getContext().bindSet(targetObservableSet, modelObservableSet, targetToModel, modelToTarget);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#dispose()
+ */
+ public final void dispose() {
+ getContext().dispose();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getBindings()
+ */
+ public final IObservableList getBindings() {
+ return getContext().getBindings();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getValidationStatusProviders()
+ */
+ public final IObservableList getValidationStatusProviders() {
+ return getContext().getValidationStatusProviders();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getValidationStatusMap()
+ */
+ public final IObservableMap getValidationStatusMap() {
+ return getContext().getValidationStatusMap();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#addBinding(org.eclipse.core.databinding.Binding)
+ */
+ public void addBinding(Binding binding) {
+ getContext().addBinding(binding);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#addValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)
+ */
+ public void addValidationStatusProvider(ValidationStatusProvider validationStatusProvider) {
+ getContext().addValidationStatusProvider(validationStatusProvider);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#updateModels()
+ */
+ public final void updateModels() {
+ getContext().updateModels();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#updateTargets()
+ */
+ public final void updateTargets() {
+ getContext().updateTargets();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#removeBinding(org.eclipse.core.databinding.Binding)
+ */
+ public boolean removeBinding(Binding binding) {
+ return getContext().removeBinding(binding);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.databinding.IDataBindingContext#removeValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)
+ */
+ public boolean removeValidationStatusProvider(ValidationStatusProvider validationStatusProvider) {
+ return getContext().removeValidationStatusProvider(validationStatusProvider);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#getValidationRealm()
+ */
+ public final Realm getValidationRealm() {
+ return getContext().getValidationRealm();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#setRealm(org.eclipse.core.databinding.observable.Realm)
+ */
+ public void setRealm(Realm realm) {
+ this.realm = realm;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.databinding.IDataBindingContext#setStatusType(int)
+ */
+ public void setStatusType(int statusType) {
+ this.statusType = statusType;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingMode.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingMode.java
new file mode 100644
index 00000000000..60bf3f96519
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/BindingMode.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public enum BindingMode {
+ TwoWay, OneWay, OneTime;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ControlDataBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ControlDataBinding.java
new file mode 100644
index 00000000000..d51b7eed3b1
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ControlDataBinding.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.internal.core.Binding;
+import org.eclipse.papyrus.xwt.internal.core.BindingGate;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class ControlDataBinding extends AbstractDataBinding {
+
+ private Object source;
+
+ public ControlDataBinding(Object source, Binding binding, IDataProvider dataProvider) {
+ super(binding, dataProvider);
+ this.source = source;
+ }
+
+ /**
+ * Get bind value of two bindings.
+ */
+ public Object getValue(Class<?> targetType) {
+ IObservableValue targetWidget = null;
+ Object target = getControl();
+ if(target != null) {
+ targetWidget = ScopeManager.observeValue(target, target, getTargetProperty(), getUpdateSourceTrigger());
+ }
+ if(source == null) {
+ return null;
+ }
+
+ Object control = UserData.getWidget(source);
+ if(control == null) {
+ control = getControl();
+ }
+
+ IObservableValue sourceWidget = ScopeManager.observeValue(control, source, getSourceProperty(), getUpdateSourceTrigger());
+
+ if(targetWidget == null) {
+ if(sourceWidget != null) {
+ if(targetType != null && !targetType.isInstance(sourceWidget)) {
+ return sourceWidget;
+ }
+ Object value = sourceWidget.getValue();
+ while(value instanceof IObservableValue) {
+ value = ((IObservableValue)value).getValue();
+ }
+ IValueConverter converter = getConverter();
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ return value;
+ }
+ return source;
+ }
+
+ IBindingContext dataBindingContext = getDataBindingContext();
+ BindingGate bindingGate = new BindingGate(dataBindingContext);
+ bindingGate.bind(sourceWidget, targetWidget, this);
+ if(sourceWidget != null) {
+ if(targetType != null && !targetType.isInstance(sourceWidget)) {
+ return sourceWidget;
+ }
+ // convert to final value
+ Object value = sourceWidget.getValue();
+ while(value instanceof IObservableValue) {
+ value = ((IObservableValue)value).getValue();
+ }
+ IValueConverter converter = getConverter();
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ return value;
+ }
+ return source;
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected Object getSource() {
+ return source;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/DataBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/DataBinding.java
new file mode 100644
index 00000000000..4c1b9e790d8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/DataBinding.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.internal.core.Binding;
+import org.eclipse.papyrus.xwt.internal.core.BindingExpressionPath;
+import org.eclipse.papyrus.xwt.internal.core.BindingGate;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+import org.eclipse.papyrus.xwt.metadata.ModelUtils;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * The default implementation of the dataBinding object.
+ *
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class DataBinding extends AbstractDataBinding {
+
+ private IObservable observableWidget;
+
+ private BindingGate bindingGate;
+
+ /**
+ * Constructor for dataProvider.
+ */
+ public DataBinding(Binding binding, IDataProvider dataProvider) {
+ super(binding, dataProvider);
+ assert dataProvider != null : "DataProvider is null";
+ }
+
+ /**
+ * Get bind value of two bindings.
+ */
+ public Object getValue(Class<?> targetType) {
+ IObservable observableWidget = getObservableWidget();
+ IObservable observableSource = getObservableSource(ScopeManager.VALUE);
+
+ /*
+ * If observableWidget is null, we need only return the data from
+ * provider.
+ */
+ if(observableWidget == null) {
+ if(observableSource == null) {
+ // TODO should raise an exception
+ return null;
+ }
+ if(targetType != null && !targetType.isInstance(observableSource)) {
+ return observableSource;
+ }
+
+ // convert to final value
+ Object value = observableSource;
+ if(observableSource instanceof IObservableValue) {
+ value = ((IObservableValue)observableSource).getValue();
+ }
+ return convertedValue(value);
+ }
+
+ BindingGate bindingContext = getBindingGate();
+
+ if(bindingContext != null && observableSource != null) {
+ Object target = getControl();
+ if(target instanceof Text && getTargetProperty().equalsIgnoreCase("text")) {
+ if(isSourcePropertyReadOnly()) {
+ Text text = (Text)target;
+ text.setEditable(false);
+ }
+ } else if(target instanceof Button && getTargetProperty().equalsIgnoreCase("selection")) {
+ if(isSourcePropertyReadOnly()) {
+ Button button = (Button)target;
+ button.setEnabled(false);
+ }
+ } else if((target instanceof Combo || target instanceof CCombo) && getTargetProperty().equalsIgnoreCase("text")) {
+ if(isSourcePropertyReadOnly()) {
+ Control control = (Control)target;
+ control.setEnabled(false);
+ }
+ } else if(target instanceof MenuItem && getTargetProperty().equalsIgnoreCase("selection")) {
+ if(isSourcePropertyReadOnly()) {
+ MenuItem menuItem = (MenuItem)target;
+ menuItem.setEnabled(false);
+ }
+ }
+ bindingContext.bind(observableSource, observableWidget, this);
+ }
+
+ if(targetType != null && !targetType.isInstance(observableSource)) {
+ return observableSource;
+ }
+
+ // convert to final value
+ Object value = observableSource;
+ while(value instanceof IObservableValue) {
+ value = ((IObservableValue)value).getValue();
+ }
+ return convertedValue(value);
+ }
+
+ private BindingGate getBindingGate() {
+ if(this.bindingGate == null) {
+ IBindingContext dataBindingContext = getDataBindingContext();
+ this.bindingGate = new BindingGate(dataBindingContext);
+ }
+
+ return this.bindingGate;
+ }
+
+ private Object convertedValue(Object value) {
+ IValueConverter converter = getConverter();
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ return value;
+ }
+
+ public boolean isSourcePropertyReadOnly() {
+ IDataProvider dataProvider = getDataProvider();
+ try {
+ return ScopeManager.isPropertyReadOnly(dataProvider, getSourcePropertyExpression());
+ } catch (XWTException e) {
+ }
+ return false;
+ }
+
+ public IObservable getObservableSource(int observeKind) {
+ IObservable observableSource = getObservableSource();
+ if(observableSource == null) {
+ IDataProvider dataProvider = getDataProvider();
+ observableSource = ScopeManager.observe(getControl(), dataProvider.getData(null), getSourcePropertyExpression(), getUpdateSourceTrigger(), observeKind);
+ if(observableSource != null) {
+ setObservableSource(observableSource);
+ }
+ }
+ return observableSource;
+ }
+
+ public IObservable getObservableWidget() {
+ if(observableWidget == null) {
+ Object target = getControl();
+ Object host = getHost();
+ String targetProperty = getTargetProperty();
+ targetProperty = ModelUtils.normalizePropertyName(targetProperty);
+ int observeKind = ScopeManager.AUTO;
+ if(host instanceof Viewer && "input".equals(targetProperty)) {
+ // It is possible to use List
+ getObservableSource(ScopeManager.COLLECTION);
+ IObservable observableSource = getObservableSource();
+ if(observableSource instanceof IObservableList) {
+ return null;
+ } else if(observableSource instanceof IObservableSet) {
+ return null;
+ }
+ }
+ try {
+ BindingExpressionPath path = getTargetPropertyExpression();
+ if(path.isEmptyPath()) {
+ return null;
+ }
+ observableWidget = ScopeManager.observe(target, host, path, getUpdateSourceTrigger(), observeKind);
+ } catch (XWTException e) {
+ }
+ }
+ return observableWidget;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/Event.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/Event.java
new file mode 100644
index 00000000000..76c1ba0efd8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/Event.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+/**
+ * @author jliu jin.liu@soyatec.com
+ */
+public class Event {
+
+ private Object eventTarget;
+
+ private Object oldValue;
+
+ private Object newValue;
+
+ private String eventType;
+
+ public Event(Object eventTarget, Object oldValue, Object newValue, String eventType) {
+ this.eventTarget = eventTarget;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ this.eventType = eventType;
+ }
+
+ /**
+ * @return the eventTarget
+ */
+ public Object getEventTarget() {
+ return eventTarget;
+ }
+
+ /**
+ * @param eventTarget
+ * the eventTarget to set
+ */
+ public void setEventTarget(Object eventTarget) {
+ this.eventTarget = eventTarget;
+ }
+
+ /**
+ * @return the oldValue
+ */
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ /**
+ * @param oldValue
+ * the oldValue to set
+ */
+ public void setOldValue(Object oldValue) {
+ this.oldValue = oldValue;
+ }
+
+ /**
+ * @return the newValue
+ */
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ /**
+ * @param newValue
+ * the newValue to set
+ */
+ public void setNewValue(Object newValue) {
+ this.newValue = newValue;
+ }
+
+ /**
+ * @return the eventType
+ */
+ public String getEventType() {
+ return eventType;
+ }
+
+ /**
+ * @param eventType
+ * the eventType to set
+ */
+ public void setEventType(String eventType) {
+ this.eventType = eventType;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventListener.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventListener.java
new file mode 100644
index 00000000000..440bb59b597
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventListener.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+/**
+ * @author jliu jin.liu@soyatec.com
+ */
+public interface EventListener {
+
+ void handleEvent(Event evt);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventManager.java
new file mode 100644
index 00000000000..7387aac7fc1
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventManager.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.databinding.observable.Realm;
+
+/**
+ * This class <code>EventManager</code> is used to manage all event listeners for a observed object.
+ *
+ * @author jliu jin.liu@soyatec.com
+ */
+public class EventManager {
+
+ private static Map<Object, EventManager> managers = new HashMap<Object, EventManager>();
+
+ private Realm realm;
+
+ private Map<String, List<EventListener>> type2listeners = new HashMap<String, List<EventListener>>();
+
+ /**
+ * private constructor, lazy creating.
+ */
+ private EventManager(Object observed, Realm realm) {
+ this.realm = realm;
+ }
+
+ public static EventManager getEventManager(Object eventTarget, Realm realm) {
+ EventManager eventManager = managers.get(eventTarget);
+ if(eventManager == null || eventManager.realm != realm) {
+ eventManager = new EventManager(eventTarget, realm);
+ managers.put(eventTarget, eventManager);
+ }
+ return eventManager;
+ }
+
+ public void dispatchEvent(Event event) {
+ String eventType = event.getEventType();
+ List<EventListener> listeners = type2listeners.get(eventType);
+ for(EventListener l : listeners) {
+ l.handleEvent(event);
+ }
+ }
+
+ public void addEventListener(String eventType, EventListener eventListener) {
+ List<EventListener> listeners = type2listeners.get(eventType);
+ if(listeners == null) {
+ listeners = new ArrayList<EventListener>();
+ type2listeners.put(eventType, listeners);
+ }
+ listeners.add(eventListener);
+ }
+
+ public void removeEventListener(String eventType, EventListener eventListener) {
+ List<EventListener> listeners = type2listeners.get(eventType);
+ if(listeners != null) {
+ listeners.remove(eventListener);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventPropertyObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventPropertyObservableValue.java
new file mode 100644
index 00000000000..0744ba44cd5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/EventPropertyObservableValue.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.papyrus.xwt.IObservableValueListener;
+import org.eclipse.papyrus.xwt.internal.core.IEventController;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.ObservableValueManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.EventProperty;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+
+public class EventPropertyObservableValue extends XWTObservableValue {
+
+ private EventProperty property;
+
+ public EventPropertyObservableValue(Object observed, EventProperty property) {
+ super(Boolean.class, observed, property.getName());
+ this.property = property;
+ IEventController controller = UserData.findEventController(observed);
+ if(controller == null) {
+ controller = UserData.updateEventController(observed);
+ }
+ IEvent event = property.getEvent();
+
+ IObservableValueListener manager = UserData.getObservableValueManager(observed);
+ if(manager == null) {
+ manager = new ObservableValueManager(observed);
+ UserData.setObservableValueManager(observed, manager);
+ }
+ try {
+ controller.setEvent(event, UserData.getWidget(observed), manager, property, IObservableValueListener.class.getDeclaredMethod("changeValueHandle", Object.class, org.eclipse.swt.widgets.Event.class));
+ manager.registerValue(property, this);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ return;
+ }
+ }
+
+ @Override
+ protected void doSetApprovedValue(Object value) {
+ UserData.setLocalData(getObserved(), property.getName(), value);
+ }
+
+ protected Object doGetValue() {
+ return UserData.getLocalData(getObserved(), property.getName());
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/IBindingContext.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/IBindingContext.java
new file mode 100644
index 00000000000..6f4f679943d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/IBindingContext.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.AggregateValidationStatus;
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.UpdateListStrategy;
+import org.eclipse.core.databinding.UpdateSetStrategy;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.ValidationStatusProvider;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.map.IObservableMap;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+
+public interface IBindingContext {
+
+ /**
+ *
+ * @see @see org.eclipse.core.databinding.AggregateValidationStatus#MERGED
+ */
+ public static final int MERGED = org.eclipse.core.databinding.AggregateValidationStatus.MERGED;
+
+ /**
+ *
+ * @see org.eclipse.core.databinding.AggregateValidationStatus#MAX_SEVERITY
+ */
+ public static final int MAX_SEVERITY = org.eclipse.core.databinding.AggregateValidationStatus.MAX_SEVERITY;
+
+ /**
+ * @return the delegate
+ */
+ public abstract org.eclipse.core.databinding.DataBindingContext getContext();
+
+ /**
+ * @return the realm
+ */
+ public abstract Realm getRealm();
+
+ /**
+ * @return the status
+ */
+ public abstract AggregateValidationStatus getStatus();
+
+ /**
+ * The status type of the status. One of the values
+ *
+ * @return the statusType
+ */
+ public abstract int getStatusType();
+
+ /**
+ * @param targetObservableValue
+ * @param modelObservableValue
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#bindValue(org.eclipse.core.databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ public abstract Binding bindValue(IObservableValue targetObservableValue, IObservableValue modelObservableValue);
+
+ /**
+ * @param obj
+ * @return
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public abstract boolean equals(Object obj);
+
+ /**
+ * @param targetObservableValue
+ * @param modelObservableValue
+ * @param targetToModel
+ * @param modelToTarget
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#bindValue(org.eclipse.core.databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue, org.eclipse.core.databinding.UpdateValueStrategy,
+ * org.eclipse.core.databinding.UpdateValueStrategy)
+ */
+ public abstract Binding bindValue(IObservableValue targetObservableValue, IObservableValue modelObservableValue, UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget);
+
+ /**
+ * @param targetObservableList
+ * @param modelObservableList
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#bindList(org.eclipse.core.databinding.observable.list.IObservableList,
+ * org.eclipse.core.databinding.observable.list.IObservableList)
+ */
+ public abstract Binding bindList(IObservableList targetObservableList, IObservableList modelObservableList);
+
+ /**
+ * @param targetObservableList
+ * @param modelObservableList
+ * @param targetToModel
+ * @param modelToTarget
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#bindList(org.eclipse.core.databinding.observable.list.IObservableList,
+ * org.eclipse.core.databinding.observable.list.IObservableList, org.eclipse.core.databinding.UpdateListStrategy,
+ * org.eclipse.core.databinding.UpdateListStrategy)
+ */
+ public abstract Binding bindList(IObservableList targetObservableList, IObservableList modelObservableList, UpdateListStrategy targetToModel, UpdateListStrategy modelToTarget);
+
+ /**
+ * @param targetObservableSet
+ * @param modelObservableSet
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#bindSet(org.eclipse.core.databinding.observable.set.IObservableSet,
+ * org.eclipse.core.databinding.observable.set.IObservableSet)
+ */
+ public abstract Binding bindSet(IObservableSet targetObservableSet, IObservableSet modelObservableSet);
+
+ /**
+ * @param targetObservableSet
+ * @param modelObservableSet
+ * @param targetToModel
+ * @param modelToTarget
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#bindSet(org.eclipse.core.databinding.observable.set.IObservableSet,
+ * org.eclipse.core.databinding.observable.set.IObservableSet, org.eclipse.core.databinding.UpdateSetStrategy,
+ * org.eclipse.core.databinding.UpdateSetStrategy)
+ */
+ public abstract Binding bindSet(IObservableSet targetObservableSet, IObservableSet modelObservableSet, UpdateSetStrategy targetToModel, UpdateSetStrategy modelToTarget);
+
+ /**
+ *
+ * @see org.eclipse.core.databinding.DataBindingContext#dispose()
+ */
+ public abstract void dispose();
+
+ /**
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#getBindings()
+ */
+ public abstract IObservableList getBindings();
+
+ /**
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#getValidationStatusProviders()
+ */
+ public abstract IObservableList getValidationStatusProviders();
+
+ /**
+ * @return
+ * @deprecated
+ * @see org.eclipse.core.databinding.DataBindingContext#getValidationStatusMap()
+ */
+ public abstract IObservableMap getValidationStatusMap();
+
+ /**
+ * @param binding
+ * @see org.eclipse.core.databinding.DataBindingContext#addBinding(org.eclipse.core.databinding.Binding)
+ */
+ public abstract void addBinding(Binding binding);
+
+ /**
+ * @param validationStatusProvider
+ * @see org.eclipse.core.databinding.DataBindingContext#addValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)
+ */
+ public abstract void addValidationStatusProvider(ValidationStatusProvider validationStatusProvider);
+
+ /**
+ *
+ * @see org.eclipse.core.databinding.DataBindingContext#updateModels()
+ */
+ public abstract void updateModels();
+
+ /**
+ *
+ * @see org.eclipse.core.databinding.DataBindingContext#updateTargets()
+ */
+ public abstract void updateTargets();
+
+ /**
+ * @param binding
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#removeBinding(org.eclipse.core.databinding.Binding)
+ */
+ public abstract boolean removeBinding(Binding binding);
+
+ /**
+ * @param validationStatusProvider
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#removeValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)
+ */
+ public abstract boolean removeValidationStatusProvider(ValidationStatusProvider validationStatusProvider);
+
+ /**
+ * @return
+ * @see org.eclipse.core.databinding.DataBindingContext#getValidationRealm()
+ */
+ public abstract Realm getValidationRealm();
+
+ /**
+ * @param realm
+ * the realm to set
+ */
+ public abstract void setRealm(Realm realm);
+
+ /**
+ * @param statusType
+ * the statusType to set
+ */
+ public abstract void setStatusType(int statusType);
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/JFaceXWTDataBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/JFaceXWTDataBinding.java
new file mode 100644
index 00000000000..3e693e1b932
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/JFaceXWTDataBinding.java
@@ -0,0 +1,475 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import java.beans.BeanInfo;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.property.value.SimpleValueProperty;
+import org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.databinding.viewers.ViewerProperties;
+import org.eclipse.jface.databinding.viewers.ViewersObservables;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+import org.eclipse.papyrus.xwt.internal.databinding.menuitem.MenuItemEnabledObservableValue;
+import org.eclipse.papyrus.xwt.internal.databinding.menuitem.MenuItemSelectionObservableValue;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.EventProperty;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class JFaceXWTDataBinding {
+
+ static final String ENABLED = "enabled";
+
+ static final String SELECTION = "selection";
+
+ static final String TEXT = "text";
+
+ public static final Class<?>[] CONTROL_ARGUMENT_TYPES = new Class[]{ Control.class };
+
+ public static final Class<?>[] VIEWER_ARGUMENT_TYPES = new Class[]{ Viewer.class };
+
+ static String[] VIEWERS_PROPERTIES = null;
+ static {
+ Method[] methods = ViewerProperties.class.getDeclaredMethods();
+ VIEWERS_PROPERTIES = new String[methods.length];
+ for(int i = 0; i < methods.length; i++) {
+ VIEWERS_PROPERTIES[i] = methods[i].getName();
+ }
+ }
+
+ public static boolean isViewerProperty(String propertyName) {
+ for(String name : VIEWERS_PROPERTIES) {
+ if(name.equals(propertyName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static Class<?> getValueType(Class<?> type, String propertyName) {
+ if(type == null || propertyName == null || propertyName.indexOf(".") != -1) {
+ return null;
+ }
+ try {
+ IMetaclass metaclass = XWT.getMetaclass(type);
+ IProperty property = metaclass.findProperty(propertyName);
+ if(property != null) {
+ return property.getType();
+ }
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ return null;
+ }
+
+ public static Object getValue(Object target, String propertyName) {
+ if(target == null || propertyName == null || propertyName.indexOf(".") != -1) {
+ return target;
+ }
+ Class<?> type = target.getClass();
+ try {
+ BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(type);
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for(PropertyDescriptor pd : propertyDescriptors) {
+ if(propertyName.equalsIgnoreCase(pd.getName())) {
+ Method readMethod = pd.getReadMethod();
+ if(readMethod != null) {
+ return readMethod.invoke(target);
+ }
+ }
+ }
+ Field[] fields = type.getDeclaredFields();
+ for(Field field : fields) {
+ if(propertyName.equalsIgnoreCase(field.getName())) {
+ Object object = field.get(target);
+ return object;
+ }
+ }
+ return UserData.getLocalData(target, propertyName);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ return null;
+ }
+
+ public static void setValue(Object target, String propertyName, Object value) {
+ Class<?> type = target.getClass();
+ try {
+ BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(type);
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for(PropertyDescriptor pd : propertyDescriptors) {
+ if(propertyName.equals(pd.getName())) {
+ Method writeMethod = pd.getWriteMethod();
+ if(writeMethod == null) {
+ return;
+ }
+ if(!writeMethod.isAccessible()) {
+ writeMethod.setAccessible(true);
+ }
+ Class<?>[] parameterTypes = writeMethod.getParameterTypes();
+ Class targetType = parameterTypes[0];
+ if(targetType != value.getClass()) {
+ if(targetType.isEnum() && value instanceof String) {
+ try {
+ writeMethod.invoke(target, new Object[]{ Enum.valueOf(targetType, (String)value) });
+ return;
+ } catch (Exception e) {
+ }
+ }
+ IConverter c = XWT.findConvertor(value.getClass(), targetType);
+ if(c != null) {
+ value = c.convert(value);
+ }
+ }
+ writeMethod.invoke(target, new Object[]{ value });
+ return;
+ }
+ }
+ Field[] fields = type.getDeclaredFields();
+ for(Field field : fields) {
+ if(propertyName.equals(field.getName())) {
+ if(!field.isAccessible()) {
+ field.setAccessible(true);
+ }
+ Class fieldType = field.getType();
+ if(fieldType.isEnum() && value instanceof String) {
+ try {
+ field.set(target, Enum.valueOf(fieldType, (String)value));
+ return;
+ } catch (Exception e) {
+ }
+ }
+ IConverter c = XWT.findConvertor(value.getClass(), fieldType);
+ if(c != null) {
+ value = c.convert(value);
+ }
+ field.set(target, value);
+ return;
+ }
+ }
+
+ IMetaclass metaclass = XWT.getMetaclass(type);
+ IProperty property = metaclass.findProperty(propertyName);
+ if(property != null) {
+ property.setValue(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static boolean isPropertyReadOnly(Class<?> type, String propertyName) {
+ if(type == null || propertyName == null || propertyName.indexOf(".") != -1) {
+ return true;
+ }
+ try {
+ IMetaclass metaclass = XWT.getMetaclass(type);
+ IProperty property = metaclass.findProperty(propertyName);
+ if(property != null) {
+ return property.isReadOnly();
+ }
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ return true;
+ }
+
+
+ public static boolean isBeanSupport(Object target) {
+ Class<?> type = toType(target);
+ Method method = null;
+ try {
+ try {
+ method = type.getMethod("addPropertyChangeListener", new Class[]{ String.class, PropertyChangeListener.class });
+ } catch (NoSuchMethodException e) {
+ method = type.getMethod("addPropertyChangeListener", new Class[]{ PropertyChangeListener.class });
+ }
+ } catch (SecurityException e) {
+ } catch (NoSuchMethodException e) {
+ }
+ return method != null;
+ }
+
+ public static Class<?> toType(Object target) {
+ Class<?> type = null;
+ if(target instanceof IObservableValue) {
+ IObservableValue value = (IObservableValue)target;
+ Object valueType = value.getValueType();
+ if(valueType instanceof Class<?>) {
+ type = (Class<?>)valueType;
+ }
+ } else if(target instanceof Class<?>) {
+ type = (Class<?>)target;
+ } else {
+ type = target.getClass();
+ }
+ if(type == null) {
+ return Object.class;
+ }
+ return type;
+ }
+
+ public static boolean isValueProperty(Class<?> object, String propertyName) {
+ if(propertyName == null) {
+ return false;
+ }
+
+ if(Viewer.class.isAssignableFrom(object)) {
+ return isViewerValueProperty(object, propertyName);
+ } else if(MenuItem.class.isAssignableFrom(object)) {
+ //
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=280157
+ // testcase:
+ // org.eclipse.papyrus.xwt.tests.databinding.bindcontrol.BindMenuItem
+ //
+ if(ENABLED.equalsIgnoreCase(propertyName)) {
+ return true;
+ } else if(SELECTION.equalsIgnoreCase(propertyName)) {
+ return true;
+ }
+ }
+ boolean isProperty = isControlValueProperty(object, propertyName);
+ if(isProperty) {
+ return true;
+ }
+ return false;
+ }
+
+ public static IObservable observeWidget(Object object, String propertyName, UpdateSourceTrigger updateSourceTrigger, int observedKind) {
+ if(propertyName == null) {
+ return null;
+ }
+ try {
+ switch(observedKind) {
+ case ScopeManager.AUTO:
+ return observePropertyValue(object, propertyName, updateSourceTrigger);
+ case ScopeManager.COLLECTION:
+ case ScopeManager.SET:
+ case ScopeManager.LIST:
+ break;
+ case ScopeManager.VALUE:
+ return observePropertyValue(object, propertyName, updateSourceTrigger);
+ default:
+ break;
+ }
+ } catch (XWTException e) {
+ }
+ return null;
+ }
+
+ protected static IObservable observePropertyValue(Object object, String propertyName, UpdateSourceTrigger updateSourceTrigger) {
+ if(object instanceof Viewer) {
+ if("input".equals(propertyName)) {
+ Viewer viewer = (Viewer)object;
+ SimpleValueProperty property = (SimpleValueProperty)ViewerProperties.input();
+ IObservableValue observableValue = new SimplePropertyObservableValue(XWT.getRealm(), viewer, property);
+ return new TypedViewerObservableValueDecorator(observableValue, viewer);
+ } else if("singleSelection".equals(propertyName)) {
+ Viewer viewer = (Viewer)object;
+ SimpleValueProperty property = (SimpleValueProperty)ViewerProperties.singleSelection();
+ IObservableValue observableValue = new SimplePropertyObservableValue(XWT.getRealm(), viewer, property);
+ return new TypedViewerObservableValueDecorator(observableValue, viewer);
+ }
+ return observePropertyValue((Viewer)object, propertyName, updateSourceTrigger);
+ } else if(object instanceof MenuItem) {
+ //
+ // TODO https://bugs.eclipse.org/bugs/show_bug.cgi?id=280157
+ // testcase:
+ // org.eclipse.papyrus.xwt.tests.databinding.bindcontrol.BindMenuItem
+ //
+ if(ENABLED.equalsIgnoreCase(propertyName)) {
+ return new MenuItemEnabledObservableValue((MenuItem)object);
+ } else if(SELECTION.equalsIgnoreCase(propertyName)) {
+ return new MenuItemSelectionObservableValue((MenuItem)object);
+ }
+ } else if(object instanceof Control) {
+ return observePropertyValue((Control)object, propertyName, updateSourceTrigger);
+ }
+ return null;
+ }
+
+ protected static boolean isControlValueProperty(Class<?> type, String propertyName) {
+ if(TEXT.equalsIgnoreCase(propertyName)) {
+ if(Text.class.isAssignableFrom(type)) {
+ return true;
+ }
+ // widget button is not supported at 3.4 version.
+ if(SWT.getVersion() == 3449 && Button.class.isAssignableFrom(type)) {
+ return false;
+ }
+ }
+ String getterName = "observe" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
+ Method method;
+ try {
+ method = SWTObservables.class.getMethod(getterName, CONTROL_ARGUMENT_TYPES);
+ if(method == null) {
+ for(Method element : SWTObservables.class.getMethods()) {
+ if(element.getParameterTypes().length != 0) {
+ continue;
+ }
+ if(element.getName().equalsIgnoreCase(getterName)) {
+ return true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ IMetaclass mateclass = XWT.getMetaclass(type);
+ IProperty property = mateclass.findProperty(propertyName);
+ if(property instanceof EventProperty) {
+ return true;
+ }
+ return false;
+ }
+
+ protected static IObservableValue observePropertyValue(Control control, String propertyName, UpdateSourceTrigger updateSourceTrigger) {
+ if(TEXT.equalsIgnoreCase(propertyName)) {
+ if(control instanceof Text || control instanceof StyledText) {
+ int event = SWT.None;
+ switch(updateSourceTrigger) {
+ case Default:
+ event = SWT.FocusOut;
+ break;
+ case LostFocus:
+ event = SWT.FocusOut;
+ break;
+ case PropertyChanged:
+ event = SWT.Modify;
+ break;
+ default:
+ throw new IllegalStateException("UpdateSourceTrigger of value " + updateSourceTrigger.name());
+ }
+ IObservableValue observableValue = SWTObservables.observeText(control, event);
+ if(observableValue != null) {
+ return observableValue;
+ }
+ }
+ // widget button is not supported at 3.4 version.
+ if(SWT.getVersion() == 3449 && control instanceof Button) {
+ return null;
+ }
+ try {
+ IObservableValue observableValue = SWTObservables.observeText(control);
+ if(observableValue != null) {
+ return observableValue;
+ }
+ } catch (IllegalArgumentException e) {
+ throw new XWTException(e);
+ }
+ } else {
+ if(propertyName == null) {
+ return null;
+ }
+ String getterName = "observe" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
+ Method method;
+ try {
+ method = SWTObservables.class.getMethod(getterName, CONTROL_ARGUMENT_TYPES);
+ if(method == null) {
+ for(Method element : SWTObservables.class.getMethods()) {
+ if(element.getParameterTypes().length != 0) {
+ continue;
+ }
+ if(element.getName().equalsIgnoreCase(getterName)) {
+ method = element;
+ break;
+ }
+ }
+ }
+ if(method != null) {
+ IObservableValue observableValue = (IObservableValue)method.invoke(null, control);
+ if(observableValue != null) {
+ return observableValue;
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+ IMetaclass mateclass = XWT.getMetaclass(control);
+ IProperty property = mateclass.findProperty(propertyName);
+ if(property instanceof EventProperty) {
+ return new EventPropertyObservableValue(control, (EventProperty)property);
+ }
+ return null;
+ }
+
+ protected static boolean isViewerValueProperty(Class<?> viewerType, String property) {
+ String getterName = "observe" + property.substring(0, 1).toUpperCase() + property.substring(1);
+ try {
+ Method method = ViewersObservables.class.getMethod(getterName, VIEWER_ARGUMENT_TYPES);
+ if(method == null) {
+ for(Method element : ViewersObservables.class.getMethods()) {
+ if(element.getParameterTypes().length != 0) {
+ continue;
+ }
+ if(element.getName().equalsIgnoreCase(getterName)) {
+ return true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ return false;
+ }
+
+ protected static IObservable observePropertyValue(Viewer viewer, String property, UpdateSourceTrigger updateSourceTrigger) {
+ String getterName = "observe" + property.substring(0, 1).toUpperCase() + property.substring(1);
+ Method method;
+ try {
+ method = ViewersObservables.class.getMethod(getterName, VIEWER_ARGUMENT_TYPES);
+ if(method == null) {
+ for(Method element : ViewersObservables.class.getMethods()) {
+ if(element.getParameterTypes().length != 0) {
+ continue;
+ }
+ if(element.getName().equalsIgnoreCase(getterName)) {
+ method = element;
+ break;
+ }
+ }
+ }
+ if(method != null) {
+ IObservable observableValue = (IObservable)method.invoke(null, viewer);
+ if(observableValue != null) {
+ return observableValue;
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ListToArrayObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ListToArrayObservableValue.java
new file mode 100644
index 00000000000..c8fc9d322b3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/ListToArrayObservableValue.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.papyrus.xwt.databinding;
+
+import java.lang.reflect.Array;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.observable.DisposeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IDisposeListener;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+
+/**
+ * Manage the Array to List and then update from List to Array
+ *
+ * @author yyang
+ */
+public class ListToArrayObservableValue extends AbstractObservableValue {
+
+ protected IObservableList source;
+
+ protected IObservableValue target;
+
+ protected Object valueType;
+
+ protected Object cacheData;
+
+ public ListToArrayObservableValue(IObservableList source, IObservableValue target) {
+ super(source.getRealm());
+ this.source = source;
+ this.target = target;
+
+ source.addChangeListener(new IChangeListener() {
+
+ public void handleChange(ChangeEvent event) {
+ ListToArrayObservableValue.this.handleChange();
+ }
+ });
+
+ source.addDisposeListener(new IDisposeListener() {
+
+ public void handleDispose(DisposeEvent event) {
+ ListToArrayObservableValue.this.dispose();
+ }
+ });
+ }
+
+ protected Object doGetValue() {
+ return source;
+ }
+
+ protected void doSetValue(Object value) {
+ super.doSetValue(value);
+ }
+
+ public Object getValueType() {
+ return source.getElementType();
+ }
+
+ @Override
+ public synchronized void dispose() {
+ super.dispose();
+ source.dispose();
+ target.dispose();
+ source = null;
+ target = null;
+ }
+
+ protected void handleChange() {
+ try {
+ Object elements = Array.newInstance((Class<?>)getValueType(), source.size());
+ Object[] objects = source.toArray((Object[])elements);
+ if(cacheData == null) {
+ cacheData = target.getValue();
+ }
+ target.setValue(objects);
+ fireValueChange(Diffs.createValueDiff(cacheData, objects));
+ cacheData = objects;
+ } catch (NegativeArraySizeException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/TypedViewerObservableValueDecorator.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/TypedViewerObservableValueDecorator.java
new file mode 100644
index 00000000000..86855d66a73
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/TypedViewerObservableValueDecorator.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.internal.databinding.viewers.ViewerObservableValueDecorator;
+import org.eclipse.jface.viewers.Viewer;
+
+public class TypedViewerObservableValueDecorator extends ViewerObservableValueDecorator {
+
+ protected Object elementType;
+
+ public TypedViewerObservableValueDecorator(IObservableValue decorated, Viewer viewer) {
+ super(decorated, viewer);
+ }
+
+ public Object getElementType() {
+ return elementType;
+ }
+
+ public void setElementType(Object elementType) {
+ this.elementType = elementType;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(!(obj instanceof TypedViewerObservableValueDecorator)) {
+ return false;
+ }
+ TypedViewerObservableValueDecorator decorator = (TypedViewerObservableValueDecorator)obj;
+ if(elementType != null) {
+ if(!elementType.equals(decorator.elementType)) {
+ return false;
+ }
+ } else if(decorator.elementType != null) {
+ return false;
+ }
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ if(elementType == null) {
+ return super.hashCode();
+ }
+ return elementType.hashCode() * super.hashCode();
+ }
+
+ @Override
+ public Object getValueType() {
+ Object elementType = getElementType();
+ if(elementType != null) {
+ return elementType;
+ }
+ return super.getValueType();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/XWTObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/XWTObservableValue.java
new file mode 100644
index 00000000000..5da1f172c7a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/databinding/XWTObservableValue.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.databinding;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.Diffs;
+import org.eclipse.core.databinding.observable.IObserving;
+import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
+import org.eclipse.core.databinding.observable.value.ValueDiff;
+import org.eclipse.jface.util.Util;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * Notes: Binding type is java.lang.String.
+ *
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public abstract class XWTObservableValue extends AbstractObservableValue implements IObserving {
+
+ private Object observed;
+
+ private Class<?> valueType;
+
+ private EventManager eventManager;
+
+ private EventListener eventListener;
+
+ private String path;
+
+ private boolean updating = false;
+
+ /**
+ *
+ */
+ public XWTObservableValue(Class<?> valueType, Object observed, String path) {
+ super(XWT.getRealm());
+ this.valueType = valueType;
+ this.observed = observed;
+ this.path = path;
+ init();
+ }
+
+ /**
+ * Add listener to observed.
+ */
+ private void init() {
+ if(eventListener == null) {
+ eventListener = new EventListener() {
+
+ public void handleEvent(Event evt) {
+ if(!updating) {
+ final ValueDiff diff = Diffs.createValueDiff(evt.getOldValue(), evt.getNewValue());
+ getRealm().exec(new Runnable() {
+
+ public void run() {
+ fireValueChange(diff);
+ }
+ });
+ }
+ }
+ };
+ }
+ eventManager = EventManager.getEventManager(observed, getRealm());
+ eventManager.addEventListener(path, eventListener);
+ }
+
+ /**
+ * @return the observed
+ */
+ public Object getObserved() {
+ return observed;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object)
+ */
+ protected void doSetValue(Object value) {
+ updating = true;
+ Object oldValue = doGetValue();
+ value = convert(oldValue == null ? null : oldValue.getClass(), value);
+ if(!Util.equals(oldValue, value)) {
+ doSetApprovedValue(value);
+ fireValueChange(Diffs.createValueDiff(oldValue, value));
+ eventManager.dispatchEvent(new Event(observed, oldValue, value, getPath()));
+ }
+ updating = false;
+ }
+
+ /**
+ * @param value
+ * @return
+ */
+ protected Object convert(Class type, Object value) {
+ if(value != null) {
+ if(type != null && type.isEnum() && value instanceof String) {
+ return Enum.valueOf(type, (String)value);
+ }
+ IConverter c = XWT.findConvertor(value.getClass(), (Class<?>)getValueType());
+ if(c != null) {
+ return c.convert(value);
+ }
+ }
+ return value;
+ }
+
+ /**
+ * @param value
+ */
+ protected abstract void doSetApprovedValue(Object value);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue()
+ */
+ protected Object doGetValue() {
+ return observed;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType()
+ */
+ public Class<?> getValueType() {
+ return valueType;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/AbstractDataProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/AbstractDataProvider.java
new file mode 100644
index 00000000000..e325a673093
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/AbstractDataProvider.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.dataproviders;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.property.value.IValueProperty;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public abstract class AbstractDataProvider implements IDataProvider {
+
+ private HashMap<String, Object> properties = new HashMap<String, Object>();
+
+ public Object getProperty(String property) {
+ return properties.get(property);
+ }
+
+ public void setProperty(String property, Object value) {
+ properties.put(property, value);
+ }
+
+ public boolean hasProperty(String property) {
+ return properties.containsKey(property);
+ }
+
+ public void removeProperty(String property) {
+ properties.remove(property);
+ }
+
+ public boolean isPropertyReadOnly(String path) {
+ return false;
+ }
+
+ public IObservable observe(Object data, String path, Object elementType, int observeKind) {
+ Object type = null;
+ if(elementType == null) {
+ type = getModelService().toModelType(data);
+ } else {
+ type = elementType;
+ }
+ Object propertyType = getModelService().toModelPropertyType(type, path);
+ Class<?> propertyTypeClass = null;
+
+ if(propertyType instanceof Class<?>) {
+ propertyTypeClass = (Class<?>)propertyType;
+ if(IBinding.class.isAssignableFrom(propertyTypeClass)) {
+ return null;
+ }
+ }
+
+ switch(observeKind) {
+ case ScopeManager.AUTO:
+ if(propertyTypeClass != null && (propertyTypeClass.isArray() || List.class.isAssignableFrom(propertyTypeClass))) {
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailList(observable, type, path, propertyType);
+ }
+ return observeList(data, path);
+ } else if(propertyTypeClass != null && (Set.class.isAssignableFrom(propertyTypeClass))) {
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailSet(observable, type, path, propertyType);
+ }
+ return observeSet(data, path);
+ } else {
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailValue(observable, type, path, propertyType);
+ }
+ return observeValue(data, path);
+ }
+ case ScopeManager.VALUE:
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailValue(observable, type, path, propertyType);
+ }
+ return observeValue(data, path);
+ case ScopeManager.COLLECTION:
+ if(propertyTypeClass != null && Set.class.isAssignableFrom(propertyTypeClass)) {
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailSet(observable, type, path, propertyType);
+ }
+ return observeSet(data, path);
+ }
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailList(observable, type, path, propertyType);
+ }
+ return observeList(data, path);
+ case ScopeManager.SET:
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailSet(observable, type, path, propertyType);
+ }
+ return observeSet(data, path);
+ case ScopeManager.LIST:
+ if(data instanceof IObservableValue) {
+ IObservableValue observable = (IObservableValue)data;
+ return observeDetailList(observable, type, path, propertyType);
+ }
+ return observeList(data, path);
+ }
+ return null;
+ }
+
+ protected abstract IObservableValue observeValue(Object bean, String propertyName);
+
+ protected IObservableList observeList(Object bean, String propertyName) {
+ return null;
+ }
+
+ protected IObservableSet observeSet(Object bean, String propertyName) {
+ return null;
+ }
+
+ protected IObservableList observeDetailList(IObservableValue bean, Object elementType, String propertyName, Object propertyType) {
+ return null;
+ }
+
+ protected IObservableSet observeDetailSet(IObservableValue bean, Object elementType, String propertyName, Object propertyType) {
+ return null;
+ }
+
+ protected abstract IObservableValue observeDetailValue(IObservableValue bean, Object elementType, String propertyName, Object propertyType);
+
+ // TODO to remove
+ public IValueProperty createValueProperty(Object type, String fullPath) {
+ throw new UnsupportedOperationException("to remove this method");
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/IObjectDataProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/IObjectDataProvider.java
new file mode 100644
index 00000000000..668af6c9ed0
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/IObjectDataProvider.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.dataproviders;
+
+import java.util.List;
+
+import org.eclipse.papyrus.xwt.IDataProvider;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public interface IObjectDataProvider extends IDataProvider {
+
+ void setObjectType(Class<?> objectType);
+
+ Class<?> getObjectType();
+
+ void setObjectInstance(Object objectInstance);
+
+ Object getObjectInstance();
+
+ void setMethodName(String methodName);
+
+ String getMethodName();
+
+ List<Object> getMethodParameters();
+
+ void setMethodParameters(List<Object> parameters);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/ObjectDataProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/ObjectDataProvider.java
new file mode 100644
index 00000000000..04e4db8ee5d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/dataproviders/ObjectDataProvider.java
@@ -0,0 +1,345 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.dataproviders;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.beans.PojoObservables;
+import org.eclipse.core.databinding.beans.PojoProperties;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.property.value.IValueProperty;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.databinding.JFaceXWTDataBinding;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class ObjectDataProvider extends AbstractDataProvider implements IObjectDataProvider {
+
+ static DataModelService dataModelService = new DataModelService() {
+
+ public Object toModelType(Object object) {
+ return JFaceXWTDataBinding.toType(object);
+ }
+
+ public Object loadModelType(String className) {
+ return XWT.getLoadingContext().loadClass(className);
+ }
+
+ public Object toModelPropertyType(Object type, String propertyName) {
+ IMetaclass metaclass = XWT.getMetaclass(type);
+ IProperty property = metaclass.findProperty(propertyName);
+
+ if(property == null) {
+ throw new XWTException(" Property \"" + propertyName + "\" is not found in the class " + metaclass.getType().getName());
+ }
+ return property.getType();
+ }
+ };
+
+ private Object objectInstance;
+
+ private Class<?> objectType;
+
+ private String methodName;
+
+ private List<Object> methodParameters;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#getMethodName()
+ */
+ public String getMethodName() {
+ return methodName;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#getMethodParameters
+ * ()
+ */
+ public List<Object> getMethodParameters() {
+ return methodParameters;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#getObjectInstance()
+ */
+ public Object getObjectInstance() {
+ if(objectInstance == null && objectType != null) {
+ try {
+ objectInstance = objectType.newInstance();
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+ return objectInstance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#getObjectType()
+ */
+ public Class<?> getObjectType() {
+ if(objectType == null && objectInstance != null) {
+ objectType = objectInstance.getClass();
+ }
+ return objectType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#setMethodName(java
+ * .lang.String)
+ */
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#setMethodParameters
+ * (java.util.List)
+ */
+ public void setMethodParameters(List<Object> parameters) {
+ this.methodParameters = parameters;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#setObjectInstance
+ * (java.lang.Object)
+ */
+ public void setObjectInstance(Object objectImstance) {
+ this.objectInstance = objectImstance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider#setObjectType(java
+ * .lang.Class)
+ */
+ public void setObjectType(Class<?> objectType) {
+ this.objectType = objectType;
+ }
+
+ protected Object getTarget() {
+ Object target = getObjectInstance();
+ if(target == null) {
+ return null;
+ }
+ Class<?> targetType = getObjectType();
+ Method method = null;
+ if(methodName != null) {
+ List<Class<?>> paras = new ArrayList<Class<?>>();
+ if(methodParameters != null) {
+ for(Object p : methodParameters) {
+ paras.add(p.getClass());
+ }
+ }
+ try {
+ if(paras.isEmpty()) {
+ method = targetType.getDeclaredMethod(methodName);
+ return method.invoke(target);
+ } else {
+ method = targetType.getDeclaredMethod(methodName, paras.toArray(new Class<?>[paras.size()]));
+ return method.invoke(target, methodParameters.toArray(new Object[methodParameters.size()]));
+ }
+ } catch (SecurityException e) {
+ } catch (IllegalArgumentException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ }
+ return target;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IDataProvider#getData(java.lang.String)
+ */
+ public Object getData(String path) {
+ if(path == null) {
+ return getTarget();
+ }
+ return getData(getTarget(), path);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IDataProvider#getData(java.lang.String)
+ */
+ public Object getData(Object object, String path) {
+ if(object instanceof IObservableValue) {
+ object = ((IObservableValue)object).getValue();
+ }
+ if(path == null || path.trim().length() == 0 || path.equals(".")) {
+ return JFaceXWTDataBinding.getValue(object, null);
+ }
+ int index = path.indexOf(".");
+ while(index != -1 && object != null) {
+ object = JFaceXWTDataBinding.getValue(object, path.substring(0, index));
+ path = path.substring(index + 1);
+ index = path.indexOf(".");
+ }
+ return JFaceXWTDataBinding.getValue(object, path);
+ }
+
+ public void setData(Object object, String path, Object value) {
+ if(object instanceof IObservableValue) {
+ object = ((IObservableValue)object).getValue();
+ }
+ int index = path.indexOf(".");
+ while(index != -1 && object != null) {
+ object = JFaceXWTDataBinding.getValue(object, path.substring(0, index));
+ path = path.substring(index + 1);
+ index = path.indexOf(".");
+ }
+ JFaceXWTDataBinding.setValue(object, path, value);
+ }
+
+ public void setData(String path, Object value) {
+ setData(getTarget(), path, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.dataproviders.IDataProvider#getDataType(java.lang.
+ * String)
+ */
+ public Class<?> getDataType(String path) {
+ Object target = getTarget();
+ if(target == null) {
+ return null;
+ }
+ Class<?> type = JFaceXWTDataBinding.toType(target);
+ if(path == null) {
+ return type;
+ }
+ return JFaceXWTDataBinding.getValueType(type, path);
+ }
+
+ /**
+ * check if the property is read only
+ *
+ * @param path
+ * @return
+ */
+ public boolean isPropertyReadOnly(String path) {
+ Object target = getTarget();
+ if(target == null || path == null) {
+ return true;
+ }
+ if(target instanceof IBinding) {
+ target = ((IBinding)target).getValue(null);
+ }
+ Class<?> type = JFaceXWTDataBinding.toType(target);
+ int index = path.indexOf(".");
+ while(index != -1 && target != null) {
+ type = JFaceXWTDataBinding.getValueType(type, path.substring(0, index));
+ path = path.substring(index + 1);
+ index = path.indexOf(".");
+ }
+ return JFaceXWTDataBinding.isPropertyReadOnly(type, path);
+ }
+
+ @Override
+ protected IObservableValue observeValue(Object bean, String propertyName) {
+ if(JFaceXWTDataBinding.isBeanSupport(bean)) {
+ return BeansObservables.observeValue(XWT.getRealm(), bean, propertyName);
+ }
+ return PojoObservables.observeValue(XWT.getRealm(), bean, propertyName);
+ }
+
+ protected IObservableList observeList(Object bean, String propertyName) {
+ if(JFaceXWTDataBinding.isBeanSupport(bean)) {
+ return BeansObservables.observeList(XWT.getRealm(), bean, propertyName);
+ }
+ return PojoObservables.observeList(XWT.getRealm(), bean, propertyName);
+ }
+
+ protected IObservableSet observeSet(Object bean, String propertyName) {
+ if(JFaceXWTDataBinding.isBeanSupport(bean)) {
+ return BeansObservables.observeSet(XWT.getRealm(), bean, propertyName);
+ }
+ return PojoObservables.observeSet(XWT.getRealm(), bean, propertyName);
+ }
+
+ protected IObservableList observeDetailList(IObservableValue bean, Object elementType, String propertyName, Object propertyType) {
+ if(JFaceXWTDataBinding.isBeanSupport(bean)) {
+ return BeansObservables.observeDetailList(bean, propertyName, (Class<?>)propertyType);
+ }
+ return PojoObservables.observeDetailList(bean, propertyName, (Class<?>)propertyType);
+ }
+
+ protected IObservableSet observeDetailSet(IObservableValue bean, Object elementType, String propertyName, Object propertyType) {
+ if(JFaceXWTDataBinding.isBeanSupport(bean)) {
+ return BeansObservables.observeDetailSet(bean, propertyName, (Class<?>)propertyType);
+ }
+ return PojoObservables.observeDetailSet(bean, propertyName, (Class<?>)propertyType);
+ }
+
+ @Override
+ protected IObservableValue observeDetailValue(IObservableValue master, Object elementType, String propertyName, Object propertyType) {
+ Class<?> beanClass = (Class<?>)elementType;
+ if(beanClass == null && master.getValueType() instanceof Class<?>) {
+ beanClass = (Class<?>)master.getValueType();
+ }
+ if(JFaceXWTDataBinding.isBeanSupport(beanClass)) {
+ return BeanProperties.value(beanClass, propertyName, (Class<?>)propertyType).observeDetail(master);
+ }
+ return PojoProperties.value(beanClass, propertyName, (Class<?>)propertyType).observeDetail(master);
+ }
+
+ public IValueProperty createValueProperty(Object type, String propertyName) {
+ if(JFaceXWTDataBinding.isBeanSupport(type)) {
+ return BeanProperties.value(JFaceXWTDataBinding.toType(type), propertyName);
+ }
+ return PojoProperties.value(JFaceXWTDataBinding.toType(type), propertyName);
+ }
+
+ public DataModelService getModelService() {
+ return dataModelService;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Color.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Color.java
new file mode 100644
index 00000000000..d111d2417a8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Color.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.graphics;
+
+/**
+ * Color consists of four elements: alpha, blue, green and red.
+ *
+ * @author yyang
+ */
+public class Color {
+
+ private int alaha = 0xFF;
+
+ private int blue;
+
+ private int green;
+
+ private int red;
+
+ private org.eclipse.swt.graphics.Color swtColor;
+
+ public Color() {
+ }
+
+ public Color(org.eclipse.swt.graphics.Color swtColor) {
+ setValue(swtColor);
+ }
+
+ public int getBlue() {
+ return blue;
+ }
+
+ public void setBlue(int blue) {
+ this.blue = blue;
+ }
+
+ public int getGreen() {
+ return green;
+ }
+
+ public void setGreen(int green) {
+ this.green = green;
+ }
+
+ public int getRed() {
+ return red;
+ }
+
+ public void setRed(int red) {
+ this.red = red;
+ }
+
+ public int getAlpha() {
+ return alaha;
+ }
+
+ public void setAlaha(int alaha) {
+ this.alaha = alaha;
+ }
+
+ public org.eclipse.swt.graphics.Color toSWTColor() {
+ if(swtColor == null) {
+ swtColor = new org.eclipse.swt.graphics.Color(null, red, green, blue);
+ }
+ return swtColor;
+ }
+
+ public void setValue(org.eclipse.swt.graphics.Color swtColor) {
+ this.swtColor = swtColor;
+ this.blue = swtColor.getBlue();
+ this.red = swtColor.getRed();
+ this.green = swtColor.getGreen();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Point.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Point.java
new file mode 100644
index 00000000000..aa4f5bc311c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Point.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.graphics;
+
+/**
+ * Color consists of four elements: alpha, blue, green and red.
+ *
+ * @author yyang
+ */
+public class Point {
+
+ public static final Point[] EMPTY_ARRAY = new Point[]{};
+
+ private double x;
+
+ private double y;
+
+ public Point() {
+ }
+
+ public Point(double x, double y) {
+ setX(x);
+ setY(y);
+ }
+
+ public double getX() {
+ return x;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(!(obj instanceof Point)) {
+ return false;
+ }
+ Point point = (Point)obj;
+ return x == point.getX() && y == point.getY();
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + y + ")";
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Rect.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Rect.java
new file mode 100644
index 00000000000..84c48a98984
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/graphics/Rect.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.graphics;
+
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * Color consists of four elements: alpha, blue, green and red.
+ *
+ * @author yyang
+ */
+public class Rect {
+
+ private double x;
+
+ private double y;
+
+ private double width;
+
+ private double height;
+
+ public Rect() {
+ }
+
+ public Rect(double x, double y, double width, double height) {
+ setX(x);
+ setY(y);
+ setWidth(width);
+ setHeight(height);
+ }
+
+ public Rect(Rectangle rectangle) {
+ setX(rectangle.x);
+ setY(rectangle.y);
+ setWidth(rectangle.width);
+ setHeight(rectangle.height);
+ }
+
+ public double getWidth() {
+ return width;
+ }
+
+ public void setWidth(double width) {
+ this.width = width;
+ }
+
+ public double getHeight() {
+ return height;
+ }
+
+ public void setHeight(double height) {
+ this.height = height;
+ }
+
+ public double getX() {
+ return x;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ }
+
+ public double getY() {
+ return y;
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(!(obj instanceof Rect)) {
+ return false;
+ }
+ Rect rect = (Rect)obj;
+ return x == rect.getX() && y == rect.getY() && width == rect.getWidth() && height == rect.getHeight();
+ }
+
+ @Override
+ public String toString() {
+ return "(" + x + ", " + y + ", " + width + ", " + height + ")";
+ }
+
+ /**
+ * Returns <code>true</code> if the point specified by the arguments is
+ * inside the area specified by the receiver, and <code>false</code> otherwise.
+ *
+ * @param x
+ * the x coordinate of the point to test for containment
+ * @param y
+ * the y coordinate of the point to test for containment
+ * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise
+ */
+ public boolean contains(double x, double y) {
+ return (x >= this.x) && (y >= this.y) && x < (this.x + width) && y < (this.y + height);
+ }
+
+ /**
+ * Returns <code>true</code> if the given point is inside the area specified
+ * by the receiver, and <code>false</code> otherwise.
+ *
+ * @param pt
+ * the point to test for containment
+ * @return <code>true</code> if the rectangle contains the point and <code>false</code> otherwise
+ *
+ * @exception IllegalArgumentException
+ * <ul>
+ * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
+ * </ul>
+ */
+ public boolean contains(Point pt) {
+ return contains(pt.getX(), pt.getY());
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CanExecuteChangedListener.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CanExecuteChangedListener.java
new file mode 100644
index 00000000000..036d5174ac1
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CanExecuteChangedListener.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+import java.beans.PropertyChangeListener;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface CanExecuteChangedListener extends PropertyChangeListener {
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CommandBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CommandBinding.java
new file mode 100644
index 00000000000..43dd85e1dea
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/CommandBinding.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeSupport;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class CommandBinding {
+
+ protected PropertyChangeSupport canExecuteSupport = new PropertyChangeSupport(this);
+
+ protected PropertyChangeSupport executeSupport = new PropertyChangeSupport(this);
+
+ protected ICommand command;
+
+ public ICommand getCommand() {
+ return command;
+ }
+
+ public CommandBinding() {
+ }
+
+ public CommandBinding(ICommand command) {
+ this.command = command;
+ }
+
+ public void setCommand(ICommand command) {
+ this.command = command;
+ }
+
+ public void addCanExecuteChangedListener(CanExecuteChangedListener listener) {
+ canExecuteSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removeCanExecuteChangedListener(CanExecuteChangedListener listener) {
+ canExecuteSupport.removePropertyChangeListener(listener);
+ }
+
+ public void fireCanExecuteChangedListener(PropertyChangeEvent args) {
+ canExecuteSupport.firePropertyChange(args);
+ }
+
+ public void addExecuteChangedListener(CanExecuteChangedListener listener) {
+ canExecuteSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removeExecuteChangedListener(CanExecuteChangedListener listener) {
+ canExecuteSupport.removePropertyChangeListener(listener);
+ }
+
+ public void fireExecuteChangedListener(PropertyChangeEvent args) {
+ canExecuteSupport.firePropertyChange(args);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ICommand.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ICommand.java
new file mode 100644
index 00000000000..ef7e905f582
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ICommand.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public interface ICommand {
+
+ boolean canExecute();
+
+ void execute(Object parameter);
+
+ void addCanExecuteChangedListener(CanExecuteChangedListener listener);
+
+ void removeCanExecuteChangedListener(CanExecuteChangedListener listener);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/InputBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/InputBinding.java
new file mode 100644
index 00000000000..98f5fa81592
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/InputBinding.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class InputBinding {
+
+ protected KeyGesture gesture;
+
+ protected Object commandTarget;
+
+ protected Object commandParameter;
+
+ protected ICommand command;
+
+ public Object getCommandTarget() {
+ return commandTarget;
+ }
+
+ public void setCommandTarget(Object commandTarget) {
+ this.commandTarget = commandTarget;
+ }
+
+ public Object getCommandParameter() {
+ return commandParameter;
+ }
+
+ public void setCommandParameter(Object commandParameter) {
+ this.commandParameter = commandParameter;
+ }
+
+ public ICommand getCommand() {
+ return command;
+ }
+
+ public void setCommand(ICommand command) {
+ this.command = command;
+ }
+
+ public KeyGesture getGesture() {
+ return gesture;
+ }
+
+ public void setGesture(KeyGesture gesture) {
+ this.gesture = gesture;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyBinding.java
new file mode 100644
index 00000000000..4a0cbf26ee4
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyBinding.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class KeyBinding extends InputBinding {
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyGesture.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyGesture.java
new file mode 100644
index 00000000000..3393500d72b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/KeyGesture.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class KeyGesture {
+
+ protected String key;
+
+ protected String displayString;
+
+ protected ModifierKeys modifiers;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getDisplayString() {
+ return displayString;
+ }
+
+ public void setDisplayString(String displayString) {
+ this.displayString = displayString;
+ }
+
+ public ModifierKeys getModifiers() {
+ return modifiers;
+ }
+
+ public void setModifiers(ModifierKeys modifiers) {
+ this.modifiers = modifiers;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ModifierKeys.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ModifierKeys.java
new file mode 100644
index 00000000000..7e221b9645c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/ModifierKeys.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public enum ModifierKeys {
+ None, Alt, Control, Shift, Windows;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/MouseAction.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/MouseAction.java
new file mode 100644
index 00000000000..ab9695580a4
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/MouseAction.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public enum MouseAction {
+ None, LeftClick, RightClick, MiddleClick, WheelClick, LeftDoubleClick, RightDoubleClick, MiddleDoubleClick;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/RoutedCommand.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/RoutedCommand.java
new file mode 100644
index 00000000000..92d52665286
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/input/RoutedCommand.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.input;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeSupport;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class RoutedCommand implements ICommand {
+
+ protected PropertyChangeSupport canExecuteSupport = new PropertyChangeSupport(this);
+
+ public boolean canExecute() {
+ return true;
+ }
+
+ public void execute(Object parameter) {
+ }
+
+ public void addCanExecuteChangedListener(CanExecuteChangedListener listener) {
+ canExecuteSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removeCanExecuteChangedListener(CanExecuteChangedListener listener) {
+ canExecuteSupport.removePropertyChangeListener(listener);
+ }
+
+ public void fireCanExecuteChangedListener(PropertyChangeEvent args) {
+ canExecuteSupport.firePropertyChange(args);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/Activator.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/Activator.java
new file mode 100644
index 00000000000..16d5497f646
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/Activator.java
@@ -0,0 +1,33 @@
+package org.eclipse.papyrus.xwt.internal;
+
+import org.eclipse.papyrus.xwt.IXWTInitializer;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.XWT;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator, IXWTInitializer {
+
+ private boolean initialized;
+
+ public void start(BundleContext context) throws Exception {
+ initialized = false;
+ XWT.addInitializer(this);
+ XWT.runOnUIThread(new Runnable() {
+
+ public void run() {
+ }
+ });
+ }
+
+ public void initialize(IXWTLoader loader) {
+ initialized = true;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Binding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Binding.java
new file mode 100644
index 00000000000..fcfd5b3c162
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Binding.java
@@ -0,0 +1,310 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.internal.core;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IValidationRule;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.core.IDynamicBinding;
+import org.eclipse.papyrus.xwt.databinding.ControlDataBinding;
+import org.eclipse.papyrus.xwt.databinding.DataBinding;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * Generic Binding definition
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class Binding extends DynamicBinding {
+
+ public static Binding[] EMPTY_ARRAY = new Binding[0];
+
+ private String path;
+
+ private Object source;
+
+ private String elementName;
+
+ private IValueConverter converter;
+
+ private IValidationRule[] validationRules = IValidationRule.EMPTY_ARRAY;
+
+ private IObservable observableSource;
+
+ public Binding() {
+ super();
+ }
+
+ /**
+ * <p>
+ * Default
+ * </p>
+ *
+ */
+ private UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default;
+
+ private BindingExpressionPath pathSegments;
+
+ public BindingExpressionPath getPathPropertySegments() {
+ if(pathSegments == null) {
+ pathSegments = new BindingExpressionPath(getPath());
+ }
+ return pathSegments;
+ }
+
+ public UpdateSourceTrigger getUpdateSourceTrigger() {
+ return updateSourceTrigger;
+ }
+
+ public void setUpdateSourceTrigger(UpdateSourceTrigger updateSourceTrigger) {
+ this.updateSourceTrigger = updateSourceTrigger;
+ }
+
+ public IValueConverter getConverter() {
+ return converter;
+ }
+
+ public void setConverter(IValueConverter converter) {
+ this.converter = converter;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public void setSource(Object source) {
+ this.source = source;
+ if(this.source instanceof IObservable) {
+ this.observableSource = (IObservable)this.source;
+ }
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getElementName() {
+ return elementName;
+ }
+
+ public void setElementName(String elementName) {
+ this.elementName = elementName;
+ }
+
+ protected Object getSourceObject() {
+ if(source != null) {
+ return source;
+ } else if(elementName != null) {
+ return XWT.findElementByName(getControl(), elementName);
+ }
+ return null;
+ }
+
+ protected boolean isSelfBinding(Object data) {
+ if(data != this) {
+ return false;
+ }
+ Binding binding = (Binding)data;
+ return BindingExpressionPath.isEmptyPath(binding.getPath());
+ }
+
+ public Object createBoundSource() {
+ Object control = getControl();
+ Object source = getSourceObject();
+ if(source == null) {
+ source = XWT.getDataContext(control, IDynamicBinding.class);
+ Object localDataContext = UserData.getLocalDataContext(control);
+ if(localDataContext == this) {
+ return source;
+ }
+ }
+ if(source instanceof IDynamicBinding) {
+ Object value = ((IDynamicBinding)source).createBoundSource();
+ if(value != null && path != null) {
+ Widget widget = UserData.getWidget(value);
+ if(widget == null) {
+ widget = UserData.getWidget(control);
+ }
+ return ScopeManager.observeValue(widget, value, getPathPropertySegments(), getUpdateSourceTrigger());
+ }
+ }
+ if(source != null && !BindingExpressionPath.isEmptyPath(path)) {
+ Widget widget = UserData.getWidget(source);
+ if(widget == null) {
+ widget = UserData.getWidget(control);
+ }
+ return ScopeManager.observeValue(widget, source, getPathPropertySegments(), getUpdateSourceTrigger());
+ }
+ return source;
+ }
+
+ public boolean isSourceControl() {
+ Object source = getSourceObject();
+ if(source == null) {
+ Object dataContextHost = getDataContextHost();
+ if(dataContextHost != null) {
+ source = UserData.getLocalDataContext(dataContextHost);
+ }
+ }
+
+ if(source instanceof IDynamicBinding) {
+ return ((IDynamicBinding)source).isSourceControl();
+ }
+ if(source instanceof IBinding) {
+ source = ((IBinding)source).getValue(null);
+ }
+
+ if(path == null) {
+ return false;
+ }
+
+ int index = BindingExpressionPath.lastIndexOf(path);
+ if(index == -1) {
+ return (source instanceof Control || source instanceof Viewer);
+ }
+
+ if(source instanceof IDataProvider) {
+ return false;
+ }
+ String parentPath = path.substring(0, index);
+ IObservable observable = ScopeManager.observeValue(getControl(), source, parentPath, getUpdateSourceTrigger());
+ if(observable != null) {
+ IObservableValue observableValue = (IObservableValue)observable;
+ Object type = observableValue.getValueType();
+ if(type != null) {
+ return UserData.isUIElementType(type);
+ }
+ }
+ return false;
+ }
+
+ public Object getValue(Class<?> targetType) {
+ Object dataContext = getSourceObject();
+ if(dataContext == null) {
+ Object dataContextHost = getDataContextHost();
+ if(dataContextHost != null) {
+ dataContext = UserData.getLocalDataContext(dataContextHost);
+ if(dataContext instanceof IDynamicBinding) {
+ IDynamicBinding dynamicBinding = (IDynamicBinding)dataContext;
+ Object boundSource = dynamicBinding.createBoundSource();
+ if(boundSource != null) {
+ dataContext = boundSource;
+ }
+ }
+ }
+ }
+
+ // direct binding
+ if(dataContext instanceof IBinding) {
+ dataContext = ((IBinding)dataContext).getValue(null);
+ }
+
+ IDataProvider dataProvider = getDataProvider(dataContext);
+
+ try {
+ if(isSourceControl()) {
+ ControlDataBinding controlDataBinding = new ControlDataBinding(dataContext, this, dataProvider);
+ return controlDataBinding.getValue(targetType);
+ }
+ } catch (XWTException e) {
+ // in case the property cannot be bound. return value
+ }
+
+ DataBinding dataBinding = null;
+ if(dataProvider != null && (path != null || dataContext instanceof IObservable)) {
+ dataBinding = new DataBinding(this, dataProvider);
+ }
+ if(dataBinding != null) {
+ return dataBinding.getValue(targetType);
+ }
+ return convertedValue(dataContext);
+ }
+
+ private Object convertedValue(Object value) {
+ IValueConverter converter = getConverter();
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ return value;
+ }
+
+ public boolean isSourcePropertyReadOnly() {
+ IDataProvider dataProvider = getDataProvider();
+ try {
+ return ScopeManager.isPropertyReadOnly(dataProvider, getPathPropertySegments());
+ } catch (XWTException e) {
+ }
+ return false;
+ }
+
+ public IObservable getObservableSource() {
+ return observableSource;
+ }
+
+ public void setObservableSource(IObservable observableSource) {
+ this.observableSource = observableSource;
+ }
+
+ /**
+ * Returns the validationRules for the binding
+ *
+ * @return the array of validationRules
+ */
+ public IValidationRule[] getValidationRules() {
+ return this.validationRules;
+ }
+
+ /**
+ * Sets a single validationRule
+ *
+ * @param validator
+ */
+ public IValidationRule getValidationRule() {
+ if(this.validationRules != null && this.validationRules.length > 0) {
+ return this.validationRules[0];
+ }
+ return null;
+ }
+
+ /**
+ * Set the validationRules for the binding
+ *
+ * @param validators
+ */
+ public void setValidationRules(IValidationRule[] validationRules) {
+ this.validationRules = validationRules;
+ }
+
+ /**
+ * Sets a single validationRule
+ *
+ * @param validator
+ */
+ public void setValidationRule(IValidationRule validationRule) {
+ this.validationRules = new IValidationRule[]{ validationRule };
+ }
+
+ public void reset() {
+ observableSource = null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingExpressionPath.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingExpressionPath.java
new file mode 100644
index 00000000000..975ce2bd512
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingExpressionPath.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.internal.core;
+
+import java.util.ArrayList;
+import java.util.Stack;
+
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.metadata.ModelUtils;
+
+public class BindingExpressionPath {
+
+ protected String fullPath;
+
+ protected String stripedPath;
+
+ protected String[] segments;
+
+ public BindingExpressionPath(String value) {
+ if(value == null) {
+ return;
+ }
+ this.fullPath = value;
+ this.stripedPath = null;
+
+ int level = 0;
+ Stack<Character> separators = new Stack<Character>();
+ ArrayList<String> collector = new ArrayList<String>();
+ int start = 0;
+ int stripStart = 0;
+ int stripEnd = 0;
+ char[] array = value.toCharArray();
+ for(int i = 0; i < array.length; i++) {
+ switch(array[i]) {
+ case '}':
+ {
+ Character character = separators.pop();
+ if(character.charValue() != '{') {
+ throw new XWTException("Syntax error is binding expression " + value + " at " + i);
+ }
+ }
+ level--;
+ break;
+ case ']':
+ {
+ Character character = separators.pop();
+ if(character.charValue() != '[') {
+ throw new XWTException("Syntax error is binding expression " + value + " at " + i);
+ }
+ }
+ level--;
+ break;
+ case ')':
+ {
+ Character character = separators.pop();
+ if(character.charValue() != '(') {
+ throw new XWTException("Syntax error is binding expression " + value + " at " + i);
+ }
+ }
+ level--;
+ if(level == 0) {
+ stripEnd = i - 1;
+ }
+ break;
+ case '(':
+ if(level == 0) {
+ stripStart = i + 1;
+ }
+ separators.push(array[i]);
+ level++;
+ break;
+ case '{':
+ case '[':
+ separators.push(array[i]);
+ level++;
+ break;
+ case '.':
+ if(level == 0) {
+ String element = value.substring(start, i);
+ element = ModelUtils.normalizePropertyName(element);
+ collector.add(element);
+ updateStripped(value, stripStart, stripEnd, element);
+ start = i + 1;
+ }
+ break;
+ }
+ }
+ if(level == 0) {
+ String element = value.substring(start, array.length);
+ element = ModelUtils.normalizePropertyName(element);
+ collector.add(element);
+
+ updateStripped(value, stripStart, stripEnd, element);
+ }
+
+ segments = collector.toArray(new String[collector.size()]);
+ }
+
+ private void updateStripped(String value, int stripStart, int stripEnd, String element) {
+ if(stripStart != 0) {
+ element = value.substring(stripStart, stripEnd + 1);
+ int index = element.lastIndexOf('.');
+ if(index != -1) {
+ element = element.substring(index + 1);
+ }
+ element = ModelUtils.normalizePropertyName(element);
+ }
+
+ if(this.stripedPath == null) {
+ this.stripedPath = element;
+ } else {
+ this.stripedPath += "." + element;
+ }
+ }
+
+ public String getFullPath() {
+ return fullPath;
+ }
+
+ public String getStripedPath() {
+ return stripedPath;
+ }
+
+ public String[] getSegments() {
+ return segments;
+ }
+
+ public boolean isEmptyPath() {
+ return isEmptyPath(getFullPath());
+ }
+
+ public static boolean isEmptyPath(String value) {
+ return value == null || value.trim().length() == 0 || ".".equals(value.trim());
+ }
+
+ public static int lastIndexOf(String value) {
+ int level = 0;
+ Stack<Character> separators = new Stack<Character>();
+ char[] array = value.toCharArray();
+ for(int i = array.length - 1; i >= 0; i--) {
+ switch(array[i]) {
+ case '{':
+ {
+ Character character = separators.pop();
+ if(character.charValue() != '}') {
+ throw new XWTException("Syntax error is binding expression " + value + " at " + i);
+ }
+ }
+ level--;
+ break;
+ case '[':
+ {
+ Character character = separators.pop();
+ if(character.charValue() != '}') {
+ throw new XWTException("Syntax error is binding expression " + value + " at " + i);
+ }
+ }
+ level--;
+ break;
+ case '(':
+ {
+ Character character = separators.pop();
+ if(character.charValue() != ')') {
+ throw new XWTException("Syntax error is binding expression " + value + " at " + i);
+ }
+ }
+ level--;
+ break;
+ case '}':
+ case ']':
+ case ')':
+ separators.push(array[i]);
+ level++;
+ break;
+ case '.':
+ if(level == 0) {
+ return i;
+ }
+ break;
+ }
+
+ if(array[i] == '.') {
+ }
+ }
+ return -1;
+ }
+
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingGate.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingGate.java
new file mode 100644
index 00000000000..b5ff8b15466
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/BindingGate.java
@@ -0,0 +1,406 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.internal.core;
+
+import org.eclipse.core.databinding.Binding;
+import org.eclipse.core.databinding.UpdateListStrategy;
+import org.eclipse.core.databinding.UpdateSetStrategy;
+import org.eclipse.core.databinding.UpdateValueStrategy;
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.IDataBindingInfo;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IValidationRule;
+import org.eclipse.papyrus.xwt.IValueConverter;
+import org.eclipse.papyrus.xwt.InverseValueConverter;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.validation.InverseValidationRule;
+
+/**
+ * @author jliu <jin.liu@soyatec.com>
+ */
+public class BindingGate {
+
+ public static final UpdateSetStrategy POLICY_UPDATE = new UpdateSetStrategy(UpdateSetStrategy.POLICY_UPDATE);
+
+ private final IBindingContext dataBindingContext;
+
+ public BindingGate(IBindingContext dataBindingContext) {
+ super();
+ this.dataBindingContext = dataBindingContext;
+ }
+
+ public Binding bind(IObservableValue source, IObservableValue target) {
+ return bind(source, target, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.databinding.IBindingContext#bind(org.eclipse.core.
+ * databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ public Binding bind(IObservable source, IObservable target, IDataBindingInfo dataBinding) {
+ if(source instanceof IObservableValue && target instanceof IObservableValue) {
+ return bindValue((IObservableValue)source, (IObservableValue)target, dataBinding);
+ } else if(source instanceof IObservableSet && target instanceof IObservableSet) {
+ IValueConverter converter = null;
+ int sourceToTargetPolicy = UpdateSetStrategy.POLICY_UPDATE;
+ int targetToSourcePolicy = UpdateSetStrategy.POLICY_UPDATE;
+ // Set policy to UpdateValueStrategy.
+ if(dataBinding != null) {
+ switch(dataBinding.getMode()) {
+ case OneWay:
+ targetToSourcePolicy = UpdateSetStrategy.POLICY_NEVER;
+ break;
+ case OneTime:
+ sourceToTargetPolicy = UpdateSetStrategy.POLICY_NEVER;
+ targetToSourcePolicy = UpdateSetStrategy.POLICY_NEVER;
+ break;
+ default:
+ break;
+ }
+ converter = dataBinding.getConverter();
+ }
+ UpdateSetStrategy sourceToTarget = new UpdateSetStrategy(sourceToTargetPolicy);
+ UpdateSetStrategy targetToSource = new UpdateSetStrategy(targetToSourcePolicy);
+ return bindSet((IObservableSet)target, (IObservableSet)source, targetToSource, sourceToTarget, converter);
+ } else if(source instanceof IObservableList && target instanceof IObservableList) {
+ IValueConverter converter = null;
+ int sourceToTargetPolicy = UpdateListStrategy.POLICY_UPDATE;
+ int targetToSourcePolicy = UpdateListStrategy.POLICY_UPDATE;
+ // Set policy to UpdateValueStrategy.
+ if(dataBinding != null) {
+ switch(dataBinding.getMode()) {
+ case OneWay:
+ targetToSourcePolicy = UpdateListStrategy.POLICY_NEVER;
+ break;
+ case OneTime:
+ sourceToTargetPolicy = UpdateListStrategy.POLICY_NEVER;
+ targetToSourcePolicy = UpdateListStrategy.POLICY_NEVER;
+ break;
+ default:
+ break;
+ }
+ converter = dataBinding.getConverter();
+ }
+ UpdateListStrategy sourceToTarget = new UpdateListStrategy(sourceToTargetPolicy);
+ UpdateListStrategy targetToSource = new UpdateListStrategy(targetToSourcePolicy);
+ return bindList((IObservableList)target, (IObservableList)source, targetToSource, sourceToTarget, converter);
+ }
+ throw new IllegalStateException();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.databinding.IBindingContext#bind(org.eclipse.core.
+ * databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ public Binding bindList(IObservableList source, IObservableList target, UpdateListStrategy sourceToTarget, UpdateListStrategy targetToSource, IValueConverter converter) {
+ if(converter != null) {
+ return bindList(source, target, sourceToTarget, targetToSource, converter, new InverseValueConverter(converter));
+ } else {
+ return bindList(source, target, sourceToTarget, targetToSource, null, null);
+ }
+ }
+
+ /**
+ *
+ * @param source
+ * @param target
+ * @param sourceToTarget
+ * if it is null, the default converter will be update policy
+ * @param targetToSource
+ * if it is null, the default converter will be update policy
+ * @param sourceToTargetConvertor
+ * if it is null, the default converter will be used
+ * @param targetToSourceConvertor
+ * if it is null, the default converter will be used
+ */
+ public Binding bindList(IObservableList source, IObservableList target, UpdateListStrategy sourceToTarget, UpdateListStrategy targetToSource, IConverter sourceToTargetConvertor, IConverter targetToSourceConvertor) {
+ if(source != null && target != null) {
+ if(sourceToTarget == null) {
+ sourceToTarget = new UpdateListStrategy(UpdateListStrategy.POLICY_UPDATE);
+ }
+ if(targetToSource == null) {
+ targetToSource = new UpdateListStrategy(UpdateListStrategy.POLICY_UPDATE);
+ }
+
+ if(sourceToTargetConvertor != null) {
+ sourceToTarget.setConverter(sourceToTargetConvertor);
+ }
+
+ if(targetToSourceConvertor != null) {
+ targetToSource.setConverter(targetToSourceConvertor);
+ }
+
+ this.dataBindingContext.bindList(target, source, targetToSource, sourceToTarget);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.databinding.IBindingContext#bind(org.eclipse.core.
+ * databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ public Binding bindSet(IObservableSet source, IObservableSet target, UpdateSetStrategy sourceToTarget, UpdateSetStrategy targetToSource, IValueConverter converter) {
+ if(converter != null) {
+ return bindSet(source, target, sourceToTarget, targetToSource, converter, new InverseValueConverter(converter));
+ } else {
+ return bindSet(source, target, sourceToTarget, targetToSource, null, null);
+ }
+ }
+
+ /**
+ *
+ * @param source
+ * @param target
+ * @param sourceToTarget
+ * if it is null, the default converter will be update policy
+ * @param targetToSource
+ * if it is null, the default converter will be update policy
+ * @param sourceToTargetConvertor
+ * if it is null, the default converter will be used
+ * @param targetToSourceConvertor
+ * if it is null, the default converter will be used
+ */
+ public Binding bindSet(IObservableSet source, IObservableSet target, UpdateSetStrategy sourceToTarget, UpdateSetStrategy targetToSource, IConverter sourceToTargetConvertor, IConverter targetToSourceConvertor) {
+ if(source != null && target != null) {
+ if(sourceToTarget == null) {
+ sourceToTarget = new UpdateSetStrategy(UpdateSetStrategy.POLICY_UPDATE);
+ }
+ if(targetToSource == null) {
+ targetToSource = new UpdateSetStrategy(UpdateSetStrategy.POLICY_UPDATE);
+ }
+
+ if(sourceToTargetConvertor != null) {
+ sourceToTarget.setConverter(sourceToTargetConvertor);
+ }
+
+ if(targetToSourceConvertor != null) {
+ targetToSource.setConverter(targetToSourceConvertor);
+ }
+
+ this.dataBindingContext.bindSet(target, source, targetToSource, sourceToTarget);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param source
+ * @param target
+ * @param sourceToTarget
+ * if it is null, the default converter will be update policy
+ * @param targetToSource
+ * if it is null, the default converter will be update policy
+ * @param sourceToTargetConvertor
+ * if it is null, the default converter will be used
+ * @param targetToSourceConvertor
+ * if it is null, the default converter will be used
+ */
+ public Binding bind(IObservableList source, IObservableList target, UpdateListStrategy sourceToTarget, UpdateListStrategy targetToSource, IConverter sourceToTargetConvertor, IConverter targetToSourceConvertor) {
+ if(source != null && target != null) {
+ if(sourceToTarget == null) {
+ sourceToTarget = new UpdateListStrategy(UpdateListStrategy.POLICY_UPDATE);
+ }
+ if(targetToSource == null) {
+ targetToSource = new UpdateListStrategy(UpdateListStrategy.POLICY_UPDATE);
+ }
+
+ if(sourceToTargetConvertor != null) {
+ sourceToTarget.setConverter(sourceToTargetConvertor);
+ }
+
+ if(targetToSourceConvertor != null) {
+ targetToSource.setConverter(targetToSourceConvertor);
+ }
+
+ this.dataBindingContext.bindList(target, source, targetToSource, sourceToTarget);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.databinding.IBindingContext#bind(org.eclipse.core.
+ * databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ private Binding bindValue(IObservableValue source, IObservableValue target, IDataBindingInfo dataBinding) {
+ IValueConverter converter = null;
+ IValidationRule[] validators = null;
+ int sourceToTargetPolicy = UpdateValueStrategy.POLICY_UPDATE;
+ int targetToSourcePolicy = UpdateValueStrategy.POLICY_UPDATE;
+ // Set policy to UpdateValueStrategy.
+ if(dataBinding != null) {
+ switch(dataBinding.getMode()) {
+ case OneWay:
+ targetToSourcePolicy = UpdateValueStrategy.POLICY_NEVER;
+ break;
+ case OneTime:
+ sourceToTargetPolicy = UpdateValueStrategy.POLICY_NEVER;
+ targetToSourcePolicy = UpdateValueStrategy.POLICY_NEVER;
+ break;
+ default:
+ break;
+ }
+ converter = dataBinding.getConverter();
+ validators = dataBinding.getValidators();
+ }
+ UpdateValueStrategy sourceToTarget = new UpdateValueStrategy(sourceToTargetPolicy);
+ UpdateValueStrategy targetToSource = new UpdateValueStrategy(targetToSourcePolicy);
+
+ bindValidators(validators, sourceToTarget, targetToSource);
+
+ return bind(source, target, sourceToTarget, targetToSource, converter);
+ }
+
+ private void bindValidators(IValidationRule[] validators, UpdateValueStrategy sourceToTarget, UpdateValueStrategy targetToSource) {
+ if(validators != null) {
+ for(IValidationRule validator : validators) {
+ switch(validator.getBindingMode()) {
+ case SourceToTarget:
+ addValidatorToStrategy(sourceToTarget, validator);
+ break;
+ case TargetToSource:
+ addValidatorToStrategy(targetToSource, new InverseValidationRule(validator));
+ break;
+ case Both:
+ default:
+ addValidatorToStrategy(sourceToTarget, validator);
+ addValidatorToStrategy(targetToSource, new InverseValidationRule(validator));
+ }
+ }
+ }
+ }
+
+ private void addValidatorToStrategy(UpdateValueStrategy strategy, IValidationRule validator) {
+ switch(validator.getPhase()) {
+ case AfterGet:
+ strategy.setAfterGetValidator(validator);
+ break;
+ case AfterConvert:
+ strategy.setAfterConvertValidator(validator);
+ break;
+ case BeforeSet:
+ default:
+ strategy.setBeforeSetValidator(validator);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.databinding.IBindingContext#bind(org.eclipse.core.
+ * databinding.observable.value.IObservableValue,
+ * org.eclipse.core.databinding.observable.value.IObservableValue)
+ */
+ public Binding bind(IObservableValue source, IObservableValue target, UpdateValueStrategy sourceToTarget, UpdateValueStrategy targetToSource, IValueConverter converter) {
+ if(converter != null) {
+ return bind(source, target, sourceToTarget, targetToSource, converter, new InverseValueConverter(converter));
+ } else {
+ return bind(source, target, sourceToTarget, targetToSource, null, null);
+ }
+ }
+
+ /**
+ *
+ * @param source
+ * @param target
+ * @param sourceToTarget
+ * if it is null, the default converter will be update policy
+ * @param targetToSource
+ * if it is null, the default converter will be update policy
+ * @param sourceToTargetConvertor
+ * if it is null, the default converter will be used
+ * @param targetToSourceConvertor
+ * if it is null, the default converter will be used
+ */
+ public Binding bind(IObservableValue source, IObservableValue target, UpdateValueStrategy sourceToTarget, UpdateValueStrategy targetToSource, IConverter sourceToTargetConvertor, IConverter targetToSourceConvertor) {
+ if(source != null && target != null) {
+ if(sourceToTarget == null) {
+ sourceToTarget = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
+ }
+ if(targetToSource == null) {
+ targetToSource = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
+ }
+
+ // Add converter to UpdateValueStrategy.
+ IDataProvider sourceDataProvider = XWT.findDataProvider(source);
+ Object sourceValueType = sourceDataProvider.getDataType(null);
+ if(sourceValueType == null) {
+ sourceValueType = Object.class;
+ }
+ IDataProvider targetDataProvider = XWT.findDataProvider(target);
+ Object targetValueType = targetDataProvider.getDataType(null);
+ if(targetValueType == null) {
+ targetValueType = Object.class;
+ }
+ Class<?> sourceType = (sourceValueType instanceof Class<?>) ? (Class<?>)sourceValueType : sourceValueType.getClass();
+ Class<?> targetType = (targetValueType instanceof Class<?>) ? (Class<?>)targetValueType : targetValueType.getClass();
+ if(sourceType == null) {
+ sourceType = Object.class;
+ } else {
+ sourceType = ObjectUtil.normalizedType(sourceType);
+ }
+
+ if(targetType == null) {
+ targetType = Object.class;
+ } else {
+ targetType = ObjectUtil.normalizedType(targetType);
+ }
+
+ if(sourceToTarget.getUpdatePolicy() != UpdateValueStrategy.POLICY_NEVER) {
+ if(sourceToTargetConvertor != null) {
+ sourceToTarget.setConverter(sourceToTargetConvertor);
+ } else if(!targetType.isAssignableFrom(sourceType)) {
+ IConverter m2t = XWT.findConvertor(sourceType, targetType);
+ if(m2t != null) {
+ sourceToTarget.setConverter(m2t);
+ }
+ }
+ }
+
+ if(targetToSource.getUpdatePolicy() != UpdateValueStrategy.POLICY_NEVER) {
+ if(targetToSourceConvertor != null) {
+ targetToSource.setConverter(targetToSourceConvertor);
+ } else if(!sourceType.isAssignableFrom(targetType)) {
+ IConverter t2m = XWT.findConvertor(targetType, sourceType);
+ if(t2m != null) {
+ targetToSource.setConverter(t2m);
+ }
+ }
+ }
+
+ this.dataBindingContext.bindValue(target, source, targetToSource, sourceToTarget);
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Core.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Core.java
new file mode 100644
index 00000000000..9873fb8cbb1
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/Core.java
@@ -0,0 +1,917 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Soyatec - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.internal.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.DefaultLoadingContext;
+import org.eclipse.papyrus.xwt.ICLRFactory;
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IDataProviderFactory;
+import org.eclipse.papyrus.xwt.ILoadingContext;
+import org.eclip