Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-04-10 15:35:21 +0000
committercletavernie2012-04-10 15:35:21 +0000
commit18b0ff7c9e903b9dcdbfab25d217941cdd4dd1cd (patch)
tree52571d5d7a291862368aba54543b3cf417f69f73 /plugins/xwt/org.eclipse.papyrus.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/org.eclipse.papyrus.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.eclipse.papyrus.xwt.ILogger;
+import org.eclipse.papyrus.xwt.IMetaclassFactory;
+import org.eclipse.papyrus.xwt.INamespaceHandler;
+import org.eclipse.papyrus.xwt.IStyle;
+import org.eclipse.papyrus.xwt.IUIResource;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.Tracking;
+import org.eclipse.papyrus.xwt.callback.IBeforeParsingCallback;
+import org.eclipse.papyrus.xwt.converters.ObjectToObject;
+import org.eclipse.papyrus.xwt.converters.StringToEnum;
+import org.eclipse.papyrus.xwt.core.IElementLoaderFactory;
+import org.eclipse.papyrus.xwt.core.IRenderingContext;
+import org.eclipse.papyrus.xwt.core.IVisualElementLoader;
+import org.eclipse.papyrus.xwt.dataproviders.ObjectDataProvider;
+import org.eclipse.papyrus.xwt.input.ICommand;
+import org.eclipse.papyrus.xwt.internal.xml.Attribute;
+import org.eclipse.papyrus.xwt.internal.xml.DocumentObject;
+import org.eclipse.papyrus.xwt.internal.xml.DocumentRoot;
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+import org.eclipse.papyrus.xwt.internal.xml.ElementManager;
+import org.eclipse.papyrus.xwt.javabean.ValueConvertorRegister;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class Core {
+
+ static public final Object[] EMPTY_ARRAY = new Object[0];
+
+ public static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ static public final String DEFAULT_STYLES_KEY = "XWT.DefaultStyles";
+
+ static public boolean TRACE_BENCH = false;
+
+ private HashMap<Class<?>, Object> registrations;
+
+ private HashMap<DocumentObject, IVisualElementLoader> elementsLoaders = new HashMap<DocumentObject, IVisualElementLoader>();
+
+ private MetaclassService metaclassService;
+
+ private IElementLoaderFactory loaderFactory;
+
+ private ILoadingContext _loadingContext = null;
+
+ private ICLRFactory clrFactory = null;
+
+ private Set<Tracking> trackingSet = new HashSet<Tracking>();
+
+ private Map<String, ICommand> commands = new HashMap<String, ICommand>();
+
+ private Map<String, INamespaceHandler> nsHandlers = new HashMap<String, INamespaceHandler>();
+
+ private ILogger logger;
+
+ private Collection<IStyle> defaultStyles = new ArrayList<IStyle>();
+
+ private static LinkedHashMap<String, IDataProviderFactory> dataProviderFactories = new LinkedHashMap<String, IDataProviderFactory>();
+
+ private Collection<Class<?>> resolveTypes = new ArrayList<Class<?>>();
+
+ private IXWTLoader xwtLoader;
+
+ static public ILogger nullLog = new ILogger() {
+
+ private Map<Tracking, String> messageMap = new HashMap<Tracking, String>();
+
+ public void error(Throwable e) {
+ }
+
+ public void error(Throwable e, String message) {
+ }
+
+ public void message(String message) {
+ }
+
+ public void warning(String message) {
+ }
+
+ public void printInfo(String message, Tracking tracking, Set<Tracking> trackType) {
+ String printMessage = "";
+
+ if(trackType != null && trackType.size() > 0) {
+ if(trackType.contains(tracking)) {
+ printMessage = messageMap.get(tracking);
+ }
+ }
+ System.out.println(printMessage);
+ }
+
+ public void addMessage(String message, Tracking tracking) {
+ if(messageMap.containsKey(tracking)) {
+ messageMap.remove(tracking);
+ }
+ messageMap.put(tracking, message);
+ }
+
+ public void removeMessage(Tracking tracking) {
+ if(messageMap.containsKey(tracking)) {
+ messageMap.remove(tracking);
+ }
+ }
+ };
+
+ public Core(IElementLoaderFactory loaderFactory, IXWTLoader xwtLoader) {
+ this.loaderFactory = loaderFactory;
+ this.registrations = new HashMap<Class<?>, Object>();
+ this.xwtLoader = xwtLoader;
+ this.metaclassService = new MetaclassService(xwtLoader);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getLogger()
+ */
+ public ILogger getLogger() {
+ if(logger == null) {
+ return Core.nullLog;
+ }
+ return logger;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#setLogger(org.eclipse.papyrus.xwt.ILogger)
+ */
+ public void setLogger(ILogger log) {
+ logger = log;
+ }
+
+ public ICLRFactory getCLRFactory() {
+ return clrFactory;
+ }
+
+ public void setCLRFactory(ICLRFactory clrFactory) {
+ this.clrFactory = clrFactory;
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @param handler
+ */
+ public void registerNamespaceHandler(String nsmapace, INamespaceHandler handler) {
+ nsHandlers.put(nsmapace, handler);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ */
+ public void unregisterNamespaceHandler(String nsmapace) {
+ nsHandlers.remove(nsmapace);
+ }
+
+ /**
+ *
+ * @param nsmapace
+ * @return
+ */
+ public INamespaceHandler getNamespaceHandler(String nsmapace) {
+ return nsHandlers.get(nsmapace);
+ }
+
+ class ConverterService {
+
+ protected Map<Class<?>, IConverter> converters = new HashMap<Class<?>, IConverter>();
+
+ public IConverter getConverter(Class<?> type) {
+ IConverter converter = converters.get(type);
+ if(converter != null) {
+ return converter;
+ }
+
+ return null;
+ }
+
+ public void register(Class<?> type, IConverter converter) {
+ converters.put(type, converter);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#findConvertor(java.lang.Class,
+ * java.lang.Class)
+ */
+ public IConverter findConvertor(Class<?> source, Class<?> target) {
+ if(source == target || (source != Object.class && source.isAssignableFrom(target))) {
+ return ObjectToObject.instance;
+ }
+ if(String.class == source && target.isEnum()) {
+ return new StringToEnum(target);
+ }
+ ValueConvertorRegister convertorRegister = (ValueConvertorRegister)getService(ValueConvertorRegister.class);
+ if(convertorRegister == null) {
+ return null;
+ }
+ return convertorRegister.findConverter(source, target);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#registerConvertor(org.eclipse.core.databinding
+ * .conversion.IConverter)
+ */
+ public void registerConvertor(IConverter converter) {
+ Class<?> source = (Class<?>)converter.getFromType();
+ Class<?> target = (Class<?>)converter.getToType();
+ ValueConvertorRegister convertorRegister = (ValueConvertorRegister)getService(ValueConvertorRegister.class);
+ convertorRegister.register(source, target, converter);
+ }
+
+ public void registerConvertor(Class<?> converter, String methodName) {
+ try {
+ Method method = converter.getDeclaredMethod(methodName);
+ Object object = method.invoke(null);
+ if(object instanceof IConverter) {
+ registerConvertor((IConverter)object);
+ }
+ } catch (SecurityException e) {
+ } catch (IllegalArgumentException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ }
+
+ public void registerConvertor(Class<?> converterType, String methodName, boolean value) {
+ IConverter converter = loadConvertor(converterType, methodName, value);
+ if(converter != null) {
+ registerConvertor(converter);
+ }
+ }
+
+ public void registerConvertor(ValueConvertorRegister convertorRegister, Class<?> source, Class<?> target, Class<?> converterType, String methodName, boolean value) {
+ IConverter converter = loadConvertor(converterType, methodName, value);
+ if(converter != null) {
+ convertorRegister.register(source, target, converter);
+ }
+ }
+
+ public IConverter loadConvertor(Class<?> converter, String methodName, boolean value) {
+ try {
+ Method method = converter.getDeclaredMethod(methodName);
+ Object object = method.invoke(null, value);
+ if(object instanceof IConverter) {
+ return (IConverter)object;
+ }
+ } catch (SecurityException e) {
+ } catch (IllegalArgumentException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getConverterService()
+ */
+ public ConverterService getConverterService() {
+ ConverterService service = (ConverterService)getService(ConverterService.class);
+ if(service == null) {
+ service = new ConverterService();
+ registerService(ConverterService.class, service);
+ service.register(Object.class, new IConverter() {
+
+ public Object convert(Object fromObject) {
+ return null;
+ }
+
+ public Object getFromType() {
+ return Object.class;
+ }
+
+ public Object getToType() {
+ return String.class;
+ }
+ });
+ }
+ return service;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#addTracking(org.eclipse.papyrus.xwt.Tracking)
+ */
+ public void addTracking(Tracking tracking) {
+ if(!trackingSet.contains(tracking)) {
+ trackingSet.add(tracking);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#isTracking(org.eclipse.papyrus.xwt.Tracking)
+ */
+ public boolean isTracking(Tracking tracking) {
+ return trackingSet.contains(tracking);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getTrackings()
+ */
+ public Set<Tracking> getTrackings() {
+ return trackingSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeTracking(org.eclipse.papyrus.xwt.Tracking)
+ */
+ public void removeTracking(Tracking tracking) {
+ if(trackingSet.contains(tracking)) {
+ trackingSet.remove(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) {
+ commands.put(name, command);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getCommand(java.lang.String)
+ */
+ public ICommand getCommand(String name) {
+ return commands.get(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getCommands()
+ */
+ public Map<String, ICommand> getCommands() {
+ return commands;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#unregisterCommand(java.lang.String)
+ */
+ public void unregisterCommand(String name) {
+ commands.remove(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#addDefaultStyle(org.eclipse.papyrus.xwt.IStyle)
+ */
+ public void addDefaultStyle(IStyle style) {
+ defaultStyles.add(style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeDefaultStyle(org.eclipse.papyrus.xwt.IStyle
+ * )
+ */
+ public void removeDefaultStyle(IStyle style) {
+ defaultStyles.remove(style);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getDefaultStyles()
+ */
+ public Collection<IStyle> getDefaultStyles() {
+ return new ArrayList<IStyle>(defaultStyles);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#addDataProviderFactory(org.eclipse.papyrus.xwt
+ * .IDataProviderFactory)
+ */
+ public void addDataProviderFactory(String name, IDataProviderFactory dataProviderFactory) {
+ if(dataProviderFactory == null) {
+ return;
+ }
+ dataProviderFactories.put(name, dataProviderFactory);
+ registerMetaclass(dataProviderFactory.getType());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#registerMetaclass(java.lang.Class)
+ */
+ public IMetaclass registerMetaclass(Class<?> type) {
+ return registerMetaclass(type, IConstants.XWT_NAMESPACE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeDataProviderFactory(org.eclipse.e4
+ * .xwt.IDataProviderFactory)
+ */
+ public void removeDataProviderFactory(String name) {
+ if(name == null) {
+ return;
+ }
+ dataProviderFactories.remove(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.IXWTLoader#removeDataProviderFactory(org.eclipse.e4
+ * .xwt.IDataProviderFactory)
+ */
+ public void removeDataProviderFactory(IDataProviderFactory dataProviderFactory) {
+ if(dataProviderFactory == null) {
+ return;
+ }
+ for(String name : dataProviderFactories.keySet()) {
+ IDataProviderFactory value = dataProviderFactories.get(name);
+ if(dataProviderFactory == value) {
+ dataProviderFactories.remove(name);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getDataProviderFactories()
+ */
+ public Collection<IDataProviderFactory> getDataProviderFactories() {
+ return dataProviderFactories.values();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#findDataProvider(java.lang.Object)
+ */
+ public IDataProvider findDataProvider(Object dataContext) {
+ if(dataContext instanceof IDataProvider) {
+ return (IDataProvider)dataContext;
+ }
+ for(IDataProviderFactory factory : dataProviderFactories.values()) {
+ IDataProvider dataProvider = factory.create(dataContext);
+ if(dataProvider != null) {
+ return dataProvider;
+ }
+ }
+ ObjectDataProvider dataProvider = new ObjectDataProvider();
+ dataProvider.setObjectInstance(dataContext);
+ return dataProvider;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#getLoadingContext()
+ */
+ public ILoadingContext getLoadingContext() {
+ if(_loadingContext == null) {
+ return DefaultLoadingContext.defaultLoadingContext;
+ }
+ return _loadingContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.e4.xwt.IXWTLoader#setLoadingContext(org.eclipse.papyrus.xwt.
+ * ILoadingContext)
+ */
+ public void setLoadingContext(ILoadingContext loadingContext) {
+ _loadingContext = loadingContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IXWTLoader#findLoadingContext(java.lang.Object)
+ */
+ public ILoadingContext findLoadingContext(Object container) {
+ return getLoadingContext();
+ }
+
+ public IMetaclass getMetaclass(ILoadingContext context, String name, String namespace) {
+ return getMetaclassService().getMetaclass(context, name, namespace);
+ }
+
+ public IMetaclass findMetaclass(Object object) {
+ if(object instanceof Class<?>) {
+ return getMetaclassService().findMetaclass((Class<?>)object);
+ }
+ return getMetaclassService().findMetaclass(object.getClass());
+ }
+
+ public IMetaclass getMetaclass(Object object) {
+ if(object instanceof Class<?>) {
+ return getMetaclassService().getMetaclass((Class<?>)object);
+ }
+ return getMetaclassService().getMetaclass(object.getClass());
+ }
+
+ public IMetaclass getMetaclass(Object object, String namespace) {
+ if(object instanceof Class) {
+ return getMetaclassService().getMetaclass((Class<?>)object, namespace);
+ }
+ return getMetaclassService().getMetaclass(object.getClass(), namespace);
+ }
+
+ public Collection<IMetaclass> getAllMetaclasses(String namespace) {
+ return getMetaclassService().getAllMetaclasses(namespace);
+ }
+
+ public void registerMetaclass(IMetaclass metaclass, String namespace) {
+ getMetaclassService().register(metaclass, namespace);
+ }
+
+ public void registerMetaclassFactory(IMetaclassFactory metaclassFactory) {
+ getMetaclassService().registerFactory(metaclassFactory);
+ }
+
+ public IMetaclass registerMetaclass(Class<?> metaclass, String namespace) {
+ return getMetaclassService().register(metaclass, namespace);
+ }
+
+ public IMetaclass registerMetaclass(Class<?> metaclass, String namespace, IMetaclass superMetaclass) {
+ return getMetaclassService().register(metaclass, namespace, superMetaclass);
+ }
+
+ public void registerMetaclassManager(String namespace, MetaclassManager manager) {
+ getMetaclassService().register(namespace, manager);
+ }
+
+ public Object getService(Class<?> type) {
+ return this.registrations.get(type);
+ }
+
+ public void registerService(Class<?> serviceType, Object service) {
+ registrations.put(serviceType, service);
+ }
+
+ protected Object createCLRElement(IRenderingContext context, Element element, Map<String, Object> options) {
+ IVisualElementLoader loader = findElementLoader(element);
+ if(loader != null) {
+ return loader.createUIElement(element, options);
+ }
+ loader = createElementLoader(context, element);
+ Object visualObject = loader.createUIElement(element, options);
+ removeElementLoader(element);
+ return visualObject;
+ }
+
+ protected IVisualElementLoader findElementLoader(DocumentObject element) {
+ IVisualElementLoader loader = elementsLoaders.get(element);
+ if(loader != null) {
+ return loader;
+ }
+ if(element.getParent() != null) {
+ return findElementLoader(element.getParent());
+ }
+ return null;
+ }
+
+ protected IVisualElementLoader createElementLoader(IRenderingContext context, DocumentObject element) {
+ IVisualElementLoader creator = loaderFactory.createElementLoader(context, xwtLoader);
+ elementsLoaders.put(element, creator);
+ return creator;
+ }
+
+ protected void removeElementLoader(DocumentObject element) {
+ elementsLoaders.remove(element);
+ }
+
+ public Object load(ILoadingContext loadingContext, URL input, Map<String, Object> options) throws Exception {
+ return load(loadingContext, null, input, options);
+ }
+
+ public IUIResource loadAsResource(InputStream stream, URL input, IBeforeParsingCallback parsingCallback) throws Exception {
+ ElementManager manager = new ElementManager();
+ Element element = null;
+ if(stream == null) {
+ element = manager.load(input, parsingCallback);
+ } else {
+ InputStream inputStream = stream;
+ if(parsingCallback != null) {
+ int size = stream.read();
+ byte[] buffer = new byte[size];
+ stream.read(buffer);
+ String content = new String(buffer);
+ stream.close();
+ content = parsingCallback.onParsing(content);
+ inputStream = new ByteArrayInputStream(content.getBytes());
+ element = manager.load(stream, input);
+ }
+ element = manager.load(inputStream, input);
+ }
+ return new UIResource(input, element);
+ }
+
+ public Object load(ILoadingContext loadingContext, IUIResource pattern, Map<String, Object> options) throws Exception {
+ UIResource uiResource = (UIResource)pattern;
+ Control control = null;
+ ElementManager manager = new ElementManager(uiResource.getURL());
+ Element element = uiResource.getContent();
+ IRenderingContext context = new ExtensionContext(loadingContext, manager, element.getNamespace());
+ Object visual = createCLRElement(context, element, options);
+ if(visual instanceof Control) {
+ control = (Control)visual;
+ } else if(visual instanceof Viewer) {
+ control = ((Viewer)visual).getControl();
+ } else {
+ Class<?> jfaceWindow = Class.forName("org.eclipse.jface.window.Window");
+ if(jfaceWindow != null && jfaceWindow.isInstance(visual)) {
+ Method createMethod = jfaceWindow.getDeclaredMethod("create");
+ createMethod.invoke(visual);
+ Method method = jfaceWindow.getDeclaredMethod("getShell");
+ control = (Control)method.invoke(visual);
+ }
+ }
+
+ if(control instanceof Composite) {
+ Object parent = options.get(IXWTLoader.CONTAINER_PROPERTY);
+ Object designMode = options.get(IXWTLoader.DESIGN_MODE_PROPERTY);
+ if(parent instanceof Composite) {
+ Composite parentComposite = (Composite)parent;
+ if(parentComposite.getLayout() == null || designMode == Boolean.TRUE) {
+ autoLayout(parentComposite, element);
+ }
+ } else if(parent == null || designMode == Boolean.TRUE) {
+ if(control instanceof Shell) {
+ autoLayout(control, element);
+ } else {
+ autoLayout(control.getShell(), element);
+ }
+ }
+ }
+ return visual;
+ }
+
+ public Control load(ILoadingContext loadingContext, InputStream stream, URL input, Map<String, Object> options) throws Exception {
+ // Detect from url or file path.
+ long start = System.currentTimeMillis();
+ Control control = null;
+ ElementManager manager = new ElementManager();
+ if(input != null) {
+ Element element = null;
+ if(stream == null) {
+ element = manager.load(input, (IBeforeParsingCallback)options.get(IXWTLoader.BEFORE_PARSING_CALLBACK));
+ } else {
+ IBeforeParsingCallback callback = (IBeforeParsingCallback)options.get(IXWTLoader.BEFORE_PARSING_CALLBACK);
+ InputStream inputStream = stream;
+ if(callback != null) {
+ int size = stream.read();
+ byte[] buffer = new byte[size];
+ stream.read(buffer);
+ String content = new String(buffer);
+ stream.close();
+ content = callback.onParsing(content);
+ inputStream = new ByteArrayInputStream(content.getBytes());
+ element = manager.load(stream, input);
+ }
+ element = manager.load(inputStream, input);
+ }
+ IRenderingContext context = new ExtensionContext(loadingContext, manager, manager.getRootElement().getNamespace());
+ Object visual = createCLRElement(context, element, options);
+ if(TRACE_BENCH) {
+ System.out.println("Loaded: " + (System.currentTimeMillis() - start) + " " + input.toString());
+ }
+ if(visual instanceof Control) {
+ control = (Control)visual;
+ } else if(visual instanceof Viewer) {
+ control = ((Viewer)visual).getControl();
+ } else {
+ Class<?> jfaceWindow = Class.forName("org.eclipse.jface.window.Window");
+ if(jfaceWindow != null && jfaceWindow.isInstance(visual)) {
+ Method createMethod = jfaceWindow.getDeclaredMethod("create");
+ createMethod.invoke(visual);
+ Method method = jfaceWindow.getDeclaredMethod("getShell");
+ control = (Control)method.invoke(visual);
+ }
+ }
+
+ Object parent = options.get(IXWTLoader.CONTAINER_PROPERTY);
+ Object designMode = options.get(IXWTLoader.DESIGN_MODE_PROPERTY);
+ if(control instanceof Composite) {
+ if(parent instanceof Composite) {
+ Composite parentComposite = (Composite)parent;
+ if(parentComposite.getLayout() == null || designMode == Boolean.TRUE) {
+ autoLayout(parentComposite, element);
+ }
+ } else if(parent == null || designMode == Boolean.TRUE) {
+ if(control instanceof Shell) {
+ autoLayout(control, element);
+ } else {
+ autoLayoutShell(control, element);
+ }
+ }
+ } else if(control != null && (parent == null || designMode == Boolean.TRUE)) {
+ autoLayoutShell(control, element);
+ }
+ }
+ return control;
+ }
+
+ protected void autoLayout(Control composite, Element element) {
+ if(element == null) {
+ return;
+ }
+ Attribute bounds = element.getAttribute("Bounds");
+ if(bounds == null) {
+ bounds = element.getAttribute("Bounds", IConstants.XWT_NAMESPACE);
+ }
+ Attribute size = element.getAttribute("Size");
+ if(size == null) {
+ size = element.getAttribute("Size", IConstants.XWT_NAMESPACE);
+ }
+ if(bounds == null && size == null) {
+ composite.pack();
+ }
+ }
+
+ protected void autoLayoutShell(Control control, Element element) {
+ if(element == null) {
+ return;
+ }
+ Attribute bounds = element.getAttribute("Bounds");
+ if(bounds == null) {
+ bounds = element.getAttribute("Bounds", IConstants.XWT_NAMESPACE);
+ }
+ Attribute size = element.getAttribute("Size");
+ if(size == null) {
+ size = element.getAttribute("Size", IConstants.XWT_NAMESPACE);
+ }
+ if(bounds == null && size == null) {
+ control.pack();
+ } else {
+ Shell shell = control.getShell();
+ Point targetSize = control.getSize();
+ Rectangle rectangle = shell.getBounds();
+ Rectangle clientArea = shell.getClientArea();
+ targetSize.x += rectangle.width - clientArea.width;
+ targetSize.y += rectangle.height - clientArea.height;
+ shell.setSize(targetSize);
+ }
+ }
+
+ static private class ExtensionContext implements IRenderingContext {
+
+ private Map<String, Object> properties = new HashMap<String, Object>();
+
+ private URL resourcePath;
+
+ private DocumentRoot documentRoot;
+
+ private String namespace;
+
+ private String encoding;
+
+ protected ILoadingContext loadingContext;
+
+ public ExtensionContext(ILoadingContext loadingContext, ElementManager elementManager, String namespace) {
+ documentRoot = elementManager.getDocumentRoot();
+ resourcePath = documentRoot.getPath();
+ this.namespace = namespace;
+ this.loadingContext = loadingContext;
+ encoding = elementManager.getEncoding();
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public InputStream openStream(String path) throws IOException {
+ return documentRoot.openStream(path);
+ }
+
+ public URL getResourcePath() {
+ return resourcePath;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IExtensionContext#getEncoding()
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public Object getProperty(String name) {
+ return properties.get(name);
+ }
+
+ public void setProperty(String name, Object value) {
+ properties.put(name, value);
+ }
+
+ public ILoadingContext getLoadingContext() {
+ return loadingContext;
+ }
+ }
+
+ public MetaclassService getMetaclassService() {
+ return metaclassService;
+ }
+
+ /**
+ * Check if the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public boolean isFileResolveType(Class<?> type) {
+ for(Class<?> resolveType : resolveTypes) {
+ if(resolveType.isAssignableFrom(type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public void registerFileResolveType(Class<?> type) {
+ if(!resolveTypes.contains(type)) {
+ resolveTypes.add(type);
+ }
+ }
+
+ /**
+ * Register the value of a property is to resolve.
+ *
+ * @param type
+ * type of property
+ * @return
+ */
+ public void unregisterFileResolveType(Class<?> type) {
+ resolveTypes.remove(type);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DataBindingTrack.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DataBindingTrack.java
new file mode 100644
index 00000000000..0dc91f5d574
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DataBindingTrack.java
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * 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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.Tracking;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.internal.xml.Attribute;
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * @author liang.zhang
+ *
+ */
+public class DataBindingTrack {
+
+ private String bindingError = "";
+
+ private Set<String> errorElements = null;
+
+ private List<Element> widgetList = null;
+
+ private Map<Element, String> bindingMap;
+
+ public DataBindingTrack() {
+ widgetList = new ArrayList<Element>();
+ errorElements = new HashSet<String>();
+ bindingMap = new HashMap<Element, String>();
+ }
+
+ public void addWidgetElement(Element element) {
+ widgetList.add(element);
+ }
+
+ private void addErrorWidgetId(String elementId) {
+ errorElements.add(elementId);
+ }
+
+ private void addBindingMessageToMap(Element element, String bindingMessage) {
+ bindingMap.put(element, bindingMessage);
+ }
+
+ private int validateParentElementError(Element bindingElement) {
+ int isError = 0;
+ if(!bindingError.equals("")) {
+ Object parentObj = bindingElement.getParent();
+ while(parentObj != null) {
+ bindingElement = (Element)parentObj;
+ if(errorElements.contains(bindingElement.getId())) {
+ isError = 1;
+ break;
+ }
+ parentObj = bindingElement.getParent();
+ }
+ }
+ return isError;
+ }
+
+ private String getCurrentWidgetPosition(Element element) {
+ if(element.getParent() != null) {
+ return " " + getCurrentWidgetPosition((Element)element.getParent());
+ }
+ return "";
+ }
+
+ public String getDataBindMessage() {
+ StringBuffer message = new StringBuffer("");
+ Iterator<Element> widgetIt = widgetList.iterator();
+ Set<Element> keys = bindingMap.keySet();
+ while(widgetIt.hasNext()) {
+ Element element = widgetIt.next();
+ int parentHasError = validateParentElementError(element);
+ if(parentHasError == 0) {
+ String content = getCurrentWidgetPosition(element);
+ if(!message.toString().equals("")) {
+ content += "+ ";
+ }
+ content = content + element.getName();
+ if(XWT.isTracking(Tracking.NAME)) {
+ Attribute nameAttr = element.getAttribute("Name");
+ if(nameAttr == null) {
+ nameAttr = element.getAttribute(IConstants.XWT_X_NAMESPACE, "Name");
+ }
+ if(nameAttr != null) {
+ content += " <" + nameAttr.getContent() + ">";
+ }
+ }
+ message.append(content);
+ if(XWT.isTracking(Tracking.DATABINDING)) {
+ if(keys.contains(element)) {
+ message.append(bindingMap.get(element));
+ } else {
+ message.append("\n");
+ }
+ }
+ }
+ }
+ return message.toString();
+ }
+
+ private void setBindingErrorMessage(String bindingError) {
+ this.bindingError = bindingError;
+ }
+
+ public void tracking(Object swtObject, Element element, Object dataContext) {
+ String bindingMessage = "";
+ if(swtObject instanceof Binding) {
+ String error = "";
+ Binding newInstance = (Binding)swtObject;
+ String path = null;
+ Attribute attr = element.getAttribute("Path");
+ if(null == attr)
+ attr = element.getAttribute("path");
+ if(null != attr)
+ path = attr.getContent();
+ Object dataContext2 = null;
+ try {
+ dataContext2 = newInstance.getValue(null);
+ if(path != null && path.length() > 0) {
+ String[] paths = path.trim().split("\\.");
+ if(paths.length > 1) {
+ String path1 = "";
+ for(int i = 0; i < paths.length - 1; i++) {
+ path1 = paths[i];
+ if(dataContext2 != null) {
+ dataContext2 = getObserveData(dataContext2, path1);
+ }
+ }
+ }
+ }
+ } catch (Exception ex) {
+ addErrorWidgetId(element.getParent().getParent().getId());
+ setBindingErrorMessage("-> Error");
+ error = "-> Error";
+ }
+ if(dataContext2 != null) {
+ bindingMessage = " (DataContext=" + dataContext2.getClass().getSimpleName() + ", Path=" + path + ")" + error + "\n";
+ addBindingMessageToMap((Element)element.getParent().getParent(), bindingMessage);// bindingMap.put((Element) element.getParent().getParent(), bindingMessage);
+ }
+ } else if(swtObject instanceof Widget) {
+ addWidgetElement(element);
+ if(dataContext != null) {
+ bindingMessage = " (DataContext=" + dataContext.getClass().getSimpleName() + ")\n";
+ addBindingMessageToMap(element, bindingMessage);
+ }
+ } else if(JFacesHelper.isViewer(swtObject)) {
+ if(dataContext != null) {
+ bindingMessage = " (DataContext=" + dataContext.getClass().getSimpleName() + ")\n";
+ addBindingMessageToMap(element, bindingMessage);// bindingMap.put(element, bindingMessage);
+ }
+ } else if(element.attributeNames(IConstants.XWT_X_NAMESPACE).length > 0) {
+ // ??
+ if(element.getParent() != null && element.getParent().getParent() != null) {
+ bindingMessage = " (DataContext=" + element.getName() + ")\n";
+ addBindingMessageToMap((Element)element.getParent().getParent(), bindingMessage);// bindingMap.put((Element) element.getParent().getParent(), bindingMessage);
+ }
+ }
+ }
+
+ public static Object getObserveData(Object dataContext, String path) {
+ try {
+ Class<?> dataContextClass = dataContext.getClass();
+ Method getMethod = ObjectUtil.findGetter(dataContextClass, path, null);
+ if(getMethod != null) {
+ return getMethod.invoke(dataContext);
+ }
+ } catch (SecurityException e) {
+ LoggerManager.log(e);
+ } catch (IllegalArgumentException e) {
+ LoggerManager.log(e);
+ } catch (IllegalAccessException e) {
+ LoggerManager.log(e);
+ } catch (InvocationTargetException e) {
+ LoggerManager.log(e);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicBinding.java
new file mode 100644
index 00000000000..440121a6c8f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicBinding.java
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * 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.lang.reflect.Method;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.annotation.UIBounds;
+import org.eclipse.papyrus.xwt.core.IDynamicBinding;
+import org.eclipse.papyrus.xwt.core.IUserDataConstants;
+import org.eclipse.papyrus.xwt.databinding.BindingMode;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * Generic Binding definition
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public abstract class DynamicBinding implements IDynamicBinding {
+
+ private Object control;
+
+ private Object host;
+
+ private BindingMode mode = BindingMode.TwoWay;
+
+ private IXWTLoader xwtLoader;
+
+ /**
+ * The name of the {@link DataBindingContext} that we will look up in static
+ * resources
+ */
+ private IBindingContext bindingContext;
+
+ /**
+ * which used to decide binding type, not only text.
+ */
+ private String type;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.core.IDynamicBinding#getContextName()
+ */
+ public IBindingContext getBindingContext() {
+ if(this.bindingContext == null) {
+ Object element = (control == null ? host : control);
+ this.bindingContext = XWT.getBindingContext(element);
+ }
+ return this.bindingContext;
+ }
+
+ public Object getHost() {
+ return host;
+ }
+
+ public void setHost(Object host) {
+ this.host = host;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.core.IDynamicBinding#setBindingContext(IBindingContext
+ * )
+ */
+ public void setBindingContext(IBindingContext bindingContext) {
+ this.bindingContext = bindingContext;
+ }
+
+ public void setControl(Object control) {
+ this.control = control;
+ }
+
+ public Object getControl() {
+ return this.control;
+ }
+
+ /**
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ public BindingMode getMode() {
+ return mode;
+ }
+
+ public void setMode(BindingMode mode) {
+ this.mode = mode;
+ }
+
+ public void setXWTLoader(IXWTLoader xwtLoader) {
+ this.xwtLoader = xwtLoader;
+ }
+
+ protected Object getDataContextHost() {
+ Object control = getControl();
+ if(control == null) {
+ return null;
+ }
+ Object data = UserData.getLocalDataContext(control);
+ if(data == null || data == this) {
+ if(data == null && UserData.hasLocalData(control, IUserDataConstants.XWT_DATACONTEXT_KEY)) {
+ return control;
+ }
+ Widget parent = UserData.getParent(control);
+ if(parent != null) {
+ return UserData.getDataContextHost(parent);
+ }
+ return null;
+ }
+ return control;
+ }
+
+ protected Object getDataContext() {
+ if(control != null) {
+ return UserData.getDataContext(control);
+ }
+ return null;
+ }
+
+ protected IDataProvider getDataProvider(Object dataContext) {
+ if(dataContext != null) {
+ if(dataContext instanceof IDataProvider) {
+ return (IDataProvider)dataContext;
+ } else {
+ return xwtLoader.findDataProvider(dataContext);
+ }
+ }
+ return null;
+ }
+
+ public IDataProvider getDataProvider() {
+ return getDataProvider(getDataContext());
+ }
+
+ protected Rectangle getControlBounds() {
+ Widget widget = (Widget)getControl();
+ if(widget instanceof Control) {
+ Control control = (Control)widget;
+ return control.getBounds();
+ }
+ Method drawMethod = findBoundsMethod(widget.getClass());
+ if(drawMethod != null) {
+ try {
+ drawMethod.setAccessible(true);
+ return (Rectangle)drawMethod.invoke(widget);
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+ Control control = findHostControl();
+ return control.getBounds();
+ }
+
+ protected Control findHostControl() {
+ Widget widget = (Widget)getControl();
+ Control host;
+ if(widget instanceof Item) {
+ Item item = (Item)widget;
+ host = (Control)XWT.findParent(item, Control.class);
+ } else if(widget instanceof Control) {
+ host = (Control)widget;
+ } else {
+ throw new XWTException();
+ }
+ return host;
+ }
+
+ private Method findBoundsMethod(Class<?> type) {
+ for(Method method : type.getDeclaredMethods()) {
+ if(method.getAnnotation(UIBounds.class) != null && method.getTypeParameters().length == 0 && method.getReturnType() == Rectangle.class) {
+ return method;
+ }
+ }
+ Class<?> supertype = type.getSuperclass();
+ if(supertype != null && supertype != Widget.class) {
+ Method method = findBoundsMethod(supertype);
+ if(method != null) {
+ return method;
+ }
+ }
+ for(Class<?> anInterface : type.getInterfaces()) {
+ Method method = findBoundsMethod(anInterface);
+ if(method != null) {
+ return method;
+ }
+ }
+ try {
+ Method method = type.getDeclaredMethod("getBounds");
+ if(method.getReturnType() == Rectangle.class) {
+ return method;
+ }
+ } catch (Exception e) {
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicValueBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicValueBinding.java
new file mode 100644
index 00000000000..70d56d631ec
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/DynamicValueBinding.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.internal.core;
+
+import org.eclipse.papyrus.xwt.core.IDynamicValueBinding;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+public class DynamicValueBinding<T> extends DynamicBinding implements IDynamicValueBinding {
+
+ private T sourceValue;
+
+ private IProperty property;
+
+ private Object object;
+
+ public DynamicValueBinding(T sourceValue) {
+ this.sourceValue = sourceValue;
+ }
+
+ public IProperty getProperty() {
+ return property;
+ }
+
+ public void setProperty(IProperty property) {
+ this.property = property;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public void setObject(Object object) {
+ this.object = object;
+ }
+
+ public T getSourceValue() {
+ return sourceValue;
+ }
+
+ public Object getValue(Class<?> type) {
+ return sourceValue;
+ }
+
+ public void reset() {
+ }
+
+ public Object createBoundSource() {
+ return null;
+ }
+
+ public boolean isSourceControl() {
+ return false;
+ }
+
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/IEventController.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/IEventController.java
new file mode 100644
index 00000000000..347e45ab5c5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/IEventController.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.internal.core;
+
+import java.lang.reflect.Method;
+
+import org.eclipse.papyrus.xwt.IEventInvoker;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Widget;
+
+public interface IEventController {
+
+ boolean hasEvent(Object receiver, IEvent event);
+
+ void addEvent(int eventType, String name, IEvent event, Widget control, Object receiver, Object arg, Method method);
+
+ void addEvent(int eventType, String name, IEvent event, Widget control, Object arg, IEventInvoker eventInvoker);
+
+ void setEvent(IEvent event, Widget control, Object receiver, Object arg, Method method);
+
+ void setEvent(IEvent event, Widget control, Object arg, IEventInvoker eventInvoker);
+
+ void handleEvent(Event e);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassManager.java
new file mode 100644
index 00000000000..d8a5a92cd53
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassManager.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * 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.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.ILoadingContext;
+import org.eclipse.papyrus.xwt.IMetaclassFactory;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.internal.utils.ClassLoaderUtil;
+import org.eclipse.papyrus.xwt.javabean.metadata.Metaclass;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class MetaclassManager {
+
+ protected Map<String, IMetaclass> nameRegister = new HashMap<String, IMetaclass>();
+
+ protected Collection<Class<?>> classRegister = new HashSet<Class<?>>();
+
+ protected MetaclassManager parent;
+
+ protected MetaclassService service;
+
+ private IXWTLoader xwtLoader;
+
+ public MetaclassManager(MetaclassService service, MetaclassManager parent, IXWTLoader xwtLoader) {
+ this.parent = parent;
+ this.service = service;
+ this.xwtLoader = xwtLoader;
+ }
+
+ public Collection<IMetaclass> getAllMetaclasses() {
+ return nameRegister.values();
+ }
+
+ public void register(IMetaclass metaclass) {
+ Class<?> type = metaclass.getType();
+ if(classRegister.contains(type)) {
+ return;
+ }
+ String key = type.getSimpleName();
+ nameRegister.put(key, metaclass);
+ classRegister.add(type);
+ }
+
+ public IMetaclass register(Class<?> javaClass) {
+ return register(javaClass, null);
+ }
+
+ public IMetaclass register(Class<?> javaClass, IMetaclass superMetaclass) {
+ IMetaclass metaclass = getMetaclass(javaClass);
+ if(metaclass != null) {
+ return metaclass;
+ }
+ if(superMetaclass == null) {
+ Class<?> superclass = javaClass.getSuperclass();
+ if(superclass != null && superclass != Object.class) {
+ register(superclass, null);
+ }
+ superMetaclass = getMetaclass(superclass);
+ }
+ IMetaclass thisMetaclass = createMetaclass(javaClass, superMetaclass);
+ register(thisMetaclass);
+ return thisMetaclass;
+ }
+
+ protected IMetaclass createMetaclass(Class<?> javaClass, IMetaclass superMetaclass) {
+ if(service != null) {
+ IMetaclassFactory factory = service.findFactory(javaClass);
+ if(factory != null) {
+ return factory.create(javaClass, superMetaclass, xwtLoader);
+ }
+ }
+ boolean lazyLoading = false; // TODO Get value from preference
+ return new Metaclass(javaClass, superMetaclass, lazyLoading, xwtLoader);
+ }
+
+ public IMetaclass getMetaclass(ILoadingContext context, String name, String namespace) {
+ IMetaclass metaclass = nameRegister.get(name);
+ if(metaclass != null) {
+ if(namespace == null || namespace.equals(IConstants.XWT_NAMESPACE)) {
+ return metaclass;
+ }
+ if(namespace != null && namespace.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO)) {
+ String packageName = namespace.substring(IConstants.XAML_CLR_NAMESPACE_PROTO.length());
+ int index = packageName.indexOf('=');
+ if(index != -1) {
+ packageName = packageName.substring(0, index);
+ }
+ // if using default package(null), use only name as class name,
+ // else use package.class as class name
+ String className = packageName.length() == 0 ? name : (packageName + "." + name);
+ if(metaclass.getType().getName().equals(className)) {
+ return metaclass;
+ }
+ }
+ }
+ if(namespace == null || !namespace.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO)) {
+ return null;
+ }
+ String packageName = namespace.substring(IConstants.XAML_CLR_NAMESPACE_PROTO.length());
+ int index = packageName.indexOf('=');
+ if(index != -1) {
+ packageName = packageName.substring(0, index);
+ }
+ // if using default package(null), use only name as class name, else use
+ // package.class as class name
+ String className = packageName.length() == 0 ? name : (packageName + "." + name);
+ // try {
+ Class<?> type = ClassLoaderUtil.loadClass(context, className);
+ if(type == null) {
+ throw new XWTException("Cannot load " + className);
+ }
+ metaclass = register(type, null);
+ // There is no need to mapping a CLR class, since the ClassLoader will
+ // be changed.
+ nameRegister.remove(type.getSimpleName());
+ return metaclass;
+ }
+
+ public IMetaclass getMetaclass(Object object) {
+ if(object instanceof Class) {
+ return getMetaclass((Class<?>)object);
+ } else if(object instanceof String) {
+ return getMetaclass((String)object);
+ }
+ Class<?> type = object.getClass();
+ return getMetaclass(type);
+ }
+
+ public IMetaclass getMetaclass(Class<?> type) {
+ if(classRegister.contains(type)) {
+ IMetaclass metaclass = nameRegister.get(type.getSimpleName());
+ if(metaclass != null && metaclass.getType() == type) {
+ return metaclass;
+ }
+ }
+ if(parent != null) {
+ IMetaclass metaclass = parent.getMetaclass(type);
+ if(metaclass != null) {
+ return metaclass;
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassService.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassService.java
new file mode 100644
index 00000000000..7ed56b7e9db
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MetaclassService.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.internal.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.ILoadingContext;
+import org.eclipse.papyrus.xwt.IMetaclassFactory;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class MetaclassService {
+
+ protected Map<String, MetaclassManager> map = new HashMap<String, MetaclassManager>();
+
+ protected ArrayList<IMetaclassFactory> factories = new ArrayList<IMetaclassFactory>();
+
+ private IXWTLoader xwtLoader;
+
+ public MetaclassService(IXWTLoader xwtLoader) {
+ this.xwtLoader = xwtLoader;
+ }
+
+ public IMetaclass getMetaclass(ILoadingContext context, String name, String namespace) {
+ MetaclassManager manager = map.get(namespace);
+ if(manager == null) {
+ manager = new MetaclassManager(this, map.get(IConstants.XWT_NAMESPACE), xwtLoader);
+ map.put(namespace, manager);
+ }
+ return manager.getMetaclass(context, name, namespace);
+ }
+
+ public IMetaclass findMetaclass(Class<?> type) {
+ MetaclassManager manager = map.get(IConstants.XWT_NAMESPACE);
+ if(manager == null) {
+ return null;
+ }
+ return manager.getMetaclass(type);
+ }
+
+ public IMetaclass getMetaclass(Class<?> type) {
+ MetaclassManager manager = map.get(IConstants.XWT_NAMESPACE);
+ if(manager == null) {
+ return null;
+ }
+ IMetaclass metaclass = manager.getMetaclass(type);
+ if(metaclass == null) {
+ String packageName = "";
+ Package packageObject = type.getPackage();
+ if(packageObject != null) {
+ packageName = packageObject.getName();
+ }
+ String key = IConstants.XAML_CLR_NAMESPACE_PROTO + ":" + packageName;
+ MetaclassManager childManager = map.get(key);
+ if(childManager == null) {
+ childManager = new MetaclassManager(this, manager, xwtLoader);
+ map.put(key, childManager);
+ }
+ metaclass = childManager.getMetaclass(type);
+ if(metaclass == null) {
+ childManager.register(type);
+ metaclass = childManager.getMetaclass(type);
+ }
+ }
+ return metaclass;
+ }
+
+ public IMetaclass getMetaclass(Class<?> type, String namespace) {
+ MetaclassManager manager = map.get(namespace);
+ if(manager == null) {
+ manager = new MetaclassManager(this, null, xwtLoader);
+ map.put(namespace, manager);
+ }
+ IMetaclass metaclass = manager.getMetaclass(type);
+ if(metaclass == null) {
+ metaclass = manager.getMetaclass(type);
+ if(metaclass == null) {
+ manager.register(type);
+ metaclass = manager.getMetaclass(type);
+ }
+ }
+ return metaclass;
+ }
+
+ public IMetaclass register(Class<?> metaclass, String namespace) {
+ MetaclassManager manager = map.get(namespace);
+ if(manager == null) {
+ throw new IllegalStateException();
+ }
+ return manager.register(metaclass);
+ }
+
+ public IMetaclass register(Class<?> metaclass, String namespace, IMetaclass superMetaclass) {
+ MetaclassManager manager = map.get(namespace);
+ if(manager == null) {
+ throw new IllegalStateException();
+ }
+ return manager.register(metaclass, superMetaclass);
+ }
+
+ public void register(IMetaclass metaclass, String namespace) {
+ MetaclassManager manager = map.get(namespace);
+ if(manager == null) {
+ manager = new MetaclassManager(this, null, xwtLoader);
+ map.put(namespace, manager);
+ }
+ manager.register(metaclass);
+ }
+
+ public Collection<IMetaclass> getAllMetaclasses(String namespace) {
+ MetaclassManager manager = map.get(namespace);
+ if(manager == null) {
+ throw new IllegalStateException();
+ }
+ return manager.getAllMetaclasses();
+ }
+
+ public void register(String namespace, MetaclassManager manager) {
+ map.put(namespace, manager);
+ }
+
+ public void registerFactory(IMetaclassFactory metaclassFactory) {
+ factories.add(metaclassFactory);
+ }
+
+ public IMetaclassFactory findFactory(Class<?> javaClass) {
+ for(int i = factories.size() - 1; i >= 0; i--) {
+ IMetaclassFactory factory = factories.get(i);
+ if(factory.isFactoryOf(javaClass)) {
+ return factory;
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MultiBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MultiBinding.java
new file mode 100644
index 00000000000..615009fbc49
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/MultiBinding.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * 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.papyrus.xwt.IDataBindingInfo;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IMultiValueConverter;
+import org.eclipse.papyrus.xwt.IValidationRule;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.converters.StringMultiValueConerter;
+import org.eclipse.papyrus.xwt.core.IDynamicBinding;
+import org.eclipse.papyrus.xwt.databinding.AggregateObservableValue;
+import org.eclipse.papyrus.xwt.databinding.IBindingContext;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+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;
+
+/**
+ * Support the aggregation of data binding
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class MultiBinding extends DynamicBinding implements IDataBindingInfo {
+
+ private Binding[] bindings = Binding.EMPTY_ARRAY;
+
+ private IMultiValueConverter valueConverter;
+
+ private IValidationRule[] valueValidators = IValidationRule.EMPTY_ARRAY;
+
+ private AggregateObservableValue observableValue;
+
+ private IObservableValue observableWidget;
+
+ private BindingExpressionPath targetPropertySegments;
+
+ /**
+ * <p>
+ * Default
+ * </p>
+ *
+ */
+ private UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default;
+
+ private BindingGate bindingGate;
+
+ public UpdateSourceTrigger getUpdateSourceTrigger() {
+ return updateSourceTrigger;
+ }
+
+ public void setUpdateSourceTrigger(UpdateSourceTrigger updateSourceTrigger) {
+ this.updateSourceTrigger = updateSourceTrigger;
+ }
+
+ public Binding[] getBindings() {
+ return bindings;
+ }
+
+ public void setBindings(Binding[] bindings) {
+ this.bindings = bindings;
+ }
+
+ public IMultiValueConverter getConverter() {
+ if(valueConverter == null) {
+ valueConverter = new StringMultiValueConerter();
+ }
+ return valueConverter;
+ }
+
+ public void setConverter(IMultiValueConverter valueConverter) {
+ this.valueConverter = valueConverter;
+ }
+
+ public boolean isSourcePropertyReadOnly() {
+ for(Binding binding : bindings) {
+ if(binding.isSourcePropertyReadOnly()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Object getValue(Class<?> targetType) {
+ if(observableValue == null) {
+ IObservableValue[] values = new IObservableValue[bindings.length];
+ for(int i = 0; i < values.length; i++) {
+ bindings[i].getValue(targetType);
+ IObservable observable = bindings[i].getObservableSource();
+ if(observable instanceof IObservableValue) {
+ values[i] = (IObservableValue)observable;
+ } else {
+ LoggerManager.log("Binding expression has a problem with " + bindings[i].getPath());
+ return null;
+ }
+ }
+
+ observableValue = new AggregateObservableValue(values, getConverter());
+ }
+
+ IObservableValue observableWidget = getObservableWidget();
+
+ IDataProvider dataProvider = getDataProvider();
+ if(dataProvider != null) {
+ BindingGate bindingGate = getBindingGate();
+ if(bindingGate != null) {
+ Object target = getControl();
+ if(target instanceof Text && getType().equalsIgnoreCase("text")) {
+ if(isSourcePropertyReadOnly()) {
+ Text text = (Text)target;
+ text.setEditable(false);
+ }
+ } else if(target instanceof Button && getType().equalsIgnoreCase("selection")) {
+ if(isSourcePropertyReadOnly()) {
+ Button button = (Button)target;
+ button.setEnabled(false);
+ }
+ } else if((target instanceof Combo || target instanceof CCombo) && getType().equalsIgnoreCase("text")) {
+ if(isSourcePropertyReadOnly()) {
+ Control control = (Control)target;
+ control.setEnabled(false);
+ }
+ } else if(target instanceof MenuItem && getType().equalsIgnoreCase("selection")) {
+ if(isSourcePropertyReadOnly()) {
+ MenuItem menuItem = (MenuItem)target;
+ menuItem.setEnabled(false);
+ }
+ }
+ }
+ bindingGate.bind(observableValue, observableWidget, this);
+ }
+
+ if(targetType == null || !targetType.isInstance(observableValue)) {
+ return observableValue.getValue();
+ }
+ return observableValue;
+ }
+
+ private BindingGate getBindingGate() {
+ if(this.bindingGate == null) {
+ IBindingContext dataBindingContext = XWT.getBindingContext(getControl());
+ this.bindingGate = new BindingGate(dataBindingContext);
+ }
+
+ return this.bindingGate;
+ }
+
+ public IObservableValue getObservableWidget() {
+ if(observableWidget == null) {
+ Object target = getControl();
+ Object host = getHost();
+ try {
+ observableWidget = ScopeManager.observeValue(target, host, getTargettPropertyExpression(), getUpdateSourceTrigger());
+ } catch (XWTException e) {
+ }
+ }
+ return observableWidget;
+ }
+
+ public Object createBoundSource() {
+ Object control = getControl();
+ Object source = XWT.getDataContext(control);
+ Object localDataContext = UserData.getLocalDataContext(control);
+ if(localDataContext == this) {
+ return source;
+ }
+
+ if(source instanceof IDynamicBinding) {
+ return ((IDynamicBinding)source).createBoundSource();
+ }
+ return source;
+ }
+
+ public boolean isSourceControl() {
+ Object source = null;
+ Object dataContextHost = getDataContextHost();
+ if(dataContextHost != null) {
+ source = UserData.getLocalDataContext(dataContextHost);
+ }
+
+ if(source instanceof IDynamicBinding) {
+ return ((IDynamicBinding)source).isSourceControl();
+ }
+ return false;
+ }
+
+ public BindingExpressionPath getTargettPropertyExpression() {
+ if(targetPropertySegments == null) {
+ targetPropertySegments = new BindingExpressionPath(getType());
+ }
+ return targetPropertySegments;
+ }
+
+ public IValidationRule[] getValidators() {
+ return valueValidators;
+ }
+
+ public void setValidators(IValidationRule[] valueValidators) {
+ this.valueValidators = valueValidators;
+ }
+
+ public void reset() {
+ for(Binding binding : bindings) {
+ binding.reset();
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeKeeper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeKeeper.java
new file mode 100644
index 00000000000..ef5d159029c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeKeeper.java
@@ -0,0 +1,263 @@
+/*******************************************************************************
+ * 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.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+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.internal.utils.UserData;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Widget;
+
+public class ScopeKeeper implements DisposeListener {
+
+ protected HashMap<String, Object> nameMap = new HashMap<String, Object>();
+
+ protected HashMap<Widget, HashMap<Object, HashMap<String, IObservable>>> bindingData = new HashMap<Widget, HashMap<Object, HashMap<String, IObservable>>>();
+
+ protected Widget host;
+
+ private final ScopeKeeper parent;
+
+ private ChangeListenerSupport changeListenerSupport = new ChangeListenerSupport();
+
+ class ChangeListenerSupport implements IChangeListener {
+
+ private List<IChangeListener> changeListeners = Collections.emptyList();
+
+ public void handleChange(ChangeEvent event) {
+ for(IChangeListener changeListener : changeListeners) {
+ changeListener.handleChange(event);
+ }
+
+ // notify to parent as well.
+ Widget parent = UserData.getTreeParent(host);
+ ScopeKeeper scopeKeeper = UserData.findScopeKeeper(parent);
+ if(scopeKeeper != null) {
+ scopeKeeper.fireChangeListener(event);
+ }
+ }
+
+ public boolean addChangeListener(IChangeListener listener) {
+ if(changeListeners.contains(listener)) {
+ return false;
+ }
+ if(changeListeners == Collections.EMPTY_LIST) {
+ changeListeners = new ArrayList<IChangeListener>();
+ }
+ changeListeners.add(listener);
+ return true;
+ }
+
+ public void removeChangeListener(IChangeListener listener) {
+ changeListeners.remove(listener);
+ }
+
+ public void dispose() {
+ changeListeners = null;
+ }
+ }
+
+ public ScopeKeeper(ScopeKeeper parent, Widget host) {
+ super();
+ this.parent = parent;
+ host.addDisposeListener(this);
+ this.host = host;
+ }
+
+ public void widgetDisposed(DisposeEvent e) {
+ Widget source = e.widget;
+ if(source == host) {
+ for(HashMap<Object, HashMap<String, IObservable>> hashMap : bindingData.values()) {
+ for(HashMap<String, IObservable> map : hashMap.values()) {
+ for(IObservable observable : map.values()) {
+ observable.removeChangeListener(changeListenerSupport);
+ }
+ }
+ }
+ changeListenerSupport.dispose();
+ }
+ HashMap<Object, HashMap<String, IObservable>> hashMap = bindingData.get(source);
+ if(hashMap != null) {
+ for(HashMap<String, IObservable> map : hashMap.values()) {
+ for(IObservable observable : map.values()) {
+ observable.removeChangeListener(changeListenerSupport);
+ }
+ }
+ bindingData.remove(source);
+ }
+ }
+
+ public void addNamedObject(String name, Object object) {
+ nameMap.put(name, object);
+ }
+
+ public Widget getHost() {
+ return host;
+ }
+
+ public Object getNamedObject(String name) {
+ Object object = nameMap.get(name);
+ if(object != null) {
+ return object;
+ }
+ return parent == null ? null : parent.getNamedObject(name);
+ }
+
+ public Collection<String> names() {
+ return nameMap.keySet();
+ }
+
+ public boolean containsName(String name) {
+ if(nameMap.containsKey(name)) {
+ return true;
+ }
+ return parent == null ? false : parent.containsName(name);
+ }
+
+ /**
+ * Register a change listener. The second call to register a same listener
+ * has no effect.
+ *
+ * @param listener
+ */
+ public boolean addChangeListener(IChangeListener listener) {
+ return changeListenerSupport.addChangeListener(listener);
+ }
+
+ /**
+ * Remove the registered change listener
+ *
+ * @param listener
+ */
+ public void removeChangeListener(IChangeListener listener) {
+ changeListenerSupport.removeChangeListener(listener);
+ }
+
+ public void fireChangeListener(ChangeEvent event) {
+ changeListenerSupport.handleChange(event);
+ }
+
+ void addObservableValue(Widget widget, Object data, String property, IObservable value) {
+ if(widget == null) {
+ widget = host;
+ } else {
+ widget.addDisposeListener(this);
+ }
+
+ HashMap<Object, HashMap<String, IObservable>> widgetData = bindingData.get(widget);
+ if(widgetData == null) {
+ widgetData = new HashMap<Object, HashMap<String, IObservable>>();
+ bindingData.put(widget, widgetData);
+ }
+
+ HashMap<String, IObservable> objectData = widgetData.get(data);
+ if(objectData == null) {
+ objectData = new HashMap<String, IObservable>();
+ widgetData.put(data, objectData);
+ }
+ if(objectData.containsKey(property)) {
+ throw new IllegalStateException();
+ }
+ objectData.put(property, value);
+
+ value.addChangeListener(changeListenerSupport);
+ }
+
+ IObservableValue getObservableValue(Widget control, Object data, String property) {
+ IObservable observable = getObservable(control, data, property);
+ if(observable instanceof IObservableValue) {
+ return (IObservableValue)observable;
+ }
+
+ return null;
+ }
+
+ IObservableList getObservableList(Widget control, Object data, String property) {
+ IObservable observable = getObservable(control, data, property);
+ if(observable instanceof IObservableList) {
+ return (IObservableList)observable;
+ }
+ return null;
+ }
+
+ IObservableSet getObservableSet(Widget control, Object data, String property) {
+ IObservable observable = getObservable(control, data, property);
+ if(observable instanceof IObservableSet) {
+ return (IObservableSet)observable;
+ }
+ return null;
+ }
+
+ IObservable localGetObservable(Widget control, Object data, String property) {
+ // find locally
+ for(HashMap<Object, HashMap<String, IObservable>> widgetData : bindingData.values()) {
+ if(widgetData != null) {
+ HashMap<String, IObservable> objectData = widgetData.get(data);
+ if(objectData != null) {
+ IObservable observable = objectData.get(property);
+ if(observable != null) {
+ return observable;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ IObservable getObservable(Widget control, Object data, String property) {
+ // find locally
+ IObservable observable = localGetObservable(control, data, property);
+ if(observable != null) {
+ return observable;
+ }
+
+ // find in other ScopeKeeper and then keep it in this ScopeKeeper.
+ Widget rootWidget = UserData.findRootWidget(control);
+ observable = deepFindObservable(rootWidget, data, property);
+ if(observable != null) {
+ addObservableValue(control, data, property, observable);
+ }
+ return observable;
+ }
+
+ static IObservable deepFindObservable(Widget control, Object data, String property) {
+ ScopeKeeper scopeKeeper = UserData.getLocalScopeKeeper(control);
+ if(scopeKeeper != null) {
+ IObservable observable = scopeKeeper.localGetObservable(control, data, property);
+ if(observable != null) {
+ return observable;
+ }
+ }
+ if(control instanceof Composite) {
+ Composite composite = (Composite)control;
+ for(Control child : composite.getChildren()) {
+ IObservable observable = deepFindObservable(child, data, property);
+ if(observable != null) {
+ return observable;
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeManager.java
new file mode 100644
index 00000000000..51496c5cb0b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/ScopeManager.java
@@ -0,0 +1,485 @@
+/*******************************************************************************
+ * 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.Collection;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+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.core.databinding.property.value.IValueProperty;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.databinding.EventPropertyObservableValue;
+import org.eclipse.papyrus.xwt.databinding.JFaceXWTDataBinding;
+import org.eclipse.papyrus.xwt.databinding.ListToArrayObservableValue;
+import org.eclipse.papyrus.xwt.databinding.TypedViewerObservableValueDecorator;
+import org.eclipse.papyrus.xwt.dataproviders.IObjectDataProvider;
+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.papyrus.xwt.metadata.ModelUtils;
+import org.eclipse.swt.widgets.Widget;
+
+public class ScopeManager {
+
+ public static final int AUTO = 0;
+
+ public static final int VALUE = 1;
+
+ public static final int SET = 2;
+
+ public static final int LIST = 3;
+
+ public static final int COLLECTION = 4;
+
+ public static IObservableValue observableValue(Object control, Object value, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ try {
+ return observeValue(control, value, fullPath, updateSourceTrigger);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ public static IObservableList observableList(Object control, Object value, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ try {
+ return (IObservableList)observe(control, value, fullPath, updateSourceTrigger, ScopeManager.LIST);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ public static IObservableSet observableSet(Object control, Object value, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ try {
+ return (IObservableSet)observe(control, value, fullPath, updateSourceTrigger, ScopeManager.SET);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ /**
+ * Reserved only for the calling from XWTLoader
+ *
+ * @param context
+ * @param data
+ * @param propertyName
+ * @return
+ */
+ public static IObservableValue findObservableValue(Object context, Object control, Object data, String propertyName) {
+ ScopeKeeper scope = UserData.findScopeKeeper(context);
+ if(control == null) {
+ control = context;
+ }
+ return scope.getObservableValue(UserData.getWidget(control), data, propertyName);
+ }
+
+ /**
+ * Reserved only for the calling from XWTLoader
+ *
+ * @param context
+ * @param data
+ * @param propertyName
+ * @return
+ */
+ public static IObservableSet findObservableSet(Object context, Object control, Object data, String propertyName) {
+ ScopeKeeper scope = UserData.findScopeKeeper(context);
+ if(control == null) {
+ control = context;
+ }
+ return scope.getObservableSet(UserData.getWidget(control), data, propertyName);
+ }
+
+ /**
+ * Reserved only for the calling from XWTLoader
+ *
+ * @param context
+ * @param data
+ * @param propertyName
+ * @return
+ */
+ public static IObservableList findObservableList(Object context, Object control, Object data, String propertyName) {
+ ScopeKeeper scope = UserData.findScopeKeeper(context);
+ if(control == null) {
+ control = context;
+ }
+ return scope.getObservableList(UserData.getWidget(control), data, propertyName);
+ }
+
+ static class ObservableValueBuilder {
+
+ private Widget widget;
+
+ private Object control;
+
+ private Object value;
+
+ private Object elementType;
+
+ private BindingExpressionPath expressionPath;
+
+ private UpdateSourceTrigger updateSourceTrigger;
+
+ private IDataProvider dataProvider;
+
+ private String currentPath;
+
+ private int observeKind = VALUE;
+
+ public ObservableValueBuilder(Object control, Object elementType, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger, int observeKind) {
+ this.control = control;
+ this.expressionPath = expressionPath;
+ this.elementType = elementType;
+ this.updateSourceTrigger = updateSourceTrigger;
+ this.observeKind = observeKind;
+ }
+
+ public IObservable observe(Object targetValue) {
+ this.value = targetValue;
+ widget = UserData.getWidget(control);
+ ScopeKeeper scopeManager = UserData.findScopeKeeper(widget);
+ if(scopeManager == null) {
+ return null;
+ }
+
+ if(expressionPath.getFullPath() == null) {
+ if(targetValue instanceof IObservable) {
+ return (IObservable)targetValue;
+ }
+ }
+
+ IObservable observable = scopeManager.getObservable(widget, value, expressionPath.getStripedPath());
+ if(observable != null) {
+ while(observable instanceof IObservableValue && ((IObservableValue)observable).getValue() instanceof IObservable) {
+ observable = (IObservable)((IObservableValue)observable).getValue();
+ }
+ return observable;
+ }
+ dataProvider = XWT.findDataProvider(value);
+ Object dataValue = value;
+ currentPath = null;
+ Object type = elementType;
+ String[] segments = expressionPath.getSegments();
+ if(segments == null || segments.length == 0) {
+ String segment = ModelUtils.normalizePropertyName(expressionPath.getFullPath());
+ observable = resolveObservablevalue(scopeManager, dataValue, type, segment);
+ } else {
+ if(observeKind == COLLECTION) {
+ // if the first is viewers' property
+ if(!JFaceXWTDataBinding.isViewerProperty(segments[0])) {
+ int kindValue = VALUE;
+ Object targetValueType = dataValue;
+ if(dataValue instanceof IObservableValue) {
+ targetValueType = ((IObservableValue)dataValue).getValueType();
+ }
+ Object propertyType = dataProvider.getModelService().toModelPropertyType(targetValueType, segments[0]);
+ if(propertyType instanceof Class<?>) {
+ Class<?> propertyTypeClass = (Class<?>)propertyType;
+ if(Collection.class.isAssignableFrom(propertyTypeClass) || propertyTypeClass.isArray()) {
+ kindValue = COLLECTION;
+ }
+ }
+ observeKind = kindValue;
+ }
+ }
+ int size = segments.length;
+ int lastObserveKind = observeKind;
+ observeKind = VALUE;
+ for(int i = 0; i < size; i++) {
+ String segment = segments[i];
+ if(i == (size - 1)) {
+ observeKind = lastObserveKind;
+ }
+ observable = resolveObservablevalue(scopeManager, dataValue, type, segment);
+ // Hasan: As long as this is already an IObservableValue we
+ // should look deep into the chain
+ while(observable instanceof IObservableValue && ((IObservableValue)observable).getValue() instanceof IObservable) {
+ observable = (IObservable)((IObservableValue)observable).getValue();
+ }
+ dataValue = observable;
+ if(i != size - 1) {
+ type = dataProvider.getModelService().toModelType(dataValue);
+ if(type != null) {
+ dataProvider = XWT.findDataProvider(type);
+ }
+ }
+ }
+ }
+ return observable;
+ }
+
+ private IObservable resolveObservablevalue(ScopeKeeper scopeManager, Object dataValue, Object type, String segment) {
+ if(!BindingExpressionPath.isEmptyPath(segment)) {
+ int length = segment.length();
+ if(length > 1 && segment.charAt(0) == '(' && segment.charAt(length - 1) == ')') {
+ // It is class
+ String path = segment.substring(1, segment.length() - 1);
+ int index = path.lastIndexOf('.');
+ if(index != -1) {
+ String className = path.substring(0, index);
+ segment = path.substring(index + 1);
+ type = dataProvider.getModelService().loadModelType(className);
+ if(type == null) {
+ type = dataProvider.getModelService().loadModelType(path);
+ if(type != null) {
+ segment = null;
+ }
+ }
+ if(type == null) {
+ throw new XWTException("Class " + className + " not found");
+ }
+ dataProvider = XWT.findDataProvider(type);
+ }
+ }
+ }
+ if(currentPath == null) {
+ currentPath = segment;
+ } else if(segment != null) {
+ currentPath = currentPath + '.' + segment;
+ }
+
+ IObservable segmentValue = scopeManager.getObservableValue(widget, value, currentPath);
+ try {
+ if(segmentValue == null) {
+ if(segment != null) {
+ segmentValue = createValueProperty(dataValue, segment, type);
+ if(segmentValue == null) {
+ throw new XWTException(" Property " + segment + " is not found in " + expressionPath.getFullPath());
+ // maybe to
+ // raise an
+ // exception
+ }
+ scopeManager.addObservableValue(widget, value, currentPath, segmentValue);
+ } else if(dataValue instanceof IObservable) {
+ segmentValue = (IObservable)dataValue;
+ }
+ } else if(segment == null && type != null) {
+ if(segmentValue instanceof TypedViewerObservableValueDecorator) {
+ TypedViewerObservableValueDecorator typedViewerObservableValueDecorator = (TypedViewerObservableValueDecorator)segmentValue;
+ typedViewerObservableValueDecorator.setElementType(type);
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ // Property is not found
+ String message = e.getMessage();
+ if(!message.startsWith("Could not find property with name")) {
+ throw e;
+ }
+ throw new XWTException(" Property " + segment + " is not found in " + expressionPath.getFullPath()); // maybe
+ // to
+ // raise
+ // an
+ // exception
+ }
+ return segmentValue;
+ }
+
+ protected IObservable createValueProperty(Object object, String propertyName, Object targetType) {
+ IObservable observable = null;
+ Object type = null;
+ if(targetType == null) {
+ type = dataProvider.getModelService().toModelType(object);
+ } else {
+ type = targetType;
+ }
+
+ if(UserData.getWidget(object) != null) {
+ observable = JFaceXWTDataBinding.observeWidget(object, propertyName, updateSourceTrigger, observeKind);
+ }
+
+ if(observable == null && dataProvider instanceof IObjectDataProvider) {
+ IMetaclass mateclass = XWT.getMetaclass(type);
+ IProperty property = mateclass.findProperty(propertyName);
+ if(property instanceof EventProperty) {
+ observable = new EventPropertyObservableValue(object, (EventProperty)property);
+ }
+ }
+
+ if(observable != null) {
+ return observable;
+ }
+ observable = dataProvider.observe(object, propertyName, type, observeKind);
+ if(observable instanceof IObservableValue) {
+ IObservableValue activeValue = (IObservableValue)observable;
+
+ Object valueType = activeValue.getValueType();
+ if(valueType instanceof Class<?>) {
+ // TODO maybe need to moved in IDataProvider
+ Class<?> classType = (Class<?>)valueType;
+ if(valueType != null && classType.isArray()) {
+ // Create a IObserableValue to handle the connection
+ // between
+ // Array and List
+
+ Object values = dataProvider.getData(propertyName);
+ ArrayList<Object> array = new ArrayList<Object>();
+ if(values != null) {
+ for(Object value : (Object[])values) {
+ array.add(value);
+ }
+ }
+ WritableList writableList = new WritableList(XWT.getRealm(), array, classType.getComponentType());
+
+ return new ListToArrayObservableValue(writableList, activeValue);
+ }
+ }
+ }
+ return observable;
+ }
+ }
+
+ static class ObservableFactory extends ObservableValueBuilder implements IObservableFactory {
+
+ public ObservableFactory(Object control, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger) {
+ super(control, null, expressionPath, updateSourceTrigger, AUTO);
+ }
+
+ public IObservable createObservable(Object target) {
+ return observe(target);
+ }
+ }
+
+ public static IObservableValue observeValue(Object control, Object value, String fullPath, UpdateSourceTrigger updateSourceTrigger) {
+ return observeValue(control, value, new BindingExpressionPath(fullPath), updateSourceTrigger);
+ }
+
+ public static IObservableValue observeValue(Object control, Object value, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger) {
+ if(value == null) {
+ value = control;
+ }
+ ObservableValueBuilder builder = new ObservableValueBuilder(control, null, expressionPath, updateSourceTrigger, ScopeManager.VALUE);
+ return (IObservableValue)builder.observe(value);
+ }
+
+ public static IObservable observe(Object control, Object value, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger) {
+ return observe(control, value, expressionPath, updateSourceTrigger, AUTO);
+ }
+
+ public static IObservableFactory observableFactory(Object control, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger) {
+ return new ObservableFactory(control, expressionPath, updateSourceTrigger);
+ }
+
+ public static IObservable observe(Object control, Object value, String fullPath, UpdateSourceTrigger updateSourceTrigger, int observeKind) {
+ return observe(control, value, new BindingExpressionPath(fullPath), updateSourceTrigger, observeKind);
+ }
+
+ public static IObservable observe(Object control, Object value, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger, int observeKind) {
+ if(value == null) {
+ value = control;
+ }
+ ObservableValueBuilder builder = new ObservableValueBuilder(control, null, expressionPath, updateSourceTrigger, observeKind);
+ return builder.observe(value);
+ }
+
+ public static IObservableValue observeValue(Object control, Object value, Class<?> type, BindingExpressionPath expressionPath, UpdateSourceTrigger updateSourceTrigger) {
+ ObservableValueBuilder builder = new ObservableValueBuilder(control, type, expressionPath, updateSourceTrigger, ScopeManager.VALUE);
+ return (IObservableValue)builder.observe(value);
+ }
+
+ public static IValueProperty createValueProperty(Object control, Object type, BindingExpressionPath expressionPath) {
+ IValueProperty valueProperty = null;
+
+ String[] segments = expressionPath.getSegments();
+ if(segments == null || segments.length == 0) {
+ String segment = expressionPath.getFullPath();
+ valueProperty = doCreateValueProperty(type, segment);
+ } else {
+ for(String segment : segments) {
+ IValueProperty segmentValueProperty = doCreateValueProperty(type, segment);
+ if(valueProperty == null) {
+ valueProperty = segmentValueProperty;
+ } else {
+ valueProperty = valueProperty.value(segmentValueProperty);
+ }
+ type = valueProperty.getValueType();
+ }
+ }
+
+ return valueProperty;
+ }
+
+ protected static IValueProperty doCreateValueProperty(Object type, String fullPath) {
+ IDataProvider dataProvider = XWT.findDataProvider(type);
+ return dataProvider.createValueProperty(type, fullPath);
+ }
+
+ /**
+ * Reserved only for the calling from XWTLoader
+ *
+ * @param context
+ * @param data
+ * @param propertyName
+ * @return
+ */
+ public static boolean isPropertyReadOnly(IDataProvider dataProvider, BindingExpressionPath expressionPath) {
+ String[] segments = expressionPath.getSegments();
+ if(segments == null || segments.length == 0) {
+ String segment = expressionPath.getFullPath();
+ return dataProvider.isPropertyReadOnly(segment);
+ } else {
+ Object type = null;
+
+ int last = segments.length - 1;
+ for(int i = 0; i < last; i++) {
+ String segment = segments[i];
+ int length = segment.length();
+ if(length > 1 && segment.charAt(0) == '(' && segment.charAt(length - 1) == ')') {
+ // It is class
+ String path = segment.substring(1, segment.length() - 1);
+ int index = path.lastIndexOf('.');
+ if(index != -1) {
+ String className = path.substring(0, index);
+ segment = path.substring(index + 1);
+ type = dataProvider.getModelService().loadModelType(className);
+ if(type == null) {
+ throw new XWTException("Class " + className + " not found");
+ }
+ dataProvider = XWT.findDataProvider(type);
+ }
+ }
+
+ type = dataProvider.getDataType(segment);
+
+ if(type != null) {
+ dataProvider = XWT.findDataProvider(type);
+ if(dataProvider == null) {
+ throw new XWTException("Data probider is not found for the type " + type.toString());
+ }
+ } else {
+ throw new XWTException("Type is not found for the property " + segment);
+ }
+ }
+ String segment = segments[last];
+
+ int length = segment.length();
+ if(length > 1 && segment.charAt(0) == '(' && segment.charAt(length - 1) == ')') {
+ // It is class
+ String path = segment.substring(1, segment.length() - 1);
+ int index = path.lastIndexOf('.');
+ if(index != -1) {
+ String className = path.substring(0, index);
+ segment = path.substring(index + 1);
+ type = dataProvider.getModelService().loadModelType(className);
+ if(type == null) {
+ throw new XWTException("Class " + className + " not found");
+ }
+ dataProvider = XWT.findDataProvider(type);
+ }
+ }
+ return dataProvider.isPropertyReadOnly(segment);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UIResource.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UIResource.java
new file mode 100644
index 00000000000..e139c73235b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UIResource.java
@@ -0,0 +1,26 @@
+package org.eclipse.papyrus.xwt.internal.core;
+
+import java.net.URL;
+
+import org.eclipse.papyrus.xwt.IUIResource;
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+
+public class UIResource implements IUIResource {
+
+ protected Element content;
+
+ protected URL url;
+
+ public UIResource(URL url, Element content) {
+ this.content = content;
+ this.url = url;
+ }
+
+ public Element getContent() {
+ return content;
+ }
+
+ public URL getURL() {
+ return url;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UpdateSourceTrigger.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UpdateSourceTrigger.java
new file mode 100644
index 00000000000..399a682aab8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/core/UpdateSourceTrigger.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.internal.core;
+
+/**
+ * <p>
+ * Default
+ * </p>
+ * <p>
+ * The default UpdateSourceTrigger value of the binding target property. The default value for most dependency properties is PropertyChanged, while
+ * the Text property has a default value of LostFocus.
+ * </p>
+ * <p>
+ * A programmatic way to determine the default UpdateSourceTrigger value of a dependency property is to get the property metadata of the property
+ * using GetMetadata and then check the value of the DefaultUpdateSourceTrigger property.
+ * </p>
+ * <p/>
+ * <p>
+ * PropertyChanged
+ * </p>
+ * <p>
+ * Updates the binding source immediately whenever the binding target property changes.
+ * </p>
+ * <p/>
+ * <p>
+ * LostFocus
+ * </p>
+ * <p>
+ * Updates the binding source whenever the binding target element loses focus.
+ * </p>
+ *
+ * @author yyang
+ *
+ */
+public enum UpdateSourceTrigger {
+ Default, PropertyChanged, LostFocus;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/AbstractMenuItemObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/AbstractMenuItemObservableValue.java
new file mode 100644
index 00000000000..e6eb29617ad
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/AbstractMenuItemObservableValue.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.databinding.menuitem;
+
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
+import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.MenuItem;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public abstract class AbstractMenuItemObservableValue extends AbstractObservableValue {
+
+ private final MenuItem menuItem;
+
+ /**
+ * Standard constructor for a MenuItem ObservableValue. Makes sure that the observable gets disposed when the MenuItem is disposed.
+ *
+ * @param widget
+ */
+ protected AbstractMenuItemObservableValue(MenuItem menuItem) {
+ this(SWTObservables.getRealm(menuItem.getDisplay()), menuItem);
+ }
+
+ /**
+ * Constructor that allows for the setting of the realm. Makes sure that the observable gets disposed when the MenuItem is disposed.
+ *
+ * @param realm
+ * @param widget
+ * @since 1.2
+ */
+ protected AbstractMenuItemObservableValue(Realm realm, MenuItem menuItem) {
+ super(realm);
+ this.menuItem = menuItem;
+ menuItem.addDisposeListener(disposeListener);
+ }
+
+ private DisposeListener disposeListener = new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ AbstractMenuItemObservableValue.this.dispose();
+ }
+ };
+
+ /**
+ * @return Returns the MenuItem.
+ */
+ public MenuItem getMenuItem() {
+ return menuItem;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemEnabledObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemEnabledObservableValue.java
new file mode 100644
index 00000000000..decf0505e80
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemEnabledObservableValue.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.internal.databinding.menuitem;
+
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.swt.widgets.MenuItem;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class MenuItemEnabledObservableValue extends AbstractMenuItemObservableValue {
+
+ public MenuItemEnabledObservableValue(MenuItem menuItem) {
+ super(menuItem);
+ }
+
+ public MenuItemEnabledObservableValue(Realm realm, MenuItem menuItem) {
+ super(realm, menuItem);
+ }
+
+ @Override
+ protected Object doGetValue() {
+ return getMenuItem().getEnabled();
+ }
+
+ public Object getValueType() {
+ return Boolean.class;
+ }
+
+ protected void doSetValue(Object value) {
+ getMenuItem().setEnabled((Boolean)value);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemSelectionObservableValue.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemSelectionObservableValue.java
new file mode 100644
index 00000000000..a3efcb2b0fe
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/databinding/menuitem/MenuItemSelectionObservableValue.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.internal.databinding.menuitem;
+
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.swt.widgets.MenuItem;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class MenuItemSelectionObservableValue extends AbstractMenuItemObservableValue {
+
+ public MenuItemSelectionObservableValue(MenuItem menuItem) {
+ super(menuItem);
+ }
+
+ public MenuItemSelectionObservableValue(Realm realm, MenuItem menuItem) {
+ super(realm, menuItem);
+ }
+
+ @Override
+ protected Object doGetValue() {
+ return getMenuItem().getSelection();
+ }
+
+ public Object getValueType() {
+ return Boolean.class;
+ }
+
+ protected void doSetValue(Object value) {
+ getMenuItem().setSelection((Boolean)value);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ClassLoaderUtil.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ClassLoaderUtil.java
new file mode 100644
index 00000000000..577d6f4c2a0
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ClassLoaderUtil.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.ILoadingContext;
+import org.eclipse.papyrus.xwt.internal.xml.DocumentObject;
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+
+public class ClassLoaderUtil {
+
+ static final String[] DefaultPackages = new String[]{
+ /*
+ * UIElement.class.getPackage().getName(), Validation.class.getPackage().getName(), Timeline.class.getPackage().getName(),
+ * Binding.class.getPackage().getName(),
+ */};
+
+ static public Class<?> loadClass(ILoadingContext loadingContext, String className) {
+ Class<?> type = doLoadClass(loadingContext, className);
+ if(type != null) {
+ return type;
+ }
+ int index = className.indexOf('.');
+ if(index == -1) {
+ for(String packageName : DefaultPackages) {
+ type = doLoadClass(loadingContext, packageName + "." + className);
+ if(type != null) {
+ return type;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static Class<?> doLoadClass(ILoadingContext loadingContext, String className) {
+ Class<?> type = loadingContext.loadClass(className);
+ if(type != null) {
+ return type;
+ }
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e1) {
+ }
+ return null;
+ }
+
+ static public Object loadMember(ILoadingContext loadingContext, String className, String memberName, boolean raiseException) {
+ Class<?> type = loadClass(loadingContext, className);
+ return loadMember(loadingContext, type, memberName, raiseException);
+ }
+
+ static public Object loadMember(ILoadingContext loadingContext, Class<?> type, String memberName, boolean raiseException) {
+
+ try {
+ Field field = type.getField(memberName);
+ if(raiseException && !Modifier.isStatic(field.getModifiers())) {
+ throw new IllegalStateException(type.getName() + "." + memberName + " is not static member.");
+ }
+ return field.get(null);
+ } catch (Exception e) {
+ if(e instanceof NoSuchFieldException) {
+ Method method = ObjectUtil.findGetter(type, memberName, null);
+ if(raiseException && (method == null || !Modifier.isStatic(method.getModifiers()))) {
+ throw new IllegalStateException(type.getName() + "." + memberName + " is not static member.");
+ }
+ try {
+ return method.invoke(null);
+ } catch (Exception exception) {
+ e = exception;
+ }
+ }
+ if(raiseException) {
+ e.printStackTrace();
+ throw new IllegalStateException(e);
+ }
+ }
+ return null;
+ }
+
+ static public Object loadStaticMember(ILoadingContext loadingContext, Element element) {
+ String name = element.getName();
+ String namespace = element.getNamespace();
+ Object value = doLoadMember(loadingContext, name, namespace);
+ if(value != null) {
+ return value;
+ }
+ String content = element.getContent();
+ if(content == null) {
+ DocumentObject member = element.getAttribute(IConstants.XWT_NAMESPACE, IConstants.XAML_X_STATIC_MEMBER);
+ if(member == null) {
+ member = element;
+ }
+ if(member != null) {
+ content = member.getContent();
+ if(content == null) {
+ for(DocumentObject documentObject : member.getChildren()) {
+ String ns = documentObject.getNamespace();
+ String n = documentObject.getName();
+ return doLoadMember(loadingContext, n, ns);
+ }
+ }
+ }
+ } else {
+ if(IConstants.XAML_X_STATIC.equals(name) && IConstants.XWT_X_NAMESPACE.equals(namespace)) {
+ namespace = IConstants.XWT_NAMESPACE;
+ return doLoadMember(loadingContext, content, namespace);
+ }
+ }
+ // TODO
+ return null;
+ }
+
+ protected static Object doLoadMember(ILoadingContext loadingContext, String name, String namespace) {
+ int lastIndex = name.lastIndexOf('.');
+ if(lastIndex == -1) {
+ throw new IllegalStateException("Separator '.' is missing in:" + name);
+ }
+ String className = name.substring(0, lastIndex);
+ String memberName = name.substring(lastIndex + 1);
+
+ try {
+ Class<?> type = NamespaceHelper.loadCLRClass(loadingContext, className, namespace);
+ if(type != null) {
+ return ClassLoaderUtil.loadMember(loadingContext, type, memberName, true);
+ }
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/DocumentObjectSorter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/DocumentObjectSorter.java
new file mode 100644
index 00000000000..9330cfb1b2e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/DocumentObjectSorter.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.internal.utils;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.papyrus.xwt.internal.xml.Attribute;
+import org.eclipse.papyrus.xwt.internal.xml.DocumentObject;
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+
+public class DocumentObjectSorter {
+
+ public static List<DocumentObject> sortWithAttr(DocumentObject[] sourceArray, String attrName) {
+ return sortWithAttr(sourceArray, new AttrComparator(attrName), attrName);
+ }
+
+ public static List<DocumentObject> sortWithAttr(DocumentObject[] sourceArray, Comparator<Element> comparator, String attrName) {
+ List<DocumentObject> columnsList = new LinkedList<DocumentObject>();
+ for(DocumentObject column : sourceArray) {
+ Element columnElement = (Element)column;
+ Attribute indexAttr = columnElement.getAttribute(attrName);
+ if(indexAttr == null) {
+ columnsList.add(column);
+ }
+ }
+
+ List<Element> tempList = new LinkedList<Element>();
+ for(DocumentObject column : sourceArray) {
+ Element columnElement = (Element)column;
+ Attribute indexAttr = columnElement.getAttribute(attrName);
+ if(indexAttr != null) {
+ tempList.add(columnElement);
+ }
+ }
+
+ if(comparator == null) {
+ comparator = new AttrComparator(attrName);
+ }
+ Collections.sort(tempList, comparator);
+
+ for(Element columnElement : tempList) {
+ Attribute indexAttr = columnElement.getAttribute(attrName);
+ try {
+ int index = Integer.parseInt(indexAttr.getContent());
+ columnsList.add(index, columnElement);
+ } catch (Exception e) {
+ columnsList.add(columnsList.size(), columnElement);
+ }
+ }
+
+ return columnsList;
+ }
+
+ private static class AttrComparator implements Comparator<Element>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String attrName;
+
+ public AttrComparator(String attrName) {
+ this.attrName = attrName;
+ }
+
+ public int compare(Element e1, Element e2) {
+ Attribute attr1 = e1.getAttribute(attrName);
+ Attribute attr2 = e2.getAttribute(attrName);
+ String compare1 = attr1.getContent();
+ String compare2 = attr2.getContent();
+ if(compare1 == null || compare2 == null) {
+ return 0;
+ }
+ try {
+ int index1 = Integer.parseInt(compare1);
+ int index2 = Integer.parseInt(compare2);
+ return index1 > index2 ? 1 : -1;
+ } catch (Exception e) {
+ return compare1.compareTo(compare2);
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/LoggerManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/LoggerManager.java
new file mode 100644
index 00000000000..9f70cc9512f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/LoggerManager.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.internal.utils;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Logger Manager.
+ *
+ * @author jliu
+ */
+public class LoggerManager {
+
+ private static Logger logger = Logger.getLogger("org.eclipse.papyrus.xwt.utils.LoggerManager");
+
+ private LoggerManager() {
+ }
+
+ public static void log(Throwable e, String message) {
+ logger.log(Level.SEVERE, message, e);
+ }
+
+ public static void log(Throwable e) {
+ log(e, null);
+ }
+
+ public static void log(String message) {
+ log(null, message);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/NamespaceHelper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/NamespaceHelper.java
new file mode 100644
index 00000000000..553340a1eb7
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/NamespaceHelper.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.internal.utils;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.ILoadingContext;
+
+public class NamespaceHelper {
+
+ static public Class<?> loadCLRClass(ILoadingContext loadingContext, String name, String namespace) throws ClassNotFoundException {
+ // xmlns:custom="clr-namespace:SDKSample;assembly=SDKSampleLibrary"
+ if(namespace.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO)) {
+ String contentSegment = namespace.substring(IConstants.XAML_CLR_NAMESPACE_PROTO.length());
+ String packageName = contentSegment;
+ String assembly = null;
+ int index = contentSegment.indexOf(";");
+ if(index != -1) {
+ packageName = contentSegment.substring(0, index);
+ contentSegment = contentSegment.substring(index + 1);
+ if(contentSegment.startsWith(IConstants.XAML_CLR_ASSEMBLY)) {
+ assembly = contentSegment.substring(IConstants.XAML_CLR_ASSEMBLY.length());
+ } else {
+ throw new IllegalStateException(IConstants.XAML_CLR_ASSEMBLY);
+ }
+ }
+ if(assembly != null) {
+ // TODO Load jar using URLClassLoader
+ }
+ if(packageName != null && packageName.length() > 0) {
+ name = packageName + "." + name;
+ }
+ return ClassLoaderUtil.loadClass(loadingContext, name);
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObjectUtil.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObjectUtil.java
new file mode 100644
index 00000000000..227a54ae30d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObjectUtil.java
@@ -0,0 +1,399 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.XWT;
+
+/**
+ * Object Tools.
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ * @version 1.0
+ */
+public class ObjectUtil {
+
+ public static final Class<?>[] EMPTY = new Class[0];
+
+ private ObjectUtil() {
+ }
+
+ public static Class<?> normalizedType(Class<?> type) {
+ if(type == int.class) {
+ return Integer.class;
+ }
+ if(type == double.class) {
+ return Double.class;
+ }
+ if(type == float.class) {
+ return Float.class;
+ }
+ if(type == boolean.class) {
+ return Boolean.class;
+ }
+ return type;
+ }
+
+ public static boolean isAssignableFrom(Class<?> source, Class<?> target) {
+ if(normalizedType(source) == normalizedType(target)) {
+ return true;
+ }
+ return source.isAssignableFrom(target);
+ }
+
+ /**
+ * Find the compatible class. This includes superclasses, interfaces and so on.
+ *
+ * @param clazz
+ * the specified class.
+ * @return Returns the class array includes its superclasses, interfaces and itself.
+ */
+ public static final Class<?>[] findCompatibleClasses(Class<?> clazz) {
+ Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
+
+ // Add itself to list.
+ classes.add(clazz);
+
+ // Add primitive compatible type
+ if(clazz == Boolean.class) {
+ classes.add(boolean.class);
+ } else if(clazz == Byte.class) {
+ classes.add(byte.class);
+ } else if(clazz == Short.class) {
+ classes.add(short.class);
+ } else if(clazz == Integer.class) {
+ classes.add(int.class);
+ } else if(clazz == Long.class) {
+ classes.add(long.class);
+ } else if(clazz == Float.class) {
+ classes.add(float.class);
+ } else if(clazz == Double.class) {
+ classes.add(double.class);
+ } else if(clazz == Character.class) {
+ classes.add(char.class);
+ } else if(clazz == boolean.class) {
+ classes.add(Boolean.class);
+ } else if(clazz == byte.class) {
+ classes.add(Byte.class);
+ } else if(clazz == short.class) {
+ classes.add(Short.class);
+ } else if(clazz == int.class) {
+ classes.add(Integer.class);
+ } else if(clazz == long.class) {
+ classes.add(Long.class);
+ } else if(clazz == float.class) {
+ classes.add(Float.class);
+ } else if(clazz == double.class) {
+ classes.add(Double.class);
+ } else if(clazz == char.class) {
+ classes.add(Character.class);
+ }
+
+ // Add its interfaces
+ findInterfaces(classes, clazz);
+
+ // Add its superclasses
+ findSuperClasses(classes, clazz);
+
+ // At last, add Object class.
+ classes.add(Object.class);
+
+ return classes.toArray(EMPTY);
+ }
+
+ public static Object resolveValue(Object value, Class<?> targetType, Object defaultValue) {
+ return resolveValue(value, value.getClass(), targetType, defaultValue);
+ }
+
+ public static Object resolveValue(Object value, Class<?> sourceType, Class<?> targetType, Object defaultValue) {
+ IConverter converter = XWT.findConvertor(sourceType, targetType);
+ if(converter != null) {
+ return converter.convert(value);
+ }
+ return defaultValue;
+ }
+
+ /**
+ * Find compatible constructor for specified class.
+ *
+ * @param clazz
+ * the specified class.
+ * @param argumentTypes
+ * constructor argument types.
+ * @return Returns constructor instance. If snot find, returns null.
+ */
+ public static final Constructor<?> findConstructor(Class<?> clazz, Class<?>... argumentTypes) {
+
+ Class<?>[][] classesArray = new Class[argumentTypes.length][];
+
+ for(int i = 0, len = argumentTypes.length; i < len; i++) {
+ Class<?>[] classes = findCompatibleClasses(argumentTypes[i]);
+ classesArray[i] = classes;
+ }
+
+ int totalPossibles = 1;
+ for(int i = 0; i < classesArray.length; i++) {
+ totalPossibles *= classesArray[i].length;
+ }
+
+ List<Class<?>[]> classList = new ArrayList<Class<?>[]>(totalPossibles);
+ computeArguments(classList, classesArray, new Class[classesArray.length], 0);
+
+ for(Class<?>[] arguments : classList) {
+ try {
+ return clazz.getConstructor(arguments);
+ } catch (NoSuchMethodException e) {
+ continue;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Find compatible public method for specified class.
+ *
+ * @param clazz
+ * the specified class.
+ * @param name
+ * method name.
+ * @param argumentTypes
+ * method argument types. If it is a null value, system will find method without argument types.
+ * @return Returns method instance. If not find, returns null.
+ */
+ public static final Method findMethod(Class<?> clazz, String name, Class<?>... argumentTypes) {
+
+ if(argumentTypes != null && argumentTypes.length > 0) {
+
+ Class<?>[][] classesArray = new Class[argumentTypes.length][];
+
+ for(int i = 0, len = argumentTypes.length; i < len; i++) {
+ Class<?>[] classes = findCompatibleClasses(argumentTypes[i]);
+ classesArray[i] = classes;
+ }
+
+ int totalPossibles = 1;
+ for(int i = 0; i < classesArray.length; i++) {
+ totalPossibles *= classesArray[i].length;
+ }
+
+ List<Class<?>[]> classList = new ArrayList<Class<?>[]>(totalPossibles);
+ computeArguments(classList, classesArray, new Class[classesArray.length], 0);
+
+ for(Class<?>[] arguments : classList) {
+ try {
+ return clazz.getDeclaredMethod(name, arguments);
+ } catch (NoSuchMethodException e) {
+ continue;
+ }
+ }
+ } else {
+
+ // find method without argument types;
+
+ Method[] methods = clazz.getMethods();
+ for(Method method : methods) {
+ if(method.getName().equals(name)) {
+ return method;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Find compatible method for specified class.
+ *
+ * @param clazz
+ * the specified class.
+ * @param name
+ * method name.
+ * @param argumentTypes
+ * method argument types. If it is a null value, system will find method without argument types.
+ * @return Returns method instance. If not find, returns null.
+ */
+ public static final Method findDeclaredMethod(Class<?> clazz, String name, Class<?>... argumentTypes) {
+
+ if(argumentTypes != null && argumentTypes.length > 0) {
+
+ Class<?>[][] classesArray = new Class[argumentTypes.length][];
+
+ for(int i = 0, len = argumentTypes.length; i < len; i++) {
+ Class<?>[] classes = findCompatibleClasses(argumentTypes[i]);
+ classesArray[i] = classes;
+ }
+
+ int totalPossibles = 1;
+ for(int i = 0; i < classesArray.length; i++) {
+ totalPossibles *= classesArray[i].length;
+ }
+
+ List<Class<?>[]> classList = new ArrayList<Class<?>[]>(totalPossibles);
+ computeArguments(classList, classesArray, new Class[classesArray.length], 0);
+
+ for(Class<?>[] arguments : classList) {
+ try {
+ return clazz.getDeclaredMethod(name, arguments);
+ } catch (NoSuchMethodException e) {
+ continue;
+ }
+ }
+ } else {
+
+ // find method without argument types;
+ Method[] methods = clazz.getDeclaredMethods();
+ for(Method method : methods) {
+ if(method.getName().equals(name) && method.getParameterTypes().length == 0) {
+ return method;
+ }
+ }
+ }
+ Class<?> superclass = clazz.getSuperclass();
+ if(superclass != null) {
+ return findDeclaredMethod(superclass, name, argumentTypes);
+ }
+
+ return null;
+ }
+
+ /**
+ * Find property getter method for specified class.
+ *
+ * @param clazz
+ * the specified class.
+ * @param name
+ * property name
+ * @param type
+ * property type. If it is a null value, system will find the suitable method.
+ * @return Returns method instance. If not find, returns null.
+ */
+ public static final Method findGetter(Class<?> clazz, String name, Class<?> type) {
+ if(name == null || name.length() == 0) {
+ throw new IllegalArgumentException("Invalid getter method name, null value found");
+ }
+
+ String getterName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
+
+ Method method;
+ try {
+ if(clazz.isEnum()) {
+ method = clazz.getClass().getMethod(getterName, EMPTY);
+ } else {
+ method = clazz.getMethod(getterName, EMPTY);
+ }
+ } catch (NoSuchMethodException e1) {
+
+ // :Check if it is a boolean getter
+ getterName = "is" + name.substring(0, 1).toUpperCase() + name.substring(1);
+ try {
+ method = clazz.getMethod(getterName, EMPTY);
+ if(method.getReturnType() != Boolean.class && method.getReturnType() != boolean.class) {
+ return null;
+ }
+ } catch (NoSuchMethodException e2) {
+ method = findCaseIgnoreGetter(clazz, name, type);
+ }
+ // :~
+ }
+
+ if(type == null) {
+ return method;
+ } else {
+ if(method != null) {
+ Class<?> returnType = method.getReturnType();
+ Class<?>[] types = findCompatibleClasses(type);
+ for(Class<?> t : types) {
+ if(t == returnType) {
+ return method;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static Method findCaseIgnoreGetter(Class<?> clazz, String name, Class<?> type) {
+ String getterName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
+ String isName = "is" + name.substring(0, 1).toUpperCase() + name.substring(1);
+
+ for(Method element : clazz.getMethods()) {
+ if(element.getParameterTypes().length != 0) {
+ continue;
+ }
+ if(element.getName().equalsIgnoreCase(getterName)) {
+ return element;
+ }
+ if(element.getName().equalsIgnoreCase(isName) && element.getReturnType() != Boolean.class && element.getReturnType() != boolean.class) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find superclasses and add them to list.
+ */
+ private static void findSuperClasses(Set<Class<?>> list, Class<?> clazz) {
+ if(clazz != null) {
+ Class<?> superClass = clazz.getSuperclass();
+
+ if(superClass != Object.class) {
+ list.add(superClass);
+
+ findInterfaces(list, superClass);
+
+ findSuperClasses(list, superClass);
+ }
+ }
+ }
+
+ /**
+ * Find interfaces and add them to list.
+ */
+ private static void findInterfaces(Set<Class<?>> list, Class<?> clazz) {
+ if(clazz != null) {
+ Class<?>[] interfaces = clazz.getInterfaces();
+
+ for(Class<?> interfac1 : interfaces) {
+ list.add(interfac1);
+ findInterfaces(list, interfac1);
+ }
+ }
+ }
+
+ /**
+ * Combine arithmetic.
+ */
+ private static void computeArguments(List<Class<?>[]> list, Class<?>[][] arguments, Class<?>[] buffer, int start) {
+ if(start >= arguments.length) {
+ Class<?>[] classes = new Class<?>[arguments.length];
+ for(int i = 0; i < arguments.length; ++i) {
+ classes[i] = buffer[i];
+ }
+ list.add(classes);
+ return;
+ }
+
+ for(int i = 0; i < arguments[start].length; ++i) {
+ buffer[start] = arguments[start][i];
+ computeArguments(list, arguments, buffer, start + 1);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObservableValueManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObservableValueManager.java
new file mode 100644
index 00000000000..26e8b359e0b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/ObservableValueManager.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.internal.utils;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.xwt.IEventGroup;
+import org.eclipse.papyrus.xwt.IObservableValueListener;
+import org.eclipse.papyrus.xwt.XWT;
+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.papyrus.xwt.metadata.ModelUtils;
+import org.eclipse.swt.widgets.Event;
+
+public class ObservableValueManager implements IObservableValueListener {
+
+ protected HashMap<String, IObservableValue> map;
+
+ protected Object host;
+
+ public ObservableValueManager(Object host) {
+ this.host = host;
+ }
+
+ public Object getHost() {
+ return host;
+ }
+
+ public void changeValueHandle(Object object, Event event) {
+ // TODO the cast is not clean.
+ EventProperty property = (EventProperty)object;
+ IObservableValue value = map.get(property.getName());
+ if(value != null) {
+ Boolean oldValue = (Boolean)value.getValue();
+ if(oldValue == null) {
+ oldValue = false;
+ }
+ value.setValue(!oldValue);
+ }
+
+ IMetaclass metaclass = XWT.getMetaclass(host);
+
+ // TODO this conversion should be simplied
+ String eventName = ModelUtils.normalizePropertyName(property.getEvent().getName());
+ IEventGroup eventGroup = metaclass.getEventGroup(eventName);
+ if(eventGroup != null) {
+ eventGroup.fireEvent(this, property);
+ }
+ }
+
+ public void registerValue(IProperty property, IObservableValue observableValue) {
+ if(map == null) {
+ map = new HashMap<String, IObservableValue>();
+ }
+ map.put(property.getName(), observableValue);
+
+ IMetaclass metaclass = XWT.getMetaclass(host);
+ // TODO it is not clean.
+ EventProperty eventProperty = (EventProperty)property;
+
+ // TODO this conversion should be simplied
+ String eventName = ModelUtils.normalizePropertyName(eventProperty.getEvent().getName());
+ IEventGroup eventGroup = metaclass.getEventGroup(eventName);
+ if(eventGroup != null) {
+ eventGroup.registerEvent(this, property);
+ }
+ }
+
+ public IObservableValue getValue(IProperty property) {
+ if(map == null) {
+ return null;
+ }
+ return map.get(property.getName());
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/TableEditorHelper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/TableEditorHelper.java
new file mode 100644
index 00000000000..10c974074a2
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/TableEditorHelper.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.utils;
+
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+public class TableEditorHelper {
+
+ public static void initEditor(final TableItem tableItem, Control editor, final int column) {
+ if(editor instanceof Text) {
+ final Text text = (Text)editor;
+ text.setText(tableItem.getText(column));
+ text.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ tableItem.setText(column, text.getText());
+ }
+ });
+ } else if(editor instanceof CCombo) {
+ final CCombo combo = (CCombo)editor;
+ combo.setText(tableItem.getText(column));
+ combo.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ tableItem.setText(column, combo.getText());
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ tableItem.setText(column, combo.getItem(combo.getSelectionIndex()));
+ }
+ });
+ } else if(editor instanceof Combo) {
+ final Combo combo = (Combo)editor;
+ combo.setText(tableItem.getText(column));
+ combo.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ tableItem.setText(column, combo.getText());
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ tableItem.setText(column, combo.getItem(combo.getSelectionIndex()));
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/UserData.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/UserData.java
new file mode 100644
index 00000000000..1c7c7e05275
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/utils/UserData.java
@@ -0,0 +1,699 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.IObservableValueListener;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.core.IUserDataConstants;
+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.internal.core.IEventController;
+import org.eclipse.papyrus.xwt.internal.core.ScopeKeeper;
+import org.eclipse.papyrus.xwt.javabean.Controller;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.custom.ControlEditor;
+import org.eclipse.swt.custom.TableTreeItem;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Caret;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.CoolItem;
+import org.eclipse.swt.widgets.ExpandItem;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.ScrollBar;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.ToolTip;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.Widget;
+
+public class UserData {
+
+ private HashMap<Object, Object> dictionary = null;
+
+ private IObservableValueListener observableValueManager;
+
+ protected IObservableValueListener getObservableValueManager() {
+ return observableValueManager;
+ }
+
+ protected void setObservableValueManager(IObservableValueListener observableValueManager) {
+ this.observableValueManager = observableValueManager;
+ }
+
+ public void setData(Object key, Object value) {
+ if(dictionary == null) {
+ dictionary = new HashMap<Object, Object>();
+ }
+ dictionary.put(key, value);
+ if(observableValueManager != null && (key instanceof IProperty)) {
+ IObservableValue observableValue = observableValueManager.getValue((IProperty)key);
+ observableValue.setValue(value);
+ }
+ }
+
+ public Object getData(Object key) {
+ if(dictionary == null) {
+ return null;
+ }
+ return dictionary.get(key);
+ }
+
+ public Object removeData(Object key) {
+ if(dictionary == null) {
+ return null;
+ }
+ return dictionary.remove(key);
+ }
+
+ public boolean containsKey(Object key) {
+ if(dictionary == null) {
+ return false;
+ }
+ return dictionary.containsKey(key);
+ }
+
+ public Collection<Object> keySet() {
+ if(dictionary == null) {
+ return Collections.emptyList();
+ }
+ return dictionary.keySet();
+ }
+
+ public static boolean isUIElementType(Object element) {
+ if(element instanceof Class<?>) {
+ Class<?> elementType = (Class<?>)element;
+ return Widget.class.isAssignableFrom(elementType) || Viewer.class.isAssignableFrom(elementType) || ControlEditor.class.isAssignableFrom(elementType);
+ }
+ return false;
+ }
+
+ public static void bindNameContext(Object element, ScopeKeeper nameContext) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return;
+ }
+ UserData dataDictionary = updateDataDictionary(widget);
+ if(dataDictionary.getData(IUserDataConstants.XWT_NAMECONTEXT_KEY) != null) {
+ throw new IllegalStateException("Name context is already set");
+ }
+ dataDictionary.setData(IUserDataConstants.XWT_NAMECONTEXT_KEY, nameContext);
+ }
+
+ protected static UserData updateDataDictionary(Object target) {
+ Widget widget = getWidget(target);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ dataDictionary = new UserData();
+ widget.setData(IUserDataConstants.XWT_USER_DATA_KEY, dataDictionary);
+ }
+ return dataDictionary;
+ }
+
+ public static Shell findShell(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ if(widget instanceof Shell) {
+ return (Shell)widget;
+ }
+ Control parent = (Control)findParent(widget, Control.class);
+ if(parent != null) {
+ return parent.getShell();
+ }
+ return null;
+ }
+
+ /**
+ * Find the root widget used by XWT. In fact, it tries to find the root
+ * ScopeKeeper
+ *
+ * @param element
+ * @return
+ */
+ public static Widget findRootWidget(Object element) {
+ Widget root = null;
+ Widget current = getWidget(element);
+ while(current != null) {
+ ScopeKeeper scopeKeeper = findScopeKeeper(current);
+ if(scopeKeeper != null) {
+ root = current;
+ }
+ current = getTreeParent(current);
+ }
+
+ return root;
+ }
+
+ public static Composite findCompositeParent(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ Control control = getParent(widget);
+ while(control != null && !(control instanceof Composite)) {
+ control = getParent(control);
+ }
+ return (Composite)control;
+ }
+
+ public static Object findParent(Widget element, Class<?> type) {
+ Widget widget = getTreeParent(element);
+ while(widget != null && !(type.isInstance(widget))) {
+ widget = getTreeParent(widget);
+ }
+ return widget;
+ }
+
+ public static ScopeKeeper findScopeKeeper(Object element) {
+ ScopeKeeper scopeKeeper = getLocalScopeKeeper(element);
+ if(scopeKeeper != null) {
+ return scopeKeeper;
+ }
+ Widget parent = getTreeParent(element);
+ if(parent != null && !parent.isDisposed()) {
+ return findScopeKeeper(parent);
+ }
+ return null;
+ }
+
+ public static Widget findScopeRoot(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+
+ Widget current = widget;
+ while(current != null) {
+ UserData dataDictionary = (UserData)current.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ Object data = dataDictionary.getData(IUserDataConstants.XWT_NAMECONTEXT_KEY);
+ if(data != null) {
+ return current;
+ }
+ }
+
+ current = getTreeParent(current);
+ }
+
+ return null;
+ }
+
+ public static ScopeKeeper getLocalScopeKeeper(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ Object data = dataDictionary.getData(IUserDataConstants.XWT_NAMECONTEXT_KEY);
+ if(data != null) {
+ return (ScopeKeeper)data;
+ }
+ }
+ return null;
+ }
+
+ public static Object findElementByName(Object context, String name) {
+ Widget widget = getWidget(context);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ ScopeKeeper nameContext = (ScopeKeeper)dataDictionary.getData(IUserDataConstants.XWT_NAMECONTEXT_KEY);
+ if(nameContext != null) {
+ Object element = nameContext.getNamedObject(name);
+ if(element != null) {
+ return element;
+ }
+ }
+ }
+ Widget parent = getTreeParent(widget);
+ if(parent != null) {
+ return findElementByName(parent, name);
+ }
+ return null;
+ }
+
+ public static String getElementName(Object object) {
+ Widget widget = getWidget(object);
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ return (String)dataDictionary.getData(IUserDataConstants.XWT_NAME_KEY);
+ }
+ return null;
+ }
+
+ public static void setElementName(Object object, String name, boolean updateScope) {
+ Widget widget = getWidget(object);
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ dataDictionary.setData(IUserDataConstants.XWT_NAME_KEY, name);
+ if(updateScope) {
+ ScopeKeeper keeper = findScopeKeeper(object);
+ if(keeper != null) {
+ keeper.addNamedObject(name, object);
+ }
+ }
+ }
+ }
+
+ public static void setCLR(Object widget, Object type) {
+ setLocalData(widget, IUserDataConstants.XWT_CLR_KEY, type);
+ }
+
+ public static Object getCLR(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ Object data = dataDictionary.getData(IUserDataConstants.XWT_CLR_KEY);
+ if(data != null) {
+ return data;
+ }
+ }
+ Widget parent = getParent(widget);
+ if(parent != null) {
+ return getCLR(parent);
+ }
+ return null;
+ }
+
+ public static Widget getTreeParent(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ widget = (Widget)dataDictionary.getData(IUserDataConstants.XWT_PARENT_KEY);
+ if(widget != null) {
+ return widget;
+ }
+ }
+ return getParent(element);
+ }
+
+ public static Control getParent(Object element) {
+ Widget widget = getWidget(element);
+ if(widget instanceof Control) {
+ Control control = (Control)widget;
+ return control.getParent();
+ } else if(widget instanceof Menu) {
+ Menu item = (Menu)widget;
+ return item.getParent();
+ } else if(widget instanceof MenuItem) {
+ MenuItem item = (MenuItem)widget;
+ Menu menu = item.getParent();
+ if(menu == null) {
+ return null;
+ }
+ return menu.getParent();
+ } else if(widget instanceof ScrollBar) {
+ ScrollBar item = (ScrollBar)widget;
+ return item.getParent();
+ } else if(widget instanceof ToolTip) {
+ ToolTip item = (ToolTip)widget;
+ return item.getParent();
+ } else if(widget instanceof CoolItem) {
+ CoolItem item = (CoolItem)widget;
+ return item.getParent();
+ } else if(widget instanceof CTabItem) {
+ CTabItem item = (CTabItem)widget;
+ return item.getParent();
+ } else if(widget instanceof ExpandItem) {
+ ExpandItem item = (ExpandItem)widget;
+ return item.getParent();
+ } else if(widget instanceof TabItem) {
+ TabItem item = (TabItem)widget;
+ return item.getParent();
+ } else if(widget instanceof TableColumn) {
+ TableColumn item = (TableColumn)widget;
+ return item.getParent();
+ } else if(widget instanceof TableItem) {
+ TableItem item = (TableItem)widget;
+ return item.getParent();
+ } else if(widget instanceof TableTreeItem) {
+ TableTreeItem item = (TableTreeItem)widget;
+ return item.getParent();
+ } else if(widget instanceof ToolItem) {
+ ToolItem item = (ToolItem)widget;
+ return item.getParent();
+ } else if(widget instanceof TreeColumn) {
+ TreeColumn item = (TreeColumn)widget;
+ return item.getParent();
+ } else if(widget instanceof TreeItem) {
+ TreeItem item = (TreeItem)widget;
+ return item.getParent();
+ } else if(widget instanceof Caret) {
+ Caret item = (Caret)widget;
+ return item.getParent();
+ }
+ return null;
+ }
+
+ public static IEventController findEventController(Object widget) {
+ return (IEventController)findData(widget, IUserDataConstants.XWT_CONTROLLER_KEY);
+ }
+
+ public static Object getDataContext(Object widget) {
+ return findData(widget, IUserDataConstants.XWT_DATACONTEXT_KEY);
+ }
+
+ public static IBindingContext getBindingContext(Object widget) {
+ return (IBindingContext)findData(widget, IUserDataConstants.XWT_BINDING_CONTEXT_KEY);
+ }
+
+ public static TriggerBase[] getTriggers(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return TriggerBase.EMPTY_ARRAY;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ TriggerBase[] triggers = (TriggerBase[])dataDictionary.getData(IUserDataConstants.XWT_TRIGGERS_KEY);
+ if(triggers != null) {
+ return triggers;
+ }
+ }
+ return TriggerBase.EMPTY_ARRAY;
+ }
+
+ public static void setTriggers(Object widget, TriggerBase[] triggers) {
+ setLocalData(widget, IUserDataConstants.XWT_TRIGGERS_KEY, triggers);
+ }
+
+ public static Widget getDataContextHost(Object element) {
+ Widget widget = getWidget(element);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ Object host = null;
+ if(dataDictionary != null) {
+ host = dataDictionary.getData(IUserDataConstants.XWT_DATACONTEXT_KEY);
+ if(host != null) {
+ return widget;
+ }
+ }
+ Widget parent = widget;
+ while(parent != null) {
+ dataDictionary = (UserData)parent.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ host = dataDictionary.getData(IUserDataConstants.XWT_DATACONTEXT_KEY);
+ if(host != null) {
+ return parent;
+ }
+ parent = (Widget)dataDictionary.getData(IUserDataConstants.XWT_PARENT_KEY);
+ } else {
+ parent = getParent(parent);
+ }
+ }
+ return null;
+ }
+
+ public static void setBindingContext(Object widget, Object bindingContext) {
+ setLocalData(widget, IUserDataConstants.XWT_BINDING_CONTEXT_KEY, bindingContext);
+ }
+
+ public static void setDataContext(Object widget, Object dataContext) {
+ setLocalData(widget, IUserDataConstants.XWT_DATACONTEXT_KEY, dataContext);
+ }
+
+ public static Widget getWidget(Object target) {
+ if(JFacesHelper.isViewer(target)) {
+ return JFacesHelper.getControl(target);
+ } else if(target instanceof Widget) {
+ return (Widget)target;
+ } else if(target instanceof TableViewerColumn) {
+ return ((TableViewerColumn)target).getColumn();
+ } else if(target instanceof ControlEditor) {
+ return ((ControlEditor)target).getEditor();
+ }
+ return null;
+ }
+
+ public static Viewer getLocalViewer(Object object) {
+ return (Viewer)getLocalData(object, IUserDataConstants.XWT_VIEWER_KEY);
+ }
+
+ public static Object getLocalDataContext(Object object) {
+ return getLocalData(object, IUserDataConstants.XWT_DATACONTEXT_KEY);
+ }
+
+ public static boolean hasLocalDataContext(Object object) {
+ return hasLocalData(object, IUserDataConstants.XWT_DATACONTEXT_KEY);
+ }
+
+ public static Object getLocalData(Object object, IProperty property) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ return null;
+ }
+ return dataDictionary.getData(property);
+ }
+
+ public static Object getLocalData(Object object, String key) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return null;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ return null;
+ }
+ return dataDictionary.getData(key);
+ }
+
+ public static boolean hasLocalData(Object object, String propertyName) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return false;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ return false;
+ }
+ return dataDictionary.containsKey(propertyName);
+ }
+
+ public static boolean hasLocalData(Object object, IProperty property) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return false;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ return false;
+ }
+ return dataDictionary.containsKey(property);
+ }
+
+ public static void removeLocalData(Object object, IProperty property) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ return;
+ }
+ dataDictionary.removeData(property);
+ }
+
+ public static void removeLocalData(Object object, String key) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return;
+ }
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary == null) {
+ return;
+ }
+ dataDictionary.removeData(key);
+ }
+
+ public static Map<String, Object> getLocalResources(Object object) {
+ return (Map<String, Object>)getLocalData(object, IUserDataConstants.XWT_RESOURCES_KEY);
+ }
+
+ public static Object findResource(Object object, String key) {
+ Map<String, Object> map = (Map<String, Object>)getLocalData(object, IUserDataConstants.XWT_RESOURCES_KEY);
+ if(map.containsKey(key)) {
+ return map.get(key);
+ }
+
+ Object parent = getTreeParent(object);
+ if(parent != null) {
+ return findResource(parent, key);
+ }
+ return null;
+ }
+
+ public static void setResources(Object object, Map<?, ?> resources) {
+ setLocalData(object, IUserDataConstants.XWT_RESOURCES_KEY, resources);
+ }
+
+ public static void setParent(Object object, Object parent) {
+ setLocalData(object, IUserDataConstants.XWT_PARENT_KEY, parent);
+ }
+
+ public static void setViewer(Object object, Object parent) {
+ setLocalData(object, IUserDataConstants.XWT_VIEWER_KEY, parent);
+ }
+
+ public static void setEventController(Object object, IEventController controller) {
+ setLocalData(object, IUserDataConstants.XWT_CONTROLLER_KEY, controller);
+ }
+
+ public static IEventController updateEventController(Object object) {
+ UserData dataDictionary = updateDataDictionary(object);
+ IEventController controller = (IEventController)dataDictionary.getData(IUserDataConstants.XWT_CONTROLLER_KEY);
+ if(controller == null) {
+ controller = new Controller();
+ dataDictionary.setData(IUserDataConstants.XWT_CONTROLLER_KEY, controller);
+ }
+ return controller;
+ }
+
+ public static void setLocalData(Object object, String key, Object value) {
+ UserData dataDictionary = updateDataDictionary(object);
+ dataDictionary.setData(key, value);
+ }
+
+ public static void setLocalData(Object object, IProperty property, Object value) {
+ UserData dataDictionary = updateDataDictionary(object);
+ dataDictionary.setData(property, value);
+ }
+
+ public static IObservableValueListener getObservableValueManager(Object object) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return null;
+ }
+
+ UserData userData = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(userData != null) {
+ return userData.getObservableValueManager();
+ }
+ return null;
+ }
+
+ public static void setObservableValueManager(Object object, IObservableValueListener eventManager) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ throw new IllegalStateException("Not SWT Widget");
+ }
+ UserData userData = updateDataDictionary(object);
+ userData.setObservableValueManager(eventManager);
+ }
+
+ public static Object findData(Object object, String key) {
+ Widget widget = getWidget(object);
+ if(widget == null) {
+ return Collections.EMPTY_MAP;
+ }
+
+ UserData dataDictionary = (UserData)widget.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ Object resources = null;
+ if(dataDictionary != null) {
+ resources = dataDictionary.getData(key);
+ if(resources != null) {
+ return resources;
+ }
+ }
+ Widget parent = widget;
+ while(parent != null) {
+ dataDictionary = (UserData)parent.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ resources = dataDictionary.getData(key);
+ if(resources != null) {
+ return resources;
+ }
+ parent = (Widget)dataDictionary.getData(IUserDataConstants.XWT_PARENT_KEY);
+ } else {
+ parent = getParent(parent);
+ }
+ }
+ return null;
+ }
+
+ public static Map<?, ?> getResources(Object object) {
+ return (Map<?, ?>)findData(object, IUserDataConstants.XWT_RESOURCES_KEY);
+ }
+
+ public static void setObjectName(Object object, String name) {
+ Widget widget = getWidget(object);
+ ScopeKeeper nameScoped;
+ if(UserData.findElementByName(widget, name) != null) {
+ // throw an exception or log a message?
+ return;
+ }
+ Widget parent = UserData.getTreeParent(widget);
+ UserData dataDictionary = (UserData)parent.getData(IUserDataConstants.XWT_USER_DATA_KEY);
+ if(dataDictionary != null) {
+ if(dataDictionary.getData(IUserDataConstants.XWT_NAMECONTEXT_KEY) != null) {
+ nameScoped = (ScopeKeeper)dataDictionary.getData(IUserDataConstants.XWT_NAMECONTEXT_KEY);
+ } else {
+ ScopeKeeper parentNameScope = findScopeKeeper(parent);
+ nameScoped = new ScopeKeeper(parentNameScope, widget);
+ bindNameContext(parent, nameScoped);
+ }
+ nameScoped.addNamedObject(name, widget);
+ }
+ // throw an exception or log a message?
+ }
+
+ public static IBindingContext createBindingContext(Object host) {
+ Widget widget = getWidget(host);
+ final IBindingContext dataBindingContext = new BindingContext(widget);
+ dataBindingContext.setRealm(XWT.getRealm());
+ widget.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ dataBindingContext.dispose();
+ }
+ });
+
+ UserData.setLocalData(host, IUserDataConstants.XWT_BINDING_CONTEXT_KEY, dataBindingContext);
+
+ return dataBindingContext;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Attribute.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Attribute.java
new file mode 100644
index 00000000000..6cd357207f4
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Attribute.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.xml;
+
+import java.util.Collection;
+
+/**
+ * @author yyang
+ * @version 1.0
+ */
+public class Attribute extends Element {
+
+ protected String namePrefix;
+
+ /**
+ * @param manager
+ * @param namespace
+ * @param name
+ * @param id
+ */
+ public Attribute(String namespace, String name, String id) {
+ super(namespace, name, null);
+ assert id != null;
+ setId(id);
+ }
+
+ public Attribute(String namespace, String name, String path, String id, Collection<Attribute> attributes) {
+ super(namespace, name, path, attributes, null);
+ assert id != null;
+ setId(id);
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ Attribute attribute = (Attribute)super.clone();
+ attribute.setId(getId());
+ return attribute;
+ }
+
+ public String getNamePrefix() {
+ return namePrefix;
+ }
+
+ public void setNamePrefix(String namePrefix) {
+ this.namePrefix = namePrefix;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentObject.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentObject.java
new file mode 100644
index 00000000000..dbe01377726
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentObject.java
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * 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.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Observable;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.xml.sax.SAXException;
+
+/**
+ * @author yyang
+ * @version 1.0
+ */
+public class DocumentObject extends Observable implements Cloneable {
+
+ private String id;
+
+ private String name;
+
+ private String namespace;
+
+ private String content;
+
+ private List<DocumentObject> children;
+
+ protected DocumentObject parent;
+
+ /**
+ * @param manager
+ * @param namespace
+ * @param name
+ */
+ public DocumentObject(String namespace, String name) {
+ assert namespace != null;
+ assert name != null;
+ this.children = new LinkedList<DocumentObject>();
+ setNamespace(namespace);
+ setName(name);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#addChild(org.soyatec.xaml.IDocumentObject )
+ */
+ public void addChild(DocumentObject child) {
+ assert child != null;
+
+ if(children.add(child)) {
+ DocumentObject oParent = (DocumentObject)(child).getParent();
+ if(oParent != null) {
+ oParent.delChild(child);
+ }
+ // Assign the new parent.
+ ((DocumentObject)child).setParent(this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#getChildren()
+ */
+ public DocumentObject[] getChildren() {
+ return children.toArray(IConstants.EMPTY_DOCOBJ_ARRAY);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#getContent()
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#getId()
+ */
+ public String getId() {
+ return id;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#getNamespace()
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#hasCildren()
+ */
+ public boolean hasChildren() {
+ return !children.isEmpty();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#include(java.io.InputStream)
+ */
+ public void include(ElementManager elementManager, InputStream input) throws IOException {
+ try {
+ elementManager.load(input, this);
+ } catch (SAXException e) {
+ throw new IOException(e.getLocalizedMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#include(java.lang.String)
+ */
+ public void include(ElementManager elementManager, String path) throws IOException {
+ InputStream input = elementManager.getDocumentRoot().openStream(path);
+ if(input != null) {
+ include(elementManager, input);
+ }
+ input.close();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentObject#setContent(java.lang.String)
+ */
+ public void setContent(String text) {
+ this.content = text;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ DocumentObject docobj = (DocumentObject)super.clone();
+
+ // Clear object id.
+ docobj.id = null;
+
+ // Clone children.
+ for(DocumentObject child : getChildren()) {
+ DocumentObject nChild = (DocumentObject)child.clone();
+ docobj.addChild(nChild);
+ }
+
+ return docobj;
+ }
+
+ /**
+ * @param id
+ * the id to set
+ */
+ protected void setId(String id) {
+ if(this.id != null) {
+ throw new IllegalStateException("Element id is already defined");
+ }
+
+ assert id != null;
+
+ this.id = id;
+ }
+
+ /**
+ * @param namespace
+ * the namespace to set
+ * @uml.property name="namespace"
+ */
+ protected void setNamespace(String namespace) {
+ assert namespace != null : "Element namespace is null";
+ assert this.namespace != null : "Element namepsace is defined";
+
+ this.namespace = namespace;
+ }
+
+ /**
+ * @param name
+ * the name to set
+ * @uml.property name="name"
+ */
+ protected void setName(String name) {
+ assert name != null : "Element name is null";
+ assert this.name != null : "Element name is defined";
+
+ this.name = name;
+ }
+
+ /**
+ * Remove child from parent.
+ *
+ * @param child
+ * the removed parent.
+ */
+ protected void delChild(DocumentObject child) {
+ assert child != null;
+
+ if(child instanceof Element) {
+ DocumentObject parent = ((Element)child).getParent();
+ if(parent != null && parent.equals(this)) {
+ children.remove(child);
+ ((Element)child).setParent(null);
+ }
+ }
+ }
+
+ public DocumentObject getParent() {
+ return parent;
+ }
+
+ public void setParent(DocumentObject parent) {
+ this.parent = parent;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentRoot.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentRoot.java
new file mode 100644
index 00000000000..f8ac63bb79d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/DocumentRoot.java
@@ -0,0 +1,463 @@
+/*******************************************************************************
+ * 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.xml;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWTException;
+
+/**
+ * @author yyang
+ * @since 1.0
+ */
+public class DocumentRoot {
+
+ /**
+ * The file type(Can be resolved by java.io.File)
+ */
+ public static final int TYPE_FILE = 0;
+
+ /**
+ * The path type(Can be resolved by java.net.URL)
+ */
+ public static final int TYPE_PATH = 1;
+
+ /**
+ * The zip format.
+ */
+ public static final int FORMAT_ZIP = 2;
+
+ /**
+ * The gzip format.
+ */
+ public static final int FORMAT_GZIP = 3;
+
+ /**
+ * The plain format.
+ */
+ public static final int FORMAT_NONE = 4;
+
+ private int type = TYPE_PATH;
+
+ private int format = FORMAT_NONE;
+
+ /**
+ * The absolute path.
+ */
+ private String basePath;
+
+ /**
+ * The relative path.
+ */
+ private URL baseURL;
+
+ /**
+ * The main file name.
+ */
+ private String baseFile;
+
+ private static URL DOCUMENT_ROOT;
+
+ static {
+ try {
+ DOCUMENT_ROOT = new File(System.getProperty("user.dir")).toURI().toURL();
+ } catch (MalformedURLException e) {
+ DOCUMENT_ROOT = null;
+ }
+ }
+
+ public DocumentRoot() {
+ reset();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentRoot#getFormat()
+ */
+ public int getFormat() {
+ return format;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentRoot#getType()
+ */
+ public int getType() {
+ return type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentRoot#getPath()
+ */
+ public URL getPath() {
+ return baseURL;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentRoot#getFile()
+ */
+ public String getFile() {
+ return baseFile;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentRoot#openStream()
+ */
+ public InputStream openStream() throws IOException {
+ switch(format) {
+ case FORMAT_GZIP:
+ return new GZIPInputStream(new URL(basePath + "/" + baseFile).openStream());
+ default:
+ return new URL(basePath + "/" + baseFile).openStream();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IDocumentRoot#openStream(java.lang.String)
+ */
+ public InputStream openStream(String path) throws IOException {
+ assert path != null;
+ InputStream in = null;
+
+ if(path.indexOf(':') < 0) {
+ if(format == FORMAT_ZIP) {
+ // If it is zip format, that means all directories and files in
+ // zip file are extracted to temporary directory.
+ File file = new File(basePath + "/" + path);
+ in = new FileInputStream(file);
+ } else {
+ // Else, maybe the file parent or url path.
+ switch(type) {
+ case TYPE_FILE:
+ File file;
+ if(path.startsWith("/")) {
+ // Use absolute path
+ file = new File(path);
+ } else {
+ // Use relative path
+ file = new File(basePath + "/" + path);
+ }
+ in = new FileInputStream(file);
+ break;
+ case TYPE_PATH:
+ URL url = new URL(basePath + "/" + path);
+ in = url.openStream();
+ break;
+ }
+ }
+ } else {
+ if(path.startsWith("classpath:")) {
+ // Use class path
+ String p = path.substring(10);
+ in = getClass().getResourceAsStream(p);
+ if(in == null) {
+ in = String.class.getResourceAsStream(p);
+ }
+ if(in == null) {
+ in = Thread.currentThread().getClass().getResourceAsStream(p);
+ }
+ if(in == null) {
+ throw new IOException("File not found in classpath: " + p);
+ }
+ } else {
+ File file = new File(path);
+ if(file.exists()) {
+ // Use Windows File path. For example, G:\\somefile.txt
+ in = new FileInputStream(file);
+ } else {
+ // Use URL path
+ in = new URL(path).openStream();
+ }
+ }
+ }
+
+ // Automatically select the stream type
+ PushbackInputStream pis = new PushbackInputStream(in, 4);
+ if(Format.isGZIP(pis)) {
+ return new GZIPInputStream(pis);
+ } else if(Format.isZIP(pis)) {
+ ZipInputStream zis = new ZipInputStream(pis);
+ // Skip entry of directory or file which contains directory
+ // path("someDirectory/someFile.suffix").
+ for(ZipEntry entry = zis.getNextEntry(); entry != null && (entry.isDirectory() || entry.getName().indexOf('/') != -1); entry = zis.getNextEntry());
+ return zis;
+ } else {
+ return pis;
+ }
+ }
+
+ /**
+ * This method is used in <code>ModelLoader</code>
+ *
+ * @param file
+ * the xaml file path.
+ */
+ protected void init(InputStream inputStream, String path) throws IOException {
+ path = path.replace('\\', '/');
+ File file = new File(path);
+ if(inputStream == null && file.exists()) {
+ // Is file
+ init(file);
+ } else {
+ // Is URL
+ basePath = null;
+ baseURL = new URL(path);
+ PushbackInputStream pis = null;
+ boolean shouldClose_pis = false;
+ if(inputStream instanceof PushbackInputStream) {
+ pis = (PushbackInputStream)inputStream;
+ } else {
+ if(inputStream == null) {
+ pis = new PushbackInputStream(baseURL.openStream(), 4);
+ shouldClose_pis = true;
+ } else {
+ pis = new PushbackInputStream(inputStream, 4);
+ }
+ }
+ if(Format.isGZIP(pis)) {
+ format = FORMAT_GZIP;
+ } else if(Format.isZIP(pis)) {
+ format = FORMAT_ZIP;
+ File tempDir = extractZipToTemporary(pis);
+ basePath = "file:/" + tempDir.getAbsolutePath();
+ baseFile = getMainFile(tempDir);
+ }
+ if(shouldClose_pis) {
+ pis.close();
+ }
+
+ if(basePath == null) {
+ while(path.endsWith("/")) {
+ path = path.substring(0, path.length() - 1);
+ }
+
+ int lastIndex = path.lastIndexOf("/");
+ if(lastIndex > 0) {
+ basePath = path.substring(0, lastIndex);
+ baseFile = path.substring(lastIndex + 1);
+ baseURL = new URL(basePath);
+ } else {
+ basePath = System.getProperty("user.dir");
+ baseURL = new File(basePath).toURI().toURL();
+ baseFile = path;
+ }
+ }
+
+ type = TYPE_PATH;
+ }
+ }
+
+ /**
+ * This method is used in <code>ModelLoader</code>
+ */
+ protected void reset() {
+ type = TYPE_PATH;
+ format = FORMAT_NONE;
+ baseURL = DOCUMENT_ROOT;
+ basePath = DOCUMENT_ROOT.toString();
+ baseFile = null;
+ }
+
+ /**
+ * This method is used in <code>ModelLoader</code>
+ *
+ * @param file
+ * the XAML file.
+ */
+ private void init(File file) throws IOException {
+ FileInputStream fis = new FileInputStream(file);
+ PushbackInputStream pis = new PushbackInputStream(fis, 4);
+ baseURL = file.getParentFile().toURI().toURL();
+ basePath = baseURL.toString();
+ baseFile = file.getName();
+ if(Format.isGZIP(pis)) {
+ format = FORMAT_GZIP;
+ } else if(Format.isZIP(pis)) {
+ format = FORMAT_ZIP;
+ File tempDir = extractZipToTemporary(pis);
+ basePath = "file:/" + tempDir.getAbsolutePath();
+ baseFile = getMainFile(tempDir);
+ baseURL = file.toURI().toURL();
+ }
+
+ type = TYPE_FILE;
+ }
+
+ private String getMainFile(File tempDir) {
+ File[] tempFiles = tempDir.listFiles(new FileFilter() {
+
+ public boolean accept(File pathname) {
+ return pathname.isFile() && pathname.getName().toLowerCase().endsWith(IConstants.XWT_EXTENSION_SUFFIX);
+ }
+ });
+ for(File tempFile : tempFiles) {
+ return tempFile.getName();
+ }
+ return null;
+ }
+
+ /**
+ * Extract zip stream to temporary directory.
+ *
+ * @param stream
+ * zip stream.
+ * @return Returns the directory file the zip stream extracted.
+ */
+ private File extractZipToTemporary(InputStream stream) throws IOException {
+ File file = new File(System.getProperty("java.io.tmpdir") + "/cb" + System.currentTimeMillis() + Math.random());
+ if(!file.mkdir()) {
+ throw new XWTException("Folder creation fails: " + file.toString());
+ }
+ file.deleteOnExit();
+
+ String directory = file.getAbsolutePath();
+ ZipInputStream in = new ZipInputStream(stream);
+ ZipEntry z;
+ while((z = in.getNextEntry()) != null) {
+ if(z.isDirectory()) {
+ String name = z.getName();
+ name = name.substring(0, name.length() - 1);
+ File f = new File(directory + File.separator + name);
+ if(!f.mkdir()) {
+ throw new XWTException("Folder creation fails: " + f.toString());
+ }
+ f.deleteOnExit();
+ } else {
+ File f = new File(directory + File.separator + z.getName());
+ if(!f.createNewFile()) {
+ throw new XWTException("File creation fails: " + f.toString());
+ }
+ f.deleteOnExit();
+ FileOutputStream out = new FileOutputStream(f);
+ byte[] cache = new byte[4096];
+ for(int i = in.read(cache); i != -1; i = in.read(cache)) {
+ out.write(cache, 0, i);
+ }
+ out.close();
+ }
+ }
+ in.close();
+
+ return file;
+ }
+
+ /**
+ * File format uitility.
+ * <p>
+ * To check the format of file or stream.
+ * </p>
+ *
+ */
+ static class Format {
+
+ /**
+ * Check the stream is a gzip format or not.
+ *
+ * @param stream
+ * the checked stream.
+ * @return Returns true is the stream is a gzip format.
+ */
+ public static boolean isGZIP(PushbackInputStream stream) throws IOException {
+ assert stream != null;
+
+ byte[] cachedBytes = new byte[2];
+ if(stream.read(cachedBytes) != cachedBytes.length) {
+ throw new RuntimeException("data content wrong.");
+ }
+ stream.unread(cachedBytes);
+ // GZIP's header data starts with two bytes{1F,8B},
+ if((cachedBytes[0] & 0xff) == 0x1f && (cachedBytes[1] & 0xff) == 0x8b) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Check the file is a gzip format or not.
+ *
+ * @param file
+ * the checked file.
+ * @return Returns true is the file is a gzip format.
+ */
+ public static boolean isGZIP(File file) throws IOException {
+ assert file != null;
+
+ FileInputStream fis = new FileInputStream(file);
+ PushbackInputStream pis = new PushbackInputStream(fis, 2);
+ boolean returnValue = isGZIP(pis);
+ pis.close();
+ return returnValue;
+ }
+
+ /**
+ * Check the stream is a zip format or not.
+ *
+ * @param stream
+ * the checked stream.
+ * @return Returns true is the stream is a zip format.
+ */
+ public static boolean isZIP(PushbackInputStream stream) throws IOException {
+ assert stream != null;
+
+ byte[] cachedBytes = new byte[4];
+ if(stream.read(cachedBytes) != cachedBytes.length) {
+ throw new RuntimeException("data content wrong.");
+ }
+ stream.unread(cachedBytes);
+ // ZIP's header data starts with four bytes{0x50, 0x4b, 0x03, 0x04},
+ if((cachedBytes[0] & 0xff) == 0x50 && (cachedBytes[1] & 0xff) == 0x4b && (cachedBytes[2] & 0xff) == 0x03 && (cachedBytes[3] & 0xff) == 0x04) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Check the file is a zip format or not.
+ *
+ * @param file
+ * the checked file.
+ * @return Returns true is the file is a zip format.
+ */
+ public static boolean isZIP(File file) throws IOException {
+ assert file != null;
+
+ FileInputStream fis = new FileInputStream(file);
+ PushbackInputStream pis = new PushbackInputStream(fis, 4);
+ boolean returnValue = isZIP(pis);
+ pis.close();
+ return returnValue;
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Element.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Element.java
new file mode 100644
index 00000000000..8f5f6f5dadb
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/Element.java
@@ -0,0 +1,261 @@
+/*******************************************************************************
+ * 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.xml;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+
+/**
+ * @since 1.0
+ * @author yyang
+ */
+public class Element extends DocumentObject {
+
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ private String path;
+
+ private Map<String, Attribute> originalAttributes;
+
+ private Map<String, Map<String, Attribute>> externalAttributes;
+
+ private String[] xmlnsMapping;
+
+ /**
+ * @return the path of this element, i.e. indexes of this element and its parents in XML.
+ */
+ public String getPath() {
+ return path;
+ }
+
+ public String getXmlns(String prefix) {
+ if(prefix == null) {
+ prefix = "";
+ }
+ if(xmlnsMapping != null) {
+ for(int i = 0; i < xmlnsMapping.length; i++) {
+ if(prefix.equals(xmlnsMapping[i++])) {
+ return xmlnsMapping[i];
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Default constructor
+ *
+ * @param context
+ * bundle context
+ * @param namespace
+ * element namespace
+ * @param name
+ * element name
+ * @param originalAttributes
+ * element arributes
+ */
+ public Element(String namespace, String name, Map<String, String> xmlnsMapping) {
+ this(namespace, name, null, null, xmlnsMapping);
+ }
+
+ public Element(String namespace, String name, String path, Collection<Attribute> attributes, Map<String, String> xmlnsMapping) {
+ super(namespace, name);
+ this.path = path;
+ if(xmlnsMapping != null) {
+ this.xmlnsMapping = new String[xmlnsMapping.size() * 2];
+ int i = 0;
+ for(Map.Entry<String, String> entry : xmlnsMapping.entrySet()) {
+ String key = entry.getKey();
+ if(key == null) {
+ key = "";
+ }
+ this.xmlnsMapping[i++] = key;
+ this.xmlnsMapping[i++] = entry.getValue();
+ }
+ }
+
+ this.originalAttributes = Collections.emptyMap();
+ this.externalAttributes = Collections.emptyMap();
+
+ if(attributes != null) {
+ for(Attribute attribute : attributes) {
+ setInternalAttribute(attribute);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.eface.core.IElement#attributeNames()
+ */
+ public String[] attributeNames() {
+ return originalAttributes.keySet().toArray(EMPTY_STRING_ARRAY);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.eface.core.IElement#attributeNamespaces()
+ */
+ public String[] attributeNamespaces() {
+ return externalAttributes.keySet().toArray(EMPTY_STRING_ARRAY);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seecom.soyatec.eface.core.IElement#setAttribute(com.soyatec.eface.core. IAttribute)
+ */
+ public void setAttribute(Attribute attribute) {
+ setInternalAttribute(attribute);
+ firePropertyChanged(attribute);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.eface.IElement#attributeNames(java.lang.String)
+ */
+ public String[] attributeNames(String namespace) {
+ if(getNamespace().equals(namespace)) {
+ return attributeNames();
+ }
+ Map<String, Attribute> externalAttribute = externalAttributes.get(namespace);
+ if(externalAttribute != null) {
+ return externalAttribute.keySet().toArray(EMPTY_STRING_ARRAY);
+ } else {
+ return Core.EMPTY_STRING_ARRAY;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.eface.core.IElement#getAttribute(java.lang.String)
+ */
+ public Attribute getAttribute(String name) {
+ assert name != null;
+ return originalAttributes.get(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.eface.core.IElement#getAttribute(java.lang.String, java.lang.String)
+ */
+ public Attribute getAttribute(String namespace, String name) {
+ Map<String, Attribute> externalAttribute = externalAttributes.get(namespace);
+ if(externalAttribute != null) {
+ return externalAttribute.get(name);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ Element element = (Element)super.clone();
+
+ element.parent = null;
+
+ if(originalAttributes.isEmpty()) {
+ originalAttributes = Collections.emptyMap();
+ } else {
+ element.originalAttributes = new LinkedHashMap<String, Attribute>(originalAttributes.size());
+ for(String attrName : originalAttributes.keySet()) {
+ Attribute attrValue = (Attribute)originalAttributes.get(attrName).clone();
+ element.originalAttributes.put(attrName, attrValue);
+ }
+ }
+
+ if(externalAttributes.isEmpty()) {
+ element.originalAttributes = Collections.emptyMap();
+ } else {
+ element.externalAttributes = new LinkedHashMap<String, Map<String, Attribute>>(externalAttributes.size());
+ for(String ns : externalAttributes.keySet()) {
+ Map<String, Attribute> oAttributes = externalAttributes.get(ns);
+ Map<String, Attribute> nAttributes = new LinkedHashMap<String, Attribute>(oAttributes.size());
+ for(Map.Entry<String, Attribute> entry : oAttributes.entrySet()) {
+ String attrName = entry.getKey();
+ Attribute attrValue = (Attribute)entry.getValue().clone();
+ nAttributes.put(attrName, attrValue);
+ }
+ element.externalAttributes.put(ns, nAttributes);
+ }
+ }
+
+ return element;
+ }
+
+ protected void setAttributes(Collection<Attribute> attributes) {
+ for(Attribute attribute : attributes) {
+ setInternalAttribute(attribute);
+ }
+ firePropertyChanged(attributes);
+ }
+
+ private void firePropertyChanged(Attribute attribute) {
+ notifyObservers(attribute);
+ }
+
+ private void firePropertyChanged(Collection<Attribute> attributes) {
+ notifyObservers(attributes);
+ }
+
+ private boolean isXWTNamespace(String namespace) {
+ String scopeNamespace = getNamespace();
+ if(namespace == null || "".equals(namespace)) {
+ return true;
+ }
+ if(scopeNamespace.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO) || scopeNamespace.equals(IConstants.XWT_NAMESPACE)) {
+ return namespace.equalsIgnoreCase(scopeNamespace) || namespace.equals(IConstants.XWT_NAMESPACE);
+ }
+ return false;
+ }
+
+ /**
+ * Set attribute without notifying event.
+ *
+ * @param attribute
+ * the modified attribute.
+ */
+ private void setInternalAttribute(Attribute attribute) {
+ assert attribute != null;
+
+ String namespace = attribute.getNamespace();
+ String name = attribute.getName();
+
+ if(isXWTNamespace(namespace)) {
+ if(originalAttributes == Collections.EMPTY_MAP) {
+ originalAttributes = new LinkedHashMap<String, Attribute>();
+ }
+ originalAttributes.put(name, attribute);
+ } else {
+ Map<String, Attribute> externalAttribute = externalAttributes.get(namespace);
+ if(externalAttribute == null) {
+ externalAttribute = new HashMap<String, Attribute>();
+ }
+ if(externalAttributes == Collections.EMPTY_MAP) {
+ externalAttributes = new LinkedHashMap<String, Map<String, Attribute>>();
+ }
+ externalAttribute.put(name, attribute);
+ externalAttributes.put(namespace, externalAttribute);
+ }
+ ((DocumentObject)attribute).setParent(this);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementHandler.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementHandler.java
new file mode 100644
index 00000000000..bb65bc61ea7
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementHandler.java
@@ -0,0 +1,797 @@
+/*******************************************************************************
+ * 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.xml;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.Stack;
+import java.util.StringTokenizer;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWT;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.Locator2;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * XAML-DOM handler.
+ *
+ * @author yyang
+ * @version 1.0
+ */
+class ElementHandler extends DefaultHandler implements ContentHandler {
+
+ private Stack<StringBuffer> bufferStack = new Stack<StringBuffer>();
+
+ private static final String[] BINDING_PROPERTIES = new String[]{ "path", "validationRule", "converter" };
+
+
+ /**
+ * Temporary element hierarchy
+ */
+ private Stack<DocumentObject> elementStack = new Stack<DocumentObject>();
+
+ private Stack<Integer> elementIndexStack;
+
+ private Stack<Boolean> switchStack;
+
+ private StringBuffer textBuffer = null;
+
+ private Locator locator;
+
+ private boolean ignoreSystemProcession;
+
+ private boolean hasSetDefaultEncoding;
+
+ private ElementManager elementManager;
+
+ private String defaultNamespace;
+
+ private ExtensionParser extensionParser = new ExtensionParser();
+
+ private HashMap<String, String> namespaceMapping = new HashMap<String, String>();
+
+ private boolean needNormalizeName = true;
+
+ /**
+ * Parse the XAML extension Markup: {StaticResource test} {StaticResource RessourceKey=test} {DynamicResource {x:Static
+ * SystemColors.ControlBrushKey}}
+ *
+ * @author yyang
+ *
+ */
+ private class ExtensionParser {
+
+ private Element root;
+
+ private DocumentObject current;
+
+ public void parse(DocumentObject element, String text) {
+ if(root != null) {
+ ExtensionParser parser = new ExtensionParser();
+ parser.parse(element, text);
+ return;
+ }
+
+ StringTokenizer stringTokenizer = new StringTokenizer(text, "{}", true);
+ String previous = null;
+ String nextPrevious = null;
+ while(stringTokenizer.hasMoreTokens()) {
+ String token = stringTokenizer.nextToken();
+
+ if(previous != null) {
+ if(previous.equals("{")) {
+ if(token.equals("}")) {
+ // escape sequence
+ if(stringTokenizer.hasMoreTokens()) {
+ handleBlock(stringTokenizer.nextToken(" \t\n\r\f"), false);
+ }
+ } else {
+ startBlock();
+ }
+ } else if(previous.equals("}")) {
+ endBlock();
+ } else {
+ StringBuilder builder = new StringBuilder();
+ builder.append(previous);
+ if(token.equals("{")) {
+ int level = 1;
+ builder.append(token);
+ while(stringTokenizer.hasMoreTokens() && level >= 0) {
+ String value = stringTokenizer.nextToken();
+ if(value.equals("{")) {
+ level++;
+ } else if(value.equals("}")) {
+ level--;
+ }
+ if(level >= 0) {
+ builder.append(value);
+ }
+ }
+ }
+ handleBlock(builder.toString(), (nextPrevious == null || !nextPrevious.equals("}")));
+ }
+ }
+ nextPrevious = previous;
+ previous = token;
+ }
+ element.addChild(root);
+ root = null;
+ current = null;
+ }
+
+ protected void startBlock() {
+ }
+
+ protected void endBlock() {
+ if(current != null) {
+ current = current.getParent().getParent();
+ }
+ }
+
+ protected Element createElement(String token) {
+ int index = token.indexOf(':');
+ String namespace = null;
+ String name = token;
+ if(index != -1) {
+ String prefix = token.substring(0, index);
+ name = token.substring(index + 1);
+ namespace = namespaceMapping.get(prefix);
+ }
+ if(namespace == null) {
+ namespace = defaultNamespace;
+ }
+ Element element = new Element(namespace, name, namespaceMapping);
+ element.setId(ElementManager.generateID(name));
+ if(current != null) {
+ current.addChild(element);
+ } else {
+ if(root == null) {
+ root = element;
+ }
+ }
+ current = element;
+ return element;
+ }
+
+ protected void handleBlock(String content, boolean newElement) {
+ String rootPattern = " \t\n\r\f=,";
+ StringTokenizer tokenizer = new StringTokenizer(content, rootPattern, true);
+ String attributeName = null;
+ String attributeValue = null;
+ boolean equals = false;
+ Element element = null;
+ if(!newElement && current instanceof Element) {
+ element = (Element)current;
+ }
+
+ boolean skip = false;
+ String token = null;
+ while(skip || tokenizer.hasMoreTokens()) {
+ if(!skip) {
+ token = tokenizer.nextToken(rootPattern).trim();
+ }
+ skip = false;
+ if(token.length() == 0) {
+ continue;
+ }
+ if(element == null) {
+ element = createElement(token);
+ } else {
+ if(token.equals("=")) {
+ equals = true;
+ if("xpath".equalsIgnoreCase(attributeName)) {
+ attributeValue = tokenizer.nextToken(",");
+ }
+ continue;
+ }
+ if(token.equals(",")) {
+ if(attributeName != null) {
+ if(attributeValue != null) {
+ Attribute attribute = new Attribute(normalizeAttrNamespace(current.getNamespace()), attributeName, ElementManager.generateID(current.getName()));
+ if(isExpendedProperty(attributeName) && "Binding".equalsIgnoreCase(element.getName())) {
+ attributeValue = expandNamespaces(element, attributeValue);
+ }
+ handleContent(attribute, attributeValue);
+ element.setAttribute(attribute);
+ current = attribute;
+ } else {
+ element.setContent(attributeName);
+ }
+ attributeName = null;
+ attributeValue = null;
+ equals = false;
+ }
+ } else {
+ if(attributeName == null) {
+ attributeName = token;
+ } else {
+ StringBuilder builder = new StringBuilder();
+ builder.append(token);
+ if(token.startsWith("{")) {
+ int level = 1;
+ while(tokenizer.hasMoreTokens() && level > 0) {
+ String value = tokenizer.nextToken("{}");
+ if(value.equals("{")) {
+ level++;
+ } else if(value.equals("}")) {
+ level--;
+ }
+ builder.append(value);
+ }
+ }
+ attributeValue = builder.toString();
+
+ try {
+ token = tokenizer.nextToken(rootPattern).trim();
+ skip = true;
+ continue;
+ } catch (NoSuchElementException e) {
+ }
+ }
+ }
+ }
+ skip = false;
+ }
+
+ if(equals) {
+ Attribute attribute = new Attribute(normalizeAttrNamespace(current.getNamespace()), attributeName, ElementManager.generateID(current.getName()));
+ if(isExpendedProperty(attributeName) && "Binding".equalsIgnoreCase(element.getName())) {
+ attributeValue = expandNamespaces(element, attributeValue);
+ }
+
+ if(attributeValue != null) {
+ handleContent(attribute, attributeValue);
+ element.setAttribute(attribute);
+ } else {
+ element.setAttribute(attribute);
+ current = attribute;
+ }
+ } else if(attributeName != null) {
+ int index = attributeName.indexOf(":");
+ if(index != -1) {
+ element = createElement(attributeName);
+ current = current.getParent();
+ } else {
+ current.setContent(attributeName);
+ }
+ }
+ }
+ };
+
+ static boolean isExpendedProperty(String name) {
+ // TODO need a generic solution for each property of Binding
+ for(String propertyName : BINDING_PROPERTIES) {
+ if(propertyName.equalsIgnoreCase(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected String expandNamespaces(DocumentObject element, String value) {
+ if(value.startsWith("{") || (value.indexOf(':') == -1)) {
+ return value;
+ }
+ int length = IConstants.XAML_CLR_NAMESPACE_PROTO.length();
+ for(String prefix : namespaceMapping.keySet()) {
+ String namespace = namespaceMapping.get(prefix);
+ if(namespace.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO)) {
+ String packageName = namespace.substring(length);
+ value = value.replace(prefix + ":", packageName + '.');
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Default constructor.
+ *
+ * @param manager
+ * loader instance.
+ */
+ public ElementHandler(ElementManager elementManager) {
+ this.ignoreSystemProcession = false;
+ this.hasSetDefaultEncoding = false;
+ this.elementManager = elementManager;
+ }
+
+ /**
+ * Internal constructor.
+ *
+ * @param loader
+ * loader instance.
+ * @param parent
+ * the parent element of loading stream.
+ */
+ public ElementHandler(DocumentObject parent, ElementManager elementManager) {
+ if(parent != null) {
+ elementStack.push(parent);
+ bufferStack.push(textBuffer);
+ }
+ ignoreSystemProcession = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#setDocumentLocator(org.xml.sax.Locator)
+ */
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ this.locator = locator;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#startDocument()
+ */
+ @Override
+ public void startDocument() throws SAXException {
+ elementIndexStack = new Stack<Integer>();
+ elementIndexStack.push(0);
+ switchStack = new Stack<Boolean>();
+ defaultNamespace = IConstants.XWT_NAMESPACE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#startPrefixMapping(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ if(prefix.length() == 0 && !ignoreSystemProcession) {
+ defaultNamespace = uri;
+ }
+ namespaceMapping.put(prefix, uri);
+ }
+
+ @Override
+ public void endPrefixMapping(String prefix) throws SAXException {
+ namespaceMapping.remove(prefix);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#endDocument()
+ */
+ @Override
+ public void endDocument() throws SAXException {
+ elementStack.clear();
+ bufferStack.clear();
+ switchStack.clear();
+ switchStack = null;
+ defaultNamespace = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
+ */
+ @Override
+ public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
+
+ if(!switchStack.isEmpty() && !switchStack.peek()) {
+ return;
+ }
+
+ String string = new String(arg0, arg1, arg2);
+ if(string.length() > 0) {
+ if(textBuffer == null) {
+ textBuffer = new StringBuffer(string);
+ } else {
+ textBuffer.append(string);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#skippedEntity(java.lang.String)
+ */
+ @Override
+ public void skippedEntity(String name) throws SAXException {
+ super.skippedEntity(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
+
+ // Set xml's encoding to default.
+ if(!ignoreSystemProcession && !hasSetDefaultEncoding) {
+ if(locator instanceof Locator2) {
+ Locator2 locator2 = (Locator2)locator;
+ String encoding = locator2.getEncoding();
+ if(encoding != null && encoding.length() > 0) {
+ elementManager.setEncoding(encoding);
+ }
+ }
+ hasSetDefaultEncoding = true;
+ }
+
+ uri = normalizeNamespace(uri);
+
+ // If super condition does not allow parse children, ignore it.
+ if(!switchStack.isEmpty() && !switchStack.peek()) {
+ if(uri.equalsIgnoreCase(IConstants.XWT_NAMESPACE)) {
+ if("Switch".equals(localName)) {
+ // If children is switch element, than set false to it.
+ switchStack.push(false);
+ }
+ }
+ return;
+ }
+
+ if(localName.indexOf('.') > 0) {
+ preProperty(uri, localName, attrs);
+ } else {
+ preElement(uri, localName, attrs);
+ }
+
+ elementIndexStack.push(0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+
+ elementIndexStack.pop();
+ if(!elementIndexStack.isEmpty()) {
+ int nextIndex = elementIndexStack.pop();
+ elementIndexStack.push(nextIndex + 1);
+ }
+
+ uri = normalizeNamespace(uri);
+
+ // If super condition does not allow parse children, ignore it.
+ if(!switchStack.isEmpty() && !switchStack.peek()) {
+ if(uri.equalsIgnoreCase(IConstants.XWT_NAMESPACE)) {
+ if("Switch".equals(localName)) {
+ switchStack.pop();
+ }
+ }
+ return;
+ }
+
+ if(!elementStack.isEmpty()) {
+ // remove current node from stack
+ DocumentObject element = elementStack.peek();
+
+ if(element instanceof Attribute) {
+ postProperty(uri, localName);
+ } else {
+ postElement(uri, localName);
+ }
+ }
+ }
+
+ private void preElement(String namespace, String name, Attributes attrs) throws SAXException {
+
+ // Process element ID
+
+ namespace = normalizeNamespace(namespace);
+ name = normalizeName(name);
+ if(name.equalsIgnoreCase("xdata")) {
+ needNormalizeName = false;
+ }
+ // Check the reference element.
+ String id = ElementManager.generateID(name);
+
+ // Check the same id elements.
+ if(elementManager.hasElement(id)) {
+ throw new SAXException(getFormattedMessage("Element already exists: ", id));
+ }
+
+ // Process attributes: original, external
+ Set<Attribute> attributes = new HashSet<Attribute>();
+ for(int i = 0, len = attrs.getLength(); i < len; i++) {
+ String attrUri = normalizeAttrNamespace(attrs.getURI(i));
+ String attrName = attrs.getLocalName(i);
+
+ Attribute attribute;
+ int index = attrName.lastIndexOf('.');
+ if(index != -1) {
+ String prefix = normalizeName(attrName.substring(0, index));
+ String attributeName = (XWT.isXWTNamespace(attrUri) ? normalizeName(attrName.substring(index + 1)) : attrName);
+
+ attribute = new Attribute(attrUri, attributeName, id);
+ attribute.setNamePrefix(prefix);
+ } else {
+ attribute = new Attribute(attrUri, (XWT.isXWTNamespace(attrUri) ? normalizeName(attrName) : attrName), id);
+ }
+ handleContent(attribute, attrs.getValue(i));
+ attributes.add(attribute);
+ }
+
+ // Create or reference element.
+ Element element = new Element(namespace, name, getIndexPath(), attributes, namespaceMapping);
+ element.setId(id);
+
+ // Add current node to stack
+ if(!elementStack.isEmpty()) {
+ elementStack.peek().addChild(element);
+ }
+
+ elementStack.push(element);
+ bufferStack.push(textBuffer);
+ textBuffer = null;
+
+ // Register to the element registry
+ elementManager.preElement(element);
+ }
+
+ private void postElement(String namespace, String name) throws SAXException {
+
+ // : The same as postReference : //
+
+ if(!elementStack.isEmpty()) {
+ // remove current node from stack
+ DocumentObject element = elementStack.pop();
+
+ // Setting element text content
+ if(textBuffer != null) {
+ String text = textBuffer.toString().trim();
+ if(text.length() > 0) {
+ handleContent(element, text);
+ }
+ }
+ textBuffer = bufferStack.pop();
+
+ // Post the element registration.
+ elementManager.postElement((Element)element);
+ }
+
+ if(name.equalsIgnoreCase("xdata")) {
+ needNormalizeName = true;
+ }
+ }
+
+ protected void handleContent(DocumentObject element, String text) {
+ if(text.startsWith("{") && text.endsWith("}")) {
+ extensionParser.parse(element, text);
+ return;
+ } else {
+ // handle the case: <x:Array Type="ns:Type" >
+ if(IConstants.XAML_X_TYPE.equals(element.getName()) || IConstants.XAML_X_STATIC.equals(element.getName())) {
+ int index = text.indexOf(':');
+ if(index != -1) {
+ String ns = text.substring(0, index);
+ String content = text.substring(index + 1);
+ String namespace = namespaceMapping.get(ns);
+ if(namespace != null) {
+ Element childElement = new Element(namespace, content, namespaceMapping);
+ childElement.setId(ElementManager.generateID(element.getName()));
+ element.addChild(childElement);
+ return;
+ }
+ }
+ }
+ }
+ if(element instanceof Attribute && IConstants.XWT_X_NAMESPACE.equals(element.getNamespace())) {
+ if(IConstants.XAML_STYLE.equalsIgnoreCase(element.getName()) || IConstants.XAML_X_CLASS.equalsIgnoreCase(element.getName()) || IConstants.XAML_X_CLASS_FACTORY.equalsIgnoreCase(element.getName())) {
+ // handle the expansion of x:Style = "(j:class).variable"
+ // and handle the expansion of x:Class = "(j:class).variable"
+ text = expandNamespaces(element, text);
+ }
+ }
+ element.setContent(text);
+ }
+
+ /**
+ * It is compatible with XAML.
+ * <p>
+ * It must support the following features:
+ *
+ * 1. <Panel> <Button> <Button.Content>Hello World</Button.Content> </Button> </Panel>
+ *
+ * 2. <Panel> <Panel.Composite> <Button Content="Hello World" /> </Panel.Composite> </Panel>
+ *
+ * 3. <Panel> <Panel.Composite> <Button> <Button.Content>Hello World</Button.Content> </Button> </Panel.Composite> </Panel>
+ *
+ * 4. <Panel> <Panel.Composite> <Button> <Button.Content>Hello</Button.Content> </Button> <Button> <Button.Content>World</Button.Content>
+ * </Button> </Panel.Composite> </Panel>
+ * </p>
+ *
+ * @param namespace
+ * attribute namespace
+ * @param name
+ * attribute full name. like: Button.Content
+ */
+ private void preProperty(String namespace, String name, Attributes attrs) throws SAXException {
+ String elementTag = normalizeName(name.substring(0, name.indexOf('.')));
+ String attributeName = (XWT.isXWTNamespace(namespace) ? normalizeName(name.substring(name.indexOf('.') + 1)) : name);
+ String elementId = null;
+
+ // Search the owner element and get the ID.
+ for(int i = elementStack.size() - 1; i >= 0; i--) {
+ DocumentObject element = elementStack.get(i);
+ if(element instanceof Element && element.getName().equals(elementTag)) {
+ elementId = element.getId();
+ break;
+ }
+ }
+
+ if(elementId == null) {
+ preElement(namespace, name, attrs);
+ } else {
+ namespace = normalizeNamespace(namespace);
+ // Process attributes: original, external
+ Collection<Attribute> collection = new ArrayList<Attribute>();
+ for(int i = 0, len = attrs.getLength(); i < len; i++) {
+
+ String attrUri = normalizeNamespace(attrs.getURI(i));
+ String attrName = attrs.getLocalName(i);
+
+ Attribute attr;
+ int index = attrName.lastIndexOf('.');
+ if(index != -1) {
+ String prefix = normalizeName(attrName.substring(0, index));
+ String aName = (XWT.isXWTNamespace(namespace) ? normalizeName(attrName.substring(index + 1)) : attrName);
+ attr = new Attribute(attrUri, aName, elementId);
+ attr.setNamePrefix(prefix);
+ } else {
+ attr = new Attribute(attrUri, (XWT.isXWTNamespace(namespace) ? normalizeName(attrName) : attrName), elementId);
+ }
+ handleContent(attr, attrs.getValue(i));
+ collection.add(attr);
+ }
+
+ Attribute attribute = new Attribute(normalizeAttrNamespace(namespace), attributeName, getIndexPath(), elementId, collection);
+ elementStack.push(attribute);
+ bufferStack.push(textBuffer);
+ textBuffer = null;
+ }
+ }
+
+ /**
+ * @see #preProperty(String, String)
+ */
+ private void postProperty(String namespace, String name) throws SAXException {
+ if(!elementStack.isEmpty()) {
+ // remove current node from stack
+ Attribute attribute = (Attribute)elementStack.pop();
+
+ // Setting attribute content
+ if(textBuffer != null) {
+ String text = textBuffer.toString().trim();
+ if(text.length() > 0) {
+ handleContent(attribute, text);
+ }
+ }
+ textBuffer = bufferStack.pop();
+
+ Element element = elementManager.getElement(attribute.getId());
+ element.setAttribute(attribute);
+ }
+ }
+
+ /**
+ * Normalize the namespace string. If uri is null or length is zero, returns default namespace.
+ *
+ * @param uri
+ * The namespace which to normalize.
+ * @return Returns the normalized namespace.
+ */
+ private String normalizeNamespace(String uri) {
+ if(uri == null || uri.length() == 0) {
+ uri = defaultNamespace;
+ }
+ if(uri.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO)) {
+ return uri;
+ }
+ return uri.toLowerCase();
+ }
+
+ /**
+ * Normalize the namespace string. If uri is null or length is zero, returns default namespace.
+ *
+ * @param uri
+ * The namespace which to normalize.
+ * @return Returns the normalized namespace.
+ */
+ private String normalizeAttrNamespace(String uri) {
+ if(uri == null || uri.length() == 0) {
+ uri = defaultNamespace;
+ }
+ if(uri.startsWith(IConstants.XAML_CLR_NAMESPACE_PROTO)) {
+ uri = defaultNamespace;
+ }
+ return uri.toLowerCase();
+ }
+
+ /**
+ * <p>
+ * Normalize the tag name to class-formal format.
+ * </p>
+ * <p>
+ * e.g. Normalize &quot;font-face-name&quot; to &quot;FontFaceName&quot;
+ * </p>
+ *
+ * @param tagName
+ * The tag name which to normalize.
+ * @return the normalized tag name.
+ */
+ private String normalizeName(String tagName) {
+ if(!needNormalizeName) {
+ return tagName;
+ }
+ StringBuffer buffer = new StringBuffer();
+
+ boolean isH = false;
+ for(int i = 0, len = tagName.length(); i < len; i++) {
+ char c = tagName.charAt(i);
+ if(i == 0) {
+ buffer.append(Character.toUpperCase(c));
+ } else {
+ switch(c) {
+ case '-':
+ isH = true;
+ break;
+ case '.':
+ isH = true;
+ buffer.append(c);
+ break;
+ default:
+ if(isH) {
+ buffer.append(Character.toUpperCase(c));
+ isH = false;
+ } else {
+ buffer.append(c);
+ }
+ break;
+ }
+ }
+ }
+ return buffer.toString();
+ }
+
+ private String getFormattedMessage(String msg, Object... args) {
+ StringBuffer buffer = new StringBuffer("[" + locator.getLineNumber() + "," + locator.getColumnNumber() + "] ");
+ buffer.append(msg);
+ return MessageFormat.format(buffer.toString(), args);
+ }
+
+ /**
+ * @return the '/' separated, zero based, path of current {@link Element}.
+ */
+ private String getIndexPath() {
+ StringBuilder sb = new StringBuilder();
+ for(Integer index : elementIndexStack) {
+ if(sb.length() != 0) {
+ sb.append('/');
+ }
+ sb.append(index.intValue());
+ }
+ return sb.toString();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementManager.java
new file mode 100644
index 00000000000..7de6221dbd5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/ElementManager.java
@@ -0,0 +1,413 @@
+/*******************************************************************************
+ * 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.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.callback.IBeforeParsingCallback;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @author yyang
+ * @since 1.0
+ */
+public class ElementManager {
+
+ private DocumentRoot documentRoot;
+
+ private SAXParserFactory parserFactory;
+
+ private ErrorHandler errorHandler;
+
+ private String encoding;
+
+ /**
+ * Cache all elements.
+ */
+ private Map<String, Element> elements;
+
+ /**
+ * Only cache root elements.
+ */
+ private Element rootElement;
+
+ private Element xDataElement;
+
+ private static Random RANDOM = new Random();
+
+ public static String generateID(String typeName) {
+ return typeName + RANDOM.nextInt(Integer.MAX_VALUE);
+ }
+
+ public ElementManager() {
+ this(null);
+ }
+
+ public ElementManager(URL url) {
+ this.documentRoot = new DocumentRoot();
+ this.elements = new HashMap<String, Element>();
+ this.encoding = System.getProperty("file.encoding");
+
+ this.parserFactory = SAXParserFactory.newInstance();
+ this.parserFactory.setNamespaceAware(true);
+ this.parserFactory.setValidating(true);
+ if(url != null) {
+ try {
+ documentRoot.init(null, url.toString());
+ } catch (IOException e) {
+ }
+ }
+
+ this.errorHandler = new ErrorHandler() {
+
+ // IFrameworkAdaptor adaptor =
+ // FrameworkUtil.getFrameworkAdaptor(context);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException exception) throws SAXException {
+ Exception cause = exception.getException();
+ try {
+ if(cause != null) {
+ XWT.getLogger().error(cause);
+ } else {
+ XWT.getLogger().error(exception);
+ }
+ } catch (Exception e) {
+ if(cause != null) {
+ throw new SAXException(exception.getLocalizedMessage(), cause);
+ } else {
+ throw new SAXException(exception);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException
+ * )
+ */
+ public void fatalError(SAXParseException exception) throws SAXException {
+ Exception cause = exception.getException();
+ try {
+ if(cause != null) {
+ XWT.getLogger().error(cause);
+ } else {
+ XWT.getLogger().error(exception);
+ }
+ } catch (Exception e) {
+ if(cause != null) {
+ throw new SAXException(exception.getLocalizedMessage(), cause);
+ } else {
+ throw new SAXException(exception);
+ }
+ }
+ throw new RuntimeException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException exception) throws SAXException {
+ Exception cause = exception.getException();
+ try {
+ if(cause != null) {
+ XWT.getLogger().error(cause);
+ } else {
+ XWT.getLogger().error(exception);
+ }
+ } catch (Exception e) {
+ if(cause != null) {
+ throw new SAXException(exception.getLocalizedMessage(), cause);
+ } else {
+ throw new SAXException(exception);
+ }
+ }
+ }
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IElementManager#getDocumentRoot()
+ */
+ public DocumentRoot getDocumentRoot() {
+ return documentRoot;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IElementManager#getElement(java.lang.String)
+ */
+ public Element getElement(String id) {
+ assert id != null;
+ return elements.get(id);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IElementManager#getElements()
+ */
+ public String[] getElements() {
+ return elements.keySet().toArray(IConstants.EMPTY_STRING_ARRAY);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IElementManager#getEncoding()
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IElementManager#getRootElement()
+ */
+ public Element getRootElement() {
+ return rootElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.soyatec.xaml.IElementManager#hasElement(java.lang.String)
+ */
+ public boolean hasElement(String id) {
+ assert id != null;
+ return elements.containsKey(id);
+ }
+
+ protected void setEncoding(String encoding) {
+ assert encoding != null;
+ this.encoding = encoding;
+ }
+
+ /**
+ * @see Core
+ */
+ public Element load(URL url, IBeforeParsingCallback callback) throws Exception {
+
+ reset();
+
+ if(callback == null) {
+ // Initialize document root
+ documentRoot.init(null, url.toString());
+
+ InputStream input = url.openStream();
+ try {
+ doLoad(input);
+ } finally {
+ input.close();
+ }
+
+ input = documentRoot.openStream();
+ try {
+ loadXData(input);
+ } finally {
+ input.close();
+ }
+ } else {
+ String content = callback.onParsing(url.toString());
+
+ documentRoot.init(null, content);
+
+ InputStream input = new ByteArrayInputStream(content.getBytes());
+ try {
+ doLoad(input);
+ } finally {
+ input.close();
+ }
+
+ input = documentRoot.openStream();
+ try {
+ loadXData(input);
+ } finally {
+ input.close();
+ }
+ }
+ return rootElement;
+ }
+
+ /**
+ * @see Core
+ */
+ public Element load(InputStream stream, URL url) throws Exception {
+
+ reset();
+
+ // Initialize document root
+ PushbackInputStream pis = null;
+ if(stream != null) {
+ if(stream instanceof PushbackInputStream) {
+ pis = (PushbackInputStream)stream;
+ } else {
+ pis = new PushbackInputStream(stream, 4);
+ }
+ }
+
+ documentRoot.init(pis, url.toString());
+
+ InputStream input = pis;
+ if(pis == null) {
+ input = documentRoot.openStream();
+ }
+ doLoad(input);
+
+ input = documentRoot.openStream();
+ loadXData(input);
+ input.close();
+ return rootElement;
+ }
+
+ /**
+ * @see ElementHandler
+ */
+ public void load(InputStream stream, DocumentObject parent) throws SAXException {
+ assert stream != null;
+
+ ElementHandler contentHandler = new ElementHandler(parent, this);
+ try {
+ SAXParser parser = parserFactory.newSAXParser();
+ parser.getXMLReader().setErrorHandler(errorHandler);
+ parser.parse(stream, contentHandler);
+ } catch (ParserConfigurationException pce) {
+ throw new SAXException(pce.getLocalizedMessage(), pce);
+ } catch (IOException ioe) {
+ throw new SAXException(ioe.getLocalizedMessage(), ioe);
+ }
+ }
+
+ private void loadXData(InputStream stream) {
+ if(xDataElement != null) {
+ try {
+ SAXParser parser = parserFactory.newSAXParser();
+ parser.getXMLReader().setErrorHandler(errorHandler);
+ StringBuilder out = new StringBuilder();
+ parser.parse(stream, new XDataHandler(out));
+ String content = out.toString();
+ xDataElement.setContent(content);
+ } catch (ParserConfigurationException e) {
+ } catch (SAXException e) {
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ /**
+ * @see ElementHandler
+ */
+ protected void preElement(Element element) {
+ assert element != null;
+ assert elements.containsKey(element.getId()) : "Element already exists in registry: " + element.getId();
+
+ // Add to cache.
+ elements.put(element.getId(), element);
+
+ // If it is a runnable element, add to top-level cache.
+ if(element.getParent() == null && rootElement == null) {
+ rootElement = element;
+ }
+ }
+
+ /**
+ * @see ElementHandler
+ */
+ protected void postElement(Element element) {
+ assert element != null;
+ assert !elements.containsKey(element.getId()) : "Element not found in registry: " + element.getId();
+ if("xdata".equalsIgnoreCase(element.getName()) && IConstants.XWT_X_NAMESPACE.equals(element.getNamespace())) {
+ xDataElement = element;
+ }
+ }
+
+ /**
+ * @see #load(File)
+ * @see #load(URL)
+ */
+ private void doLoad(InputStream stream) throws Exception {
+ assert stream != null;
+ ElementHandler contentHandler = new ElementHandler(this);
+ try {
+ SAXParser parser = parserFactory.newSAXParser();
+ parser.getXMLReader().setErrorHandler(errorHandler);
+ parser.parse(stream, contentHandler);
+ } catch (SAXException saxe) {
+ // Exception cause = saxe.getException();
+ // try {
+ // if (cause != null) {
+ // XWT.getLogger().error(cause);
+ // } else {
+ // XWT.getLogger().error(saxe);
+ // }
+ // } catch (Exception e) {
+ // // e.printStackTrace();
+ // }
+ throw saxe;
+ } catch (ParserConfigurationException pce) {
+ try {
+ XWT.getLogger().error(pce);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw pce;
+ } catch (IOException ioe) {
+ try {
+ XWT.getLogger().error(ioe);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw ioe;
+ }
+ }
+
+ /**
+ * @see #load(File)
+ * @see #load(URL)
+ */
+ private void reset() {
+
+ // Reset code base.
+ documentRoot.reset();
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/XDataHandler.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/XDataHandler.java
new file mode 100644
index 00000000000..592bf0ec309
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/internal/xml/XDataHandler.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.internal.xml;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * @author jliu jin.liu@soyatec.com
+ */
+public class XDataHandler extends DefaultHandler implements ContentHandler {
+
+ private boolean namespaceBegin = false;
+
+ private String currentNamespace;
+
+ private String currentNamespaceUri;
+
+ private StringBuilder out;
+
+ private boolean started;
+
+ public XDataHandler(StringBuilder out) {
+ this.out = out;
+ }
+
+ public void startPrefixMapping(String prefix, String uri) {
+ namespaceBegin = true;
+ currentNamespace = prefix;
+ currentNamespaceUri = uri;
+ }
+
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
+ if(started) {
+ out.append("<" + qName);
+ if(namespaceBegin) {
+ out.append(" xmlns:" + currentNamespace + "=\"" + currentNamespaceUri + "\"");
+ namespaceBegin = false;
+ }
+ for(int i = 0; i < atts.getLength(); i++) {
+ out.append(" " + atts.getQName(i) + "=\"" + atts.getValue(i) + "\"");
+ }
+ out.append(">");
+ }
+ if(localName.equalsIgnoreCase("xdata")) {
+ started = true;
+ }
+ }
+
+ public void endElement(String namespaceURI, String localName, String qName) {
+ if(localName.equalsIgnoreCase("xdata")) {
+ started = false;
+ }
+ if(started) {
+ out.append("</" + qName + ">");
+ }
+ }
+
+ public void characters(char[] ch, int start, int length) {
+ if(started) {
+ for(int i = start; i < start + length; i++) {
+ out.append(ch[i]);
+ }
+ }
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length) {
+ if(started) {
+ for(int i = start; i < start + length; i++) {
+ out.append(ch[i]);
+ }
+ }
+ }
+
+ public void processingInstruction(String target, String data) {
+ if(started) {
+ out.append("<?" + target + " " + data + "?>");
+ }
+ }
+
+ public void skippedEntity(String name) {
+ if(started) {
+ out.append("&" + name + ";");
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/Controller.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/Controller.java
new file mode 100644
index 00000000000..ac706050f70
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/Controller.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.javabean;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.eclipse.papyrus.xwt.IEventConstants;
+import org.eclipse.papyrus.xwt.IEventInvoker;
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.internal.core.IEventController;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Widget;
+
+public class Controller implements Listener, IEventController {
+
+ int waterMark = 0;
+
+ protected int[] eventTypes = null;
+
+ protected String[] names = null;
+
+ protected Object[] handlers = null;
+
+ protected Object[] receivers = null;
+
+ protected Object[] args = null;
+
+ protected void fireEvent(Event e) {
+ int eventType = e.type;
+ if(eventTypes == null) {
+ return;
+ }
+
+ for(int i = 0; i < eventTypes.length; i++) {
+ if(eventTypes[i] == eventType) {
+ Object handler = handlers[i];
+ if(handler instanceof IEventInvoker) {
+ IEventInvoker eventInvoker = (IEventInvoker)handler;
+ try {
+ eventInvoker.invoke(args[i], e);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return;
+ }
+ } else {
+ Method method = (Method)handler;
+ try {
+ method.setAccessible(true);
+ // support old style
+ if(method.getParameterTypes().length == 1) {
+ method.invoke(receivers[i], e);
+ } else {
+ method.invoke(receivers[i], args[i], e);
+ }
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.javabean.IEventHandler#hasEvent(java.lang.Object,
+ * org.eclipse.papyrus.xwt.metadata.IEvent)
+ */
+ public boolean hasEvent(Object receiver, IEvent event) {
+ if(receivers == null) {
+ return false;
+ }
+ for(int i = 0; i < receivers.length; i++) {
+ if(receivers[i] == receiver && names[i].equalsIgnoreCase(event.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.javabean.IEventHandler#addEvent(int,
+ * java.lang.String, org.eclipse.papyrus.xwt.metadata.IEvent,
+ * org.eclipse.swt.widgets.Widget, java.lang.Object, java.lang.Object,
+ * java.lang.reflect.Method)
+ */
+ public void addEvent(int eventType, String name, IEvent event, Widget control, Object receiver, Object arg, Method method) {
+ doAddEvent(eventType, name, event, control, receiver, arg, method);
+ }
+
+ public void addEvent(int eventType, String name, IEvent event, Widget control, Object arg, IEventInvoker eventInvoker) {
+ doAddEvent(eventType, name, event, control, null, arg, eventInvoker);
+ }
+
+ protected void doAddEvent(int eventType, String name, IEvent event, Widget control, Object receiver, Object arg, Object method) {
+ if(eventTypes == null) {
+ eventTypes = new int[3];
+ handlers = new Method[3];
+ names = new String[3];
+ receivers = new Object[3];
+ args = new Object[3];
+ } else {
+ for(int i = 0; i < eventTypes.length; i++) {
+ if(eventTypes[i] == eventType && handlers[i] == method && receivers[i] == receivers && args[i] == arg) {
+ return;
+ }
+ }
+ }
+ if(waterMark >= eventTypes.length) {
+ int[] oldEventTypes = eventTypes;
+ Object[] oldHandlers = handlers;
+ Object[] oldReceivers = receivers;
+ Object[] oldNames = names;
+ Object[] oldArgs = args;
+
+ eventTypes = new int[waterMark + 3];
+ handlers = new Object[waterMark + 3];
+ receivers = new Object[waterMark + 3];
+ names = new String[waterMark + 3];
+ args = new Object[waterMark + 3];
+
+ System.arraycopy(oldEventTypes, 0, eventTypes, 0, waterMark);
+ System.arraycopy(oldHandlers, 0, handlers, 0, waterMark);
+ System.arraycopy(oldReceivers, 0, receivers, 0, waterMark);
+ System.arraycopy(oldArgs, 0, args, 0, waterMark);
+ System.arraycopy(oldNames, 0, names, 0, waterMark);
+ }
+
+ eventTypes[waterMark] = eventType;
+ handlers[waterMark] = method;
+ receivers[waterMark] = receiver;
+ args[waterMark] = arg;
+ names[waterMark++] = name;
+
+ if(eventType == IEventConstants.XWT_SWT_LOADED) {
+ int swt_paint = XWTMaps.getEvent("swt.paint");
+ if(swt_paint != SWT.None) { // for RAP integration
+ Listener[] listeners = control.getListeners(swt_paint);
+ if(listeners.length > 0) {
+ for(Listener listener : listeners) {
+ control.removeListener(swt_paint, listener);
+ }
+ control.addListener(swt_paint, new LoadedEventListener(control));
+ for(Listener listener : listeners) {
+ control.addListener(swt_paint, listener);
+ }
+ } else {
+ control.addListener(swt_paint, new LoadedEventListener(control));
+ }
+ }
+ }
+ control.addListener(eventType, this);
+ }
+
+ class LoadedEventListener implements Listener {
+
+ protected Widget control;
+
+ public LoadedEventListener(Widget control) {
+ this.control = control;
+ }
+
+ public void handleEvent(Event event) {
+ Event loadedEvent = copy(event);
+ loadedEvent.type = IEventConstants.XWT_SWT_LOADED;
+ if(XWTMaps.getEvent("swt.paint") != SWT.None) {
+ control.removeListener(XWTMaps.getEvent("swt.paint"), this);
+ }
+ Controller.this.handleEvent(loadedEvent);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.javabean.IEventHandler#setEvent(org.eclipse.papyrus.xwt
+ * .metadata.IEvent, org.eclipse.swt.widgets.Widget, java.lang.Object,
+ * java.lang.Object, java.lang.reflect.Method)
+ */
+ public void setEvent(IEvent event, Widget control, Object receiver, Object arg, Method method) {
+ String name = event.getName();
+ int eventType = getEventTypeByName(name);
+ if(eventType != SWT.None) {
+ addEvent(eventType, name, event, control, receiver, arg, method);
+ }
+ }
+
+ public void setEvent(IEvent event, Widget control, Object arg, IEventInvoker eventInvoker) {
+ String name = event.getName();
+ int eventType = getEventTypeByName(name);
+ if(eventType != SWT.None) {
+ doAddEvent(eventType, name, event, control, null, arg, eventInvoker);
+ }
+ }
+
+ public static Event copy(Event event) {
+ Event copyEvent = new Event();
+ for(Field field : event.getClass().getDeclaredFields()) {
+ try {
+ field.set(copyEvent, field.get(event));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return copyEvent;
+ }
+
+ public static int getEventTypeByName(String name) {
+ if(IEventConstants.KEY_DOWN.equalsIgnoreCase(name)) {
+ return SWT.KeyDown;
+ } else if(IEventConstants.KEY_UP.equalsIgnoreCase(name)) {
+ return SWT.KeyUp;
+ } else if(IEventConstants.MOUSE_DOWN.equalsIgnoreCase(name)) {
+ return SWT.MouseDown;
+ } else if(IEventConstants.MOUSE_UP.equalsIgnoreCase(name)) {
+ return SWT.MouseUp;
+ } else if(IEventConstants.MOUSE_MOVE.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.mousemove");
+ } else if(IEventConstants.MOUSE_ENTER.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.mouseenter");
+ } else if(IEventConstants.MOUSE_EXIT.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.mouseexit");
+ } else if(IEventConstants.MOUSE_DOUBLE_CLICK.equalsIgnoreCase(name)) {
+ return SWT.MouseDoubleClick;
+ } else if(IEventConstants.PAINT.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.paint");
+ } else if(IEventConstants.MOVE.equalsIgnoreCase(name)) {
+ return SWT.Move;
+ } else if(IEventConstants.RESIZE.equalsIgnoreCase(name)) {
+ return SWT.Resize;
+ } else if(IEventConstants.DISPOSE.equalsIgnoreCase(name)) {
+ return SWT.Dispose;
+ } else if(IEventConstants.SELECTION.equalsIgnoreCase(name)) {
+ return SWT.Selection;
+ } else if(IEventConstants.DEFAULT_SELECTION.equalsIgnoreCase(name)) {
+ return SWT.DefaultSelection;
+ } else if(IEventConstants.FOCUS_IN.equalsIgnoreCase(name)) {
+ return SWT.FocusIn;
+ } else if(IEventConstants.FOCUS_OUT.equalsIgnoreCase(name)) {
+ return SWT.FocusOut;
+ } else if(IEventConstants.EXPAND.equalsIgnoreCase(name)) {
+ return SWT.Expand;
+ } else if(IEventConstants.COLLAPSE.equalsIgnoreCase(name)) {
+ return SWT.Collapse;
+ } else if(IEventConstants.ICONIFY.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.iconify");
+ } else if(IEventConstants.DEICONIFY.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.deiconify");
+ } else if(IEventConstants.CLOSE.equalsIgnoreCase(name)) {
+ return SWT.Close;
+ } else if(IEventConstants.SHOW.equalsIgnoreCase(name)) {
+ return SWT.Show;
+ } else if(IEventConstants.HIDE.equalsIgnoreCase(name)) {
+ return SWT.Hide;
+ } else if(IEventConstants.MODIFY.equalsIgnoreCase(name)) {
+ return SWT.Modify;
+ } else if(IEventConstants.VERIFY.equalsIgnoreCase(name)) {
+ return SWT.Verify;
+ } else if(IEventConstants.ACTIVATE.equalsIgnoreCase(name)) {
+ return SWT.Activate;
+ } else if(IEventConstants.DEACTIVATE.equalsIgnoreCase(name)) {
+ return SWT.Deactivate;
+ } else if(IEventConstants.HELP.equalsIgnoreCase(name)) {
+ return SWT.Help;
+ } else if(IEventConstants.DRAG_SELECT.equalsIgnoreCase(name)) {
+ return SWT.DragDetect;
+ } else if(IEventConstants.ARM.equalsIgnoreCase(name)) {
+ return SWT.Arm;
+ } else if(IEventConstants.TRAVERSE.equalsIgnoreCase(name)) {
+ return SWT.Traverse;
+ } else if(IEventConstants.MOUSE_HOVER.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.mousehover");
+ } else if(IEventConstants.HARD_KEY_DOWN.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.hardkeydown");
+ } else if(IEventConstants.HARD_KEY_UP.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.hardkeyup");
+ } else if(IEventConstants.MENU_DETECT.equalsIgnoreCase(name)) {
+ return SWT.MenuDetect;
+ } else if(IEventConstants.MOUSE_WHEEL.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.mousewheel");
+ } else if(IEventConstants.SETTINGS.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.settings");
+ } else if(IEventConstants.ERASE_ITEM.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.eraseitem");
+ } else if(IEventConstants.MEASURE_ITEM.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.measureitem");
+ } else if(IEventConstants.PAINT_ITEM.equalsIgnoreCase(name)) {
+ return XWTMaps.getEvent("swt.paintitem");
+ } else if(IEventConstants.XWT_LOADED.equalsIgnoreCase(name) || IEventConstants.XWT_LOADED_EVENT.equalsIgnoreCase(name)) {
+ return IEventConstants.XWT_SWT_LOADED;
+ }
+ // case SWT.PaintItem:
+ // firePaintItem(e);
+ // break;
+ // case DND.DragStart:
+ // dnde = new DNDEventWrapper(e);
+ // fireGiveFeedback(dnde);
+ // break;
+ // case DND.DragEnter:
+ // dnde = new DNDEventWrapper(e);
+ // fireDragEnter(dnde);
+ // break;
+ // case DND.DragLeave:
+ // dnde = new DNDEventWrapper(e);
+ // fireDragLeaves(dnde);
+ // break;
+ // case DND.DragOver:
+ // dnde = new DNDEventWrapper(e);
+ // fireDragOver(dnde);
+ // break;
+ // case DND.Drop:
+ // dnde = new DNDEventWrapper(e);
+ // fireDrop(dnde);
+ // break;
+ // }
+ return SWT.None;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.papyrus.xwt.javabean.IEventHandler#handleEvent(org.eclipse.swt
+ * .widgets.Event)
+ */
+ public void handleEvent(Event e) {
+ fireEvent(e);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoader.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoader.java
new file mode 100644
index 00000000000..0adaa7863d9
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoader.java
@@ -0,0 +1,1728 @@
+/*******************************************************************************
+ * 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.javabean;
+
+import java.io.File;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.papyrus.xwt.ICLRFactory;
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.IDataProvider;
+import org.eclipse.papyrus.xwt.IEventHandler;
+import org.eclipse.papyrus.xwt.IEventInvoker;
+import org.eclipse.papyrus.xwt.IIndexedElement;
+import org.eclipse.papyrus.xwt.ILoadingContext;
+import org.eclipse.papyrus.xwt.INamespaceHandler;
+import org.eclipse.papyrus.xwt.IStyle;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.ResourceDictionary;
+import org.eclipse.papyrus.xwt.Tracking;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.XWTLoader;
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.annotation.UI;
+import org.eclipse.papyrus.xwt.callback.ICreatedCallback;
+import org.eclipse.papyrus.xwt.callback.ILoadedCallback;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.core.IDynamicBinding;
+import org.eclipse.papyrus.xwt.core.IDynamicValueBinding;
+import org.eclipse.papyrus.xwt.core.IRenderingContext;
+import org.eclipse.papyrus.xwt.core.IVisualElementLoader;
+import org.eclipse.papyrus.xwt.core.Setter;
+import org.eclipse.papyrus.xwt.core.Style;
+import org.eclipse.papyrus.xwt.input.ICommand;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+import org.eclipse.papyrus.xwt.internal.core.DataBindingTrack;
+import org.eclipse.papyrus.xwt.internal.core.IEventController;
+import org.eclipse.papyrus.xwt.internal.core.ScopeKeeper;
+import org.eclipse.papyrus.xwt.internal.utils.ClassLoaderUtil;
+import org.eclipse.papyrus.xwt.internal.utils.DocumentObjectSorter;
+import org.eclipse.papyrus.xwt.internal.utils.LoggerManager;
+import org.eclipse.papyrus.xwt.internal.utils.NamespaceHelper;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.internal.utils.TableEditorHelper;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.internal.xml.Attribute;
+import org.eclipse.papyrus.xwt.internal.xml.DocumentObject;
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.PropertiesConstants;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableItemProperty;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+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.PathHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ControlEditor;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+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.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class ResourceLoader implements IVisualElementLoader {
+
+ static Map<String, Object> EMPTY_MAP = Collections.emptyMap();
+
+ static final String RESOURCE_LOADER_PROPERTY = "XWT.ResourceLoader";
+
+ private static final String COLUMN = "Column";
+
+ private Map<String, Object> options;
+
+ protected ResourceLoader parentLoader;
+
+ protected IRenderingContext context;
+
+ protected IXWTLoader loader;
+
+ protected Object scopedObject;
+
+ protected ScopeKeeper nameScoped;
+
+ protected LoadingData loadData = new LoadingData();
+
+ protected Event loadedEvent = new Event();
+
+ class LoadingData {
+
+ protected LoadingData parent;
+
+ protected Object clr;
+
+ protected Collection<IStyle> styles = Collections.emptyList();
+
+ private Object currentWidget = null;
+
+ private Object host = null;
+
+ private Object dataContext = null;
+
+ public Object getDataContext() {
+ return dataContext;
+ }
+
+ public void setDataContext(Object dataContext) {
+ this.dataContext = dataContext;
+ }
+
+ public Object getHost() {
+ return host;
+ }
+
+ public Object getCurrentWidget() {
+ return currentWidget;
+ }
+
+ public Object findElement(Class<?> type) {
+ if(type.isInstance(currentWidget)) {
+ return currentWidget;
+ }
+ if(parent != null) {
+ return parent.findElement(type);
+ }
+ return null;
+ }
+
+ public void setCurrentWidget(Object currentWidget) {
+ this.currentWidget = currentWidget;
+ }
+
+ public LoadingData getParent() {
+ return parent;
+ }
+
+ public LoadingData() {
+ }
+
+ public LoadingData(LoadingData loadingData, Object host) {
+ this.parent = loadingData;
+ this.styles = loadingData.styles;
+ this.clr = loadingData.clr;
+ this.currentWidget = loadingData.currentWidget;
+ this.dataContext = loadingData.dataContext;
+ this.host = host;
+ }
+
+ public Collection<IStyle> getStyles() {
+ return styles;
+ }
+
+ public void setStyles(Collection<IStyle> styles) {
+ this.styles = styles;
+ }
+
+ public Object getClr() {
+ return clr;
+ }
+
+ public void setClr(Object clr) {
+ this.clr = clr;
+ }
+
+ public void inject(Object targetObject, String name) {
+ doInject(targetObject, name, null);
+ }
+
+ protected void doInject(Object targetObject, String name, Object previousClr) {
+ Class<?> filedType = targetObject.getClass();
+ if(clr != null && (previousClr != clr || previousClr == null)) {
+ for(Field field : clr.getClass().getDeclaredFields()) {
+ UI annotation = field.getAnnotation(UI.class);
+ if(annotation != null) {
+ if(!field.getType().isAssignableFrom(filedType)) {
+ continue;
+ }
+ String annotationValue = annotation.value();
+ if(annotationValue == null || annotationValue.length() == 0) {
+ if(field.getName().equals(name)) {
+ field.setAccessible(true);
+ try {
+ field.set(clr, targetObject);
+ return;
+ } catch (Exception e) {
+ }
+ }
+ } else if(annotationValue.equals(name)) {
+ field.setAccessible(true);
+ try {
+ field.set(clr, targetObject);
+ break;
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+ }
+ if(parent != null) {
+ parent.doInject(targetObject, name, clr);
+ }
+ }
+
+ public void updateEvent(IRenderingContext context, Widget control, IEvent event, String handler) {
+ IEventController eventController = UserData.updateEventController(control);
+ Method method = null;
+ Object clrObject = null;
+ LoadingData current = this;
+ ResourceLoader currentParentLoader = parentLoader;
+ while(current != null) {
+ Object receiver = current.getClr();
+ if(receiver instanceof IEventHandler) {
+ IEventHandler eventManager = (IEventHandler)receiver;
+ IEventInvoker eventInvoker = eventManager.getEventInvoker(handler, control.getClass(), Event.class);
+ if(eventInvoker != null) {
+ eventController.setEvent(event, control, control, eventInvoker);
+ }
+ } else if(receiver != null) {
+ Class<?> clazz = receiver.getClass();
+ method = ObjectUtil.findMethod(clazz, handler, control.getClass(), Event.class);
+ if(method == null) {
+ method = ObjectUtil.findMethod(clazz, handler, Event.class);
+ }
+ if(method == null) {
+ // Load again.
+ clazz = ClassLoaderUtil.loadClass(context.getLoadingContext(), clazz.getName());
+ method = ObjectUtil.findMethod(clazz, handler, Event.class);
+ }
+ if(method != null) {
+ clrObject = receiver;
+ eventController.setEvent(event, control, clrObject, control, method);
+ break;
+ }
+ }
+ current = current.getParent();
+ if(current == null && currentParentLoader != null) {
+ current = currentParentLoader.loadData;
+ currentParentLoader = currentParentLoader.parentLoader;
+ }
+ }
+ if(method == null) {
+ LoggerManager.log(new XWTException("Event handler \"" + handler + "\" is not found."));
+ }
+ }
+
+ public void end() {
+ if(parent == null || clr != parent.getClr()) {
+ Method method = ObjectUtil.findDeclaredMethod(clr.getClass(), "initializeComponent");
+ if(method == null) {
+ method = ObjectUtil.findDeclaredMethod(clr.getClass(), "InitializeComponent");
+ }
+ if(method != null) {
+ try {
+ method.setAccessible(true);
+ method.invoke(clr);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ }
+ }
+ }
+
+ public void addStyle(IStyle style) {
+ if(styles == Collections.EMPTY_LIST) {
+ styles = new ArrayList<IStyle>();
+ }
+ styles.add(style);
+ }
+ }
+
+ private DataBindingTrack dataBindingTrack;
+
+ /**
+ * @param context
+ */
+ public ResourceLoader(IRenderingContext context, IXWTLoader loader) {
+ this.context = context;
+ this.loader = loader;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IVisualElementLoader#createUIElement(org.eclipse.
+ * e4.xwt.Element, org.eclipse.papyrus.xwt.ILoadData,
+ * org.eclipse.papyrus.xwt.IResourceDictionary)
+ */
+ public Object createUIElement(Element element, Map<String, Object> options) {
+ try {
+ this.options = options;
+ Object container = options.get(IXWTLoader.CONTAINER_PROPERTY);
+ Widget parent = UserData.getWidget(container);
+ if(!loader.getTrackings().isEmpty()) {
+ dataBindingTrack = new DataBindingTrack();
+ }
+ parentLoader = (ResourceLoader)options.get(RESOURCE_LOADER_PROPERTY);
+ options.remove(RESOURCE_LOADER_PROPERTY);
+ ResourceDictionary resourceDictionary = (ResourceDictionary)options.get(IXWTLoader.RESOURCE_DICTIONARY_PROPERTY);
+
+ if(resourceDictionary != null) {
+ Object styles = resourceDictionary.get(Core.DEFAULT_STYLES_KEY);
+ if(styles != null) {
+ loadData.setStyles((Collection<IStyle>)styles);
+ resourceDictionary.remove(Core.DEFAULT_STYLES_KEY);
+ }
+ }
+ if(!options.containsKey(IXWTLoader.CLASS_FACTORY_PROPERTY)) {
+ try {
+ options.put(IXWTLoader.CLASS_FACTORY_PROPERTY, loader.getCLRFactory());
+ } catch (UnsupportedOperationException e) {
+ if(options.isEmpty()) {
+ options = new HashMap<String, Object>();
+ options.put(IXWTLoader.CLASS_FACTORY_PROPERTY, loader.getCLRFactory());
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ Object control = doCreate(parent, element, null, options);
+
+ // get databinding messages and print into console view
+ if(dataBindingTrack != null) {
+ String dataBindingMessage = dataBindingTrack.getDataBindMessage();// getDataBindMessage();
+ org.eclipse.papyrus.xwt.ILogger log = loader.getLogger();
+ log.addMessage(dataBindingMessage, Tracking.DATABINDING);
+ log.printInfo(dataBindingMessage, Tracking.DATABINDING, loader.getTrackings());
+ }
+ if(control instanceof Composite) {
+ ((Composite)control).layout();
+ }
+ ILoadedCallback loadedAction = (ILoadedCallback)options.get(IXWTLoader.LOADED_CALLBACK);
+ if(loadedAction != null) {
+ loadedAction.onLoaded(control);
+ }
+ return control;
+ } catch (Exception e) {
+ if(e instanceof RuntimeException) {
+ throw ((RuntimeException)e);
+ }
+
+ throw new XWTException(e);
+ }
+ }
+
+ protected Object doCreate(Object parent, Element element, Class<?> constraintType, Map<String, Object> options) throws Exception {
+ int styles = -1;
+ if(options.containsKey(IXWTLoader.INIT_STYLE_PROPERTY)) {
+ styles = (Integer)options.get(IXWTLoader.INIT_STYLE_PROPERTY);
+ }
+
+ ResourceDictionary dico = (ResourceDictionary)options.get(IXWTLoader.RESOURCE_DICTIONARY_PROPERTY);
+ Object dataContext = options.get(IXWTLoader.DATACONTEXT_PROPERTY);
+ Object bindingContext = options.get(IXWTLoader.BINDING_CONTEXT_PROPERTY);
+ String name = element.getName();
+ String namespace = element.getNamespace();
+ if(IConstants.XWT_X_NAMESPACE.equalsIgnoreCase(namespace)) {
+ if(IConstants.XAML_X_NULL.equalsIgnoreCase(name)) {
+ return null;
+ }
+ if(IConstants.XAML_X_TYPE.equalsIgnoreCase(name) && constraintType != null && constraintType instanceof Class<?>) {
+ DocumentObject[] children = element.getChildren();
+ if(children != null && children.length > 0) {
+ if(children[0] instanceof Element) {
+ Element type = (Element)children[0];
+ IMetaclass metaclass = loader.getMetaclass(type.getName(), type.getNamespace());
+ if(metaclass != null) {
+ return metaclass.getType();
+ }
+ }
+ } else {
+ String content = element.getContent();
+ return loader.convertFrom(Class.class, content);
+ }
+ }
+ return null;
+ }
+ IMetaclass metaclass = loader.getMetaclass(name, namespace);
+ if(constraintType != null && !(IBinding.class.isAssignableFrom(metaclass.getType())) && (!constraintType.isAssignableFrom(metaclass.getType()))) {
+ if(!constraintType.isArray() || !constraintType.getComponentType().isAssignableFrom(metaclass.getType())) {
+ IConverter converter = XWT.findConvertor(metaclass.getType(), constraintType);
+ if(converter == null) {
+ return null;
+ }
+ }
+ }
+ Object targetObject = null;
+ Integer styleValue = getStyleValue(element, styles);
+
+ if(parent == null || metaclass.getType() == Shell.class) {
+ if(dataBindingTrack != null) {
+ dataBindingTrack.addWidgetElement(element);
+ }
+ Shell shell = null;
+ if((parent == null && metaclass.getType() != Shell.class) || styleValue == null || styleValue == -1) {
+ styleValue = SWT.SHELL_TRIM;
+ }
+ Display display = Display.getCurrent();
+ shell = new Shell(display, styleValue);
+ targetObject = shell;
+ invokeCreatededAction(element, targetObject);
+ loadData.setCurrentWidget(shell);
+
+ if(metaclass.getType() != Shell.class) {
+ shell.setLayout(new FillLayout());
+ return doCreate(targetObject, element, constraintType, options);
+ } else {
+ if(bindingContext != null) {
+ setBindingContext(metaclass, targetObject, dico, bindingContext);
+ }
+ if(dataContext != null) {
+ setDataContext(metaclass, targetObject, dico, dataContext);
+ }
+ }
+ pushStack(parent);
+
+ // for Shell
+ Attribute classAttribute = element.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_CLASS);
+ if(classAttribute != null) {
+ String className = classAttribute.getContent();
+ loadShellCLR(className, shell);
+ } else {
+ Attribute classFactoryAttribute = element.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_CLASS_FACTORY);
+ ICLRFactory clrFactory = (ICLRFactory)options.get(XWTLoader.CLASS_FACTORY_PROPERTY);
+ if(classFactoryAttribute != null) {
+ String content = classFactoryAttribute.getContent();
+ Object clr = loadFactoryCLR(content, clrFactory);
+ loadData.setClr(clr);
+ UserData.setCLR(shell, clr);
+ } else {
+ if(clrFactory != null) {
+ Object clr = clrFactory.createCLR(null, options);
+ loadData.setClr(clr);
+ UserData.setCLR(shell, clr);
+ }
+ }
+ }
+ } else {
+ pushStack(parent);
+
+ //
+ // load the content in case of UserControl
+ //
+ Class<?> type = metaclass.getType();
+ URL file = type.getResource(type.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX);
+ if(file != null && nameScoped != null) {
+ if(parent instanceof Composite) {
+ Object childDataContext = getDataContext(element, (Widget)parent);
+ Object childBindingContext = getBindingContext(element, (Widget)parent);
+ if(dataContext != null) {
+ childDataContext = dataContext;
+ }
+ if(bindingContext != null) {
+ childBindingContext = bindingContext;
+ }
+ Map<String, Object> nestedOptions = new HashMap<String, Object>();
+ nestedOptions.put(IXWTLoader.CONTAINER_PROPERTY, parent);
+ if(styleValue != null) {
+ nestedOptions.put(IXWTLoader.INIT_STYLE_PROPERTY, styleValue);
+ }
+ nestedOptions.put(IXWTLoader.DATACONTEXT_PROPERTY, childDataContext);
+ nestedOptions.put(IXWTLoader.BINDING_CONTEXT_PROPERTY, childBindingContext);
+ nestedOptions.put(RESOURCE_LOADER_PROPERTY, this);
+ nestedOptions.put(IXWTLoader.CLASS_FACTORY_PROPERTY, null); // disable
+ // the
+ // global
+ // setting
+ targetObject = loader.loadWithOptions(file, nestedOptions);
+ if(targetObject == null) {
+ return null;
+ }
+ invokeCreatededAction(element, targetObject);
+ } else {
+ throw new XWTException("Cannot add user control: Parent is not a composite");
+ }
+ } else {
+ Object[] parameters = null;
+ if(TableViewerColumn.class.isAssignableFrom(type)) {
+ int columnIndex = getColumnIndex(element);
+ parameters = (styleValue != null ? new Object[]{ parent, styleValue, columnIndex } : new Object[]{ parent, SWT.NONE, columnIndex });
+ } else {
+ parameters = (styleValue != null ? new Object[]{ parent, styleValue } : new Object[]{ parent });
+ }
+
+ // x:Class
+ {
+ boolean hasClass = false;
+ Attribute classAttribute = element.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_CLASS);
+ if(classAttribute != null) {
+ String className = classAttribute.getContent();
+ targetObject = loadCLR(className, parameters, metaclass.getType(), options);
+ hasClass = true;
+ } else {
+ Object clr = options.get(XWTLoader.CLASS_PROPERTY);
+ if(clr != null) {
+ loadData.setClr(clr);
+ hasClass = true;
+ }
+ }
+ if(!hasClass) {
+ Attribute classFactoryAttribute = element.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_CLASS_FACTORY);
+ ICLRFactory clrFactory = (ICLRFactory)options.get(XWTLoader.CLASS_FACTORY_PROPERTY);
+ if(classFactoryAttribute != null) {
+ Object clr = loadFactoryCLR(classFactoryAttribute.getContent(), clrFactory);
+ if(clr != null) {
+ loadData.setClr(clr);
+ }
+ } else {
+ if(clrFactory != null) {
+ loadData.setClr(clrFactory.createCLR(null, options));
+ }
+ }
+ }
+
+ if(targetObject == null) {
+ targetObject = metaclass.newInstance(parameters);
+ invokeCreatededAction(element, targetObject);
+ Widget widget = UserData.getWidget(targetObject);
+ if(widget != null) {
+ Object clr = loadData.getClr();
+ if(clr != null) {
+ UserData.setCLR(widget, clr);
+ }
+ }
+ } else {
+ metaclass = loader.getMetaclass(targetObject);
+ }
+ }
+
+ if(targetObject == null) {
+ return null;
+ }
+ }
+ }
+ Widget widget = UserData.getWidget(targetObject);
+ if(widget != null) {
+ loadData.setCurrentWidget(targetObject);
+ }
+ if(scopedObject == null && widget != null) {
+ scopedObject = widget;
+ nameScoped = new ScopeKeeper((parent == null ? null : UserData.findScopeKeeper(parent)), widget);
+ UserData.bindNameContext(widget, nameScoped);
+ }
+
+ // set first data context and resource dictionary
+ setDataContext(metaclass, targetObject, dico, dataContext);
+ if(bindingContext != null) {
+ setBindingContext(metaclass, targetObject, dico, bindingContext);
+ }
+
+ if(dataBindingTrack != null) {
+ dataBindingTrack.tracking(targetObject, element, dataContext);
+ }
+
+ // set parent relationship and viewer
+ if(targetObject instanceof Widget) {
+ if(parent != null) {
+ UserData.setParent(targetObject, parent);
+ }
+ } else if(JFacesHelper.isViewer(targetObject)) {
+ UserData.setParent(targetObject, parent);
+ UserData.setViewer(targetObject, targetObject);
+ } else if(targetObject instanceof TableItemProperty.Cell) {
+ ((TableItemProperty.Cell)targetObject).setParent((TableItem)parent);
+ }
+
+ applyStyles(element, targetObject);
+
+ for(Map.Entry<String, Object> entry : options.entrySet()) {
+ String key = entry.getKey();
+ if(IXWTLoader.Utilities.isPropertyName(key)) {
+ continue;
+ }
+ IProperty property = metaclass.findProperty(key);
+ if(property == null) {
+ throw new XWTException("Property " + key + " not found.");
+ }
+ property.setValue(targetObject, entry.getValue());
+ }
+
+ Map<String, IProperty> delayedAttributes = new HashMap<String, IProperty>();
+ init(metaclass, targetObject, element, delayedAttributes);
+ if(targetObject instanceof Style && element.getChildren().length > 0) {
+ Collection<Setter> setters = new ArrayList<Setter>();
+ for(DocumentObject doc : element.getChildren()) {
+ Object child = doCreate(targetObject, (Element)doc, null, Collections.<String, Object> emptyMap());
+ if(!(child instanceof Setter)) {
+ throw new XWTException("Setter is expected in Style.");
+ }
+ setters.add((Setter)child);
+ }
+ ((Style)targetObject).setSetters(setters.toArray(new Setter[setters.size()]));
+ } else if(targetObject instanceof ControlEditor) {
+ for(DocumentObject doc : element.getChildren()) {
+ Object editor = doCreate(parent, (Element)doc, null, Collections.<String, Object> emptyMap());
+ if(editor != null && editor instanceof Control) {
+ ((ControlEditor)targetObject).setEditor((Control)editor);
+ ((Control)editor).setData(PropertiesConstants.DATA_CONTROLEDITOR_OF_CONTROL, targetObject);
+ }
+ }
+ } else if(targetObject instanceof IDataProvider) {
+ for(DocumentObject doc : element.getChildren()) {
+ if(IConstants.XWT_X_NAMESPACE.equals(doc.getNamespace())) {
+ String content = doc.getContent();
+ if(content != null) {
+ ((IDataProvider)targetObject).setProperty(doc.getName(), content);
+ }
+ }
+ }
+ } else {
+ for(DocumentObject doc : element.getChildren()) {
+ doCreate(targetObject, (Element)doc, null, Collections.<String, Object> emptyMap());
+ }
+ }
+
+ iniDelayedAttribute(metaclass, targetObject, element, null, delayedAttributes);
+
+ postCreation(targetObject);
+ popStack();
+ return targetObject;
+ }
+
+ protected void iniDelayedAttribute(IMetaclass metaclass, Object targetObject, Element element, String namespace, Map<String, IProperty> delayedAttributes) throws Exception {
+ Set<String> keys = delayedAttributes.keySet();
+ while(!keys.isEmpty()) {
+ for(String delayed : keys.toArray(new String[keys.size()])) {
+ IProperty property = delayedAttributes.get(delayed);
+ boolean hasDependency = false;
+ IProperty[] dependencies = property.getLoadingType().getDependencies();
+ if(dependencies.length > 0) {
+ for(IProperty dependency : dependencies) {
+ if(delayedAttributes.containsValue(dependency)) {
+ hasDependency = true;
+ break;
+ }
+ }
+ }
+ if(!hasDependency) {
+ initAttribute(metaclass, targetObject, element, null, delayed);
+ keys.remove(delayed);
+ }
+ }
+ }
+ }
+
+ /**
+ * This method is invoked directly after creation of component instance, but
+ * before applying its attributes and creating children.
+ *
+ * @param element
+ * the source element in XML.
+ * @param targetObject
+ * the created visual object.
+ */
+ protected void postCreation0(Element element, Object targetObject) {
+ }
+
+ private void invokeCreatededAction(Element element, Object targetObject) {
+ if(targetObject != null) {
+ postCreation0(element, targetObject);
+ }
+ if(options != null) {
+ ICreatedCallback createdAction = (ICreatedCallback)options.get(IXWTLoader.CREATED_CALLBACK);
+ if(createdAction != null) {
+ createdAction.onCreated(targetObject);
+ }
+ }
+ }
+
+ /**
+ * This method is invoked after full creation of component, i.e. after
+ * creating its instance, applying its attributes and creating children.
+ */
+ protected void postCreation(Object target) {
+ }
+
+ protected void setDataContext(IMetaclass metaclass, Object targetObject, ResourceDictionary dico, Object dataContext) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
+ Object control = null;
+ IMetaclass widgetMetaclass = metaclass;
+ if(JFacesHelper.isViewer(targetObject)) {
+ Widget widget = JFacesHelper.getControl(targetObject);
+ widgetMetaclass = loader.getMetaclass(widget.getClass());
+ control = targetObject;
+ } else if(targetObject instanceof Widget) {
+ control = targetObject;
+ } else {
+ control = loadData.getCurrentWidget();
+ }
+ if(control != null) {
+ if(targetObject instanceof IDynamicBinding) {
+ IDynamicBinding dynamicBinding = (IDynamicBinding)targetObject;
+ dynamicBinding.setControl(control);
+ dynamicBinding.setHost(loadData.getHost());
+ }
+ if(dico != null) {
+ UserData.setResources(control, dico);
+ }
+ if(dataContext != null) {
+ IProperty property = widgetMetaclass.findProperty(IConstants.XAML_DATA_CONTEXT);
+ if(property != null) {
+ property.setValue(UserData.getWidget(control), dataContext);
+ } else {
+ throw new XWTException("DataContext is missing in " + widgetMetaclass.getType().getName());
+ }
+ }
+ }
+ }
+
+ protected void setBindingContext(IMetaclass metaclass, Object targetObject, ResourceDictionary dico, Object bindingContext) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
+ Object control = null;
+ IMetaclass widgetMetaclass = metaclass;
+ if(JFacesHelper.isViewer(targetObject)) {
+ Widget widget = JFacesHelper.getControl(targetObject);
+ widgetMetaclass = loader.getMetaclass(widget.getClass());
+ control = targetObject;
+ } else if(targetObject instanceof Widget) {
+ control = targetObject;
+ } else {
+ control = loadData.getCurrentWidget();
+ }
+ if(control != null) {
+ if(targetObject instanceof IDynamicBinding) {
+ IDynamicBinding dynamicBinding = (IDynamicBinding)targetObject;
+ dynamicBinding.setControl(control);
+ dynamicBinding.setHost(loadData.getHost());
+ }
+ if(dico != null) {
+ UserData.setResources(control, dico);
+ }
+ if(bindingContext != null) {
+ IProperty property = widgetMetaclass.findProperty(IConstants.XAML_BINDING_CONTEXT);
+ if(property != null) {
+ property.setValue(UserData.getWidget(control), bindingContext);
+ } else {
+ throw new XWTException("DataContext is missing in " + widgetMetaclass.getType().getName());
+ }
+ }
+ }
+ }
+
+ protected void applyStyles(Element element, Object targetObject) throws Exception {
+ if(targetObject instanceof Widget) {
+ Widget widget = (Widget)targetObject;
+ Map<String, Object> dico = UserData.getLocalResources(widget);
+ Attribute attribute = element.getAttribute(IConstants.XAML_RESOURCES);
+ if(attribute == null) {
+ attribute = element.getAttribute(IConstants.XWT_NAMESPACE, IConstants.XAML_RESOURCES);
+ }
+ if(attribute != null) {
+ if(attribute.getChildren().length > 0) {
+ if(dico == null) {
+ dico = new ResourceDictionary();
+ UserData.setResources(widget, dico);
+ }
+
+ for(DocumentObject doc : attribute.getChildren()) {
+ Element elem = (Element)doc;
+ Object doCreate = doCreate(widget, elem, null, EMPTY_MAP);
+ Attribute keyAttribute = elem.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_KEY);
+ if(keyAttribute == null) {
+ keyAttribute = elem.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_TYPE);
+ }
+ if(keyAttribute != null) {
+ dico.put(keyAttribute.getContent(), doCreate);
+ }
+ if(doCreate instanceof IStyle) {
+ IStyle style = (IStyle)doCreate;
+ loadData.addStyle(style);
+ }
+ }
+ }
+ }
+
+ // apply the styles defined in parent's resources via TargetType
+ Widget current = widget;
+ while(current != null) {
+ dico = UserData.getLocalResources(current);
+ if(dico != null) {
+ for(Object value : dico.values()) {
+ if(value instanceof Style) {
+ Style style = (Style)value;
+ Class<?> targetType = style.getTargetType();
+ if(targetType != null && targetType.isInstance(widget)) {
+ style.apply(targetObject);
+ }
+ }
+ }
+ }
+ current = UserData.getTreeParent(current);
+ }
+ }
+
+ for(IStyle style : loadData.getStyles()) {
+ style.applyStyle(targetObject);
+ }
+ }
+
+ protected int getColumnIndex(Element columnElement) {
+ String name = columnElement.getName();
+ String namespace = columnElement.getNamespace();
+ IMetaclass metaclass = loader.getMetaclass(name, namespace);
+ int index = -1;
+ Class<?> type = metaclass.getType();
+ if(TableViewerColumn.class.isAssignableFrom(type)) {
+ DocumentObject parent = columnElement.getParent();
+ List<DocumentObject> children = DocumentObjectSorter.sortWithAttr(parent.getChildren(), "Index");
+ index = children.indexOf(columnElement);
+ }
+
+ return index;
+ }
+
+ /**
+ * @param tableItem
+ */
+ protected void installTableEditors(TableItem tableItem) {
+ Table table = tableItem.getParent();
+ TableColumn[] columns = table.getColumns();
+ if(columns == null || columns.length == 0) {
+ return;
+ }
+ for(TableColumn tableColumn : columns) {
+ Object data = tableColumn.getData(PropertiesConstants.DATA_DEFINED_EDITOR);
+ if(data == null || !(data instanceof Element)) {
+ continue;
+ }
+ int column = table.indexOf(tableColumn);
+ Element editor = (Element)data;
+ try {
+ TableEditor tableEditor = (TableEditor)doCreate(table, editor, null, EMPTY_MAP);
+ if(tableEditor != null) {
+ tableEditor.setColumn(column);
+ tableEditor.setItem(tableItem);
+ }
+ } catch (Exception e) {
+ continue;
+ }
+ }
+ }
+
+ protected Object getDataContext(Element element, Widget swtObject) {
+ // x:DataContext
+ try {
+ Object dataContext = loadData.getDataContext();
+ if(dataContext != null) {
+ return dataContext;
+ }
+ {
+ Attribute dataContextAttribute = element.getAttribute(IConstants.XAML_DATA_CONTEXT);
+ if(dataContextAttribute != null) {
+ Widget composite = swtObject;
+ DocumentObject documentObject = dataContextAttribute.getChildren()[0];
+ if(IConstants.XAML_STATICRESOURCES.equals(documentObject.getName()) || IConstants.XAML_DYNAMICRESOURCES.equals(documentObject.getName())) {
+ String key = documentObject.getContent();
+ dataContext = new StaticResourceBinding(composite, key);
+ loadData.setDataContext(dataContext);
+ return dataContext;
+ } else if(IConstants.XAML_BINDING.equals(documentObject.getName())) {
+ dataContext = doCreate(swtObject, (Element)documentObject, null, EMPTY_MAP);
+ loadData.setDataContext(dataContext);
+ return dataContext;
+ } else {
+ LoggerManager.log(new UnsupportedOperationException(documentObject.getName()));
+ }
+ }
+ }
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+
+ return null;
+ }
+
+ protected Object getBindingContext(Element element, Widget swtObject) {
+ // x:DataContext
+ try {
+ {
+ Attribute dataContextAttribute = element.getAttribute(IConstants.XAML_BINDING_CONTEXT);
+ if(dataContextAttribute != null) {
+ Widget composite = swtObject;
+ DocumentObject documentObject = dataContextAttribute.getChildren()[0];
+ if(IConstants.XAML_STATICRESOURCES.equals(documentObject.getName()) || IConstants.XAML_DYNAMICRESOURCES.equals(documentObject.getName())) {
+ String key = documentObject.getContent();
+ return new StaticResourceBinding(composite, key);
+ } else if(IConstants.XAML_BINDING.equals(documentObject.getName())) {
+ return doCreate(swtObject, (Element)documentObject, null, EMPTY_MAP);
+ } else {
+ LoggerManager.log(new UnsupportedOperationException(documentObject.getName()));
+ }
+ }
+ }
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+
+ return null;
+ }
+
+ protected void pushStack(Object host) {
+ loadData = new LoadingData(loadData, host);
+ }
+
+ protected void popStack() {
+ LoadingData previous = loadData;
+ loadData = previous.getParent();
+
+ previous.end();
+ }
+
+ protected Integer getStyleValue(Element element, int styles) {
+ Attribute attribute = element.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_STYLE);
+ if(attribute == null) {
+ if(styles != -1) {
+ return styles;
+ }
+ return null;
+ }
+ if(styles == -1) {
+ return (Integer)loader.findConvertor(String.class, Integer.class).convert(attribute.getContent());
+ }
+ return styles | (Integer)loader.findConvertor(String.class, Integer.class).convert(attribute.getContent());
+ }
+
+ protected void init(IMetaclass metaclass, Object targetObject, Element element, Map<String, IProperty> delayedAttributes) throws Exception {
+ // editors for TableItem,
+ if(targetObject instanceof TableItem) {
+ installTableEditors((TableItem)targetObject);
+ }
+
+ // x:DataContext
+ if(loadData.getDataContext() == null) {
+ Attribute dataContextAttribute = element.getAttribute(IConstants.XAML_DATA_CONTEXT);
+ if(dataContextAttribute != null) {
+ IProperty property = metaclass.findProperty(IConstants.XAML_DATA_CONTEXT);
+ Widget composite = UserData.getWidget(targetObject);
+ DocumentObject documentObject = dataContextAttribute.getChildren()[0];
+ if(IConstants.XAML_STATICRESOURCES.equals(documentObject.getName()) || IConstants.XAML_DYNAMICRESOURCES.equals(documentObject.getName())) {
+ String key = documentObject.getContent();
+ property.setValue(composite, new StaticResourceBinding(composite, key));
+ } else if(IConstants.XAML_BINDING.equals(documentObject.getName())) {
+ Object object = doCreate(targetObject, (Element)documentObject, null, EMPTY_MAP);
+ property.setValue(composite, object);
+ } else {
+ LoggerManager.log(new UnsupportedOperationException(documentObject.getName()));
+ }
+ }
+ }
+
+ HashSet<String> done = new HashSet<String>();
+
+ Attribute nameAttr = element.getAttribute(IConstants.XAML_X_NAME);
+ if(nameAttr == null) {
+ nameAttr = element.getAttribute(IConstants.XWT_X_NAMESPACE, IConstants.XAML_X_NAME);
+ }
+ if(nameAttr != null && UserData.getWidget(targetObject) != null) {
+ String value = nameAttr.getContent();
+ loadData.inject(targetObject, value);
+
+ nameScoped.addNamedObject(value, targetObject);
+ UserData.setElementName(targetObject, value, false);
+ done.add(IConstants.XAML_X_NAME);
+ }
+
+ for(String attrName : element.attributeNames()) {
+ IProperty property = metaclass.findProperty(attrName);
+ if(IConstants.XWT_X_NAMESPACE.equals(element.getAttribute(attrName).getNamespace())) {
+ continue;
+ } else if(delayedAttributes != null && property != null && property.getLoadingType().getValueLoading() != IValueLoading.Normal) {
+ delayedAttributes.put(attrName, property);
+ } else {
+ if(!done.contains(attrName)) {
+ initAttribute(metaclass, targetObject, element, null, attrName);
+ done.add(attrName);
+ }
+ }
+ }
+
+ for(String namespace : element.attributeNamespaces()) {
+ if(IConstants.XWT_X_NAMESPACE.equals(namespace)) {
+ for(String attrName : element.attributeNames(namespace)) {
+ if("class".equalsIgnoreCase(attrName) || IConstants.XAML_STYLE.equalsIgnoreCase(attrName)) {
+ continue; // done before
+ } else if(IConstants.XAML_X_NAME.equalsIgnoreCase(attrName)) {
+ nameScoped.addNamedObject(element.getAttribute(namespace, attrName).getContent(), targetObject);
+ done.add(attrName);
+ } else if(IConstants.XAML_DATA_CONTEXT.equalsIgnoreCase(attrName)) {
+ continue; // done before
+ } else if(IConstants.XAML_X_ARRAY.equalsIgnoreCase(attrName)) {
+ IProperty property = metaclass.findProperty(attrName);
+ Class<?> type = property.getType();
+ Object value = getArrayProperty(type, targetObject, element, attrName);
+ if(value != null) {
+ property.setValue(targetObject, value);
+ }
+ } else if(IConstants.XAML_RESOURCES.equalsIgnoreCase(attrName)) {
+ continue;
+ } else {
+ if(!done.contains(attrName)) {
+ initAttribute(metaclass, targetObject, element, namespace, attrName);
+ done.add(attrName);
+ }
+ }
+ }
+ continue;
+ }
+
+ for(String attrName : element.attributeNames(namespace)) {
+ if(IConstants.XAML_X_NAME.equalsIgnoreCase(attrName) && (targetObject instanceof Widget)) {
+ continue;
+ }
+ if(!done.contains(attrName)) {
+ initAttribute(metaclass, targetObject, element, namespace, attrName);
+ done.add(attrName);
+ }
+ }
+ }
+ for(String attrName : element.attributeNames()) {
+ if(IConstants.XAML_X_NAME.equalsIgnoreCase(attrName) && UserData.getWidget(targetObject) != null) {
+ continue;
+ }
+ if(!done.contains(attrName) && !delayedAttributes.containsKey(attrName)) {
+ initAttribute(metaclass, targetObject, element, null, attrName);
+ done.add(attrName);
+ }
+ }
+
+ //
+ // handle foreigner namespace
+ //
+ for(String namespace : element.attributeNamespaces()) {
+ if(XWT.isXWTNamespace(namespace)) {
+ continue;
+ }
+ INamespaceHandler namespaceHandler = loader.getNamespaceHandler(namespace);
+ if(namespaceHandler != null) {
+ for(String attrName : element.attributeNames(namespace)) {
+ Attribute attribute = element.getAttribute(namespace, attrName);
+ Widget widget = UserData.getWidget(loadData.getCurrentWidget());
+ namespaceHandler.handleAttribute(widget, targetObject, attrName, attribute.getContent());
+ }
+ }
+ }
+ }
+
+ protected Object getArrayProperty(Class<?> type, Object swtObject, DocumentObject docObject, String attrName) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
+ Class<?> arrayType = null;
+ if(type == Object.class) {
+ if(docObject instanceof Element) {
+ Element element = (Element)docObject;
+ Attribute attribute = element.getAttribute(IConstants.XWT_NAMESPACE, IConstants.XAML_X_TYPE);
+ if(attribute == null) {
+ throw new XWTException("The type attribute is missing in the element x:Array.");
+ }
+ String value = attribute.getContent();
+ IMetaclass metaclass = XWT.getMetaclass(value, attribute.getNamespace());
+ if(metaclass == null) {
+ throw new XWTException("The type \"" + value + "\" is not found.");
+ }
+ arrayType = metaclass.getType();
+ }
+ } else {
+ if(!type.isArray()) {
+ throw new XWTException("Type mismatch: property " + attrName + " isn't an array.");
+ }
+ arrayType = type.getComponentType();
+ }
+ if(arrayType != null) {
+ List<Object> list = new ArrayList<Object>();
+ for(DocumentObject childModel : docObject.getChildren()) {
+ if(!(childModel instanceof Element)) {
+ continue;
+ }
+ Object child = createInstance(swtObject, (Element)childModel);
+ list.add(child);
+ }
+ Object[] array = (Object[])Array.newInstance(arrayType, list.size());
+ list.toArray(array);
+
+ for(int i = 0; i < array.length; i++) {
+ if(array[i] instanceof IIndexedElement) {
+ ((IIndexedElement)array[i]).setIndex(swtObject, i);
+ }
+ }
+ return array;
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Object getCollectionProperty(Class<?> type, Object swtObject, DocumentObject element, String attrName) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
+ Collection<Object> collector = null;
+ if(type.isInterface()) {
+ collector = new ArrayList<Object>();
+ } else {
+ if(Modifier.isAbstract(type.getModifiers())) {
+ LoggerManager.log(new XWTException("Collection " + type.getSimpleName() + " is abstract type"));
+ }
+ try {
+ collector = (Collection)type.newInstance();
+ } catch (InstantiationException e) {
+ LoggerManager.log(new XWTException(e));
+ }
+ }
+
+ for(DocumentObject childModel : element.getChildren()) {
+ if(!(childModel instanceof Element)) {
+ continue;
+ }
+ Object child = createInstance(swtObject, (Element)childModel);
+ collector.add(child);
+ if(child instanceof IIndexedElement) {
+ ((IIndexedElement)child).setIndex(swtObject, collector.size() - 1);
+ }
+ }
+ return collector;
+ }
+
+ protected String findNamespace(DocumentObject context, String prefix) {
+ while(context != null && !(context instanceof Element)) {
+ context = context.getParent();
+ }
+ if(context == null) {
+ return null;
+ }
+ Element element = (Element)context;
+
+ if(prefix != null) {
+ prefix = (prefix.length() == 0 ? null : prefix);
+ }
+
+ String namespace = element.getXmlns(prefix);
+ if(namespace != null) {
+ return namespace;
+ }
+ DocumentObject parent = element.getParent();
+ return findNamespace(parent, prefix);
+ }
+
+ protected Object createInstance(Object swtObject, Element element) {
+ String name = element.getName();
+ String namespace = element.getNamespace();
+ if(IConstants.XWT_X_NAMESPACE.equalsIgnoreCase(namespace) && IConstants.XAML_X_NULL.equalsIgnoreCase(name)) {
+ return null;
+ }
+ try {
+ Class<?> type = NamespaceHelper.loadCLRClass(context.getLoadingContext(), name, namespace);
+ IMetaclass metaclass = loader.getMetaclass(name, namespace);
+ if(type == null) {
+ if(metaclass != null) {
+ type = metaclass.getType();
+ }
+ }
+ if(metaclass == null) {
+ throw new XWTException("Class for " + name + " is not found.");
+ }
+ // type = expected type;
+ // Need to support the
+ String content = element.getContent();
+ Object instance = null;
+ if(content == null) {
+ instance = metaclass.newInstance(new Object[]{ swtObject });
+ invokeCreatededAction(element, instance);
+ if(instance instanceof TableEditor) {
+ // TODO should be moved into IMetaclass
+ TableEditor tableEditor = (TableEditor)instance;
+ if(swtObject instanceof TableItem) {
+ TableItem item = (TableItem)swtObject;
+ tableEditor.setItem(item);
+ for(DocumentObject doc : element.getChildren()) {
+ Control control = (Control)doCreate(((TableItem)swtObject).getParent(), (Element)doc, null, EMPTY_MAP);
+ tableEditor.setEditor(control);
+ int column = getColumnValue(element);
+ TableEditorHelper.initEditor(item, control, column);
+ }
+ }
+ }
+ } else {
+ Constructor<?> constructor = type.getConstructor(type);
+ if(constructor != null) {
+ instance = constructor.newInstance(loader.convertFrom(type, content));
+ invokeCreatededAction(element, instance);
+ } else {
+ LoggerManager.log(new XWTException("Constructor \"" + name + "(" + type.getSimpleName() + ")\" is not found"));
+ }
+ }
+ Map<String, IProperty> delayedAttributes = new HashMap<String, IProperty>();
+ init(metaclass, instance, element, delayedAttributes);
+ iniDelayedAttribute(metaclass, instance, element, null, delayedAttributes);
+
+ for(DocumentObject doc : element.getChildren()) {
+ doCreate(instance, (Element)doc, null, Collections.<String, Object> emptyMap());
+ }
+ return instance;
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ return null;
+ }
+
+ static protected int getColumnValue(Element context) {
+ Attribute attribute = context.getAttribute(COLUMN);
+ if(attribute != null) {
+ String content = attribute.getContent();
+ if(content != null) {
+ return Integer.parseInt(content);
+ }
+ }
+ return 0;
+ }
+
+ protected void loadShellCLR(String className, Shell shell) {
+ Class<?> type = ClassLoaderUtil.loadClass(context.getLoadingContext(), className);
+ try {
+ Object instance = type.newInstance();
+ loadData.setClr(instance);
+ UserData.setCLR(shell, instance);
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ }
+
+ protected Object loadFactoryCLR(String value, ICLRFactory factory) {
+ String token;
+ String arg;
+ if(value.startsWith("+")) {
+ if(factory == null) {
+ throw new XWTException("ICLRFactory option is missing.");
+ }
+ arg = value.substring(1).trim();
+ return factory.createCLR(arg, options);
+ } else {
+ StringTokenizer stringTokenizer = new StringTokenizer(value);
+ if(!stringTokenizer.hasMoreTokens()) {
+ throw new XWTException("x:ClassFactory is empty");
+ }
+ token = stringTokenizer.nextToken();
+ arg = value.substring(token.length()).trim();
+ }
+ int index = token.lastIndexOf('.');
+ if(index != -1) {
+ String memberName = token.substring(index + 1);
+ String typeName = token.substring(0, index);
+ Class<?> type = ClassLoaderUtil.loadClass(context.getLoadingContext(), typeName);
+ if(type != null) {
+ Object member = ClassLoaderUtil.loadMember(context.getLoadingContext(), type, memberName, false);
+ if(member instanceof ICLRFactory) {
+ factory = (ICLRFactory)member;
+ }
+ if(factory != null) {
+ return factory.createCLR(arg, options);
+ }
+ }
+ }
+ Class<?> type = ClassLoaderUtil.loadClass(context.getLoadingContext(), token);
+ if(type != null && ICLRFactory.class.isAssignableFrom(type)) {
+ try {
+ ICLRFactory localFactory = (ICLRFactory)type.newInstance();
+ return localFactory.createCLR(arg, options);
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+ throw new XWTException(value + " ClassFactory not found.");
+ }
+
+ protected Object loadCLR(String className, Object[] parameters, Class<?> currentTagType, Map<String, Object> options) {
+ Class<?> type = ClassLoaderUtil.loadClass(context.getLoadingContext(), className);
+ if(type == null) {
+ return null;
+ }
+ try {
+ Object clr = options.get(XWTLoader.CLASS_PROPERTY);
+ if(clr != null && type.isInstance(clr)) {
+ loadData.setClr(clr);
+ if(clr instanceof Widget) {
+ UserData.setCLR(clr, clr);
+ }
+ } else if(currentTagType != null && currentTagType.isAssignableFrom(type)) {
+ IMetaclass metaclass = loader.getMetaclass(type);
+ Object instance = metaclass.newInstance(parameters);
+ loadData.setClr(instance);
+ // use x:Class's instance
+ if(instance instanceof Widget) {
+ UserData.setCLR(instance, instance);
+ }
+ return instance;
+ } else {
+ Object instance = type.newInstance();
+ loadData.setClr(instance);
+ if(instance instanceof Widget) {
+ UserData.setCLR(instance, instance);
+ }
+ }
+ } catch (Exception e) {
+ LoggerManager.log(e);
+ }
+ return null;
+ }
+
+ protected void initAttribute(IMetaclass metaclass, Object targetObject, Element element, String namespace, String attrName) throws Exception {
+ if(attrName.indexOf('.') != -1) {
+ String[] segments = attrName.split("\\.");
+ IMetaclass currentMetaclass = metaclass;
+ Object target = targetObject;
+ for(int i = 0; i < segments.length - 1; i++) {
+ IProperty property = currentMetaclass.findProperty(segments[i]);
+ if(property != null) {
+ target = property.getValue(target);
+ if(target == null) {
+ LoggerManager.log(new XWTException("Property \"" + segments[i] + "\" is null."));
+ }
+ currentMetaclass = loader.getMetaclass(target);
+ } else {
+ LoggerManager.log(new XWTException("Property \"" + segments[i] + "\" not found in " + element.getName() + "."));
+ }
+ }
+ initSegmentAttribute(currentMetaclass, segments[segments.length - 1], target, element, namespace, attrName);
+ return;
+ }
+ initSegmentAttribute(metaclass, attrName, targetObject, element, namespace, attrName);
+ }
+
+ protected void addCommandExecuteListener(String commandName, final Widget targetButton) {
+ final ICommand commandObj = loader.getCommand(commandName);
+ if(commandObj != null) {
+ targetButton.addListener(SWT.Selection, new Listener() {
+
+ public void handleEvent(Event event) {
+ commandObj.execute(targetButton);
+ }
+ });
+ }
+ }
+
+ protected void initSegmentAttribute(IMetaclass metaclass, String propertyName, Object target, Element element, String namespace, String attrName) throws Exception {
+ Attribute attribute = namespace == null ? element.getAttribute(attrName) : element.getAttribute(namespace, attrName);
+ if(attribute == null) {
+ attribute = element.getAttribute(attrName);
+ }
+ IProperty property = null;
+ boolean isAttached = false;
+ {
+ String namePrefix = attribute.getNamePrefix();
+ if(namePrefix == null) {
+ property = metaclass.findProperty(propertyName);
+ } else {
+ //
+ IMetaclass metaclassAttached = loader.getMetaclass(namePrefix, attribute.getNamespace());
+ if(metaclassAttached != null) {
+ property = metaclassAttached.findProperty(propertyName);
+ isAttached = true;
+ } else {
+ LoggerManager.log(attribute.getNamespace() + " -> " + namePrefix + " is not found.");
+ return;
+ }
+ }
+ }
+
+ if(propertyName.equals(IConstants.XAML_DATA_CONTEXT)) {
+ property = null;
+ }
+ if(IConstants.XAML_COMMAND.equalsIgnoreCase(propertyName) && ICommand.class.isAssignableFrom(property.getType()) && (target instanceof Widget)) {
+ addCommandExecuteListener(attribute.getContent(), (Widget)target);
+ }
+ if(property == null) {
+ if(options.get(IXWTLoader.DESIGN_MODE_PROPERTY) == Boolean.TRUE) {
+ return;
+ }
+ // prepare event
+ IEvent event = metaclass.findEvent(attrName);
+ if(event == null) {
+ return;
+ }
+ // add events for controls and items.
+ if(!(target instanceof Widget)) {
+ return;
+ }
+ loadData.updateEvent(context, (Widget)target, event, attribute.getContent());
+ return;
+ }
+
+ String contentValue = attribute.getContent();
+ if("MenuItem".equalsIgnoreCase(element.getName()) && "Text".equalsIgnoreCase(attrName)) {
+ Attribute attributeAccelerator = element.getAttribute("Accelerator");
+ if(attributeAccelerator != null) {
+ contentValue = contentValue + '\t' + getContentValue(attributeAccelerator.getContent());
+ }
+ }
+
+ if(contentValue != null && "Accelerator".equalsIgnoreCase(attrName)) {
+ contentValue = XWTMaps.getCombAccelerator(contentValue);
+ if(contentValue.contains("'")) {
+ contentValue = removeSubString(contentValue, "'");
+ }
+ }
+ if(contentValue != null && loader.isFileResolveType(property.getType())) {
+ contentValue = getImagePath(contentValue);
+ }
+ // if (contentValue != null
+ // && (URL.class.isAssignableFrom(property.getType()))) {
+ // contentValue = getSourceURL(contentValue);
+ // }
+ Object value = null;
+ DocumentObject[] children = attribute.getChildren();
+ boolean usingExistingValue = false;
+ if(contentValue == null) {
+ Class<?> type = property.getType();
+ if(Collection.class.isAssignableFrom(type)) {
+ value = getCollectionProperty(type, target, attribute, attrName);
+ } else {
+ Object directTarget = null;
+ if(TableViewerColumn.class.isAssignableFrom(type) && attrName.equalsIgnoreCase("columns")) {
+ children = DocumentObjectSorter.sortWithAttr(children, "Index").toArray(new DocumentObject[children.length]);
+ } else {
+ try {
+ Object propertyValue = property.getValue(target);
+ if(UserData.getWidget(propertyValue) != null) {
+ directTarget = propertyValue;
+ // use the existing property value as parent,
+ // not need to add the constraint
+ if(!property.isValueAsParent()) {
+ if(isChildTypeCompatible(attribute, type)) {
+ directTarget = null;
+ } else {
+ type = null;
+ usingExistingValue = true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ if(directTarget == null) {
+ directTarget = target;
+ }
+
+ for(DocumentObject child : children) {
+ String name = child.getName();
+ String ns = child.getNamespace();
+ if(name.equalsIgnoreCase(IConstants.XAML_X_STATIC) && ns.equals(IConstants.XWT_X_NAMESPACE)) {
+ value = getStaticValue(child);
+ } else if(name.equalsIgnoreCase(IConstants.XAML_STATICRESOURCES) && ns.equals(IConstants.XWT_NAMESPACE)) {
+ String key = child.getContent();
+ value = new StaticResourceBinding(loadData.getCurrentWidget(), key);
+ } else if((IConstants.XWT_X_NAMESPACE.equals(ns) && IConstants.XAML_X_ARRAY.equalsIgnoreCase(name))) {
+ value = getArrayProperty(property.getType(), directTarget, child, name);
+ } else if(property.getType().isArray()) {
+ value = getArrayProperty(property.getType(), directTarget, attribute, name);
+ break;
+ } else if(isAssignableFrom(element, TableColumn.class) && isAssignableFrom(child, TableEditor.class)) {
+ value = child;
+ } else if(TableViewerColumn.class.isAssignableFrom(property.getType()) && attribute.getContent() != null) {
+ value = attribute.getContent();
+ } else {
+ if("Null".equals(child.getName()) && IConstants.XWT_X_NAMESPACE.equals(child.getNamespace())) {
+ property.setValue(directTarget, null);
+ return;
+ } else {
+ value = doCreate(directTarget, (Element)child, type, EMPTY_MAP);
+ if(value == null && type != null && !(type == Table.class && "TableColumn".equals(child.getName()) && Table.class.isInstance(directTarget))) {
+ throw new XWTException(child.getName() + " cannot be a content of " + type.getName() + " " + target.getClass().getName() + "." + property.getName());
+ }
+ if(value instanceof IDynamicBinding) {
+ ((IDynamicBinding)value).setType(attrName);
+ }
+ }
+ }
+ }
+ }
+ }
+ if(contentValue != null && value == null && !IConstants.XAML_COMMAND.equalsIgnoreCase(propertyName)) {
+ if(property.getType().isInstance(Class.class)) {
+ int index = contentValue.lastIndexOf(':');
+ if(index != -1) {
+ String prefix = contentValue.substring(0, index);
+ contentValue = findNamespace(attribute, prefix) + contentValue.substring(index);
+ }
+ }
+ value = loader.convertFrom(property.getType(), contentValue);
+ }
+ if(!usingExistingValue) {
+ if(value != null) {
+ Class<?> propertyType = property.getType();
+ if(!propertyType.isAssignableFrom(value.getClass()) || (value instanceof IBinding && !(IBinding.class.isAssignableFrom(propertyType)))) {
+ Object orginalValue = value;
+ IConverter converter = loader.findConvertor(value.getClass(), propertyType);
+ if(converter != null) {
+ value = converter.convert(value);
+ if(value != null && orginalValue instanceof IBinding && !propertyType.isAssignableFrom(value.getClass())) {
+ converter = loader.findConvertor(value.getClass(), propertyType);
+ if(converter != null) {
+ value = converter.convert(value);
+ } else {
+ LoggerManager.log(new XWTException("Convertor " + value.getClass().getSimpleName() + "->" + propertyType.getSimpleName() + " is not found"));
+ }
+ }
+ } else {
+ LoggerManager.log(new XWTException("Convertor " + value.getClass().getSimpleName() + "->" + propertyType.getSimpleName() + " is not found"));
+ }
+ }
+ if(isAttached) {
+ UserData.setLocalData(target, property, value);
+ } else {
+ if(value instanceof IDynamicValueBinding) {
+ IDynamicValueBinding dynamicValueBinding = (IDynamicValueBinding)value;
+ dynamicValueBinding.setControl(loadData.findElement(Widget.class));
+ dynamicValueBinding.setProperty(property);
+ dynamicValueBinding.setObject(target);
+ }
+ property.setValue(target, value);
+ }
+ } else {
+ if(value == null) {
+ value = property.getValue(target);
+ }
+ if(value != null) {
+ // create children.
+ for(DocumentObject child : children) {
+ String name = child.getName();
+ String ns = child.getNamespace();
+ if(!IConstants.XWT_X_NAMESPACE.equals(ns) || !IConstants.XAML_X_ARRAY.equalsIgnoreCase(name)) {
+ Class<?> type = property.getType();
+ if(!Collection.class.isAssignableFrom(type)) {
+ doCreate(value, (Element)child, null, EMPTY_MAP);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(attribute.attributeNames(IConstants.XWT_NAMESPACE).length > 0) {
+ IMetaclass propertyMetaclass = loader.getMetaclass(property.getType());
+ if(value == null) {
+ value = property.getValue(target);
+ }
+ if(value != null) {
+ Map<String, IProperty> delayedAttributes = new HashMap<String, IProperty>();
+ init(propertyMetaclass, value, attribute, delayedAttributes);
+ iniDelayedAttribute(metaclass, target, element, namespace, delayedAttributes);
+ }
+ }
+ }
+
+ protected boolean isChildTypeCompatible(Attribute attribute, Class<?> type) {
+ DocumentObject[] children = attribute.getChildren();
+ if(children.length != 1) {
+ return false;
+ }
+ DocumentObject child = children[0];
+ if(!(child instanceof Element)) {
+ return false;
+ }
+ Element childElement = (Element)child;
+
+ String name = childElement.getName();
+ String namespace = childElement.getNamespace();
+ IMetaclass metaclass = loader.getMetaclass(name, namespace);
+ if(metaclass == null) {
+ return false;
+ }
+ return type.isAssignableFrom(metaclass.getType());
+ }
+
+ /**
+ * @param contentValue
+ * @return
+ */
+ protected String getSourceURL(String contentValue) {
+ URL url = null;
+ try {
+ url = new URL(contentValue);
+ } catch (MalformedURLException e) {
+ if(!contentValue.startsWith("/")) {
+ contentValue = "/" + contentValue;
+ }
+ ILoadingContext loadingContext = context.getLoadingContext();
+ URL resource = loadingContext.getResource(contentValue);
+ if(resource == null) {
+ try {
+ resource = new URL(context.getResourcePath() + contentValue);
+ return resource.toString();
+ } catch (MalformedURLException e1) {
+ }
+ } else {
+ return resource.toString();
+ }
+ }
+ if(url != null) {
+ return url.toString();
+ }
+ return contentValue;
+ }
+
+ protected Class<?> getJavaType(DocumentObject element) {
+ String name = element.getName();
+ String namespace = element.getNamespace();
+ if(IConstants.XWT_X_NAMESPACE.equalsIgnoreCase(namespace) && IConstants.XAML_X_NULL.equalsIgnoreCase(name)) {
+ return null;
+ }
+ IMetaclass metaclass = loader.getMetaclass(name, namespace);
+ if(metaclass == null) {
+ return null;
+ }
+ return metaclass.getType();
+ }
+
+ protected boolean isAssignableFrom(DocumentObject element, Class<?> type) {
+ Class<?> targetType = getJavaType(element);
+ if(targetType == null) {
+ return false;
+ }
+ return targetType.isAssignableFrom(type);
+ }
+
+ protected Object getStaticValue(DocumentObject child) {
+ DocumentObject[] children = child.getChildren();
+ if(children.length == 1) {
+ Element element = (Element)children[0];
+ if(element != null) {
+ return ClassLoaderUtil.loadStaticMember(context.getLoadingContext(), element);
+ }
+ }
+ return null;
+ }
+
+ protected String getImagePath(String contentValue) {
+ String value = contentValue;
+ try {
+ File file = new File(contentValue);
+ if(file.exists()) {
+ return file.toURI().toURL().toString();
+ }
+ if(!contentValue.startsWith("/")) {
+ URL url = context.getResourcePath();
+ if(url != null) {
+ return url.toString() + "/" + contentValue;
+ }
+ contentValue = "/" + contentValue;
+ }
+ ILoadingContext loadingContext = context.getLoadingContext();
+ URL resource = loadingContext.getResource(contentValue);
+ if(resource == null) {
+ URL resourcePath = context.getResourcePath();
+ String fPath = resourcePath.toString();
+ String absolutePath = PathHelper.getAbsolutePath(fPath, contentValue);
+ if((file = new File(absolutePath)).exists()) {
+ return file.toURI().toURL().toString();
+ }
+ resource = new URL(absolutePath);
+ }
+ return resource.toString();
+ } catch (MalformedURLException e) {
+ return value;
+ }
+ }
+
+ protected String removeSubString(String str, String subString) {
+ StringBuffer stringBuffer = new StringBuffer();
+ int lenOfsource = str.length();
+ int i;
+ int posStart;
+ for(posStart = 0; (i = str.indexOf(subString, posStart)) >= 0; posStart = i + subString.length()) {
+ stringBuffer.append(str.substring(posStart, i));
+ }
+ if(posStart < lenOfsource) {
+ stringBuffer.append(str.substring(posStart));
+ }
+ return stringBuffer.toString();
+ }
+
+ protected String getContentValue(String text) {
+ StringBuffer stringBuffer = new StringBuffer();
+ String subString = "SWT.";
+ String str = XWTMaps.getCombAccelerator(text);
+
+ if(str.contains(subString)) {
+ str = removeSubString(str, subString);
+ }
+ if(str.contains("'")) {
+ str = removeSubString(str, "'");
+ }
+ if(str.contains(" ")) {
+ str = removeSubString(str, " ");
+ }
+ if(str.contains("|")) {
+ str = str.replace('|', '+');
+ }
+ stringBuffer.append(str);
+ return stringBuffer.toString();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoaderFactory.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoaderFactory.java
new file mode 100644
index 00000000000..18e1d9fd262
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ResourceLoaderFactory.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.javabean;
+
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.core.IElementLoaderFactory;
+import org.eclipse.papyrus.xwt.core.IRenderingContext;
+import org.eclipse.papyrus.xwt.core.IVisualElementLoader;
+
+public class ResourceLoaderFactory implements IElementLoaderFactory {
+
+ public ResourceLoaderFactory() {
+ }
+
+ public IVisualElementLoader createElementLoader(IRenderingContext context, IXWTLoader loader) {
+ return new ResourceLoader(context, loader);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/StaticResourceBinding.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/StaticResourceBinding.java
new file mode 100644
index 00000000000..91b9aa9100a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/StaticResourceBinding.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.javabean;
+
+import java.util.Map;
+
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Widget;
+
+public class StaticResourceBinding implements IBinding {
+
+ protected Object widget;
+
+ protected String key;
+
+ public StaticResourceBinding(Object widget, String key) {
+ this.widget = widget;
+ this.key = key;
+ }
+
+ public Object getValue(Class<?> targetType) {
+ Widget parent = UserData.getWidget(widget);
+ while(parent != null) {
+ Map<String, Object> dico = UserData.getLocalResources(parent);
+ if(dico != null && dico.containsKey(key)) {
+ Object data = dico.get(key);
+ if(data instanceof IBinding) {
+ return ((IBinding)data).getValue(targetType);
+ }
+ return data;
+ }
+ parent = (Widget)UserData.getParent(parent);
+ }
+ throw new XWTException("Key " + key + " is not found.");
+ }
+
+ public void reset() {
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ValueConvertorRegister.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ValueConvertorRegister.java
new file mode 100644
index 00000000000..5437fba9c2c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/ValueConvertorRegister.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.javabean;
+
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+
+public class ValueConvertorRegister {
+
+ static protected HashMap<Class<?>, HashMap<Class<?>, IConverter>> register = new HashMap<Class<?>, HashMap<Class<?>, IConverter>>();
+
+ public void register(Class<?> source, Class<?> target, IConverter converter) {
+ HashMap<Class<?>, IConverter> convertors = register.get(source);
+ if(convertors == null) {
+ convertors = new HashMap<Class<?>, IConverter>();
+ register.put(source, convertors);
+ }
+ convertors.put(target, converter);
+ }
+
+ public IConverter findConverter(Class<?> source, Class<?> target) {
+ HashMap<Class<?>, IConverter> convertors = register.get(source);
+ if(convertors == null) {
+ if(source.isEnum()) {
+ convertors = register.get(Enum.class);
+ if(convertors == null) {
+ return null;
+ }
+ } else {
+ Class<?>[] interfacees = source.getInterfaces();
+ for(Class<?> class1 : interfacees) {
+ IConverter converter = findConverter(class1, target);
+ if(converter != null) {
+ return converter;
+ }
+ }
+ Class<?> superclass = source.getSuperclass();
+ if(superclass != null) {
+ IConverter converter = findConverter(superclass, target);
+ if(converter != null) {
+ return converter;
+ }
+ }
+ return null;
+ }
+ }
+ return findConverter(convertors, target);
+ }
+
+ private IConverter findConverter(HashMap<Class<?>, IConverter> convertors, Class<?> current) {
+ IConverter converter = convertors.get(current);
+ if(converter == null) {
+ if(current.isEnum()) {
+ converter = convertors.get(Enum.class);
+ }
+ }
+ if(converter == null) {
+ Class<?> superclass = current.getSuperclass();
+ if(superclass == null && current != Object.class) {
+ superclass = Object.class;
+ }
+ if(superclass != null) {
+ converter = findConverter(convertors, superclass);
+ }
+ }
+ return converter;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/AbstractMetaclass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/AbstractMetaclass.java
new file mode 100644
index 00000000000..3ff5f3aecdc
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/AbstractMetaclass.java
@@ -0,0 +1,742 @@
+/*******************************************************************************
+ * 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.javabean.metadata;
+
+import java.beans.BeanInfo;
+import java.beans.EventSetDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.papyrus.xwt.IEventConstants;
+import org.eclipse.papyrus.xwt.IEventGroup;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.BeanProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.DynamicProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.EventProperty;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.FieldProperty;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IObjectInitializer;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Region;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Monitor;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ *
+ * @author xye (xiaowei.ye@soyatec.com)
+ */
+public abstract class AbstractMetaclass implements IMetaclass {
+
+ public static IObjectInitializer[] EMPTY_INITIALIZERS = new IObjectInitializer[0];
+
+ public static IProperty[] EMPTY_PROPERTIES = new IProperty[0];
+
+ public static IEvent[] EMPTY_ROUTED_EVENTS = new IEvent[0];
+
+ protected final Map<String, IProperty> propertyCache = new HashMap<String, IProperty>();
+
+ protected Map<String, IEvent> routedEventCache = new HashMap<String, IEvent>();
+
+ protected Map<String, IEventGroup> eventGroupCache = Collections.emptyMap();
+
+ protected Class<?> type;
+
+ protected String name;
+
+ protected IMetaclass superClass;
+
+ protected IXWTLoader xwtLoader;
+
+ protected boolean buildTypedEvents;
+
+ private boolean initialize = false;
+
+ private IObjectInitializer[] initializers = EMPTY_INITIALIZERS;
+
+ protected boolean shouldIgnored(Class<?> declaredType, String propertyName, Class<?> propertyType) {
+ String packageName = "";
+ if(type.getPackage() != null) {
+ packageName = declaredType.getPackage().getName();
+ }
+ if(("data".equals(propertyName) && packageName.startsWith("org.eclipse.swt."))) {
+ return true;
+ }
+ if("class".equals(propertyName)) {
+ return true;
+ }
+ if(("handle".equals(propertyName) && int.class == propertyType) || ("monitor".equals(propertyName) && Monitor.class == propertyType) || ("region".equals(propertyName) && Region.class == propertyType) || ("parent".equals(propertyName) && Composite.class == propertyType) || ("shell".equals(propertyName) && Shell.class == propertyType) || ("display".equals(propertyName) && Display.class == propertyType)) {
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean isWidgetType(Class<?> type) {
+ Class<?> superClass = type.getSuperclass();
+ if(superClass != null) {
+ if(superClass.getName().equalsIgnoreCase(Widget.class.getName())) {
+ return true;
+ } else {
+ return isWidgetType(superClass);
+ }
+ }
+ return false;
+ }
+
+ protected final IXWTLoader getXWTLoader() {
+ return xwtLoader;
+ }
+
+ public IProperty addProperty(IProperty property) {
+ String name = normalize(property.getName());
+ return propertyCache.put(name, property);
+ }
+
+ public void removeProperty(String propertyName) {
+ String name = normalize(propertyName);
+ propertyCache.remove(name);
+ }
+
+ private void buildTypedEvents() {
+ if(buildTypedEvents) {
+ return;
+ }
+ if(isSubclassOf(getXWTLoader().getMetaclass(Widget.class))) {
+ addTypedEvent(IEventConstants.ACTIVATE, SWT.Activate);
+ addTypedEvent(IEventConstants.ARM, SWT.Arm);
+ addTypedEvent(IEventConstants.CLOSE, SWT.Close);
+ addTypedEvent(IEventConstants.COLLAPSE, SWT.Collapse);
+ addTypedEvent(IEventConstants.DEACTIVATE, SWT.Deactivate);
+ addTypedEvent(IEventConstants.DEFAULT_SELECTION, SWT.DefaultSelection);
+ addTypedEvent(IEventConstants.DEICONIFY, XWTMaps.getEvent("swt.deiconify"));
+ addTypedEvent(IEventConstants.DISPOSE, SWT.Dispose);
+ addTypedEvent(IEventConstants.DRAG_SELECT, SWT.DragDetect);
+ addTypedEvent(IEventConstants.ERASE_ITEM, XWTMaps.getEvent("swt.eraseitem"));
+ addTypedEvent(IEventConstants.EXPAND, SWT.Expand);
+ addTypedEvent(IEventConstants.FOCUS_IN, SWT.FocusIn);
+ addTypedEvent(IEventConstants.FOCUS_OUT, SWT.FocusOut);
+ addTypedEvent(IEventConstants.HARD_KEY_DOWN, XWTMaps.getEvent("swt.hardkeydown"));
+ addTypedEvent(IEventConstants.HARD_KEY_UP, XWTMaps.getEvent("swt.hardkeyup"));
+ addTypedEvent(IEventConstants.HELP, SWT.Help);
+ addTypedEvent(IEventConstants.HIDE, SWT.Hide);
+ addTypedEvent(IEventConstants.ICONIFY, XWTMaps.getEvent("swt.iconify"));
+ addTypedEvent(IEventConstants.KEY_DOWN, SWT.KeyDown);
+ addTypedEvent(IEventConstants.KEY_UP, SWT.KeyUp);
+ addTypedEvent(IEventConstants.MEASURE_ITEM, XWTMaps.getEvent("swt.measureitem"));
+ addTypedEvent(IEventConstants.MENU_DETECT, SWT.MenuDetect);
+ addTypedEvent(IEventConstants.MODIFY, SWT.Modify);
+ addTypedEvent(IEventConstants.MOUSE_DOUBLE_CLICK, SWT.MouseDoubleClick);
+ addTypedEvent(IEventConstants.MOUSE_DOWN, SWT.MouseDown);
+ addTypedEvent(IEventConstants.MOUSE_ENTER, XWTMaps.getEvent("swt.mouseenter"));
+ addTypedEvent(IEventConstants.MOUSE_EXIT, XWTMaps.getEvent("swt.mouseexit"));
+ addTypedEvent(IEventConstants.MOUSE_HOVER, XWTMaps.getEvent("swt.mousehover"));
+ addTypedEvent(IEventConstants.MOUSE_MOVE, XWTMaps.getEvent("swt.mousemove"));
+ addTypedEvent(IEventConstants.MOUSE_UP, SWT.MouseUp);
+ addTypedEvent(IEventConstants.MOUSE_WHEEL, XWTMaps.getEvent("swt.mousewheel"));
+ addTypedEvent(IEventConstants.MOVE, SWT.Move);
+ addTypedEvent(IEventConstants.PAINT, XWTMaps.getEvent("swt.paint"));
+ addTypedEvent(IEventConstants.PAINT_ITEM, XWTMaps.getEvent("swt.paintitem"));
+ addTypedEvent(IEventConstants.RESIZE, SWT.Resize);
+ addTypedEvent(IEventConstants.SELECTION, SWT.Selection); // sash
+ addTypedEvent(IEventConstants.SET_DATA, SWT.SetData);
+ // addTypedEvent ("Settings", SWT.Settings); // note: this event
+ // only goes to Display
+ addTypedEvent(IEventConstants.SHOW, SWT.Show);
+ addTypedEvent(IEventConstants.TRAVERSE, SWT.Traverse);
+ addTypedEvent(IEventConstants.VERIFY, SWT.Verify);
+ addTypedEvent(IEventConstants.IME_COMPOSITION, XWTMaps.getEvent("swt.imecomposition"));
+ }
+ buildTypedEvents = true;
+ }
+
+ private void addTypedEvent(String name, int eventType) {
+ String eventName = IEventConstants.getEventName(name);
+ if(!routedEventCache.containsKey(eventName)) {
+ TypedEvent typedEvent = new TypedEvent(name, eventType);
+ routedEventCache.put(eventName, typedEvent);
+ String eventPropertyName = IEventConstants.getEventPropertyName(name);
+ String eventDataName = IEventConstants.getEventPropertyDataName(name);
+ addProperty(new EventProperty(eventPropertyName, eventDataName, typedEvent));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#findDefaultProperty()
+ */
+ public IProperty findDefaultProperty() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.soyatec.xaswt.core.metadata.IMetaclass#findEvent(java.lang.String)
+ */
+ public IEvent findEvent(String name) {
+ assertInitialize();
+ return routedEventCache.get(normalize(name));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.soyatec.xaswt.core.metadata.IMetaclass#findProperty(java.lang.String)
+ */
+ public IProperty findProperty(String name) {
+ assertInitialize();
+ IProperty property = propertyCache.get(normalize(name));
+ if(property == null && superClass != null) {
+ property = superClass.findProperty(name);
+ }
+ if(property == null) {
+ try {
+ Method getter = DynamicProperty.createGetter(type, name);
+ if(getter == null) {
+ return null;
+ }
+ Class<?> propertyType = getter.getReturnType();
+ if(shouldIgnored(getter.getDeclaringClass(), name, propertyType)) {
+ return null;
+ }
+ Method setter = DynamicProperty.createSetter(type, propertyType, name);
+ return new DynamicProperty(propertyType, setter, getter, name);
+ } catch (NoSuchMethodException e) {
+ return null;
+ }
+
+ }
+ return property;
+ }
+
+ protected String normalize(String name) {
+ return name == null ? name : name.toLowerCase();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#getEvents()
+ */
+ public IEvent[] getEvents() {
+ assertInitialize();
+ return routedEventCache.values().toArray(new IEvent[]{});
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#getProperties()
+ */
+ public IProperty[] getProperties() {
+ assertInitialize();
+ return propertyCache.values().toArray(new IProperty[propertyCache.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#getSuperClass()
+ */
+ public IMetaclass getSuperClass() {
+ return superClass;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#getType()
+ */
+ public Class<?> getType() {
+ return type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#isAbstract()
+ */
+ public boolean isAbstract() {
+ return Modifier.isAbstract(type.getModifiers());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.soyatec.xaswt.core.metadata.IMetaclass#isAssignableFrom(com.soyatec
+ * .xaswt.core.metadata.IMetaclass)
+ */
+ public boolean isAssignableFrom(IMetaclass metaclass) {
+ return getType().isAssignableFrom(metaclass.getType());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.soyatec.xaswt.core.metadata.IMetaclass#isInstance(java.lang.Object)
+ */
+ public boolean isInstance(Object object) {
+ return type.isInstance(object);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.soyatec.xaswt.core.metadata.IMetaclass#isSubclassOf(com.soyatec.xaswt
+ * .core.metadata.IMetaclass)
+ */
+ public boolean isSubclassOf(IMetaclass metaclass) {
+ assertInitialize();
+ if(metaclass == null) {
+ return false;
+ }
+ if(this == metaclass) {
+ return true;
+ }
+ if(superClass == metaclass) {
+ return true;
+ }
+ if(superClass != null) {
+ return superClass.isSubclassOf(metaclass);
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.soyatec.xaswt.core.metadata.IMetaclass#isSuperclassOf(com.soyatec
+ * .xaswt.core.metadata.IMetaclass)
+ */
+ public boolean isSuperclassOf(IMetaclass metaclass) {
+ return metaclass.isSubclassOf(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#newInstance()
+ */
+ public Object newInstance(Object[] parameters) {
+ assertInitialize();
+ Object object = doNewInstance(parameters);
+ if(parameters != null && parameters.length > 0) {
+ try {
+ updateContainment(parameters[0], object);
+ initialize(object);
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+ return object;
+ }
+
+ private void updateContainment(Object parent, Object childElement) throws IllegalAccessException, InvocationTargetException, NoSuchFieldException {
+ if(childElement != null && parent != null && !(parent instanceof Widget)) {
+ //
+ // Add to default property identified by the type
+ //
+ IMetaclass parentMetaclass = XWT.getMetaclass(parent);
+ IProperty[] properties = parentMetaclass.getProperties();
+ IProperty useProperty = null;
+ int count = 0;
+ Class<?> childType = childElement.getClass();
+
+ for(IProperty property : properties) {
+ Class<?> propertyType = property.getType();
+ if(propertyType == null || propertyType == Object.class) {
+ continue;
+ }
+ if(property.isContainement()) {
+ useProperty = property;
+ count++;
+ }
+ }
+ if(count > 1) {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Class has more containment properties: ");
+ count = 0;
+ for(IProperty property : properties) {
+ Class<?> propertyType = property.getType();
+ if(propertyType == null || propertyType == Object.class) {
+ continue;
+ }
+ if(property.isContainement()) {
+ if(count != 0) {
+ builder.append(", ");
+ }
+ builder.append(property.getName());
+ count++;
+ }
+ }
+ throw new XWTException("Class has more containment properties: ");
+ }
+
+ if(count == 0) {
+ for(IProperty property : properties) {
+ Class<?> propertyType = property.getType();
+ if(propertyType == null || propertyType == Object.class) {
+ continue;
+ }
+ if(propertyType.isArray()) {
+ Class<?> dataType = propertyType.getComponentType();
+ if(dataType.isAssignableFrom(childType)) {
+ if(useProperty == null) {
+ useProperty = property;
+ }
+ count++;
+ }
+ } else if(Collection.class.isAssignableFrom(propertyType)) {
+ if(useProperty == null) {
+ useProperty = property;
+ }
+ count++;
+ } else if(propertyType.isAssignableFrom(childType)) {
+ if(useProperty == null) {
+ useProperty = property;
+ }
+ count++;
+ }
+ }
+ }
+ if(count == 1) {
+ Class<?> propertyType = useProperty.getType();
+ if(propertyType.isArray()) {
+ Object[] existingValue = (Object[])useProperty.getValue(parent);
+ Class<?> dataType = propertyType.getComponentType();
+ Object[] value = null;
+ if(existingValue == null) {
+ value = (Object[])Array.newInstance(dataType, 1);
+ value[0] = childElement;
+ } else {
+ value = (Object[])Array.newInstance(dataType, existingValue.length + 1);
+ System.arraycopy(existingValue, 0, value, 0, existingValue.length);
+ value[existingValue.length] = childElement;
+ }
+ useProperty.setValue(parent, value);
+ } else if(Collection.class.isAssignableFrom(propertyType) && !(childElement instanceof IBinding)) {
+ Collection<Object> existingValue = (Collection)useProperty.getValue(parent);
+ if(existingValue == null) {
+ existingValue = new ArrayList<Object>();
+ }
+ existingValue.add(childElement);
+ useProperty.setValue(parent, existingValue);
+ } else if(propertyType.isAssignableFrom(childType)) {
+ useProperty.setValue(parent, childElement);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IMetaclass#newInstance()
+ */
+ public Object doNewInstance(Object[] parameters) {
+ assertInitialize();
+ try {
+ if(parameters.length == 0 || (!(parameters[0] instanceof Widget || JFacesHelper.isViewer(parameters[0])))) {
+ return getType().newInstance();
+ }
+ } catch (InstantiationException e1) {
+ } catch (IllegalAccessException e1) {
+ }
+
+ try {
+ Object swtObject = null;
+ Object parent = parameters[0];
+ Widget directParent = UserData.getWidget(parent);
+ if(directParent == null) {
+ directParent = UserData.getTreeParent(parent);
+ }
+ if(directParent != null && Control.class.isAssignableFrom(getType()) && !(directParent instanceof Composite)) {
+ directParent = getXWTLoader().findCompositeParent(directParent);
+ }
+
+ Object styleValue = null;
+ if(parameters.length == 2 && parameters[1] != null && (parameters[1].getClass() == int.class || parameters[1].getClass() == Integer.class)) {
+ styleValue = parameters[1];
+ }
+
+ Constructor<?> defaultConstructor = null;
+ for(Constructor<?> constructor : getType().getConstructors()) {
+ Class<?>[] parameterTypes = constructor.getParameterTypes();
+ if(parameterTypes.length > 2 || parameterTypes.length == 0) {
+ if(parameterTypes.length == 0) {
+ defaultConstructor = constructor;
+ }
+ continue;
+ }
+
+ if(parameterTypes[0].isAssignableFrom(parent.getClass())) {
+ if(parameterTypes.length == 1) {
+ if(styleValue == null) {
+ swtObject = constructor.newInstance(new Object[]{ parent });
+ break;
+ }
+ } else if(parameterTypes[1].isAssignableFrom(int.class)) {
+ if(styleValue == null) {
+ swtObject = constructor.newInstance(new Object[]{ parent, 0 });
+ } else {
+ swtObject = constructor.newInstance(new Object[]{ parent, styleValue });
+ }
+ break;
+ }
+ }
+ }
+
+ if(swtObject == null) {
+ for(Constructor<?> constructor : getType().getConstructors()) {
+ Class<?>[] parameterTypes = constructor.getParameterTypes();
+ if(parameterTypes.length > 2 || parameterTypes.length == 0) {
+ if(parameterTypes.length == 0) {
+ defaultConstructor = constructor;
+ }
+ continue;
+ }
+
+ if(directParent != null && parameterTypes[0].isAssignableFrom(directParent.getClass())) {
+ if(parameterTypes.length == 1) {
+ swtObject = constructor.newInstance(new Object[]{ directParent });
+ break;
+ } else if(parameterTypes[1].isAssignableFrom(int.class)) {
+ if(styleValue == null) {
+ swtObject = constructor.newInstance(new Object[]{ directParent, 0 });
+ } else {
+ swtObject = constructor.newInstance(new Object[]{ directParent, styleValue });
+ }
+ break;
+ }
+ }
+ }
+ }
+ if(swtObject == null) {
+ if(defaultConstructor == null) {
+ if(UserData.isUIElementType(getType())) {
+ // this is used for Visual
+ Shell shell = new Shell();
+ try {
+ Constructor<?> constructor = getType().getConstructor(Composite.class, int.class);
+ if(constructor != null) {
+ return constructor.newInstance(shell, SWT.NONE);
+ }
+ } catch (Exception e) {
+ throw new XWTException("Constructor " + getType().getName() + " no found.");
+ }
+ }
+ try {
+ swtObject = getType().newInstance();
+ } catch (Exception e) {
+ throw new XWTException("Constructor " + getType().getName() + " no found.");
+ }
+ } else {
+ swtObject = defaultConstructor.newInstance();
+ }
+ }
+ return swtObject;
+ } catch (SecurityException e) {
+ throw new XWTException(e);
+ } catch (IllegalArgumentException e) {
+ throw new XWTException(e);
+ } catch (InstantiationException e) {
+ throw new XWTException(e);
+ } catch (IllegalAccessException e) {
+ throw new XWTException(e);
+ } catch (InvocationTargetException e) {
+ throw new XWTException(e);
+ }
+ }
+
+ public Class<?> getDataContextType() {
+ return Object.class;
+ }
+
+ private void assertInitialize() {
+ initialize(type, superClass);
+ }
+
+ protected void initialize(Class<?> type, IMetaclass superClass) {
+ if(isInitialize()) {
+ return;
+ }
+ try {
+ BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(type);
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for(PropertyDescriptor p : propertyDescriptors) {
+ String propertyName = p.getName();
+ Class<?> propertyType = p.getPropertyType();
+ if(p.getReadMethod() == null) {
+ continue;
+ }
+ if(shouldIgnored(p.getReadMethod().getDeclaringClass(), propertyName, propertyType) || propertyCache.containsKey(propertyName.toLowerCase())) {
+ continue;
+ }
+ if(p.getPropertyType() != null) {
+ IProperty property = (superClass != null ? superClass.findProperty(p.getName().toLowerCase()) : null);
+ if(property != null && !property.isDefault()) {
+ addProperty(property);
+ } else {
+ if(p.getWriteMethod() != null || !p.getPropertyType().isPrimitive()) {
+ addProperty(new BeanProperty(p));
+ }
+ }
+ }
+ }
+ for(Field f : type.getDeclaredFields()) {
+ if(Modifier.isStatic(f.getModifiers())) {
+ continue;
+ }
+ String propertyName = f.getName();
+ Class<?> propertyType = f.getType();
+ if(shouldIgnored(f.getDeclaringClass(), propertyName, propertyType)) {
+ continue;
+ }
+
+ if(!propertyCache.containsKey(normalize(propertyName)) && !Modifier.isFinal(f.getModifiers()) && Modifier.isPublic(f.getModifiers())) {
+ addProperty(new FieldProperty(f));
+ }
+ }
+
+ for(EventSetDescriptor eventSetDescriptor : beanInfo.getEventSetDescriptors()) {
+ String name = IEventConstants.getEventName(eventSetDescriptor.getName());
+ BeanEvent event = new BeanEvent(eventSetDescriptor.getName(), eventSetDescriptor);
+ routedEventCache.put(name, event);
+ String propertyName = IEventConstants.getEventPropertyName(eventSetDescriptor.getName());
+ String propertyDataName = IEventConstants.getEventPropertyDataName(eventSetDescriptor.getName());
+ addProperty(new EventProperty(propertyName, propertyDataName, event));
+ }
+ if(isWidgetType(type)) {
+ LoadedEvent loadedEvent = new LoadedEvent(IEventConstants.XWT_LOADED_EVENT);
+ routedEventCache.put(normalize(IEventConstants.XWT_LOADED), loadedEvent);
+ routedEventCache.put(normalize(IEventConstants.XWT_LOADED_EVENT), loadedEvent);
+ }
+
+ markInitialized();
+ buildTypedEvents();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (IntrospectionException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void markInitialized() {
+ initialize = true;
+ }
+
+ private boolean isInitialize() {
+ return initialize;
+ }
+
+ public void addEventGroup(IEventGroup eventGroup) {
+ if(eventGroupCache == Collections.<String, IEventGroup> emptyMap()) {
+ eventGroupCache = new HashMap<String, IEventGroup>();
+ }
+ for(String string : eventGroup.getEventNames()) {
+ if(eventGroupCache.containsKey(string)) {
+ throw new IllegalArgumentException("Event \"" + string + "\" already existis in a group.");
+ }
+ String key = normalize(string);
+ if("menudetecteventevent".equals(key)) {
+ System.out.println(string);
+ }
+
+ eventGroupCache.put(key, eventGroup);
+ }
+ }
+
+ public IEventGroup getEventGroup(String event) {
+ IEventGroup eventGroup = eventGroupCache.get(event);
+ if(eventGroup == null && superClass != null) {
+ return superClass.getEventGroup(event);
+ }
+ return eventGroup;
+ }
+
+ public void addInitializer(IObjectInitializer initializer) {
+ for(int i = 0; i < initializers.length; i++) {
+ if(initializers[i] == initializer) {
+ return;
+ }
+ }
+ IObjectInitializer[] oldValue = initializers;
+ initializers = new IObjectInitializer[oldValue.length + 1];
+ System.arraycopy(oldValue, 0, initializers, 0, oldValue.length);
+ initializers[oldValue.length] = initializer;
+ }
+
+ public void removeInitializer(IObjectInitializer initializer) {
+ for(int i = 0; i < initializers.length; i++) {
+ if(initializers[i] == initializer) {
+ IObjectInitializer[] oldValue = initializers;
+ initializers = new IObjectInitializer[oldValue.length - 1];
+ System.arraycopy(oldValue, 0, initializers, 0, i);
+ System.arraycopy(oldValue, i + 1, initializers, i, oldValue.length - i - 1);
+ return;
+ }
+ }
+ }
+
+ public IObjectInitializer[] getInitializers() {
+ return initializers;
+ }
+
+ public void initialize(Object instance) {
+ if(superClass != null) {
+ superClass.initialize(instance);
+ }
+
+ for(int i = 0; i < initializers.length; i++) {
+ if(initializers[i] != null) {
+ initializers[i].initialize(instance);
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BeanEvent.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BeanEvent.java
new file mode 100644
index 00000000000..4ee3a760e9e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BeanEvent.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.javabean.metadata;
+
+import java.beans.EventSetDescriptor;
+
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class BeanEvent extends Behavior implements IEvent {
+
+ protected EventSetDescriptor eventSetDescriptor;
+
+ public BeanEvent(String name, EventSetDescriptor eventSetDescriptor) {
+ super(name);
+ this.eventSetDescriptor = eventSetDescriptor;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Behavior.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Behavior.java
new file mode 100644
index 00000000000..31999d57589
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Behavior.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.javabean.metadata;
+
+import org.eclipse.papyrus.xwt.metadata.IBehavior;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public abstract class Behavior implements IBehavior {
+
+ private String name;
+
+ protected int flags;
+
+ public Behavior(String name) {
+ this.name = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.soyatec.xaswt.core.metadata.IBehavior#getName()
+ */
+ public final String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BindingMetaclass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BindingMetaclass.java
new file mode 100644
index 00000000000..39acb399cfa
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/BindingMetaclass.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.javabean.metadata;
+
+import org.eclipse.jface.viewers.ViewerColumn;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.internal.core.Binding;
+import org.eclipse.papyrus.xwt.internal.core.DynamicBinding;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.TableItemProperty;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Item;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class BindingMetaclass extends Metaclass {
+
+ public BindingMetaclass(IXWTLoader xwtLoader) {
+ this(Binding.class, xwtLoader);
+ }
+
+ public BindingMetaclass(Class<?> type, IXWTLoader xwtLoader) {
+ super(type, null, xwtLoader);
+ }
+
+ @Override
+ public Object newInstance(Object[] parameters) {
+ DynamicBinding newInstance = (DynamicBinding)super.newInstance(parameters);
+ if(JFacesHelper.isViewer(parameters[0]))
+ newInstance.setControl(parameters[0]);
+ else if(parameters[0] instanceof Control)
+ newInstance.setControl((Control)parameters[0]);
+ else if(parameters[0] instanceof TableItemProperty.Cell)
+ newInstance.setControl(((TableItemProperty.Cell)parameters[0]).getParent());
+ else if(parameters[0] instanceof Item)
+ newInstance.setControl((Item)parameters[0]);
+ else if(parameters[0] instanceof ViewerColumn) {
+ newInstance.setControl((ViewerColumn)parameters[0]);
+ }
+ newInstance.setXWTLoader(xwtLoader);
+ return newInstance;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ComboBoxCellEditorMetaclass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ComboBoxCellEditorMetaclass.java
new file mode 100644
index 00000000000..f1cfefda764
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ComboBoxCellEditorMetaclass.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.javabean.metadata;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.jface.ComboBoxCellEditor;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Widget;
+
+public class ComboBoxCellEditorMetaclass extends Metaclass {
+
+ public ComboBoxCellEditorMetaclass(IMetaclass superClass, IXWTLoader xwtLoader) {
+ super(ComboBoxCellEditor.class, superClass, xwtLoader);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.xwt.javabean.metadata.Metaclass#newInstance(java.lang. Object[])
+ */
+ @Override
+ public Object newInstance(Object[] parameters) {
+ try {
+ if(parameters.length == 1) {
+ Constructor<?> constructor = getType().getConstructor(Composite.class, String[].class);
+ return constructor.newInstance(getParent(parameters[0]), new String[]{});
+ } else if(parameters.length == 2) {
+ Constructor<?> constructor = getType().getConstructor(Composite.class, String[].class, int.class);
+ return constructor.newInstance(getParent(parameters[0]), new String[]{}, parameters[2]);
+ } else if(parameters.length == 3) {
+ Constructor<?> constructor = getType().getConstructor(Composite.class, String[].class, int.class);
+ return constructor.newInstance(getParent(parameters[0]), parameters[1], parameters[2]);
+ }
+ } catch (SecurityException e1) {
+ } catch (IllegalArgumentException e1) {
+ } catch (NoSuchMethodException e1) {
+ } catch (InstantiationException e1) {
+ } catch (IllegalAccessException e1) {
+ } catch (InvocationTargetException e1) {
+ }
+ return super.newInstance(parameters);
+ }
+
+ private Widget getParent(Object object) {
+ Widget parent = null;
+ Widget directParent = null;
+
+ if(object instanceof Widget) {
+ directParent = parent = (Widget)object;
+ } else if(JFacesHelper.isViewer(object)) {
+ directParent = parent = JFacesHelper.getControl(object);
+ } else
+ throw new IllegalStateException();
+ if(Control.class.isAssignableFrom(getType()) && !(parent instanceof Composite)) {
+ directParent = xwtLoader.findCompositeParent(parent);
+ }
+
+ return directParent;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ExpandItemHeightAction.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ExpandItemHeightAction.java
new file mode 100644
index 00000000000..150fb07d7f5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/ExpandItemHeightAction.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.javabean.metadata;
+
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.papyrus.xwt.metadata.ISetPostAction;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.ExpandItem;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class ExpandItemHeightAction implements ISetPostAction {
+
+ public void action(Object target, IProperty property, Object value) {
+ if(target instanceof ExpandItem && value instanceof Control) {
+ ExpandItem targetControl = (ExpandItem)target;
+ Control valueControl = (Control)value;
+ targetControl.setHeight(valueControl.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/LoadedEvent.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/LoadedEvent.java
new file mode 100644
index 00000000000..8e26324703d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/LoadedEvent.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.javabean.metadata;
+
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class LoadedEvent implements IEvent {
+
+ private String name;
+
+ public LoadedEvent(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Metaclass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Metaclass.java
new file mode 100644
index 00000000000..f37cdd86db2
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/Metaclass.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.javabean.metadata;
+
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.XWTLoaderManager;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+
+/**
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class Metaclass extends AbstractMetaclass {
+
+ /**
+ *
+ * @param type
+ * @param superClass
+ * @param initialize
+ */
+ public Metaclass(Class<?> type, IMetaclass superClass, boolean initialize) {
+ this(type, superClass, XWTLoaderManager.getDefault());
+ }
+
+ /**
+ *
+ * @param type
+ * @param superClass
+ * @param initialize
+ * @param xwtLoader
+ */
+ public Metaclass(Class<?> type, IMetaclass superClass, boolean initialize, IXWTLoader xwtLoader) {
+ this.type = type;
+ this.name = type.getSimpleName();
+ this.superClass = superClass;
+ this.xwtLoader = xwtLoader;
+ if(initialize) {
+ initialize(type, superClass);
+ }
+ }
+
+ /**
+ * Default initialize it
+ *
+ * @param type
+ * @param superClass
+ */
+ public Metaclass(Class<?> type, IMetaclass superClass) {
+ this(type, superClass, false, XWTLoaderManager.getDefault());
+ }
+
+ /**
+ * Default initialize it
+ *
+ * @param type
+ * @param superClass
+ */
+ public Metaclass(Class<?> type, IMetaclass superClass, IXWTLoader xwtLoader) {
+ this(type, superClass, false, xwtLoader);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableEditorMetaclass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableEditorMetaclass.java
new file mode 100644
index 00000000000..7ba87f8ab48
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableEditorMetaclass.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.javabean.metadata;
+
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Widget;
+
+public class TableEditorMetaclass extends Metaclass {
+
+ public TableEditorMetaclass(IMetaclass superClass, IXWTLoader xwtLoader) {
+ super(TableEditor.class, superClass, xwtLoader);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.xwt.javabean.metadata.Metaclass#newInstance(java.lang. Object[])
+ */
+ @Override
+ public Object newInstance(Object[] parameters) {
+ Object widget = parameters[0];
+ if(parameters.length == 0 || !(widget instanceof Widget)) {
+ throw new IllegalStateException("Table parent is missing.");
+ }
+ Table table = null;
+ if(widget instanceof Table) {
+ table = (Table)widget;
+ } else {
+ table = (Table)UserData.findParent((Widget)widget, Table.class);
+ }
+ if(table == null) {
+ throw new IllegalStateException("Table parent is missing.");
+ }
+ return super.newInstance(new Object[]{ table });
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableViewerColumnMetaClass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableViewerColumnMetaClass.java
new file mode 100644
index 00000000000..825636953c9
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TableViewerColumnMetaClass.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.javabean.metadata;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.papyrus.xwt.IXWTLoader;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class TableViewerColumnMetaClass extends Metaclass {
+
+ public TableViewerColumnMetaClass(IMetaclass superClass, IXWTLoader xwtLoader) {
+ super(TableViewerColumn.class, superClass, xwtLoader);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.xwt.javabean.metadata.Metaclass#newInstance(java.lang. Object[])
+ */
+ @Override
+ public Object newInstance(Object[] parameters) {
+ Object object = doNewInstance(parameters);
+ if(object != null) {
+ initialize(object);
+ }
+ return object;
+ }
+
+ @Override
+ public Object doNewInstance(Object[] parameters) {
+ try {
+ if(parameters.length == 1 && parameters[0] instanceof TableViewer) {
+ Constructor<?> constructor = getType().getConstructor(TableViewer.class, int.class);
+ return constructor.newInstance(parameters[0], SWT.NONE);
+ } else if(parameters.length == 2) {
+ if(parameters[0] instanceof TableViewer && parameters[1] instanceof Integer) {
+ Constructor<?> constructor = getType().getConstructor(TableViewer.class, int.class);
+ return constructor.newInstance(parameters);
+ } else if(parameters[0] instanceof TableViewer && parameters[1] instanceof TableColumn) {
+ Constructor<?> constructor = getType().getConstructor(TableViewer.class, TableColumn.class);
+ return constructor.newInstance(parameters);
+ }
+ } else if(parameters.length == 3 && parameters[0] instanceof TableViewer && parameters[1] instanceof Integer && parameters[2] instanceof Integer) {
+ Constructor<?> constructor = getType().getConstructor(TableViewer.class, int.class, int.class);
+ return constructor.newInstance(parameters[0], ((Integer)parameters[1]).intValue(), ((Integer)parameters[2]).intValue());
+ }
+ } catch (SecurityException e) {
+ } catch (IllegalArgumentException e) {
+ } catch (NoSuchMethodException e) {
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+
+ return super.newInstance(parameters);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TypedEvent.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TypedEvent.java
new file mode 100644
index 00000000000..96be32f340b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/TypedEvent.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.javabean.metadata;
+
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+
+/**
+ * @author jliu
+ */
+public class TypedEvent implements IEvent {
+
+ private String name;
+
+ private int eventType;
+
+ /**
+ * SWT event type.
+ */
+ public TypedEvent(String name, int eventType) {
+ this.name = name;
+ this.eventType = eventType;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.core.metadata.IBehavior#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ public int getEventType() {
+ return eventType;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/AbstractProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/AbstractProperty.java
new file mode 100644
index 00000000000..e38ebb8fdbe
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/AbstractProperty.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.javabean.metadata.properties;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.papyrus.xwt.javabean.metadata.Behavior;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.papyrus.xwt.metadata.ISetPostAction;
+
+public abstract class AbstractProperty extends Behavior implements IProperty {
+
+ static final int VALUE_AS_PARENT = 1 << 1;
+
+ protected Collection<ISetPostAction> setPostActions = Collections.emptyList();
+
+ private Class<?> type;
+
+ protected ILoadingType loadingType;
+
+ public AbstractProperty(String name, Class<?> type) {
+ this(name, type, ILoadingType.DEFAULT);
+ }
+
+ public AbstractProperty(String name, Class<?> type, ILoadingType loadingType) {
+ super(name);
+ setType(type);
+ this.loadingType = loadingType;
+ }
+
+ public void addSetPostAction(ISetPostAction setPostAction) {
+ if(setPostActions == Collections.EMPTY_LIST) {
+ setPostActions = new ArrayList<ISetPostAction>();
+ }
+ if(!setPostActions.contains(setPostAction)) {
+ setPostActions.add(setPostAction);
+ }
+ }
+
+ public void removeSetPostAction(ISetPostAction setPostAction) {
+ setPostActions.remove(setPostAction);
+ }
+
+ protected void fireSetPostAction(Object target, IProperty property, Object value) {
+ for(ISetPostAction setPostAction : setPostActions) {
+ setPostAction.action(target, property, value);
+ }
+ }
+
+ public boolean isDefault() {
+ return false;
+ }
+
+ public boolean isContainement() {
+ return false;
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.metadata.IProperty#setType(java.lang.Class)
+ */
+ public void setType(Class<?> type) {
+ if(type == boolean.class) {
+ type = Boolean.class;
+ } else if(type == int.class) {
+ type = Integer.class;
+ } else if(type == long.class) {
+ type = Long.class;
+ } else if(type == char.class) {
+ type = Character.class;
+ } else if(type == float.class) {
+ type = Float.class;
+ } else if(type == double.class) {
+ type = Double.class;
+ } else if(type == byte.class) {
+ type = Byte.class;
+ } else if(type == short.class) {
+ type = Short.class;
+ }
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.metadata.IProperty#getType()
+ */
+ public Class<?> getType() {
+ return type;
+ }
+
+ public boolean isValueAsParent() {
+ return (flags & VALUE_AS_PARENT) == VALUE_AS_PARENT;
+ }
+
+ public void setValueAsParent(boolean value) {
+ flags |= VALUE_AS_PARENT;
+ }
+
+ public ILoadingType getLoadingType() {
+ return loadingType;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/BeanProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/BeanProperty.java
new file mode 100644
index 00000000000..a0219a93f27
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/BeanProperty.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.annotation.Containment;
+import org.eclipse.papyrus.xwt.core.IBinding;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+
+public class BeanProperty extends AbstractProperty {
+
+ protected PropertyDescriptor descriptor;
+
+ private boolean containment = false;
+
+ public BeanProperty(PropertyDescriptor descriptor) {
+ this(descriptor, ILoadingType.DEFAULT);
+ }
+
+ public BeanProperty(PropertyDescriptor descriptor, ILoadingType loadingType) {
+ super(descriptor.getName(), descriptor.getPropertyType(), loadingType);
+ this.descriptor = descriptor;
+
+ Method readMethod = descriptor.getReadMethod();
+ if(readMethod != null) {
+ Annotation annotation = readMethod.getAnnotation(Containment.class);
+ if(annotation != null) {
+ containment = true;
+ }
+ }
+ Method writeMethod = descriptor.getWriteMethod();
+ if(writeMethod != null) {
+ Annotation annotation = writeMethod.getAnnotation(Containment.class);
+ if(annotation != null) {
+ containment = true;
+ }
+ }
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(descriptor != null && descriptor.getWriteMethod() != null) {
+ Method writeMethod = descriptor.getWriteMethod();
+ // Bug of invoke boolean value.
+ Class<?>[] parameterTypes = writeMethod.getParameterTypes();
+ if(parameterTypes.length == 1) {
+ Class<?> type = parameterTypes[0];
+ Class<?> propertyType = getType();
+ if(propertyType != Object.class) {
+ type = propertyType;
+ }
+ if(!ObjectUtil.isAssignableFrom(IBinding.class, propertyType)) {
+ if(value != null && type != value.getClass()) {
+ value = ObjectUtil.resolveValue(value, type, value);
+ }
+ }
+
+ Object oldValue = null;
+ Method readMethod = descriptor.getReadMethod();
+ if(readMethod != null) {
+ oldValue = readMethod.invoke(target);
+ }
+
+ if(value == null && type != null && UserData.getWidget(target) != null) {
+ if(type == String.class) {
+ value = "";
+ } else if(type == Boolean.class) {
+ value = false;
+ }
+ }
+
+ if(oldValue != value) {
+ writeMethod.setAccessible(true);
+ try {
+ writeMethod.invoke(target, value);
+ fireSetPostAction(target, this, value);
+ } catch (IllegalArgumentException e) {
+ if(value == null) {
+ throw new XWTException("Property type " + getName() + " of " + target.getClass().getName() + " cannot be null.", e);
+ }
+ throw new XWTException("Property type " + getName() + " of " + target.getClass().getName() + " is mismatch with " + value.getClass().getName() + " expected type is " + parameterTypes[0].getName(), e);
+ } catch (InvocationTargetException e) {
+ throw new XWTException("Problem of invoke " + getName() + " of " + target.getClass().getName() + " with a value of type " + value.getClass().getName(), e);
+ }
+ }
+ }
+ }
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(descriptor != null && descriptor.getReadMethod() != null) {
+ Method readMethod = descriptor.getReadMethod();
+ readMethod.setAccessible(true);
+ return readMethod.invoke(target);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isDefault() {
+ return true;
+ }
+
+ public boolean isContainement() {
+ return containment;
+ }
+
+ public boolean isReadOnly() {
+ return descriptor.getWriteMethod() == null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/ColumnViewerColumnsProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/ColumnViewerColumnsProperty.java
new file mode 100644
index 00000000000..a62179786a1
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/ColumnViewerColumnsProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.papyrus.xwt.core.IUserDataConstants;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class ColumnViewerColumnsProperty extends AbstractProperty {
+
+ public ColumnViewerColumnsProperty() {
+ super(PropertiesConstants.PROPERTY_COLUMNS, TableViewerColumn.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableViewer tableViewer = (TableViewer)target;
+ Table table = (Table)tableViewer.getControl();
+ int count = table.getColumnCount();
+ if(count != 0) {
+ String[] columnProperties = new String[count];
+ for(int i = 0; i < columnProperties.length; i++) {
+ TableColumn column = table.getColumn(i);
+ columnProperties[i] = (String)UserData.getLocalData(column, IUserDataConstants.XWT_PROPERTY_DATA_KEY);
+ if(columnProperties[i] != null) {
+ UserData.setLocalData(column, IUserDataConstants.XWT_PROPERTY_DATA_KEY, null);
+ }
+ }
+ tableViewer.setColumnProperties(columnProperties);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DataProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DataProperty.java
new file mode 100644
index 00000000000..1470df85c67
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DataProperty.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+
+/**
+ * Additional property to store in user data in widget
+ *
+ * @author yyang
+ *
+ */
+public class DataProperty extends AbstractProperty {
+
+ protected String key;
+
+ protected Object defaultValue;
+
+ public DataProperty(String name, String key) {
+ this(name, key, Object.class, null);
+ }
+
+ public DataProperty(String name, String key, Class<?> propertyType) {
+ this(name, key, propertyType, null);
+ }
+
+ public DataProperty(String name, String key, Class<?> propertyType, Object defaultValue) {
+ this(name, key, propertyType, defaultValue, ILoadingType.DEFAULT);
+ }
+
+ public DataProperty(String name, String key, Class<?> propertyType, Object defaultValue, ILoadingType loadingType) {
+ super(name, propertyType, loadingType);
+ this.key = key;
+ this.defaultValue = defaultValue;
+ }
+
+ public Object getValue(Object target) {
+ Object object = UserData.getLocalData(target, key);
+ if(object == null) {
+ return defaultValue;
+ }
+ return object;
+ }
+
+ public void setValue(Object target, Object value) {
+ UserData.setLocalData(target, key, value);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicBeanProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicBeanProperty.java
new file mode 100644
index 00000000000..fc2800db743
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicBeanProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ *
+ * This is a new type of dynamic properties, some properties, such as texts for TableItem and TreeItem, we used the setText(String[]) and String =
+ * getText();
+ *
+ * @author jliu
+ *
+ */
+public class DynamicBeanProperty extends DynamicProperty {
+
+ public DynamicBeanProperty(Class<?> type, Class<?> propertyType, String propertyName) {
+ super(propertyType, createSetter0(type, propertyType, propertyName), null, propertyName);
+ }
+
+ public DynamicBeanProperty(Class<?> type, Class<?> propertyType, String propertyName, String setterName) {
+ super(propertyType, createSetter0(type, propertyType, setterName), null, propertyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.javabean.metadata.properties.DynamicProperty#getValue (java.lang.Object)
+ */
+ @Override
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicProperty.java
new file mode 100644
index 00000000000..4b1d0bb5132
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/DynamicProperty.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+
+/**
+ * This class is used to extend the Java Bean model
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class DynamicProperty extends AbstractProperty {
+
+ private final Method setter;
+
+ private final Method getter;
+
+ public DynamicProperty(Class<?> type, Class<?> propertyType, String name) {
+ this(propertyType, createSetter0(type, propertyType, name), createGetter0(propertyType, name), name);
+ }
+
+ public DynamicProperty(Class<?> type, Class<?> propertyType, String name, ILoadingType loadingType) {
+ this(propertyType, createSetter0(type, propertyType, name), createGetter0(propertyType, name), name, loadingType);
+ }
+
+ public DynamicProperty(Class<?> propertyType, Method setter, Method getter, String name) {
+ this(propertyType, setter, getter, name, ILoadingType.DEFAULT);
+ }
+
+ public DynamicProperty(Class<?> propertyType, Method setter, Method getter, String name, ILoadingType loadingType) {
+ super(name, propertyType, loadingType);
+ this.setter = setter;
+ this.getter = getter;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ setter.invoke(target, value);
+ fireSetPostAction(target, this, value);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return getter.invoke(target, (Object[])null);
+ }
+
+ protected static Method createSetter0(Class<?> type, Class<?> propertyType, String name) {
+ try {
+ return createSetter(type, propertyType, name);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ public static Method createSetter(Class<?> type, Class<?> propertyType, String name) throws SecurityException, NoSuchMethodException {
+ return type.getMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), propertyType);
+ }
+
+ protected static Method createGetter0(Class<?> type, String name) {
+ try {
+ return createGetter(type, name);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+ public static Method createGetter(Class<?> type, String name) throws SecurityException, NoSuchMethodException {
+ return ObjectUtil.findGetter(type, name, null);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/EventProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/EventProperty.java
new file mode 100644
index 00000000000..aa8be5ea52c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/EventProperty.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.javabean.metadata.properties;
+
+import org.eclipse.papyrus.xwt.metadata.IEvent;
+
+/**
+ * A property to hold the event state
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class EventProperty extends DataProperty {
+
+ protected IEvent event;
+
+ public EventProperty(String name, String key, IEvent event) {
+ super(name, key, Boolean.class, false);
+ this.event = event;
+ }
+
+ public IEvent getEvent() {
+ return event;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/FieldProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/FieldProperty.java
new file mode 100644
index 00000000000..0ca05228ba7
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/FieldProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+
+/**
+ * @author jliu
+ *
+ */
+public class FieldProperty extends AbstractProperty {
+
+ private Field field;
+
+ public FieldProperty(Field field) {
+ super(field.getName(), field.getType());
+ this.field = field;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.metadata.IProperty#getValue(java.lang.Object)
+ */
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return field.get(target);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.metadata.IProperty#setValue(java.lang.Object, java.lang.Object)
+ */
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(value != null) {
+ Class<?> fieldType = field.getType();
+ Class<?> valueType = value.getClass();
+ if(!ObjectUtil.isAssignableFrom(fieldType, value.getClass())) {
+ IConverter converter = XWT.findConvertor(valueType, fieldType);
+ if(converter != null) {
+ value = converter.convert(value);
+ } else {
+ throw new XWTException("Converter " + valueType.getName() + "->" + fieldType.getName());
+ }
+ }
+ }
+ field.set(target, value);
+ fireSetPostAction(target, this, value);
+ }
+
+ @Override
+ public boolean isDefault() {
+ return true;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/InputBeanProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/InputBeanProperty.java
new file mode 100644
index 00000000000..ccad270a5f3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/InputBeanProperty.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.databinding.observable.IObservableCollection;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.databinding.viewers.ObservableSetContentProvider;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ContentViewer;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.collection.CollectionViewSource;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.jface.DefaultViewerLabelProvider;
+import org.eclipse.papyrus.xwt.jface.JFacesHelper;
+import org.eclipse.papyrus.xwt.jface.ObservableMapLabelProvider;
+import org.eclipse.papyrus.xwt.jface.ObservableTreeContentProvider;
+import org.eclipse.papyrus.xwt.metadata.DelegateProperty;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+
+/**
+ * Handle manually the type conversion. Maybe it can be done using the
+ * IConverter. Only the type of IProperty should be IObservableCollection
+ *
+ * @author yyang
+ *
+ */
+public class InputBeanProperty extends DelegateProperty {
+
+ // public InputBeanProperty(IProperty delegate) {
+ // super(delegate);
+ // }
+
+ public InputBeanProperty(IProperty delegate, ILoadingType loadingType) {
+ super(delegate, loadingType);
+ }
+
+ @Override
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(value == null) {
+ return;
+ }
+
+ if(value instanceof Class<?>) {
+ Class<?> type = (Class<?>)value;
+ if(type.isEnum()) {
+ value = new WritableList(XWT.getRealm(), Arrays.asList(type.getEnumConstants()), type);
+ }
+ }
+
+ Class<?> elementType = getElementType();
+ if(value.getClass().isArray()) {
+ elementType = value.getClass().getComponentType();
+ }
+ if(value instanceof IObservableList) {
+ IObservableList list = (IObservableList)value;
+ Object listElementType = list.getElementType();
+ if(listElementType instanceof Class<?>) {
+ elementType = (Class<?>)listElementType;
+ }
+ } else if(elementType == Object.class && value instanceof Collection<?>) {
+ Collection<?> collection = (Collection<?>)value;
+ for(Iterator<?> iterator = collection.iterator(); iterator.hasNext();) {
+ Object object = (Object)iterator.next();
+ if(object != null) {
+ elementType = object.getClass();
+ break;
+ }
+ }
+ }
+
+ if(target instanceof ContentViewer) {
+ ContentViewer viewer = (ContentViewer)target;
+
+ String[] propertyNames = JFacesHelper.getViewerProperties(viewer);
+ if(target instanceof AbstractTreeViewer) {
+ IContentProvider contentProvider = (IContentProvider)viewer.getContentProvider();
+ if(contentProvider instanceof ObservableTreeContentProvider) {
+ ObservableTreeContentProvider xwtContentProvider = (ObservableTreeContentProvider)contentProvider;
+ xwtContentProvider.updateContext(viewer, value);
+ }
+ if(contentProvider instanceof ObservableTreeContentProvider) {
+ ObservableTreeContentProvider listContentProvider = (ObservableTreeContentProvider)contentProvider;
+ viewer.setLabelProvider(new ObservableMapLabelProvider(viewer, listContentProvider.getKnownElements(), propertyNames));
+ }
+ } else {
+ IContentProvider contentProvider = viewer.getContentProvider();
+ if(value instanceof List<?> || value.getClass().isArray()) {
+ if(contentProvider == null) {
+ contentProvider = new ObservableListContentProvider();
+ viewer.setContentProvider(contentProvider);
+ }
+ if(propertyNames != null && propertyNames.length > 0 && hasDefaultLabelProvider(viewer) && contentProvider instanceof ObservableListContentProvider) {
+ ObservableListContentProvider listContentProvider = (ObservableListContentProvider)contentProvider;
+ viewer.setLabelProvider(new ObservableMapLabelProvider(viewer, listContentProvider.getKnownElements(), propertyNames));
+ }
+ } else if(value instanceof Set<?>) {
+ if(contentProvider == null) {
+ contentProvider = new ObservableSetContentProvider();
+ viewer.setContentProvider(contentProvider);
+ }
+ if(propertyNames != null && propertyNames.length > 0 && hasDefaultLabelProvider(viewer) && contentProvider instanceof ObservableSetContentProvider) {
+ ObservableSetContentProvider setContentProvider = (ObservableSetContentProvider)contentProvider;
+ viewer.setLabelProvider(new ObservableMapLabelProvider(viewer, setContentProvider.getKnownElements(), propertyNames));
+ }
+ }
+ }
+ }
+ if(value instanceof CollectionViewSource) {
+ value = ((CollectionViewSource)value).getView();
+ } else if((value instanceof Collection<?>) && !(value instanceof IObservableCollection)) {
+ value = ObjectUtil.resolveValue(value, IObservableCollection.class, value);
+ }
+ super.setValue(target, value);
+ }
+
+ protected boolean hasDefaultLabelProvider(ContentViewer viewer) {
+ IBaseLabelProvider labelProvider = viewer.getLabelProvider();
+ return (labelProvider == null || labelProvider.getClass() == DefaultViewerLabelProvider.class);
+ }
+
+ protected Class<?> getElementType() {
+ IProperty property = getDelegate();
+ Class<?> type = property.getType();
+ if(type == null) {
+ return Object.class;
+ }
+ if(type.isArray()) {
+ return type.getComponentType();
+ }
+ return Object.class;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/MultiSelectionBeanProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/MultiSelectionBeanProperty.java
new file mode 100644
index 00000000000..ec60da2fc6b
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/MultiSelectionBeanProperty.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+
+/**
+ * Handle manually the type conversion. Maybe it can be done using the
+ * IConverter. Only the type of IProperty should be IObservableCollection
+ *
+ * @author yyang
+ *
+ */
+public class MultiSelectionBeanProperty extends AbstractProperty {
+
+ public MultiSelectionBeanProperty(String name) {
+ this(name, ILoadingType.DEFAULT);
+ }
+
+ public MultiSelectionBeanProperty(String name, ILoadingType loadingType) {
+ super(name, Object.class, loadingType);
+ }
+
+ public Object getValue(Object source) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ ISelection selection = ((ISelectionProvider)source).getSelection();
+ if(selection instanceof IStructuredSelection) {
+ return ((IStructuredSelection)selection).toList();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ public void setValue(Object source, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(value instanceof List<?>) {
+ List<?> list = (List<?>)value;
+ ((ISelectionProvider)source).setSelection(new StructuredSelection(list));
+ } else if(value instanceof Set<?>) {
+ Set<?> set = (Set<?>)value;
+ ((ISelectionProvider)source).setSelection(new StructuredSelection(set.toArray()));
+ return;
+ } else if(value.getClass().isArray()) {
+ ((ISelectionProvider)source).setSelection(new StructuredSelection((Object[])value));
+ return;
+ }
+ ((ISelectionProvider)source).setSelection(StructuredSelection.EMPTY);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/PropertiesConstants.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/PropertiesConstants.java
new file mode 100644
index 00000000000..0c6a81fd6d8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/PropertiesConstants.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.javabean.metadata.properties;
+
+/**
+ * @author jliu
+ *
+ */
+public final class PropertiesConstants {
+
+ // Properties
+ public static final String PROPERTY_EDITOR = "editor";
+
+ public static final String PROPERTY_EDITORS = "editors";
+
+ public static final String PROPERTY_DYNAMIC = "dynamic";
+
+ public static final String PROPERTY_CELLS = "cells";
+
+ public static final String PROPERTY_TEXTS = "texts";
+
+ public static final String PROPERTY_TEXT = "text";
+
+ public static final String PROPERTY_URL = "url";
+
+ public static final String PROPERTY_WIDTH = "width";
+
+ public static final String PROPERTY_BINDING_PATH = "bindingPath";
+
+ public static final String PROPERTY_ITEM_TEXT = "itemText";
+
+ public static final String PROPERTY_ITEM_IMAGE = "itemImage";
+
+ public static final String PROPERTY_IMAGE = "image";
+
+ public static final String PROPERTY_COLUMNS = "columns";
+
+ public static final String PROPERTY_COLUMN_PROPERTIES = "columnProperties";
+
+ public static final String PROPERTY_SINGLE_SELECTION = "singleSelection";
+
+ public static final String PROPERTY_MULTI_SELECTION = "multiSelection";
+
+ // Data
+ public static final String DATA_DEFINED_EDITOR = "Defined table editors";
+
+ public static final String DATA_TABLE_UTIL = "tableUtil";
+
+ public static final String DATA_CONTROLEDITOR_OF_CONTROL = "TableEditor of a control";
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/SingleSelectionBeanProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/SingleSelectionBeanProperty.java
new file mode 100644
index 00000000000..842f56c9f16
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/SingleSelectionBeanProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+
+/**
+ * IViewer property
+ *
+ * @author yyang
+ */
+public class SingleSelectionBeanProperty extends AbstractProperty {
+
+ public SingleSelectionBeanProperty(String name) {
+ this(name, ILoadingType.DEFAULT);
+ }
+
+ public SingleSelectionBeanProperty(String name, ILoadingType loadingType) {
+ super(name, Object.class, loadingType);
+ }
+
+ public Object getValue(Object source) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ ISelection selection = ((ISelectionProvider)source).getSelection();
+ if(selection instanceof IStructuredSelection) {
+ return ((IStructuredSelection)selection).getFirstElement();
+ }
+ return null;
+ }
+
+ public void setValue(Object source, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ IStructuredSelection selection = value == null ? StructuredSelection.EMPTY : new StructuredSelection(value);
+ if(source instanceof Viewer) {
+ ((Viewer)source).setSelection(selection, true);
+ } else {
+ ((ISelectionProvider)source).setSelection(selection);
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/StyleProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/StyleProperty.java
new file mode 100644
index 00000000000..bc10cb094b8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/StyleProperty.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.core.Style;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class StyleProperty extends AbstractProperty {
+
+ public StyleProperty() {
+ super(IConstants.XAML_STYLE, Object.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ if(!(value instanceof Style)) {
+ throw new XWTException("Style is expected.");
+ }
+ Style style = (Style)value;
+ style.apply(target);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableColumnEditorProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableColumnEditorProperty.java
new file mode 100644
index 00000000000..443cc06cf69
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableColumnEditorProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.papyrus.xwt.internal.xml.Element;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableColumnEditorProperty extends AbstractProperty {
+
+ public TableColumnEditorProperty() {
+ super(PropertiesConstants.PROPERTY_EDITOR, Element.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableColumn tableColumn = (TableColumn)target;
+ return tableColumn.getData(PropertiesConstants.DATA_DEFINED_EDITOR);
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableColumn tableColumn = (TableColumn)target;
+ tableColumn.setData(PropertiesConstants.DATA_DEFINED_EDITOR, value);
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableEditorDynamicProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableEditorDynamicProperty.java
new file mode 100644
index 00000000000..46a9ac02efe
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableEditorDynamicProperty.java
@@ -0,0 +1,323 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableEditorDynamicProperty extends AbstractProperty {
+
+ public TableEditorDynamicProperty() {
+ super(PropertiesConstants.PROPERTY_DYNAMIC, Boolean.class);
+ }
+
+ public TableEditorDynamicProperty(ILoadingType loadingType) {
+ super(PropertiesConstants.PROPERTY_DYNAMIC, Boolean.class, loadingType);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.xwt.metadata.IProperty#getValue(java.lang.Object)
+ */
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.xwt.metadata.IProperty#setValue(java.lang.Object, java.lang.Object)
+ */
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+
+ Boolean isDynamic = (Boolean)value;
+ TableEditor tableEditor = (TableEditor)target;
+ final Control control = tableEditor.getEditor();
+ Table tableParent = null;
+ Composite parent = control.getParent();
+ if(parent instanceof Table) {
+ tableParent = (Table)parent;
+ } else if(tableEditor.getItem() != null) {
+ tableParent = tableEditor.getItem().getParent();
+ }
+ if(tableParent == null) {
+ return;
+ }
+ final Table table = tableParent;
+ if(isDynamic) {
+ control.setVisible(false);
+ control.addFocusListener(new FocusAdapter() {
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ control.setVisible(false);
+ }
+ });
+
+ control.addKeyListener(new KeyAdapter() {
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if(e.character == SWT.CR && control.isFocusControl()) {
+ table.notifyListeners(SWT.DefaultSelection, new Event());
+ }
+ }
+ });
+
+ Object mouseHander = table.getData(PropertiesConstants.DATA_TABLE_UTIL);
+ if(mouseHander == null) {
+ TableUtil tableUtil = new TableUtil(table);
+ table.setData(PropertiesConstants.DATA_TABLE_UTIL, tableUtil);
+ }
+
+ table.addSelectionListener(new TableSelectionHandler(table, tableEditor));
+ }
+ }
+
+ static private class TableSelectionHandler implements SelectionListener {
+
+ private Table table;
+
+ private TableEditor tableEditor;
+
+ public TableSelectionHandler(Table table, TableEditor tableEditor) {
+ this.table = table;
+ this.tableEditor = tableEditor;
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ Control editor = tableEditor.getEditor();
+ if(editor.isDisposed()) {
+ return;
+ }
+ if(editor.isFocusControl()) {
+ editor.setVisible(false);
+ } else {
+ editor.setFocus();
+ }
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ Control editor = tableEditor.getEditor();
+ if(editor.isDisposed()) {
+ return;
+ }
+ TableUtil tableUtil = (TableUtil)table.getData(PropertiesConstants.DATA_TABLE_UTIL);
+ TableItem item = tableUtil.getItem();
+ int column = tableUtil.getColumn();
+
+ if(item == tableEditor.getItem() && column == tableEditor.getColumn()) {
+ editor.setVisible(true);
+ } else {
+ editor.setVisible(false);
+ }
+ }
+ }
+
+ private static class TableUtil extends MouseAdapter implements KeyListener {
+
+ private Table table;
+
+ private TableItem item;
+
+ private TableColumn column;
+
+ public TableUtil(Table table) {
+ this.table = table;
+ table.addMouseListener(this);
+ table.addKeyListener(this);
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ if(table.isDisposed() || !table.isVisible())
+ return;
+ Point pt = new Point(e.x, e.y);
+ int lineWidth = table.getLinesVisible() ? table.getGridLineWidth() : 0;
+ TableItem item = table.getItem(pt);
+
+ int start = item != null ? table.indexOf(item) : table.getTopIndex();
+ int end = table.getItemCount();
+ Rectangle clientRect = table.getClientArea();
+ for(int i = start; i < end; i++) {
+ TableItem nextItem = table.getItem(i);
+ Rectangle rect = nextItem.getBounds(0);
+ if(pt.y >= rect.y && pt.y < rect.y + rect.height + lineWidth) {
+ item = nextItem;
+ break;
+ }
+ if(rect.y > clientRect.y + clientRect.height)
+ return;
+ }
+ if(item == null)
+ return;
+
+ this.item = item;
+
+ TableColumn newColumn = null;
+ int columnCount = table.getColumnCount();
+ if(columnCount == 0) {
+ if((table.getStyle() & SWT.FULL_SELECTION) == 0) {
+ Rectangle rect = item.getBounds(0);
+ rect.width += lineWidth;
+ rect.height += lineWidth;
+ if(!rect.contains(pt))
+ return;
+ }
+ } else {
+ for(int i = 0; i < columnCount; i++) {
+ Rectangle rect = item.getBounds(i);
+ rect.width += lineWidth;
+ rect.height += lineWidth;
+ if(rect.contains(pt)) {
+ newColumn = table.getColumn(i);
+ break;
+ }
+ }
+ if(newColumn == null) {
+ if((table.getStyle() & SWT.FULL_SELECTION) == 0)
+ return;
+ newColumn = table.getColumn(0);
+ }
+ }
+
+ column = newColumn;
+ table.notifyListeners(SWT.DefaultSelection, new Event());
+ }
+
+ public TableItem getItem() {
+ return item;
+ }
+
+ public int getRow() {
+ return item == null ? (table.getItemCount() > 0 ? 0 : -1) : table.indexOf(item);
+ }
+
+ public void setRow(int rowIndex) {
+ if(rowIndex >= 0 && rowIndex < table.getItemCount()) {
+ item = table.getItem(rowIndex);
+ } else {
+ item = null;
+ }
+ }
+
+ public int getColumn() {
+ return column == null ? (table.getColumnCount() > 0 ? 0 : -1) : table.indexOf(column);
+ }
+
+ public void setColumn(int columnIndex) {
+ if(columnIndex >= 0 && columnIndex < table.getColumnCount()) {
+ column = table.getColumn(columnIndex);
+ } else {
+ column = null;
+ }
+ }
+
+ public void keyPressed(KeyEvent event) {
+ int rowIndex = getRow();
+ int columnIndex = column == null ? 0 : table.indexOf(column);
+
+ switch(event.keyCode) {
+ case SWT.ARROW_UP:
+ setRow(Math.max(0, rowIndex - 1));
+ break;
+ case SWT.ARROW_DOWN:
+ setRow(Math.min(rowIndex + 1, table.getItemCount() - 1));
+ break;
+ case SWT.ARROW_LEFT:
+ case SWT.ARROW_RIGHT:
+ int columnCount = table.getColumnCount();
+ if(columnCount == 0)
+ break;
+ int[] order = table.getColumnOrder();
+ int index = 0;
+ while(index < order.length) {
+ if(order[index] == columnIndex)
+ break;
+ index++;
+ }
+ if(index == order.length)
+ index = 0;
+ int leadKey = (XWTMaps.getStyle("SWT.RIGHT_TO_LEFT") != SWT.NONE) ? ((table.getStyle() & XWTMaps.getStyle("SWT.RIGHT_TO_LEFT")) != 0 ? SWT.ARROW_RIGHT : SWT.ARROW_LEFT) : SWT.ARROW_LEFT;
+ if(event.keyCode == leadKey) {
+ setColumn(order[Math.max(0, index - 1)]);
+ } else {
+ setColumn(order[Math.min(columnCount - 1, index + 1)]);
+ }
+ table.notifyListeners(SWT.Selection, new Event());
+ break;
+ case SWT.HOME:
+ setRow(0);
+ setColumn(columnIndex);
+ break;
+ case SWT.END:
+ setRow(table.getItemCount() - 1);
+ setColumn(columnIndex);
+ break;
+ case SWT.PAGE_UP:
+ int topIndex = table.getTopIndex();
+ if(topIndex == rowIndex) {
+ Rectangle rect = table.getClientArea();
+ TableItem item = table.getItem(topIndex);
+ Rectangle itemRect = item.getBounds(0);
+ rect.height -= itemRect.y;
+ int height = table.getItemHeight();
+ int page = Math.max(1, rect.height / height);
+ topIndex = Math.max(0, topIndex - page + 1);
+ }
+
+ setRow(topIndex);
+ break;
+ case SWT.PAGE_DOWN:
+ int downIndex = table.getTopIndex();
+ Rectangle rect = table.getClientArea();
+ TableItem item = table.getItem(downIndex);
+ Rectangle itemRect = item.getBounds(0);
+ rect.height -= itemRect.y;
+ int height = table.getItemHeight();
+ int page = Math.max(1, rect.height / height);
+ int end = table.getItemCount() - 1;
+ downIndex = Math.min(end, downIndex + page - 1);
+ if(downIndex == rowIndex) {
+ downIndex = Math.min(end, downIndex + page - 1);
+ }
+ setRow(downIndex);
+ break;
+ }
+ }
+
+ public void keyReleased(KeyEvent e) {
+ // Ignore
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemEditorProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemEditorProperty.java
new file mode 100644
index 00000000000..4f2a50a9c5f
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemEditorProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+
+import org.eclipse.swt.custom.TableEditor;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableItemEditorProperty extends AbstractProperty {
+
+ public TableItemEditorProperty() {
+ super(PropertiesConstants.PROPERTY_EDITORS, Collection.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableItem tableItem = (TableItem)target;
+ Collection<TableEditor> tableEditors = (Collection<TableEditor>)value;
+
+ for(TableEditor tableEditor : tableEditors) {
+ if(tableEditor != null) {
+ disposeOldEditor(tableEditor.getColumn(), tableItem);
+ tableEditor.setItem(tableItem);
+ }
+ }
+ }
+
+ /**
+ * Dispose old Table editors for current tableItem at given column index.
+ *
+ * @param column
+ * @param tableItem
+ */
+ private void disposeOldEditor(int column, TableItem tableItem) {
+ Table table = tableItem.getParent();
+ Control[] children = table.getChildren();
+ for(Control control : children) {
+ Object editor = control.getData(PropertiesConstants.DATA_CONTROLEDITOR_OF_CONTROL);
+ if(editor == null || !(editor instanceof TableEditor)) {
+ continue;
+ }
+ if(column == ((TableEditor)editor).getColumn() && tableItem == ((TableEditor)editor).getItem()) {
+ control.dispose();
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemProperty.java
new file mode 100644
index 00000000000..05e16ee6881
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableItemProperty.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableItemProperty extends AbstractProperty {
+
+ public static class Cell {
+
+ public Cell() {
+ }
+
+ private TableItem parent;
+
+ private String text;
+
+ private Image image;
+
+ public TableItem getParent() {
+ return parent;
+ }
+
+ public void setParent(TableItem parent) {
+ this.parent = parent;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public void setImage(Image image) {
+ this.image = image;
+ }
+ }
+
+ public TableItemProperty() {
+ super(PropertiesConstants.PROPERTY_CELLS, Collection.class);
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+
+ Collection<Cell> cells = (Collection<Cell>)value;
+ TableItem tableItem = (TableItem)target;
+
+ String[] texts = new String[cells.size()];
+ Image[] images = new Image[cells.size()];
+
+ int i = 0;
+ for(Cell cell : cells) {
+ String text = (cell).getText();
+ texts[i] = text == null ? "" : text;
+ images[i] = cell.getImage();
+ i++;
+ }
+ tableItem.setText(texts);
+ tableItem.setImage(images);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnDynamicProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnDynamicProperty.java
new file mode 100644
index 00000000000..3bbdd734581
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnDynamicProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableViewerColumnDynamicProperty extends AbstractProperty {
+
+ private String propertyKey;
+
+ public String getPropertyKey() {
+ return propertyKey;
+ }
+
+ public TableViewerColumnDynamicProperty(String propertyName, String propertyKey, Class<?> type) {
+ super(propertyName, type);
+ this.propertyKey = propertyKey;
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableViewerColumn tableViewerColumn = (TableViewerColumn)target;
+ TableColumn tableColumn = tableViewerColumn.getColumn();
+ UserData.setLocalData(tableColumn, getPropertyKey(), value);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnImageProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnImageProperty.java
new file mode 100644
index 00000000000..72708cb999d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnImageProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableViewerColumnImageProperty extends AbstractProperty {
+
+ public TableViewerColumnImageProperty() {
+ super(PropertiesConstants.PROPERTY_IMAGE, Image.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableViewerColumn tableViewerColumn = (TableViewerColumn)target;
+ TableColumn tableColumn = tableViewerColumn.getColumn();
+ Image image = (Image)value;
+ tableColumn.setImage(image);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnTextProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnTextProperty.java
new file mode 100644
index 00000000000..d78132f4ff9
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnTextProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableViewerColumnTextProperty extends AbstractProperty {
+
+ public TableViewerColumnTextProperty() {
+ super(PropertiesConstants.PROPERTY_TEXT, String.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableViewerColumn tableViewerColumn = (TableViewerColumn)target;
+ TableColumn tableColumn = tableViewerColumn.getColumn();
+ String text = (String)value;
+ tableColumn.setText(text);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnWidthProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnWidthProperty.java
new file mode 100644
index 00000000000..ca620f78641
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TableViewerColumnWidthProperty.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.javabean.metadata.properties;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.widgets.TableColumn;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class TableViewerColumnWidthProperty extends AbstractProperty {
+
+ public TableViewerColumnWidthProperty() {
+ super(PropertiesConstants.PROPERTY_WIDTH, int.class);
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return null;
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ TableViewerColumn tableViewerColumn = (TableViewerColumn)target;
+ TableColumn tableColumn = tableViewerColumn.getColumn();
+ int width = (Integer)value;
+ tableColumn.setWidth(width);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TriggersProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TriggersProperty.java
new file mode 100644
index 00000000000..00da9d711f9
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/javabean/metadata/properties/TriggersProperty.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.javabean.metadata.properties;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.core.IUserDataConstants;
+import org.eclipse.papyrus.xwt.core.TriggerBase;
+import org.eclipse.papyrus.xwt.metadata.ILoadingType;
+
+public class TriggersProperty extends DataProperty {
+
+ public TriggersProperty(ILoadingType loadingType) {
+ super(IConstants.XAML_TRIGGERS, IUserDataConstants.XWT_TRIGGERS_KEY, TriggerBase[].class, TriggerBase.EMPTY_ARRAY, loadingType);
+ }
+
+ @Override
+ public void setValue(Object target, Object value) {
+ super.setValue(target, value);
+
+ TriggerBase[] triggers = (TriggerBase[])value;
+ for(TriggerBase triggerBase : triggers) {
+ if(triggerBase != null) {
+ triggerBase.prepare(target);
+ }
+ }
+ for(TriggerBase triggerBase : triggers) {
+ if(triggerBase != null) {
+ triggerBase.on(target);
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/AbstractDialog.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/AbstractDialog.java
new file mode 100644
index 00000000000..a320dadd28d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/AbstractDialog.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.jface;
+
+import java.net.URL;
+import java.util.HashMap;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.XWTLoader;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public abstract class AbstractDialog extends Dialog {
+
+ protected Object dataContext;
+
+ protected String title;
+
+ public AbstractDialog(Shell parentShell, String title, Object dataContext) {
+ super(parentShell);
+ this.dataContext = dataContext;
+ this.title = title;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ if(title != null) {
+ getShell().setText(title);
+ }
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+ HashMap<String, Object> newOptions = new HashMap<String, Object>();
+ initOptions(parent, newOptions);
+ Object element = XWT.loadWithOptions(getContentURL(), newOptions);
+ if(!(element instanceof Control)) {
+ throw new XWTException("Root element must a control.");
+ }
+ GridLayoutFactory.fillDefaults().generateLayout(parent);
+ parent.layout(true, true);
+ return (Control)element;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ parent.setVisible(true);
+ }
+ return null;
+ }
+
+ protected void initOptions(Composite parent, HashMap<String, Object> newOptions) {
+ newOptions.put(XWTLoader.CONTAINER_PROPERTY, parent);
+ newOptions.put(XWTLoader.DATACONTEXT_PROPERTY, dataContext);
+ newOptions.put(XWTLoader.CLASS_PROPERTY, geCLR());
+ }
+
+ protected abstract URL getContentURL();
+
+ protected ClassLoader getClassLoader() {
+ return this.getClass().getClassLoader();
+ }
+
+ protected Object geCLR() {
+ return this;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/CellEditorHelper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/CellEditorHelper.java
new file mode 100644
index 00000000000..5cf4bc83f5d
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/CellEditorHelper.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.jface;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.xwt.XWTException;
+
+public class CellEditorHelper {
+
+ protected TableViewer tableViewer;
+
+ protected int index;
+
+ public CellEditorHelper(TableViewer parent, int index) {
+ this.index = index;
+ this.tableViewer = parent;
+ }
+
+ public Class<?> getTargetType() {
+ ISelection selection = this.tableViewer.getSelection();
+ if(!selection.isEmpty() && selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ Object element = structuredSelection.getFirstElement();
+ Object property = this.tableViewer.getColumnProperties()[index];
+ String propertyName = property.toString();
+ try {
+ BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(element.getClass());
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for(PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+ if(propertyDescriptor.getName().equalsIgnoreCase(propertyName)) {
+ return propertyDescriptor.getPropertyType();
+ }
+ }
+ } catch (IntrospectionException e) {
+ throw new XWTException(e);
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ComboBoxCellEditor.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ComboBoxCellEditor.java
new file mode 100644
index 00000000000..9428fbc468a
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ComboBoxCellEditor.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.jface;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.xwt.IIndexedElement;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.swt.widgets.Composite;
+
+public class ComboBoxCellEditor extends org.eclipse.jface.viewers.ComboBoxCellEditor implements IIndexedElement {
+
+ protected CellEditorHelper cellEditorHelper;
+
+ public ComboBoxCellEditor() {
+ super();
+ }
+
+ public ComboBoxCellEditor(Composite parent, String[] items, int style) {
+ super(parent, items, style);
+ }
+
+ public ComboBoxCellEditor(Composite parent, String[] items) {
+ super(parent, items);
+ }
+
+ @Override
+ protected void doSetValue(Object value) {
+ if(value != null) {
+ Class<?> targetType = getTargetType();
+ if(targetType != String.class) {
+ IConverter converter = XWT.findConvertor(targetType, String.class);
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ }
+ String[] items = getItems();
+ for(int i = 0; i < items.length; i++) {
+ if(items[i].equals(value)) {
+ super.doSetValue(i);
+ return;
+ }
+ }
+ }
+ super.doSetValue(-1);
+ }
+
+ @Override
+ protected Object doGetValue() {
+ Object value = super.doGetValue();
+ String[] items = getItems();
+ int selected = (Integer)value;
+ if(selected < 0) {
+ return null;
+ }
+ String selectedString = items[selected];
+ Class<?> targetType = getTargetType();
+ if(targetType != String.class) {
+ IConverter converter = XWT.findConvertor(String.class, targetType);
+ if(converter != null) {
+ return converter.convert(value);
+ }
+ }
+ return selectedString;
+ }
+
+ protected Class<?> getTargetType() {
+ if(cellEditorHelper != null) {
+ return cellEditorHelper.getTargetType();
+ }
+ return Object.class;
+ }
+
+ public void setIndex(Object parent, int index) {
+ if(!(parent instanceof TableViewer)) {
+ throw new XWTException("TableView is expected, not \"" + parent.getClass().getName() + "\"");
+ }
+ cellEditorHelper = new CellEditorHelper((TableViewer)parent, index);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultCellModifier.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultCellModifier.java
new file mode 100644
index 00000000000..26638b07a63
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultCellModifier.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.jface;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.swt.widgets.TableItem;
+
+public class DefaultCellModifier implements ICellModifier {
+
+ protected TableViewer tableViewer;
+
+ public DefaultCellModifier(TableViewer tableViewer) {
+ this.tableViewer = tableViewer;
+ }
+
+ private BeanInfo getBeanInfo(Object element) {
+ try {
+ return java.beans.Introspector.getBeanInfo(element.getClass());
+ } catch (IntrospectionException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public boolean canModify(Object element, String property) {
+ return getDescriptor(element, property) != null;
+ }
+
+ public Object getValue(Object element, String property) {
+ PropertyDescriptor descriptor = getDescriptor(element, property);
+ if(descriptor != null) {
+ try {
+ return descriptor.getReadMethod().invoke(element);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return "";
+ }
+
+ public void modify(Object element, String property, Object value) {
+ if(element instanceof TableItem) {
+ TableItem tableItem = (TableItem)element;
+ Object data = tableItem.getData();
+ PropertyDescriptor descriptor = getDescriptor(data, property);
+ if(descriptor != null) {
+ try {
+ Class<?> type = descriptor.getPropertyType();
+ IConverter converter = XWT.findConvertor(value.getClass(), type);
+ if(converter != null) {
+ Object newValue = converter.convert(value);
+ descriptor.getWriteMethod().invoke(data, newValue);
+ tableViewer.refresh(data);
+ } else {
+ throw new XWTException("Converter doesn't exist from \"" + value.getClass().getName() + "\" to \"" + type.getName());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private PropertyDescriptor getDescriptor(Object element, String property) {
+ BeanInfo beanInfo = getBeanInfo(element);
+ if(beanInfo != null) {
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for(PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+ if(propertyDescriptor.getName().equalsIgnoreCase(property)) {
+ return propertyDescriptor;
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultListContentProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultListContentProvider.java
new file mode 100644
index 00000000000..6622457bab0
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultListContentProvider.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.jface;
+
+import java.util.Collection;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+
+public class DefaultListContentProvider implements IStructuredContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof Collection<?>) {
+ Collection<?> collection = (Collection<?>)inputElement;
+ return collection.toArray();
+ }
+ if(inputElement instanceof Object[]) {
+ return (Object[])inputElement;
+ }
+ return Core.EMPTY_ARRAY;
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultViewerLabelProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultViewerLabelProvider.java
new file mode 100644
index 00000000000..84452120569
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/DefaultViewerLabelProvider.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.jface;
+
+import org.eclipse.jface.viewers.AbstractTableViewer;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.papyrus.xwt.core.IUserDataConstants;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.javabean.metadata.properties.PropertiesConstants;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ *
+ * @author yyang (yves.yang@soyatec.com)
+ */
+public class DefaultViewerLabelProvider implements ITableLabelProvider, ILabelProvider {
+
+ private Viewer viewer;
+
+ protected String bindingPath;
+
+ private IProperty columnsProperty;
+
+ public DefaultViewerLabelProvider(Viewer viewer) {
+ this.viewer = viewer;
+ }
+
+ public String getBindingPath() {
+ return bindingPath;
+ }
+
+ public void setBindingPath(String bindingPath) {
+ this.bindingPath = bindingPath;
+ }
+
+ protected IProperty getColumnsProperty() {
+ if(columnsProperty == null) {
+ IMetaclass metaclass = XWT.getMetaclass(viewer.getClass());
+ columnsProperty = metaclass.findProperty(PropertiesConstants.PROPERTY_COLUMNS);
+ if(columnsProperty == null) {
+ throw new XWTException("Columns property is not found.");
+ }
+ }
+ return columnsProperty;
+ }
+
+ protected Viewer getViewer() {
+ return viewer;
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public Image getImage(Object element) {
+ return getColumnImage(element, 0);
+ }
+
+ public String getText(Object dataContext) {
+ return getColumnText(dataContext, 0);
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ return JFacesHelper.getColumnText(getViewer(), element, columnIndex, getPaths());
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return JFacesHelper.getColumnImage(getViewer(), element, columnIndex, getPaths());
+ }
+
+ protected Object[] getPaths() {
+ Viewer viewer = getViewer();
+ if(viewer instanceof AbstractTableViewer) {
+ Object[] objects = ((AbstractTableViewer)getViewer()).getColumnProperties();
+ for(int i = 0; i < objects.length; i++) {
+ if((objects[i] == null)) {
+ objects[i] = getBindingPath();
+ }
+ }
+ return objects;
+ }
+ String path = bindingPath;
+ if(path == null) {
+ path = (String)UserData.getLocalData(getViewer(), IUserDataConstants.XWT_PROPERTY_DATA_KEY);
+ }
+ if(path == null) {
+ return Core.EMPTY_ARRAY;
+ }
+ return new String[]{ path };
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFaceInitializer.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFaceInitializer.java
new file mode 100644
index 00000000000..01e2d6fc63e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFaceInitializer.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.jface;
+
+import org.eclipse.jface.viewers.AbstractListViewer;
+import org.eclipse.jface.viewers.AbstractTableViewer;
+import org.eclipse.papyrus.xwt.metadata.IObjectInitializer;
+
+public class JFaceInitializer implements IObjectInitializer {
+
+ public void initialize(Object object) {
+ if(object instanceof AbstractListViewer) {
+ AbstractListViewer viewer = (AbstractListViewer)object;
+ viewer.setLabelProvider(new DefaultViewerLabelProvider(viewer));
+ } else if(object instanceof AbstractTableViewer) {
+ AbstractTableViewer viewer = (AbstractTableViewer)object;
+ viewer.setLabelProvider(new DefaultViewerLabelProvider(viewer));
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFacesHelper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFacesHelper.java
new file mode 100644
index 00000000000..24342c1af41
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/JFacesHelper.java
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * 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.jface;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+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.IUserDataConstants;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.papyrus.xwt.internal.utils.UserData;
+import org.eclipse.papyrus.xwt.metadata.IMetaclass;
+import org.eclipse.papyrus.xwt.metadata.IProperty;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+public class JFacesHelper {
+
+ public static Class<?>[] getSupportedElements() {
+ return JFACES_SUPPORTED_ELEMENTS;
+ }
+
+ public static boolean isViewer(Object obj) {
+ if(JFACES_VIEWER == null || obj == null)
+ return false;
+ return JFACES_VIEWER.isAssignableFrom(obj.getClass());
+ }
+
+ public static Control getControl(Object obj) {
+ if(!isViewer(obj))
+ throw new XWTException("Expecting a JFaces viewer:" + obj);
+ try {
+ Method method = JFACES_VIEWER.getMethod("getControl");
+ return (Control)method.invoke(obj);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private static Class<?>[] JFACES_SUPPORTED_ELEMENTS;
+
+ private static Class<?> JFACES_VIEWER;
+
+ static {
+ List<Class<?>> collector = new ArrayList<Class<?>>();
+ try {
+
+ JFACES_VIEWER = Class.forName("org.eclipse.jface.viewers.Viewer");
+ String[] jfaceClasses = new String[]{ "org.eclipse.jface.viewers.ComboViewer", "org.eclipse.jface.viewers.ListViewer", "org.eclipse.jface.viewers.TreeViewer", "org.eclipse.jface.viewers.TableViewer", "org.eclipse.jface.viewers.TableTreeViewer", "org.eclipse.jface.viewers.CheckboxTableViewer", "org.eclipse.jface.viewers.CheckboxTreeViewer",
+ // Dialogs
+ "org.eclipse.jface.dialogs.TrayDialog", "org.eclipse.jface.dialogs.TitleAreaDialog",
+ // Add CellEditors for JFave Viewers.
+ "org.eclipse.jface.viewers.CellEditor", "org.eclipse.jface.viewers.ComboBoxViewerCellEditor", TextCellEditor.class.getName(), CheckboxCellEditor.class.getName() };
+ for(String clazz : jfaceClasses) {
+ try {
+ collector.add(Class.forName(clazz));
+ } catch (Throwable e) {
+ System.out.println("No JFaces support for " + clazz);
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ System.out.println("No JFaces support");
+ }
+ JFACES_SUPPORTED_ELEMENTS = collector.toArray(new Class[collector.size()]);
+ }
+
+ public static String[] getViewerProperties(Viewer viewer) {
+ if(viewer instanceof ColumnViewer) {
+ ColumnViewer columnViewer = (ColumnViewer)viewer;
+ Object[] properties = columnViewer.getColumnProperties();
+ String[] propertyNames = Core.EMPTY_STRING_ARRAY;
+ if(properties != null) {
+ int size = 0;
+ for(int i = 0; i < properties.length; i++) {
+ if(properties[i] != null) {
+ size++;
+ }
+ }
+
+ propertyNames = new String[size];
+ for(int i = 0, j = 0; i < properties.length; i++) {
+ if(properties[i] != null) {
+ propertyNames[j++] = properties[i].toString();
+ }
+ }
+ }
+ if(propertyNames.length != 0) {
+ return propertyNames;
+ }
+ }
+ String path = (String)UserData.getLocalData(viewer, IUserDataConstants.XWT_PROPERTY_DATA_KEY);
+ if(path != null) {
+ return new String[]{ path };
+ }
+ return Core.EMPTY_STRING_ARRAY;
+ }
+
+ public static Object getColumnObject(Object element, int columnIndex, Object[] properties) {
+ if(element == null) {
+ return null;
+ }
+ Object dataContext = element;
+
+ if(properties != null && columnIndex < properties.length) {
+ Object propertyElement = properties[columnIndex];
+ if(propertyElement != null) {
+ String propertyName = propertyElement.toString();
+ if(propertyName != null) {
+ try {
+ IMetaclass metaclass = XWT.getMetaclass(dataContext);
+ IProperty property = metaclass.findProperty(propertyName.toLowerCase());
+ if(property != null) {
+ dataContext = property.getValue(dataContext);
+ if(dataContext != null) {
+ Class<?> type = dataContext.getClass();
+ Class<?> propertyType = property.getType();
+ if(propertyType != null && !propertyType.isAssignableFrom(type)) {
+ dataContext = ObjectUtil.resolveValue(dataContext, type, propertyType, dataContext);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ }
+ }
+ }
+ return dataContext;
+ }
+
+ public static String getColumnText(Viewer viewer, Object element, int columnIndex) {
+ String[] propertyNames = JFacesHelper.getViewerProperties(viewer);
+ return getColumnText(viewer, element, columnIndex, propertyNames);
+ }
+
+ public static String getColumnText(Viewer viewer, Object element, int columnIndex, Object[] properties) {
+ Object value = getColumnObject(element, columnIndex, properties);
+
+ try {
+ if(viewer instanceof TableViewer) {
+ Table table = ((TableViewer)viewer).getTable();
+ TableColumn[] columns = table.getColumns();
+ TableColumn column = columns[columnIndex];
+ if(UserData.hasLocalData(column, IUserDataConstants.XWT_PROPERTY_ITEM_TEXT_KEY)) {
+ Object userDataValue = UserData.getLocalData(column, IUserDataConstants.XWT_PROPERTY_ITEM_TEXT_KEY);
+ if(userDataValue instanceof IBinding) {
+ IBinding binding = (IBinding)userDataValue;
+ binding.reset();
+ UserData.setDataContext(column, value);
+ value = binding.getValue(null);
+ } else {
+ value = userDataValue;
+ }
+ } else if(UserData.hasLocalData(column, IUserDataConstants.XWT_PROPERTY_ITEM_IMAGE_KEY)) {
+ return null;
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ if(value != null) {
+ return value.toString();
+ }
+ return "";
+ }
+
+ public static Image getColumnImage(Viewer viewer, Object element, int columnIndex) {
+ String[] propertyNames = JFacesHelper.getViewerProperties(viewer);
+ return getColumnImage(viewer, element, columnIndex, propertyNames);
+ }
+
+ public static Image getColumnImage(Viewer viewer, Object element, int columnIndex, Object[] properties) {
+ Object value = getColumnObject(element, columnIndex, properties);
+ if(value == null) {
+ return null;
+ }
+ try {
+ if(viewer instanceof TableViewer) {
+ Table table = ((TableViewer)viewer).getTable();
+ TableColumn[] columns = table.getColumns();
+ TableColumn column = columns[columnIndex];
+ if(UserData.hasLocalData(column, IUserDataConstants.XWT_PROPERTY_ITEM_IMAGE_KEY)) {
+ Object userDataValue = UserData.getLocalData(column, IUserDataConstants.XWT_PROPERTY_ITEM_IMAGE_KEY);
+ if(userDataValue instanceof IBinding) {
+ IBinding binding = (IBinding)userDataValue;
+ binding.reset();
+ UserData.setDataContext(column, value);
+ value = binding.getValue(null);
+ } else {
+ value = userDataValue;
+ }
+ } else {
+ return null;
+ }
+ }
+ } catch (Exception e) {
+ throw new XWTException(e);
+ }
+ if(value instanceof IObservableValue) {
+ IObservableValue observableValue = (IObservableValue)value;
+ value = observableValue.getValue();
+ }
+ if(value instanceof Image) {
+ return (Image)value;
+ } else if(value != null) {
+ value = ObjectUtil.resolveValue(value, Image.class, value);
+ if(value == null) {
+ return null;
+ }
+ if(value instanceof Image) {
+ return (Image)value;
+ }
+ throw new XWTException("Converter from " + value.getClass() + " to Image is missing.");
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableMapLabelProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableMapLabelProvider.java
new file mode 100644
index 00000000000..9a3b3cb9072
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableMapLabelProvider.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 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 164247
+ * Brad Reynolds - bug 164134
+ * yves yang - port to XWT
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.jface;
+
+import java.util.Set;
+
+import org.eclipse.core.databinding.observable.map.IMapChangeListener;
+import org.eclipse.core.databinding.observable.map.IObservableMap;
+import org.eclipse.core.databinding.observable.map.MapChangeEvent;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * A label provider based on one or more observable maps that track attributes
+ * that this label provider uses for display. Clients may customize by
+ * subclassing and overriding {@link #getColumnText(Object, int)}, {@link #getColumnImage(Object, int)}, for tables or trees with columns, or by
+ * implementing additional mixin interfaces for colors, fonts etc.
+ *
+ * @since 1.1
+ *
+ */
+public class ObservableMapLabelProvider extends LabelProvider implements ILabelProvider, ITableLabelProvider {
+
+ private final IObservableMap[] textMaps;
+
+ private Viewer viewer;
+
+ private IMapChangeListener mapChangeListener = new IMapChangeListener() {
+
+ public void handleMapChange(MapChangeEvent event) {
+ Set<?> affectedElements = event.diff.getChangedKeys();
+ LabelProviderChangedEvent newEvent = new LabelProviderChangedEvent(ObservableMapLabelProvider.this, affectedElements.toArray());
+ fireLabelProviderChanged(newEvent);
+ }
+ };
+
+ /**
+ * @param textMaps
+ */
+ public ObservableMapLabelProvider(Viewer viewer, IObservableSet domain, String[] propertyNames) {
+ textMaps = new XWTObservableWrapper[propertyNames.length];
+
+ for(int i = 0; i < textMaps.length; i++) {
+ textMaps[i] = new XWTObservableWrapper(domain, viewer, propertyNames[i]);
+ textMaps[i].addMapChangeListener(mapChangeListener);
+ }
+ this.viewer = viewer;
+ }
+
+ public void dispose() {
+ for(int i = 0; i < textMaps.length; i++) {
+ textMaps[i].removeMapChangeListener(mapChangeListener);
+ }
+ super.dispose();
+ }
+
+ public Image getImage(Object element) {
+ return getColumnImage(element, 0);
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if(columnIndex < textMaps.length) {
+ Object result = textMaps[columnIndex].get(element);
+ return JFacesHelper.getColumnImage(viewer, result, columnIndex);
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ return getColumnText(element, 0);
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if(columnIndex < textMaps.length) {
+ Object result = textMaps[columnIndex].get(element);
+ return JFacesHelper.getColumnText(viewer, result, columnIndex);
+ }
+ return null;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableTreeContentProvider.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableTreeContentProvider.java
new file mode 100644
index 00000000000..0581fcac890
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ObservableTreeContentProvider.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * 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.jface;
+
+import org.eclipse.core.databinding.observable.IObservable;
+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.jface.databinding.viewers.ObservableListTreeContentProvider;
+import org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.internal.core.Core;
+import org.eclipse.papyrus.xwt.internal.core.UpdateSourceTrigger;
+
+public class ObservableTreeContentProvider implements ITreeContentProvider {
+
+ private String contentPath;
+
+ private Object context;
+
+ private Object value;
+
+ private ITreeContentProvider delegate;
+
+ public String getContentPath() {
+ return contentPath;
+ }
+
+ public void setContentPath(String contentPath) {
+ this.contentPath = contentPath;
+ }
+
+ public void dispose() {
+ if(delegate == null) {
+ return;
+ }
+ delegate.dispose();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if(newInput == null) {
+ return;
+ }
+ updateContext(viewer, newInput);
+ delegate.inputChanged(viewer, oldInput, newInput);
+ }
+
+
+ public Object[] getChildren(Object parentElement) {
+ if(delegate == null) {
+ return Core.EMPTY_ARRAY;
+ }
+ return delegate.getChildren(parentElement);
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public boolean hasChildren(Object element) {
+ if(delegate == null) {
+ return false;
+ }
+ return delegate.hasChildren(element);
+ }
+
+ public Object getParent(Object element) {
+ if(delegate == null) {
+ return null;
+ }
+ return delegate.getParent(element);
+ }
+
+ public IObservableSet getKnownElements() {
+ if(delegate == null) {
+ return null;
+ }
+ if(delegate instanceof ObservableSetTreeContentProvider) {
+ ObservableSetTreeContentProvider contentProvider = (ObservableSetTreeContentProvider)delegate;
+ return contentProvider.getKnownElements();
+ }
+ if(delegate instanceof ObservableListTreeContentProvider) {
+ ObservableListTreeContentProvider contentProvider = (ObservableListTreeContentProvider)delegate;
+ return contentProvider.getKnownElements();
+ }
+ throw new IllegalStateException();
+ }
+
+ public void updateContext(Object context, Object value) {
+ if(context == this.context && this.value == value) {
+ return;
+ }
+ this.context = context;
+ this.value = value;
+ IObservableFactory observableFactory = XWT.observableFactory(context, getContentPath(), UpdateSourceTrigger.Default);
+ IObservable observable = observableFactory.createObservable(value);
+
+ if(observable instanceof IObservableList) {
+ delegate = new ObservableListTreeContentProvider(observableFactory, null);
+ } else if(observable instanceof IObservableSet) {
+ delegate = new ObservableSetTreeContentProvider(observableFactory, null);
+ } else {
+ throw new UnsupportedOperationException(observable.getClass().getName());
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/TextCellEditor.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/TextCellEditor.java
new file mode 100644
index 00000000000..a763d2f5952
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/TextCellEditor.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.jface;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.papyrus.xwt.IIndexedElement;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTException;
+import org.eclipse.swt.widgets.Composite;
+
+public class TextCellEditor extends org.eclipse.jface.viewers.TextCellEditor implements IIndexedElement {
+
+ protected CellEditorHelper cellEditorHelper;
+
+ public TextCellEditor(Composite parent) {
+ super(parent);
+ }
+
+ public TextCellEditor(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ @Override
+ protected void doSetValue(Object value) {
+ if(value == null) {
+ super.doSetValue("");
+ } else {
+ Class<?> targetType = getTargetType();
+ if(targetType != String.class) {
+ IConverter converter = XWT.findConvertor(targetType, String.class);
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ }
+ super.doSetValue(value);
+ }
+ }
+
+ @Override
+ protected Object doGetValue() {
+ Object value = super.doGetValue();
+ Class<?> targetType = getTargetType();
+ if(targetType != value.getClass()) {
+ IConverter converter = XWT.findConvertor(value.getClass(), targetType);
+ if(converter != null) {
+ value = converter.convert(value);
+ }
+ }
+ return value;
+ }
+
+ protected Class<?> getTargetType() {
+ if(cellEditorHelper != null) {
+ return cellEditorHelper.getTargetType();
+ }
+ return Object.class;
+ }
+
+ public void setIndex(Object parent, int index) {
+ if(!(parent instanceof TableViewer)) {
+ throw new XWTException("TableView is expected, not \"" + parent.getClass().getName() + "\"");
+ }
+ cellEditorHelper = new CellEditorHelper((TableViewer)parent, index);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ViewerFilter.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ViewerFilter.java
new file mode 100644
index 00000000000..1467a0a7df8
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/ViewerFilter.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.jface;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.xwt.core.Condition;
+
+public class ViewerFilter extends org.eclipse.jface.viewers.ViewerFilter {
+
+ protected Condition[] conditions = Condition.EMPTY_ARRAY;
+
+ public Condition[] getConditions() {
+ return conditions;
+ }
+
+ public void setConditions(Condition[] conditions) {
+ this.conditions = conditions;
+ }
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ // No condition is same as no filter
+ if(conditions.length == 0) {
+ return false;
+ }
+ for(Condition condition : conditions) {
+ if(!condition.evaluate(element)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTDialog.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTDialog.java
new file mode 100644
index 00000000000..241b5b78daf
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTDialog.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.jface;
+
+import java.net.URL;
+
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Default XWT Dialog with a content via static URL
+ *
+ * @author yyang <yves.yang@soyatec.com>
+ */
+public class XWTDialog extends AbstractDialog {
+
+ private Class<?> contentForm;
+
+ public XWTDialog(Shell parentShell, String title, Object dataContext, Class<?> contentForm) {
+ super(parentShell, title, dataContext);
+ this.contentForm = contentForm;
+ }
+
+ @Override
+ protected URL getContentURL() {
+ if(contentForm != null) {
+ return contentForm.getResource(contentForm.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX);
+ }
+ return null;
+ }
+
+ @Override
+ protected ClassLoader getClassLoader() {
+ return contentForm.getClassLoader();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTObservableWrapper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTObservableWrapper.java
new file mode 100644
index 00000000000..596495dd806
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTObservableWrapper.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * 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.jface;
+
+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.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.IDisposeListener;
+import org.eclipse.core.databinding.observable.IStaleListener;
+import org.eclipse.core.databinding.observable.Realm;
+import org.eclipse.core.databinding.observable.map.IMapChangeListener;
+import org.eclipse.core.databinding.observable.map.IObservableMap;
+import org.eclipse.core.databinding.observable.set.IObservableSet;
+import org.eclipse.core.databinding.property.value.IValueProperty;
+import org.eclipse.papyrus.xwt.internal.core.BindingExpressionPath;
+import org.eclipse.papyrus.xwt.internal.core.ScopeManager;
+
+public class XWTObservableWrapper implements IObservableMap {
+
+ private IObservableMap delegate;
+
+ private IObservableSet domain;
+
+ private Object control;
+
+ private Object data;
+
+ private String path;
+
+ private List<IMapChangeListener> changeListeners = Collections.emptyList();
+
+ public XWTObservableWrapper(IObservableSet domain, Object control, String path) {
+ this.control = control;
+ this.domain = domain;
+ this.path = path;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public void addMapChangeListener(IMapChangeListener listener) {
+ if(delegate == null) {
+ if(changeListeners.isEmpty()) {
+ changeListeners = new ArrayList<IMapChangeListener>();
+ }
+ changeListeners.add(listener);
+ } else {
+ delegate.addMapChangeListener(listener);
+ }
+ }
+
+ public void clear() {
+ checkDelegated();
+ delegate.clear();
+ }
+
+ public boolean containsKey(Object key) {
+ checkDelegated();
+ return delegate.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ checkDelegated();
+ return delegate.containsValue(value);
+ }
+
+ public Set entrySet() {
+ checkDelegated();
+ return delegate.entrySet();
+ }
+
+ public boolean equals(Object o) {
+ checkDelegated();
+ return delegate.equals(o);
+ }
+
+ public Object get(Object key) {
+ if(data == null) {
+ data = key;
+ }
+ checkDelegated();
+ return delegate.get(key);
+ }
+
+ public Object getKeyType() {
+ checkDelegated();
+ return delegate.getKeyType();
+ }
+
+ public Object getValueType() {
+ checkDelegated();
+ return delegate.getValueType();
+ }
+
+ public int hashCode() {
+ checkDelegated();
+ return delegate.hashCode();
+ }
+
+ public boolean isEmpty() {
+ checkDelegated();
+ return delegate.isEmpty();
+ }
+
+ public Set keySet() {
+ checkDelegated();
+ return delegate.keySet();
+ }
+
+ public Object put(Object key, Object value) {
+ checkDelegated();
+ return delegate.put(key, value);
+ }
+
+ public void putAll(Map t) {
+ checkDelegated();
+ delegate.putAll(t);
+ }
+
+ public Object remove(Object key) {
+ checkDelegated();
+ return delegate.remove(key);
+ }
+
+ public void removeMapChangeListener(IMapChangeListener listener) {
+ if(delegate == null) {
+ changeListeners.remove(listener);
+ } else {
+ delegate.removeMapChangeListener(listener);
+ }
+ }
+
+ public int size() {
+ checkDelegated();
+ return delegate.size();
+ }
+
+ public Collection values() {
+ checkDelegated();
+ return delegate.values();
+ }
+
+ public void addChangeListener(IChangeListener listener) {
+ checkDelegated();
+ delegate.addChangeListener(listener);
+ }
+
+ public void addDisposeListener(IDisposeListener listener) {
+ checkDelegated();
+ delegate.addDisposeListener(listener);
+ }
+
+ public void addStaleListener(IStaleListener listener) {
+ checkDelegated();
+ delegate.addStaleListener(listener);
+ }
+
+ public void dispose() {
+ if(delegate != null) {
+ delegate.dispose();
+ }
+ }
+
+ public Realm getRealm() {
+ checkDelegated();
+ return delegate.getRealm();
+ }
+
+ public boolean isDisposed() {
+ checkDelegated();
+ return delegate.isDisposed();
+ }
+
+ public boolean isStale() {
+ checkDelegated();
+ return delegate.isStale();
+ }
+
+ public void removeChangeListener(IChangeListener listener) {
+ checkDelegated();
+ delegate.removeChangeListener(listener);
+ }
+
+ public void removeDisposeListener(IDisposeListener listener) {
+ checkDelegated();
+ delegate.removeDisposeListener(listener);
+ }
+
+ public void removeStaleListener(IStaleListener listener) {
+ checkDelegated();
+ delegate.removeStaleListener(listener);
+ }
+
+ protected void checkDelegated() {
+ if(delegate == null) {
+ IValueProperty property = ScopeManager.createValueProperty(control, data, new BindingExpressionPath(path));
+ delegate = property.observeDetail(domain);
+ for(IMapChangeListener listener : changeListeners) {
+ delegate.addMapChangeListener(listener);
+ }
+ changeListeners.clear();
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTTitleAreaDialog.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTTitleAreaDialog.java
new file mode 100644
index 00000000000..2aa5c9222e6
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/jface/XWTTitleAreaDialog.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.jface;
+
+import java.net.URL;
+import java.util.HashMap;
+
+import org.eclipse.core.databinding.AggregateValidationStatus;
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.papyrus.xwt.IConstants;
+import org.eclipse.papyrus.xwt.XWT;
+import org.eclipse.papyrus.xwt.XWTLoader;
+import org.eclipse.papyrus.xwt.databinding.BindingContext;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ *
+ * @author yyang <yves.yang@soyatec.com>
+ */
+public class XWTTitleAreaDialog extends TitleAreaDialog {
+
+ private Object dataContext;
+
+ private BindingContext bindingContext;
+
+ private AggregateValidationStatus validationStatus;
+
+ private Class<?> contentCLS;
+
+ public XWTTitleAreaDialog(Shell parentShell, Object dataContext, BindingContext bindingContext) {
+ super(parentShell);
+ this.dataContext = dataContext;
+ this.bindingContext = bindingContext;
+ }
+
+ public XWTTitleAreaDialog(Shell parentShell, Class<?> contentCLS, Object dataContext) {
+ this(parentShell, contentCLS, dataContext, null);
+ }
+
+ public XWTTitleAreaDialog(Shell parentShell, Class<?> contentCLS, Object dataContext, BindingContext bindingContext) {
+ super(parentShell);
+ this.contentCLS = contentCLS;
+ this.dataContext = dataContext;
+ this.bindingContext = bindingContext;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Control control = super.createDialogArea(parent);
+
+ if(bindingContext == null) {
+ bindingContext = new BindingContext(parent);
+ }
+ validationStatus = bindingContext.getStatus();
+ validationStatus.addChangeListener(new IChangeListener() {
+
+ public void handleChange(ChangeEvent event) {
+ IStatus status = (IStatus)validationStatus.getValue();
+ setMessage(status.getMessage(), status.getSeverity());
+ }
+ });
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(contentCLS.getClassLoader());
+ HashMap<String, Object> newOptions = new HashMap<String, Object>();
+ newOptions.put(XWTLoader.CONTAINER_PROPERTY, parent);
+ Object dataContext = getDataContext();
+ if(dataContext != null) {
+ newOptions.put(XWTLoader.DATACONTEXT_PROPERTY, dataContext);
+ }
+ BindingContext bindingContext = getBindingContext();
+ if(bindingContext != null) {
+ newOptions.put(XWTLoader.BINDING_CONTEXT_PROPERTY, bindingContext);
+ }
+ newOptions.put(XWTLoader.CLASS_PROPERTY, contentCLS);
+
+ XWT.loadWithOptions(getContentURL(), newOptions);
+ GridLayoutFactory.fillDefaults().generateLayout(parent);
+ parent.layout(true, true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ parent.setVisible(true);
+ }
+ return control;
+ }
+
+ public URL getContentURL() {
+ if(contentCLS != null) {
+ return contentCLS.getResource(contentCLS.getSimpleName() + IConstants.XWT_EXTENSION_SUFFIX);
+ }
+ return null;
+ }
+
+ public Object getDataContext() {
+ return dataContext;
+ }
+
+ public BindingContext getBindingContext() {
+ return bindingContext;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DefaultLoadingType.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DefaultLoadingType.java
new file mode 100644
index 00000000000..b55fe1cc011
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DefaultLoadingType.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.metadata;
+
+public class DefaultLoadingType implements ILoadingType {
+
+ private IValueLoading valueLoading;
+
+ private IProperty[] properties;
+
+ public DefaultLoadingType(IValueLoading valueLoading, IProperty[] properties) {
+ this.valueLoading = valueLoading;
+ this.properties = properties;
+ }
+
+ public IValueLoading getValueLoading() {
+ return valueLoading;
+ }
+
+ public IProperty[] getDependencies() {
+ return properties;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DelegateProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DelegateProperty.java
new file mode 100644
index 00000000000..f2c0c33badf
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/DelegateProperty.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.metadata;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ *
+ * Facility class to override the default behavior
+ *
+ * @author yyang
+ */
+public class DelegateProperty implements IProperty {
+
+ protected IProperty delegate;
+
+ protected ILoadingType loadingType;
+
+ public DelegateProperty(IProperty delegate) {
+ this(delegate, ILoadingType.DEFAULT);
+ }
+
+ public DelegateProperty(ILoadingType loadingType) {
+ this(null, loadingType);
+ }
+
+ public DelegateProperty(IProperty delegate, ILoadingType loadingType) {
+ this.delegate = delegate;
+ this.loadingType = loadingType;
+ }
+
+ public void addSetPostAction(ISetPostAction setPostAction) {
+ this.delegate.addSetPostAction(setPostAction);
+ }
+
+ public Class<?> getType() {
+ return this.delegate.getType();
+ }
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ return this.delegate.getValue(target);
+ }
+
+ public boolean isDefault() {
+ return false;
+ }
+
+ public boolean isContainement() {
+ return false;
+ }
+
+ public void removeSetPostAction(ISetPostAction setPostAction) {
+ this.delegate.removeSetPostAction(setPostAction);
+ }
+
+ public boolean isReadOnly() {
+ return this.delegate.isReadOnly();
+ }
+
+ public void setType(Class<?> type) {
+ this.delegate.setType(type);
+ }
+
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException {
+ this.delegate.setValue(target, value);
+ }
+
+ public String getName() {
+ return this.delegate.getName();
+ }
+
+ public void setName(String name) {
+ this.delegate.setName(name);
+ }
+
+ public IProperty getDelegate() {
+ return delegate;
+ }
+
+ public void setDelegate(IProperty delegate) {
+ this.delegate = delegate;
+ }
+
+ public boolean isValueAsParent() {
+ return this.delegate.isValueAsParent();
+ }
+
+ public ILoadingType getLoadingType() {
+ return loadingType;
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IBehavior.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IBehavior.java
new file mode 100644
index 00000000000..48b207b02d4
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IBehavior.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.metadata;
+
+/**
+ * Common behavior of Property and event
+ *
+ * @author yyang
+ */
+public interface IBehavior {
+
+ /**
+ * Getter of the property <tt>name</tt>
+ *
+ * @return Returns the name.
+ */
+ public String getName();
+
+ public void setName(String name);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IEvent.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IEvent.java
new file mode 100644
index 00000000000..22b3cefd616
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IEvent.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.metadata;
+
+/**
+ * UI event
+ *
+ * @author yyang
+ */
+public interface IEvent extends IBehavior {
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ILoadingType.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ILoadingType.java
new file mode 100644
index 00000000000..feed04b275e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ILoadingType.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.metadata;
+
+/**
+ * This class is used to indicate when the property can be
+ * initialized during the XML Loading.
+ *
+ * @author yyang <yves.yang@soyatec.com>
+ */
+public interface ILoadingType {
+
+ public ILoadingType DEFAULT = new ILoadingType() {
+
+ public IValueLoading getValueLoading() {
+ return IValueLoading.Normal;
+ }
+
+ public IProperty[] getDependencies() {
+ return IProperty.EMPTY_ARRAY;
+ }
+ };
+
+ /**
+ * When the property can be loaded.
+ *
+ * @return
+ */
+ IValueLoading getValueLoading();
+
+ /**
+ * The dependency properties must be loaded before.
+ *
+ * @return
+ */
+ IProperty[] getDependencies();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IMetaclass.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IMetaclass.java
new file mode 100644
index 00000000000..8ec251c4353
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IMetaclass.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.metadata;
+
+import org.eclipse.papyrus.xwt.IEventGroup;
+
+/**
+ * UI metaclass
+ *
+ * @author yyang
+ */
+public interface IMetaclass {
+
+ public String getName();
+
+ public IProperty[] getProperties();
+
+ public IMetaclass getSuperClass();
+
+ public IEvent[] getEvents();
+
+ public IProperty findProperty(String name);
+
+ public void removeProperty(String name);
+
+ public IProperty findDefaultProperty();
+
+ public IEvent findEvent(String name);
+
+ public Object newInstance(Object[] parameters);
+
+ public boolean isAbstract();
+
+ public boolean isInstance(Object object);
+
+ public boolean isSubclassOf(IMetaclass metaclass);
+
+ public boolean isSuperclassOf(IMetaclass metaclass);
+
+ public boolean isAssignableFrom(IMetaclass metaclass);
+
+ public Class<?> getType();
+
+ public IProperty addProperty(IProperty property);
+
+ public Class<?> getDataContextType();
+
+ public void addEventGroup(IEventGroup eventGroup);
+
+ public IEventGroup getEventGroup(String event);
+
+ public void addInitializer(IObjectInitializer initializer);
+
+ public void removeInitializer(IObjectInitializer initializer);
+
+ public IObjectInitializer[] getInitializers();
+
+ public void initialize(Object instance);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IObjectInitializer.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IObjectInitializer.java
new file mode 100644
index 00000000000..afbda63525c
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IObjectInitializer.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.metadata;
+
+/**
+ * Provide a mechanism to initialize the instance
+ *
+ * @author yyang
+ *
+ */
+public interface IObjectInitializer {
+
+ void initialize(Object object);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IProperty.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IProperty.java
new file mode 100644
index 00000000000..07a3ec05df6
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IProperty.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.metadata;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * UI property
+ *
+ * @author yyang
+ */
+public interface IProperty extends IBehavior {
+
+ IProperty[] EMPTY_ARRAY = new IProperty[]{};
+
+ public Class<?> getType();
+
+ public void setType(Class<?> type);
+
+ /**
+ * Can generate event
+ *
+ * @return
+ */
+ public void setValue(Object target, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException;
+
+ public Object getValue(Object target) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchFieldException;
+
+ public void addSetPostAction(ISetPostAction setPostAction);
+
+ public void removeSetPostAction(ISetPostAction setPostAction);
+
+ public boolean isDefault();
+
+ public boolean isContainement();
+
+ public boolean isReadOnly();
+
+ /**
+ * use the value ad parent for the children. Table.table, Form.setHeadClient etc
+ *
+ * @return
+ */
+ public boolean isValueAsParent();
+
+ public ILoadingType getLoadingType();
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ISetPostAction.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ISetPostAction.java
new file mode 100644
index 00000000000..2d26eaead00
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ISetPostAction.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.metadata;
+
+public interface ISetPostAction {
+
+ void action(Object target, IProperty property, Object value);
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IValueLoading.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IValueLoading.java
new file mode 100644
index 00000000000..26b097eb060
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/IValueLoading.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.metadata;
+
+/**
+ * This class is used to indicate when the property can be
+ * initialized during the XML Loading.
+ *
+ * @author yyang <yves.yang@soyatec.com>
+ */
+public enum IValueLoading {
+ /**
+ * Set property just after Widget creation. It is the default value.
+ */
+ Normal,
+
+ /**
+ * Set property just after the complete initialization before the creation
+ * of children
+ */
+ PostInitialization,
+
+ /**
+ * Set property just after the creation of children
+ */
+ PostChildren;
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ModelUtils.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ModelUtils.java
new file mode 100644
index 00000000000..0ebc27cf061
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/metadata/ModelUtils.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.metadata;
+
+/**
+ *
+ * @author yyang
+ *
+ */
+public class ModelUtils {
+
+ public static String normalizeEventName(String name) {
+ return name.toLowerCase();
+ }
+
+ public static String normalizePropertyName(String name) {
+ if(name == null || name.length() == 0) {
+ return name;
+ }
+ char c = name.charAt(0);
+ if(Character.isLowerCase(c)) {
+ return name;
+ }
+ return Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java
new file mode 100644
index 00000000000..82e625936c5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class NamedColorsUtil {
+
+ private static ResourceBundle COLORS = ResourceBundle.getBundle("org.eclipse.papyrus.xwt.utils.colors");
+
+ private static String[] colorNames;
+ static {
+ List<String> colors = new ArrayList<String>();
+ Enumeration<String> keys = COLORS.getKeys();
+ while(keys.hasMoreElements()) {
+ String color = keys.nextElement();
+ colors.add(color);
+ }
+ if(!colors.isEmpty()) {
+ colorNames = colors.toArray(new String[0]);
+ Arrays.sort(colorNames);
+ }
+ }
+
+ public static String[] getColorNames() {
+ return colorNames;
+ }
+
+ public static String getColorValue(String name) {
+ if(!hasColor(name)) {
+ return null;
+ }
+ String value = COLORS.getString(name);
+ if(value != null) {
+ value = value.trim();
+ }
+ return value;
+ }
+
+ public static boolean hasColor(String name) {
+ if(name == null) {
+ return false;
+ }
+ String[] colorNames = getColorNames();
+ if(colorNames == null) {
+ return false;
+ }
+ return Arrays.asList(colorNames).contains(name);
+ }
+
+ public static Color getColor(String name) {
+ if(!hasColor(name)) {
+ return null;
+ }
+ String colorValue = getColorValue(name);
+ if(colorValue != null) {
+ return (Color)ObjectUtil.resolveValue(colorValue, Color.class, null);
+ }
+ return null;
+ }
+
+ /**
+ * Utility class.
+ */
+ private NamedColorsUtil() {
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/OperatorExceptionMessage.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/OperatorExceptionMessage.java
new file mode 100644
index 00000000000..5efd85d6b7e
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/OperatorExceptionMessage.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.utils;
+
+/**
+ * @author YaHong.Song(yahong.song@soyatec.com)
+ *
+ */
+public final class OperatorExceptionMessage {
+
+ public static final String TYPE_UN_SAME = "different data type exception";
+
+ public static final String OPRERANR_NULL = "the operant value is null exception";
+
+ public static final String TYPE_WRONG = "type is not supported exception";
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/PathHelper.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/PathHelper.java
new file mode 100644
index 00000000000..4ed66773cd3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/PathHelper.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.io.File;
+import java.util.StringTokenizer;
+
+/**
+ * @author jliu jin.liu@soyatec.com
+ */
+public class PathHelper {
+
+ public static final String URL_IDENTIFY_PREFIX = "file:";
+
+ public static final String BACKWARD_SLASH = "\\";
+
+ public static final String FORWARD_SLASH = "/";
+
+ public static final String RELATIVE_PATH_SIG = "../";
+
+ public static final String WHITE_SPACE_ASCII = "%20";
+
+ public static String getRelativePath(String source, String target) {
+ if(source == null || target == null) {
+ return target;
+ }
+ File sourceFile = new File(source);
+ if(!sourceFile.exists()) {
+ return target;
+ }
+ File targetFile = new File(target);
+ if(!targetFile.exists()) {
+ return target;
+ }
+ source = switchToForwardSlashes(source);
+ target = switchToForwardSlashes(target);
+ int index = target.indexOf(FORWARD_SLASH);
+ String container = null;
+ while(index != -1) {
+ container = target.substring(0, index);
+ if(!source.startsWith(container + FORWARD_SLASH)) {
+ break;
+ }
+ source = source.substring(index + 1);
+ target = target.substring(index + 1);
+ index = target.indexOf(FORWARD_SLASH);
+ }
+ index = source.indexOf(FORWARD_SLASH);
+ while(index != -1) {
+ target = RELATIVE_PATH_SIG + target;
+ source = source.substring(index + 1);
+ index = source.indexOf(FORWARD_SLASH);
+ }
+ return target;
+ }
+
+ /**
+ * Switch to file path slashes
+ */
+ public static String switchToForwardSlashes(String path) {
+ path = path.replace(File.separatorChar, FORWARD_SLASH.charAt(0));
+ path = path.replace(BACKWARD_SLASH.charAt(0), FORWARD_SLASH.charAt(0));
+ return path;
+ }
+
+ public static String getAbsolutePath(String source, String relative) {
+ if(source.indexOf(WHITE_SPACE_ASCII) != -1) {
+ source = source.replace(WHITE_SPACE_ASCII, " ");
+ }
+ if(relative.indexOf(WHITE_SPACE_ASCII) != -1) {
+ relative = relative.replace(WHITE_SPACE_ASCII, " ");
+ }
+ if(source.startsWith(FORWARD_SLASH)) {
+ source = source.substring(1);
+ }
+ String prefix = null;
+ if(source.startsWith(URL_IDENTIFY_PREFIX)) {
+ prefix = URL_IDENTIFY_PREFIX;
+ source = source.substring(URL_IDENTIFY_PREFIX.length());
+ if(System.getProperty("os.arch").startsWith("Win")) {
+ source = source.substring(1);
+ }
+ }
+ File file = new File(source);
+ if(!file.exists()) {
+ return relative;
+ }
+ if(file.isFile()) {
+ source = file.getParent();
+ }
+ source = switchToForwardSlashes(source);
+ relative = switchToForwardSlashes(relative);
+ if(relative.startsWith(FORWARD_SLASH)) {
+ relative = relative.substring(1);
+ }
+ int index = relative.lastIndexOf(FORWARD_SLASH);
+ if(index != -1) {
+ String container = relative.substring(0, index);
+ int i = source.indexOf(container);
+ if(i != -1) {
+ source = source.substring(0, i);
+ } else {
+ int j = relative.indexOf(RELATIVE_PATH_SIG);
+ while(j != -1) {
+ relative = relative.substring(j + RELATIVE_PATH_SIG.length());
+ source = source.substring(0, source.lastIndexOf(FORWARD_SLASH));
+ j = relative.indexOf(RELATIVE_PATH_SIG);
+ }
+ }
+ }
+ if(System.getProperty("os.arch").startsWith("Win")) {
+ source = "/" + source;
+ }
+
+ return (prefix != null ? prefix : "") + source + FORWARD_SLASH + relative;
+ }
+
+ /**
+ * Convert to relative url based on base
+ */
+ public static String convertToRelative(String input, String base) {
+ StringTokenizer inputTokenizer = new StringTokenizer(input, FORWARD_SLASH);
+ StringTokenizer baseTokenizer = new StringTokenizer(base, FORWARD_SLASH);
+ String token1 = "", token2 = "";
+ //
+ while(true) {
+ if(!inputTokenizer.hasMoreTokens() || !baseTokenizer.hasMoreTokens())
+ break;
+ token1 = baseTokenizer.nextToken();
+ token2 = inputTokenizer.nextToken();
+ if(!token1.equals(token2))
+ break;
+ }
+ StringBuilder builder = new StringBuilder();
+ while(baseTokenizer.hasMoreTokens()) {
+ baseTokenizer.nextToken();
+ builder.append(RELATIVE_PATH_SIG);
+ }
+ builder.append(token2);
+ while(inputTokenizer.hasMoreTokens()) {
+ builder.append(FORWARD_SLASH + inputTokenizer.nextToken());
+ }
+ return builder.toString();
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/ResourceManager.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/ResourceManager.java
new file mode 100644
index 00000000000..c447e2584cd
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/ResourceManager.java
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * 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.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.eclipse.papyrus.xwt.XWTMaps;
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * @author jliu
+ */
+public class ResourceManager {
+
+ public static ResourceManager resources = new ResourceManager();
+
+ private Map<String, Color> key2Colors = new HashMap<String, Color>();
+
+ private Map<String, Font> key2Fonts = new HashMap<String, Font>();
+
+ private Map<String, Image> key2Images = new HashMap<String, Image>();
+
+ /**
+ * Default constructor.
+ */
+ private ResourceManager() {
+ }
+
+ public Color getColor(String colorStr) {
+ Color color = key2Colors.get(colorStr);
+ if(color == null || color.isDisposed()) {
+ key2Colors.put(colorStr, color = ColorTool.getColor(colorStr));
+ }
+ return color;
+ }
+
+ public Font getFont(String fontStr) {
+ Font font = key2Fonts.get(fontStr);
+ if(font == null || font.isDisposed()) {
+ key2Fonts.put(fontStr, font = FontTool.getFont(fontStr));
+ }
+ return font;
+ }
+
+ public Image getImage(String imagePath) {
+ if(imagePath == null) {
+ return null;
+ }
+ try {
+ return getImage(new URL(imagePath));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public Image getImage(URL file) {
+ String key = file.toString();
+ Image image = key2Images.get(key);
+ if(image == null || image.isDisposed()) {
+ key2Images.put(key, image = ImageTool.getImage(file));
+ }
+ return image;
+ }
+
+ public synchronized void dispose() {
+ // dispose colors.
+ Collection<Color> colors = key2Colors.values();
+ for(Color color : colors) {
+ if(color != null) {
+ color.dispose();
+ }
+ }
+ key2Colors.clear();
+
+ // dispose fonts.
+ Collection<Font> fonts = key2Fonts.values();
+ for(Font font : fonts) {
+ if(font != null) {
+ font.dispose();
+ }
+ }
+ key2Colors.clear();
+
+ // dispose images
+ Collection<Image> images = key2Images.values();
+ for(Image image : images) {
+ if(image != null) {
+ image.dispose();
+ }
+ }
+ }
+
+ static class ColorTool {
+
+ static Color getColor(String colorStr) {
+ if(NamedColorsUtil.hasColor(colorStr)) {
+ return NamedColorsUtil.getColor(colorStr);
+ }
+ if(colorStr.toLowerCase().startsWith("swt.")) {
+ return getSWTColor(colorStr);
+ } else if(colorStr.startsWith("#")) {
+ try {
+ int rgb = Integer.parseInt(colorStr.substring(1), 16);
+ return getColor(rgb);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ } else if(colorStr.indexOf(",") != -1) {
+ List<String> rgbs = new ArrayList<String>();
+ StringTokenizer stk = new StringTokenizer(colorStr, ",");
+ while(stk.hasMoreTokens()) {
+ rgbs.add(stk.nextToken());
+ }
+ if(rgbs.size() == 3) {
+ try {
+ int r = Integer.parseInt(rgbs.get(0).trim());
+ int g = Integer.parseInt(rgbs.get(1).trim());
+ int b = Integer.parseInt(rgbs.get(2).trim());
+ return getColor(r, g, b);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+ }
+ return getSWTColor(colorStr);
+ }
+
+ static Color getColor(int red, int green, int blue) {
+ if(red > 255 || green > 255 || blue > 255 || red < 0 || green < 0 || blue < 0) {
+ return null;
+ }
+ return new Color(Display.getCurrent(), red, green, blue);
+ }
+
+ static Color getColor(int rgb) {
+ int value = 0xff000000 | rgb;
+ int red = (value >> 16) & 0xFF;
+ int green = (value >> 8) & 0xFF;
+ int blue = (value >> 0) & 0xFF;
+ return getColor(red, green, blue);
+ }
+
+ static Color getSWTColor(String colorStr) {
+ if(!(colorStr.toLowerCase().startsWith("swt."))) {
+ if(!(colorStr.toLowerCase().startsWith("color_"))) {
+ colorStr = "COLOR_" + colorStr;
+ }
+ colorStr = "SWT." + colorStr;
+ }
+ int swtColor = XWTMaps.getColor(colorStr);
+ return getSWTColor(swtColor);
+ }
+
+ static Color getSWTColor(int swtValue) {
+ return Display.getCurrent().getSystemColor(swtValue);
+ }
+ }
+
+ static class FontTool {
+
+ static Font getFont(String fontStr) {
+ if(fontStr.indexOf(",") != -1) {
+ StringTokenizer stk = new StringTokenizer(fontStr, ",");
+ String name = null;
+ int height = 0;
+ int style = SWT.NORMAL;
+ while(stk.hasMoreTokens()) {
+ String token = stk.nextToken().trim();
+ if(token.equalsIgnoreCase("normal") || token.equalsIgnoreCase("bold") || token.equalsIgnoreCase("italic") || token.contains("|")) {
+ style = (Integer)ObjectUtil.resolveValue(token, Integer.class, style);
+ } else if(isInt(token)) {
+ height = Integer.parseInt(token);
+ } else {
+ name = token;
+ }
+ }
+ return getFont(name, height, style);
+ }
+ return getFont(fontStr, 12, SWT.NORMAL);
+ }
+
+ static boolean isInt(String value) {
+ try {
+ Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ return true;
+ }
+
+ static Font getFont(String name, int height, int style) {
+ if(name == null) {
+ return null;
+ }
+ return new Font(Display.getCurrent(), name, height, style);
+ }
+
+ static Font getSWTFont() {
+ return Display.getCurrent().getSystemFont();
+ }
+ }
+
+ static class ImageTool {
+
+ static Image getImage(String resource) {
+ return getImage(ResourceManager.class.getResource(resource));
+ }
+
+ static Image getImage(URL url) {
+ if(url == null) {
+ return null;
+ }
+ try {
+ InputStream stream = url.openStream();
+ try {
+ return new Image(Display.getCurrent(), stream);
+ } finally {
+ stream.close();
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+ }
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/colors.properties b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/colors.properties
new file mode 100644
index 00000000000..d9306a3ff98
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/colors.properties
@@ -0,0 +1,150 @@
+###############################################################################
+# 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
+###############################################################################
+AliceBlue #F0F8FF
+AntiqueWhite #FAEBD7
+Aqua #00FFFF
+Aquamarine #7FFFD4
+Azure #F0FFFF
+Beige #F5F5DC
+Bisque #FFE4C4
+Black #000000
+BlanchedAlmond #FFEBCD
+Blue #0000FF
+BlueViolet #8A2BE2
+Brown #A52A2A
+BurlyWood #DEB887
+CadetBlue #5F9EA0
+Chartreuse #7FFF00
+Chocolate #D2691E
+Coral #FF7F50
+CornflowerBlue #6495ED
+Cornsilk #FFF8DC
+Crimson #DC143C
+Cyan #00FFFF
+DarkBlue #00008B
+DarkCyan #008B8B
+DarkGoldenRod #B8860B
+DarkGray #A9A9A9
+DarkGreen #006400
+DarkKhaki #BDB76B
+DarkMagenta #8B008B
+DarkOliveGreen #556B2F
+Darkorange #FF8C00
+DarkOrchid #9932CC
+DarkRed #8B0000
+DarkSalmon #E9967A
+DarkSeaGreen #8FBC8F
+DarkSlateBlue #483D8B
+DarkSlateGray #2F4F4F
+DarkTurquoise #00CED1
+DarkViolet #9400D3
+DeepPink #FF1493
+DeepSkyBlue #00BFFF
+DimGray #696969
+DodgerBlue #1E90FF
+FireBrick #B22222
+FloralWhite #FFFAF0
+ForestGreen #228B22
+Fuchsia #FF00FF
+Gainsboro #DCDCDC
+GhostWhite #F8F8FF
+Gold #FFD700
+GoldenRod #DAA520
+Gray #808080
+Green #008000
+GreenYellow #ADFF2F
+HoneyDew #F0FFF0
+HotPink #FF69B4
+IndianRed #CD5C5C
+Indigo #4B0082
+Ivory #FFFFF0
+Khaki #F0E68C
+Lavender #E6E6FA
+LavenderBlush #FFF0F5
+LawnGreen #7CFC00
+LemonChiffon #FFFACD
+LightBlue #ADD8E6
+LightCoral #F08080
+LightCyan #E0FFFF
+LightGoldenRodYellow #FAFAD2
+LightGrey #D3D3D3
+LightGreen #90EE90
+LightPink #FFB6C1
+LightSalmon #FFA07A
+LightSeaGreen #20B2AA
+LightSkyBlue #87CEFA
+LightSlateGray #778899
+LightSteelBlue #B0C4DE
+LightYellow #FFFFE0
+Lime #00FF00
+LimeGreen #32CD32
+Linen #FAF0E6
+Magenta #FF00FF
+Maroon #800000
+MediumAquaMarine #66CDAA
+MediumBlue #0000CD
+MediumOrchid #BA55D3
+MediumPurple #9370D8
+MediumSeaGreen #3CB371
+MediumSlateBlue #7B68EE
+MediumSpringGreen #00FA9A
+MediumTurquoise #48D1CC
+MediumVioletRed #C71585
+MidnightBlue #191970
+MintCream #F5FFFA
+MistyRose #FFE4E1
+Moccasin #FFE4B5
+NavajoWhite #FFDEAD
+Navy #000080
+OldLace #FDF5E6
+Olive #808000
+OliveDrab #6B8E23
+Orange #FFA500
+OrangeRed #FF4500
+Orchid #DA70D6
+PaleGoldenRod #EEE8AA
+PaleGreen #98FB98
+PaleTurquoise #AFEEEE
+PaleVioletRed #D87093
+PapayaWhip #FFEFD5
+PeachPuff #FFDAB9
+Peru #CD853F
+Pink #FFC0CB
+Plum #DDA0DD
+PowderBlue #B0E0E6
+Purple #800080
+Red #FF0000
+RosyBrown #BC8F8F
+RoyalBlue #4169E1
+SaddleBrown #8B4513
+Salmon #FA8072
+SandyBrown #F4A460
+SeaGreen #2E8B57
+SeaShell #FFF5EE
+Sienna #A0522D
+Silver #C0C0C0
+SkyBlue #87CEEB
+SlateBlue #6A5ACD
+SlateGray #708090
+Snow #FFFAFA
+SpringGreen #00FF7F
+SteelBlue #4682B4
+Tan #D2B48C
+Teal #008080
+Thistle #D8BFD8
+Tomato #FF6347
+Turquoise #40E0D0
+Violet #EE82EE
+Wheat #F5DEB3
+White #FFFFFF
+WhiteSmoke #F5F5F5
+Yellow #FFFF00
+YellowGreen #9ACD32 \ No newline at end of file
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/AbstractValidationRule.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/AbstractValidationRule.java
new file mode 100644
index 00000000000..4a31d740b90
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/AbstractValidationRule.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.validation;
+
+import org.eclipse.papyrus.xwt.IValidationRule;
+
+/**
+ * Abstract implementation of {@link IValidationRule}
+ *
+ * @author hceylan
+ */
+public abstract class AbstractValidationRule implements IValidationRule {
+
+ /**
+ *
+ */
+ public AbstractValidationRule() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IValueValidator#getBindingMode()
+ */
+ public Direction getBindingMode() {
+ return Direction.Both;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IValueValidator#getPhase()
+ */
+ public Phase getPhase() {
+ return Phase.AfterGet;
+ }
+
+}
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/InverseValidationRule.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/InverseValidationRule.java
new file mode 100644
index 00000000000..e2d94de26e3
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/validation/InverseValidationRule.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.validation;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.papyrus.xwt.IValidationRule;
+
+public class InverseValidationRule implements IValidationRule {
+
+ private final IValidationRule delegate;
+
+ public InverseValidationRule(IValidationRule delegate) {
+ super();
+
+ this.delegate = delegate;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IValueValidator#getBindingMode()
+ */
+ public Direction getBindingMode() {
+ switch(delegate.getBindingMode()) {
+ case SourceToTarget:
+ return Direction.TargetToSource;
+ case TargetToSource:
+ return Direction.SourceToTarget;
+ case Both:
+ default:
+ return Direction.Both;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IValueValidator#getPhase()
+ */
+ public Phase getPhase() {
+ return delegate.getPhase();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.papyrus.xwt.IValueValidator#validateBack(java.lang.Object)
+ */
+ public IStatus validateBack(Object value) {
+ return delegate.validate(value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ */
+ public IStatus validate(Object value) {
+ return delegate.validateBack(value);
+ }
+
+}

Back to the top