Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF48
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/plugin.xml56
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties3
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/schema/resourceLocators.exsd8
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/IResourcePart.java34
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptCommonCorePlugin.java40
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptResourceModel.java16
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/ResourceReference.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java3
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/LibraryProviderPropertyTester.java47
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/ResourceReferenceAdapterFactory.java (renamed from common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/ResourceAdapterFactory.java)28
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libprov/LibraryProviderPropertyTester.java41
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/operations/AbstractJptFileCreationDataModelProvider.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java82
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java98
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ProjectAdapterFactory.java50
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java260
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleProjectResourceLocator.java68
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java46
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java14
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java3
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java19
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java12
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/CallbackJobSynchronizer.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobSynchronizer.java9
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java15
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/SimpleSchedulingRule.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/AbstractSingleUseQueueingJobCommandExecutor.java105
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/CommandJobCommandAdapter.java47
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandCommandAdapter.java44
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandJob.java44
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java95
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java195
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SimpleJobCommandExecutor.java209
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingExtendedJobCommandExecutor.java103
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingJobCommandExecutor.java39
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTAnnotatedElement.java11
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnum.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMember.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTPackage.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTType.java9
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ProjectResourceLocator.java58
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ResourceLocator.java37
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java14
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedCommandExecutor.java107
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedExtendedCommandExecutor.java164
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/ExtendedJobCommandExecutor.java225
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/InterruptibleJobCommand.java81
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommand.java (renamed from common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobCommand.java)39
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommandExecutor.java129
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java105
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/RepeatingJobCommand.java85
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemExtendedLabelProvider.java235
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemLabelProvider.java224
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java280
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemTreeContentProvider.java187
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java82
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractTreeItemContentProvider.java204
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ContentProvider.java40
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java58
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/EmptySelection.java43
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemStructuredStateProviderManager.java45
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemTreeStateProviderManager.java101
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/LabelProviderAdapter.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorContentProvider.java135
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorLabelProvider.java117
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullLabelProvider.java60
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullTreeContentProvider.java60
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SelectionChangedAdapter.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleItemTreeStateProviderFactoryProvider.java48
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleMessageTreeContent.java100
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemExtendedLabelProvider.java54
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemLabelProvider.java59
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemTreeContentProvider.java79
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StructuredContentProvider.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/TreeContentProvider.java44
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java160
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java236
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java54
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java61
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTTreeChangeListenerWrapper.java151
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java362
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/DisposeAdapter.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java147
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandExecutor.java60
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandExecutor.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PageAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter.java41
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter2.java50
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PropertyAdapter.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandExecutor.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/WindowAdapter.java38
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/BooleanStateController.java81
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/MultiControlBooleanStateController.java65
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SimpleBooleanStateController.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java23
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/PropertySheetWidgetFactory.java15
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/DelegatingContentAndLabelProvider.java207
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ExtendedLabelProvider.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProvider.java49
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProviderFactory.java (renamed from common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemContentProviderFactory.java)16
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProvider.java44
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProviderFactory.java16
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProvider.java105
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProviderFactory.java (renamed from common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeItemContentProviderFactory.java)18
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProvider.java111
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProviderFactory.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeStateProviderFactoryProvider.java (renamed from common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemContentProvider.java)26
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/StructuredStateProvider.java (renamed from common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeItemContentProvider.java)32
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeStateProvider.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF111
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/BooleanReference.java166
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ExceptionHandler.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ExceptionHandler.java)8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Filter.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ModifiableObjectReference.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ObjectReference.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ReadOnlyObjectReference.java43
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/Command.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Command.java)4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/CommandExecutor.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/CommandExecutor.java)39
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/ExtendedCommandExecutor.java126
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/InterruptibleCommand.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/InterruptibleCommand.java)6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/InterruptibleCommandExecutor.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/InterruptibleCommandExecutor.java)6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/NotifyingRepeatingCommand.java102
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/RepeatingCommand.java80
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulCommandExecutor.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulExtendedCommandExecutor.java25
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractBooleanReference.java85
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractTransformer.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AsynchronousCommandExecutor.java168
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Classpath.java22
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CollectingExceptionHandler.java54
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ConsumerThreadCoordinator.java112
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/FilterAdapter.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/IntReference.java133
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/LazyObjectReference.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/LazyReadOnlyObjectReference.java)14
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java12
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableBooleanReference.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/BooleanReference.java)8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableIntReference.java40
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyBooleanReference.java46
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyIntReference.java145
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableAdapter.java26
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleBooleanReference.java24
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleCommandExecutor.java46
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleFilter.java61
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleIntReference.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleObjectReference.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StatefulCommandExecutor.java33
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedBoolean.java10
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedInt.java10
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedObject.java10
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedStack.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommandExecutor.java65
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Transformer.java2
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TransformerAdapter.java27
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandExecutor.java276
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandExecutor.java96
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSafeCommandExecutor.java57
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandExecutor.java165
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractStatefulCommandExecutor.java67
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractThreadLocalCommandExecutor.java63
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousCommandExecutor.java100
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousExtendedCommandExecutor.java153
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java160
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousRepeatingCommandWrapper.java287
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/CommandRunnable.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CommandRunnable.java)15
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/CompositeCommand.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CompositeCommand.java)11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java98
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingCommandExecutor.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingExtendedCommandExecutor.java83
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandState.java220
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandWrapper.java170
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RunnableCommand.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableCommand.java)15
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeCommandExecutor.java44
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeExtendedCommandExecutor.java63
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulCommandExecutor.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulExtendedCommandExecutor.java64
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingCommandExecutor.java33
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingExtendedCommandExecutor.java78
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SynchronizingCommand.java163
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommand.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommand.java)14
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommandExecutor.java30
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalExtendedCommandExecutor.java40
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModel.java29
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java27
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java138
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java35
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java32
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectPropertyValueModelAdapter.java42
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectTreeValueModelAdapter.java119
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BufferedWritablePropertyValueModel.java169
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingPropertyValueModelWrapper.java101
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationPropertyValueModel.java112
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java107
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ChangePropertyValueModelAdapter.java40
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java118
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionListValueModelAdapter.java9
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java105
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java52
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java12
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java95
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoubleModifiablePropertyValueModel.java53
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoublePropertyValueModel.java165
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java130
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java25
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringPropertyValueModel.java98
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringWritablePropertyValueModel.java114
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemChangeListValueModelAdapter.java24
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java124
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCollectionValueModelAdapter.java11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java45
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java83
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelWrapper.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/NullPropertyValueModel.java12
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java91
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyCollectionValueModelAdapter.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyListValueModelAdapter.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelWrapper.java82
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ReadOnlyWritablePropertyValueModelWrapper.java11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SetCollectionValueModel.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimplePropertyValueModel.java26
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelWrapper.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StatePropertyValueModelAdapter.java40
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java9
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java132
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationWritablePropertyValueModel.java115
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreeAspectAdapter.java155
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreePropertyValueModelAdapter.java144
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueAspectAdapter.java50
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueChangeAdapter.java24
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/RadioButtonModelAdapter.java86
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/node/AbstractNode.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/AsynchronousSynchronizer.java188
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackAsynchronousSynchronizer.java120
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackSynchronousSynchronizer.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/AbstractChangeListener.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/SimpleChangeListener.java)11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ChangeAdapter.java14
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CollectionChangeAdapter.java15
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CommandChangeListener.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ListChangeAdapter.java15
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/PropertyChangeAdapter.java17
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java12
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/WritablePropertyValueModel.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java115
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java65
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF1
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java22
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java9
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java10
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java5
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java5
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java18
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousCommandExecutorTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AsynchronousCommandExecutorTests.java)18
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousRepeatingCommandWrapperTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java)126
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandExecutorTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandExecutorTests.java)33
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandRunnableTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandRunnableTests.java)9
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandTests.java)17
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CompositeCommandTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeCommandTests.java)11
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java37
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java14
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java24
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java22
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java14
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java118
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java223
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java19
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java27
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java15
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java35
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java362
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java5
-rw-r--r--jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/DbwsGeneratorUi.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/wizards/gen/DbwsGeneratorWizard.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml107
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/GenericJaxbProjectManager.java45
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbNode.java6
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java14
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java8
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java31
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JavaElementAdapterFactory.java46
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JaxbPlatformTester.java63
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/ResourceAdapterFactory.java51
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libprov/JaxbLibraryProviderInstallOperationConfigAdapterFactory.java46
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/JaxbPlatformTester.java54
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java129
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbindex/JaxbIndexResourceImpl.java174
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java100
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java11
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml10
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorItemLabelProviderFactory.java27
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorUi.java20
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbPersistentAttributeItemLabelProvider.java44
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorItemLabelProviderFactory.java82
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory.java92
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorUi.java24
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemContentProvider.java37
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemLabelProvider.java51
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemContentProvider.java36
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemLabelProvider.java56
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumConstantItemLabelProvider.java51
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemContentProvider.java38
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemLabelProvider.java43
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemContentProvider.java37
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemLabelProvider.java54
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPersistentAttributeItemLabelProvider.java79
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbRegistryItemContentProvider.java39
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbTypeItemLabelProvider.java60
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentAndLabelProvider.java22
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentProvider.java126
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorItemLabelProviderFactory.java24
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorLabelProvider.java138
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorTreeItemContentProviderFactory.java25
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectModel.java11
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java22
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/navigator/JaxbNavigatorUi.java14
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/META-INF/MANIFEST.MF2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml248
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/GenericJpaProjectManager.java1100
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaNode.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatform.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatformFactory.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProject.java221
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProjectManager.java94
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java114
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java31
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaRootContextNode.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappedSuperclass.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/XmlFile.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaEntity.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdTypeMapping.java (renamed from jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaStructureNodes.java)23
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaMappedSuperclass.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmEntity.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmIdTypeMapping.java (renamed from jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmStructureNodes.java)22
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/ClassRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/Persistence.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceStructureNodes.java37
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java295
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java575
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/FileAdapterFactory.java130
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java1417
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaPackageInfoResourceModelProvider.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaResourceModelProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaPlatformTester.java60
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaTester.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/ProjectAdapterFactory.java100
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/SimpleJpaProjectConfig.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/WorkspaceAdapterFactory.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/PersistentAttributePropertyTester.java37
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/XmlFilePropertyTester.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java102
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetInstallDelegate.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDelegate.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/RuntimeChangedListener.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaDataSource.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericRootContextNode.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericMappingFileRef.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/libprov/JpaLibraryProviderInstallOperationConfigAdapterFactory.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationOperation.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/OrmFileCreationOperation.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JavaElementAdapterFactory.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformDescriptionImpl.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformTester.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/ResourceAdapterFactory.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeleteMappingFileParticipant.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveFolderParticipant.java31
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveMappingFileParticipant.java31
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameFolderParticipant.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameMappingFileParticipant.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourceAdapterFactory.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourcePropertyTester.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/synch/SynchronizeClassesJob.java146
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java99
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/MetamodelSynchronizer.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/xml/JpaXmlResource.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/plugin.xml18
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/AbstractEclipseLinkDDLGenerator.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/operations/EclipseLinkOrmFileCreationDataModelProvider.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF1
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml17
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLink2_3PersistenceUnitMetadataComposite.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_0DetailsProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_3DetailsProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsDetailsProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_1UiDefinition.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_2UiDefinition.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_0UiDefinition.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_1UiDefinition.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXmlUiDefinition.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/EclipseLinkPersistenceXmlUiDefinition.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/connection/CacheStatementsPropertiesComposite.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java94
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemLabelProviderFactory.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkPersistenceUnitItemContentProvider.java71
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_1JpaPlatformUiFactory.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_2JpaPlatformUiFactory.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUi.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUiFactory.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_1JpaPlatformUiFactory.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_2JpaPlatformUiFactory.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_3JpaPlatformUiFactory.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_4JpaPlatformUiFactory.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUiFactory.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorItemContentProviderFactory.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorProvider.java34
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceItemContentProviderFactory.java135
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceStructureItemContentProviderFactory.java42
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceUnitItemContentProvider.java57
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/v2_0/persistence/EclipseLinkPersistenceXml2_0UiDefinition.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml339
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java34
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaPlatformUi.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java33
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaRootContextNodeModel.java34
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiPlugin.java147
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/ResourceUiDefinition.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsPageManager.java (renamed from jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsPage.java)53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsProvider.java38
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/EditorPartAdapterFactory.java65
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java137
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaFileAdapterFactory.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaPlatformAdapterFactory.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaStructureNodeAdapterFactory.java76
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptResourceModelPropertyTester.java64
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java197
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java59
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java241
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java75
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlHandler.java62
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java70
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java59
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/UpgradeXmlFileVersionHandler.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractEntityMappingsDetailsProvider.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractJpaDetailsPage.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractOverridesComposite.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsComposite.java40
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MapAsComposite.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java38
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/AbstractJavaResourceUiDefinition.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentAttributeDetailsProvider.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentTypeDetailsProvider.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsDetailsProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentAttributeDetailsProvider.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentTypeDetailsProvider.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmXmlUiDefinition.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/PersistenceEditor.java65
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/JarFileItemLabelProvider.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/XmlMappingFileViewerFilter.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0FlagTransformer.java61
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0ProjectFlagModel.java31
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/EntityMappings2_0DetailsProvider.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/OrmXml2_0UiDefinition.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceXml2_0UiDefinition.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/platform/generic/Generic2_0JpaPlatformUiFactory.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlJavaCompletionProposalComputer.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlSseCompletionProposalComputer.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/listeners/SWTConnectionListenerWrapper.java471
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/menus/MapAsContribution.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentProvider.java254
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java85
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java100
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorLabelProvider.java138
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java75
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemContentProvider.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemLabelProvider.java90
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceXmlUiDefinition.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/BaseJpaPlatformUi.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/ClassRefItemLabelProvider.java80
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java54
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUi.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUiFactory.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java287
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java118
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorProvider.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JarFileRefItemLabelProvider.java85
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java56
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java75
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java99
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemContentProvider.java74
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemLabelProvider.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceItemLabelProvider.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemContentProvider.java198
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java160
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java66
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java100
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java78
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemContentProvider.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemLabelProvider.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java700
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelection.java60
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelectionManager.java288
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaDetailsSelectionParticipant.java42
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaPageManager.java296
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelection.java37
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionEvent.java64
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionManager.java57
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionParticipant.java38
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaStructureSelectionParticipant.java69
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java336
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWindowManager.java126
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWorkbenchManager.java251
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/SelectionManagerFactory.java105
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorAdapterFactory.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorSelectionParticipant.java215
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/ViewPartAdapterFactory.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchAdapterFactory.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchPartAdapterFactory.java61
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchWindowAdapterFactory.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/EntityMappingsItemContentProvider.java55
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java33
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemContentProviderFactory.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemLabelProviderFactory.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaResourceModelStructureProvider.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemContentProviderFactory.java67
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemLabelProviderFactory.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JpaFileItemContentProvider.java51
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/MappingStructureItemLabelProviderFactory.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemContentProviderFactory.java79
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemLabelProviderFactory.java27
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmResourceModelStructureProvider.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemContentProviderFactory.java75
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemLabelProviderFactory.java65
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProvider.java55
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProviderFactory.java270
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemLabelProviderFactory.java48
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceResourceModelStructureProvider.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemContentProviderFactory.java91
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java106
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceUnitItemContentProvider.java176
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/ResourceModelItemContentProvider.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/AbstractJpaView.java166
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaDetailsView.java392
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java505
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructureView.java227
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructurePage.java412
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructureView.java134
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityClassWizardPage.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityWizard.java32
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java343
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java52
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/orm/MappingFileWizard.java106
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/navigator/JpaNavigatorProvider.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaEditorManager.java45
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaSelectionManager.java81
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaViewManager.java99
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/structure/JpaStructureProvider.java41
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests.extension.resource/src/org/eclipse/jpt/jpa/core/tests/extension/resource/TestJpaPlatformUiFactory.java15
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java16
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java116
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceTests.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JpaProjectManagerTests.java176
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/projects/TestJpaProject.java61
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java4
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF2
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java13
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java3
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java71
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java11
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF2
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java17
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java22
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java9
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java3
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java4
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java16
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java16
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java18
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java22
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java3
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java18
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java18
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java97
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java5
659 files changed, 24924 insertions, 16577 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF
index 2b26df13ba..0f5bc3bef3 100644
--- a/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF
@@ -28,15 +28,33 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)"
Dali-Comment: We friend 'utility' to all non-EclipseLink, non-test bundles
Export-Package: org.eclipse.jpt.common.core,
- org.eclipse.jpt.common.core.internal;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.gen;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.libprov;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.libval;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.operations;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.resource;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.resource.java;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.resource.java.binary;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
- org.eclipse.jpt.common.core.internal.resource.java.source;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.gen;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.libprov;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.libval;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.operations;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.resource;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.resource.java;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.resource.java.binary;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.resource.java.source;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
org.eclipse.jpt.common.core.internal.utility;
x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
@@ -46,12 +64,20 @@ Export-Package: org.eclipse.jpt.common.core,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
org.eclipse.jpt.jpa.ui",
- org.eclipse.jpt.common.core.internal.utility.jdt;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core",
- org.eclipse.jpt.common.core.internal.utility.translators;x-friends:="org.eclipse.jpt.jpa.core,org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.utility.command;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
+ org.eclipse.jpt.common.core.internal.utility.jdt;
+ x-friends:="org.eclipse.jpt.jaxb.core,
+ org.eclipse.jpt.jpa.core",
+ org.eclipse.jpt.common.core.internal.utility.translators;
+ x-friends:="org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jaxb.core",
org.eclipse.jpt.common.core.libprov,
org.eclipse.jpt.common.core.libval,
org.eclipse.jpt.common.core.resource,
org.eclipse.jpt.common.core.resource.java,
org.eclipse.jpt.common.core.utility,
+ org.eclipse.jpt.common.core.utility.command,
org.eclipse.jpt.common.core.utility.jdt
Import-Package: com.ibm.icu.text;version="4.0.1"
diff --git a/common/plugins/org.eclipse.jpt.common.core/plugin.xml b/common/plugins/org.eclipse.jpt.common.core/plugin.xml
index 0fe4f7e514..6110a45534 100644
--- a/common/plugins/org.eclipse.jpt.common.core/plugin.xml
+++ b/common/plugins/org.eclipse.jpt.common.core/plugin.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
- Copyright (c) 2011 Oracle. All rights reserved.
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0, which accompanies this distribution
- and is available at http://www.eclipse.org/legal/epl-v10.html.
-
- Contributors:
- Oracle - initial API and implementation
+ Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0, which accompanies this distribution
+ and is available at http://www.eclipse.org/legal/epl-v10.html.
+
+ Contributors:
+ Oracle - initial API and implementation
-->
<plugin>
@@ -26,7 +26,29 @@
schema="schema/resourceLocators.exsd"/>
- <!-- ***** Eclipse core extensions ***** -->
+ <!-- ***** adapters ***** -->
+
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+
+ <!-- IProject -> ProjectResourceLocator -->
+ <factory
+ adaptableType="org.eclipse.core.resources.IProject"
+ class="org.eclipse.jpt.common.core.internal.resource.ProjectAdapterFactory">
+ <adapter type="org.eclipse.jpt.common.core.resource.ProjectResourceLocator"/>
+ </factory>
+
+ <!-- ResourceReference -> IResource -->
+ <factory
+ adaptableType="org.eclipse.jpt.common.core.ResourceReference"
+ class="org.eclipse.jpt.common.core.internal.ResourceReferenceAdapterFactory">
+ <adapter type="org.eclipse.core.resources.IResource"/>
+ </factory>
+
+ </extension>
+
+
+ <!-- ***** content types ***** -->
<extension
point="org.eclipse.core.contenttype.contentTypes">
@@ -54,17 +76,7 @@
</extension>
- <extension
- point="org.eclipse.core.runtime.adapters">
-
- <factory
- class="org.eclipse.jpt.common.core.internal.ResourceAdapterFactory"
- adaptableType="org.eclipse.core.resources.IResource">
- <adapter type="org.eclipse.jpt.common.core.IResourcePart"/>
- </factory>
-
- </extension>
-
+ <!-- ***** property testers ***** -->
<extension
point="org.eclipse.core.expressions.propertyTesters">
@@ -74,11 +86,13 @@
type="org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider"
namespace="org.eclipse.jpt.common.core"
properties="id, extendsId"
- class="org.eclipse.jpt.common.core.internal.libprov.LibraryProviderPropertyTester"/>
+ class="org.eclipse.jpt.common.core.internal.LibraryProviderPropertyTester"/>
</extension>
+ <!-- ***** Dali extensions (eat our own dogfood) ***** -->
+
<extension
point="org.eclipse.jpt.common.core.resourceLocators">
@@ -141,6 +155,8 @@
</extension>
+ <!-- ***** WTP Library Provider Framework Integration ***** -->
+
<extension
point="org.eclipse.jst.common.project.facet.core.libraryProviders">
diff --git a/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties b/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties
index e474609500..a4eef57496 100644
--- a/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties
+++ b/common/plugins/org.eclipse.jpt.common.core/property_files/jpt_common_core.properties
@@ -1,5 +1,5 @@
################################################################################
-# Copyright (c) 2011 Oracle. All rights reserved.
+# Copyright (c) 2012 Oracle. All rights reserved.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0, which accompanies this distribution
# and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,6 +7,7 @@
# Contributors:
# Oracle - initial API and implementation
################################################################################
+DALI_JOB_NAME=Dali
DALI_EVENT_HANDLER_THREAD_NAME=Dali Event Handler
GENERATION_CREATING_LAUNCH_CONFIG_TASK=Creating launch configuration
GENERATION_SAVING_LAUNCH_CONFIG_TASK=Saving launch configuration
diff --git a/common/plugins/org.eclipse.jpt.common.core/schema/resourceLocators.exsd b/common/plugins/org.eclipse.jpt.common.core/schema/resourceLocators.exsd
index 5eaf59b07a..d82f686e66 100644
--- a/common/plugins/org.eclipse.jpt.common.core/schema/resourceLocators.exsd
+++ b/common/plugins/org.eclipse.jpt.common.core/schema/resourceLocators.exsd
@@ -6,7 +6,7 @@
<meta.schema plugin="org.eclipse.jpt.common.core" id="resourceLocators" name="Resource Locators"/>
</appinfo>
<documentation>
- Used to provide custom (non-java) resource location logic to JPT projects.
+ Used to provide custom (non-Java) resource location logic to JPT projects.
</documentation>
</annotation>
@@ -120,7 +120,7 @@
<documentation>
&lt;br&gt;
&lt;p&gt;
-The following example is the included simple java resource locator, which is used for simple java projects. It is of &quot;lowest&quot; priority, since all JPT projects will at their roots be simple java projects.
+The following example is the included simple Java resource locator, which is used for simple Java projects. It is of &quot;lowest&quot; priority, since all JPT projects will at their roots be simple Java projects.
&lt;p&gt;
&lt;pre&gt;
&lt;extension
@@ -147,11 +147,11 @@ The following example is the included simple java resource locator, which is use
</appinfo>
<documentation>
&lt;p&gt;
-The contributed resource locator class must implement &lt;code&gt;org.eclipse.jpt.co9mmon.core.resource.ResourceLocator&lt;/code&gt;.
+The contributed resource locator class must implement &lt;code&gt;org.eclipse.jpt.common.core.resource.ResourceLocator&lt;/code&gt;.
&lt;p&gt;
The enablement variables include:
&lt;ul&gt;
-&lt;li&gt;&quot;project&quot; which gives the current IProject.&lt;/li&gt;
+&lt;li&gt;&quot;project&quot; which gives the current &lt;code&gt;IProject&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
</documentation>
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/IResourcePart.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/IResourcePart.java
deleted file mode 100644
index e5e6a4251a..0000000000
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/IResourcePart.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.core;
-
-import org.eclipse.core.resources.IResource;
-
-
-/**
- * Represents an object that can be described as being part of an {@link IResource}
- *
- * Provisional API: This interface is part of an interim API that is still
- * under development and expected to change significantly before reaching
- * stability. It is available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- *
- * @version 2.1
- * @since 2.1
- */
-public interface IResourcePart
-{
- /**
- * Return the resource of which this object is a part
- */
- IResource getResource();
-}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptCommonCorePlugin.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptCommonCorePlugin.java
index 1dfc996b70..ccbb34d598 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptCommonCorePlugin.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptCommonCorePlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,9 +9,6 @@
******************************************************************************/
package org.eclipse.jpt.common.core;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
@@ -19,10 +16,8 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.common.core.internal.libval.LibraryValidatorManager;
-import org.eclipse.jpt.common.core.internal.resource.ResourceLocatorManager;
import org.eclipse.jpt.common.core.libprov.JptLibraryProviderInstallOperationConfig;
import org.eclipse.jpt.common.core.libval.LibraryValidator;
-import org.eclipse.jpt.common.core.resource.ResourceLocator;
import org.osgi.framework.BundleContext;
public class JptCommonCorePlugin
@@ -82,22 +77,6 @@ public class JptCommonCorePlugin
return Platform.getContentTypeManager().getContentType(contentType);
}
- public static ResourceLocator getResourceLocator(IProject project) {
- return ResourceLocatorManager.instance().getResourceLocator(project);
- }
-
- public static IFile getPlatformFile(IProject project, IPath runtimePath) {
- ResourceLocator resourceLocator = getResourceLocator(project);
- if (resourceLocator == null) {
- return null;
- }
- IPath sourcePath = resourceLocator.getResourcePath(project, runtimePath);
- if (sourcePath == null) {
- return null;
- }
- return project.getWorkspace().getRoot().getFile(sourcePath);
- }
-
public static Iterable<LibraryValidator> getLibraryValidators(
JptLibraryProviderInstallOperationConfig config) {
return LibraryValidatorManager.instance().getLibraryValidators(config);
@@ -108,7 +87,7 @@ public class JptCommonCorePlugin
private static JptCommonCorePlugin INSTANCE;
/**
- * Return the singleton jpt common core plug-in.
+ * Return the singleton Dali common core plug-in.
*/
public static JptCommonCorePlugin instance() {
return INSTANCE;
@@ -118,13 +97,6 @@ public class JptCommonCorePlugin
// ********** public static methods **********
/**
- * Log the specified status.
- */
- public static void log(IStatus status) {
- INSTANCE.getLog().log(status);
- }
-
- /**
* Log the specified message.
*/
public static void log(String msg) {
@@ -145,6 +117,13 @@ public class JptCommonCorePlugin
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, throwable));
}
+ /**
+ * Log the specified status.
+ */
+ public static void log(IStatus status) {
+ INSTANCE.getLog().log(status);
+ }
+
// ********** plug-in implementation **********
@@ -169,6 +148,5 @@ public class JptCommonCorePlugin
super.stop(context);
// nothing yet...
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptResourceModel.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptResourceModel.java
index d43f22cc7c..f183add042 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptResourceModel.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/JptResourceModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.common.core;
+import org.eclipse.core.resources.IFile;
+
/**
* Listeners are notified whenever anything in the JPT resource model changes.
* <p>
@@ -22,14 +24,19 @@ package org.eclipse.jpt.common.core;
* @since 2.2
*/
public interface JptResourceModel {
-
/**
- * Return the resource type of the model. This may potentially change.
- * Return null if it cannot be determined, the content type or version is null.
+ * Return the model's resource type. This can change.
+ * Return <code>null</code> if the resource type cannot be determined,
+ * the content type is <code>null</code> or the version is <code>null</code>.
*/
JptResourceType getResourceType();
/**
+ * Return the model's file.
+ */
+ IFile getFile();
+
+ /**
* Changes to the resource model result in events.
* In particular, the JPA project performs an "update" whenever a resource
* model changes.
@@ -40,5 +47,4 @@ public interface JptResourceModel {
* @see #addResourceModelListener(JptResourceModelListener)
*/
void removeResourceModelListener(JptResourceModelListener listener);
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/ResourceReference.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/ResourceReference.java
new file mode 100644
index 0000000000..8075a9ec6b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/ResourceReference.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core;
+
+import org.eclipse.core.resources.IResource;
+
+/**
+ * An object that has a corresponding {@link IResource}
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ * @see org.eclipse.jpt.common.core.internal.ResourceReferenceAdapterFactory
+ */
+public interface ResourceReference {
+ /**
+ * Return the resource of which this object is a part
+ */
+ IResource getResource();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java
index b962c61115..b9e6e40681 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/JptCommonCoreMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,6 +16,7 @@ import org.eclipse.osgi.util.NLS;
*/
public class JptCommonCoreMessages {
+ public static String DALI_JOB_NAME;
public static String DALI_EVENT_HANDLER_THREAD_NAME;
public static String GENERATION_CREATING_LAUNCH_CONFIG_TASK;
public static String GENERATION_SAVING_LAUNCH_CONFIG_TASK;
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/LibraryProviderPropertyTester.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/LibraryProviderPropertyTester.java
new file mode 100644
index 0000000000..0f3e21f034
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/LibraryProviderPropertyTester.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider;
+
+/**
+ * Property tester for {@link ILibraryProvider}.
+ * See <code>org.eclipse.jpt.common.core/plugin.xml</code>
+ */
+public class LibraryProviderPropertyTester
+ extends PropertyTester
+{
+ public static final String ID = "id"; //$NON-NLS-1$
+ public static final String EXTENDS_ID = "extendsId"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof ILibraryProvider) {
+ return this.test((ILibraryProvider) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(ILibraryProvider libraryProvider, String property, Object expectedValue) {
+ if (property.equals(ID)) {
+ return libraryProvider.getId().equals(expectedValue);
+ }
+ if (property.equals(EXTENDS_ID)) {
+ while (libraryProvider != null) {
+ if (libraryProvider.getId().equals(expectedValue)) {
+ return true;
+ }
+ libraryProvider = libraryProvider.getBaseProvider();
+ }
+ return false;
+ }
+ return false;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/ResourceAdapterFactory.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/ResourceReferenceAdapterFactory.java
index 6514e060f1..f97e5d0dd1 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/ResourceAdapterFactory.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/ResourceReferenceAdapterFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,37 +11,33 @@ package org.eclipse.jpt.common.core.internal;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jpt.common.core.IResourcePart;
+import org.eclipse.jpt.common.core.ResourceReference;
/**
- * Factory to build adapters for converting Eclipse resources to Dali
- * resource parts.
- * <p>
+ * Factory to build adapters for a {@link ResourceReference}:<ul>
+ * <li>{@link IResource}
+ * </ul>
* See <code>org.eclipse.jpt.common.core plugin.xml</code>.
*/
-public class ResourceAdapterFactory
+public class ResourceReferenceAdapterFactory
implements IAdapterFactory
{
- private static final Class<?>[] ADAPTER_LIST = new Class[] { IResourcePart.class };
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { IResource.class };
public Class<?>[] getAdapterList() {
return ADAPTER_LIST;
}
public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
- if (adaptableObject instanceof IResource) {
- return this.getAdapter((IResource) adaptableObject, adapterType);
+ if (adaptableObject instanceof ResourceReference) {
+ return this.getAdapter((ResourceReference) adaptableObject, adapterType);
}
return null;
}
- private Object getAdapter(final IResource resource, Class <?>adapterType) {
- if (adapterType == IResourcePart.class) {
- return new IResourcePart() {
- public IResource getResource() {
- return resource;
- }
- };
+ private Object getAdapter(ResourceReference resourceReference, Class <?>adapterType) {
+ if (adapterType == IResource.class) {
+ return resourceReference.getResource();
}
return null;
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libprov/LibraryProviderPropertyTester.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libprov/LibraryProviderPropertyTester.java
deleted file mode 100644
index e3bb569eed..0000000000
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libprov/LibraryProviderPropertyTester.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.core.internal.libprov;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider;
-
-public class LibraryProviderPropertyTester
- extends PropertyTester {
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if (! (property.equals("id") || property.equals("extendsId")) //$NON-NLS-1$ //$NON-NLS-2$
- || ! (receiver instanceof ILibraryProvider)
- || ! (expectedValue instanceof String)) {
- return false;
- }
-
- ILibraryProvider libraryProvider = (ILibraryProvider) receiver;
-
- if (property.equals("id")) { //$NON-NLS-1$
- return libraryProvider.getId().equals(expectedValue);
- }
- else if (property.equals("extendsId")) { //$NON-NLS-1$
- while (libraryProvider != null) {
- if (libraryProvider.getId().equals(expectedValue)) {
- return true;
- }
- libraryProvider = libraryProvider.getBaseProvider();
- }
- }
-
- return false;
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/operations/AbstractJptFileCreationDataModelProvider.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/operations/AbstractJptFileCreationDataModelProvider.java
index e15e98011a..1106f12032 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/operations/AbstractJptFileCreationDataModelProvider.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/operations/AbstractJptFileCreationDataModelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
@@ -130,7 +131,8 @@ public abstract class AbstractJptFileCreationDataModelProvider
protected IContainer getDefaultContainer() {
IProject project = (IProject) this.model.getProperty(PROJECT);
if (project != null) {
- return JptCommonCorePlugin.getResourceLocator(project).getDefaultResourceLocation(project);
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ return locator.getDefaultResourceLocation();
}
return null;
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java
index 104081ec57..d76318d249 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource;
@@ -17,63 +17,71 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
public class ModuleResourceLocator
- extends SimpleJavaResourceLocator {
-
+ extends SimpleJavaResourceLocator
+{
/**
- * Return the folder representing the "META-INF" runtime location
+ * Return the folder representing the <code>META-INF</code> runtime location.
*/
@Override
public IContainer getDefaultResourceLocation(IProject project) {
- IVirtualComponent component = ComponentCore.createComponent(project);
- return component.getRootFolder().getFolder(META_INF_PATH).getUnderlyingFolder();
+ return this.getRootFolder(project).getFolder(META_INF_PATH).getUnderlyingFolder();
}
@Override
public IPath getResourcePath(IProject project, IPath runtimePath) {
- IVirtualComponent component = ComponentCore.createComponent(project);
- return component.getRootFolder().getFile(runtimePath).getWorkspaceRelativePath();
+ return this.getRootFolder(project).getFile(runtimePath).getWorkspaceRelativePath();
}
@Override
public IPath getRuntimePath(IProject project, IPath resourcePath) {
+ IVirtualFolder rootFolder = this.getRootFolder(project);
IFile file = PlatformTools.getFile(resourcePath);
- IVirtualComponent component = ComponentCore.createComponent(project);
- IVirtualFolder root = component.getRootFolder();
- IVirtualFile vFile = findVirtualFile(root, file);
+ IVirtualFile vFile = this.getVirtualFile(rootFolder, file);
if (vFile != null) {
return vFile.getRuntimePath().makeRelative();
}
- // couldn't find it. try the super-case
+ // couldn't find it - try the super-case
return super.getRuntimePath(project, resourcePath);
}
- private IVirtualFile findVirtualFile(IVirtualFolder vFolder, IFile file) {
+ protected IVirtualFile getVirtualFile(IVirtualFolder vFolder, IFile file) {
try {
- for (IVirtualResource vResource : vFolder.members()) {
- if (vResource.getType() == IVirtualResource.FILE) {
- IVirtualFile vFile = (IVirtualFile) vResource;
- if (file.equals(vFile.getUnderlyingResource())) {
- return vFile;
- }
- }
- else if (vResource.getType() == IVirtualResource.FOLDER) {
- IVirtualFile vFile = findVirtualFile((IVirtualFolder) vResource, file);
- if (vFile != null) {
- return vFile;
- }
- }
- }
+ return this.getVirtualFile_(vFolder, file);
+ } catch (CoreException ex) {
+ JptCommonCorePlugin.log(ex);
+ return null;
}
- catch (CoreException ce) {
- // fall through
- JptCommonCorePlugin.log(ce);
+ }
+
+ protected IVirtualFile getVirtualFile_(IVirtualFolder vFolder, IFile file) throws CoreException {
+ for (IVirtualResource vResource : vFolder.members()) {
+ IVirtualFile vFile = this.getVirtualFile(vResource, file);
+ if (vFile != null) {
+ return vFile;
+ }
}
return null;
}
+
+ protected IVirtualFile getVirtualFile(IVirtualResource vResource, IFile file) throws CoreException {
+ switch (vResource.getType()) {
+ case IVirtualResource.FILE:
+ IVirtualFile vFile = (IVirtualFile) vResource;
+ return file.equals(vFile.getUnderlyingResource()) ? vFile : null;
+ case IVirtualResource.FOLDER:
+ // recurse
+ return this.getVirtualFile_((IVirtualFolder) vResource, file);
+ default:
+ return null;
+ }
+ }
+
+ protected IVirtualFolder getRootFolder(IProject project) {
+ return ComponentCore.createComponent(project).getRootFolder();
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java
index 4dcd3fd221..2e8f070000 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource;
@@ -16,68 +16,74 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
-import org.eclipse.pde.core.project.IBundleProjectDescription;
import org.eclipse.pde.core.project.IBundleProjectService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class PluginResourceLocator
- extends SimpleJavaResourceLocator {
-
+ extends SimpleJavaResourceLocator
+{
@Override
public IContainer getDefaultResourceLocation(IProject project) {
- try {
- IContainer root = getBundleRoot(project);
- return root.getFolder(META_INF_PATH);
- }
- catch (CoreException ce) {
- // fall through
- JptCommonCorePlugin.log(ce);
- }
- return super.getDefaultResourceLocation(project);
+ IContainer bundleRoot = this.getBundleRoot(project);
+ return (bundleRoot != null) ?
+ bundleRoot.getFolder(META_INF_PATH) :
+ super.getDefaultResourceLocation(project);
}
-
+
@Override
public IPath getResourcePath(IProject project, IPath runtimePath) {
- try {
- IContainer root = getBundleRoot(project);
- IPath resourcePath = root.getFullPath().append(runtimePath);
+ IContainer bundleRoot = this.getBundleRoot(project);
+ if (bundleRoot != null) {
+ IPath resourcePath = bundleRoot.getFullPath().append(runtimePath);
if (project.getWorkspace().getRoot().getFile(resourcePath).exists()) {
return resourcePath;
}
}
- catch (CoreException ce) {
- // fall through
- JptCommonCorePlugin.log(ce);
- }
return super.getResourcePath(project, runtimePath);
}
-
+
@Override
public IPath getRuntimePath(IProject project, IPath resourcePath) {
- IFile file = PlatformTools.getFile(resourcePath);
- try {
- IContainer root = getBundleRoot(project);
- if (root.contains(file)) {
- return resourcePath.makeRelativeTo(root.getFullPath());
+ IContainer bundleRoot = this.getBundleRoot(project);
+ if (bundleRoot != null) {
+ IFile file = PlatformTools.getFile(resourcePath);
+ if (bundleRoot.contains(file)) {
+ return resourcePath.makeRelativeTo(bundleRoot.getFullPath());
}
}
- catch (CoreException ce) {
- // fall through
- JptCommonCorePlugin.log(ce);
- }
return super.getRuntimePath(project, resourcePath);
}
-
- protected IContainer getBundleRoot(IProject project)
- throws CoreException {
-
- IBundleProjectService service = getBundleProjectService();
- IBundleProjectDescription description = service.getDescription(project);
- IPath path = description.getBundleRoot();
- return (path == null) ? project : project.getFolder(path);
+
+ protected IContainer getBundleRoot(IProject project) {
+ try {
+ return this.getBundleRoot_(project);
+ } catch (CoreException ex) {
+ // problem creating description on an existing project
+ JptCommonCorePlugin.log(ex);
+ return null;
+ }
}
-
+
+ protected IContainer getBundleRoot_(IProject project) throws CoreException {
+ BundleContext bundleContext = JptCommonCorePlugin.instance().getBundle().getBundleContext();
+ if (bundleContext == null) {
+ return project;
+ }
+ ServiceReference<IBundleProjectService> serviceRef = bundleContext.getServiceReference(IBundleProjectService.class);
+ if (serviceRef == null) {
+ return project;
+ }
+ IBundleProjectService service = bundleContext.getService(serviceRef);
+ if (service == null) {
+ bundleContext.ungetService(serviceRef);
+ return project;
+ }
+ IPath bundleRoot = service.getDescription(project).getBundleRoot();
+ bundleContext.ungetService(serviceRef);
+ return (bundleRoot == null) ? project : project.getFolder(bundleRoot);
+ }
+
protected IBundleProjectService getBundleProjectService() {
BundleContext context = JptCommonCorePlugin.instance().getBundle().getBundleContext();
ServiceReference<IBundleProjectService> reference = context.getServiceReference(IBundleProjectService.class);
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ProjectAdapterFactory.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ProjectAdapterFactory.java
new file mode 100644
index 0000000000..1b0e356297
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ProjectAdapterFactory.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.resource;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
+
+/**
+ * Factory to build Dali adapters for an {@link IProject}:<ul>
+ * <li>{@link org.eclipse.jpt.common.core.resource.ProjectResourceLocator}
+ * </ul>
+ * See <code>org.eclipse.jpt.common.core/plugin.xml</code>.
+ */
+public class ProjectAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ ProjectResourceLocator.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IProject) {
+ return this.getAdapter((IProject) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IProject project, Class<?> adapterType) {
+ if (adapterType == ProjectResourceLocator.class) {
+ return this.getProjectResourceLocator(project);
+ }
+ return null;
+ }
+
+ private ProjectResourceLocator getProjectResourceLocator(IProject project) {
+ return new SimpleProjectResourceLocator(project);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java
index 2050f09006..a409df8da8 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource;
@@ -22,131 +22,195 @@ import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.core.resource.ResourceLocator;
+import org.eclipse.jpt.common.utility.Filter;
+import org.eclipse.jpt.common.utility.internal.Transformer;
+import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
+import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
+import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
import org.eclipse.jst.j2ee.internal.J2EEConstants;
-public class SimpleJavaResourceLocator
- implements ResourceLocator {
-
- protected static IPath META_INF_PATH = new Path(J2EEConstants.META_INF);
-
+public class SimpleJavaResourceLocator
+ implements ResourceLocator
+{
+ protected static final IPath META_INF_PATH = new Path(J2EEConstants.META_INF);
+
/**
- * Simply ensure the container is either:
- * - on the java project classpath
- * or
- * - in the non-java resources, but not in the project output location
+ * Return whether the specified container is either:<ul>
+ * <li>on the corresponding Java project's classpath; or
+ * <li>in the non-Java resources, but not in the project output location
+ * </ul>
*/
- public boolean acceptResourceLocation(IProject project, IContainer container) {
- IJavaProject javaProject = getJavaProject(project);
+ public boolean resourceLocationIsValid(IProject project, IContainer container) {
+ try {
+ return this.resourceLocationIsValid_(project, container);
+ } catch (JavaModelException ex) {
+ JptCommonCorePlugin.log(ex);
+ // happens if the Java project does not exist
+ return false;
+ }
+ }
+
+ protected boolean resourceLocationIsValid_(IProject project, IContainer container) throws JavaModelException {
+ IJavaProject javaProject = this.getJavaProject(project);
if (javaProject.isOnClasspath(container)) {
return true;
}
- try {
- IPath outputLocation = javaProject.getOutputLocation();
- if (container.equals(project) && outputLocation.isPrefixOf(container.getFullPath())) {
- return true;
- }
- for (Object resource : javaProject.getNonJavaResources()) {
- if (resource instanceof IFolder) {
- IFolder folder = (IFolder) resource;
- if ((folder.equals(container) || folder.contains(container))
- && ! outputLocation.isPrefixOf(container.getFullPath())) {
- return true;
- }
+
+ IPath outputPath = javaProject.getOutputLocation();
+ IPath containerPath = container.getFullPath();
+ if (container.equals(project) && outputPath.isPrefixOf(containerPath)) {
+ return true;
+ }
+
+ if (outputPath.isPrefixOf(containerPath)) {
+ return false;
+ }
+ for (Object resource : javaProject.getNonJavaResources()) {
+ if (resource instanceof IFolder) {
+ IFolder folder = (IFolder) resource;
+ if (folder.getFullPath().isPrefixOf(containerPath)) {
+ return true;
}
}
}
- catch (JavaModelException jme) {
- JptCommonCorePlugin.log(jme);
- // only happens if the java project doesn't exist. fall through.
- }
+
return false;
}
-
+
/**
- * Return
- * - the first package fragment root (source folder) META-INF folder if it exists,
- * or
- * - the project rooted META-INF folder if it exists
- * or
- * - the non-existent META-INF folder in the first package fragment root (source folder)
+ * Return the default resource location for the specified project:<ul>
+ * <li>the first package fragment root (source folder) <code>META-INF</code>
+ * folder if it exists; or
+ * <li>the project rooted <code>META-INF</code> folder if it exists; or
+ * <li>the non-existent <code>META-INF</code> folder in the first package
+ * fragment root (source folder)
+ * </ul>
*/
public IContainer getDefaultResourceLocation(IProject project) {
- IJavaProject javaProject = getJavaProject(project);
- IContainer defaultLocation = null;
try {
- for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
- if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
- IContainer rootContainer = (IContainer) root.getUnderlyingResource();
- IFolder metaInfFolder = rootContainer.getFolder(META_INF_PATH);
- if (metaInfFolder.exists()) {
- return metaInfFolder;
- }
- if (defaultLocation == null) {
- // hold on to this in case the META-INF folder can't be found
- defaultLocation = metaInfFolder;
- }
- }
- }
- IFolder metaInfFolder = project.getFolder(META_INF_PATH);
+ return this.getDefaultResourceLocation_(project);
+ } catch (Exception ex) {
+ JptCommonCorePlugin.log(ex);
+ // happens if the Java project does not exist or there is a problem with the
+ // Java resources
+ return null;
+ }
+ }
+
+ protected IContainer getDefaultResourceLocation_(IProject project) throws JavaModelException {
+ IContainer defaultLocation = null;
+ for (IContainer sourceFolder : this.getSourceFolders(project)) {
+ IFolder metaInfFolder = sourceFolder.getFolder(META_INF_PATH);
if (metaInfFolder.exists()) {
return metaInfFolder;
}
+ if (defaultLocation == null) {
+ // save the first one, to use if none found
+ defaultLocation = metaInfFolder;
+ }
}
- catch (JavaModelException jme) {
- // only happens if the java project doesn't exist or there is some problem with the
- // java resources. fall through.
- JptCommonCorePlugin.log(jme);
+ IFolder metaInfFolder = project.getFolder(META_INF_PATH);
+ if (metaInfFolder.exists()) {
+ return metaInfFolder;
}
-
return defaultLocation;
}
-
+
public IPath getResourcePath(IProject project, IPath runtimePath) {
- IJavaProject javaProject = getJavaProject(project);
- IPath firstResourcePath = null;
try {
- for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
- if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
- IContainer rootContainer = (IContainer) root.getUnderlyingResource();
- IPath resourcePath = rootContainer.getFullPath().append(runtimePath);
- if (firstResourcePath == null) {
- firstResourcePath = resourcePath;
- }
- IFile file = project.getWorkspace().getRoot().getFile(resourcePath);
- if (file.exists()) {
- return file.getFullPath();
- }
- }
- }
- }
- catch (JavaModelException jme) {
- JptCommonCorePlugin.log(jme);
+ return this.getResourcePath_(project, runtimePath);
+ } catch (Exception ex) {
+ JptCommonCorePlugin.log(ex);
return null;
}
- return firstResourcePath;
}
-
+
+ protected IPath getResourcePath_(IProject project, IPath runtimePath) throws JavaModelException {
+ IPath defaultResourcePath = null;
+ for (IContainer sourceFolder : this.getSourceFolders(project)) {
+ IPath resourcePath = sourceFolder.getFullPath().append(runtimePath);
+ IFile file = project.getWorkspace().getRoot().getFile(resourcePath);
+ if (file.exists()) {
+ return file.getFullPath();
+ }
+ if (defaultResourcePath == null) {
+ // save the first one, to use if none found
+ defaultResourcePath = resourcePath;
+ }
+ }
+ return defaultResourcePath;
+ }
+
public IPath getRuntimePath(IProject project, IPath resourcePath) {
- IJavaProject javaProject = getJavaProject(project);
- IFile file = PlatformTools.getFile(resourcePath);
try {
- for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
- if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
- IContainer rootContainer = (IContainer) root.getUnderlyingResource();
- if (rootContainer.contains(file)) {
- return resourcePath.makeRelativeTo(rootContainer.getFullPath());
- }
- }
- }
+ return this.getRuntimePath_(project, resourcePath);
+ } catch (Exception ex) {
+ JptCommonCorePlugin.log(ex);
+ return resourcePath.makeRelativeTo(project.getFullPath());
}
- catch (JavaModelException jme) {
- // fall through
- JptCommonCorePlugin.log(jme);
+ }
+
+ protected IPath getRuntimePath_(IProject project, IPath resourcePath) throws JavaModelException {
+ IFile file = PlatformTools.getFile(resourcePath);
+ for (IContainer sourceFolder : this.getSourceFolders(project)) {
+ if (sourceFolder.contains(file)) {
+ return resourcePath.makeRelativeTo(sourceFolder.getFullPath());
+ }
}
return resourcePath.makeRelativeTo(project.getFullPath());
}
-
- private IJavaProject getJavaProject(IProject project) {
+
+ protected Iterable<IContainer> getSourceFolders(IProject project) throws JavaModelException {
+ return new TransformationIterable<IPackageFragmentRoot, IContainer>(this.getSourcePackageFragmentRoots(project), ROOT_CONTAINER_TRANSFORMER);
+ }
+
+ protected static final Transformer<IPackageFragmentRoot, IContainer> ROOT_CONTAINER_TRANSFORMER = new RootContainerTransformer();
+
+ protected static class RootContainerTransformer
+ implements Transformer<IPackageFragmentRoot, IContainer>
+ {
+ public IContainer transform(IPackageFragmentRoot pfr) {
+ try {
+ return this.transform_(pfr);
+ } catch (JavaModelException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ protected IContainer transform_(IPackageFragmentRoot pfr) throws JavaModelException {
+ return (IContainer) pfr.getUnderlyingResource();
+ }
+ }
+
+ protected Iterable<IPackageFragmentRoot> getSourcePackageFragmentRoots(IProject project) throws JavaModelException {
+ return new FilteringIterable<IPackageFragmentRoot>(this.getPackageFragmentRoots(project), SOURCE_ROOT_FILTER);
+ }
+
+ protected static final Filter<IPackageFragmentRoot> SOURCE_ROOT_FILTER = new SourceRootFilter();
+
+ protected static class SourceRootFilter
+ implements Filter<IPackageFragmentRoot>
+ {
+ public boolean accept(IPackageFragmentRoot pfr) {
+ try {
+ return this.accept_(pfr);
+ } catch (JavaModelException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ protected boolean accept_(IPackageFragmentRoot pfr) throws JavaModelException {
+ return pfr.getKind() == IPackageFragmentRoot.K_SOURCE;
+ }
+ }
+
+ protected Iterable<IPackageFragmentRoot> getPackageFragmentRoots(IProject project) throws JavaModelException {
+ return new ArrayIterable<IPackageFragmentRoot>(this.getPackageFragmentRootsArray(project));
+ }
+
+ protected IPackageFragmentRoot[] getPackageFragmentRootsArray(IProject project) throws JavaModelException {
+ return this.getJavaProject(project).getPackageFragmentRoots();
+ }
+
+ protected IJavaProject getJavaProject(IProject project) {
return JavaCore.create(project);
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleProjectResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleProjectResourceLocator.java
new file mode 100644
index 0000000000..71b1d522ef
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleProjectResourceLocator.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.resource;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
+import org.eclipse.jpt.common.core.resource.ResourceLocator;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * @see org.eclipse.jpt.common.core.internal.resource.ProjectAdapterFactory
+ * @see ResourceLocatorManager
+ */
+public class SimpleProjectResourceLocator
+ implements ProjectResourceLocator
+{
+ protected final IProject project;
+
+
+ public SimpleProjectResourceLocator(IProject project) {
+ super();
+ this.project = project;
+ }
+
+ public boolean resourceLocationIsValid(IContainer container) {
+ ResourceLocator resourceLocator = this.getResourceLocator();
+ return (resourceLocator != null) && resourceLocator.resourceLocationIsValid(this.project, container);
+ }
+
+ public IContainer getDefaultResourceLocation() {
+ ResourceLocator resourceLocator = this.getResourceLocator();
+ return (resourceLocator == null) ? null : resourceLocator.getDefaultResourceLocation(this.project);
+ }
+
+ public IPath getResourcePath(IPath runtimePath) {
+ ResourceLocator resourceLocator = this.getResourceLocator();
+ return (resourceLocator == null) ? null : resourceLocator.getResourcePath(this.project, runtimePath);
+ }
+
+ public IPath getRuntimePath(IPath resourcePath) {
+ ResourceLocator resourceLocator = this.getResourceLocator();
+ return (resourceLocator == null) ? null : resourceLocator.getRuntimePath(this.project, resourcePath);
+ }
+
+ public IFile getPlatformFile(IPath runtimePath) {
+ IPath sourcePath = this.getResourcePath(runtimePath);
+ return (sourcePath == null) ? null : this.project.getWorkspace().getRoot().getFile(sourcePath);
+ }
+
+ protected ResourceLocator getResourceLocator() {
+ return ResourceLocatorManager.instance().getResourceLocator(this.project);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.project);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java
index a7fffe7e8c..7d1cb6bfb4 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource;
@@ -14,41 +14,39 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jst.j2ee.internal.J2EEConstants;
-import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
public class WebModuleResourceLocator
- extends ModuleResourceLocator{
-
- protected static IPath WEB_INF_CLASSES_PATH = new Path(J2EEConstants.WEB_INF_CLASSES);
-
+ extends ModuleResourceLocator
+{
+ protected static final IPath WEB_INF_CLASSES_PATH = new Path(J2EEConstants.WEB_INF_CLASSES);
+ protected static final IPath WEB_META_INF_PATH = WEB_INF_CLASSES_PATH.append(META_INF_PATH);
+
/**
- * Return the folder representing the "WEB-INF/classes/META-INF" location
+ * Return the folder representing the <code>WEB-INF/classes/META-INF</code>
+ * location.
*/
@Override
public IContainer getDefaultResourceLocation(IProject project) {
- IVirtualComponent component = ComponentCore.createComponent(project);
- return component.getRootFolder().getFolder(WEB_INF_CLASSES_PATH.append(META_INF_PATH)).getUnderlyingFolder();
+ return this.getRootFolder(project).getFolder(WEB_META_INF_PATH).getUnderlyingFolder();
}
-
+
/**
- * Return the full resource path representing the given runtime location appended
- * to the "WEB-INF/classes" location
+ * Return the full resource path representing the specified runtime location
+ * appended to the <code>WEB-INF/classes</code> location.
*/
@Override
public IPath getResourcePath(IProject project, IPath runtimePath) {
return super.getResourcePath(project, WEB_INF_CLASSES_PATH.append(runtimePath));
}
-
+
/**
*
*/
@Override
public IPath getRuntimePath(IProject project, IPath resourcePath) {
IPath runtimePath = super.getRuntimePath(project, resourcePath);
- if (WEB_INF_CLASSES_PATH.isPrefixOf(runtimePath)) {
- return runtimePath.makeRelativeTo(WEB_INF_CLASSES_PATH);
- }
- return runtimePath;
+ return WEB_INF_CLASSES_PATH.isPrefixOf(runtimePath) ?
+ runtimePath.makeRelativeTo(WEB_INF_CLASSES_PATH) :
+ runtimePath;
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java
index be988599b1..d8cb8f1c1e 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java
@@ -36,7 +36,7 @@ abstract class BinaryMember
private boolean transient_; // 'transient' is a reserved word
private boolean public_; // 'public' is a reserved word
private boolean static_; // 'static' is a reserved word
- boolean protected_; // 'protected' is a reserved word
+ private boolean protected_; // 'protected' is a reserved word
// ********** construction/initialization **********
@@ -273,7 +273,7 @@ abstract class BinaryMember
}
public boolean isPublicOrProtected() {
- return isPublic() || isProtected();
+ return this.isPublic() || this.isProtected();
}
// ********** IMember adapter **********
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java
index c1bc7414c6..33c4f9de52 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java
@@ -193,7 +193,7 @@ final class BinaryType
// ***** public/protected no-arg constructor *****
public boolean hasPublicOrProtectedNoArgConstructor() {
- Iterable<JavaResourceMethod> constructors = getConstructors();
+ Iterable<JavaResourceMethod> constructors = this.getConstructors();
if (CollectionTools.size(constructors) == 0) {
return true;
}
@@ -207,7 +207,7 @@ final class BinaryType
}
public boolean hasPublicNoArgConstructor() {
- Iterable<JavaResourceMethod> constructors = getConstructors();
+ Iterable<JavaResourceMethod> constructors = this.getConstructors();
if (CollectionTools.size(constructors) == 0) {
return true;
}
@@ -220,10 +220,10 @@ final class BinaryType
}
protected Iterable<JavaResourceMethod> getConstructors() {
- return new FilteringIterable<JavaResourceMethod>(getMethods()) {
+ return new FilteringIterable<JavaResourceMethod>(this.getMethods()) {
@Override
- protected boolean accept(JavaResourceMethod o) {
- return o.isConstructor();
+ protected boolean accept(JavaResourceMethod method) {
+ return method.isConstructor();
}
};
}
@@ -260,7 +260,7 @@ final class BinaryType
// Both requirements are validated by the compiler so they are excluded here
public boolean hasEqualsMethod() {
for (JavaResourceMethod method : this.getMethods()) {
- if (StringTools.stringsAreEqual(method.getMethodName(), "equals")
+ if (StringTools.stringsAreEqual(method.getMethodName(), "equals") //$NON-NLS-1$
&& method.getParametersSize() == 1
&& StringTools.stringsAreEqual(method.getParameterTypeName(0), Object.class.getName())) {
return true;
@@ -275,7 +275,7 @@ final class BinaryType
// Both requirements are validated by the compiler so they are excluded here
public boolean hasHashCodeMethod() {
for (JavaResourceMethod method : this.getMethods()) {
- if (StringTools.stringsAreEqual(method.getMethodName(), "hashCode")
+ if (StringTools.stringsAreEqual(method.getMethodName(), "hashCode") //$NON-NLS-1$
&& method.getParametersSize() == 0) {
return true;
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java
index 57c43e85dd..bf69665e48 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -19,7 +19,7 @@ import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.ListenerList;
/**
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
index 7ecfef3165..694c3af5ab 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
@@ -195,7 +195,6 @@ abstract class SourceMember<M extends Member>
}
public boolean isPublicOrProtected() {
- return isPublic() || isProtected();
+ return this.isPublic() || this.isProtected();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java
index 3ea302a474..0ee2aae4a1 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2010, 2012 Red Hat, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource.java.source;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -20,7 +19,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
/**
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
index c2769e6e5d..f28e79420e 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
@@ -281,7 +281,7 @@ final class SourceType
}
public boolean hasPublicNoArgConstructor() {
- Iterable<JavaResourceMethod> constructors = getConstructors();
+ Iterable<JavaResourceMethod> constructors = this.getConstructors();
if (CollectionTools.size(constructors) == 0) {
return true;
}
@@ -294,10 +294,10 @@ final class SourceType
}
protected Iterable<JavaResourceMethod> getConstructors() {
- return new FilteringIterable<JavaResourceMethod>(getMethods()) {
+ return new FilteringIterable<JavaResourceMethod>(this.getMethods()) {
@Override
- protected boolean accept(JavaResourceMethod o) {
- return o.isConstructor();
+ protected boolean accept(JavaResourceMethod method) {
+ return method.isConstructor();
}
};
}
@@ -578,7 +578,7 @@ final class SourceType
// Both requirements are validated by the compiler so they are excluded here
public boolean hasEqualsMethod() {
for (JavaResourceMethod method : this.getMethods()) {
- if (StringTools.stringsAreEqual(method.getMethodName(), "equals")
+ if (StringTools.stringsAreEqual(method.getMethodName(), "equals") //$NON-NLS-1$
&& method.getParametersSize() == 1
&& StringTools.stringsAreEqual(method.getParameterTypeName(0), Object.class.getName())) {
return true;
@@ -593,7 +593,7 @@ final class SourceType
// Both requirements are validated by the compiler so they are excluded here
public boolean hasHashCodeMethod() {
for (JavaResourceMethod method : this.getMethods()) {
- if (StringTools.stringsAreEqual(method.getMethodName(), "hashCode")
+ if (StringTools.stringsAreEqual(method.getMethodName(), "hashCode") //$NON-NLS-1$
&& method.getParametersSize() == 0) {
return true;
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java
index fc1f76eb08..bf5333f91d 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,7 +21,7 @@ import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/CallbackJobSynchronizer.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/CallbackJobSynchronizer.java
index 38a4cda80f..947d027e5e 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/CallbackJobSynchronizer.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/CallbackJobSynchronizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,6 +12,7 @@ package org.eclipse.jpt.common.core.internal.utility;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
import org.eclipse.jpt.common.utility.internal.ListenerList;
import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
@@ -148,7 +149,5 @@ public class CallbackJobSynchronizer
this.scheduled = false;
super.stop();
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobSynchronizer.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobSynchronizer.java
index 2ab0283e5a..768e8e01e6 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobSynchronizer.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobSynchronizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
@@ -104,7 +105,9 @@ public class JobSynchronizer
* This is the job that gets scheduled by the job synchronizer.
* When the job is run it executes the client-supplied job command.
*/
- static class SynchronizationJob extends Job {
+ static class SynchronizationJob
+ extends Job
+ {
/**
* The client-supplied job command that executes every time the job
* runs.
@@ -192,7 +195,5 @@ public class JobSynchronizer
public boolean shouldSchedule() {
return this.shouldSchedule;
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java
index 44183a9b68..462ccd18c3 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/PlatformTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -27,7 +27,15 @@ import org.eclipse.jpt.common.core.JptCommonCorePlugin;
* A collection of utilities for dealing with the Eclipse platform API.
*/
public class PlatformTools {
-
+ /**
+ * Add some Generic Goodness to the method signature.
+ * @see org.eclipse.core.runtime.IAdapterManager#getAdapter(Object, Class)
+ */
+ @SuppressWarnings("unchecked")
+ public static <A> A getAdapter(Object o, Class<A> adapterType) {
+ return (A) Platform.getAdapterManager().getAdapter(o, adapterType);
+ }
+
/**
* Return the {@link IContainer} with the workspace relative "full" path
*/
@@ -66,7 +74,7 @@ public class PlatformTools {
fileContents = file.getContents();
} catch (CoreException ex) {
// seems like we can ignore any exception that might occur here;
- // e.g. we get a FNFE if the workspace is out of synch with the O/S file system
+ // e.g. we get a FNFE if the workspace is out of sync with the O/S file system
// JptCorePlugin.log(ex);
// look for content type based on the file name only(?)
@@ -104,5 +112,4 @@ public class PlatformTools {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/SimpleSchedulingRule.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/SimpleSchedulingRule.java
index 04d8a24d15..ca5915ac96 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/SimpleSchedulingRule.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/SimpleSchedulingRule.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.core.internal.utility;
+import java.io.Serializable;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -16,8 +17,10 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
* A job scheduling rule that conflicts only with itself.
*/
public final class SimpleSchedulingRule
- implements ISchedulingRule
+ implements ISchedulingRule, Serializable
{
+ private static final long serialVersionUID = 1L;
+
public SimpleSchedulingRule() {
super();
}
@@ -34,5 +37,4 @@ public final class SimpleSchedulingRule
public String toString() {
return StringTools.buildToStringFor(this);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/AbstractSingleUseQueueingJobCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/AbstractSingleUseQueueingJobCommandExecutor.java
new file mode 100644
index 0000000000..ef298557aa
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/AbstractSingleUseQueueingJobCommandExecutor.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.core.utility.command.CombinedCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.command.AbstractSingleUseQueueingCommandExecutor;
+
+/**
+ * This job command executor wraps and extends an
+ * {@link AbstractSingleUseQueueingCommandExecutor},
+ * adding support for executing {@link JobCommand}s.
+ * <p>
+ * <strong>NB:</strong> This executor <em>ignores</em> any
+ * {@link ISchedulingRule scheduling rules}.
+ */
+public abstract class AbstractSingleUseQueueingJobCommandExecutor<E1 extends AbstractSingleUseQueueingCommandExecutor<E2>, E2 extends StatefulCommandExecutor>
+ implements CombinedCommandExecutor, StatefulCommandExecutor
+{
+ /**
+ * Since the {@link JobCommand}s are simply converted into {@link Command}s,
+ * we can delegate to an {@link AbstractSingleUseQueueingCommandExecutor}.
+ */
+ protected final E1 commandExecutor;
+
+
+ protected AbstractSingleUseQueueingJobCommandExecutor(E1 commandExecutor) {
+ super();
+ this.commandExecutor = commandExecutor;
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#start()
+ */
+ public void start() {
+ this.commandExecutor.start();
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
+ */
+ public void execute(Command command) {
+ this.commandExecutor.execute(command);
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
+ */
+ public void execute(JobCommand command) {
+ this.commandExecutor.execute(new JobCommandCommandAdapter(command));
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
+ */
+ public void execute(JobCommand command, String jobName) {
+ // ignore 'jobName'
+ this.commandExecutor.execute(new JobCommandCommandAdapter(command));
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#execute(Command)
+ */
+ public void execute(JobCommand command, String jobName, ISchedulingRule rule) {
+ // ignore 'jobName' and 'rule'
+ this.commandExecutor.execute(new JobCommandCommandAdapter(command));
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#suspend()
+ */
+ public void suspend() {
+ this.commandExecutor.suspend();
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#resume()
+ */
+ public void resume() {
+ this.commandExecutor.resume();
+ }
+
+ /**
+ * @see AbstractSingleUseQueueingCommandExecutor#stop()
+ */
+ public void stop() throws InterruptedException {
+ this.commandExecutor.stop();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/CommandJobCommandAdapter.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/CommandJobCommandAdapter.java
new file mode 100644
index 0000000000..97c52316e3
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/CommandJobCommandAdapter.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Adapt a {@link Command} to the {@link JobCommand} interface.
+ * Necessarily, the progress monitor is ignored and a status of
+ * OK is returned.
+ */
+public class CommandJobCommandAdapter
+ implements JobCommand
+{
+ private final Command command;
+
+
+ public CommandJobCommandAdapter(Command command) {
+ super();
+ if (command == null) {
+ throw new NullPointerException();
+ }
+ this.command = command;
+ }
+
+ public IStatus execute(IProgressMonitor monitor) {
+ this.command.execute();
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.command);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandCommandAdapter.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandCommandAdapter.java
new file mode 100644
index 0000000000..ac69a5b03b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandCommandAdapter.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Adapt a {@link JobCommand} to the {@link Command} interface.
+ * Necessarily passing in a <em>null</em> progress monitor
+ * and ignoring the returned status.
+ */
+public class JobCommandCommandAdapter
+ implements Command
+{
+ private final JobCommand jobCommand;
+
+
+ public JobCommandCommandAdapter(JobCommand jobCommand) {
+ super();
+ if (jobCommand == null) {
+ throw new NullPointerException();
+ }
+ this.jobCommand = jobCommand;
+ }
+
+ public void execute() {
+ this.jobCommand.execute(new NullProgressMonitor());
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.jobCommand);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandJob.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandJob.java
new file mode 100644
index 0000000000..70318e1df2
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/JobCommandJob.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+
+/**
+ * A job that executes a {@link JobCommand job command} or
+ * {@link Command command}.
+ */
+public class JobCommandJob
+ extends Job
+{
+ private final JobCommand command;
+
+
+ public JobCommandJob(String name, Command command) {
+ this(name, new CommandJobCommandAdapter(command));
+ }
+
+ public JobCommandJob(String name, JobCommand command) {
+ super(name);
+ if (command == null) {
+ throw new NullPointerException();
+ }
+ this.command = command;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return this.command.execute(monitor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java
new file mode 100644
index 0000000000..1e49f6b18f
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jpt.common.core.utility.command.NotifyingRepeatingJobCommand;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.core.utility.command.JobCommandExecutor;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.ListenerList;
+
+/**
+ * @see org.eclipse.jpt.common.utility.internal.command.NotifyingRepeatingCommandWrapper
+ */
+public class NotifyingRepeatingJobCommandWrapper
+ extends RepeatingJobCommandWrapper
+ implements NotifyingRepeatingJobCommand
+{
+ private final ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
+
+
+ // ********** construction **********
+
+ /**
+ * Construct a notifying repeating command wrapper that executes the
+ * specified command. Any exceptions thrown by the command or listener
+ * will be handled by the specified exception handler.
+ */
+ public NotifyingRepeatingJobCommandWrapper(JobCommand command, ExceptionHandler exceptionHandler) {
+ super(command, exceptionHandler);
+ }
+
+ /**
+ * Construct a notifying repeating command wrapper that executes the
+ * specified command and uses the specified command executor to execute the
+ * wrapped command whenever it is not already executing.
+ * Any exceptions thrown by the command or listener will be handled by the
+ * specified exception handler.
+ */
+ public NotifyingRepeatingJobCommandWrapper(JobCommand command, JobCommandExecutor startCommandExecutor, ExceptionHandler exceptionHandler) {
+ super(command, startCommandExecutor, exceptionHandler);
+ }
+
+
+ // ********** listeners **********
+
+ public void addListener(Listener listener) {
+ this.listenerList.add(listener);
+ }
+
+ public void removeListener(Listener listener) {
+ this.listenerList.remove(listener);
+ }
+
+
+ // ********** override **********
+
+ @Override
+ /* private protected */ IStatus executeCommand(IProgressMonitor monitor) {
+ IStatus status = super.executeCommand(monitor);
+ if (this.state.isQuiesced()) {
+ // hmmm - we will notify listeners even when we are "stopped"; that seems OK...
+ this.executionQuiesced(monitor);
+ }
+ return status;
+ }
+
+ /**
+ * Notify our listeners.
+ */
+ private void executionQuiesced(IProgressMonitor monitor) {
+ for (Listener listener : this.listenerList.getListeners()) {
+ this.notifyListener(listener, monitor);
+ }
+ }
+
+ private void notifyListener(Listener listener, IProgressMonitor monitor) {
+ try {
+ listener.executionQuiesced(this, monitor);
+ } catch (OperationCanceledException ex) {
+ throw ex; // seems reasonable...
+ } catch (Throwable ex) {
+ this.exceptionHandler.handleException(ex);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java
new file mode 100644
index 0000000000..8fee7f6366
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/RepeatingJobCommandWrapper.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.core.utility.command.JobCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.RepeatingJobCommand;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.command.RepeatingCommandState;
+
+/**
+ * Wrap a repeating {@link JobCommand}.
+ * <p>
+ * <strong>NB:</strong> The {@link IProgressMonitor progress monitor} passed to
+ * the job command wrapper is <em>ignored</em>. The {@link IProgressMonitor
+ * progress monitor} passed to the <em>wrapped</em> job command is determined by
+ * the {@link #startCommandExecutor start command executor}. That same
+ * {@link IProgressMonitor progress monitor} is passed to the <em>wrapped</em>
+ * job command for every execution during an execution "cycle". It is
+ * <em>not</em> reset with each execution; so several
+ * executions may take place before a new progress monitor is passed to the
+ * command.
+ * @see org.eclipse.jpt.common.utility.internal.command.RepeatingCommandWrapper
+ */
+public class RepeatingJobCommandWrapper
+ implements RepeatingJobCommand
+{
+ /**
+ * The client-supplied command that performs the execution. It may
+ * trigger further calls to {@link #execute(IProgressMonitor)}
+ * (i.e. the <em>wrapped</em>
+ * command's execution may recurse back to the client code that executes the
+ * <em>wrapper</em> command).
+ */
+ /* CU private */ final JobCommand command;
+
+ /**
+ * The command executed whenever the wrapped {@link #command} must be
+ * executed and it is not already executing. If the wrapped {@link #command}
+ * is already executing, it will simply be re-executed directly (once it has
+ * completed its current execution), as opposed to calling the start
+ * command.
+ */
+ private final JobCommand startCommand;
+
+ /**
+ * The client-supplied command executor that provides the context for the
+ * {@link #startCommand start command}. By default, the start command is
+ * executed directly; but this executor provides a hook for executing the
+ * {@link #startCommand start command} asynchronously; after which,
+ * subsequent overlapping executions are executed synchronously.
+ */
+ private final JobCommandExecutor startCommandExecutor;
+
+ /**
+ * This handles the exceptions thrown by the <em>wrapped</em> command.
+ */
+ final ExceptionHandler exceptionHandler;
+
+ /**
+ * The command wrapper's state.
+ */
+ final RepeatingCommandState state;
+
+
+ // ********** construction **********
+
+ /**
+ * Construct a repeating command wrapper that executes the specified
+ * command. Any exceptions thrown by the command will be handled by the
+ * specified exception handler.
+ */
+ public RepeatingJobCommandWrapper(JobCommand command, ExceptionHandler exceptionHandler) {
+ this(command, JobCommandExecutor.Default.instance(), exceptionHandler);
+ }
+
+ /**
+ * Construct a repeating command wrapper that executes the specified
+ * command and uses the specified command executor to execute the wrapped
+ * command whenever it is not already executing.
+ * Any exceptions thrown by the command will be handled by the
+ * specified exception handler.
+ */
+ public RepeatingJobCommandWrapper(JobCommand command, JobCommandExecutor startCommandExecutor, ExceptionHandler exceptionHandler) {
+ super();
+ if ((command == null) || (startCommandExecutor == null) || (exceptionHandler == null)) {
+ throw new NullPointerException();
+ }
+ this.command = command;
+ this.startCommandExecutor = startCommandExecutor;
+ this.startCommand = this.buildStartJobCommand();
+ this.exceptionHandler = exceptionHandler;
+ this.state = this.buildState();
+ }
+
+ private JobCommand buildStartJobCommand() {
+ return new StartJobCommand();
+ }
+
+ private RepeatingCommandState buildState() {
+ return new RepeatingCommandState();
+ }
+
+
+ // ********** RepeatingJobCommand implementation **********
+
+ public void start() {
+ this.state.start();
+ }
+
+ /**
+ * It is possible to come back here if the wrapped command recurses
+ * to the client and triggers another execution.
+ */
+ // pretty sure no need for this method to be 'synchronized'
+ public IStatus execute(IProgressMonitor monitor) {
+ if (this.state.isReadyToStartExecutionCycle()) {
+ this.startCommandExecutor.execute(this.startCommand);
+ }
+ return Status.OK_STATUS;
+ }
+
+ public void stop() throws InterruptedException {
+ this.state.stop();
+ }
+
+ /**
+ * The start command.
+ * @see #startCommandExecutor
+ */
+ /* CU private */ class StartJobCommand
+ implements JobCommand
+ {
+ public IStatus execute(IProgressMonitor monitor) {
+ return RepeatingJobCommandWrapper.this.execute_(monitor);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, RepeatingJobCommandWrapper.this.command);
+ }
+ }
+
+ /**
+ * This method will be called only once per execution cycle.
+ * Any further calls to {@link #execute(IProgressMonitor)} will
+ * simply set the {@link #state} to "repeat",
+ * causing the command to execute again.
+ */
+ /* CU private */ IStatus execute_(IProgressMonitor monitor) {
+ if (this.state.wasStoppedBeforeFirstExecutionCouldStart()) {
+ return Status.OK_STATUS;
+ }
+
+ do {
+ IStatus status = this.executeCommand(monitor);
+ if (status.getSeverity() == IStatus.CANCEL) {
+ return status; // seems reasonable...
+ }
+ } while (this.state.isRepeat());
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Execute the client-supplied command. Do not allow any unhandled
+ * exceptions to kill the wrapper. Pass to the exception handler.
+ * @see NotifyingRepeatingJobCommandWrapper
+ */
+ /* private protected */ IStatus executeCommand(IProgressMonitor monitor) {
+ try {
+ return this.command.execute(monitor);
+ } catch (OperationCanceledException ex) {
+ return Status.CANCEL_STATUS; // seems reasonable...
+ } catch (Throwable ex) {
+ this.exceptionHandler.handleException(ex);
+ return Status.OK_STATUS;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.command);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SimpleJobCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SimpleJobCommandExecutor.java
new file mode 100644
index 0000000000..96c858b752
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SimpleJobCommandExecutor.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jpt.common.core.utility.command.CombinedExtendedCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
+
+/**
+ * A command executor that schedules a {@link org.eclipse.core.runtime.jobs.Job
+ * job} to [asynchronously] execute each {@link JobCommand job command} or
+ * {@link Command command}.
+ * Synchronous command executions are coordinated with the job via a
+ * {@link LocalJobChangeListener job listener}.
+ */
+public class SimpleJobCommandExecutor
+ implements CombinedExtendedCommandExecutor
+{
+ private final String defaultJobName;
+ private final ISchedulingRule defaultJobSchedulingRule;
+
+
+ /**
+ * Construct a job command executor with no default job name and no
+ * default scheduling rule.
+ */
+ public SimpleJobCommandExecutor() {
+ this(null);
+ }
+
+ /**
+ * Construct a job command executor with the specified default job name and
+ * no default scheduling rule.
+ */
+ public SimpleJobCommandExecutor(String defaultJobName) {
+ this(defaultJobName, null);
+ }
+
+ /**
+ * Construct a job command executor with the specified default job name and
+ * default scheduling rule.
+ */
+ public SimpleJobCommandExecutor(String defaultJobName, ISchedulingRule defaultJobSchedulingRule) {
+ super();
+ this.defaultJobName = defaultJobName;
+ this.defaultJobSchedulingRule = defaultJobSchedulingRule;
+ }
+
+ public void execute(Command command) {
+ this.execute(new CommandJobCommandAdapter(command));
+ }
+
+ public void waitToExecute(Command command) throws InterruptedException {
+ this.waitToExecute(new CommandJobCommandAdapter(command));
+ }
+
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ return this.waitToExecute(new CommandJobCommandAdapter(command), timeout);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the default name and scheduling rule.
+ */
+ public void execute(JobCommand command) {
+ this.execute(command, null);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the default scheduling rule.
+ */
+ public void execute(JobCommand command, String jobName) {
+ this.execute(command, jobName, this.defaultJobSchedulingRule);
+ }
+
+ public void execute(JobCommand command, String jobName, ISchedulingRule rule) {
+ this.execute_(command, this.buildJobName(jobName, command), rule);
+ }
+
+ /**
+ * Pre-condition: the job name must not be <code>null</code>.
+ */
+ private void execute_(JobCommand command, String jobName, ISchedulingRule rule) {
+ Job job = new JobCommandJob(jobName, command);
+ job.setRule(rule);
+ job.schedule();
+ }
+
+ /**
+ * Assign the resulting {@link Job} the default name and scheduling rule.
+ */
+ public void waitToExecute(JobCommand command) throws InterruptedException {
+ this.waitToExecute(command, null);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the default name and scheduling rule.
+ */
+ public boolean waitToExecute(JobCommand command, long timeout) throws InterruptedException {
+ return this.waitToExecute(command, null, timeout);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the specified name and the default
+ * scheduling rule.
+ */
+ public void waitToExecute(JobCommand command, String jobName) throws InterruptedException {
+ this.waitToExecute(command, jobName, this.defaultJobSchedulingRule);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the specified name and the default
+ * scheduling rule.
+ */
+ public boolean waitToExecute(JobCommand command, String jobName, long timeout) throws InterruptedException {
+ return this.waitToExecute(command, jobName, this.defaultJobSchedulingRule, timeout);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the specified name and scheduling rule.
+ */
+ public void waitToExecute(JobCommand command, String jobName, ISchedulingRule rule) throws InterruptedException {
+ this.waitToExecute_(command, this.buildJobName(jobName, command), rule, 0);
+ }
+
+ /**
+ * Assign the resulting {@link Job} the specified name and scheduling rule.
+ */
+ public boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule rule, long timeout) throws InterruptedException {
+ return this.waitToExecute_(command, this.buildJobName(jobName, command), rule, timeout);
+ }
+
+ /**
+ * Pre-condition: the job name must not be <code>null</code>.
+ * <p>
+ * Schedule a job that will notify us when it is finished.
+ * The current thread will suspend until the job is finished.
+ */
+ private boolean waitToExecute_(JobCommand command, String jobName, ISchedulingRule rule, long timeout) throws InterruptedException {
+ if ((timeout == 0L) && Job.getJobManager().isSuspended()) {
+ // the job manager is suspended during workbench start-up;
+ // so this method will lock up accordingly, which is not a Good Thing
+ // if it is called from the Eclipse Main thread during start-up
+ // (i.e. deadlock!)
+ return false;
+ }
+
+ Job job = new JobCommandJob(jobName, command);
+ LocalJobChangeListener listener = new LocalJobChangeListener();
+ job.addJobChangeListener(listener);
+ job.setRule(rule);
+ job.schedule();
+ try {
+ return listener.waitUntilDone(timeout);
+ } finally {
+ job.removeJobChangeListener(listener);
+ }
+ }
+
+ private String buildJobName(String jobName, Object command) {
+ if (jobName != null) {
+ return jobName;
+ }
+ if (this.defaultJobName != null) {
+ return this.defaultJobName;
+ }
+ return StringTools.buildToStringClassName(command.getClass());
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+
+ // ********** job listener **********
+
+ /**
+ * This job listener notifies any interested threads when the
+ * {@link Job job} is done.
+ */
+ /* CU private */ class LocalJobChangeListener
+ extends JobChangeAdapter
+ {
+ private final SynchronizedBoolean done = new SynchronizedBoolean(false);
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ super.done(event);
+ this.done.setTrue();
+ }
+
+ boolean waitUntilDone(long timeout) throws InterruptedException {
+ return this.done.waitUntilTrue(timeout);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingExtendedJobCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingExtendedJobCommandExecutor.java
new file mode 100644
index 0000000000..5957e3e4b4
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingExtendedJobCommandExecutor.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.core.utility.command.CombinedExtendedCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.SingleUseQueueingExtendedCommandExecutor;
+
+/**
+ * This command executor wraps and extends a {@link SingleUseQueueingExtendedCommandExecutor},
+ * adding support for executing {@link JobCommand}s.
+ */
+public class SingleUseQueueingExtendedJobCommandExecutor
+ extends AbstractSingleUseQueueingJobCommandExecutor<SingleUseQueueingExtendedCommandExecutor, StatefulExtendedCommandExecutor>
+ implements CombinedExtendedCommandExecutor, StatefulExtendedCommandExecutor
+{
+ public SingleUseQueueingExtendedJobCommandExecutor() {
+ this(new SingleUseQueueingExtendedCommandExecutor());
+ }
+
+ public SingleUseQueueingExtendedJobCommandExecutor(ExtendedCommandExecutor commandExecutor) {
+ this(new SingleUseQueueingExtendedCommandExecutor(commandExecutor));
+ }
+
+ public SingleUseQueueingExtendedJobCommandExecutor(StatefulExtendedCommandExecutor commandExecutor) {
+ this(new SingleUseQueueingExtendedCommandExecutor(commandExecutor));
+ }
+
+ public SingleUseQueueingExtendedJobCommandExecutor(SingleUseQueueingExtendedCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command)
+ */
+ public void waitToExecute(Command command) throws InterruptedException {
+ this.commandExecutor.waitToExecute(command);
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command, long)
+ */
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ return this.commandExecutor.waitToExecute(command, timeout);
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command)
+ */
+ public void waitToExecute(JobCommand command) throws InterruptedException {
+ this.commandExecutor.waitToExecute(new JobCommandCommandAdapter(command));
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command, long)
+ */
+ public boolean waitToExecute(JobCommand command, long timeout) throws InterruptedException {
+ return this.commandExecutor.waitToExecute(new JobCommandCommandAdapter(command), timeout);
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command)
+ */
+ public void waitToExecute(JobCommand command, String jobName) throws InterruptedException {
+ // ignore 'jobName'
+ this.commandExecutor.waitToExecute(new JobCommandCommandAdapter(command));
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command, long)
+ */
+ public boolean waitToExecute(JobCommand command, String jobName, long timeout) throws InterruptedException {
+ // ignore 'jobName'
+ return this.commandExecutor.waitToExecute(new JobCommandCommandAdapter(command), timeout);
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command)
+ */
+ public void waitToExecute(JobCommand command, String jobName, ISchedulingRule rule) throws InterruptedException {
+ // ignore 'jobName' and 'rule'
+ this.commandExecutor.waitToExecute(new JobCommandCommandAdapter(command));
+ }
+
+ /**
+ * @see SingleUseQueueingExtendedCommandExecutor#waitToExecute(Command, long)
+ */
+ public boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule rule, long timeout) throws InterruptedException {
+ // ignore 'jobName' and 'rule'
+ return this.commandExecutor.waitToExecute(new JobCommandCommandAdapter(command), timeout);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingJobCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingJobCommandExecutor.java
new file mode 100644
index 0000000000..3b25de6625
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/SingleUseQueueingJobCommandExecutor.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility.command;
+
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.SingleUseQueueingCommandExecutor;
+
+/**
+ * This command executor wraps and extends a {@link SingleUseQueueingCommandExecutor},
+ * adding support for executing {@link JobCommand}s.
+ */
+public class SingleUseQueueingJobCommandExecutor
+ extends AbstractSingleUseQueueingJobCommandExecutor<SingleUseQueueingCommandExecutor, StatefulCommandExecutor>
+{
+ public SingleUseQueueingJobCommandExecutor() {
+ this(new SingleUseQueueingCommandExecutor());
+ }
+
+ public SingleUseQueueingJobCommandExecutor(CommandExecutor commandExecutor) {
+ this(new SingleUseQueueingCommandExecutor(commandExecutor));
+ }
+
+ public SingleUseQueueingJobCommandExecutor(StatefulCommandExecutor commandExecutor) {
+ this(new SingleUseQueueingCommandExecutor(commandExecutor));
+ }
+
+ public SingleUseQueueingJobCommandExecutor(SingleUseQueueingCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java
index 48ac9b202a..9a264f76d2 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,7 +23,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AbstractType;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.Type;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Adapt and extend a JDT abstract type.
@@ -196,5 +196,4 @@ public abstract class AbstractJDTType
protected static List<BodyDeclaration> bodyDeclarations(TypeDeclaration typeDeclaration) {
return typeDeclaration.bodyDeclarations();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTAnnotatedElement.java
index c771c77ce5..85171fede1 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTAnnotatedElement.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTAnnotatedElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,8 +21,8 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.TextEdit;
@@ -176,7 +176,9 @@ public abstract class JDTAnnotatedElement
* simple command that calls back to the member to apply the edits
* in the same way as if the document were not shared
*/
- protected class ModifySharedDocumentCommand implements Command {
+ protected class ModifySharedDocumentCommand
+ implements Command
+ {
private final TextEdit edits;
private final IDocument doc;
@@ -197,5 +199,4 @@ public abstract class JDTAnnotatedElement
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnum.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnum.java
index 53d9bc2c1c..47ed58b777 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnum.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnum.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,7 +20,7 @@ import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.Enum;
import org.eclipse.jpt.common.core.utility.jdt.Type;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Adapt and extend a JDT enum.
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java
index 6c2714d6e7..ea3529597d 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -19,7 +19,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.Enum;
import org.eclipse.jpt.common.core.utility.jdt.EnumConstant;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Adapt and extend a JDT enum constant.
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java
index e343cb1596..45668bf042 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.FieldAttribute;
import org.eclipse.jpt.common.core.utility.jdt.Type;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Adapt and extend a JDT field.
@@ -217,5 +217,4 @@ public class JDTFieldAttribute
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMember.java
index 35638f0503..609e79756f 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMember.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,7 +16,7 @@ import org.eclipse.jpt.common.core.utility.jdt.AbstractType;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.Member;
import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Adapt and extend a JDT member with simplified annotation handling.
@@ -86,5 +86,4 @@ public abstract class JDTMember extends JDTAnnotatedElement
protected AbstractType getDeclaringType() {
return this.declaringType;
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java
index 26133ed2cc..17d31b430d 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,9 +22,9 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.MethodAttribute;
import org.eclipse.jpt.common.core.utility.jdt.Type;
-import org.eclipse.jpt.common.utility.CommandExecutor;
import org.eclipse.jpt.common.utility.JavaType;
import org.eclipse.jpt.common.utility.MethodSignature;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.NameTools;
import org.eclipse.jpt.common.utility.internal.SimpleMethodSignature;
@@ -214,7 +214,6 @@ public class JDTMethodAttribute
public boolean isConstructor() {
return this.methodBinding.isConstructor();
}
-
}
protected static class JPTToolsAdapter
@@ -262,7 +261,5 @@ public class JDTMethodAttribute
}
return null;
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTPackage.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTPackage.java
index 2cef772df9..3057928eaf 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTPackage.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTPackage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2005, 2012 Red Hat, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,7 +18,7 @@ import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedPackage;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
public class JDTPackage
extends JDTAnnotatedElement
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTType.java
index 55bef8862a..48d3da117e 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,7 +21,7 @@ import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.Type;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Adapt and extend a JDT type.
@@ -157,7 +157,9 @@ public class JDTType
// ********** JPT tools adapter **********
- protected static class JPTToolsAdapter implements JPTTools.TypeAdapter {
+ protected static class JPTToolsAdapter
+ implements JPTTools.TypeAdapter
+ {
private final ITypeBinding typeBinding;
protected JPTToolsAdapter(ITypeBinding typeBinding) {
super();
@@ -203,5 +205,4 @@ public class JDTType
return this.typeBinding.isPrimitive();
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ProjectResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ProjectResourceLocator.java
new file mode 100644
index 0000000000..00f72fdbae
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ProjectResourceLocator.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.common.core.resource;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * See <code>org.eclipse.jpt.common.core/plugin.xml</code>.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 3.2
+ * @since 3.2
+ * @see org.eclipse.jpt.common.core.internal.resource.ProjectAdapterFactory
+ */
+public interface ProjectResourceLocator {
+ /**
+ * Return whether the specified container is an acceptable (non-Java)
+ * resource location for the locator's project.
+ */
+ boolean resourceLocationIsValid(IContainer container);
+
+ /**
+ * Return the default location in which to create new (non-Java) resources.
+ */
+ IContainer getDefaultResourceLocation();
+
+ /**
+ * Return the workspace relative absolute resource path best represented by
+ * the specified runtime path for the locator's project.
+ */
+ IPath getResourcePath(IPath runtimePath);
+
+ /**
+ * Return the runtime path best represented by the specified workspace
+ * relative absolute resource path for the locator's project.
+ */
+ IPath getRuntimePath(IPath resourcePath);
+
+ /**
+ * Return an {@link IFile} that best represents the specified runtime
+ * location.
+ */
+ IFile getPlatformFile(IPath runtimePath);
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ResourceLocator.java
index 491608c147..fcb82ba6c7 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ResourceLocator.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/ResourceLocator.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.common.core.resource;
@@ -14,6 +14,12 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
/**
+ * Client-defined resource locator.
+ * <p>
+ * See <code>org.eclipse.jpt.common.core/plugin.xml</code>.
+ * <p>
+ * See <code>org.eclipse.jpt.common.core/schema/resourceLocators.exsd</code>.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
@@ -24,27 +30,26 @@ import org.eclipse.core.runtime.IPath;
* @since 3.0
*/
public interface ResourceLocator {
-
/**
- * Return whether the given container is an acceptable (non-java) resource
- * location for the given project
+ * Return whether the specified container is an acceptable (non-Java)
+ * resource location for the specified project.
*/
- boolean acceptResourceLocation(IProject project, IContainer container);
+ boolean resourceLocationIsValid(IProject project, IContainer container);
/**
- * Return the default location in which to create new (non-java) resources
+ * Return the default location in which to create new (non-Java) resources.
*/
IContainer getDefaultResourceLocation(IProject project);
/**
- * Return the workspace relative absolute resource path best represented by the given
- * runtime path for the given project
+ * Return the workspace relative absolute resource path best represented by
+ * the specified runtime path for the specified project.
*/
IPath getResourcePath(IProject project, IPath runtimePath);
/**
- * Return the runtime path best represented by the given workspace relative absolute
- * resource path for the given project
+ * Return the runtime path best represented by the specified workspace
+ * relative absolute resource path for the specified project.
*/
IPath getRuntimePath(IProject project, IPath resourcePath);
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java
index 147f717bb4..0a752f4137 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,11 +12,11 @@ package org.eclipse.jpt.common.core.resource.java;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
/**
* Dali resource for JDT compilation unit.
- *
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
@@ -70,5 +70,4 @@ public interface JavaResourceCompilationUnit
* Build an AST for the compilation unit with its bindings resolved.
*/
CompilationUnit buildASTRoot();
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java
index d2dd201252..b4f237120c 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java
@@ -51,12 +51,14 @@ public interface JavaResourceType
String PRIVATE_NO_ARG_CONSTRUCTOR_PROPERTY = "privateNoArgConstructor"; //$NON-NLS-1$
/**
- * Return whether the type has a public or protected no-arg constructor *or* only the default constructor
+ * Return whether the type has a public or protected no-arg constructor
+ * <em>or</em> only the default constructor.
*/
boolean hasPublicOrProtectedNoArgConstructor();
/**
- * Return whether the type has a public or protected no-arg constructor *or* only the default constructor
+ * Return whether the type has a public no-arg constructor
+ * <em>or</em> only the default constructor.
*/
boolean hasPublicNoArgConstructor();
@@ -73,12 +75,14 @@ public interface JavaResourceType
boolean hasAnyAnnotatedMethods();
/**
- * Return whether the type has equals() method
+ * Return whether the type overrides the
+ * {@link Object#equals(Object)} method.
*/
boolean hasEqualsMethod();
/**
- * Return whether the type has hashCode() method
+ * Return whether the type overrides the
+ * {@link Object#hashCode()} method.
*/
boolean hasHashCodeMethod();
@@ -99,5 +103,5 @@ public interface JavaResourceType
Iterable<JavaResourceMethod> getMethods();
String METHODS_COLLECTION = "methods"; //$NON-NLS-1$
- JavaResourceMethod getMethod(String propertyName);
+ JavaResourceMethod getMethod(String name);
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedCommandExecutor.java
new file mode 100644
index 0000000000..982911ad1f
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedCommandExecutor.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Combine the job command executor and command executor interfaces.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface CombinedCommandExecutor
+ extends JobCommandExecutor, CommandExecutor
+{
+ /**
+ * Singleton implementation of the command executor interface
+ * that simply executes the command without any sort of enhancement.
+ */
+ final class Default
+ implements CombinedCommandExecutor, Serializable
+ {
+ public static final CombinedCommandExecutor INSTANCE = new Default();
+ public static CombinedCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public void execute(Command command) {
+ command.execute();
+ }
+ public void execute(JobCommand command) {
+ command.execute(new NullProgressMonitor());
+ }
+ public void execute(JobCommand command, String jobName) {
+ this.execute(command);
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(command);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that ignores any commands.
+ */
+ final class Inactive
+ implements CombinedCommandExecutor, Serializable
+ {
+ public static final CombinedCommandExecutor INSTANCE = new Inactive();
+ public static CombinedCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Inactive() {
+ super();
+ }
+ public void execute(Command command) {
+ // do nothing
+ }
+ public void execute(JobCommand command) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedExtendedCommandExecutor.java
new file mode 100644
index 0000000000..f1a57014b9
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/CombinedExtendedCommandExecutor.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Combine the synchronouse job command executor and command executor
+ * interfaces.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface CombinedExtendedCommandExecutor
+ extends CombinedCommandExecutor, ExtendedJobCommandExecutor, ExtendedCommandExecutor
+{
+ /**
+ * Singleton implementation of the command executor interface
+ * that simply executes the command without any sort of enhancement.
+ */
+ final class Default
+ implements CombinedExtendedCommandExecutor, Serializable
+ {
+ public static final CombinedExtendedCommandExecutor INSTANCE = new Default();
+ public static CombinedExtendedCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public void execute(Command command) {
+ command.execute();
+ }
+ public void waitToExecute(Command command) {
+ command.execute();
+ }
+ public boolean waitToExecute(Command command, long timeout) {
+ command.execute();
+ return true;
+ }
+ public void execute(JobCommand command) {
+ command.execute(new NullProgressMonitor());
+ }
+ public void execute(JobCommand command, String jobName) {
+ this.execute(command);
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(command);
+ }
+ public void waitToExecute(JobCommand command) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(JobCommand command, long timeout) {
+ this.execute(command);
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, long timeout) {
+ this.execute(command);
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule, long timeout) {
+ this.execute(command);
+ return true;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that ignores any commands.
+ */
+ final class Inactive
+ implements CombinedExtendedCommandExecutor, Serializable
+ {
+ public static final CombinedExtendedCommandExecutor INSTANCE = new Inactive();
+ public static CombinedExtendedCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Inactive() {
+ super();
+ }
+ public void execute(Command command) {
+ // do nothing
+ }
+ public void waitToExecute(Command command) {
+ // do nothing
+ }
+ public boolean waitToExecute(Command command, long timeout) {
+ // do nothing
+ return true;
+ }
+ public void execute(JobCommand command) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // do nothing
+ }
+ public void waitToExecute(JobCommand command) {
+ // do nothing
+ }
+ public boolean waitToExecute(JobCommand command, long timeout) throws InterruptedException {
+ // do nothing
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName) {
+ // do nothing
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, long timeout) throws InterruptedException {
+ // do nothing
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // do nothing
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule, long timeout) throws InterruptedException {
+ // do nothing
+ return true;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/ExtendedJobCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/ExtendedJobCommandExecutor.java
new file mode 100644
index 0000000000..15c4b5d0a9
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/ExtendedJobCommandExecutor.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This interface extends the normal command executor to allow the client
+ * to control when a command is required to be executed synchronously.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface ExtendedJobCommandExecutor
+ extends JobCommandExecutor
+{
+ /**
+ * Suspend the current thread until the specified command is executed.
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor. The command may or may
+ * not be assigned to a {@link org.eclipse.core.runtime.jobs.Job}
+ * for execution.
+ * @see #execute(JobCommand)
+ */
+ void waitToExecute(JobCommand command) throws InterruptedException;
+
+ /**
+ * Suspend the current thread until the specified command is executed
+ * or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if
+ * the command was executed in the allotted time;
+ * return <code>false</code> if a time-out occurred and the command was
+ * <em>not</em> executed.
+ * If the time-out is zero, wait indefinitely.
+ * <p>
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor. The command may or may
+ * not be assigned to a {@link org.eclipse.core.runtime.jobs.Job}
+ * for execution.
+ * @see #execute(JobCommand)
+ */
+ boolean waitToExecute(JobCommand command, long timeout) throws InterruptedException;
+
+ /**
+ * Suspend the current thread until the specified command is executed.
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor. The command may or may
+ * not be assigned to a {@link org.eclipse.core.runtime.jobs.Job}
+ * for execution.
+ * @see #execute(JobCommand, String)
+ */
+ void waitToExecute(JobCommand command, String jobName) throws InterruptedException;
+
+ /**
+ * Suspend the current thread until the specified command is executed
+ * or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if
+ * the command was executed in the allotted time;
+ * return <code>false</code> if a time-out occurred and the command was
+ * <em>not</em> executed.
+ * If the time-out is zero, wait indefinitely.
+ * <p>
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor. The command may or may
+ * not be assigned to a {@link org.eclipse.core.runtime.jobs.Job}
+ * for execution.
+ * @see #execute(JobCommand, String)
+ */
+ boolean waitToExecute(JobCommand command, String jobName, long timeout) throws InterruptedException;
+
+ /**
+ * Suspend the current thread until the specified command is executed.
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor. The command may or may
+ * not be assigned to a {@link org.eclipse.core.runtime.jobs.Job}
+ * for execution.
+ * @see #execute(JobCommand, String, ISchedulingRule)
+ */
+ void waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule) throws InterruptedException;
+
+
+ /**
+ * Suspend the current thread until the specified command is executed
+ * or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if
+ * the command was executed in the allotted time;
+ * return <code>false</code> if a time-out occurred and the command was
+ * <em>not</em> executed.
+ * If the time-out is zero, wait indefinitely.
+ * <p>
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor. The command may or may
+ * not be assigned to a {@link org.eclipse.core.runtime.jobs.Job}
+ * for execution.
+ * @see #execute(JobCommand, String, ISchedulingRule)
+ */
+ boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule, long timeout) throws InterruptedException;
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that simply executes the command without any sort of enhancement.
+ */
+ final class Default
+ implements ExtendedJobCommandExecutor, Serializable
+ {
+ public static final ExtendedJobCommandExecutor INSTANCE = new Default();
+ public static ExtendedJobCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public void execute(JobCommand command) {
+ command.execute(new NullProgressMonitor());
+ }
+ public void execute(JobCommand command, String jobName) {
+ this.execute(command);
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(command);
+ }
+ public void waitToExecute(JobCommand command) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(JobCommand command, long timeout) {
+ this.execute(command);
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, long timeout) {
+ this.execute(command);
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule, long timeout) {
+ this.execute(command);
+ return true;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that ignores any commands.
+ */
+ final class Inactive
+ implements ExtendedJobCommandExecutor, Serializable
+ {
+ public static final ExtendedJobCommandExecutor INSTANCE = new Inactive();
+ public static ExtendedJobCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Inactive() {
+ super();
+ }
+ public void execute(JobCommand command) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // do nothing
+ }
+ public void waitToExecute(JobCommand command) {
+ // do nothing
+ }
+ public boolean waitToExecute(JobCommand command, long timeout) throws InterruptedException {
+ // do nothing
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName) {
+ // do nothing
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, long timeout) throws InterruptedException {
+ // do nothing
+ return true;
+ }
+ public void waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // do nothing
+ }
+ public boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule, long timeout) throws InterruptedException {
+ // do nothing
+ return true;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/InterruptibleJobCommand.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/InterruptibleJobCommand.java
new file mode 100644
index 0000000000..4eb68d4bbb
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/InterruptibleJobCommand.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Simple interface for implementing the GOF Command design pattern
+ * in an Eclipse job
+ * and allows for the command to throw an {@link InterruptedException}.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jpt.common.core.utility.command.JobCommand
+ */
+public interface InterruptibleJobCommand {
+
+ /**
+ * Execute the command. The semantics of the command
+ * is determined by the contract between the client and server.
+ * The command should check, as appropriate, whether the specified progress
+ * monitor is {@link IProgressMonitor#isCanceled() "canceled"}; if it is,
+ * the command should return a result
+ * status of severity {@link IStatus#CANCEL}. The singleton
+ * cancel status {@link org.eclipse.core.runtime.Status#CANCEL_STATUS} can be used for
+ * this purpose.
+ * <p>
+ * Nested methods can also check the progress monitor
+ * and, if it is "canceled", throw an
+ * {@link org.eclipse.core.runtime.OperationCanceledException OperationCanceledException}.
+ *
+ * @see IProgressMonitor#isCanceled()
+ * @see org.eclipse.core.runtime.jobs.Job#run(IProgressMonitor monitor)
+ */
+ IStatus execute(IProgressMonitor monitor) throws InterruptedException;
+
+
+ /**
+ * Singleton implementation of the interruptible job command interface that
+ * will throw an interrupted exception when executed.
+ */
+ final class Interrupted
+ implements InterruptibleJobCommand, Serializable
+ {
+ public static final InterruptibleJobCommand INSTANCE = new Interrupted();
+ public static InterruptibleJobCommand instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Interrupted() {
+ super();
+ }
+ // throw an exception
+ public IStatus execute(IProgressMonitor monitor) throws InterruptedException {
+ throw new InterruptedException();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobCommand.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommand.java
index 0a46bb470d..b70f49e3dc 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JobCommand.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,13 +7,14 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.core.internal.utility;
+package org.eclipse.jpt.common.core.utility.command;
import java.io.Serializable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.utility.internal.StringTools;
/**
* Simple interface for implementing the GOF Command design pattern in an
@@ -25,24 +26,36 @@ import org.eclipse.core.runtime.Status;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface JobCommand {
-
+public interface JobCommand
+ extends InterruptibleJobCommand
+{
/**
* Execute the command. The semantics of the command
* is determined by the contract between the client and server.
* The command should check, as appropriate, whether the specified progress
* monitor is {@link IProgressMonitor#isCanceled() "canceled"}; if it is,
- * the command should throw an
+ * the command should return a result
+ * status of severity {@link IStatus#CANCEL}. The singleton
+ * cancel status {@link Status#CANCEL_STATUS} can be used for
+ * this purpose.
+ * <p>
+ * Nested methods can also check the progress monitor
+ * and, if it is "canceled", throw an
* {@link org.eclipse.core.runtime.OperationCanceledException OperationCanceledException}.
+ *
* @see IProgressMonitor#isCanceled()
+ * @see org.eclipse.core.runtime.jobs.Job#run(IProgressMonitor monitor)
*/
IStatus execute(IProgressMonitor monitor);
+
/**
* Singleton implementation of the job command interface that will do
* nothing when executed.
*/
- final class Null implements JobCommand, Serializable {
+ final class Null
+ implements JobCommand, Serializable
+ {
public static final JobCommand INSTANCE = new Null();
public static JobCommand instance() {
return INSTANCE;
@@ -51,12 +64,12 @@ public interface JobCommand {
private Null() {
super();
}
- public IStatus execute(IProgressMonitor arg0) {
+ public IStatus execute(IProgressMonitor monitor) {
return Status.OK_STATUS;
}
@Override
public String toString() {
- return "JobCommand.Null"; //$NON-NLS-1$
+ return StringTools.buildSingletonToString(this);
}
private static final long serialVersionUID = 1L;
private Object readResolve() {
@@ -65,11 +78,14 @@ public interface JobCommand {
}
}
+
/**
* Singleton implementation of the job command interface that will throw an
* exception when executed.
*/
- final class Disabled implements JobCommand, Serializable {
+ final class Disabled
+ implements JobCommand, Serializable
+ {
public static final JobCommand INSTANCE = new Disabled();
public static JobCommand instance() {
return INSTANCE;
@@ -79,12 +95,12 @@ public interface JobCommand {
super();
}
// throw an exception
- public IStatus execute(IProgressMonitor arg0) {
+ public IStatus execute(IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
@Override
public String toString() {
- return "JobCommand.Disabled"; //$NON-NLS-1$
+ return StringTools.buildSingletonToString(this);
}
private static final long serialVersionUID = 1L;
private Object readResolve() {
@@ -92,5 +108,4 @@ public interface JobCommand {
return INSTANCE;
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommandExecutor.java
new file mode 100644
index 0000000000..e2e1bcef8c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/JobCommandExecutor.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This interface allows clients to control how a job command is executed.
+ * This is useful when the server provides the command but the client provides
+ * the context (e.g. the client would like to execute the command synchronously
+ * rather than dispatching it to a job queue).
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface JobCommandExecutor {
+
+ /**
+ * Execute the specified command, synchronously or asynchronously.
+ * Commands with the same scheduling rule must be executed in the order in
+ * which they are passed to the command executor.
+ * The command may or may not be assigned to a
+ * {@link org.eclipse.core.runtime.jobs.Job} for execution.
+ */
+ void execute(JobCommand command);
+
+ /**
+ * Execute the specified command, synchronously or asynchronously.
+ * Commands with the same scheduling rule must be executed in the order in
+ * which they are passed to the command executor.
+ * The command may or may not be assigned to a
+ * {@link org.eclipse.core.runtime.jobs.Job} for execution.
+ */
+ void execute(JobCommand command, String jobName);
+
+ /**
+ * Execute the specified command, synchronously or asynchronously.
+ * Commands with the same scheduling rule must be executed in the order in
+ * which they are passed to the command executor.
+ * The command may or may not be assigned to a
+ * {@link org.eclipse.core.runtime.jobs.Job} for execution.
+ */
+ void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule);
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that simply executes the command without any sort of enhancement.
+ */
+ final class Default
+ implements JobCommandExecutor, Serializable
+ {
+ public static final JobCommandExecutor INSTANCE = new Default();
+ public static JobCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public void execute(JobCommand command) {
+ command.execute(new NullProgressMonitor());
+ }
+ public void execute(JobCommand command, String jobName) {
+ this.execute(command);
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(command);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that ignores any commands.
+ */
+ final class Inactive
+ implements JobCommandExecutor, Serializable
+ {
+ public static final JobCommandExecutor INSTANCE = new Inactive();
+ public static JobCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Inactive() {
+ super();
+ }
+ public void execute(JobCommand command) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName) {
+ // do nothing
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java
new file mode 100644
index 0000000000..2710618aa2
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/NotifyingRepeatingJobCommand.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import java.util.EventListener;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Extend the repeating job command to support listeners that are notified
+ * when an execution "cycle" is complete; i.e. the job command has,
+ * for the moment, handled every execution request and quiesced.
+ * This notification is <em>not</em> guaranteed to occur with <em>every</em>
+ * execution "cycle"; since other, unrelated, executions can be triggered
+ * concurrently, causing the "cycle" to continue.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface NotifyingRepeatingJobCommand
+ extends RepeatingJobCommand
+{
+ /**
+ * Add the specified listener.
+ */
+ void addListener(Listener listener);
+
+ /**
+ * Remove the specified listener.
+ */
+ void removeListener(Listener listener);
+
+
+ // ********** listener **********
+
+ /**
+ * Interface implemented by listeners to be notified whenever the
+ * job command has quiesced.
+ */
+ public interface Listener
+ extends EventListener
+ {
+ /**
+ * The specified job command has quiesced.
+ */
+ IStatus executionQuiesced(JobCommand command, IProgressMonitor monitor);
+ }
+
+
+ // ********** null singleton **********
+
+ /**
+ * Singleton implementation of the notifying repeating command interface that
+ * will do nothing when executed.
+ */
+ final class Null
+ implements NotifyingRepeatingJobCommand, Serializable
+ {
+ public static final NotifyingRepeatingJobCommand INSTANCE = new Null();
+ public static NotifyingRepeatingJobCommand instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public void start() {
+ // do nothing
+ }
+ public IStatus execute(IProgressMonitor monitor) {
+ return Status.OK_STATUS;
+ }
+ public void stop() {
+ // do nothing
+ }
+ public void addListener(Listener listener) {
+ // do nothing
+ }
+ public void removeListener(Listener listener) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/RepeatingJobCommand.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/RepeatingJobCommand.java
new file mode 100644
index 0000000000..c9952b5b59
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/utility/command/RepeatingJobCommand.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This job command will execute repeatedly the minimum
+ * number of times. The assumption is the job command's effects are
+ * cumulative(?); i.e. the cumulative result of multiple executions of the
+ * job command is no different than the result of a single execution of the job
+ * command. Once the job command is executing, any further requests to execute
+ * simply trigger a re-execution of the job command once it has finished its
+ * current execution.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface RepeatingJobCommand
+ extends JobCommand
+{
+ /**
+ * Start the job command, allowing it to begin executing with the next call
+ * to {@link #execute(IProgressMonitor)}.
+ * @exception IllegalStateException when the command is not stopped
+ */
+ void start();
+
+ /**
+ * Stop the job command; ignore further calls to
+ * {@link #execute(IProgressMonitor)}.
+ * @exception IllegalStateException when the command executor is not started
+ */
+ void stop() throws InterruptedException;
+
+
+ /**
+ * Singleton implementation of the repeating job command interface that
+ * will do nothing when executed.
+ */
+ final class Null
+ implements RepeatingJobCommand, Serializable
+ {
+ public static final RepeatingJobCommand INSTANCE = new Null();
+ public static RepeatingJobCommand instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public void start() {
+ // do nothing
+ }
+ public IStatus execute(IProgressMonitor monitor) {
+ return Status.OK_STATUS;
+ }
+ public void stop() {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemExtendedLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemExtendedLabelProvider.java
new file mode 100644
index 0000000000..affc4ca4ac
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemExtendedLabelProvider.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Abstract {@link ItemLabelProvider} that provides support for listening to an
+ * {@link #item} and notifying the
+ * {@link org.eclipse.jpt.common.ui.jface.ItemLabelProvider.Manager manager}
+ * whenever the item changes in a significant way.
+ * <p>
+ * Subclasses can implement the following methods if the corresponding aspects
+ * of the {@link #item} change:<ul>
+ * <li>{@link #buildImageModel()}<br>
+ * Return a {@link PropertyValueModel} that represents the item's image
+ * <li>{@link #buildTextModel()}<br>
+ * Return a {@link PropertyValueModel} that represents the item's text
+ * <li>{@link #buildDescriptionModel()}<br>
+ * Return a {@link PropertyValueModel} that represents the item's description
+ * </ul>
+ * Alternatively, subclasses can implement the following methods if the
+ * corresponding aspects of the {@link #item} do <em>not</em> change:<ul>
+ * <li>{@link #getImage()}<br>
+ * Return the item's image
+ * <li>{@link #getText()}<br>
+ * Return the item's text
+ * <li>{@link #getDescription()}<br>
+ * Return the item's description
+ * </ul>
+ * For each aspect (image, text, and description) one and only one of the two
+ * methods must be overridden.
+ *
+ * @see StaticItemExtendedLabelProvider
+ */
+public abstract class AbstractItemExtendedLabelProvider<I>
+ implements ItemExtendedLabelProvider
+{
+ protected final ItemLabelProvider.Manager manager;
+
+ protected final I item;
+
+ protected volatile PropertyChangeListener listener;
+
+ protected volatile PropertyValueModel<Image> imageModel;
+
+ protected volatile PropertyValueModel<String> textModel;
+
+ protected volatile PropertyValueModel<String> descriptionModel;
+
+
+ protected AbstractItemExtendedLabelProvider(I item, ItemLabelProvider.Manager manager) {
+ this.item = item;
+ this.manager = manager;
+ }
+
+
+ // ********** image **********
+
+ public Image getImage() {
+ return this.getImageModel().getValue();
+ }
+
+ /**
+ * Return the image model (lazy-initialized).
+ */
+ protected synchronized PropertyValueModel<Image> getImageModel() {
+ if (this.imageModel == null) {
+ this.imageModel = this.buildImageModel();
+ this.engageImageModel();
+ }
+ return this.imageModel;
+ }
+
+ /**
+ * Construct an image model.
+ */
+ protected PropertyValueModel<Image> buildImageModel() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void engageImageModel() {
+ this.imageModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.getListener());
+ }
+
+ protected void disengageImageModel() {
+ this.imageModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+ }
+
+ protected void disposeImageModel() {
+ if (this.imageModel != null) {
+ this.disengageImageModel();
+ this.imageModel = null;
+ }
+ }
+
+
+ // ********** text **********
+
+ public String getText() {
+ return this.getTextModel().getValue();
+ }
+
+ /**
+ * Return the text model (lazy-initialized).
+ */
+ protected synchronized PropertyValueModel<String> getTextModel() {
+ if (this.textModel == null) {
+ this.textModel = this.buildTextModel();
+ this.engageTextModel();
+ }
+ return this.textModel;
+ }
+
+ /**
+ * Construct a text model.
+ */
+ protected PropertyValueModel<String> buildTextModel() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void engageTextModel() {
+ this.textModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.getListener());
+ }
+
+ protected void disengageTextModel() {
+ this.textModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+ }
+
+ protected void disposeTextModel() {
+ if (this.textModel != null) {
+ this.disengageTextModel();
+ this.textModel = null;
+ }
+ }
+
+
+ // ********** description **********
+
+ public String getDescription() {
+ return this.getDescriptionModel().getValue();
+ }
+
+ /**
+ * Return the description model (lazy-initialized).
+ */
+ protected synchronized PropertyValueModel<String> getDescriptionModel() {
+ if (this.descriptionModel == null) {
+ this.descriptionModel = this.buildDescriptionModel();
+ this.engageDescriptionModel();
+ }
+ return this.descriptionModel;
+ }
+
+ /**
+ * Construct a description model.
+ */
+ protected PropertyValueModel<String> buildDescriptionModel() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void engageDescriptionModel() {
+ this.descriptionModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.getListener());
+ }
+
+ protected void disengageDescriptionModel() {
+ this.descriptionModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener);
+ }
+
+ protected void disposeDescriptionModel() {
+ if (this.descriptionModel != null) {
+ this.disengageDescriptionModel();
+ this.descriptionModel = null;
+ }
+ }
+
+
+ // ********** listener **********
+
+ protected synchronized PropertyChangeListener getListener() {
+ if (this.listener == null) {
+ this.listener = this.buildListener();
+ }
+ return this.listener;
+ }
+
+ /**
+ * Build a listener that will listen to the {@link #imageModel},
+ * {@link #textModel}, and {@link #descriptionModel}.
+ */
+ protected PropertyChangeListener buildListener() {
+ return new Listener();
+ }
+
+ /* CU private */ class Listener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ AbstractItemExtendedLabelProvider.this.itemChanged();
+ }
+ }
+
+ /* CU private */ void itemChanged() {
+ this.manager.updateLabel(this.item);
+ }
+
+
+ // ********** dispose **********
+
+ public synchronized void dispose() {
+ this.disposeImageModel();
+ this.disposeTextModel();
+ this.disposeDescriptionModel();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.item);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemLabelProvider.java
deleted file mode 100644
index c351dddcd8..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemLabelProvider.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.jface;
-
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.utility.model.Model;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
-import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Implementation of {@link ItemLabelProvider} that provides updating
- * label information for a Model object.
- *
- * The typical subclass will override the following methods:
- * #buildImageModel()
- * return a {@link PropertyValueModel} that represents the image for the
- * represented model object
- * #buildTextModel()
- * return a {@link PropertyValueModel} that represents the text for the
- * represented model object.
- * #buildDescriptionModel()
- * return a {@link PropertyValueModel} that represents the description for
- * the represented model object
- *
- * Other methods may be overridden, but take care to preserve the logic provided
- * by this class.
- */
-public abstract class AbstractItemLabelProvider implements ItemLabelProvider
-{
- private DelegatingContentAndLabelProvider labelProvider;
-
- private Model model;
-
- private PropertyValueModel<Image> imageModel;
-
- private PropertyValueModel<String> textModel;
-
- private PropertyValueModel<String> descriptionModel;
-
- private PropertyChangeListener labelChangeListener;
-
-
- protected AbstractItemLabelProvider(
- Model model, DelegatingContentAndLabelProvider labelProvider) {
- this.model = model;
- this.labelProvider = labelProvider;
- this.labelChangeListener = buildLabelChangeListener();
- }
-
-
- /**
- * Construct a listener to update the viewer (through the label provider)
- * if the text or image changes
- */
- protected PropertyChangeListener buildLabelChangeListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- getLabelProvider().updateLabel(getModel());
- }
- };
- }
-
- /**
- * Return the image value model
- * (lazy and just-in-time initialized)
- */
- protected synchronized PropertyValueModel<Image> getImageModel() {
- if (this.imageModel == null) {
- this.imageModel = buildImageModel();
- engageImageModel();
- }
- return this.imageModel;
- }
-
- /**
- * Construct an image model
- */
- protected abstract PropertyValueModel<Image> buildImageModel();
-
- /**
- * Should only be overridden with a call to super.engageImageModel() before
- * subclass logic
- */
- protected void engageImageModel() {
- this.imageModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.labelChangeListener);
- }
-
- /**
- * Should only be overridden with a call to super.disengageImageModel() after
- * subclass logic
- */
- protected void disengageImageModel() {
- this.imageModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.labelChangeListener);
- }
-
- /**
- * Return the text value model
- * (lazy and just-in-time initialized)
- */
- protected synchronized PropertyValueModel<String> getTextModel() {
- if (this.textModel == null) {
- this.textModel = buildTextModel();
- engageTextModel();
- }
- return this.textModel;
- }
-
- /**
- * Construct a text value model
- */
- protected abstract PropertyValueModel<String> buildTextModel();
-
- /**
- * Should only be overridden with a call to super.engageTextModel() before
- * subclass logic
- */
- protected void engageTextModel() {
- this.textModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.labelChangeListener);
- }
-
- /**
- * Should only be overridden with a call to super.disengageTextModel() after
- * subclass logic
- */
- protected void disengageTextModel() {
- this.textModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.labelChangeListener);
- }
-
- /**
- * Return the description value model
- * (lazy and just-in-time initialized)
- */
- protected synchronized PropertyValueModel<String> getDescriptionModel() {
- if (this.descriptionModel == null) {
- this.descriptionModel = buildDescriptionModel();
- engageDescriptionModel();
- }
- return this.descriptionModel;
- }
-
- /**
- * Construct a description value model
- */
- protected abstract PropertyValueModel<String> buildDescriptionModel();
-
- /**
- * Should only be overridden with a call to super.engageDescriptionModel() before
- * subclass logic
- */
- protected void engageDescriptionModel() {
- this.descriptionModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.labelChangeListener);
- }
-
- /**
- * Should only be overridden with a call to super.disengageDescriptionModel() after
- * subclass logic
- */
- protected void disengageDescriptionModel() {
- this.descriptionModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.labelChangeListener);
- }
-
- /**
- * Return the model object represented by this item
- */
- public Model getModel() {
- return this.model;
- }
-
- /**
- * Return the label provider that delegates to this item
- */
- public DelegatingContentAndLabelProvider getLabelProvider() {
- return this.labelProvider;
- }
-
- public Image getImage() {
- return getImageModel().getValue();
- }
-
- public String getText() {
- return getTextModel().getValue();
- }
-
- public String getDescription() {
- return getDescriptionModel().getValue();
- }
-
- public void dispose() {
- disposeTextModel();
- disposeImageModel();
- disposeDescriptionModel();
- }
-
- protected synchronized void disposeTextModel() {
- if (this.textModel != null) {
- disengageTextModel();
- this.textModel = null;
- }
- }
-
- protected synchronized void disposeImageModel() {
- if (this.imageModel != null) {
- disengageImageModel();
- this.imageModel = null;
- }
- }
-
- protected synchronized void disposeDescriptionModel() {
- if (this.descriptionModel != null) {
- disengageDescriptionModel();
- this.descriptionModel = null;
- }
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java
new file mode 100644
index 0000000000..0bf4676761
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java
@@ -0,0 +1,280 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import java.util.HashMap;
+import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemStructuredContentProvider;
+import org.eclipse.jpt.common.ui.jface.StructuredStateProvider;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * This provider maintains caches of item content and label providers, each
+ * keyed by item. This allows the providers to listen to the items and update
+ * the viewer as necessary.
+ * <p>
+ * <strong>NB:</strong> This class, if used as a label provider should typically
+ * be used also as a content provider for the same viewer. Otherwise, the item
+ * label providers will not be disposed until the viewer is disposed; because
+ * the item label providers are disposed (here) as their associated items are
+ * disposed by their item content providers, which are listening to the items.
+ * This is only a problem if the items in the tree can be removed, thus leaking
+ * stale item label providers in the manager's cache. The default behavior is
+ * to disallow using the manager as only a label provider (see
+ * {@link #checkViewer()}).
+ *
+ * @see ItemStructuredContentProvider
+ * @see ItemExtendedLabelProvider
+ */
+public abstract class AbstractItemStructuredStateProviderManager<V extends StructuredViewer, CP extends ItemStructuredContentProvider>
+ extends BaseLabelProvider
+ implements StructuredStateProvider, ItemStructuredContentProvider.Manager, ItemExtendedLabelProvider.Manager
+{
+ /**
+ * May be <code>null</code>.
+ */
+ protected final ItemExtendedLabelProviderFactory itemLabelProviderFactory;
+
+ protected final HashMap<Object, CP> itemContentProviders = new HashMap<Object, CP>();
+
+ protected final HashMap<Object, ItemExtendedLabelProvider> itemLabelProviders = new HashMap<Object, ItemExtendedLabelProvider>();
+
+ protected volatile V viewer;
+
+
+ protected AbstractItemStructuredStateProviderManager(ItemExtendedLabelProviderFactory itemLabelProviderFactory) {
+ super();
+ this.itemLabelProviderFactory = itemLabelProviderFactory;
+ }
+
+
+ // ********** content provider **********
+
+ @SuppressWarnings("unchecked")
+ public synchronized void inputChanged(Viewer v, Object oldInput, Object newInput) {
+ if (oldInput != newInput) {
+ this.disposeProviders();
+ }
+ this.viewer = (V) v;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ CP provider = this.getItemContentProvider(inputElement);
+ return (provider == null) ? EMPTY_ARRAY : provider.getElements();
+ }
+
+
+ // ********** label provider **********
+
+ public Image getImage(Object element) {
+ ItemLabelProvider provider = this.getItemLabelProvider(element);
+ return (provider == null) ? null :provider.getImage();
+ }
+
+ public String getText(Object element) {
+ ItemLabelProvider provider = this.getItemLabelProvider(element);
+ return (provider == null) ? null : provider.getText();
+ }
+
+ public String getDescription(Object element) {
+ ItemExtendedLabelProvider provider = this.getItemLabelProvider(element);
+ return (provider == null) ? null : provider.getDescription();
+ }
+
+
+ // ********** item provider caches **********
+
+ protected synchronized CP getItemContentProvider(Object item) {
+ CP provider = this.itemContentProviders.get(item);
+ if (provider == null) {
+ if ( ! this.itemContentProviders.containsKey(item)) { // null is an allowed value
+ provider = this.buildItemContentProvider(item);
+ this.itemContentProviders.put(item, provider);
+ }
+ }
+ return provider;
+ }
+
+ protected abstract CP buildItemContentProvider(Object item);
+
+ protected synchronized ItemExtendedLabelProvider getItemLabelProvider(Object item) {
+ ItemExtendedLabelProvider provider = this.itemLabelProviders.get(item);
+ if (provider == null) {
+ if ( ! this.itemLabelProviders.containsKey(item)) { // null is an allowed value
+ provider = this.buildItemLabelProvider(item);
+ this.itemLabelProviders.put(item, provider);
+ }
+ }
+ return provider;
+ }
+
+ protected ItemExtendedLabelProvider buildItemLabelProvider(Object item) {
+ this.checkViewer();
+ return (this.itemLabelProviderFactory == null) ? null : this.itemLabelProviderFactory.buildProvider(item, this);
+ }
+
+ /**
+ * The viewer passes itself to its content provider; so it will be
+ * initialized by the time we get here if this provider is the
+ * viewer's content provider.
+ */
+ protected void checkViewer() {
+ if (this.viewer == null) {
+ throw new IllegalStateException("This provider must be used as a content provider *as well as* a label provider."); //$NON-NLS-1$
+ }
+ }
+
+
+ // ********** update elements **********
+
+ /**
+ * Dispatch to the UI thread.
+ */
+ public void updateElements(Object inputElement) {
+ this.execute(new UpdateElementsRunnable(inputElement));
+ }
+
+ /* CU private */ class UpdateElementsRunnable
+ extends RunnableAdapter
+ {
+ private final Object inputElement;
+ UpdateElementsRunnable(Object inputElement) {
+ super();
+ this.inputElement = inputElement;
+ }
+ @Override
+ public void run() {
+ AbstractItemStructuredStateProviderManager.this.updateElements_(this.inputElement);
+ }
+ }
+
+ /**
+ * Update the specified item's elements.
+ */
+ /* CU private */ void updateElements_(Object inputElement) {
+ if (this.viewerIsAlive()) {
+ this.viewer.refresh(inputElement);
+ }
+ }
+
+
+ // ********** update label **********
+
+ /**
+ * Dispatch to the UI thread.
+ */
+ public void updateLabel(Object item) {
+ this.execute(new UpdateLabelRunnable(item));
+ }
+
+ /* CU private */ class UpdateLabelRunnable
+ extends RunnableAdapter
+ {
+ private final Object item;
+ UpdateLabelRunnable(Object item) {
+ super();
+ this.item = item;
+ }
+ @Override
+ public void run() {
+ AbstractItemStructuredStateProviderManager.this.updateLabel_(this.item);
+ }
+ }
+
+ /**
+ * Update the specified item's label.
+ */
+ /* CU private */ void updateLabel_(Object item) {
+ if (this.viewerIsAlive()) {
+ this.fireLabelProviderChanged(new LabelProviderChangedEvent(this, item));
+ }
+ }
+
+
+ // ********** update description **********
+
+ public void updateDescription(Object item) {
+ // NOP - currently there is no way affect the status bar;
+ // it is updated when the viewer's selection changes
+ }
+
+
+ // ********** misc **********
+
+ protected void execute(Runnable runnable) {
+ SWTUtil.execute(this.viewer, runnable);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+ protected boolean viewerIsAlive() {
+ Control control = (this.viewer == null) ? null : this.viewer.getControl();
+ return (control != null) && ! control.isDisposed();
+ }
+
+
+ // ********** dispose **********
+
+ /**
+ * Disposes all items
+ */
+ @Override
+ public synchronized void dispose() {
+ this.disposeProviders();
+ super.dispose();
+ }
+
+ protected synchronized void disposeProviders() {
+ // coded this way because the item providers will call back to this
+ // manager to dispose their children when they are disposed
+ while ( ! this.itemContentProviders.isEmpty()) {
+ this.dispose_(this.itemContentProviders.keySet().iterator().next());
+ }
+ // dispose the label providers for any items that did not have a content provider;
+ // although that is most likely a bug, it is allowed and handled
+ while (! this.itemLabelProviders.isEmpty()) {
+ this.dispose_(this.itemLabelProviders.keySet().iterator().next());
+ }
+ }
+
+ /**
+ * Dispose the specified item's content and label providers.
+ */
+ public synchronized void dispose(Object item) {
+ this.dispose_(item);
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private void dispose_(Object item) {
+ ItemStructuredContentProvider icp = this.itemContentProviders.remove(item);
+ if (icp != null) {
+ icp.dispose();
+ }
+ ItemLabelProvider ilp = this.itemLabelProviders.remove(item);
+ if (ilp != null) {
+ ilp.dispose();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemTreeContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemTreeContentProvider.java
new file mode 100644
index 0000000000..c79b5a61f6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemTreeContentProvider.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import java.util.ConcurrentModificationException;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+
+/**
+ * Abstract {@link ItemTreeContentProvider} that provides support for listening to an
+ * {@link #item} and notifying the
+ * {@link org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager manager}
+ * whenever the item's children change in a significant way.
+ * <p>
+ * Subclasses must implement the following method:<ul>
+ * <li>{@link #buildChildrenModel()}<br>
+ * Return a {@link CollectionValueModel} that represents the item's children
+ * </ul>
+ *
+ * @see StaticItemTreeContentProvider
+ */
+public abstract class AbstractItemTreeContentProvider<I, C>
+ implements ItemTreeContentProvider
+{
+ protected final Manager manager;
+
+ protected final I item;
+
+ protected volatile CollectionValueModel<C> childrenModel;
+
+ protected volatile CollectionChangeListener childrenListener;
+
+
+ protected AbstractItemTreeContentProvider(I item, Manager manager) {
+ this.item = item;
+ this.manager = manager;
+ }
+
+
+ // ********** children **********
+
+ /**
+ * Typical implementation for a tree.
+ */
+ public Object[] getElements() {
+ return this.getChildren();
+ }
+
+ // TODO bjv
+ public Object[] getChildren() {
+ while (true) {
+ try {
+ return ArrayTools.array(this.getChildrenModel());
+ } catch (ConcurrentModificationException ex) {
+ // try again - hack: need to make value model stuff thread-safe...
+ }
+ }
+ }
+
+ /**
+ * Return the children model (lazy-initialized).
+ */
+ protected synchronized CollectionValueModel<C> getChildrenModel() {
+ if (this.childrenModel == null) {
+ this.childrenModel = this.buildChildrenModel();
+ this.childrenListener = this.buildChildrenListener();
+ this.engageChildrenModel();
+ }
+ return this.childrenModel;
+ }
+
+ /**
+ * Construct a children model.
+ */
+ protected abstract CollectionValueModel<C> buildChildrenModel();
+
+ /**
+ * Override with potentially more efficient logic.
+ */
+ public boolean hasChildren() {
+ return this.getChildrenModel().iterator().hasNext();
+ }
+
+ protected void engageChildrenModel() {
+ this.childrenModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.childrenListener);
+ }
+
+ protected void disengageChildrenModel() {
+ this.childrenModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this.childrenListener);
+ }
+
+
+ // ********** listener **********
+
+ protected CollectionChangeListener buildChildrenListener() {
+ return new ChildrenListener();
+ }
+
+ protected class ChildrenListener
+ extends CollectionChangeAdapter
+ {
+ @Override
+ @SuppressWarnings("unchecked")
+ public void itemsAdded(CollectionAddEvent event) {
+ AbstractItemTreeContentProvider.this.childrenAdded((Iterable<C>) event.getItems());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ AbstractItemTreeContentProvider.this.childrenRemoved((Iterable<C>) event.getItems());
+ }
+
+ /**
+ * <strong>NB:</strong> Any removed children will malinger until the
+ * manager itself is disposed.
+ */
+ @Override
+ public void collectionChanged(CollectionChangeEvent event) {
+ AbstractItemTreeContentProvider.this.childrenChanged();
+ }
+
+ /**
+ * <strong>NB:</strong> Any removed children will malinger until the
+ * manager itself is disposed.
+ */
+ @Override
+ public void collectionCleared(CollectionClearEvent event) {
+ AbstractItemTreeContentProvider.this.childrenChanged();
+ }
+ }
+
+ protected void childrenAdded(@SuppressWarnings("unused") Iterable<C> children) {
+ this.manager.updateChildren(this.item);
+ }
+
+ protected void childrenRemoved(Iterable<C> children) {
+ this.manager.updateChildren(this.item);
+ for (Object child : children) {
+ this.manager.dispose(child);
+ }
+ }
+
+ protected void childrenChanged() {
+ this.manager.updateChildren(this.item);
+ }
+
+
+ // ********** dispose **********
+
+ public synchronized void dispose() {
+ if (this.childrenModel != null) {
+ this.dispose_();
+ }
+ }
+
+ /**
+ * Pre-condition: {@link #childrenModel} is not <code>null</code>.
+ */
+ protected void dispose_() {
+ for (Object child : this.childrenModel) {
+ this.manager.dispose(child);
+ }
+ this.disengageChildrenModel();
+ this.childrenModel = null;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.item);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java
new file mode 100644
index 0000000000..cd7e6ed8d1
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.core.commands.common.EventManager;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Provide support for {@link ISelectionChangedListener selection change
+ * listeners} and {@link #fireSelectionChanged(ISelection) the safe firing of
+ * events}.
+ */
+public abstract class AbstractSelectionProvider
+ extends EventManager
+ implements ISelectionProvider
+{
+ protected AbstractSelectionProvider() {
+ super();
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ this.addListenerObject(listener);
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ this.removeListenerObject(listener);
+ }
+
+ protected void fireSelectionChanged(ISelection selection) {
+ SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
+ for (Object listener : this.getListeners()) {
+ SafeRunner.run(new ListenerNotifier(listener, event));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+
+ // ********** listener notifier **********
+
+ /**
+ * A runnable that forwards an event to a listener and handles any
+ * exceptions thrown by the listener by notifying the user via a dialog.
+ */
+ /* CU private */ class ListenerNotifier
+ extends SafeRunnable
+ {
+ private final ISelectionChangedListener listener;
+ private final SelectionChangedEvent event;
+
+ ListenerNotifier(Object listener, SelectionChangedEvent event) {
+ super();
+ this.listener = (ISelectionChangedListener) listener;
+ this.event = event;
+ }
+
+ public void run() {
+ this.listener.selectionChanged(this.event);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.listener);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractTreeItemContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractTreeItemContentProvider.java
deleted file mode 100644
index c5631b8d6a..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractTreeItemContentProvider.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.jface;
-
-import java.util.Iterator;
-
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.utility.internal.ArrayTools;
-import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.NullCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.Model;
-import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.ListValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * Implementation of {@link TreeItemContentProvider} that provides updating
- * children information for a Model object.
- *
- * The typical subclass will override the following methods:
- * #getParent()
- * the default behavior for this method is to return null. there is no
- * property value model for this as this should not be changing for a given
- * node. all such changes will be provided by the parent side of the relationship.
- * #buildChildrenModel()
- * return a {@link ListValueModel} that represents the children for the represented
- * model object. #buildChildrenModel(CollectionValueModel) and
- * #buildChildrenModel(PropertyValueModel) are provided if the children are more
- * easily represented as a collection or as a property (single child)
- * the default behavior is to return a {@link NullListValueModel}
- *
- * Other methods may be overridden, but take care to preserve the logic provided
- * by this class.
- */
-public abstract class AbstractTreeItemContentProvider<E>
- implements TreeItemContentProvider
-{
- private DelegatingTreeContentAndLabelProvider treeContentProvider;
-
- private Model model;
-
- private CollectionValueModel<E> childrenModel;
-
- private CollectionChangeListener childrenListener;
-
-
- protected AbstractTreeItemContentProvider(
- Model model, DelegatingTreeContentAndLabelProvider treeContentProvider) {
- this.model = model;
- this.treeContentProvider = treeContentProvider;
- this.childrenListener = buildChildrenListener();
- }
-
- /**
- * Construct a listener to refresh the tree (through the tree content provider)
- * if the children change
- */
- protected CollectionChangeListener buildChildrenListener() {
- return new CollectionChangeListener() {
-
- public void itemsAdded(CollectionAddEvent event) {
- getTreeContentProvider().updateContent(getModel());
- }
-
- public void itemsRemoved(CollectionRemoveEvent event) {
- getTreeContentProvider().updateContent(getModel());
- for (Object item : event.getItems()) {
- getTreeContentProvider().dispose(item);
- }
- }
-
- public void collectionChanged(CollectionChangeEvent event) {
- getTreeContentProvider().updateContent(getModel());
- // in the case of a list changed event, we don't have
- // access to the removed objects, so we can't dispose them.
- // keep a watch on this to see if this becomes a problem.
- }
-
- public void collectionCleared(CollectionClearEvent event) {
- getTreeContentProvider().updateContent(getModel());
- // in the case of a list cleared event, we don't have
- // access to the removed objects, so we can't dispose them.
- // keep a watch on this to see if this becomes a problem.
- }
- };
- }
-
- /**
- * Return the children model
- * (lazy and just-in-time initialized)
- */
- protected synchronized Iterator<E> childrenModel() {
- if (this.childrenModel == null) {
- this.childrenModel = buildChildrenModel();
- engageChildren();
- }
- return this.childrenModel.iterator();
- }
-
- /**
- * Construct a children model
- */
- protected CollectionValueModel<E> buildChildrenModel() {
- return new NullCollectionValueModel<E>();
- }
-
- /**
- * Utility method that can be used if the children model is better represented
- * as a collection.
- * This wraps the children collection model and uses it internally as a list
- * model.
- */
- protected CollectionValueModel<E> buildChildrenModel(ListValueModel<E> lvm) {
- return new ListCollectionValueModelAdapter<E>(lvm);
- }
-
- /**
- * Utility method that can be used if the children model is better represented
- * as a single value property.
- * This wraps the children (child) property model and uses it internally as a list
- * model.
- */
- protected ListValueModel<E> buildChildrenModel(PropertyValueModel<E> lvm) {
- return new PropertyListValueModelAdapter<E>(lvm);
- }
-
- /**
- * Return the model object represented by this node
- */
- public Model getModel() {
- return this.model;
- }
-
- /**
- * Return the tree content provider that delegates to this node
- */
- public DelegatingTreeContentAndLabelProvider getTreeContentProvider() {
- return this.treeContentProvider;
- }
-
- public Object getParent() {
- return null;
- }
-
- public Object[] getElements() {
- return getChildren();
- }
-
- public Object[] getChildren() {
- return ArrayTools.array(this.childrenModel());
- }
-
- /**
- * Override with potentially more efficient logic
- */
- public boolean hasChildren() {
- return this.childrenModel().hasNext();
- }
-
- /**
- * Should only be overridden with a call to super.dispose()
- */
- public void dispose() {
- for (Object child : getChildren()) {
- getTreeContentProvider().dispose(child);
- }
- disposeChildrenModel();
- }
-
- /**
- * Should only be overridden with a call to super.engageChildren() before
- * subclass logic
- */
- protected void engageChildren() {
- this.childrenModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.childrenListener);
- }
-
- protected synchronized void disposeChildrenModel() {
- if (this.childrenModel != null) {
- this.disengageChildrenModel();
- this.childrenModel = null;
- }
- }
- /**
- * Should only be overridden with a call to super.disengageChildren() after
- * subclass logic
- */
- protected void disengageChildrenModel() {
- this.childrenModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this.childrenListener);
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ContentProvider.java
new file mode 100644
index 0000000000..176f774443
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ContentProvider.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Convenience implementation of {@link IContentProvider}.
+ */
+public class ContentProvider
+ implements IContentProvider
+{
+ private static final IContentProvider NULL_PROVIDER = new ContentProvider();
+
+ public static IContentProvider nullProvider() {
+ return NULL_PROVIDER;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // do nothing
+ }
+
+ public void dispose() {
+ // do nothing
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java
deleted file mode 100644
index d5df216b6e..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.jface;
-
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-
-/**
- * Extension of {@link DelegatingContentAndLabelProvider} that provides an extension
- * to provide tree content
- */
-public class DelegatingTreeContentAndLabelProvider
- extends DelegatingContentAndLabelProvider
- implements ITreeContentProvider
-{
- public DelegatingTreeContentAndLabelProvider(
- TreeItemContentProviderFactory treeItemContentProviderFactory) {
- super(treeItemContentProviderFactory);
- }
-
- public DelegatingTreeContentAndLabelProvider(
- TreeItemContentProviderFactory treeItemContentProviderFactory,
- ItemLabelProviderFactory itemLabelProviderFactory) {
- super(treeItemContentProviderFactory, itemLabelProviderFactory);
- }
-
-
- @Override
- protected TreeItemContentProvider itemContentProvider(Object item) {
- return (TreeItemContentProvider) super.itemContentProvider(item);
- }
-
- public Object[] getChildren(Object parentElement) {
- TreeItemContentProvider provider = itemContentProvider(parentElement);
- return (provider == null) ? new Object[0] : provider.getChildren();
- }
-
- public Object getParent(Object element) {
- TreeItemContentProvider provider = itemContentProvider(element);
- return (provider == null) ? null : provider.getParent();
- }
-
- public boolean hasChildren(Object element) {
- TreeItemContentProvider provider = itemContentProvider(element);
- return (provider == null) ? false : provider.hasChildren();
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/EmptySelection.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/EmptySelection.java
new file mode 100644
index 0000000000..089d0f78b1
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/EmptySelection.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Empty implementation of {@link ISelection}.
+ * Implemented as a singleton.
+ */
+public class EmptySelection
+ implements ISelection
+{
+ public static final ISelection INSTANCE = new EmptySelection();
+
+ public static ISelection instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure a single instance.
+ */
+ private EmptySelection() {
+ super();
+ }
+
+ public boolean isEmpty() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemStructuredStateProviderManager.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemStructuredStateProviderManager.java
new file mode 100644
index 0000000000..677c1d526f
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemStructuredStateProviderManager.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemStructuredContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemStructuredContentProviderFactory;
+
+/**
+ * @see AbstractItemStructuredStateProviderManager
+ */
+public class ItemStructuredStateProviderManager
+ extends AbstractItemStructuredStateProviderManager<StructuredViewer, ItemStructuredContentProvider>
+{
+ /**
+ * Never <code>null</code>.
+ */
+ protected final ItemStructuredContentProviderFactory itemContentProviderFactory;
+
+
+ public ItemStructuredStateProviderManager(ItemStructuredContentProviderFactory itemContentProviderFactory) {
+ this(itemContentProviderFactory, null);
+ }
+
+ public ItemStructuredStateProviderManager(ItemStructuredContentProviderFactory itemContentProviderFactory, ItemExtendedLabelProviderFactory itemLabelProviderFactory) {
+ super(itemLabelProviderFactory);
+ if (itemContentProviderFactory == null) {
+ throw new NullPointerException();
+ }
+ this.itemContentProviderFactory = itemContentProviderFactory;
+ }
+
+ @Override
+ protected ItemStructuredContentProvider buildItemContentProvider(Object item) {
+ return this.itemContentProviderFactory.buildProvider(item, this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemTreeStateProviderManager.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemTreeStateProviderManager.java
new file mode 100644
index 0000000000..b5d40efa54
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/ItemTreeStateProviderManager.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.TreeStateProvider;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
+
+/**
+ * @see AbstractItemStructuredStateProviderManager
+ * @see ItemTreeContentProvider
+ */
+public class ItemTreeStateProviderManager
+ extends AbstractItemStructuredStateProviderManager<TreeViewer, ItemTreeContentProvider>
+ implements TreeStateProvider, ItemTreeContentProvider.Manager
+{
+ /**
+ * Never <code>null</code>.
+ */
+ protected final ItemTreeContentProviderFactory itemContentProviderFactory;
+
+
+ public ItemTreeStateProviderManager(ItemTreeContentProviderFactory itemContentProviderFactory) {
+ this(itemContentProviderFactory, null);
+ }
+
+ public ItemTreeStateProviderManager(ItemTreeContentProviderFactory itemContentProviderFactory, ItemExtendedLabelProviderFactory itemLabelProviderFactory) {
+ super(itemLabelProviderFactory);
+ if (itemContentProviderFactory == null) {
+ throw new NullPointerException();
+ }
+ this.itemContentProviderFactory = itemContentProviderFactory;
+ }
+
+
+ // ********** tree content provider **********
+
+ public boolean hasChildren(Object element) {
+ ItemTreeContentProvider provider = this.getItemContentProvider(element);
+ return (provider != null) && provider.hasChildren();
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ ItemTreeContentProvider provider = this.getItemContentProvider(parentElement);
+ return (provider == null) ? EMPTY_ARRAY : provider.getChildren();
+ }
+
+ public Object getParent(Object element) {
+ ItemTreeContentProvider provider = this.getItemContentProvider(element);
+ return (provider == null) ? null : provider.getParent();
+ }
+
+ @Override
+ protected ItemTreeContentProvider buildItemContentProvider(Object item) {
+ return this.itemContentProviderFactory.buildProvider(item, this);
+ }
+
+
+ // ********** update children **********
+
+ /**
+ * Dispatch to the UI thread.
+ */
+ public void updateChildren(Object inputElement) {
+ SWTUtil.execute(this.viewer, new UpdateChildrenRunnable(inputElement));
+ }
+
+ /* CU private */ class UpdateChildrenRunnable
+ extends RunnableAdapter
+ {
+ private final Object element;
+ UpdateChildrenRunnable(Object element) {
+ super();
+ this.element = element;
+ }
+ @Override
+ public void run() {
+ ItemTreeStateProviderManager.this.updateChildren_(this.element);
+ }
+ }
+
+ /**
+ * Update the specified item's children.
+ */
+ /* CU private */ void updateChildren_(Object element) {
+ if (this.viewerIsAlive()) {
+ this.viewer.refresh(element, false);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/LabelProviderAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/LabelProviderAdapter.java
new file mode 100644
index 0000000000..e5e7ac18f2
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/LabelProviderAdapter.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Convenience implementation of {@link ILabelProviderListener}.
+ */
+public class LabelProviderAdapter
+ implements ILabelProviderListener
+{
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ // do nothing
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorContentProvider.java
new file mode 100644
index 0000000000..17ba135212
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorContentProvider.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.TreeStateProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.navigator.ICommonContentExtensionSite;
+import org.eclipse.ui.navigator.ICommonContentProvider;
+
+/**
+ * This content provider delegates to a {@link TreeStateProvider} that is
+ * shared with a partner {@link NavigatorLabelProvider label provider}.
+ * <p>
+ * Concrete subclasses of this provider can be used as the content provider
+ * in extensions of <code>org.eclipse.ui.navigator.navigatorContent</code>.
+ */
+public abstract class NavigatorContentProvider
+ implements ICommonContentProvider
+{
+ protected TreeStateProvider delegate;
+
+
+ /**
+ * Must use zero-argument constructor because the provider is instantiated
+ * by the Navigator Content extension point
+ * (<code>org.eclipse.ui.navigator.navigatorContent</code>).
+ */
+ protected NavigatorContentProvider() {
+ super();
+ }
+
+ /**
+ * The content provider is initialized first; so we build the delegate
+ * here.
+ */
+ public void init(ICommonContentExtensionSite config) {
+ this.delegate = this.buildDelegate();
+ }
+
+ protected TreeStateProvider buildDelegate() {
+ return new ItemTreeStateProviderManager(
+ this.buildItemContentProviderFactory(),
+ this.buildItemLabelProviderFactory()
+ );
+ }
+
+ /**
+ * Return a factory that will build item content providers for the
+ * appropriate items in the navigator.
+ */
+ protected abstract ItemTreeContentProviderFactory buildItemContentProviderFactory();
+
+ /**
+ * Return a factory that will build item label providers for the
+ * appropriate items in the navigator.
+ */
+ protected abstract ItemExtendedLabelProviderFactory buildItemLabelProviderFactory();
+
+ public void inputChanged(Viewer commonViewer, Object oldInput, Object newInput) {
+ this.delegate.inputChanged(commonViewer, oldInput, newInput);
+ }
+
+ public Object[] getElements(Object inputElement) {
+ // never called?
+ return this.delegate.getElements(inputElement);
+ }
+
+ public Object getParent(Object element) {
+ return this.delegate.getParent(element);
+ }
+
+ public boolean hasChildren(Object element) {
+ return this.hasChildren_(element) || this.delegate.hasChildren(element);
+ }
+
+ /**
+ * Return whether the specified element has children. This method handles
+ * any element that is <em>not</em> handled by the {@link #delegate} but is
+ * the parent of element(s) that <em>are</em> handled by the
+ * {@link #delegate} (i.e. any third-party element that is to hold the
+ * provider's elements; e.g. a project). Return <code>false</code> if the
+ * element is to be handled by the {@link #delegate}.
+ */
+ protected abstract boolean hasChildren_(Object element);
+
+ public Object[] getChildren(Object element) {
+ Object[] children = this.getChildren_(element);
+ return (children != null) ? children : this.delegate.getChildren(element);
+ }
+
+ /**
+ * Return the specified element's children. This method handles
+ * any element that is <em>not</em> handled by the {@link #delegate} but is
+ * the parent of element(s) that <em>are</em> handled by the
+ * {@link #delegate} (i.e. any third-party element that is to hold the
+ * provider's elements; e.g. a project). Return <code>null</code> if the
+ * element is to be handled by the {@link #delegate}.
+ */
+ protected abstract Object[] getChildren_(Object element);
+
+ public void saveState(IMemento memento) {
+ // TODO
+ }
+
+ public void restoreState(IMemento memento) {
+ // TODO
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+ public void dispose() {
+ this.delegate.dispose();
+ }
+
+ /**
+ * @see NavigatorLabelProvider#getDelegate()
+ */
+ TreeStateProvider getDelegate() {
+ return this.delegate;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorLabelProvider.java
new file mode 100644
index 0000000000..d85ae97b22
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NavigatorLabelProvider.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jpt.common.ui.internal.jface.LabelProviderAdapter;
+import org.eclipse.jpt.common.ui.jface.TreeStateProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.navigator.ICommonContentExtensionSite;
+import org.eclipse.ui.navigator.ICommonLabelProvider;
+
+/**
+ * @see NavigatorContentProvider
+ * <p>
+ * This provider can be used as the label provider
+ * in extensions of <code>org.eclipse.ui.navigator.navigatorContent</code>.
+ */
+public class NavigatorLabelProvider
+ extends BaseLabelProvider
+ implements ICommonLabelProvider
+{
+ /**
+ * "Partner" content provider that holds the tree
+ * state provider.
+ */
+ private NavigatorContentProvider contentProvider;
+
+ /**
+ * Listen to the delegate provider and forward any events.
+ */
+ private DelegateListener delegateListener;
+
+
+ public NavigatorLabelProvider() {
+ super();
+ }
+
+ /**
+ * @see #dispose()
+ */
+ public void init(ICommonContentExtensionSite config) {
+ this.contentProvider = (NavigatorContentProvider) config.getExtension().getContentProvider();
+ this.delegateListener = new DelegateListener();
+ this.getDelegate().addListener(this.delegateListener);
+ }
+
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return this.getDelegate().isLabelProperty(element, property);
+ }
+
+ public Image getImage(Object element) {
+ return this.getDelegate().getImage(element);
+ }
+
+ public String getText(Object element) {
+ return this.getDelegate().getText(element);
+ }
+
+ public String getDescription(Object element) {
+ return this.getDelegate().getDescription(element);
+ }
+
+ public void saveState(IMemento memento) {
+ // TODO
+ }
+
+ public void restoreState(IMemento memento) {
+ // TODO
+ }
+
+ private TreeStateProvider getDelegate() {
+ return this.contentProvider.getDelegate();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+ /**
+ * NB: The delegate will remove our listener when it is disposed
+ * in {@link NavigatorContentProvider#dispose()}. :-(
+ * @see BaseLabelProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ }
+
+
+ // ********** delegate listener **********
+
+ /* CU private */ class DelegateListener
+ extends LabelProviderAdapter
+ {
+ @Override
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ NavigatorLabelProvider.this.labelProviderChanged(event);
+ }
+ }
+
+ /* CU private */ void labelProviderChanged(LabelProviderChangedEvent event) {
+ // forward the event with *this* provider as the source
+ this.fireLabelProviderChanged(new LabelProviderChangedEvent(this, event.getElements()));
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullLabelProvider.java
deleted file mode 100644
index 1380b3dac6..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullLabelProvider.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.jface;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Null implementation of the ILabelProvider interface.
- * Implemented as a singleton.
- */
-public final class NullLabelProvider
- implements ILabelProvider
-{
- public static final NullLabelProvider INSTANCE = new NullLabelProvider();
-
- public static ILabelProvider instance() {
- return INSTANCE;
- }
-
- /**
- * Ensure a single instance.
- */
- private NullLabelProvider() {
- super();
- }
-
- public Image getImage(Object element) {
- return null;
- }
-
- public String getText(Object element) {
- return null;
- }
-
- public void addListener(ILabelProviderListener listener) {
- // do nothing
- }
-
- public void dispose() {
- // do nothing
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void removeListener(ILabelProviderListener listener) {
- // do nothing
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullTreeContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullTreeContentProvider.java
deleted file mode 100644
index f050ffa226..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/NullTreeContentProvider.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.jface;
-
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Null implementation of the ILabelProvider interface.
- * Implemented as a singleton.
- */
-public final class NullTreeContentProvider
- implements ITreeContentProvider
-{
- private static final Object[] EMPTY_ARRAY = new Object[0];
- public static final NullTreeContentProvider INSTANCE = new NullTreeContentProvider();
-
- public static ITreeContentProvider instance() {
- return INSTANCE;
- }
-
- /**
- * Ensure a single instance.
- */
- private NullTreeContentProvider() {
- super();
- }
-
- public Object[] getChildren(Object parentElement) {
- return EMPTY_ARRAY;
- }
-
- public Object getParent(Object element) {
- return null;
- }
-
- public boolean hasChildren(Object element) {
- return false;
- }
-
- public Object[] getElements(Object inputElement) {
- return EMPTY_ARRAY;
- }
-
- public void dispose() {
- // do nothing
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // do nothing
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SelectionChangedAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SelectionChangedAdapter.java
new file mode 100644
index 0000000000..165ac1c850
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SelectionChangedAdapter.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Convenience implementation of {@link ISelectionChangedListener}.
+ */
+public class SelectionChangedAdapter
+ implements ISelectionChangedListener
+{
+ public void selectionChanged(SelectionChangedEvent event) {
+ // do nothing
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleItemTreeStateProviderFactoryProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleItemTreeStateProviderFactoryProvider.java
new file mode 100644
index 0000000000..454e7040f4
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleItemTreeStateProviderFactoryProvider.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Straightforward implementation of {@link ItemTreeStateProviderFactoryProvider}.
+ */
+public class SimpleItemTreeStateProviderFactoryProvider
+ implements ItemTreeStateProviderFactoryProvider
+{
+ private final ItemTreeContentProviderFactory contentProviderFactory;
+ private final ItemExtendedLabelProviderFactory labelProviderFactory;
+
+
+ public SimpleItemTreeStateProviderFactoryProvider(
+ ItemTreeContentProviderFactory contentProviderFactory,
+ ItemExtendedLabelProviderFactory labelProviderFactory
+ ) {
+ super();
+ this.contentProviderFactory = contentProviderFactory;
+ this.labelProviderFactory = labelProviderFactory;
+ }
+
+ public ItemTreeContentProviderFactory getItemContentProviderFactory() {
+ return this.contentProviderFactory;
+ }
+
+ public ItemExtendedLabelProviderFactory getItemLabelProviderFactory() {
+ return this.labelProviderFactory;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleMessageTreeContent.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleMessageTreeContent.java
new file mode 100644
index 0000000000..ca019ef46e
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/SimpleMessageTreeContent.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Tree content with a root with a single child, the message that will be
+ * displayed in the tree widget.
+ * <p>
+ * To display a message in a {@link org.eclipse.jface.viewers.TreeViewer}:
+ * <pre>
+ * TreeViewer treeViewer = ...;
+ * treeViewer.setInput(null);
+ * treeViewer.setContentProvider(SimpleMessageTreeContent.contentProvider());
+ * treeViewer.setLabelProvider(SimpleMessageTreeContent.labelProvider());
+ * treeViewer.setInput(new SimpleMessageTreeContent("message"));
+ * </pre>
+ */
+public class SimpleMessageTreeContent {
+ private final String message;
+
+ public SimpleMessageTreeContent(String message) {
+ super();
+ this.message = message;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.message);
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+
+
+ // ********** tree content provider **********
+
+ public static ITreeContentProvider contentProvider() {
+ return CONTENT_PROVIDER;
+ }
+
+ private static final ITreeContentProvider CONTENT_PROVIDER = new ContentProvider();
+
+ /**
+ * Content provider for message tree content.
+ */
+ /* CU private */ static class ContentProvider
+ extends TreeContentProvider
+ {
+ @Override
+ public boolean hasChildren(Object element) {
+ return (element instanceof SimpleMessageTreeContent);
+ }
+
+ @Override
+ public Object[] getChildren(Object element) {
+ if (element instanceof SimpleMessageTreeContent) {
+ String msg = ((SimpleMessageTreeContent) element).getMessage();
+ return new Object[] { msg };
+ }
+ return EMPTY_ARRAY;
+ }
+ }
+
+
+ // ********** label provider **********
+
+ public static ILabelProvider labelProvider() {
+ return LABEL_PROVIDER;
+ }
+
+ private static final ILabelProvider LABEL_PROVIDER = new LabelProvider();
+
+ /**
+ * Label provider for message tree content.
+ */
+ /* CU private */ static class LabelProvider
+ extends org.eclipse.jface.viewers.LabelProvider
+ {
+ @Override
+ public String getText(Object element) {
+ return (element instanceof String) ? (String) element : null;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemExtendedLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemExtendedLabelProvider.java
new file mode 100644
index 0000000000..5033a00292
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemExtendedLabelProvider.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Item label provider that contains unchanging image, text, and description.
+ */
+public class StaticItemExtendedLabelProvider
+ extends StaticItemLabelProvider
+ implements ItemExtendedLabelProvider
+{
+ protected final String description;
+
+ /**
+ * Construct an item label provider that returns the specified text
+ * but no image. The provider will also return the specified text as the
+ * description.
+ */
+ public StaticItemExtendedLabelProvider(String text) {
+ this(null, text);
+ }
+
+ /**
+ * Construct an item label provider that returns the specified image
+ * and text. The provider will also return the specified text as the
+ * description.
+ */
+ public StaticItemExtendedLabelProvider(Image image, String text) {
+ this(image, text, text);
+ }
+
+ /**
+ * Construct an item label provider that returns the specified image, text,
+ * and description.
+ */
+ public StaticItemExtendedLabelProvider(Image image, String text, String description) {
+ super(image, text);
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemLabelProvider.java
new file mode 100644
index 0000000000..29415f13b3
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemLabelProvider.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Item label provider that contains unchanging image and text.
+ */
+public class StaticItemLabelProvider
+ implements ItemLabelProvider
+{
+ protected final Image image;
+ protected final String text;
+
+ /**
+ * Construct an item label provider that returns the specified text but
+ * no image.
+ */
+ public StaticItemLabelProvider(String text) {
+ this(null, text);
+ }
+
+ /**
+ * Construct an item label provider that returns the specified image
+ * and text.
+ */
+ public StaticItemLabelProvider(Image image, String text) {
+ super();
+ this.image = image;
+ this.text = text;
+ }
+
+ public Image getImage() {
+ return this.image;
+ }
+
+ public String getText() {
+ return this.text;
+ }
+
+ public void dispose() {
+ // NOP
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.text);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemTreeContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemTreeContentProvider.java
new file mode 100644
index 0000000000..4eddce1fa0
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StaticItemTreeContentProvider.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Item tree content provider that contains unchanging parent and children.
+ *
+ * @see org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Null
+ */
+public class StaticItemTreeContentProvider
+ implements ItemTreeContentProvider
+{
+ protected final Object parent;
+ protected final Object[] children;
+
+ /**
+ * Construct an item tree content provider for an item with neither
+ * a parent nor children.
+ */
+ public StaticItemTreeContentProvider() {
+ this(null);
+ }
+
+ /**
+ * Construct an item tree content provider for an item with the specified
+ * parent but no children.
+ */
+ public StaticItemTreeContentProvider(Object parent) {
+ this(parent, EMPTY_ARRAY);
+ }
+
+ /**
+ * Construct an item tree content provider for an item with the specified
+ * parent and children.
+ */
+ public StaticItemTreeContentProvider(Object parent, Object[] children) {
+ super();
+ if (children == null) {
+ throw new NullPointerException();
+ }
+ this.parent = parent;
+ this.children = children;
+ }
+
+ public Object[] getElements() {
+ return this.children;
+ }
+
+ public Object getParent() {
+ return this.parent;
+ }
+
+ public Object[] getChildren() {
+ return this.children;
+ }
+
+ public boolean hasChildren() {
+ return this.children.length > 0;
+ }
+
+ public void dispose() {
+ // NOP
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StructuredContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StructuredContentProvider.java
new file mode 100644
index 0000000000..891c15309b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/StructuredContentProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+
+/**
+ * Convenience implementation of {@link IStructuredContentProvider}.
+ */
+public class StructuredContentProvider
+ extends ContentProvider
+ implements IStructuredContentProvider
+{
+ private static final IStructuredContentProvider NULL_PROVIDER = new StructuredContentProvider();
+
+ public static IStructuredContentProvider nullProvider() {
+ return NULL_PROVIDER;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return EMPTY_ARRAY;
+ }
+
+ protected static final Object[] EMPTY_ARRAY = new Object[0];
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/TreeContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/TreeContentProvider.java
new file mode 100644
index 0000000000..86fcbcd311
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/TreeContentProvider.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.jface;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+
+/**
+ * Convenience implementation of {@link ITreeContentProvider}.
+ */
+public class TreeContentProvider
+ extends StructuredContentProvider
+ implements ITreeContentProvider
+{
+ private static final ITreeContentProvider NULL_PROVIDER = new TreeContentProvider();
+
+ public static ITreeContentProvider nullProvider() {
+ return NULL_PROVIDER;
+ }
+
+ @Override
+ public Object[] getElements(Object input) {
+ // typical tree implementation
+ return this.getChildren(input);
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Object[] getChildren(Object element) {
+ return EMPTY_ARRAY;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java
index 8918708bbf..8c94238d76 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,16 +9,19 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
-import org.eclipse.swt.widgets.Display;
/**
* Wrap another collection change listener and forward events to it on the SWT
* UI thread, asynchronously if necessary.
+ *
+ * @see SWTPropertyChangeListenerWrapper
*/
public class SWTCollectionChangeListenerWrapper
implements CollectionChangeListener
@@ -34,118 +37,105 @@ public class SWTCollectionChangeListenerWrapper
}
public void itemsAdded(CollectionAddEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.itemsAdded_(event);
- } else {
- this.executeOnUIThread(this.buildItemsAddedRunnable(event));
- }
- }
-
- public void itemsRemoved(CollectionRemoveEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.itemsRemoved_(event);
- } else {
- this.executeOnUIThread(this.buildItemsRemovedRunnable(event));
- }
+ this.execute(new ItemsAddedRunnable(event));
}
- public void collectionCleared(CollectionClearEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.collectionCleared_(event);
- } else {
- this.executeOnUIThread(this.buildCollectionClearedRunnable(event));
+ /* CU private */ class ItemsAddedRunnable
+ extends RunnableAdapter
+ {
+ private final CollectionAddEvent event;
+ ItemsAddedRunnable(CollectionAddEvent event) {
+ super();
+ this.event = event;
}
- }
-
- public void collectionChanged(CollectionChangeEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.collectionChanged_(event);
- } else {
- this.executeOnUIThread(this.buildCollectionChangedRunnable(event));
+ @Override
+ public void run() {
+ SWTCollectionChangeListenerWrapper.this.itemsAdded_(this.event);
}
}
- private Runnable buildItemsAddedRunnable(final CollectionAddEvent event) {
- return new Runnable() {
- public void run() {
- SWTCollectionChangeListenerWrapper.this.itemsAdded_(event);
- }
- @Override
- public String toString() {
- return "items added runnable"; //$NON-NLS-1$
- }
- };
+ void itemsAdded_(CollectionAddEvent event) {
+ this.listener.itemsAdded(event);
}
- private Runnable buildItemsRemovedRunnable(final CollectionRemoveEvent event) {
- return new Runnable() {
- public void run() {
- SWTCollectionChangeListenerWrapper.this.itemsRemoved_(event);
- }
- @Override
- public String toString() {
- return "items removed runnable"; //$NON-NLS-1$
- }
- };
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ this.execute(new ItemsRemovedRunnable(event));
}
- private Runnable buildCollectionClearedRunnable(final CollectionClearEvent event) {
- return new Runnable() {
- public void run() {
- SWTCollectionChangeListenerWrapper.this.collectionCleared_(event);
- }
- @Override
- public String toString() {
- return "collection cleared runnable"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class ItemsRemovedRunnable
+ extends RunnableAdapter
+ {
+ private final CollectionRemoveEvent event;
+ ItemsRemovedRunnable(CollectionRemoveEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTCollectionChangeListenerWrapper.this.itemsRemoved_(this.event);
+ }
}
- private Runnable buildCollectionChangedRunnable(final CollectionChangeEvent event) {
- return new Runnable() {
- public void run() {
- SWTCollectionChangeListenerWrapper.this.collectionChanged_(event);
- }
- @Override
- public String toString() {
- return "collection changed runnable"; //$NON-NLS-1$
- }
- };
+ void itemsRemoved_(CollectionRemoveEvent event) {
+ this.listener.itemsRemoved(event);
}
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
+ public void collectionCleared(CollectionClearEvent event) {
+ this.execute(new CollectionClearedRunnable(event));
}
- /**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
- * more predictable when debugging, at the risk of deadlocks.
- */
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
+ /* CU private */ class CollectionClearedRunnable
+ extends RunnableAdapter
+ {
+ private final CollectionClearEvent event;
+ CollectionClearedRunnable(CollectionClearEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTCollectionChangeListenerWrapper.this.collectionCleared_(this.event);
+ }
}
- void itemsAdded_(CollectionAddEvent event) {
- this.listener.itemsAdded(event);
+ void collectionCleared_(CollectionClearEvent event) {
+ this.listener.collectionCleared(event);
}
- void itemsRemoved_(CollectionRemoveEvent event) {
- this.listener.itemsRemoved(event);
+ public void collectionChanged(CollectionChangeEvent event) {
+ this.execute(new CollectionChangedRunnable(event));
}
- void collectionCleared_(CollectionClearEvent event) {
- this.listener.collectionCleared(event);
+ /* CU private */ class CollectionChangedRunnable
+ extends RunnableAdapter
+ {
+ private final CollectionChangeEvent event;
+ CollectionChangedRunnable(CollectionChangeEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTCollectionChangeListenerWrapper.this.collectionChanged_(this.event);
+ }
}
void collectionChanged_(CollectionChangeEvent event) {
this.listener.collectionChanged(event);
}
+ /**
+ * {@link SWTUtil#execute(Runnable)} seems to work OK;
+ * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * more predictable when debugging, at the risk of deadlocks.
+ */
+ private void execute(Runnable r) {
+ SWTUtil.execute(r);
+// SWTUtil.syncExec(r);
+ }
+
@Override
public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
+ return "SWT(" + this.listener + ')'; //$NON-NLS-1$
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java
index 321080dfc5..3037b60e79 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTListChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
@@ -16,11 +18,12 @@ import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
-import org.eclipse.swt.widgets.Display;
/**
* Wrap another list change listener and forward events to it on the SWT
* UI thread, asynchronously if necessary.
+ *
+ * @see SWTPropertyChangeListenerWrapper
*/
public class SWTListChangeListenerWrapper
implements ListChangeListener
@@ -36,166 +39,149 @@ public class SWTListChangeListenerWrapper
}
public void itemsAdded(ListAddEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.itemsAdded_(event);
- } else {
- this.executeOnUIThread(this.buildItemsAddedRunnable(event));
- }
+ this.execute(new ItemsAddedRunnable(event));
}
- public void itemsRemoved(ListRemoveEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.itemsRemoved_(event);
- } else {
- this.executeOnUIThread(this.buildItemsRemovedRunnable(event));
+ /* CU private */ class ItemsAddedRunnable
+ extends RunnableAdapter
+ {
+ private final ListAddEvent event;
+ ItemsAddedRunnable(ListAddEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTListChangeListenerWrapper.this.itemsAdded_(this.event);
}
}
- public void itemsMoved(ListMoveEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.itemsMoved_(event);
- } else {
- this.executeOnUIThread(this.buildItemsMovedRunnable(event));
- }
+ void itemsAdded_(ListAddEvent event) {
+ this.listener.itemsAdded(event);
}
- public void itemsReplaced(ListReplaceEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.itemsReplaced_(event);
- } else {
- this.executeOnUIThread(this.buildItemsReplacedRunnable(event));
- }
+ public void itemsRemoved(ListRemoveEvent event) {
+ this.execute(new ItemsRemovedRunnable(event));
}
- public void listCleared(ListClearEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.listCleared_(event);
- } else {
- this.executeOnUIThread(this.buildListClearedRunnable(event));
+ /* CU private */ class ItemsRemovedRunnable
+ extends RunnableAdapter
+ {
+ private final ListRemoveEvent event;
+ ItemsRemovedRunnable(ListRemoveEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTListChangeListenerWrapper.this.itemsRemoved_(this.event);
}
}
- public void listChanged(ListChangeEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.listChanged_(event);
- } else {
- this.executeOnUIThread(this.buildListChangedRunnable(event));
- }
+ void itemsRemoved_(ListRemoveEvent event) {
+ this.listener.itemsRemoved(event);
}
- private Runnable buildItemsAddedRunnable(final ListAddEvent event) {
- return new Runnable() {
- public void run() {
- SWTListChangeListenerWrapper.this.itemsAdded_(event);
- }
- @Override
- public String toString() {
- return "items added runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildItemsRemovedRunnable(final ListRemoveEvent event) {
- return new Runnable() {
- public void run() {
- SWTListChangeListenerWrapper.this.itemsRemoved_(event);
- }
- @Override
- public String toString() {
- return "items removed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildItemsMovedRunnable(final ListMoveEvent event) {
- return new Runnable() {
- public void run() {
- SWTListChangeListenerWrapper.this.itemsMoved_(event);
- }
- @Override
- public String toString() {
- return "items moved runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildItemsReplacedRunnable(final ListReplaceEvent event) {
- return new Runnable() {
- public void run() {
- SWTListChangeListenerWrapper.this.itemsReplaced_(event);
- }
- @Override
- public String toString() {
- return "items replaced runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildListClearedRunnable(final ListClearEvent event) {
- return new Runnable() {
- public void run() {
- SWTListChangeListenerWrapper.this.listCleared_(event);
- }
- @Override
- public String toString() {
- return "list cleared runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildListChangedRunnable(final ListChangeEvent event) {
- return new Runnable() {
- public void run() {
- SWTListChangeListenerWrapper.this.listChanged_(event);
- }
- @Override
- public String toString() {
- return "list changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
+ public void itemsMoved(ListMoveEvent event) {
+ this.execute(new ItemsMovedRunnable(event));
}
- /**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
- * more predictable when debugging, at the risk of deadlocks.
- */
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
+ /* CU private */ class ItemsMovedRunnable
+ extends RunnableAdapter
+ {
+ private final ListMoveEvent event;
+ ItemsMovedRunnable(ListMoveEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTListChangeListenerWrapper.this.itemsMoved_(this.event);
+ }
}
- void itemsAdded_(ListAddEvent event) {
- this.listener.itemsAdded(event);
+ void itemsMoved_(ListMoveEvent event) {
+ this.listener.itemsMoved(event);
}
- void itemsRemoved_(ListRemoveEvent event) {
- this.listener.itemsRemoved(event);
+ public void itemsReplaced(ListReplaceEvent event) {
+ this.execute(new ItemsReplacedRunnable(event));
}
- void itemsMoved_(ListMoveEvent event) {
- this.listener.itemsMoved(event);
+ /* CU private */ class ItemsReplacedRunnable
+ extends RunnableAdapter
+ {
+ private final ListReplaceEvent event;
+ ItemsReplacedRunnable(ListReplaceEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTListChangeListenerWrapper.this.itemsReplaced_(this.event);
+ }
+ }
+
+ public void listCleared(ListClearEvent event) {
+ this.execute(new ListClearedRunnable(event));
}
void itemsReplaced_(ListReplaceEvent event) {
this.listener.itemsReplaced(event);
}
+ /* CU private */ class ListClearedRunnable
+ extends RunnableAdapter
+ {
+ private final ListClearEvent event;
+ ListClearedRunnable(ListClearEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTListChangeListenerWrapper.this.listCleared_(this.event);
+ }
+ }
+
void listCleared_(ListClearEvent event) {
this.listener.listCleared(event);
}
+ public void listChanged(ListChangeEvent event) {
+ this.execute(new ListChangedRunnable(event));
+ }
+
+ /* CU private */ class ListChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ListChangeEvent event;
+ ListChangedRunnable(ListChangeEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTListChangeListenerWrapper.this.listChanged_(this.event);
+ }
+ }
+
void listChanged_(ListChangeEvent event) {
this.listener.listChanged(event);
}
+ /**
+ * {@link SWTUtil#execute(Runnable)} seems to work OK;
+ * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * more predictable when debugging, at the risk of deadlocks.
+ */
+ private void execute(Runnable r) {
+ SWTUtil.execute(r);
+// SWTUtil.syncExec(r);
+ }
+
@Override
public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
+ return "SWT(" + this.listener + ')'; //$NON-NLS-1$
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java
index f95fbe6005..a12e215685 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,9 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.swt.widgets.Display;
/**
* Wrap another property change listener and forward events to it on the SWT
@@ -37,46 +38,39 @@ public class SWTPropertyChangeListenerWrapper
}
public void propertyChanged(PropertyChangeEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.propertyChanged_(event);
- } else {
- this.executeOnUIThread(this.buildPropertyChangedRunnable(event));
- }
+ this.execute(new PropertyChangedRunnable(event));
}
- private Runnable buildPropertyChangedRunnable(final PropertyChangeEvent event) {
- return new Runnable() {
- public void run() {
- SWTPropertyChangeListenerWrapper.this.propertyChanged_(event);
- }
- @Override
- public String toString() {
- return "property changed runnable"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class PropertyChangedRunnable
+ extends RunnableAdapter
+ {
+ private final PropertyChangeEvent event;
+ PropertyChangedRunnable(PropertyChangeEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTPropertyChangeListenerWrapper.this.propertyChanged_(this.event);
+ }
}
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
+ void propertyChanged_(PropertyChangeEvent event) {
+ this.listener.propertyChanged(event);
}
/**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
+ * {@link SWTUtil#execute(Runnable)} seems to work OK;
+ * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
- }
-
- void propertyChanged_(PropertyChangeEvent event) {
- this.listener.propertyChanged(event);
+ private void execute(Runnable r) {
+ SWTUtil.execute(r);
+// SWTUtil.syncExec(r);
}
@Override
public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
+ return "SWT(" + this.listener + ')'; //$NON-NLS-1$
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
index 16bf1194db..7437bf48b2 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTStateChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,16 +9,16 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.listeners;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
-import org.eclipse.swt.widgets.Display;
/**
* Wrap another state change listener and forward events to it on the SWT
- * UI thread, asynchronously if necessary. If the event arrived on the UI
- * thread that is probably because it was initiated by a UI widget; as a
- * result, we want to loop back synchronously so the events can be
- * short-circuited.
+ * UI thread, asynchronously if necessary.
+ *
+ * @see SWTPropertyChangeListenerWrapper
*/
public class SWTStateChangeListenerWrapper
implements StateChangeListener
@@ -34,46 +34,39 @@ public class SWTStateChangeListenerWrapper
}
public void stateChanged(StateChangeEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.stateChanged_(event);
- } else {
- this.executeOnUIThread(this.buildStateChangedRunnable(event));
- }
+ this.execute(new StateChangedRunnable(event));
}
- private Runnable buildStateChangedRunnable(final StateChangeEvent event) {
- return new Runnable() {
- public void run() {
- SWTStateChangeListenerWrapper.this.stateChanged_(event);
- }
- @Override
- public String toString() {
- return "state changed runnable"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class StateChangedRunnable
+ extends RunnableAdapter
+ {
+ private final StateChangeEvent event;
+ StateChangedRunnable(StateChangeEvent event) {
+ super();
+ this.event = event;
+ }
+ @Override
+ public void run() {
+ SWTStateChangeListenerWrapper.this.stateChanged_(this.event);
+ }
}
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
+ void stateChanged_(StateChangeEvent event) {
+ this.listener.stateChanged(event);
}
/**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
+ * {@link SWTUtil#execute(Runnable)} seems to work OK;
+ * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
* more predictable when debugging, at the risk of deadlocks.
*/
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
- }
-
- void stateChanged_(StateChangeEvent event) {
- this.listener.stateChanged(event);
+ private void execute(Runnable r) {
+ SWTUtil.execute(r);
+// SWTUtil.syncExec(r);
}
@Override
public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
+ return "SWT(" + this.listener + ')'; //$NON-NLS-1$
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTTreeChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTTreeChangeListenerWrapper.java
deleted file mode 100644
index 84255e6fd9..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/listeners/SWTTreeChangeListenerWrapper.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.internal.listeners;
-
-import org.eclipse.jpt.common.utility.model.event.TreeAddEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeClearEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Wrap another tree change listener and forward events to it on the SWT
- * UI thread, asynchronously if necessary.
- */
-public class SWTTreeChangeListenerWrapper
- implements TreeChangeListener
-{
- private final TreeChangeListener listener;
-
- public SWTTreeChangeListenerWrapper(TreeChangeListener listener) {
- super();
- if (listener == null) {
- throw new NullPointerException();
- }
- this.listener = listener;
- }
-
- public void nodeAdded(TreeAddEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.nodeAdded_(event);
- } else {
- this.executeOnUIThread(this.buildNodeAddedRunnable(event));
- }
- }
-
- public void nodeRemoved(TreeRemoveEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.nodeRemoved_(event);
- } else {
- this.executeOnUIThread(this.buildNodeRemovedRunnable(event));
- }
- }
-
- public void treeCleared(TreeClearEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.treeCleared_(event);
- } else {
- this.executeOnUIThread(this.buildTreeClearedRunnable(event));
- }
- }
-
- public void treeChanged(TreeChangeEvent event) {
- if (this.isExecutingOnUIThread()) {
- this.treeChanged_(event);
- } else {
- this.executeOnUIThread(this.buildTreeChangedRunnable(event));
- }
- }
-
- private Runnable buildNodeAddedRunnable(final TreeAddEvent event) {
- return new Runnable() {
- public void run() {
- SWTTreeChangeListenerWrapper.this.nodeAdded_(event);
- }
- @Override
- public String toString() {
- return "node added runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildNodeRemovedRunnable(final TreeRemoveEvent event) {
- return new Runnable() {
- public void run() {
- SWTTreeChangeListenerWrapper.this.nodeRemoved_(event);
- }
- @Override
- public String toString() {
- return "node removed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildTreeClearedRunnable(final TreeClearEvent event) {
- return new Runnable() {
- public void run() {
- SWTTreeChangeListenerWrapper.this.treeCleared_(event);
- }
- @Override
- public String toString() {
- return "tree cleared runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildTreeChangedRunnable(final TreeChangeEvent event) {
- return new Runnable() {
- public void run() {
- SWTTreeChangeListenerWrapper.this.treeChanged_(event);
- }
- @Override
- public String toString() {
- return "tree changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
- }
-
- /**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
- * more predictable when debugging, at the risk of deadlocks.
- */
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
- }
-
- void nodeAdded_(TreeAddEvent event) {
- this.listener.nodeAdded(event);
- }
-
- void nodeRemoved_(TreeRemoveEvent event) {
- this.listener.nodeRemoved(event);
- }
-
- void treeCleared_(TreeClearEvent event) {
- this.listener.treeCleared(event);
- }
-
- void treeChanged_(TreeChangeEvent event) {
- this.listener.treeChanged(event);
- }
-
- @Override
- public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java
index 05e5bd5767..b338393dc4 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/properties/JptProjectPropertiesPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -28,12 +28,12 @@ import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.model.value.BufferedWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.listener.SimpleChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.AbstractChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jst.common.project.facet.core.libprov.IPropertyChangeListener;
@@ -42,7 +42,6 @@ import org.eclipse.jst.common.project.facet.ui.libprov.LibraryFacetPropertyPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -53,128 +52,132 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.ui.internal.FacetsPropertyPage;
public abstract class JptProjectPropertiesPage
extends LibraryFacetPropertyPage {
-
+
protected final WritablePropertyValueModel<IProject> projectModel;
protected final BufferedWritablePropertyValueModel.Trigger trigger;
-
+
protected final ChangeListener validationListener;
-
-
+
+
public JptProjectPropertiesPage() {
super();
this.projectModel = new SimplePropertyValueModel<IProject>();
this.trigger = new BufferedWritablePropertyValueModel.Trigger();
-
- buildModels();
-
+
+ this.buildModels();
+
this.validationListener = this.buildValidationListener();
}
-
-
+
+
/**
* Build any additional models needed by this page. The project model has been created at this
* point.
*/
protected abstract void buildModels();
-
-
+
+
// ********** convenience methods **********
-
- protected static boolean flagIsSet(PropertyValueModel<Boolean> flagModel) {
+
+ public static boolean flagIsSet(PropertyValueModel<Boolean> flagModel) {
Boolean flag = flagModel.getValue();
return (flag != null) && flag.booleanValue();
}
-
-
+
+
// ********** LibraryFacetPropertyPage implementation **********
-
-
protected IPropertyChangeListener buildLibraryProviderListener() {
- return new IPropertyChangeListener() {
- public void propertyChanged(String property, Object oldValue, Object newValue ) {
- if (LibraryInstallDelegate.PROP_AVAILABLE_PROVIDERS.equals(property)) {
- adjustLibraryProviders();
- }
- }
- };
- }
-
+ return new LibraryProviderListener();
+ }
+
+ protected class LibraryProviderListener
+ implements IPropertyChangeListener
+ {
+ public void propertyChanged(String property, Object oldValue, Object newValue ) {
+ if (LibraryInstallDelegate.PROP_AVAILABLE_PROVIDERS.equals(property)) {
+ JptProjectPropertiesPage.this.adjustLibraryProviders();
+ }
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
protected abstract void adjustLibraryProviders();
-
-
+
+
// ********** page **********
@Override
protected Control createPageContents(Composite parent) {
if (this.projectModel.getValue() != null) {
- disengageListeners();
+ this.disengageListeners();
}
-
- this.projectModel.setValue(getProject());
-
+
+ this.projectModel.setValue(this.getProject());
+
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
-
- createWidgets(composite);
-
+
+ this.createWidgets(composite);
+
Dialog.applyDialogFont(composite);
-
- adjustLibraryProviders();
-
- engageListeners();
- updateValidation();
+
+ this.adjustLibraryProviders();
+
+ this.engageListeners();
+ this.updateValidation();
return composite;
}
-
+
/**
* Build specific widgets. Layout and validation will be taken care of.
*/
protected abstract void createWidgets(Composite parent);
-
+
protected void engageListeners() {
- engageValidationListener();
+ this.engageValidationListener();
}
-
+
protected void disengageListeners() {
- disengageValidationListener();
+ this.disengageValidationListener();
}
-
+
protected Link buildFacetsPageLink(Composite parent, String text) {
- Link facetsPageLink = buildLink(parent, text);
- facetsPageLink.addSelectionListener(buildFacetsPageLinkListener()); // the link will be GCed
+ Link facetsPageLink = this.buildLink(parent, text);
+ facetsPageLink.addSelectionListener(new FacetsPageLinkListener()); // the link will be GCed
return facetsPageLink;
}
-
- private SelectionListener buildFacetsPageLinkListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- openProjectFacetsPage();
- }
- @Override
- public String toString() {
- return "facets page link listener"; //$NON-NLS-1$
- }
- };
+
+ /* CU private */ class FacetsPageLinkListener
+ extends SelectionAdapter
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ JptProjectPropertiesPage.this.openProjectFacetsPage();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
-
+
protected void openProjectFacetsPage() {
- ((IWorkbenchPreferenceContainer)getContainer()).openPage(FacetsPropertyPage.ID, null);
+ ((IWorkbenchPreferenceContainer)this.getContainer()).openPage(FacetsPropertyPage.ID, null);
}
-
+
/**
* Don't allow {@link org.eclipse.jface.preference.PreferencePage#computeSize()}
* to cache the page's size, since the size of the "Library" panel can
@@ -184,18 +187,18 @@ public abstract class JptProjectPropertiesPage
public Point computeSize() {
return this.doComputeSize();
}
-
-
+
+
// ********** widgets **********
-
+
protected Button buildCheckBox(Composite parent, int horizontalSpan, String text) {
- return buildButton(parent, horizontalSpan, text, SWT.CHECK);
+ return this.buildButton(parent, horizontalSpan, text, SWT.CHECK);
}
-
+
protected Button buildRadioButton(Composite parent, int horizontalSpan, String text) {
- return buildButton(parent, horizontalSpan, text, SWT.RADIO);
+ return this.buildButton(parent, horizontalSpan, text, SWT.RADIO);
}
-
+
protected Button buildButton(Composite parent, int horizontalSpan, String text, int style) {
Button button = new Button(parent, SWT.NONE | style);
button.setText(text);
@@ -204,11 +207,11 @@ public abstract class JptProjectPropertiesPage
button.setLayoutData(gd);
return button;
}
-
+
protected Combo buildDropDown(Composite parent) {
- return buildDropDown(parent, 1);
+ return this.buildDropDown(parent, 1);
}
-
+
protected Combo buildDropDown(Composite parent, int horizontalSpan) {
Combo combo = new Combo(parent, SWT.READ_ONLY);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
@@ -216,7 +219,7 @@ public abstract class JptProjectPropertiesPage
combo.setLayoutData(gd);
return combo;
}
-
+
protected Label buildLabel(Composite parent, String text) {
Label label = new Label(parent, SWT.LEFT);
label.setText(text);
@@ -225,7 +228,7 @@ public abstract class JptProjectPropertiesPage
label.setLayoutData(gd);
return label;
}
-
+
protected Link buildLink(Composite parent, String text) {
Link link = new Link(parent, SWT.NONE);
GridData data = new GridData(GridData.END, GridData.CENTER, false, false);
@@ -234,8 +237,8 @@ public abstract class JptProjectPropertiesPage
link.setText(text);
return link;
}
-
-
+
+
// ********** OK/Revert/Apply behavior **********
@Override
@@ -247,8 +250,10 @@ public abstract class JptProjectPropertiesPage
this.buildOkProgressMonitorDialog().run(true, false, this.buildOkRunnableWithProgress());
}
catch (InterruptedException ex) {
+ // should *not* happen...
+ Thread.currentThread().interrupt();
return false;
- }
+ }
catch (InvocationTargetException ex) {
throw new RuntimeException(ex.getTargetException());
}
@@ -256,172 +261,189 @@ public abstract class JptProjectPropertiesPage
return true;
}
- private IRunnableContext buildOkProgressMonitorDialog() {
+ protected IRunnableContext buildOkProgressMonitorDialog() {
return new ProgressMonitorDialog(this.getShell());
}
- private IRunnableWithProgress buildOkRunnableWithProgress() {
- return new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- IWorkspace ws = ResourcesPlugin.getWorkspace();
- try {
- // the build we execute in #performOk_() locks the workspace root,
- // so we need to use the workspace root as our scheduling rule here
- ws.run(
- buildOkWorkspaceRunnable(),
- ws.getRoot(),
- IWorkspace.AVOID_UPDATE,
- monitor);
- }
- catch (CoreException ex) {
- throw new InvocationTargetException(ex);
- }
- }
- };
+ protected IRunnableWithProgress buildOkRunnableWithProgress() {
+ return new OkRunnableWithProgress();
}
-
- /* private */ IWorkspaceRunnable buildOkWorkspaceRunnable() {
- return new IWorkspaceRunnable() {
+
+ protected class OkRunnableWithProgress
+ implements IRunnableWithProgress
+ {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ IWorkspace ws = ResourcesPlugin.getWorkspace();
+ try {
+ // the build we execute in #performOk_() locks the workspace root,
+ // so we need to use the workspace root as our scheduling rule here
+ ws.run(
+ new OkWorkspaceRunnable(),
+ ws.getRoot(),
+ IWorkspace.AVOID_UPDATE,
+ monitor
+ );
+ } catch (CoreException ex) {
+ throw new InvocationTargetException(ex);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+ /* class private */ class OkWorkspaceRunnable
+ implements IWorkspaceRunnable
+ {
public void run(IProgressMonitor monitor) throws CoreException {
- performOk_(monitor);
+ JptProjectPropertiesPage.this.performOk_(monitor);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
}
- };
+ }
}
-
+
+
// ********** OK/Revert/Apply behavior **********
-
- void performOk_(IProgressMonitor monitor) throws CoreException {
- if (isBuffering()) {
- boolean rebuild = projectRebuildRequired();
+
+ /* CU private */ void performOk_(IProgressMonitor monitor) throws CoreException {
+ if (this.isBuffering()) {
+ boolean rebuild = this.projectRebuildRequired();
this.trigger.accept();
if (rebuild) {
- rebuildProject();
+ this.rebuildProject();
}
this.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
}
}
-
+
protected abstract boolean projectRebuildRequired();
-
- protected abstract void rebuildProject();
-
+
+ protected abstract void rebuildProject() throws CoreException;
+
/**
* Return whether any of the models are buffering a change.
*/
private boolean isBuffering() {
- for (BufferedWritablePropertyValueModel<?> model : buildBufferedModels()) {
+ for (BufferedWritablePropertyValueModel<?> model : this.buildBufferedModels()) {
if (model.isBuffering()) {
return true;
}
}
return false;
}
-
+
protected abstract BufferedWritablePropertyValueModel<?>[] buildBufferedModels();
-
+
@Override
protected void performDefaults() {
super.performDefaults();
this.trigger.reset();
}
-
-
+
+
// ********** dispose **********
-
+
@Override
public void dispose() {
- disengageListeners();
+ this.disengageListeners();
super.dispose();
}
-
-
+
+
// ********** validation **********
-
+
private ChangeListener buildValidationListener() {
- return new SimpleChangeListener() {
- @Override
- protected void modelChanged() {
- validate();
- }
- @Override
- public String toString() {
- return "validation listener"; //$NON-NLS-1$
- }
- };
+ return new ValidationListener();
}
-
+
+ /* CU private */ class ValidationListener
+ extends AbstractChangeListener
+ {
+ @Override
+ protected void modelChanged() {
+ JptProjectPropertiesPage.this.validate();
+ }
+ }
+
protected void validate() {
- if ( ! getControl().isDisposed()) {
- updateValidation();
+ if ( ! this.getControl().isDisposed()) {
+ this.updateValidation();
}
}
private void engageValidationListener() {
- for (Model model : buildValidationModels()) {
+ for (Model model : this.buildValidationModels()) {
model.addChangeListener(this.validationListener);
}
}
-
+
protected abstract Model[] buildValidationModels();
-
+
private void disengageValidationListener() {
- for (Model model : buildReverseValidationModels()) {
+ for (Model model : this.buildReverseValidationModels()) {
model.removeChangeListener(this.validationListener);
}
}
-
+
protected Model[] buildReverseValidationModels() {
- return ArrayTools.reverse(buildValidationModels());
+ return ArrayTools.reverse(this.buildValidationModels());
}
protected static final Integer ERROR_STATUS = Integer.valueOf(IStatus.ERROR);
protected static final Integer WARNING_STATUS = Integer.valueOf(IStatus.WARNING);
protected static final Integer INFO_STATUS = Integer.valueOf(IStatus.INFO);
protected static final Integer OK_STATUS = Integer.valueOf(IStatus.OK);
-
+
protected IStatus buildInfoStatus(String message) {
return this.buildStatus(IStatus.INFO, message);
}
-
+
protected IStatus buildWarningStatus(String message) {
return this.buildStatus(IStatus.WARNING, message);
}
-
+
protected IStatus buildErrorStatus(String message) {
return this.buildStatus(IStatus.ERROR, message);
}
-
+
protected IStatus buildStatus(int severity, String message) {
return new Status(severity, JptCommonCorePlugin.PLUGIN_ID, message);
}
-
+
@Override
protected IStatus performValidation() {
HashMap<Integer, ArrayList<IStatus>> statuses = new HashMap<Integer, ArrayList<IStatus>>();
statuses.put(ERROR_STATUS, new ArrayList<IStatus>());
statuses.put(WARNING_STATUS, new ArrayList<IStatus>());
statuses.put(INFO_STATUS, new ArrayList<IStatus>());
- statuses.put(OK_STATUS, CollectionTools.list(Status.OK_STATUS));
-
- performValidation(statuses);
-
- if ( ! statuses.get(ERROR_STATUS).isEmpty()) {
- return statuses.get(ERROR_STATUS).get(0);
- }
- else if ( ! statuses.get(WARNING_STATUS).isEmpty()) {
- return statuses.get(WARNING_STATUS).get(0);
+ statuses.put(OK_STATUS, new ArrayList<IStatus>());
+
+ /* library provider */
+ this.addStatus(super.performValidation(), statuses);
+ this.performValidation(statuses);
+
+ ArrayList<IStatus> list = statuses.get(ERROR_STATUS);
+ if ( ! list.isEmpty()) {
+ return list.get(0);
}
- else if ( ! statuses.get(INFO_STATUS).isEmpty()) {
- return statuses.get(INFO_STATUS).get(0);
+ list = statuses.get(WARNING_STATUS);
+ if ( ! list.isEmpty()) {
+ return list.get(0);
}
- else {
- return statuses.get(OK_STATUS).get(0);
+ list = statuses.get(INFO_STATUS);
+ if ( ! list.isEmpty()) {
+ return list.get(0);
}
+ return Status.OK_STATUS;
}
-
- protected void performValidation(Map<Integer, ArrayList<IStatus>> statuses) {
- /* library provider */
- IStatus lpStatus = super.performValidation();
- statuses.get(Integer.valueOf(lpStatus.getSeverity())).add(lpStatus);
+
+ protected abstract void performValidation(Map<Integer, ArrayList<IStatus>> statuses);
+
+ protected void addStatus(IStatus status, Map<Integer, ArrayList<IStatus>> statuses) {
+ statuses.get(Integer.valueOf(status.getSeverity())).add(status);
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/DisposeAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/DisposeAdapter.java
new file mode 100644
index 0000000000..a765a55feb
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/DisposeAdapter.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.swt;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+
+/**
+ * Convenience SWT dispose listener.
+ */
+public class DisposeAdapter
+ implements DisposeListener
+{
+ public void widgetDisposed(DisposeEvent e) {
+ // NOP
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java
index fe2063799f..743d8745e4 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/util/SWTUtil.java
@@ -18,6 +18,7 @@ import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
@@ -35,23 +36,97 @@ import org.eclipse.ui.forms.widgets.ScrolledForm;
public class SWTUtil {
/**
- * Causes the <code>run()</code> method of the given runnable to be invoked
- * by the user-interface thread at the next reasonable opportunity. The caller
- * of this method continues to run in parallel, and is not notified when the
- * runnable has completed.
- *
- * @param runnable Code to run on the user-interface thread
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @see #syncExec
+ * @see Display#asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ * @see #execute(Runnable)
*/
public static void asyncExec(Runnable runnable) {
getStandardDisplay().asyncExec(runnable);
}
/**
+ * @see Display#syncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #execute(Runnable)
+ */
+ public static void syncExec(Runnable runnable) {
+ getStandardDisplay().syncExec(runnable);
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the UI thread;
+ * otherwise asynchrounously dispatch the runnable to the UI thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the UI thread.
+ *
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ */
+ public static void execute(Runnable runnable) {
+ Display display = Display.getCurrent();
+ if (display != null) {
+ // the current thread is the UI thread
+ runnable.run();
+ } else {
+ Display.getDefault().asyncExec(runnable);
+ }
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the specified
+ * viewer's thread;
+ * otherwise asynchrounously dispatch the runnable to the viewer's thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the viewer's thread.
+ *
+ * @see #execute(Runnable)
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ */
+ public static void execute(Viewer viewer, Runnable runnable) {
+ execute(viewer.getControl(), runnable);
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the specified
+ * control's thread;
+ * otherwise asynchrounously dispatch the runnable to the control's thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the control's thread.
+ *
+ * @see #execute(Runnable)
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ */
+ public static void execute(Control control, Runnable runnable) {
+ execute(control.getDisplay(), runnable);
+ }
+
+ /**
+ * Execute the specified runnable if the current thread is the specified
+ * display's thread;
+ * otherwise asynchrounously dispatch the runnable to the display's thread,
+ * returning immediately. This is useful for event handlers when it is not
+ * obviously whether the events are fired on the display's thread.
+ *
+ * @see #execute(Runnable)
+ * @see Display#asyncExec(Runnable)
+ * @see #asyncExec(Runnable)
+ * @see #syncExec(Runnable)
+ */
+ public static void execute(Display display, Runnable runnable) {
+ if (display.getThread() == Thread.currentThread()) {
+ // the current thread is the display's thread
+ runnable.run();
+ } else {
+ display.asyncExec(runnable);
+ }
+ }
+
+ /**
* Tweaks the given <code>Combo</code> to remove the default value when the
* widget receives the focus and to show the default when the widget loses
* the focus.
@@ -73,40 +148,26 @@ public class SWTUtil {
* @return The shell, never <code>null</code>
*/
public static Shell getShell() {
-
// Retrieve the active shell, which can be the shell from any window
Shell shell = getStandardDisplay().getActiveShell();
-
- // No shell could be found, revert back to the active workbench window
- if (shell == null) {
- shell = getWorkbench().getActiveWorkbenchWindow().getShell();
- }
-
- // Make sure it's never null
- if (shell == null) {
- shell = new Shell(getStandardDisplay().getActiveShell());
+ if (shell != null) {
+ return shell;
}
- return shell;
+ // No shell could be found, revert back to the active workbench window
+ shell = getWorkbench().getActiveWorkbenchWindow().getShell();
+ return (shell != null) ? shell : new Shell();
}
/**
- * Returns the standard display to be used. The method first checks, if the
- * thread calling this method has an associated display. If so, this display
- * is returned. Otherwise the method returns the default display.
- *
- * @return The current display if not <code>null</code> otherwise the default
- * display is returned
+ * Return the "standard" {@link Display display}. Return the
+ * {@link Display#getCurrent() display associated with the current thread}
+ * if it is present; otherwise return the
+ * {@link Display#getDefault() default display}.
*/
- public static Display getStandardDisplay()
- {
+ public static Display getStandardDisplay() {
Display display = Display.getCurrent();
-
- if (display == null) {
- display = Display.getDefault();
- }
-
- return display;
+ return (display != null) ? display : Display.getDefault();
}
public static int getTableHeightHint(Table table, int rows) {
@@ -166,25 +227,13 @@ public class SWTUtil {
/**
- * Causes the <code>run()</code> method of the given runnable to be invoked
- * by the user-interface thread at the next reasonable opportunity. The
- * thread which calls this method is suspended until the runnable completes.
- *
- * @param runnable code to run on the user-interface thread.
- * @see #asyncExec
- */
- public static void syncExec(Runnable runnable) {
- getStandardDisplay().syncExec(runnable);
- }
-
- /**
* Determines if the current thread is the UI event thread.
*
* @return <code>true</code> if it's the UI event thread, <code>false</code>
* otherwise
*/
public static boolean uiThread() {
- return getStandardDisplay().getThread() == Thread.currentThread();
+ return Display.getCurrent() != null;
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandExecutor.java
new file mode 100644
index 0000000000..ec8ffd6dcb
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AbstractUiCommandExecutor.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.utility;
+
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
+import org.eclipse.jpt.common.utility.internal.command.SynchronizingCommand;
+
+/**
+ * Gather the tiny bit of common behavior.
+ */
+abstract class AbstractUiCommandExecutor
+ implements ExtendedCommandExecutor
+{
+ AbstractUiCommandExecutor() {
+ super();
+ }
+
+ Runnable buildRunnable(Command command) {
+ return new CommandRunnable(command);
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
+
+ /**
+ * A common way to put a time constraint on a command dispatched
+ * to the UI thread.
+ */
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ if (timeout == 0L) {
+ this.waitToExecute(command);
+ return true;
+ }
+
+ // configure the sync command to execute the client command
+ SynchronizingCommand syncCommand = new SynchronizingCommand(command);
+
+ // dispatch the sync command to the UI thread...
+ SWTUtil.asyncExec(this.buildRunnable(syncCommand));
+
+ // ...and wait for it to execute
+ try {
+ return syncCommand.waitForExecution(timeout);
+ } finally {
+ syncCommand.release();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandExecutor.java
index 9a8b3aa0d8..d905f53b5d 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandExecutor.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/AsynchronousUiCommandExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,22 +9,23 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.utility;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
/**
- * This implementation of CommandExecutor can be used by a non-UI
- * thread to asynchronously modify a JPA project with any objects associated
- * with documents that are currently displayed in the UI.
+ * This command executor asynchronously executes a {@link Command command}
+ * on the UI thread.
+ * <p>
+ * This command executor allows a non-UI process to modify any objects
+ * associated with documents that are currently displayed in the UI.
*/
public final class AsynchronousUiCommandExecutor
- implements CommandExecutor
+ extends AbstractUiCommandExecutor
{
- public static final CommandExecutor INSTANCE = new AsynchronousUiCommandExecutor();
+ public static final ExtendedCommandExecutor INSTANCE = new AsynchronousUiCommandExecutor();
- public static CommandExecutor instance() {
+ public static ExtendedCommandExecutor instance() {
return INSTANCE;
}
@@ -34,16 +35,10 @@ public final class AsynchronousUiCommandExecutor
}
public void execute(Command command) {
- this.getDisplay().asyncExec(this.buildRunnable(command));
+ SWTUtil.asyncExec(this.buildRunnable(command));
}
- private Runnable buildRunnable(Command command) {
- return new CommandRunnable(command);
+ public void waitToExecute(Command command) {
+ SWTUtil.syncExec(this.buildRunnable(command));
}
-
- private Display getDisplay() {
- Display display = Display.getCurrent();
- return (display != null) ? display : Display.getDefault();
- }
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PageAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PageAdapter.java
new file mode 100644
index 0000000000..ff7494bf92
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PageAdapter.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.utility;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.ui.IPageListener;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * Convenience implementation of {@link IPageListener}.
+ */
+public class PageAdapter
+ implements IPageListener
+{
+ public void pageOpened(IWorkbenchPage page) {
+ // do nothing
+ }
+ public void pageActivated(IWorkbenchPage page) {
+ // do nothing
+ }
+ public void pageClosed(IWorkbenchPage page) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter.java
new file mode 100644
index 0000000000..527bea9abe
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.utility;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Convenience implementation of {@link IPartListener}.
+ */
+public class PartAdapter
+ implements IPartListener
+{
+ public void partOpened(IWorkbenchPart part) {
+ // do nothing
+ }
+ public void partBroughtToTop(IWorkbenchPart part) {
+ // do nothing
+ }
+ public void partActivated(IWorkbenchPart part) {
+ // do nothing
+ }
+ public void partDeactivated(IWorkbenchPart part) {
+ // do nothing
+ }
+ public void partClosed(IWorkbenchPart part) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter2.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter2.java
new file mode 100644
index 0000000000..25176a909d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PartAdapter2.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.utility;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPartReference;
+
+/**
+ * Convenience implementation of {@link IPartListener2}.
+ */
+public class PartAdapter2
+ implements IPartListener2
+{
+ public void partOpened(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partActivated(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partVisible(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partInputChanged(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partHidden(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partDeactivated(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ public void partClosed(IWorkbenchPartReference partRef) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PropertyAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PropertyAdapter.java
new file mode 100644
index 0000000000..039808a373
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/PropertyAdapter.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.utility;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.ui.IPropertyListener;
+
+/**
+ * Convenience implementation of {@link IPropertyListener}.
+ */
+public class PropertyAdapter
+ implements IPropertyListener
+{
+ public void propertyChanged(Object source, int propId) {
+ // do nothing
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandExecutor.java
index 895dd212f3..d3be8f3190 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandExecutor.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/SynchronousUiCommandExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,22 +9,23 @@
******************************************************************************/
package org.eclipse.jpt.common.ui.internal.utility;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
/**
- * This implementation of CommandExecutor can be used by a non-UI
- * thread to synchronously modify a JPA project with any objects associated
- * with documents that are currently displayed in the UI.
+ * This command executor synchronously executes a {@link Command command}
+ * on the UI thread.
+ * <p>
+ * This command executor allows a non-UI process to modify any objects
+ * associated with documents that are currently displayed in the UI.
*/
public final class SynchronousUiCommandExecutor
- implements CommandExecutor
+ extends AbstractUiCommandExecutor
{
- public static final CommandExecutor INSTANCE = new SynchronousUiCommandExecutor();
+ public static final ExtendedCommandExecutor INSTANCE = new SynchronousUiCommandExecutor();
- public static CommandExecutor instance() {
+ public static ExtendedCommandExecutor instance() {
return INSTANCE;
}
@@ -34,16 +35,10 @@ public final class SynchronousUiCommandExecutor
}
public void execute(Command command) {
- this.getDisplay().syncExec(this.buildRunnable(command));
+ SWTUtil.syncExec(this.buildRunnable(command));
}
- private Runnable buildRunnable(Command command) {
- return new CommandRunnable(command);
+ public void waitToExecute(Command command) {
+ this.execute(command);
}
-
- private Display getDisplay() {
- Display display = Display.getCurrent();
- return (display != null) ? display : Display.getDefault();
- }
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/WindowAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/WindowAdapter.java
new file mode 100644
index 0000000000..8a8e08a36c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/WindowAdapter.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.internal.utility;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbenchWindow;
+
+/**
+ * Convenience implementation of {@link IWindowListener}.
+ */
+public class WindowAdapter
+ implements IWindowListener
+{
+ public void windowOpened(IWorkbenchWindow window) {
+ // do nothing
+ }
+ public void windowActivated(IWorkbenchWindow window) {
+ // do nothing
+ }
+ public void windowDeactivated(IWorkbenchWindow window) {
+ // do nothing
+ }
+ public void windowClosed(IWorkbenchWindow window) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/BooleanStateController.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/BooleanStateController.java
index 5ea988de7c..c8c5800cc4 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/BooleanStateController.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/BooleanStateController.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,12 @@
package org.eclipse.jpt.common.ui.internal.utility.swt;
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
+import org.eclipse.jpt.common.ui.internal.swt.DisposeAdapter;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.swt.events.DisposeEvent;
@@ -89,29 +93,31 @@ abstract class BooleanStateController {
}
private PropertyChangeListener buildBooleanChangeListener_() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- BooleanStateController.this.booleanChanged(event);
- }
- @Override
- public String toString() {
- return "boolean listener"; //$NON-NLS-1$
- }
- };
+ return new BooleanChangeListener();
+ }
+
+ /* CU private */ class BooleanChangeListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ BooleanStateController.this.booleanChanged(event);
+ }
}
private DisposeListener buildControlDisposeListener() {
- return new DisposeListener() {
- public void widgetDisposed(DisposeEvent event) {
- // the control is not yet "disposed" when we receive this event
- // so we can still remove our listener
- BooleanStateController.this.controlDisposed((Control) event.widget);
- }
- @Override
- public String toString() {
- return "control dispose listener"; //$NON-NLS-1$
- }
- };
+ return new ControlDisposeListener();
+ }
+
+ /* CU private */ class ControlDisposeListener
+ extends DisposeAdapter
+ {
+ @Override
+ public void widgetDisposed(DisposeEvent event) {
+ // the control is not yet "disposed" when we receive this event
+ // so we can still remove our listener
+ BooleanStateController.this.controlDisposed((Control) event.widget);
+ }
}
@@ -154,15 +160,35 @@ abstract class BooleanStateController {
control.removeDisposeListener(this.controlDisposeListener);
}
- private void setControlState(Boolean b) {
- this.setControlState(this.booleanValue(b));
+ private void setControlState(Boolean controlState) {
+ this.setControlState(this.booleanValue(controlState));
}
- abstract void setControlState(boolean b);
+ abstract void setControlState(boolean controlState);
- void setControlState(Control control, boolean b) {
+ void setControlState(Control control, boolean controlState) {
+ SWTUtil.execute(new SetControlStateRunnable(control, controlState));
+ }
+
+ /* CU private */ class SetControlStateRunnable
+ extends RunnableAdapter
+ {
+ private final Control control;
+ private final boolean controlState;
+ SetControlStateRunnable(Control control, boolean controlState) {
+ super();
+ this.control = control;
+ this.controlState = controlState;
+ }
+ @Override
+ public void run() {
+ BooleanStateController.this.setControlState_(this.control, this.controlState);
+ }
+ }
+
+ /* CU private */ void setControlState_(Control control, boolean controlState) {
if ( ! control.isDisposed()) {
- this.adapter.setState(control, b);
+ this.adapter.setState(control, controlState);
}
}
@@ -182,7 +208,6 @@ abstract class BooleanStateController {
// ********** adapter interface **********
interface Adapter {
- void setState(Control control, boolean b);
+ void setState(Control control, boolean controlState);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/MultiControlBooleanStateController.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/MultiControlBooleanStateController.java
index aa52a80af1..0c48ad96b5 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/MultiControlBooleanStateController.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/MultiControlBooleanStateController.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,12 +10,12 @@
package org.eclipse.jpt.common.ui.internal.utility.swt;
import java.util.HashSet;
-
import org.eclipse.jpt.common.utility.internal.iterables.SnapshotCloneIterable;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -75,55 +75,59 @@ final class MultiControlBooleanStateController
// ********** initialization **********
private CollectionChangeListener buildControlsListener() {
- return new CollectionChangeListener() {
- @SuppressWarnings("unchecked")
- public void itemsAdded(CollectionAddEvent event) {
- MultiControlBooleanStateController.this.addControls((Iterable<? extends Control>) event.getItems());
- }
- @SuppressWarnings("unchecked")
- public void itemsRemoved(CollectionRemoveEvent event) {
- MultiControlBooleanStateController.this.removeControls((Iterable<? extends Control>) event.getItems());
- }
- public void collectionCleared(CollectionClearEvent event) {
- MultiControlBooleanStateController.this.clearControls();
- }
- @SuppressWarnings("unchecked")
- public void collectionChanged(CollectionChangeEvent event) {
- MultiControlBooleanStateController.this.clearControls();
- MultiControlBooleanStateController.this.addControls((Iterable<? extends Control>) event.getCollection());
- }
- @Override
- public String toString() {
- return "controls listener"; //$NON-NLS-1$
- }
- };
+ return new ControlsListener();
+ }
+
+ /* CU private */ class ControlsListener
+ extends CollectionChangeAdapter
+ {
+ @Override
+ @SuppressWarnings("unchecked")
+ public void itemsAdded(CollectionAddEvent event) {
+ MultiControlBooleanStateController.this.addControls((Iterable<? extends Control>) event.getItems());
+ }
+ @Override
+ @SuppressWarnings("unchecked")
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ MultiControlBooleanStateController.this.removeControls((Iterable<? extends Control>) event.getItems());
+ }
+ @Override
+ public void collectionCleared(CollectionClearEvent event) {
+ MultiControlBooleanStateController.this.clearControls();
+ }
+ @Override
+ @SuppressWarnings("unchecked")
+ public void collectionChanged(CollectionChangeEvent event) {
+ MultiControlBooleanStateController.this.clearControls();
+ MultiControlBooleanStateController.this.addControls((Iterable<? extends Control>) event.getCollection());
+ }
}
// ********** controls **********
@Override
- void setControlState(boolean b) {
+ void setControlState(boolean controlState) {
for (Control control : this.controls) {
- this.setControlState(control, b);
+ this.setControlState(control, controlState);
}
}
/* CU private */ void addControls(Iterable<? extends Control> controls_) {
- boolean b = this.getBooleanValue();
for (Control control : controls_) {
- this.addControl(control, b);
+ this.addControl(control);
}
}
- private void addControl(Control control, boolean b) {
+ private void addControl(Control control) {
if (this.controls.isEmpty()) {
this.engageBooleanModel();
this.controlsModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.controlsListener);
}
if (this.controls.add(control)) {
this.engageControl(control);
- this.setControlState(control, b);
+ // wait until the models are engaged to get the boolean value... :-)
+ this.setControlState(control, this.getBooleanValue());
} else {
throw new IllegalArgumentException("duplicate control: " + control); //$NON-NLS-1$
}
@@ -153,5 +157,4 @@ final class MultiControlBooleanStateController
super.controlDisposed(control);
this.removeControl(control);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SimpleBooleanStateController.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SimpleBooleanStateController.java
index 0b38bb3c1d..ea036488b5 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SimpleBooleanStateController.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/utility/swt/SimpleBooleanStateController.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -55,8 +55,8 @@ final class SimpleBooleanStateController
// ********** controls **********
@Override
- void setControlState(boolean b) {
- this.setControlState(this.control, b);
+ void setControlState(boolean controlState) {
+ this.setControlState(this.control, controlState);
}
@Override
@@ -64,5 +64,4 @@ final class SimpleBooleanStateController
super.controlDisposed(c);
this.disengageBooleanModel();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java
index 6703d6a3a0..f09d1075bb 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/IntegerCombo.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -127,31 +127,25 @@ public abstract class IntegerCombo<T extends Model>
);
}
- private String getDefaultValueString() {
+ /* CU private */ String getDefaultValueString() {
return this.defaultValueHolder.getValue();
}
protected WritablePropertyValueModel<String> buildSelectedItemStringHolder() {
return new TransformationWritablePropertyValueModel<Integer, String>(buildSelectedItemHolder()) {
@Override
- protected String transform(Integer value) {
- return value == null ?
- getDefaultValueString()
- :
- value.toString();
+ protected String transform(Integer v) {
+ return (v == null) ? getDefaultValueString() : v.toString();
}
@Override
- protected Integer reverseTransform_(String value) {
- int intLength;
+ protected Integer reverseTransform_(String v) {
try {
- intLength = Integer.parseInt(value);
- }
- catch (NumberFormatException e) {
- //if the default is selected from the combo, set length to null
+ return Integer.valueOf(v);
+ } catch (NumberFormatException ex) {
+ // if the default is selected from the combo, set length to null
return null;
}
- return Integer.valueOf(intLength);
}
};
}
@@ -184,5 +178,4 @@ public abstract class IntegerCombo<T extends Model>
e.doit = false;
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/PropertySheetWidgetFactory.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/PropertySheetWidgetFactory.java
index c841976fc0..82313fb8fa 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/PropertySheetWidgetFactory.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/PropertySheetWidgetFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,13 +23,18 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
* @version 2.0
* @since 2.0
*/
-public class PropertySheetWidgetFactory extends FormWidgetFactory {
+public class PropertySheetWidgetFactory
+ extends FormWidgetFactory
+{
+ /**
+ * Creates a new <code>PropertySheetWidgetFactory</code>.
+ */
+ public PropertySheetWidgetFactory() {
+ this(new TabbedPropertySheetWidgetFactory());
+ }
/**
* Creates a new <code>PropertySheetWidgetFactory</code>.
- *
- * @param widgetFactory The actual factory responsible for creating the new
- * widgets
*/
public PropertySheetWidgetFactory(TabbedPropertySheetWidgetFactory widgetFactory) {
super(widgetFactory);
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/DelegatingContentAndLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/DelegatingContentAndLabelProvider.java
deleted file mode 100644
index 66f3be391d..0000000000
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/DelegatingContentAndLabelProvider.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.ui.jface;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.jface.viewers.BaseLabelProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.LabelProviderChangedEvent;
-import org.eclipse.jface.viewers.StructuredViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.navigator.IDescriptionProvider;
-
-/**
- * Implementation of {@link IStructuredContentProvider} and {@link ILabelProvider} that
- * maintains a collection (Map, actually) of {@link ItemContentProvider}
- * delegates that perform the function of providing content and label information
- * for each represented item
- *
- * NB: This class, if used as a label provider *MUST* be used as a content provider
- * for the same viewer. It may be used as a content provider with a different
- * label provider, however.
- *
- * Provisional API: This class is part of an interim API that is still
- * under development and expected to change significantly before reaching
- * stability. It is available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- */
-public abstract class DelegatingContentAndLabelProvider
- extends BaseLabelProvider
- implements IStructuredContentProvider, ILabelProvider, IDescriptionProvider
-{
- private final ItemContentProviderFactory itemContentProviderFactory;
-
- private final ItemLabelProviderFactory itemLabelProviderFactory;
-
- private final Map<Object, ItemContentProvider> itemContentProviders;
-
- private final Map<Object, ItemLabelProvider> itemLabelProviders;
-
- StructuredViewer viewer;
-
-
- protected DelegatingContentAndLabelProvider(
- ItemContentProviderFactory itemContentProviderFactory) {
- this(itemContentProviderFactory, null);
- }
-
- protected DelegatingContentAndLabelProvider(
- ItemContentProviderFactory itemContentProviderFactory,
- ItemLabelProviderFactory itemLabelProviderFactory) {
- super();
- this.itemContentProviderFactory = itemContentProviderFactory;
- this.itemLabelProviderFactory = itemLabelProviderFactory;
- this.itemContentProviders = new HashMap<Object, ItemContentProvider>();
- this.itemLabelProviders = new HashMap<Object, ItemLabelProvider>();
- }
-
-
- protected ItemContentProvider itemContentProvider(Object item) {
- ItemContentProvider itemContentProvider = this.itemContentProviders.get(item);
- if (itemContentProvider != null) {
- return itemContentProvider;
- }
- itemContentProvider = this.itemContentProviderFactory.buildItemContentProvider(item, this);
- if (itemContentProvider == null) {
- return null;
- }
- this.itemContentProviders.put(item, itemContentProvider);
- return itemContentProvider;
- }
-
- protected ItemLabelProvider itemLabelProvider(Object item) {
- if (this.viewer == null) {
- throw new IllegalStateException(
- "This provider must be used as a content" + //$NON-NLS-1$
- "provider *as well as* a label provider."); //$NON-NLS-1$
- }
- ItemLabelProvider itemLabelProvider = this.itemLabelProviders.get(item);
- if (itemLabelProvider != null) {
- return itemLabelProvider;
- }
- itemLabelProvider = this.itemLabelProviderFactory.buildItemLabelProvider(item, this);
- if (itemLabelProvider == null) {
- return null;
- }
- this.itemLabelProviders.put(item, itemLabelProvider);
- return itemLabelProvider;
- }
-
-
- public Object[] getElements(Object inputElement) {
- return itemContentProvider(inputElement).getElements();
- }
-
- public Image getImage(Object element) {
- ItemLabelProvider provider = itemLabelProvider(element);
- return (provider == null) ? null :provider.getImage();
- }
-
- public String getText(Object element) {
- ItemLabelProvider provider = itemLabelProvider(element);
- return (provider == null) ? null : provider.getText();
- }
-
- public String getDescription(Object element) {
- ItemLabelProvider provider = itemLabelProvider(element);
- return (provider == null) ? null : provider.getDescription();
- }
-
- /**
- * Disposes all items
- */
- @Override
- public void dispose() {
- disposeProviders();
- super.dispose();
- }
-
- protected void disposeProviders() {
- // coded this way to allow some item providers to dispose of their child
- // elements without disrupting the entire process
- while (! this.itemContentProviders.isEmpty()) {
- dispose(this.itemContentProviders.keySet().iterator().next());
- }
- // this catches any items that weren't disposed from the content providers,
- // though there most likely won't be any items represented here that
- // haven't already been disposed
- while (! this.itemLabelProviders.isEmpty()) {
- dispose(this.itemLabelProviders.keySet().iterator().next());
- }
- }
-
- /**
- * Disposes item
- */
- public void dispose(Object item) {
- if (this.itemContentProviders.containsKey(item)) {
- this.itemContentProviders.get(item).dispose();
- this.itemContentProviders.remove(item);
- }
- if (this.itemLabelProviders.containsKey(item)) {
- this.itemLabelProviders.get(item).dispose();
- this.itemLabelProviders.remove(item);
- }
- }
-
- public void inputChanged(Viewer structuredViewer, Object oldInput, Object newInput) {
- if (oldInput != newInput) {
- disposeProviders();
- }
- this.viewer = (StructuredViewer) structuredViewer;
- }
-
- /**
- * Update the content for the given item
- */
- public void updateContent(final Object item) {
- Runnable runnable = new Runnable() {
- public void run() {
- if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
- viewer.refresh(item);
- }
- }
- };
- if (!viewerIsDisposed()) {
- this.viewer.getControl().getDisplay().asyncExec(runnable);
- }
- }
-
- // open up visibility a bit for inner classes
- @Override
- protected void fireLabelProviderChanged(LabelProviderChangedEvent event) {
- super.fireLabelProviderChanged(event);
- }
-
- /**
- * Update the label for the given item
- */
- public void updateLabel(final Object item) {
- Runnable runnable = new Runnable() {
- public void run() {
- if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
- fireLabelProviderChanged(new LabelProviderChangedEvent(DelegatingContentAndLabelProvider.this, item));
- }
- }
- };
- if (!viewerIsDisposed()) {
- this.viewer.getControl().getDisplay().asyncExec(runnable);
- }
- }
-
- protected boolean viewerIsDisposed() {
- return this.viewer.getControl().isDisposed();
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ExtendedLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ExtendedLabelProvider.java
new file mode 100644
index 0000000000..6a96068edf
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ExtendedLabelProvider.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.jface;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.ui.navigator.IDescriptionProvider;
+
+/**
+ * Combine provider interfaces to be implemented by a single provider that can
+ * be used as both a label and description provider for a tree.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface ExtendedLabelProvider
+ extends ILabelProvider, IDescriptionProvider
+{
+ // combine interfaces
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProvider.java
new file mode 100644
index 0000000000..ef9445953b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProvider.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.jface;
+
+/**
+ * Implementations of this interface can be used to maintain the label (image
+ * and text) and description of a specific item. The implementation will monitor
+ * the item for any changes that affect the description and forward them
+ * appropriately to the {@link Manager}.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider
+ * @see org.eclipse.ui.navigator.IDescriptionProvider
+ */
+public interface ItemExtendedLabelProvider
+ extends ItemLabelProvider
+{
+ /**
+ * Return the description for the provider's item.
+ *
+ * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(Object)
+ */
+ String getDescription();
+
+ /**
+ * An item extended label provider's manager is notified whenever the item's
+ * description has changed.
+ */
+ interface Manager
+ extends ItemLabelProvider.Manager
+ {
+ /**
+ * The description for the specified item has changed. Update appropriately.
+ */
+ void updateDescription(Object item);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemContentProviderFactory.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProviderFactory.java
index a9c951d816..ad675de6f8 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemContentProviderFactory.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemExtendedLabelProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,17 +10,17 @@
package org.eclipse.jpt.common.ui.jface;
/**
- * Factory interface used to describe how to build {@link ItemContentProvider}s
- * for a {@link DelegatingContentAndLabelProvider}
- *
+ * Factory interface for constructing item extended label providers.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface ItemContentProviderFactory
-{
- ItemContentProvider buildItemContentProvider(Object item,
- DelegatingContentAndLabelProvider contentAndLabelProvider);
+public interface ItemExtendedLabelProviderFactory {
+ /**
+ * Build an extended label provider for the specified item.
+ */
+ ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProvider.java
index 592a8a6bbe..921a8e5712 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProvider.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,36 +12,50 @@ package org.eclipse.jpt.common.ui.jface;
import org.eclipse.swt.graphics.Image;
/**
- * Interface used in conjunction with DelegatingLabelProvider to return
- * label information for a particular item.
- * @see DelegatingLabelProvider
- * @see ItemLabelProviderFactory
- *
+ * Implementations of this interface can be used to maintain the label (image,
+ * and text) of a specific item. The implementation will monitor
+ * the item for any changes that affect the label and forward them appropriately
+ * to the {@link Manager}.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider
*/
-public interface ItemLabelProvider
-{
+public interface ItemLabelProvider {
/**
- * Return the image for the item
+ * Return the image for the provider's item.
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
*/
Image getImage();
/**
- * Return the text for the item
+ * Return the text for the provider's item.
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
*/
public String getText();
/**
- * Return the description for the item
+ * Dispose the item label provider.
+ * Remove any item listeners as appropriate.
*/
- public String getDescription();
-
+ void dispose();
+
+
/**
- * Dispose of this label provider, cleaning up all references, listeners, etc.
+ * An item label provider's manager is notified whenever the item's
+ * label has changed.
*/
- void dispose();
+ interface Manager {
+ /**
+ * The label (image and/or text) for the specified item has changed.
+ * Update appropriately.
+ */
+ void updateLabel(Object item);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProviderFactory.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProviderFactory.java
index db61b3905f..36c25d38a4 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProviderFactory.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemLabelProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,17 +10,17 @@
package org.eclipse.jpt.common.ui.jface;
/**
- * Factory interface used to describe how to build IItemLabelProviders
- * for a DelegatingContentAndLabelProvider
- *
+ * Factory interface for constructing item label providers.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface ItemLabelProviderFactory
-{
- ItemLabelProvider buildItemLabelProvider(Object item,
- DelegatingContentAndLabelProvider contentAndLabelProvider);
+public interface ItemLabelProviderFactory {
+ /**
+ * Build a label provider for the specified item.
+ */
+ ItemLabelProvider buildProvider(Object item, ItemLabelProvider.Manager manager);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProvider.java
new file mode 100644
index 0000000000..0ddbfe980c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProvider.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.jface;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Implementations of this interface can be used to maintain the elements
+ * of a specific input element. The implementation will monitor
+ * the item for any changes that affect the elements and forward them
+ * appropriately to the {@link Manager}.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider
+ */
+public interface ItemStructuredContentProvider {
+ /**
+ * Return the input element's elements.
+ * <strong>NB:</strong>
+ * When this method is called, the item is an <em>input</em> element.
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, Object, Object)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(Object)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object)
+ */
+ Object[] getElements();
+
+ /**
+ * Dispose the item content provider.
+ * Remove any item listeners as appropriate.
+ */
+ void dispose();
+
+
+ /**
+ * Convenience constant for when no children are present.
+ */
+ Object[] EMPTY_ARRAY = new Object[0];
+
+
+ /**
+ * An item structured content provider's manager is notified whenever the
+ * input element's elements have changed.
+ */
+ interface Manager {
+ /**
+ * The elements for the specified input element have changed.
+ * Update appropriately.
+ */
+ void updateElements(Object inputElement);
+
+ /**
+ * The specified element has been removed from the input element.
+ * Dispose of the element's providers, if necessary.
+ */
+ void dispose(Object element);
+ }
+
+
+ /**
+ * A "null" item structured content provider that has no elements.
+ */
+ final class Null
+ implements ItemStructuredContentProvider, Serializable
+ {
+ public static final ItemStructuredContentProvider INSTANCE = new Null();
+ public static ItemStructuredContentProvider instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public Object[] getElements() {
+ return EMPTY_ARRAY;
+ }
+ public void dispose() {
+ // NOP
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeItemContentProviderFactory.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProviderFactory.java
index 393a737525..31f168e131 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeItemContentProviderFactory.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemStructuredContentProviderFactory.java
@@ -1,26 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.ui.jface;
/**
- * Extension of {@link ItemContentProviderFactory} that extends functionality
- * for tree content
- *
+ * Factory interface for constructing item content providers.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface TreeItemContentProviderFactory extends ItemContentProviderFactory
-{
- public TreeItemContentProvider buildItemContentProvider(Object item,
- DelegatingContentAndLabelProvider contentAndLabelProvider);
+public interface ItemStructuredContentProviderFactory {
+ /**
+ * Build a structured content provider for the specified item.
+ */
+ ItemStructuredContentProvider buildProvider(Object item, ItemStructuredContentProvider.Manager manager);
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProvider.java
new file mode 100644
index 0000000000..32c3d90c05
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProvider.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.jface;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Implementations of this interface can be used to maintain the content of a
+ * specific tree element. The implementation will monitor the element for any
+ * changes that affect the element's children and forward them
+ * appropriately to the {@link Manager}.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @see org.eclipse.jface.viewers.IContentProvider
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider
+ * @see org.eclipse.jface.viewers.ITreeContentProvider
+ */
+public interface ItemTreeContentProvider
+ extends ItemStructuredContentProvider
+{
+ /**
+ * Return the item's parent.
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(Object)
+ */
+ Object getParent();
+
+ /**
+ * Return whether the item has children.
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(Object)
+ */
+ boolean hasChildren();
+
+ /**
+ * Return the item's children.
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(Object)
+ */
+ Object[] getChildren();
+
+
+ /**
+ * An item tree content provider's manager is notified whenever the
+ * item's children have changed.
+ */
+ interface Manager
+ extends ItemStructuredContentProvider.Manager
+ {
+ /**
+ * The children for the specified element have changed.
+ * Update appropriately.
+ */
+ void updateChildren(Object element);
+ }
+
+
+ /**
+ * A "null" item tree content provider that has no elements, parent,
+ * or parent.
+ */
+ final class Null
+ implements ItemTreeContentProvider, Serializable
+ {
+ public static final ItemStructuredContentProvider INSTANCE = new Null();
+ public static ItemStructuredContentProvider instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public Object[] getElements() {
+ return EMPTY_ARRAY;
+ }
+ public Object getParent() {
+ return null;
+ }
+ public Object[] getChildren() {
+ return EMPTY_ARRAY;
+ }
+ public boolean hasChildren() {
+ return false;
+ }
+ public void dispose() {
+ // NOP
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProviderFactory.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProviderFactory.java
new file mode 100644
index 0000000000..027a2b4110
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeContentProviderFactory.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.jface;
+
+/**
+ * Factory interface for constructing item tree content providers.
+ * Typically used by {@link ItemTreeContentProvider.Manager item tree content
+ * provider managers}.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface ItemTreeContentProviderFactory {
+ /**
+ * Build a tree content provider for the specified item.
+ * Return <code>null</code> if there is no provider for the specified item.
+ */
+ ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager);
+}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeStateProviderFactoryProvider.java
index 2f21206f8c..e866a7f669 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemContentProvider.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/ItemTreeStateProviderFactoryProvider.java
@@ -1,36 +1,34 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.ui.jface;
/**
- * Marker interface used in conjunction with DelegatingContentProvider to return
- * content information for a particular item.
- * @see DelegatingContentProvider
- * @see ItemContentProviderFactory
- *
+ * This provider supplies the factories used by a tree view to build
+ * the content and labels its tree.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface ItemContentProvider
-{
+public interface ItemTreeStateProviderFactoryProvider {
/**
- * Return the elements of the represented item.
- * Note that when this is called, the represented item is an input element.
+ * Return a factory to be used to create {@link ItemTreeContentProvider}s
+ * for a tree view.
*/
- Object[] getElements();
+ ItemTreeContentProviderFactory getItemContentProviderFactory();
/**
- * Dispose of this content provider, cleaning up all references, listeners, etc.
+ * Return a factory to be used to create {@link ItemExtendedLabelProvider}s
+ * for a tree view.
*/
- void dispose();
+ ItemExtendedLabelProviderFactory getItemLabelProviderFactory();
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeItemContentProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/StructuredStateProvider.java
index 2e978f00b8..027b876ebd 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeItemContentProvider.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/StructuredStateProvider.java
@@ -1,40 +1,32 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
+ * Copyright (c) 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.ui.jface;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+
/**
- * Interface used in conjunction with DelegatingTreeContentProvider to return
- * tree information for a particular item.
- * @see DelegatingTreeContentProvider
- * @see TreeItemContentProviderFactory
- *
+ * Combine all the various provider interfaces to be implemented by a single
+ * provider that can be used as both a content and label provider for a
+ * structured viewer.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface TreeItemContentProvider extends ItemContentProvider
+public interface StructuredStateProvider
+ extends IStructuredContentProvider, ExtendedLabelProvider
{
/**
- * Return the parent of the represented item
- */
- Object getParent();
-
- /**
- * Return whether the represented item has children
- */
- boolean hasChildren();
-
- /**
- * Return the children of the represented item
+ * Convenience constant for when no elements are present.
*/
- Object[] getChildren();
+ Object[] EMPTY_ARRAY = new Object[0];
}
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeStateProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeStateProvider.java
new file mode 100644
index 0000000000..b36e432137
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/jface/TreeStateProvider.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.ui.jface;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+
+/**
+ * Combine all the various provider interfaces to be implemented by a single
+ * provider that can be used as both a content and label provider for a
+ * tree viewer.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface TreeStateProvider
+ extends StructuredStateProvider, ITreeContentProvider
+{
+ // combine interfaces
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
index a33f4bb854..727c058254 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
@@ -7,139 +7,114 @@ Bundle-Version: 2.0.100.qualifier
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Dali-Comment: *NO* EclipseLink friends!
+Dali-Comment: the UI-related packages are friends with only UI plug-ins
Export-Package: org.eclipse.jpt.common.utility,
+ org.eclipse.jpt.common.utility.command,
org.eclipse.jpt.common.utility.internal;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
+ org.eclipse.jpt.common.utility.internal.command;
+ x-friends:="org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.ui,
+ org.eclipse.jpt.jaxb.core,
+ org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jpa.db,
+ org.eclipse.jpt.jpa.db.ui,
+ org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.enumerations;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.iterables;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.iterators;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.model;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.model.listener.awt;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
- org.eclipse.jpt.common.ui,
- org.eclipse.jpt.jaxb.core,
+ x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.ui,
- org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
- org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.model.value;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
- org.eclipse.jpt.common.ui,
- org.eclipse.jpt.jaxb.core,
+ x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.ui,
- org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
- org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.model.value.prefs;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
- org.eclipse.jpt.common.ui,
- org.eclipse.jpt.jaxb.core,
+ x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.ui,
- org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
- org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.model.value.swing;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
- org.eclipse.jpt.common.ui,
- org.eclipse.jpt.jaxb.core,
+ x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.ui,
- org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
- org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.node;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.swing;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
- org.eclipse.jpt.common.ui,
- org.eclipse.jpt.jaxb.core,
+ x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.ui,
- org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
- org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.synchronizers;
- x-friends:="org.eclipse.jpt.jpa.core,
- org.eclipse.jpt.common.core,
+ x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.core,
org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.db,
org.eclipse.jpt.jpa.db.ui,
org.eclipse.jpt.jpa.gen,
- org.eclipse.jpt.jpa.ui,
- org.eclipse.jpt.jaxb.core.schemagen",
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.model,
org.eclipse.jpt.common.utility.model.event,
org.eclipse.jpt.common.utility.model.listener,
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/BooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/BooleanReference.java
new file mode 100644
index 0000000000..0a73528e4e
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/BooleanReference.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility;
+
+import java.io.Serializable;
+
+/**
+ * Interface for a container for holding a <code>boolean</code> that cannot be
+ * changed by clients.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface BooleanReference {
+
+ /**
+ * Return the current <code>boolean</code> value.
+ */
+ boolean getValue();
+
+ /**
+ * Return whether the current <code>boolean</code> value is equal to the
+ * specified value.
+ */
+ boolean is(boolean value);
+
+ /**
+ * Return whether the current <code>boolean</code> value is not equal to
+ * the specified value.
+ */
+ boolean isNot(boolean value);
+
+ /**
+ * Return whether the current <code>boolean</code> value is
+ * <code>true</code>.
+ */
+ boolean isTrue();
+
+ /**
+ * Return whether the current <code>boolean</code> value is
+ * <code>false</code>.
+ */
+ boolean isFalse();
+
+
+ /**
+ * Convenience method.
+ */
+ final class Value {
+ public static BooleanReference of(boolean value) {
+ return value ? True.instance() : False.instance();
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the read-only boolean reference interface
+ * whose value is always <code>true</code>.
+ */
+ final class True
+ implements BooleanReference, Serializable
+ {
+ public static final BooleanReference INSTANCE = new True();
+
+ public static BooleanReference instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private True() {
+ super();
+ }
+
+ public boolean getValue() {
+ return true;
+ }
+
+ public boolean is(boolean value) {
+ return value;
+ }
+
+ public boolean isNot(boolean value) {
+ return ! value;
+ }
+
+ public boolean isTrue() {
+ return true;
+ }
+
+ public boolean isFalse() {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "[true]"; //$NON-NLS-1$
+ }
+
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the read-only boolean reference interface
+ * whose value is always <code>false</code>.
+ */
+ final class False
+ implements BooleanReference, Serializable
+ {
+ public static final BooleanReference INSTANCE = new False();
+
+ public static BooleanReference instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private False() {
+ super();
+ }
+
+ public boolean getValue() {
+ return false;
+ }
+
+ public boolean is(boolean value) {
+ return ! value;
+ }
+
+ public boolean isNot(boolean value) {
+ return value;
+ }
+
+ public boolean isTrue() {
+ return false;
+ }
+
+ public boolean isFalse() {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "[false]"; //$NON-NLS-1$
+ }
+
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ExceptionHandler.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ExceptionHandler.java
index 549b38471a..c91948a4c9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ExceptionHandler.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ExceptionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,9 +7,10 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
+package org.eclipse.jpt.common.utility;
import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
/**
* Simple interface for allowing clients to pass an exception handler to a
@@ -75,6 +76,9 @@ public interface ExceptionHandler {
}
public void handleException(Throwable t) {
// re-throw the exception unchecked
+ if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ }
throw new RuntimeException(t);
}
@Override
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Filter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Filter.java
index 30509f6c49..bae01f6240 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Filter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Filter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -37,17 +37,17 @@ public interface Filter<T> {
* Singleton implementation of the filter interface that accepts all the
* objects (i.e. it does no filtering).
*/
- final class Null<S>
+ final class Transparent<S>
implements Filter<S>, Serializable
{
@SuppressWarnings("rawtypes")
- public static final Filter INSTANCE = new Null();
+ public static final Filter INSTANCE = new Transparent();
@SuppressWarnings("unchecked")
public static <R> Filter<R> instance() {
return INSTANCE;
}
// ensure single instance
- private Null() {
+ private Transparent() {
super();
}
// nothing is filtered - everything is accepted
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ModifiableObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ModifiableObjectReference.java
new file mode 100644
index 0000000000..3bbd0a735c
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ModifiableObjectReference.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility;
+
+/**
+ * Provide a container for passing an object that can be changed by the recipient.
+ */
+public interface ModifiableObjectReference<V>
+ extends ObjectReference<V>
+{
+ /**
+ * Set the value.
+ * Return the previous value.
+ */
+ V setValue(V value);
+
+ /**
+ * Set the value to <code>null</code>.
+ * Return the previous value.
+ */
+ V setNull();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ObjectReference.java
index 991c2c97d2..54b6ba49f9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ObjectReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ObjectReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,20 +10,33 @@
package org.eclipse.jpt.common.utility;
/**
- * Provide a container for passing an object that can be changed by the recipient.
+ * Provide a container for holding an object that cannot be changed.
+ *
+ * @see ModifiableObjectReference
*/
-public interface ObjectReference<V>
- extends ReadOnlyObjectReference<V>
-{
+public interface ObjectReference<V> {
+ /**
+ * Return the current value.
+ */
+ V getValue();
+
+ /**
+ * Return whether the current value is equal to the specified value.
+ */
+ boolean valueEquals(Object object);
+
+ /**
+ * Return whether the current value is not equal to the specified value.
+ */
+ boolean valueNotEqual(Object object);
+
/**
- * Set the value.
- * Return the previous value.
+ * Return whether the current value is <code>null</code>.
*/
- V setValue(V value);
+ boolean isNull();
/**
- * Set the value to <code>null</code>.
- * Return the previous value.
+ * Return whether the current value is not <code>null</code>.
*/
- V setNull();
+ boolean isNotNull();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ReadOnlyObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ReadOnlyObjectReference.java
deleted file mode 100644
index 02c4ff6a24..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/ReadOnlyObjectReference.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility;
-
-/**
- * Provide a container for holding an object that cannot be changed.
- *
- * @see ObjectReference
- */
-public interface ReadOnlyObjectReference<V>
-{
- /**
- * Return the current value.
- */
- V getValue();
-
- /**
- * Return whether the current value is equal to the specified value.
- */
- boolean valueEquals(Object object);
-
- /**
- * Return whether the current value is not equal to the specified value.
- */
- boolean valueNotEqual(Object object);
-
- /**
- * Return whether the current value is <code>null</code>.
- */
- boolean isNull();
-
- /**
- * Return whether the current value is not <code>null</code>.
- */
- boolean isNotNull();
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Command.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/Command.java
index 59d35fbc1a..ba7bd56d46 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/Command.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/Command.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,7 +7,7 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility;
+package org.eclipse.jpt.common.utility.command;
import java.io.Serializable;
import org.eclipse.jpt.common.utility.internal.StringTools;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/CommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/CommandExecutor.java
index 07a8ea41a4..c8c8af64ac 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/CommandExecutor.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/CommandExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,7 +7,7 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility;
+package org.eclipse.jpt.common.utility.command;
import java.io.Serializable;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -27,7 +27,10 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
public interface CommandExecutor {
/**
- * Execute the specified command.
+ * Execute the specified command, synchronously or asynchronously.
+ * The commands themselves must be executed in the order in which
+ * they are passed to the command executor (at least when passed
+ * from clients executing on the same thread).
*/
void execute(Command command);
@@ -60,4 +63,34 @@ public interface CommandExecutor {
return INSTANCE;
}
}
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that ignores any commands.
+ */
+ final class Inactive
+ implements CommandExecutor, Serializable
+ {
+ public static final CommandExecutor INSTANCE = new Inactive();
+ public static CommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Inactive() {
+ super();
+ }
+ public void execute(Command command) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/ExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/ExtendedCommandExecutor.java
new file mode 100644
index 0000000000..fabb5c5d05
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/ExtendedCommandExecutor.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This interface extends the normal command executor; it allows the client
+ * to specify when a command <em>must</em> be executed synchronously.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface ExtendedCommandExecutor
+ extends CommandExecutor
+{
+ /**
+ * Suspend the current thread until the specified command is executed.
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor (at least when passed
+ * from clients executing on the same thread).
+ * @see #execute(Command)
+ */
+ void waitToExecute(Command command) throws InterruptedException;
+
+ /**
+ * Suspend the current thread until the specified command is executed
+ * or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if
+ * the command was executed in the allotted time;
+ * return <code>false</code> if a time-out occurred and the command was
+ * <em>not</em> executed.
+ * If the time-out is zero, wait indefinitely.
+ * <p>
+ * The command itself must be executed <em>after</em> any other commands
+ * previously passed to the command executor (at least when passed
+ * from clients executing on the same thread).
+ * @see #execute(Command)
+ */
+ boolean waitToExecute(Command command, long timeout) throws InterruptedException;
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that simply executes the command without any sort of enhancement.
+ */
+ final class Default
+ implements ExtendedCommandExecutor, Serializable
+ {
+ public static final ExtendedCommandExecutor INSTANCE = new Default();
+ public static ExtendedCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public void execute(Command command) {
+ command.execute();
+ }
+ public void waitToExecute(Command command) {
+ command.execute();
+ }
+ public boolean waitToExecute(Command command, long timeout) {
+ command.execute();
+ return true;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+
+ /**
+ * Singleton implementation of the command executor interface
+ * that ignores any commands.
+ */
+ final class Inactive
+ implements ExtendedCommandExecutor, Serializable
+ {
+ public static final ExtendedCommandExecutor INSTANCE = new Inactive();
+ public static ExtendedCommandExecutor instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Inactive() {
+ super();
+ }
+ public void execute(Command command) {
+ // do nothing
+ }
+ public void waitToExecute(Command command) {
+ // do nothing
+ }
+ public boolean waitToExecute(Command command, long timeout) {
+ // do nothing
+ return true;
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/InterruptibleCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/InterruptibleCommand.java
index 685350045b..c7bfaa78f4 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/InterruptibleCommand.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/InterruptibleCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,7 +7,7 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility;
+package org.eclipse.jpt.common.utility.command;
import java.io.Serializable;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -22,7 +22,7 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @see org.eclipse.jpt.common.utility.Command
+ * @see org.eclipse.jpt.common.utility.command.Command
*/
public interface InterruptibleCommand {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/InterruptibleCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/InterruptibleCommandExecutor.java
index 651164bc23..14ec4d1445 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/InterruptibleCommandExecutor.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/InterruptibleCommandExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,7 +7,7 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility;
+package org.eclipse.jpt.common.utility.command;
import java.io.Serializable;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -24,7 +24,7 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @see org.eclipse.jpt.common.utility.CommandExecutor
+ * @see org.eclipse.jpt.common.utility.command.CommandExecutor
*/
public interface InterruptibleCommandExecutor {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/NotifyingRepeatingCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/NotifyingRepeatingCommand.java
new file mode 100644
index 0000000000..7076a20e8e
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/NotifyingRepeatingCommand.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.command;
+
+import java.io.Serializable;
+import java.util.EventListener;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Extend the repeating command to support listeners that are notified
+ * when an execution "cycle" is complete; i.e. the command has,
+ * for the moment, handled every execution request and quiesced.
+ * This notification is <em>not</em> guaranteed to occur with <em>every</em>
+ * execution "cycle"; since other, unrelated, executions can be triggered
+ * concurrently, causing the "cycle" to continue.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface NotifyingRepeatingCommand
+ extends RepeatingCommand
+{
+ /**
+ * Add the specified listener.
+ */
+ void addListener(Listener listener);
+
+ /**
+ * Remove the specified listener.
+ */
+ void removeListener(Listener listener);
+
+
+ // ********** listener **********
+
+ /**
+ * Interface implemented by listeners to be notified whenever the
+ * command has quiesced.
+ */
+ public interface Listener
+ extends EventListener
+ {
+ /**
+ * The specified command has quiesced.
+ */
+ void executionQuiesced(Command command);
+ }
+
+
+ // ********** null singleton **********
+
+ /**
+ * Singleton implementation of the notifying repeating command interface
+ * that will do nothing when executed.
+ */
+ final class Null
+ implements NotifyingRepeatingCommand, Serializable
+ {
+ public static final NotifyingRepeatingCommand INSTANCE = new Null();
+ public static NotifyingRepeatingCommand instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public void start() {
+ // do nothing
+ }
+ public void execute() {
+ // do nothing
+ }
+ public void stop() {
+ // do nothing
+ }
+ public void addListener(Listener listener) {
+ // do nothing
+ }
+ public void removeListener(Listener listener) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/RepeatingCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/RepeatingCommand.java
new file mode 100644
index 0000000000..c73f2c11a5
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/RepeatingCommand.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.command;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This command will execute repeatedly the minimum
+ * number of times. The assumption is the command's effects are
+ * cumulative(?); i.e. the cumulative result of multiple executions of the
+ * command is no different than the result of a single execution of the command.
+ * Once the command is executing, any further requests to execute simply trigger
+ * a re-execution of the command once it has finished its current execution.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface RepeatingCommand
+ extends Command
+{
+ /**
+ * Start the command, allowing it to begin executing with the next call to
+ * {@link #execute()}.
+ * @exception IllegalStateException when the command is not stopped
+ */
+ void start();
+
+ /**
+ * Stop the command; ignore further calls to {@link #execute()}.
+ * @exception IllegalStateException when the command executor is not started
+ */
+ void stop() throws InterruptedException;
+
+
+ /**
+ * Singleton implementation of the repeating command interface that will do
+ * nothing when executed.
+ */
+ final class Null
+ implements RepeatingCommand, Serializable
+ {
+ public static final RepeatingCommand INSTANCE = new Null();
+ public static RepeatingCommand instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public void start() {
+ // do nothing
+ }
+ public void execute() {
+ // do nothing
+ }
+ public void stop() {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulCommandExecutor.java
new file mode 100644
index 0000000000..a7e66f7366
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulCommandExecutor.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.command;
+
+/**
+ * Add the ability to start and stop the command executor.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface StatefulCommandExecutor
+ extends CommandExecutor
+{
+ /**
+ * Start the command executor.
+ * @exception IllegalStateException when the command executor is not stopped
+ */
+ void start();
+
+ /**
+ * Stop the command executor.
+ * @exception IllegalStateException when the command executor is not started
+ */
+ void stop() throws InterruptedException;
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulExtendedCommandExecutor.java
new file mode 100644
index 0000000000..d2874face3
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/command/StatefulExtendedCommandExecutor.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.command;
+
+/**
+ * Add the ability to start and stop the command executor.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface StatefulExtendedCommandExecutor
+ extends StatefulCommandExecutor, ExtendedCommandExecutor
+{
+ // combine interfaces
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractBooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractBooleanReference.java
new file mode 100644
index 0000000000..5e6f1b1ad6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractBooleanReference.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+/**
+ * Convenience abstract class for boolean reference implementations.
+ * Subclasses need only implement<ul>
+ * <li>{@link #getValue()}
+ * <li>{@link #setValue(boolean)}
+ * </ul>
+ */
+public abstract class AbstractBooleanReference
+ implements ModifiableBooleanReference
+{
+ protected AbstractBooleanReference() {
+ super();
+ }
+
+ public boolean is(boolean value) {
+ return this.getValue() == value;
+ }
+
+ public boolean isNot(boolean value) {
+ return this.getValue() != value;
+ }
+
+ public boolean isTrue() {
+ return this.getValue();
+ }
+
+ public boolean isFalse() {
+ return ! this.getValue();
+ }
+
+ public boolean flip() {
+ return this.setValue( ! this.getValue());
+ }
+
+ public boolean setNot(boolean value) {
+ return this.setValue( ! value);
+ }
+
+ public boolean setTrue() {
+ return this.setValue(true);
+ }
+
+ public boolean setFalse() {
+ return this.setValue(false);
+ }
+
+
+ // ********** standard methods **********
+
+ /**
+ * Object identity is critical to boolean references.
+ * There is no reason for two different boolean references to be
+ * <em>equal</em>.
+ *
+ * @see #is(boolean)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
+ /**
+ * @see #equals(Object)
+ */
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return '[' + String.valueOf(this.getValue()) + ']';
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractTransformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractTransformer.java
new file mode 100644
index 0000000000..b6a4e2a2de
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AbstractTransformer.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+/**
+ * Convenience transformer that returns <code>null</code> if the original
+ * object is <code>null</code>; otherwise it calls {@link #transform_(Object)},
+ * which is to be implemented by subclasses.
+ */
+public abstract class AbstractTransformer<T1, T2>
+ extends TransformerAdapter<T1, T2>
+{
+ @Override
+ public final T2 transform(T1 o) {
+ return (o == null) ? null : this.transform_(o);
+ }
+
+ /**
+ * Transform the specified object; its value is guaranteed to be not
+ * <code>null</code>.
+ */
+ protected abstract T2 transform_(T1 o);
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AsynchronousCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AsynchronousCommandExecutor.java
deleted file mode 100644
index 62b2e70653..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/AsynchronousCommandExecutor.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
-
-import java.util.concurrent.ThreadFactory;
-
-import org.eclipse.jpt.common.utility.Command;
-
-/**
- * This command executor will dispatch commands to be executed in a separate
- * thread, allowing calls to {@link CommandExecutor#execute(Command)} to return
- * immediately.
- * <p>
- * <strong>NB:</strong> The client-supplied commands should handle any
- * exception appropriately (e.g. log the exception and return gracefully) so
- * the command execution thread can continue executing.
- */
-public class AsynchronousCommandExecutor
- implements StatefulCommandExecutor
-{
- /**
- * This command queue is shared with the command execution/consumer thread.
- * Adding a command to it will trigger the command to be executed by the
- * command execution thread or, if another command is currently executing,
- * to execute the new command once the currently executing command has
- * finished executing.
- */
- final SynchronizedQueue<Command> commands = new SynchronizedQueue<Command>();
-
- /**
- * Most of the thread-related behavior is delegated to this coordinator.
- */
- private final ConsumerThreadCoordinator consumerThreadCoordinator;
-
-
- // ********** construction **********
-
- /**
- * Construct an asynchronous command executor.
- * Use simple JDK thread(s) for the command execution thread(s).
- * Allow the command execution thread(s) to be assigned JDK-generated names.
- */
- public AsynchronousCommandExecutor() {
- this(SimpleThreadFactory.instance(), null);
- }
-
- /**
- * Construct an asynchronous command executor.
- * Use the specified thread factory to construct the command execution thread(s).
- * Allow the command execution thread(s) to be assigned JDK-generated names.
- */
- public AsynchronousCommandExecutor(ThreadFactory threadFactory) {
- this(threadFactory, null);
- }
-
- /**
- * Construct an asynchronous command executor.
- * Use simple JDK thread(s) for the command execution thread(s).
- * Assign the command execution thread(s) the specified name.
- */
- public AsynchronousCommandExecutor(String threadName) {
- this(SimpleThreadFactory.instance(), threadName);
- }
-
- /**
- * Construct an asynchronous command executor.
- * Assign the command execution thread(s) the specified name.
- */
- public AsynchronousCommandExecutor(ThreadFactory threadFactory, String threadName) {
- super();
- this.consumerThreadCoordinator = this.buildConsumerThreadCoordinator(threadFactory, threadName);
- }
-
- private ConsumerThreadCoordinator buildConsumerThreadCoordinator(ThreadFactory threadFactory, String threadName) {
- return new ConsumerThreadCoordinator(this.buildConsumer(), threadFactory, threadName);
- }
-
- private ConsumerThreadCoordinator.Consumer buildConsumer() {
- return new Consumer();
- }
-
-
- // ********** CallbackStatefulCommandExecutor implementation **********
-
- /**
- * Build and start the command execution/consumer thread.
- * <p>
- * Note: We don't clear the command queue here; so if a command has been
- * added to the queue <em>before</em> getting here, the first command will
- * be executed promptly (albeit, asynchronously).
- * The command queue will be non-empty if:<ul>
- * <li>{@link #execute(Command)} was called after the command executor was
- * constructed but before {@link #start()} was called; or
- * <li>{@link #execute(Command)} was called after {@link #stop()} was called
- * but before {@link #start()} was called (to restart the command executor); or
- * <li>{@link #stop()} was called when there were still outstanding commands
- * remaining in the command queue
- * </ul>
- */
- public void start() {
- this.consumerThreadCoordinator.start();
- }
-
- /**
- * Put the specified command on the command queue, to be consumed by the
- * command execution thread.
- */
- public void execute(Command command) {
- this.commands.enqueue(command);
- }
-
- /**
- * Interrupt the command execution thread so that it stops executing at the
- * end of the current command. Suspend the current thread until
- * the command execution thread is finished executing. If any uncaught
- * exceptions were thrown while the execution thread was executing,
- * wrap them in a composite exception and throw the composite exception.
- */
- public void stop() {
- this.consumerThreadCoordinator.stop();
- }
-
-
- // ********** consumer **********
-
- /**
- * This implementation of {@link ConsumerThreadCoordinator.Consumer}
- * will execute the commands enqueued by the asynchronous command executor.
- * It will wait until the shared command queue is non-empty to begin executing the
- * commands in the queue. Once a comand is executed, the thread will quiesce until
- * another command is placed in the command queue. If a new command is
- * enqueued during the execution of another command (either recursively by
- * the command itself or by another thread),
- * the new command will be executed immediately after the currently
- * executing command is finished.
- * Stop the thread by calling {@link Thread#interrupt()}.
- */
- class Consumer
- implements ConsumerThreadCoordinator.Consumer
- {
- Consumer() {
- super();
- }
-
- /**
- * Wait until a command has been placed in the queue.
- */
- public void waitForProducer() throws InterruptedException {
- AsynchronousCommandExecutor.this.commands.waitUntilNotEmpty();
- }
-
- /**
- * Execute the first command in the queue and notify our listeners.
- */
- public void execute() {
- AsynchronousCommandExecutor.this.commands.dequeue().execute();
- }
-
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Classpath.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Classpath.java
index dcf03bd2cf..33657d5e41 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Classpath.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Classpath.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -543,7 +543,7 @@ public class Classpath
* @see #classNames()
*/
public Iterable<String> getClassNames() {
- return this.getClassNames(Filter.Null.<String>instance());
+ return this.getClassNames(Filter.Transparent.<String>instance());
}
/**
@@ -562,7 +562,7 @@ public class Classpath
* to the specified collection.
*/
public void addClassNamesTo(Collection<String> classNames) {
- this.addClassNamesTo(classNames, Filter.Null.<String>instance());
+ this.addClassNamesTo(classNames, Filter.Transparent.<String>instance());
}
/**
@@ -580,7 +580,7 @@ public class Classpath
* Just a bit more performant than {@link #getClassNames()}.
*/
public Iterator<String> classNames() {
- return this.classNames(Filter.Null.<String>instance());
+ return this.classNames(Filter.Transparent.<String>instance());
}
/**
@@ -628,7 +628,7 @@ public class Classpath
}
- // ********** inner class **********
+ // ********** classpath entry **********
/**
* <code>Entry</code> models a Java classpath entry, which can be either a
@@ -636,7 +636,9 @@ public class Classpath
* similarly, a <code>.zip</code> file). The entry can return the names of
* classes found in it etc.
*/
- public static class Entry implements Serializable {
+ public static class Entry
+ implements Serializable
+ {
private final String fileName;
private final File file;
private final File canonicalFile;
@@ -750,7 +752,7 @@ public class Classpath
* @see #classNames()
*/
public Iterable<String> getClassNames() {
- return this.getClassNames(Filter.Null.<String>instance());
+ return this.getClassNames(Filter.Transparent.<String>instance());
}
/**
@@ -769,7 +771,7 @@ public class Classpath
* to the specified collection.
*/
public void addClassNamesTo(Collection<String> classNames) {
- this.addClassNamesTo(classNames, Filter.Null.<String>instance());
+ this.addClassNamesTo(classNames, Filter.Transparent.<String>instance());
}
/**
@@ -860,7 +862,7 @@ public class Classpath
* Just a bit more performant than {@link #getClassNames()}.
*/
public Iterator<String> classNames() {
- return this.classNames(Filter.Null.<String>instance());
+ return this.classNames(Filter.Transparent.<String>instance());
}
/**
@@ -933,7 +935,5 @@ public class Classpath
}
return classNames.iterator();
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CollectingExceptionHandler.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CollectingExceptionHandler.java
new file mode 100644
index 0000000000..93ac401f0a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CollectingExceptionHandler.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+import java.util.Vector;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
+import org.eclipse.jpt.common.utility.internal.iterables.SnapshotCloneIterable;
+
+/**
+ * An exception handler that collects and hold the exceptions handed to it.
+ * They can be retrieved at a later time via calls to {@link #getExceptions()}
+ * and {{@link #clearExceptions()}.
+ */
+public class CollectingExceptionHandler
+ implements ExceptionHandler
+{
+ private final Vector<Throwable> exceptions = new Vector<Throwable>();
+
+ public void handleException(Throwable t) {
+ this.exceptions.add(t);
+ }
+
+ /**
+ * Return the current list of exceptions handled by the handler so far.
+ */
+ public Iterable<Throwable> getExceptions() {
+ return new LiveCloneIterable<Throwable>(this.exceptions);
+ }
+
+ /**
+ * Clear and return the current list of exceptions handled by the handler
+ * so far.
+ */
+ public Iterable<Throwable> clearExceptions() {
+ synchronized (this.exceptions) {
+ Iterable<Throwable> result = new SnapshotCloneIterable<Throwable>(this.exceptions);
+ this.exceptions.clear();
+ return result;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.exceptions);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ConsumerThreadCoordinator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ConsumerThreadCoordinator.java
index 8dc34e968d..25dfbf438a 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ConsumerThreadCoordinator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ConsumerThreadCoordinator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,8 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal;
-import java.util.Vector;
import java.util.concurrent.ThreadFactory;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
/**
* A <code>ConsumerThreadCoordinator</code> controls the creation,
@@ -18,10 +18,6 @@ import java.util.concurrent.ThreadFactory;
* the coordinator with a {@link Consumer} that both waits for the producer
* to "produce" something to "consume" and, once the wait is over,
* "consumes" whatever is available.
- * <p>
- * <strong>NB:</strong> The client-supplied consumer should handle any
- * exception appropriately (e.g. log the exception and return gracefully) so
- * the thread can continue executing.
*/
public class ConsumerThreadCoordinator {
/**
@@ -49,10 +45,9 @@ public class ConsumerThreadCoordinator {
private volatile Thread thread;
/**
- * A list of the uncaught exceptions thrown by the consumer
- * during the current start/stop cycle.
+ * This handles the exceptions thrown by the consumer.
*/
- final Vector<Throwable> exceptions = new Vector<Throwable>();
+ /* CU private */ final ExceptionHandler exceptionHandler;
// ********** construction **********
@@ -61,39 +56,40 @@ public class ConsumerThreadCoordinator {
* Construct a consumer thread coordinator for the specified consumer.
* Use simple JDK thread(s) for the consumer thread(s).
* Allow the consumer thread(s) to be assigned JDK-generated names.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
*/
- public ConsumerThreadCoordinator(Consumer consumer) {
- this(consumer, SimpleThreadFactory.instance());
- }
-
- /**
- * Construct a consumer thread coordinator for the specified consumer.
- * Use the specified thread factory to construct the consumer thread(s).
- * Allow the consumer thread(s) to be assigned JDK-generated names.
- */
- public ConsumerThreadCoordinator(Consumer consumer, ThreadFactory threadFactory) {
- this(consumer, threadFactory, null);
+ public ConsumerThreadCoordinator(Consumer consumer, ExceptionHandler exceptionHandler) {
+ this(consumer, null, exceptionHandler);
}
/**
* Construct a consumer thread coordinator for the specified consumer.
* Assign the consumer thread(s) the specified name.
* Use simple JDK thread(s) for the consumer thread(s).
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
*/
- public ConsumerThreadCoordinator(Consumer consumer, String threadName) {
- this(consumer, SimpleThreadFactory.instance(), threadName);
+ public ConsumerThreadCoordinator(Consumer consumer, String threadName, ExceptionHandler exceptionHandler) {
+ this(consumer, SimpleThreadFactory.instance(), threadName, exceptionHandler);
}
/**
* Construct a consumer thread coordinator for the specified consumer.
* Use the specified thread factory to construct the consumer thread(s).
* Assign the consumer thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
*/
- public ConsumerThreadCoordinator(Consumer consumer, ThreadFactory threadFactory, String threadName) {
+ public ConsumerThreadCoordinator(Consumer consumer, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
super();
this.runnable = this.buildRunnable(consumer);
+ if ((threadFactory == null) || ((exceptionHandler == null))) {
+ throw new NullPointerException();
+ }
this.threadFactory = threadFactory;
this.threadName = threadName;
+ this.exceptionHandler = exceptionHandler;
}
private Runnable buildRunnable(Consumer consumer) {
@@ -101,10 +97,12 @@ public class ConsumerThreadCoordinator {
}
- // ********** Lifecycle support **********
+ // ********** lifecycle support **********
/**
* Build and start the consumer thread.
+ *
+ * @exception IllegalStateException if the coordinator has already been started
*/
public synchronized void start() {
if (this.thread != null) {
@@ -128,29 +126,21 @@ public class ConsumerThreadCoordinator {
* the consumer thread is finished executing. If any uncaught
* exceptions were thrown while the consumer thread was executing,
* wrap them in a composite exception and throw the composite exception.
+ *
+ * @exception IllegalStateException if the coordinator has not been started
*/
- public synchronized void stop() {
+ public synchronized void stop() throws InterruptedException {
if (this.thread == null) {
throw new IllegalStateException("Not started."); //$NON-NLS-1$
}
this.thread.interrupt();
- try {
- this.thread.join();
- } catch (InterruptedException ex) {
- // the thread that called #stop() was interrupted while waiting to
- // join the consumer thread - ignore;
- // 'thread' is still "interrupted", so its #run() loop will still stop
- // after its current execution - we just won't wait around for it...
- }
+ this.thread.join();
this.thread = null;
-
- if (this.exceptions.size() > 0) {
- Throwable[] temp = this.exceptions.toArray(new Throwable[this.exceptions.size()]);
- this.exceptions.clear();
- throw new CompositeException(temp);
- }
}
+
+ // ********** misc **********
+
@Override
public String toString() {
return StringTools.buildToStringFor(this, this.thread);
@@ -161,11 +151,11 @@ public class ConsumerThreadCoordinator {
/**
* This implementation of {@link Runnable} is a long-running consumer that
- * will repeatedly execute the consumer {@link Consumer#execute()} method.
+ * will repeatedly execute the consumer {@link Consumer#consume()} method.
* With each iteration, the consumer thread will wait
* until the other consumer method, {@link Consumer#waitForProducer()}, allows the
* consumer thread to proceed (i.e. there is something for the consumer to
- * consume). Once {@link Consumer#execute()} is finished, the thread will quiesce
+ * consume). Once {@link Consumer#consume()} is finished, the thread will quiesce
* until {@link Consumer#waitForProducer()} returns again.
* Stop the thread by calling {@link Thread#interrupt()}.
*/
@@ -180,6 +170,9 @@ public class ConsumerThreadCoordinator {
RunnableConsumer(Consumer consumer) {
super();
+ if (consumer == null) {
+ throw new NullPointerException();
+ }
this.consumer = consumer;
}
@@ -188,44 +181,42 @@ public class ConsumerThreadCoordinator {
* In each loop: Pause execution until {@link Consumer#waitForProducer()}
* allows us to proceed.
* <p>
- * If this thread is interrupted <em>during</em> {@link Consumer#execute()},
- * the call to {@link Thread#interrupted()} will stop the loop. If this thread is
+ * If this thread is interrupted <em>during</em> {@link Consumer#consume()},
+ * the call to {@link Thread#isInterrupted()} will stop the loop. If this thread is
* interrupted during the call to {@link Consumer#waitForProducer()},
* we will catch the {@link InterruptedException} and stop the loop also.
+ *
+ * @see ConsumerThreadCoordinator#stop()
*/
public void run() {
- while ( ! Thread.interrupted()) {
+ while ( ! Thread.currentThread().isInterrupted()) {
try {
this.consumer.waitForProducer();
} catch (InterruptedException ex) {
// we were interrupted while waiting, must be Quittin' Time
+ Thread.currentThread().interrupt(); // set the Thread's interrupt status
return;
+ } catch (RuntimeException ex) {
+ ConsumerThreadCoordinator.this.exceptionHandler.handleException(ex);
+ return; // hmmm... kill the thread?
}
- this.execute();
+ this.consume();
}
}
/**
- * Execute the consumer {@link Consumer#execute()} method.
+ * Delegate to the consumer {@link Consumer#consume()} method.
* Do not allow any unhandled exceptions to kill the thread.
- * Store them up for later pain.
+ * Pass them to the exception handler.
* @see ConsumerThreadCoordinator#stop()
*/
- private void execute() {
+ private void consume() {
try {
- this.execute_();
- } catch (Throwable ex) {
- ConsumerThreadCoordinator.this.exceptions.add(ex);
+ this.consumer.consume();
+ } catch (RuntimeException ex) {
+ ConsumerThreadCoordinator.this.exceptionHandler.handleException(ex);
}
}
-
- /**
- * Subclass-implemented behavior: consume stuff.
- */
- private void execute_() {
- this.consumer.execute();
- }
-
}
@@ -247,7 +238,6 @@ public class ConsumerThreadCoordinator {
/**
* Consume whatever is currently available.
*/
- void execute();
+ void consume();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/FilterAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/FilterAdapter.java
new file mode 100644
index 0000000000..204515d5ca
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/FilterAdapter.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+import org.eclipse.jpt.common.utility.Filter;
+
+/**
+ * Convenience filter implementation that accepts everything.
+ *
+ * @see org.eclipse.jpt.common.utility.Filter.Transparent
+ */
+public class FilterAdapter<T>
+ implements Filter<T>
+{
+ public boolean accept(T o) {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/IntReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/IntReference.java
index ad989b4fda..a790457d0b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/IntReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/IntReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,31 +10,136 @@
package org.eclipse.jpt.common.utility.internal;
/**
- * Interface for a container for passing an integer that can be changed by
- * the recipient.
+ * Interface for a container for holding an <code>int</code> that cannot be
+ * changed by clients.
*/
public interface IntReference
- extends ReadOnlyIntReference
+ extends Comparable<IntReference>
{
/**
- * Set the <code>int</code> value.
- * Return the previous value.
+ * Return the current <code>int</code> value.
*/
- int setValue(int value);
+ int getValue();
/**
- * Set the <code>int</code> value to zero.
- * Return the previous value.
+ * Return whether the current <code>int</code> value is equal to the
+ * specified value.
*/
- int setZero();
+ boolean equals(int v);
/**
- * Increment and return the <code>int</code> value.
+ * Return whether the current <code>int</code> value is not equal to
+ * the specified value.
*/
- int increment();
+ boolean notEqual(int v);
/**
- * Decrement and return the <code>int</code> value.
+ * Return whether the current <code>int</code> value is zero.
*/
- int decrement();
+ boolean isZero();
+
+ /**
+ * Return whether the current <code>int</code> value is not zero.
+ */
+ boolean isNotZero();
+
+ /**
+ * Return whether the current <code>int</code> value is greater than
+ * the specified value.
+ */
+ boolean isGreaterThan(int v);
+
+ /**
+ * Return whether the current <code>int</code> value is greater than
+ * or equal to the specified value.
+ */
+ boolean isGreaterThanOrEqual(int v);
+
+ /**
+ * Return whether the current <code>int</code> value is less than
+ * the specified value.
+ */
+ boolean isLessThan(int v);
+
+ /**
+ * Return whether the current <code>int</code> value is less than
+ * or equal to the specified value.
+ */
+ boolean isLessThanOrEqual(int v);
+
+ /**
+ * Return whether the current <code>int</code> value is positive.
+ */
+ boolean isPositive();
+
+ /**
+ * Return whether the current <code>int</code> value is not positive
+ * (i.e. negative or zero).
+ */
+ boolean isNotPositive();
+
+ /**
+ * Return whether the current <code>int</code> value is negative.
+ */
+ boolean isNegative();
+
+ /**
+ * Return whether the current <code>int</code> value is not negative
+ * (i.e. zero or positive).
+ */
+ boolean isNotNegative();
+
+ /**
+ * Return the absolute value of the current <code>int</code> value.
+ */
+ int abs();
+
+ /**
+ * Return the negative value of the current <code>int</code> value.
+ */
+ int neg();
+
+ /**
+ * Return the current <code>int</code> value plus the specified value.
+ */
+ int add(int v);
+
+ /**
+ * Return current <code>int</code> value minus the specified value.
+ */
+ int subtract(int v);
+
+ /**
+ * Return current <code>int</code> value multiplied by the specified value.
+ */
+ int multiply(int v);
+
+ /**
+ * Return current <code>int</code> value divided by the specified value.
+ */
+ int divide(int v);
+
+ /**
+ * Return the remainder of the current <code>int</code> value divided by
+ * the specified value.
+ */
+ int remainder(int v);
+
+ /**
+ * Return the minimum of the current <code>int</code> value and
+ * the specified value.
+ */
+ int min(int v);
+
+ /**
+ * Return the maximum of the current <code>int</code> value and
+ * the specified value.
+ */
+ int max(int v);
+
+ /**
+ * Return the current <code>int</code> value raised to the power
+ * of the specified value.
+ */
+ double pow(int v);
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/LazyReadOnlyObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/LazyObjectReference.java
index 84d01e34c3..454a6e1cf0 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/LazyReadOnlyObjectReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/LazyObjectReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
-import org.eclipse.jpt.common.utility.ReadOnlyObjectReference;
+import org.eclipse.jpt.common.utility.ObjectReference;
/**
* Provide a thread-safe, reasonably performing container for holding an
@@ -27,8 +27,8 @@ import org.eclipse.jpt.common.utility.ReadOnlyObjectReference;
* @see SimpleObjectReference
* @see SynchronizedObject
*/
-public abstract class LazyReadOnlyObjectReference<V>
- implements ReadOnlyObjectReference<V>, Cloneable, Serializable
+public abstract class LazyObjectReference<V>
+ implements ObjectReference<V>, Cloneable, Serializable
{
/** Backing value. */
private volatile V value = null;
@@ -41,7 +41,7 @@ public abstract class LazyReadOnlyObjectReference<V>
/**
* Create a lazy object reference.
*/
- public LazyReadOnlyObjectReference() {
+ protected LazyObjectReference() {
super();
}
@@ -87,10 +87,10 @@ public abstract class LazyReadOnlyObjectReference<V>
// ********** standard methods **********
@Override
- public LazyReadOnlyObjectReference<V> clone() {
+ public LazyObjectReference<V> clone() {
try {
@SuppressWarnings("unchecked")
- LazyReadOnlyObjectReference<V> clone = (LazyReadOnlyObjectReference<V>) super.clone();
+ LazyObjectReference<V> clone = (LazyObjectReference<V>) super.clone();
return clone;
} catch (CloneNotSupportedException ex) {
throw new InternalError();
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java
index 632b3fd5df..6161fb00c9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,20 +15,21 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.Arrays;
-import java.util.EventListener;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
/**
* Maintain a thread-safe list of listeners that does not allow adding
* duplicate listeners or removing non-listeners.
+ *
+ * @parm <L> the type of listeners held by the list
*/
-public class ListenerList<L extends EventListener>
+public class ListenerList<L>
implements Serializable
{
/**
- * We can mark this volatile and not synchronize the read methods because
- * we never change the <em>contents</em> of the array.
+ * We can mark this <code>volatile</code> and not synchronize the read
+ * methods because we never change the <em>contents</em> of the array.
*/
private transient volatile L[] listeners;
@@ -167,5 +168,4 @@ public class ListenerList<L extends EventListener>
this.listeners = ArrayTools.add(this.listeners, (L) o);
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/BooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableBooleanReference.java
index 9d114257d1..c22849ae58 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/BooleanReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableBooleanReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,12 +9,14 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal;
+import org.eclipse.jpt.common.utility.BooleanReference;
+
/**
* Interface for a container for passing a flag that can be changed by
* the recipient.
*/
-public interface BooleanReference
- extends ReadOnlyBooleanReference
+public interface ModifiableBooleanReference
+ extends BooleanReference
{
/**
* Set the <code>boolean</code> value.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableIntReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableIntReference.java
new file mode 100644
index 0000000000..135b86068a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ModifiableIntReference.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+/**
+ * Interface for a container for passing an integer that can be changed by
+ * the recipient.
+ */
+public interface ModifiableIntReference
+ extends IntReference
+{
+ /**
+ * Set the <code>int</code> value.
+ * Return the previous value.
+ */
+ int setValue(int value);
+
+ /**
+ * Set the <code>int</code> value to zero.
+ * Return the previous value.
+ */
+ int setZero();
+
+ /**
+ * Increment and return the <code>int</code> value.
+ */
+ int increment();
+
+ /**
+ * Decrement and return the <code>int</code> value.
+ */
+ int decrement();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyBooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyBooleanReference.java
deleted file mode 100644
index 0d2c56a3bf..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyBooleanReference.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
-
-/**
- * Interface for a container for holding a <code>boolean</code> that cannot be
- * changed by clients.
- */
-public interface ReadOnlyBooleanReference
-{
- /**
- * Return the current <code>boolean</code> value.
- */
- boolean getValue();
-
- /**
- * Return whether the current <code>boolean</code> value is equal to the
- * specified value.
- */
- boolean is(boolean value);
-
- /**
- * Return whether the current <code>boolean</code> value is not equal to
- * the specified value.
- */
- boolean isNot(boolean value);
-
- /**
- * Return whether the current <code>boolean</code> value is
- * <code>true</code>.
- */
- boolean isTrue();
-
- /**
- * Return whether the current <code>boolean</code> value is
- * <code>false</code>.
- */
- boolean isFalse();
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyIntReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyIntReference.java
deleted file mode 100644
index 50e5154669..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ReadOnlyIntReference.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
-
-/**
- * Interface for a container for holding an <code>int</code> that cannot be
- * changed by clients.
- */
-public interface ReadOnlyIntReference
- extends Comparable<ReadOnlyIntReference>
-{
- /**
- * Return the current <code>int</code> value.
- */
- int getValue();
-
- /**
- * Return whether the current <code>int</code> value is equal to the
- * specified value.
- */
- boolean equals(int v);
-
- /**
- * Return whether the current <code>int</code> value is not equal to
- * the specified value.
- */
- boolean notEqual(int v);
-
- /**
- * Return whether the current <code>int</code> value is zero.
- */
- boolean isZero();
-
- /**
- * Return whether the current <code>int</code> value is not zero.
- */
- boolean isNotZero();
-
- /**
- * Return whether the current <code>int</code> value is greater than
- * the specified value.
- */
- boolean isGreaterThan(int v);
-
- /**
- * Return whether the current <code>int</code> value is greater than
- * or equal to the specified value.
- */
- boolean isGreaterThanOrEqual(int v);
-
- /**
- * Return whether the current <code>int</code> value is less than
- * the specified value.
- */
- boolean isLessThan(int v);
-
- /**
- * Return whether the current <code>int</code> value is less than
- * or equal to the specified value.
- */
- boolean isLessThanOrEqual(int v);
-
- /**
- * Return whether the current <code>int</code> value is positive.
- */
- boolean isPositive();
-
- /**
- * Return whether the current <code>int</code> value is not positive
- * (i.e. negative or zero).
- */
- boolean isNotPositive();
-
- /**
- * Return whether the current <code>int</code> value is negative.
- */
- boolean isNegative();
-
- /**
- * Return whether the current <code>int</code> value is not negative
- * (i.e. zero or positive).
- */
- boolean isNotNegative();
-
- /**
- * Return the absolute value of the current <code>int</code> value.
- */
- int abs();
-
- /**
- * Return the negative value of the current <code>int</code> value.
- */
- int neg();
-
- /**
- * Return the current <code>int</code> value plus the specified value.
- */
- int add(int v);
-
- /**
- * Return current <code>int</code> value minus the specified value.
- */
- int subtract(int v);
-
- /**
- * Return current <code>int</code> value multiplied by the specified value.
- */
- int multiply(int v);
-
- /**
- * Return current <code>int</code> value divided by the specified value.
- */
- int divide(int v);
-
- /**
- * Return the remainder of the current <code>int</code> value divided by
- * the specified value.
- */
- int remainder(int v);
-
- /**
- * Return the minimum of the current <code>int</code> value and
- * the specified value.
- */
- int min(int v);
-
- /**
- * Return the maximum of the current <code>int</code> value and
- * the specified value.
- */
- int max(int v);
-
- /**
- * Return the current <code>int</code> value raised to the power
- * of the specified value.
- */
- double pow(int v);
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableAdapter.java
new file mode 100644
index 0000000000..ef5bcc608d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableAdapter.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+/**
+ * Convenience runnable that does nothing.
+ */
+public class RunnableAdapter
+ implements Runnable
+{
+ public void run() {
+ // NOP
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleBooleanReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleBooleanReference.java
index 9dabf58f59..c514b69892 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleBooleanReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleBooleanReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -17,7 +17,7 @@ import java.io.Serializable;
* @see SynchronizedBoolean
*/
public class SimpleBooleanReference
- implements BooleanReference, Cloneable, Serializable
+ implements ModifiableBooleanReference, Cloneable, Serializable
{
/** Backing <code>boolean</code>. */
protected volatile boolean value;
@@ -100,6 +100,26 @@ public class SimpleBooleanReference
}
}
+ /**
+ * Object identity is critical to boolean references.
+ * There is no reason for two different boolean references to be
+ * <em>equal</em>.
+ *
+ * @see #is(boolean)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj);
+ }
+
+ /**
+ * @see #equals(Object)
+ */
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
@Override
public String toString() {
return '[' + String.valueOf(this.value) + ']';
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleCommandExecutor.java
deleted file mode 100644
index 169654a766..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleCommandExecutor.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
-
-import org.eclipse.jpt.common.utility.Command;
-
-/**
- * Straightforward implementation of {@link StatefulCommandExecutor}.
- */
-public class SimpleCommandExecutor
- implements StatefulCommandExecutor
-{
- private boolean active = false;
-
- public SimpleCommandExecutor() {
- super();
- }
-
- public void start() {
- if (this.active) {
- throw new IllegalStateException("Not stopped."); //$NON-NLS-1$
- }
- this.active = true;
- }
-
- public void execute(Command command) {
- if (this.active) {
- command.execute();
- }
- }
-
- public void stop() {
- if ( ! this.active) {
- throw new IllegalStateException("Not started."); //$NON-NLS-1$
- }
- this.active = false;
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleFilter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleFilter.java
index 7cff1214c6..3d664984b7 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleFilter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,47 +15,48 @@ import org.eclipse.jpt.common.utility.Filter;
/**
* Simple, abstract implementation of <code>Filter</code>
* that holds on to a criterion object that can be used in the
- * <code>accept(Object)</code> or <code>reject(Object)</code>
+ * {@link #accept(Object) accept} or {@link #reject(Object) reject}
* methods. Subclasses can override either of these methods,
* depending on which is easier to implement. Note that at least
* one of these methods <em>must</em> be overridden or
* an infinite loop will occur. If both of them are overridden,
- * only the <code>accept(Object)</code> method will be used.
+ * only the {@link #accept(Object) accept} method will be used.
* <p>
- * Simplifies the implementation of straightforward inner classes.
+ * This class simplifies the implementation of straightforward inner classes.
* Here is an example of a filter that can be used by a
- * <code>FilteringIterator</code> to return only those strings
- * in the nested iterator start with "prefix":
+ * {@link org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable
+ * FilteringIterable} to return only those strings
+ * in the nested iterable that start with <code>"prefix"</code>:
* <pre>
- * Filter<String> filter = new SimpleFilter<String>("prefix") {
- * public boolean accept(String o) {
- * return o.startsWith((String) criterion);
- * }
- * };
+ * Filter<String> filter = new SimpleFilter<String, String>("prefix") {
+ * public boolean accept(String string) {
+ * return string.startsWith(criterion);
+ * }
+ * };
* </pre>
*/
-public abstract class SimpleFilter<T, S>
+public abstract class SimpleFilter<T, C>
implements Filter<T>, Cloneable, Serializable
{
- protected final S criterion;
+ protected final C criterion;
private static final long serialVersionUID = 1L;
/**
- * More useful constructor. The specified criterion can
- * be used by a subclass to "accept" or "reject" objects.
+ * Construct a simple filter with a <code>null</code> criterion
*/
- protected SimpleFilter(S criterion) {
- super();
- this.criterion = criterion;
+ protected SimpleFilter() {
+ this(null);
}
/**
- * Construct a simple filter with a null criterion
+ * More useful constructor. The specified criterion can
+ * be used by a subclass to "accept" or "reject" objects.
*/
- protected SimpleFilter() {
- this(null);
+ protected SimpleFilter(C criterion) {
+ super();
+ this.criterion = criterion;
}
/**
@@ -74,11 +75,19 @@ public abstract class SimpleFilter<T, S>
return ! this.reject(o);
}
+ /**
+ * Return the filter's criterion.
+ */
+ public C getCriterion() {
+ return this.criterion;
+ }
+
@Override
- @SuppressWarnings("unchecked")
- public SimpleFilter<T, S> clone() {
+ public SimpleFilter<T, C> clone() {
try {
- return (SimpleFilter<T, S>) super.clone();
+ @SuppressWarnings("unchecked")
+ SimpleFilter<T, C> clone = (SimpleFilter<T, C>) super.clone();
+ return clone;
} catch (CloneNotSupportedException ex) {
throw new InternalError();
}
@@ -90,8 +99,7 @@ public abstract class SimpleFilter<T, S>
return false;
}
SimpleFilter<?, ?> other = (SimpleFilter<?, ?>) o;
- return (this.criterion == null) ?
- (other.criterion == null) : this.criterion.equals(other.criterion);
+ return Tools.valuesAreEqual(this.criterion, other.criterion);
}
@Override
@@ -103,5 +111,4 @@ public abstract class SimpleFilter<T, S>
public String toString() {
return StringTools.buildToStringFor(this, this.criterion);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleIntReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleIntReference.java
index fa7a3b452d..63950ebbb9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleIntReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleIntReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,7 +21,7 @@ import java.io.Serializable;
* @see SynchronizedInt
*/
public final class SimpleIntReference
- implements IntReference, Cloneable, Serializable
+ implements ModifiableIntReference, Cloneable, Serializable
{
/** Backing <code>int</code>. */
private volatile int value = 0;
@@ -162,7 +162,7 @@ public final class SimpleIntReference
// ********** Comparable implementation **********
- public int compareTo(ReadOnlyIntReference ref) {
+ public int compareTo(IntReference ref) {
int v = ref.getValue();
return (this.value < v) ? -1 : ((this.value == v) ? 0 : 1);
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleObjectReference.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleObjectReference.java
index 5134aa98a3..ea08c4d9ea 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleObjectReference.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleObjectReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
-import org.eclipse.jpt.common.utility.ObjectReference;
+import org.eclipse.jpt.common.utility.ModifiableObjectReference;
/**
* Provide a container for passing an object that can be changed by the recipient.
@@ -18,7 +18,7 @@ import org.eclipse.jpt.common.utility.ObjectReference;
* @see SynchronizedObject
*/
public class SimpleObjectReference<V>
- implements ObjectReference<V>, Cloneable, Serializable
+ implements ModifiableObjectReference<V>, Cloneable, Serializable
{
/** Backing value. */
private volatile V value;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StatefulCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StatefulCommandExecutor.java
deleted file mode 100644
index 97e99de81c..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StatefulCommandExecutor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
-
-import org.eclipse.jpt.common.utility.CommandExecutor;
-
-/**
- * This interface allows clients to control how a command is executed.
- * This is useful when the server provides the command but the client provides
- * the context (e.g. the client would like to dispatch the command to the UI
- * thread).
- */
-public interface StatefulCommandExecutor
- extends CommandExecutor
-{
- /**
- * Start the command executor.
- */
- void start();
-
- /**
- * Stop the command executor.
- */
- void stop();
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedBoolean.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedBoolean.java
index 79c368b364..f4bc28d4b3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedBoolean.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedBoolean.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,8 @@
package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
-import org.eclipse.jpt.common.utility.InterruptibleCommand;
-import org.eclipse.jpt.common.utility.InterruptibleCommandExecutor;
+import org.eclipse.jpt.common.utility.command.InterruptibleCommand;
+import org.eclipse.jpt.common.utility.command.InterruptibleCommandExecutor;
/**
* This class provides synchronized access to a <code>boolean</code> value.
@@ -22,7 +22,7 @@ import org.eclipse.jpt.common.utility.InterruptibleCommandExecutor;
* @see SimpleBooleanReference
*/
public class SynchronizedBoolean
- implements InterruptibleCommandExecutor, BooleanReference, Cloneable, Serializable
+ implements InterruptibleCommandExecutor, ModifiableBooleanReference, Cloneable, Serializable
{
/** Backing <code>boolean</code>. */
private boolean value;
@@ -597,7 +597,7 @@ public class SynchronizedBoolean
* thread.
*/
public void execute(InterruptibleCommand command) throws InterruptedException {
- if (Thread.interrupted()) {
+ if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
synchronized (this.mutex) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedInt.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedInt.java
index 999aa44aa8..3c0a12ed93 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedInt.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedInt.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
/**
* This class provides synchronized access to an <code>int</code>.
@@ -21,7 +21,7 @@ import org.eclipse.jpt.common.utility.Command;
* @see SimpleIntReference
*/
public class SynchronizedInt
- implements IntReference, Cloneable, Serializable
+ implements ModifiableIntReference, Cloneable, Serializable
{
/** Backing <code>int</code>. */
private int value;
@@ -869,7 +869,7 @@ public class SynchronizedInt
* thread.
*/
public void execute(Command command) throws InterruptedException {
- if (Thread.interrupted()) {
+ if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
synchronized (this.mutex) {
@@ -880,7 +880,7 @@ public class SynchronizedInt
// ********** Comparable implementation **********
- public int compareTo(ReadOnlyIntReference ref) {
+ public int compareTo(IntReference ref) {
int thisValue = this.getValue();
int otherValue = ref.getValue();
return (thisValue < otherValue) ? -1 : ((thisValue == otherValue) ? 0 : 1);
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedObject.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedObject.java
index f3f2048e01..60f282916b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedObject.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedObject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,8 @@
package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.ObjectReference;
+import org.eclipse.jpt.common.utility.ModifiableObjectReference;
+import org.eclipse.jpt.common.utility.command.Command;
/**
* This class provides synchronized access to an object of type <code>V</code>.
@@ -23,7 +23,7 @@ import org.eclipse.jpt.common.utility.ObjectReference;
* @see SimpleObjectReference
*/
public class SynchronizedObject<V>
- implements ObjectReference<V>, Cloneable, Serializable
+ implements ModifiableObjectReference<V>, Cloneable, Serializable
{
/** Backing value. */
private V value;
@@ -434,7 +434,7 @@ public class SynchronizedObject<V>
* thread.
*/
public void execute(Command command) throws InterruptedException {
- if (Thread.interrupted()) {
+ if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
synchronized (this.mutex) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedStack.java
index 17033fc574..21bb4ce347 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SynchronizedStack.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.common.utility.internal;
import java.io.Serializable;
import java.util.EmptyStackException;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
/**
* Thread-safe implementation of the {@link Stack} interface.
@@ -287,7 +287,7 @@ public class SynchronizedStack<E>
* thread.
*/
public void execute(Command command) throws InterruptedException {
- if (Thread.interrupted()) {
+ if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
synchronized (this.mutex) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommandExecutor.java
deleted file mode 100644
index e8e5064614..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommandExecutor.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
-
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-
-/**
- * This implementation of the CommandExecutor interface allows the client to
- * specify a different Command Executor for each thread.
- */
-public class ThreadLocalCommandExecutor implements CommandExecutor {
- protected final ThreadLocal<CommandExecutor> threadLocal;
- protected final CommandExecutor defaultCommandExecutor;
-
- /**
- * The default command executor simply executes the command directly.
- */
- public ThreadLocalCommandExecutor() {
- this(CommandExecutor.Default.instance());
- }
-
- public ThreadLocalCommandExecutor(CommandExecutor defaultCommandExecutor) {
- super();
- this.defaultCommandExecutor = defaultCommandExecutor;
- this.threadLocal = this.buildThreadLocal();
- }
-
- protected ThreadLocal<CommandExecutor> buildThreadLocal() {
- return new ThreadLocal<CommandExecutor>();
- }
-
- public void execute(Command command) {
- this.getThreadLocalCommandExecutor().execute(command);
- }
-
- protected CommandExecutor getThreadLocalCommandExecutor() {
- CommandExecutor ce = this.threadLocal.get();
- return (ce != null) ? ce : this.defaultCommandExecutor;
- }
-
- /**
- * Set the current thread's command executor to the specified value.
- */
- public void set(CommandExecutor commandExecutor) {
- this.threadLocal.set(commandExecutor);
- }
-
- /**
- * Return the string representation of the current thread's command
- * executor.
- */
- @Override
- public String toString() {
- return this.getThreadLocalCommandExecutor().toString();
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Transformer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Transformer.java
index 38430f5ce1..2aa982a3bb 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Transformer.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Transformer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TransformerAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TransformerAdapter.java
new file mode 100644
index 0000000000..d5427a271a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/TransformerAdapter.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+/**
+ * Convenience transformer that returns <code>null</code> for every
+ * transformation.
+ */
+public class TransformerAdapter<T1, T2>
+ implements Transformer<T1, T2>
+{
+ public T2 transform(T1 o) {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandExecutor.java
new file mode 100644
index 0000000000..8a059e1f9b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandExecutor.java
@@ -0,0 +1,276 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import java.util.concurrent.ThreadFactory;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
+import org.eclipse.jpt.common.utility.internal.SimpleThreadFactory;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedQueue;
+
+/**
+ * This command executor will dispatch commands to be executed in a separate
+ * thread, allowing calls to
+ * {@link org.eclipse.jpt.common.utility.command.CommandExecutor#execute(Command)}
+ * to return immediately.
+ * <p>
+ * <strong>NB:</strong> If a client-supplied command throws a runtime exception
+ * while it is executing, the command executor will use its
+ * {@link ExceptionHandler exception handler} to handle the exception.
+ */
+public abstract class AbstractAsynchronousCommandExecutor<E extends StatefulCommandExecutor>
+ implements StatefulCommandExecutor
+{
+ /**
+ * The wrapped command executor.
+ */
+ protected final E commandExecutor;
+
+ /**
+ * This command queue is shared with the command execution/consumer thread.
+ * Adding a command to it will trigger the command to be executed by the
+ * command execution thread or, if another command is currently executing,
+ * to execute the new command once the currently executing command has
+ * finished executing.
+ */
+ private final SynchronizedQueue<Command> commands = new SynchronizedQueue<Command>();
+
+ /**
+ * Most of the thread-related behavior is delegated to this coordinator.
+ */
+ private final ConsumerThreadCoordinator consumerThreadCoordinator;
+
+
+ // ********** construction **********
+
+ /**
+ * Construct an asynchronous command executor.
+ * Delegate command execution to the specified command executor.
+ * Use the specified thread factory to construct the command execution
+ * thread(s) and assign them the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ protected AbstractAsynchronousCommandExecutor(Config<E> config) {
+ this(config.getCommandExecutor(), config.getThreadFactory(), config.getThreadName(), config.getExceptionHandler());
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Delegate command execution to the specified command executor.
+ * Use the specified thread factory to construct the command execution
+ * thread(s) and assign them the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ protected AbstractAsynchronousCommandExecutor(
+ E commandExecutor,
+ ThreadFactory threadFactory,
+ String threadName,
+ ExceptionHandler exceptionHandler
+ ) {
+ super();
+ if (commandExecutor == null) {
+ throw new NullPointerException();
+ }
+ this.commandExecutor = commandExecutor;
+ this.consumerThreadCoordinator = this.buildConsumerThreadCoordinator(threadFactory, threadName, exceptionHandler);
+ }
+
+ private ConsumerThreadCoordinator buildConsumerThreadCoordinator(ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ return new ConsumerThreadCoordinator(this.buildConsumer(), threadFactory, threadName, exceptionHandler);
+ }
+
+ private ConsumerThreadCoordinator.Consumer buildConsumer() {
+ return new Consumer();
+ }
+
+
+ // ********** StatefulCommandExecutor implementation **********
+
+ /**
+ * Build and start the command execution/consumer thread.
+ * <p>
+ * Note: We don't clear the command queue here; so if a command has been
+ * added to the queue <em>before</em> getting here, the first command will
+ * be executed promptly (albeit, asynchronously).
+ * The command queue will be non-empty if:<ul>
+ * <li>{@link #execute(Command)} was called after the command executor was
+ * constructed but before {@link #start()} was called; or
+ * <li>{@link #execute(Command)} was called after {@link #stop()} was called
+ * but before {@link #start()} was called (to restart the command executor); or
+ * <li>{@link #stop()} was called when there were still outstanding commands
+ * remaining in the command queue
+ * </ul>
+ *
+ * @exception IllegalStateException if the executor has already been started
+ */
+ public synchronized void start() {
+ this.commandExecutor.start();
+ this.consumerThreadCoordinator.start();
+ }
+
+ /**
+ * Put the specified command on the command queue, to be consumed by the
+ * command execution thread. If the executor is stopped, the command will
+ * be queued and executed once the executor is, if ever, started.
+ */
+ public synchronized void execute(Command command) {
+ this.commands.enqueue(command);
+ }
+
+ /**
+ * Interrupt the command execution thread so that it stops executing at the
+ * end of the current command. Suspend the current thread until
+ * the command execution thread is finished executing. If any uncaught
+ * exceptions were thrown while the execution thread was executing,
+ * wrap them in a composite exception and throw the composite exception.
+ * Any remaining commands will be executed once the exector is, if ever,
+ * restarted.
+ *
+ * @exception IllegalStateException if the executor has not been started
+ */
+ public synchronized void stop() throws InterruptedException {
+ this.consumerThreadCoordinator.stop();
+ this.commandExecutor.stop();
+ }
+
+
+ // ********** misc **********
+
+ /* CU private */ void waitForCommand() throws InterruptedException {
+ this.commands.waitUntilNotEmpty();
+ }
+
+ /* CU private */ void executeNextCommand() {
+ this.commandExecutor.execute(this.commands.dequeue());
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.consumerThreadCoordinator);
+ }
+
+
+ // ********** consumer **********
+
+ /**
+ * This implementation of
+ * {@link org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator.Consumer}
+ * will execute the commands enqueued by the asynchronous command executor.
+ * It will wait until the shared command queue is non-empty to begin executing the
+ * commands in the queue. Once a comand is executed, the thread will quiesce until
+ * another command is placed in the command queue. If a new command is
+ * enqueued during the execution of another command (either recursively by
+ * the command itself or by another thread),
+ * the new command will be executed immediately after the currently
+ * executing command is finished.
+ * Stop the thread by calling {@link Thread#interrupt()}.
+ */
+ class Consumer
+ implements ConsumerThreadCoordinator.Consumer
+ {
+ /**
+ * Wait until a command has been placed in the queue.
+ */
+ public void waitForProducer() throws InterruptedException {
+ AbstractAsynchronousCommandExecutor.this.waitForCommand();
+ }
+
+ /**
+ * Execute the first command in the queue.
+ */
+ public void consume() {
+ AbstractAsynchronousCommandExecutor.this.executeNextCommand();
+ }
+ }
+
+
+ // ********** config **********
+
+ /**
+ * Config useful for instantiating an {@link AbstractAsynchronousCommandExecutor}.
+ */
+ public interface Config<E extends StatefulCommandExecutor> {
+ E getCommandExecutor();
+ ThreadFactory getThreadFactory();
+ String getThreadName();
+ ExceptionHandler getExceptionHandler();
+ }
+
+ /**
+ * Config useful for instantiating an {@link AbstractAsynchronousCommandExecutor}.
+ */
+ protected abstract static class SimpleConfig<E extends StatefulCommandExecutor>
+ implements Config<E>
+ {
+ private volatile E commandExecutor;
+ private volatile ThreadFactory threadFactory;
+ private volatile String threadName;
+ private volatile ExceptionHandler exceptionHandler;
+
+ protected SimpleConfig() {
+ super();
+ this.commandExecutor = this.buildDefaultCommandExecutor();
+ this.threadFactory = this.buildDefaultThreadFactory();
+ this.threadName = this.buildDefaultThreadName();
+ this.exceptionHandler = this.buildDefaultExceptionHandler();
+ }
+
+ protected SimpleConfig(E commandExecutor, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super();
+ this.commandExecutor = commandExecutor;
+ this.threadFactory = threadFactory;
+ this.threadName = threadName;
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ public void setCommandExecutor(E commandExecutor) {
+ this.commandExecutor = commandExecutor;
+ }
+ public E getCommandExecutor() {
+ return this.commandExecutor;
+ }
+ protected abstract E buildDefaultCommandExecutor();
+
+ public void setThreadFactory(ThreadFactory threadFactory) {
+ this.threadFactory = threadFactory;
+ }
+ public ThreadFactory getThreadFactory() {
+ return this.threadFactory;
+ }
+ protected ThreadFactory buildDefaultThreadFactory() {
+ return SimpleThreadFactory.instance();
+ }
+
+ public void setThreadName(String threadName) {
+ this.threadName = threadName;
+ }
+ public String getThreadName() {
+ return this.threadName;
+ }
+ protected String buildDefaultThreadName() {
+ return null;
+ }
+
+ public void setExceptionHandler(ExceptionHandler exceptionHandler) {
+ this.exceptionHandler = exceptionHandler;
+ }
+ public ExceptionHandler getExceptionHandler() {
+ return this.exceptionHandler;
+ }
+ protected ExceptionHandler buildDefaultExceptionHandler() {
+ return ExceptionHandler.Runtime.instance();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandExecutor.java
new file mode 100644
index 0000000000..6edd43eae8
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandExecutor.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.SimpleQueue;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
+
+/**
+ * This is a command executor that queues up any commands
+ * that are {@link #execute(Command) executed} while the executor is
+ * {@link #stop() stopped}. These commands will be
+ * executed when the executor is {@link #start() started}.
+ */
+public abstract class AbstractQueueingCommandExecutor<E extends StatefulCommandExecutor>
+ implements StatefulCommandExecutor
+{
+ protected final E commandExecutor;
+ protected final SynchronizedBoolean active = new SynchronizedBoolean(false);
+ private SimpleQueue<Command> queue = new SimpleQueue<Command>();
+
+
+ protected AbstractQueueingCommandExecutor(E commandExecutor) {
+ super();
+ if (commandExecutor == null) {
+ throw new NullPointerException();
+ }
+ this.commandExecutor = commandExecutor;
+ }
+
+ /**
+ * Start the command executor, executing all the commands that were
+ * queued up while the executor was {@link #stop() stopped}.
+ */
+ public synchronized void start() {
+ if (this.active.isTrue()) {
+ throw new IllegalStateException("Not stopped."); //$NON-NLS-1$
+ }
+ this.commandExecutor.start();
+ while ( ! this.queue.isEmpty()) {
+ this.commandExecutor.execute(this.queue.dequeue());
+ }
+ this.active.setTrue();
+ }
+
+ /**
+ * If the command executor is active, execute the specified command;
+ * otherwise, queue the command to be executed once the executor is
+ * {@link #start() started}.
+ */
+ public void execute(Command command) {
+ if (this.commandIsToBeExecuted(command)) {
+ this.commandExecutor.execute(command);
+ }
+ }
+
+ /**
+ * Return whether the command executor is active and, if it is <em>in</em>active,
+ * place the specified command in the queue for later execution.
+ */
+ private synchronized boolean commandIsToBeExecuted(Command command) {
+ if (this.active.isFalse()) {
+ this.queue.enqueue(command);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Stop the command executor. Any further requests to
+ * {@link #execute(Command) execute} a command will result in the command
+ * being queued up to be executed once the command executor is
+ * {@link #start() restarted}.
+ */
+ public synchronized void stop() throws InterruptedException {
+ if (this.active.isFalse()) {
+ throw new IllegalStateException("Not started."); //$NON-NLS-1$
+ }
+ this.active.setFalse();
+ this.commandExecutor.stop();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.queue);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSafeCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSafeCommandExecutor.java
new file mode 100644
index 0000000000..adc2abffa6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSafeCommandExecutor.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This command executor wraps another command executor and uses an exception
+ * handler to handle any exceptions thrown by an executing command.
+ */
+public abstract class AbstractSafeCommandExecutor<E extends CommandExecutor>
+ implements CommandExecutor
+{
+ protected final E commandExecutor;
+ protected final ExceptionHandler exceptionHandler;
+
+
+ /**
+ * <strong>NB:</strong> The default exception handler simply
+ * <em>ignores</em> any and all exceptions.
+ */
+ protected AbstractSafeCommandExecutor(E commandExecutor) {
+ this(commandExecutor, ExceptionHandler.Null.instance());
+ }
+
+ protected AbstractSafeCommandExecutor(E commandExecutor, ExceptionHandler exceptionHandler) {
+ super();
+ if ((commandExecutor == null) || (exceptionHandler == null)) {
+ throw new NullPointerException();
+ }
+ this.commandExecutor = commandExecutor;
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ public void execute(Command command) {
+ try {
+ this.commandExecutor.execute(command);
+ } catch (RuntimeException ex) {
+ this.exceptionHandler.handleException(ex);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandExecutor.java
new file mode 100644
index 0000000000..19dca1845d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandExecutor.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.SimpleQueue;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * This is a command executor that queues up any commands that are
+ * {@link #execute(Command) executed} before the executor has been
+ * {@link #start() started} or while the executor is
+ * {@link #suspend() suspended}. These commands will be
+ * executed once the executor is {@link #start() started} or
+ * {@link #resume() resumed}. Once the executor is {@link #start() started},
+ * all commands are executed <em>synchronously</em>.
+ * Once the executor is {@link #stop() stopped}, no further commands will be
+ * executed; and the executor can<em>not</em> be {@link #start() restarted}.
+ */
+public abstract class AbstractSingleUseQueueingCommandExecutor<E extends StatefulCommandExecutor>
+ implements StatefulCommandExecutor
+{
+ protected final E commandExecutor;
+ private State state;
+ private SimpleQueue<Command> queue = new SimpleQueue<Command>();
+
+ private enum State {
+ PRE_START,
+ ACTIVE,
+ SUSPENDED,
+ DEAD
+ }
+
+
+ protected AbstractSingleUseQueueingCommandExecutor(E commandExecutor) {
+ super();
+ if (commandExecutor == null) {
+ throw new NullPointerException();
+ }
+ this.commandExecutor = commandExecutor;
+ this.state = State.PRE_START;
+ }
+
+ /**
+ * Start the command executor, executing all the commands that were
+ * queued up since the executor was first constructed.
+ */
+ public synchronized void start() {
+ if (this.state != State.PRE_START) {
+ throw this.buildISE();
+ }
+ this.commandExecutor.start();
+ while ( ! this.queue.isEmpty()) {
+ this.commandExecutor.execute(this.queue.dequeue());
+ }
+ this.state = State.ACTIVE;
+ }
+
+ public void execute(Command command) {
+ if (this.commandIsToBeExecuted(command)) {
+ this.commandExecutor.execute(command);
+ }
+ }
+
+ /**
+ * If the command executor is active (i.e. it has been
+ * {@link #start() started}), execute the specified command.
+ * If the command executor has not been {@link #start() started} or it is
+ * {@link #suspend() suspended}, queue the
+ * command to be executed when the executor is {@link #start() started} or
+ * {@link #resume() resumed}.
+ * If the command executor is dead (i.e. it has been
+ * {@link #stop() stopped}), ignore the command.
+ */
+ private synchronized boolean commandIsToBeExecuted(Command command) {
+ switch (this.state) {
+ case ACTIVE:
+ // execute the command outside the lock
+ return true;
+ case PRE_START:
+ case SUSPENDED:
+ this.queue.enqueue(command);
+ return false;
+ case DEAD:
+ // ignore
+ return false;
+ }
+ throw this.buildISE();
+ }
+
+ /**
+ * Suspend the command executor. Any further requests to
+ * {@link #execute(Command) execute} a command will result in the command
+ * being queued up to be executed once the command executor is
+ * {@link #resume() resumed}.
+ */
+ public synchronized void suspend() {
+ if (this.state != State.ACTIVE) {
+ throw this.buildISE();
+ }
+ this.state = State.SUSPENDED;
+ }
+
+ /**
+ * Resume the command executor, executing all the commands that were
+ * queued up since the executor was {@link #suspend() suspended}.
+ */
+ public synchronized void resume() {
+ if (this.state != State.SUSPENDED) {
+ throw this.buildISE();
+ }
+ while ( ! this.queue.isEmpty()) {
+ this.commandExecutor.execute(this.queue.dequeue());
+ }
+ this.state = State.ACTIVE;
+ }
+
+ /**
+ * Stop the command executor. Any queued commands (i.e. the commands
+ * {@link #execute(Command) executed} while the command executor had not
+ * been {@link #start() started} or was
+ * {@link #suspend() suspended}) will be ignored.
+ * Any further requests to
+ * {@link #execute(Command) execute} a command will be ignored.
+ * The command executor <em>cannot</em> be {@link #start() restarted},
+ * {@link #suspend() suspended} or {@link #resume() resumed} once it has
+ * been stopped.
+ */
+ public synchronized void stop() throws InterruptedException {
+ switch (this.state) {
+ case ACTIVE:
+ // nothing to do
+ break;
+ case SUSPENDED:
+ // drain the queue
+ while ( ! this.queue.isEmpty()) {
+ this.queue.dequeue();
+ }
+ break;
+ case PRE_START:
+ case DEAD:
+ throw this.buildISE();
+ }
+
+ this.commandExecutor.stop();
+ this.state = State.DEAD;
+ }
+
+ private IllegalStateException buildISE() {
+ return new IllegalStateException(String.valueOf(this.state));
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.state);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractStatefulCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractStatefulCommandExecutor.java
new file mode 100644
index 0000000000..724565ae92
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractStatefulCommandExecutor.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
+
+/**
+ * Straightforward implementation of {@link StatefulCommandExecutor}
+ * that executes commands immediately by default. This executor can
+ * also be used to adapt simple {@link CommandExecutor}s to the
+ * {@link StatefulCommandExecutor} interface, providing support for
+ * lifecycle state.
+ */
+public abstract class AbstractStatefulCommandExecutor<E extends CommandExecutor>
+ implements StatefulCommandExecutor
+{
+ protected final SynchronizedBoolean active = new SynchronizedBoolean(false);
+ protected final E commandExecutor;
+
+
+ protected AbstractStatefulCommandExecutor(E commandExecutor) {
+ super();
+ if (commandExecutor == null) {
+ throw new NullPointerException();
+ }
+ this.commandExecutor = commandExecutor;
+ }
+
+ public synchronized void start() {
+ if (this.active.isTrue()) {
+ throw new IllegalStateException("Not stopped."); //$NON-NLS-1$
+ }
+ this.active.setTrue();
+ }
+
+ /**
+ * If the command executor is inactive the command is simply ignored.
+ */
+ public void execute(Command command) {
+ if (this.active.isTrue()) {
+ this.commandExecutor.execute(command);
+ }
+ }
+
+ public synchronized void stop() {
+ if (this.active.isFalse()) {
+ throw new IllegalStateException("Not started."); //$NON-NLS-1$
+ }
+ this.active.setFalse();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractThreadLocalCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractThreadLocalCommandExecutor.java
new file mode 100644
index 0000000000..b14779de7d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractThreadLocalCommandExecutor.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+
+/**
+ * This command executor allows the client to
+ * specify a different command executor for each thread.
+ */
+public abstract class AbstractThreadLocalCommandExecutor<E extends CommandExecutor>
+ implements CommandExecutor
+{
+ protected final ThreadLocal<E> threadLocal;
+ protected final E defaultCommandExecutor;
+
+
+ protected AbstractThreadLocalCommandExecutor(E defaultCommandExecutor) {
+ super();
+ if (defaultCommandExecutor == null) {
+ throw new NullPointerException();
+ }
+ this.defaultCommandExecutor = defaultCommandExecutor;
+ this.threadLocal = this.buildThreadLocal();
+ }
+
+ protected ThreadLocal<E> buildThreadLocal() {
+ return new ThreadLocal<E>();
+ }
+
+ public void execute(Command command) {
+ this.getThreadLocalCommandExecutor().execute(command);
+ }
+
+ protected E getThreadLocalCommandExecutor() {
+ E ce = this.threadLocal.get();
+ return (ce != null) ? ce : this.defaultCommandExecutor;
+ }
+
+ /**
+ * Set the current thread's command executor to the specified value.
+ */
+ public void set(E commandExecutor) {
+ this.threadLocal.set(commandExecutor);
+ }
+
+ /**
+ * Return the string representation of the current thread's command
+ * executor.
+ */
+ @Override
+ public String toString() {
+ return '[' + this.getThreadLocalCommandExecutor().toString() + ']';
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousCommandExecutor.java
new file mode 100644
index 0000000000..b07ed385c6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousCommandExecutor.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import java.util.concurrent.ThreadFactory;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.SimpleThreadFactory;
+
+/**
+ * @see AbstractAsynchronousCommandExecutor
+ */
+public class AsynchronousCommandExecutor
+ extends AbstractAsynchronousCommandExecutor<StatefulCommandExecutor>
+{
+ /**
+ * Construct an asynchronous command executor.
+ * Use simple JDK thread(s) for the command execution thread(s).
+ * Allow the command execution thread(s) to be assigned JDK-generated names.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousCommandExecutor(ExceptionHandler exceptionHandler) {
+ this(null, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Use simple JDK thread(s) for the command execution thread(s).
+ * Assign the command execution thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousCommandExecutor(String threadName, ExceptionHandler exceptionHandler) {
+ this(new SimpleStatefulCommandExecutor(CommandExecutor.Default.instance()), SimpleThreadFactory.instance(), threadName, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Delegate command execution to the specified command executor.
+ * Use the specified thread factory to construct the command execution
+ * thread(s) and assign them the specified name.
+ * Any exceptions thrown by a command will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousCommandExecutor(StatefulCommandExecutor commandExecutor, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super(commandExecutor, threadFactory, threadName, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Delegate command execution to the specified command executor.
+ * Use the specified thread factory to construct the command execution
+ * thread(s) and assign them the specified name.
+ * Any exceptions thrown by a command will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousCommandExecutor(Config config) {
+ super(config);
+ }
+
+
+ // ********** config **********
+
+ /**
+ * Config useful for instantiating an {@link AsynchronousCommandExecutor}.
+ */
+ public interface Config
+ extends AbstractAsynchronousCommandExecutor.Config<StatefulCommandExecutor>
+ {
+ // generic
+ }
+
+ /**
+ * Config useful for instantiating an {@link AsynchronousCommandExecutor}.
+ */
+ public static class SimpleConfig
+ extends AbstractAsynchronousCommandExecutor.SimpleConfig<StatefulCommandExecutor>
+ implements Config
+ {
+ public SimpleConfig() {
+ super();
+ }
+ public SimpleConfig(StatefulCommandExecutor commandExecutor, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super(commandExecutor, threadFactory, threadName, exceptionHandler);
+ }
+ @Override
+ protected StatefulCommandExecutor buildDefaultCommandExecutor() {
+ return new SimpleStatefulCommandExecutor();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousExtendedCommandExecutor.java
new file mode 100644
index 0000000000..700ac65783
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousExtendedCommandExecutor.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import java.util.concurrent.ThreadFactory;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.SimpleThreadFactory;
+
+/**
+ * {@link Command}s executed via calls to {@link #waitToExecute(Command)} will
+ * execute on the <em>current</em> thread <em>after</em> all the commands
+ * already dispatched to the other thread have executed.
+ *
+ * @see AbstractAsynchronousCommandExecutor
+ */
+public class AsynchronousExtendedCommandExecutor
+ extends AbstractAsynchronousCommandExecutor<StatefulExtendedCommandExecutor>
+ implements StatefulExtendedCommandExecutor
+{
+ /**
+ * Construct an asynchronous command executor.
+ * Use simple JDK thread(s) for the command execution thread(s).
+ * Allow the command execution thread(s) to be assigned JDK-generated names.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousExtendedCommandExecutor(ExceptionHandler exceptionHandler) {
+ this(null, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Use simple JDK thread(s) for the command execution thread(s).
+ * Assign the command execution thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousExtendedCommandExecutor(String threadName, ExceptionHandler exceptionHandler) {
+ this(new SimpleStatefulExtendedCommandExecutor(ExtendedCommandExecutor.Default.instance()), SimpleThreadFactory.instance(), threadName, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Delegate command execution to the specified command executor.
+ * Use the specified thread factory to construct the command execution
+ * thread(s) and assign them the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousExtendedCommandExecutor(StatefulExtendedCommandExecutor commandExecutor, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super(commandExecutor, threadFactory, threadName, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous command executor.
+ * Delegate command execution to the specified command executor.
+ * Use the specified thread factory to construct the command execution
+ * thread(s) and assign them the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousExtendedCommandExecutor(Config config) {
+ super(config);
+ }
+
+
+ /**
+ * Wait until all the commands currently on the queue have been executed,
+ * then execute the specified command. Suspend the command-executing thread
+ * while we execute the specified command.
+ */
+ public void waitToExecute(Command command) throws InterruptedException {
+ SynchronizingCommand syncCommand = new SynchronizingCommand();
+
+ this.execute(syncCommand); // dispatch the sync command to the other thread
+
+ try {
+ syncCommand.waitForExecution();
+ this.commandExecutor.waitToExecute(command);
+ } finally {
+ syncCommand.release();
+ }
+ }
+
+ /**
+ * Wait until all the commands currently on the queue have been executed,
+ * then execute the specified command. Suspend the command-executing thread
+ * while we execute the specified command.
+ */
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ if (timeout == 0L) {
+ this.waitToExecute(command);
+ return true;
+ }
+
+ long stop = System.currentTimeMillis() + timeout;
+ SynchronizingCommand syncCommand = new SynchronizingCommand();
+
+ this.execute(syncCommand); // dispatch the sync command to the other thread
+
+ try {
+ if (syncCommand.waitForExecution(timeout)) {
+ // adjust the time
+ timeout = stop - System.currentTimeMillis();
+ return (timeout > 0) && this.commandExecutor.waitToExecute(command, timeout);
+ }
+ return false;
+ } finally {
+ syncCommand.release();
+ }
+ }
+
+
+ // ********** config **********
+
+ /**
+ * Config useful for instantiating an {@link AsynchronousExtendedCommandExecutor}.
+ */
+ public interface Config
+ extends AbstractAsynchronousCommandExecutor.Config<StatefulExtendedCommandExecutor>
+ {
+ // generic
+ }
+
+ /**
+ * Config useful for instantiating an {@link AsynchronousExtendedCommandExecutor}.
+ */
+ public static class SimpleConfig
+ extends AbstractAsynchronousCommandExecutor.SimpleConfig<StatefulExtendedCommandExecutor>
+ implements Config
+ {
+ public SimpleConfig() {
+ super();
+ }
+ public SimpleConfig(StatefulExtendedCommandExecutor commandExecutor, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super(commandExecutor, threadFactory, threadName, exceptionHandler);
+ }
+ @Override
+ protected StatefulExtendedCommandExecutor buildDefaultCommandExecutor() {
+ return new SimpleStatefulExtendedCommandExecutor();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java
new file mode 100644
index 0000000000..dd54a23709
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import java.util.concurrent.ThreadFactory;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.NotifyingRepeatingCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
+import org.eclipse.jpt.common.utility.internal.ListenerList;
+
+/**
+ * Extend the asynchronous repeating command to notify listeners
+ * when an execution "cycle" is complete; i.e. the command has,
+ * for the moment, handled every outstanding "execute" request and quiesced.
+ * This notification is <em>not</em> guaranteed to occur with <em>every</em>
+ * execution "cycle"; since other, unrelated, executions can be
+ * triggered concurrently.
+ * <p>
+ * <strong>NB:</strong> Listeners should handle any exceptions
+ * appropriately (e.g. log the exception and return gracefully so the thread
+ * can continue the synchronization process).
+ */
+public class AsynchronousNotifyingRepeatingCommandWrapper
+ extends AsynchronousRepeatingCommandWrapper
+ implements NotifyingRepeatingCommand
+{
+ private final ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
+
+ /**
+ * This handles any exceptions thrown by the listeners.
+ */
+ private final ExceptionHandler exceptionHandler;
+
+
+ // ********** construction **********
+
+ /**
+ * Construct an asynchronous notifying repeating command that executes the
+ * specified command.
+ * Allow the execution thread(s) to be assigned JDK-generated names.
+ */
+ public AsynchronousNotifyingRepeatingCommandWrapper(Command command, ExceptionHandler exceptionHandler) {
+ super(command, exceptionHandler);
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ /**
+ * Construct an asynchronous notifying repeating command that executes the
+ * specified command.
+ * Assign the synchronization thread(s) the specified name.
+ */
+ public AsynchronousNotifyingRepeatingCommandWrapper(Command command, String threadName, ExceptionHandler exceptionHandler) {
+ super(command, threadName, exceptionHandler);
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ /**
+ * Construct an asynchronous repeating command that executes the
+ * specified command.
+ * Use the specified thread factory to construct the synchronization thread(s).
+ * Assign the synchronization thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousNotifyingRepeatingCommandWrapper(Config config) {
+ super(config);
+ this.exceptionHandler = config.getExceptionHandler();
+ }
+
+ /**
+ * Construct an asynchronous notifying repeating command that executes the
+ * specified command.
+ * Use the specified thread factory to construct the synchronization thread(s).
+ * Assign the synchronization thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousNotifyingRepeatingCommandWrapper(Command command, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super(command, threadFactory, threadName, exceptionHandler);
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ /**
+ * Build a consumer that will let us know when the execution thread has
+ * quiesced.
+ */
+ @Override
+ ConsumerThreadCoordinator.Consumer buildConsumer(Command command) {
+ return new NotifyingConsumer(command);
+ }
+
+
+ // ********** NotifyingRepeatingCommand implementation **********
+
+ public void addListener(Listener listener) {
+ this.listenerList.add(listener);
+ }
+
+ public void removeListener(Listener listener) {
+ this.listenerList.remove(listener);
+ }
+
+ /**
+ * Notify our listeners.
+ */
+ /* CU private */ void executionQuiesced() {
+ for (Listener listener : this.listenerList.getListeners()) {
+ try {
+ listener.executionQuiesced(this);
+ } catch (RuntimeException ex) {
+ // we could let the ConsumerThreadCoordinator handle these;
+ // but then the loop would be stopped with the first exception...
+ this.exceptionHandler.handleException(ex);
+ }
+ }
+ }
+
+
+ // ********** consumer **********
+
+ /**
+ * Extend {@link AsynchronousRepeatingCommandWrapper.Consumer}
+ * to notify the repeating command when execution has quiesced
+ * (i.e. the command has finished executing and there are no further
+ * requests for execution).
+ * Because execution is asynchronous, no other thread will be able to
+ * initiate another execution until the command's listeners have been
+ * notified. Note also, the command's listeners can, themselves,
+ * trigger another execution (by directly or indirectly calling
+ * {@link org.eclipse.jpt.common.utility.command.Command#execute()});
+ * but this execution will not occur until <em>after</em> all the
+ * listeners have been notified.
+ */
+ /* CU private */ class NotifyingConsumer
+ extends Consumer
+ {
+ NotifyingConsumer(Command command) {
+ super(command);
+ }
+
+ @Override
+ public void consume() {
+ super.consume();
+ // hmmm - we will notify listeners even when we our thread is "interrupted";
+ // that seems ok... ~bjv
+ if (AsynchronousNotifyingRepeatingCommandWrapper.this.executeFlag.isFalse()) {
+ AsynchronousNotifyingRepeatingCommandWrapper.this.executionQuiesced();
+ }
+ }
+
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousRepeatingCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousRepeatingCommandWrapper.java
new file mode 100644
index 0000000000..76331d4728
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousRepeatingCommandWrapper.java
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import java.util.concurrent.ThreadFactory;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.RepeatingCommand;
+import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
+import org.eclipse.jpt.common.utility.internal.SimpleThreadFactory;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
+
+/**
+ * This repeating command will perform a client-supplied command in a separate
+ * thread, allowing calls to {@link org.eclipse.jpt.common.utility.command.Command#execute()}
+ * to return immediately.
+ * <p>
+ * <strong>NB:</strong> The client-supplied command should handle any exceptions
+ * appropriately (e.g. log the exception and return gracefully so the thread
+ * can continue the execution process).
+ */
+public class AsynchronousRepeatingCommandWrapper
+ implements RepeatingCommand
+{
+ /**
+ * This flag is shared with the execution/consumer thread. Setting it to
+ * <code>true</code> will trigger the execution to begin or, if the
+ * execution is currently under way, to execute again, once the current
+ * execution is complete.
+ */
+ final SynchronizedBoolean executeFlag = new SynchronizedBoolean(false);
+
+ /**
+ * Most of the thread-related behavior is delegated to this coordinator.
+ */
+ private final ConsumerThreadCoordinator consumerThreadCoordinator;
+
+
+ // ********** construction **********
+
+ /**
+ * Construct an asynchronous repeating command that executes the specified
+ * command.
+ * Use simple JDK thread(s) for the execution thread(s).
+ * Allow the execution thread(s) to be assigned JDK-generated names.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousRepeatingCommandWrapper(Command command, ExceptionHandler exceptionHandler) {
+ this(command, null, null, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous repeating command that executes the specified
+ * command. Assign the execution thread(s) the specified name.
+ * Use simple JDK thread(s) for the execution thread(s).
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousRepeatingCommandWrapper(Command command, String threadName, ExceptionHandler exceptionHandler) {
+ this(command, null, threadName, exceptionHandler);
+ }
+
+ /**
+ * Construct an asynchronous repeating command that executes the specified
+ * command.
+ * Use the specified thread factory to construct the synchronization thread(s).
+ * Assign the synchronization thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousRepeatingCommandWrapper(Config config) {
+ this(config.getCommand(), config.getThreadFactory(), config.getThreadName(), config.getExceptionHandler());
+ }
+
+ /**
+ * Construct an asynchronous repeating command that executes the specified
+ * command.
+ * Use the specified thread factory to construct the synchronization thread(s).
+ * Assign the synchronization thread(s) the specified name.
+ * Any exceptions thrown by the consumer will be handled by the
+ * specified exception handler.
+ */
+ public AsynchronousRepeatingCommandWrapper(Command command, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super();
+ this.consumerThreadCoordinator = new ConsumerThreadCoordinator(this.buildConsumer(command), threadFactory, threadName, exceptionHandler);
+ }
+
+ ConsumerThreadCoordinator.Consumer buildConsumer(Command command) {
+ return new Consumer(command);
+ }
+
+
+ // ********** RepeatingCommand implementation **********
+
+ /**
+ * Build and start the execution thread, but postpone the first
+ * execution until requested, i.e. via a call to {@link #execute()}.
+ * <p>
+ * Note: We don't clear the "execute" flag here; so if the flag has
+ * been set to <code>true</code> <em>before</em> getting here, the first
+ * execution will start promptly (albeit, asynchronously).
+ * The "execute" flag will be set if:<ul>
+ * <li>{@link #execute()} was called after the repeating command was
+ * constructed but before {@link #start()} was called; or
+ * <li>{@link #execute()} was called after {@link #stop()} was called
+ * but before {@link #start()} was called (to restart the repeating
+ * command); or
+ * <li>{@link #stop()} was called when there was an outstanding request
+ * for an execution (i.e. the "execute" flag was <code>true</code> at
+ * the time {@link #stop()} was called)
+ * </ul>
+ *
+ * @exception IllegalStateException if the command has already been started
+ */
+ public void start() {
+ this.consumerThreadCoordinator.start();
+ }
+
+ /**
+ * Set the "execute" flag so the execution thread will either<ul>
+ * <li>if the thread is quiesced, start an execution immediately, or
+ * <li>if the thread is currently executing, execute again,
+ * once the current execution is complete
+ * </ul>
+ */
+ public void execute() {
+ this.executeFlag.setTrue();
+ }
+
+ /**
+ * Interrupt the execution thread so that it stops executing at the
+ * end of the current execution. Suspend the current thread until
+ * the execution thread is finished executing. If any uncaught
+ * exceptions were thrown while the execution thread was executing,
+ * wrap them in a composite exception and throw the composite exception.
+ *
+ * @exception IllegalStateException if the coordinator has not been started
+ */
+ public void stop() throws InterruptedException {
+ this.consumerThreadCoordinator.stop();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.consumerThreadCoordinator);
+ }
+
+
+ // ********** consumer **********
+
+ /**
+ * This implementation of
+ * {@link org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator.Consumer}
+ * will execute the client-supplied command.
+ * It will wait until the shared "execute" flag is set to execute the
+ * command. Once the comand is executed, the thread will quiesce until
+ * the flag is set again. If the flag was set during the execution of the
+ * command (either recursively by the command itself or by another thread),
+ * the command will be re-executed immediately. Stop the thread by calling
+ * {@link Thread#interrupt()}.
+ */
+ class Consumer
+ implements ConsumerThreadCoordinator.Consumer
+ {
+ /**
+ * The client-supplied command that executes on the
+ * execution/consumer thread.
+ */
+ private final Command command;
+
+ Consumer(Command command) {
+ super();
+ if (command == null) {
+ throw new NullPointerException();
+ }
+ this.command = command;
+ }
+
+ /**
+ * Wait until the "execute" flag is set,
+ * then clear it and allow the command to execute.
+ */
+ public void waitForProducer() throws InterruptedException {
+ AsynchronousRepeatingCommandWrapper.this.executeFlag.waitToSetFalse();
+ }
+
+ /**
+ * Execute the client-supplied command.
+ */
+ public void consume() {
+ this.command.execute();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.command);
+ }
+ }
+
+
+ // ********** config **********
+
+ /**
+ * Config useful for instantiating an {@link AbstractAsynchronousCommandExecutor}.
+ */
+ public interface Config {
+ Command getCommand();
+ ThreadFactory getThreadFactory();
+ String getThreadName();
+ ExceptionHandler getExceptionHandler();
+ }
+
+ /**
+ * Config useful for instantiating an {@link AbstractAsynchronousCommandExecutor}.
+ */
+ protected abstract static class SimpleConfig
+ implements Config
+ {
+ private volatile Command command;
+ private volatile ThreadFactory threadFactory;
+ private volatile String threadName;
+ private volatile ExceptionHandler exceptionHandler;
+
+ protected SimpleConfig() {
+ super();
+ this.command = this.buildDefaultCommand();
+ this.threadFactory = this.buildDefaultThreadFactory();
+ this.threadName = this.buildDefaultThreadName();
+ this.exceptionHandler = this.buildDefaultExceptionHandler();
+ }
+
+ protected SimpleConfig(Command command, ThreadFactory threadFactory, String threadName, ExceptionHandler exceptionHandler) {
+ super();
+ this.command = command;
+ this.threadFactory = threadFactory;
+ this.threadName = threadName;
+ this.exceptionHandler = exceptionHandler;
+ }
+
+ public void setCommand(Command command) {
+ this.command = command;
+ }
+ public Command getCommand() {
+ return this.command;
+ }
+ protected abstract Command buildDefaultCommand();
+
+ public void setThreadFactory(ThreadFactory threadFactory) {
+ this.threadFactory = threadFactory;
+ }
+ public ThreadFactory getThreadFactory() {
+ return this.threadFactory;
+ }
+ protected ThreadFactory buildDefaultThreadFactory() {
+ return SimpleThreadFactory.instance();
+ }
+
+ public void setThreadName(String threadName) {
+ this.threadName = threadName;
+ }
+ public String getThreadName() {
+ return this.threadName;
+ }
+ protected String buildDefaultThreadName() {
+ return null;
+ }
+
+ public void setExceptionHandler(ExceptionHandler exceptionHandler) {
+ this.exceptionHandler = exceptionHandler;
+ }
+ public ExceptionHandler getExceptionHandler() {
+ return this.exceptionHandler;
+ }
+ protected ExceptionHandler buildDefaultExceptionHandler() {
+ return ExceptionHandler.Runtime.instance();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CommandRunnable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/CommandRunnable.java
index 8f66ef255c..e5abcaaeca 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CommandRunnable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/CommandRunnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,14 +7,16 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
+package org.eclipse.jpt.common.utility.internal.command;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
/**
- * Wrap a Command so it can be used as a Runnable.
+ * Wrap a {@link Command} so it can be used as a {@link Runnable}.
*/
-public class CommandRunnable implements Runnable {
+public class CommandRunnable
+ implements Runnable
+{
protected final Command command;
public CommandRunnable(Command command) {
@@ -31,7 +33,6 @@ public class CommandRunnable implements Runnable {
@Override
public String toString() {
- return "Runnable[" + this.command.toString() +']'; //$NON-NLS-1$
+ return "Runnable[" + this.command +']'; //$NON-NLS-1$
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CompositeCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/CompositeCommand.java
index fce6610235..c1fa124415 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/CompositeCommand.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/CompositeCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,9 +7,10 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
+package org.eclipse.jpt.common.utility.internal.command;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
/**
@@ -27,6 +28,9 @@ public class CompositeCommand
public CompositeCommand(Iterable<Command> commands) {
super();
+ if (commands == null) {
+ throw new NullPointerException();
+ }
this.commands = commands;
}
@@ -40,5 +44,4 @@ public class CompositeCommand
public String toString() {
return StringTools.buildToStringFor(this, this.commands);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java
new file mode 100644
index 0000000000..03bb6ebb61
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.NotifyingRepeatingCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.internal.ListenerList;
+
+/**
+ * <strong>NB:</strong> If another execution cycle is initiated while we are
+ * notifying the command's listeners (i.e. the {@link #state} is set
+ * to "repeat"), the new
+ * execution will not start until all the listeners are notified.
+ * <p>
+ * <strong>NB2:</strong> The command's listeners can, themselves,
+ * trigger another execution (by directly or indirectly calling
+ * {@link #execute()});
+ * but, again, this execution will not occur until <em>after</em> all the
+ * listeners have been notified.
+ * <p>
+ * <strong>NB3:</strong> Along with any exceptions thrown by the wrapped
+ * command, any exceptions thrown by the command's listeners will
+ * be passed to the {@link #exceptionHandler exception handler}.
+ */
+public class NotifyingRepeatingCommandWrapper
+ extends RepeatingCommandWrapper
+ implements NotifyingRepeatingCommand
+{
+ private final ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
+
+
+ // ********** construction **********
+
+ /**
+ * Construct a notifying repeating command wrapper that executes the
+ * specified command. Any exceptions thrown by the command or listener
+ * will be handled by the specified exception handler.
+ */
+ public NotifyingRepeatingCommandWrapper(Command command, ExceptionHandler exceptionHandler) {
+ super(command, exceptionHandler);
+ }
+
+ /**
+ * Construct a notifying repeating command wrapper that executes the specified
+ * command and uses the specified command executor to execute the wrapped
+ * command whenever it is not already executing.
+ * Any exceptions thrown by the command or listener will be handled by the
+ * specified exception handler.
+ */
+ public NotifyingRepeatingCommandWrapper(Command command, CommandExecutor startCommandExecutor, ExceptionHandler exceptionHandler) {
+ super(command, startCommandExecutor, exceptionHandler);
+ }
+
+
+ // ********** listeners **********
+
+ public void addListener(Listener listener) {
+ this.listenerList.add(listener);
+ }
+
+ public void removeListener(Listener listener) {
+ this.listenerList.remove(listener);
+ }
+
+
+ // ********** override **********
+
+ @Override
+ /* private protected */ void executeCommand() {
+ super.executeCommand();
+ if (this.state.isQuiesced()) {
+ // hmmm - we will notify listeners even when we are "stopped"; that seems OK...
+ this.executionQuiesced();
+ }
+ }
+
+ /**
+ * Notify our listeners.
+ */
+ private void executionQuiesced() {
+ for (Listener listener : this.listenerList.getListeners()) {
+ try {
+ listener.executionQuiesced(this);
+ } catch (Throwable ex) {
+ this.exceptionHandler.handleException(ex);
+ }
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingCommandExecutor.java
new file mode 100644
index 0000000000..3898cbd44d
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingCommandExecutor.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+
+/**
+ * @see AbstractQueueingCommandExecutor
+ */
+public class QueueingCommandExecutor
+ extends AbstractQueueingCommandExecutor<StatefulCommandExecutor>
+{
+ public QueueingCommandExecutor() {
+ this(CommandExecutor.Default.instance());
+ }
+
+ public QueueingCommandExecutor(CommandExecutor commandExecutor) {
+ this(new SimpleStatefulCommandExecutor(commandExecutor));
+ }
+
+ public QueueingCommandExecutor(StatefulCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingExtendedCommandExecutor.java
new file mode 100644
index 0000000000..b030ed4175
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/QueueingExtendedCommandExecutor.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulExtendedCommandExecutor;
+
+/**
+ * Calls to {@link #waitToExecute(Command)} will suspend the current thread
+ * until the command executor is {@link #start() started} and any previously-
+ * dispatched commands have executed.
+ *
+ * @see AbstractQueueingCommandExecutor
+ */
+public class QueueingExtendedCommandExecutor
+ extends AbstractQueueingCommandExecutor<StatefulExtendedCommandExecutor>
+ implements StatefulExtendedCommandExecutor
+{
+ public QueueingExtendedCommandExecutor() {
+ this(ExtendedCommandExecutor.Default.instance());
+ }
+
+ public QueueingExtendedCommandExecutor(ExtendedCommandExecutor commandExecutor) {
+ this(new SimpleStatefulExtendedCommandExecutor(commandExecutor));
+ }
+
+ public QueueingExtendedCommandExecutor(StatefulExtendedCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+
+ /**
+ * Suspend the current thread until the command executor is
+ * {@link #start() started}.
+ */
+ public void waitToExecute(Command command) throws InterruptedException {
+ SynchronizingCommand syncCommand = new SynchronizingCommand();
+
+ this.execute(syncCommand); // put the sync command on the queue and wait until it has executed
+
+ try {
+ syncCommand.waitForExecution();
+ this.commandExecutor.waitToExecute(command);
+ } finally {
+ syncCommand.release();
+ }
+ }
+
+ /**
+ * Wait until all the commands currently on the queue have been executed,
+ * then execute the specified command. Suspend the command-executing thread
+ * while we execute the specified command.
+ */
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ if (timeout == 0L) {
+ this.waitToExecute(command);
+ return true;
+ }
+
+ long stop = System.currentTimeMillis() + timeout;
+ SynchronizingCommand syncCommand = new SynchronizingCommand();
+
+ this.execute(syncCommand); // dispatch the sync command to the other thread
+
+ try {
+ if (syncCommand.waitForExecution(timeout)) {
+ // adjust the time
+ timeout = stop - System.currentTimeMillis();
+ return (timeout > 0) && this.commandExecutor.waitToExecute(command, timeout);
+ }
+ return false;
+ } finally {
+ syncCommand.release();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandState.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandState.java
new file mode 100644
index 0000000000..20a7463b0b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandState.java
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedObject;
+
+/**
+ * Provide the state machine to support minimal repeat command executions.
+ */
+public class RepeatingCommandState {
+ /**
+ * The current state.
+ */
+ private final SynchronizedObject<State> state;
+
+ /**
+ * The initial {@link #state} is {@link #STOPPED}.
+ * Clients must call {@link #start()} before the command can be
+ * executed.
+ */
+ private enum State {
+ STOPPED,
+ READY,
+ PRE_EXECUTION,
+ EXECUTING,
+ REPEAT,
+ STOPPING
+ }
+
+
+ // ********** construction **********
+
+ /**
+ * Construct a repeating command state.
+ */
+ public RepeatingCommandState() {
+ super();
+ // use the command wrapper as the mutex so it is freed up by the wait in #stop()
+ this.state = new SynchronizedObject<State>(State.STOPPED, this);
+ }
+
+
+ /**
+ * Set the {@link #state} to {@link State#READY READY}.
+ * @exception IllegalStateException if the command wrapper is not
+ * {@link State#STOPPED STOPPED}.
+ */
+ public synchronized void start() {
+ switch (this.state.getValue()) {
+ case STOPPED:
+ this.state.setValue(State.READY);
+ break;
+ case READY:
+ case PRE_EXECUTION:
+ case EXECUTING:
+ case REPEAT:
+ case STOPPING:
+ throw this.buildISE();
+ }
+ }
+
+ /**
+ * A client has requested an execution.
+ * Return whether we are ready to begin a new execution "cycle".
+ * If an execution is already under way, return <code>false</code>;
+ * but set the {@link #state} to {@link State#REPEAT REPEAT}
+ * so another execution will occur once the current
+ * execution is complete.
+ * <p>
+ * <strong>NB:</strong> This method has possible side-effects:
+ * The value of {@link #state} may be changed.
+ */
+ public synchronized boolean isReadyToStartExecutionCycle() {
+ switch (this.state.getValue()) {
+ case STOPPED:
+ // execution is not allowed
+ return false;
+ case READY:
+ // start a new execution, possibly asynchronously
+ this.state.setValue(State.PRE_EXECUTION);
+ return true;
+ case PRE_EXECUTION:
+ // no need to set 'state' to PRE_EXECUTION again,
+ // the command has not yet begun executing
+ return false;
+ case EXECUTING:
+ // set 'state' to REPEAT so a new execution will occur once the current one is finished
+ this.state.setValue(State.REPEAT);
+ return false;
+ case REPEAT:
+ // no need to set 'state' to REPEAT again
+ return false;
+ case STOPPING:
+ // no further executions are allowed
+ return false;
+ }
+ throw this.buildISE();
+ }
+
+ /**
+ * An execution "cycle" is ready to begin.
+ * Make sure a call to {@link #stop()} did not slip in between the
+ * dispatching of the initial wrapped command execution (when
+ * {@link #isReadyToStartExecutionCycle()} returns <code>true</code>) and the
+ * actual execution of the wrapped command.
+ * This can happen if the wrapped command was dispatched asynchronously.
+ * <p>
+ * This method should be called from the actual execution method, before it
+ * starts looping.
+ */
+ public synchronized boolean wasStoppedBeforeFirstExecutionCouldStart() {
+ switch (this.state.getValue()) {
+ case STOPPED:
+ // a call to stop() slipped in before the command could start
+ // executing, probably because it was dispatched asynchronously
+ // by 'startCommandExecutor' (e.g. in a job)
+ return true;
+ case PRE_EXECUTION:
+ this.state.setValue(State.EXECUTING);
+ return false;
+ case READY:
+ case EXECUTING:
+ case REPEAT:
+ case STOPPING:
+ throw this.buildISE();
+ }
+ throw this.buildISE();
+ }
+
+ /**
+ * The current execution has finished.
+ * Return whether we should begin another execution because a call to
+ * execute occurred <em>during</em> the just-completed execution.
+ */
+ public synchronized boolean isRepeat() {
+ switch (this.state.getValue()) {
+ case STOPPED:
+ case READY:
+ case PRE_EXECUTION:
+ throw this.buildISE();
+ case EXECUTING:
+ // execution has finished and there are no outstanding requests for another; return to READY
+ this.state.setValue(State.READY);
+ return false;
+ case REPEAT:
+ // set 'state' back to EXECUTING and begin another execution
+ this.state.setValue(State.EXECUTING);
+ return true;
+ case STOPPING:
+ // a client initiated a "stop" during the previous execution;
+ // mark the "stop" complete and perform no more executions
+ this.state.setValue(State.STOPPED);
+ return false;
+ }
+ throw this.buildISE();
+ }
+
+ /**
+ * Return whether the execution "cycle" is "quiesced" (i.e. there are no
+ * outstanding execution requests).
+ */
+ public boolean isQuiesced() {
+ return this.state.getValue() != State.REPEAT;
+ }
+
+ /**
+ * Set {@link #state} so no further executions occur.
+ * @exception IllegalStateException if the command wrapper is already
+ * {@link State#STOPPED STOPPED} or {@link State#STOPPING STOPPING}.
+ */
+ public synchronized void stop() throws InterruptedException {
+ switch (this.state.getValue()) {
+ case READY:
+ case PRE_EXECUTION:
+ // simply set 'state' to STOPPED and return
+ this.state.setValue(State.STOPPED);
+ break;
+ case EXECUTING:
+ case REPEAT:
+ // set 'state' to STOPPING and wait until the current execution has finished
+ this.state.setValue(State.STOPPING);
+ this.waitUntilStopped();
+ break;
+ case STOPPED:
+ case STOPPING:
+ throw this.buildISE();
+ }
+ }
+
+ /**
+ * This wait will free up the command wrapper's synchronized methods
+ * (since the command wrapper is the mutex for {@link #state}).
+ * <p>
+ * If the thread that called {@link #stop()} is interrupted while waiting
+ * for the current command to finish executing on another thread,
+ * {@link #state} will still be {@link State#STOPPING STOPPING}, so the loop
+ * begun by the command wrapper will still stop and set {@link #state} to
+ * {@link State#STOPPED STOPPED}, we just won't wait around for it....
+ */
+ private void waitUntilStopped() throws InterruptedException {
+ this.state.waitUntilValueIs(State.STOPPED);
+ }
+
+ private IllegalStateException buildISE() {
+ return new IllegalStateException("state: " + this.state); //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.state);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandWrapper.java
new file mode 100644
index 0000000000..be9e4e127e
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RepeatingCommandWrapper.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.RepeatingCommand;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
+/**
+ * Wrap a repeating {@link Command}.
+ */
+public class RepeatingCommandWrapper
+ implements RepeatingCommand
+{
+ /**
+ * The client-supplied command that performs the execution. It may
+ * trigger further calls to {@link #execute()} (i.e. the <em>wrapped</em>
+ * command's execution may recurse back to the client code that executes the
+ * <em>wrapper</em> command).
+ */
+ /* CU private */ final Command command;
+
+ /**
+ * The command executed whenever the wrapped {@link #command} must be
+ * executed and it is not already executing. If the wrapped {@link #command}
+ * is already executing, it will simply be re-executed directly (once it has
+ * completed its current execution), as opposed to calling the start
+ * command.
+ */
+ private final Command startCommand;
+
+ /**
+ * The client-supplied command executor that provides the context for the
+ * {@link #startCommand start command}. By default, the start command is
+ * executed directly; but this executor provides a hook for executing the
+ * {@link #startCommand start command} asynchronously; after which,
+ * subsequent overlapping executions are executed synchronously.
+ */
+ private final CommandExecutor startCommandExecutor;
+
+ /**
+ * This handles the exceptions thrown by the <em>wrapped</em> command.
+ */
+ final ExceptionHandler exceptionHandler;
+
+ /**
+ * The command wrapper's state.
+ */
+ final RepeatingCommandState state;
+
+
+ // ********** construction **********
+
+ /**
+ * Construct a repeating command wrapper that executes the specified
+ * command. Any exceptions thrown by the command will be handled by the
+ * specified exception handler.
+ */
+ public RepeatingCommandWrapper(Command command, ExceptionHandler exceptionHandler) {
+ this(command, CommandExecutor.Default.instance(), exceptionHandler);
+ }
+
+ /**
+ * Construct a repeating command wrapper that executes the specified
+ * command and uses the specified command executor to execute the wrapped
+ * command whenever it is not already executing.
+ * Any exceptions thrown by the command will be handled by the
+ * specified exception handler.
+ */
+ public RepeatingCommandWrapper(Command command, CommandExecutor startCommandExecutor, ExceptionHandler exceptionHandler) {
+ super();
+ if ((command == null) || (startCommandExecutor == null) || (exceptionHandler == null)) {
+ throw new NullPointerException();
+ }
+ this.command = command;
+ this.startCommandExecutor = startCommandExecutor;
+ this.startCommand = this.buildStartCommand();
+ this.exceptionHandler = exceptionHandler;
+ this.state = this.buildState();
+ }
+
+ private Command buildStartCommand() {
+ return new StartCommand();
+ }
+
+ private RepeatingCommandState buildState() {
+ return new RepeatingCommandState();
+ }
+
+
+ // ********** RepeatingCommand implementation **********
+
+ public void start() {
+ this.state.start();
+ }
+
+ /**
+ * It is possible to come back here if the wrapped command recurses
+ * to the client and triggers another execution.
+ */
+ // pretty sure no need for this method to be 'synchronized'
+ public void execute() {
+ if (this.state.isReadyToStartExecutionCycle()) {
+ this.startCommandExecutor.execute(this.startCommand);
+ }
+ }
+
+ public void stop() throws InterruptedException {
+ this.state.stop();
+ }
+
+ /**
+ * The start command.
+ * @see #startCommandExecutor
+ */
+ /* CU private */ class StartCommand
+ implements Command
+ {
+ public void execute() {
+ RepeatingCommandWrapper.this.execute_();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, RepeatingCommandWrapper.this.command);
+ }
+ }
+
+ /**
+ * This method will be called only once per execution cycle.
+ * Any further calls to {@link #execute()} will
+ * simply set the {@link #state} to "repeat",
+ * causing the command to execute again.
+ */
+ /* CU private */ void execute_() {
+ if (this.state.wasStoppedBeforeFirstExecutionCouldStart()) {
+ return;
+ }
+
+ do {
+ this.executeCommand();
+ } while (this.state.isRepeat());
+ }
+
+ /**
+ * Execute the client-supplied command. Do not allow any unhandled
+ * exceptions to kill the wrapper. Pass to the exception handler.
+ * @see NotifyingRepeatingCommandWrapper
+ */
+ /* private protected */ void executeCommand() {
+ try {
+ this.command.execute();
+ } catch (Throwable ex) {
+ this.exceptionHandler.handleException(ex);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.command);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RunnableCommand.java
index 997996b5ff..1ce0c1c60a 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/RunnableCommand.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/RunnableCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,14 +7,16 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
+package org.eclipse.jpt.common.utility.internal.command;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
/**
- * Wrap a Runnable so it can be used as a Command.
+ * Wrap a {@link Runnable} so it can be used as a {@link Command}.
*/
-public class RunnableCommand implements Command {
+public class RunnableCommand
+ implements Command
+{
protected final Runnable runnable;
public RunnableCommand(Runnable runnable) {
@@ -31,7 +33,6 @@ public class RunnableCommand implements Command {
@Override
public String toString() {
- return "Command[" + this.runnable.toString() +']'; //$NON-NLS-1$
+ return "Command[" + this.runnable +']'; //$NON-NLS-1$
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeCommandExecutor.java
new file mode 100644
index 0000000000..00233bc53b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeCommandExecutor.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+
+/**
+ * @see AbstractSafeCommandExecutor
+ */
+public class SafeCommandExecutor
+ extends AbstractSafeCommandExecutor<CommandExecutor>
+{
+ /**
+ * <strong>NB:</strong> The default exception handler simply
+ * <em>ignores</em> any and all exceptions.
+ */
+ public SafeCommandExecutor() {
+ this(CommandExecutor.Default.instance());
+ }
+
+ /**
+ * <strong>NB:</strong> The default exception handler simply
+ * <em>ignores</em> any and all exceptions.
+ */
+ public SafeCommandExecutor(CommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+
+ public SafeCommandExecutor(ExceptionHandler exceptionHandler) {
+ this(CommandExecutor.Default.instance(), exceptionHandler);
+ }
+
+ public SafeCommandExecutor(CommandExecutor commandExecutor, ExceptionHandler exceptionHandler) {
+ super(commandExecutor, exceptionHandler);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeExtendedCommandExecutor.java
new file mode 100644
index 0000000000..ecfdce4ccb
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SafeExtendedCommandExecutor.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+
+/**
+ * @see AbstractSafeCommandExecutor
+ */
+public class SafeExtendedCommandExecutor
+ extends AbstractSafeCommandExecutor<ExtendedCommandExecutor>
+ implements ExtendedCommandExecutor
+{
+ /**
+ * <strong>NB:</strong> The default exception handler simply
+ * <em>ignores</em> any and all exceptions.
+ */
+ public SafeExtendedCommandExecutor() {
+ this(ExtendedCommandExecutor.Default.instance());
+ }
+
+ /**
+ * <strong>NB:</strong> The default exception handler simply
+ * <em>ignores</em> any and all exceptions.
+ */
+ public SafeExtendedCommandExecutor(ExtendedCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+
+ public SafeExtendedCommandExecutor(ExceptionHandler exceptionHandler) {
+ this(ExtendedCommandExecutor.Default.instance(), exceptionHandler);
+ }
+
+ public SafeExtendedCommandExecutor(ExtendedCommandExecutor commandExecutor, ExceptionHandler exceptionHandler) {
+ super(commandExecutor, exceptionHandler);
+ }
+
+ public void waitToExecute(Command command) throws InterruptedException {
+ try {
+ this.commandExecutor.waitToExecute(command);
+ } catch (RuntimeException ex) {
+ this.exceptionHandler.handleException(ex);
+ }
+ }
+
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ try {
+ return this.commandExecutor.waitToExecute(command, timeout);
+ } catch (RuntimeException ex) {
+ this.exceptionHandler.handleException(ex);
+ return true; // hmmm... seems like we get here only if the command executed
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulCommandExecutor.java
new file mode 100644
index 0000000000..1c95bd1ec6
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulCommandExecutor.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+
+/**
+ * Straightforward implementation of {@link StatefulCommandExecutor}
+ * that executes commands immediately by default. This executor can
+ * also be used to adapt simple {@link CommandExecutor}s to the
+ * {@link StatefulCommandExecutor} interface, providing support for
+ * lifecycle state.
+ */
+public class SimpleStatefulCommandExecutor
+ extends AbstractStatefulCommandExecutor<CommandExecutor>
+{
+ public SimpleStatefulCommandExecutor() {
+ this(CommandExecutor.Default.instance());
+ }
+
+ public SimpleStatefulCommandExecutor(CommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulExtendedCommandExecutor.java
new file mode 100644
index 0000000000..88b20bd779
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SimpleStatefulExtendedCommandExecutor.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulExtendedCommandExecutor;
+
+/**
+ * Straightforward implementation of {@link StatefulExtendedCommandExecutor}
+ * that executes commands immediately by default. This executor can
+ * also be used to adapt simple {@link CommandExecutor}s to the
+ * {@link StatefulExtendedCommandExecutor} interface, providing support for
+ * lifecycle state. Any calls to {@link #waitToExecute(Command)} suspend the
+ * calling thread until the command executor is {@link #start() started}.
+ */
+public class SimpleStatefulExtendedCommandExecutor
+ extends AbstractStatefulCommandExecutor<ExtendedCommandExecutor>
+ implements StatefulExtendedCommandExecutor
+{
+ public SimpleStatefulExtendedCommandExecutor() {
+ this(ExtendedCommandExecutor.Default.instance());
+ }
+
+ public SimpleStatefulExtendedCommandExecutor(ExtendedCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+
+ /**
+ * Suspend the current thread until the command executor is
+ * {@link #start() started}.
+ */
+ public void waitToExecute(Command command) throws InterruptedException {
+ this.active.waitUntilTrue();
+ this.commandExecutor.waitToExecute(command);
+ }
+
+ /**
+ * Suspend the current thread until the command executor is
+ * {@link #start() started}.
+ */
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ if (timeout == 0L) {
+ this.waitToExecute(command);
+ return true;
+ }
+
+ long stop = System.currentTimeMillis() + timeout;
+ if (this.active.waitUntilTrue(timeout)) {
+ // adjust the time
+ timeout = stop - System.currentTimeMillis();
+ return (timeout > 0) && this.commandExecutor.waitToExecute(command, timeout);
+ }
+ return false;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingCommandExecutor.java
new file mode 100644
index 0000000000..5bd07e12f2
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingCommandExecutor.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+
+/**
+ * @see AbstractSingleUseQueueingCommandExecutor
+ */
+public class SingleUseQueueingCommandExecutor
+ extends AbstractSingleUseQueueingCommandExecutor<StatefulCommandExecutor>
+{
+ public SingleUseQueueingCommandExecutor() {
+ this(ExtendedCommandExecutor.Default.instance());
+ }
+
+ public SingleUseQueueingCommandExecutor(CommandExecutor commandExecutor) {
+ this(new SimpleStatefulCommandExecutor(commandExecutor));
+ }
+
+ public SingleUseQueueingCommandExecutor(StatefulCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingExtendedCommandExecutor.java
new file mode 100644
index 0000000000..ab7b130b40
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SingleUseQueueingExtendedCommandExecutor.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.command.StatefulExtendedCommandExecutor;
+
+/**
+ * Calls to {@link #waitToExecute(Command)} will suspend the current thread
+ * until the command executor is {@link #start() started} and any previously-
+ * dispatched commands have executed.
+ * <p>
+ * <strong>NB:</strong> Calls to {@link #waitToExecute(Command)} will suspend
+ * the current thread <em>indefinitely</em> if the command executor is
+ * {@link #stop() stopped}.
+ *
+ * @see AbstractSingleUseQueueingCommandExecutor
+ */
+public class SingleUseQueueingExtendedCommandExecutor
+ extends AbstractSingleUseQueueingCommandExecutor<StatefulExtendedCommandExecutor>
+ implements StatefulExtendedCommandExecutor
+{
+ public SingleUseQueueingExtendedCommandExecutor() {
+ this(ExtendedCommandExecutor.Default.instance());
+ }
+
+ public SingleUseQueueingExtendedCommandExecutor(ExtendedCommandExecutor commandExecutor) {
+ this(new SimpleStatefulExtendedCommandExecutor(commandExecutor));
+ }
+
+ public SingleUseQueueingExtendedCommandExecutor(StatefulExtendedCommandExecutor commandExecutor) {
+ super(commandExecutor);
+ }
+
+ public void waitToExecute(Command command) throws InterruptedException {
+ SynchronizingCommand syncCommand = new SynchronizingCommand();
+
+ this.execute(syncCommand); // put the sync command on the queue and wait until it has executed
+
+ try {
+ syncCommand.waitForExecution();
+ this.commandExecutor.waitToExecute(command);
+ } finally {
+ syncCommand.release();
+ }
+ }
+
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ if (timeout == 0L) {
+ this.waitToExecute(command);
+ return true;
+ }
+
+ long stop = System.currentTimeMillis() + timeout;
+ SynchronizingCommand syncCommand = new SynchronizingCommand();
+
+ this.execute(syncCommand); // dispatch the sync command to the other thread
+
+ try {
+ if (syncCommand.waitForExecution(timeout)) {
+ // adjust the time
+ timeout = stop - System.currentTimeMillis();
+ return (timeout > 0) && this.commandExecutor.waitToExecute(command, timeout);
+ }
+ return false;
+ } finally {
+ syncCommand.release();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SynchronizingCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SynchronizingCommand.java
new file mode 100644
index 0000000000..d6300d8e71
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/SynchronizingCommand.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
+
+/**
+ * A <em>synchronizing</em> command can be used to coordinate the execution of
+ * the {@link Thread thread} that <em>creates</em> the <em>synchronizing</em>
+ * command (Thread A, the "primary" thread) with another {@link Thread thread}
+ * that <em>executes</em> the <em>synchronizing</em> command (Thread B, the
+ * "secondary" thread).
+ * <p>
+ * Typically, Thread A dispatches {@Command commands} to a
+ * {@link org.eclipse.jpt.common.utility.command.CommandExecutor command
+ * executor}) that executes the {@Command commands} asynchronously on Thread B.
+ * A <em>synchronizing</em> command allows Thread A to
+ * dispatch a <em>synchronizing</em> command to Thread B and suspend until
+ * the {@link #command} held by the <em>synchronizing</em> command
+ * has executed (on <em>Thread B</em>). (This can be useful when Thread B is the
+ * UI {@link Thread thread} and the {@link #command} must modify a UI widget.)
+ * Once the {@link #command} held by the <em>synchronizing</em> command has
+ * executed, Thread B suspends and notifies Thread A to proceed. Thread A can
+ * optionally execute yet another {@Command command} (on <em>Thread A</em>).
+ * Once Thread A has executed its command, it must notify Thread B that it may
+ * proceed (now independently of Thread A).
+ * <p>
+ * <strong>Timeouts:</strong> If Thread A specifies a time-limit
+ * ({@link #waitForExecution(long)}) for its suspension, and a timeout occurs
+ * (i.e. it takes too long for the <em>synchronizing</em> command to begin
+ * executing or its {@link #command} takes too long to execute),
+ * the {@link #command} held by the <em>synchronizing</em> command will
+ * <em>still be executed</em>; but Thread A will not be notified when the
+ * execution is complete. [It seems reasonable that the {@link #command} always
+ * execute, since, if it is too long-running, it will execute anyway....]
+ * <p>
+ * <strong>Synchronous Execution:</strong> If the <em>synchronizing</em> command
+ * is <em>created</em> and <em>executed</em> on the same {@link Thread thread},
+ * the assumption is Thread A and Thread B are the same {@link Thread thread}
+ * and all {@Command commands} are executing synchronously (e.g. during testing
+ * or "batch" executing).
+ * In that situation, the <em>synchronizing</em> command will <em>not</em>
+ * suspend its {@link Thread thread}.
+ */
+public class SynchronizingCommand
+ implements Command
+{
+ private final Thread thread = Thread.currentThread(); // Thread A
+ private final SynchronizedBoolean flag = new SynchronizedBoolean(false);
+ private volatile boolean expired = false; // guarded by #flag
+ private final Command command;
+
+
+ /**
+ * Construct a <em>synchronizing</em> command that does <em>not</em> execute
+ * a {@link #command} on the "secondary" {@link Thread thread} (Thread B),
+ * but simply suspends that thread until the <em>synchronizing</em> command
+ * is {@link #release() released} by the "primary" thread (Thread A).
+ */
+ public SynchronizingCommand() {
+ this(Command.Null.instance());
+ }
+
+ /**
+ * Construct a <em>synchronizing</em> command that executes the specified
+ * a command on the "secondary" {@link Thread thread} (Thread B),
+ * and then suspends that thread until the <em>synchronizing</em> command
+ * is {@link #release() released} by the "primary" thread (Thread A).
+ */
+ public SynchronizingCommand(Command command) {
+ super();
+ if (command == null) {
+ throw new NullPointerException();
+ }
+ this.command = command;
+ }
+
+ /**
+ * Typically called by a
+ * {@link org.eclipse.jpt.common.utility.command.CommandExecutor command
+ * executor} executing Thread B.
+ * <p>
+ * The "synchronizing" command has reached the front of the command queue
+ * and is executing on Thread B.
+ * Execute the wrapped command and return control to the Thread A.
+ * Suspend Thread B until Thread A resets the flag.
+ * <p>
+ * If the "synchronizing" command is executed (synchronously) on the same
+ * thread where the command was created (i.e. Thread A),
+ * it will simply set the flag appropriately and return.
+ * Otherwise, the current thread would stall indefinitely.
+ * <p>
+ * If Thread A has timed out, skip any further synchronization.
+ */
+ public void execute() {
+ this.command.execute();
+
+ synchronized (this.flag) {
+ if (this.expired) {
+ // reset the 'expired' flag and exit (don't wait for Thread A)
+ this.expired = false;
+ return;
+ }
+ // Thread A is still waiting - notify it
+ this.flag.setTrue();
+ }
+
+ if (Thread.currentThread() != this.thread) {
+ try {
+ this.flag.waitUntilFalse();
+ } catch (InterruptedException ex) {
+ // something has interrupted Thread B (the "secondary" thread);
+ // it must not want us to wait for Thread A to finish executing...
+ Thread.currentThread().interrupt(); // set the Thread's interrupt status
+ }
+ }
+ }
+
+ /**
+ * Called by Thread A to wait on Thread B to execute its command.
+ * @see #waitForExecution(long)
+ */
+ public void waitForExecution() throws InterruptedException {
+ this.flag.waitUntilTrue();
+ }
+
+ /**
+ * Called by Thread A to wait on Thread B to execute its command.
+ * @see #waitForExecution()
+ */
+ public boolean waitForExecution(long timeout) throws InterruptedException {
+ synchronized (this.flag) {
+ if (this.flag.waitUntilTrue(timeout) ) {
+ return true;
+ }
+ this.expired = true;
+ return false;
+ }
+ }
+
+ /**
+ * Called by Thread A to indicate it has executed its command.
+ * At this point the threads are independent and no longer synchronized
+ * with each other.
+ */
+ public void release() {
+ this.flag.setFalse();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.flag);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommand.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommand.java
index 02168fc1b6..e22b6199a9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ThreadLocalCommand.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,15 +7,17 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal;
+package org.eclipse.jpt.common.utility.internal.command;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
/**
* This implementation of the Command interface allows the client to
* specify a different Command for each thread.
*/
-public class ThreadLocalCommand implements Command {
+public class ThreadLocalCommand
+ implements Command
+{
protected final ThreadLocal<Command> threadLocal;
protected final Command defaultCommand;
@@ -28,6 +30,9 @@ public class ThreadLocalCommand implements Command {
public ThreadLocalCommand(Command defaultCommand) {
super();
+ if (defaultCommand == null) {
+ throw new NullPointerException();
+ }
this.defaultCommand = defaultCommand;
this.threadLocal = this.buildThreadLocal();
}
@@ -59,5 +64,4 @@ public class ThreadLocalCommand implements Command {
public String toString() {
return this.get().toString();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommandExecutor.java
new file mode 100644
index 0000000000..d47329efd4
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalCommandExecutor.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+
+/**
+ * @see AbstractThreadLocalCommandExecutor
+ */
+public class ThreadLocalCommandExecutor
+ extends AbstractThreadLocalCommandExecutor<CommandExecutor>
+{
+ /**
+ * The default command executor simply executes commands directly.
+ */
+ public ThreadLocalCommandExecutor() {
+ this(CommandExecutor.Default.instance());
+ }
+
+ public ThreadLocalCommandExecutor(CommandExecutor defaultCommandExecutor) {
+ super(defaultCommandExecutor);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalExtendedCommandExecutor.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalExtendedCommandExecutor.java
new file mode 100644
index 0000000000..b84ef42108
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/ThreadLocalExtendedCommandExecutor.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.command;
+
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+
+/**
+ * @see AbstractThreadLocalCommandExecutor
+ */
+public class ThreadLocalExtendedCommandExecutor
+ extends AbstractThreadLocalCommandExecutor<ExtendedCommandExecutor>
+ implements ExtendedCommandExecutor
+{
+ /**
+ * The default command executor simply executes commands directly.
+ */
+ public ThreadLocalExtendedCommandExecutor() {
+ this(ExtendedCommandExecutor.Default.instance());
+ }
+
+ public ThreadLocalExtendedCommandExecutor(ExtendedCommandExecutor defaultCommandExecutor) {
+ super(defaultCommandExecutor);
+ }
+
+ public void waitToExecute(Command command) throws InterruptedException {
+ this.getThreadLocalCommandExecutor().waitToExecute(command);
+ }
+
+ public boolean waitToExecute(Command command, long timeout) throws InterruptedException {
+ return this.getThreadLocalCommandExecutor().waitToExecute(command, timeout);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java
index af4b952a2b..6774ac4b6d 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -72,7 +72,7 @@ import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
* <p>
* <strong>NB3:</strong> Any listener that is added during the firing of events will <em>not</em> be
* also notified. This is a bit inconsistent with NB2, but seems reasonable
- * since any added listener should already be in synch with the model.
+ * since any added listener should already be in sync with the model.
* <p>
* <strong>NB4:</strong> This class is serializable, but it will only write out listeners that
* are also serializable while silently leaving behind listeners that are not.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModel.java
index af624292d6..27e31c28b1 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -17,22 +17,27 @@ import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
/**
- * This abstract class provides the infrastructure for "lazily" adding listeners
- * to an underlying model as necessary. Subclasses will need to engage and
- * disegage the underlying model and fire the appropriate property change
- * events. Subclasses must implement the appropriate {@link PropertyValueModel}.
+ * This abstract class provides the infrastructure for "lazily" adding/removing
+ * listeners to/from an underlying model as <em>property</em> change
+ * listeners are added to/removed from itself.
+ * Subclasses will need to engage and disengage the underlying model
+ * appropriately and fire the appropriate <em>property</em>
+ * change events.
+ * <p>
+ * Subclasses must implement the appropriate {@link PropertyValueModel}.
* <p>
* Subclasses must implement the following methods:<ul>
* <li>{@link #engageModel()}<p>
- * implement this method to add the appropriate listener to the underlying model
+ * implement this method to add the appropriate listener(s) to the
+ * underlying model
* <li>{@link #disengageModel()}<p>
- * implement this method to remove the appropriate listener from the underlying model
+ * implement this method to remove the appropriate listener(s) from the
+ * underlying model
* </ul>
*/
public abstract class AbstractPropertyValueModel
extends AbstractModel
{
-
// ********** constructor/initialization **********
protected AbstractPropertyValueModel() {
@@ -45,7 +50,7 @@ public abstract class AbstractPropertyValueModel
}
- // ********** extend change support **********
+ // ********** listeners **********
/**
* Extend to start listening to the underlying model if necessary.
@@ -91,9 +96,6 @@ public abstract class AbstractPropertyValueModel
}
}
-
- // ********** queries **********
-
/**
* Return whether the model has no property value listeners.
*/
@@ -109,7 +111,7 @@ public abstract class AbstractPropertyValueModel
}
- // ********** behavior **********
+ // ********** subclass implementation **********
/**
* Engage the underlying model.
@@ -120,5 +122,4 @@ public abstract class AbstractPropertyValueModel
* Stop listening to the underlying model.
*/
protected abstract void disengageModel();
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java
index b2dde293a2..a77b11b6cf 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractPropertyValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,20 +14,22 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
/**
* This abstract class provides the infrastructure needed to wrap
* a model, "lazily" listen to it, and convert
- * its change notifications into property value model change
+ * its change notifications into <em>property</em> value model change
* notifications.
* <p>
* Subclasses must implement:<ul>
* <li>{@link #buildValue()}<p>
* to return the current property value, as derived from the
- * current model
+ * current state of the underlying model
* <li>{@link #engageModel_()}<p>
- * to start listening to the adapted model
+ * to start listening to the underlying (adapted) model
* <li>{@link #disengageModel_()}<p>
- * to stop listening to the adapted model
+ * to stop listening to the underlying (adapted) model
* </ul>
* Subclasses can call {@link #propertyChanged()} whenever the calculated
* value of the property changes (as determined by the subclass).
+ *
+ * @param <V> the type of the model's value
*/
public abstract class AbstractPropertyValueModelAdapter<V>
extends AbstractPropertyValueModel
@@ -39,7 +41,7 @@ public abstract class AbstractPropertyValueModelAdapter<V>
* We need this because the value may be calculated and we may
* not able to derive the "old value" from any fired events.
*/
- protected V value;
+ protected volatile V value;
// ********** constructor/initialization **********
@@ -64,18 +66,18 @@ public abstract class AbstractPropertyValueModelAdapter<V>
// ********** behavior **********
/**
- * Start listening to the model and build the value.
+ * Start listening to the underlying model and build the value.
*/
@Override
protected void engageModel() {
this.engageModel_();
- // synch our value *after* we start listening to the model,
+ // sync our value *after* we start listening to the model,
// since the model's value might change when a listener is added
this.value = this.buildValue();
}
/**
- * Start listening to the model.
+ * Start listening to the underlying model.
*/
protected abstract void engageModel_();
@@ -86,7 +88,7 @@ public abstract class AbstractPropertyValueModelAdapter<V>
protected abstract V buildValue();
/**
- * Stop listening to the model and clear the value.
+ * Stop listening to the underlying model and clear the value.
*/
@Override
protected void disengageModel() {
@@ -96,13 +98,13 @@ public abstract class AbstractPropertyValueModelAdapter<V>
}
/**
- * Stop listening to the model.
+ * Stop listening to the underlying model.
*/
protected abstract void disengageModel_();
/**
* The underlying model changed in some fashion.
- * Recalculate the value and notify any listeners.
+ * Recalculate the model's value and notify listeners.
*/
protected void propertyChanged() {
Object old = this.value;
@@ -113,5 +115,4 @@ public abstract class AbstractPropertyValueModelAdapter<V>
public void toString(StringBuilder sb) {
sb.append(this.value);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java
index 99f17918c3..9dd8d46bd8 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
import org.eclipse.jpt.common.utility.internal.model.SingleAspectChangeSupport;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -22,13 +23,17 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* This abstract extension of {@link AbstractModel} provides a base for adding
* change listeners (property change, collection change, list change, tree change)
* to a subject and converting the subject's change notifications into a single
- * set of change notifications for a common aspect (e.g. <code>VALUE</code>).
+ * set of change notifications for a common aspect
+ * (e.g. {@link PropertyValueModel#VALUE}).
* <p>
- * The adapter will only listen to the subject (and subject holder) when the
+ * The adapter will only listen to the subject (and subject model) when the
* adapter itself actually has listeners. This will allow the adapter to be
- * garbage collected when appropriate
+ * garbage collected when appropriate.
+ *
+ * @param <S> the type of the model's subject
+ * @param <A> the type of the subject's aspect
*/
-public abstract class AspectAdapter<S>
+public abstract class AspectAdapter<S, A>
extends AbstractModel
{
/**
@@ -37,21 +42,21 @@ public abstract class AspectAdapter<S>
* We need to hold on to this directly so we can
* disengage it when it changes.
*/
- protected S subject;
+ protected volatile S subject;
/**
- * A value model that holds the subject
+ * A value model that holds the {@link #subject}
* that holds the aspect and provides change notification.
* This is useful when there are a number of aspect adapters
* that have the same subject and that subject can change.
- * All the aspect adapters should share the same subject holder.
+ * All the aspect adapters can share the same subject model.
* For now, this is can only be set upon construction and is
* immutable.
*/
protected final PropertyValueModel<? extends S> subjectHolder;
- /** A listener that keeps us in synch with the subject holder. */
- protected final PropertyChangeListener subjectChangeListener;
+ /** A listener that keeps us in sync with the subject model. */
+ protected final PropertyChangeListener subjectListener;
// ********** constructors **********
@@ -64,16 +69,16 @@ public abstract class AspectAdapter<S>
}
/**
- * Construct an aspect adapter for the specified subject holder.
- * The subject holder cannot be null.
+ * Construct an aspect adapter for the specified subject model.
+ * The subject model cannot be <code>null</code>.
*/
- protected AspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
+ protected AspectAdapter(PropertyValueModel<? extends S> subjectModel) {
super();
- if (subjectHolder == null) {
+ if (subjectModel == null) {
throw new NullPointerException();
}
- this.subjectHolder = subjectHolder;
- this.subjectChangeListener = this.buildSubjectChangeListener();
+ this.subjectHolder = subjectModel;
+ this.subjectListener = this.buildSubjectListener();
// the subject is null when we are not listening to it
// this will typically result in our value being null
this.subject = null;
@@ -87,29 +92,32 @@ public abstract class AspectAdapter<S>
return new LocalChangeSupport(this, this.getListenerClass(), this.getListenerAspectName());
}
- /**
- * The subject holder's value has changed, keep our subject in synch.
- */
- protected PropertyChangeListener buildSubjectChangeListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- AspectAdapter.this.subjectChanged();
- }
- @Override
- public String toString() {
- return "subject change listener"; //$NON-NLS-1$
- }
- };
+ protected PropertyChangeListener buildSubjectListener() {
+ return new SubjectListener();
+ }
+
+ protected class SubjectListener
+ extends PropertyChangeAdapter
+ {
+ /**
+ * The subject model's value has changed, keep our subject in sync.
+ */
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ AspectAdapter.this.subjectChanged();
+ }
}
// ********** behavior **********
/**
- * The subject has changed. Notify listeners that the value has changed.
+ * The subject has changed.
+ * Move our subject listener and
+ * notify listeners that the value has changed.
*/
protected synchronized void subjectChanged() {
- Object oldValue = this.getValue();
+ A old = this.getAspectValue();
boolean hasListeners = this.hasListeners();
if (hasListeners) {
this.disengageSubject();
@@ -117,14 +125,14 @@ public abstract class AspectAdapter<S>
this.subject = this.subjectHolder.getValue();
if (hasListeners) {
this.engageSubject();
- this.fireAspectChanged(oldValue, this.getValue());
+ this.fireAspectChanged(old, this.getAspectValue());
}
}
/**
* Return the aspect's current value.
*/
- protected abstract Object getValue();
+ protected abstract A getAspectValue();
/**
* Return the class of listener that is interested in the aspect adapter's
@@ -133,9 +141,10 @@ public abstract class AspectAdapter<S>
protected abstract Class<? extends EventListener> getListenerClass();
/**
- * Return the name of the aspect adapter's aspect (e.g. VALUE).
+ * Return the name of the aspect adapter's aspect
+ * (e.g. {@link PropertyValueModel#VALUE}).
* This is the name of the aspect adapter's single aspect, not the
- * name of the subject's aspect the aspect adapter is adapting.
+ * name of the subject's aspect(s) the aspect adapter is adapting.
*/
protected abstract String getListenerAspectName();
@@ -154,7 +163,25 @@ public abstract class AspectAdapter<S>
/**
* The aspect has changed, notify listeners appropriately.
*/
- protected abstract void fireAspectChanged(Object oldValue, Object newValue);
+ protected abstract void fireAspectChanged(A oldValue, A newValue);
+
+
+ // ********** engage/disengage models **********
+
+ /**
+ * Called by {@link LocalChangeSupport}
+ */
+ protected void engageModels() {
+ this.engageSubjectHolder();
+ this.engageSubject();
+ }
+
+ protected void engageSubjectHolder() {
+ this.subjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.subjectListener);
+ // sync our subject *after* we start listening to the subject holder,
+ // since its value might change when a listener is added
+ this.subject = this.subjectHolder.getValue();
+ }
protected void engageSubject() {
// check for nothing to listen to
@@ -164,10 +191,18 @@ public abstract class AspectAdapter<S>
}
/**
- * The subject is not null - add our listener.
+ * The {@link #subject} is not <code>null</code> - add our listener.
*/
protected abstract void engageSubject_();
+ /**
+ * Called by {@link LocalChangeSupport}
+ */
+ protected void disengageModels() {
+ this.disengageSubject();
+ this.disengageSubjectHolder();
+ }
+
protected void disengageSubject() {
// check for nothing to listen to
if (this.subject != null) {
@@ -176,33 +211,16 @@ public abstract class AspectAdapter<S>
}
/**
- * The subject is not null - remove our listener.
+ * The {@link #subject} is not <code>null</code> - remove our listener.
*/
protected abstract void disengageSubject_();
- protected void engageSubjectHolder() {
- this.subjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.subjectChangeListener);
- // synch our subject *after* we start listening to the subject holder,
- // since its value might change when a listener is added
- this.subject = this.subjectHolder.getValue();
- }
-
protected void disengageSubjectHolder() {
- this.subjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.subjectChangeListener);
+ this.subjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.subjectListener);
// clear out the subject when we are not listening to its holder
this.subject = null;
}
- protected void engageModels() {
- this.engageSubjectHolder();
- this.engageSubject();
- }
-
- protected void disengageModels() {
- this.disengageSubject();
- this.disengageSubjectHolder();
- }
-
// ********** local change support **********
@@ -215,10 +233,12 @@ public abstract class AspectAdapter<S>
* A relevant listener is a listener of the relevant type and aspect or a
* general-purpose listener.
*/
- protected class LocalChangeSupport extends SingleAspectChangeSupport {
+ protected class LocalChangeSupport
+ extends SingleAspectChangeSupport
+ {
private static final long serialVersionUID = 1L;
- public LocalChangeSupport(AspectAdapter<S> source, Class<? extends EventListener> validListenerClass, String validAspectName) {
+ public LocalChangeSupport(AspectAdapter<S, A> source, Class<? extends EventListener> validListenerClass, String validAspectName) {
super(source, validListenerClass, validAspectName);
}
@@ -260,7 +280,5 @@ public abstract class AspectAdapter<S>
AspectAdapter.this.disengageModels();
}
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java
index 9c7f316629..ec46773400 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -48,22 +48,22 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* override this method only if returning a zero when the
* subject is null is unacceptable
* </ul>
- * To notify listeners, subclasses can call {@link #collectionChanged()}
+ * To notify listeners, subclasses can call {@link #aspectChanged()}
* whenever the aspect has changed.
+ *
+ * @param <S> the type of the model's subject
+ * @param <E> the type of the subject's collection aspect's elements
*/
public abstract class AspectCollectionValueModelAdapter<S, E>
- extends AspectAdapter<S>
+ extends AspectAdapter<S, Collection<E>>
implements CollectionValueModel<E>
{
-
- // ********** constructors **********
-
/**
* Construct a collection value model adapter for an aspect of the
* specified subject.
*/
- protected AspectCollectionValueModelAdapter(PropertyValueModel<? extends S> subjectHolder) {
- super(subjectHolder);
+ protected AspectCollectionValueModelAdapter(PropertyValueModel<? extends S> subjectModel) {
+ super(subjectModel);
}
@@ -78,7 +78,8 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
/**
* Return the elements of the subject's collection aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #iterator()
*/
protected Iterator<E> iterator_() {
@@ -87,7 +88,8 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
/**
* Return the elements of the subject's collection aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #iterator_()
*/
protected Iterable<E> getIterable() {
@@ -103,7 +105,8 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
/**
* Return the size of the subject's collection aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #size()
*/
protected int size_() {
@@ -114,7 +117,7 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
// ********** AspectAdapter implementation **********
@Override
- protected Object getValue() {
+ protected Collection<E> getAspectValue() {
return this.buildValueCollection();
}
@@ -134,12 +137,11 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
}
@Override
- protected void fireAspectChanged(Object oldValue, Object newValue) {
- @SuppressWarnings("unchecked") Collection<E> newCollection = (Collection<E>) newValue;
- this.fireCollectionChanged(VALUES, newCollection);
+ protected void fireAspectChanged(Collection<E> oldValue, Collection<E> newValue) {
+ this.fireCollectionChanged(VALUES, newValue);
}
- protected void collectionChanged() {
+ protected void aspectChanged() {
this.fireCollectionChanged(VALUES, this.buildValueCollection());
}
@@ -151,5 +153,4 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
public void toString(StringBuilder sb) {
sb.append(this.buildValueCollection());
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java
index 41d36a066c..da7db5c4f4 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -58,11 +58,14 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* override this method only if returning an empty array when the
* subject is null is unacceptable
* </ul>
- * To notify listeners, subclasses can call {@link #listChanged()}
+ * To notify listeners, subclasses can call {@link #aspectChanged()}
* whenever the aspect has changed.
+ *
+ * @param <S> the type of the model's subject
+ * @param <E> the type of the subject's list aspect's elements
*/
public abstract class AspectListValueModelAdapter<S, E>
- extends AspectAdapter<S>
+ extends AspectAdapter<S, List<E>>
implements ListValueModel<E>
{
private static final Object[] EMPTY_ARRAY = new Object[0];
@@ -74,8 +77,8 @@ public abstract class AspectListValueModelAdapter<S, E>
* Construct a list value model adapter for an aspect of the
* specified subject.
*/
- protected AspectListValueModelAdapter(PropertyValueModel<? extends S> subjectHolder) {
- super(subjectHolder);
+ protected AspectListValueModelAdapter(PropertyValueModel<? extends S> subjectModel) {
+ super(subjectModel);
}
@@ -97,7 +100,8 @@ public abstract class AspectListValueModelAdapter<S, E>
/**
* Return the elements of the subject's list aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #listIterator()
*/
protected ListIterator<E> listIterator_() {
@@ -106,7 +110,8 @@ public abstract class AspectListValueModelAdapter<S, E>
/**
* Return the elements of the subject's list aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #listIterator_()
*/
protected ListIterable<E> getListIterable() {
@@ -129,7 +134,8 @@ public abstract class AspectListValueModelAdapter<S, E>
/**
* Return the size of the subject's list aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #size()
*/
protected int size_() {
@@ -156,7 +162,7 @@ public abstract class AspectListValueModelAdapter<S, E>
// ********** AspectAdapter implementation **********
@Override
- protected List<E> getValue() {
+ protected List<E> getAspectValue() {
return this.buildValueList();
}
@@ -176,12 +182,11 @@ public abstract class AspectListValueModelAdapter<S, E>
}
@Override
- protected void fireAspectChanged(Object oldValue, Object newValue) {
- @SuppressWarnings("unchecked") List<E> newList = (List<E>) newValue;
- this.fireListChanged(LIST_VALUES, newList);
+ protected void fireAspectChanged(List<E> oldValue, List<E> newValue) {
+ this.fireListChanged(LIST_VALUES, newValue);
}
- protected void listChanged() {
+ protected void aspectChanged() {
this.fireListChanged(LIST_VALUES, this.buildValueList());
}
@@ -193,5 +198,4 @@ public abstract class AspectListValueModelAdapter<S, E>
public void toString(StringBuilder sb) {
sb.append(this.buildValueList());
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectPropertyValueModelAdapter.java
index 180153a586..a46f54931c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectPropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectPropertyValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -41,11 +41,14 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
* override this method only if something must be done when the subject
* is <code>null</code> (e.g. throw an exception)
* </ul>
- * To notify listeners, subclasses can call {@link #propertyChanged()}
+ * To notify listeners, subclasses can call {@link #aspectChanged()}
* whenever the aspect has changed.
+ *
+ * @param <S> the type of the model's subject
+ * @param <V> the type of the subject's property aspect
*/
public abstract class AspectPropertyValueModelAdapter<S, V>
- extends AspectAdapter<S>
+ extends AspectAdapter<S, V>
implements WritablePropertyValueModel<V>
{
/**
@@ -55,17 +58,18 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
* not be in the property change event fired by the subject,
* especially when dealing with multiple aspects.
*/
- protected V value;
+ protected volatile V value;
- // ********** constructors **********
+ // ********** constructor **********
/**
* Construct a property value model adapter for an aspect of the
* specified subject.
+ * The subject model cannot be <code>null</code>.
*/
- protected AspectPropertyValueModelAdapter(PropertyValueModel<? extends S> subjectHolder) {
- super(subjectHolder);
+ protected AspectPropertyValueModelAdapter(PropertyValueModel<? extends S> subjectModel) {
+ super(subjectModel);
// our value is null when we are not listening to the subject
this.value = null;
}
@@ -76,7 +80,6 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
/**
* Return the value of the subject's aspect.
*/
- @Override
public final V getValue() {
return this.value;
}
@@ -95,7 +98,8 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
/**
* Set the value of the subject's aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #setValue(Object)
*/
protected void setValue_(@SuppressWarnings("unused") V value) {
@@ -106,6 +110,11 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
// ********** AspectAdapter implementation **********
@Override
+ protected V getAspectValue() {
+ return this.value;
+ }
+
+ @Override
protected Class<? extends EventListener> getListenerClass() {
return PropertyChangeListener.class;
}
@@ -121,14 +130,14 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
}
@Override
- protected void fireAspectChanged(Object oldValue, Object newValue) {
+ protected void fireAspectChanged(V oldValue, V newValue) {
this.firePropertyChanged(VALUE, oldValue, newValue);
}
@Override
protected void engageSubject() {
super.engageSubject();
- // synch our value *after* we start listening to the subject,
+ // sync our value *after* we start listening to the subject,
// since its value might change when a listener is added
this.value = this.buildValue();
}
@@ -145,7 +154,7 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
/**
* Return the aspect's value.
- * At this point the subject may be null.
+ * At this point the subject may be <code>null</code>.
*/
protected V buildValue() {
return (this.subject == null) ? null : this.buildValue_();
@@ -153,7 +162,8 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
/**
* Return the value of the subject's aspect.
- * At this point we can be sure the subject is not null.
+ * At this point we can be sure the {@link #subject} is
+ * <em>not</em> <code>null</code>.
* @see #buildValue()
*/
protected V buildValue_() {
@@ -164,15 +174,13 @@ public abstract class AspectPropertyValueModelAdapter<S, V>
* This method can be called by subclasses whenever the subject's aspect
* has changed; listeners will be notified appropriately.
*/
- protected void propertyChanged() {
+ protected void aspectChanged() {
V old = this.value;
- this.value = this.buildValue();
- this.fireAspectChanged(old, this.value);
+ this.fireAspectChanged(old, this.value = this.buildValue());
}
@Override
public void toString(StringBuilder sb) {
sb.append(this.value);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectTreeValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectTreeValueModelAdapter.java
deleted file mode 100644
index 6989991744..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectTreeValueModelAdapter.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import java.util.Collection;
-import java.util.EventListener;
-import java.util.Iterator;
-
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator;
-import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.TreeValueModel;
-
-/**
- * This {@link AspectAdapter} provides basic tree change support.
- * This converts an "aspect" (as defined by subclasses) into
- * a single {@link #NODES} tree.
- * <p>
- * The typical subclass will override the following methods:<ul>
- * <li>{@link #engageSubject_()}<p>
- * implement this method to add the appropriate listener to the subject
- * <li>{@link #disengageSubject_()}<p>
- * implement this method to remove the appropriate listener from the subject
- * <li>{@link #nodes_()}<p>
- * at the very minimum, override this method to return an iterator
- * on the subject's tree aspect; it does not need to be overridden if
- * {@link #nodes()} is overridden and its behavior changed
- * <li>{@link #nodes()}<p>
- * override this method only if returning an empty iterator when the
- * subject is null is unacceptable
- * </ul>
- * To notify listeners, subclasses can call {@link #treeChanged()}
- * whenever the aspect has changed.
- */
-public abstract class AspectTreeValueModelAdapter<S, E>
- extends AspectAdapter<S>
- implements TreeValueModel<E>
-{
-
- // ********** constructors **********
-
- /**
- * Construct a tree value model adapter for an aspect of the
- * specified subject.
- */
- protected AspectTreeValueModelAdapter(PropertyValueModel<? extends S> subjectHolder) {
- super(subjectHolder);
- }
-
-
- // ********** TreeValueModel implementation **********
-
- /**
- * Return the nodes of the subject's tree aspect.
- */
- public Iterator<E> nodes() {
- return (this.subject == null) ? EmptyIterator.<E>instance() : this.nodes_();
- }
-
- /**
- * Return the nodes of the subject's tree aspect.
- * At this point we can be sure the subject is not null.
- * @see #nodes()
- */
- protected Iterator<E> nodes_() {
- throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
- }
-
-
- // ********** AspectAdapter implementation **********
-
- @Override
- protected Object getValue() {
- return this.buildValueCollection();
- }
-
- @Override
- protected Class<? extends EventListener> getListenerClass() {
- return TreeChangeListener.class;
- }
-
- @Override
- protected String getListenerAspectName() {
- return NODES;
- }
-
- @Override
- protected boolean hasListeners() {
- return this.hasAnyTreeChangeListeners(NODES);
- }
-
- @Override
- protected void fireAspectChanged(Object oldValue, Object newValue) {
- @SuppressWarnings("unchecked") Collection<E> newNodes = (Collection<E>) newValue;
- this.fireTreeChanged(NODES, newNodes);
- }
-
- protected void treeChanged() {
- this.fireTreeChanged(NODES, this.buildValueCollection());
- }
-
- protected Collection<E> buildValueCollection() {
- return CollectionTools.collection(this.nodes());
- }
-
- @Override
- public void toString(StringBuilder sb) {
- sb.append(this.buildValueCollection());
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BufferedWritablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BufferedWritablePropertyValueModel.java
index 87d191ca6a..15031a21a7 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BufferedWritablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/BufferedWritablePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,126 +10,130 @@
package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
- * A <code>BufferedWritablePropertyValueModel</code> is used to hold a temporary copy of the value
- * in another property value model (the "wrapped" value holder). The application
+ * A <code>BufferedWritablePropertyValueModel</code> is used to hold a temporary
+ * copy of the value
+ * in another property value model (the "wrapped" value model). The application
* can modify this temporary copy, ad nauseam; but the temporary copy is only
- * passed through to the "wrapped" value holder when the trigger "accepts" the
+ * passed through to the "wrapped" value model when the trigger "accepts" the
* buffered value. Alternatively, the application can "reset" the buffered value
* to the original, "wrapped" value.
* <p>
- * The trigger is another {@link PropertyValueModel} that holds a {@link Boolean}
- * and the application changes the trigger's value to true on "accept", false on "reset".
+ * The trigger is another {@link PropertyValueModel} that holds a
+ * {@link Boolean} and the application changes the trigger's value to
+ * <code>true</code> on "accept", <code>false</code> on "reset".
+ * <p>
* Typically, in a dialog:<ul>
* <li>pressing the "OK" button will trigger an "accept" and close the dialog
* <li>pressing the "Cancel" button will simply close the dialog,
- * dropping the "buffered" values into the bit bucket
- * <li>pressing the "Apply" button will trigger an "accept" and leave the dialog open
- * <li>pressing the "Restore" button will trigger a "reset" and leave the dialog open
+ * dropping the "buffered" values into the bit bucket
+ * <li>pressing the "Apply" button will trigger an "accept" and leave the
+ * dialog open
+ * <li>pressing the "Restore" button will trigger a "reset" and leave the
+ * dialog open
* </ul>
- * <p>
* A number of buffered property value models can wrap another set of
* property aspect adapters that adapt the various aspects of a single
- * domain model. All the bufferd property value models can be hooked to the
+ * domain model. All the buffered property value models can be hooked to the
* same trigger, and that trigger is controlled by the application, typically
- * via the OK button in a dialog.
+ * via the "OK" button in a dialog.
*
+ * @param <V> the type of the model's value
* @see PropertyAspectAdapter
*/
-public class BufferedWritablePropertyValueModel<T>
- extends PropertyValueModelWrapper<T>
- implements WritablePropertyValueModel<T>
+public class BufferedWritablePropertyValueModel<V>
+ extends PropertyValueModelWrapper<V>
+ implements WritablePropertyValueModel<V>
{
-
/**
* We cache the value here until it is accepted and passed
- * through to the wrapped value holder.
+ * through to the wrapped value model.
*/
- protected T bufferedValue;
+ protected volatile V bufferedValue;
/**
* This is set to true when we are "accepting" the buffered value
- * and passing it through to the wrapped value holder. This allows
+ * and passing it through to the wrapped value model. This allows
* us to ignore the property change event fired by the wrapped
- * value holder.
- * (We can't stop listening to the wrapped value holder, because
+ * value model.
+ * (We can't stop listening to the wrapped value model, because
* if we are the only listener that could "deactivate" the wrapped
- * value holder.)
+ * value model.)
*/
- protected boolean accepting;
+ protected volatile boolean accepting;
/**
* This is the trigger that indicates whether the buffered value
* should be accepted or reset.
*/
- protected final PropertyValueModel<Boolean> triggerHolder;
+ protected final PropertyValueModel<Boolean> triggerModel;
- /** This listens to the trigger holder. */
- protected final PropertyChangeListener triggerChangeListener;
+ /** This listens to the trigger model. */
+ protected final PropertyChangeListener triggerListener;
/**
* This flag indicates whether our buffered value has been assigned
- * a value and is possibly out of synch with the wrapped value.
+ * a value and is possibly out of sync with the wrapped value.
*/
- protected boolean buffering;
+ protected volatile boolean buffering;
- // ********** constructors **********
+ // ********** constructor/initialization **********
/**
* Construct a buffered property value model with the specified wrapped
- * property value model and trigger holder.
+ * property value model and trigger model.
*/
- public BufferedWritablePropertyValueModel(WritablePropertyValueModel<T> valueHolder, PropertyValueModel<Boolean> triggerHolder) {
- super(valueHolder);
- if (triggerHolder == null) {
+ // TODO wrap the value model in a CachingPVMWrapper and get rid of accepting flag
+ public BufferedWritablePropertyValueModel(WritablePropertyValueModel<V> valueModel, PropertyValueModel<Boolean> triggerModel) {
+ super(valueModel);
+ if (triggerModel == null) {
throw new NullPointerException();
}
- this.triggerHolder = triggerHolder;
+ this.triggerModel = triggerModel;
this.bufferedValue = null;
this.buffering = false;
this.accepting = false;
- this.triggerChangeListener = this.buildTriggerChangeListener();
+ this.triggerListener = this.buildTriggerListener();
}
+ protected PropertyChangeListener buildTriggerListener() {
+ return new TriggerListener();
+ }
- // ********** initialization **********
-
- protected PropertyChangeListener buildTriggerChangeListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- BufferedWritablePropertyValueModel.this.triggerChanged(event);
- }
- @Override
- public String toString() {
- return "trigger change listener"; //$NON-NLS-1$
- }
- };
+ protected class TriggerListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ BufferedWritablePropertyValueModel.this.triggerChanged(event);
+ }
}
- // ********** ValueModel implementation **********
+ // ********** value **********
/**
* If we are currently "buffering" a value, return that;
* otherwise, return the wrapped value.
*/
- public T getValue() {
- return this.buffering ? this.bufferedValue : this.valueHolder.getValue();
+ public V getValue() {
+ return this.buffering ? this.bufferedValue : this.valueModel.getValue();
}
/**
* Assign the new value to our "buffered" value.
- * It will be pushed to the wrapped value holder
+ * It will be pushed to the wrapped value model
* when the trigger is "accepted".
*/
- public void setValue(T value) {
+ public void setValue(V value) {
if (this.buffering) {
- if (this.valuesAreEqual(value, this.valueHolder.getValue())) {
+ if (this.valuesAreEqual(value, this.valueModel.getValue())) {
// the buffered value is being set back to the original value
this.reset();
} else {
@@ -139,11 +143,11 @@ public class BufferedWritablePropertyValueModel<T>
this.firePropertyChanged(VALUE, old, value);
}
} else {
- if (this.valuesAreEqual(value, this.valueHolder.getValue())) {
+ if (this.valuesAreEqual(value, this.valueModel.getValue())) {
// the buffered value is being set to the same value as the original value - ignore
} else {
// the buffered value is being set for the first time
- Object old = this.valueHolder.getValue();
+ Object old = this.valueModel.getValue();
this.bufferedValue = value;
this.buffering = true;
this.firePropertyChanged(VALUE, old, value);
@@ -155,20 +159,20 @@ public class BufferedWritablePropertyValueModel<T>
// ********** PropertyValueModelWrapper extensions **********
/**
- * extend to engage the trigger holder also
+ * Extend to engage the trigger model also.
*/
@Override
protected void engageModel() {
super.engageModel();
- this.triggerHolder.addPropertyChangeListener(VALUE, this.triggerChangeListener);
+ this.triggerModel.addPropertyChangeListener(VALUE, this.triggerListener);
}
/**
- * extend to disengage the trigger holder also
+ * Extend to disengage the trigger model also.
*/
@Override
protected void disengageModel() {
- this.triggerHolder.removePropertyChangeListener(VALUE, this.triggerChangeListener);
+ this.triggerModel.removePropertyChangeListener(VALUE, this.triggerListener);
super.disengageModel();
}
@@ -181,9 +185,9 @@ public class BufferedWritablePropertyValueModel<T>
* them and our own listeners are already aware of the change.
*/
@Override
- protected void valueChanged(PropertyChangeEvent event) {
+ protected void wrappedValueChanged(PropertyChangeEvent event) {
if ( ! this.accepting) {
- this.valueChanged_(event);
+ this.wrappedValueChanged_(event);
}
}
@@ -194,7 +198,7 @@ public class BufferedWritablePropertyValueModel<T>
* If we do not yet have a "buffered" value, simply propagate the
* change notification with the buffered model as the source.
*/
- protected void valueChanged_(PropertyChangeEvent event) {
+ protected void wrappedValueChanged_(PropertyChangeEvent event) {
if (this.buffering) {
if (this.valuesAreEqual(event.getNewValue(), this.bufferedValue)) {
// the buffered value is being set back to the original value
@@ -220,18 +224,23 @@ public class BufferedWritablePropertyValueModel<T>
// the default is to do nothing
}
+ protected void triggerChanged(PropertyChangeEvent event) {
+ this.triggerChanged(((Boolean) event.getNewValue()).booleanValue());
+ }
+
/**
* The trigger changed:<ul>
- * <li>If it is now true, "accept" the buffered value and push
- * it to the wrapped value holder.
- * <li>If it is now false, "reset" the buffered value to its original value.
+ * <li>If it is now <code>true</code>, "accept" the buffered value and push
+ * it to the wrapped value model.
+ * <li>If it is now <code>false</code>, "reset" the buffered value to its
+ * original value.
* </ul>
*/
- protected void triggerChanged(PropertyChangeEvent event) {
+ protected void triggerChanged(boolean triggerValue) {
// if nothing has been "buffered", we don't need to do anything:
// nothing needs to be passed through; nothing needs to be reset;
if (this.buffering) {
- if (((Boolean) event.getNewValue()).booleanValue()) {
+ if (triggerValue) {
this.accept();
} else {
this.reset();
@@ -241,10 +250,10 @@ public class BufferedWritablePropertyValueModel<T>
protected void accept() {
// set the accepting flag so we ignore any events
- // fired by the wrapped value holder
+ // fired by the wrapped value model
this.accepting = true;
try {
- this.getValueHolder().setValue(this.bufferedValue);
+ this.getValueModel().setValue(this.bufferedValue);
} finally {
this.bufferedValue = null;
this.buffering = false;
@@ -258,7 +267,7 @@ public class BufferedWritablePropertyValueModel<T>
Object old = this.bufferedValue;
this.bufferedValue = null;
this.buffering = false;
- this.firePropertyChanged(VALUE, old, this.valueHolder.getValue());
+ this.firePropertyChanged(VALUE, old, this.valueModel.getValue());
}
@Override
@@ -267,7 +276,7 @@ public class BufferedWritablePropertyValueModel<T>
}
- // ********** convenience methods **********
+ // ********** misc **********
/**
* Return whether the buffered model is currently "buffering"
@@ -281,24 +290,22 @@ public class BufferedWritablePropertyValueModel<T>
* Our constructor accepts only a {@link WritablePropertyValueModel}{@code<T>}.
*/
@SuppressWarnings("unchecked")
- protected WritablePropertyValueModel<T> getValueHolder() {
- return (WritablePropertyValueModel<T>) this.valueHolder;
+ protected WritablePropertyValueModel<V> getValueModel() {
+ return (WritablePropertyValueModel<V>) this.valueModel;
}
- // ********** inner class **********
+ // ********** trigger **********
/**
* <code>Trigger</code> is a special property value model that only maintains its
* value (of <code>true</code> or <code>false</code>) during the change notification caused by
- * {@link #setValue(T)}. In other words, a <code>Trigger</code>
+ * {@link #setValue(Object)}. In other words, a <code>Trigger</code>
* only has a valid value when it is being set.
*/
- public static class Trigger extends SimplePropertyValueModel<Boolean> {
-
-
- // ********** constructor **********
-
+ public static class Trigger
+ extends SimplePropertyValueModel<Boolean>
+ {
/**
* Construct a trigger with a null value.
*/
@@ -386,7 +393,5 @@ public class BufferedWritablePropertyValueModel<T>
public boolean isReset() {
return ! this.booleanValue();
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingPropertyValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingPropertyValueModelWrapper.java
new file mode 100644
index 0000000000..cb58b44fa5
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingPropertyValueModelWrapper.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+
+/**
+ * Wrap a writable property value model and cache its value so any changes
+ * made via the wrapper model will not fire any events to its listeners.
+ * Thus, a client can modify and listen to the wrapper model and not receive
+ * a change event when the client modifies the wrapper model; but any changes
+ * made by other clients (directly to the original model) will fire events
+ * to the client.
+ *
+ * @param <V> the type of the model's value
+ */
+public class CachingPropertyValueModelWrapper<V>
+ extends PropertyValueModelWrapper<V>
+ implements WritablePropertyValueModel<V>
+{
+ /**
+ * Cache the value so we ignore any property change events
+ * we ourselves trigger.
+ */
+ protected volatile V value;
+
+
+ /**
+ * Construct a caching writable property value model with the specified
+ * nested writable property value model.
+ */
+ public CachingPropertyValueModelWrapper(WritablePropertyValueModel<V> valueModel) {
+ super(valueModel);
+ }
+
+ /**
+ * Return the cached value, since it is up-to-date.
+ */
+ public V getValue() {
+ return this.value;
+ }
+
+ /**
+ * Cache the new value so we ignore the resulting property change event.
+ */
+ public void setValue(V value) {
+ this.value = value;
+ this.getValueModel().setValue(value);
+ }
+
+ @Override
+ protected void wrappedValueChanged(V oldValue, V newValue) {
+ V old = this.value;
+ // the new event will be suppressed if it is the result of a new value
+ // forwarded from this wrapper (i.e. 'old' and 'newValue' are equal)
+ this.firePropertyChanged(VALUE, old, this.value = newValue);
+ }
+
+ /**
+ * Our constructors accept only a
+ * {@link WritablePropertyValueModel}{@code<V>},
+ * so this cast should be safe.
+ */
+ @SuppressWarnings("unchecked")
+ protected WritablePropertyValueModel<V> getValueModel() {
+ return (WritablePropertyValueModel<V>) this.valueModel;
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.value);
+ }
+
+
+ // ********** listeners **********
+
+ /**
+ * We have listeners, cache the nested value.
+ */
+ @Override
+ protected void engageModel() {
+ super.engageModel();
+ this.value = this.valueModel.getValue();
+ }
+
+ /**
+ * We have no more listeners, clear the cached value.
+ */
+ @Override
+ protected void disengageModel() {
+ this.value = null;
+ super.disengageModel();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationPropertyValueModel.java
deleted file mode 100644
index c62e6853bf..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationPropertyValueModel.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.internal.Transformer;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * A <code>CachingTransformationPropertyValueModel</code> wraps another
- * {@link PropertyValueModel} and uses a {@link Transformer}
- * to transform the wrapped value before it is returned by {@link #getValue()}.
- * The transformed value is calculated and cached during initialization and every
- * time the wrapped value changes. This can be useful when the old value
- * passed in to {@link #valueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)}
- * can no longer be "transformed" because its state is no longer valid.
- * This caching can also improve time performance in some situations.
- * <p>
- * As an alternative to building a {@link Transformer},
- * a subclass of <code>CachingTransformationPropertyValueModel</code> can
- * either override {@link #transform_(Object)} or,
- * if something other than null should be returned when the wrapped value
- * is null, override {@link #transform(Object)}.
- */
-public class CachingTransformationPropertyValueModel<T1, T2>
- extends TransformationPropertyValueModel<T1, T2>
-{
- /**
- * Cache the transformed value so that during property change event notification
- * we do not have to transform the old value. The old value could no longer be valid in
- * the model; as a result, transforming it would not be valid.
- */
- protected T2 cachedValue;
-
-
- // ********** constructors/initialization **********
-
- /**
- * Construct a property value model with the specified nested
- * property value model and the default transformer.
- * Use this constructor if you want to override
- * {@link #transform_(Object)} or {@link #transform(Object)}
- * instead of building a {@link Transformer}.
- */
- public CachingTransformationPropertyValueModel(PropertyValueModel<? extends T1> valueHolder) {
- super(valueHolder);
- }
-
- /**
- * Construct an property value model with the specified nested
- * property value model and transformer.
- */
- public CachingTransformationPropertyValueModel(PropertyValueModel<? extends T1> valueHolder, Transformer<T1, T2> transformer) {
- super(valueHolder, transformer);
- }
-
-
- // ********** behavior **********
-
- /**
- * We have listeners, transform the nested value and cache the result.
- */
- @Override
- protected void engageModel() {
- super.engageModel();
- this.cachedValue = this.transform(this.valueHolder.getValue());
- }
-
- /**
- * We have no more listeners, clear the cached value.
- */
- @Override
- protected void disengageModel() {
- this.cachedValue = null;
- super.disengageModel();
- }
-
- /**
- * No need to transform the nested value, simply return the cached value,
- * which is already transformed.
- */
- @Override
- public T2 getValue() {
- return this.cachedValue;
- }
-
- /**
- * Transform the specified new value, caching it before returning it.
- * A bit of a side-effect, but it seems reasonable.
- */
- @Override
- protected T2 transformNew(T1 value) {
- this.cachedValue = super.transformNew(value);
- return this.cachedValue;
- }
-
- /**
- * No need to transform the old value, simply return the cached value,
- * which is already transformed.
- */
- @Override
- protected T2 transformOld(T1 value) {
- return this.cachedValue;
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java
deleted file mode 100644
index 1560367c3e..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
-import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
-
-/**
- * A <code>CachingTransformationWritablePropertyValueModel<code> augments the
- * behavior of a {@link TransformationWritablePropertyValueModel} by caching
- * the transformed value.
- * The transformed value is calculated and cached during initialization and every
- * time the wrapped value changes. This can be useful when the old value
- * passed in to {@link #valueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)}
- * can no longer be "transformed" because its state is no longer valid.
- * This caching can also improve time performance in some situations.
- */
-public class CachingTransformationWritablePropertyValueModel<T1, T2>
- extends TransformationWritablePropertyValueModel<T1, T2>
-{
- /**
- * Cache the transformed value so that during property change event notification
- * we do not have to transform the old value. The old value could no longer be valid in
- * the model; as a result, transforming it would not be valid.
- */
- protected T2 cachedValue;
-
-
- // ********** constructors/initialization **********
-
- /**
- * Construct a writable property value model with the specified nested
- * writable property value model and the default bidi transformer.
- * Use this constructor if you want to override
- * {@link #transform_(Object)} and {@link reverseTransform_(Object)}
- * (or {@link #transform(Object)} and {@link #reverseTransform(Object)})
- * methods instead of building a {@link BidiTransformer}.
- */
- public CachingTransformationWritablePropertyValueModel(WritablePropertyValueModel<T1> valueHolder) {
- super(valueHolder);
- }
-
- /**
- * Construct a writable property value model with the specified nested
- * writable property value model and bidi transformer.
- */
- public CachingTransformationWritablePropertyValueModel(WritablePropertyValueModel<T1> valueHolder, BidiTransformer<T1, T2> transformer) {
- super(valueHolder, transformer);
- }
-
-
- // ********** behavior **********
-
- /**
- * We have listeners, transform the nested value and cache the result.
- */
- @Override
- protected void engageModel() {
- super.engageModel();
- this.cachedValue = this.transform(this.valueHolder.getValue());
- }
-
- /**
- * We have no more listeners, clear the cached value.
- */
- @Override
- protected void disengageModel() {
- this.cachedValue = null;
- super.disengageModel();
- }
-
- /**
- * No need to transform the nested value, simply return the cached value,
- * which is already transformed.
- */
- @Override
- public T2 getValue() {
- return this.cachedValue;
- }
-
- /**
- * Transform the specified new value, caching it before returning it.
- * A bit of a side-effect, but it seems reasonable.
- */
- @Override
- protected T2 transformNew(T1 value) {
- this.cachedValue = super.transformNew(value);
- return this.cachedValue;
- }
-
- /**
- * No need to transform the old value, simply return the cached value,
- * which is already transformed.
- */
- @Override
- protected T2 transformOld(T1 value) {
- return this.cachedValue;
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ChangePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ChangePropertyValueModelAdapter.java
index 56d8ddd85e..3dcf14af6a 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ChangePropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ChangePropertyValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.ChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.listener.SimpleChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.AbstractChangeListener;
/**
* This abstract class provides the infrastructure needed to wrap
@@ -20,7 +20,7 @@ import org.eclipse.jpt.common.utility.model.listener.SimpleChangeListener;
* its change notifications into property value model change
* notifications.
* <p>
- * Subclasses must override:<ul>
+ * Subclasses must implement:<ul>
* <li>{@link #buildValue()}<p>
* to return the current property value, as derived from the
* current model
@@ -37,8 +37,8 @@ public abstract class ChangePropertyValueModelAdapter<T>
/** The wrapped model. */
protected final Model model;
- /** A listener that allows us to synch with changes to the wrapped collection holder. */
- protected final ChangeListener changeListener;
+ /** A listener that allows us to sync with changes to the wrapped collection model. */
+ protected final ChangeListener modelListener;
// ********** constructor/initialization **********
@@ -48,21 +48,24 @@ public abstract class ChangePropertyValueModelAdapter<T>
*/
protected ChangePropertyValueModelAdapter(Model model) {
super();
+ if (model == null) {
+ throw new NullPointerException();
+ }
this.model = model;
- this.changeListener = this.buildChangeListener();
+ this.modelListener = this.buildChangeListener();
}
protected ChangeListener buildChangeListener() {
- return new SimpleChangeListener() {
- @Override
- protected void modelChanged(ChangeEvent event) {
- ChangePropertyValueModelAdapter.this.modelChanged(event);
- }
- @Override
- public String toString() {
- return "change listener command"; //$NON-NLS-1$
- }
- };
+ return new ModelListener();
+ }
+
+ protected class ModelListener
+ extends AbstractChangeListener
+ {
+ @Override
+ protected void modelChanged(ChangeEvent event) {
+ ChangePropertyValueModelAdapter.this.modelChanged(event);
+ }
}
@@ -73,7 +76,7 @@ public abstract class ChangePropertyValueModelAdapter<T>
*/
@Override
protected void engageModel_() {
- this.model.addChangeListener(this.changeListener);
+ this.model.addChangeListener(this.modelListener);
}
/**
@@ -81,7 +84,7 @@ public abstract class ChangePropertyValueModelAdapter<T>
*/
@Override
protected void disengageModel_() {
- this.model.removeChangeListener(this.changeListener);
+ this.model.removeChangeListener(this.modelListener);
}
@@ -95,5 +98,4 @@ public abstract class ChangePropertyValueModelAdapter<T>
// by default, simply recalculate the value and fire an event
this.propertyChanged();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java
index b9a0cf9362..c84c33eb0e 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionAspectAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,14 +9,13 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
-import java.util.Arrays;
import java.util.Collection;
-
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -28,12 +27,15 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* <p>
* The typical subclass will override the following methods (see the descriptions
* in {@link AspectCollectionValueModelAdapter}):<ul>
- * <li>{@link #getIterable()}
- * <li>{@link #size_()}
+ * <li>{@link #getIterable()} - preferred
+ * <li>{@link #size_()} - semi-preferred
* <li>{@link #iterator_()}
* <li>{@link #iterator()}
* <li>{@link #size()}
* </ul>
+ *
+ * @param <S> the type of the adapter's subject
+ * @param <E> the type of the adapter's collection's elements
*/
public abstract class CollectionAspectAdapter<S extends Model, E>
extends AspectCollectionValueModelAdapter<S, E>
@@ -41,47 +43,47 @@ public abstract class CollectionAspectAdapter<S extends Model, E>
/**
* The name of the subject's collections that we use for the value.
*/
- protected final String[] collectionNames;
- protected static final String[] EMPTY_COLLECTION_NAMES = new String[0];
+ protected final String[] aspectNames;
+ protected static final String[] EMPTY_ASPECT_NAMES = new String[0];
/** A listener that listens to the subject's collection aspects. */
- protected final CollectionChangeListener collectionChangeListener;
+ protected final CollectionChangeListener aspectChangeListener;
// ********** constructors **********
/**
* Construct a collection aspect adapter for the specified subject
- * and collection.
+ * and collection aspect.
*/
- protected CollectionAspectAdapter(String collectionName, S subject) {
- this(new String[] {collectionName}, subject);
+ protected CollectionAspectAdapter(String aspectName, S subject) {
+ this(new String[] {aspectName}, subject);
}
/**
* Construct a collection aspect adapter for the specified subject
- * and collections.
+ * and collection aspects.
*/
- protected CollectionAspectAdapter(String[] collectionNames, S subject) {
- this(new StaticPropertyValueModel<S>(subject), collectionNames);
+ protected CollectionAspectAdapter(String[] aspectNames, S subject) {
+ this(new StaticPropertyValueModel<S>(subject), aspectNames);
}
/**
- * Construct a collection aspect adapter for the specified subject holder
- * and collections.
+ * Construct a collection aspect adapter for the specified subject model
+ * and collection apects.
*/
- protected CollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder, String... collectionNames) {
- super(subjectHolder);
- this.collectionNames = collectionNames;
- this.collectionChangeListener = this.buildCollectionChangeListener();
+ protected CollectionAspectAdapter(PropertyValueModel<? extends S> subjectModel, String... aspectNames) {
+ super(subjectModel);
+ this.aspectNames = aspectNames;
+ this.aspectChangeListener = this.buildAspectChangeListener();
}
/**
* Construct a collection aspect adapter for the specified subject holder
- * and collections.
+ * and collection aspects.
*/
- protected CollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder, Collection<String> collectionNames) {
- this(subjectHolder, collectionNames.toArray(new String[collectionNames.size()]));
+ protected CollectionAspectAdapter(PropertyValueModel<? extends S> subjectModel, Collection<String> aspectNames) {
+ this(subjectModel, aspectNames.toArray(new String[aspectNames.size()]));
}
/**
@@ -90,33 +92,40 @@ public abstract class CollectionAspectAdapter<S extends Model, E>
* change for a particular subject; but the subject will change, resulting in
* a new collection.
*/
- protected CollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
- this(subjectHolder, EMPTY_COLLECTION_NAMES);
+ protected CollectionAspectAdapter(PropertyValueModel<? extends S> subjectModel) {
+ this(subjectModel, EMPTY_ASPECT_NAMES);
}
// ********** initialization **********
- protected CollectionChangeListener buildCollectionChangeListener() {
- // transform the subject's collection change events into VALUES collection change events
- return new CollectionChangeListener() {
- public void itemsAdded(CollectionAddEvent event) {
- CollectionAspectAdapter.this.itemsAdded(event);
- }
- public void itemsRemoved(CollectionRemoveEvent event) {
- CollectionAspectAdapter.this.itemsRemoved(event);
- }
- public void collectionCleared(CollectionClearEvent event) {
- CollectionAspectAdapter.this.collectionCleared(event);
- }
- public void collectionChanged(CollectionChangeEvent event) {
- CollectionAspectAdapter.this.collectionChanged(event);
- }
- @Override
- public String toString() {
- return "collection change listener: " + Arrays.asList(CollectionAspectAdapter.this.collectionNames); //$NON-NLS-1$
- }
- };
+ protected CollectionChangeListener buildAspectChangeListener() {
+ return new AspectChangeListener();
+ }
+
+ /**
+ * Transform the subject's collection change events into {@link #VALUES}
+ * collection change events
+ */
+ protected class AspectChangeListener
+ extends CollectionChangeAdapter
+ {
+ @Override
+ public void itemsAdded(CollectionAddEvent event) {
+ CollectionAspectAdapter.this.aspectItemsAdded(event);
+ }
+ @Override
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ CollectionAspectAdapter.this.aspectItemsRemoved(event);
+ }
+ @Override
+ public void collectionCleared(CollectionClearEvent event) {
+ CollectionAspectAdapter.this.aspectCollectionCleared(event);
+ }
+ @Override
+ public void collectionChanged(CollectionChangeEvent event) {
+ CollectionAspectAdapter.this.aspectCollectionChanged(event);
+ }
}
@@ -124,35 +133,34 @@ public abstract class CollectionAspectAdapter<S extends Model, E>
@Override
protected void engageSubject_() {
- for (String collectionName : this.collectionNames) {
- ((Model) this.subject).addCollectionChangeListener(collectionName, this.collectionChangeListener);
+ for (String collectionName : this.aspectNames) {
+ this.subject.addCollectionChangeListener(collectionName, this.aspectChangeListener);
}
}
@Override
protected void disengageSubject_() {
- for (String collectionName : this.collectionNames) {
- ((Model) this.subject).removeCollectionChangeListener(collectionName, this.collectionChangeListener);
+ for (String collectionName : this.aspectNames) {
+ this.subject.removeCollectionChangeListener(collectionName, this.aspectChangeListener);
}
}
- // ********** behavior **********
+ // ********** events **********
- protected void itemsAdded(CollectionAddEvent event) {
+ protected void aspectItemsAdded(CollectionAddEvent event) {
this.fireItemsAdded(event.clone(this, VALUES));
}
- protected void itemsRemoved(CollectionRemoveEvent event) {
+ protected void aspectItemsRemoved(CollectionRemoveEvent event) {
this.fireItemsRemoved(event.clone(this, VALUES));
}
- protected void collectionCleared(CollectionClearEvent event) {
+ protected void aspectCollectionCleared(CollectionClearEvent event) {
this.fireCollectionCleared(event.clone(this, VALUES));
}
- protected void collectionChanged(CollectionChangeEvent event) {
+ protected void aspectCollectionChanged(CollectionChangeEvent event) {
this.fireCollectionChanged(event.clone(this, VALUES));
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionListValueModelAdapter.java
index 4c3d8b4cca..8ae33d53e9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -27,10 +27,10 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
* a read-only {@link ListValueModel}, sorta.
* <p>
* To maintain a reasonably consistent appearance to client code, we
- * keep an internal list somewhat in synch with the wrapped collection.
+ * keep an internal list somewhat in sync with the wrapped collection.
* <p>
* <strong>NB:</strong> Since we only listen to the wrapped collection when we have
- * listeners ourselves and we can only stay in synch with the wrapped
+ * listeners ourselves and we can only stay in sync with the wrapped
* collection while we are listening to it, results to various methods
* (e.g. {@link #size()}, {@link #get(int)}) will be unpredictable whenever
* we do not have any listeners. This should not be too painful since,
@@ -128,7 +128,7 @@ public class CollectionListValueModelAdapter<E>
@Override
protected void engageModel() {
this.collectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.collectionChangeListener);
- // synch our list *after* we start listening to the collection holder,
+ // sync our list *after* we start listening to the collection model,
// since its value might change when a listener is added
this.buildList();
}
@@ -213,5 +213,4 @@ public class CollectionListValueModelAdapter<E>
public void toString(StringBuilder sb) {
sb.append(this.list);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java
index 24d18b27ab..1f636e5fd1 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionPropertyValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
+import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
@@ -30,19 +31,24 @@ import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
* Subclasses might want to override the following methods
* to improve performance (by not recalculating the value, if possible):<ul>
* <li>{@link #itemsAdded(CollectionAddEvent event)}
+ * <li>{@link #itemsAdded(Iterable)}
* <li>{@link #itemsRemoved(CollectionRemoveEvent event)}
+ * <li>{@link #itemsRemoved(Iterable)}
* <li>{@link #collectionCleared(CollectionClearEvent event)}
* <li>{@link #collectionChanged(CollectionChangeEvent event)}
* </ul>
+ *
+ * @param <V> the type of the model's value
+ * @param <E> the type of the wrapped collection value model's elements
*/
-public abstract class CollectionPropertyValueModelAdapter<V>
+public abstract class CollectionPropertyValueModelAdapter<V, E>
extends AbstractPropertyValueModelAdapter<V>
{
/** The wrapped collection value model. */
- protected final CollectionValueModel<?> collectionModel;
+ protected final CollectionValueModel<? extends E> collectionModel;
- /** A listener that allows us to synch with changes to the wrapped collection holder. */
- protected final CollectionChangeListener collectionChangeListener;
+ /** A listener that allows us to sync with changes to the wrapped collection model. */
+ protected final CollectionChangeListener collectionListener;
// ********** constructor/initialization **********
@@ -51,42 +57,52 @@ public abstract class CollectionPropertyValueModelAdapter<V>
* Construct a property value model with the specified wrapped
* collection value model.
*/
- protected CollectionPropertyValueModelAdapter(CollectionValueModel<?> collectionModel) {
+ protected CollectionPropertyValueModelAdapter(CollectionValueModel<? extends E> collectionModel) {
super();
+ if (collectionModel == null) {
+ throw new NullPointerException();
+ }
this.collectionModel = collectionModel;
- this.collectionChangeListener = this.buildCollectionChangeListener();
+ this.collectionListener = this.buildCollectionListener();
+ }
+
+ protected CollectionChangeListener buildCollectionListener() {
+ return new CollectionListener();
}
- protected CollectionChangeListener buildCollectionChangeListener() {
- return new CollectionChangeListener() {
- public void itemsAdded(CollectionAddEvent event) {
- CollectionPropertyValueModelAdapter.this.itemsAdded(event);
- }
- public void itemsRemoved(CollectionRemoveEvent event) {
- CollectionPropertyValueModelAdapter.this.itemsRemoved(event);
- }
- public void collectionCleared(CollectionClearEvent event) {
- CollectionPropertyValueModelAdapter.this.collectionCleared(event);
- }
- public void collectionChanged(CollectionChangeEvent event) {
- CollectionPropertyValueModelAdapter.this.collectionChanged(event);
- }
- @Override
- public String toString() {
- return "collection change listener"; //$NON-NLS-1$
- }
- };
+ /**
+ * Straightforward callbacks to the adapter.
+ */
+ protected class CollectionListener
+ extends CollectionChangeAdapter
+ {
+ @Override
+ public void itemsAdded(CollectionAddEvent event) {
+ CollectionPropertyValueModelAdapter.this.itemsAdded(event);
+ }
+ @Override
+ public void itemsRemoved(CollectionRemoveEvent event) {
+ CollectionPropertyValueModelAdapter.this.itemsRemoved(event);
+ }
+ @Override
+ public void collectionCleared(CollectionClearEvent event) {
+ CollectionPropertyValueModelAdapter.this.collectionCleared(event);
+ }
+ @Override
+ public void collectionChanged(CollectionChangeEvent event) {
+ CollectionPropertyValueModelAdapter.this.collectionChanged(event);
+ }
}
- // ********** behavior **********
+ // ********** listener **********
/**
* Start listening to the collection holder.
*/
@Override
protected void engageModel_() {
- this.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.collectionChangeListener);
+ this.collectionModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.collectionListener);
}
/**
@@ -94,7 +110,7 @@ public abstract class CollectionPropertyValueModelAdapter<V>
*/
@Override
protected void disengageModel_() {
- this.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this.collectionChangeListener);
+ this.collectionModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this.collectionListener);
}
@@ -104,7 +120,17 @@ public abstract class CollectionPropertyValueModelAdapter<V>
* Items were added to the wrapped collection holder;
* propagate the change notification appropriately.
*/
- protected void itemsAdded(@SuppressWarnings("unused") CollectionAddEvent event) {
+ protected void itemsAdded(CollectionAddEvent event) {
+ @SuppressWarnings("unchecked")
+ Iterable<E> items = (Iterable<E>) event.getItems();
+ this.itemsAdded(items);
+ }
+
+ /**
+ * The specified items were added to the wrapped collection holder;
+ * propagate the change notification appropriately.
+ */
+ protected void itemsAdded(@SuppressWarnings("unused") Iterable<E> items) {
// by default, simply recalculate the value and fire an event
this.propertyChanged();
}
@@ -113,8 +139,18 @@ public abstract class CollectionPropertyValueModelAdapter<V>
* Items were removed from the wrapped collection holder;
* propagate the change notification appropriately.
*/
- protected void itemsRemoved(@SuppressWarnings("unused") CollectionRemoveEvent event) {
- // by default, simply recalculate the value and fire an event
+ protected void itemsRemoved(CollectionRemoveEvent event) {
+ @SuppressWarnings("unchecked")
+ Iterable<E> items = (Iterable<E>) event.getItems();
+ this.itemsRemoved(items);
+ }
+
+ /**
+ * The specified items were removed from the wrapped collection holder;
+ * propagate the change notification appropriately.
+ */
+ protected void itemsRemoved(@SuppressWarnings("unused") Iterable<E> items) {
+ // by default, simply recalculate the value and fire an event if necessary
this.propertyChanged();
}
@@ -123,7 +159,7 @@ public abstract class CollectionPropertyValueModelAdapter<V>
* propagate the change notification appropriately.
*/
protected void collectionCleared(@SuppressWarnings("unused") CollectionClearEvent event) {
- // by default, simply recalculate the value and fire an event
+ // by default, simply recalculate the value and fire an event if necessary
this.propertyChanged();
}
@@ -132,8 +168,7 @@ public abstract class CollectionPropertyValueModelAdapter<V>
* propagate the change notification appropriately.
*/
protected void collectionChanged(@SuppressWarnings("unused") CollectionChangeEvent event) {
- // by default, simply recalculate the value and fire an event
+ // by default, simply recalculate the value and fire an event if necessary
this.propertyChanged();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java
index a791dcb3d3..a3417a13b1 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CollectionValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -28,7 +28,7 @@ public abstract class CollectionValueModelWrapper<E>
/** The wrapped collection value model. */
protected final CollectionValueModel<? extends E> collectionHolder;
- /** A listener that allows us to synch with changes to the wrapped collection holder. */
+ /** A listener that allows us to sync with changes to the wrapped collection model. */
protected final CollectionChangeListener collectionChangeListener;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java
index acedc5ebb4..a08ef48875 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeBooleanPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,8 @@
package org.eclipse.jpt.common.utility.internal.model.value;
import java.util.Collection;
-
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -32,7 +33,7 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* that determine the model's value (TRUE or FALSE) when <code>null</code>.
*/
public class CompositeBooleanPropertyValueModel
- extends CompositePropertyValueModel<Boolean>
+ extends CompositePropertyValueModel<Boolean, Boolean>
{
/**
* Calculation of the model's value is delegated to this adapter.
@@ -205,6 +206,9 @@ public class CompositeBooleanPropertyValueModel
*/
public CompositeBooleanPropertyValueModel(Adapter adapter, Boolean defaultValue, PropertyValueModel<Boolean>... array) {
super(array);
+ if (adapter == null) {
+ throw new NullPointerException();
+ }
this.adapter = adapter;
this.defaultValue = defaultValue;
}
@@ -227,6 +231,9 @@ public class CompositeBooleanPropertyValueModel
*/
public <E extends PropertyValueModel<Boolean>> CompositeBooleanPropertyValueModel(Adapter adapter, Boolean defaultValue, Collection<E> collection) {
super(collection);
+ if (adapter == null) {
+ throw new NullPointerException();
+ }
this.adapter = adapter;
this.defaultValue = defaultValue;
}
@@ -249,6 +256,9 @@ public class CompositeBooleanPropertyValueModel
*/
public CompositeBooleanPropertyValueModel(Adapter adapter, Boolean defaultValue, CollectionValueModel<? extends PropertyValueModel<Boolean>> collectionModel) {
super(collectionModel);
+ if (adapter == null) {
+ throw new NullPointerException();
+ }
this.adapter = adapter;
this.defaultValue = defaultValue;
}
@@ -257,8 +267,8 @@ public class CompositeBooleanPropertyValueModel
// ********** implementation **********
/**
- * Return true if all the contained booleans are true; otherwise return
- * false.
+ * Return the {@link #defaultValue} if the collection is empty;
+ * otherwise delegate to the {@link #adapter}.
*/
@Override
protected Boolean buildValue() {
@@ -270,18 +280,21 @@ public class CompositeBooleanPropertyValueModel
}
protected Iterable<Boolean> getBooleans() {
- return new TransformationIterable<PropertyValueModel<Boolean>, Boolean>(this.getCollectionModel()) {
- @Override
- protected Boolean transform(PropertyValueModel<Boolean> booleanModel) {
- return booleanModel.getValue();
- }
- };
+ return new TransformationIterable<PropertyValueModel<? extends Boolean>, Boolean>(this.collectionModel, BOOLEAN_TRANSFORMER);
}
- @Override
- @SuppressWarnings("unchecked")
- protected CollectionValueModel<? extends PropertyValueModel<Boolean>> getCollectionModel() {
- return (CollectionValueModel<? extends PropertyValueModel<Boolean>>) super.getCollectionModel();
+ protected static final Transformer<PropertyValueModel<? extends Boolean>, Boolean> BOOLEAN_TRANSFORMER = new BooleanTransformer();
+
+ protected static class BooleanTransformer
+ implements Transformer<PropertyValueModel<? extends Boolean>, Boolean>
+ {
+ public Boolean transform(PropertyValueModel<? extends Boolean> booleanModel) {
+ return booleanModel.getValue();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
}
@@ -294,13 +307,14 @@ public class CompositeBooleanPropertyValueModel
public interface Adapter {
/**
* Return the composite boolean value of the specified collection
- * of boolean models.
+ * of booleans.
*/
Boolean buildValue(Iterable<Boolean> booleans);
}
/**
- * Return true if all the booleans are true; otherwise return false.
+ * Return <code>true</code> if all the booleans are <code>true</code>;
+ * otherwise return <code>false</code>.
*/
public static final Adapter AND_ADAPTER = new Adapter() {
public Boolean buildValue(Iterable<Boolean> booleans) {
@@ -318,7 +332,8 @@ public class CompositeBooleanPropertyValueModel
};
/**
- * Return false if all the booleans are false; otherwise return true.
+ * Return <code>false</code> if all the booleans are <code>false</code>;
+ * otherwise return <code>true</code>.
*/
public static final Adapter OR_ADAPTER = new Adapter() {
public Boolean buildValue(Iterable<Boolean> booleans) {
@@ -334,5 +349,4 @@ public class CompositeBooleanPropertyValueModel
return "OR_ADAPTER"; //$NON-NLS-1$
}
};
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java
index 72f16a3344..8e979626be 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -90,7 +90,7 @@ public class CompositeCollectionValueModel<E1, E2>
* collection value model. Use this constructor if<ul>
* <li> the wrapped collection value model already contains other
* collection value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -114,7 +114,7 @@ public class CompositeCollectionValueModel<E1, E2>
* list value model. Use this constructor if<ul>
* <li> the wrapped collection value model already contains other
* collection value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -135,7 +135,7 @@ public class CompositeCollectionValueModel<E1, E2>
* collection. Use this constructor if<ul>
* <li> the wrapped collection value model already contains other
* collection value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -156,7 +156,7 @@ public class CompositeCollectionValueModel<E1, E2>
* collection. Use this constructor if<ul>
* <li> the wrapped collection value model already contains other
* collection value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -222,7 +222,7 @@ public class CompositeCollectionValueModel<E1, E2>
@Override
protected void engageModel() {
super.engageModel();
- // synch our cache *after* we start listening to the wrapped collection,
+ // sync our cache *after* we start listening to the wrapped collection,
// since its value might change when a listener is added
this.addAllComponentSources();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java
index 3b017b08c9..2fe04c401c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 20124 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -92,7 +92,7 @@ public class CompositeListValueModel<E1, E2>
* list value model. Use this constructor if<ul>
* <li> the wrapped list value model already contains other
* list value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -116,7 +116,7 @@ public class CompositeListValueModel<E1, E2>
* list. Use this constructor if<ul>
* <li> the wrapped list value model already contains other
* list value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -137,7 +137,7 @@ public class CompositeListValueModel<E1, E2>
* list. Use this constructor if<ul>
* <li> the wrapped list value model already contains other
* list value models, or
- * <li> you want to override {@link #transform(E1)}
+ * <li> you want to override {@link #transform(Object) transform(E1)}
* instead of building a {@link Transformer}
* </ul>
*/
@@ -231,7 +231,7 @@ public class CompositeListValueModel<E1, E2>
@Override
protected void engageModel() {
super.engageModel();
- // synch our cache *after* we start listening to the wrapped list,
+ // sync our cache *after* we start listening to the wrapped list,
// since its value might change when a listener is added
this.addComponentSources(0, this.listHolder, this.listHolder.size(), false); // false = do not fire event
}
@@ -679,5 +679,4 @@ public class CompositeListValueModel<E1, E2>
protected ListValueModel<E2> getComponentLVM(ListEvent event) {
return (ListValueModel<E2>) event.getSource();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java
index 0654c0694c..5731fab0c3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,13 +12,13 @@ package org.eclipse.jpt.common.utility.internal.model.value;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-
import org.eclipse.jpt.common.utility.internal.IdentityHashBag;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -35,22 +35,26 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* </ul>
* <strong>NB:</strong> The wrapped collection must not contain any duplicates
* or this class will throw an exception.
+ *
+ * @param <V> the type of the model's value
+ * @param <E> the type of the wrapped collection value model's
+ * property value model's values
*/
-public abstract class CompositePropertyValueModel<V>
- extends CollectionPropertyValueModelAdapter<V>
+public abstract class CompositePropertyValueModel<V, E>
+ extends CollectionPropertyValueModelAdapter<V, PropertyValueModel<? extends E>>
{
/**
* Cache the component property value models so we can stop listening to
* them when they are removed from the collection value model.
*/
- protected final IdentityHashBag<PropertyValueModel<?>> componentPVMs =
- new IdentityHashBag<PropertyValueModel<?>>();
+ protected final IdentityHashBag<PropertyValueModel<? extends E>> componentPVMs =
+ new IdentityHashBag<PropertyValueModel<? extends E>>();
/**
* Listen to every property value model in the collection value model.
* If one changes, we need to re-calculate our value.
*/
- protected final PropertyChangeListener propertyChangeListener;
+ protected final PropertyChangeListener componentListener;
// ********** constructors **********
@@ -59,7 +63,7 @@ public abstract class CompositePropertyValueModel<V>
* Construct a property value model that is a composite of the specified
* property value models.
*/
- public CompositePropertyValueModel(PropertyValueModel<?>... collection) {
+ public CompositePropertyValueModel(PropertyValueModel<? extends E>... collection) {
this(Arrays.asList(collection));
}
@@ -67,32 +71,33 @@ public abstract class CompositePropertyValueModel<V>
* Construct a property value model that is a composite of the specified
* property value models.
*/
- public <E extends PropertyValueModel<?>> CompositePropertyValueModel(Collection<E> collection) {
- this(new StaticCollectionValueModel<E>(collection));
+ public <P extends PropertyValueModel<? extends E>> CompositePropertyValueModel(Collection<? extends P> collection) {
+ this(new StaticCollectionValueModel<P>(collection));
}
/**
* Construct a property value model that is a composite of the specified
* property value models.
*/
- public CompositePropertyValueModel(CollectionValueModel<? extends PropertyValueModel<?>> collectionModel) {
+ public <P extends PropertyValueModel<? extends E>> CompositePropertyValueModel(CollectionValueModel<P> collectionModel) {
super(collectionModel);
- this.propertyChangeListener = this.buildPropertyChangeListener();
+ this.componentListener = this.buildComponentListener();
}
// ********** initialization **********
- protected PropertyChangeListener buildPropertyChangeListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- CompositePropertyValueModel.this.propertyChanged(event);
- }
- @Override
- public String toString() {
- return "property change listener"; //$NON-NLS-1$
- }
- };
+ protected PropertyChangeListener buildComponentListener() {
+ return new ComponentListener();
+ }
+
+ protected class ComponentListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ CompositePropertyValueModel.this.componentChanged(event);
+ }
}
@@ -103,7 +108,7 @@ public abstract class CompositePropertyValueModel<V>
* the performance of building a new value (e.g. some property changes may
* not necessitate the re-calculation of the value).
*/
- protected void propertyChanged(@SuppressWarnings("unused") PropertyChangeEvent event) {
+ protected void componentChanged(@SuppressWarnings("unused") PropertyChangeEvent event) {
this.propertyChanged();
}
@@ -113,25 +118,25 @@ public abstract class CompositePropertyValueModel<V>
@Override
protected void engageModel_() {
super.engageModel_();
- this.addComponentPVMs(this.getCollectionModel());
+ this.addComponentPVMs(this.collectionModel);
}
- protected <E extends PropertyValueModel<?>> void addComponentPVMs(Iterable<E> pvms) {
- for (PropertyValueModel<?> each : pvms) {
+ protected <P extends PropertyValueModel<? extends E>> void addComponentPVMs(Iterable<P> pvms) {
+ for (P each : pvms) {
this.componentPVMs.add(each);
- each.addPropertyChangeListener(VALUE, this.propertyChangeListener);
+ each.addPropertyChangeListener(VALUE, this.componentListener);
}
}
@Override
protected void disengageModel_() {
- this.removeComponentPVMs(this.getCollectionModel());
+ this.removeComponentPVMs(this.collectionModel);
super.disengageModel_();
}
- protected <E extends PropertyValueModel<?>> void removeComponentPVMs(Iterable<E> pvms) {
- for (PropertyValueModel<?> each : pvms) {
- each.removePropertyChangeListener(VALUE, this.propertyChangeListener);
+ protected <P extends PropertyValueModel<? extends E>> void removeComponentPVMs(Iterable<P> pvms) {
+ for (P each : pvms) {
+ each.removePropertyChangeListener(VALUE, this.componentListener);
this.componentPVMs.remove(each);
}
}
@@ -156,14 +161,14 @@ public abstract class CompositePropertyValueModel<V>
protected void removeAllComponentPVMs() {
// copy the list so we don't eat our own tail
- ArrayList<PropertyValueModel<?>> copy = new ArrayList<PropertyValueModel<?>>(this.componentPVMs);
+ ArrayList<PropertyValueModel<? extends E>> copy = new ArrayList<PropertyValueModel<? extends E>>(this.componentPVMs);
this.removeComponentPVMs(copy);
}
@Override
protected void collectionChanged(CollectionChangeEvent event) {
this.removeAllComponentPVMs();
- this.addComponentPVMs(this.getCollectionModel());
+ this.addComponentPVMs(this.collectionModel);
super.collectionChanged(event);
}
@@ -171,28 +176,22 @@ public abstract class CompositePropertyValueModel<V>
// ********** convenience methods **********
/**
- * Our constructor accepts only a {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<?>>}.
+ * Our constructor accepts only a
+ * {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<? extends E>>}.
*/
// minimize scope of suppressed warnings
@SuppressWarnings("unchecked")
- protected CollectionValueModel<? extends PropertyValueModel<?>> getCollectionModel() {
- return (CollectionValueModel<? extends PropertyValueModel<?>>) this.collectionModel;
- }
-
- /**
- * Our constructor accepts only a {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<?>>}.
- */
- @SuppressWarnings("unchecked")
- protected Iterable<? extends PropertyValueModel<?>> getItems(CollectionAddEvent event) {
- return (Iterable<? extends PropertyValueModel<?>>) event.getItems();
+ protected Iterable<? extends PropertyValueModel<? extends E>> getItems(CollectionAddEvent event) {
+ return (Iterable<? extends PropertyValueModel<? extends E>>) event.getItems();
}
/**
- * Our constructor accepts only a {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<?>>}.
+ * Our constructor accepts only a
+ * {@link CollectionValueModel}{@code<? extends }{@link PropertyValueModel}{@code<? extends E>>}.
*/
+ // minimize scope of suppressed warnings
@SuppressWarnings("unchecked")
- protected Iterable<? extends PropertyValueModel<?>> getItems(CollectionRemoveEvent event) {
- return (Iterable<? extends PropertyValueModel<?>>) event.getItems();
+ protected Iterable<? extends PropertyValueModel<? extends E>> getItems(CollectionRemoveEvent event) {
+ return (Iterable<? extends PropertyValueModel<? extends E>>) event.getItems();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoubleModifiablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoubleModifiablePropertyValueModel.java
new file mode 100644
index 0000000000..5150261ee8
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoubleModifiablePropertyValueModel.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+
+/**
+ * Add support for changing the double property value model.
+ *
+ * @param <V> the type of the both the <em>wrapped</em> and <em>wrapper</em>
+ * models' values
+ */
+public class DoubleModifiablePropertyValueModel<V>
+ extends DoublePropertyValueModel<V>
+ implements WritablePropertyValueModel<V>
+{
+ /**
+ * Construct a double modifiable property value model for the specified
+ * wrapped property value model model.
+ */
+ public DoubleModifiablePropertyValueModel(PropertyValueModel<? extends WritablePropertyValueModel<V>> valueModel) {
+ super(valueModel);
+ }
+
+ public void setValue(V value) {
+ WritablePropertyValueModel<V> vmv = this.getValueModelValueModel();
+ if (vmv == null) {
+ this.setValue_(value);
+ } else {
+ vmv.setValue(value);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected WritablePropertyValueModel<V> getValueModelValueModel() {
+ return (WritablePropertyValueModel<V>) this.valueModelValueModel;
+ }
+
+ /**
+ * The wrapped value model model is missing. Handle the specified new value.
+ */
+ protected void setValue_(@SuppressWarnings("unused") V value) {
+ // do nothing by default
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoublePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoublePropertyValueModel.java
new file mode 100644
index 0000000000..d8452cb924
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/DoublePropertyValueModel.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+
+/**
+ * This property value model <em>wrapper</em> wraps another property value model
+ * and treats the <em>wrapped</em> model's value as the <em>wrapper</em>'s value.
+ * Any change events fired by the <em>wrapped</em> model are simply forwarded by
+ * the <em>wrapper</em> as its own.
+ * Similarly, changing the <em>wrapper</em>'s <em>wrapped</em> model can also
+ * trigger a change event
+ * (see {@link #wrappedValueChanged(PropertyValueModel, PropertyValueModel)}).
+ * That is, the <em>wrapped</em> model is held by yet another property value
+ * model!
+ * <p>
+ * <ul>
+ * <li>Double (<em>wrapper</em>) property value model - a client can listen to
+ * this model and receive the same change notification whether the
+ * <em>wrapped</em> model or the <em>wrapped</em> model's value changes;
+ * much like an {@link PropertyAspectAdapter aspect adapter} whose subject
+ * model is <em>not</em> another property value model
+ * <ul>
+ * <li><em>Wrapped</em> property value model - this model is built and
+ * maintained by the server that also builds the <em>wrapper</em> model
+ * (i.e. the server will monitor some other model that determines when
+ * the <em>wrapped</em> model is changed)
+ * <ul>
+ * <li>Original property value model - this model is the "original"
+ * model that contains the value of interest
+ * </ul>
+ * </ul>
+ * </ul>
+ * <p>
+ * This wrapper is useful when a change in the <em>wrapped</em> model is
+ * signaled by a non-value event and a third-party would like to change it.
+ *
+ * @param <V> the type of the both the <em>wrapped</em> and <em>wrapper</em>
+ * models' values
+ */
+public class DoublePropertyValueModel<V>
+ extends PropertyValueModelWrapper<PropertyValueModel<? extends V>>
+ implements PropertyValueModel<V>
+{
+ /**
+ * The optionally present wrapped value model value; held by
+ * {@link #valueModel}. This may be <code>null</code>.
+ */
+ protected volatile PropertyValueModel<? extends V> valueModelValueModel;
+
+ /**
+ * A listener that allows us to sync with changes to the wrapped value
+ * model model.
+ */
+ protected final PropertyChangeListener valueModelValueListener;
+
+
+ // ********** constructors/initialization **********
+
+ /**
+ * Construct a double property value model for the specified
+ * wrapped property value model model.
+ */
+ public DoublePropertyValueModel(PropertyValueModel<? extends PropertyValueModel<? extends V>> valueModel) {
+ super(valueModel);
+ this.valueModelValueListener = this.buildValueModelValueListener();
+ }
+
+ protected PropertyChangeListener buildValueModelValueListener() {
+ return new ValueModelListener();
+ }
+
+ /* CU private */ class ValueModelListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModel.this.wrappedValueModelValueChanged(event);
+ }
+ }
+
+
+ // ********** PropertyValueModel implementation **********
+
+ public V getValue() {
+ return (this.valueModelValueModel == null) ? null : this.valueModelValueModel.getValue();
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.getValue());
+ }
+
+
+ // ********** wrapped value model **********
+
+ /**
+ * The value model has changed.
+ * Move our value model listener and
+ * notify listeners that the value has changed.
+ */
+ @Override
+ protected void wrappedValueChanged(PropertyValueModel<? extends V> oldValue, PropertyValueModel<? extends V> newValue) {
+ if (this.hasListeners()) {
+ V old = this.getValue();
+ this.disengageValueModel();
+ this.engageValueModel();
+ this.firePropertyChanged(VALUE, old, this.getValue());
+ }
+ }
+
+
+ // ********** wrapped value model value **********
+
+ /**
+ * The value of the wrapped value model's value model has changed.
+ * Forward the event as our own.
+ */
+ protected void wrappedValueModelValueChanged(PropertyChangeEvent event) {
+ this.firePropertyChanged(event.clone(this));
+ }
+
+ /**
+ * Begin listening to the value model.
+ */
+ @Override
+ protected void engageModel() {
+ super.engageModel();
+ this.engageValueModel();
+ }
+
+ protected void engageValueModel() {
+ this.valueModelValueModel = this.valueModel.getValue();
+ if (this.valueModelValueModel != null) {
+ this.valueModelValueModel.addPropertyChangeListener(VALUE, this.valueModelValueListener);
+ }
+ }
+
+ /**
+ * Stop listening to the value model.
+ */
+ @Override
+ protected void disengageModel() {
+ this.disengageValueModel();
+ super.disengageModel();
+ }
+
+ protected void disengageValueModel() {
+ if (this.valueModelValueModel != null) {
+ this.valueModelValueModel.removePropertyChangeListener(VALUE, this.valueModelValueListener);
+ }
+ this.valueModelValueModel = null;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java
new file mode 100644
index 0000000000..0f88a5676f
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ElementPropertyValueModelAdapter.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.model.value;
+
+import org.eclipse.jpt.common.utility.Filter;
+import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+
+/**
+ * Adapt an element in a collection value model to a property value model.
+ * The property model's value is determined by whether the collection model
+ * contains the value: If the collection model contains the value,
+ * the property model's value is <em>that</em> element; otherwise, the property
+ * model's value is <code>null</code>. A {@link #predicate} is used to determine
+ * whether the collection model contains the relevant value.
+ * <p>
+ * This is useful for a client (e.g. a UI widget) that is longer-living than its
+ * underlying model. Obviously, the client must be prepared to handle a value of
+ * <code>null</code>.
+ *
+ * @param <V> the type of the both the model's value and
+ * the wrapped collection value model's elements
+ */
+public class ElementPropertyValueModelAdapter<V>
+ extends CollectionPropertyValueModelAdapter<V, V>
+{
+ /**
+ * A predicate used to determine whether an element in the wrapped
+ * collection model is the model's value.
+ */
+ protected final Filter<V> predicate;
+
+
+ /**
+ * Construct a property value model whose value depends on whether the
+ * specified collection value model contains the value. The specified
+ * filter is used to determine whether an element in the specified
+ * collection model is the property value.
+ */
+ public ElementPropertyValueModelAdapter(CollectionValueModel<? extends V> collectionModel, Filter<V> predicate) {
+ super(collectionModel);
+ if (predicate == null) {
+ throw new NullPointerException();
+ }
+ this.predicate = predicate;
+ }
+
+ /**
+ * If the collection model contains the property model's {@link #value},
+ * return that element; otherwise return <code>null</code>.
+ */
+ @Override
+ protected V buildValue() {
+ for (V each : this.collectionModel) {
+ if (this.predicate.accept(each)) {
+ return each;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Check whether the wrapped collection model now contains the
+ * {@link #value}.
+ */
+ @Override
+ protected void itemsAdded(Iterable<V> items) {
+ if (this.value == null) {
+ this.itemsAdded_(items);
+ }
+ }
+
+ protected void itemsAdded_(Iterable<V> items) {
+ for (V each : items) {
+ if (this.predicate.accept(each)) {
+ this.firePropertyChanged(VALUE, null, this.value = each);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Check whether the wrapped collection model no longer contains the
+ * {@link #value}.
+ */
+ @Override
+ protected void itemsRemoved(Iterable<V> items) {
+ if (this.value != null) {
+ this.itemsRemoved_(items);
+ }
+ }
+
+ protected void itemsRemoved_(Iterable<V> items) {
+ for (V each : items) {
+ if (this.valuesAreEqual(each, this.value)) {
+ V old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = null);
+ return;
+ }
+ }
+ }
+
+ /**
+ * The {@link #value} must now be <code>null</code>.
+ */
+ @Override
+ protected void collectionCleared(CollectionClearEvent event) {
+ if (this.value != null) {
+ V old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = null);
+ }
+ }
+
+ /**
+ * Re-calculate the {@link #value}.
+ */
+ @Override
+ protected void collectionChanged(CollectionChangeEvent event) {
+ V old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = this.buildValue());
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java
index 3defd4f00d..0a92b48e96 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,9 +10,7 @@
package org.eclipse.jpt.common.utility.internal.model.value;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
-
import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
@@ -53,7 +51,7 @@ public class FilteringCollectionValueModel<E>
private Filter<E> filter;
/** Cache the items that were accepted by the filter */
- private final Collection<E> filteredItems = new ArrayList<E>();
+ private final ArrayList<E> filteredItems = new ArrayList<E>();
// ********** constructors **********
@@ -62,16 +60,16 @@ public class FilteringCollectionValueModel<E>
* Construct a collection value model with the specified wrapped
* collection value model and a filter that simply accepts every object.
*/
- public FilteringCollectionValueModel(CollectionValueModel<? extends E> collectionHolder) {
- this(collectionHolder, Filter.Null.<E>instance());
+ public FilteringCollectionValueModel(CollectionValueModel<? extends E> collectionModel) {
+ this(collectionModel, Filter.Transparent.<E>instance());
}
/**
* Construct a collection value model with the specified wrapped
* collection value model and filter.
*/
- public FilteringCollectionValueModel(CollectionValueModel<? extends E> collectionHolder, Filter<E> filter) {
- super(collectionHolder);
+ public FilteringCollectionValueModel(CollectionValueModel<? extends E> collectionModel, Filter<E> filter) {
+ super(collectionModel);
this.filter = filter;
}
@@ -79,16 +77,16 @@ public class FilteringCollectionValueModel<E>
* Construct a collection value model with the specified wrapped
* list value model and a filter that simply accepts every object.
*/
- public FilteringCollectionValueModel(ListValueModel<E> listHolder) {
- this(new ListCollectionValueModelAdapter<E>(listHolder));
+ public FilteringCollectionValueModel(ListValueModel<? extends E> listModel) {
+ this(new ListCollectionValueModelAdapter<E>(listModel));
}
/**
* Construct a collection value model with the specified wrapped
* list value model and filter.
*/
- public FilteringCollectionValueModel(ListValueModel<E> listHolder, Filter<E> filter) {
- this(new ListCollectionValueModelAdapter<E>(listHolder), filter);
+ public FilteringCollectionValueModel(ListValueModel<? extends E> listModel, Filter<E> filter) {
+ this(new ListCollectionValueModelAdapter<E>(listModel), filter);
}
@@ -108,7 +106,7 @@ public class FilteringCollectionValueModel<E>
@Override
protected void engageModel() {
super.engageModel();
- // synch our cache *after* we start listening to the nested collection,
+ // sync our cache *after* we start listening to the nested collection,
// since its value might change when a listener is added
CollectionTools.addAll(this.filteredItems, this.filter(this.collectionHolder));
}
@@ -175,5 +173,4 @@ public class FilteringCollectionValueModel<E>
public void toString(StringBuilder sb) {
sb.append(this.filteredItems);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringPropertyValueModel.java
index 56935822d8..5fb549409c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringPropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.Filter;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
/**
@@ -19,62 +18,52 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* to determine when the wrapped value is to be returned by calls
* to {@link #getValue()}.
* <p>
- * As an alternative to building a {@link Filter}, a subclass
- * can override {@link #accept(T)}.
- * <p>
* One, possibly undesirable, side-effect of using this value model is that
- * it must return *something* as the value. The default behavior is
+ * it must return <em>something</em> as the value. The default behavior is
* to return <code>null</code> whenever the wrapped value is not "accepted",
* which can be configured and/or overridden ({@link #getDefaultValue()}).
+ *
+ * @param <V> the type of the model's <em>filtered</em> value
+ * @see Filter
*/
-public class FilteringPropertyValueModel<T>
- extends PropertyValueModelWrapper<T>
- implements PropertyValueModel<T>
+public class FilteringPropertyValueModel<V>
+ extends PropertyValueModelWrapper<V>
+ implements PropertyValueModel<V>
{
- protected final Filter<T> filter;
- protected final T defaultValue;
-
-
- // ********** constructors **********
-
/**
- * Construct a filtering property value model with the specified nested
- * property value model and a disabled filter.
- * Use this constructor if you want to override {@link #accept(T)}
- * instead of building a {@link Filter}.
- * The default value will be <code>null</code>.
+ * The model returns any wrapped value accepted by this filter and returns
+ * the {@link #defaultValue} in place of any wrapped value rejected by this
+ * filter.
*/
- public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder) {
- this(valueHolder, Filter.Disabled.<T>instance(), null);
- }
+ protected final Filter<V> filter;
/**
- * Construct a filtering property value model with the specified nested
- * property value model, specified default value, and a disabled filter.
- * Use this constructor if you want to override {@link #accept(T)}
- * instead of building a {@link Filter}
- * <em>and</em> you need to specify
- * a default value other than <code>null</code>.
+ * The value returned by the model if the wrapped value is reject by the
+ * {@link #filter}.
*/
- public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder, T defaultValue) {
- this(valueHolder, Filter.Disabled.<T>instance(), defaultValue);
- }
+ protected final V defaultValue;
+
+
+ // ********** constructors **********
/**
* Construct a filtering property value model with the specified nested
* property value model and filter.
* The default value will be <code>null</code>.
*/
- public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder, Filter<T> filter) {
- this(valueHolder, filter, null);
+ public FilteringPropertyValueModel(PropertyValueModel<? extends V> valueModel, Filter<V> filter) {
+ this(valueModel, filter, null);
}
/**
* Construct a filtering property value model with the specified nested
* property value model, filter, and default value.
*/
- public FilteringPropertyValueModel(PropertyValueModel<? extends T> valueHolder, Filter<T> filter, T defaultValue) {
- super(valueHolder);
+ public FilteringPropertyValueModel(PropertyValueModel<? extends V> valueModel, Filter<V> filter, V defaultValue) {
+ super(valueModel);
+ if (filter == null) {
+ throw new NullPointerException();
+ }
this.filter = filter;
this.defaultValue = defaultValue;
}
@@ -82,23 +71,17 @@ public class FilteringPropertyValueModel<T>
// ********** PropertyValueModel implementation **********
- public T getValue() {
- return this.filterValue(this.valueHolder.getValue());
+ public V getValue() {
+ return this.filterValue(this.valueModel.getValue());
}
// ********** PropertyValueModelWrapper implementation **********
@Override
- protected void valueChanged(PropertyChangeEvent event) {
+ protected void wrappedValueChanged(V oldValue, V newValue) {
// filter the values before propagating the change event
- @SuppressWarnings("unchecked")
- T eventOldValue = (T) event.getOldValue();
- Object oldValue = this.filterValue(eventOldValue);
- @SuppressWarnings("unchecked")
- T eventNewValue = (T) event.getNewValue();
- Object newValue = this.filterValue(eventNewValue);
- this.firePropertyChanged(VALUE, oldValue, newValue);
+ this.firePropertyChanged(VALUE, this.filterValue(oldValue), this.filterValue(newValue));
}
@@ -108,21 +91,8 @@ public class FilteringPropertyValueModel<T>
* If the specified value is "accepted" simply return it,
* otherwise return the default value.
*/
- protected T filterValue(T value) {
- return this.accept(value) ? value : this.getDefaultValue();
- }
-
- /**
- * Return whether the filtering property value model should
- * return the specified value from a call to
- * {@link #getValue()}; the value came
- * from the nested property value model
- * <p>
- * This method can be overridden by a subclass as an
- * alternative to building a {@link Filter}.
- */
- protected boolean accept(T value) {
- return this.filter.accept(value);
+ protected V filterValue(V value) {
+ return this.filter.accept(value) ? value : this.getDefaultValue();
}
/**
@@ -130,13 +100,15 @@ public class FilteringPropertyValueModel<T>
* the nested value was rejected by the filter.
* The default is <code>null</code>.
*/
- protected T getDefaultValue() {
+ protected V getDefaultValue() {
return this.defaultValue;
}
+ /**
+ * Print the filtered value.
+ */
@Override
public void toString(StringBuilder sb) {
sb.append(this.getValue());
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringWritablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringWritablePropertyValueModel.java
index 61eac0eec9..98d2904cc5 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringWritablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/FilteringWritablePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,115 +9,81 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
-import org.eclipse.jpt.common.utility.internal.BidiFilter;
+import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
* A <code>FilteringWritablePropertyValueModel</code> wraps another
- * {@link WritablePropertyValueModel} and uses a {@link BidiFilter}
+ * {@link WritablePropertyValueModel} and uses a pair of {@link Filter}s
* to determine when the wrapped value is to be returned by calls
- * to {@link FilteringPropertyValueModel#getValue() getValue()} and modified by calls to
- * {@link #setValue(T)}.
- * <p>
- * As an alternative to building a {@link BidiFilter}, a subclass
- * can override {@link FilteringPropertyValueModel#accept(T) accept(T)} and {@link #reverseAccept(T)}.
+ * to {@link #getValue()} and modified by calls to
+ * {@link #setValue(Object) setValue(V)}.
* <p>
* One, possibly undesirable, side-effect of using this value model is that
- * it must return *something* as the value. The default behavior is
+ * it must return <em>something</em> as the value. The default behavior is
* to return <code>null</code> whenever the wrapped value is not "accepted",
- * which can be configured and/or overridden ({@link FilteringPropertyValueModel#getDefaultValue() getDefaultValue()}).
+ * which can be configured and/or overridden
+ * ({@link FilteringPropertyValueModel#getDefaultValue() getDefaultValue()}).
+ * <p>
+ * Another, possibly undesirable, side-effect of using this value model is that
+ * it will not fire an event if a new value is not "accepted", even if it is
+ * different than the current value.
* <p>
* Similarly, if an incoming value is not "reverse accepted", <em>nothing</em>
- * will passed through to the wrapped value holder, not even <code>null</code>.
+ * will passed through to the wrapped value model, not even <code>null</code>.
+ *
+ * @param <V> the type of the model's <em>filtered</em> value
+ * @see Filter
*/
-public class FilteringWritablePropertyValueModel<T>
- extends FilteringPropertyValueModel<T>
- implements WritablePropertyValueModel<T>
+public class FilteringWritablePropertyValueModel<V>
+ extends FilteringPropertyValueModel<V>
+ implements WritablePropertyValueModel<V>
{
+ /**
+ * The model sets the wrapped value to any value accepted by this filter
+ * and does nothing with any value rejected by this filter.
+ */
+ protected final Filter<V> setFilter;
// ********** constructors **********
/**
* Construct a filtering property value model with the specified nested
- * property value model and a disabled filter.
- * Use this constructor if you want to override
- * {@link #accept(T)} and {@link #reverseAccept(T)}
- * instead of building a {@link BidiFilter}.
+ * property value model, <em>get</em> filter, and <em>set</em> filter.
* The default value will be <code>null</code>.
*/
- public FilteringWritablePropertyValueModel(WritablePropertyValueModel<T> valueHolder) {
- this(valueHolder, BidiFilter.Disabled.<T>instance(), null);
+ public FilteringWritablePropertyValueModel(WritablePropertyValueModel<V> valueModel, Filter<V> getFilter, Filter<V> setFilter) {
+ this(valueModel, getFilter, setFilter, null);
}
/**
* Construct a filtering property value model with the specified nested
- * property value model, specified default value, and a disabled filter.
- * Use this constructor if you want to override
- * {@link #accept(T)} and {@link #reverseAccept(T)}
- * instead of building a {@link BidiFilter}.
- * <em>and</em> you need to specify
- * a default value other than <code>null</code>.
- */
- public FilteringWritablePropertyValueModel(WritablePropertyValueModel<T> valueHolder, T defaultValue) {
- this(valueHolder, BidiFilter.Disabled.<T>instance(), defaultValue);
- }
-
- /**
- * Construct an property value model with the specified nested
- * property value model and filter.
- * The default value will be <code>null</code>.
- */
- public FilteringWritablePropertyValueModel(WritablePropertyValueModel<T> valueHolder, BidiFilter<T> filter) {
- this(valueHolder, filter, null);
- }
-
- /**
- * Construct an property value model with the specified nested
- * property value model, filter, and default value.
+ * property value model, <em>get</em> filter, <em>set</em> filter,
+ * and default value.
*/
- public FilteringWritablePropertyValueModel(WritablePropertyValueModel<T> valueHolder, BidiFilter<T> filter, T defaultValue) {
- super(valueHolder, filter, defaultValue);
+ public FilteringWritablePropertyValueModel(WritablePropertyValueModel<V> valueModel, Filter<V> getFilter, Filter<V> setFilter, V defaultValue) {
+ super(valueModel, getFilter, defaultValue);
+ if (setFilter == null) {
+ throw new NullPointerException();
+ }
+ this.setFilter = setFilter;
}
// ********** WritablePropertyValueModel implementation **********
- public void setValue(T value) {
- if (this.reverseAccept(value)) {
- this.getValueHolder().setValue(value);
+ public void setValue(V value) {
+ if (this.setFilter.accept(value)) {
+ this.getValueModel().setValue(value);
}
}
-
- // ********** queries **********
-
- /**
- * Return whether the filtering writable property value model
- * should pass through the specified value to the nested
- * writable property value model in a call to
- * {@link #setValue(T)}.
- * <p>
- * This method can be overridden by a subclass as an
- * alternative to building a {@link BidiFilter}.
- */
- protected boolean reverseAccept(T value) {
- return this.getFilter().reverseAccept(value);
- }
-
/**
* Our constructor accepts only a {@link WritablePropertyValueModel}{@code<T>}.
*/
@SuppressWarnings("unchecked")
- protected WritablePropertyValueModel<T> getValueHolder() {
- return (WritablePropertyValueModel<T>) this.valueHolder;
- }
-
- /**
- * Our constructors accept only a bidirectional filter.
- */
- protected BidiFilter<T> getFilter() {
- return (BidiFilter<T>) this.filter;
+ protected WritablePropertyValueModel<V> getValueModel() {
+ return (WritablePropertyValueModel<V>) this.valueModel;
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemChangeListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemChangeListValueModelAdapter.java
index b6f817b79c..fd54e605fd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemChangeListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemChangeListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.ChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.listener.SimpleChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.AbstractChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
/**
@@ -40,16 +40,16 @@ public class ItemChangeListValueModelAdapter<E>
// ********** initialization **********
protected ChangeListener buildItemChangeListener() {
- return new SimpleChangeListener() {
- @Override
- protected void modelChanged(ChangeEvent event) {
- ItemChangeListValueModelAdapter.this.itemAspectChanged(event);
- }
- @Override
- public String toString() {
- return "item change listener"; //$NON-NLS-1$
- }
- };
+ return new ItemChangeListener();
+ }
+
+ protected class ItemChangeListener
+ extends AbstractChangeListener
+ {
+ @Override
+ protected void modelChanged(ChangeEvent event) {
+ ItemChangeListValueModelAdapter.this.itemAspectChanged(event);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java
index 82b5eb4e9b..495e940419 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListAspectAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,9 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
-import java.util.Arrays;
import java.util.Collection;
-
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
@@ -19,6 +17,7 @@ import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
+import org.eclipse.jpt.common.utility.model.listener.ListChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -38,6 +37,9 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* <li>{@link #size()}
* <li>{@link #toArray()}
* </ul>
+ *
+ * @param <S> the type of the adapter's subject
+ * @param <E> the type of the adapter's list's elements
*/
public abstract class ListAspectAdapter<S extends Model, E>
extends AspectListValueModelAdapter<S, E>
@@ -45,47 +47,47 @@ public abstract class ListAspectAdapter<S extends Model, E>
/**
* The name of the subject's lists that we use for the value.
*/
- protected final String[] listNames;
- protected static final String[] EMPTY_LIST_NAMES = new String[0];
+ protected final String[] aspectNames;
+ protected static final String[] EMPTY_ASPECT_NAMES = new String[0];
/** A listener that listens to the subject's list aspects. */
- protected final ListChangeListener listChangeListener;
+ protected final ListChangeListener aspectChangeListener;
// ********** constructors **********
/**
* Construct a list aspect adapter for the specified subject
- * and list.
+ * and list aspect.
*/
- protected ListAspectAdapter(String listName, S subject) {
- this(new String[] {listName}, subject);
+ protected ListAspectAdapter(String aspectName, S subject) {
+ this(new String[] {aspectName}, subject);
}
/**
* Construct a list aspect adapter for the specified subject
- * and lists.
+ * and list aspects.
*/
- protected ListAspectAdapter(String[] listNames, S subject) {
- this(new StaticPropertyValueModel<S>(subject), listNames);
+ protected ListAspectAdapter(String[] aspectNames, S subject) {
+ this(new StaticPropertyValueModel<S>(subject), aspectNames);
}
/**
* Construct a list aspect adapter for the specified subject holder
* and lists.
*/
- protected ListAspectAdapter(PropertyValueModel<? extends S> subjectHolder, String... listNames) {
- super(subjectHolder);
- this.listNames = listNames;
- this.listChangeListener = this.buildListChangeListener();
+ protected ListAspectAdapter(PropertyValueModel<? extends S> subjectModel, String... aspectNames) {
+ super(subjectModel);
+ this.aspectNames = aspectNames;
+ this.aspectChangeListener = this.buildAspectChangeListener();
}
/**
* Construct a list aspect adapter for the specified subject holder
* and lists.
*/
- protected ListAspectAdapter(PropertyValueModel<? extends S> subjectHolder, Collection<String> listNames) {
- this(subjectHolder, listNames.toArray(new String[listNames.size()]));
+ protected ListAspectAdapter(PropertyValueModel<? extends S> subjectModel, Collection<String> aspectNames) {
+ this(subjectModel, aspectNames.toArray(new String[aspectNames.size()]));
}
/**
@@ -94,39 +96,48 @@ public abstract class ListAspectAdapter<S extends Model, E>
* change for a particular subject; but the subject will change, resulting in
* a new list.
*/
- protected ListAspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
- this(subjectHolder, EMPTY_LIST_NAMES);
+ protected ListAspectAdapter(PropertyValueModel<? extends S> subjectModel) {
+ this(subjectModel, EMPTY_ASPECT_NAMES);
}
// ********** initialization **********
- protected ListChangeListener buildListChangeListener() {
- // transform the subject's list change events into VALUE list change events
- return new ListChangeListener() {
- public void itemsAdded(ListAddEvent event) {
- ListAspectAdapter.this.itemsAdded(event);
- }
- public void itemsRemoved(ListRemoveEvent event) {
- ListAspectAdapter.this.itemsRemoved(event);
- }
- public void itemsReplaced(ListReplaceEvent event) {
- ListAspectAdapter.this.itemsReplaced(event);
- }
- public void itemsMoved(ListMoveEvent event) {
- ListAspectAdapter.this.itemsMoved(event);
- }
- public void listCleared(ListClearEvent event) {
- ListAspectAdapter.this.listCleared(event);
- }
- public void listChanged(ListChangeEvent event) {
- ListAspectAdapter.this.listChanged(event);
- }
- @Override
- public String toString() {
- return "list change listener: " + Arrays.asList(ListAspectAdapter.this.listNames); //$NON-NLS-1$
- }
- };
+ protected ListChangeListener buildAspectChangeListener() {
+ return new AspectChangeListener();
+ }
+
+ /**
+ * Transform the subject's list change events into {@link #LIST_VALUES}
+ * list change events
+ */
+ protected class AspectChangeListener
+ extends ListChangeAdapter
+ {
+ @Override
+ public void itemsAdded(ListAddEvent event) {
+ ListAspectAdapter.this.aspectItemsAdded(event);
+ }
+ @Override
+ public void itemsRemoved(ListRemoveEvent event) {
+ ListAspectAdapter.this.aspectItemsRemoved(event);
+ }
+ @Override
+ public void itemsReplaced(ListReplaceEvent event) {
+ ListAspectAdapter.this.aspectItemsReplaced(event);
+ }
+ @Override
+ public void itemsMoved(ListMoveEvent event) {
+ ListAspectAdapter.this.aspectItemsMoved(event);
+ }
+ @Override
+ public void listCleared(ListClearEvent event) {
+ ListAspectAdapter.this.aspectListCleared(event);
+ }
+ @Override
+ public void listChanged(ListChangeEvent event) {
+ ListAspectAdapter.this.aspectListChanged(event);
+ }
}
@@ -134,43 +145,42 @@ public abstract class ListAspectAdapter<S extends Model, E>
@Override
protected void engageSubject_() {
- for (String listName : this.listNames) {
- ((Model) this.subject).addListChangeListener(listName, this.listChangeListener);
+ for (String listName : this.aspectNames) {
+ this.subject.addListChangeListener(listName, this.aspectChangeListener);
}
}
@Override
protected void disengageSubject_() {
- for (String listName : this.listNames) {
- ((Model) this.subject).removeListChangeListener(listName, this.listChangeListener);
+ for (String listName : this.aspectNames) {
+ this.subject.removeListChangeListener(listName, this.aspectChangeListener);
}
}
// ********** behavior **********
- protected void itemsAdded(ListAddEvent event) {
+ protected void aspectItemsAdded(ListAddEvent event) {
this.fireItemsAdded(event.clone(this, LIST_VALUES));
}
- protected void itemsRemoved(ListRemoveEvent event) {
+ protected void aspectItemsRemoved(ListRemoveEvent event) {
this.fireItemsRemoved(event.clone(this, LIST_VALUES));
}
- protected void itemsReplaced(ListReplaceEvent event) {
+ protected void aspectItemsReplaced(ListReplaceEvent event) {
this.fireItemsReplaced(event.clone(this, LIST_VALUES));
}
- protected void itemsMoved(ListMoveEvent event) {
+ protected void aspectItemsMoved(ListMoveEvent event) {
this.fireItemsMoved(event.clone(this, LIST_VALUES));
}
- protected void listCleared(ListClearEvent event) {
+ protected void aspectListCleared(ListClearEvent event) {
this.fireListCleared(event.clone(this, LIST_VALUES));
}
- protected void listChanged(ListChangeEvent event) {
+ protected void aspectListChanged(ListChangeEvent event) {
this.fireListChanged(event.clone(this, LIST_VALUES));
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCollectionValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCollectionValueModelAdapter.java
index e37f223a6f..a99ecf83c1 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCollectionValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCollectionValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -27,12 +27,12 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
* An adapter that allows us to make a {@link ListValueModel} behave like
* a read-only {@link CollectionValueModel}, sorta.
* <p>
- * We keep an internal collection somewhat in synch with the wrapped list.
+ * We keep an internal collection somewhat in sync with the wrapped list.
* <p>
* <strong>NB:</strong> Since we only listen to the wrapped list when we have
- * listeners ourselves and we can only stay in synch with the wrapped
+ * listeners ourselves and we can only stay in sync with the wrapped
* list while we are listening to it, results to various methods
- * (e.g. {@link #size()}, {@link iterator()}) will be unpredictable whenever
+ * (e.g. {@link #size()}, {@link #iterator()}) will be unpredictable whenever
* we do not have any listeners. This should not be too painful since,
* most likely, client objects will also be listeners.
*/
@@ -123,7 +123,7 @@ public class ListCollectionValueModelAdapter<E>
@Override
protected void engageModel() {
this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener);
- // synch our collection *after* we start listening to the list holder,
+ // sync our collection *after* we start listening to the list model,
// since its value might change when a listener is added
this.buildCollection();
}
@@ -229,5 +229,4 @@ public class ListCollectionValueModelAdapter<E>
public void toString(StringBuilder sb) {
sb.append(this.collection);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java
index 753638b098..60cf3e2184 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,12 +14,12 @@ import java.util.EventListener;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterators.ReadOnlyListIterator;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.StateChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -28,9 +28,12 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* This extension of {@link AspectAdapter} provides list change support
* by adapting a subject's state change events to a minimum set
* of list change events.
+ *
+ * @param <S> the type of the adapter's subject
+ * @param <E> the type of the adapter's list's elements
*/
public abstract class ListCurator<S extends Model, E>
- extends AspectAdapter<S>
+ extends AspectAdapter<S, List<E>>
implements ListValueModel<E>
{
/** How the list looked before the last state change */
@@ -50,11 +53,11 @@ public abstract class ListCurator<S extends Model, E>
}
/**
- * Construct a curator for the specified subject holder.
- * The subject holder cannot be null.
+ * Construct a curator for the specified subject model.
+ * The subject model cannot be <code>null</code>.
*/
- protected ListCurator(PropertyValueModel<? extends S> subjectHolder) {
- super(subjectHolder);
+ protected ListCurator(PropertyValueModel<? extends S> subjectModel) {
+ super(subjectModel);
this.record = new ArrayList<E>();
this.stateChangeListener = this.buildStateChangeListener();
}
@@ -66,15 +69,16 @@ public abstract class ListCurator<S extends Model, E>
* The subject's state has changed, do inventory and report to listeners.
*/
protected StateChangeListener buildStateChangeListener() {
- return new StateChangeListener() {
- public void stateChanged(StateChangeEvent event) {
- ListCurator.this.submitInventoryReport();
- }
- @Override
- public String toString() {
- return "state change listener"; //$NON-NLS-1$
- }
- };
+ return new SubjectStateChangeListener();
+ }
+
+ protected class SubjectStateChangeListener
+ extends StateChangeAdapter
+ {
+ @Override
+ public void stateChanged(StateChangeEvent event) {
+ ListCurator.this.submitInventoryReport();
+ }
}
@@ -113,8 +117,8 @@ public abstract class ListCurator<S extends Model, E>
// ********** AspectAdapter implementation **********
@Override
- protected ListIterator<E> getValue() {
- return this.iterator();
+ protected List<E> getAspectValue() {
+ return this.record;
}
@Override
@@ -136,7 +140,7 @@ public abstract class ListCurator<S extends Model, E>
* The aspect has changed, notify listeners appropriately.
*/
@Override
- protected void fireAspectChanged(Object oldValue, Object newValue) {
+ protected void fireAspectChanged(List<E> oldValue, List<E> newValue) {
this.fireListChanged(LIST_VALUES, this.record);
}
@@ -146,7 +150,7 @@ public abstract class ListCurator<S extends Model, E>
@Override
protected void engageSubject_() {
((Model) this.subject).addStateChangeListener(this.stateChangeListener);
- // synch our list *after* we start listening to the subject,
+ // sync our list *after* we start listening to the subject,
// since its value might change when a listener is added
CollectionTools.addAll(this.record, this.iteratorForRecord());
}
@@ -222,5 +226,4 @@ public abstract class ListCurator<S extends Model, E>
public void toString(StringBuilder sb) {
sb.append(this.record);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java
index e3f7105771..de238160c9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListPropertyValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
+import org.eclipse.jpt.common.utility.model.listener.ListChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
@@ -43,10 +44,10 @@ public abstract class ListPropertyValueModelAdapter<T>
extends AbstractPropertyValueModelAdapter<T>
{
/** The wrapped list value model. */
- protected final ListValueModel<?> listHolder;
+ protected final ListValueModel<?> listModel;
- /** A listener that allows us to synch with changes to the wrapped list holder. */
- protected final ListChangeListener listChangeListener;
+ /** A listener that allows us to sync with changes to the wrapped list model. */
+ protected final ListChangeListener listListener;
// ********** constructor/initialization **********
@@ -55,48 +56,57 @@ public abstract class ListPropertyValueModelAdapter<T>
* Construct a property value model with the specified wrapped
* list value model.
*/
- protected ListPropertyValueModelAdapter(ListValueModel<?> listHolder) {
+ protected ListPropertyValueModelAdapter(ListValueModel<?> listModel) {
super();
- this.listHolder = listHolder;
- this.listChangeListener = this.buildListChangeListener();
+ if (listModel == null) {
+ throw new NullPointerException();
+ }
+ this.listModel = listModel;
+ this.listListener = this.buildListListener();
}
- protected ListChangeListener buildListChangeListener() {
- return new ListChangeListener() {
- public void itemsAdded(ListAddEvent event) {
- ListPropertyValueModelAdapter.this.itemsAdded(event);
- }
- public void itemsRemoved(ListRemoveEvent event) {
- ListPropertyValueModelAdapter.this.itemsRemoved(event);
- }
- public void itemsReplaced(ListReplaceEvent event) {
- ListPropertyValueModelAdapter.this.itemsReplaced(event);
- }
- public void itemsMoved(ListMoveEvent event) {
- ListPropertyValueModelAdapter.this.itemsMoved(event);
- }
- public void listCleared(ListClearEvent event) {
- ListPropertyValueModelAdapter.this.listCleared(event);
- }
- public void listChanged(ListChangeEvent event) {
- ListPropertyValueModelAdapter.this.listChanged(event);
- }
- @Override
- public String toString() {
- return "list change listener"; //$NON-NLS-1$
- }
- };
+ protected ListChangeListener buildListListener() {
+ return new ListListener();
+ }
+
+ protected class ListListener
+ extends ListChangeAdapter
+ {
+ @Override
+ public void itemsAdded(ListAddEvent event) {
+ ListPropertyValueModelAdapter.this.itemsAdded(event);
+ }
+ @Override
+ public void itemsRemoved(ListRemoveEvent event) {
+ ListPropertyValueModelAdapter.this.itemsRemoved(event);
+ }
+ @Override
+ public void itemsReplaced(ListReplaceEvent event) {
+ ListPropertyValueModelAdapter.this.itemsReplaced(event);
+ }
+ @Override
+ public void itemsMoved(ListMoveEvent event) {
+ ListPropertyValueModelAdapter.this.itemsMoved(event);
+ }
+ @Override
+ public void listCleared(ListClearEvent event) {
+ ListPropertyValueModelAdapter.this.listCleared(event);
+ }
+ @Override
+ public void listChanged(ListChangeEvent event) {
+ ListPropertyValueModelAdapter.this.listChanged(event);
+ }
}
- // ********** behavior **********
+ // ********** listener **********
/**
* Start listening to the list holder.
*/
@Override
protected void engageModel_() {
- this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener);
+ this.listModel.addListChangeListener(ListValueModel.LIST_VALUES, this.listListener);
}
/**
@@ -104,11 +114,11 @@ public abstract class ListPropertyValueModelAdapter<T>
*/
@Override
protected void disengageModel_() {
- this.listHolder.removeListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener);
+ this.listModel.removeListChangeListener(ListValueModel.LIST_VALUES, this.listListener);
}
- // ********** collection change support **********
+ // ********** list change support **********
/**
* Items were added to the wrapped list holder;
@@ -163,5 +173,4 @@ public abstract class ListPropertyValueModelAdapter<T>
// by default, simply recalculate the value and fire an event
this.propertyChanged();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelWrapper.java
index 7e01a399f3..1e5ef8807a 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -30,7 +30,7 @@ public abstract class ListValueModelWrapper<E>
/** The wrapped list value model. */
protected final ListValueModel<? extends E> listHolder;
- /** A listener that allows us to synch with changes to the wrapped list holder. */
+ /** A listener that allows us to sync with changes to the wrapped list model. */
protected final ListChangeListener listChangeListener;
@@ -160,5 +160,4 @@ public abstract class ListValueModelWrapper<E>
* propagate the change notification appropriately.
*/
protected abstract void listChanged(ListChangeEvent event);
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/NullPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/NullPropertyValueModel.java
index f445d96b36..1183325ea9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/NullPropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/NullPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
+import java.io.Serializable;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -20,7 +21,7 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
*/
public final class NullPropertyValueModel<T>
extends AbstractModel
- implements PropertyValueModel<T>
+ implements PropertyValueModel<T>, Serializable
{
private static final long serialVersionUID = 1L;
@@ -31,19 +32,12 @@ public final class NullPropertyValueModel<T>
super();
}
-
- // ********** PropertyValueModel implementation **********
-
public T getValue() {
return null;
}
-
- // ********** Object overrides **********
-
@Override
public String toString() {
return this.getClass().getSimpleName();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java
index 327a7342d3..f5969076a8 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyAspectAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,11 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
-import java.util.Arrays;
import java.util.Collection;
-
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -29,79 +28,86 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* <li>{@link #buildValue()}
* <li>{@link #setValue(Object)}
* </ul>
+ *
+ * @param <S> the type of the model's subject
+ * @param <V> the type of the subject's property aspect
*/
public abstract class PropertyAspectAdapter<S extends Model, V>
extends AspectPropertyValueModelAdapter<S, V>
{
/** The name of the subject's properties that we use for the value. */
- protected final String[] propertyNames;
- protected static final String[] EMPTY_PROPERTY_NAMES = new String[0];
+ protected final String[] aspectNames;
+ protected static final String[] EMPTY_ASPECT_NAMES = new String[0];
/** A listener that listens to the appropriate properties of the subject. */
- protected final PropertyChangeListener propertyChangeListener;
+ protected final PropertyChangeListener aspectChangeListener;
// ********** constructors **********
/**
* Construct a property aspect adapter for the specified subject
- * and property.
+ * and property aspect.
*/
- protected PropertyAspectAdapter(String propertyName, S subject) {
- this(new String[] {propertyName}, subject);
+ protected PropertyAspectAdapter(String aspectName, S subject) {
+ this(new String[] {aspectName}, subject);
}
/**
* Construct a property aspect adapter for the specified subject
- * and properties.
+ * and property aspects.
*/
- protected PropertyAspectAdapter(String[] propertyNames, S subject) {
- this(new StaticPropertyValueModel<S>(subject), propertyNames);
+ protected PropertyAspectAdapter(String[] aspectNames, S subject) {
+ this(new StaticPropertyValueModel<S>(subject), aspectNames);
}
/**
- * Construct a property aspect adapter for the specified subject holder
- * and properties.
+ * Construct a property aspect adapter for the specified subject model
+ * and property aspects.
*/
- protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectHolder, String... propertyNames) {
- super(subjectHolder);
- this.propertyNames = propertyNames;
- this.propertyChangeListener = this.buildPropertyChangeListener();
+ protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectModel, String... aspectNames) {
+ super(subjectModel);
+ this.aspectNames = aspectNames;
+ this.aspectChangeListener = this.buildAspectChangeListener();
}
/**
- * Construct a property aspect adapter for the specified subject holder
- * and properties.
+ * Construct a property aspect adapter for the specified subject model
+ * and property aspects.
*/
- protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectHolder, Collection<String> propertyNames) {
- this(subjectHolder, propertyNames.toArray(new String[propertyNames.size()]));
+ protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectModel, Collection<String> aspectNames) {
+ this(subjectModel, aspectNames.toArray(new String[aspectNames.size()]));
}
/**
- * Construct a property aspect adapter for an "unchanging" property in
+ * Construct a property aspect adapter for an "unchanging" property aspect in
* the specified subject. This is useful for a property aspect that does not
* change for a particular subject; but the subject will change, resulting in
* a new property. (A {@link TransformationPropertyValueModel} could also be
* used in this situation.)
*/
- protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
- this(subjectHolder, EMPTY_PROPERTY_NAMES);
+ protected PropertyAspectAdapter(PropertyValueModel<? extends S> subjectModel) {
+ this(subjectModel, EMPTY_ASPECT_NAMES);
}
// ********** initialization **********
- protected PropertyChangeListener buildPropertyChangeListener() {
- // transform the subject's property change events into VALUE property change events
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- PropertyAspectAdapter.this.propertyChanged(event);
- }
- @Override
- public String toString() {
- return "property change listener: " + Arrays.asList(PropertyAspectAdapter.this.propertyNames); //$NON-NLS-1$
- }
- };
+ protected PropertyChangeListener buildAspectChangeListener() {
+ return new AspectChangeListener();
+ }
+
+ /**
+ * Transform the subject's property change events into
+ * {@link #VALUE} property change events.
+ */
+ protected class AspectChangeListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ PropertyAspectAdapter.this.aspectChanged(event);
+ }
}
@@ -109,20 +115,19 @@ public abstract class PropertyAspectAdapter<S extends Model, V>
@Override
protected void engageSubject_() {
- for (String propertyName : this.propertyNames) {
- ((Model) this.subject).addPropertyChangeListener(propertyName, this.propertyChangeListener);
+ for (String propertyName : this.aspectNames) {
+ this.subject.addPropertyChangeListener(propertyName, this.aspectChangeListener);
}
}
@Override
protected void disengageSubject_() {
- for (String propertyName : this.propertyNames) {
- ((Model) this.subject).removePropertyChangeListener(propertyName, this.propertyChangeListener);
+ for (String propertyName : this.aspectNames) {
+ this.subject.removePropertyChangeListener(propertyName, this.aspectChangeListener);
}
}
- protected void propertyChanged(@SuppressWarnings("unused") PropertyChangeEvent event) {
- this.propertyChanged();
+ protected void aspectChanged(@SuppressWarnings("unused") PropertyChangeEvent event) {
+ this.aspectChanged();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyCollectionValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyCollectionValueModelAdapter.java
index 1d432aeda5..24af307f1c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyCollectionValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyCollectionValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -98,7 +98,7 @@ public class PropertyCollectionValueModelAdapter<E>
@Override
protected void engageModel() {
this.valueHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.propertyChangeListener);
- // synch our value *after* we start listening to the value holder,
+ // sync our value *after* we start listening to the value model,
// since its value might change when a listener is added
this.value = this.valueHolder.getValue();
}
@@ -137,5 +137,4 @@ public class PropertyCollectionValueModelAdapter<E>
public void toString(StringBuilder sb) {
StringTools.append(sb, this);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyListValueModelAdapter.java
index 81fa3cc8a8..c845d4fa5e 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -119,7 +119,7 @@ public class PropertyListValueModelAdapter<E>
@Override
protected void engageModel() {
this.valueHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.propertyChangeListener);
- // synch our value *after* we start listening to the value holder,
+ // sync our value *after* we start listening to the value model,
// since its value might change when a listener is added
this.value = this.valueHolder.getValue();
}
@@ -153,5 +153,4 @@ public class PropertyListValueModelAdapter<E>
public void toString(StringBuilder sb) {
StringTools.append(sb, this);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelWrapper.java
index 241b85d609..eebc569e89 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/PropertyValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,6 +10,7 @@
package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -19,74 +20,91 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* its change notifications. Subclasses must implement the appropriate
* {@link PropertyValueModel}.
* <p>
- * Subclasses must implement the following methods:<ul>
- * <li>{@link #valueChanged(PropertyChangeEvent)}<p>
+ * Subclasses must implement one of the following methods:<ul>
+ * <li>{@link #wrappedValueChanged(PropertyChangeEvent)}<p>
+ * implement this method to propagate the appropriate change notification
+ * <li>{@link #wrappedValueChanged(Object, Object) valueChanged(V, V)}<p>
* implement this method to propagate the appropriate change notification
* </ul>
+ *
+ * @param <V> the type of the <em>wrapped</em> model's value
*/
public abstract class PropertyValueModelWrapper<V>
extends AbstractPropertyValueModel
{
- /** The wrapped property value model. */
- protected final PropertyValueModel<? extends V> valueHolder;
+ /** The wrapped property value model. Never <code>null</code>. */
+ protected final PropertyValueModel<? extends V> valueModel;
- /** A listener that allows us to synch with changes to the wrapped value holder. */
- protected final PropertyChangeListener valueChangeListener;
+ /** A listener that allows us to sync with changes to the wrapped value model. */
+ protected final PropertyChangeListener valueListener;
// ********** constructors/initialization **********
/**
* Construct a property value model with the specified wrapped
- * property value model. The value holder is required.
+ * property value model.
*/
- protected PropertyValueModelWrapper(PropertyValueModel<? extends V> valueHolder) {
+ protected PropertyValueModelWrapper(PropertyValueModel<? extends V> valueModel) {
super();
- if (valueHolder == null) {
+ if (valueModel == null) {
throw new NullPointerException();
}
- this.valueHolder = valueHolder;
- this.valueChangeListener = this.buildValueChangeListener();
+ this.valueModel = valueModel;
+ this.valueListener = this.buildValueListener();
+ }
+
+ protected PropertyChangeListener buildValueListener() {
+ return new ValueListener();
}
-
- protected PropertyChangeListener buildValueChangeListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- PropertyValueModelWrapper.this.valueChanged(event);
- }
- @Override
- public String toString() {
- return "value change listener"; //$NON-NLS-1$
- }
- };
+
+ /* CU private */ class ValueListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ PropertyValueModelWrapper.this.wrappedValueChanged(event);
+ }
}
-
- // ********** behavior **********
-
+
+ // ********** listen to wrapped value model **********
+
/**
* Begin listening to the value holder.
*/
@Override
protected void engageModel() {
- this.valueHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.valueChangeListener);
+ this.valueModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.valueListener);
}
-
+
/**
* Stop listening to the value holder.
*/
@Override
protected void disengageModel() {
- this.valueHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.valueChangeListener);
+ this.valueModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.valueListener);
}
-
+
// ********** property change support **********
/**
- * The value of the wrapped value holder has changed;
+ * The value of the wrapped value model has changed;
* propagate the change notification appropriately.
+ * @see #wrappedValueChanged(Object, Object)
*/
- protected abstract void valueChanged(PropertyChangeEvent event);
+ @SuppressWarnings("unchecked")
+ protected void wrappedValueChanged(PropertyChangeEvent event) {
+ this.wrappedValueChanged((V) event.getOldValue(), (V) event.getNewValue());
+ }
+ /**
+ * The value of the wrapped value model has changed;
+ * propagate the change notification appropriately.
+ * @see #wrappedValueChanged(PropertyChangeEvent)
+ */
+ protected void wrappedValueChanged(@SuppressWarnings("unused") V oldValue, @SuppressWarnings("unused") V newValue) {
+ throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ReadOnlyWritablePropertyValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ReadOnlyWritablePropertyValueModelWrapper.java
index dcf7b97594..749a009879 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ReadOnlyWritablePropertyValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ReadOnlyWritablePropertyValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,13 +23,13 @@ public class ReadOnlyWritablePropertyValueModelWrapper<T>
extends PropertyValueModelWrapper<T>
implements WritablePropertyValueModel<T>
{
- public ReadOnlyWritablePropertyValueModelWrapper(PropertyValueModel<? extends T> valueHolder) {
- super(valueHolder);
+ public ReadOnlyWritablePropertyValueModelWrapper(PropertyValueModel<? extends T> valueModel) {
+ super(valueModel);
}
public T getValue() {
- return this.valueHolder.getValue();
+ return this.valueModel.getValue();
}
public void setValue(T value) {
@@ -37,7 +37,7 @@ public class ReadOnlyWritablePropertyValueModelWrapper<T>
}
@Override
- protected void valueChanged(PropertyChangeEvent event) {
+ protected void wrappedValueChanged(PropertyChangeEvent event) {
this.firePropertyChanged(event.clone(this));
}
@@ -45,5 +45,4 @@ public class ReadOnlyWritablePropertyValueModelWrapper<T>
public void toString(StringBuilder sb) {
sb.append(this.getValue());
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SetCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SetCollectionValueModel.java
index d04722f9ff..8fac2c1442 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SetCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SetCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -71,7 +71,7 @@ public class SetCollectionValueModel<E>
@Override
protected void engageModel() {
super.engageModel();
- // synch our cache *after* we start listening to the nested collection,
+ // sync our cache *after* we start listening to the nested collection,
// since its value might change when a listener is added
CollectionTools.addAll(this.bag, this.collectionHolder);
}
@@ -130,5 +130,4 @@ public class SetCollectionValueModel<E>
public void toString(StringBuilder sb) {
StringTools.append(sb, this);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimplePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimplePropertyValueModel.java
index 844d1c693e..c26e3a5238 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimplePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimplePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,27 +16,30 @@ import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
- * Implementation of {@link WritablePropertyValueModel} that simply holds on to an
- * object and uses it as the value.
+ * Implementation of {@link WritablePropertyValueModel} that simply holds on to
+ * an object, uses it as the value, and fires the appropriate event when the
+ * value changes.
+ *
+ * @param <V> the type of the model's value
*/
-public class SimplePropertyValueModel<T>
+public class SimplePropertyValueModel<V>
extends AbstractModel
- implements WritablePropertyValueModel<T>
+ implements WritablePropertyValueModel<V>
{
/** The value. */
- protected T value;
+ protected V value;
/**
* Construct a property value model for the specified value.
*/
- public SimplePropertyValueModel(T value) {
+ public SimplePropertyValueModel(V value) {
super();
this.value = value;
}
/**
- * Construct a property value model with a starting value of null.
+ * Construct a property value model with a value of <code>null</code>.
*/
public SimplePropertyValueModel() {
this(null);
@@ -48,12 +51,12 @@ public class SimplePropertyValueModel<T>
}
- public T getValue() {
+ public V getValue() {
return this.value;
}
- public void setValue(T value) {
- T old = this.value;
+ public void setValue(V value) {
+ V old = this.value;
this.value = value;
this.firePropertyChanged(VALUE, old, value);
}
@@ -62,5 +65,4 @@ public class SimplePropertyValueModel<T>
public void toString(StringBuilder sb) {
sb.append(this.value);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java
index 0f1ff4cf55..3cf9d24d80 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,7 +21,8 @@ import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
/**
* An adapter that allows us to make a {@link CollectionValueModel}
- * (or {@link ListValueModel}) behave like a {@link ListValueModel}
+ * (or {@link org.eclipse.jpt.common.utility.model.value.ListValueModel ListValueModel})
+ * behave like a {@link org.eclipse.jpt.common.utility.model.value.ListValueModel ListValueModel}
* that keeps its contents sorted and notifies listeners appropriately.
* <p>
* The {@link Comparator} can be changed at any time; allowing the same
@@ -29,7 +30,7 @@ import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
* wants to sort a list of files first by name, then by date, then by size).
* <p>
* <strong>NB:</strong> Since we only listen to the wrapped collection when we have
- * listeners ourselves and we can only stay in synch with the wrapped
+ * listeners ourselves and we can only stay in sync with the wrapped
* collection while we are listening to it, results to various methods
* (e.g. {@link #size()}, {@link #get(int)}) will be
* unpredictable whenever
@@ -121,5 +122,4 @@ public class SortedListValueModelAdapter<E>
this.fireItemsReplaced(LIST_VALUES, diffRange.start, sortedItems, unsortedItems);
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelWrapper.java
index 8514f37266..0195f52616 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -36,7 +36,7 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
* wants to sort a list of files first by name, then by date, then by size).
* <p>
* <strong>NB:</strong> Since we only listen to the wrapped collection when we have
- * listeners ourselves and we can only stay in synch with the wrapped
+ * listeners ourselves and we can only stay in sync with the wrapped
* collection while we are listening to it, results to various methods
* (e.g. {@link #size()}, {@link #get(int)}) will be unpredictable whenever
* we do not have any listeners. This should not be too painful since,
@@ -121,7 +121,7 @@ public class SortedListValueModelWrapper<E>
@Override
protected void engageModel() {
super.engageModel();
- // synch the sorted list *after* we start listening to the wrapped list holder,
+ // sync the sorted list *after* we start listening to the wrapped list model,
// since its value might change when a listener is added
this.buildSortedList();
}
@@ -246,5 +246,4 @@ public class SortedListValueModelWrapper<E>
public void toString(StringBuilder sb) {
sb.append(this.sortedList);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StatePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StatePropertyValueModelAdapter.java
index 6d179ffa63..011195c562 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StatePropertyValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/StatePropertyValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.StateChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
/**
@@ -35,8 +36,8 @@ public abstract class StatePropertyValueModelAdapter<T>
/** The wrapped model. */
protected final Model model;
- /** A listener that allows us to synch with changes to the wrapped model. */
- protected final StateChangeListener stateChangeListener;
+ /** A listener that allows us to sync with changes to the wrapped model. */
+ protected final StateChangeListener stateListener;
// ********** constructor/initialization **********
@@ -46,31 +47,35 @@ public abstract class StatePropertyValueModelAdapter<T>
*/
protected StatePropertyValueModelAdapter(Model model) {
super();
+ if (model == null) {
+ throw new NullPointerException();
+ }
this.model = model;
- this.stateChangeListener = this.buildStateChangeListener();
+ this.stateListener = this.buildStateListener();
}
- protected StateChangeListener buildStateChangeListener() {
- return new StateChangeListener() {
- public void stateChanged(StateChangeEvent event) {
- StatePropertyValueModelAdapter.this.stateChanged(event);
- }
- @Override
- public String toString() {
- return "state change listener"; //$NON-NLS-1$
- }
- };
+ protected StateChangeListener buildStateListener() {
+ return new StateListener();
+ }
+
+ protected class StateListener
+ extends StateChangeAdapter
+ {
+ @Override
+ public void stateChanged(StateChangeEvent event) {
+ StatePropertyValueModelAdapter.this.stateChanged(event);
+ }
}
- // ********** behavior **********
+ // ********** listener **********
/**
* Start listening to the model.
*/
@Override
protected void engageModel_() {
- this.model.addStateChangeListener(this.stateChangeListener);
+ this.model.addStateChangeListener(this.stateListener);
}
/**
@@ -78,7 +83,7 @@ public abstract class StatePropertyValueModelAdapter<T>
*/
@Override
protected void disengageModel_() {
- this.model.removeStateChangeListener(this.stateChangeListener);
+ this.model.removeStateChangeListener(this.stateListener);
}
@@ -92,5 +97,4 @@ public abstract class StatePropertyValueModelAdapter<T>
// by default, simply recalculate the value and fire an event
this.propertyChanged();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java
index edc4055ff3..af9d0bbace 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -29,7 +29,7 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
* An adapter that allows us to transform a {@link ListValueModel}
* (or adapted {@link CollectionValueModel}) into a read-only {@link ListValueModel}
* whose items are tranformations of the items in the wrapped
- * {@link ListValueModel}. It will keep its contents in synch with
+ * {@link ListValueModel}. It will keep its contents in sync with
* the contents of the wrapped {@link ListValueModel} and notifies its
* listeners of any changes.
* <p>
@@ -43,7 +43,7 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
* wrapped item is <code>null</code>, override {@link #transformItem(Object)}.
* <p>
* <strong>NB:</strong> Since we only listen to the wrapped list when we have
- * listeners ourselves and we can only stay in synch with the wrapped
+ * listeners ourselves and we can only stay in sync with the wrapped
* list while we are listening to it, results to various methods
* (e.g. {@link #size()}, {@link #get(int)}) will be unpredictable whenever
* we do not have any listeners. This should not be too painful since,
@@ -139,7 +139,7 @@ public class TransformationListValueModel<E1, E2>
@Override
protected void engageModel() {
super.engageModel();
- // synch the transformed list *after* we start listening to the list holder,
+ // sync the transformed list *after* we start listening to the list model,
// since its value might change when a listener is added
this.transformedList.addAll(this.transformItems(this.listHolder));
}
@@ -305,5 +305,4 @@ public class TransformationListValueModel<E1, E2>
return (item == null) ? null : TransformationListValueModel.this.transformItem_(item);
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java
index 6c7dadb7c4..8798ec7c8c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationPropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.internal.Transformer;
-import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
/**
@@ -18,19 +17,35 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* {@link PropertyValueModel} and uses a {@link Transformer}
* to transform the wrapped value before it is returned by {@link #getValue()}.
* <p>
+ * The transformed value is calculated and cached during initialization and every
+ * time the wrapped value changes. This can be useful when the old value
+ * passed in to {@link #wrappedValueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)}
+ * can no longer be "transformed" because its state is no longer valid.
+ * This caching can also improve time performance in some situations.
+ * <p>
* As an alternative to building a {@link Transformer},
* a subclass of <code>TransformationPropertyValueModel</code> can
* either override {@link #transform_(Object)} or,
- * if something other than null should be returned when the wrapped value
- * is null, override {@link #transform(Object)}.
+ * if something other than <code>null</code> should be returned when the
+ * wrapped value is <code>null</code>, override {@link #transform(Object)}.
*
+ * @param <V1> the type of the <em>wrapped</em> model's value
+ * @param <V2> the type of the model's <em>transformed</em> value
* @see Transformer
*/
-public class TransformationPropertyValueModel<T1, T2>
- extends PropertyValueModelWrapper<T1>
- implements PropertyValueModel<T2>
+public class TransformationPropertyValueModel<V1, V2>
+ extends PropertyValueModelWrapper<V1>
+ implements PropertyValueModel<V2>
{
- protected final Transformer<T1, T2> transformer;
+ /**
+ * Cache the transformed value so that during property change event
+ * notification we do not have to transform the old value. It is possible
+ * the old value is no longer be valid in the model; as a result,
+ * transforming it would not be valid.
+ */
+ protected volatile V2 value;
+
+ protected final Transformer<V1, V2> transformer;
// ********** constructors/initialization **********
@@ -42,103 +57,108 @@ public class TransformationPropertyValueModel<T1, T2>
* {@link #transform_(Object)} or {@link #transform(Object)}
* method instead of building a {@link Transformer}.
*/
- public TransformationPropertyValueModel(PropertyValueModel<? extends T1> valueHolder) {
- super(valueHolder);
+ public TransformationPropertyValueModel(PropertyValueModel<? extends V1> valueModel) {
+ super(valueModel);
this.transformer = this.buildTransformer();
}
/**
* Construct a property value model with the specified nested
- * property value model and transformer.
+ * property value model and transformer. Depending on the nested model,
+ * the transformer may be required to handle a <code>null</code> value.
*/
- public TransformationPropertyValueModel(PropertyValueModel<? extends T1> valueHolder, Transformer<T1, T2> transformer) {
- super(valueHolder);
+ public TransformationPropertyValueModel(PropertyValueModel<? extends V1> valueModel, Transformer<V1, V2> transformer) {
+ super(valueModel);
+ if (transformer == null) {
+ throw new NullPointerException();
+ }
this.transformer = transformer;
}
- protected Transformer<T1, T2> buildTransformer() {
+ protected Transformer<V1, V2> buildTransformer() {
return new DefaultTransformer();
}
// ********** PropertyValueModel implementation **********
- public T2 getValue() {
- // transform the object returned by the nested value model before returning it
- return this.transform(this.valueHolder.getValue());
+ /**
+ * No need to transform the nested value, simply return the cached value,
+ * which is already transformed.
+ */
+ public V2 getValue() {
+ return this.value;
}
// ********** PropertyValueModelWrapper implementation **********
+ /**
+ * Propagate the event with transformed values.
+ */
@Override
- protected void valueChanged(PropertyChangeEvent event) {
- // transform the values before propagating the change event
- @SuppressWarnings("unchecked")
- T1 eventOldValue = (T1) event.getOldValue();
- Object oldValue = this.transformOld(eventOldValue);
- @SuppressWarnings("unchecked")
- T1 eventNewValue = (T1) event.getNewValue();
- Object newValue = this.transformNew(eventNewValue);
- this.firePropertyChanged(VALUE, oldValue, newValue);
+ protected void wrappedValueChanged(V1 oldValue, V1 newValue) {
+ V2 old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = this.transform(newValue));
}
- // ********** behavior **********
+ // ********** transformation **********
/**
* Transform the specified value and return the result.
- * This is called by
- * {@link #getValue()},
- * {@link #transformOld(Object)}, and
- * {@link #transformNew(Object)}.
*/
- protected T2 transform(T1 value) {
- return this.transformer.transform(value);
+ protected V2 transform(V1 v) {
+ return this.transformer.transform(v);
}
/**
- * Transform the specified, non-null, value and return the result.
+ * Transform the specified, non-<code>null</code>, value and return the result.
*/
- protected T2 transform_(@SuppressWarnings("unused") T1 value) {
+ protected V2 transform_(@SuppressWarnings("unused") V1 v) {
throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
}
- /**
- * Transform the specified old value and return the result.
- * By default, call {@link #transform(Object)}.
- * This is called by {@link #valueChanged(PropertyChangeEvent)}.
- */
- protected T2 transformOld(T1 value) {
- return this.transform(value);
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.value);
}
-
+
+
+ // ********** listeners **********
+
/**
- * Transform the specified new value and return the result.
- * By default, call {@link #transform(Object)}.
- * This is called by {@link #valueChanged(PropertyChangeEvent)}.
+ * We have listeners, transform the nested value and cache the result.
*/
- protected T2 transformNew(T1 value) {
- return this.transform(value);
+ @Override
+ protected void engageModel() {
+ super.engageModel();
+ this.value = this.transform(this.valueModel.getValue());
}
+ /**
+ * We have no more listeners, clear the cached value.
+ */
@Override
- public void toString(StringBuilder sb) {
- sb.append(this.getValue());
+ protected void disengageModel() {
+ this.value = null;
+ super.disengageModel();
}
// ********** default transformer **********
/**
- * The default transformer will return null if the wrapped value is null.
- * If the wrapped value is not null, it is transformed by a subclass
+ * The default transformer will return <code>null</code> if the wrapped
+ * value is <code>null</code>. If the wrapped value is not
+ * <code>null</code>, it is transformed by a subclass
* implementation of {@link TransformationPropertyValueModel#transform_(Object)}.
*/
- protected class DefaultTransformer implements Transformer<T1, T2> {
- public T2 transform(T1 value) {
- return (value == null) ? null : TransformationPropertyValueModel.this.transform_(value);
+ protected class DefaultTransformer
+ implements Transformer<V1, V2>
+ {
+ public V2 transform(V1 v) {
+ return (v == null) ? null : TransformationPropertyValueModel.this.transform_(v);
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationWritablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationWritablePropertyValueModel.java
index 1d42d4c54e..be357e7869 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationWritablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationWritablePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,80 +9,109 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value;
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
* A <code>TransformationWritablePropertyValueModel</code> wraps another
- * {@link WritablePropertyValueModel} and uses a {@link BidiTransformer}
+ * {@link WritablePropertyValueModel} and uses two {@link Transformer}s
* to:<ul>
* <li>transform the wrapped value before it is returned by {@link #getValue()}
* <li>"reverse-transform" the new value that comes in via
* {@link #setValue(Object)}
* </ul>
- * As an alternative to building a {@link BidiTransformer},
+ * <strong>NB:</strong> If the mapping between the wrapped values and the
+ * transformed values is not strictly one-to-one, the behavior of the
+ * transformation model may seem unpredictable; since the wrapped model's
+ * change events can cause the transformation model's value to change.
+ * For example: If the value is a string to be <em>transformed</em> to uppercase
+ * and <em>reverse-transformed</em> to lowercase; then mixed case values passed to
+ * the transformation model will be<ul>
+ * <li>unchanged if the transformation model has <em>no</em> listeners
+ * <li>changed to uppercase if the transformation model has any listeners
+ * ({@link #wrappedValueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)})
+ * </ul>
+ * As an alternative to building two {@link Transformer}s,
* a subclass of <code>TransformationWritablePropertyValueModel</code> can
* override {@link #transform_(Object)} and {@link #reverseTransform_(Object)};
- * or, if something other than null should be returned when the wrapped value
- * is null or the new value is null, override {@link #transform(Object)}
- * and {@link #reverseTransform(Object)}.
+ * or, if something other than <code>null</code> should be returned when the
+ * wrapped value is <code>null</code> or the new value is <code>null</code>,
+ * override {@link #transform(Object)} and {@link #reverseTransform(Object)}.
+ *
+ * @param <V1> the type of the <em>wrapped</em> model's value
+ * @param <V2> the type of the model's <em>transformed</em> value
+ * @see Transformer
*/
-public class TransformationWritablePropertyValueModel<T1, T2>
- extends TransformationPropertyValueModel<T1, T2>
- implements WritablePropertyValueModel<T2>
+public class TransformationWritablePropertyValueModel<V1, V2>
+ extends TransformationPropertyValueModel<V1, V2>
+ implements WritablePropertyValueModel<V2>
{
+ protected final Transformer<V2, V1> reverseTransformer;
+
// ********** constructors/initialization **********
/**
* Construct a writable property value model with the specified nested
- * writable property value model and the default bidi transformer.
+ * writable property value model and the default transformers.
* Use this constructor if you want to override the
* {@link #transform_(Object)} and {@link #reverseTransform_(Object)}
* (or {@link #transform(Object)} and {@link #reverseTransform(Object)})
- * methods instead of building a {@link BidiTransformer}.
+ * methods instead of building {@link Transformer}s.
*/
- public TransformationWritablePropertyValueModel(WritablePropertyValueModel<T1> valueHolder) {
- super(valueHolder);
+ public TransformationWritablePropertyValueModel(WritablePropertyValueModel<V1> valueModel) {
+ super(valueModel);
+ this.reverseTransformer = this.buildReverseTransformer();
}
/**
* Construct a writable property value model with the specified nested
- * writable property value model and bidi transformer.
+ * writable property value model and transformers.
*/
- public TransformationWritablePropertyValueModel(WritablePropertyValueModel<T1> valueHolder, BidiTransformer<T1, T2> transformer) {
- super(valueHolder, transformer);
+ public TransformationWritablePropertyValueModel(WritablePropertyValueModel<V1> valueModel, Transformer<V1, V2> transformer, Transformer<V2, V1> reverseTransformer) {
+ super(valueModel, transformer);
+ if (reverseTransformer == null) {
+ throw new NullPointerException();
+ }
+ this.reverseTransformer = reverseTransformer;
}
- @Override
- protected BidiTransformer<T1, T2> buildTransformer() {
- return new DefaultBidiTransformer();
+ protected Transformer<V2, V1> buildReverseTransformer() {
+ return new DefaultReverseTransformer();
}
// ********** WritablePropertyValueModel implementation **********
- public void setValue(T2 value) {
- // "reverse-transform" the object before passing it to the the nested value model
- this.getValueHolder().setValue(this.reverseTransform(value));
+ /**
+ * Cache and "reverse-transform" the new value before passing it to the the
+ * nested value model.
+ * A side-effect of caching the new value is that the wrapper will
+ * <em>not</em> fire an event when the wrapped model fires an event when
+ * called from here.
+ * @see #wrappedValueChanged(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)
+ */
+ public void setValue(V2 value) {
+ this.value = value;
+ this.getValueModel().setValue(this.reverseTransform(value));
}
- // ********** behavior **********
+ // ********** transformation **********
/**
* "Reverse-transform" the specified value and return the result.
* This is called by {@link #setValue(Object)}.
*/
- protected T1 reverseTransform(T2 value) {
- return this.getTransformer().reverseTransform(value);
+ protected V1 reverseTransform(V2 v) {
+ return this.reverseTransformer.transform(v);
}
/**
* "Reverse-transform" the specified, non-<code>null</code>,
* value and return the result.
*/
- protected T1 reverseTransform_(@SuppressWarnings("unused") T2 value) {
+ protected V1 reverseTransform_(@SuppressWarnings("unused") V2 v) {
throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
}
@@ -90,42 +119,28 @@ public class TransformationWritablePropertyValueModel<T1, T2>
// ********** queries **********
/**
- * Our constructors accept only a {@link WritablePropertyValueModel<T1>},
+ * Our constructors accept only a {@link WritablePropertyValueModel}{@code<V>},
* so this cast should be safe.
*/
@SuppressWarnings("unchecked")
- protected WritablePropertyValueModel<T1> getValueHolder() {
- return (WritablePropertyValueModel<T1>) this.valueHolder;
- }
-
- /**
- * Our constructors accept only a {@link BidiTransformer<T1, T2>},
- * so this cast should be safe.
- */
- protected BidiTransformer<T1, T2> getTransformer() {
- return (BidiTransformer<T1, T2>) this.transformer;
+ protected WritablePropertyValueModel<V1> getValueModel() {
+ return (WritablePropertyValueModel<V1>) this.valueModel;
}
- // ********** default bidi transformer **********
+ // ********** default reverse transformer **********
/**
- * The default bidi transformer will return <code>null</code> if the
- * wrapped value is <code>null</code>.
- * If the wrapped value is not <code>null</code>, it is transformed by a subclass
- * implementation of {@link #transform_(Object)}.
- * The default bidi transformer will also return <code>null</code>
+ * The default reverse transformer will return <code>null</code>
* if the new value is <code>null</code>.
* If the new value is not <code>null</code>, it is reverse-transformed
* by a subclass implementation of {@link #reverseTransform_(Object)}.
*/
- protected class DefaultBidiTransformer
- extends DefaultTransformer
- implements BidiTransformer<T1, T2>
+ protected class DefaultReverseTransformer
+ implements Transformer<V2, V1>
{
- public T1 reverseTransform(T2 value) {
- return (value == null) ? null : TransformationWritablePropertyValueModel.this.reverseTransform_(value);
+ public V1 transform(V2 v) {
+ return (v == null) ? null : TransformationWritablePropertyValueModel.this.reverseTransform_(v);
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreeAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreeAspectAdapter.java
deleted file mode 100644
index 178d1ed2bb..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreeAspectAdapter.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.eclipse.jpt.common.utility.model.Model;
-import org.eclipse.jpt.common.utility.model.event.TreeAddEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeClearEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-
-/**
- * This extension of {@link AspectTreeValueModelAdapter} provides
- * basic tree change support.
- * This converts a set of one or more trees into
- * a single {@link #NODES} tree.
- * <p>
- * The typical subclass will override the following methods (see the descriptions
- * in {@link AspectTreeValueModelAdapter}):<ul>
- * <li>{@link #nodes_()}
- * <li>{@link #nodes()}
- * </ul>
- */
-public abstract class TreeAspectAdapter<S extends Model, E>
- extends AspectTreeValueModelAdapter<S, E>
-{
- /**
- * The name of the subject's trees that we use for the value.
- */
- protected final String[] treeNames;
- protected static final String[] EMPTY_TREE_NAMES = new String[0];
-
- /** A listener that listens to the subject's tree aspects. */
- protected final TreeChangeListener treeChangeListener;
-
-
- // ********** constructors **********
-
- /**
- * Construct a tree aspect adapter for the specified subject
- * and tree.
- */
- protected TreeAspectAdapter(String treeName, S subject) {
- this(new String[] {treeName}, subject);
- }
-
- /**
- * Construct a tree aspect adapter for the specified subject
- * and trees.
- */
- protected TreeAspectAdapter(String[] treeNames, S subject) {
- this(new StaticPropertyValueModel<S>(subject), treeNames);
- }
-
- /**
- * Construct a tree aspect adapter for the specified subject holder
- * and trees.
- */
- protected TreeAspectAdapter(PropertyValueModel<? extends S> subjectHolder, String... treeNames) {
- super(subjectHolder);
- this.treeNames = treeNames;
- this.treeChangeListener = this.buildTreeChangeListener();
- }
-
- /**
- * Construct a tree aspect adapter for the specified subject holder
- * and trees.
- */
- protected TreeAspectAdapter(PropertyValueModel<? extends S> subjectHolder, Collection<String> treeNames) {
- this(subjectHolder, treeNames.toArray(new String[treeNames.size()]));
- }
-
- /**
- * Construct a tree aspect adapter for an "unchanging" tree in
- * the specified subject. This is useful for a tree aspect that does not
- * change for a particular subject; but the subject will change, resulting in
- * a new tree.
- */
- protected TreeAspectAdapter(PropertyValueModel<? extends S> subjectHolder) {
- this(subjectHolder, EMPTY_TREE_NAMES);
- }
-
-
- // ********** initialization **********
-
- protected TreeChangeListener buildTreeChangeListener() {
- // transform the subject's tree change events into VALUE tree change events
- return new TreeChangeListener() {
- public void nodeAdded(TreeAddEvent event) {
- TreeAspectAdapter.this.nodeAdded(event);
- }
- public void nodeRemoved(TreeRemoveEvent event) {
- TreeAspectAdapter.this.nodeRemoved(event);
- }
- public void treeCleared(TreeClearEvent event) {
- TreeAspectAdapter.this.treeCleared(event);
- }
- public void treeChanged(TreeChangeEvent event) {
- TreeAspectAdapter.this.treeChanged(event);
- }
- @Override
- public String toString() {
- return "tree change listener: " + Arrays.asList(TreeAspectAdapter.this.treeNames); //$NON-NLS-1$
- }
- };
- }
-
-
- // ********** AspectAdapter implementation **********
-
- @Override
- protected void engageSubject_() {
- for (String treeName : this.treeNames) {
- ((Model) this.subject).addTreeChangeListener(treeName, this.treeChangeListener);
- }
- }
-
- @Override
- protected void disengageSubject_() {
- for (String treeName : this.treeNames) {
- ((Model) this.subject).removeTreeChangeListener(treeName, this.treeChangeListener);
- }
- }
-
-
- // ********** behavior **********
-
- protected void nodeAdded(TreeAddEvent event) {
- this.fireNodeAdded(event.clone(this, NODES));
- }
-
- protected void nodeRemoved(TreeRemoveEvent event) {
- this.fireNodeRemoved(event.clone(this, NODES));
- }
-
- protected void treeCleared(TreeClearEvent event) {
- this.fireTreeCleared(event.clone(this, NODES));
- }
-
- protected void treeChanged(TreeChangeEvent event) {
- this.fireTreeChanged(event.clone(this, NODES));
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreePropertyValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreePropertyValueModelAdapter.java
deleted file mode 100644
index 66258c2108..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TreePropertyValueModelAdapter.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.model.value;
-
-import org.eclipse.jpt.common.utility.model.event.TreeAddEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeClearEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
-import org.eclipse.jpt.common.utility.model.value.TreeValueModel;
-
-/**
- * This abstract class provides the infrastructure needed to wrap
- * a tree value model, "lazily" listen to it, and convert
- * its change notifications into property value model change
- * notifications.
- * <p>
- * Subclasses must override:<ul>
- * <li>{@link #buildValue()}<p>
- * to return the current property value, as derived from the
- * current collection value
- * </ul>
- * Subclasses might want to override the following methods
- * to improve performance (by not recalculating the value, if possible):<ul>
- * <li>{@link #nodeAdded(TreeChangeEvent event)}
- * <li>{@link #nodeRemoved(TreeChangeEvent event)}
- * <li>{@link #treeCleared(TreeChangeEvent event)}
- * <li>{@link #treeChanged(TreeChangeEvent event)}
- * </ul>
- */
-public abstract class TreePropertyValueModelAdapter<T>
- extends AbstractPropertyValueModelAdapter<T>
-{
- /** The wrapped tree value model. */
- protected final TreeValueModel<?> treeHolder;
-
- /** A listener that allows us to synch with changes to the wrapped tree holder. */
- protected final TreeChangeListener treeChangeListener;
-
-
- // ********** constructor/initialization **********
-
- /**
- * Construct a property value model with the specified wrapped
- * tree value model.
- */
- protected TreePropertyValueModelAdapter(TreeValueModel<?> treeHolder) {
- super();
- this.treeHolder = treeHolder;
- this.treeChangeListener = this.buildTreeChangeListener();
- }
-
- protected TreeChangeListener buildTreeChangeListener() {
- return new TreeChangeListener() {
- public void nodeAdded(TreeAddEvent event) {
- TreePropertyValueModelAdapter.this.nodeAdded(event);
- }
- public void nodeRemoved(TreeRemoveEvent event) {
- TreePropertyValueModelAdapter.this.nodeRemoved(event);
- }
- public void treeCleared(TreeClearEvent event) {
- TreePropertyValueModelAdapter.this.treeCleared(event);
- }
- public void treeChanged(TreeChangeEvent event) {
- TreePropertyValueModelAdapter.this.treeChanged(event);
- }
- @Override
- public String toString() {
- return "tree change listener"; //$NON-NLS-1$
- }
- };
- }
-
-
- // ********** behavior **********
-
- /**
- * Start listening to the tree holder.
- */
- @Override
- protected void engageModel_() {
- this.treeHolder.addTreeChangeListener(TreeValueModel.NODES, this.treeChangeListener);
- }
-
- /**
- * Stop listening to the tree holder.
- */
- @Override
- protected void disengageModel_() {
- this.treeHolder.removeTreeChangeListener(TreeValueModel.NODES, this.treeChangeListener);
- }
-
- @Override
- public void toString(StringBuilder sb) {
- sb.append(this.treeHolder);
- }
-
-
- // ********** state change support **********
-
- /**
- * Nodes were added to the wrapped tree holder;
- * propagate the change notification appropriately.
- */
- protected void nodeAdded(@SuppressWarnings("unused") TreeAddEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * Nodes were removed from the wrapped tree holder;
- * propagate the change notification appropriately.
- */
- protected void nodeRemoved(@SuppressWarnings("unused") TreeRemoveEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * The wrapped tree holder was cleared;
- * propagate the change notification appropriately.
- */
- protected void treeCleared(@SuppressWarnings("unused") TreeClearEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
- /**
- * The wrapped tree holder changed;
- * propagate the change notification appropriately.
- */
- protected void treeChanged(@SuppressWarnings("unused") TreeChangeEvent event) {
- // by default, simply recalculate the value and fire an event
- this.propertyChanged();
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueAspectAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueAspectAdapter.java
index 5876d5e444..98a3429569 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueAspectAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueAspectAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,17 +16,18 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
* Abstract class that provides support for wrapping a {@link WritablePropertyValueModel}
- * and listening for changes to <em>aspects</em> of the <em>value</em> contained
- * by the {@link WritablePropertyValueModel}. Changes to the {@link WritablePropertyValueModel}'s
- * value are also monitored.
+ * and listening for changes to <em>aspects</em> of the <em>value</em> held
+ * by the {@link WritablePropertyValueModel}. Changes to the
+ * {@link WritablePropertyValueModel}'s value are also monitored.
* <p>
* This is useful if you have a value that may change, but whose aspects can also
* change in a fashion that might be of interest to the client.
* <p>
- * <strong>NB:</strong> Clients will need to listen for two different change notifications:
- * a property change event will be be fired when the <em>value</em> changes;
- * a state change event will be fired when an <em>aspect</em> of the value changes.
- * <p>
+ * <strong>NB:</strong> Clients will need to listen for two different change
+ * notifications:<ul>
+ * <li>a property change event will be be fired when the <em>value</em> changes;
+ * <li>a state change event will be fired when an <em>aspect</em> of the value changes.
+ * </ul>
* Subclasses need to override two methods:<ul>
* <li>{@link #engageValue_()}<p>
* begin listening to the appropriate aspect of the value and call
@@ -40,17 +41,17 @@ public abstract class ValueAspectAdapter<V>
extends PropertyValueModelWrapper<V>
implements WritablePropertyValueModel<V>
{
- /** Cache the value so we can disengage. Null until we have a listener*/
- protected V value;
+ /** Cache the value so we can disengage. */
+ protected volatile V value;
// ********** constructors/initialization **********
/**
- * Constructor - the value holder is required.
+ * Constructor - the value model is required.
*/
- protected ValueAspectAdapter(WritablePropertyValueModel<V> valueHolder) {
- super(valueHolder);
+ protected ValueAspectAdapter(WritablePropertyValueModel<V> valueModel) {
+ super(valueModel);
this.value = null;
}
@@ -73,21 +74,21 @@ public abstract class ValueAspectAdapter<V>
// ********** WritablePropertyValueModel implementation **********
public void setValue(V value) {
- this.getValueHolder().setValue(value);
+ this.getValueModel().setValue(value);
}
// ********** PropertyValueModelWrapper implementation **********
@Override
- protected void valueChanged(PropertyChangeEvent event) {
+ protected void wrappedValueChanged(PropertyChangeEvent event) {
this.disengageValue();
this.engageValue();
this.firePropertyChanged(event.clone(this));
}
- // ********** extend change support **********
+ // ********** listeners **********
/**
* Extend to start listening to the underlying model if necessary.
@@ -111,9 +112,6 @@ public abstract class ValueAspectAdapter<V>
}
}
-
- // ********** AbstractPropertyValueModel overrides **********
-
/**
* Extend to check for state change listeners.
*/
@@ -122,9 +120,6 @@ public abstract class ValueAspectAdapter<V>
return this.hasAnyStateChangeListeners() || super.hasListeners();
}
-
- // ********** PropertyValueModelWrapper overrides **********
-
/**
* Extend to engage an aspect of the value model's value.
*/
@@ -150,7 +145,7 @@ public abstract class ValueAspectAdapter<V>
* Start listening to an aspect of the current value.
*/
protected void engageValue() {
- this.value = this.valueHolder.getValue();
+ this.value = this.valueModel.getValue();
if (this.value != null) {
this.engageValue_();
}
@@ -158,7 +153,7 @@ public abstract class ValueAspectAdapter<V>
/**
* Start listening to some aspect of the current value.
- * At this point we can be sure the value is not null.
+ * At this point we can be sure the value is not <code>null</code>.
*/
protected abstract void engageValue_();
@@ -174,7 +169,7 @@ public abstract class ValueAspectAdapter<V>
/**
* Stop listening to an aspect of the current value.
- * At this point we can be sure the value is not null.
+ * At this point we can be sure the value is not <code>null</code>.
*/
protected abstract void disengageValue_();
@@ -189,13 +184,12 @@ public abstract class ValueAspectAdapter<V>
* Our constructor accepts only a {@link WritablePropertyValueModel}{@code<V>}.
*/
@SuppressWarnings("unchecked")
- protected WritablePropertyValueModel<V> getValueHolder() {
- return (WritablePropertyValueModel<V>) this.valueHolder;
+ protected WritablePropertyValueModel<V> getValueModel() {
+ return (WritablePropertyValueModel<V>) this.valueModel;
}
@Override
public void toString(StringBuilder sb) {
sb.append(this.getValue());
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueChangeAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueChangeAdapter.java
index 36dca8e8dd..7340d284cc 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueChangeAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ValueChangeAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.common.utility.internal.model.value;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.event.ChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.listener.SimpleChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.AbstractChangeListener;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
@@ -40,16 +40,16 @@ public class ValueChangeAdapter<V extends Model>
// ********** initialization **********
protected ChangeListener buildValueAspectListener() {
- return new SimpleChangeListener() {
- @Override
- protected void modelChanged(ChangeEvent event) {
- ValueChangeAdapter.this.valueAspectChanged(event);
- }
- @Override
- public String toString() {
- return "value change listener"; //$NON-NLS-1$
- }
- };
+ return new ValueAspectListener();
+ }
+
+ protected class ValueAspectListener
+ extends AbstractChangeListener
+ {
+ @Override
+ protected void modelChanged(ChangeEvent event) {
+ ValueChangeAdapter.this.valueAspectChanged(event);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java
index 2b6670abe4..867f848382 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -44,7 +44,7 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
* rely on that event to keep our internally cached value in synch.
*/
public class PreferencePropertyValueModel<P>
- extends AspectAdapter<Preferences>
+ extends AspectAdapter<Preferences, P>
implements WritablePropertyValueModel<P>
{
/** The key to the preference we use for the value. */
@@ -179,7 +179,6 @@ public class PreferencePropertyValueModel<P>
/**
* Return the cached (converted) value.
*/
- @Override
public synchronized P getValue() {
return this.value;
}
@@ -208,6 +207,11 @@ public class PreferencePropertyValueModel<P>
// ********** AspectAdapter implementation **********
@Override
+ protected synchronized P getAspectValue() {
+ return this.value;
+ }
+
+ @Override
protected Class<? extends EventListener> getListenerClass() {
return PropertyChangeListener.class;
}
@@ -342,5 +346,4 @@ public class PreferencePropertyValueModel<P>
this.value = this.buildValue();
this.fireAspectChanged(old, this.value);
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java
index f12a84f138..e37b2666ca 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -32,7 +32,7 @@ import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
* "preference" changes and converts them into VALUE collection changes.
*/
public class PreferencesCollectionValueModel<P>
- extends AspectAdapter<Preferences>
+ extends AspectAdapter<Preferences, Object>
implements CollectionValueModel<PreferencePropertyValueModel<P>>
{
@@ -98,7 +98,7 @@ public class PreferencesCollectionValueModel<P>
// ********** AspectAdapter implementation **********
@Override
- protected Object getValue() {
+ protected Object getAspectValue() {
return this.iterator();
}
@@ -199,5 +199,4 @@ public class PreferencesCollectionValueModel<P>
// a preference's value changed - do nothing
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/RadioButtonModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/RadioButtonModelAdapter.java
index 83d3113454..25d50cd1a9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/RadioButtonModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/swing/RadioButtonModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,27 +9,28 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.model.value.swing;
-import org.eclipse.jpt.common.utility.internal.BidiFilter;
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
+import org.eclipse.jpt.common.utility.Filter;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.model.value.FilteringWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
/**
- * This javax.swing.ButtonModel can be used to keep a listener
- * (e.g. a JRadioButton) in synch with a (typically shared)
- * PropertyValueModel that holds one value out of a set of values.
- *
- * NOTE: Do *not* use this model with a ButtonGroup, since the
+ * This {@link javax.swing.ButtonModel} can be used to keep a listener
+ * (e.g. a {@link javax.swing.JRadioButton}) in synch with a (typically shared)
+ * {@link org.eclipse.jpt.common.utility.model.value.PropertyValueModel}
+ * that holds one value out of a set of values.
+ * <p>
+ * <strong>NB:</strong> Do <em>not</em> use this model with a
+ * {@link javax.swing.ButtonGroup}, since the
* shared value holder and the wrappers built by this adapter will
* keep the appropriate radio button checked. Also, this allows
* us to uncheck all the radio buttons in a group when the shared
- * value is null.
+ * value is <code>null</code>.
*/
public class RadioButtonModelAdapter
extends ToggleButtonModelAdapter
{
-
// ********** constructors **********
/**
@@ -60,8 +61,8 @@ public class RadioButtonModelAdapter
* value to the button value.
*/
public static WritablePropertyValueModel<Boolean> buildBooleanHolder(WritablePropertyValueModel<Object> valueHolder, Object buttonValue) {
- WritablePropertyValueModel<Object> filteringPVM = new FilteringWritablePropertyValueModel<Object>(valueHolder, new RadioButtonFilter(buttonValue));
- return new TransformationWritablePropertyValueModel<Object, Boolean>(filteringPVM, new RadioButtonTransformer(buttonValue));
+ WritablePropertyValueModel<Object> filteringPVM = new FilteringWritablePropertyValueModel<Object>(valueHolder, Filter.Transparent.instance(), new SetRadioButtonFilter(buttonValue));
+ return new TransformationWritablePropertyValueModel<Object, Boolean>(filteringPVM, new RadioButtonTransformer(buttonValue), new ReverseRadioButtonTransformer(buttonValue));
}
@@ -85,42 +86,41 @@ public class RadioButtonModelAdapter
}
- // ********** inner classes **********
+ // ********** filters **********
/**
* This filter will only pass through a new value to the wrapped
- * value holder when it matches the configured button value.
+ * value model when it matches the configured button value.
*/
- public static class RadioButtonFilter implements BidiFilter<Object> {
+ public static class SetRadioButtonFilter
+ implements Filter<Object>
+ {
private Object buttonValue;
- public RadioButtonFilter(Object buttonValue) {
+ public SetRadioButtonFilter(Object buttonValue) {
super();
this.buttonValue = buttonValue;
}
/**
- * always return the wrapped value
- */
- public boolean accept(Object value) {
- return true;
- }
-
- /**
* pass through the value to the wrapped property value model
* *only* when it matches our button value
*/
- public boolean reverseAccept(Object value) {
+ public boolean accept(Object value) {
return (value != null) && value.equals(this.buttonValue);
}
-
}
+
+ // ********** transformers **********
+
/**
- * This transformer will convert the wrapped value to Boolean.TRUE
+ * This transformer will convert a value to {@link Boolean#TRUE}
* when it matches the configured button value.
*/
- public static class RadioButtonTransformer implements BidiTransformer<Object, Boolean> {
+ public static class RadioButtonTransformer
+ implements Transformer<Object, Boolean>
+ {
private Object buttonValue;
public RadioButtonTransformer(Object buttonValue) {
@@ -129,23 +129,37 @@ public class RadioButtonModelAdapter
}
/**
- * if the wrapped value matches our button value return true,
- * if it is some other value return false;
- * but if it is null simply pass it through because it will cause the
- * button model's default value to be used
+ * If the specified value matches the button value return {@link Boolean#TRUE},
+ * if it is some other value return {@link Boolean#FALSE};
+ * but if it is <code>null</code> simply pass it through because it will
+ * cause the button model's default value to be used
*/
public Boolean transform(Object value) {
return (value == null) ? null : Boolean.valueOf(value.equals(this.buttonValue));
}
+ }
+
+ /**
+ * This transformer will convert {@link Boolean#TRUE} to the configured
+ * button value and {@link Boolean#FALSE} to <code>null</code>.
+ */
+ public static class ReverseRadioButtonTransformer
+ implements Transformer<Boolean, Object>
+ {
+ private Object buttonValue;
+
+ public ReverseRadioButtonTransformer(Object buttonValue) {
+ super();
+ this.buttonValue = buttonValue;
+ }
/**
- * if the new value is true, pass through the our button value;
- * otherwise pass through null
+ * If the specified value is {@link Boolean#TRUE},
+ * pass through the our button value;
+ * otherwise pass through <code>null</code>.
*/
- public Object reverseTransform(Boolean value) {
+ public Object transform (Boolean value) {
return (value.booleanValue()) ? this.buttonValue : null;
}
-
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/node/AbstractNode.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/node/AbstractNode.java
index 3f32a57bfd..449642da78 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/node/AbstractNode.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/node/AbstractNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -778,7 +778,7 @@ public abstract class AbstractNode
* Rebuild the "branch" problems and return whether they have
* changed.
* NB: The entire collection of "branch" problems must be re-calculated
- * with EVERY "significant" change - we cannot keep it in synch via
+ * with EVERY "significant" change - we cannot keep it in sync via
* change notifications because if a descendant with problems is
* removed or replaced we will not receive notification that its
* problems were removed from our "branch" problems.
@@ -937,5 +937,4 @@ public abstract class AbstractNode
public final String toString() {
return super.toString();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/AsynchronousSynchronizer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/AsynchronousSynchronizer.java
deleted file mode 100644
index da4a234623..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/AsynchronousSynchronizer.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.synchronizers;
-
-import java.util.concurrent.ThreadFactory;
-
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
-import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
-
-/**
- * This synchronizer will perform synchronizations in a separate thread,
- * allowing calls to {@link Synchronizer#synchronize()} to return immediately.
- * <p>
- * <strong>NB:</strong> The client-supplied command should handle any exceptions
- * appropriately (e.g. log the exception and return gracefully so the thread
- * can continue the synchronization process).
- */
-public class AsynchronousSynchronizer
- implements Synchronizer
-{
- /**
- * This flag is shared with the synchronization/consumer thread. Setting it to true
- * will trigger the synchronization to begin or, if the synchronization is
- * currently executing, to execute again, once the current execution is
- * complete.
- */
- final SynchronizedBoolean synchronizeFlag = new SynchronizedBoolean(false);
-
- /**
- * Most of the thread-related behavior is delegated to this coordinator.
- */
- private final ConsumerThreadCoordinator consumerThreadCoordinator;
-
-
- // ********** construction **********
-
- /**
- * Construct an asynchronous synchronizer that uses the specified command to
- * perform the synchronization.
- * Use simple JDK thread(s) for the synchronization thread(s).
- * Allow the synchronization thread(s) to be assigned
- * JDK-generated names.
- */
- public AsynchronousSynchronizer(Command command) {
- this(command, null, null);
- }
-
- /**
- * Construct an asynchronous synchronizer that uses the specified command to
- * perform the synchronization.
- * Use the specified thread factory to construct the synchronization thread(s).
- * Allow the synchronization thread(s) to be assigned
- * JDK-generated names.
- */
- public AsynchronousSynchronizer(Command command, ThreadFactory threadFactory) {
- this(command, threadFactory, null);
- }
-
- /**
- * Construct an asynchronous synchronizer that uses the specified command to
- * perform the synchronization. Assign the synchronization thread(s) the specified
- * name.
- * Use simple JDK thread(s) for the synchronization thread(s).
- */
- public AsynchronousSynchronizer(Command command, String threadName) {
- this(command, null, threadName);
- }
-
- /**
- * Construct an asynchronous synchronizer that uses the specified command to
- * perform the synchronization.
- * Use the specified thread factory to construct the synchronization thread(s).
- * Assign the synchronization thread(s) the specified
- * name.
- */
- public AsynchronousSynchronizer(Command command, ThreadFactory threadFactory, String threadName) {
- super();
- if (command == null) {
- throw new NullPointerException();
- }
- this.consumerThreadCoordinator = new ConsumerThreadCoordinator(this.buildConsumer(command), threadFactory, threadName);
- }
-
- ConsumerThreadCoordinator.Consumer buildConsumer(Command command) {
- return new Consumer(command);
- }
-
-
- // ********** Synchronizer implementation **********
-
- /**
- * Build and start the synchronization thread, but postpone the first
- * synchronization until requested, i.e. via a call to
- * {@link #synchronize()}.
- * <p>
- * Note: We don't clear the "synchronize" flag here; so if the flag has
- * been set <em>before</em> getting here, the first synchronization will
- * start promptly (albeit, asynchronously).
- * The "synchronize" flag will be set if:<ul>
- * <li>{@link #synchronize()} was called after the synchronizer was
- * constructed but before {@link #start()} was called; or
- * <li>{@link #synchronize()} was called after {@link #stop()} was called
- * but before {@link #start()} was called (to restart the synchronizer); or
- * <li>{@link #stop()} was called when there was an outstanding request
- * for a synchronization (i.e. the "synchronization" flag was set at
- * the time {@link #stop()} was called)
- * </ul>
- */
- public void start() {
- this.consumerThreadCoordinator.start();
- }
-
- /**
- * Set the "synchronize" flag so the synchronization thread will either<ul>
- * <li>if the thread is quiesced, start a synchronization immediately, or
- * <li>if the thread is currently executing a synchronization, execute another
- * synchronization once the current synchronization is complete
- * </ul>
- */
- public void synchronize() {
- this.synchronizeFlag.setTrue();
- }
-
- /**
- * Interrupt the synchronization thread so that it stops executing at the
- * end of the current synchronization. Suspend the current thread until
- * the synchronization thread is finished executing. If any uncaught
- * exceptions were thrown while the synchronization thread was executing,
- * wrap them in a composite exception and throw the composite exception.
- */
- public void stop() {
- this.consumerThreadCoordinator.stop();
- }
-
-
- // ********** consumer **********
-
- /**
- * This implementation of {@link ConsumerThreadCoordinator.Consumer}
- * will execute the client-supplied "synchronize" command.
- * It will wait until the shared "synchronize" flag is set to execute the
- * command. Once the comand is executed, the thread will quiesce until
- * the flag is set again. If the flag was set during the execution of the
- * command (either recursively by the command itself or by another thread),
- * the command will be re-executed immediately. Stop the thread by calling
- * {@link Thread#interrupt()}.
- */
- class Consumer
- implements ConsumerThreadCoordinator.Consumer
- {
- /**
- * The client-supplied command that executes on the
- * synchronization/consumer thread.
- */
- private final Command command;
-
- Consumer(Command command) {
- super();
- this.command = command;
- }
-
- /**
- * Wait until the "synchronize" flag is set,
- * then clear it and allow the "synchronize" command to execute.
- */
- public void waitForProducer() throws InterruptedException {
- AsynchronousSynchronizer.this.synchronizeFlag.waitToSetFalse();
- }
-
- /**
- * Execute the client-supplied command.
- */
- public void execute() {
- this.command.execute();
- }
-
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackAsynchronousSynchronizer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackAsynchronousSynchronizer.java
deleted file mode 100644
index 06af819213..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackAsynchronousSynchronizer.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.synchronizers;
-
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
-import org.eclipse.jpt.common.utility.internal.ListenerList;
-import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
-
-/**
- * Extend the asynchronous synchronizer to notify listeners
- * when a synchronization "cycle" is complete; i.e. the synchronization has,
- * for the moment, handled every outstanding "synchronize" request and quiesced.
- * This notification is <em>not</em> guaranteed to occur with <em>every</em>
- * synchronization "cycle"; since other, unrelated, synchronizations can be
- * triggered concurrently.
- * <p>
- * <strong>NB:</strong> Listeners should handle any exceptions
- * appropriately (e.g. log the exception and return gracefully so the thread
- * can continue the synchronization process).
- */
-public class CallbackAsynchronousSynchronizer
- extends AsynchronousSynchronizer
- implements CallbackSynchronizer
-{
- private final ListenerList<Listener> listenerList = new ListenerList<Listener>(Listener.class);
-
-
- // ********** construction **********
-
- /**
- * Construct a callback asynchronous synchronizer that uses the specified
- * command to perform the synchronization. Allow the synchronization thread(s)
- * to be assigned JDK-generated names.
- */
- public CallbackAsynchronousSynchronizer(Command command) {
- super(command);
- }
-
- /**
- * Construct a callback asynchronous synchronizer that uses the specified
- * command to perform the synchronization. Assign the synchronization thread(s)
- * the specified name.
- */
- public CallbackAsynchronousSynchronizer(Command command, String threadName) {
- super(command, threadName);
- }
-
- /**
- * Build a consumer that will let us know when the synchronization has
- * quiesced.
- */
- @Override
- ConsumerThreadCoordinator.Consumer buildConsumer(Command command) {
- return new CallbackConsumer(command);
- }
-
-
- // ********** CallbackSynchronizer implementation **********
-
- public void addListener(Listener listener) {
- this.listenerList.add(listener);
- }
-
- public void removeListener(Listener listener) {
- this.listenerList.remove(listener);
- }
-
- /**
- * Notify our listeners.
- */
- void synchronizationQuiesced() {
- for (Listener listener : this.listenerList.getListeners()) {
- listener.synchronizationQuiesced(this);
- }
- }
-
-
- // ********** synchronization thread runnable **********
-
- /**
- * Extend {@link AsynchronousSynchronizer.Consumer}
- * to notify the synchronizer when the synchronization has quiesced
- * (i.e. the command has finished executing and there are no further
- * requests for synchronization).
- * Because synchronization is asynchronous, no other thread will be able to
- * initiate another synchronization until the synchronizer's listeners have been
- * notified. Note also, the synchronizer's listeners can, themselves,
- * trigger another synchronization (by directly or indirectly calling
- * {@link org.eclipse.jpt.common.utility.synchronizers.Synchronizer#synchronize()});
- * but this synchronization will not occur until <em>after</em> all the
- * listeners have been notified.
- */
- class CallbackConsumer
- extends Consumer
- {
- CallbackConsumer(Command command) {
- super(command);
- }
-
- @Override
- public void execute() {
- super.execute();
- // hmmm - we will notify listeners even when we our thread is "interrupted";
- // that seems ok... ~bjv
- if (CallbackAsynchronousSynchronizer.this.synchronizeFlag.isFalse()) {
- CallbackAsynchronousSynchronizer.this.synchronizationQuiesced();
- }
- }
-
- }
-
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackSynchronousSynchronizer.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackSynchronousSynchronizer.java
index d811067b8b..c377403a93 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackSynchronousSynchronizer.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/synchronizers/CallbackSynchronousSynchronizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.synchronizers;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.ListenerList;
import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
@@ -79,5 +79,4 @@ public class CallbackSynchronousSynchronizer
this.synchronizationQuiesced();
}
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/SimpleChangeListener.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/AbstractChangeListener.java
index cc82b775bf..45ff18ecc2 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/SimpleChangeListener.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/AbstractChangeListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.listener;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.ChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
@@ -41,10 +42,10 @@ import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public abstract class SimpleChangeListener
+public abstract class AbstractChangeListener
implements ChangeListener
{
- public SimpleChangeListener() {
+ public AbstractChangeListener() {
super();
}
@@ -128,4 +129,8 @@ public abstract class SimpleChangeListener
throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ChangeAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ChangeAdapter.java
index 51dcbd0391..1567b90b9c 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ChangeAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ChangeAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.listener;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
@@ -35,7 +36,12 @@ import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public class ChangeAdapter implements ChangeListener {
+public class ChangeAdapter
+ implements ChangeListener
+{
+ public ChangeAdapter() {
+ super();
+ }
// ***** state
public void stateChanged(StateChangeEvent event) {
@@ -106,4 +112,8 @@ public class ChangeAdapter implements ChangeListener {
// do nothing
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CollectionChangeAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CollectionChangeAdapter.java
index 99ca881f23..516f5551ab 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CollectionChangeAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CollectionChangeAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.listener;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
@@ -23,11 +24,9 @@ import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public class CollectionChangeAdapter implements CollectionChangeListener {
-
- /**
- * Default constructor.
- */
+public class CollectionChangeAdapter
+ implements CollectionChangeListener
+{
public CollectionChangeAdapter() {
super();
}
@@ -48,4 +47,8 @@ public class CollectionChangeAdapter implements CollectionChangeListener {
// do nothing
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CommandChangeListener.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CommandChangeListener.java
index 5b3fd4a76f..8d601eb571 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CommandChangeListener.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/CommandChangeListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.listener;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
/**
* Convenience implementation of {@link ChangeListener}.
@@ -22,7 +22,7 @@ import org.eclipse.jpt.common.utility.Command;
* will almost certainly be broken (repeatedly) as the API evolves.
*/
public class CommandChangeListener
- extends SimpleChangeListener
+ extends AbstractChangeListener
{
protected final Command command;
@@ -40,5 +40,4 @@ public class CommandChangeListener
protected void modelChanged() {
this.command.execute();
}
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ListChangeAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ListChangeAdapter.java
index a2b85b47f7..bff54138bf 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ListChangeAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/ListChangeAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.listener;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
@@ -25,11 +26,9 @@ import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public class ListChangeAdapter implements ListChangeListener {
-
- /**
- * Default constructor.
- */
+public class ListChangeAdapter
+ implements ListChangeListener
+{
public ListChangeAdapter() {
super();
}
@@ -58,4 +57,8 @@ public class ListChangeAdapter implements ListChangeListener {
// do nothing
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/PropertyChangeAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/PropertyChangeAdapter.java
index c492353133..01f54eab3f 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/PropertyChangeAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/listener/PropertyChangeAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,12 +9,14 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.model.listener;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
/**
* Convenience implementation of {@link PropertyChangeListener}.
* This is probably of limited use, since there only a single method to implement;
- * maybe as a null implementation.
+ * maybe it is useful as a null implementation. One minor benefit is the
+ * implementation of {@link #toString()}.
* <p>
* Provisional API: This class is part of an interim API that is still
* under development and expected to change significantly before reaching
@@ -22,10 +24,19 @@ import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public class PropertyChangeAdapter implements PropertyChangeListener {
+public class PropertyChangeAdapter
+ implements PropertyChangeListener
+{
+ public PropertyChangeAdapter() {
+ super();
+ }
public void propertyChanged(PropertyChangeEvent event) {
// do nothing
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java
index 180be43f1d..c098c884de 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/PropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,16 +21,14 @@ import org.eclipse.jpt.common.utility.model.Model;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @param <T> the type of value held by the model
+ * @param <V> the type of value held by the model
*/
-public interface PropertyValueModel<T>
+public interface PropertyValueModel<V>
extends Model
{
-
/**
- * Return the property's value.
+ * Return the model's value.
*/
- T getValue();
+ V getValue();
String VALUE = "value"; //$NON-NLS-1$
-
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/WritablePropertyValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/WritablePropertyValueModel.java
index fe35c351f2..0592ea3688 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/WritablePropertyValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/model/value/WritablePropertyValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,16 +18,14 @@ package org.eclipse.jpt.common.utility.model.value;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @param <T> the type of value held by the model
+ * @param <V> the type of value held by the model
*/
-public interface WritablePropertyValueModel<T>
- extends PropertyValueModel<T>
+public interface WritablePropertyValueModel<V>
+ extends PropertyValueModel<V>
{
-
/**
* Set the value and fire a property change notification.
* @see PropertyValueModel#VALUE
*/
- void setValue(T value);
-
+ void setValue(V value);
}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
index 4c3bd461f3..6f952c5ff5 100644
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -32,7 +32,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilat
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.BitTools;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java
index 223b8e64cd..e390adfc97 100644
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,23 +23,20 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.ItemTreeStateProviderManager;
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.TreeStateProvider;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.NullCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.swt.SWT;
@@ -104,8 +101,8 @@ public class DelegatingLabelProviderUiTest extends ApplicationWindow
tree = new TreeViewer(panel, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
tree.getTree().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
- DelegatingContentAndLabelProvider contentAndLabelProvider =
- new DelegatingTreeContentAndLabelProvider(
+ TreeStateProvider contentAndLabelProvider =
+ new ItemTreeStateProviderManager(
new VehicleContentProviderFactory(),
new VehicleLabelProviderFactory());
tree.setContentProvider(contentAndLabelProvider);
@@ -305,103 +302,69 @@ public class DelegatingLabelProviderUiTest extends ApplicationWindow
private static class VehicleContentProviderFactory
- implements TreeItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
{
- public TreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
if (item instanceof Root) {
- return new RootContentProvider(
- (Root) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider);
+ return this.buildRootProvider((Root) item);
}
- return new VehicleContentProvider(
- (Vehicle) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider);
+ return this.buildVehicleProvider((Vehicle) item);
}
- }
-
-
- private static class RootContentProvider extends AbstractTreeItemContentProvider<Vehicle>
- {
- public RootContentProvider(Root item, DelegatingTreeContentAndLabelProvider contentAndLabelProvider) {
- super(item, contentAndLabelProvider);
- }
-
- @Override
- public Root getModel() {
- return (Root) super.getModel();
- }
-
- @Override
- public Object getParent() {
- return null;
- }
-
- @Override
- protected CollectionValueModel<Vehicle> buildChildrenModel() {
- return new StaticCollectionValueModel<Vehicle>(this.getModel().vehicles());
+ protected ItemTreeContentProvider buildRootProvider(Root item) {
+ return new StaticItemTreeContentProvider(null, item.vehicles());
}
- }
-
- @SuppressWarnings("unchecked")
- private static class VehicleContentProvider extends AbstractTreeItemContentProvider
- {
- public VehicleContentProvider(Vehicle item, DelegatingTreeContentAndLabelProvider contentAndLabelProvider) {
- super(item, contentAndLabelProvider);
- }
-
- @Override
- public Vehicle getModel() {
- return (Vehicle) super.getModel();
- }
-
- @Override
- public Object getParent() {
- return getModel().parent();
- }
-
- @Override
- protected CollectionValueModel buildChildrenModel() {
- return new NullCollectionValueModel();
+ protected ItemTreeContentProvider buildVehicleProvider(Vehicle item) {
+ return new StaticItemTreeContentProvider(item.parent());
}
}
private static class VehicleLabelProviderFactory
- implements ItemLabelProviderFactory
+ implements ItemExtendedLabelProviderFactory
{
- public ItemLabelProvider buildItemLabelProvider(Object element, DelegatingContentAndLabelProvider labelProvider) {
- return new VehicleLabelProvider((Vehicle) element, labelProvider);
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ return new VehicleLabelProvider((Vehicle) item, manager);
}
}
- private static class VehicleLabelProvider extends AbstractItemLabelProvider
+ private static class VehicleLabelProvider
+ extends AbstractItemExtendedLabelProvider<Vehicle>
{
- public VehicleLabelProvider(Vehicle vehicle, DelegatingContentAndLabelProvider labelProvider) {
- super(vehicle, labelProvider);
+ public VehicleLabelProvider(Vehicle vehicle, ItemLabelProvider.Manager manager) {
+ super(vehicle, manager);
}
@Override
protected PropertyValueModel<Image> buildImageModel() {
- return new PropertyAspectAdapter<Vehicle, Image>(
- new StaticPropertyValueModel<Vehicle>((Vehicle) getModel()),
- Vehicle.COLOR_PROPERTY, Vehicle.GREYED_PROPERTY, Vehicle.TRANSLUCENT_PROPERTY) {
+ return new PropertyAspectAdapter<Vehicle, Image>(IMAGE_ASPECT_NAMES, this.item) {
@Override
protected Image buildValue_() {
return subject.image();
}
};
}
+ private static final String[] IMAGE_ASPECT_NAMES =
+ new String[] {
+ Vehicle.COLOR_PROPERTY,
+ Vehicle.GREYED_PROPERTY,
+ Vehicle.TRANSLUCENT_PROPERTY
+ };
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<Vehicle, String>(
- new StaticPropertyValueModel<Vehicle>((Vehicle) getModel()),
- Vehicle.VEHICLE_TYPE_PROPERTY, Vehicle.COLOR_PROPERTY) {
+ return new PropertyAspectAdapter<Vehicle, String>(TEXT_ASPECT_NAMES, this.item) {
@Override
protected String buildValue_() {
return subject.color().description() + ' ' + subject.vehicleType().description();
}
};
}
+ private static final String[] TEXT_ASPECT_NAMES =
+ new String[] {
+ Vehicle.VEHICLE_TYPE_PROPERTY,
+ Vehicle.COLOR_PROPERTY
+ };
@Override
protected PropertyValueModel<String> buildDescriptionModel() {
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java
index 00af4be8e7..dae068f2d6 100644
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -26,11 +26,10 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.internal.jface.ItemTreeStateProviderManager;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.NotNullFilter;
import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator;
@@ -111,7 +110,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
private void buildControlTreePanel(Composite parent) {
controlTree = buildTreePanel(
parent, "Control tree",
- new DelegatingTreeContentAndLabelProvider(new ControlTreeItemContentProviderFactory()),
+ new ItemTreeStateProviderManager(new ControlTreeItemContentProviderFactory()),
new LabelProvider());
controlTree.addSelectionChangedListener(buildTreeSelectionChangedListener());
selectedNode.addPropertyChangeListener(
@@ -127,7 +126,7 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
private void buildViewTreePanel(Composite parent) {
viewTree = buildTreePanel(
parent, "View tree",
- new DelegatingTreeContentAndLabelProvider(new ViewTreeItemContentProviderFactory()),
+ new ItemTreeStateProviderManager(new ViewItemTreeContentProviderFactory()),
new LabelProvider());
}
@@ -287,70 +286,62 @@ public class DelegatingTreeContentProviderUiTest extends ApplicationWindow
static abstract class AbstractTreeItemContentProviderFactory
- implements TreeItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
{
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- return new GenericTreeItemContentProvider(
- (TreeNode) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider);
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ return new GenericItemTreeContentProvider((TreeNode) item, manager);
}
}
- static class ControlTreeItemContentProviderFactory extends AbstractTreeItemContentProviderFactory
+ static class ControlTreeItemContentProviderFactory
+ extends AbstractTreeItemContentProviderFactory
{
-
+ // nothing
}
- static class ViewTreeItemContentProviderFactory
+ static class ViewItemTreeContentProviderFactory
extends AbstractTreeItemContentProviderFactory
{
@Override
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
if (item instanceof Parent) {
- return new ViewTreeParentItemContentProvider(
- (Parent) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider);
+ return new ViewParentItemTreeContentProvider((Parent) item, manager);
}
- return super.buildItemContentProvider(item, contentAndLabelProvider);
+ return super.buildProvider(item, manager);
}
}
- static class GenericTreeItemContentProvider extends AbstractTreeItemContentProvider<TreeNode>
+ static class GenericItemTreeContentProvider
+ extends AbstractItemTreeContentProvider<TreeNode, TreeNode>
{
- public GenericTreeItemContentProvider(
- TreeNode treeNode, DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider) {
- super(treeNode, treeContentAndLabelProvider);
+ public GenericItemTreeContentProvider(TreeNode treeNode, ItemTreeContentProvider.Manager manager) {
+ super(treeNode, manager);
}
- protected TreeNode treeNode() {
- return (TreeNode) getModel();
- }
-
- @Override
public TreeNode getParent() {
- return treeNode().parent();
+ return this.item.parent();
}
@Override
protected CollectionValueModel<TreeNode> buildChildrenModel() {
return new ListCollectionValueModelAdapter<TreeNode>(
- new ListAspectAdapter<TreeNode, TreeNode>(TreeNode.CHILDREN_LIST, treeNode()) {
+ new ListAspectAdapter<TreeNode, TreeNode>(TreeNode.CHILDREN_LIST, this.item) {
@Override
protected ListIterator<TreeNode> listIterator_() {
- return treeNode().children();
+ return this.subject.children();
}
});
}
}
- static class ViewTreeParentItemContentProvider extends GenericTreeItemContentProvider
+ static class ViewParentItemTreeContentProvider
+ extends GenericItemTreeContentProvider
{
- public ViewTreeParentItemContentProvider(
- TreeNode treeNode, DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider) {
- super(treeNode, treeContentAndLabelProvider);
+ public ViewParentItemTreeContentProvider(TreeNode treeNode, ItemTreeContentProvider.Manager manager) {
+ super(treeNode, manager);
}
@Override
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF b/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF
index eeb203128b..2e830623fa 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
org.junit;bundle-version="3.8.0"
Export-Package: org.eclipse.jpt.common.utility.tests.internal;x-internal:=true,
+ org.eclipse.jpt.common.utility.tests.internal.command;x-internal:=true,
org.eclipse.jpt.common.utility.tests.internal.enumerations;x-internal:=true,
org.eclipse.jpt.common.utility.tests.internal.iterables;x-internal:=true,
org.eclipse.jpt.common.utility.tests.internal.iterators;x-internal:=true,
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java
index 23097f3ab5..90f9977935 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ExceptionHandlerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,7 +11,7 @@ package org.eclipse.jpt.common.utility.tests.internal;
import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.internal.ExceptionHandler;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
public class ExceptionHandlerTests extends TestCase {
@@ -29,8 +29,8 @@ public class ExceptionHandlerTests extends TestCase {
assertNotNull(exceptionHandler.toString());
}
- public void testRuntimeExceptionHandler() {
- Exception npe = new NullPointerException();
+ public void testRuntimeExceptionHandler1() {
+ Exception npe = new Exception();
ExceptionHandler exceptionHandler = ExceptionHandler.Runtime.instance();
boolean exCaught = false;
try {
@@ -43,6 +43,20 @@ public class ExceptionHandlerTests extends TestCase {
assertTrue(exCaught);
}
+ public void testRuntimeExceptionHandler2() {
+ Exception npe = new NullPointerException();
+ ExceptionHandler exceptionHandler = ExceptionHandler.Runtime.instance();
+ boolean exCaught = false;
+ try {
+ exceptionHandler.handleException(npe);
+ fail();
+ } catch (RuntimeException ex) {
+ assertSame(npe, ex);
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
public void testRuntimeExceptionHandlerToString() {
ExceptionHandler exceptionHandler = ExceptionHandler.Runtime.instance();
assertNotNull(exceptionHandler.toString());
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java
index b27a0a3543..44ec8ce09a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/FilterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -21,19 +21,19 @@ public class FilterTests extends TestCase {
}
public void testNullFilter() {
- Filter<String> filter = Filter.Null.instance();
+ Filter<String> filter = Filter.Transparent.instance();
assertTrue(filter.accept(""));
assertTrue(filter.accept("foo"));
assertTrue(filter.accept("bar"));
}
public void testNullFilter_toString() {
- Filter<String> filter = Filter.Null.instance();
+ Filter<String> filter = Filter.Transparent.instance();
assertNotNull(filter.toString());
}
public void testNullFilter_serialization() throws Exception {
- Filter<String> filter = Filter.Null.instance();
+ Filter<String> filter = Filter.Transparent.instance();
assertSame(filter, TestTools.serialize(filter));
}
@@ -75,5 +75,4 @@ public class FilterTests extends TestCase {
Filter<String> filter = Filter.Disabled.instance();
assertSame(filter, TestTools.serialize(filter));
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
index 883607e128..c62bad8a82 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.common.utility.tests.internal;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.jpt.common.utility.tests.internal.command.JptUtilityCommandTests;
import org.eclipse.jpt.common.utility.tests.internal.enumerations.JptUtilityEnumerationsTests;
import org.eclipse.jpt.common.utility.tests.internal.iterables.JptUtilityIterablesTests;
import org.eclipse.jpt.common.utility.tests.internal.iterators.JptUtilityIteratorsTests;
@@ -26,6 +27,7 @@ public class JptCommonUtilityTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptCommonUtilityTests.class.getPackage().getName());
+ suite.addTest(JptUtilityCommandTests.suite());
suite.addTest(JptUtilityEnumerationsTests.suite());
suite.addTest(JptUtilityIterablesTests.suite());
suite.addTest(JptUtilityIteratorsTests.suite());
@@ -34,7 +36,6 @@ public class JptCommonUtilityTests {
suite.addTest(JptUtilitySynchronizersTests.suite());
suite.addTestSuite(ArrayToolsTests.class);
- suite.addTestSuite(AsynchronousCommandExecutorTests.class);
suite.addTestSuite(BagTests.class);
suite.addTestSuite(BidiFilterTests.class);
suite.addTestSuite(BidiStringConverterTests.class);
@@ -45,10 +46,6 @@ public class JptCommonUtilityTests {
suite.addTestSuite(ClasspathTests.class);
suite.addTestSuite(ClassNameTests.class);
suite.addTestSuite(CollectionToolsTests.class);
- suite.addTestSuite(CommandExecutorTests.class);
- suite.addTestSuite(CommandRunnableTests.class);
- suite.addTestSuite(CommandTests.class);
- suite.addTestSuite(CompositeCommandTests.class);
suite.addTestSuite(ExceptionHandlerTests.class);
suite.addTestSuite(FileToolsTests.class);
suite.addTestSuite(FilterTests.class);
@@ -87,5 +84,4 @@ public class JptCommonUtilityTests {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java
index 10ac313cc0..749253a198 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/MultiThreadedTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -133,7 +133,7 @@ public abstract class MultiThreadedTestCase
public void run() {
try {
this.runnable.run();
- } catch (Throwable ex) {
+ } catch (RuntimeException ex) {
MultiThreadedTestCase.this.exceptions.add(ex);
}
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java
index 18df9552c5..b666004427 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedIntTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -310,7 +310,7 @@ public class SynchronizedIntTests
return new Command() {
public void execute(final SynchronizedInt sInt) throws InterruptedException {
sInt.execute(
- new org.eclipse.jpt.common.utility.Command() {
+ new org.eclipse.jpt.common.utility.command.Command() {
public void execute() {
// pretend to perform some long initialization process
try {
@@ -358,5 +358,4 @@ public class SynchronizedIntTests
private interface Command {
void execute(SynchronizedInt sInt) throws InterruptedException;
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java
index cffe99690a..d0fa703b62 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/SynchronizedObjectTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -187,7 +187,7 @@ public class SynchronizedObjectTests
return new Command() {
public void execute(final SynchronizedObject<Object> sObject) throws InterruptedException {
sObject.execute(
- new org.eclipse.jpt.common.utility.Command() {
+ new org.eclipse.jpt.common.utility.command.Command() {
public void execute() {
// pretend to perform some long initialization process
try {
@@ -235,5 +235,4 @@ public class SynchronizedObjectTests
private interface Command {
void execute(SynchronizedObject<Object> so) throws InterruptedException;
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java
new file mode 100644
index 0000000000..34040e489f
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/TestCommand.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal;
+
+/**
+ * Command that can be used to execute tests; i.e. a command that allows its
+ * implementation to throw exceptions.
+ */
+public interface TestCommand {
+ void execute() throws Exception;
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AsynchronousCommandExecutorTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousCommandExecutorTests.java
index f8b32dcd28..767882fbd9 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/AsynchronousCommandExecutorTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousCommandExecutorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,11 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.AsynchronousCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.AsynchronousExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
public class AsynchronousCommandExecutorTests
extends MultiThreadedTestCase
@@ -22,7 +24,10 @@ public class AsynchronousCommandExecutorTests
public void testExecution() throws Exception {
TestCommand command = new TestCommand();
- StatefulCommandExecutor commandExecutor = new AsynchronousCommandExecutor(this.buildThreadFactory());
+ AsynchronousExtendedCommandExecutor.SimpleConfig config = new AsynchronousExtendedCommandExecutor.SimpleConfig();
+ config.setThreadFactory(this.buildThreadFactory());
+ config.setExceptionHandler(ExceptionHandler.Runtime.instance());
+ StatefulCommandExecutor commandExecutor = new AsynchronousExtendedCommandExecutor(config);
commandExecutor.start();
commandExecutor.execute(command);
commandExecutor.execute(command);
@@ -38,5 +43,4 @@ public class AsynchronousCommandExecutorTests
this.count++;
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousRepeatingCommandWrapperTests.java
index 3ddbadc460..975cf6aff4 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/AsynchronousSynchronizerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/AsynchronousRepeatingCommandWrapperTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,31 +7,33 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.synchronizers;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.CompositeException;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.RepeatingCommand;
+import org.eclipse.jpt.common.utility.internal.CollectingExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
-import org.eclipse.jpt.common.utility.internal.synchronizers.AsynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
+import org.eclipse.jpt.common.utility.internal.command.AsynchronousRepeatingCommandWrapper;
import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
@SuppressWarnings("nls")
-public class AsynchronousSynchronizerTests
+public class AsynchronousRepeatingCommandWrapperTests
extends MultiThreadedTestCase
{
PrimaryModel1 primaryModel1;
SecondaryModel1 secondaryModel1;
Command command1;
- Synchronizer synchronizer1;
+ RepeatingCommand repeatingCommand1;
PrimaryModel2 primaryModel2;
SecondaryModel2 secondaryModel2;
Command command2;
- Synchronizer synchronizer2;
+ RepeatingCommand repeatingCommand2;
- public AsynchronousSynchronizerTests(String name) {
+ public AsynchronousRepeatingCommandWrapperTests(String name) {
super(name);
}
@@ -41,20 +43,20 @@ public class AsynchronousSynchronizerTests
this.primaryModel1 = new PrimaryModel1();
this.secondaryModel1 = new SecondaryModel1(this.primaryModel1);
this.command1 = new SynchronizeSecondaryModelCommand1(this.secondaryModel1);
- this.synchronizer1 = new AsynchronousSynchronizer(this.command1, this.buildThreadFactory());
- this.primaryModel1.setSynchronizer(this.synchronizer1);
+ this.repeatingCommand1 = new AsynchronousRepeatingCommandWrapper(this.command1, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
+ this.primaryModel1.setSynchronizer(this.repeatingCommand1);
this.primaryModel2 = new PrimaryModel2();
this.secondaryModel2 = new SecondaryModel2(this.primaryModel2);
this.command2 = new SynchronizeSecondaryModelCommand2(this.primaryModel2, this.secondaryModel2);
- this.synchronizer2 = new AsynchronousSynchronizer(this.command2, this.buildThreadFactory());
- this.primaryModel2.setSynchronizer(this.synchronizer2);
+ this.repeatingCommand2 = new AsynchronousRepeatingCommandWrapper(this.command2, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
+ this.primaryModel2.setSynchronizer(this.repeatingCommand2);
}
@Override
protected void tearDown() throws Exception {
- this.synchronizer1.stop();
- this.synchronizer2.stop();
+ this.repeatingCommand1.stop();
+ this.repeatingCommand2.stop();
super.tearDown();
}
@@ -63,7 +65,7 @@ public class AsynchronousSynchronizerTests
}
public void testToString() {
- assertNotNull(this.synchronizer1.toString());
+ assertNotNull(this.repeatingCommand1.toString());
}
public void testChange() throws Exception {
@@ -71,34 +73,34 @@ public class AsynchronousSynchronizerTests
this.primaryModel1.setCount(7);
this.sleep(TICK);
- this.synchronizer1.stop();
+ this.repeatingCommand1.stop();
this.sleep(TICK);
assertEquals(14, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testStart() throws Exception {
assertEquals(4, this.secondaryModel1.getDoubleCount());
- this.primaryModel1.setSynchronizer(Synchronizer.Null.instance());
+ this.primaryModel1.setSynchronizer(RepeatingCommand.Null.instance());
this.primaryModel1.setCount(7);
assertEquals(4, this.secondaryModel1.getDoubleCount());
- this.primaryModel1.setSynchronizer(this.synchronizer1);
+ this.primaryModel1.setSynchronizer(this.repeatingCommand1);
// the async synchronizer does not synchronize at start-up
assertEquals(4, this.secondaryModel1.getDoubleCount());
this.primaryModel1.setCount(8);
this.sleep(TICK);
- this.synchronizer1.stop();
+ this.repeatingCommand1.stop();
this.sleep(TICK);
assertEquals(16, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testStop() throws Exception {
@@ -108,7 +110,7 @@ public class AsynchronousSynchronizerTests
assertEquals(4, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testDoubleStart() throws Exception {
@@ -124,13 +126,13 @@ public class AsynchronousSynchronizerTests
this.primaryModel1.setCount(7);
this.sleep(TICK);
- this.synchronizer1.stop();
+ this.repeatingCommand1.stop();
this.sleep(TICK);
assertEquals(14, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testDoubleStop() throws Exception {
@@ -148,7 +150,7 @@ public class AsynchronousSynchronizerTests
assertEquals(4, this.secondaryModel1.getDoubleCount());
// re-start so tear-down works
- this.synchronizer1.start();
+ this.repeatingCommand1.start();
}
public void testRecursiveChange() throws Exception {
@@ -166,7 +168,7 @@ public class AsynchronousSynchronizerTests
public void testNullCommand() {
boolean exCaught = false;
try {
- Synchronizer s = new AsynchronousSynchronizer(null, this.buildThreadFactory());
+ RepeatingCommand s = new AsynchronousRepeatingCommandWrapper(null, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
fail("bogus: " + s);
} catch (NullPointerException ex) {
exCaught = true;
@@ -174,8 +176,8 @@ public class AsynchronousSynchronizerTests
assertTrue(exCaught);
}
- public void testThreadName() {
- Synchronizer s = new AsynchronousSynchronizer(this.command1, this.buildThreadFactory(), "sync");
+ public void testThreadName() throws Exception {
+ RepeatingCommand s = new AsynchronousRepeatingCommandWrapper(this.command1, this.buildThreadFactory(), "sync", ExceptionHandler.Runtime.instance());
s.start();
ConsumerThreadCoordinator ctc = (ConsumerThreadCoordinator) ReflectionTools.getFieldValue(s, "consumerThreadCoordinator");
Thread t = (Thread) ReflectionTools.getFieldValue(ctc, "thread");
@@ -183,11 +185,11 @@ public class AsynchronousSynchronizerTests
s.stop();
}
- public void testSynchronizeCalledBeforeStart() throws Exception {
+ public void testExecuteCalledBeforeStart() throws Exception {
SimpleCommand command = new SimpleCommand();
- Synchronizer synchronizer = new AsynchronousSynchronizer(command, this.buildThreadFactory());
+ RepeatingCommand synchronizer = new AsynchronousRepeatingCommandWrapper(command, this.buildThreadFactory(), null, ExceptionHandler.Runtime.instance());
- synchronizer.synchronize();
+ synchronizer.execute();
synchronizer.start();
this.sleep(TICK);
synchronizer.stop();
@@ -203,24 +205,18 @@ public class AsynchronousSynchronizerTests
public void testException() throws Exception {
BogusCommand command = new BogusCommand();
- Synchronizer synchronizer = new AsynchronousSynchronizer(command, this.buildThreadFactory());
+ CollectingExceptionHandler exHandler = new CollectingExceptionHandler();
+ RepeatingCommand synchronizer = new AsynchronousRepeatingCommandWrapper(command, this.buildThreadFactory(), null, exHandler);
synchronizer.start();
- synchronizer.synchronize();
+ synchronizer.execute();
this.sleep(TICK);
- synchronizer.synchronize();
+ synchronizer.execute();
this.sleep(TICK);
- boolean exCaught = false;
- try {
- synchronizer.stop();
- fail();
- } catch (CompositeException ex) {
- assertEquals(2, ex.getExceptions().length);
- exCaught = true;
- }
- assertTrue(exCaught);
+ synchronizer.stop();
+ assertEquals(2, CollectionTools.size(exHandler.getExceptions()));
assertEquals(2, command.count);
}
@@ -234,7 +230,10 @@ public class AsynchronousSynchronizerTests
// ********** synchronize commands **********
- public static class SynchronizeSecondaryModelCommand1 implements Command {
+
+ public static class SynchronizeSecondaryModelCommand1
+ implements Command
+ {
private final SecondaryModel1 secondaryModel;
public SynchronizeSecondaryModelCommand1(SecondaryModel1 secondaryModel) {
@@ -245,13 +244,14 @@ public class AsynchronousSynchronizerTests
public void execute() {
this.secondaryModel.synchronize();
}
-
}
/**
* the primary model (subclass) has to synchronize with itself (superclass)
*/
- public static class SynchronizeSecondaryModelCommand2 extends SynchronizeSecondaryModelCommand1 {
+ public static class SynchronizeSecondaryModelCommand2
+ extends SynchronizeSecondaryModelCommand1
+ {
private final PrimaryModel2 primaryModel;
public SynchronizeSecondaryModelCommand2(PrimaryModel2 primaryModel, SecondaryModel2 secondaryModel) {
@@ -264,21 +264,22 @@ public class AsynchronousSynchronizerTests
super.execute();
this.primaryModel.synchronize();
}
-
}
+
// ********** primary models **********
+
/**
* this object will call the synchronizer whenever its count changes,
* allowing interested parties to synchronize with the change
*/
public static class PrimaryModel1 {
- protected Synchronizer synchronizer;
+ protected RepeatingCommand synchronizer;
protected int count = 2;
public PrimaryModel1() {
super();
- this.setSynchronizer_(Synchronizer.Null.instance());
+ this.setSynchronizer_(RepeatingCommand.Null.instance());
}
public int getCount() {
@@ -292,10 +293,10 @@ public class AsynchronousSynchronizerTests
}
protected void stateChanged() {
- this.synchronizer.synchronize();
+ this.synchronizer.execute();
}
- public void setSynchronizer(Synchronizer synchronizer) {
+ public void setSynchronizer(RepeatingCommand synchronizer) throws InterruptedException {
if (synchronizer == null) {
throw new NullPointerException();
}
@@ -303,7 +304,7 @@ public class AsynchronousSynchronizerTests
this.setSynchronizer_(synchronizer);
}
- protected void setSynchronizer_(Synchronizer synchronizer) {
+ protected void setSynchronizer_(RepeatingCommand synchronizer) {
this.synchronizer = synchronizer;
this.synchronizer.start();
}
@@ -311,7 +312,7 @@ public class AsynchronousSynchronizerTests
public void startSynchronizer() {
this.synchronizer.start(); // this should cause an exception
}
- public void dispose() {
+ public void dispose() throws InterruptedException {
this.synchronizer.stop();
}
@@ -328,7 +329,6 @@ public class AsynchronousSynchronizerTests
sb.append("count=");
sb.append(this.count);
}
-
}
/**
@@ -336,7 +336,9 @@ public class AsynchronousSynchronizerTests
* with the change. Whenever the [inherited] 'count' changes, 'countPlus3'
* is updated appropriately and another synchronize is initiated if appropriate.
*/
- public static class PrimaryModel2 extends PrimaryModel1 {
+ public static class PrimaryModel2
+ extends PrimaryModel1
+ {
private int countPlus3 = 0;
public PrimaryModel2() {
@@ -365,10 +367,11 @@ public class AsynchronousSynchronizerTests
sb.append(", countPlus3=");
sb.append(this.countPlus3);
}
-
}
+
// ********** secondary models **********
+
/**
* This dependent object updates its 'doubleCount' whenever the
* PrimaryModel1's 'count' changes, via the 'synchronizer'.
@@ -404,10 +407,11 @@ public class AsynchronousSynchronizerTests
sb.append("doubleCount=");
sb.append(this.doubleCount);
}
-
}
- public static class SecondaryModel2 extends SecondaryModel1 {
+ public static class SecondaryModel2
+ extends SecondaryModel1
+ {
private int doubleCountPlus3 = 0;
public SecondaryModel2(PrimaryModel2 extendedPrimaryModel) {
@@ -437,7 +441,5 @@ public class AsynchronousSynchronizerTests
sb.append(", doubleCountPlus3=");
sb.append(this.doubleCountPlus3);
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandExecutorTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandExecutorTests.java
index 693b9c91b4..cb7d75ea1e 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandExecutorTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandExecutorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,11 +7,14 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.ThreadLocalCommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.ThreadLocalExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
public class CommandExecutorTests
extends MultiThreadedTestCase
@@ -48,12 +51,12 @@ public class CommandExecutorTests
}
public void testThreadLocalCommandExecutor_toString() throws Exception {
- CommandExecutor commandExecutor = new ThreadLocalCommandExecutor();
+ CommandExecutor commandExecutor = new ThreadLocalExtendedCommandExecutor();
assertNotNull(commandExecutor.toString());
}
public void testThreadLocalCommandExecutor() throws Exception {
- ThreadLocalCommandExecutor threadLocalCommandExecutor = new ThreadLocalCommandExecutor();
+ ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor = new ThreadLocalExtendedCommandExecutor();
TestRunnable testRunnable1 = new TestRunnable(threadLocalCommandExecutor, 1);
Thread thread1 = this.buildThread(testRunnable1);
thread1.run();
@@ -80,23 +83,30 @@ public class CommandExecutorTests
assertNull(testRunnable3.testCommandExecutor);
}
- static class TestCommandExecutor implements CommandExecutor {
+ static class TestCommandExecutor implements ExtendedCommandExecutor {
int count = 0;
public void execute(Command command) {
this.count++;
command.execute();
}
+ public void waitToExecute(Command command) {
+ this.execute(command);
+ }
+ public boolean waitToExecute(Command command, long timeout) {
+ this.execute(command);
+ return true;
+ }
}
static class TestRunnable implements Runnable {
- final ThreadLocalCommandExecutor threadLocalCommandExecutor;
+ final ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor;
final int executionCount;
final TestCommand testCommand = new TestCommand();
final TestCommandExecutor testCommandExecutor;
- TestRunnable(ThreadLocalCommandExecutor threadLocalCommandExecutor, int executionCount) {
+ TestRunnable(ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor, int executionCount) {
this(threadLocalCommandExecutor, executionCount, new TestCommandExecutor());
}
- TestRunnable(ThreadLocalCommandExecutor threadLocalCommandExecutor, int executionCount, TestCommandExecutor testCommandExecutor) {
+ TestRunnable(ThreadLocalExtendedCommandExecutor threadLocalCommandExecutor, int executionCount, TestCommandExecutor testCommandExecutor) {
super();
this.threadLocalCommandExecutor = threadLocalCommandExecutor;
this.executionCount = executionCount;
@@ -109,5 +119,4 @@ public class CommandExecutorTests
}
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandRunnableTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandRunnableTests.java
index 623b2b2449..d5dce4e56c 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandRunnableTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandRunnableTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,12 +7,12 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
@SuppressWarnings("nls")
public class CommandRunnableTests extends TestCase {
@@ -51,5 +51,4 @@ public class CommandRunnableTests extends TestCase {
}
};
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandTests.java
index 0eb8392e8b..266a0101e4 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CommandTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CommandTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,13 +7,15 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
-import org.eclipse.jpt.common.utility.internal.RunnableCommand;
-import org.eclipse.jpt.common.utility.internal.ThreadLocalCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
+import org.eclipse.jpt.common.utility.internal.command.RunnableCommand;
+import org.eclipse.jpt.common.utility.internal.command.ThreadLocalCommand;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
public class CommandTests
extends MultiThreadedTestCase
@@ -133,5 +135,4 @@ public class CommandTests
}
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeCommandTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CompositeCommandTests.java
index cfabc54bef..69aa1f8c8d 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/CompositeCommandTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/CompositeCommandTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,13 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal;
+package org.eclipse.jpt.common.utility.tests.internal.command;
import junit.framework.TestCase;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.CommandRunnable;
-import org.eclipse.jpt.common.utility.internal.CompositeCommand;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.command.CommandRunnable;
+import org.eclipse.jpt.common.utility.internal.command.CompositeCommand;
public class CompositeCommandTests extends TestCase {
boolean command1Executed = false;
@@ -57,5 +57,4 @@ public class CompositeCommandTests extends TestCase {
}
};
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java
new file mode 100644
index 0000000000..6d40c97327
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/command/JptUtilityCommandTests.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.command;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * decentralize test creation code
+ */
+public class JptUtilityCommandTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptUtilityCommandTests.class.getPackage().getName());
+
+ suite.addTestSuite(AsynchronousCommandExecutorTests.class);
+ suite.addTestSuite(AsynchronousRepeatingCommandWrapperTests.class);
+ suite.addTestSuite(CommandExecutorTests.class);
+ suite.addTestSuite(CommandRunnableTests.class);
+ suite.addTestSuite(CommandTests.class);
+ suite.addTestSuite(CompositeCommandTests.class);
+
+ return suite;
+ }
+
+ private JptUtilityCommandTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
index f17f265cf1..f7c7e31cef 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,11 +10,10 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
import org.eclipse.jpt.common.utility.internal.BidiTransformer;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
@@ -39,7 +38,7 @@ public class CachingTransformationPropertyValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null));
- this.transformationObjectHolder = new CachingTransformationPropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
+ this.transformationObjectHolder = new TransformationPropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
}
private BidiTransformer<Person, Person> buildTransformer() {
@@ -192,8 +191,9 @@ public class CachingTransformationPropertyValueModelTests extends TestCase {
}
- class Person extends AbstractModel {
-
+ class Person
+ extends AbstractModel
+ {
private String name;
public static final String NAME_PROPERTY = "name";
@@ -235,7 +235,5 @@ public class CachingTransformationPropertyValueModelTests extends TestCase {
public Person getChild() {
return this.child;
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
index 3560f4a814..2304cd293e 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,11 +10,10 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
@@ -23,7 +22,9 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
-public class CachingTransformationWritablePropertyValueModelTests extends TestCase {
+public class CachingTransformationWritablePropertyValueModelTests
+ extends TestCase
+{
private WritablePropertyValueModel<Person> objectHolder;
PropertyChangeEvent event;
@@ -38,15 +39,20 @@ public class CachingTransformationWritablePropertyValueModelTests extends TestCa
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null));
- this.transformationObjectHolder = new CachingTransformationWritablePropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
+ this.transformationObjectHolder = new TransformationWritablePropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer(), this.buildReverseTransformer());
}
- private BidiTransformer<Person, Person> buildTransformer() {
- return new BidiTransformer<Person, Person>() {
+ private Transformer<Person, Person> buildTransformer() {
+ return new Transformer<Person, Person>() {
public Person transform(Person p) {
return (p == null) ? null : p.getParent();
}
- public Person reverseTransform(Person p) {
+ };
+ }
+
+ private Transformer<Person, Person> buildReverseTransformer() {
+ return new Transformer<Person, Person>() {
+ public Person transform(Person p) {
return (p == null) ? null : p.getChild();
}
};
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
index b9542f9d21..470b3cf096 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -326,22 +326,22 @@ public class CollectionAspectAdapterTests extends TestCase {
@Override
protected Iterator<String> iterator_() {
- if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.NAMES_COLLECTION) {
return this.subject.names();
}
- if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
return this.subject.descriptions();
}
- throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
public void add(String item) {
- if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.NAMES_COLLECTION) {
this.subject.addName(item);
- } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
this.subject.addDescription(item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -352,12 +352,12 @@ public class CollectionAspectAdapterTests extends TestCase {
}
public void remove(Object item) {
- if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) {
+ if (this.aspectNames[0] == TestSubject.NAMES_COLLECTION) {
this.subject.removeName((String) item);
- } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) {
this.subject.removeDescription((String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -366,7 +366,5 @@ public class CollectionAspectAdapterTests extends TestCase {
this.remove(stream.next());
}
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
index 559c12635d..7791fb2b37 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java
@@ -189,7 +189,7 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
* otherwise the value is false
*/
static class LocalAdapter
- extends CollectionPropertyValueModelAdapter<Boolean>
+ extends CollectionPropertyValueModelAdapter<Boolean, String>
implements WritablePropertyValueModel<Boolean>
{
private String item;
@@ -234,7 +234,5 @@ public class CollectionPropertyValueModelAdapterTests extends TestCase {
private boolean booleanValueOf(Object b) {
return (b == null) ? false : ((Boolean) b).booleanValue();
}
-
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
index 5fa2413fea..a9cd9c9cdb 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositePropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -57,21 +57,16 @@ public class CompositePropertyValueModelTests extends TestCase {
this.compositePVM = this.buildCompositePVM(cvm);
}
- private <T extends PropertyValueModel<?>> PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<T> pvms) {
- return new CompositePropertyValueModel<Integer>(pvms) {
+ private <T extends PropertyValueModel<Integer>> PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<T> pvms) {
+ return new CompositePropertyValueModel<Integer, Integer>(pvms) {
@Override
protected Integer buildValue() {
int sum = 0;
- for (PropertyValueModel<Integer> each : this.getCollectionModel()) {
+ for (PropertyValueModel<? extends Integer> each : this.collectionModel) {
sum += each.getValue().intValue();
}
return Integer.valueOf(sum);
}
- @Override
- @SuppressWarnings("unchecked")
- protected CollectionValueModel<PropertyValueModel<Integer>> getCollectionModel() {
- return (CollectionValueModel<PropertyValueModel<Integer>>) super.getCollectionModel();
- }
};
}
@@ -195,5 +190,4 @@ public class CompositePropertyValueModelTests extends TestCase {
assertEquals(Integer.valueOf(oldValue), this.event.getOldValue());
assertEquals(Integer.valueOf(newValue), this.event.getNewValue());
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
new file mode 100644
index 0000000000..785f5ec099
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import org.eclipse.jpt.common.utility.internal.model.value.DoubleModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+
+@SuppressWarnings("nls")
+public class DoubleModifiablePropertyValueModelTests
+ extends DoublePropertyValueModelTests
+{
+ public DoubleModifiablePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected PropertyValueModel<String> buildDoubleModel() {
+ return new DoubleModifiablePropertyValueModel<String>(this.stringModelModel);
+ }
+
+ protected WritablePropertyValueModel<String> getDoubleModel() {
+ return (WritablePropertyValueModel<String>) this.doubleModel;
+ }
+
+ public void testSetValue() {
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals(this.stringModel, this.stringModelModel.getValue());
+ assertNull(this.doubleModel.getValue());
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertEquals("foo", this.doubleModel.getValue());
+
+ this.getDoubleModel().setValue("bar");
+ assertEquals("bar", this.stringModel.getValue());
+ assertEquals("bar", this.doubleModel.getValue());
+
+ this.stringModelModel.setValue(null);
+ assertNull(this.doubleModel.getValue());
+ this.getDoubleModel().setValue("TTT"); // NOP?
+ assertEquals("bar", this.stringModel.getValue());
+ assertNull(this.doubleModel.getValue());
+ }
+
+ public void testPropertyChange3() {
+ this.stringModel.addChangeListener(this.stringModelListener);
+ this.stringModelModel.addChangeListener(this.stringModelModelListener);
+ this.doubleModel.addChangeListener(this.doubleModelListener);
+ this.verifyPropertyChanges2();
+ }
+
+ public void testPropertyChange4() {
+ this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelListener);
+ this.stringModelModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelModelListener);
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ this.verifyPropertyChanges2();
+ }
+
+ protected void verifyPropertyChanges2() {
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue("bar");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "foo", "bar");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "bar");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue(null);
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "bar", null);
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "bar", null);
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue("foo");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, null, "foo");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, null, "foo");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ this.stringModelModel.setValue(stringModel2);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, this.stringModel, stringModel2);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "TTT");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.getDoubleModel().setValue("XXX");
+ assertNull(this.stringModelEvent);
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "TTT", "XXX");
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals("XXX", stringModel2.getValue());
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModelModel.setValue(this.stringModel);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, stringModel2, this.stringModel);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "XXX", "foo");
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
new file mode 100644
index 0000000000..b8d8be9684
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoublePropertyValueModelTests.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.model.value;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+
+@SuppressWarnings("nls")
+public class DoublePropertyValueModelTests
+ extends TestCase
+{
+ protected WritablePropertyValueModel<String> stringModel;
+ protected ChangeListener stringModelListener;
+ protected PropertyChangeEvent stringModelEvent;
+
+ protected WritablePropertyValueModel<WritablePropertyValueModel<String>> stringModelModel;
+ protected ChangeListener stringModelModelListener;
+ protected PropertyChangeEvent stringModelModelEvent;
+
+ protected PropertyValueModel<String> doubleModel;
+ protected ChangeListener doubleModelListener;
+ protected PropertyChangeEvent doubleModelEvent;
+
+ public DoublePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.stringModel = new SimplePropertyValueModel<String>("foo");
+ this.stringModelListener = new StringModelListener();
+
+ this.stringModelModel = new SimplePropertyValueModel<WritablePropertyValueModel<String>>(stringModel);
+ this.stringModelModelListener = new StringModelModelListener();
+
+ this.doubleModel = this.buildDoubleModel();
+ this.doubleModelListener = new DoubleModelListener();
+ }
+
+ protected PropertyValueModel<String> buildDoubleModel() {
+ return new DoublePropertyValueModel<String>(this.stringModelModel);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testGetValue1() {
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals(this.stringModel, this.stringModelModel.getValue());
+ assertNull(this.doubleModel.getValue());
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertEquals("foo", this.doubleModel.getValue());
+
+ this.stringModel.setValue("bar");
+ assertEquals("bar", this.stringModel.getValue());
+ assertEquals("bar", this.doubleModel.getValue());
+
+ this.stringModel.setValue("baz");
+ assertEquals("baz", this.stringModel.getValue());
+ assertEquals("baz", this.doubleModel.getValue());
+
+ this.stringModel.setValue(null);
+ assertNull(this.stringModel.getValue());
+ assertNull(this.doubleModel.getValue());
+
+ this.stringModel.setValue("foo");
+ assertEquals("foo", this.stringModel.getValue());
+ assertEquals("foo", this.doubleModel.getValue());
+ }
+
+ public void testGetValue2() {
+ assertNull(this.doubleModel.getValue());
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertEquals("foo", this.doubleModel.getValue());
+
+ this.stringModelModel.setValue(null);
+ assertNull(this.doubleModel.getValue());
+
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ this.stringModelModel.setValue(stringModel2);
+ assertEquals("TTT", this.doubleModel.getValue());
+
+ this.stringModelModel.setValue(this.stringModel);
+ assertEquals("foo", this.doubleModel.getValue());
+ }
+
+ public void testLazyListening() {
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.stringModelModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.doubleModel.addChangeListener(this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.stringModelModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.doubleModel.removeChangeListener(this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) this.stringModelModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.doubleModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) stringModel2).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.stringModelModel.setValue(stringModel2);
+ assertTrue(((AbstractModel) this.stringModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) stringModel2).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.stringModelModel.setValue(this.stringModel);
+ assertTrue(((AbstractModel) this.stringModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(((AbstractModel) stringModel2).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testPropertyChange1() {
+ this.stringModel.addChangeListener(this.stringModelListener);
+ this.stringModelModel.addChangeListener(this.stringModelModelListener);
+ this.doubleModel.addChangeListener(this.doubleModelListener);
+ this.verifyPropertyChanges1();
+ }
+
+ public void testPropertyChange2() {
+ this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelListener);
+ this.stringModelModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelModelListener);
+ this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
+ this.verifyPropertyChanges1();
+ }
+
+ protected void verifyPropertyChanges1() {
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModel.setValue("bar");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "foo", "bar");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "bar");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModel.setValue(null);
+ this.verifyEvent(this.stringModelEvent, this.stringModel, "bar", null);
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "bar", null);
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModel.setValue("foo");
+ this.verifyEvent(this.stringModelEvent, this.stringModel, null, "foo");
+ assertNull(this.stringModelModelEvent);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, null, "foo");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ WritablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<String>("TTT");
+ this.stringModelModel.setValue(stringModel2);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, this.stringModel, stringModel2);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "TTT");
+
+ this.stringModelEvent = null;
+ this.stringModelModelEvent = null;
+ this.doubleModelEvent = null;
+ this.stringModelModel.setValue(this.stringModel);
+ assertNull(this.stringModelEvent);
+ this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, stringModel2, this.stringModel);
+ this.verifyEvent(this.doubleModelEvent, this.doubleModel, "TTT", "foo");
+ }
+
+ protected void verifyEvent(PropertyChangeEvent event, Object source, Object oldValue, Object newValue) {
+ assertEquals(source, event.getSource());
+ assertEquals(PropertyValueModel.VALUE, event.getPropertyName());
+ assertEquals(oldValue, event.getOldValue());
+ assertEquals(newValue, event.getNewValue());
+ }
+
+ protected class StringModelListener
+ extends ChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModelTests.this.stringModelEvent = event;
+ }
+ }
+
+ protected class StringModelModelListener
+ extends ChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModelTests.this.stringModelModelEvent = event;
+ }
+ }
+
+ protected class DoubleModelListener
+ extends ChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DoublePropertyValueModelTests.this.doubleModelEvent = event;
+ }
+ }
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
index a20db7f063..1f081b1b0f 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,7 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.BidiFilter;
+import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.value.FilteringWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
@@ -38,15 +37,20 @@ public class FilteringPropertyValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<String>("foo");
- this.filteredObjectHolder = new FilteringWritablePropertyValueModel<String>(this.objectHolder, this.buildFilter());
+ this.filteredObjectHolder = new FilteringWritablePropertyValueModel<String>(this.objectHolder, this.buildFilter(), this.buildSetFilter());
}
- private BidiFilter<String> buildFilter() {
- return new BidiFilter<String>() {
+ private Filter<String> buildFilter() {
+ return new Filter<String>() {
public boolean accept(String s) {
return (s != null) && s.startsWith("b");
}
- public boolean reverseAccept(String s) {
+ };
+ }
+
+ private Filter<String> buildSetFilter() {
+ return new Filter<String>() {
+ public boolean accept(String s) {
return (s != null) && s.startsWith("b");
}
};
@@ -187,5 +191,4 @@ public class FilteringPropertyValueModelTests extends TestCase {
assertEquals(oldValue, e.getOldValue());
assertEquals(newValue, e.getNewValue());
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java
index 9812dd32bd..8f256b46f3 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/JptUtilityModelValueTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,13 +15,13 @@ import org.eclipse.jpt.common.utility.tests.internal.model.value.prefs.JptUtilit
import org.eclipse.jpt.common.utility.tests.internal.model.value.swing.JptUtilityModelValueSwingTests;
public class JptUtilityModelValueTests {
-
+
public static Test suite() {
TestSuite suite = new TestSuite(JptUtilityModelValueTests.class.getPackage().getName());
suite.addTest(JptUtilityModelValuePrefsTests.suite());
suite.addTest(JptUtilityModelValueSwingTests.suite());
-
+
suite.addTestSuite(BufferedWritablePropertyValueModelTests.class);
suite.addTestSuite(CachingTransformationPropertyValueModelTests.class);
suite.addTestSuite(CachingTransformationWritablePropertyValueModelTests.class);
@@ -32,6 +32,8 @@ public class JptUtilityModelValueTests {
suite.addTestSuite(CompositeCollectionValueModelTests.class);
suite.addTestSuite(CompositeListValueModelTests.class);
suite.addTestSuite(CompositePropertyValueModelTests.class);
+ suite.addTestSuite(DoublePropertyValueModelTests.class);
+ suite.addTestSuite(DoubleModifiablePropertyValueModelTests.class);
suite.addTestSuite(ExtendedListValueModelWrapperTests.class);
suite.addTestSuite(FilteringCollectionValueModelTests.class);
suite.addTestSuite(FilteringPropertyValueModelTests.class);
@@ -61,7 +63,6 @@ public class JptUtilityModelValueTests {
suite.addTestSuite(TransformationListValueModelTests.class);
suite.addTestSuite(TransformationListValueModelTests.TransformerTests.class);
suite.addTestSuite(TransformationPropertyValueModelTests.class);
- suite.addTestSuite(TreeAspectAdapterTests.class);
suite.addTestSuite(ValueCollectionAdapterTests.class);
suite.addTestSuite(ValueListAdapterTests.class);
suite.addTestSuite(ValuePropertyAdapterTests.class);
@@ -69,10 +70,9 @@ public class JptUtilityModelValueTests {
return suite;
}
-
+
private JptUtilityModelValueTests() {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java
index d6f3fd2999..e0a12398d7 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -419,22 +419,22 @@ public class ListAspectAdapterTests extends TestCase {
@Override
protected ListIterator<String> listIterator_() {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
return this.subject.names();
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
return this.subject.descriptions();
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
public void add(int index, Object item) {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
this.subject.addName(index, (String) item);
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
this.subject.addDescription(index, (String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -445,12 +445,12 @@ public class ListAspectAdapterTests extends TestCase {
}
public String remove(int index) {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
return this.subject.removeName(index);
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
return this.subject.removeDescription(index);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@@ -463,14 +463,13 @@ public class ListAspectAdapterTests extends TestCase {
}
public Object replace(int index, Object item) {
- if (this.listNames[0] == TestSubject.NAMES_LIST) {
+ if (this.aspectNames[0] == TestSubject.NAMES_LIST) {
return this.subject.setName(index, (String) item);
- } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTIONS_LIST) {
return this.subject.setDescription(index, (String) item);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.listNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
index a9a4ec6c28..3e6aaae055 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyAspectAdapterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -59,22 +59,22 @@ public class PropertyAspectAdapterTests extends TestCase {
// this is not a aspect adapter - the value is determined by the aspect name
@Override
protected String buildValue_() {
- if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) {
+ if (this.aspectNames[0] == TestSubject.NAME_PROPERTY) {
return this.subject.getName();
- } else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
return this.subject.getDescription();
} else {
- throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
@Override
protected void setValue_(String value) {
- if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) {
+ if (this.aspectNames[0] == TestSubject.NAME_PROPERTY) {
this.subject.setName(value);
- } else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
+ } else if (this.aspectNames[0] == TestSubject.DESCRIPTION_PROPERTY) {
this.subject.setDescription(value);
} else {
- throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]);
+ throw new IllegalStateException("invalid aspect name: " + this.aspectNames[0]);
}
}
};
@@ -340,5 +340,4 @@ public class PropertyAspectAdapterTests extends TestCase {
this.firePropertyChanged(DESCRIPTION_PROPERTY, old, description);
}
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
index 8344919d69..156cf8115a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,7 @@
package org.eclipse.jpt.common.utility.tests.internal.model.value;
import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.BidiTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationWritablePropertyValueModel;
@@ -23,7 +22,9 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
-public class TransformationPropertyValueModelTests extends TestCase {
+public class TransformationPropertyValueModelTests
+ extends TestCase
+{
private WritablePropertyValueModel<String> objectHolder;
PropertyChangeEvent event;
@@ -38,15 +39,20 @@ public class TransformationPropertyValueModelTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
this.objectHolder = new SimplePropertyValueModel<String>("foo");
- this.transformationObjectHolder = new TransformationWritablePropertyValueModel<String, String>(this.objectHolder, this.buildTransformer());
+ this.transformationObjectHolder = new TransformationWritablePropertyValueModel<String, String>(this.objectHolder, this.buildTransformer(), this.buildReverseTransformer());
}
- private BidiTransformer<String, String> buildTransformer() {
- return new BidiTransformer<String, String>() {
+ private Transformer<String, String> buildTransformer() {
+ return new Transformer<String, String>() {
public String transform(String s) {
return (s == null) ? null : s.toUpperCase();
}
- public String reverseTransform(String s) {
+ };
+ }
+
+ private Transformer<String, String> buildReverseTransformer() {
+ return new Transformer<String, String>() {
+ public String transform(String s) {
return (s == null) ? null : s.toLowerCase();
}
};
@@ -60,6 +66,9 @@ public class TransformationPropertyValueModelTests extends TestCase {
public void testValue() {
assertEquals("foo", this.objectHolder.getValue());
+ assertNull(this.transformationObjectHolder.getValue());
+ ChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addChangeListener(listener);
assertEquals("FOO", this.transformationObjectHolder.getValue());
this.objectHolder.setValue("bar");
@@ -84,17 +93,26 @@ public class TransformationPropertyValueModelTests extends TestCase {
assertEquals("bar", this.objectHolder.getValue());
assertEquals("BAR", this.transformationObjectHolder.getValue());
+ // NB: odd behavior(!)
this.transformationObjectHolder.setValue("Foo");
assertEquals("foo", this.objectHolder.getValue());
+ assertEquals("Foo", this.transformationObjectHolder.getValue());
+ ChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addChangeListener(listener);
assertEquals("FOO", this.transformationObjectHolder.getValue());
+ this.transformationObjectHolder.removeChangeListener(listener);
this.transformationObjectHolder.setValue(null);
assertNull(this.objectHolder.getValue());
assertNull(this.transformationObjectHolder.getValue());
+ // NB: odd behavior(!)
this.transformationObjectHolder.setValue("baz");
assertEquals("baz", this.objectHolder.getValue());
+ assertEquals("baz", this.transformationObjectHolder.getValue());
+ this.transformationObjectHolder.addChangeListener(listener);
assertEquals("BAZ", this.transformationObjectHolder.getValue());
+ this.transformationObjectHolder.removeChangeListener(listener);
}
public void testLazyListening() {
@@ -185,5 +203,4 @@ public class TransformationPropertyValueModelTests extends TestCase {
assertEquals(oldValue, e.getOldValue());
assertEquals(newValue, e.getNewValue());
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java
deleted file mode 100644
index 22ffb59825..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TreeAspectAdapterTests.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.model.value;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.HashBag;
-import org.eclipse.jpt.common.utility.internal.iterators.ChainIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.ReadOnlyIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.TreeIterator;
-import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.TreeAspectAdapter;
-import org.eclipse.jpt.common.utility.model.event.TreeAddEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeClearEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeEvent;
-import org.eclipse.jpt.common.utility.model.event.TreeRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.ChangeListener;
-import org.eclipse.jpt.common.utility.model.listener.TreeChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.TreeValueModel;
-import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-
-@SuppressWarnings("nls")
-public class TreeAspectAdapterTests extends TestCase {
- private TestSubject subject1;
- private WritablePropertyValueModel<TestSubject> subjectHolder1;
- private TreeAspectAdapter<TestSubject, List<TestNode>> aa1;
- private TreeEvent event1;
- private TreeChangeListener listener1;
-
- private TestSubject subject2;
-
-
- public TreeAspectAdapterTests(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.subject1 = new TestSubject();
- TestNode root, node;
-
- root = this.subject1.getRootNameNode();
- node = this.subject1.addName(root, "name 1.1");
- this.subject1.addName(node, "name 1.1.1");
- this.subject1.addName(node, "name 1.1.2");
- node = this.subject1.addName(root, "name 1.2");
- this.subject1.addName(node, "name 1.2.1");
- node = this.subject1.addName(root, "name 1.3");
-
- root = this.subject1.getRootDescriptionNode();
- node = this.subject1.addDescription(root, "description 1.1");
- this.subject1.addDescription(node, "description 1.1.1");
- this.subject1.addDescription(node, "description 1.1.2");
- node = this.subject1.addDescription(root, "description 1.2");
- this.subject1.addDescription(node, "description 1.2.1");
- node = this.subject1.addDescription(root, "description 1.3");
-
- this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1);
- this.aa1 = this.buildAspectAdapter(this.subjectHolder1);
- this.listener1 = this.buildValueChangeListener1();
- this.aa1.addTreeChangeListener(TreeValueModel.NODES, this.listener1);
- this.event1 = null;
-
- this.subject2 = new TestSubject();
-
- root = this.subject2.getRootNameNode();
- node = this.subject2.addName(root, "name 2.1");
- this.subject2.addName(node, "name 2.1.1");
- this.subject2.addName(node, "name 2.1.2");
- node = this.subject2.addName(root, "name 2.2");
- this.subject2.addName(node, "name 2.2.1");
- node = this.subject2.addName(root, "name 2.3");
-
- root = this.subject2.getRootDescriptionNode();
- node = this.subject2.addDescription(root, "description 2.1");
- this.subject2.addDescription(node, "description 2.1.1");
- this.subject2.addDescription(node, "description 2.1.2");
- node = this.subject2.addDescription(root, "description 2.2");
- this.subject2.addDescription(node, "description 2.2.1");
- node = this.subject2.addDescription(root, "description 2.3");
- }
-
- private TreeAspectAdapter<TestSubject, List<TestNode>> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) {
- return new TreeAspectAdapter<TestSubject, List<TestNode>>(subjectHolder, TestSubject.NAMES_TREE) {
- // this is not a typical aspect adapter - the value is determined by the aspect name
- @Override
- protected Iterator<List<TestNode>> nodes_() {
- if (this.treeNames[0] == TestSubject.NAMES_TREE) {
- return this.subject.namePaths();
- }
- if (this.treeNames[0] == TestSubject.DESCRIPTIONS_TREE) {
- return this.subject.descriptionPaths();
- }
- throw new IllegalStateException("invalid aspect name: " + this.treeNames[0]);
- }
- };
- }
-
- private ChangeListener buildValueChangeListener1() {
- return new ChangeAdapter() {
- @Override
- public void nodeAdded(TreeAddEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- @Override
- public void nodeRemoved(TreeRemoveEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- @Override
- public void treeCleared(TreeClearEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- @Override
- public void treeChanged(TreeChangeEvent e) {
- TreeAspectAdapterTests.this.value1Changed(e);
- }
- };
- }
-
- void value1Changed(TreeEvent e) {
- this.event1 = e;
- }
-
- @Override
- protected void tearDown() throws Exception {
- TestTools.clear(this);
- super.tearDown();
- }
-
- public void testSubjectHolder() {
- assertNull(this.event1);
-
- this.subjectHolder1.setValue(this.subject2);
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
-
- this.event1 = null;
- this.subjectHolder1.setValue(null);
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
-
- this.event1 = null;
- this.subjectHolder1.setValue(this.subject1);
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
- }
-
- public void testTreeStructureChange() {
- assertNull(this.event1);
-
- this.subject1.addTwoNames(this.subject1.getRootNameNode(), "jam", "jaz");
- assertNotNull(this.event1);
- assertEquals(this.aa1, this.event1.getSource());
- assertEquals(TreeValueModel.NODES, this.event1.getTreeName());
- assertTrue(this.subject1.containsNameNode("jam"));
- assertTrue(this.subject1.containsNameNode("jaz"));
- }
-
- public void testNodes() {
- assertEquals(this.convertToNames(this.subject1.namePaths()), this.convertToNames(this.aa1.nodes()));
- }
-
- private Collection<String> convertToNames(Iterator<List<TestNode>> namePaths) {
- Collection<String> result = new HashBag<String>();
- while (namePaths.hasNext()) {
- List<TestNode> path = namePaths.next();
- StringBuffer sb = new StringBuffer();
- sb.append('[');
- for (int i = 0; i < path.size(); i++) {
- sb.append(path.get(i).getText());
- if (i < path.size() - 1) {
- sb.append(':');
- }
- }
- sb.append(']');
- result.add(sb.toString());
- }
- return result;
- }
-
- public void testHasListeners() {
- assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
- assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- this.aa1.removeTreeChangeListener(TreeValueModel.NODES, this.listener1);
- assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
-
- ChangeListener listener2 = this.buildValueChangeListener1();
- this.aa1.addChangeListener(listener2);
- assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
- assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- this.aa1.removeChangeListener(listener2);
- assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE));
- assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES));
- }
-
- // ********** inner classes **********
-
- class TestSubject extends AbstractModel {
- private TestNode rootNameNode;
- public static final String NAMES_TREE = "names";
- private TestNode rootDescriptionNode;
- public static final String DESCRIPTIONS_TREE = "descriptions";
-
- public TestSubject() {
- this.rootNameNode = new TestNode("root name");
- this.rootDescriptionNode = new TestNode("root description");
- }
- public TestNode getRootNameNode() {
- return this.rootNameNode;
- }
- public Iterator<TestNode> nameNodes() {
- return new TreeIterator<TestNode>(this.rootNameNode) {
- @Override
- public Iterator<TestNode> children(TestNode next) {
- return next.children();
- }
- };
- }
- public Iterator<List<TestNode>> namePaths() {
- return new TransformationIterator<TestNode, List<TestNode>>(this.nameNodes()) {
- @Override
- protected List<TestNode> transform(TestNode next) {
- return next.getPath();
- }
- };
- }
- public TestNode addName(TestNode parent, String name) {
- TestNode child = new TestNode(name);
- parent.addChild(child);
- this.fireNodeAdded(NAMES_TREE, child.getPath());
- return child;
- }
- public void addTwoNames(TestNode parent, String name1, String name2) {
- parent.addChild(new TestNode(name1));
- parent.addChild(new TestNode(name2));
- this.fireTreeChanged(NAMES_TREE, parent.getPath());
- }
- public void removeNameNode(TestNode nameNode) {
- nameNode.getParent().removeChild(nameNode);
- this.fireNodeRemoved(NAMES_TREE, nameNode.getPath());
- }
- public boolean containsNameNode(String name) {
- return this.nameNode(name) != null;
- }
- public TestNode nameNode(String name) {
- for (Iterator<TestNode> stream = this.nameNodes(); stream.hasNext(); ) {
- TestNode node = stream.next();
- if (node.getText().equals(name)) {
- return node;
- }
- }
- return null;
- }
- public TestNode getRootDescriptionNode() {
- return this.rootDescriptionNode;
- }
- public Iterator<TestNode> descriptionNodes() {
- return new TreeIterator<TestNode>(this.rootDescriptionNode) {
- @Override
- public Iterator<TestNode> children(TestNode next) {
- return next.children();
- }
- };
- }
- public Iterator<List<TestNode>> descriptionPaths() {
- return new TransformationIterator<TestNode, List<TestNode>>(this.descriptionNodes()) {
- @Override
- protected List<TestNode> transform(TestNode next) {
- return next.getPath();
- }
- };
- }
- public TestNode addDescription(TestNode parent, String description) {
- TestNode child = new TestNode(description);
- parent.addChild(child);
- this.fireNodeAdded(DESCRIPTIONS_TREE, child.getPath());
- return child;
- }
- public void removeDescriptionNode(TestNode descriptionNode) {
- descriptionNode.getParent().removeChild(descriptionNode);
- this.fireNodeRemoved(DESCRIPTIONS_TREE, descriptionNode.getPath());
- }
- public boolean containsDescriptionNode(String name) {
- for (Iterator<TestNode> stream = this.descriptionNodes(); stream.hasNext(); ) {
- TestNode node = stream.next();
- if (node.getText().equals(name)) {
- return true;
- }
- }
- return false;
- }
- }
-
- class TestNode {
- private final String text;
- private TestNode parent;
- private final Collection<TestNode> children;
-
- public TestNode(String text) {
- this.text = text;
- this.children = new HashBag<TestNode>();
- }
- public String getText() {
- return this.text;
- }
- public TestNode getParent() {
- return this.parent;
- }
- private void setParent(TestNode parent) {
- this.parent = parent;
- }
- public Iterator<TestNode> children() {
- return new ReadOnlyIterator<TestNode>(this.children);
- }
- public void addChild(TestNode child) {
- this.children.add(child);
- child.setParent(this);
- }
- public void removeChild(TestNode child) {
- this.children.remove(child);
- }
- public List<TestNode> getPath() {
- return CollectionTools.reverseList(this.buildAntiPath());
- }
- private Iterator<TestNode> buildAntiPath() {
- return new ChainIterator<TestNode>(this) {
- @Override
- protected TestNode nextLink(TestNode currentLink) {
- return currentLink.getParent();
- }
- };
- }
- @Override
- public String toString() {
- return "TestNode(" + this.text + ")";
- }
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java
index 96acf3075b..da7ad6f1f1 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/JptUtilitySynchronizersTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,7 +20,6 @@ public class JptUtilitySynchronizersTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptUtilitySynchronizersTests.class.getPackage().getName());
- suite.addTestSuite(AsynchronousSynchronizerTests.class);
suite.addTestSuite(SynchronizerTests.class);
suite.addTestSuite(SynchronousSynchronizerTests.class);
@@ -31,5 +30,4 @@ public class JptUtilitySynchronizersTests {
super();
throw new UnsupportedOperationException();
}
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
index e7601bc657..4bec15e68c 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/synchronizers/SynchronousSynchronizerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.synchronizers;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.CompositeException;
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
@@ -752,5 +752,4 @@ public class SynchronousSynchronizerTests
public static String timestamp() {
return String.valueOf((System.currentTimeMillis() % 10000) / 1000f);
}
-
}
diff --git a/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/DbwsGeneratorUi.java b/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/DbwsGeneratorUi.java
index 8000bf3b6c..de2e5e81d3 100644
--- a/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/DbwsGeneratorUi.java
+++ b/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/DbwsGeneratorUi.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2010, 2011 Oracle. All rights reserved.
+* Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -228,7 +228,7 @@ public class DbwsGeneratorUi
}
private IJavaProject getJavaProjectFrom(IProject project) {
- return (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ return ((IJavaElement) project.getAdapter(IJavaElement.class)).getJavaProject();
}
private Shell getCurrentShell() {
diff --git a/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/wizards/gen/DbwsGeneratorWizard.java b/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/wizards/gen/DbwsGeneratorWizard.java
index a0c798a854..5b91e00fa6 100644
--- a/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/wizards/gen/DbwsGeneratorWizard.java
+++ b/jaxb/plugins/org.eclipse.jpt.dbws.eclipselink.ui/src/org/eclipse/jpt/dbws/eclipselink/ui/internal/wizards/gen/DbwsGeneratorWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2010, 2011 Oracle. All rights reserved.
+* Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -211,6 +211,6 @@ public class DbwsGeneratorWizard extends Wizard implements IWorkbenchWizard {
}
private IJavaProject getJavaProjectFrom(IProject project) {
- return (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ return ((IJavaElement) project.getAdapter(IJavaElement.class)).getJavaProject();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml
index 72b573e81d..7028056480 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/plugin.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
- Copyright (c) 2010, 2011 Oracle. All rights reserved.
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0, which accompanies this distribution
- and is available at http://www.eclipse.org/legal/epl-v10.html
-
- Contributors:
- Oracle - initial API and implementation
+ Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0, which accompanies this distribution
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ Oracle - initial API and implementation
-->
<plugin>
@@ -20,7 +20,33 @@
schema="schema/jaxbPlatforms.exsd"/>
- <!-- ***** extensions ***** -->
+ <!-- ***** adapters ***** -->
+
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+
+ <factory
+ class="org.eclipse.jpt.jaxb.core.internal.ResourceAdapterFactory"
+ adaptableType="org.eclipse.core.resources.IResource">
+ <adapter type="org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription"/>
+ </factory>
+
+ <factory
+ class="org.eclipse.jpt.jaxb.core.internal.JavaElementAdapterFactory"
+ adaptableType="org.eclipse.jdt.core.IJavaElement">
+ <adapter type="org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription"/>
+ </factory>
+
+ <factory
+ class="org.eclipse.jpt.jaxb.core.internal.libprov.JaxbLibraryProviderInstallOperationConfigAdapterFactory"
+ adaptableType="org.eclipse.jpt.jaxb.core.libprov.JaxbLibraryProviderInstallOperationConfig">
+ <adapter type="org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription"/>
+ </factory>
+
+ </extension>
+
+
+ <!-- ***** content types ***** -->
<extension
point="org.eclipse.core.contenttype.contentTypes">
@@ -41,43 +67,27 @@
</extension>
+
+ <!-- ***** property testers ***** -->
+
<extension
point="org.eclipse.core.expressions.propertyTesters">
-
- <propertyTester
- id="org.eclipse.jpt.jaxb.core.propertyTester.platformResource"
- type="org.eclipse.core.resources.IResource"
- namespace="org.eclipse.jpt.jaxb.core"
- properties="jaxbPlatform, jaxbPlatformGroup"
- class="org.eclipse.jpt.jaxb.core.internal.JaxbPlatformTester"/>
-
- <propertyTester
- id="org.eclipse.jpt.jaxb.core.propertyTester.javaElement"
- type="org.eclipse.jdt.core.IJavaElement"
- namespace="org.eclipse.jpt.jaxb.core"
- properties="jaxbPlatform, jaxbPlatformGroup"
- class="org.eclipse.jpt.jaxb.core.internal.JaxbPlatformTester"/>
-
+
<propertyTester
id="org.eclipse.jpt.jaxb.core.propertyTester.jaxbPlatformDescription"
type="org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription"
namespace="org.eclipse.jpt.jaxb.core"
properties="jaxbPlatform, jaxbPlatformGroup"
- class="org.eclipse.jpt.jaxb.core.internal.JaxbPlatformTester"/>
-
- <propertyTester
- id="org.eclipse.jpt.jaxb.core.propertyTester.jaxbLibraryProviderConfig"
- type="org.eclipse.jpt.jaxb.core.libprov.JaxbLibraryProviderInstallOperationConfig"
- namespace="org.eclipse.jpt.jaxb.core"
- properties="jaxbPlatform, jaxbPlatformGroup"
- class="org.eclipse.jpt.jaxb.core.internal.JaxbPlatformTester"/>
-
+ class="org.eclipse.jpt.jaxb.core.internal.platform.JaxbPlatformTester"/>
+
</extension>
- <!-- =================================================================================== -->
- <!-- Extension: JAXB Problem Marker -->
- <!-- **** Do NOT qualify the marker id with org.eclipse.jpt.jaxb.core, see bug 252891 -->
- <!-- =================================================================================== -->
+
+ <!-- ***** markers ***** -->
+ <!--
+ *** Do NOT qualify the marker id with "org.eclipse.jpt.jaxb.core".
+ *** See bug 252891.
+ -->
<extension
point="org.eclipse.core.resources.markers"
id="jaxbProblemMarker"
@@ -92,8 +102,10 @@
<super type="org.eclipse.wst.validation.problemmarker2"/>
<super type="org.eclipse.jdt.core.problem"/>
</extension>
-
-
+
+
+ <!-- ***** Dali extensions (eat our own dogfood) ***** -->
+
<extension
point="org.eclipse.jpt.jaxb.core.jaxbPlatforms">
@@ -128,7 +140,8 @@
class="org.eclipse.jpt.jaxb.core.internal.libval.JaxbJreLibraryValidator">
<enablement>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="jaxb-jre-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="jaxb-jre-library-provider"/>
</with>
</enablement>
</libraryValidator>
@@ -138,7 +151,8 @@
class="org.eclipse.jpt.jaxb.core.internal.libval.GenericJaxbUserLibraryValidator">
<enablement>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="jaxb-user-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="jaxb-user-library-provider"/>
</with>
</enablement>
</libraryValidator>
@@ -149,7 +163,8 @@
class="org.eclipse.jpt.core.internal.libval.GenericEclipseLinkBundlesLibraryValidator">
<enablement>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.core.extendsId" value="eclipselink-bundles-library-provider"/>
+ <test property="org.eclipse.jpt.core.extendsId"
+ value="eclipselink-bundles-library-provider"/>
</with>
</enablement>
</libraryValidator>
@@ -235,8 +250,10 @@
-->
</extension>
-
-
+
+
+ <!-- ***** WTP facet framework ***** -->
+
<extension
point="org.eclipse.wst.common.project.facet.core.runtimes">
@@ -291,7 +308,9 @@
</extension>
-
+
+ <!-- ***** WTP validation framework ***** -->
+
<extension
point="org.eclipse.wst.validation.validatorV2"
id="jaxbValidator"
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/GenericJaxbProjectManager.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/GenericJaxbProjectManager.java
index 61f6cd5f40..d8fbf291a5 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/GenericJaxbProjectManager.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/GenericJaxbProjectManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -33,14 +33,15 @@ import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
import org.eclipse.jpt.common.core.internal.utility.CallbackJobSynchronizer;
-import org.eclipse.jpt.common.core.internal.utility.JobCommand;
import org.eclipse.jpt.common.core.internal.utility.JobSynchronizer;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.AsynchronousCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.SimpleCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.StatefulCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.StatefulCommandExecutor;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
+import org.eclipse.jpt.common.utility.internal.command.AsynchronousExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.SimpleStatefulExtendedCommandExecutor;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
@@ -139,7 +140,23 @@ class GenericJaxbProjectManager
* Determine how Resource and Java change events are
* handled (i.e. synchronously or asynchronously).
*/
- private volatile StatefulCommandExecutor eventHandler = new AsynchronousCommandExecutor(JptCommonCoreMessages.DALI_EVENT_HANDLER_THREAD_NAME);
+ private volatile StatefulCommandExecutor eventHandler =
+ new AsynchronousExtendedCommandExecutor(
+ JptCommonCoreMessages.DALI_EVENT_HANDLER_THREAD_NAME,
+ new LocalExceptionHandler()
+ );
+
+ /* CU private */ class LocalExceptionHandler
+ implements ExceptionHandler
+ {
+ public void handleException(Throwable t) {
+ JptJaxbCorePlugin.log(t);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
/**
* Listen for<ul>
@@ -263,7 +280,11 @@ class GenericJaxbProjectManager
JavaCore.removeElementChangedListener(this.javaElementChangeListener);
FacetedProjectFramework.removeListener(this.facetedProjectListener);
this.getWorkspace().removeResourceChangeListener(this.resourceChangeListener);
- this.eventHandler.stop();
+ try {
+ this.eventHandler.stop();
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
this.clearJaxbProjects();
}
@@ -673,9 +694,9 @@ class GenericJaxbProjectManager
/**
* This method is called (via reflection) when the test plug-in is loaded.
- * @see JptCoreTestsPlugin#start(BundleContext)
+ * @see JptJaxbCoreTestsPlugin#start(BundleContext)
*/
- public void handleEventsSynchronously() {
+ public void handleEventsSynchronously() throws InterruptedException {
try {
this.lock.acquire();
this.handleEventsSynchronously_();
@@ -684,9 +705,9 @@ class GenericJaxbProjectManager
}
}
- private void handleEventsSynchronously_() {
+ private void handleEventsSynchronously_() throws InterruptedException {
this.eventHandler.stop();
- this.eventHandler = new SimpleCommandExecutor();
+ this.eventHandler = new SimpleStatefulExtendedCommandExecutor();
this.eventHandler.start();
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbNode.java
index a4eb6c5099..92a7831390 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.jaxb.core;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jpt.common.core.IResourcePart;
+import org.eclipse.jpt.common.core.ResourceReference;
import org.eclipse.jpt.common.utility.model.Model;
/**
@@ -27,7 +27,7 @@ import org.eclipse.jpt.common.utility.model.Model;
* @since 3.0
*/
public interface JaxbNode
- extends Model, IAdaptable, IResourcePart
+ extends Model, IAdaptable, ResourceReference
{
/**
* Return the JAXB project the node belongs to.
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java
index ca7799c966..df8afc4081 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -19,7 +19,7 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
@@ -367,20 +367,20 @@ public interface JaxbProject
// ********** modifying shared documents **********
/**
- * Set a thread-specific implementation of the {@link CommandExecutor}
+ * Set a thread-specific implementation of the {@link ExtendedCommandExecutor}
* interface that will be used to execute a command to modify a shared
* document. If necessary, the command executor can be cleared by
* setting it to null.
* This allows background clients to modify documents that are
- * already present in the UI. See implementations of {@link CommandExecutor}.
+ * already present in the UI. See implementations of {@link ExtendedCommandExecutor}.
*/
- void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor);
+ void setThreadLocalModifySharedDocumentCommandExecutor(ExtendedCommandExecutor commandExecutor);
/**
* Return the project-wide implementation of the
- * {@link CommandExecutor} interface.
+ * {@link ExtendedCommandExecutor} interface.
*/
- CommandExecutor getModifySharedDocumentCommandExecutor();
+ ExtendedCommandExecutor getModifySharedDocumentCommandExecutor();
// ********** construction config **********
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
index b1e56f477e..8357f5f173 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,7 +16,7 @@ import java.util.Set;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.core.internal.utility.jdt.JDTModifiedDeclaration.Adapter;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.Tools;
@@ -91,9 +91,9 @@ public abstract class AbstractJaxbNode
// ********** IAdaptable implementation **********
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public Object getAdapter(Class adapter) {
- return Platform.getAdapterManager().getAdapter(this, adapter);
+ return PlatformTools.getAdapter(this, adapter);
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
index 92e72ced1c..686bbb11b3 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -38,17 +38,17 @@ import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.JptResourceModel;
import org.eclipse.jpt.common.core.JptResourceModelListener;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
-import org.eclipse.jpt.common.core.resource.ResourceLocator;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
import org.eclipse.jpt.common.utility.internal.BitTools;
import org.eclipse.jpt.common.utility.internal.NotNullFilter;
-import org.eclipse.jpt.common.utility.internal.ThreadLocalCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.command.ThreadLocalExtendedCommandExecutor;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
@@ -182,7 +182,7 @@ public abstract class AbstractJaxbProject
/**
* Support for modifying documents shared with the UI.
*/
- protected final ThreadLocalCommandExecutor modifySharedDocumentCommandExecutor;
+ protected final ThreadLocalExtendedCommandExecutor modifySharedDocumentCommandExecutor;
// ********** constructor/initialization **********
@@ -230,8 +230,8 @@ public abstract class AbstractJaxbProject
return this.project;
}
- protected ThreadLocalCommandExecutor buildModifySharedDocumentCommandExecutor() {
- return new ThreadLocalCommandExecutor();
+ protected ThreadLocalExtendedCommandExecutor buildModifySharedDocumentCommandExecutor() {
+ return new ThreadLocalExtendedCommandExecutor();
}
protected InitialResourceProxyVisitor buildInitialResourceProxyVisitor() {
@@ -390,7 +390,7 @@ public abstract class AbstractJaxbProject
return null;
}
}
- else if (! isInAcceptableResourceLocation(file)) {
+ else if (! fileResourceLocationIsValid(file)) {
return null;
}
@@ -420,9 +420,12 @@ public abstract class AbstractJaxbProject
}
/* (non-java resource) file is in acceptable resource location */
- protected boolean isInAcceptableResourceLocation(IFile file) {
- ResourceLocator resourceLocator = JptCommonCorePlugin.getResourceLocator(getProject());
- return resourceLocator.acceptResourceLocation(getProject(), file.getParent());
+ protected boolean fileResourceLocationIsValid(IFile file) {
+ return this.getProjectResourceLocator().resourceLocationIsValid(file.getParent());
+ }
+
+ protected ProjectResourceLocator getProjectResourceLocator() {
+ return (ProjectResourceLocator) this.project.getAdapter(ProjectResourceLocator.class);
}
/**
@@ -1465,11 +1468,11 @@ public abstract class AbstractJaxbProject
// ********** support for modifying documents shared with the UI **********
- public void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor) {
+ public void setThreadLocalModifySharedDocumentCommandExecutor(ExtendedCommandExecutor commandExecutor) {
this.modifySharedDocumentCommandExecutor.set(commandExecutor);
}
- public CommandExecutor getModifySharedDocumentCommandExecutor() {
+ public ExtendedCommandExecutor getModifySharedDocumentCommandExecutor() {
return this.modifySharedDocumentCommandExecutor;
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JavaElementAdapterFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JavaElementAdapterFactory.java
new file mode 100644
index 0000000000..df776cf336
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JavaElementAdapterFactory.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
+
+/**
+ * Factory to build Dali adapters for an {@link IJavaElement}:<ul>
+ * <li>{@link JaxbPlatformDescription}
+ * </ul>
+ * See <code>org.eclipse.jpt.jaxb.core/plugin.xml</code>.
+ */
+public class JavaElementAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JaxbPlatformDescription.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IJavaElement) {
+ return this.getAdapter((IJavaElement) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IJavaElement javaElement, Class<?> adapterType) {
+ if (adapterType == JaxbPlatformDescription.class) {
+ return javaElement.getResource().getAdapter(JaxbPlatformDescription.class);
+ }
+ return null;
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JaxbPlatformTester.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JaxbPlatformTester.java
deleted file mode 100644
index 6cd7bda963..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/JaxbPlatformTester.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.core.internal;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
-import org.eclipse.jpt.jaxb.core.libprov.JaxbLibraryProviderInstallOperationConfig;
-import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
-import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformGroupDescription;
-
-
-public class JaxbPlatformTester
- extends PropertyTester {
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if (! (property.equals("jaxbPlatform") || property.equals("jaxbPlatformGroup"))
- || ! (expectedValue instanceof String)) { //$NON-NLS-1$
- return false;
- }
-
- JaxbPlatformDescription platform = null;
-
- if (receiver instanceof IResource) {
- platform = platform(((IResource) receiver).getProject());
- }
- else if (receiver instanceof IJavaElement) {
- platform = platform(((IJavaElement) receiver).getResource().getProject());
- }
- else if (receiver instanceof JaxbPlatformDescription) {
- platform = (JaxbPlatformDescription) receiver;
- }
- else if (receiver instanceof JaxbLibraryProviderInstallOperationConfig) {
- platform = ((JaxbLibraryProviderInstallOperationConfig) receiver).getJaxbPlatform();
- }
-
- if (property.equals("jaxbPlatform")) {
- JaxbPlatformDescription otherPlatform = JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatform((String) expectedValue);
- return platform == null ? false : platform.equals(otherPlatform);
- }
- if (property.equals("jaxbPlatformGroup")) {
- JaxbPlatformGroupDescription group = (platform == null) ? null : platform.getGroup();
- JaxbPlatformGroupDescription otherGroup = JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatformGroup((String) expectedValue);
- return group == null ? false : group.equals(otherGroup);
- }
- return false;
- }
-
- private JaxbPlatformDescription platform(IProject project) {
- return (project == null)
- ? null
- : JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatform(JptJaxbCorePlugin.getJaxbPlatformId(project));
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/ResourceAdapterFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/ResourceAdapterFactory.java
new file mode 100644
index 0000000000..85857f5824
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/ResourceAdapterFactory.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
+
+/**
+ * Factory to build Dali adapters for an {@link IResource}:<ul>
+ * <li>{@link JaxbPlatformDescription}
+ * </ul>
+ * See <code>org.eclipse.jpt.jaxb.core/plugin.xml</code>.
+ */
+public class ResourceAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JaxbPlatformDescription.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IResource) {
+ return this.getAdapter((IResource) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IResource resource, Class<?> adapterType) {
+ if (adapterType == JaxbPlatformDescription.class) {
+ return this.getJaxbPlatformDescription(resource);
+ }
+ return null;
+ }
+
+ private JaxbPlatformDescription getJaxbPlatformDescription(IResource resource) {
+ return JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatform(JptJaxbCorePlugin.getJaxbPlatformId(resource.getProject()));
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libprov/JaxbLibraryProviderInstallOperationConfigAdapterFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libprov/JaxbLibraryProviderInstallOperationConfigAdapterFactory.java
new file mode 100644
index 0000000000..0fede72a1b
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/libprov/JaxbLibraryProviderInstallOperationConfigAdapterFactory.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.libprov;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jaxb.core.libprov.JaxbLibraryProviderInstallOperationConfig;
+import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
+
+/**
+ * Factory to build Dali adapters for an {@link JaxbLibraryProviderInstallOperationConfig}:<ul>
+ * <li>{@link JaxbPlatformDescription}
+ * </ul>
+ * See <code>org.eclipse.jpt.jaxb.core/plugin.xml</code>.
+ */
+public class JaxbLibraryProviderInstallOperationConfigAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JaxbPlatformDescription.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof JaxbLibraryProviderInstallOperationConfig) {
+ return this.getAdapter((JaxbLibraryProviderInstallOperationConfig) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(JaxbLibraryProviderInstallOperationConfig config, Class<?> adapterType) {
+ if (adapterType == JaxbPlatformDescription.class) {
+ return config.getJaxbPlatform();
+ }
+ return null;
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/JaxbPlatformTester.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/JaxbPlatformTester.java
new file mode 100644
index 0000000000..599dc4e1ac
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/platform/JaxbPlatformTester.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.platform;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
+import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformGroupDescription;
+
+/**
+ * Property tester for {@link JaxbPlatformDescription}.
+ * See <code>org.eclipse.jpt.jaxb.core/plugin.xml</code>
+ */
+public class JaxbPlatformTester
+ extends PropertyTester
+{
+ public static final String JAXB_PLATFORM = "jaxbPlatform"; //$NON-NLS-1$
+ public static final String JAXB_PLATFORM_GROUP = "jaxbPlatformGroup"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof JaxbPlatformDescription) {
+ return this.test((JaxbPlatformDescription) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(JaxbPlatformDescription platform, String property, Object expectedValue) {
+ if (property.equals(JAXB_PLATFORM)) {
+ JaxbPlatformDescription expected = this.getJaxbPlatform(expectedValue);
+ return Tools.valuesAreEqual(platform, expected);
+ }
+ if (property.equals(JAXB_PLATFORM_GROUP)) {
+ JaxbPlatformGroupDescription expected = this.getJaxbPlatformGroup(expectedValue);
+ return Tools.valuesAreEqual(platform.getGroup(), expected);
+ }
+ return false;
+ }
+
+ private JaxbPlatformDescription getJaxbPlatform(Object id) {
+ return JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatform((String) id);
+ }
+
+ private JaxbPlatformGroupDescription getJaxbPlatformGroup(Object id) {
+ return JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatformGroup((String) id);
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java
new file mode 100644
index 0000000000..82237263e9
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.resource;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.common.core.JptResourceModel;
+import org.eclipse.jpt.common.core.JptResourceModelListener;
+import org.eclipse.jpt.common.utility.internal.ListenerList;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+
+public abstract class AbstractJaxbFileResourceModel<S>
+ implements JptResourceModel
+{
+ protected final IFile file;
+
+ /**
+ * This is <code>null</code> if there is no package name.
+ */
+ protected final String packageName;
+
+ protected final S state;
+
+ protected final ListenerList<JptResourceModelListener> resourceModelListenerList =
+ new ListenerList<JptResourceModelListener>(JptResourceModelListener.class);
+
+
+ protected AbstractJaxbFileResourceModel(IFile file) {
+ super();
+ if (file == null) {
+ throw new NullPointerException();
+ }
+ this.file = file;
+ this.packageName = this.buildPackageName();
+ this.state = this.buildState();
+ this.load();
+ }
+
+ protected String buildPackageName() {
+ String pkg = this.buildPackageName_();
+ return StringTools.stringIsEmpty(pkg) ? null : pkg;
+ }
+
+ protected String buildPackageName_() {
+ IJavaElement javaElement = JavaCore.create(this.file.getParent());
+ if ((javaElement != null) && (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT)) {
+ return ((IPackageFragment) javaElement).getElementName();
+ }
+ return null;
+ }
+
+ protected abstract S buildState();
+
+ public String getPackageName() {
+ return this.packageName;
+ }
+
+ protected void reload() {
+ this.load();
+ }
+
+ protected void load() {
+ InputStream stream = null;
+ try {
+ stream = this.file.getContents();
+ if (stream != null) {
+ this.load(new BufferedInputStream(stream));
+ }
+ } catch (Exception ex) {
+ JptJaxbCorePlugin.log(ex);
+ } finally {
+ this.closeStream(stream);
+ }
+ }
+
+ /**
+ * The specified stream is not <code>null</code>.
+ */
+ protected abstract void load(InputStream stream) throws IOException;
+
+ protected void closeStream(InputStream stream) {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException ex) {
+ JptJaxbCorePlugin.log(ex);
+ }
+ }
+
+ public void update() {
+ this.reload();
+ this.resourceModelChanged();
+ }
+
+
+ // ********** JptResourceModel implementation **********
+
+ public IFile getFile() {
+ return this.file;
+ }
+
+ public void addResourceModelListener(JptResourceModelListener listener) {
+ this.resourceModelListenerList.add(listener);
+ }
+
+ public void removeResourceModelListener(JptResourceModelListener listener) {
+ this.resourceModelListenerList.remove(listener);
+ }
+
+ protected void resourceModelChanged() {
+ for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) {
+ listener.resourceModelChanged(this);
+ }
+ }
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbindex/JaxbIndexResourceImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbindex/JaxbIndexResourceImpl.java
index a1d1335731..4e17fb10e4 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbindex/JaxbIndexResourceImpl.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbindex/JaxbIndexResourceImpl.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jaxb.core.internal.resource.jaxbindex;
@@ -13,131 +13,79 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.List;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.core.JptResourceModelListener;
import org.eclipse.jpt.common.core.JptResourceType;
-import org.eclipse.jpt.common.utility.internal.ListenerList;
-import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.iterables.SnapshotCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+import org.eclipse.jpt.jaxb.core.internal.resource.AbstractJaxbFileResourceModel;
import org.eclipse.jpt.jaxb.core.resource.jaxbindex.JaxbIndexResource;
-
+/**
+ * JAXB index
+ */
public class JaxbIndexResourceImpl
- implements JaxbIndexResource {
-
- protected final ListenerList<JptResourceModelListener> resourceModelListenerList =
- new ListenerList<JptResourceModelListener>(JptResourceModelListener.class);
-
-
- protected IFile file;
-
- protected String packageName;
-
- protected final List<String> classNames = new Vector<String>();
-
-
+ extends AbstractJaxbFileResourceModel<Vector<String>>
+ implements JaxbIndexResource
+{
public JaxbIndexResourceImpl(IFile file) {
- super();
- if (file == null) {
- throw new IllegalArgumentException("file cannot be null");
- }
- this.file = file;
- this.packageName = buildPackageName();
- buildClassNames();
+ super(file);
}
-
-
- protected String buildPackageName() {
- IJavaElement javaElement = JavaCore.create(this.file.getParent());
- if (javaElement != null && javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
- return ((IPackageFragment) javaElement).getElementName();
- }
- return null;
+
+ @Override
+ protected Vector<String> buildState() {
+ return new Vector<String>();
}
-
- private void buildClassNames() {
- InputStream stream = null;
-
- try {
- stream = file.getContents();
- }
- catch (CoreException ce) {
- JptJaxbCorePlugin.log(ce);
- return;
- }
-
- if (stream != null) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
- try {
- String line = reader.readLine();
- while (line != null) {
- String className = line.trim();
- this.classNames.add(className);
- line = reader.readLine();
- }
- }
- catch (Exception ex) {
- JptJaxbCorePlugin.log(ex);
- }
- finally {
- try {
- reader.close();
- }
- catch (IOException ioe) {
- JptJaxbCorePlugin.log(ioe);
- }
- }
- }
+
+ @Override
+ protected void reload() {
+ this.state.clear();
+ super.reload();
}
-
- public String getPackageName() {
- return this.packageName;
+
+ @Override
+ protected void load(InputStream stream) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+ String line = reader.readLine();
+ while (line != null) {
+ this.state.add(line.trim());
+ line = reader.readLine();
+ }
}
-
+
public Iterable<String> getFullyQualifiedClassNames() {
- String packageName = getPackageName();
- final String packagePrefix = StringTools.stringIsEmpty(packageName) ? "" : packageName + ".";
+ return (this.packageName == null) ?
+ this.getSimpleClassNames() :
+ this.getPrefixedClassNames();
+ }
+
+ protected Iterable<String> getSimpleClassNames() {
+ return new SnapshotCloneIterable<String>(this.state);
+ }
+
+ protected Iterable<String> getPrefixedClassNames() {
return new TransformationIterable<String, String>(
- new SnapshotCloneIterable<String>(this.classNames)) {
- @Override
- protected String transform(String shortClassName) {
- return packagePrefix + shortClassName;
- }
- };
+ this.getSimpleClassNames(),
+ new PrefixTransformer(this.packageName + '.')
+ );
}
-
- void update() {
- this.classNames.clear();
- buildClassNames();
- resourceModelChanged();
+
+ protected class PrefixTransformer
+ implements Transformer<String, String>
+ {
+ protected final String prefix;
+ protected PrefixTransformer(String prefix) {
+ super();
+ this.prefix = prefix;
+ }
+ public String transform(String string) {
+ return this.prefix + string;
+ }
}
-
-
- // ********** JptResourceModel implementation **********
-
+
public JptResourceType getResourceType() {
return JptJaxbCorePlugin.JAXB_INDEX_RESOURCE_TYPE;
}
-
- public void addResourceModelListener(JptResourceModelListener listener) {
- this.resourceModelListenerList.add(listener);
- }
-
- public void removeResourceModelListener(JptResourceModelListener listener) {
- this.resourceModelListenerList.remove(listener);
- }
-
- protected void resourceModelChanged() {
- for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) {
- listener.resourceModelChanged(this);
- }
- }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java
index 67a308902b..be6842c4aa 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/jaxbprops/JaxbPropertiesResourceImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,107 +13,43 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.core.JptResourceModelListener;
import org.eclipse.jpt.common.core.JptResourceType;
-import org.eclipse.jpt.common.utility.internal.ListenerList;
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
+import org.eclipse.jpt.jaxb.core.internal.resource.AbstractJaxbFileResourceModel;
import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource;
-
+/**
+ * JAXB index
+ */
public class JaxbPropertiesResourceImpl
+ extends AbstractJaxbFileResourceModel<Properties>
implements JaxbPropertiesResource
{
- protected final IFile file;
-
- protected final String packageName;
-
- protected final Properties properties = new Properties();
-
- protected final ListenerList<JptResourceModelListener> resourceModelListenerList =
- new ListenerList<JptResourceModelListener>(JptResourceModelListener.class);
-
-
public JaxbPropertiesResourceImpl(IFile file) {
- super();
- if (file == null) {
- throw new NullPointerException();
- }
- this.file = file;
- this.packageName = this.buildPackageName();
- this.loadProperties();
- }
-
- protected String buildPackageName() {
- IJavaElement javaElement = JavaCore.create(this.file.getParent());
- if ((javaElement != null) && (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT)) {
- return ((IPackageFragment) javaElement).getElementName();
- }
- return null;
- }
-
- protected void reloadProperties() {
- this.properties.clear();
- this.loadProperties();
+ super(file);
}
- protected void loadProperties() {
- InputStream stream = null;
- try {
- stream = this.file.getContents();
- if (stream != null) {
- this.properties.load(stream);
- }
- } catch (Exception ex) {
- JptJaxbCorePlugin.log(ex);
- } finally {
- this.closeStream(stream);
- }
+ @Override
+ protected Properties buildState() {
+ return new Properties();
}
- protected void closeStream(InputStream stream) {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (IOException ex) {
- JptJaxbCorePlugin.log(ex);
- }
+ @Override
+ protected void reload() {
+ this.state.clear();
+ super.reload();
}
- void update() {
- this.reloadProperties();
- this.resourceModelChanged();
- }
-
- public String getPackageName() {
- return this.packageName;
+ @Override
+ protected void load(InputStream stream) throws IOException {
+ this.state.load(stream);
}
public String getProperty(String propertyName) {
- return this.properties.getProperty(propertyName);
+ return this.state.getProperty(propertyName);
}
-
- // ********** JptResourceModel implementation **********
-
public JptResourceType getResourceType() {
return JptJaxbCorePlugin.JAXB_PROPERTIES_RESOURCE_TYPE;
}
-
- public void addResourceModelListener(JptResourceModelListener listener) {
- this.resourceModelListenerList.add(listener);
- }
-
- public void removeResourceModelListener(JptResourceModelListener listener) {
- this.resourceModelListenerList.remove(listener);
- }
-
- protected void resourceModelChanged() {
- for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) {
- listener.resourceModelChanged(this);
- }
- }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java
index e743b5e569..e22b76e706 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,9 +13,8 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jpt.common.core.IResourcePart;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
@@ -113,11 +112,9 @@ public class JaxbValidator
}
private IMessage adjustMessage(IMessage message) {
- IAdaptable targetObject = (IAdaptable) message.getTargetObject();
- IResource targetResource = ((IResourcePart) targetObject.getAdapter(IResourcePart.class)).getResource();
- message.setTargetObject(targetResource);
+ message.setTargetObject(PlatformTools.getAdapter(message.getTargetObject(), IResource.class));
if (message.getLineNumber() == IMessage.LINENO_UNSET) {
- message.setAttribute(IMarker.LOCATION, " ");
+ message.setAttribute(IMarker.LOCATION, " "); //$NON-NLS-1$
}
return message;
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml
index a4e3f8f9c2..febcbf61d0 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
- Copyright (c) 2011 Oracle. All rights reserved.
+ Copyright (c) 2011, 2012 Oracle. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0, which accompanies this distribution
and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -63,10 +63,14 @@
<enablement>
<and>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="jaxb-user-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="jaxb-user-library-provider"/>
</with>
<with variable="config">
- <test property="org.eclipse.jpt.jaxb.core.jaxbPlatformGroup" value="eclipselink"/>
+ <adapt type = "org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription">
+ <test property="org.eclipse.jpt.jaxb.core.jaxbPlatformGroup"
+ value="eclipselink"/>
+ </adapt>
</with>
</and>
</enablement>
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorItemLabelProviderFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorItemLabelProviderFactory.java
index 547c390161..52d9500cb7 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorItemLabelProviderFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorItemLabelProviderFactory.java
@@ -1,16 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.eclipselink.ui.internal;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
import org.eclipse.jpt.jaxb.ui.internal.jaxb21.GenericJaxb_2_1_NavigatorItemLabelProviderFactory;
@@ -32,14 +31,12 @@ public class ELJaxbNavigatorItemLabelProviderFactory
@Override
- public ItemLabelProvider buildItemLabelProvider(
- Object item,
- DelegatingContentAndLabelProvider contentAndLabelProvider) {
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
if (item instanceof JaxbPersistentAttribute) {
- return new ELJaxbPersistentAttributeItemLabelProvider((JaxbPersistentAttribute) item, contentAndLabelProvider);
+ return new ELJaxbPersistentAttributeItemLabelProvider((JaxbPersistentAttribute) item, manager);
}
- return super.buildItemLabelProvider(item, contentAndLabelProvider);
+ return super.buildProvider(item, manager);
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorUi.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorUi.java
index e8a1573b48..86a9cfa556 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorUi.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbNavigatorUi.java
@@ -1,15 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.eclipselink.ui.internal;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
import org.eclipse.jpt.jaxb.ui.internal.jaxb21.GenericJaxb_2_1_NavigatorUi;
@@ -30,7 +30,7 @@ public class ELJaxbNavigatorUi
@Override
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
+ public ItemExtendedLabelProviderFactory getItemLabelProviderFactory() {
return ELJaxbNavigatorItemLabelProviderFactory.instance();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbPersistentAttributeItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbPersistentAttributeItemLabelProvider.java
index 00999326b7..ea3b47b243 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbPersistentAttributeItemLabelProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.ui/src/org/eclipse/jpt/jaxb/eclipselink/ui/internal/ELJaxbPersistentAttributeItemLabelProvider.java
@@ -1,42 +1,30 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.eclipselink.ui.internal;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
import org.eclipse.jpt.jaxb.ui.internal.jaxb21.JaxbPersistentAttributeItemLabelProvider;
import org.eclipse.swt.graphics.Image;
-public class ELJaxbPersistentAttributeItemLabelProvider
- extends JaxbPersistentAttributeItemLabelProvider {
-
- public ELJaxbPersistentAttributeItemLabelProvider(
- JaxbPersistentAttribute attribute, DelegatingContentAndLabelProvider labelProvider) {
- super(attribute, labelProvider);
+public class ELJaxbPersistentAttributeItemLabelProvider
+ extends JaxbPersistentAttributeItemLabelProvider
+{
+ public ELJaxbPersistentAttributeItemLabelProvider(JaxbPersistentAttribute attribute, ItemLabelProvider.Manager manager) {
+ super(attribute, manager);
}
@Override
- protected PropertyValueModel<Image> buildImageModel() {
-
- return new PropertyAspectAdapter<JaxbPersistentAttribute, Image>(
- new String[] {JaxbPersistentAttribute.DEFAULT_MAPPING_KEY_PROPERTY, JaxbPersistentAttribute.MAPPING_PROPERTY},
- getModel()) {
-
- @Override
- protected Image buildValue_() {
- return ELJaxbMappingImageHelper.imageForAttributeMapping(this.subject.getMappingKey());
- }
- };
+ protected Image buildImage(String mappingKey) {
+ return ELJaxbMappingImageHelper.imageForAttributeMapping(mappingKey);
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
index 65970846fd..46deb25170 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/plugin.xml
@@ -122,7 +122,7 @@
icon="icons/full/obj16/jaxb_content.gif"
activeByDefault="true"
contentProvider="org.eclipse.jpt.jaxb.ui.internal.navigator.JaxbNavigatorContentProvider"
- labelProvider="org.eclipse.jpt.jaxb.ui.internal.navigator.JaxbNavigatorLabelProvider">
+ labelProvider="org.eclipse.jpt.common.ui.internal.jface.NavigatorLabelProvider">
<triggerPoints>
<or>
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java
index 9a8fb04f8e..3870640f37 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -120,7 +120,7 @@ public class JaxbJavaCompletionProposalComputer
// the context's "token" is really a sort of "prefix" - it does NOT
// correspond to the "start" and "end" we get below...
char[] prefix = cc.getToken();
- Filter<String> filter = ((prefix == null) ? Filter.Null.<String>instance() : new IgnoreCasePrefixFilter(prefix));
+ Filter<String> filter = ((prefix == null) ? Filter.Transparent.<String>instance() : new IgnoreCasePrefixFilter(prefix));
// the token "start" is the offset of the token's first character
int tokenStart = cc.getTokenStart();
// the token "end" is the offset of the token's last character (yuk)
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorItemLabelProviderFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorItemLabelProviderFactory.java
index 7e6c6bb8a3..58bc367db3 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorItemLabelProviderFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorItemLabelProviderFactory.java
@@ -1,27 +1,30 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
import org.eclipse.jpt.jaxb.core.context.JaxbClass;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
import org.eclipse.jpt.jaxb.core.context.JaxbEnum;
import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
+import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
+import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
+import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
public class GenericJaxb_2_1_NavigatorItemLabelProviderFactory
- implements ItemLabelProviderFactory {
+ implements ItemExtendedLabelProviderFactory {
private static GenericJaxb_2_1_NavigatorItemLabelProviderFactory INSTANCE;
@@ -39,28 +42,65 @@ public class GenericJaxb_2_1_NavigatorItemLabelProviderFactory
}
- public ItemLabelProvider buildItemLabelProvider(
- Object item,
- DelegatingContentAndLabelProvider contentAndLabelProvider) {
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
if (item instanceof JaxbContextRoot) {
- return new JaxbContextRootItemLabelProvider((JaxbContextRoot) item, contentAndLabelProvider);
+ return this.buildJaxbContextRootProvider((JaxbContextRoot) item, manager);
}
else if (item instanceof JaxbPackage) {
- return new JaxbPackageItemLabelProvider((JaxbPackage) item, contentAndLabelProvider);
+ return this.buildJaxbPackageProvider((JaxbPackage) item, manager);
}
else if (item instanceof JaxbClass) {
- return new JaxbClassItemLabelProvider((JaxbClass) item, contentAndLabelProvider);
+ return new JaxbClassItemLabelProvider((JaxbClass) item, manager);
}
else if (item instanceof JaxbEnum) {
- return new JaxbEnumItemLabelProvider((JaxbEnum) item, contentAndLabelProvider);
+ return new JaxbEnumItemLabelProvider((JaxbEnum) item, manager);
}
else if (item instanceof JaxbPersistentAttribute) {
- return new JaxbPersistentAttributeItemLabelProvider((JaxbPersistentAttribute) item, contentAndLabelProvider);
+ return new JaxbPersistentAttributeItemLabelProvider((JaxbPersistentAttribute) item, manager);
}
else if (item instanceof JaxbEnumConstant) {
- return new JaxbEnumConstantItemLabelProvider((JaxbEnumConstant) item, contentAndLabelProvider);
+ return this.buildJaxbEnumConstantProvider((JaxbEnumConstant) item, manager);
}
return null;
}
+
+ protected ItemExtendedLabelProvider buildJaxbContextRootProvider(JaxbContextRoot root, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return new StaticItemExtendedLabelProvider(
+ JptJaxbUiPlugin.getImage(JptJaxbUiIcons.JAXB_CONTENT),
+ JptJaxbUiMessages.JaxbContent_label,
+ this.buildJaxbContextRootDescription(root)
+ );
+ }
+
+ protected String buildJaxbContextRootDescription(JaxbContextRoot root) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(JptJaxbUiMessages.JaxbContent_label);
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(root.getResource().getFullPath().makeRelative());
+ return sb.toString();
+ }
+
+ protected ItemExtendedLabelProvider buildJaxbEnumConstantProvider(JaxbEnumConstant enumConstant, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return new StaticItemExtendedLabelProvider(
+ JptJaxbUiPlugin.getImage(JptJaxbUiIcons.ENUM_CONSTANT),
+ enumConstant.getName()
+ );
+ }
+
+ protected ItemExtendedLabelProvider buildJaxbPackageProvider(JaxbPackage pkg, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return new StaticItemExtendedLabelProvider(
+ JptJaxbUiPlugin.getImage(JptJaxbUiIcons.PACKAGE),
+ pkg.getName(),
+ this.buildJaxbPackageDescription(pkg)
+ );
+ }
+
+ protected String buildJaxbPackageDescription(JaxbPackage pkg) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(pkg.getName());
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(pkg.getResource().getFullPath().makeRelative());
+ return sb.toString();
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory.java
index 57a6265e1a..52c3fa79e9 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory.java
@@ -1,62 +1,72 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
import org.eclipse.jpt.jaxb.core.context.JaxbClass;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
import org.eclipse.jpt.jaxb.core.context.JaxbEnum;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
-
+/**
+ *
+ */
public class GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory
- implements TreeItemContentProviderFactory {
-
- private static GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory INSTANCE;
-
-
- public static GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory instance() {
- if (INSTANCE == null) {
- INSTANCE = new GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory();
- }
+ implements ItemTreeContentProviderFactory
+{
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
return INSTANCE;
}
-
-
- private GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory() {
+
+
+ protected GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory() {
super();
}
-
-
- public TreeItemContentProvider buildItemContentProvider(
- Object item,
- DelegatingContentAndLabelProvider contentAndLabelProvider) {
-
- DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider =
- (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider;
-
+
+ public ItemTreeContentProvider buildProvider(Object item, Manager manager) {
if (item instanceof JaxbContextRoot) {
- return new JaxbContextRootItemContentProvider((JaxbContextRoot) item, treeContentAndLabelProvider);
+ return this.buildJaxbContextRootProvider((JaxbContextRoot) item, manager);
}
- else if (item instanceof JaxbPackage) {
- return new JaxbPackageItemContentProvider((JaxbPackage) item, treeContentAndLabelProvider);
+ if (item instanceof JaxbPackage) {
+ return this.buildJaxbPackageProvider((JaxbPackage) item, manager);
}
- else if (item instanceof JaxbClass) {
- return new JaxbClassItemContentProvider((JaxbClass) item, treeContentAndLabelProvider);
+ if (item instanceof JaxbClass) {
+ return this.buildJaxbClassProvider((JaxbClass) item, manager);
}
- else if (item instanceof JaxbEnum) {
- return new JaxbEnumItemContentProvider((JaxbEnum) item, treeContentAndLabelProvider);
+ if (item instanceof JaxbEnum) {
+ return this.buildJaxbEnumProvider((JaxbEnum) item, manager);
}
return null;
}
+
+ protected ItemTreeContentProvider buildJaxbContextRootProvider(JaxbContextRoot item, Manager manager) {
+ return new JaxbContextRootItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildJaxbPackageProvider(JaxbPackage item, Manager manager) {
+ return new JaxbPackageItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildJaxbClassProvider(JaxbClass item, Manager manager) {
+ return new JaxbClassItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildJaxbEnumProvider(JaxbEnum item, Manager manager) {
+ return new JaxbEnumItemContentProvider(item, manager);
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorUi.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorUi.java
index 175f5e6d0d..d0481c87f5 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorUi.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/GenericJaxb_2_1_NavigatorUi.java
@@ -1,16 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
import org.eclipse.jpt.jaxb.ui.navigator.JaxbNavigatorUi;
@@ -33,11 +33,11 @@ public class GenericJaxb_2_1_NavigatorUi
}
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
+ public ItemTreeContentProviderFactory getTreeItemContentProviderFactory() {
return GenericJaxb_2_1_NavigatorTreeItemContentProviderFactory.instance();
}
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
+ public ItemExtendedLabelProviderFactory getItemLabelProviderFactory() {
return GenericJaxb_2_1_NavigatorItemLabelProviderFactory.instance();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemContentProvider.java
index 28e2566077..cbf6b8e38f 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemContentProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemContentProvider.java
@@ -1,16 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
@@ -23,22 +22,16 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
public class JaxbClassItemContentProvider
- extends AbstractTreeItemContentProvider<JaxbPersistentAttribute> {
+ extends AbstractItemTreeContentProvider<JaxbClass, JaxbPersistentAttribute>
+{
- public JaxbClassItemContentProvider(
- JaxbClass jaxbClass, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(jaxbClass, contentProvider);
+ public JaxbClassItemContentProvider(JaxbClass jaxbClass, Manager manager) {
+ super(jaxbClass, manager);
}
- @Override
- public JaxbClass getModel() {
- return (JaxbClass) super.getModel();
- }
-
- @Override
public JaxbContextRoot getParent() {
- return (JaxbContextRoot) getModel().getParent();
+ return (JaxbContextRoot) this.item.getParent();
}
@Override
@@ -50,7 +43,7 @@ public class JaxbClassItemContentProvider
}
protected PropertyValueModel<JaxbClassMapping> buildMappingModel() {
- return new PropertyAspectAdapter<JaxbClass, JaxbClassMapping>(JaxbClass.MAPPING_PROPERTY, getModel()) {
+ return new PropertyAspectAdapter<JaxbClass, JaxbClassMapping>(JaxbClass.MAPPING_PROPERTY, this.item) {
@Override
protected JaxbClassMapping buildValue_() {
return this.subject.getMapping();
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemLabelProvider.java
index bfb87c8d68..1b5db6e35c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemLabelProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbClassItemLabelProvider.java
@@ -1,15 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
@@ -18,29 +18,24 @@ import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jaxb.core.context.JaxbClass;
import org.eclipse.jpt.jaxb.core.context.JaxbClassMapping;
+import org.eclipse.jpt.jaxb.core.context.JaxbType;
+import org.eclipse.jpt.jaxb.core.context.JaxbTypeMapping;
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
import org.eclipse.swt.graphics.Image;
public class JaxbClassItemLabelProvider
- extends JaxbTypeItemLabelProvider {
+ extends JaxbTypeItemLabelProvider<JaxbClass>
+{
- public JaxbClassItemLabelProvider(
- JaxbClass jaxbPersistentClass, DelegatingContentAndLabelProvider labelProvider) {
-
- super(jaxbPersistentClass, labelProvider);
- }
-
-
- @Override
- public JaxbClass getModel() {
- return (JaxbClass) super.getModel();
+ public JaxbClassItemLabelProvider(JaxbClass jaxbPersistentClass, ItemLabelProvider.Manager manager) {
+ super(jaxbPersistentClass, manager);
}
@Override
protected PropertyValueModel<Image> buildImageModel() {
- return new JaxbClassImageModel(getModel());
+ return new JaxbClassImageModel(this.item);
}
@@ -57,7 +52,7 @@ public class JaxbClassItemLabelProvider
public JaxbClassImageModel(JaxbClass subject) {
- super(new StaticPropertyValueModel(subject));
+ super(new StaticPropertyValueModel<JaxbClass>(subject));
this.isXmlRegistryModel = buildIsXmlRegistryModel();
this.mappingModel = buildMappingModel();
this.isXmlTransientModel = buildIsXmlTransientModel();
@@ -66,16 +61,16 @@ public class JaxbClassItemLabelProvider
protected PropertyValueModel<Boolean> buildIsXmlRegistryModel() {
- return new PropertyAspectAdapter<JaxbClass, Boolean>(JaxbClass.XML_REGISTRY_PROPERTY, JaxbClassItemLabelProvider.this.getModel()) {
+ return new PropertyAspectAdapter<JaxbClass, Boolean>(JaxbClass.XML_REGISTRY_PROPERTY, JaxbClassItemLabelProvider.this.item) {
@Override
protected Boolean buildValue_() {
- return this.subject.getXmlRegistry() != null;
+ return Boolean.valueOf(this.subject.getXmlRegistry() != null);
}
};
}
protected PropertyValueModel<JaxbClassMapping> buildMappingModel() {
- return new PropertyAspectAdapter<JaxbClass, JaxbClassMapping> (JaxbClass.MAPPING_PROPERTY, JaxbClassItemLabelProvider.this.getModel()) {
+ return new PropertyAspectAdapter<JaxbClass, JaxbClassMapping> (JaxbType.MAPPING_PROPERTY, JaxbClassItemLabelProvider.this.item) {
@Override
protected JaxbClassMapping buildValue_() {
return this.subject.getMapping();
@@ -84,10 +79,10 @@ public class JaxbClassItemLabelProvider
}
protected PropertyValueModel<Boolean> buildIsXmlTransientModel() {
- return new PropertyAspectAdapter<JaxbClassMapping, Boolean>(this.mappingModel, JaxbClassMapping.XML_TRANSIENT_PROPERTY) {
+ return new PropertyAspectAdapter<JaxbClassMapping, Boolean>(this.mappingModel, JaxbTypeMapping.XML_TRANSIENT_PROPERTY) {
@Override
protected Boolean buildValue_() {
- return this.subject.isXmlTransient();
+ return Boolean.valueOf(this.subject.isXmlTransient());
}
};
}
@@ -96,7 +91,7 @@ public class JaxbClassItemLabelProvider
// transform the subject's property change events into VALUE property change events
return new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent event) {
- JaxbClassImageModel.this.propertyChanged();
+ JaxbClassImageModel.this.aspectChanged();
}
};
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemContentProvider.java
index 4f6a013de8..b0894be526 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemContentProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemContentProvider.java
@@ -1,17 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
@@ -19,29 +18,22 @@ import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
public class JaxbContextRootItemContentProvider
- extends AbstractTreeItemContentProvider<JaxbPackage> {
+ extends AbstractItemTreeContentProvider<JaxbContextRoot, JaxbPackage> {
- public JaxbContextRootItemContentProvider(
- JaxbContextRoot rootContext, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(rootContext, contentProvider);
+ public JaxbContextRootItemContentProvider(JaxbContextRoot rootContext, Manager manager) {
+ super(rootContext, manager);
}
- @Override
- public JaxbContextRoot getModel() {
- return (JaxbContextRoot) super.getModel();
- }
-
- @Override
public IProject getParent() {
- return getModel().getJaxbProject().getProject();
+ return item.getJaxbProject().getProject();
}
@Override
protected CollectionValueModel<JaxbPackage> buildChildrenModel() {
return new CollectionAspectAdapter<JaxbContextRoot, JaxbPackage>(
JaxbContextRoot.PACKAGES_COLLECTION,
- getModel()) {
+ this.item) {
@Override
protected Iterable<JaxbPackage> getIterable() {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemLabelProvider.java
deleted file mode 100644
index 1fa5c4e31d..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbContextRootItemLabelProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
-import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
-import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
-import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages;
-import org.eclipse.swt.graphics.Image;
-
-
-public class JaxbContextRootItemLabelProvider
- extends AbstractItemLabelProvider {
-
- public JaxbContextRootItemLabelProvider(
- JaxbContextRoot rootContextNode, DelegatingContentAndLabelProvider labelProvider) {
-
- super(rootContextNode, labelProvider);
- }
-
-
- @Override
- public JaxbContextRoot getModel() {
- return (JaxbContextRoot) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJaxbUiPlugin.getImage(JptJaxbUiIcons.JAXB_CONTENT));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(JptJaxbUiMessages.JaxbContent_label);
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(JptJaxbUiMessages.JaxbContent_label);
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumConstantItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumConstantItemLabelProvider.java
deleted file mode 100644
index 0a839f0d08..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumConstantItemLabelProvider.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant;
-import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
-import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
-import org.eclipse.swt.graphics.Image;
-
-
-public class JaxbEnumConstantItemLabelProvider
- extends AbstractItemLabelProvider {
-
- public JaxbEnumConstantItemLabelProvider(
- JaxbEnumConstant jaxbEnumConstant, DelegatingContentAndLabelProvider labelProvider) {
-
- super(jaxbEnumConstant, labelProvider);
- }
-
-
- @Override
- public JaxbEnumConstant getModel() {
- return (JaxbEnumConstant) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJaxbUiPlugin.getImage(JptJaxbUiIcons.ENUM_CONSTANT));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(getModel().getName());
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- return new StaticPropertyValueModel<String>(getModel().getName());
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemContentProvider.java
index 8ada32297a..9c25e9a1da 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemContentProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemContentProvider.java
@@ -1,16 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
@@ -19,30 +18,23 @@ import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
import org.eclipse.jpt.jaxb.core.context.JaxbEnum;
import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant;
import org.eclipse.jpt.jaxb.core.context.JaxbEnumMapping;
+import org.eclipse.jpt.jaxb.core.context.JaxbType;
public class JaxbEnumItemContentProvider
- extends AbstractTreeItemContentProvider<JaxbEnumConstant> {
+ extends AbstractItemTreeContentProvider<JaxbEnum, JaxbEnumConstant> {
- public JaxbEnumItemContentProvider(
- JaxbEnum jaxbEnum, DelegatingTreeContentAndLabelProvider contentProvider) {
-
- super(jaxbEnum, contentProvider);
+ public JaxbEnumItemContentProvider(JaxbEnum jaxbEnum, Manager manager) {
+ super(jaxbEnum, manager);
}
- @Override
- public JaxbEnum getModel() {
- return (JaxbEnum) super.getModel();
- }
-
- @Override
public JaxbContextRoot getParent() {
- return (JaxbContextRoot) getModel().getParent();
+ return (JaxbContextRoot) this.item.getParent();
}
protected PropertyValueModel<JaxbEnumMapping> buildMappingModel() {
- return new PropertyAspectAdapter<JaxbEnum, JaxbEnumMapping>(JaxbEnum.MAPPING_PROPERTY, getModel()) {
+ return new PropertyAspectAdapter<JaxbEnum, JaxbEnumMapping>(JaxbType.MAPPING_PROPERTY, this.item) {
@Override
protected JaxbEnumMapping buildValue_() {
return this.subject.getMapping();
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemLabelProvider.java
index 8dbdacd834..40a36bffb2 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemLabelProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbEnumItemLabelProvider.java
@@ -1,15 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
@@ -18,28 +18,23 @@ import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jaxb.core.context.JaxbEnum;
import org.eclipse.jpt.jaxb.core.context.JaxbEnumMapping;
+import org.eclipse.jpt.jaxb.core.context.JaxbType;
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
import org.eclipse.swt.graphics.Image;
public class JaxbEnumItemLabelProvider
- extends JaxbTypeItemLabelProvider {
+ extends JaxbTypeItemLabelProvider<JaxbEnum>
+{
- public JaxbEnumItemLabelProvider(
- JaxbEnum jaxbEnum, DelegatingContentAndLabelProvider labelProvider) {
- super(jaxbEnum, labelProvider);
- }
-
-
- @Override
- public JaxbEnum getModel() {
- return (JaxbEnum) super.getModel();
+ public JaxbEnumItemLabelProvider(JaxbEnum jaxbEnum, ItemLabelProvider.Manager manager) {
+ super(jaxbEnum, manager);
}
@Override
protected PropertyValueModel<Image> buildImageModel() {
- return new JaxbEnumImageModel(getModel());
+ return new JaxbEnumImageModel(this.item);
}
@@ -54,7 +49,7 @@ public class JaxbEnumItemLabelProvider
public JaxbEnumImageModel(JaxbEnum subject) {
- super(new StaticPropertyValueModel(subject));
+ super(new StaticPropertyValueModel<JaxbEnum>(subject));
this.mappingModel = buildMappingModel();
this.isXmlTransientModel = buildIsXmlTransientModel();
this.propertyChangeListener = buildPropertyChangeListener();
@@ -62,7 +57,7 @@ public class JaxbEnumItemLabelProvider
protected PropertyValueModel<JaxbEnumMapping> buildMappingModel() {
- return new PropertyAspectAdapter<JaxbEnum, JaxbEnumMapping> (JaxbEnum.MAPPING_PROPERTY, JaxbEnumItemLabelProvider.this.getModel()) {
+ return new PropertyAspectAdapter<JaxbEnum, JaxbEnumMapping> (JaxbType.MAPPING_PROPERTY, JaxbEnumItemLabelProvider.this.item) {
@Override
protected JaxbEnumMapping buildValue_() {
return this.subject.getMapping();
@@ -74,7 +69,7 @@ public class JaxbEnumItemLabelProvider
return new PropertyAspectAdapter<JaxbEnumMapping, Boolean>(this.mappingModel, JaxbEnumMapping.XML_TRANSIENT_PROPERTY) {
@Override
protected Boolean buildValue_() {
- return this.subject.isXmlTransient();
+ return Boolean.valueOf(this.subject.isXmlTransient());
}
};
}
@@ -83,7 +78,7 @@ public class JaxbEnumItemLabelProvider
// transform the subject's property change events into VALUE property change events
return new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent event) {
- JaxbEnumImageModel.this.propertyChanged();
+ JaxbEnumImageModel.this.aspectChanged();
}
};
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemContentProvider.java
index 620c6e783e..37fc82362f 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemContentProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemContentProvider.java
@@ -1,16 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
@@ -19,23 +18,15 @@ import org.eclipse.jpt.jaxb.core.context.JaxbType;
public class JaxbPackageItemContentProvider
- extends AbstractTreeItemContentProvider<JaxbType> {
+ extends AbstractItemTreeContentProvider<JaxbPackage, JaxbType> {
- public JaxbPackageItemContentProvider(
- JaxbPackage jaxbPackage, DelegatingTreeContentAndLabelProvider contentProvider) {
-
- super(jaxbPackage, contentProvider);
+ public JaxbPackageItemContentProvider(JaxbPackage jaxbPackage, Manager manager) {
+ super(jaxbPackage, manager);
}
- @Override
- public JaxbPackage getModel() {
- return (JaxbPackage) super.getModel();
- }
-
- @Override
public JaxbContextRoot getParent() {
- return (JaxbContextRoot) getModel().getParent();
+ return (JaxbContextRoot) this.item.getParent();
}
@Override
@@ -44,7 +35,7 @@ public class JaxbPackageItemContentProvider
JaxbContextRoot.TYPES_COLLECTION, getParent()) {
@Override
protected Iterable<JaxbType> getIterable() {
- return this.subject.getTypes(getModel());
+ return this.subject.getTypes(JaxbPackageItemContentProvider.this.item);
}
};
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemLabelProvider.java
deleted file mode 100644
index a275cb7634..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPackageItemLabelProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
-import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
-import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons;
-import org.eclipse.swt.graphics.Image;
-
-
-public class JaxbPackageItemLabelProvider
- extends AbstractItemLabelProvider {
-
- public JaxbPackageItemLabelProvider(
- JaxbPackage jaxbPackage, DelegatingContentAndLabelProvider labelProvider) {
-
- super(jaxbPackage, labelProvider);
- }
-
- @Override
- public JaxbPackage getModel() {
- return (JaxbPackage) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJaxbUiPlugin.getImage(JptJaxbUiIcons.PACKAGE));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(getModel().getName());
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(getModel().getName());
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPersistentAttributeItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPersistentAttributeItemLabelProvider.java
index d314f2dd87..0c1ee41d75 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPersistentAttributeItemLabelProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbPersistentAttributeItemLabelProvider.java
@@ -1,18 +1,17 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute;
import org.eclipse.jpt.jaxb.ui.internal.JaxbMappingImageHelper;
@@ -20,45 +19,57 @@ import org.eclipse.swt.graphics.Image;
public class JaxbPersistentAttributeItemLabelProvider
- extends AbstractItemLabelProvider {
+ extends AbstractItemExtendedLabelProvider<JaxbPersistentAttribute>
+{
+ protected final String text;
+ protected final String description;
- public JaxbPersistentAttributeItemLabelProvider(
- JaxbPersistentAttribute attribute, DelegatingContentAndLabelProvider labelProvider) {
-
- super(attribute, labelProvider);
- }
-
-
- @Override
- public JaxbPersistentAttribute getModel() {
- return (JaxbPersistentAttribute) super.getModel();
+ public JaxbPersistentAttributeItemLabelProvider(JaxbPersistentAttribute attribute, ItemLabelProvider.Manager manager) {
+ super(attribute, manager);
+ this.text = this.buildText();
+ this.description = this.buildDescription();
}
@Override
protected PropertyValueModel<Image> buildImageModel() {
- return new PropertyAspectAdapter<JaxbPersistentAttribute, Image>(
- new String[] {JaxbPersistentAttribute.DEFAULT_MAPPING_KEY_PROPERTY, JaxbPersistentAttribute.MAPPING_PROPERTY},
- getModel()) {
+ return new PropertyAspectAdapter<JaxbPersistentAttribute, Image>(IMAGE_ASPECT_NAMES, this.item) {
@Override
protected Image buildValue_() {
- return JaxbMappingImageHelper.imageForAttributeMapping(this.subject.getMappingKey());
+ return JaxbPersistentAttributeItemLabelProvider.this.buildImage(this.subject.getMappingKey());
}
};
}
-
+
+ protected Image buildImage(String mappingKey) {
+ return JaxbMappingImageHelper.imageForAttributeMapping(mappingKey);
+ }
+
+ protected static final String[] IMAGE_ASPECT_NAMES = new String[] {
+ JaxbPersistentAttribute.DEFAULT_MAPPING_KEY_PROPERTY,
+ JaxbPersistentAttribute.MAPPING_PROPERTY
+ };
+
@Override
- protected PropertyValueModel<String> buildTextModel() {
+ public String getText() {
+ return this.text;
+ }
+
+ protected String buildText() {
StringBuffer sb = new StringBuffer();
- if (getModel().isInherited()) {
- sb.append(getModel().getDeclaringJavaResourceType().getName());
+ if (this.item.isInherited()) {
+ sb.append(this.item.getDeclaringJavaResourceType().getName());
sb.append('.');
}
- sb.append(getModel().getName());
- return new StaticPropertyValueModel<String>(sb.toString());
+ sb.append(this.item.getName());
+ return sb.toString();
}
@Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- return new StaticPropertyValueModel<String>(getModel().getName());
+ public String getDescription() {
+ return this.description;
+ }
+
+ protected String buildDescription() {
+ return this.item.getName();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbRegistryItemContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbRegistryItemContentProvider.java
deleted file mode 100644
index 846e5b97e2..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbRegistryItemContentProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
-import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod;
-import org.eclipse.jpt.jaxb.core.context.XmlRegistry;
-
-
-public class JaxbRegistryItemContentProvider
- extends AbstractTreeItemContentProvider<JaxbElementFactoryMethod> {
-
- public JaxbRegistryItemContentProvider(
- XmlRegistry jaxbRegistry, DelegatingTreeContentAndLabelProvider contentProvider) {
-
- super(jaxbRegistry, contentProvider);
- }
-
-
- @Override
- public XmlRegistry getModel() {
- return (XmlRegistry) super.getModel();
- }
-
- @Override
- public JaxbContextRoot getParent() {
- return (JaxbContextRoot) getModel().getParent();
- }
-
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbTypeItemLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbTypeItemLabelProvider.java
index c97eb44550..e08db985c7 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbTypeItemLabelProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/jaxb21/JaxbTypeItemLabelProvider.java
@@ -1,46 +1,50 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.jaxb21;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.jaxb.core.context.JaxbType;
-public abstract class JaxbTypeItemLabelProvider
- extends AbstractItemLabelProvider {
+public abstract class JaxbTypeItemLabelProvider<I extends JaxbType>
+ extends AbstractItemExtendedLabelProvider<I>
+{
+ protected final String text;
+ protected final String description;
- protected JaxbTypeItemLabelProvider(
- JaxbType jaxbType, DelegatingContentAndLabelProvider labelProvider) {
-
- super(jaxbType, labelProvider);
+ protected JaxbTypeItemLabelProvider(I jaxbType, ItemLabelProvider.Manager manager) {
+ super(jaxbType, manager);
+ this.text = this.buildText();
+ this.description = this.buildDescription();
}
-
+
@Override
- public JaxbType getModel() {
- return (JaxbType) super.getModel();
+ public String getText() {
+ return this.text;
}
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(getModel().getTypeQualifiedName());
+ protected String buildText() {
+ return this.item.getTypeQualifiedName();
}
@Override
- protected PropertyValueModel<String> buildDescriptionModel() {
+ public String getDescription() {
+ return this.description;
+ }
+
+ protected String buildDescription() {
StringBuilder sb = new StringBuilder();
- sb.append(getModel().getFullyQualifiedName());
+ sb.append(this.item.getFullyQualifiedName());
sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
+ sb.append(this.item.getResource().getFullPath().makeRelative());
+ return sb.toString();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentAndLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentAndLabelProvider.java
deleted file mode 100644
index c4844b218a..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentAndLabelProvider.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.ui.internal.navigator;
-
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-
-
-public class JaxbNavigatorContentAndLabelProvider
- extends DelegatingTreeContentAndLabelProvider {
-
- public JaxbNavigatorContentAndLabelProvider() {
- super(new JaxbNavigatorTreeItemContentProviderFactory(), new JaxbNavigatorItemLabelProviderFactory());
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentProvider.java
index e23922e219..134eb9fd1a 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorContentProvider.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.navigator;
import org.eclipse.core.resources.IProject;
@@ -18,6 +17,9 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jpt.common.ui.internal.jface.NavigatorContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
@@ -29,9 +31,6 @@ import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
import org.eclipse.jpt.jaxb.ui.platform.JaxbPlatformUi;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.navigator.ICommonContentExtensionSite;
-import org.eclipse.ui.navigator.ICommonContentProvider;
/**
* This extension of navigator content provider delegates to the platform UI
@@ -44,10 +43,8 @@ import org.eclipse.ui.navigator.ICommonContentProvider;
* platform UI implementation.
*/
public class JaxbNavigatorContentProvider
- implements ICommonContentProvider {
-
- private JaxbNavigatorContentAndLabelProvider delegate;
-
+ extends NavigatorContentProvider
+{
private final CollectionChangeListener jaxbProjectListener;
private StructuredViewer viewer;
@@ -63,46 +60,24 @@ public class JaxbNavigatorContentProvider
return new JaxbProjectListener();
}
- public JaxbNavigatorContentAndLabelProvider getDelegate() {
- return this.delegate;
+ @Override
+ protected ItemTreeContentProviderFactory buildItemContentProviderFactory() {
+ return new JaxbNavigatorTreeItemContentProviderFactory();
}
-
-
- // **************** IContentProvider implementation ************************
-
- public void dispose() {
- JptJaxbCorePlugin.getProjectManager().removeCollectionChangeListener(JaxbProjectManager.JAXB_PROJECTS_COLLECTION, this.jaxbProjectListener);
- if (this.delegate != null) {
- this.delegate.dispose();
- }
+
+ @Override
+ protected ItemExtendedLabelProviderFactory buildItemLabelProviderFactory() {
+ return new JaxbNavigatorItemLabelProviderFactory();
}
-
+
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (this.delegate != null) {
- this.delegate.inputChanged(viewer, oldInput, newInput);
- }
+ super.inputChanged(viewer, oldInput, newInput);
this.viewer = (StructuredViewer) viewer;
}
-
- // **************** IStructuredContentProvider implementation **************
-
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
-
- // **************** ITreeContentProvider implementation ********************
-
- public Object getParent(Object element) {
- if (this.delegate != null) {
- return this.delegate.getParent(element);
- }
-
- return null;
- }
-
- public boolean hasChildren(Object element) {
+ @Override
+ protected boolean hasChildren_(Object element) {
if (element instanceof IAdaptable) {
IProject project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
@@ -117,15 +92,11 @@ public class JaxbNavigatorContentProvider
}
}
}
-
- if (this.delegate != null) {
- return this.delegate.hasChildren(element);
- }
-
return false;
}
-
- public Object[] getChildren(Object parentElement) {
+
+ @Override
+ protected Object[] getChildren_(Object parentElement) {
if (parentElement instanceof IAdaptable) {
IProject project = (IProject) ((IAdaptable) parentElement).getAdapter(IProject.class);
@@ -142,44 +113,19 @@ public class JaxbNavigatorContentProvider
}
}
}
-
- if (this.delegate != null) {
- return this.delegate.getChildren(parentElement);
- }
-
- return new Object[0];
- }
-
-
- // **************** IMementoAware implementation ***************************
-
- public void saveState(IMemento memento) {
- // no op
- }
-
- public void restoreState(IMemento memento) {
- // no op
+ return null;
}
-
- // **************** ICommonContentProvider implementation ******************
-
- public void init(ICommonContentExtensionSite config) {
- if (this.delegate == null) {
- JaxbNavigatorLabelProvider labelProvider = (JaxbNavigatorLabelProvider) config.getExtension().getLabelProvider();
- if (labelProvider != null && labelProvider.getDelegate() != null) {
- this.delegate = labelProvider.getDelegate();
- }
- else {
- this.delegate = new JaxbNavigatorContentAndLabelProvider();
- }
- }
+ @Override
+ public void dispose() {
+ super.dispose();
+ JptJaxbCorePlugin.getProjectManager().removeCollectionChangeListener(JaxbProjectManager.JAXB_PROJECTS_COLLECTION, this.jaxbProjectListener);
}
// **************** member classes *****************************************
- private class JaxbProjectListener
+ /* CU private */ class JaxbProjectListener
implements CollectionChangeListener
{
public void collectionChanged(CollectionChangeEvent event) {
@@ -222,9 +168,7 @@ public class JaxbNavigatorContentProvider
return Status.OK_STATUS;
}
};
- if (project != null) {
- refreshJob.setRule(project);
- }
+ refreshJob.setRule(project);
refreshJob.schedule();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorItemLabelProviderFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorItemLabelProviderFactory.java
index ee3b2cbeb3..fe25b2d926 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorItemLabelProviderFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorItemLabelProviderFactory.java
@@ -1,9 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -12,16 +12,15 @@ package org.eclipse.jpt.jaxb.ui.internal.navigator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
import org.eclipse.jpt.jaxb.ui.platform.JaxbPlatformUi;
public class JaxbNavigatorItemLabelProviderFactory
- implements ItemLabelProviderFactory {
+ implements ItemExtendedLabelProviderFactory {
/**
* Exactly *one* of these factories is created for each view that utilizes it.
@@ -31,24 +30,23 @@ public class JaxbNavigatorItemLabelProviderFactory
*
* Key: platform description, Value: delegate content provider factory
*/
- private final Map<JaxbPlatformDescription, ItemLabelProviderFactory> delegates;
+ private final Map<JaxbPlatformDescription, ItemExtendedLabelProviderFactory> delegates = new HashMap<JaxbPlatformDescription, ItemExtendedLabelProviderFactory>();
public JaxbNavigatorItemLabelProviderFactory() {
super();
- this.delegates = new HashMap<JaxbPlatformDescription, ItemLabelProviderFactory>();
}
- public ItemLabelProvider buildItemLabelProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- ItemLabelProviderFactory delegate = getDelegate(item);
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ ItemExtendedLabelProviderFactory delegate = getDelegate(item);
if (delegate != null) {
- return delegate.buildItemLabelProvider(item, contentAndLabelProvider);
+ return delegate.buildProvider(item, manager);
}
return null;
}
- private ItemLabelProviderFactory getDelegate(Object element) {
+ private ItemExtendedLabelProviderFactory getDelegate(Object element) {
if (! (element instanceof IAdaptable)) {
return null;
}
@@ -64,7 +62,7 @@ public class JaxbNavigatorItemLabelProviderFactory
return delegates.get(platformDesc);
}
JaxbPlatformUi platformUi = JptJaxbUiPlugin.getJaxbPlatformUiManager().getJaxbPlatformUi(platformDesc);
- ItemLabelProviderFactory delegate =
+ ItemExtendedLabelProviderFactory delegate =
(platformUi == null) ? null : platformUi.getNavigatorUi().getItemLabelProviderFactory();
delegates.put(platformDesc, delegate);
return delegate;
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorLabelProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorLabelProvider.java
deleted file mode 100644
index 615a7bac26..0000000000
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorLabelProvider.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jaxb.ui.internal.navigator;
-
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.navigator.ICommonContentExtensionSite;
-import org.eclipse.ui.navigator.ICommonLabelProvider;
-
-/**
- * This extension of navigator label provider delegates to the platform UI
- * (see the org.eclipse.jpt.ui.jpaPlatform extension point) for navigator labels.
- *
- * This label provider provides a label for the root "JPA Content" node provided
- * by the content provider (see {@link JaxbNavigatorContentProvider}) and delegates
- * to the label provider returned by the platform UI implementation for labels
- * for children of the "JPA Content" node (or for any other sub-node).
- */
-public class JaxbNavigatorLabelProvider
- extends LabelProvider
- implements ICommonLabelProvider {
-
- private JaxbNavigatorContentAndLabelProvider delegate;
-
-
- public JaxbNavigatorLabelProvider() {
- super();
- }
-
-
- public JaxbNavigatorContentAndLabelProvider getDelegate() {
- return delegate;
- }
-
-
- // **************** IBaseLabelProvider implementation **********************
-
- @Override
- public void addListener(ILabelProviderListener listener) {
- if (delegate != null) {
- delegate.addListener(listener);
- }
- super.addListener(listener);
- }
-
- @Override
- public void removeListener(ILabelProviderListener listener) {
- super.removeListener(listener);
- if (delegate != null) {
- delegate.removeListener(listener);
- }
- }
-
- @Override
- public boolean isLabelProperty(Object element, String property) {
- if (delegate != null) {
- return delegate.isLabelProperty(element, property);
- }
-
- return super.isLabelProperty(element, property);
- }
-
- @Override
- public void dispose() {
- if (delegate != null) {
- delegate.dispose();
- }
- super.dispose();
- }
-
-
- // **************** ILabelProvider implementation **************************
-
- @Override
- public Image getImage(Object element) {
- if (delegate != null) {
- return delegate.getImage(element);
- }
-
- return super.getImage(element);
- }
-
- @Override
- public String getText(Object element) {
- if (delegate != null) {
- return delegate.getText(element);
- }
-
- return super.getText(element);
- }
-
-
- // **************** IDescriptionProvider implementation ********************
-
- public String getDescription(Object element) {
- if (delegate != null) {
- return delegate.getDescription(element);
- }
-
- return super.getText(element);
- }
-
-
- // **************** IMementoAware implementation ***************************
-
- public void saveState(IMemento memento) {
- // no op
- }
-
- public void restoreState(IMemento memento) {
- // no op
- }
-
-
- // **************** ICommonLabelProvider implementation ********************
-
- public void init(ICommonContentExtensionSite config) {
- if (delegate == null) {
- JaxbNavigatorContentProvider contentProvider = (JaxbNavigatorContentProvider) config.getExtension().getContentProvider();
- if (contentProvider != null && contentProvider.getDelegate() != null) {
- delegate = contentProvider.getDelegate();
- }
- else {
- delegate = new JaxbNavigatorContentAndLabelProvider();
- }
- }
- }
-}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorTreeItemContentProviderFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorTreeItemContentProviderFactory.java
index 567fbb04f1..5c6f3979bd 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorTreeItemContentProviderFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/navigator/JaxbNavigatorTreeItemContentProviderFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,19 +10,17 @@
package org.eclipse.jpt.jaxb.ui.internal.navigator;
import java.util.HashMap;
-import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription;
import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin;
import org.eclipse.jpt.jaxb.ui.platform.JaxbPlatformUi;
public class JaxbNavigatorTreeItemContentProviderFactory
- implements TreeItemContentProviderFactory {
-
+ implements ItemTreeContentProviderFactory
+{
/**
* Exactly *one* of these factories is created for each view that utilizes it.
* Therefore, as we delegate to the platform UI for each project, we should
@@ -31,24 +29,23 @@ public class JaxbNavigatorTreeItemContentProviderFactory
*
* Key: platform id, Value: delegate content provider factory
*/
- private Map<JaxbPlatformDescription, TreeItemContentProviderFactory> delegates;
+ private HashMap<JaxbPlatformDescription, ItemTreeContentProviderFactory> delegates = new HashMap<JaxbPlatformDescription, ItemTreeContentProviderFactory>();
public JaxbNavigatorTreeItemContentProviderFactory() {
super();
- this.delegates = new HashMap<JaxbPlatformDescription, TreeItemContentProviderFactory>();
}
- public TreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- TreeItemContentProviderFactory delegate = getDelegate(item);
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ ItemTreeContentProviderFactory delegate = getDelegate(item);
if (delegate != null) {
- return delegate.buildItemContentProvider(item, contentAndLabelProvider);
+ return delegate.buildProvider(item, manager);
}
return null;
}
- private TreeItemContentProviderFactory getDelegate(Object element) {
+ private ItemTreeContentProviderFactory getDelegate(Object element) {
if (! (element instanceof IAdaptable)) {
return null;
}
@@ -64,7 +61,7 @@ public class JaxbNavigatorTreeItemContentProviderFactory
return delegates.get(platformDesc);
}
JaxbPlatformUi platformUi = JptJaxbUiPlugin.getJaxbPlatformUiManager().getJaxbPlatformUi(platformDesc);
- TreeItemContentProviderFactory delegate =
+ ItemTreeContentProviderFactory delegate =
(platformUi == null) ? null : platformUi.getNavigatorUi().getTreeItemContentProviderFactory();
delegates.put(platformDesc, delegate);
return delegate;
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectModel.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectModel.java
index 96fb670b28..a7c219623c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectModel.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectModel.java
@@ -1,3 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
package org.eclipse.jpt.jaxb.ui.internal.properties;
import org.eclipse.core.resources.IProject;
@@ -47,7 +56,7 @@ class JaxbProjectModel
}
void platformChanged() {
- this.propertyChanged();
+ this.aspectChanged();
}
@Override
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java
index b9eadb8d96..dfd89c363b 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -278,7 +278,7 @@ public class JaxbProjectPropertiesPage
// user is unable to unset the platform, so no validation necessary
/* library provider */
- super.performValidation(statuses);
+ // default validation is OK
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
index 31cc774ed4..1647d137de 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html
@@ -265,7 +265,7 @@ public class JaxbSchemasPropertiesPage
new AddEditSchemaDialog(
getShell(),
null,
- this.schemasModel.getValue());
+ this.schemasModel.getAspectValue());
// opens the dialog - just returns if the user cancels it
if (dialog.open() == Window.CANCEL) {
@@ -280,7 +280,7 @@ public class JaxbSchemasPropertiesPage
}
private PropertyValueModel<Boolean> buildEditEnabledModel() {
- return new CollectionPropertyValueModelAdapter<Boolean>(this.schemasSelectionModel) {
+ return new CollectionPropertyValueModelAdapter<Boolean, Schema>(this.schemasSelectionModel) {
@Override
protected Boolean buildValue() {
return Boolean.valueOf(this.collectionModel.size() == 1);
@@ -295,7 +295,7 @@ public class JaxbSchemasPropertiesPage
new AddEditSchemaDialog(
getShell(),
schema,
- this.schemasModel.getValue());
+ this.schemasModel.getAspectValue());
// opens the dialog - just returns if the user cancels it
if (dialog.open() == Window.CANCEL) {
@@ -308,7 +308,7 @@ public class JaxbSchemasPropertiesPage
}
private PropertyValueModel<Boolean> buildRemoveEnabledModel() {
- return new CollectionPropertyValueModelAdapter<Boolean>(this.schemasSelectionModel) {
+ return new CollectionPropertyValueModelAdapter<Boolean, Schema>(this.schemasSelectionModel) {
@Override
protected Boolean buildValue() {
return Boolean.valueOf(this.collectionModel.size() >= 1);
@@ -347,6 +347,8 @@ public class JaxbSchemasPropertiesPage
this.buildOkProgressMonitorDialog().run(true, false, this.buildOkRunnableWithProgress());
}
catch (InterruptedException ex) {
+ // should *not* happen...
+ Thread.currentThread().interrupt();
return false;
}
catch (InvocationTargetException ex) {
@@ -409,7 +411,7 @@ public class JaxbSchemasPropertiesPage
static class SchemasModel
- extends AspectAdapter<JaxbProject>
+ extends AspectAdapter<JaxbProject, Collection<Schema>>
implements CollectionValueModel<Schema> {
/**
@@ -478,7 +480,7 @@ public class JaxbSchemasPropertiesPage
if (this.subject != null) {
this.schemas.addAll(buildSchemas_());
}
- fireCollectionChanged(VALUES, getValue());
+ fireCollectionChanged(VALUES, getAspectValue());
}
public Schema addSchema(String namespace, String location) {
@@ -510,8 +512,8 @@ public class JaxbSchemasPropertiesPage
}
@Override
- protected void fireAspectChanged(Object oldValue, Object newValue) {
- fireCollectionChanged(VALUES, getValue());
+ protected void fireAspectChanged(Collection<Schema> oldValue, Collection<Schema> newValue) {
+ this.synchronizeCollection(newValue, new ArrayList<Schema>(oldValue), VALUES);
}
@Override
@@ -537,7 +539,7 @@ public class JaxbSchemasPropertiesPage
}
@Override
- protected Collection<Schema> getValue() {
+ protected Collection<Schema> getAspectValue() {
return CollectionTools.collection(iterator());
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java
index 89c3c8ca3e..88fe945dc9 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/ProjectWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2010 Oracle. All rights reserved.
+* Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -69,7 +69,7 @@ public class ProjectWizardPage extends WizardPage
}
public static IJavaProject getJavaProjectFrom(IProject project) {
- return (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ return ((IJavaElement) project.getAdapter(IJavaElement.class)).getJavaProject();
}
// ********** constructor **********
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java
index 4286c6933c..e4d8959a41 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/classesgen/ClassesGeneratorWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2010, 2011 Oracle. All rights reserved.
+* Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -269,7 +269,7 @@ public class ClassesGeneratorWizard
}
public IJavaProject getJavaProjectFrom(IProject project) {
- return (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ return ((IJavaElement) project.getAdapter(IJavaElement.class)).getJavaProject();
}
private boolean displayOverwritingClassesWarning(ClassesGeneratorOptions generatorOptions) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java
index 7b1dc1c747..4f44a8ab64 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2010, 2011 Oracle. All rights reserved.
+* Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -140,7 +140,7 @@ public class SchemaGeneratorWizard extends Wizard implements INewWizard
}
private IJavaProject getJavaProjectFrom(IProject project) {
- IJavaProject javaProject = (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class));
+ IJavaProject javaProject = ((IJavaElement) project.getAdapter(IJavaElement.class)).getJavaProject();
if(javaProject == null) {
throw new RuntimeException("Not a Java Project"); //$NON-NLS-1$
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/navigator/JaxbNavigatorUi.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/navigator/JaxbNavigatorUi.java
index 2db5a2e7aa..7e5f1b6f6c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/navigator/JaxbNavigatorUi.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/navigator/JaxbNavigatorUi.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,10 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.jaxb.ui.navigator;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
/**
* Defines content and label provider factories for Project Navigator view for a given JAXB project.
@@ -29,12 +29,12 @@ import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
public interface JaxbNavigatorUi {
/**
- * Return the factory to create {@link TreeItemContentProvider}s
+ * Return the factory to create {@link ItemTreeContentProvider}s
*/
- TreeItemContentProviderFactory getTreeItemContentProviderFactory();
+ ItemTreeContentProviderFactory getTreeItemContentProviderFactory();
/**
* Return the factory to create {@link ItemLabelProvider}s
*/
- ItemLabelProviderFactory getItemLabelProviderFactory();
+ ItemExtendedLabelProviderFactory getItemLabelProviderFactory();
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java
index 1077b49b4b..bba329c672 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.jaxb.core.tests.internal.projects;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject;
-import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer;
import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.core/META-INF/MANIFEST.MF
index bf3b9657c4..c0a5988b60 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/META-INF/MANIFEST.MF
@@ -75,8 +75,6 @@ Export-Package: org.eclipse.jpt.jpa.core,
org.eclipse.jpt.jpa.core.internal.resource.java.source;x-internal:=true,
org.eclipse.jpt.jpa.core.internal.resource.orm;x-internal:=true,
org.eclipse.jpt.jpa.core.internal.resource.persistence;x-internal:=true,
- org.eclipse.jpt.jpa.core.internal.resource.xml;x-internal:=true,
- org.eclipse.jpt.jpa.core.internal.synch;x-internal:=true,
org.eclipse.jpt.jpa.core.internal.validation;x-internal:=true,
org.eclipse.jpt.jpa.core.jpa2,
org.eclipse.jpt.jpa.core.jpa2.context,
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml
index 15a8a20ad9..f82202a4ff 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
- Copyright (c) 2007, 2011 Oracle. All rights reserved.
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0, which accompanies this distribution
- and is available at http://www.eclipse.org/legal/epl-v10.html.
-
- Contributors:
- Oracle - initial API and implementation
+ Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0, which accompanies this distribution
+ and is available at http://www.eclipse.org/legal/epl-v10.html.
+
+ Contributors:
+ Oracle - initial API and implementation
-->
<plugin>
@@ -18,10 +18,68 @@
id="jpaPlatforms"
name="%JPA_PLATFORM"
schema="schema/jpaPlatforms.exsd"/>
-
-
- <!-- ***** Eclipse core extensions ***** -->
-
+
+
+ <!-- ***** adapters ***** -->
+
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+
+ <!-- IWorkspace -> JpaProjectManager -->
+ <factory
+ adaptableType="org.eclipse.core.resources.IWorkspace"
+ class="org.eclipse.jpt.jpa.core.internal.WorkspaceAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.core.JpaProjectManager"/>
+ </factory>
+
+ <!-- IProject
+ -> JpaProject.Reference
+ -> JpaProject
+ -->
+ <factory
+ adaptableType="org.eclipse.core.resources.IProject"
+ class="org.eclipse.jpt.jpa.core.internal.ProjectAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.core.JpaProject$Reference"/>
+ <adapter type="org.eclipse.jpt.jpa.core.JpaProject"/>
+ </factory>
+
+ <!-- IFile
+ -> JpaFile.Reference
+ -> JpaFile
+ -->
+ <factory
+ adaptableType="org.eclipse.core.resources.IFile"
+ class="org.eclipse.jpt.jpa.core.internal.FileAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.core.JpaFile$Reference"/>
+ <adapter type="org.eclipse.jpt.jpa.core.JpaFile"/>
+ </factory>
+
+ <!-- IResource -> JpaPlatformDescription -->
+ <factory
+ adaptableType="org.eclipse.core.resources.IResource"
+ class="org.eclipse.jpt.jpa.core.internal.platform.ResourceAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"/>
+ </factory>
+
+ <!-- IJavaElement -> JpaPlatformDescription -->
+ <factory
+ adaptableType="org.eclipse.jdt.core.IJavaElement"
+ class="org.eclipse.jpt.jpa.core.internal.platform.JavaElementAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"/>
+ </factory>
+
+ <!-- JpaLibraryProviderInstallOperationConfig -> JpaPlatformDescription -->
+ <factory
+ adaptableType="org.eclipse.jpt.jpa.core.libprov.JpaLibraryProviderInstallOperationConfig"
+ class="org.eclipse.jpt.jpa.core.internal.libprov.JpaLibraryProviderInstallOperationConfigAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"/>
+ </factory>
+
+ </extension>
+
+
+ <!-- ***** content types ***** -->
+
<extension
point="org.eclipse.core.contenttype.contentTypes">
@@ -82,97 +140,71 @@
</content-type>
</extension>
-
-
+
+
+ <!-- ***** property testers ***** -->
+
<extension
point="org.eclipse.core.expressions.propertyTesters">
-
+
<propertyTester
id="org.eclipse.jpt.jpa.core.propertyTester.persistentAttribute"
type="org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute"
namespace="org.eclipse.jpt.jpa.core"
- properties="isMapped, isVirtual"
+ properties="isMapped, isNotMapped, isVirtual, isNotVirtual"
class="org.eclipse.jpt.jpa.core.internal.context.PersistentAttributePropertyTester"/>
-
- <propertyTester
- id="org.eclipse.jpt.jpa.core.propertyTester.platformResource"
- type="org.eclipse.core.resources.IResource"
- namespace="org.eclipse.jpt.jpa.core"
- properties="jpaPlatform, jpaPlatformGroup"
- class="org.eclipse.jpt.jpa.core.internal.JpaPlatformTester"/>
-
- <propertyTester
- id="org.eclipse.jpt.jpa.core.propertyTester.javaElement"
- type="org.eclipse.jdt.core.IJavaElement"
- namespace="org.eclipse.jpt.jpa.core"
- properties="jpaPlatform, jpaPlatformGroup"
- class="org.eclipse.jpt.jpa.core.internal.JpaPlatformTester"/>
-
+
<propertyTester
id="org.eclipse.jpt.jpa.core.propertyTester.jpaPlatformDescription"
type="org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription"
namespace="org.eclipse.jpt.jpa.core"
properties="jpaPlatform, jpaPlatformGroup"
- class="org.eclipse.jpt.jpa.core.internal.JpaPlatformTester"/>
-
- <propertyTester
- id="org.eclipse.jpt.jpa.core.propertyTester.jpaLibraryProviderConfig"
- type="org.eclipse.jpt.jpa.core.libprov.JpaLibraryProviderInstallOperationConfig"
- namespace="org.eclipse.jpt.jpa.core"
- properties="jpaPlatform, jpaPlatformGroup"
- class="org.eclipse.jpt.jpa.core.internal.JpaPlatformTester"/>
-
- <propertyTester
- id="org.eclipse.jpt.jpa.core.propertyTester.xmlResource"
- type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource"
- namespace="org.eclipse.jpt.jpa.core"
- properties="isLatestSupportedVersion"
- class="org.eclipse.jpt.jpa.core.internal.resource.xml.JpaXmlResourcePropertyTester"/>
-
+ class="org.eclipse.jpt.jpa.core.internal.platform.JpaPlatformTester"/>
+
<propertyTester
id="org.eclipse.jpt.jpa.core.propertyTester.xmlFile"
type="org.eclipse.jpt.jpa.core.context.XmlFile"
namespace="org.eclipse.jpt.jpa.core"
- properties="isLatestSupportedVersion"
- class="org.eclipse.jpt.jpa.core.internal.resource.xml.JpaXmlResourcePropertyTester"/>
-
+ properties="isLatestSupportedVersion, isNotLatestSupportedVersion"
+ class="org.eclipse.jpt.jpa.core.internal.context.XmlFilePropertyTester"/>
+
</extension>
-
-
+
+
+ <!-- ***** preferences ***** -->
+
<extension
- point="org.eclipse.core.runtime.adapters">
-
- <factory
- class="org.eclipse.jpt.jpa.core.internal.ProjectAdapterFactory"
- adaptableType="org.eclipse.core.resources.IProject">
- <adapter type="org.eclipse.jpt.jpa.core.JpaProject"/>
- </factory>
-
- <factory
- class="org.eclipse.jpt.jpa.core.internal.ProjectAdapterFactory"
- adaptableType="org.eclipse.jdt.core.IJavaProject">
- <adapter type="org.eclipse.jpt.jpa.core.JpaProject"/>
- </factory>
+ point="org.eclipse.core.runtime.preferences">
- <factory
- class="org.eclipse.jpt.jpa.core.internal.resource.xml.JpaXmlResourceAdapterFactory"
- adaptableType="org.eclipse.core.resources.IFile">
- <adapter type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource"/>
- </factory>
+ <initializer
+ class="org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferenceInitializer"/>
</extension>
-
-
+
+
+ <!-- ***** markers ***** -->
+ <!--
+ *** Do NOT qualify the marker id with "org.eclipse.jpt.jpa.core".
+ *** See bug 252891.
+ -->
+
<extension
- point="org.eclipse.core.runtime.preferences">
+ point="org.eclipse.core.resources.markers"
+ id="jpaProblemMarker"
+ name="%JPA_PROBLEM">
+
+ <persistent value="true"/>
- <initializer
- class="org.eclipse.jpt.jpa.core.internal.prefs.JpaPreferenceInitializer"/>
+ <!-- Can't use text marker until we have specific models for each input type (XML, java)
+ <super type="org.eclipse.core.resources.textmarker"/>
+ -->
+ <super type="org.eclipse.wst.validation.problemmarker2"/>
+ <super type="org.eclipse.jdt.core.problem"/>
</extension>
-
-
- <!-- ***** JPT extensions (eat our own dogfood) ***** -->
+
+
+ <!-- ***** Dali extensions (eat our own dogfood) ***** -->
<extension
point="org.eclipse.jpt.jpa.core.jpaPlatforms">
@@ -208,7 +240,8 @@
class="org.eclipse.jpt.jpa.core.internal.libval.GenericJpaUserLibraryValidator">
<enablement>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="jpa-user-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="jpa-user-library-provider"/>
</with>
</enablement>
</libraryValidator>
@@ -218,21 +251,17 @@
class="org.eclipse.jpt.jpa.core.internal.libval.GenericEclipseLinkBundlesLibraryValidator">
<enablement>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="eclipselink-bundles-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="eclipselink-bundles-library-provider"/>
</with>
</enablement>
</libraryValidator>
</extension>
-
-
-
- <!--
- ******************************************
- * Library Provider Framework Integration *
- ******************************************
- -->
-
+
+
+ <!-- ***** WTP Library Provider Framework Integration ***** -->
+
<extension
point="org.eclipse.jst.common.project.facet.core.legacyLibraryProviderDetectors">
@@ -319,7 +348,7 @@
</provider>
<!--
- All osgi library providers that point to eclipselink bundles extend this.
+ All OSGi library providers that point to EclipseLink bundles extend this.
It exists purely as an identifier for library validation.
-->
<provider
@@ -405,7 +434,7 @@
</extension>
- <!-- ***** WTP extensions ***** -->
+ <!-- ***** WTP resource factories ***** -->
<extension
point="org.eclipse.wst.common.modulecore.resourceFactories">
@@ -429,6 +458,8 @@
</extension>
+ <!-- ***** WTP facet framework ***** -->
+
<extension
point="org.eclipse.wst.common.project.facet.core.facets">
@@ -502,6 +533,9 @@
</extension>
+
+ <!-- ***** WTP validation framework ***** -->
+
<extension
point="org.eclipse.wst.validation.validatorV2"
id="jpaValidator"
@@ -528,26 +562,8 @@
</extension>
- <!-- =================================================================================== -->
- <!-- Extension: JPA Problem Marker -->
- <!-- **** Do NOT qualify the marker id with org.eclipse.jpt.jpa.core, see bug 252891 -->
- <!-- =================================================================================== -->
- <extension
- point="org.eclipse.core.resources.markers"
- id="jpaProblemMarker"
- name="%JPA_PROBLEM">
+ <!-- ***** refactoring ***** -->
- <persistent value="true"/>
-
- <!-- Can't use text marker until we have specific models for each input type (XML, java)
- <super type="org.eclipse.core.resources.textmarker"/>
- -->
-
- <super type="org.eclipse.wst.validation.problemmarker2"/>
- <super type="org.eclipse.jdt.core.problem"/>
- </extension>
-
-
<extension
point="org.eclipse.ltk.core.refactoring.deleteParticipants">
@@ -610,10 +626,11 @@
</enablement>
</moveParticipant>
</extension>
-
-
+
+
<extension
point="org.eclipse.ltk.core.refactoring.renameParticipants">
+
<renameParticipant
class="org.eclipse.jpt.jpa.core.internal.refactoring.JpaRenameTypeParticipant"
id="org.eclipse.jpt.jpa.core.ltk.jpaRenameTypeParticipant"
@@ -624,6 +641,7 @@
</with>
</enablement>
</renameParticipant>
+
<renameParticipant
class="org.eclipse.jpt.jpa.core.internal.refactoring.JpaRenamePackageParticipant"
id="org.eclipse.jpt.jpa.core.ltk.jpaRenamePackageParticipant"
@@ -634,6 +652,7 @@
</with>
</enablement>
</renameParticipant>
+
<renameParticipant
class="org.eclipse.jpt.jpa.core.internal.refactoring.JpaRenameFolderParticipant"
id="org.eclipse.jpt.jpa.core.ltk.jpaRenameFolderParticipant"
@@ -644,6 +663,7 @@
</with>
</enablement>
</renameParticipant>
+
<renameParticipant
class="org.eclipse.jpt.jpa.core.internal.refactoring.JpaRenameMappingFileParticipant"
id="org.eclipse.jpt.jpa.core.ltk.jpaRenameMappingFileParticipant"
@@ -661,8 +681,11 @@
</enablement>
</renameParticipant>
</extension>
+
+
<extension
point="org.eclipse.ltk.core.refactoring.moveParticipants">
+
<moveParticipant
class="org.eclipse.jpt.jpa.core.internal.refactoring.JpaMoveMappingFileParticipant"
id="org.eclipse.jpt.jpa.core.ltk.jpaMoveMappingFileParticipant"
@@ -679,7 +702,8 @@
</with>
</enablement>
</moveParticipant>
- <moveParticipant
+
+ <moveParticipant
class="org.eclipse.jpt.jpa.core.internal.refactoring.JpaMoveFolderParticipant"
id="org.eclipse.jpt.jpa.core.ltk.jpaMoveFolderParticipant"
name="%JPA_MOVE_FOLDER_PARTICIPANT_NAME">
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties
index b08508d2e6..fb899e6ce3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties
@@ -1,5 +1,5 @@
################################################################################
-# Copyright (c) 2006, 2010 Oracle. All rights reserved.
+# Copyright (c) 2006, 2012 Oracle. All rights reserved.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0, which accompanies this distribution
# and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,17 @@
################################################################################
NONE=<None>
+
+BUILD_JPA_PROJECTS_JOB_NAME=Build JPA Projects
+GET_JPA_PROJECTS_JOB_NAME=Get JPA Projects
+GET_JPA_PROJECT_JOB_NAME=Get JPA Project
+REBUILD_JPA_PROJECT_JOB_NAME=Rebuild JPA Project
+BUILD_VALIDATION_MESSAGES_JOB_NAME=JPA Validation
+PROJECT_CHANGE_EVENT_HANDLER_JOB_NAME=JPA Project Change Event Handler
+PROJECT_POST_CLEAN_BUILD_EVENT_HANDLER_JOB_NAME=JPA Project Post-Clean Build Event Handler
+FACET_FILE_CHANGE_EVENT_HANDLER_JOB_NAME=JPA Facet File Change Event Handler
+JAVA_CHANGE_EVENT_HANDLER_JOB_NAME=JPA Java Change Event Handler
+
VALIDATE_JOB=Validation
VALIDATE_PROJECT_NOT_JPA=Project does not have the JPA facet
VALIDATE_PROJECT_IMPROPER_PLATFORM=Project's JPA platform does not support this file type
@@ -30,8 +41,6 @@ VALIDATE_CONNECTION_DOESNT_CONTAIN_SCHEMA=Schema ''{0}'' does not exist on the c
VALIDATE_RUNTIME_NOT_SPECIFIED=There is no server runtime associated with this project to provide a JPA implementation
VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30=The server runtime selected does not support EJB 3.0, so it likely does not provide a JPA implementation
VALIDATE_LIBRARY_NOT_SPECIFIED=No JPA implementation library specified
-SYNCHRONIZE_CLASSES_JOB=Synchronizing classes
-SYNCHRONIZING_CLASSES_TASK=Synchronizing classes ...
INVALID_PERSISTENCE_XML_CONTENT=Invalid persistence.xml content
ERROR_SYNCHRONIZING_CLASSES_COULD_NOT_VALIDATE=Error synchronizing classes. Could not validate.
ERROR_WRITING_FILE=Could not write to persistence.xml
@@ -43,6 +52,7 @@ REGISTRY_FAILED_INTERFACE_ASSIGNMENT=Unable to assign the class ''{0}'' declared
REGISTRY_FAILED_INSTANTIATION=Unable to instantiate the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}''.
CONTEXT_MODEL_SYNC_JOB_NAME=Synchronize JPA project: ''{0}''
UPDATE_JOB_NAME=Update JPA project: ''{0}''
+METAMODEL_SYNC_JOB_NAME=Synchronize JPA project metamodel: ''{0}''
PLATFORM_ID_DOES_NOT_EXIST=No JPA platform exists for the id: ''{0}''. The JPA project was not created for project ''{1}''. Ensure that the platform''s plugin has been added to this Eclipse installation.
PREFERENCES_FLUSH_JOB_NAME=Flush Preferences: {0}
OSGI_BUNDLES_LIBRARY_VALIDATOR__BUNDLE_NOT_FOUND=The bundle ''{0}'' could not be found.
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/GenericJpaProjectManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/GenericJpaProjectManager.java
deleted file mode 100644
index 44d0ded6b1..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/GenericJpaProjectManager.java
+++ /dev/null
@@ -1,1100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core;
-
-import java.util.Vector;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceProxy;
-import org.eclipse.core.resources.IResourceProxyVisitor;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.jobs.IJobManager;
-import org.eclipse.core.runtime.jobs.ILock;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.ElementChangedEvent;
-import org.eclipse.jdt.core.IElementChangedListener;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
-import org.eclipse.jpt.common.core.internal.utility.CallbackJobSynchronizer;
-import org.eclipse.jpt.common.core.internal.utility.JobCommand;
-import org.eclipse.jpt.common.core.internal.utility.JobSynchronizer;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.AsynchronousCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.SimpleCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.StatefulCommandExecutor;
-import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.internal.SynchronizedBoolean;
-import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
-import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
-import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
-import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
-import org.eclipse.jpt.jpa.core.internal.SimpleJpaProjectConfig;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
-import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent;
-
-/**
- * The JPA project manager maintains a list of all JPA projects in the workspace.
- * It keeps the list (and the state of the JPA projects themselves)
- * synchronized with the workspace by listening for various
- * changes:<ul>
- * <li>Resource
- * <li>Java
- * <li>Faceted Project
- * </ul>
- * We use an Eclipse {@link ILock lock} to synchronize access to the JPA
- * projects when dealing with these events. In an effort to reduce deadlocks,
- * the simple Resource and Java change events are dispatched to a background
- * thread, allowing us to handle the events outside of the workspace lock held
- * during resource and Java change notifications.
- * <p>
- * Events that trigger either the adding or removing of a JPA project (e.g.
- * {@link IResourceChangeEvent#POST_CHANGE}) are handled "synchronously"
- * by allowing the background thread to handle any outstanding events before
- * updating the list of JPA projects and returning execution to the event
- * source.
- * <p>
- * Various things that cause us to add or remove a JPA project:<ul>
- * <li>The {@link JptJpaCorePlugin} will "lazily" instantiate and {@link #start() start}
- * a JPA project manager as appropriate. This will trigger the manager
- * to find and add all pre-existing JPA projects.
- *
- * <li>Project created and facet installed<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * <li>Project facet uninstalled<p>
- * {@link IFacetedProjectEvent.Type#PRE_UNINSTALL}
- *
- * <li>Project opened<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#ADDED} facet settings file
- * (<code>/.settings/org.eclipse.wst.common.project.facet.core.xml</code>)
- * <li>Project closed<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#REMOVED} facet settings file
- *
- * <li>Pre-existing project imported from directory or archive (created and opened)<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#ADDED} facet settings file
- * <li>Project renamed<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#REMOVED} facet settings file of old project
- * -> {@link IResourceDelta#ADDED} facet settings file of new project
- * <li>Project deleted<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#REMOVED} facet settings file
- *
- * <li>Project facet installed by editing the facets settings file directly<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#CHANGED} facet settings file
- * <li>Project facet uninstalled by editing the facets settings file directly<p>
- * {@link IResourceChangeEvent#POST_CHANGE}
- * -> {@link IResource#FILE}
- * -> {@link IResourceDelta#CHANGED} facet settings file
- * </ul>
- */
-// TODO remove faceted project listener and rely solely on resource change events
-// for the faceted project settings file
-class GenericJpaProjectManager
- extends AbstractModel
- implements JpaProjectManager
-{
- /**
- * All the JPA projects in the workspace.
- */
- private final Vector<JpaProject> jpaProjects = new Vector<JpaProject>();
-
- /**
- * Synchronize access to the JPA projects.
- */
- /* CU private */ final ILock lock = this.getJobManager().newLock();
-
- /**
- * Determine how Resource and Java change events are
- * handled (i.e. synchronously or asynchronously).
- */
- private volatile StatefulCommandExecutor eventHandler = new AsynchronousCommandExecutor(JptCommonCoreMessages.DALI_EVENT_HANDLER_THREAD_NAME);
-
- /**
- * Listen for<ul>
- * <li>changes to projects and files
- * <li>clean builds
- * </ul>
- */
- private final IResourceChangeListener resourceChangeListener = new ResourceChangeListener();
-
- /**
- * The types of resource change events that interest
- * {@link #resourceChangeListener}.
- */
- private static final int RESOURCE_CHANGE_EVENT_TYPES =
- IResourceChangeEvent.POST_CHANGE |
- IResourceChangeEvent.POST_BUILD;
-
- /**
- * Listen for changes to this file to determine when the JPA facet is
- * added to or removed from a "faceted" project.
- */
- private static final String FACETED_PROJECT_FRAMEWORK_SETTINGS_FILE_NAME = FacetedProjectFramework.PLUGIN_ID + ".xml"; //$NON-NLS-1$
-
- /**
- * Listen for the JPA facet being added to or removed from a "faceted" project.
- */
- private final IFacetedProjectListener facetedProjectListener = new FacetedProjectListener();
-
- /**
- * The types of faceted project events that interest
- * {@link #facetedProjectListener}.
- */
- private static final IFacetedProjectEvent.Type[] FACETED_PROJECT_EVENT_TYPES = new IFacetedProjectEvent.Type[] {
- IFacetedProjectEvent.Type.PRE_UNINSTALL
- };
-
- /**
- * Listen for Java changes (unless the Dali UI is active).
- * @see #javaElementChangeListenerIsActive()
- */
- private final JavaElementChangeListener javaElementChangeListener = new JavaElementChangeListener();
-
- /**
- * The types of resource change events that interest
- * {@link #javaElementChangeListener}.
- */
- private static final int JAVA_CHANGE_EVENT_TYPES =
- ElementChangedEvent.POST_CHANGE |
- ElementChangedEvent.POST_RECONCILE;
-
-
- // ********** constructor **********
-
- /**
- * Internal: called by {@link JptJpaCorePlugin Dali plug-in}.
- */
- GenericJpaProjectManager() {
- super();
- }
-
-
- // ********** plug-in controlled life-cycle **********
-
- /**
- * Internal: called by {@link JptJpaCorePlugin Dali plug-in}.
- */
- void start() {
- try {
- this.lock.acquire();
- this.start_();
- } finally {
- this.lock.release();
- }
- }
-
- private void start_() {
- debug("*** JPA project manager START ***"); //$NON-NLS-1$
- try {
- this.buildJpaProjects();
- this.eventHandler.start();
- this.getWorkspace().addResourceChangeListener(this.resourceChangeListener, RESOURCE_CHANGE_EVENT_TYPES);
- FacetedProjectFramework.addListener(this.facetedProjectListener, FACETED_PROJECT_EVENT_TYPES);
- JavaCore.addElementChangedListener(this.javaElementChangeListener, JAVA_CHANGE_EVENT_TYPES);
- } catch (RuntimeException ex) {
- JptJpaCorePlugin.log(ex);
- this.stop_();
- }
- }
-
- /**
- * Side-effect: {@link #jpaProjects} populated.
- */
- private void buildJpaProjects() {
- try {
- this.buildJpaProjects_();
- } catch (CoreException ex) {
- // if we have a problem, leave the currently built JPA projects in
- // place and keep executing (should be OK...)
- JptJpaCorePlugin.log(ex);
- }
- }
-
- private void buildJpaProjects_() throws CoreException {
- this.getWorkspace().getRoot().accept(new ResourceProxyVisitor(), IResource.NONE);
- }
-
- /**
- * Internal: called by {@link JptJpaCorePlugin Dali plug-in}.
- */
- void stop() throws Exception {
- try {
- this.lock.acquire();
- this.stop_();
- } finally {
- this.lock.release();
- }
- }
-
- private void stop_() {
- debug("*** JPA project manager STOP ***"); //$NON-NLS-1$
- JavaCore.removeElementChangedListener(this.javaElementChangeListener);
- FacetedProjectFramework.removeListener(this.facetedProjectListener);
- this.getWorkspace().removeResourceChangeListener(this.resourceChangeListener);
- this.eventHandler.stop();
- this.clearJpaProjects();
- }
-
- private void clearJpaProjects() {
- // clone to prevent concurrent modification exceptions
- for (JpaProject jpaProject : this.getJpaProjects_()) {
- this.removeJpaProject(jpaProject);
- }
- }
-
-
- // ********** JpaProjectManager implementation **********
-
- public Iterable<JpaProject> getJpaProjects() {
- try {
- this.lock.acquire();
- return this.getJpaProjects_();
- } finally {
- this.lock.release();
- }
- }
-
- private Iterable<JpaProject> getJpaProjects_() {
- return new LiveCloneIterable<JpaProject>(this.jpaProjects);
- }
-
- public int getJpaProjectsSize() {
- return this.jpaProjects.size();
- }
-
- public JpaProject getJpaProject(IProject project) {
- try {
- this.lock.acquire();
- return this.getJpaProject_(project);
- } finally {
- this.lock.release();
- }
- }
-
- private JpaProject getJpaProject_(IProject project) {
- for (JpaProject jpaProject : this.jpaProjects) {
- if (jpaProject.getProject().equals(project)) {
- return jpaProject;
- }
- }
- return null;
- }
-
- public JpaFile getJpaFile(IFile file) {
- JpaProject jpaProject = this.getJpaProject(file.getProject());
- return (jpaProject == null) ? null : jpaProject.getJpaFile(file);
- }
-
- public void rebuildJpaProject(IProject project) {
- try {
- this.lock.acquire();
- this.rebuildJpaProject_(project);
- } finally {
- this.lock.release();
- }
- }
-
- /**
- * assumption: the JPA project holder exists
- */
- private void rebuildJpaProject_(IProject project) {
- this.removeJpaProject(this.getJpaProject_(project));
- this.addJpaProject(project);
- }
-
- public boolean javaElementChangeListenerIsActive() {
- return this.javaElementChangeListener.isActive();
- }
-
- public void setJavaElementChangeListenerIsActive(boolean javaElementChangeListenerIsActive) {
- this.javaElementChangeListener.setActive(javaElementChangeListenerIsActive);
- }
-
- public IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
- }
-
- public IJobManager getJobManager() {
- return Job.getJobManager();
- }
-
-
- // ********** adding/removing JPA projects **********
-
- /* CU private */ void addJpaProject(IProject project) {
- this.addJpaProject(this.buildJpaProject(project));
- }
-
- private void addJpaProject(JpaProject jpaProject) {
- // figure out exactly when JPA projects are added
- dumpStackTrace("add: ", jpaProject); //$NON-NLS-1$
- // the JPA project will be null if we have any problems building it...
- // (e.g. if we have problems getting the JPA platform)
- if (jpaProject != null) {
- this.addItemToCollection(jpaProject, this.jpaProjects, JPA_PROJECTS_COLLECTION);
- }
- }
-
- /**
- * return null if we have any problems...
- */
- private JpaProject buildJpaProject(IProject project) {
- return this.buildJpaProject(this.buildJpaProjectConfig(project));
- }
-
- /**
- * return null if we have any problems...
- */
- private JpaProject buildJpaProject(JpaProject.Config config) {
- JpaPlatform jpaPlatform = config.getJpaPlatform();
- if (jpaPlatform == null) {
- return null;
- }
- JpaProject jpaProject = this.buildJpaProject(jpaPlatform, config);
- if (jpaProject == null) {
- return null;
- }
- jpaProject.setContextModelSynchronizer(this.buildJobContextModelSynchronizer(jpaProject));
- jpaProject.setUpdateSynchronizer(this.buildJobUpdateSynchronizer(jpaProject));
- return jpaProject;
- }
-
- /**
- * return null if we have any problems...
- */
- private JpaProject buildJpaProject(JpaPlatform jpaPlatform, JpaProject.Config config) {
- try {
- return jpaPlatform.getJpaFactory().buildJpaProject(config);
- } catch (RuntimeException ex) {
- JptJpaCorePlugin.log(ex);
- return null;
- }
- }
-
- private JpaProject.Config buildJpaProjectConfig(IProject project) {
- SimpleJpaProjectConfig config = new SimpleJpaProjectConfig();
- config.setProject(project);
- config.setJpaPlatform(JptJpaCorePlugin.getJpaPlatformManager().buildJpaPlatformImplementation(project));
- config.setConnectionProfileName(JptJpaCorePlugin.getConnectionProfileName(project));
- config.setUserOverrideDefaultCatalog(JptJpaCorePlugin.getUserOverrideDefaultCatalog(project));
- config.setUserOverrideDefaultSchema(JptJpaCorePlugin.getUserOverrideDefaultSchema(project));
- config.setDiscoverAnnotatedClasses(JptJpaCorePlugin.discoverAnnotatedClasses(project));
- config.setMetamodelSourceFolderName(JptJpaCorePlugin.getMetamodelSourceFolderName(project));
- return config;
- }
-
- private Synchronizer buildJobContextModelSynchronizer(JpaProject jpaProject) {
- return new JobSynchronizer(
- this.buildContextModelJobName(jpaProject),
- this.buildContextModelJobCommand(jpaProject),
- jpaProject.getProject()
- );
- }
-
- private String buildContextModelJobName(JpaProject jpaProject) {
- return NLS.bind(JptCoreMessages.CONTEXT_MODEL_SYNC_JOB_NAME, jpaProject.getName());
- }
-
- private JobCommand buildContextModelJobCommand(final JpaProject jpaProject) {
- return new JobCommand() {
- public IStatus execute(IProgressMonitor monitor) {
- return jpaProject.synchronizeContextModel(monitor);
- }
- };
- }
-
- private CallbackSynchronizer buildJobUpdateSynchronizer(JpaProject jpaProject) {
- return new CallbackJobSynchronizer(
- this.buildUpdateJobName(jpaProject),
- this.buildUpdateJobCommand(jpaProject),
- jpaProject.getProject()
- );
- }
-
- private String buildUpdateJobName(JpaProject jpaProject) {
- return NLS.bind(JptCoreMessages.UPDATE_JOB_NAME, jpaProject.getName());
- }
-
- private JobCommand buildUpdateJobCommand(final JpaProject jpaProject) {
- return new JobCommand() {
- public IStatus execute(IProgressMonitor monitor) {
- return jpaProject.update(monitor);
- }
- };
- }
-
- /* CU private */ void removeJpaProject(JpaProject jpaProject) {
- // figure out exactly when JPA projects are removed
- dumpStackTrace("remove: ", jpaProject); //$NON-NLS-1$
- this.removeItemFromCollection(jpaProject, this.jpaProjects, JPA_PROJECTS_COLLECTION);
- jpaProject.dispose();
- }
-
-
- // ********** Project POST_CHANGE **********
-
- /* CU private */ void projectChanged(IResourceDelta delta) {
- this.eventHandler.execute(this.buildProjectChangedCommand(delta));
- }
-
- private Command buildProjectChangedCommand(final IResourceDelta delta) {
- return new EventHandlerCommand("Project POST_CHANGE Command") { //$NON-NLS-1$
- @Override
- void execute_() {
- GenericJpaProjectManager.this.projectChanged_(delta);
- }
- };
- }
-
- /**
- * Forward the specified resource delta to all our JPA projects;
- * they will each determine whether the event is significant.
- */
- /* CU private */ void projectChanged_(IResourceDelta delta) {
- for (JpaProject jpaProject : this.jpaProjects) {
- jpaProject.projectChanged(delta);
- }
- }
-
-
- // ********** Project POST_BUILD (CLEAN_BUILD) **********
-
- /* CU private */ void projectPostCleanBuild(IProject project) {
- this.executeAfterEventsHandled(this.buildProjectPostCleanBuildCommand(project));
- }
-
- private Command buildProjectPostCleanBuildCommand(final IProject project) {
- return new EventHandlerCommand("Project POST_BUILD (CLEAN_BUILD) Command") { //$NON-NLS-1$
- @Override
- void execute_() {
- GenericJpaProjectManager.this.projectPostCleanBuild_(project);
- }
- };
- }
-
- /* CU private */ void projectPostCleanBuild_(IProject project) {
- JpaProject jpaProject = this.getJpaProject_(project);
- if (jpaProject != null) {
- this.removeJpaProject(jpaProject);
- this.addJpaProject(project);
- }
- }
-
-
- // ********** File POST_CHANGE **********
-
- /**
- * The Faceted Project settings file has changed in some fashion, check
- * whether the JPA facet has been added to or removed from the specified
- * project.
- */
- /* CU private */ void checkForJpaFacetTransition(IProject project) {
- JpaProject jpaProject = this.getJpaProject_(project);
-
- if (JpaFacet.isInstalled(project)) {
- if (jpaProject == null) { // JPA facet added
- this.executeAfterEventsHandled(this.buildAddJpaProjectCommand(project));
- }
- } else {
- if (jpaProject != null) { // JPA facet removed
- this.executeAfterEventsHandled(this.buildRemoveJpaProjectCommand(jpaProject));
- }
- }
- }
-
- private Command buildAddJpaProjectCommand(final IProject project) {
- return new EventHandlerCommand("Add JPA Project Command") { //$NON-NLS-1$
- @Override
- void execute_() {
- GenericJpaProjectManager.this.addJpaProject(project);
- }
- };
- }
-
- private Command buildRemoveJpaProjectCommand(final JpaProject jpaProject) {
- return new EventHandlerCommand("Remove JPA Project Command") { //$NON-NLS-1$
- @Override
- void execute_() {
- GenericJpaProjectManager.this.removeJpaProject(jpaProject);
- }
- };
- }
-
-
- // ********** FacetedProject PRE_UNINSTALL **********
-
- /* CU private */ void jpaFacetedProjectPreUninstall(IProjectFacetActionEvent event) {
- IProject project = event.getProject().getProject();
- this.executeAfterEventsHandled(this.buildJpaFacetedProjectPreUninstallCommand(project));
- }
-
- private Command buildJpaFacetedProjectPreUninstallCommand(final IProject project) {
- return new EventHandlerCommand("Faceted Project PRE_UNINSTALL Command") { //$NON-NLS-1$
- @Override
- void execute_() {
- GenericJpaProjectManager.this.jpaFacetedProjectPreUninstall_(project);
- }
- };
- }
-
- /* CU private */ void jpaFacetedProjectPreUninstall_(IProject project) {
- // assume(?) this is the first event to indicate we need to remove the JPA project from the JPA project manager
- this.removeJpaProject(this.getJpaProject_(project));
- }
-
-
- // ********** Java element changed **********
-
- /* CU private */ void javaElementChanged(ElementChangedEvent event) {
- this.eventHandler.execute(this.buildJavaElementChangedCommand(event));
- }
-
- private Command buildJavaElementChangedCommand(final ElementChangedEvent event) {
- return new EventHandlerCommand("Java element changed Command") { //$NON-NLS-1$
- @Override
- void execute_() {
- GenericJpaProjectManager.this.javaElementChanged_(event);
- }
- };
- }
-
- /**
- * Forward the Java element changed event to all the JPA projects
- * because the event could affect multiple projects.
- */
- /* CU private */ void javaElementChanged_(ElementChangedEvent event) {
- for (JpaProject jpaProject : this.jpaProjects) {
- jpaProject.javaElementChanged(event);
- }
- }
-
-
- // ********** misc **********
-
- @Override
- public void toString(StringBuilder sb) {
- sb.append(this.jpaProjects);
- }
-
-
- // ********** event handler **********
-
- /**
- * If the event handler is executing asynchronously:<br>
- * Allow all the commands currently on the command executor's queue to execute.
- * Once they have executed, suspend the command executor and process the
- * specified command (on <em>this</em> thread, <em>not</em> the command
- * executor thread). Once the specified command is finished, allow the
- * command executor to resume processing its command queue.
- * <p>
- * If the event handler is executing synchronously:<br>
- * All the events have already been handled synchronously, so we simply
- * execute the specified command [sorta] directly.
- */
- private void executeAfterEventsHandled(Command command) {
- SynchronizedBoolean flag = new SynchronizedBoolean(false);
- this.eventHandler.execute(new PauseCommand(flag));
- try {
- flag.waitUntilTrue();
- } catch (InterruptedException ex) {
- // ignore - not sure why this thread would be interrupted
- }
- try {
- command.execute();
- } finally {
- flag.setFalse();
- }
- }
-
- /**
- * If this "pause" command is executing (asynchronously) on a different
- * thread than the JPA project manager:<ol>
- * <li>it will set the flag to <code>true</code>, allowing the JPA project
- * manager to resume executing on its own thread
- * <li>then it will suspend its command executor until the JPA project
- * manager sets the flag back to <code>false</code>.
- * </ol>
- * If this "pause" command is executing (synchronously) on the same thread
- * as the JPA project manager, it will simply set the flag to
- * <code>true</code> and return.
- */
- private static class PauseCommand
- implements Command
- {
- private final Thread producerThread;
- private final SynchronizedBoolean flag;
-
- PauseCommand(SynchronizedBoolean flag) {
- this(Thread.currentThread(), flag);
- }
-
- PauseCommand(Thread producerThread, SynchronizedBoolean flag) {
- super();
- this.producerThread = producerThread;
- this.flag = flag;
- }
-
- public void execute() {
- this.flag.setTrue();
- if (Thread.currentThread() != this.producerThread) {
- try {
- this.flag.waitUntilFalse();
- } catch (InterruptedException ex) {
- // ignore - the command executor will check for interruptions
- }
- }
- }
- }
-
- /**
- * This method is called (via reflection) when the test plug-in is loaded.
- * See JptCoreTestsPlugin#start(BundleContext)
- */
- @SuppressWarnings("unused")
- private void handleEventsSynchronously() {
- try {
- this.lock.acquire();
- this.handleEventsSynchronously_();
- } finally {
- this.lock.release();
- }
- }
-
- private void handleEventsSynchronously_() {
- this.eventHandler.stop();
- this.eventHandler = new SimpleCommandExecutor();
- this.eventHandler.start();
- }
-
-
- // ********** resource proxy visitor **********
-
- /**
- * Visit the workspace resource tree, adding a JPA project to the
- * JPA project manager for each open Eclipse project that has a JPA facet.
- */
- private class ResourceProxyVisitor
- implements IResourceProxyVisitor
- {
- ResourceProxyVisitor() {
- super();
- }
-
- public boolean visit(IResourceProxy resourceProxy) {
- switch (resourceProxy.getType()) {
- case IResource.ROOT :
- return true; // all projects are in the "root"
- case IResource.PROJECT :
- this.processProject(resourceProxy);
- return false; // no nested projects
- case IResource.FOLDER :
- return false; // ignore
- case IResource.FILE :
- return false; // ignore
- default :
- return false;
- }
- }
-
- private void processProject(IResourceProxy resourceProxy) {
- if (resourceProxy.isAccessible()) { // the project exists and is open
- IProject project = (IProject) resourceProxy.requestResource();
- if (JpaFacet.isInstalled(project)) {
- GenericJpaProjectManager.this.addJpaProject(project);
- }
- }
- }
-
- @Override
- public String toString() {
- return StringTools.buildToStringFor(this);
- }
-
- }
-
-
- // ********** event handler command **********
-
- /**
- * Command that holds the JPA project manager lock while
- * executing.
- */
- private abstract class EventHandlerCommand
- implements Command
- {
- private final String name;
-
- EventHandlerCommand(String name) {
- super();
- this.name = name;
- }
-
- public final void execute() {
- try {
- GenericJpaProjectManager.this.lock.acquire();
- this.execute_();
- } catch (RuntimeException ex) {
- JptJpaCorePlugin.log(ex);
- } finally {
- GenericJpaProjectManager.this.lock.release();
- }
- }
-
- abstract void execute_();
-
- @Override
- public String toString() {
- return this.name;
- }
- }
-
-
- // ********** resource change listener **********
-
- private class ResourceChangeListener
- implements IResourceChangeListener
- {
- ResourceChangeListener() {
- super();
- }
-
- /**
- * PRE_UNINSTALL is the only facet event we use for
- * removing JPA projects. These are the cases where we listen for resource events.
- * <p>
- * Check for:<ul>
- * <li>facet settings file added/removed/changed
- * (<code>/.settings/org.eclipse.wst.common.project.facet.core.xml</code>)
- * <li>file add/remove - forwarded to the individual JPA projects
- * <li>project clean
- * </ul>
- */
- public void resourceChanged(IResourceChangeEvent event) {
- switch (event.getType()) {
- case IResourceChangeEvent.POST_CHANGE :
- this.processPostChangeEvent(event);
- break;
-
- // workspace or project events
- case IResourceChangeEvent.PRE_REFRESH :
- break; // ignore
- case IResourceChangeEvent.PRE_BUILD :
- break; // ignore
- case IResourceChangeEvent.POST_BUILD :
- this.processPostBuildEvent(event);
- break;
-
- // project-only events
- case IResourceChangeEvent.PRE_CLOSE :
- break; // ignore
- case IResourceChangeEvent.PRE_DELETE :
- break; // ignore
- default :
- break;
- }
- }
-
- private void processPostChangeEvent(IResourceChangeEvent event) {
- debug("Resource POST_CHANGE"); //$NON-NLS-1$
- this.processPostChangeDelta(event.getDelta());
- }
-
- private void processPostChangeDelta(IResourceDelta delta) {
- IResource resource = delta.getResource();
- switch (resource.getType()) {
- case IResource.ROOT :
- this.processPostChangeRootDelta(delta);
- break;
- case IResource.PROJECT :
- this.processPostChangeProjectDelta(delta);
- break;
- case IResource.FOLDER :
- this.processPostChangeFolderDelta((IFolder) resource, delta);
- break;
- case IResource.FILE :
- this.processPostChangeFileDelta((IFile) resource, delta);
- break;
- default :
- break;
- }
- }
-
- // ***** POST_CHANGE ROOT
- private void processPostChangeRootDelta(IResourceDelta delta) {
- this.processPostChangeDeltaChildren(delta);
- }
-
- // ***** POST_CHANGE PROJECT
- /**
- * Process the project first for the Opening project case.
- * The JPA project will not be built until the children are processed
- * and we see that the facet metadata file is added.
- * Otherwise the JPA project would be built and then we would process
- * the ADDED deltas for all the files in the project.
- */
- private void processPostChangeProjectDelta(IResourceDelta delta) {
- GenericJpaProjectManager.this.projectChanged(delta);
- this.processPostChangeDeltaChildren(delta);
- }
-
- // ***** POST_CHANGE FOLDER
- private void processPostChangeFolderDelta(IFolder folder, IResourceDelta delta) {
- if (folder.getName().equals(".settings")) { //$NON-NLS-1$
- this.processPostChangeDeltaChildren(delta);
- }
- }
-
- // ***** POST_CHANGE FILE
- private void processPostChangeFileDelta(IFile file, IResourceDelta delta) {
- if (file.getName().equals(FACETED_PROJECT_FRAMEWORK_SETTINGS_FILE_NAME)) {
- this.checkForFacetFileChanges(file, delta);
- }
- }
-
- private void checkForFacetFileChanges(IFile file, IResourceDelta delta) {
- switch (delta.getKind()) {
- case IResourceDelta.ADDED :
- case IResourceDelta.REMOVED :
- case IResourceDelta.CHANGED :
- GenericJpaProjectManager.this.checkForJpaFacetTransition(file.getProject());
- break;
- case IResourceDelta.ADDED_PHANTOM :
- break; // ignore
- case IResourceDelta.REMOVED_PHANTOM :
- break; // ignore
- default :
- break;
- }
- }
-
- private void processPostChangeDeltaChildren(IResourceDelta delta) {
- for (IResourceDelta child : delta.getAffectedChildren()) {
- this.processPostChangeDelta(child); // recurse
- }
- }
-
- /**
- * A post build event has occurred.
- * Check for whether the build was a "clean" build and trigger project update.
- */
- // ***** POST_BUILD
- private void processPostBuildEvent(IResourceChangeEvent event) {
- debug("Resource POST_BUILD: ", event.getResource()); //$NON-NLS-1$
- if (event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) {
- this.processPostCleanBuildDelta(event.getDelta());
- }
- }
-
- private void processPostCleanBuildDelta(IResourceDelta delta) {
- IResource resource = delta.getResource();
- switch (resource.getType()) {
- case IResource.ROOT :
- this.processPostCleanBuildDeltaChildren(delta);
- break;
- case IResource.PROJECT :
- this.processProjectPostCleanBuild((IProject) resource);
- break;
- case IResource.FOLDER :
- break; // ignore
- case IResource.FILE :
- break; // ignore
- default :
- break;
- }
- }
-
- private void processPostCleanBuildDeltaChildren(IResourceDelta delta) {
- for (IResourceDelta child : delta.getAffectedChildren()) {
- this.processPostCleanBuildDelta(child); // recurse
- }
- }
-
- private void processProjectPostCleanBuild(IProject project) {
- debug("\tProject CLEAN: ", project.getName()); //$NON-NLS-1$
- GenericJpaProjectManager.this.projectPostCleanBuild(project);
- }
-
- @Override
- public String toString() {
- return StringTools.buildToStringFor(this);
- }
-
- }
-
-
- // ********** faceted project listener **********
-
- /**
- * Forward the Faceted project change event back to the JPA project manager.
- */
- private class FacetedProjectListener
- implements IFacetedProjectListener
- {
- FacetedProjectListener() {
- super();
- }
-
- /**
- * Check for:<ul>
- * <li>un-install of JPA facet
- * </ul>
- */
- public void handleEvent(IFacetedProjectEvent event) {
- switch (event.getType()) {
- case PRE_UNINSTALL :
- this.processPreUninstallEvent((IProjectFacetActionEvent) event);
- break;
- default :
- break;
- }
- }
-
- private void processPreUninstallEvent(IProjectFacetActionEvent event) {
- debug("Facet PRE_UNINSTALL: ", event.getProjectFacet()); //$NON-NLS-1$
- if (event.getProjectFacet().equals(JpaFacet.FACET)) {
- GenericJpaProjectManager.this.jpaFacetedProjectPreUninstall(event);
- }
- }
-
- @Override
- public String toString() {
- return StringTools.buildToStringFor(this);
- }
-
- }
-
-
- // ********** Java element change listener **********
-
- /**
- * Forward the Java element change event back to the JPA project manager.
- */
- private class JavaElementChangeListener
- implements IElementChangedListener
- {
- /**
- * A flag to activate/deactivate the listener
- * so we can ignore Java events whenever Dali is manipulating the Java
- * source code via the Dali model. We do this because the 0.5 sec delay
- * between the Java source being changed and the corresponding event
- * being fired causes us no end of pain.
- */
- private volatile boolean active = true;
-
- JavaElementChangeListener() {
- super();
- }
-
- public void elementChanged(ElementChangedEvent event) {
- if (this.active) {
- GenericJpaProjectManager.this.javaElementChanged(event);
- }
- // TODO save unhandled events and process when listener is reactivated?
- }
-
- void setActive(boolean active) {
- this.active = active;
- }
-
- boolean isActive() {
- return this.active;
- }
-
- @Override
- public String toString() {
- return StringTools.buildToStringFor(this);
- }
-
- }
-
-
- // ********** DEBUG **********
-
- // @see JpaProjectManagerTests#testDEBUG()
- private static final boolean DEBUG = false;
-
- /**
- * trigger #toString() call and string concatenation only if DEBUG is true
- */
- /* CU private */ static void debug(String message, Object object) {
- if (DEBUG) {
- debug_(message + object);
- }
- }
-
- /* CU private */ static void debug(String message) {
- if (DEBUG) {
- debug_(message);
- }
- }
-
- private static void debug_(String message) {
- System.out.println(Thread.currentThread().getName() + ": " + message); //$NON-NLS-1$
- }
-
- /* CU private */ static void dumpStackTrace() {
- dumpStackTrace(null);
- }
-
- /* CU private */ static void dumpStackTrace(String message, Object object) {
- if (DEBUG) {
- dumpStackTrace_(message + object);
- }
- }
-
- /* CU private */ static void dumpStackTrace(String message) {
- if (DEBUG) {
- dumpStackTrace_(message);
- }
- }
-
- private static void dumpStackTrace_(String message) {
- // lock System.out so the stack elements are printed out contiguously
- synchronized (System.out) {
- if (message != null) {
- debug_(message);
- }
- StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- // skip the first 3 elements - those are this method and 2 methods in Thread
- for (int i = 3; i < stackTrace.length; i++) {
- StackTraceElement element = stackTrace[i];
- if (element.getMethodName().equals("invoke0")) { //$NON-NLS-1$
- break; // skip all elements outside of the JUnit test
- }
- System.out.println("\t" + element); //$NON-NLS-1$
- }
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java
index 87ea72231d..d92623ff71 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,7 +16,18 @@ import org.eclipse.jpt.common.core.JptResourceModel;
/**
* A JPA Project contains JPA files for all files in the project that
* are relevant to the JPA spec.
- *
+ * <p>
+ * To retrieve the JPA file corresponding to an Eclipse file:
+ * <pre>
+ * IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember("Foo.java");
+ * JpaFile jpaFile = (JpaFile) file.getAdapter(JpaFile.class);
+ * </pre>
+ * This is a non-blocking call; and as a result it will return <code>null</code>
+ * if the JPA file or its JPA project is currently under construction. Use a
+ * {@link Reference JPA file reference} to retrieve a JPA file in a blocking
+ * fashion that will return a JPA file once it and its JPA project have been
+ * constructed.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
@@ -25,6 +36,9 @@ import org.eclipse.jpt.common.core.JptResourceModel;
*
* @version 2.2
* @since 2.0
+ *
+ * @see Reference
+ * @see org.eclipse.jpt.jpa.core.internal.FileAdapterFactory
*/
public interface JpaFile
extends JpaNode
@@ -95,4 +109,25 @@ public interface JpaFile
*/
JpaStructureNode getStructureNode(int textOffset);
+
+ // ********** reference **********
+
+ /**
+ * Standard adapter for retrieving a {@link JpaFile JPA file}:
+ * <pre>
+ * IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Foo Project");
+ * IFile file = project.getFile("plugin.xml");
+ * JpaFile.Reference jpaFileRef = (JpaFile.Reference) file.getAdapter(JpaFile.Reference.class);
+ * JpaFile jpaFile = jpaFileRef.getValue();
+ * </pre>
+ * @see org.eclipse.jpt.jpa.core.internal.FileAdapterFactory
+ */
+ interface Reference {
+ /**
+ * Return the JPA file corresponding to the reference's Eclipse file,
+ * or <code>null</code> if unable to associate the specified file with a
+ * JPA file. This method can be long-running.
+ */
+ JpaFile getValue() throws InterruptedException;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaNode.java
index b1e0e5dfbc..e4081c7c29 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.jpa.core;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jpt.common.core.IResourcePart;
+import org.eclipse.jpt.common.core.ResourceReference;
import org.eclipse.jpt.common.utility.model.Model;
/**
@@ -27,9 +27,14 @@ import org.eclipse.jpt.common.utility.model.Model;
* @since 2.0
*/
public interface JpaNode
- extends Model, IAdaptable, IResourcePart
+ extends Model, IAdaptable, ResourceReference
{
/**
+ * Return the JPA project manager.
+ */
+ JpaProject.Manager getJpaProjectManager();
+
+ /**
* Return the JPA project the node belongs to.
*/
JpaProject getJpaProject();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatform.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatform.java
index 68126056d0..25f2f20261 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatform.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatform.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.jpa.core;
import java.util.Comparator;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jpt.common.core.AnnotationProvider;
import org.eclipse.jpt.common.core.JptResourceType;
@@ -48,6 +49,7 @@ import org.eclipse.wst.common.project.facet.core.DefaultVersionComparator;
* @since 2.0
*/
public interface JpaPlatform
+ extends IAdaptable
{
// ********** meta stuff **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatformFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatformFactory.java
index c3bb9dd128..dd1e4b001d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatformFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaPlatformFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,10 +10,15 @@
package org.eclipse.jpt.jpa.core;
/**
- * This interface is to be implemented by a JPA vendor to build a
- * {@link JpaPlatform}.
+ * This interface is to be implemented by a JPA vendor to extend Dali by
+ * building a {@link JpaPlatform}.
* <p>
- * See the <code>org.eclipse.jpt.jpa.core.jpaPlatforms</code> extension point.
+ * See the extension point
+ * <code>org.eclipse.jpt.jpa.core.jpaPlatforms</code>
+ * in
+ * <code>org.eclipse.jpt.jpa.core/plugin.xml</code>
+ * and
+ * <code>org.eclipse.jpt.jpa.core/schema/jpaPlatforms.exsd</code>
* <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProject.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProject.java
index 2fbd53ac77..7fe5956893 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProject.java
@@ -13,8 +13,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
@@ -22,9 +20,9 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragmentRoot;
import org.eclipse.jpt.common.core.resource.java.JavaResourceTypeCache;
-import org.eclipse.jpt.common.utility.CommandExecutor;
-import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.jpa.db.Catalog;
@@ -35,14 +33,25 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
/**
- * A JPA project is associated with an Eclipse project (and its corresponding
- * Java project). It holds the <em>resource</em> model that corresponds to the
+ * A JPA project is associated with an {@link IProject Eclipse project}
+ * (and its corresponding {@link IJavaProject Java project}).
+ * It holds the <em>resource</em> model that corresponds to the
* various JPA-related resources (the <code>persistence.xml</code> file, its
* mapping files [<code>orm.xml</code>], and the Java source files). It also
* holds the <em>context</em> model that represents
* the JPA metadata, as derived from spec-defined defaults, Java source code
* annotations, and XML descriptors.
* <p>
+ * To retrieve the JPA project corresponding to an Eclipse project:
+ * <pre>
+ * IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Foo Project");
+ * JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
+ * </pre>
+ * This is a non-blocking call; and as a result it will return <code>null</code>
+ * if the JPA project is currently under construction. Use a {@link
+ * Reference JPA project reference} to retrieve a JPA project in a blocking
+ * fashion that will return a JPA project once it has been constructed.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
@@ -51,6 +60,9 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
*
* @version 3.0
* @since 2.0
+ *
+ * @see Reference
+ * @see org.eclipse.jpt.jpa.core.internal.ProjectAdapterFactory
*/
public interface JpaProject
extends JpaNode
@@ -59,6 +71,11 @@ public interface JpaProject
// ********** general **********
/**
+ * Return the JPA project manager.
+ */
+ Manager getManager();
+
+ /**
* Return the JPA project's name, which is the same as the associated
* Eclipse project's name.
*/
@@ -246,87 +263,13 @@ public interface JpaProject
// ********** synchronize context model with resource model **********
/**
- * Return the synchronizer that will synchronize the context model with
- * the resource model whenever the resource model changes.
- */
- Synchronizer getContextModelSynchronizer();
-
- /**
- * Set the synchronizer that will keep the context model synchronized with
- * the resource model whenever the resource model changes.
- * Before setting the synchronizer, clients should save the current
- * synchronizer so it can be restored later.
- *
- * @see #getContextModelSynchronizer()
- */
- void setContextModelSynchronizer(Synchronizer synchronizer);
-
- /**
- * The JPA project's resource model has changed; synchronize the JPA
- * project's context model with it. This method is typically called when the
- * resource model state has changed when it is synchronized with its
- * underlying Eclipse resource as the result of an Eclipse resource change
- * event. This method can also be called when a client (e.g. a JUnit test
- * case) has manipulated the resource model via its API (as opposed to
- * modifying the underlying Eclipse resource directly) and needs the context
- * model to be synchronized accordingly (since manipulating the resource
- * model via its API will not trigger this method). Whether the context
- * model is synchronously (or asynchronously) depends on the current context
- * model synchronizer.
- *
- * @see #synchronizeContextModelAndWait()
+ * Should only be used by [incorrectly written] tests....
+ * [The tests would be more valid if they modified the source code
+ * directly allowing resource/Java change events to <em>synchronize</em>
+ * the context model....]
*/
void synchronizeContextModel();
- /**
- * Force the JPA project's context model to synchronize with it resource
- * model <em>synchronously</em>.
- *
- * @see #synchronizeContextModel()
- * @see #updateAndWait()
- */
- void synchronizeContextModelAndWait();
-
- /**
- * This is the callback used by the context model synchronizer to perform
- * the actual "synchronize".
- */
- IStatus synchronizeContextModel(IProgressMonitor monitor);
-
-
- // ********** project "update" **********
-
- /**
- * Return the synchronizer that will update the context model whenever
- * it has any changes. This allows any intra-JPA project dependencies to
- * be updated.
- */
- CallbackSynchronizer getUpdateSynchronizer();
-
- /**
- * Set the synchronizer that will update the context model whenever
- * it has any changes. This allows any intra-JPA project dependencies to
- * be updated.
- * Before setting the update synchronizer, clients should save the current
- * synchronizer so it can be restored later.
- *
- * @see #getUpdateSynchronizer()
- */
- void setUpdateSynchronizer(CallbackSynchronizer synchronizer);
-
- /**
- * Force the JPA project to "update" <em>synchronously</em>.
- *
- * @see #synchronizeContextModelAndWait()
- */
- void updateAndWait();
-
- /**
- * This is the callback used by the update synchronizer to perform the
- * actual "update".
- */
- IStatus update(IProgressMonitor monitor);
-
// ********** utility **********
@@ -490,23 +433,58 @@ public interface JpaProject
void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses);
- // ********** modifying shared documents **********
+ // ********** manager **********
/**
- * Set a thread-specific implementation of the {@link CommandExecutor}
- * interface that will be used to execute a command to modify a shared
- * document. If necessary, the command executor can be cleared by
- * setting it to <code>null</code>.
- * This allows background clients to modify documents that are
- * already present in the UI. See implementations of {@link CommandExecutor}.
+ * The JPA project manager provides behavior to be used by all the JPA
+ * projects
*/
- void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor);
+ interface Manager {
- /**
- * Return the project-wide implementation of the
- * {@link CommandExecutor} interface.
- */
- CommandExecutor getModifySharedDocumentCommandExecutor();
+ // ********** commands **********
+
+ /**
+ * Execute the specified command, possibly asynchronously, synchronizing
+ * with all the other stuff manipulating the JPA projects
+ * (e.g. resource change events).
+ * If, once the command comes up for execution, the specified JPA project
+ * is no longer present, the command will <em>not</em> be executed by the
+ * JPA project manager.
+ */
+ void execute(JobCommand command, String jobName, JpaProject jpaProject);
+
+
+ // ********** modifying shared documents **********
+
+ /**
+ * Return the project-wide implementation of the
+ * {@link ExtendedCommandExecutor} interface.
+ */
+ ExtendedCommandExecutor getModifySharedDocumentCommandExecutor();
+
+
+ // ********** logging **********
+
+ /**
+ * Log the specified message.
+ */
+ void log(String msg);
+
+ /**
+ * Log the specified exception/error.
+ */
+ void log(Throwable throwable);
+
+ /**
+ * Log the specified message and exception/error.
+ */
+ void log(String msg, Throwable throwable);
+
+ /**
+ * Return an exception handler that can be used by the JPA model.
+ */
+ ExceptionHandler getExceptionHandler();
+ }
// ********** construction config **********
@@ -514,8 +492,12 @@ public interface JpaProject
/**
* The settings used to construct a JPA project.
*/
- interface Config
- {
+ interface Config {
+ /**
+ * Return the JPA platform to be associated with the new JPA project.
+ */
+ Manager getJpaProjectManager();
+
/**
* Return the Eclipse project to be associated with the new JPA project.
*/
@@ -553,4 +535,43 @@ public interface JpaProject
*/
boolean discoverAnnotatedClasses();
}
+
+
+ // ********** reference **********
+
+ /**
+ * Standard adapter for "synchronously" retrieving a
+ * {@link JpaProject JPA project}
+ * (i.e. if necessary, wait for the JPA project to be constructed;
+ * thus the {@link InterruptedException}):
+ * <pre>
+ * IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Foo Project");
+ * JpaProject.Reference jpaProjectRef = (JpaProject.Reference) project.getAdapter(JpaProject.Reference.class);
+ * JpaProject jpaProject = jpaProjectRef.getValue();
+ * </pre>
+ * @see org.eclipse.jpt.jpa.core.internal.ProjectAdapterFactory
+ */
+ interface Reference {
+ /**
+ * Return the JPA project corresponding to the reference's Eclipse project.
+ * Return <code>null</code> if unable to associate the Eclipse
+ * project with a JPA project. This method can be long-running.
+ */
+ JpaProject getValue() throws InterruptedException;
+
+ /**
+ * The JPA settings associated with the reference's Eclipse project
+ * have changed in such a way as to require the associated
+ * JPA project to be completely rebuilt
+ * (e.g. when the user changes a project's JPA platform).
+ * Return the new JPA project.
+ */
+ JpaProject rebuild() throws InterruptedException;
+
+ /**
+ * Build the JPA validation messages for the reference's
+ * Eclipse project.
+ */
+ Iterable<IMessage> buildValidationMessages(IReporter reporter) throws InterruptedException;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProjectManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProjectManager.java
index 2601919a09..2198a3faee 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProjectManager.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaProjectManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,12 +9,21 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.common.utility.BooleanReference;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
import org.eclipse.jpt.common.utility.model.Model;
/**
- * The JPA project manager holds all the JPA projects in the workspace.
+ * The JPA project manager holds all the JPA projects in the Eclipse workspace
+ * and provides support for executing long-running commands that modify the
+ * context model.
+ * <p>
+ * To retrieve the JPA project manager corresponding to an Eclipse workspace:
+ * <pre>
+ * IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ * JpaProjectManager jpaProjectManager = (JpaProjectManager) workspace.getAdapter(JpaProjectManager.class);
+ * </pre>
* <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
@@ -28,47 +37,80 @@ import org.eclipse.jpt.common.utility.model.Model;
public interface JpaProjectManager
extends Model
{
+ // ********** JPA projects **********
+
+ /**
+ * Return the JPA project manager's JPA projects. This is a potentially
+ * long-running query (note the {@link InterruptedException}) as it will
+ * wait for any unbuilt JPA projects to be built or re-built.
+ * @see #getJpaProjects()
+ */
+ Iterable<JpaProject> waitToGetJpaProjects() throws InterruptedException;
+
/**
- * Return the JPA model's JPA projects.
+ * Return the JPA project manager's JPA projects. The returned collection
+ * will not include any unbuilt or currently re-building JPA projects;
+ * but the client can listen for the appropriate events to be notified as
+ * JPA projects are added and/or removed from the collection.
+ * @see #addCollectionChangeListener(String, org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener)
+ * @see #JPA_PROJECTS_COLLECTION
+ * @see #waitToGetJpaProjects()
*/
Iterable<JpaProject> getJpaProjects();
public static final String JPA_PROJECTS_COLLECTION = "jpaProjects"; //$NON-NLS-1$
/**
- * Return the size of the JPA model's list of JPA projects.
+ * The size returned here corresponds to the collection returned by
+ * {@link #getJpaProjects()}.
*/
int getJpaProjectsSize();
- /**
- * Return the JPA project corresponding to the specified Eclipse project.
- * Return <code>null</code> if unable to associate the specified Eclipse
- * project with a JPA project.
- */
- JpaProject getJpaProject(IProject project);
+
+ // ********** batch commands **********
/**
- * Return the JPA file corresponding to the specified Eclipse file,
- * or <code>null</code> if unable to associate the specified file with a
- * JPA file.
+ * Suspend the current thread until the specified command is
+ * executed, configuring the JPA
+ * project manager appropriately so all events, JPA project updates, etc.
+ * are handled synchronously. The assumption is this method will be called
+ * when either the workspace is "headless" (non-UI) or none of the change
+ * events are fired from anywhere but the UI thread (e.g. Java Reconciler
+ * fires change events in a background thread).
+ * @see #execute(Command, ExtendedCommandExecutor)
*/
- JpaFile getJpaFile(IFile file);
+ void execute(Command batchCommand) throws InterruptedException;
/**
- * The JPA settings associated with the specified Eclipse project
- * have changed in such a way as to require the associated
- * JPA project to be completely rebuilt
- * (e.g. when the user changes a project's JPA platform).
+ * Suspend the current thread until the specified command is
+ * executed, configuring the JPA
+ * project manager appropriately so all events, JPA project updates, etc.
+ * are handled synchronously. The assumption is this method will be called
+ * from within a job that may execute on a non-UI thread, necessitating a
+ * command executor that will modify on the UI thread any documents that are
+ * currently open in the UI.
*/
- void rebuildJpaProject(IProject project);
+ void execute(Command command, ExtendedCommandExecutor threadLocalModifySharedDocumentCommandExecutor) throws InterruptedException;
+
+
+ // ********** async event listener flags **********
/**
- * Return whether the model's Java change listener is active.
+ * Add a flag that will be used to determine whether the manager's
+ * asynchronous event listeners are active:<ul>
+ * <li>If all the flags are <code>true</code>, the listeners
+ * are active.
+ * <li>If <em>any</em> flag is <code>false</code>, the listeners
+ * are <em><b>in</b></em>active
+ * </ul>
+ * This flag provides a way for clients to modify the context model directly
+ * without worrying about collisions caused by asynchronous events.
+ * @see #execute(Command, ExtendedCommandExecutor)
*/
- boolean javaElementChangeListenerIsActive();
+ void addAsyncEventListenerFlag(BooleanReference flag);
/**
- * Set whether the model's Java change listener is active.
+ * Remove the specified flag.
+ * @see #addAsyncEventListenerFlag(BooleanReference)
*/
- void setJavaElementChangeListenerIsActive(boolean javaElementChangeListenerIsActive);
-
+ void removeAsyncEventListenerFlag(BooleanReference flag);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java
index c94dbd0088..8a62dc7b3c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaStructureNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,19 +9,18 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.model.Model;
/**
- * Implement this interface for objects that appear in the Structure view
- * This is used by JpaSelection to determine selection in the editor.
- * Details pages are also provided for each JpaStructureNode.
- *
- * I did not implement JpaContextNode and I'm not even sure we should implement
- * JpaNode. It is possibly someone could want a structure node that is
- * not actually a contextNode in the model.//TODO
- *
+ * Interface implemented by any object to appear in the JPA Structure view
+ * and JPA Details View. This interface is also used by the JPA Selection
+ * Managers.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
@@ -32,33 +31,106 @@ import org.eclipse.jpt.common.core.utility.TextRange;
* @since 2.0
*/
public interface JpaStructureNode
- extends JpaNode
+ extends Model, IAdaptable
{
/**
- * Return the structure node at the given offset.
+ * Return the structure node at the specified offset in the structure node's
+ * corresponding text file.
*/
JpaStructureNode getStructureNode(int textOffset);
-
+
/**
* Return the text range to be used to select text in the editor
- * corresponding to this node.
+ * corresponding to the structure node.
*/
TextRange getSelectionTextRange();
-
+
+ /**
+ * Return the structure node's context type.
+ * Type used to identify a JPA structure node's type with respect to the
+ * structure node's context
+ * (i.e. its type in the scope of the JPA platform that created the
+ * structure node and the structure node's resource).
+ *
+ * @see #getJpaPlatform()
+ * @see #getResourceType()
+ * @see #getType()
+ */
+ ContextType getContextType();
+
/**
- * Return a unique identifier for all of this class of structure nodes
+ * Return the structure node's JPA platform.
+ * This is used to find the appropriate UI platform for building the
+ * structure node's JPA Details Page.
*/
- String getId();
-
+ JpaPlatform getJpaPlatform();
+
/**
- * Return the content type of the structure node's resource.
- * This is used to find the appropriate ui provider for building composites
+ * Return the structure node's resource type.
+ * This is used to find the appropriate UI provider for building the
+ * structure node's JPA Details Page.
*/
JptResourceType getResourceType();
/**
- * Dispose of this structureNode and dispose of child structureNodes.
- * Typically this would be used to update the JpaFile rootStructureNodes.
+ * Return the structure node's type.
+ * This is used to find the appropriate UI provider for building the
+ * structure node's JPA Details Page.
+ */
+ Class<? extends JpaStructureNode> getType();
+
+ /**
+ * Dispose the structure node and its children.
+ * Typically this would be used to update the structure node's
+ * JPA file's root structure nodes.
*/
void dispose();
+
+
+ /**
+ * Type used to identify a JPA structure node's type with respect to the
+ * structure node's context
+ * (i.e. its type in the scope of the JPA platform that created the
+ * structure node and the structure node's resource).
+ */
+ final class ContextType {
+ private final JpaStructureNode node;
+
+ public ContextType(JpaStructureNode node) {
+ super();
+ if (node == null) {
+ throw new NullPointerException();
+ }
+ this.node = node;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if ((obj == null) || (obj.getClass() != this.getClass())) {
+ return false;
+ }
+ ContextType other = (ContextType) obj;
+ return this.node.getJpaPlatform().equals(other.node.getJpaPlatform()) &&
+ this.node.getResourceType().equals(other.node.getResourceType()) &&
+ this.node.getType().equals(other.node.getType());
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int hash = 17;
+ hash = hash * prime + this.node.getJpaPlatform().hashCode();
+ hash = hash * prime + this.node.getResourceType().hashCode();
+ hash = hash * prime + this.node.getType().hashCode();
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.node);
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java
index 16c59b2e5d..6e890cf29e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Entity.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -24,7 +24,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
* @since 2.0
*/
public interface Entity
- extends TypeMapping
+ extends IdTypeMapping
{
// ********** name **********
@@ -35,14 +35,6 @@ public interface Entity
String DEFAULT_NAME_PROPERTY = "defaultName"; //$NON-NLS-1$
- // ********** id class **********
-
- /**
- * Return the (aggregate) class reference for configuring and validating id class
- */
- IdClassReference getIdClassReference();
-
-
// ********** table **********
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java
new file mode 100644
index 0000000000..3a14d74832
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/IdTypeMapping.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.context;
+
+/**
+ * ID type mapping:<ul>
+ * <li>entity
+ * <li>mapped superclass
+ * </ul>
+ * Provisional API: This interface is part of an interim API that is still under
+ * development and expected to change significantly before reaching stability.
+ * It is available at this early stage to solicit feedback from pioneering
+ * adopters on the understanding that any code that uses this API will almost
+ * certainly be broken (repeatedly) as the API evolves.
+ */
+public interface IdTypeMapping
+ extends TypeMapping
+{
+ /**
+ * Return the (aggregate) class reference for configuring and validating
+ * the type mapping's ID class.
+ */
+ IdClassReference getIdClassReference();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaRootContextNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaRootContextNode.java
index 72f17ddf63..878eb81f4d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaRootContextNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaRootContextNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,6 @@
package org.eclipse.jpt.jpa.core.context;
import java.util.List;
-
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -30,14 +29,13 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public interface JpaRootContextNode
extends JpaContextNode
{
-
// ********** persistence.xml **********
/**
* String constant associated with changes to the persistence XML property
* @see #addPropertyChangeListener(String, org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener)
*/
- public final static String PERSISTENCE_XML_PROPERTY = "persistenceXml"; //$NON-NLS-1$
+ String PERSISTENCE_XML_PROPERTY = "persistenceXml"; //$NON-NLS-1$
/**
* Return the content represented by the <code>persistence.xml</code>
@@ -53,5 +51,4 @@ public interface JpaRootContextNode
* Add validation messages to the specified list.
*/
public void validate(List<IMessage> messages, IReporter reporter);
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappedSuperclass.java
index 6a60964bef..c931411a09 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappedSuperclass.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappedSuperclass.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,7 @@ package org.eclipse.jpt.jpa.core.context;
* @since 2.0
*/
public interface MappedSuperclass
- extends TypeMapping
+ extends IdTypeMapping
{
- IdClassReference getIdClassReference();
+ // nothing yet
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/XmlFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/XmlFile.java
index f413d9d170..5f42cc33c4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/XmlFile.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/XmlFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.context;
+import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
@@ -31,4 +32,31 @@ public interface XmlFile
* Return the resource model object
*/
JpaXmlResource getXmlResource();
+
+ /**
+ * Return whether the XML file's version is the latest supported by its
+ * JPA platform.
+ */
+ boolean isLatestSupportedVersion();
+
+
+ /**
+ * Common implementations.
+ */
+ class XmlFile_ {
+
+ /**
+ * @see #isLatestSupportedVersion()
+ */
+ public static boolean isLatestSupportedVersion(XmlFile xmlFile) {
+ String xmlFileVersion = xmlFile.getXmlResource().getVersion();
+ String latestVersion = xmlFile.getJpaProject().getJpaPlatform().getMostRecentSupportedResourceType(xmlFile.getXmlResource().getContentType()).getVersion();
+ return Tools.valuesAreEqual(xmlFileVersion, latestVersion);
+ }
+
+ private XmlFile_() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaEntity.java
index 993344ef97..74eea2c80b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaEntity.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -26,14 +26,12 @@ import org.eclipse.jpt.jpa.core.resource.java.EntityAnnotation;
* @since 2.0
*/
public interface JavaEntity
- extends Entity, JavaTypeMapping
+ extends Entity, JavaIdTypeMapping
{
EntityAnnotation getMappingAnnotation();
JavaTable getTable();
- JavaIdClassReference getIdClassReference();
-
JavaDiscriminatorColumn getDiscriminatorColumn();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaStructureNodes.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdTypeMapping.java
index e95b3def50..5a5e64f2a6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaStructureNodes.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdTypeMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,28 +9,19 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.context.java;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.IdTypeMapping;
/**
- *
- *
+ * Java ID type mapping
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
- *
- * @version 2.0
- * @since 2.0
*/
-public interface JavaStructureNodes
+public interface JavaIdTypeMapping
+ extends JavaTypeMapping, IdTypeMapping
{
- String COMPILATION_UNIT_ID =
- JptJpaCorePlugin.PLUGIN_ID + ".java.compilationUnit"; //$NON-NLS-1$
-
- String PERSISTENT_TYPE_ID =
- JptJpaCorePlugin.PLUGIN_ID + ".java.persistentType"; //$NON-NLS-1$
-
- String PERSISTENT_ATTRIBUTE_ID =
- JptJpaCorePlugin.PLUGIN_ID + ".java.persistentAttribute"; //$NON-NLS-1$
+ JavaIdClassReference getIdClassReference();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaMappedSuperclass.java
index ff39157e4b..9e0180153f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaMappedSuperclass.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaMappedSuperclass.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -25,11 +25,14 @@ import org.eclipse.jpt.jpa.core.resource.java.MappedSuperclassAnnotation;
* @since 2.0
*/
public interface JavaMappedSuperclass
- extends MappedSuperclass, JavaTypeMapping
+ extends MappedSuperclass, JavaIdTypeMapping
{
MappedSuperclassAnnotation getMappingAnnotation();
- JavaIdClassReference getIdClassReference();
-
+ /**
+ * According to the spec,
+ * only <em>Java</em> mapped superclasses can have queries.
+ * The <code>orm.xml</code> mapped superclasses cannot.
+ */
JavaQueryContainer getQueryContainer();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmEntity.java
index 37ae997983..0a2231800d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmEntity.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -29,7 +29,7 @@ import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity;
* @since 2.0
*/
public interface OrmEntity
- extends Entity, OrmTypeMapping
+ extends Entity, OrmIdTypeMapping
{
XmlEntity getXmlTypeMapping();
@@ -39,8 +39,6 @@ public interface OrmEntity
OrmTable getTable();
- OrmIdClassReference getIdClassReference();
-
OrmDiscriminatorColumn getDiscriminatorColumn();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmStructureNodes.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmIdTypeMapping.java
index 64bd9c75bc..fa247bc878 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmStructureNodes.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmIdTypeMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,27 +9,19 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.context.orm;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.IdTypeMapping;
/**
- *
- *
+ * <code>orm.xml</code> ID type mapping
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
- *
- * @version 2.0
- * @since 2.0
*/
-public interface OrmStructureNodes
+public interface OrmIdTypeMapping
+ extends OrmTypeMapping, IdTypeMapping
{
-
- String ENTITY_MAPPINGS_ID = JptJpaCorePlugin.PLUGIN_ID + ".orm.entityMappings"; //$NON-NLS-1$
-
- String PERSISTENT_TYPE_ID = JptJpaCorePlugin.PLUGIN_ID + ".orm.persistentType"; //$NON-NLS-1$
-
- String PERSISTENT_ATTRIBUTE_ID = JptJpaCorePlugin.PLUGIN_ID + ".orm.persistentAttribute"; //$NON-NLS-1$
-
+ OrmIdClassReference getIdClassReference();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java
index 437675b778..5c74a5156f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/OrmMappedSuperclass.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -26,12 +26,10 @@ import org.eclipse.jpt.jpa.core.resource.orm.XmlMappedSuperclass;
* @since 2.0
*/
public interface OrmMappedSuperclass
- extends MappedSuperclass, OrmTypeMapping
+ extends MappedSuperclass, OrmIdTypeMapping
{
XmlMappedSuperclass getXmlTypeMapping();
- OrmIdClassReference getIdClassReference();
-
JavaMappedSuperclass getJavaTypeMapping();
JavaMappedSuperclass getJavaTypeMappingForDefaults();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/ClassRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/ClassRef.java
index 5902e9dd5f..76a81be189 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/ClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/ClassRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,6 +11,8 @@ package org.eclipse.jpt.jpa.core.context.persistence;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
@@ -95,6 +97,17 @@ public interface ClassRef
*/
JavaPersistentType getJavaPersistentType();
+ Transformer<ClassRef, JavaPersistentType> JAVA_PERSISTENT_TYPE_TRANSFORMER = new JavaPersistentTypeTransformer();
+
+ class JavaPersistentTypeTransformer
+ extends AbstractTransformer<ClassRef, JavaPersistentType>
+ {
+ @Override
+ protected JavaPersistentType transform_(ClassRef ref) {
+ return ref.getJavaPersistentType();
+ }
+ }
+
// ********** refactoring **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java
index 1ae7d394b8..363d9f6996 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,6 +10,8 @@
package org.eclipse.jpt.jpa.core.context.persistence;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
import org.eclipse.jpt.jpa.core.context.java.JarFile;
@@ -64,6 +66,17 @@ public interface JarFileRef
*/
JarFile getJarFile();
+ Transformer<JarFileRef, JarFile> JAR_FILE_TRANSFORMER = new JarFileTransformer();
+
+ class JarFileTransformer
+ extends AbstractTransformer<JarFileRef, JarFile>
+ {
+ @Override
+ protected JarFile transform_(JarFileRef ref) {
+ return ref.getJarFile();
+ }
+ }
+
// ********** refactoring **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java
index ae341bec17..0c25241a99 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,6 +14,8 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.Generator;
import org.eclipse.jpt.jpa.core.context.MappingFile;
@@ -84,6 +86,17 @@ public interface MappingFileRef
*/
MappingFile getMappingFile();
+ Transformer<MappingFileRef, MappingFile> MAPPING_FILE_TRANSFORMER = new MappingFileTransformer();
+
+ class MappingFileTransformer
+ extends AbstractTransformer<MappingFileRef, MappingFile>
+ {
+ @Override
+ protected MappingFile transform_(MappingFileRef ref) {
+ return ref.getMappingFile();
+ }
+ }
+
// ********** persistence unit metadata **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/Persistence.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/Persistence.java
index 6008ae34b4..80a3fddecd 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/Persistence.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/Persistence.java
@@ -35,57 +35,63 @@ public interface Persistence
* Return the resource model object associated with this context model object
*/
XmlPersistence getXmlPersistence();
-
+
/**
* Covariant override.
*/
PersistenceXml getParent();
-
- // **************** persistence units **************************************
-
+ PersistenceXml getPersistenceXml();
+
+
+ // ********** persistence units **********
+
/**
* String constant associated with changes to the persistence units list
*/
String PERSISTENCE_UNITS_LIST = "persistenceUnits"; //$NON-NLS-1$
-
+
/**
* Return the persistence element's persistence units.
*/
ListIterable<PersistenceUnit> getPersistenceUnits();
-
+
/**
* Return the number of persistence units.
*/
int getPersistenceUnitsSize();
-
+
+ /**
+ * Return the persistence unit at the specified index.
+ */
+ PersistenceUnit getPersistenceUnit(int index);
+
/**
* Add a persistence unit and return it.
*/
PersistenceUnit addPersistenceUnit();
-
+
/**
* Add a persistence unit at the specified index and return it.
*/
PersistenceUnit addPersistenceUnit(int index);
-
+
/**
* Remove the specified persistence unit from the persistence node.
*/
void removePersistenceUnit(PersistenceUnit persistenceUnit);
-
+
/**
* Remove the persistence unit at the specified index from the persistence node.
*/
void removePersistenceUnit(int index);
-
-
- // **************** text range *********************************************
-
+
+
+ // ********** text range **********
+
/**
* Return whether the text representation of this persistence contains
* the specified text offset.
*/
boolean containsOffset(int textOffset);
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceStructureNodes.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceStructureNodes.java
deleted file mode 100644
index 2e34050432..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceStructureNodes.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core.context.persistence;
-
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-
-/**
- *
- *
- * Provisional API: This interface is part of an interim API that is still
- * under development and expected to change significantly before reaching
- * stability. It is available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- *
- * @version 2.2
- * @since 2.0
- */
-public interface PersistenceStructureNodes
-{
- String PREFIX = JptJpaCorePlugin.PLUGIN_ID_ + "persistence"; //$NON-NLS-1$
- String PREFIX_ = PREFIX + '.';
-
- String PERSISTENCE_ID = PREFIX_ + "persistence"; //$NON-NLS-1$
- String PERSISTENCE_UNIT_ID = PREFIX_ + "persistenceUnit"; //$NON-NLS-1$
- String CLASS_REF_ID = PREFIX_ + "classRef"; //$NON-NLS-1$
- String MAPPING_FILE_REF_ID = PREFIX_ + "mappingFileRef"; //$NON-NLS-1$
- String JAR_FILE_REF_ID = PREFIX_ + "jarFileRef"; //$NON-NLS-1$
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java
index eb3e15ace8..7485e99b95 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java
@@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.context.persistence;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
@@ -726,6 +727,13 @@ public interface PersistenceUnit
*/
boolean containsOffset(int textOffset);
+ /**
+ * Synchronize the persistence unit's list of specified classes with the
+ * types in the project currently annotated.
+ */
+ void synchronizeClasses(IProgressMonitor monitor);
+
+
// ********** validation **********
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java
index c9b6422427..db59f411f1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaNode.java
@@ -17,7 +17,7 @@ import java.util.Set;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jpt.common.core.internal.utility.jdt.JDTModifiedDeclaration.Adapter;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
@@ -26,6 +26,7 @@ import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable;
+import org.eclipse.jpt.common.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.AspectChangeSupport;
import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
@@ -100,9 +101,9 @@ public abstract class AbstractJpaNode
// ********** IAdaptable implementation **********
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public Object getAdapter(Class adapter) {
- return Platform.getAdapterManager().getAdapter(this, adapter);
+ return PlatformTools.getAdapter(this, adapter);
}
@@ -116,10 +117,17 @@ public abstract class AbstractJpaNode
return this.parent.getResource();
}
+ /**
+ * @see AbstractJpaProject#getJpaProject()
+ */
public JpaProject getJpaProject() {
return this.parent.getJpaProject();
}
+ public JpaProject.Manager getJpaProjectManager() {
+ return this.getJpaProject().getManager();
+ }
+
// ********** convenience methods **********
@@ -127,7 +135,11 @@ public abstract class AbstractJpaNode
return this.getJpaProject().getJavaProject();
}
- protected JpaPlatform getJpaPlatform() {
+ /**
+ * This is <code>public</code> as a convenience because various subclasses
+ * implement interfaces that require this method.
+ */
+ public JpaPlatform getJpaPlatform() {
return this.getJpaProject().getJpaPlatform();
}
@@ -182,6 +194,30 @@ public abstract class AbstractJpaNode
}
+ // ********** logging **********
+
+ /**
+ * Log the specified message.
+ */
+ protected void log(String msg) {
+ this.getJpaProjectManager().log(msg);
+ }
+
+ /**
+ * Log the specified exception/error.
+ */
+ protected void log(Throwable throwable) {
+ this.getJpaProjectManager().log(throwable);
+ }
+
+ /**
+ * Log the specified message and exception/error.
+ */
+ protected void log(String msg, Throwable throwable) {
+ this.getJpaProjectManager().log(msg, throwable);
+ }
+
+
// ********** AspectChangeSupport.Listener support **********
protected void aspectChanged(String aspectName) {
@@ -245,8 +281,9 @@ public abstract class AbstractJpaNode
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class CollectionContainer<C, R> {
-
+ protected abstract class CollectionContainer<C, R>
+ implements Iterable<C>
+ {
protected final Vector<C> contextElements = new Vector<C>();
protected CollectionContainer() {
@@ -291,6 +328,10 @@ public abstract class AbstractJpaNode
return new LiveCloneIterable<C>(this.contextElements);
}
+ public Iterator<C> iterator() {
+ return new CloneIterator<C>(this.contextElements);
+ }
+
/**
* Return the size of the context elements collection
*/
@@ -307,36 +348,57 @@ public abstract class AbstractJpaNode
}
/**
- * Add the specified context element to the collection ignoring
- * the specified index as we only have a collection
+ * Add the specified context element to the container at the specified
+ * index.
+ */
+ protected abstract C addContextElement_(int index, C element);
+
+ /**
+ * Add context elements for the specified resource elements at the
+ * specified index.
*/
- protected C addContextElement_(@SuppressWarnings("unused") int index, C contextElement) {
- AbstractJpaNode.this.addItemToCollection(contextElement, this.contextElements, this.getContextElementsPropertyName());
- return contextElement;
+ public Iterable<C> addContextElements(int index, Iterable<R> resourceElements) {
+ ArrayList<C> newContextElements = new ArrayList<C>();
+ for (R resourceElement : resourceElements) {
+ newContextElements.add(this.buildContextElement(resourceElement));
+ }
+ return this.addAll(index, newContextElements);
}
/**
+ * Add the specified context elements to the collection.
+ */
+ protected abstract Iterable<C> addAll(int index, Iterable<C> elements);
+
+ /**
* Remove the specified context element from the container.
*/
- public void removeContextElement(C element) {
- AbstractJpaNode.this.removeItemFromCollection(element, this.contextElements, this.getContextElementsPropertyName());
- }
+ public abstract void removeContextElement(C element);
- @SuppressWarnings("unused")
- protected void moveContextElement(int index, C element) {
- //no-op, not a list
+ /**
+ * Remove the specified context elements from the container.
+ */
+ public abstract void removeAll(Iterable<C> elements);
+
+ protected abstract void moveContextElement(int index, C element);
+
+ @Override
+ public String toString() {
+ return this.contextElements.toString();
}
}
+
/**
* Adapter used to synchronize a context collection container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class ContextCollectionContainer<C extends JpaContextNode, R> extends CollectionContainer<C, R> {
-
- protected ContextCollectionContainer() {
+ protected abstract class AbstractContextCollectionContainer<C extends JpaContextNode, R>
+ extends CollectionContainer<C, R>
+ {
+ protected AbstractContextCollectionContainer() {
super();
}
@@ -417,16 +479,61 @@ public abstract class AbstractJpaNode
}
}
+
/**
- * Adapter used to synchronize a context list container with its corresponding
+ * Adapter used to synchronize a context collection container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class ListContainer<C, R>
- extends CollectionContainer<C, R> {
+ protected abstract class ContextCollectionContainer<C extends JpaContextNode, R>
+ extends AbstractContextCollectionContainer<C, R>
+ {
+ protected ContextCollectionContainer() {
+ super();
+ }
- protected ListContainer() {
+ @Override
+ protected C addContextElement_(int index, C element) {
+ // ignore the index - not a list
+ AbstractJpaNode.this.addItemToCollection(element, this.contextElements, this.getContextElementsPropertyName());
+ return element;
+ }
+
+ @Override
+ protected Iterable<C> addAll(int index, Iterable<C> elements) {
+ // ignore the index - not a list
+ AbstractJpaNode.this.addItemsToCollection(elements, this.contextElements, this.getContextElementsPropertyName());
+ return elements;
+ }
+
+ @Override
+ public void removeContextElement(C element) {
+ AbstractJpaNode.this.removeItemFromCollection(element, this.contextElements, this.getContextElementsPropertyName());
+ }
+
+ @Override
+ public void removeAll(Iterable<C> elements) {
+ AbstractJpaNode.this.removeItemsFromCollection(elements, this.contextElements, this.getContextElementsPropertyName());
+ }
+
+ @Override
+ protected void moveContextElement(int index, C element) {
+ // NOP - not a list
+ }
+ }
+
+
+ /**
+ * Adapter used to synchronize a context list container with its corresponding
+ * resource container.
+ * @param <C> the type of context elements
+ * @param <R> the type of resource elements
+ */
+ protected abstract class ContextListContainer<C extends JpaContextNode, R>
+ extends AbstractContextCollectionContainer<C, R>
+ {
+ protected ContextListContainer() {
super();
}
@@ -441,22 +548,24 @@ public abstract class AbstractJpaNode
/**
* Return the index of the specified context element.
*/
- public int indexOfContextElement(C contextElement) {
- return this.contextElements.indexOf(contextElement);
+ public int indexOfContextElement(C element) {
+ return this.contextElements.indexOf(element);
}
public C getContextElement(int index) {
return this.contextElements.elementAt(index);
}
- /**
- * Add a context element for the specified resource element at the
- * specified index.
- */
@Override
- protected C addContextElement_(int index, C contextElement) {
- AbstractJpaNode.this.addItemToList(index, contextElement, this.contextElements, this.getContextElementsPropertyName());
- return contextElement;
+ protected C addContextElement_(int index, C element) {
+ AbstractJpaNode.this.addItemToList(index, element, this.contextElements, this.getContextElementsPropertyName());
+ return element;
+ }
+
+ @Override
+ protected Iterable<C> addAll(int index, Iterable<C> elements) {
+ AbstractJpaNode.this.addItemsToList(index, elements, this.contextElements, this.getContextElementsPropertyName());
+ return elements;
}
/**
@@ -464,56 +573,50 @@ public abstract class AbstractJpaNode
* specified source index.
*/
public void moveContextElement(int targetIndex, int sourceIndex) {
- this.moveContextElement(targetIndex, this.contextElements.get(sourceIndex));
+ AbstractJpaNode.this.moveItemInList(targetIndex, sourceIndex, this.contextElements, this.getContextElementsPropertyName());
}
- /**
- * Move the specified context element to the specified index.
- */
@Override
public void moveContextElement(int index, C element) {
AbstractJpaNode.this.moveItemInList(index, element, this.contextElements, this.getContextElementsPropertyName());
}
/**
+ * clear the list of context elements
+ */
+ public void clearContextList() {
+ AbstractJpaNode.this.clearList(this.contextElements, getContextElementsPropertyName());
+ }
+
+ /**
* Remove the context element at the specified index from the container.
*/
- public void removeContextElement(int index) {
- AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ public C removeContextElement(int index) {
+ return AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
}
- public void synchronizeWithResourceModel() {
- ListIterable<R> resourceElements = getResourceElements();
-
- int index = 0;
- for (R resourceElement : resourceElements) {
- if (this.getContextElementsSize() > index) {
- if (this.getContextElement(index) != resourceElement) {
- this.addContextElement(index, resourceElement);
- }
- }
- else {
- this.addContextElement(index, resourceElement);
- }
- index++;
- }
-
- for ( ; index < this.getContextElementsSize(); ) {
- this.removeContextElement(index);
- }
+ @Override
+ public void removeContextElement(C element) {
+ this.removeContextElement(this.indexOfContextElement(element));
+ }
+
+ @Override
+ public void removeAll(Iterable<C> elements) {
+ AbstractJpaNode.this.removeItemsFromList(elements, this.contextElements, this.getContextElementsPropertyName());
}
}
+
/**
* Adapter used to synchronize a context list container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class ContextListContainer<C extends JpaContextNode, R>
- extends ContextCollectionContainer<C, R> {
-
- protected ContextListContainer() {
+ protected abstract class ListContainer<C, R>
+ extends CollectionContainer<C, R>
+ {
+ protected ListContainer() {
super();
}
@@ -528,22 +631,24 @@ public abstract class AbstractJpaNode
/**
* Return the index of the specified context element.
*/
- public int indexOfContextElement(C contextElement) {
- return this.contextElements.indexOf(contextElement);
+ public int indexOfContextElement(C element) {
+ return this.contextElements.indexOf(element);
}
public C getContextElement(int index) {
- return this.contextElements.elementAt(index);
+ return this.contextElements.get(index);
+ }
+
+ @Override
+ protected C addContextElement_(int index, C element) {
+ AbstractJpaNode.this.addItemToList(index, element, this.contextElements, this.getContextElementsPropertyName());
+ return element;
}
- /**
- * Add a context element for the specified resource element at the
- * specified index.
- */
@Override
- protected C addContextElement_(int index, C contextElement) {
- AbstractJpaNode.this.addItemToList(index, contextElement, this.contextElements, this.getContextElementsPropertyName());
- return contextElement;
+ protected Iterable<C> addAll(int index, Iterable<C> newContextElements) {
+ AbstractJpaNode.this.addItemsToList(index, newContextElements, this.contextElements, this.getContextElementsPropertyName());
+ return newContextElements;
}
/**
@@ -551,34 +656,50 @@ public abstract class AbstractJpaNode
* specified source index.
*/
public void moveContextElement(int targetIndex, int sourceIndex) {
- this.moveContextElement(targetIndex, this.contextElements.get(sourceIndex));
- }
-
- /**
- * clear the list of context elements
- */
- public void clearContextList() {
- AbstractJpaNode.this.clearList(this.contextElements, getContextElementsPropertyName());
+ AbstractJpaNode.this.moveItemInList(targetIndex, sourceIndex, this.contextElements, this.getContextElementsPropertyName());
}
- /**
- * Move the specified context element to the specified index.
- */
@Override
public void moveContextElement(int index, C element) {
AbstractJpaNode.this.moveItemInList(index, element, this.contextElements, this.getContextElementsPropertyName());
}
+ @Override
+ public void removeContextElement(C element) {
+ this.removeContextElement(this.indexOfContextElement(element));
+ }
+
/**
* Remove the context element at the specified index from the container.
*/
- public C removeContextElement(int index) {
- return AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ public void removeContextElement(int index) {
+ AbstractJpaNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
}
@Override
- public void removeContextElement(C contextElement) {
- this.removeContextElement(this.indexOfContextElement(contextElement));
+ public void removeAll(Iterable<C> elements) {
+ AbstractJpaNode.this.removeItemsFromList(elements, this.contextElements, this.getContextElementsPropertyName());
+ }
+
+ public void synchronizeWithResourceModel() {
+ ListIterable<R> resourceElements = getResourceElements();
+
+ int index = 0;
+ for (R resourceElement : resourceElements) {
+ if (this.getContextElementsSize() > index) {
+ if (this.getContextElement(index) != resourceElement) {
+ this.addContextElement(index, resourceElement);
+ }
+ }
+ else {
+ this.addContextElement(index, resourceElement);
+ }
+ index++;
+ }
+
+ for ( ; index < this.getContextElementsSize(); ) {
+ this.removeContextElement(index);
+ }
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
index aedda37c2d..533f8799bc 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
@@ -3,7 +3,7 @@
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -24,13 +24,15 @@ import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
@@ -46,7 +48,9 @@ import org.eclipse.jpt.common.core.JptResourceModelListener;
import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryTypeCache;
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceTypeCompilationUnit;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
-import org.eclipse.jpt.common.core.resource.ResourceLocator;
+import org.eclipse.jpt.common.core.internal.utility.command.NotifyingRepeatingJobCommandWrapper;
+import org.eclipse.jpt.common.core.internal.utility.command.RepeatingJobCommandWrapper;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
@@ -54,13 +58,14 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragmentRoot;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceTypeCache;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.core.utility.command.JobCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.NotifyingRepeatingJobCommand;
+import org.eclipse.jpt.common.core.utility.command.RepeatingJobCommand;
import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.BitTools;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.internal.ThreadLocalCommandExecutor;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
@@ -68,10 +73,6 @@ import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SnapshotCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
-import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
import org.eclipse.jpt.jpa.core.JpaDataSource;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaFile;
@@ -94,6 +95,7 @@ import org.eclipse.jpt.jpa.db.SchemaContainer;
import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider;
import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderFramework;
import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -103,16 +105,16 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
/**
* JPA project. Holds all the JPA stuff.
- *
+ * <p>
* The JPA platform provides the hooks for vendor-specific stuff.
- *
+ * <p>
* The JPA files are the "resource" model (i.e. objects that correspond directly
* to Eclipse resources; e.g. Java source code files, XML files, JAR files).
- *
- * The root context node is the "context"model (i.e. objects that attempt to
+ * <p>
+ * The root context node is the "context" model (i.e. objects that attempt to
* model the JPA spec, using the "resource" model as an adapter to the Eclipse
* resources).
- *
+ * <p>
* The data source is an adapter to the DTP meta-data model.
*/
public abstract class AbstractJpaProject
@@ -120,6 +122,11 @@ public abstract class AbstractJpaProject
implements JpaProject2_0
{
/**
+ * The JPA project manager.
+ */
+ protected final Manager manager;
+
+ /**
* The Eclipse project corresponding to the JPA project.
*/
protected final IProject project;
@@ -161,35 +168,20 @@ public abstract class AbstractJpaProject
protected final JpaRootContextNode rootContextNode;
/**
- * A pluggable synchronizer that keeps the JPA
- * project's context model synchronized with its resource model, either
- * synchronously or asynchronously (or not at all). A synchronous synchronizer
- * is the default. For performance reasons, a UI should
- * immediately change this to an asynchronous synchronizer. A synchronous
- * synchronizer can be used when the project is being manipulated by a "batch"
- * (or non-UI) client (e.g. when testing "synchronization"). A null updater
- * can used during tests that do not care whether "synchronization" occur.
- * Clients will need to explicitly configure the synchronizer if they require
- * an asynchronous synchronizer.
+ * A repeating command that keeps the JPA project's context model
+ * synchronized with its resource model, either synchronously or
+ * asynchronously (or not at all), depending on the JPA project manager.
*/
- protected volatile Synchronizer contextModelSynchronizer;
+ protected volatile RepeatingJobCommand synchronizeContextModelCommand;
protected volatile boolean synchronizingContextModel = false;
/**
* A pluggable synchronizer that "updates" the JPA project, either
- * synchronously or asynchronously (or not at all). A synchronous updater
- * is the default, allowing a newly-constructed JPA project to be "updated"
- * upon return from the constructor. For performance reasons, a UI should
- * immediately change this to an asynchronous updater. A synchronous
- * updater can be used when the project is being manipulated by a "batch"
- * (or non-UI) client (e.g. when testing the "update" behavior). A null
- * updater can used during tests that do not care whether "synchronization"
- * occur.
- * Clients will need to explicitly configure the updater if they require
- * an asynchronous updater.
+ * synchronously or asynchronously (or not at all), depending on the JPA
+ * project manager.
*/
- protected volatile CallbackSynchronizer updateSynchronizer;
- protected final CallbackSynchronizer.Listener updateSynchronizerListener;
+ protected volatile NotifyingRepeatingJobCommand updateCommand;
+ protected final NotifyingRepeatingJobCommand.Listener updateCommandListener;
/**
* The data source that wraps the DTP model.
@@ -216,11 +208,6 @@ public abstract class AbstractJpaProject
protected volatile boolean discoversAnnotatedClasses;
/**
- * Support for modifying documents shared with the UI.
- */
- protected final ThreadLocalCommandExecutor modifySharedDocumentCommandExecutor;
-
- /**
* The name of the Java project source folder that holds the generated
* metamodel. If the name is <code>null</code> the metamodel is not
* generated.
@@ -232,18 +219,19 @@ public abstract class AbstractJpaProject
protected AbstractJpaProject(JpaProject.Config config) {
super(null); // JPA project is the root of the containment tree
- if ((config.getProject() == null) || (config.getJpaPlatform() == null)) {
+ if ((config.getJpaProjectManager() == null) || (config.getProject() == null) || (config.getJpaPlatform() == null)) {
throw new NullPointerException();
}
+ this.manager = config.getJpaProjectManager();
this.project = config.getProject();
+ this.synchronizeContextModelCommand = this.buildSynchronizeContextModelCommand();
+ this.updateCommand = this.buildTempUpdateCommand(); // temporary command
this.jpaPlatform = config.getJpaPlatform();
this.dataSource = this.getJpaFactory().buildJpaDataSource(this, config.getConnectionProfileName());
this.userOverrideDefaultCatalog = config.getUserOverrideDefaultCatalog();
this.userOverrideDefaultSchema = config.getUserOverrideDefaultSchema();
this.discoversAnnotatedClasses = config.discoverAnnotatedClasses();
- this.modifySharedDocumentCommandExecutor = this.buildModifySharedDocumentCommandExecutor();
-
this.resourceModelListener = this.buildResourceModelListener();
// build the JPA files corresponding to the Eclipse project's files
InitialResourceProxyVisitor visitor = this.buildInitialResourceProxyVisitor();
@@ -260,12 +248,8 @@ public abstract class AbstractJpaProject
this.rootContextNode = this.buildRootContextNode();
- // there *shouldn't* be any changes to the resource model...
- this.setContextModelSynchronizer_(this.buildSynchronousContextModelSynchronizer());
-
- this.updateSynchronizerListener = this.buildUpdateSynchronizerListener();
- // "update" the project before returning
- this.setUpdateSynchronizer_(this.buildSynchronousUpdateSynchronizer());
+ this.updateCommandListener = this.buildUpdateCommandListener();
+ this.initializeContextModel();
// start listening to this cache once the context model has been built
// and all the external types are faulted in
@@ -290,6 +274,31 @@ public abstract class AbstractJpaProject
return this.getJpaFactory().buildRootContextNode(this);
}
+ /**
+ * Execute a synchronous <em>sync</em> and <em>update</em> before returning
+ * from the constructor.
+ */
+ protected void initializeContextModel() {
+ // there *shouldn't* be any changes to the resource model yet...
+ this.synchronizeContextModelCommand.start();
+
+ // perform a synchronous update...
+ this.updateCommand.start();
+ this.update();
+ try {
+ this.updateCommand.stop();
+ } catch (InterruptedException ex) {
+ // the initial update is synchronous, so this shouldn't happen...
+ // but let our thread know it was interrupted during a wait
+ Thread.currentThread().interrupt();
+ }
+
+ // ...then delegate further updates to the JPA project manager
+ this.updateCommand = this.buildUpdateCommand();
+ this.updateCommand.addListener(this.updateCommandListener);
+ this.updateCommand.start();
+ }
+
// ********** initial resource proxy visitor **********
@@ -297,7 +306,9 @@ public abstract class AbstractJpaProject
return new InitialResourceProxyVisitor();
}
- protected class InitialResourceProxyVisitor implements IResourceProxyVisitor {
+ protected class InitialResourceProxyVisitor
+ implements IResourceProxyVisitor
+ {
protected InitialResourceProxyVisitor() {
super();
}
@@ -325,6 +336,10 @@ public abstract class AbstractJpaProject
return false; // no children
}
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
}
@@ -350,6 +365,10 @@ public abstract class AbstractJpaProject
return this;
}
+ public Manager getManager() {
+ return this.manager;
+ }
+
public String getName() {
return this.project.getName();
}
@@ -582,10 +601,13 @@ public abstract class AbstractJpaProject
}
protected boolean fileResourceLocationIsValid(IFile file) {
- ResourceLocator resourceLocator = JptCommonCorePlugin.getResourceLocator(this.getProject());
- return resourceLocator.acceptResourceLocation(this.getProject(), file.getParent());
+ return this.getProjectResourceLocator().resourceLocationIsValid(file.getParent());
}
+ protected ProjectResourceLocator getProjectResourceLocator() {
+ return (ProjectResourceLocator) this.project.getAdapter(ProjectResourceLocator.class);
+ }
+
/**
* Log any developer exceptions and don't build a JPA file rather
* than completely failing to build the JPA Project.
@@ -594,7 +616,7 @@ public abstract class AbstractJpaProject
try {
return this.getJpaPlatform().buildJpaFile(this, file);
} catch (Exception ex) {
- JptJpaCorePlugin.log(ex);
+ JptJpaCorePlugin.log("Error building JPA file: " + file.getFullPath(), ex); //$NON-NLS-1$
return null;
}
}
@@ -709,7 +731,7 @@ public abstract class AbstractJpaProject
jdtCompilationUnit,
this.jpaPlatform.getAnnotationProvider(),
this.jpaPlatform.getAnnotationEditFormatter(),
- this.modifySharedDocumentCommandExecutor
+ this.manager.getModifySharedDocumentCommandExecutor()
);
}
@@ -739,7 +761,7 @@ public abstract class AbstractJpaProject
// ********** utility **********
public IFile getPlatformFile(IPath runtimePath) {
- return JptCommonCorePlugin.getPlatformFile(this.project, runtimePath);
+ return this.getProjectResourceLocator().getPlatformFile(runtimePath);
}
@@ -767,7 +789,7 @@ public abstract class AbstractJpaProject
*/
protected JptResourceModel getResourceModel(IPath runtimePath, IContentType contentType) {
IFile file = this.getPlatformFile(runtimePath);
- return (file != null && file.exists()) ? this.getResourceModel(file, contentType) : null;
+ return ((file != null) && file.exists()) ? this.getResourceModel(file, contentType) : null;
}
/**
@@ -832,13 +854,13 @@ public abstract class AbstractJpaProject
return new FilteringIterable<JavaResourceAbstractType>(this.getInternalAnnotatedSourceJavaResourceTypes()) {
@Override
protected boolean accept(JavaResourceAbstractType jraType) {
- return jraType.isAnnotatedWith(getTypeMappingAnnotations());
+ return jraType.isAnnotatedWith(AbstractJpaProject.this.getTypeMappingAnnotations());
}
};
}
public Iterable<String> getTypeMappingAnnotations() {
- return new TransformationIterable<JavaTypeMappingDefinition, String>(getJpaPlatform().getJavaTypeMappingDefinitions()) {
+ return new TransformationIterable<JavaTypeMappingDefinition, String>(this.getJpaPlatform().getJavaTypeMappingDefinitions()) {
@Override
protected String transform(JavaTypeMappingDefinition o) {
return o.getAnnotationName();
@@ -902,8 +924,8 @@ public abstract class AbstractJpaProject
}
public JavaResourceAbstractType getJavaResourceType(String typeName, JavaResourceAbstractType.Kind kind) {
- JavaResourceAbstractType resourceType = getJavaResourceType(typeName);
- if (resourceType == null || resourceType.getKind() != kind) {
+ JavaResourceAbstractType resourceType = this.getJavaResourceType(typeName);
+ if ((resourceType == null) || (resourceType.getKind() != kind)) {
return null;
}
return resourceType;
@@ -982,7 +1004,7 @@ public abstract class AbstractJpaProject
// TODO
public JavaResourcePackageFragmentRoot getJavaResourcePackageFragmentRoot(String jarFileName) {
// return this.getJarResourcePackageFragmentRoot(this.convertToPlatformFile(jarFileName));
- return this.getJavaResourcePackageFragmentRoot(this.getProject().getFile(jarFileName));
+ return this.getJavaResourcePackageFragmentRoot(this.project.getFile(jarFileName));
}
protected JavaResourcePackageFragmentRoot getJavaResourcePackageFragmentRoot(IFile jarFile) {
@@ -1072,12 +1094,75 @@ public abstract class AbstractJpaProject
/**
* Synchronize the metamodel for 2.0-compatible JPA projects.
*/
- public void synchronizeMetamodel() {
+ public IStatus synchronizeMetamodel(IProgressMonitor monitor) {
if (this.isJpa2_0Compatible()) {
if (this.metamodelSourceFolderName != null) {
- ((JpaRootContextNode2_0) this.rootContextNode).synchronizeMetamodel();
+ this.scheduleSynchronizeMetamodelJob();
}
}
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * We dispatch a job even when the JPA project manager is "synchronous"
+ * because we will synchronously execute an update when we receive a
+ * resource change event that is fired when a file is changed; and we
+ * cannot modify another file in response to a file change because the
+ * rules are incompatible. For example, if the <code>persistence.xml</code>
+ * file changes, we will receive a resource change event while the
+ * <code>persistence.xml</code> file is locked. We will not be able to
+ * lock and modify the necessary metamodel source files under this lock.
+ */
+ protected void scheduleSynchronizeMetamodelJob() {
+ this.buildSynchronizeMetamodelJob().schedule();
+ }
+
+ protected Job buildSynchronizeMetamodelJob() {
+ Job job = this.buildSynchronizeMetamodelJob_();
+ // lock the project so we are synchronized with the JPA project manager
+ job.setRule(this.project);
+ return job;
+ }
+
+ protected Job buildSynchronizeMetamodelJob_() {
+ return new SynchronizeMetamodelJob(this.buildSynchronizeMetamodelJobName());
+ }
+
+ protected String buildSynchronizeMetamodelJobName() {
+ return NLS.bind(JptCoreMessages.METAMODEL_SYNC_JOB_NAME, this.getName());
+ }
+
+ /**
+ * Use a {@link WorkspaceJob} to
+ * suppress the resource change events until we are finished synchronizing
+ * the metamodel.
+ */
+ protected class SynchronizeMetamodelJob
+ extends WorkspaceJob
+ {
+ protected SynchronizeMetamodelJob(String name) {
+ super(name);
+ }
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ return AbstractJpaProject.this.synchronizeMetamodel_(monitor);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
+ }
+
+ /**
+ * Called by the {@link SynchronizeMetamodelJob#runInWorkspace(IProgressMonitor)}.
+ * <p>
+ * Now that we have the appropriate resource locks, acquire the JPA project
+ * manager lock. This is a hack to get around the Eclipse restriction
+ * that prevents us from acquiring incompatible locks/scheduling rules; at
+ * the risk of deadlocks(!).
+ */
+ protected IStatus synchronizeMetamodel_(IProgressMonitor monitor) {
+ return ((JpaRootContextNode2_0) this.rootContextNode).synchronizeMetamodel(monitor);
}
public void disposeMetamodel() {
@@ -1091,7 +1176,7 @@ public abstract class AbstractJpaProject
}
protected IFolder getMetaModelSourceFolder() {
- return this.getProject().getFolder(this.metamodelSourceFolderName);
+ return this.project.getFolder(this.metamodelSourceFolderName);
}
/**
@@ -1288,15 +1373,13 @@ public abstract class AbstractJpaProject
*/
protected boolean jpaFileIsAlive(JpaFile jpaFile) {
IFile file = jpaFile.getFile();
- if (! file.exists()) {
+ if ( ! file.exists()) {
return false;
}
- if (fileIsJavaRelated(file)) {
- return getJavaProject().isOnClasspath(file);
- }
- else {
- return fileResourceLocationIsValid(file);
+ if (this.fileIsJavaRelated(file)) {
+ return this.getJavaProject().isOnClasspath(file);
}
+ return this.fileResourceLocationIsValid(file);
}
/**
@@ -1363,6 +1446,12 @@ public abstract class AbstractJpaProject
}
protected boolean javaCompilationUnitDeltaIsRelevant(IJavaElementDelta delta) {
+ // ignore Java notification for ADDED or REMOVED;
+ // these are handled via resource notification
+ if (delta.getKind() != IJavaElementDelta.CHANGED) {
+ return false;
+ }
+
// ignore changes to/from primary working copy - no content has changed;
// and make sure there are no other flags set that indicate *both* a
// change to/from primary working copy *and* content has changed
@@ -1370,9 +1459,24 @@ public abstract class AbstractJpaProject
return false;
}
- // ignore java notification for ADDED or REMOVED;
- // these are handled via resource notification
- return delta.getKind() == IJavaElementDelta.CHANGED;
+ // ignore when the compilation unit's resource is deleted;
+ // because the AST parser will log an exception for the missing file
+ if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_RESOURCE)) {
+ ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement();
+ if ( ! this.compilationUnitResourceExists(compilationUnit)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected boolean compilationUnitResourceExists(ICompilationUnit compilationUnit) {
+ try {
+ return compilationUnit.getCorrespondingResource().exists();
+ } catch (JavaModelException ex) {
+ return false;
+ }
}
@@ -1403,11 +1507,11 @@ public abstract class AbstractJpaProject
protected void validateLibraryProvider_(List<IMessage> messages) throws CoreException {
Map<String, Object> enablementVariables = new HashMap<String, Object>();
- enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, getJpaPlatform().getId());
- enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, getJpaPlatform().getDescription());
+ enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, this.getJpaPlatform().getId());
+ enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, this.getJpaPlatform().getDescription());
- ILibraryProvider libraryProvider = LibraryProviderFramework.getCurrentProvider(getProject(), JpaFacet.FACET);
- IFacetedProject facetedProject = ProjectFacetsManager.create(getProject());
+ ILibraryProvider libraryProvider = LibraryProviderFramework.getCurrentProvider(this.project, JpaFacet.FACET);
+ IFacetedProject facetedProject = ProjectFacetsManager.create(this.project);
IProjectFacetVersion facetVersion = facetedProject.getInstalledVersion(JpaFacet.FACET);
if ( ! libraryProvider.isEnabledFor(facetedProject, facetVersion, enablementVariables)) {
messages.add(
@@ -1460,9 +1564,9 @@ public abstract class AbstractJpaProject
// ********** dispose **********
public void dispose() {
- this.contextModelSynchronizer.stop();
- this.updateSynchronizer.stop();
- this.updateSynchronizer.removeListener(this.updateSynchronizerListener);
+ this.stopCommand(this.synchronizeContextModelCommand);
+ this.stopCommand(this.updateCommand);
+ this.updateCommand.removeListener(this.updateCommandListener);
this.dataSource.dispose();
// the XML resources are held indefinitely by the WTP translator framework,
// so we better remove our listener or the JPA project will not be GCed
@@ -1471,20 +1575,29 @@ public abstract class AbstractJpaProject
}
}
+ protected void stopCommand(RepeatingJobCommand command) {
+ try {
+ command.stop();
+ } catch (InterruptedException ex) {
+ // allow the dispose to complete;
+ // but let our thread know it was interrupted during a wait
+ Thread.currentThread().interrupt();
+ }
+ }
+
// ********** resource model listener **********
protected JptResourceModelListener buildResourceModelListener() {
- return new DefaultResourceModelListener();
+ return new ResourceModelListener();
}
- protected class DefaultResourceModelListener
+ protected class ResourceModelListener
implements JptResourceModelListener
{
- protected DefaultResourceModelListener() {
+ protected ResourceModelListener() {
super();
}
-
public void resourceModelChanged(JptResourceModel jpaResourceModel) {
// String msg = Thread.currentThread() + " resource model change: " + jpaResourceModel;
// System.out.println(msg);
@@ -1502,8 +1615,17 @@ public abstract class AbstractJpaProject
IFile file = WorkbenchResourceHelper.getFile((JpaXmlResource)jpaResourceModel);
AbstractJpaProject.this.removeJpaFile(file);
}
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
}
+ /**
+ * Called from {@link ResourceModelListener#resourceModelChanged(JptResourceModel)}.
+ */
+ // TODO pass down the resource model (for a possible optimization?)
protected void synchronizeContextModel(@SuppressWarnings("unused") JptResourceModel jpaResourceModel) {
this.synchronizeContextModel();
}
@@ -1513,7 +1635,7 @@ public abstract class AbstractJpaProject
// TODO need to do the same thing for external projects and compilation units
public void projectChanged(IResourceDelta delta) {
- if (delta.getResource().equals(this.getProject())) {
+ if (delta.getResource().equals(this.project)) {
this.internalProjectChanged(delta);
} else {
this.externalProjectChanged(delta);
@@ -1521,10 +1643,6 @@ public abstract class AbstractJpaProject
}
protected void internalProjectChanged(IResourceDelta delta) {
- if (delta.getKind() == IResourceDelta.REMOVED) {
- this.setContextModelSynchronizer(Synchronizer.Null.instance());
- this.setUpdateSynchronizer(CallbackSynchronizer.Null.instance());
- }
ResourceDeltaVisitor resourceDeltaVisitor = this.buildInternalResourceDeltaVisitor();
resourceDeltaVisitor.visitDelta(delta);
// at this point, if we have added and/or removed JpaFiles, an "update" will have been triggered;
@@ -1540,7 +1658,9 @@ public abstract class AbstractJpaProject
return new InternalResourceDeltaVisitor();
}
- protected class InternalResourceDeltaVisitor extends ResourceDeltaVisitor {
+ protected class InternalResourceDeltaVisitor
+ extends ResourceDeltaVisitor
+ {
protected InternalResourceDeltaVisitor() {
super();
}
@@ -1548,6 +1668,10 @@ public abstract class AbstractJpaProject
public boolean fileChangeIsSignificant(IFile file, int deltaKind) {
return AbstractJpaProject.this.synchronizeJpaFiles(file, deltaKind);
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
}
/**
@@ -1576,7 +1700,7 @@ public abstract class AbstractJpaProject
protected boolean checkForChangedFileContent(IFile file) {
JpaFile jpaFile = this.getJpaFile(file);
if (jpaFile == null) {
- // the file might have changed its content to something that we are interested in
+ // the file might have changed its content to something significant to Dali
return this.addJpaFile(file);
}
@@ -1585,7 +1709,7 @@ public abstract class AbstractJpaProject
return false;
}
- // the content type changed, we need to build a new JPA file
+ // the content type changed, we need to remove the old JPA file and build a new one
// (e.g. the schema of an orm.xml file changed from JPA to EclipseLink)
this.removeJpaFile(jpaFile);
this.addJpaFile(file);
@@ -1616,7 +1740,9 @@ public abstract class AbstractJpaProject
return new ExternalResourceDeltaVisitor();
}
- protected class ExternalResourceDeltaVisitor extends ResourceDeltaVisitor {
+ protected class ExternalResourceDeltaVisitor
+ extends ResourceDeltaVisitor
+ {
protected ExternalResourceDeltaVisitor() {
super();
}
@@ -1624,6 +1750,10 @@ public abstract class AbstractJpaProject
public boolean fileChangeIsSignificant(IFile file, int deltaKind) {
return AbstractJpaProject.this.synchronizeExternalFiles(file, deltaKind);
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
}
/**
@@ -1688,7 +1818,9 @@ public abstract class AbstractJpaProject
/**
* add or remove a JPA file for every [appropriate] file encountered by the visitor
*/
- protected abstract class ResourceDeltaVisitor implements IResourceDeltaVisitor {
+ protected abstract class ResourceDeltaVisitor
+ implements IResourceDeltaVisitor
+ {
protected boolean encounteredSignificantChange = false;
protected ResourceDeltaVisitor() {
@@ -1738,114 +1870,115 @@ public abstract class AbstractJpaProject
return this.encounteredSignificantChange;
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
}
- // ********** support for modifying documents shared with the UI **********
-
- public void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor) {
- this.modifySharedDocumentCommandExecutor.set(commandExecutor);
- }
-
- public CommandExecutor getModifySharedDocumentCommandExecutor() {
- return this.modifySharedDocumentCommandExecutor;
- }
+ // ********** synchronize context model with resource model **********
- protected ThreadLocalCommandExecutor buildModifySharedDocumentCommandExecutor() {
- return new ThreadLocalCommandExecutor();
+ protected RepeatingJobCommand buildSynchronizeContextModelCommand() {
+ return new RepeatingJobCommandWrapper(
+ this.buildSynchronizeContextModelJobCommand(),
+ this.buildStartSynchronizeContextModelJobCommandExecutor(),
+ this.manager.getExceptionHandler()
+ );
}
-
- // ********** synchronize context model with resource model **********
-
- public Synchronizer getContextModelSynchronizer() {
- return this.contextModelSynchronizer;
+ protected JobCommand buildSynchronizeContextModelJobCommand() {
+ return new SynchronizeContextModelJobCommand();
}
- public void setContextModelSynchronizer(Synchronizer synchronizer) {
- if (synchronizer == null) {
- throw new NullPointerException();
- }
- this.contextModelSynchronizer.stop();
- this.setContextModelSynchronizer_(synchronizer);
+ protected JobCommandExecutor buildStartSynchronizeContextModelJobCommandExecutor() {
+ return new ManagerJobCommandExecutor(this.buildSynchronizeContextModelJobName());
}
- protected void setContextModelSynchronizer_(Synchronizer synchronizer) {
- this.contextModelSynchronizer = synchronizer;
- this.contextModelSynchronizer.start();
+ protected String buildSynchronizeContextModelJobName() {
+ return NLS.bind(JptCoreMessages.CONTEXT_MODEL_SYNC_JOB_NAME, this.getName());
}
/**
- * Delegate to the context model synchronizer so clients can configure how
- * synchronizations occur.
+ * The JPA project's resource model has changed; synchronize the JPA
+ * project's context model with it. This method is typically called when the
+ * resource model state has changed when it is synchronized with its
+ * underlying Eclipse resource as the result of an Eclipse resource change
+ * event. This method can also be called when a client (e.g. a JUnit test
+ * case) has manipulated the resource model via its API (as opposed to
+ * modifying the underlying Eclipse resource directly) and needs the context
+ * model to be synchronized accordingly (since manipulating the resource
+ * model via its API will not trigger this method). Whether the context
+ * model is synchronously (or asynchronously) depends on the JPA project
+ * manager.
*/
public void synchronizeContextModel() {
- this.synchronizingContextModel = true;
- this.contextModelSynchronizer.synchronize();
- this.synchronizingContextModel = false;
+ try {
+ this.synchronizingContextModel = true;
+ this.synchronizeContextModelCommand.execute(null); // this progress monitor is ignored
+ } finally {
+ this.synchronizingContextModel = false;
+ }
// There are some changes to the resource model that will not change
// the existing context model and trigger an update (e.g. adding an
// @Entity annotation when the JPA project is automatically
// discovering annotated classes); so we explicitly execute an update
// here to discover those changes.
+ // TODO change sync so it will *always* trigger an update?
this.update();
}
+ protected class SynchronizeContextModelJobCommand
+ implements JobCommand
+ {
+ public IStatus execute(IProgressMonitor monitor) {
+ return AbstractJpaProject.this.synchronizeContextModel(monitor);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
+ }
+
/**
- * Called by the context model synchronizer.
+ * Called by the {@link SynchronizeContextModelJobCommand#execute(IProgressMonitor)}.
*/
- public IStatus synchronizeContextModel(IProgressMonitor monitor) {
+ // TODO pass the monitor down
+ protected IStatus synchronizeContextModel(@SuppressWarnings("unused") IProgressMonitor monitor) {
this.rootContextNode.synchronizeWithResourceModel();
return Status.OK_STATUS;
}
- public void synchronizeContextModelAndWait() {
- Synchronizer temp = this.contextModelSynchronizer;
- this.setContextModelSynchronizer(this.buildSynchronousContextModelSynchronizer());
- this.synchronizeContextModel();
- this.setContextModelSynchronizer(temp);
- }
+ // ********** JPA project "update" **********
- // ********** default context model synchronizer (synchronous) **********
-
- protected Synchronizer buildSynchronousContextModelSynchronizer() {
- return new SynchronousSynchronizer(this.buildSynchronousContextModelSynchronizerCommand());
+ /**
+ * The first update is executed synchronously during construction.
+ * Once that is complete, we delegate to the JPA project manager.
+ */
+ protected NotifyingRepeatingJobCommand buildTempUpdateCommand() {
+ return new NotifyingRepeatingJobCommandWrapper(this.buildUpdateJobCommand(), this.manager.getExceptionHandler());
}
- protected Command buildSynchronousContextModelSynchronizerCommand() {
- return new SynchronousContextModelSynchronizerCommand();
+ protected NotifyingRepeatingJobCommand buildUpdateCommand() {
+ return new NotifyingRepeatingJobCommandWrapper(
+ this.buildUpdateJobCommand(),
+ this.buildStartUpdateJobCommandExecutor(),
+ this.manager.getExceptionHandler()
+ );
}
- protected class SynchronousContextModelSynchronizerCommand
- implements Command
- {
- public void execute() {
- AbstractJpaProject.this.synchronizeContextModel(new NullProgressMonitor());
- }
+ protected JobCommand buildUpdateJobCommand() {
+ return new UpdateJobCommand();
}
-
- // ********** project "update" **********
-
- public CallbackSynchronizer getUpdateSynchronizer() {
- return this.updateSynchronizer;
+ protected JobCommandExecutor buildStartUpdateJobCommandExecutor() {
+ return new ManagerJobCommandExecutor(this.buildUpdateJobName());
}
- public void setUpdateSynchronizer(CallbackSynchronizer synchronizer) {
- if (synchronizer == null) {
- throw new NullPointerException();
- }
- this.updateSynchronizer.stop();
- this.updateSynchronizer.removeListener(this.updateSynchronizerListener);
- this.setUpdateSynchronizer_(synchronizer);
- }
-
- protected void setUpdateSynchronizer_(CallbackSynchronizer synchronizer) {
- this.updateSynchronizer = synchronizer;
- this.updateSynchronizer.addListener(this.updateSynchronizerListener);
- this.updateSynchronizer.start();
+ protected String buildUpdateJobName() {
+ return NLS.bind(JptCoreMessages.UPDATE_JOB_NAME, this.getName());
}
@Override
@@ -1858,7 +1991,7 @@ public abstract class AbstractJpaProject
* The JPA project's state has changed, "update" those parts of the
* JPA project that are dependent on other parts of the JPA project.
* <p>
- * Delegate to the update synchronizer so clients can configure how
+ * Delegate to the JPA project manager so clients can configure how
* updates occur.
* <p>
* Ignore any <em>updates</em> that occur while we are synchronizing
@@ -1867,70 +2000,100 @@ public abstract class AbstractJpaProject
* only useful for synchronous <em>syncs</em> and <em>updates</em>; since
* the job scheduling rules will prevent the <em>sync</em> and
* <em>update</em> jobs from running concurrently.
- *
- * @see #updateAndWait()
*/
protected void update() {
if ( ! this.synchronizingContextModel) {
- this.updateSynchronizer.synchronize();
+ this.updateCommand.execute(null); // this progress monitor is ignored
}
}
- /**
- * Called by the update synchronizer.
- */
- public IStatus update(IProgressMonitor monitor) {
- this.rootContextNode.update();
- return Status.OK_STATUS;
+ protected class UpdateJobCommand
+ implements JobCommand
+ {
+ public IStatus execute(IProgressMonitor monitor) {
+ return AbstractJpaProject.this.update(monitor);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
+ }
}
/**
- * This is the callback used by the update synchronizer to notify the JPA
- * project that the "update" has quiesced (i.e. the "update" has completed
- * and there are no outstanding requests for further "updates").
+ * Called by the {@link UpdateJobCommand#execute(IProgressMonitor)}.
*/
- public void updateQuiesced() {
- this.synchronizeMetamodel();
- }
-
- public void updateAndWait() {
- CallbackSynchronizer temp = this.updateSynchronizer;
- this.setUpdateSynchronizer(this.buildSynchronousUpdateSynchronizer());
- this.update();
- this.setUpdateSynchronizer(temp);
+ // TODO pass the monitor down
+ protected IStatus update(@SuppressWarnings("unused") IProgressMonitor monitor) {
+ this.rootContextNode.update();
+ return Status.OK_STATUS;
}
- // ********** default update synchronizer (synchronous) **********
-
- protected CallbackSynchronizer buildSynchronousUpdateSynchronizer() {
- return new CallbackSynchronousSynchronizer(this.buildSynchronousUpdateSynchronizerCommand());
- }
+ // ********** update command listener **********
- protected Command buildSynchronousUpdateSynchronizerCommand() {
- return new SynchronousUpdateSynchronizerCommand();
+ protected NotifyingRepeatingJobCommand.Listener buildUpdateCommandListener() {
+ return new UpdateCommandListener();
}
- protected class SynchronousUpdateSynchronizerCommand
- implements Command
+ protected class UpdateCommandListener
+ implements NotifyingRepeatingJobCommand.Listener
{
- public void execute() {
- AbstractJpaProject.this.update(new NullProgressMonitor());
+ public IStatus executionQuiesced(JobCommand command, IProgressMonitor monitor) {
+ return AbstractJpaProject.this.updateQuiesced(monitor);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, AbstractJpaProject.this);
}
}
+ /**
+ * This is the callback used by the update command to notify the JPA
+ * project that the "update" has quiesced (i.e. the "update" has completed
+ * and there are no outstanding requests for further "updates").
+ * Called by {@link UpdateCommandListener#executionQuiesced(JobCommand, IProgressMonitor)}.
+ */
+ protected IStatus updateQuiesced(IProgressMonitor monitor) {
+ return this.synchronizeMetamodel(monitor);
+ }
- // ********** update synchronizer listener **********
- protected CallbackSynchronizer.Listener buildUpdateSynchronizerListener() {
- return new UpdateSynchronizerListener();
- }
+ // ********** job command executor **********
- protected class UpdateSynchronizerListener
- implements CallbackSynchronizer.Listener
+ /**
+ * Delegate execution to the JPA project manager, which will determine
+ * whether commands are executed synchronously or asynchronously.
+ *
+ * @see #buildStartSynchronizeContextModelJobCommandExecutor()
+ * @see #buildStartUpdateJobCommandExecutor()
+ */
+ protected class ManagerJobCommandExecutor
+ implements JobCommandExecutor
{
- public void synchronizationQuiesced(CallbackSynchronizer synchronizer) {
- AbstractJpaProject.this.updateQuiesced();
+ protected final String defaultJobName;
+ protected ManagerJobCommandExecutor(String defaultJobName) {
+ super();
+ if (defaultJobName == null) {
+ throw new NullPointerException();
+ }
+ this.defaultJobName = defaultJobName;
+ }
+ /**
+ * This should be the only method called on this executor....
+ */
+ public void execute(JobCommand command) {
+ this.execute(command, this.defaultJobName);
+ }
+ public void execute(JobCommand command, String jobName) {
+ AbstractJpaProject.this.manager.execute(command, jobName, AbstractJpaProject.this);
+ }
+ public void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ // the JPA project manager will supply the scheduling rule
+ this.execute(command, jobName);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.defaultJobName);
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/FileAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/FileAdapterFactory.java
new file mode 100644
index 0000000000..30c17dd44e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/FileAdapterFactory.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.common.core.JptResourceModel;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
+
+/**
+ * Factory to build Dali adapters for an {@link IFile}
+ * (The comments for the adapters produced by {@link ProjectAdapterFactory}
+ * are applicable here also):<ul>
+ * <li>{@link org.eclipse.jpt.jpa.core.JpaFile.Reference JpaFile.Reference}
+ * <li>{@link org.eclipse.jpt.jpa.core.JpaFile JpaFile}
+ * <li>{@link JpaXmlResource} -
+ * Like the JPA file adapter, this adapter will only return a JPA XML
+ * resource if it is immediately available.
+ * This adapter should be used by any process that can ignore
+ * any uncreated JPA XML resources because it is demand-driven and re-queries
+ * for the JPA XML resource every time it executes and its results are only
+ * temporary (e.g. UI menus).
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>.
+ *
+ * @see ProjectAdapterFactory
+ */
+public class FileAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaFile.Reference.class,
+ JpaFile.class,
+ JpaXmlResource.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IFile) {
+ return this.getAdapter((IFile) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IFile file, Class<?> adapterType) {
+ if (adapterType == JpaFile.Reference.class) {
+ return this.getJpaFileReference(file);
+ }
+ if (adapterType == JpaFile.class) {
+ return this.getJpaFile(file);
+ }
+ if (adapterType == JpaXmlResource.class) {
+ return this.getJpaXmlResource(file);
+ }
+ return null;
+ }
+
+ private JpaFile.Reference getJpaFileReference(IFile file) {
+ return new JpaFileReference(file);
+ }
+
+ private JpaFile getJpaFile(IFile file) {
+ JpaProject jpaProject = this.getJpaProject(file.getProject());
+ return (jpaProject == null) ? null : jpaProject.getJpaFile(file);
+ }
+
+ private JpaXmlResource getJpaXmlResource(IFile file) {
+ JpaFile jpaFile = this.getJpaFile(file);
+ if (jpaFile != null) {
+ JptResourceModel resourceModel = jpaFile.getResourceModel();
+ if (resourceModel instanceof JpaXmlResource) {
+ return (JpaXmlResource) resourceModel;
+ }
+ }
+ return null;
+ }
+
+ private JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
+
+ // ********** JPA file reference **********
+
+ /**
+ * @see ProjectAdapterFactory.JpaProjectReference
+ */
+ /* CU private */ static class JpaFileReference
+ implements JpaFile.Reference
+ {
+ private final IFile file;
+
+ JpaFileReference(IFile file) {
+ super();
+ this.file = file;
+ }
+
+ public JpaFile getValue() throws InterruptedException {
+ JpaProject jpaProject = this.getJpaProject();
+ return (jpaProject == null) ? null : jpaProject.getJpaFile(this.file);
+ }
+
+ private JpaProject getJpaProject() throws InterruptedException {
+ return this.getJpaProjectReference().getValue();
+ }
+
+ private JpaProject.Reference getJpaProjectReference() {
+ return ((JpaProject.Reference) this.file.getProject().getAdapter(JpaProject.Reference.class));
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.file);
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java
index f304a0f6b5..6a45d503d7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -17,6 +17,7 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.core.internal.utility.jdt.DefaultAnnotationEditFormatter;
import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.EntityGeneratorDatabaseAnnotationNameBuilder;
import org.eclipse.jpt.jpa.core.JpaFactory;
import org.eclipse.jpt.jpa.core.JpaFile;
@@ -83,6 +84,11 @@ public class GenericJpaPlatform
return this.jpaVersion;
}
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.id);
+ }
+
// ********** factory **********
@@ -201,6 +207,14 @@ public class GenericJpaPlatform
}
+ // ********** adapter **********
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public Object getAdapter(Class adapter) {
+ return PlatformTools.getAdapter(this, adapter);
+ }
+
+
// ********** Hermes integration **********
public JPQLGrammar getJpqlGrammar() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
new file mode 100644
index 0000000000..fdacc8dccf
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
@@ -0,0 +1,1417 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Vector;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobManager;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.ElementChangedEvent;
+import org.eclipse.jdt.core.IElementChangedListener;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
+import org.eclipse.jpt.common.core.internal.utility.command.CommandJobCommandAdapter;
+import org.eclipse.jpt.common.core.internal.utility.command.SimpleJobCommandExecutor;
+import org.eclipse.jpt.common.core.internal.utility.command.SingleUseQueueingExtendedJobCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.ExtendedJobCommandExecutor;
+import org.eclipse.jpt.common.core.utility.command.JobCommand;
+import org.eclipse.jpt.common.utility.BooleanReference;
+import org.eclipse.jpt.common.utility.ExceptionHandler;
+import org.eclipse.jpt.common.utility.ModifiableObjectReference;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.command.ExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.command.ThreadLocalExtendedCommandExecutor;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.jpt.common.utility.internal.iterables.SnapshotCloneIterable;
+import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.jpa.core.JpaFacet;
+import org.eclipse.jpt.jpa.core.JpaPlatform;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
+import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+
+/**
+ * The JPA project manager maintains a list of all the JPA projects in the
+ * workspace. It keeps the list (and the state of the JPA projects themselves)
+ * synchronized with the workspace by listening for Resource and Java change
+ * events.
+ * <p>
+ * We use Eclipse {@link ISchedulingRule scheduling rules} to synchronize
+ * access to the JPA projects when dealing with these events. In an effort to
+ * reduce deadlocks, the Resource and Java change events are dispatched to
+ * background jobs, allowing us to handle the events outside of the workspace
+ * lock held during Resource and Java change notifications. The
+ * {@link ISchedulingRule scheduling rules} are also used to synchronize the
+ * event handling with the various other asynchronous Dali activities:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.core.internal.validation.JpaValidator Validation}
+ * <li>JPA Project context model {@link JpaProject#synchronizeContextModel()
+ * <em>synchronization</em>} [with the resource model]
+ * <li>JPA Project {@link org.eclipse.jpt.jpa.core.internal.AbstractJpaProject#update()
+ * <em>update</em>}
+ * </ul>
+ * Any method that returns a value (e.g. {@link #waitToGetJpaProjects()}) is
+ * "synchronized" with the background jobs. This allows any outstanding events
+ * to be handled <em>before</em> the value is returned.
+ * <p>
+ * Various things that cause us to add or remove a JPA project:<ul>
+ * <li>The {@link JptJpaCorePlugin} will "lazily" instantiate and
+ * {@link #start() start} a JPA project manager as appropriate.
+ * This will trigger the manager to find and add all pre-existing
+ * JPA projects.
+ *
+ * <li>Project created and facet installed<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}
+ * <li>Project facet uninstalled<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}
+ *
+ * <li>Project opened<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#ADDED}<p>
+ * facet settings file<p>
+ * (<code>.settings/org.eclipse.wst.common.project.facet.core.xml</code>)
+ * <li>Project closed<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#REMOVED}
+ * <p>facet settings file
+ *
+ * <li>Pre-existing project imported from directory or archive (created and opened)<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#ADDED}<p>
+ * facet settings file
+ * <li>Project renamed<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#REMOVED}<p>
+ * facet settings file of old project<p>
+ * -> {@link IResourceDelta#ADDED}<p>
+ * facet settings file of new project
+ * <li>Project deleted<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#REMOVED}<p>
+ * facet settings file
+ *
+ * <li>Project facet installed by editing the facets settings file directly<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#CHANGED}<p>
+ * facet settings file
+ * <li>Project facet uninstalled by editing the facets settings file directly<p>
+ * {@link IResourceChangeEvent#POST_CHANGE}<p>
+ * -> {@link IResource#FILE}<p>
+ * -> {@link IResourceDelta#CHANGED}<p>
+ * facet settings file
+ * </ul>
+ */
+public class InternalJpaProjectManager
+ extends AbstractModel
+ implements JpaProjectManager, JpaProject.Manager
+{
+ /**
+ * Determine how commands (Resource and Java change events etc.) are
+ * handled (i.e. synchronously or asynchronously).
+ * The default command executor executes commands asynchronously via
+ * Eclipse {@link Job jobs}.
+ */
+ private volatile ExtendedJobCommandExecutor commandExecutor;
+
+ /**
+ * All the JPA projects in the workspace.
+ */
+ private final Vector<JpaProject> jpaProjects = new Vector<JpaProject>();
+
+ /**
+ * Listen for<ul>
+ * <li>changes to<ul>
+ * <li>projects
+ * <li>package fragment roots
+ * <li>files
+ * </ul>
+ * <li>clean builds
+ * </ul>
+ */
+ private final IResourceChangeListener resourceChangeListener = new ResourceChangeListener();
+
+ /**
+ * The types of resource change events that interest
+ * {@link #resourceChangeListener}.
+ */
+ private static final int RESOURCE_CHANGE_EVENT_TYPES =
+ IResourceChangeEvent.POST_CHANGE |
+ IResourceChangeEvent.POST_BUILD;
+
+ /**
+ * Listen for changes to this file to determine when the JPA facet is
+ * added to or removed from a "faceted" project.
+ */
+ private static final String FACETED_PROJECT_FRAMEWORK_SETTINGS_FILE_NAME = FacetedProjectFramework.PLUGIN_ID + ".xml"; //$NON-NLS-1$
+
+ /**
+ * Listen for Java changes (unless the Dali UI is active).
+ * @see #asyncEventListenersAreActive()
+ */
+ private final JavaElementChangeListener javaElementChangeListener = new JavaElementChangeListener();
+
+ /**
+ * The types of Java element change events that interest
+ * {@link #javaElementChangeListener}.
+ */
+ private static final int JAVA_CHANGE_EVENT_TYPES =
+ ElementChangedEvent.POST_CHANGE |
+ ElementChangedEvent.POST_RECONCILE;
+
+ /**
+ * A set of flags to activate/deactivate the asynchronous event listeners.
+ * <p>
+ * This set of flags hacks around our problems with bi-directional updates.
+ * We must worry about changes to the Java source code that are
+ * initiated by the Dali resource model because there is no way to either
+ * receive the corresponding Java events <em>synchronously</em> or suppress
+ * them. We need <em>not</em> worry about changes initiated by the Java
+ * source code since they are handled by the Java resource model in a way
+ * that does not return any changes back to the Java source code.
+ * <p>
+ * We can ignore Java events whenever Dali is manipulating the Java
+ * source code via the Dali model. We do this because the 0.5 sec delay
+ * between the Java source being changed in the Java Editor and the
+ * corresponding event being fired causes us no end of pain....
+ * <p>
+ * <strong>NB:</strong> The following may not be accurate in Eclipse 4.x....
+ * <p>
+ * Fortunately we <em>will</em> be active whenever a Java source file is
+ * saved, even when <Ctrl+S> is pressed from within a Dali composite. This
+ * is because, when the file is saved, the editor, presumably,
+ * takes the focus temporarily, activating this listener. Then, while this
+ * listener is active, we receive a Java change event for the compilation
+ * unit being saved. This allows us to re-cache our resource model text
+ * ranges so they are in sync with the Java source before execution of the
+ * validation job. Once the Java source file is saved, the Dali composite
+ * re-takes the focus and this listener is once again inactive.
+ */
+ private final HashSet<BooleanReference> asyncEventListenerFlags = new HashSet<BooleanReference>();
+
+ /**
+ * Support for modifying documents shared with the UI.
+ */
+ private final ThreadLocalExtendedCommandExecutor modifySharedDocumentCommandExecutor = new ThreadLocalExtendedCommandExecutor();
+
+ /**
+ * Log any exceptions appropriately.
+ */
+ private final ExceptionHandler exceptionHandler;
+
+ /**
+ * See org.eclipse.jpt.jpa.core.tests.JptJpaCoreTestsPlugin#start(org.osgi.framework.BundleContext).
+ */
+ /* CU private */ volatile boolean test = false;
+
+
+ // ********** constructor **********
+
+ /**
+ * Internal: Called <em>only</em> by the
+ * {@link JptJpaCorePlugin#getJpaProjectManager_(IWorkspace) Dali plug-in}.
+ */
+ public InternalJpaProjectManager() {
+ super();
+ this.exceptionHandler = this.buildExceptionHandler();
+ }
+
+ private ExceptionHandler buildExceptionHandler() {
+ return new LocalExceptionHandler();
+ }
+
+
+ // ********** plug-in controlled life-cycle **********
+
+ /**
+ * Internal: Called <em>only</em> by the
+ * {@link JptJpaCorePlugin#getJpaProjectManager_(IWorkspace) Dali plug-in}.
+ * The JPA project manager will not be returned to any clients by the
+ * {@link JptJpaCorePlugin Dali plug-in} until <em>after</em>
+ * the manager has been started (i.e. this method has been called).
+ * As a result, we need not synchronize with the scheduling rule.
+ */
+ public void start() {
+ debug("*** JPA project manager START ***"); //$NON-NLS-1$
+ try {
+ this.commandExecutor = this.buildAsynchronousCommandExecutor();
+ this.buildJpaProjects();
+ this.getWorkspace().addResourceChangeListener(this.resourceChangeListener, RESOURCE_CHANGE_EVENT_TYPES);
+ JavaCore.addElementChangedListener(this.javaElementChangeListener, JAVA_CHANGE_EVENT_TYPES);
+ } catch (RuntimeException ex) {
+ this.log(ex);
+ this.stop();
+ }
+ }
+
+ /**
+ * Internal: Called <em>only</em> by the
+ * {@link JptJpaCorePlugin#stop(org.osgi.framework.BundleContext) Dali plug-in}.
+ * The JPA project manager will <em>not</em> be restarted.
+ */
+ public void stop() {
+ debug("*** JPA project manager STOP ***"); //$NON-NLS-1$
+ JavaCore.removeElementChangedListener(this.javaElementChangeListener);
+ this.getWorkspace().removeResourceChangeListener(this.resourceChangeListener);
+ this.clearJpaProjects();
+ // if the current executor is async, commands can continue to execute
+ // after we replace it here, but there will be no JPA projects for them to process...
+ this.commandExecutor = ExtendedJobCommandExecutor.Inactive.instance();
+ debug("*** JPA project manager DEAD ***"); //$NON-NLS-1$
+ }
+
+
+ // ********** build JPA projects **********
+
+ /**
+ * The JPA projects are built asynchronously in a job.
+ * Side-effect: {@link #jpaProjects} populated.
+ */
+ private void buildJpaProjects() {
+ debug("dispatch: build JPA projects"); //$NON-NLS-1$
+ BuildJpaProjectsCommand command = new BuildJpaProjectsCommand();
+ this.execute(command, JptCoreMessages.BUILD_JPA_PROJECTS_JOB_NAME, this.getWorkspaceRoot());
+ }
+
+ /* CU private */ class BuildJpaProjectsCommand
+ implements JobCommand
+ {
+ public IStatus execute(IProgressMonitor monitor) {
+ InternalJpaProjectManager.this.buildJpaProjects_(monitor);
+ return Status.OK_STATUS;
+ }
+ }
+
+ /* CU private */ void buildJpaProjects_(IProgressMonitor monitor) {
+ debug("execute: build JPA projects"); //$NON-NLS-1$
+ try {
+ this.getWorkspaceRoot().accept(new ResourceProxyVisitor(monitor), IResource.NONE);
+ } catch (Exception ex) {
+ // if we have a problem, leave the currently built JPA projects in
+ // place and keep executing (should be OK...)
+ this.log(ex);
+ }
+ debug("end: build JPA projects"); //$NON-NLS-1$
+ }
+
+
+ // ********** clear JPA projects **********
+
+ /**
+ * <strong>NB:</strong>
+ * {@link IJobManager#beginRule(ISchedulingRule, IProgressMonitor)}
+ * will jump <em>ahead</em> of any job scheduled with a conflicting rule(!).
+ * We should only use this method of synchronization in {@link #stop()}.
+ */
+ private void clearJpaProjects() {
+ try {
+ this.getJobManager().beginRule(this.getWorkspaceRoot(), null);
+ this.clearJpaProjects_();
+ } finally {
+ this.getJobManager().endRule(this.getWorkspaceRoot());
+ }
+ }
+
+ private void clearJpaProjects_() {
+ debug("execute: clear JPA projects"); //$NON-NLS-1$
+ // clone the collection to prevent concurrent modification exception
+ for (JpaProject jpaProject : this.getJpaProjects()) {
+ this.removeJpaProject(jpaProject);
+ }
+ debug("end: clear JPA projects"); //$NON-NLS-1$
+ }
+
+
+ // ********** get JPA projects **********
+
+ public Iterable<JpaProject> waitToGetJpaProjects() throws InterruptedException {
+ debug("dispatch: get JPA projects"); //$NON-NLS-1$
+ GetJpaProjectsCommand command = new GetJpaProjectsCommand();
+ this.waitToExecute(command, JptCoreMessages.GET_JPA_PROJECTS_JOB_NAME, this.getWorkspaceRoot());
+ return command.result;
+ }
+
+ /* CU private */ class GetJpaProjectsCommand
+ implements Command
+ {
+ Iterable<JpaProject> result;
+ public void execute() {
+ this.result = InternalJpaProjectManager.this.getJpaProjects_();
+ }
+ }
+
+ /**
+ * Pre-condition: called from {@link GetJpaProjectsCommand#execute()}
+ */
+ /* CU private */ Iterable<JpaProject> getJpaProjects_() {
+ debug("execute: get JPA projects: ", this.jpaProjects); //$NON-NLS-1$
+ // clone the JPA projects immediately, while we have the lock
+ return this.getJpaProjects();
+ }
+
+ public Iterable<JpaProject> getJpaProjects() {
+ return new SnapshotCloneIterable<JpaProject>(this.jpaProjects);
+ }
+
+ public int getJpaProjectsSize() {
+ return this.jpaProjects.size();
+ }
+
+
+ // ********** get JPA project **********
+
+ /**
+ * @see ProjectAdapterFactory.JpaProjectReference#getValue()
+ */
+ JpaProject waitToGetJpaProject(IProject project) throws InterruptedException {
+ debug("dispatch: get JPA project: ", project.getName()); //$NON-NLS-1$
+ GetJpaProjectCommand command = new GetJpaProjectCommand(project);
+ this.waitToExecute(command, JptCoreMessages.GET_JPA_PROJECT_JOB_NAME, project);
+ return command.result;
+ }
+
+ /**
+ * Not needed...?
+ * It's nigh pointless to put a time-out on this call, since there are many
+ * things that can trigger a time-out (e.g. validation). Either the client
+ * wants to wait for the JPA project and uses a
+ * {@link org.eclipse.jpt.jpa.core.JpaProject.Reference}
+ * or the client can use the event notification mechanism to be notified
+ * when the JPA project shows up....
+ */
+ // @see ProjectAdapterFactory.JpaProjectReference#getValue(ModifiableObjectReference, long)
+ @SuppressWarnings("unused")
+ private boolean waitToGetJpaProject(ModifiableObjectReference<JpaProject> jpaProjectRef, IProject project, long timeout) throws InterruptedException {
+ debug("dispatch: get JPA project (time-out): ", project.getName()); //$NON-NLS-1$
+ GetJpaProjectCommand command = new GetJpaProjectCommand(project);
+ boolean result = this.waitToExecute(command, JptCoreMessages.GET_JPA_PROJECT_JOB_NAME, project, timeout);
+ if (result) {
+ jpaProjectRef.setValue(command.result);
+ } else {
+ debug("time-out: get JPA project: ", project.getName()); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /* CU private */ class GetJpaProjectCommand
+ implements Command
+ {
+ private final IProject project;
+ JpaProject result;
+ GetJpaProjectCommand(IProject project) {
+ this.project = project;
+ }
+ public void execute() {
+ this.result = InternalJpaProjectManager.this.getJpaProjectUnsafe(this.project);
+ }
+ }
+
+ /**
+ * Pre-condition: called from {@link GetJpaProjectCommand#execute()}
+ */
+ /* CU private */ JpaProject getJpaProjectUnsafe(IProject project) {
+ debug("execute: get JPA project: ", project.getName()); //$NON-NLS-1$
+ // no need to clone here, since we have the lock
+ JpaProject jpaProject = selectJpaProject(this.jpaProjects, project);
+ if (jpaProject == null) {
+ debug("not found: get JPA project: ", project.getName()); //$NON-NLS-1$
+ }
+ return jpaProject;
+ }
+
+ /**
+ * Called from {@link ProjectAdapterFactory#getJpaProject(IProject)}.
+ */
+ JpaProject getJpaProject_(IProject project) {
+ return selectJpaProject(this.getJpaProjects(), project);
+ }
+
+ private static JpaProject selectJpaProject(Iterable<JpaProject> jpaProjects, IProject project) {
+ for (JpaProject jpaProject : jpaProjects) {
+ if (jpaProject.getProject().equals(project)) {
+ return jpaProject;
+ }
+ }
+ return null;
+ }
+
+
+ // ********** rebuild JPA project **********
+
+ /**
+ * @see ProjectAdapterFactory.JpaProjectReference#rebuild()
+ */
+ // e.g. changed JPA platform
+ JpaProject rebuildJpaProject(IProject project) throws InterruptedException {
+ debug("dispatch: rebuild JPA project: ", project.getName()); //$NON-NLS-1$
+ RebuildJpaProjectCommand command = new RebuildJpaProjectCommand(project);
+ this.waitToExecute(command, JptCoreMessages.REBUILD_JPA_PROJECT_JOB_NAME, project);
+ return command.result;
+ }
+
+ /* CU private */ class RebuildJpaProjectCommand
+ implements JobCommand
+ {
+ private final IProject project;
+ JpaProject result;
+ RebuildJpaProjectCommand(IProject project) {
+ this.project = project;
+ }
+ public IStatus execute(IProgressMonitor monitor) {
+ this.result = InternalJpaProjectManager.this.rebuildJpaProject_(this.project, monitor);
+ return Status.OK_STATUS;
+ }
+ }
+
+ /* CU private */ JpaProject rebuildJpaProject_(IProject project, IProgressMonitor monitor) {
+ debug("execute: rebuild JPA project: ", project.getName()); //$NON-NLS-1$
+ this.removeJpaProject(this.getJpaProject_(project));
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ return this.addJpaProject(project);
+ }
+
+
+ // ********** build validation messages **********
+
+ /**
+ * @see ProjectAdapterFactory.JpaProjectReference#buildValidationMessages(IReporter)
+ */
+ Iterable<IMessage> buildValidationMessages(IProject project, IReporter reporter) throws InterruptedException {
+ debug("dispatch: build validation messages: ", project.getName()); //$NON-NLS-1$
+ BuildValidationMessagesCommand command = new BuildValidationMessagesCommand(project, reporter);
+ this.waitToExecute(command, JptCoreMessages.BUILD_VALIDATION_MESSAGES_JOB_NAME, project);
+ return command.result;
+ }
+
+ /* CU private */ class BuildValidationMessagesCommand
+ implements Command
+ {
+ private final IProject project;
+ private final IReporter reporter;
+ Iterable<IMessage> result;
+ BuildValidationMessagesCommand(IProject project, IReporter reporter) {
+ this.project = project;
+ this.reporter = reporter;
+ }
+ public void execute() {
+ this.result = InternalJpaProjectManager.this.buildValidationMessages_(this.project, this.reporter);
+ }
+ }
+
+ /* CU private */ Iterable<IMessage> buildValidationMessages_(IProject project, IReporter reporter) {
+ debug("execute: build validation messages: ", project.getName()); //$NON-NLS-1$
+ JpaProject jpaProject = this.getJpaProject_(project);
+ if (jpaProject == null) {
+ return this.buildNoJpaProjectMessages(project);
+ }
+ try {
+ return jpaProject.getValidationMessages(reporter);
+ } catch (RuntimeException ex) {
+ this.log(ex);
+ return EmptyIterable.<IMessage>instance();
+ }
+ }
+
+ private Iterable<IMessage> buildNoJpaProjectMessages(IProject project) {
+ return new SingleElementIterable<IMessage>(this.buildNoJpaProjectMessage(project));
+ }
+
+ private IMessage buildNoJpaProjectMessage(IProject project) {
+ return DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.NO_JPA_PROJECT,
+ project
+ );
+ }
+
+
+ // ********** add JPA project **********
+
+ /**
+ * Pre-condition: The specified project is locked.
+ * If there are any problems building the JPA project,
+ * log the exception and do not add anything to the manager.
+ * Return the newly-created JPA project.
+ */
+ /* CU private */ JpaProject addJpaProject(IProject project) {
+ JpaProject jpaProject = this.buildJpaProject(project);
+ // figure out exactly when JPA projects are added
+ if (jpaProject == null) {
+ dumpStackTrace("add JPA project fail: ", project); //$NON-NLS-1$
+ } else {
+ dumpStackTrace("add JPA project: ", jpaProject); //$NON-NLS-1$
+ }
+ // the JPA project will be null if we have any problems building it...
+ // (e.g. if we have problems getting the JPA platform)
+ if (jpaProject != null) {
+ this.addItemToCollection(jpaProject, this.jpaProjects, JPA_PROJECTS_COLLECTION);
+ }
+ return jpaProject;
+ }
+
+ /**
+ * Return <code>null</code> if we have any problems....
+ */
+ private JpaProject buildJpaProject(IProject project) {
+ return this.buildJpaProject(this.buildJpaProjectConfig(project));
+ }
+
+ /**
+ * Return <code>null</code> if we have any problems....
+ */
+ private JpaProject buildJpaProject(JpaProject.Config config) {
+ return this.buildJpaProject(config.getJpaPlatform(), config);
+ }
+
+ /**
+ * Return <code>null</code> if we have any problems....
+ */
+ private JpaProject buildJpaProject(JpaPlatform jpaPlatform, JpaProject.Config config) {
+ try {
+ return (jpaPlatform == null) ? null : jpaPlatform.getJpaFactory().buildJpaProject(config);
+ } catch (RuntimeException ex) {
+ this.log(ex);
+ return null;
+ }
+ }
+
+ private JpaProject.Config buildJpaProjectConfig(IProject project) {
+ SimpleJpaProjectConfig config = new SimpleJpaProjectConfig();
+ config.setJpaProjectManager(this);
+ config.setProject(project);
+ config.setJpaPlatform(JptJpaCorePlugin.getJpaPlatformManager().buildJpaPlatformImplementation(project));
+ config.setConnectionProfileName(JptJpaCorePlugin.getConnectionProfileName(project));
+ config.setUserOverrideDefaultCatalog(JptJpaCorePlugin.getUserOverrideDefaultCatalog(project));
+ config.setUserOverrideDefaultSchema(JptJpaCorePlugin.getUserOverrideDefaultSchema(project));
+ config.setDiscoverAnnotatedClasses(JptJpaCorePlugin.discoverAnnotatedClasses(project));
+ config.setMetamodelSourceFolderName(JptJpaCorePlugin.getMetamodelSourceFolderName(project));
+ return config;
+ }
+
+
+ // ********** remove JPA project **********
+
+ /**
+ * Pre-condition: The specified JPA project's project is locked.
+ */
+ private void removeJpaProject(JpaProject jpaProject) {
+ // figure out exactly when JPA projects are removed
+ dumpStackTrace("remove JPA project: ", jpaProject); //$NON-NLS-1$
+ this.removeItemFromCollection(jpaProject, this.jpaProjects, JPA_PROJECTS_COLLECTION);
+ try {
+ jpaProject.dispose();
+ } catch (RuntimeException ex) {
+ this.log(ex);
+ }
+ }
+
+
+ // ********** Project POST_CHANGE **********
+
+ /* CU private */ void projectChanged(IResourceDelta delta) {
+ debug("dispatch: project changed: ", delta.getResource()); //$NON-NLS-1$
+ ProjectChangeEventHandlerCommand command = new ProjectChangeEventHandlerCommand(delta);
+ this.execute(command, JptCoreMessages.PROJECT_CHANGE_EVENT_HANDLER_JOB_NAME, this.getWorkspaceRoot());
+ }
+
+ /* CU private */ class ProjectChangeEventHandlerCommand
+ implements JobCommand
+ {
+ private final IResourceDelta delta;
+ ProjectChangeEventHandlerCommand(IResourceDelta delta) {
+ this.delta = delta;
+ }
+ public IStatus execute(IProgressMonitor monitor) {
+ InternalJpaProjectManager.this.projectChanged_(this.delta, monitor);
+ return Status.OK_STATUS;
+ }
+ }
+
+ /**
+ * Forward the specified resource delta to <em>all</em> the JPA projects;
+ * they will each determine whether the event is significant.
+ */
+ /* CU private */ void projectChanged_(IResourceDelta delta, IProgressMonitor monitor) {
+ debug("execute: project changed: ", delta.getResource()); //$NON-NLS-1$
+// debug("execute: project changed: ", ((org.eclipse.core.internal.events.ResourceDelta) delta).toDeepDebugString()); //$NON-NLS-1$
+ for (JpaProject jpaProject : this.jpaProjects) {
+ try {
+ jpaProject.projectChanged(delta);
+ } catch (RuntimeException ex) {
+ this.log(ex);
+ }
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ }
+ }
+
+
+ // ********** Project POST_BUILD (CLEAN_BUILD) **********
+
+ /* CU private */ void projectPostCleanBuild(IProject project) {
+ debug("dispatch: post clean build: ", project.getName()); //$NON-NLS-1$
+ ProjectPostCleanBuildEventHandlerCommand command = new ProjectPostCleanBuildEventHandlerCommand(project);
+ this.execute(command, JptCoreMessages.PROJECT_POST_CLEAN_BUILD_EVENT_HANDLER_JOB_NAME, project);
+ }
+
+ /* CU private */ class ProjectPostCleanBuildEventHandlerCommand
+ implements JobCommand
+ {
+ private final IProject project;
+ ProjectPostCleanBuildEventHandlerCommand(IProject project) {
+ this.project = project;
+ }
+ public IStatus execute(IProgressMonitor monitor) {
+ InternalJpaProjectManager.this.projectPostCleanBuild_(this.project, monitor);
+ return Status.OK_STATUS;
+ }
+ }
+
+ /* CU private */ void projectPostCleanBuild_(IProject project, IProgressMonitor monitor) {
+ debug("execute: post clean build: ", project.getName()); //$NON-NLS-1$
+ JpaProject jpaProject = this.getJpaProject_(project);
+ if (jpaProject != null) {
+ this.removeJpaProject(jpaProject);
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ this.addJpaProject(project);
+ }
+ }
+
+
+ // ********** File POST_CHANGE **********
+
+ /**
+ * The Faceted Project settings file has changed in some fashion, check
+ * whether the JPA facet has been added to or removed from the specified
+ * project.
+ */
+ /* CU private */ void checkForJpaFacetTransition(IProject project) {
+ debug("dispatch: project facet file changed: ", project.getName()); //$NON-NLS-1$
+ FacetFileChangeEventHandlerCommand command = new FacetFileChangeEventHandlerCommand(project);
+ this.execute(command, JptCoreMessages.FACET_FILE_CHANGE_EVENT_HANDLER_JOB_NAME, project);
+ }
+
+ /* CU private */ class FacetFileChangeEventHandlerCommand
+ implements Command
+ {
+ private final IProject project;
+ FacetFileChangeEventHandlerCommand(IProject project) {
+ this.project = project;
+ }
+ public void execute() {
+ InternalJpaProjectManager.this.checkForJpaFacetTransition_(this.project);
+ }
+ }
+
+ /* CU private */ void checkForJpaFacetTransition_(IProject project) {
+ debug("execute: project facet file changed: ", project.getName()); //$NON-NLS-1$
+ JpaProject jpaProject = this.getJpaProject_(project);
+
+ if (JpaFacet.isInstalled(project)) {
+ if (jpaProject == null) { // JPA facet added
+ this.addJpaProject(project);
+ }
+ } else {
+ if (jpaProject != null) { // JPA facet removed
+ this.removeJpaProject(jpaProject);
+ }
+ }
+ }
+
+
+ // ********** Java element changed **********
+
+ /* CU private */ void javaElementChanged(ElementChangedEvent event) {
+ debug("dispatch: Java element changed: ", event.getDelta()); //$NON-NLS-1$
+ JavaChangeEventHandlerCommand command = new JavaChangeEventHandlerCommand(event);
+ this.execute(command, JptCoreMessages.JAVA_CHANGE_EVENT_HANDLER_JOB_NAME, this.getWorkspaceRoot());
+ }
+
+ /* CU private */ class JavaChangeEventHandlerCommand
+ implements JobCommand
+ {
+ private final ElementChangedEvent event;
+ JavaChangeEventHandlerCommand(ElementChangedEvent event) {
+ this.event = event;
+ }
+ public IStatus execute(IProgressMonitor monitor) {
+ InternalJpaProjectManager.this.javaElementChanged_(this.event, monitor);
+ return Status.OK_STATUS;
+ }
+ }
+
+ /**
+ * Forward the Java element changed event to <em>all</em> the JPA projects
+ * as the event could affect multiple projects.
+ */
+ /* CU private */ void javaElementChanged_(ElementChangedEvent event, IProgressMonitor monitor) {
+ debug("execute: Java element changed: ", event.getDelta()); //$NON-NLS-1$
+ for (JpaProject jpaProject : this.jpaProjects) {
+ try {
+ jpaProject.javaElementChanged(event);
+ } catch (RuntimeException ex) {
+ this.log(ex);
+ }
+ if (monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ }
+ }
+
+
+ // ********** support for modifying documents shared with the UI **********
+
+ public ExtendedCommandExecutor getModifySharedDocumentCommandExecutor() {
+ return this.modifySharedDocumentCommandExecutor;
+ }
+
+ private void setThreadLocalModifySharedDocumentCommandExecutor(ExtendedCommandExecutor commandExecutor) {
+ this.modifySharedDocumentCommandExecutor.set(commandExecutor);
+ }
+
+
+ // ********** logging **********
+
+ public void log(String msg) {
+ JptJpaCorePlugin.log(msg);
+ }
+
+ public void log(Throwable throwable) {
+ JptJpaCorePlugin.log(throwable);
+ }
+
+ public void log(String msg, Throwable throwable) {
+ JptJpaCorePlugin.log(msg, throwable);
+ }
+
+ public ExceptionHandler getExceptionHandler() {
+ return this.exceptionHandler;
+ }
+
+ /* CU private */ class LocalExceptionHandler
+ implements ExceptionHandler
+ {
+ public void handleException(Throwable t) {
+ InternalJpaProjectManager.this.log(t);
+ if (InternalJpaProjectManager.this.test) {
+ t.printStackTrace();
+ }
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** misc **********
+
+ private IWorkspaceRoot getWorkspaceRoot() {
+ return this.getWorkspace().getRoot();
+ }
+
+ private IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ private ISchedulingRule getCurrentRule() {
+ return this.getJobManager().currentRule();
+ }
+
+ private IJobManager getJobManager() {
+ return Job.getJobManager();
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.getJpaProjects());
+ }
+
+
+ // ********** command execution **********
+
+ /**
+ * Make sure the JPA project is still around when the command reaches the
+ * front of the command queue.
+ * <p>
+ * Called by JPA project <em>synchronizes</em> and <em>updates</em>:
+ * @see org.eclipse.jpt.jpa.core.internal.AbstractJpaProject.ManagerJobCommandExecutor#execute(JobCommand, String)
+ */
+ public void execute(JobCommand command, String jobName, JpaProject jpaProject) {
+ debug("dispatch: client command: ", command); //$NON-NLS-1$
+ this.execute(new ClientJobCommandWrapper(command, jpaProject), jobName, jpaProject.getProject());
+ }
+
+ private void execute(Command command, String jobName, ISchedulingRule schedulingRule) {
+ this.execute(new CommandJobCommandAdapter(command), jobName, schedulingRule);
+ }
+
+ private void execute(JobCommand command, String jobName, ISchedulingRule schedulingRule) {
+ this.commandExecutor.execute(command, jobName, schedulingRule);
+ }
+
+ private void waitToExecute(Command command, String jobName, ISchedulingRule schedulingRule) throws InterruptedException {
+ this.waitToExecute(new CommandJobCommandAdapter(command), jobName, schedulingRule);
+ }
+
+ private void waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule) throws InterruptedException {
+ this.waitToExecute(command, jobName, schedulingRule, 0);
+ }
+
+ private boolean waitToExecute(Command command, String jobName, ISchedulingRule schedulingRule, long timeout) throws InterruptedException {
+ return this.waitToExecute(new CommandJobCommandAdapter(command), jobName, schedulingRule, timeout);
+ }
+
+ /**
+ * Check whether the specified scheduling rule
+ * {@link ISchedulingRule#isConflicting(ISchedulingRule) conflicts} with the
+ * {@link IJobManager#currentRule() current rule}. If the rules conflict,
+ * execute the specified command directly (i.e. synchronously) to prevent a
+ * deadlock. This should not cause a problem because if the current rule
+ * conflicts with the specified rule, the current rule will also prevent any
+ * other, conflicting, JPA project manager commands from executing.
+ */
+ private boolean waitToExecute(JobCommand command, String jobName, ISchedulingRule schedulingRule, long timeout) throws InterruptedException {
+ ISchedulingRule currentRule = this.getCurrentRule();
+ if ((currentRule != null) && schedulingRule.isConflicting(currentRule)) {
+ dumpStackTrace("scheduling rule conflict: ", schedulingRule, currentRule); //$NON-NLS-1$
+ command.execute(new NullProgressMonitor());
+ return true;
+ }
+ return this.commandExecutor.waitToExecute(command, jobName, schedulingRule, timeout);
+ }
+
+ public void execute(Command command) throws InterruptedException {
+ this.execute(command, null);
+ }
+
+ public void execute(Command command, ExtendedCommandExecutor threadLocalModifySharedDocumentCommandExecutor) throws InterruptedException {
+ this.setThreadLocalModifySharedDocumentCommandExecutor(threadLocalModifySharedDocumentCommandExecutor);
+ this.executeCommandsSynchronously();
+ try {
+ command.execute();
+ } finally {
+ this.executeCommandsAsynchronously();
+ }
+ // not really necessary - thread locals are GCed
+ this.setThreadLocalModifySharedDocumentCommandExecutor(null);
+ }
+
+ /**
+ * <strong>NB:</strong>
+ * This method is called (via reflection) when the test plug-in is loaded.
+ * This is only useful during tests because none of the files are open in
+ * the UI, so all the Java events come to us synchronously (i.e. without the
+ * 0.5 second delay).
+ * <p>
+ * See org.eclipse.jpt.jpa.core.tests.JptJpaCoreTestsPlugin#start(org.osgi.framework.BundleContext).
+ *
+ * @see #executeCommandsAsynchronously()
+ */
+ private synchronized void executeCommandsSynchronously() throws InterruptedException {
+ if ( ! (this.commandExecutor instanceof SimpleJobCommandExecutor)) {
+ throw new IllegalStateException();
+ }
+
+ // de-activate async (Java) events
+ this.addAsyncEventListenerFlag(BooleanReference.False.instance());
+ // save the current executor
+ SimpleJobCommandExecutor old = (SimpleJobCommandExecutor) this.commandExecutor;
+ // install a new (not-yet-started) executor
+ SingleUseQueueingExtendedJobCommandExecutor newCE = this.buildSynchronousCommandExecutor();
+ this.commandExecutor = newCE;
+ // wait for all the outstanding commands to finish
+ old.waitToExecute(Command.Null.instance());
+ // start up the new executor (it will now execute any commands that
+ // arrived while we were waiting on the outstanding commands)
+ newCE.start();
+ }
+
+ private SingleUseQueueingExtendedJobCommandExecutor buildSynchronousCommandExecutor() {
+ return new SingleUseQueueingExtendedJobCommandExecutor();
+ }
+
+ private synchronized void executeCommandsAsynchronously() {
+ if ( ! (this.commandExecutor instanceof SingleUseQueueingExtendedJobCommandExecutor)) {
+ throw new IllegalStateException();
+ }
+
+ // no need to wait on a synchronous executor...
+ this.commandExecutor = this.buildAsynchronousCommandExecutor();
+ // re-activate async (Java) events
+ this.removeAsyncEventListenerFlag(BooleanReference.False.instance());
+ }
+
+ private SimpleJobCommandExecutor buildAsynchronousCommandExecutor() {
+ return new SimpleJobCommandExecutor(JptCommonCoreMessages.DALI_JOB_NAME);
+ }
+
+
+ // ********** job command wrapper **********
+
+ /* CU private */ class ClientJobCommandWrapper
+ implements JobCommand
+ {
+ private final JobCommand jobCommand;
+ private final JpaProject jpaProject;
+
+ ClientJobCommandWrapper(JobCommand jobCommand, JpaProject jpaProject) {
+ super();
+ if ((jobCommand == null) || (jpaProject == null)) {
+ throw new NullPointerException();
+ }
+ this.jobCommand = jobCommand;
+ this.jpaProject = jpaProject;
+ }
+
+ public IStatus execute(IProgressMonitor monitor) {
+ InternalJpaProjectManager.this.execute_(this.jobCommand, monitor, jpaProject);
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.jobCommand);
+ }
+ }
+
+ /**
+ * Execute the specified command only if the specified JPA project is still
+ * around. (i.e. The JPA project may have been removed between the time the
+ * client requested the JPA project manager to execute the command and the
+ * time the command reached the front of the execution queue.)
+ * Called by {@link ClientJobCommandWrapper#execute(IProgressMonitor)}.
+ */
+ /* CU private */ void execute_(JobCommand command, IProgressMonitor monitor, JpaProject jpaProject) {
+ if (this.jpaProjects.contains(jpaProject)) {
+ debug("execute: client command: ", command); //$NON-NLS-1$
+ command.execute(monitor);
+ } else {
+ debug("ignore: client command: ", command); //$NON-NLS-1$
+ }
+ }
+
+
+ // ********** resource proxy visitor **********
+
+ /**
+ * Visit the workspace resource tree, adding a JPA project to the
+ * JPA project manager for each open Eclipse project that has a JPA facet.
+ */
+ /* CU private */ class ResourceProxyVisitor
+ implements IResourceProxyVisitor
+ {
+ private final IProgressMonitor monitor;
+
+ ResourceProxyVisitor(IProgressMonitor monitor) {
+ super();
+ this.monitor = monitor;
+ }
+
+ public boolean visit(IResourceProxy resourceProxy) {
+ switch (resourceProxy.getType()) {
+ case IResource.ROOT :
+ return true; // all projects are in the "root"
+ case IResource.PROJECT :
+ this.processProject(resourceProxy);
+ return false; // no nested projects
+ case IResource.FOLDER :
+ return false; // ignore
+ case IResource.FILE :
+ return false; // ignore
+ default :
+ return false;
+ }
+ }
+
+ private void processProject(IResourceProxy resourceProxy) {
+ if (resourceProxy.isAccessible()) { // the project exists and is open
+ IProject project = (IProject) resourceProxy.requestResource();
+ if (JpaFacet.isInstalled(project)) {
+ InternalJpaProjectManager.this.addJpaProject(project);
+ }
+ }
+ if (this.monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** resource change listener **********
+
+ /* CU private */ class ResourceChangeListener
+ implements IResourceChangeListener
+ {
+ /**
+ * PRE_UNINSTALL is the only facet event we use for
+ * removing JPA projects. These are the cases where we listen for resource events.
+ * <p>
+ * Check for:<ul>
+ * <li>facet settings file added/removed/changed
+ * (<code>/.settings/org.eclipse.wst.common.project.facet.core.xml</code>)
+ * <li>file add/remove - forwarded to the individual JPA projects
+ * <li>project clean
+ * </ul>
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ switch (event.getType()) {
+ case IResourceChangeEvent.POST_CHANGE :
+ this.processPostChangeEvent(event);
+ break;
+
+ // workspace or project events
+ case IResourceChangeEvent.PRE_REFRESH :
+ break; // ignore
+ case IResourceChangeEvent.PRE_BUILD :
+ break; // ignore
+ case IResourceChangeEvent.POST_BUILD :
+ this.processPostBuildEvent(event);
+ break;
+
+ // project-only events
+ case IResourceChangeEvent.PRE_CLOSE :
+ break; // ignore
+ case IResourceChangeEvent.PRE_DELETE :
+ break; // ignore
+ default :
+ break;
+ }
+ }
+
+ private void processPostChangeEvent(IResourceChangeEvent event) {
+ debug("Resource POST_CHANGE event: ", event.getResource()); //$NON-NLS-1$
+ this.processPostChangeDelta(event.getDelta());
+ }
+
+ private void processPostChangeDelta(IResourceDelta delta) {
+ IResource resource = delta.getResource();
+ switch (resource.getType()) {
+ case IResource.ROOT :
+ this.processPostChangeRootDelta(delta);
+ break;
+ case IResource.PROJECT :
+ this.processPostChangeProjectDelta(delta);
+ break;
+ case IResource.FOLDER :
+ this.processPostChangeFolderDelta((IFolder) resource, delta);
+ break;
+ case IResource.FILE :
+ this.processPostChangeFileDelta((IFile) resource, delta);
+ break;
+ default :
+ break;
+ }
+ }
+
+ // ***** POST_CHANGE ROOT
+ private void processPostChangeRootDelta(IResourceDelta delta) {
+ this.processPostChangeDeltaChildren(delta);
+ }
+
+ // ***** POST_CHANGE PROJECT
+ /**
+ * Process the project <em>first</em> for the "opening" project case; so
+ * the JPA project will not be built until the children are processed
+ * and we see that the facet metadata file is added.
+ * Otherwise the JPA project would be built and <em>then</em> we would
+ * process the <code>ADDED</code> deltas for all the files in
+ * the project we would've discovered during JPA project construction
+ * (i.e. we would throw an exception because we would try to add a file
+ * to the JPA project that it already contained).
+ */
+ private void processPostChangeProjectDelta(IResourceDelta delta) {
+ InternalJpaProjectManager.this.projectChanged(delta);
+ this.processPostChangeDeltaChildren(delta);
+ }
+
+ // ***** POST_CHANGE FOLDER
+ private void processPostChangeFolderDelta(IFolder folder, IResourceDelta delta) {
+ if (folder.getName().equals(".settings")) { //$NON-NLS-1$
+ this.processPostChangeDeltaChildren(delta);
+ }
+ }
+
+ // ***** POST_CHANGE FILE
+ private void processPostChangeFileDelta(IFile file, IResourceDelta delta) {
+ if (file.getName().equals(FACETED_PROJECT_FRAMEWORK_SETTINGS_FILE_NAME)) {
+ this.checkForFacetFileChanges(file, delta);
+ }
+ }
+
+ private void checkForFacetFileChanges(IFile file, IResourceDelta delta) {
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED :
+ case IResourceDelta.REMOVED :
+ case IResourceDelta.CHANGED :
+ InternalJpaProjectManager.this.checkForJpaFacetTransition(file.getProject());
+ break;
+ case IResourceDelta.ADDED_PHANTOM :
+ break; // ignore
+ case IResourceDelta.REMOVED_PHANTOM :
+ break; // ignore
+ default :
+ break;
+ }
+ }
+
+ private void processPostChangeDeltaChildren(IResourceDelta delta) {
+ for (IResourceDelta child : delta.getAffectedChildren()) {
+ this.processPostChangeDelta(child); // recurse
+ }
+ }
+
+ /**
+ * A post build event has occurred.
+ * Check for whether the build was a "clean" build and completely
+ * rebuild the appropriate JPA project.
+ */
+ // ***** POST_BUILD
+ private void processPostBuildEvent(IResourceChangeEvent event) {
+ debug("Resource POST_BUILD event: ", event.getDelta().getResource()); //$NON-NLS-1$
+ if (event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) {
+ this.processPostCleanBuildDelta(event.getDelta());
+ }
+ }
+
+ private void processPostCleanBuildDelta(IResourceDelta delta) {
+ IResource resource = delta.getResource();
+ switch (resource.getType()) {
+ case IResource.ROOT :
+ this.processPostCleanBuildDeltaChildren(delta);
+ break;
+ case IResource.PROJECT :
+ this.processProjectPostCleanBuild((IProject) resource);
+ break;
+ case IResource.FOLDER :
+ break; // ignore
+ case IResource.FILE :
+ break; // ignore
+ default :
+ break;
+ }
+ }
+
+ private void processPostCleanBuildDeltaChildren(IResourceDelta delta) {
+ for (IResourceDelta child : delta.getAffectedChildren()) {
+ this.processPostCleanBuildDelta(child); // recurse
+ }
+ }
+
+ private void processProjectPostCleanBuild(IProject project) {
+ debug("\tProject CLEAN event: ", project.getName()); //$NON-NLS-1$
+ InternalJpaProjectManager.this.projectPostCleanBuild(project);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** Java element change listener **********
+
+ /**
+ * Forward the Java element change event back to the JPA project manager.
+ */
+ /* CU private */ class JavaElementChangeListener
+ implements IElementChangedListener
+ {
+ public void elementChanged(ElementChangedEvent event) {
+ if (this.isActive()) {
+ InternalJpaProjectManager.this.javaElementChanged(event);
+ }
+ }
+
+ private boolean isActive() {
+ return InternalJpaProjectManager.this.asyncEventListenersAreActive();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.isActive() ? "active" : "inactive"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+
+ // ********** async events **********
+
+ boolean asyncEventListenersAreActive() {
+ synchronized (this.asyncEventListenerFlags) {
+ return this.asyncEventListenersAreActive_();
+ }
+ }
+
+ /**
+ * All the flags must be <code>true</code>.
+ */
+ private boolean asyncEventListenersAreActive_() {
+ for (BooleanReference flag : this.asyncEventListenerFlags) {
+ if (flag.isFalse()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void addAsyncEventListenerFlag(BooleanReference flag) {
+ synchronized (this.asyncEventListenerFlags) {
+ this.addAsyncEventListenerFlag_(flag);
+ }
+ }
+
+ private void addAsyncEventListenerFlag_(BooleanReference flag) {
+ if ( ! this.asyncEventListenerFlags.add(flag)) {
+ throw new IllegalArgumentException("duplicate flag: " + flag); //$NON-NLS-1$
+ }
+ }
+
+ public void removeAsyncEventListenerFlag(BooleanReference flag) {
+ synchronized (this.asyncEventListenerFlags) {
+ this.removeAsyncEventListenerFlag_(flag);
+ }
+ }
+
+ private void removeAsyncEventListenerFlag_(BooleanReference flag) {
+ if ( ! this.asyncEventListenerFlags.remove(flag)) {
+ throw new IllegalArgumentException("missing flag: " + flag); //$NON-NLS-1$
+ }
+ }
+
+
+ // ********** DEBUG **********
+
+ // see JpaProjectManagerTests.testDEBUG()
+ private static final boolean DEBUG = false;
+
+ /* CU private */ static void debug(String message) {
+ debug(message, null);
+ }
+
+ /* CU private */ static void debug(String message, Object object) {
+ debug(message, object, null);
+ }
+
+ /* CU private */ static void debug(String message, Object object, Object additionalInfo) {
+ if (DEBUG) {
+ // lock System.out so the strings are printed out contiguously
+ synchronized (System.out) {
+ debug_(message, object, additionalInfo);
+ }
+ }
+ }
+
+ private static void debug_(String message, Object object, Object additionalInfo) {
+ System.out.print(buildTimestamp());
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.print(Thread.currentThread().getName());
+ System.out.print(": "); //$NON-NLS-1$
+ System.out.print(message);
+ if (object != null) {
+ System.out.print(object);
+ if (additionalInfo != null) {
+ System.out.print(" ("); //$NON-NLS-1$
+ System.out.print(additionalInfo);
+ System.out.print(")"); //$NON-NLS-1$
+ }
+ }
+ System.out.println();
+ }
+
+ private static synchronized String buildTimestamp() {
+ return DATE_FORMAT.format(new Date());
+ }
+ private static final String DATE_FORMAT_PATTERN = "yyyy.MM.dd HH:mm:ss.SSS"; //$NON-NLS-1$
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_PATTERN);
+
+ /* CU private */ static void dumpStackTrace() {
+ dumpStackTrace(null);
+ }
+
+ /* CU private */ static void dumpStackTrace(String message) {
+ dumpStackTrace(message, null);
+ }
+
+ /* CU private */ static void dumpStackTrace(String message, Object object) {
+ dumpStackTrace(message, object, null);
+ }
+
+ /* CU private */ static void dumpStackTrace(String message, Object object, Object additionalInfo) {
+ if (DEBUG) {
+ // lock System.out so the stack elements are printed out contiguously
+ synchronized (System.out) {
+ dumpStackTrace_(message, object, additionalInfo);
+ }
+ }
+ }
+
+ private static final boolean DEBUG_STACK_TRACE = false;
+ private static void dumpStackTrace_(String message, Object object, Object additionalInfo) {
+ if (message != null) {
+ debug_(message, object, additionalInfo);
+ }
+ if (DEBUG_STACK_TRACE) {
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ // skip the first 3 elements - those are this method and 2 methods in Thread
+ for (int i = 3; i < stackTrace.length; i++) {
+ StackTraceElement element = stackTrace[i];
+ if (element.getMethodName().equals("invoke0")) { //$NON-NLS-1$
+ break; // skip all elements outside of the JUnit test
+ }
+ System.out.print('\t');
+ System.out.println(element);
+ }
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaPackageInfoResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaPackageInfoResourceModelProvider.java
index 7221dd2af8..f4132f0dff 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaPackageInfoResourceModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaPackageInfoResourceModelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -19,7 +19,6 @@ import org.eclipse.jpt.common.core.internal.resource.java.source.SourcePackageIn
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaResourceModelProvider;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
/**
* Java package-info.java source code
@@ -51,21 +50,26 @@ public class JavaPackageInfoResourceModelProvider
public JavaResourceCompilationUnit buildResourceModel(JpaProject jpaProject, IFile file) {
ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
try {
- if (compilationUnit.getPackageDeclarations().length > 0){
- return new SourcePackageInfoCompilationUnit(
- compilationUnit,
- jpaProject.getJpaPlatform().getAnnotationProvider(),
- jpaProject.getJpaPlatform().getAnnotationEditFormatter(),
- jpaProject.getModifySharedDocumentCommandExecutor());
+ if (compilationUnit.getPackageDeclarations().length == 0){
+ //ignore package-info placed in default package as
+ //it doesn't have package declaration and can't hold annotations
+ return null;
}
- //ignore package-info placed in default package as
- //it doesn't have package declaration and can't hold annotations
- return null;
- } catch (JavaModelException e) {
- JptJpaCorePlugin.log(e);
+ } catch (JavaModelException ex) {
+ jpaProject.getManager().log(ex);
// Ignore -- project is in a bad state. This will get recalled if necessary
return null;
}
+ return new SourcePackageInfoCompilationUnit(
+ compilationUnit,
+ jpaProject.getJpaPlatform().getAnnotationProvider(),
+ jpaProject.getJpaPlatform().getAnnotationEditFormatter(),
+ jpaProject.getManager().getModifySharedDocumentCommandExecutor()
+ );
}
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaResourceModelProvider.java
index d248f7680e..d523f11c86 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaResourceModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JavaResourceModelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -50,8 +50,12 @@ public class JavaResourceModelProvider
JavaCore.createCompilationUnitFrom(file),
jpaProject.getJpaPlatform().getAnnotationProvider(),
jpaProject.getJpaPlatform().getAnnotationEditFormatter(),
- jpaProject.getModifySharedDocumentCommandExecutor()
+ jpaProject.getManager().getModifySharedDocumentCommandExecutor()
);
}
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaPlatformTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaPlatformTester.java
deleted file mode 100644
index 985056b392..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaPlatformTester.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.core.libprov.JpaLibraryProviderInstallOperationConfig;
-import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
-import org.eclipse.jpt.jpa.core.platform.JpaPlatformGroupDescription;
-
-public class JpaPlatformTester extends PropertyTester {
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if (! (property.equals("jpaPlatform") || property.equals("jpaPlatformGroup"))
- || ! (expectedValue instanceof String)) { //$NON-NLS-1$
- return false;
- }
-
- JpaPlatformDescription platform = null;
-
- if (receiver instanceof IResource) {
- platform = platform(((IResource) receiver).getProject());
- }
- else if (receiver instanceof IJavaElement) {
- platform = platform(((IJavaElement) receiver).getResource().getProject());
- }
- else if (receiver instanceof JpaPlatformDescription) {
- platform = (JpaPlatformDescription) receiver;
- }
- else if (receiver instanceof JpaLibraryProviderInstallOperationConfig) {
- platform = ((JpaLibraryProviderInstallOperationConfig) receiver).getJpaPlatform();
- }
-
- if (property.equals("jpaPlatform")) {
- JpaPlatformDescription otherPlatform = JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatform((String) expectedValue);
- return platform == null ? false : platform.equals(otherPlatform);
- }
- if (property.equals("jpaPlatformGroup")) {
- JpaPlatformGroupDescription group = (platform == null) ? null : platform.getGroup();
- JpaPlatformGroupDescription otherGroup = JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatformGroup((String) expectedValue);
- return group == null ? false : group.equals(otherGroup);
- }
- return false;
- }
-
- private JpaPlatformDescription platform(IProject project) {
- return (project == null)
- ? null
- : JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatform(JptJpaCorePlugin.getJpaPlatformId(project));
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaTester.java
deleted file mode 100644
index fd62b02ccf..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaTester.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2008 BEA Systems, Inc and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Konstantin Komissarchik - initial implementation and ongoing maintenance
- * Oracle - copied and modified from org.eclipse.wst.common.project.facet.core.internal.FacetedProjectPropertyTester
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-
-public class JpaTester extends PropertyTester {
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if (!property.equals("projectFacet")) { //$NON-NLS-1$
- return false;
- }
- if (receiver instanceof IJavaElement) {
- IProject project = ((IJavaElement) receiver).getResource().getProject();
- if (project != null) {
-
- String val = (String) expectedValue;
- int colon = val.indexOf( ':' );
- String facetID;
- String facetVer;
- if( colon == -1 || colon == val.length() - 1 ) {
- facetID = val;
- facetVer = null;
- } else {
- facetID = val.substring( 0, colon );
- facetVer = val.substring( colon + 1 );
- }
- try {
- return FacetedProjectFramework.hasProjectFacet( project, facetID, facetVer );
- } catch (CoreException e) {
- JptJpaCorePlugin.log(e.getStatus());
- return false;
- }
- }
- }
- return false;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java
index eb5ec8c8ca..01d193d69b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,9 +14,21 @@ import org.eclipse.osgi.util.NLS;
/**
* Localized messages used by Dali core.
*/
+// TODO bjv rename...
public class JptCoreMessages {
public static String NONE;
+
+ public static String BUILD_JPA_PROJECTS_JOB_NAME;
+ public static String GET_JPA_PROJECTS_JOB_NAME;
+ public static String GET_JPA_PROJECT_JOB_NAME;
+ public static String REBUILD_JPA_PROJECT_JOB_NAME;
+ public static String BUILD_VALIDATION_MESSAGES_JOB_NAME;
+ public static String PROJECT_CHANGE_EVENT_HANDLER_JOB_NAME;
+ public static String PROJECT_POST_CLEAN_BUILD_EVENT_HANDLER_JOB_NAME;
+ public static String FACET_FILE_CHANGE_EVENT_HANDLER_JOB_NAME;
+ public static String JAVA_CHANGE_EVENT_HANDLER_JOB_NAME;
+
public static String VALIDATE_JOB;
public static String VALIDATE_PROJECT_NOT_JPA;
public static String VALIDATE_PROJECT_IMPROPER_PLATFORM;
@@ -38,8 +50,6 @@ public class JptCoreMessages {
public static String VALIDATE_RUNTIME_NOT_SPECIFIED;
public static String VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30;
public static String VALIDATE_LIBRARY_NOT_SPECIFIED;
- public static String SYNCHRONIZE_CLASSES_JOB;
- public static String SYNCHRONIZING_CLASSES_TASK;
public static String INVALID_PERSISTENCE_XML_CONTENT;
public static String ERROR_SYNCHRONIZING_CLASSES_COULD_NOT_VALIDATE;
public static String ERROR_WRITING_FILE;
@@ -51,6 +61,7 @@ public class JptCoreMessages {
public static String REGISTRY_FAILED_INSTANTIATION;
public static String CONTEXT_MODEL_SYNC_JOB_NAME;
public static String UPDATE_JOB_NAME;
+ public static String METAMODEL_SYNC_JOB_NAME;
public static String PLATFORM_ID_DOES_NOT_EXIST;
public static String PREFERENCES_FLUSH_JOB_NAME;
public static String OSGI_BUNDLES_LIBRARY_VALIDATOR__BUNDLE_NOT_FOUND;
@@ -65,5 +76,4 @@ public class JptCoreMessages {
private JptCoreMessages() {
throw new UnsupportedOperationException();
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/ProjectAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/ProjectAdapterFactory.java
index 1e1d2cdba8..ebdb307bf9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/ProjectAdapterFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/ProjectAdapterFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,53 +10,111 @@
package org.eclipse.jpt.jpa.core.internal;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
/**
- * [Double-duty] factory to build adapters for either standard projects or
- * Java projects:
- * - JPA project
- *
- * See org.eclipse.jpt.jpa.core plugin.xml.
+ * Factory to build Dali adapters for an {@link IProject}:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.core.JpaProject.Reference JpaProject.Reference} -
+ * This adapter will always return a JPA project if it is available;
+ * even if it must wait for the JPA project to be created (note the
+ * {@link InterruptedException}).
+ * This adapter should be used by any process that cannot ignore any
+ * potential JPA projects (e.g. refactoring operations).
+ * <li>{@link org.eclipse.jpt.jpa.core.JpaProject JpaProject} -
+ * This adapter will only return a JPA project if it is immediately
+ * available.
+ * This adapter should be used by any process that can ignore
+ * any uncreated JPA projects because it is demand-driven and re-queries
+ * for the JPA project every time it executes and its results are only
+ * temporary (e.g. UI menus).
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>.
*/
public class ProjectAdapterFactory
implements IAdapterFactory
{
- private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaProject.class };
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaProject.Reference.class,
+ JpaProject.class,
+ };
public Class<?>[] getAdapterList() {
return ADAPTER_LIST;
}
-
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) {
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
if (adaptableObject instanceof IProject) {
return this.getAdapter((IProject) adaptableObject, adapterType);
}
- if (adaptableObject instanceof IJavaProject) {
- return this.getAdapter((IJavaProject) adaptableObject, adapterType);
- }
return null;
- }
+ }
- private Object getAdapter(IProject project, Class <?>adapterType) {
+ private Object getAdapter(IProject project, Class<?> adapterType) {
+ if (adapterType == JpaProject.Reference.class) {
+ return this.getJpaProjectReference(project);
+ }
if (adapterType == JpaProject.class) {
return this.getJpaProject(project);
}
return null;
}
- private Object getAdapter(IJavaProject javaProject, Class <?>adapterType) {
- if (adapterType == JpaProject.class) {
- return this.getJpaProject(javaProject.getProject());
+ private JpaProject.Reference getJpaProjectReference(IProject project) {
+ return new JpaProjectReference(this.getJpaProjectManager(project.getWorkspace()), project);
+ }
+
+ private JpaProject getJpaProject(IProject project) {
+ for (JpaProject jpaProject : this.getJpaProjectManager(project.getWorkspace()).getJpaProjects_()) {
+ if (jpaProject.getProject().equals(project)) {
+ return jpaProject;
+ }
}
return null;
}
- private JpaProject getJpaProject(IProject project) {
- return JptJpaCorePlugin.getJpaProject(project);
+ private InternalJpaProjectManager getJpaProjectManager(IWorkspace workspace) {
+ return (InternalJpaProjectManager) workspace.getAdapter(JpaProjectManager.class);
}
+
+ // ********** JPA project reference **********
+
+ /**
+ * @see InternalJpaProjectManager
+ */
+ /* CU private */ static class JpaProjectReference
+ implements JpaProject.Reference
+ {
+ private InternalJpaProjectManager jpaProjectManager;
+ private final IProject project;
+
+ JpaProjectReference(InternalJpaProjectManager jpaProjectManager, IProject project) {
+ super();
+ this.jpaProjectManager = jpaProjectManager;
+ this.project = project;
+ }
+
+ public JpaProject getValue() throws InterruptedException {
+ return this.jpaProjectManager.waitToGetJpaProject(this.project);
+ }
+
+ public JpaProject rebuild() throws InterruptedException {
+ return this.jpaProjectManager.rebuildJpaProject(this.project);
+ }
+
+ public Iterable<IMessage> buildValidationMessages(IReporter reporter) throws InterruptedException {
+ return this.jpaProjectManager.buildValidationMessages(this.project, reporter);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.project);
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/SimpleJpaProjectConfig.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/SimpleJpaProjectConfig.java
index 67535d5bb3..705e78bfce 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/SimpleJpaProjectConfig.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/SimpleJpaProjectConfig.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,12 +12,16 @@ package org.eclipse.jpt.jpa.core.internal;
import org.eclipse.core.resources.IProject;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaPlatform;
+import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.jpa2.JpaProject2_0;
/**
* Straightforward implementation of the JPA project config.
*/
-public class SimpleJpaProjectConfig implements JpaProject2_0.Config {
+public class SimpleJpaProjectConfig
+ implements JpaProject2_0.Config
+{
+ protected JpaProject.Manager jpaProjectManager;
protected IProject project;
protected JpaPlatform jpaPlatform;
protected String connectionProfileName;
@@ -26,10 +30,19 @@ public class SimpleJpaProjectConfig implements JpaProject2_0.Config {
protected boolean discoverAnnotatedClasses;
protected String metamodelSourceFolderName;
+
public SimpleJpaProjectConfig() {
super();
}
+ public JpaProject.Manager getJpaProjectManager() {
+ return this.jpaProjectManager;
+ }
+
+ public void setJpaProjectManager(JpaProject.Manager jpaProjectManager) {
+ this.jpaProjectManager = jpaProjectManager;
+ }
+
public IProject getProject() {
return this.project;
}
@@ -90,5 +103,4 @@ public class SimpleJpaProjectConfig implements JpaProject2_0.Config {
public String toString() {
return StringTools.buildToStringFor(this, this.project.getName());
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/WorkspaceAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/WorkspaceAdapterFactory.java
new file mode 100644
index 0000000000..e2f6e475b9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/WorkspaceAdapterFactory.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+
+/**
+ * Factory to build Dali adapters for an {@link IWorkspace}:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.core.JpaProjectManager}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>.
+ */
+public class WorkspaceAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaProjectManager.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IWorkspace) {
+ return this.getAdapter((IWorkspace) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IWorkspace workspace, Class<?> adapterType) {
+ if (adapterType == JpaProjectManager.class) {
+ return this.getJpaProjectManager(workspace);
+ }
+ return null;
+ }
+
+ private JpaProjectManager getJpaProjectManager(IWorkspace workspace) {
+ return JptJpaCorePlugin.getJpaProjectManager(workspace);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/PersistentAttributePropertyTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/PersistentAttributePropertyTester.java
index 7620a04d2e..ff5cfc699e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/PersistentAttributePropertyTester.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/PersistentAttributePropertyTester.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,36 +12,45 @@ package org.eclipse.jpt.jpa.core.internal.context;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+/**
+ * Property tester for {@link ReadOnlyPersistentAttribute}.
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>
+ */
public class PersistentAttributePropertyTester
extends PropertyTester
{
public static final String IS_MAPPED = "isMapped"; //$NON-NLS-1$
-
+ public static final String IS_NOT_MAPPED = "isNotMapped"; //$NON-NLS-1$
public static final String IS_VIRTUAL = "isVirtual"; //$NON-NLS-1$
+ public static final String IS_NOT_VIRTUAL = "isNotVirtual"; //$NON-NLS-1$
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if (property == null) {
- return false;
- }
- if ( ! (expectedValue instanceof Boolean)) {
- return false;
+ if (receiver instanceof ReadOnlyPersistentAttribute) {
+ return this.test((ReadOnlyPersistentAttribute) receiver, property, expectedValue);
}
- return this.test_(receiver, property, ((Boolean) expectedValue).booleanValue());
+ return false;
}
- /**
- * pre-condition: property is not <code>null</code>
- */
- protected boolean test_(Object receiver, String property, boolean expected) {
+ protected boolean test(ReadOnlyPersistentAttribute attribute, String property, Object expectedValue) {
+ if (property.equals(IS_NOT_MAPPED)) {
+ return ! this.test(attribute, IS_MAPPED, expectedValue);
+ }
if (property.equals(IS_MAPPED)) {
- boolean actual = ((ReadOnlyPersistentAttribute) receiver).getMapping().getKey() != null;
+ boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
+ boolean actual = (attribute.getMapping().getKey() != null);
return actual == expected;
}
+
+ if (property.equals(IS_NOT_VIRTUAL)) {
+ return ! this.test(attribute, IS_VIRTUAL, expectedValue);
+ }
if (property.equals(IS_VIRTUAL)) {
- boolean actual = ((ReadOnlyPersistentAttribute) receiver).isVirtual();
+ boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
+ boolean actual = attribute.isVirtual();
return actual == expected;
}
+
return false;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/XmlFilePropertyTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/XmlFilePropertyTester.java
new file mode 100644
index 0000000000..4b8da00999
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/XmlFilePropertyTester.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.context;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jpt.jpa.core.context.XmlFile;
+
+/**
+ * Property tester for {@link XmlFile}.
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>
+ */
+public class XmlFilePropertyTester
+ extends PropertyTester
+{
+ public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
+ public static final String IS_NOT_LATEST_SUPPORTED_VERSION = "isNotLatestSupportedVersion"; //$NON-NLS-1$
+
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof XmlFile) {
+ return this.test((XmlFile) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(XmlFile xmlFile, String property, Object expectedValue) {
+ if (property.equals(IS_NOT_LATEST_SUPPORTED_VERSION)) {
+ return ! this.test(xmlFile, IS_LATEST_SUPPORTED_VERSION, expectedValue);
+ }
+ if (property.equals(IS_LATEST_SUPPORTED_VERSION)) {
+ boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
+ boolean actual = xmlFile.isLatestSupportedVersion();
+ return actual == expected;
+ }
+ return false;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
index 163f844407..a0815940ad 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
@@ -35,7 +35,6 @@ import org.eclipse.jpt.jpa.core.context.java.DefaultJavaAttributeMappingDefiniti
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMappingDefinition;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.java.JavaStructureNodes;
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
import org.eclipse.jpt.jpa.core.internal.context.PersistentAttributeTextRangeResolver;
import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelField;
@@ -437,8 +436,12 @@ public abstract class AbstractJavaPersistentAttribute
// ********** JpaStructureNode implementation **********
- public String getId() {
- return JavaStructureNodes.PERSISTENT_ATTRIBUTE_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<JavaPersistentAttribute> getType() {
+ return JavaPersistentAttribute.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
@@ -591,9 +594,9 @@ public abstract class AbstractJavaPersistentAttribute
public boolean contains(int offset, CompilationUnit astRoot) {
TextRange fullTextRange = this.getResourceAttribute().getTextRange(astRoot);
// 'fullTextRange' will be null if the attribute no longer exists in the java;
- // the context model can be out of synch with the resource model
+ // the context model can be out of sync with the resource model
// when a selection event occurs before the context model has a
- // chance to synch with the resource model via the update thread
+ // chance to sync with the resource model via the update thread
return (fullTextRange == null) ? false : fullTextRange.includes(offset);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
index d490f58a73..8ce9799f5c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
@@ -49,7 +49,6 @@ import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
-import org.eclipse.jpt.jpa.core.context.java.JavaStructureNodes;
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.jpa2.resource.java.Access2_0Annotation;
@@ -892,8 +891,12 @@ public abstract class AbstractJavaPersistentType
// ********** JpaStructureNode implementation **********
- public String getId() {
- return JavaStructureNodes.PERSISTENT_TYPE_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<JavaPersistentType> getType() {
+ return JavaPersistentType.class;
}
// it would be nice if the we passed in an astRoot here, but then we
@@ -915,9 +918,9 @@ public abstract class AbstractJavaPersistentType
protected boolean contains(int offset, CompilationUnit astRoot) {
TextRange fullTextRange = this.resourceType.getTextRange(astRoot);
// 'fullTextRange' will be null if the type no longer exists in the java;
- // the context model can be out of synch with the resource model
+ // the context model can be out of sync with the resource model
// when a selection event occurs before the context model has a
- // chance to synch with the resource model via the update thread
+ // chance to sync with the resource model via the update thread
return (fullTextRange == null) ? false : fullTextRange.includes(offset);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
index a0be9813f0..8b0f97d3bf 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
@@ -44,7 +44,6 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer;
import org.eclipse.jpt.jpa.core.context.orm.OrmSequenceGenerator;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
import org.eclipse.jpt.jpa.core.context.orm.OrmTableGenerator;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMappingDefinition;
@@ -185,8 +184,12 @@ public abstract class AbstractEntityMappings
// ********** JpaStructureNode implementation **********
- public String getId() {
- return OrmStructureNodes.ENTITY_MAPPINGS_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<EntityMappings> getType() {
+ return EntityMappings.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java
index b2fc33f978..e942556bde 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentAttribute.java
@@ -31,7 +31,6 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMappingDefinition;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
import org.eclipse.jpt.jpa.core.internal.context.PersistentAttributeTextRangeResolver;
@@ -409,8 +408,12 @@ public abstract class SpecifiedOrmPersistentAttribute
// ********** JpaStructureNode implementation **********
- public String getId() {
- return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<OrmPersistentAttribute> getType() {
+ return OrmPersistentAttribute.class;
}
public JpaStructureNode getStructureNode(int offset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java
index 9af943c0d0..24b871786a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java
@@ -53,13 +53,11 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMappingDefinition;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools;
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaPersistentType;
import org.eclipse.jpt.jpa.core.internal.context.java.PropertyAccessor;
-import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.jpa.core.jpa2.context.MetamodelSourceType;
@@ -1141,8 +1139,12 @@ public abstract class SpecifiedOrmPersistentType
// ********** JpaStructureNode implementation **********
- public String getId() {
- return OrmStructureNodes.PERSISTENT_TYPE_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<OrmPersistentType> getType() {
+ return OrmPersistentType.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java
index a8adf954b3..fe5ac8ac60 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/VirtualOrmPersistentAttribute.java
@@ -25,7 +25,6 @@ import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.jpa.core.internal.context.java.FieldAccessor;
import org.eclipse.jpt.jpa.core.internal.context.java.PropertyAccessor;
@@ -299,8 +298,12 @@ public class VirtualOrmPersistentAttribute
// ********** JpaStructureNode implementation **********
- public String getId() {
- return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<OrmPersistentAttribute> getType() {
+ return OrmPersistentAttribute.class;
}
public JpaStructureNode getStructureNode(int offset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java
index d38f369ce3..cb65b89725 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractJarFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -27,7 +27,6 @@ import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.java.JarFile;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceStructureNodes;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
@@ -86,8 +85,12 @@ public abstract class AbstractJarFileRef
// ********** JpaStructureNode implementation **********
- public String getId() {
- return PersistenceStructureNodes.JAR_FILE_REF_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<JarFileRef> getType() {
+ return JarFileRef.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
index 540b657b53..213cf0dbdf 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -29,7 +29,6 @@ import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.Query;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceStructureNodes;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
@@ -198,8 +197,12 @@ public abstract class AbstractMappingFileRef
// ********** JpaStructureNode implementation **********
- public String getId() {
- return PersistenceStructureNodes.MAPPING_FILE_REF_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<MappingFileRef> getType() {
+ return MappingFileRef.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
index c2bac433f8..ea833c7036 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
@@ -23,6 +23,10 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -61,6 +65,7 @@ import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
import org.eclipse.jpt.jpa.core.context.java.JavaGenerator;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaQuery;
import org.eclipse.jpt.jpa.core.context.orm.OrmEntity;
import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator;
@@ -69,7 +74,6 @@ import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceStructureNodes;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitProperties;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitTransactionType;
@@ -271,8 +275,12 @@ public abstract class AbstractPersistenceUnit
// ********** JpaStructureNode implementation **********
- public String getId() {
- return PersistenceStructureNodes.PERSISTENCE_UNIT_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<PersistenceUnit> getType() {
+ return PersistenceUnit.class;
}
public TextRange getSelectionTextRange() {
@@ -759,6 +767,20 @@ public abstract class AbstractPersistenceUnit
return classRef;
}
+ protected Iterable<ClassRef> addSpecifiedClassRefs(Iterable<String> classNames) {
+ return this.addSpecifiedClassRefs(this.getSpecifiedClassRefsSize(), classNames);
+ }
+
+ protected Iterable<ClassRef> addSpecifiedClassRefs(int index, Iterable<String> classNames) {
+ ArrayList<XmlJavaClassRef> xmlClassRefs = new ArrayList<XmlJavaClassRef>();
+ for (String className : classNames) {
+ xmlClassRefs.add(this.buildXmlJavaClassRef(className));
+ }
+ Iterable<ClassRef> classRefs = this.specifiedClassRefContainer.addContextElements(index, xmlClassRefs);
+ this.xmlPersistenceUnit.getClasses().addAll(index, xmlClassRefs);
+ return classRefs;
+ }
+
protected XmlJavaClassRef buildXmlJavaClassRef(String className) {
XmlJavaClassRef ref = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
ref.setJavaClass(className);
@@ -785,6 +807,18 @@ public abstract class AbstractPersistenceUnit
this.specifiedClassRefContainer.removeContextElement(index).dispose();
}
+ protected void removeSpecifiedClassRefs(Iterable<ClassRef> classRefs) {
+ ArrayList<XmlJavaClassRef> xmlClassRefs = new ArrayList<XmlJavaClassRef>();
+ for (ClassRef classRef : classRefs) {
+ xmlClassRefs.add(classRef.getXmlClassRef());
+ }
+ this.specifiedClassRefContainer.removeAll(classRefs);
+ for (ClassRef classRef : classRefs) {
+ classRef.dispose();
+ }
+ this.xmlPersistenceUnit.getClasses().removeAll(xmlClassRefs);
+ }
+
protected void syncSpecifiedClassRefs() {
this.specifiedClassRefContainer.synchronizeWithResourceModel();
}
@@ -856,7 +890,7 @@ public abstract class AbstractPersistenceUnit
/**
* Return the names of all the Java classes in the JPA project that are
* mapped (i.e. have the appropriate annotation etc.) but not specified
- * in the persistence unit.
+ * in the persistence unit or any of its mapping files.
*/
protected Iterable<String> getImpliedClassNames_() {
return new FilteringIterable<String>(this.getJpaProject().getMappedJavaSourceClassNames()) {
@@ -1918,6 +1952,62 @@ public abstract class AbstractPersistenceUnit
}
+ // ********** synchronize classes **********
+
+ public void synchronizeClasses(IProgressMonitor monitor) {
+ SubMonitor sm = SubMonitor.convert(monitor, 3);
+
+ // calculate the refs to remove and add
+ HashSet<String> newTypeNames = CollectionTools.set(this.getJpaProject().getMappedJavaSourceClassNames());
+ ArrayList<ClassRef> deadClassRefs = new ArrayList<ClassRef>();
+ HashSet<String> mappingFileTypeNames = this.getMappingFileTypeNames();
+
+ for (ClassRef classRef : this.getSpecifiedClassRefs()) {
+ JavaPersistentType specifiedJPT = classRef.getJavaPersistentType();
+ if (specifiedJPT == null) {
+ // Java type cannot be resolved
+ deadClassRefs.add(classRef);
+ } else {
+ String specifiedName = specifiedJPT.getName();
+ if ( ! newTypeNames.remove(specifiedName)) {
+ // Java type is not annotated
+ deadClassRefs.add(classRef);
+ } else if (mappingFileTypeNames.contains(specifiedName)) {
+ // type is also listed in a mapping file
+ deadClassRefs.add(classRef);
+ }
+ }
+ }
+ if (sm.isCanceled()) {
+ return;
+ }
+ sm.worked(1);
+
+ this.removeSpecifiedClassRefs(deadClassRefs);
+ if (sm.isCanceled()) {
+ return;
+ }
+ sm.worked(1);
+
+ this.addSpecifiedClassRefs(newTypeNames);
+ sm.worked(1);
+ }
+
+ /**
+ * Return the names of all the types specified in the persistence unit's
+ * mapping files.
+ */
+ protected HashSet<String> getMappingFileTypeNames() {
+ HashSet<String> result = new HashSet<String>();
+ for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) {
+ for (PersistentType persistentType : mappingFileRef.getPersistentTypes()) {
+ result.add(persistentType.getName());
+ }
+ }
+ return result;
+ }
+
+
// ********** misc **********
public XmlPersistenceUnit getXmlPersistenceUnit() {
@@ -2539,7 +2629,8 @@ public abstract class AbstractPersistenceUnit
/**
* Not the prettiest code....
*/
- public void synchronizeMetamodel() {
+ // TODO check monitor for cancel
+ public IStatus synchronizeMetamodel(IProgressMonitor monitor) {
// gather up the persistent unit's types, eliminating duplicates;
// if we have persistent types with the same name in multiple locations,
// the last one we encounter wins (i.e. the classes in the orm.xml take
@@ -2643,6 +2734,7 @@ public abstract class AbstractPersistenceUnit
for (MetamodelSourceType topLevelType : topLevelTypes) {
topLevelType.synchronizeMetamodel(memberTypeTree);
}
+ return Status.OK_STATUS;
}
protected MetamodelSourceType selectSourceType(Iterable<MetamodelSourceType> types, String typeName) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetInstallDelegate.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetInstallDelegate.java
index 5c07250f1a..81073a58a1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetInstallDelegate.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetInstallDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,8 +20,7 @@ import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
-import org.eclipse.jpt.common.core.resource.ResourceLocator;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.internal.operations.OrmFileCreationDataModelProvider;
@@ -133,11 +132,11 @@ public class JpaFacetInstallDelegate
}
protected IPath defaultResourceLocation(IProject project) {
- ResourceLocator resourceLocator = JptCommonCorePlugin.getResourceLocator(project);
+ ProjectResourceLocator resourceLocator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
if (resourceLocator == null) {
- JptJpaCorePlugin.log("No resource locator for project");
+ JptJpaCorePlugin.log("No resource locator for project: " + project); //$NON-NLS-1$
return null;
}
- return resourceLocator.getDefaultResourceLocation(project).getFullPath();
+ return resourceLocator.getDefaultResourceLocation().getFullPath();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java
index ab06bfed9c..e7540f9fa3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDataModelProvider.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.facet;
import org.eclipse.core.resources.IProject;
@@ -16,13 +15,11 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
public class JpaFacetVersionChangeDataModelProvider
extends JpaFacetDataModelProvider
- implements JpaFacetDataModelProperties
{
protected static final IStatus PLATFORM_DOES_NOT_SUPPORT_FACET_VERSION_STATUS =
buildErrorStatus(JptCoreMessages.VALIDATE_PLATFORM_DOES_NOT_SUPPORT_FACET_VERSION);
@@ -41,8 +38,20 @@ public class JpaFacetVersionChangeDataModelProvider
}
protected JpaProject getJpaProject() {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
- return JptJpaCorePlugin.getJpaProject(project);
+ try {
+ return this.getJpaProjectReference().getValue();
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ return null;
+ }
+ }
+
+ protected JpaProject.Reference getJpaProjectReference() {
+ return (JpaProject.Reference) this.getProject().getAdapter(JpaProject.Reference.class);
+ }
+
+ protected IProject getProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(this.getProjectName());
}
@@ -60,7 +69,11 @@ public class JpaFacetVersionChangeDataModelProvider
@Override
protected Boolean getDefaultUserWantsToOverrideDefaultCatalog() {
- return getJpaProject().getUserOverrideDefaultCatalog() != null;
+ return Boolean.valueOf(this.getDefaultUserWantsToOverrideDefaultCatalog_());
+ }
+
+ protected boolean getDefaultUserWantsToOverrideDefaultCatalog_() {
+ return this.getJpaProject().getUserOverrideDefaultCatalog() != null;
}
@Override
@@ -70,7 +83,11 @@ public class JpaFacetVersionChangeDataModelProvider
@Override
protected Boolean getDefaultUserWantsToOverrideDefaultSchema() {
- return getJpaProject().getUserOverrideDefaultSchema() != null;
+ return Boolean.valueOf(this.getDefaultUserWantsToOverrideDefaultSchema_());
+ }
+
+ protected boolean getDefaultUserWantsToOverrideDefaultSchema_() {
+ return this.getJpaProject().getUserOverrideDefaultSchema() != null;
}
@Override
@@ -80,6 +97,10 @@ public class JpaFacetVersionChangeDataModelProvider
@Override
protected Boolean getDefaultDiscoverAnnotatedClasses() {
+ return Boolean.valueOf(this.getDefaultDiscoverAnnotatedClasses_());
+ }
+
+ protected boolean getDefaultDiscoverAnnotatedClasses_() {
return getJpaProject().discoversAnnotatedClasses();
}
@@ -91,7 +112,7 @@ public class JpaFacetVersionChangeDataModelProvider
// add existing platform to list of choices
Iterable<JpaPlatformDescription> validPlatformDescs = super.buildValidPlatformDescriptions();
if (! CollectionTools.contains(validPlatformDescs, getDefaultPlatform())) {
- validPlatformDescs = new CompositeIterable(getDefaultPlatform(), validPlatformDescs);
+ validPlatformDescs = new CompositeIterable<JpaPlatformDescription>(getDefaultPlatform(), validPlatformDescs);
}
return validPlatformDescs;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDelegate.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDelegate.java
index 9935431623..c4a3e907a3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDelegate.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetVersionChangeDelegate.java
@@ -1,19 +1,21 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.facet;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -27,9 +29,21 @@ public class JpaFacetVersionChangeDelegate
{
SubMonitor sm = SubMonitor.convert(monitor, 2);
super.execute_(project, fv, config, sm.newChild(1));
-
- JptJpaCorePlugin.rebuildJpaProject(project);
+ this.rebuildJpaProject(project);
sm.worked(1);
// nothing further to do here *just* yet
}
+
+ protected void rebuildJpaProject(IProject project) throws CoreException {
+ try {
+ this.rebuildJpaProject_(project);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ throw new CoreException(new Status(IStatus.CANCEL, JptJpaCorePlugin.PLUGIN_ID, null, ex));
+ }
+ }
+
+ protected void rebuildJpaProject_(IProject project) throws InterruptedException {
+ ((JpaProject.Reference) project.getAdapter(JpaProject.Reference.class)).rebuild();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/RuntimeChangedListener.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/RuntimeChangedListener.java
index 88d881e740..6a58138938 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/RuntimeChangedListener.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/RuntimeChangedListener.java
@@ -1,17 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.facet;
import java.util.HashMap;
import java.util.Map;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -27,8 +26,8 @@ import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
public class RuntimeChangedListener
- implements IFacetedProjectListener {
-
+ implements IFacetedProjectListener
+{
public void handleEvent(IFacetedProjectEvent facetedProjectEvent) {
IFacetedProjectBase fpb = facetedProjectEvent.getWorkingCopy();
@@ -51,13 +50,29 @@ public class RuntimeChangedListener
}
protected String getJpaPlatformId(IProject project) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ JpaProject jpaProject = this.getJpaProject(project);
return (jpaProject == null) ? null : jpaProject.getJpaPlatform().getId();
}
protected JpaPlatformDescription getJpaPlatformDescription(IProject project) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ JpaProject jpaProject = this.getJpaProject(project);
return (jpaProject == null) ? null : jpaProject.getJpaPlatform().getDescription();
}
-
+
+ protected JpaProject getJpaProject(IProject project) {
+ try {
+ return this.getJpaProject_(project);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ return null;
+ }
+ }
+
+ protected JpaProject getJpaProject_(IProject project) throws InterruptedException {
+ return this.getJpaProjectReference(project).getValue();
+ }
+
+ protected JpaProject.Reference getJpaProjectReference(IProject project) {
+ return ((JpaProject.Reference) project.getAdapter(JpaProject.Reference.class));
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaDataSource.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaDataSource.java
index b00190e46f..a35e675b89 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaDataSource.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/GenericJpaDataSource.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -93,7 +93,7 @@ public class GenericJpaDataSource
String old = this.connectionProfileName;
this.connectionProfileName = name;
if (this.firePropertyChanged(CONNECTION_PROFILE_NAME_PROPERTY, old, name)) {
- // synch the connection profile when the name changes
+ // sync the connection profile when the name changes
this.setConnectionProfile(this.buildConnectionProfile(name));
JptJpaCorePlugin.setConnectionProfileName(this.getJpaProject().getProject(), name);
}
@@ -201,7 +201,7 @@ public class GenericJpaDataSource
return;
}
// the connection profile will already have the new name,
- // we just need to synch the name held by the data source
+ // we just need to sync the name held by the data source
if (newName.equals(GenericJpaDataSource.this.connectionProfile.getName())) {
GenericJpaDataSource.this.setConnectionProfileName(newName);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericRootContextNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericRootContextNode.java
index c46c469e3d..bb748cdfbd 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericRootContextNode.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericRootContextNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,9 @@ import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
@@ -197,6 +200,11 @@ public class GenericRootContextNode
return null;
}
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.jpaProject.getName());
+ }
+
// ********** metamodel **********
@@ -206,10 +214,10 @@ public class GenericRootContextNode
}
}
- public void synchronizeMetamodel() {
- if (this.persistenceXml != null) {
- ((PersistenceXml2_0) this.persistenceXml).synchronizeMetamodel();
- }
+ public IStatus synchronizeMetamodel(IProgressMonitor monitor) {
+ return (this.persistenceXml != null) ?
+ ((PersistenceXml2_0) this.persistenceXml).synchronizeMetamodel(monitor) :
+ Status.OK_STATUS;
}
public void disposeMetamodel() {
@@ -316,5 +324,4 @@ public class GenericRootContextNode
}
}
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java
index fc11378989..1b9a7609a5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJarFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,9 +15,9 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragmentRoot;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper;
@@ -73,8 +73,12 @@ public class GenericJarFile
// ********** JpaStructureNode implementation **********
- public String getId() {
- return null;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<JarFile> getType() {
+ return JarFile.class;
}
public TextRange getSelectionTextRange() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
index e96acc56a2..92a2f1d3ec 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -203,6 +203,10 @@ public class GenericOrmXml
return this.getJpaFile(this.xmlResource.getFile());
}
+ public boolean isLatestSupportedVersion() {
+ return XmlFile_.isLatestSupportedVersion(this);
+ }
+
public boolean isIn(IFolder folder) {
IResource member = folder.findMember(this.xmlResource.getFile().getName());
IFile file = this.xmlResource.getFile();
@@ -212,9 +216,12 @@ public class GenericOrmXml
// ********** JpaStructureNode implementation **********
- public String getId() {
- // isn't actually displayed, so needs no details page
- return null;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<OrmXml> getType() {
+ return OrmXml.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java
index ddf31c9991..5ad77e09a5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericClassRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -25,7 +25,6 @@ import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceStructureNodes;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceXmlContextNode;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
@@ -229,8 +228,12 @@ public class GenericClassRef
// ********** JpaStructureNode implementation **********
- public String getId() {
- return PersistenceStructureNodes.CLASS_REF_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<ClassRef> getType() {
+ return ClassRef.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericMappingFileRef.java
index 43a0a78e9f..5d5b555a53 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericMappingFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
@@ -144,7 +144,8 @@ public class GenericMappingFileRef
protected ReplaceEdit createMoveEdit(IFolder originalFolder, IPath runtimeDestination) {
IProject project = originalFolder.getProject();
IPath fullPath = originalFolder.getFullPath();
- IPath originalLocation = JptCommonCorePlugin.getResourceLocator(project).getRuntimePath(project, fullPath);
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ IPath originalLocation = locator.getRuntimePath(fullPath);
return this.createMoveEdit(originalLocation, runtimeDestination);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java
index a81707e11a..636afafeca 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistence.java
@@ -10,13 +10,16 @@
package org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence;
import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementListIterable;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceStructureNodes;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceXmlContextNode;
@@ -82,18 +85,30 @@ public class GenericPersistence
return (this.persistenceUnit == null) ? 0 : 1;
}
+ public PersistenceUnit getPersistenceUnit(int index) {
+ if ((index != 0) || (this.persistenceUnit == null)) {
+ throw this.buildIOOBE(index);
+ }
+ return this.persistenceUnit;
+ }
+
+ protected IndexOutOfBoundsException buildIOOBE(int index) {
+ return new IndexOutOfBoundsException("index: " + index); //$NON-NLS-1$
+ }
+
public PersistenceUnit addPersistenceUnit() {
return this.addPersistenceUnit(this.getPersistenceUnitsSize());
}
public PersistenceUnit addPersistenceUnit(int index) {
- if ((index > 0) || (this.persistenceUnit != null)) {
- throw new IllegalStateException("This implementation does not support multiple persistence units."); //$NON-NLS-1$
+ if ((index != 0) || (this.persistenceUnit != null)) {
+ throw this.buildIOOBE(index);
}
XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit();
this.persistenceUnit = this.buildPersistenceUnit(xmlPersistenceUnit);
this.xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit);
this.fireItemAdded(PERSISTENCE_UNITS_LIST, index, this.persistenceUnit);
+ this.persistenceUnit.setName(this.getJpaProject().getName()); // default to the project name
return this.persistenceUnit;
}
@@ -105,8 +120,8 @@ public class GenericPersistence
}
public void removePersistenceUnit(int index) {
- if ((index > 0) || (this.persistenceUnit == null)) {
- throw new IndexOutOfBoundsException("index: " + index); //$NON-NLS-1$
+ if ((index != 0) || (this.persistenceUnit == null)) {
+ throw this.buildIOOBE(index);
}
PersistenceUnit old = this.persistenceUnit;
this.persistenceUnit.dispose();
@@ -164,7 +179,6 @@ public class GenericPersistence
return this.getContextNodeFactory().buildPersistenceUnit(this, xmlPersistenceUnit);
}
-
// ********** metamodel **********
public void initializeMetamodel() {
@@ -173,10 +187,14 @@ public class GenericPersistence
}
}
- public void synchronizeMetamodel() {
+ public IStatus synchronizeMetamodel(IProgressMonitor monitor) {
for (PersistenceUnit pu : this.getPersistenceUnits()) {
- ((PersistenceUnit2_0) pu).synchronizeMetamodel();
+ IStatus status = ((PersistenceUnit2_0) pu).synchronizeMetamodel(monitor);
+ if (status.getSeverity() == IStatus.CANCEL) {
+ return status; // seems reasonable...
+ }
}
+ return Status.OK_STATUS;
}
public void disposeMetamodel() {
@@ -204,7 +222,7 @@ public class GenericPersistence
return (PersistenceXml) super.getParent();
}
- protected PersistenceXml getPersistenceXml() {
+ public PersistenceXml getPersistenceXml() {
return this.getParent();
}
@@ -216,8 +234,12 @@ public class GenericPersistence
// ********** JpaStructureNode implementation **********
- public String getId() {
- return PersistenceStructureNodes.PERSISTENCE_ID;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<Persistence> getType() {
+ return Persistence.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
@@ -297,5 +319,4 @@ public class GenericPersistence
}
this.persistenceUnit.validate(messages, reporter);
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
index d3ca90ee9b..37bcb619c5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,10 @@
package org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence;
import java.util.List;
-
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.jpa.core.JpaFile;
@@ -19,6 +21,7 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceXmlContextNode;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
@@ -163,6 +166,10 @@ public class GenericPersistenceXml
return this.getJpaFile(this.xmlResource.getFile());
}
+ public boolean isLatestSupportedVersion() {
+ return XmlFile_.isLatestSupportedVersion(this);
+ }
+
// ********** metamodel **********
@@ -172,10 +179,10 @@ public class GenericPersistenceXml
}
}
- public void synchronizeMetamodel() {
- if (this.persistence != null) {
- ((Persistence2_0) this.persistence).synchronizeMetamodel();
- }
+ public IStatus synchronizeMetamodel(IProgressMonitor monitor) {
+ return (this.persistence != null) ?
+ ((Persistence2_0) this.persistence).synchronizeMetamodel(monitor) :
+ Status.OK_STATUS;
}
public void disposeMetamodel() {
@@ -187,9 +194,12 @@ public class GenericPersistenceXml
// ********** JpaStructureNode implementation **********
- public String getId() {
- // isn't actually displayed, so needs no details page
- return null;
+ public ContextType getContextType() {
+ return new ContextType(this);
+ }
+
+ public Class<PersistenceXml> getType() {
+ return PersistenceXml.class;
}
public JpaStructureNode getStructureNode(int textOffset) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/libprov/JpaLibraryProviderInstallOperationConfigAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/libprov/JpaLibraryProviderInstallOperationConfigAdapterFactory.java
new file mode 100644
index 0000000000..8d8a1b22da
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/libprov/JpaLibraryProviderInstallOperationConfigAdapterFactory.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.libprov;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.core.libprov.JpaLibraryProviderInstallOperationConfig;
+import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
+
+/**
+ * Factory to build Dali adapters for an {@link JpaLibraryProviderInstallOperationConfig}:<ul>
+ * <li>{@link JpaPlatformDescription}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>.
+ */
+public class JpaLibraryProviderInstallOperationConfigAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaPlatformDescription.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof JpaLibraryProviderInstallOperationConfig) {
+ return this.getAdapter((JpaLibraryProviderInstallOperationConfig) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(JpaLibraryProviderInstallOperationConfig config, Class<?> adapterType) {
+ if (adapterType == JpaPlatformDescription.class) {
+ return config.getJpaPlatform();
+ }
+ return null;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
index 1ab0a16337..843f652d24 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,9 +15,8 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.operations.AbstractJptFileCreationDataModelProvider;
-import org.eclipse.jpt.common.core.resource.ResourceLocator;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
@@ -91,9 +90,8 @@ public abstract class AbstractJpaFileCreationDataModelProvider
IStatus.ERROR, JptJpaCorePlugin.PLUGIN_ID,
JptCoreMessages.VALIDATE_PROJECT_IMPROPER_PLATFORM);
}
- ResourceLocator resourceLocator = JptCommonCorePlugin.getResourceLocator(project);
- if (resourceLocator != null /* should never be null, but there might be crazy circumstances */
- && ! resourceLocator.acceptResourceLocation(project, container)) {
+ ProjectResourceLocator resourceLocator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ if ( ! resourceLocator.resourceLocationIsValid(container)) {
return new Status(
IStatus.WARNING, JptJpaCorePlugin.PLUGIN_ID,
JptCoreMessages.VALIDATE_CONTAINER_QUESTIONABLE);
@@ -138,7 +136,20 @@ public abstract class AbstractJpaFileCreationDataModelProvider
}
protected JpaProject getJpaProject(IProject project) {
- return (project == null) ? null : JptJpaCorePlugin.getJpaProject(project);
+ return (project == null) ? null : this.getJpaProject_(project);
+ }
+
+ protected JpaProject getJpaProject_(IProject project) {
+ try {
+ return this.getJpaProjectReference(project).getValue();
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ return null;
+ }
+ }
+
+ protected JpaProject.Reference getJpaProjectReference(IProject project) {
+ return ((JpaProject.Reference) project.getAdapter(JpaProject.Reference.class));
}
protected String getJpaFacetVersion(IProject project) throws CoreException {
@@ -147,7 +158,7 @@ public abstract class AbstractJpaFileCreationDataModelProvider
}
protected boolean hasSupportedPlatform(IProject project) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ JpaProject jpaProject = this.getJpaProject(project);
return (jpaProject != null) && isSupportedPlatformId(jpaProject.getJpaPlatform().getId());
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationOperation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationOperation.java
index e27c9479b5..f2a551d710 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationOperation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/AbstractJpaFileCreationOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,8 @@
package org.eclipse.jpt.jpa.core.internal.operations;
-import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.*;
+import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.CONTAINER_PATH;
+import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.FILE_NAME;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -26,7 +27,6 @@ import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.resource.AbstractXmlResourceProvider;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
@@ -75,13 +75,30 @@ public abstract class AbstractJpaFileCreationOperation
protected JpaProject getJpaProject() throws ExecutionException {
IProject project = getProject();
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ JpaProject jpaProject = this.getJpaProject(project);
if (jpaProject == null) {
throw new ExecutionException("Project does not have JPA facet"); //$NON-NLS-1$
}
return jpaProject;
}
+ protected JpaProject getJpaProject(IProject project) throws ExecutionException {
+ try {
+ return this.getJpaProject_(project);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ throw new ExecutionException(null, ex);
+ }
+ }
+
+ protected JpaProject getJpaProject_(IProject project) throws InterruptedException {
+ return this.getJpaProjectReference(project).getValue();
+ }
+
+ protected JpaProject.Reference getJpaProjectReference(IProject project) {
+ return (JpaProject.Reference) project.getAdapter(JpaProject.Reference.class);
+ }
+
/**
* This method will create the container as specified in the data model if it does not exist.
*/
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/OrmFileCreationOperation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/OrmFileCreationOperation.java
index 61eaf568fd..3244c83a38 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/OrmFileCreationOperation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/operations/OrmFileCreationOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,17 +18,15 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
import org.eclipse.jpt.jpa.core.internal.resource.orm.OrmXmlResourceProvider;
import org.eclipse.jpt.jpa.core.resource.AbstractXmlResourceProvider;
-import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
public class OrmFileCreationOperation
@@ -73,32 +71,34 @@ public class OrmFileCreationOperation
}
protected void addMappingFileToPersistenceXml() throws ExecutionException {
- if (! getDataModel().getBooleanProperty(ADD_TO_PERSISTENCE_UNIT)) {
- return;
+ if (this.getDataModel().getBooleanProperty(ADD_TO_PERSISTENCE_UNIT)) {
+ this.addMappingFileToPersistenceXml_();
}
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.file.getProject());
- JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
-
- final PersistenceUnit pUnit = getPersistenceUnit();
+ }
+
+ protected void addMappingFileToPersistenceXml_() throws ExecutionException {
+ PersistenceUnit pUnit = getPersistenceUnit();
- resource.modify(new Runnable() {
- public void run() {
- IPath containerPath = (IPath) getDataModel().getProperty(CONTAINER_PATH);
- String fileName = getDataModel().getStringProperty(FILE_NAME);
- IContainer container = PlatformTools.getContainer(containerPath);
- IPath filePath = container.getFullPath().append(fileName);
- IProject project = container.getProject();
- IPath runtimePath = JptCommonCorePlugin.getResourceLocator(project).getRuntimePath(project, filePath);
- for (MappingFileRef ref : pUnit.getSpecifiedMappingFileRefs()) {
- if (runtimePath.equals(ref.getFileName())) {
- return;
- }
- }
- pUnit.addSpecifiedMappingFileRef(runtimePath.toString());
+ IPath containerPath = (IPath) getDataModel().getProperty(CONTAINER_PATH);
+ String fileName = getDataModel().getStringProperty(FILE_NAME);
+ IContainer container = PlatformTools.getContainer(containerPath);
+ IPath filePath = container.getFullPath().append(fileName);
+ IProject project = container.getProject();
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ IPath runtimePath = locator.getRuntimePath(filePath);
+ boolean found = false;
+ for (MappingFileRef ref : pUnit.getSpecifiedMappingFileRefs()) {
+ if (runtimePath.equals(ref.getFileName())) {
+ found = true;
+ break;
}
- });
+ }
+ if ( ! found) {
+ pUnit.addSpecifiedMappingFileRef(runtimePath.toString());
+ }
+ this.getJpaProject().getPersistenceXmlResource().save();
}
-
+
@Override
protected AbstractXmlResourceProvider getXmlResourceProvider(IFile file) {
return OrmXmlResourceProvider.getXmlResourceProvider(file);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JavaElementAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JavaElementAdapterFactory.java
new file mode 100644
index 0000000000..4e695c9a13
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JavaElementAdapterFactory.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.platform;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
+
+/**
+ * Factory to build Dali adapters for an {@link IJavaElement}:<ul>
+ * <li>{@link JpaPlatformDescription}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>.
+ */
+public class JavaElementAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaPlatformDescription.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IJavaElement) {
+ return this.getAdapter((IJavaElement) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IJavaElement javaElement, Class<?> adapterType) {
+ if (adapterType == JpaPlatformDescription.class) {
+ return javaElement.getResource().getAdapter(JpaPlatformDescription.class);
+ }
+ return null;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformDescriptionImpl.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformDescriptionImpl.java
index 9b4f62447b..c8198fa4f8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformDescriptionImpl.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformDescriptionImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -96,7 +96,7 @@ public class JpaPlatformDescriptionImpl
}
public JpaPlatform buildJpaPlatform() {
- JpaPlatformFactory factory = (JpaPlatformFactory) XPointTools.instantiate(
+ JpaPlatformFactory factory = XPointTools.instantiate(
this.pluginId, JpaPlatformManagerImpl.QUALIFIED_EXTENSION_POINT_ID,
this.factoryClassName, JpaPlatformFactory.class);
return factory.buildJpaPlatform(getId());
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformTester.java
new file mode 100644
index 0000000000..b1812101e4
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/JpaPlatformTester.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Oracle. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.platform;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
+import org.eclipse.jpt.jpa.core.platform.JpaPlatformGroupDescription;
+
+/**
+ * Property tester for {@link JpaPlatformDescription}.
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>
+ */
+public class JpaPlatformTester
+ extends PropertyTester
+{
+ public static final String JPA_PLATFORM = "jpaPlatform"; //$NON-NLS-1$
+ public static final String JPA_PLATFORM_GROUP = "jpaPlatformGroup"; //$NON-NLS-1$
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof JpaPlatformDescription) {
+ return this.test((JpaPlatformDescription) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(JpaPlatformDescription platform, String property, Object expectedValue) {
+ if (property.equals(JPA_PLATFORM)) {
+ JpaPlatformDescription expected = this.getJpaPlatform(expectedValue);
+ return Tools.valuesAreEqual(platform, expected);
+ }
+ if (property.equals(JPA_PLATFORM_GROUP)) {
+ JpaPlatformGroupDescription expected = this.getJpaPlatformGroup(expectedValue);
+ return Tools.valuesAreEqual(platform.getGroup(), expected);
+ }
+ return false;
+ }
+
+ private JpaPlatformDescription getJpaPlatform(Object id) {
+ return JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatform((String) id);
+ }
+
+ private JpaPlatformGroupDescription getJpaPlatformGroup(Object id) {
+ return JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatformGroup((String) id);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/ResourceAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/ResourceAdapterFactory.java
new file mode 100644
index 0000000000..5c5dda6863
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/platform/ResourceAdapterFactory.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.platform;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
+
+/**
+ * Factory to build Dali adapters for an {@link IResource}:<ul>
+ * <li>{@link JpaPlatformDescription}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code>.
+ */
+public class ResourceAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaPlatformDescription.class
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IResource) {
+ return this.getAdapter((IResource) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IResource resource, Class<?> adapterType) {
+ if (adapterType == JpaPlatformDescription.class) {
+ return this.getJpaPlatformDescription(resource);
+ }
+ return null;
+ }
+
+ private JpaPlatformDescription getJpaPlatformDescription(IResource resource) {
+ // TODO go directly to the JpaPlatformManager
+ return JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatform(JptJpaCorePlugin.getJpaPlatformId(resource.getProject()));
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java
index 9d948a34c3..11771b2e9d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,6 +14,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -110,16 +111,17 @@ public abstract class AbstractJpaDeleteTypeParticipant
//since the progress bar will hang if a large JPA project is being loaded,
//we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 2);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 2);
sm.subTask(this.getCheckConditionsSubTaskName());
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : jpaProjectManager.getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createDeleteEdits(sm.newChild(10), jpaProject);
}
if (sm.isCanceled()) {
@@ -137,6 +139,18 @@ public abstract class AbstractJpaDeleteTypeParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
/**
* This will be appended to the main refactoring task named : 'Checking preconditions...'
*/
@@ -181,9 +195,9 @@ public abstract class AbstractJpaDeleteTypeParticipant
return;
}
SubMonitor sm = SubMonitor.convert(monitor, 1 + persistenceUnit.getMappingFileRefsSize());
- Iterable<DeleteEdit> persistenceXmlDeleteEdits = this.createPersistenceXmlDeleteEdits(persistenceUnit);
- if (!CollectionTools.isEmpty(persistenceXmlDeleteEdits)) {
- this.persistenceXmlDeleteEdits.put(jpaProject.getPersistenceXmlResource().getFile(), persistenceXmlDeleteEdits);
+ Iterable<DeleteEdit> edits = this.createPersistenceXmlDeleteEdits(persistenceUnit);
+ if (!CollectionTools.isEmpty(edits)) {
+ this.persistenceXmlDeleteEdits.put(jpaProject.getPersistenceXmlResource().getFile(), edits);
}
sm.worked(1);
for (MappingFileRef mappingFileRef : persistenceUnit.getMappingFileRefs()) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java
index 9024e3eed8..3360d65d13 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal.refactoring;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -50,7 +51,7 @@ public abstract class AbstractJpaMoveJavaElementParticipant
extends MoveParticipant implements ISharableParticipant {
/**
- * Store the {@link IJavaElements}s to be moved and their corresponding {@link MoveArguments}
+ * Store the {@link IJavaElement}s to be moved and their corresponding {@link MoveArguments}
*/
protected final Map<IJavaElement, MoveArguments> originalJavaElements;
@@ -107,16 +108,17 @@ public abstract class AbstractJpaMoveJavaElementParticipant
@Override
public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditionsContext context) throws OperationCanceledException {
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 2);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 2);
sm.subTask(this.getCheckConditionsSubTaskName());
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : jpaProjectManager.getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createReplaceEdits(sm.newChild(10), jpaProject);
}
if (sm.isCanceled()) {
@@ -134,6 +136,18 @@ public abstract class AbstractJpaMoveJavaElementParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected abstract String getCompositeChangeName();
/**
@@ -185,10 +199,10 @@ public abstract class AbstractJpaMoveJavaElementParticipant
if (sm.isCanceled()) {
throw new OperationCanceledException();
}
- Iterable<ReplaceEdit> mappingFileReplaceEdits = this.createMappingFileReplaceEditsCheckClasspath(mappingFileRef);
- if (!CollectionTools.isEmpty(mappingFileReplaceEdits)) {
+ Iterable<ReplaceEdit> edits = this.createMappingFileReplaceEditsCheckClasspath(mappingFileRef);
+ if (!CollectionTools.isEmpty(edits)) {
IFile file = (IFile) mappingFileRef.getMappingFile().getResource();
- this.mappingFileReplaceEdits.put(file, mappingFileReplaceEdits);
+ this.mappingFileReplaceEdits.put(file, edits);
}
sm.worked(1);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java
index 123153e758..7d653279f2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal.refactoring;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -87,16 +88,17 @@ public abstract class AbstractJpaRenameJavaElementParticipant
@Override
public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditionsContext context) throws OperationCanceledException {
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 2);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 2);
sm.subTask(this.getCheckConditionsSubTaskName());
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : jpaProjectManager.getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createReplaceEdits(sm.newChild(10), jpaProject);
}
if (sm.isCanceled()) {
@@ -114,6 +116,18 @@ public abstract class AbstractJpaRenameJavaElementParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected abstract String getCompositeChangeName();
/**
@@ -165,10 +179,10 @@ public abstract class AbstractJpaRenameJavaElementParticipant
if (sm.isCanceled()) {
throw new OperationCanceledException();
}
- Iterable<ReplaceEdit> mappingFileReplaceEdits = this.createMappingFileReplaceEditsCheckClasspath(mappingFileRef);
- if (!CollectionTools.isEmpty(mappingFileReplaceEdits)) {
+ Iterable<ReplaceEdit> edits = this.createMappingFileReplaceEditsCheckClasspath(mappingFileRef);
+ if (!CollectionTools.isEmpty(edits)) {
IFile file = (IFile) mappingFileRef.getMappingFile().getResource();
- this.mappingFileReplaceEdits.put(file, mappingFileReplaceEdits);
+ this.mappingFileReplaceEdits.put(file, edits);
}
sm.worked(1);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeleteMappingFileParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeleteMappingFileParticipant.java
index 31fd726b99..cebebbcca4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeleteMappingFileParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeleteMappingFileParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal.refactoring;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -104,16 +105,17 @@ public class JpaDeleteMappingFileParticipant
//since the progress bar will hang if a large JPA project is being loaded,
//we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 1);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 1);
sm.subTask(JpaCoreRefactoringMessages.JPA_DELETE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME);
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : JptJpaCorePlugin.getJpaProjectManager().getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createDeleteEdits(jpaProject);
sm.worked(10);
}
@@ -128,6 +130,18 @@ public class JpaDeleteMappingFileParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected void createDeleteEdits(JpaProject jpaProject) throws OperationCanceledException {
PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
if (persistenceUnit == null) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveFolderParticipant.java
index faa035ba20..6ed5de1958 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveFolderParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveFolderParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -22,7 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
@@ -50,7 +51,7 @@ import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
/**
- * Participant in the move refactoring of {@link IFolders}s.
+ * Participant in the move refactoring of {@link IFolder}s.
* Any mapping file references in the persistence.xml will be updated to reflect the new location.
*/
public class JpaMoveFolderParticipant
@@ -116,16 +117,17 @@ public class JpaMoveFolderParticipant
//since the progress bar will hang if a large JPA project is being loaded,
//we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 1);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 1);
sm.subTask(JpaCoreRefactoringMessages.JPA_MOVE_FOLDER_REFACTORING_SUB_TASK_NAME);
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : JptJpaCorePlugin.getJpaProjectManager().getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createReplaceEdits(jpaProject);
sm.worked(10);
}
@@ -140,6 +142,18 @@ public class JpaMoveFolderParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected void createReplaceEdits(JpaProject jpaProject) throws OperationCanceledException {
PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
if (persistenceUnit == null) {
@@ -194,7 +208,8 @@ public class JpaMoveFolderParticipant
protected Iterable<ReplaceEdit> createPersistenceUnitReplaceEdits(PersistenceUnit persistenceUnit, IFolder folder, IContainer destination) {
IProject project = destination.getProject();
IPath fullPath = destination.getFullPath().append(folder.getName());
- IPath runtimePath = JptCommonCorePlugin.getResourceLocator(project).getRuntimePath(project, fullPath);
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ IPath runtimePath = locator.getRuntimePath(fullPath);
return persistenceUnit.createMoveFolderEdits(folder, runtimePath);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveMappingFileParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveMappingFileParticipant.java
index e26e694930..df9441cdc6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveMappingFileParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaMoveMappingFileParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,6 +14,7 @@ import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -21,7 +22,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
@@ -118,16 +119,17 @@ public class JpaMoveMappingFileParticipant
//since the progress bar will hang if a large JPA project is being loaded,
//we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 1);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 1);
sm.subTask(JpaCoreRefactoringMessages.JPA_MOVE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME);
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : JptJpaCorePlugin.getJpaProjectManager().getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createReplaceEdits(jpaProject);
sm.worked(10);
}
@@ -142,6 +144,18 @@ public class JpaMoveMappingFileParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected void createReplaceEdits(JpaProject jpaProject) throws OperationCanceledException {
PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
if (persistenceUnit == null) {
@@ -194,10 +208,11 @@ public class JpaMoveMappingFileParticipant
};
}
- private Iterable<ReplaceEdit> createPersistenceUnitReplaceEdits(PersistenceUnit persistenceUnit, IFile mappingFile, IFolder destination) {
+ protected Iterable<ReplaceEdit> createPersistenceUnitReplaceEdits(PersistenceUnit persistenceUnit, IFile mappingFile, IFolder destination) {
IProject project = destination.getProject();
IPath fullPath = destination.getFullPath();
- IPath runtimePath = JptCommonCorePlugin.getResourceLocator(project).getRuntimePath(project, fullPath);
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ IPath runtimePath = locator.getRuntimePath(fullPath);
return persistenceUnit.createMoveMappingFileEdits(mappingFile, runtimePath);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameFolderParticipant.java
index 268b0d74b4..f9b5e29a52 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameFolderParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameFolderParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -40,7 +41,7 @@ import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
/**
- * Participant in the rename refactoring of {@link IFolders}s.
+ * Participant in the rename refactoring of {@link IFolder}s.
* If the renamed mapping file is listed in a persistence.xml file of any JpaProject
* then a Change object is created that will rename that reference from the file.
* If the renamed mapping file is an implied mapping file, then an actual reference to the mapping file will be specified.
@@ -92,16 +93,17 @@ public class JpaRenameFolderParticipant
//since the progress bar will hang if a large JPA project is being loaded,
//we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 1);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 1);
sm.subTask(JpaCoreRefactoringMessages.JPA_RENAME_FOLDER_REFACTORING_SUB_TASK_NAME);
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : JptJpaCorePlugin.getJpaProjectManager().getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createReplaceEdits(jpaProject);
sm.worked(10);
}
@@ -116,6 +118,18 @@ public class JpaRenameFolderParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected void createReplaceEdits(JpaProject jpaProject) throws OperationCanceledException {
PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
if (persistenceUnit == null) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameMappingFileParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameMappingFileParticipant.java
index e4e18412dd..6ee1373e46 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameMappingFileParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaRenameMappingFileParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal.refactoring;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -90,16 +91,17 @@ public class JpaRenameMappingFileParticipant
//since the progress bar will hang if a large JPA project is being loaded,
//we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ Iterable<JpaProject> jpaProjects = this.getJpaProjects();
+ int size = CollectionTools.size(jpaProjects);
+ if (size == 0) {
return null;
}
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 1);
+ SubMonitor sm = SubMonitor.convert(monitor, size*10 + 1);
sm.subTask(JpaCoreRefactoringMessages.JPA_RENAME_MAPPING_FILE_REFACTORING_SUB_TASK_NAME);
ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
- for (JpaProject jpaProject : JptJpaCorePlugin.getJpaProjectManager().getJpaProjects()) {
+ for (JpaProject jpaProject : jpaProjects) {
this.createReplaceEdits(jpaProject);
sm.worked(10);
}
@@ -114,6 +116,18 @@ public class JpaRenameMappingFileParticipant
return null;
}
+ protected Iterable<JpaProject> getJpaProjects() throws OperationCanceledException {
+ try {
+ return this.getJpaProjectManager().waitToGetJpaProjects();
+ } catch (InterruptedException ex) {
+ throw new OperationCanceledException(ex.getMessage());
+ }
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
protected void createReplaceEdits(JpaProject jpaProject) throws OperationCanceledException {
PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
if (persistenceUnit == null) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourceAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourceAdapterFactory.java
deleted file mode 100644
index 4ed01aa73c..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourceAdapterFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal.resource.xml;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jpt.common.core.JptResourceModel;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
-
-public class JpaXmlResourceAdapterFactory
- implements IAdapterFactory
-{
- private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaXmlResource.class };
-
- public Class<?>[] getAdapterList() {
- return ADAPTER_LIST;
- }
-
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) {
- if (adaptableObject instanceof IFile) {
- return this.getAdapter((IFile) adaptableObject, adapterType);
- }
- return null;
- }
-
- private Object getAdapter(final IFile file, Class <?>adapterType) {
- if (adapterType == JpaXmlResource.class) {
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- if (jpaFile != null) {
- JptResourceModel resourceModel = jpaFile.getResourceModel();
- if (resourceModel instanceof JpaXmlResource) {
- return resourceModel;
- }
- }
- }
- return null;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourcePropertyTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourcePropertyTester.java
deleted file mode 100644
index c06f2204a8..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/xml/JpaXmlResourcePropertyTester.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal.resource.xml;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.core.context.XmlFile;
-import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
-
-// TODO move to o.e.jpt.core.internal(.context)?
-// rename to JpaXmlPropertyTester
-public class JpaXmlResourcePropertyTester
- extends PropertyTester
-{
- public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
-
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- JpaXmlResource xmlResource = null;
- if (receiver instanceof JpaXmlResource) {
- xmlResource = (JpaXmlResource) receiver;
- }
- else if (receiver instanceof XmlFile) {
- xmlResource = ((XmlFile) receiver).getXmlResource();
- }
- else {
- return false;
- }
-
- if (IS_LATEST_SUPPORTED_VERSION.equals(property)) {
- boolean expected = ((Boolean) expectedValue).booleanValue();
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(xmlResource.getProject());
- IContentType contentType = xmlResource.getContentType();
- boolean actual =
- xmlResource.getVersion() != null
- && xmlResource.getVersion().equals(
- jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(contentType).getVersion());
-
- return actual == expected;
- }
-
- return false;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/synch/SynchronizeClassesJob.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/synch/SynchronizeClassesJob.java
deleted file mode 100644
index cbc3693446..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/synch/SynchronizeClassesJob.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.core.internal.synch;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResourceRuleFactory;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
-import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
-import org.eclipse.jpt.jpa.core.resource.persistence.XmlJavaClassRef;
-import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistence;
-import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit;
-import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
-
-/**
- * Synchronizes the lists of persistent classes in a persistence unit and a
- * persistence project.
- */
-public class SynchronizeClassesJob extends WorkspaceJob
-{
- private IFile persistenceXmlFile;
-
-
- public SynchronizeClassesJob(IFile file) {
- super(JptCoreMessages.SYNCHRONIZE_CLASSES_JOB);
- IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
- setRule(ruleFactory.modifyRule(file.getProject()));
- this.persistenceXmlFile = file;
- }
-
- @Override
- public IStatus runInWorkspace(IProgressMonitor monitor) {
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- final SubMonitor sm = SubMonitor.convert(monitor, JptCoreMessages.SYNCHRONIZING_CLASSES_TASK, 20);
- final JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.persistenceXmlFile.getProject());
- final JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
- if (resource == null) {
- //the resource would only be null if the persistence.xml file had an invalid content type
- return Status.OK_STATUS;
- }
- if (sm.isCanceled()) {
- return Status.CANCEL_STATUS;
- }
- sm.worked(1);
-
- resource.modify(new Runnable() {
- public void run() {
- XmlPersistence persistence = (XmlPersistence) resource.getRootObject();
- XmlPersistenceUnit persistenceUnit;
-
- if (persistence.getPersistenceUnits().size() > 0) {
- persistenceUnit = persistence.getPersistenceUnits().get(0);
- }
- else {
- persistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit();
- persistenceUnit.setName(jpaProject.getName());
- persistence.getPersistenceUnits().add(persistenceUnit);
- }
- sm.worked(1);
-
- persistenceUnit.getClasses().clear();
- sm.worked(1);
-
- addClassRefs(sm.newChild(17), jpaProject, persistenceUnit);
- }
- });
- return Status.OK_STATUS;
- }
-
- protected void addClassRefs(IProgressMonitor monitor, JpaProject jpaProject, XmlPersistenceUnit persistenceUnit) {
- Iterable<String> mappedClassNames = getMappedClassNames(jpaProject, '$');
- final SubMonitor sm = SubMonitor.convert(monitor, CollectionTools.size(mappedClassNames));
-
- for (String fullyQualifiedTypeName : mappedClassNames) {
- if ( ! mappingFileContains(jpaProject, fullyQualifiedTypeName)) {
- XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
- classRef.setJavaClass(fullyQualifiedTypeName);
- persistenceUnit.getClasses().add(classRef);
- }
- sm.worked(1);
- }
- }
-
- protected Iterable<String> getMappedClassNames(final JpaProject jpaProject, final char enclosingTypeSeparator) {
- return new TransformationIterable<String, String>(jpaProject.getMappedJavaSourceClassNames()) {
- @Override
- protected String transform(String fullyQualifiedName) {
- IType jdtType = SynchronizeClassesJob.this.findType(jpaProject, fullyQualifiedName);
- return jdtType.getFullyQualifiedName(enclosingTypeSeparator);
- }
- };
- }
-
- protected IType findType(JpaProject jpaProject, String typeName) {
- try {
- return jpaProject.getJavaProject().findType(typeName);
- } catch (JavaModelException ex) {
- return null; // ignore exception?
- }
- }
-
- boolean mappingFileContains(JpaProject jpaProject, String fullyQualifiedTypeName) {
- PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
- if (persistenceXml == null) {
- return false;
- }
- Persistence persistence = persistenceXml.getPersistence();
- if (persistence == null) {
- return false;
- }
- if (persistence.getPersistenceUnitsSize() == 0) {
- return false;
- }
- PersistenceUnit persistenceUnit = persistence.getPersistenceUnits().iterator().next();
- for (MappingFileRef mappingFileRef : persistenceUnit.getMappingFileRefs()) {
- if (mappingFileRef.getPersistentType(fullyQualifiedTypeName) != null) {
- return true;
- }
- }
- return false;
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java
index 45b7fa7697..2dcde658bd 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidationPreferences.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,9 +11,9 @@ package org.eclipse.jpt.jpa.core.internal.validation;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.jpt.common.core.IResourcePart;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.osgi.service.prefs.BackingStoreException;
@@ -48,33 +48,38 @@ public class JpaValidationPreferences {
if (problemPreference == null){
return NO_SEVERITY_PREFERENCE;
- } else if (problemPreference.equals(ERROR)){
+ }
+ if (problemPreference.equals(ERROR)){
return IMessage.HIGH_SEVERITY;
- } else if (problemPreference.equals(WARNING)){
+ }
+ if (problemPreference.equals(WARNING)){
return IMessage.NORMAL_SEVERITY;
- } else if (problemPreference.equals(INFO)){
+ }
+ if (problemPreference.equals(INFO)){
return IMessage.LOW_SEVERITY;
}
return NO_SEVERITY_PREFERENCE;
}
private static IProject getProject(Object targetObject) {
- IAdaptable target = (IAdaptable)targetObject;
- IResource resource = ((IResourcePart) target.getAdapter(IResourcePart.class)).getResource();
- IProject project = resource.getProject();
- return project;
+ IResource resource = PlatformTools.getAdapter(targetObject, IResource.class);
+ return (resource == null) ? null : resource.getProject();
}
/**
- * Returns whether or not this problem should be ignored based on project or
- * workspace preferences
+ * Return whether the specified problem should <em>not</em> be ignored based
+ * on project or workspace preferences.
*/
- public static boolean isProblemIgnored(IProject project, String messageId){
- String problemPreference = getPreference(project, messageId);
- if (problemPreference != null && problemPreference.equals(IGNORE)){
- return true;
- }
- return false;
+ public static boolean problemIsNotIgnored(IProject project, String messageId) {
+ return ! problemIsIgnored(project, messageId);
+ }
+
+ /**
+ * Return whether the specified problem should be ignored based on project or
+ * workspace preferences.
+ */
+ public static boolean problemIsIgnored(IProject project, String messageId) {
+ return Tools.valuesAreEqual(getPreference(project, messageId), IGNORE);
}
private static String getPreference(IProject project, String messageId) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
index ec844cf87f..f15ae1e8a1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/validation/JpaValidator.java
@@ -1,9 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -13,10 +13,8 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jpt.common.core.IResourcePart;
-import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.wst.validation.AbstractValidator;
@@ -32,47 +30,49 @@ import org.eclipse.wst.validation.internal.provisional.core.IValidator;
* This class is referenced in the JPA extension for the
* WTP validator extension point.
*/
-public class JpaValidator extends AbstractValidator implements IValidator {
-
+public class JpaValidator
+ extends AbstractValidator
+ implements IValidator
+{
public JpaValidator() {
super();
}
-
+
// ********** IValidator implementation **********
public void validate(IValidationContext context, IReporter reporter) {
- validate(reporter, project(context));
+ this.validate(reporter, ((IProjectValidationContext) context).getProject());
}
-
+
public void cleanup(IReporter reporter) {
// nothing to do
}
-
-
- // **************** AbstractValidator impl *********************************
-
+
+
+ // ********** AbstractValidator implementation **********
+
@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
- if (resource.getType() != IResource.FILE)
+ if (resource.getType() != IResource.FILE) {
return null;
+ }
ValidationResult result = new ValidationResult();
IReporter reporter = result.getReporter(monitor);
IProject project = resource.getProject();
- this.clearMarkers(project);
result.setSuspendValidation(project);
this.validate(reporter, project);
return result;
}
-
-
- // **************** internal conv. *****************************************
+
+
+ // ********** internal **********
+
private void clearMarkers(IProject project) {
try {
- clearMarkers_(project);
- }
- catch (CoreException ce) {
- JptJpaCorePlugin.log(ce);
+ this.clearMarkers_(project);
+ } catch (CoreException ex) {
+ JptJpaCorePlugin.log(ex);
}
}
@@ -82,39 +82,42 @@ public class JpaValidator extends AbstractValidator implements IValidator {
marker.delete();
}
}
-
+
private void validate(IReporter reporter, IProject project) {
- for (IMessage message : this.getValidationMessages(reporter, project)) {
- // check to see if the message should be ignored based on preferences
- if (!JpaValidationPreferences.isProblemIgnored(project, message.getId())){
- reporter.addMessage(this, adjustMessage(message));
+ Iterable<IMessage> messages = this.buildValidationMessages(reporter, project);
+ // since the validation messages are usually built asynchronously
+ // and a workspace shutdown could occur in the meantime,
+ // wait until we actually get the new messages before we clear out the old messages
+ this.clearMarkers(project);
+ for (IMessage message : messages) {
+ // check preferences for IGNORE
+ if (JpaValidationPreferences.problemIsNotIgnored(project, message.getId())){
+ reporter.addMessage(this, this.adjustMessage(message));
}
}
}
-
- private IProject project(IValidationContext context) {
- return ((IProjectValidationContext) context).getProject();
- }
-
- private Iterable<IMessage> getValidationMessages(IReporter reporter, IProject project) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
- if (jpaProject != null) {
- return jpaProject.getValidationMessages(reporter);
+
+ private Iterable<IMessage> buildValidationMessages(IReporter reporter, IProject project) {
+ try {
+ return this.buildValidationMessages_(reporter, project);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(ex);
}
- return new SingleElementIterable<IMessage>(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.NO_JPA_PROJECT,
- project
- ));
}
-
+
+ private Iterable<IMessage> buildValidationMessages_(IReporter reporter, IProject project) throws InterruptedException {
+ return this.getJpaProjectReference(project).buildValidationMessages(reporter);
+ }
+
+ private JpaProject.Reference getJpaProjectReference(IProject project) {
+ return (JpaProject.Reference) project.getAdapter(JpaProject.Reference.class);
+ }
+
private IMessage adjustMessage(IMessage message) {
- IAdaptable targetObject = (IAdaptable) message.getTargetObject();
- IResource targetResource = ((IResourcePart) targetObject.getAdapter(IResourcePart.class)).getResource();
- message.setTargetObject(targetResource);
+ message.setTargetObject(PlatformTools.getAdapter(message.getTargetObject(), IResource.class));
if (message.getLineNumber() == IMessage.LINENO_UNSET) {
- message.setAttribute(IMarker.LOCATION, " ");
+ message.setAttribute(IMarker.LOCATION, " "); //$NON-NLS-1$
}
return message;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/MetamodelSynchronizer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/MetamodelSynchronizer.java
index fb2518f03f..d3e6cf1f98 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/MetamodelSynchronizer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpa2/MetamodelSynchronizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,6 +10,9 @@
package org.eclipse.jpt.jpa.core.jpa2;
import java.io.Serializable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.utility.internal.StringTools;
@@ -24,7 +27,8 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.StaticMetamodelAnnotation;
* When a JPA project is first created (e.g. when the user adds the JPA
* Facet to a Faceted project or when a workspace containing a JPA project is
* opened), if it is configured to generate the
- * Canonical Metamodel (i.e. its metamodel source folder is non-null), it will
+ * Canonical Metamodel (i.e. its metamodel source folder is non-
+ * <code>null</code>), it will
* first discover what metamodel classes are already present in the metamodel
* source folder. Any class appropriately annotated with
* <code>javax.persistence.metamodel.StaticMetamodel</code>
@@ -39,7 +43,7 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.StaticMetamodelAnnotation;
* Metamodel is cleared from the context model, but the generated source files are
* left in place.
* </li><li>
- * When a JPA project's metamodel source folder is set to a non-null value,
+ * When a JPA project's metamodel source folder is set to a non-<code>null</code> value,
* like when a JPA project is first created, the resulting Canonical Metamodel
* will be merged with whatever is already present in the folder.
* </li></ul>
@@ -54,7 +58,6 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.StaticMetamodelAnnotation;
* @since 2.3
*/
public interface MetamodelSynchronizer {
-
/**
* The value used to tag a generated type:
* <pre>
@@ -65,7 +68,7 @@ public interface MetamodelSynchronizer {
void initializeMetamodel();
- void synchronizeMetamodel();
+ IStatus synchronizeMetamodel(IProgressMonitor progressMonitor);
void disposeMetamodel();
@@ -74,28 +77,37 @@ public interface MetamodelSynchronizer {
* Singleton implementation of the metamodel synchronizer interface that
* does nothing. (Not sure we need this....)
*/
- final class Null implements MetamodelSynchronizer, Serializable {
+ final class Null
+ implements MetamodelSynchronizer, Serializable
+ {
public static final MetamodelSynchronizer INSTANCE = new Null();
+
public static MetamodelSynchronizer instance() {
return INSTANCE;
}
+
// ensure single instance
private Null() {
super();
}
+
public void initializeMetamodel() {
// do nothing
}
- public void synchronizeMetamodel() {
- // do nothing
+
+ public IStatus synchronizeMetamodel(IProgressMonitor monitor) {
+ return Status.OK_STATUS;
}
+
public void disposeMetamodel() {
// do nothing
}
+
@Override
public String toString() {
- return "MetamodelSynchronizer.Null"; //$NON-NLS-1$
+ return StringTools.buildSingletonToString(this);
}
+
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
@@ -103,6 +115,7 @@ public interface MetamodelSynchronizer {
}
}
+
final class MetamodelTools {
/**
@@ -172,6 +185,5 @@ public interface MetamodelSynchronizer {
}
return false;
}
-
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java
index b6dd391075..e3ee9dcfdb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -38,6 +38,7 @@ import org.eclipse.jem.util.emf.workbench.FlexibleProjectResourceSet;
import org.eclipse.jem.util.emf.workbench.IEMFContextContributor;
import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.utility.internal.ListenerList;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
@@ -98,8 +99,7 @@ public abstract class AbstractXmlResourceProvider
resourceUri = URI.createPlatformResourceURI(resourcePath.toString(), false);
}
else {
- IPath absolutePath =
- JptCommonCorePlugin.getResourceLocator(this.project).getResourcePath(this.project, resourcePath);
+ IPath absolutePath = this.getProjectResourceLocator().getResourcePath(resourcePath);
resourceUri = URI.createPlatformResourceURI(absolutePath.toString(), false);
}
@@ -107,6 +107,10 @@ public abstract class AbstractXmlResourceProvider
return uriConverter.normalize(resourceUri);
}
+ protected ProjectResourceLocator getProjectResourceLocator() {
+ return (ProjectResourceLocator) this.project.getAdapter(ProjectResourceLocator.class);
+ }
+
/**
* Return the resource, if it exists. If no file exists for this resource,
* this will return a stub resource. You must call #createResource() to
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/xml/JpaXmlResource.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/xml/JpaXmlResource.java
index 0a4e29b098..99eec44c56 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/xml/JpaXmlResource.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/xml/JpaXmlResource.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,9 +11,7 @@ package org.eclipse.jpt.jpa.core.resource.xml;
import java.io.IOException;
import java.util.Collections;
-
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.content.IContentType;
@@ -235,19 +233,10 @@ public class JpaXmlResource
return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName));
}
- public IProject getProject() {
- return this.getFile().getProject();
- }
-
- public void modify(Runnable runnable) {
+ public void save() {
try {
- runnable.run();
- try {
- save(Collections.EMPTY_MAP);
- } catch (IOException ex) {
- JptJpaCorePlugin.log(ex);
- }
- } catch (Exception ex) {
+ this.save(Collections.EMPTY_MAP);
+ } catch (IOException ex) {
JptJpaCorePlugin.log(ex);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java
index 15cae4fad8..22e3d7d663 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/ConnectionAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.db;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+
/**
* An empty implementation of {@link ConnectionListener}.
* <p>
@@ -68,4 +70,9 @@ public class ConnectionAdapter
public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey) {
// do nothing
}
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/plugin.xml
index 34379ca44f..ca9b42c072 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/plugin.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
- Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ Copyright (c) 2008, 2012 Oracle. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0, which accompanies this distribution
and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -104,10 +104,14 @@
<enablement>
<and>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="jpa-user-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="jpa-user-library-provider"/>
</with>
<with variable="config">
- <test property="org.eclipse.jpt.jpa.core.jpaPlatformGroup" value="eclipselink"/>
+ <adapt type = "org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription">
+ <test property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
+ value="eclipselink"/>
+ </adapt>
</with>
</and>
</enablement>
@@ -119,10 +123,14 @@
<enablement>
<and>
<with variable="libraryProvider">
- <test property="org.eclipse.jpt.common.core.extendsId" value="eclipselink-bundles-library-provider"/>
+ <test property="org.eclipse.jpt.common.core.extendsId"
+ value="eclipselink-bundles-library-provider"/>
</with>
<with variable="config">
- <test property="org.eclipse.jpt.jpa.core.jpaPlatformGroup" value="eclipselink"/>
+ <adapt type = "org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription">
+ <test property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
+ value="eclipselink"/>
+ </adapt>
</with>
</and>
</enablement>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/AbstractEclipseLinkDDLGenerator.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/AbstractEclipseLinkDDLGenerator.java
index a4b8127fa5..f6cd283a41 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/AbstractEclipseLinkDDLGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/ddlgen/AbstractEclipseLinkDDLGenerator.java
@@ -19,9 +19,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
-
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
@@ -149,7 +147,6 @@ public abstract class AbstractEclipseLinkDDLGenerator extends AbstractJptGenerat
//reconnect since we disconnected in preGenerate();
//ensure the project is fully updated before validating - bug 277236
protected void reconnect() {
- getJpaProject().updateAndWait();
ConnectionProfile cp = this.getConnectionProfile();
if (cp != null) {
cp.connect();
@@ -157,10 +154,7 @@ public abstract class AbstractEclipseLinkDDLGenerator extends AbstractJptGenerat
}
protected void validateProject() {
- IProject project = this.getJpaProject().getProject();
- ValidateJob job = new ValidateJob(project);
- job.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project));
- job.schedule();
+ new ValidateJob(this.jpaProject.getProject()).schedule();
}
// ********** ClasspathEntry **********
@@ -305,28 +299,24 @@ public abstract class AbstractEclipseLinkDDLGenerator extends AbstractJptGenerat
/**
* Performs validation after tables have been generated
*/
- private class ValidateJob extends Job
+ /* CU private */ class ValidateJob
+ extends Job
{
- private IProject project;
-
+ private final IProject[] projects;
- public ValidateJob(IProject project) {
+ ValidateJob(IProject project) {
super(JptCoreMessages.VALIDATE_JOB);
- this.project = project;
+ this.projects = new IProject[] {project};
}
-
@Override
protected IStatus run(IProgressMonitor monitor) {
- IStatus status = Status.OK_STATUS;
try {
- ValidationFramework.getDefault().validate(
- new IProject[] {this.project}, true, false, monitor);
- }
- catch (CoreException ce) {
- status = Status.CANCEL_STATUS;
+ ValidationFramework.getDefault().validate(this.projects, true, false, monitor);
+ } catch (CoreException ex) {
+ throw new RuntimeException(ex);
}
- return status;
+ return Status.OK_STATUS;
}
}
@@ -356,16 +346,11 @@ public abstract class AbstractEclipseLinkDDLGenerator extends AbstractJptGenerat
// ********** Queries **********
protected JpaPlatform getPlatform() {
- return this.getJpaProject().getJpaPlatform();
+ return this.jpaProject.getJpaPlatform();
}
- protected JpaProject getJpaProject() {
- return this.jpaProject;
- }
-
-
protected ConnectionProfile getConnectionProfile() {
- return this.getJpaProject().getConnectionProfile();
+ return this.jpaProject.getConnectionProfile();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/operations/EclipseLinkOrmFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/operations/EclipseLinkOrmFileCreationDataModelProvider.java
index 25e4011de1..2d6b3e56eb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/operations/EclipseLinkOrmFileCreationDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/operations/EclipseLinkOrmFileCreationDataModelProvider.java
@@ -1,15 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.internal.operations;
+import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.internal.operations.OrmFileCreationDataModelProvider;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
@@ -48,11 +48,12 @@ public class EclipseLinkOrmFileCreationDataModelProvider
@Override
protected String getDefaultVersion() {
- if (getProject() == null) {
+ JpaProject jpaProject = this.getJpaProject();
+ if (jpaProject == null) {
return null;
}
try {
- return getJpaProject().getJpaPlatform().getMostRecentSupportedResourceType(
+ return jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(
JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE).getVersion();
}
catch (IllegalArgumentException iae) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF
index dbbdf30ac5..c510214afc 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/META-INF/MANIFEST.MF
@@ -21,6 +21,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jpt.jpa.ui;bundle-version="[3.0.0,4.0.0)",
org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
org.eclipse.ui;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.ui.navigator;bundle-version="[3.4.0,4.0.0)",
org.eclipse.ui.forms;bundle-version="[3.4.0,4.0.0)",
org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)",
org.eclipse.wst.common.frameworks.ui;bundle-version="[1.1.200,2.0.0)",
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
index 1797c30395..ffb3f3ed23 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.2"?> <!--
- Copyright (c) 2007, 2011 Oracle. All rights reserved.
+<?eclipse version="3.2"?>
+<!--
+ Copyright (c) 2007, 2012 Oracle. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0, which accompanies this distribution
and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -97,14 +98,14 @@
</or>
<adapt type="org.eclipse.core.resources.IResource">
<test
- forcePluginActivation="true"
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa" />
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
+ </adapt>
+ <adapt type = "org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription">
+ <test property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
+ value="eclipselink"/>
</adapt>
- <test
- property="org.eclipse.jpt.jpa.core.jpaPlatformGroup"
- value="eclipselink">
- </test>
</and>
</enablement>
</commonWizard>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java
index 430527f4e8..8e9aeee564 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkMultitenancyComposite.java
@@ -17,7 +17,6 @@ import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.ui.internal.widgets.TriStateCheckBox;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
@@ -312,7 +311,7 @@ public class EclipseLinkMultitenancyComposite extends Pane<EclipseLinkMultitenan
@Override
protected Boolean buildValue() {
- return Boolean.valueOf(this.listHolder.size() > 0);
+ return Boolean.valueOf(this.listModel.size() > 0);
}
public void setValue(Boolean value) {
@@ -346,56 +345,54 @@ public class EclipseLinkMultitenancyComposite extends Pane<EclipseLinkMultitenan
}
}
- private class TenantDiscriminatorColumnPaneEnablerHolder
- extends CachingTransformationPropertyValueModel<EclipseLinkMultitenancy2_3, Boolean>
+ /* CU private */ class TenantDiscriminatorColumnPaneEnablerHolder
+ extends TransformationPropertyValueModel<EclipseLinkMultitenancy2_3, Boolean>
{
private StateChangeListener stateChangeListener;
-
- public TenantDiscriminatorColumnPaneEnablerHolder() {
+ TenantDiscriminatorColumnPaneEnablerHolder() {
super(
new ValueListAdapter<EclipseLinkMultitenancy2_3>(
new ReadOnlyWritablePropertyValueModelWrapper<EclipseLinkMultitenancy2_3>(getSubjectHolder()),
- EclipseLinkMultitenancy2_3.SPECIFIED_TENANT_DISCRIMINATOR_COLUMNS_LIST));
- this.stateChangeListener = buildStateChangeListener();
+ EclipseLinkMultitenancy2_3.SPECIFIED_TENANT_DISCRIMINATOR_COLUMNS_LIST
+ )
+ );
+ this.stateChangeListener = this.buildStateChangeListener();
}
private StateChangeListener buildStateChangeListener() {
return new StateChangeListener() {
public void stateChanged(StateChangeEvent event) {
- valueStateChanged();
+ TenantDiscriminatorColumnPaneEnablerHolder.this.valueStateChanged();
}
};
}
void valueStateChanged() {
- Object oldValue = this.cachedValue;
- Object newValue = transformNew(this.valueHolder.getValue());
- firePropertyChanged(VALUE, oldValue, newValue);
+ Object old = this.value;
+ this.value = this.transform(this.valueModel.getValue());
+ this.firePropertyChanged(VALUE, old, this.value);
}
@Override
- protected Boolean transform(EclipseLinkMultitenancy2_3 value) {
- if (value == null) {
- return Boolean.FALSE;
- }
- return super.transform(value);
+ protected Boolean transform(EclipseLinkMultitenancy2_3 v) {
+ return (v == null) ? Boolean.FALSE : super.transform(v);
}
@Override
- protected Boolean transform_(EclipseLinkMultitenancy2_3 value) {
- return Boolean.valueOf(value.getSpecifiedTenantDiscriminatorColumnsSize() > 0);
+ protected Boolean transform_(EclipseLinkMultitenancy2_3 v) {
+ return Boolean.valueOf(v.getSpecifiedTenantDiscriminatorColumnsSize() > 0);
}
@Override
protected void engageModel() {
super.engageModel();
- this.valueHolder.addStateChangeListener(this.stateChangeListener);
+ this.valueModel.addStateChangeListener(this.stateChangeListener);
}
@Override
protected void disengageModel() {
- this.valueHolder.removeStateChangeListener(this.stateChangeListener);
+ this.valueModel.removeStateChangeListener(this.stateChangeListener);
super.disengageModel();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLink2_3PersistenceUnitMetadataComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLink2_3PersistenceUnitMetadataComposite.java
index 14dcb68200..d29110cf30 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLink2_3PersistenceUnitMetadataComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLink2_3PersistenceUnitMetadataComposite.java
@@ -32,7 +32,7 @@ import org.eclipse.jpt.jpa.ui.internal.details.db.SchemaCombo;
import org.eclipse.jpt.jpa.ui.internal.details.orm.EntityMappingsDetailsPage;
import org.eclipse.jpt.jpa.ui.internal.details.orm.JptUiDetailsOrmMessages;
import org.eclipse.jpt.jpa.ui.internal.details.orm.PersistenceUnitMetadataComposite;
-import org.eclipse.jpt.jpa.ui.internal.jpa2.Jpa2_0ProjectFlagModel;
+import org.eclipse.jpt.jpa.ui.internal.jpa2.Jpa2_0FlagTransformer;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
@@ -132,7 +132,7 @@ public class EclipseLink2_3PersistenceUnitMetadataComposite extends PersistenceU
JpaHelpContextIds.ENTITY_ORM_DELIMITED_IDENTIFIERS
);
- SWTTools.controlVisibleState(new Jpa2_0ProjectFlagModel<OrmPersistenceUnitMetadata>(this.getSubjectHolder()), diCheckBox);
+ SWTTools.controlVisibleState(Jpa2_0FlagTransformer.convertToFlagModel(this.getSubjectHolder()), diCheckBox);
// Tenant discriminator columns group pane
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_0DetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_0DetailsProvider.java
index 393e154fdb..24cc9f6e46 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_0DetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_0DetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,13 +13,13 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.AbstractEntityMappingsDetailsProvider;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible for creating the {@link JpaDetailsPage}
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
* when the information comes from the XML file (either from the persistence
* configuration or from the Mappings Descriptor).
*
@@ -56,7 +56,7 @@ public class EclipseLinkEntityMappings2_0DetailsProvider
resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_2_2_RESOURCE_TYPE);
}
- public JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(
+ public JpaDetailsPageManager<? extends JpaStructureNode> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_3DetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_3DetailsProvider.java
index f52aa8b2ac..fa2e449002 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_3DetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappings2_3DetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,13 +13,13 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.AbstractEntityMappingsDetailsProvider;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible for creating the {@link JpaDetailsPage}
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
* when the information comes from the XML file (either from the persistence
* configuration or from the Mappings Descriptor).
*
@@ -55,7 +55,7 @@ public class EclipseLinkEntityMappings2_3DetailsProvider
resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_2_4_RESOURCE_TYPE);
}
- public JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(
+ public JpaDetailsPageManager<? extends JpaStructureNode> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsDetailsProvider.java
index 99f0bf3bff..92305d4a4a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,13 +13,13 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.AbstractEntityMappingsDetailsProvider;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible for creating the {@link JpaDetailsPage}
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
* when the information comes from the XML file (either from the persistence
* configuration or from the Mappings Descriptor).
*
@@ -56,7 +56,7 @@ public class EclipseLinkEntityMappingsDetailsProvider
|| resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE);
}
- public JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(
+ public JpaDetailsPageManager<? extends JpaStructureNode> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java
index bdc6fb4156..4064375f3f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2011 Oracle. All rights reserved.
+* Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,10 +12,10 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyWritablePropertyValueModelWrapper;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
@@ -158,7 +158,7 @@ public class EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite extend
@Override
protected Boolean buildValue() {
- return Boolean.valueOf(this.listHolder.size() > 0);
+ return Boolean.valueOf(this.listModel.size() > 0);
}
public void setValue(Boolean value) {
@@ -192,55 +192,54 @@ public class EclipseLinkEntityMappingsTenantDiscriminatorColumnsComposite extend
}
}
- private class TenantDiscriminatorColumnPaneEnablerHolder
- extends CachingTransformationPropertyValueModel<EntityMappings, Boolean>
+ /* CU private */ class TenantDiscriminatorColumnPaneEnablerHolder
+ extends TransformationPropertyValueModel<EntityMappings, Boolean>
{
private StateChangeListener stateChangeListener;
- public TenantDiscriminatorColumnPaneEnablerHolder() {
+ TenantDiscriminatorColumnPaneEnablerHolder() {
super(
new ValueListAdapter<EntityMappings>(
new ReadOnlyWritablePropertyValueModelWrapper<EntityMappings>(getSubjectHolder()),
- EclipseLinkEntityMappings.SPECIFIED_TENANT_DISCRIMINATOR_COLUMNS_LIST));
- this.stateChangeListener = buildStateChangeListener();
+ EclipseLinkEntityMappings.SPECIFIED_TENANT_DISCRIMINATOR_COLUMNS_LIST
+ )
+ );
+ this.stateChangeListener = this.buildStateChangeListener();
}
private StateChangeListener buildStateChangeListener() {
return new StateChangeListener() {
public void stateChanged(StateChangeEvent event) {
- valueStateChanged();
+ TenantDiscriminatorColumnPaneEnablerHolder.this.valueStateChanged();
}
};
}
void valueStateChanged() {
- Object oldValue = this.cachedValue;
- Object newValue = transformNew(this.valueHolder.getValue());
- firePropertyChanged(VALUE, oldValue, newValue);
+ Object old = this.value;
+ this.value = this.transform(this.valueModel.getValue());
+ firePropertyChanged(VALUE, old, this.value);
}
@Override
- protected Boolean transform(EntityMappings value) {
- if (value == null) {
- return Boolean.FALSE;
- }
- return super.transform(value);
+ protected Boolean transform(EntityMappings v) {
+ return (v == null) ? Boolean.FALSE : super.transform(v);
}
@Override
- protected Boolean transform_(EntityMappings value) {
- return Boolean.valueOf(((EclipseLinkEntityMappings) value).getSpecifiedTenantDiscriminatorColumnsSize() > 0);
+ protected Boolean transform_(EntityMappings v) {
+ return Boolean.valueOf(((EclipseLinkEntityMappings) v).getSpecifiedTenantDiscriminatorColumnsSize() > 0);
}
@Override
protected void engageModel() {
super.engageModel();
- this.valueHolder.addStateChangeListener(this.stateChangeListener);
+ this.valueModel.addStateChangeListener(this.stateChangeListener);
}
@Override
protected void disengageModel() {
- this.valueHolder.removeStateChangeListener(this.stateChangeListener);
+ this.valueModel.removeStateChangeListener(this.stateChangeListener);
super.disengageModel();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_1UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_1UiDefinition.java
index cce7dedd4f..3c1553efac 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_1UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_1UiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,10 +11,10 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkOrmResourceModelStructureProvider;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmTypeMappingUiDefinition;
@@ -33,7 +33,7 @@ import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToManyMappingUiDefiniti
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToOneMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmTransientMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmVersionMappingUiDefinition;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmXmlUiDefinition;
public class EclipseLinkOrmXml1_1UiDefinition
extends AbstractOrmXmlResourceUiDefinition
@@ -67,10 +67,10 @@ public class EclipseLinkOrmXml1_1UiDefinition
return resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_1_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkOrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return OrmXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
-
+
@Override
protected void addOrmAttributeMappingUiDefinitionsTo(
List<OrmAttributeMappingUiDefinition<? extends AttributeMapping>> definitions) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_2UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_2UiDefinition.java
index 0d1a46eaf6..46d56c8b9e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_2UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml1_2UiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,10 +11,10 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkOrmResourceModelStructureProvider;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmTypeMappingUiDefinition;
@@ -33,7 +33,7 @@ import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToManyMappingUiDefiniti
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToOneMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmTransientMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmVersionMappingUiDefinition;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmXmlUiDefinition;
public class EclipseLinkOrmXml1_2UiDefinition
extends AbstractOrmXmlResourceUiDefinition
@@ -67,8 +67,8 @@ public class EclipseLinkOrmXml1_2UiDefinition
return resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_2_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkOrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return OrmXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_0UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_0UiDefinition.java
index 0676e6fa65..b82cbf9f36 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_0UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_0UiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,10 +11,10 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkOrmResourceModelStructureProvider;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmTypeMappingUiDefinition;
@@ -33,8 +33,8 @@ import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToManyMappingUiDefiniti
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToOneMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmTransientMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmVersionMappingUiDefinition;
+import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmXmlUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.jpa2.details.orm.OrmElementCollectionMapping2_0UiDefinition;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
public class EclipseLinkOrmXml2_0UiDefinition
extends AbstractOrmXmlResourceUiDefinition
@@ -68,8 +68,8 @@ public class EclipseLinkOrmXml2_0UiDefinition
return resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_2_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkOrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return OrmXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_1UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_1UiDefinition.java
index 582b4c1251..c6ac7d7062 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_1UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXml2_1UiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,10 +11,10 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkOrmResourceModelStructureProvider;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmTypeMappingUiDefinition;
@@ -33,10 +33,11 @@ import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToManyMappingUiDefiniti
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToOneMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmTransientMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmVersionMappingUiDefinition;
+import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmXmlUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.jpa2.details.orm.OrmElementCollectionMapping2_0UiDefinition;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-public class EclipseLinkOrmXml2_1UiDefinition extends AbstractOrmXmlResourceUiDefinition
+public class EclipseLinkOrmXml2_1UiDefinition
+ extends AbstractOrmXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new EclipseLinkOrmXml2_1UiDefinition();
@@ -67,8 +68,8 @@ public class EclipseLinkOrmXml2_1UiDefinition extends AbstractOrmXmlResourceUiDe
return resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_2_1_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkOrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return OrmXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXmlUiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXmlUiDefinition.java
index e22aa222dc..47da418dcb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXmlUiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/orm/EclipseLinkOrmXmlUiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,10 +11,10 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.JptJpaEclipseLinkCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkOrmResourceModelStructureProvider;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmTypeMappingUiDefinition;
@@ -33,7 +33,7 @@ import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToManyMappingUiDefiniti
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToOneMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmTransientMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmVersionMappingUiDefinition;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmXmlUiDefinition;
public class EclipseLinkOrmXmlUiDefinition
extends AbstractOrmXmlResourceUiDefinition
@@ -67,8 +67,8 @@ public class EclipseLinkOrmXmlUiDefinition
return resourceType.equals(JptJpaEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_1_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkOrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return OrmXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/EclipseLinkPersistenceXmlUiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/EclipseLinkPersistenceXmlUiDefinition.java
index 356cafc52b..c04baff4ff 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/EclipseLinkPersistenceXmlUiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/EclipseLinkPersistenceXmlUiDefinition.java
@@ -1,24 +1,26 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkPersistenceResourceModelStructureProvider;
+import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkPersistenceStructureItemContentProviderFactory;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.persistence.details.AbstractPersistenceXmlResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.persistence.details.PersistenceXmlUiFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceStructureItemLabelProviderFactory;
-public class EclipseLinkPersistenceXmlUiDefinition extends AbstractPersistenceXmlResourceUiDefinition
+public class EclipseLinkPersistenceXmlUiDefinition
+ extends AbstractPersistenceXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new EclipseLinkPersistenceXmlUiDefinition();
@@ -49,7 +51,13 @@ public class EclipseLinkPersistenceXmlUiDefinition extends AbstractPersistenceXm
return resourceType.equals(JptJpaCorePlugin.PERSISTENCE_XML_1_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkPersistenceResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return STRUCTURE_VIEW_FACTORY_PROVIDER;
}
+
+ public static final ItemTreeStateProviderFactoryProvider STRUCTURE_VIEW_FACTORY_PROVIDER =
+ new SimpleItemTreeStateProviderFactoryProvider(
+ EclipseLinkPersistenceStructureItemContentProviderFactory.instance(),
+ PersistenceStructureItemLabelProviderFactory.instance()
+ );
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java
index 66db507641..62d2f96c0c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2008, 2011 Oracle. All rights reserved.
+* Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -65,8 +65,8 @@ public class SharedCacheComposite extends Pane<CachingEntity>
// If the number of ListValueModel equals 1, that means the shared
// Cache properties is not set (partially selected), which means we
// want to see the default value appended to the text
- if (this.listHolder.size() == 1) {
- return (Boolean) this.listHolder.listIterator().next();
+ if (this.listModel.size() == 1) {
+ return (Boolean) this.listModel.listIterator().next();
}
return null;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/connection/CacheStatementsPropertiesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/connection/CacheStatementsPropertiesComposite.java
index 38d885d1a5..e96e1e9ead 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/connection/CacheStatementsPropertiesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/connection/CacheStatementsPropertiesComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2008, 2011 Oracle. All rights reserved.
+* Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -66,10 +66,10 @@ public class CacheStatementsPropertiesComposite<T extends Connection>
}
@Override
- protected void subjectChanged() {
- Object oldValue = this.getValue();
+ protected synchronized void subjectChanged() {
+ Boolean oldValue = this.getValue();
super.subjectChanged();
- Object newValue = this.getValue();
+ Boolean newValue = this.getValue();
// Make sure the default value is appended to the text
if (oldValue == newValue && newValue == null) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java
deleted file mode 100644
index 3eb475bd0f..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.eclipselink.ui.internal.persistencexml.details;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.jpa.core.context.JpaContextNode;
-import org.eclipse.jpt.jpa.core.context.MappingFile;
-import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericNavigatorItemContentProviderFactory;
-
-/**
- * EclipseLinkNavigatorItemContentProviderFactory
- */
-public class EclipseLinkNavigatorItemContentProviderFactory
- extends GenericNavigatorItemContentProviderFactory
- implements TreeItemContentProviderFactory
-{
- @Override
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider =
- (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider;
-
- if (item instanceof EclipseLinkPersistenceUnit) {
- return new EclipseLinkPersistenceUnitItemContentProvider(
- (EclipseLinkPersistenceUnit) item, treeContentAndLabelProvider);
- }
-
- return super.buildItemContentProvider(item, contentAndLabelProvider);
- }
-
-
- public static class EclipseLinkPersistenceUnitItemContentProvider
- extends PersistenceUnitItemContentProvider
- {
- public EclipseLinkPersistenceUnitItemContentProvider(
- EclipseLinkPersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistenceUnit, contentProvider);
- }
-
- @Override
- public EclipseLinkPersistenceUnit getModel() {
- return (EclipseLinkPersistenceUnit) super.getModel();
- }
-
- @Override
- protected CollectionValueModel<JpaContextNode> buildChildrenModel() {
- List<CollectionValueModel<? extends JpaContextNode>> list = new ArrayList<CollectionValueModel<? extends JpaContextNode>>();
- list.add(buildSpecifiedOrmXmlCvm());
- list.add(buildImpliedMappingFileCvm());
- list.add(buildImpliedEclipseLinkMappingFileCvm());
- list.add(buildPersistentTypeCvm());
- list.add(buildJarFileCvm());
- return new CompositeCollectionValueModel<CollectionValueModel<? extends JpaContextNode>, JpaContextNode>(list);
- }
-
- private CollectionValueModel<MappingFile> buildImpliedEclipseLinkMappingFileCvm() {
- return new PropertyCollectionValueModelAdapter<MappingFile>(
- new PropertyAspectAdapter<MappingFileRef, MappingFile>(
- new PropertyAspectAdapter<EclipseLinkPersistenceUnit, MappingFileRef>(
- EclipseLinkPersistenceUnit.IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY,
- getModel()) {
- @Override
- protected MappingFileRef buildValue_() {
- return subject.getImpliedEclipseLinkMappingFileRef();
- }
- },
- MappingFileRef.MAPPING_FILE_PROPERTY) {
- @Override
- protected MappingFile buildValue_() {
- return subject.getMappingFile();
- }
- }
- );
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemLabelProviderFactory.java
deleted file mode 100644
index e0807daa68..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemLabelProviderFactory.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.eclipselink.ui.internal.persistencexml.details;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericNavigatorItemLabelProviderFactory;
-
-/**
- * EclipseLinkNavigatorItemLabelProviderFactory
- */
-public class EclipseLinkNavigatorItemLabelProviderFactory
- extends GenericNavigatorItemLabelProviderFactory
- implements ItemLabelProviderFactory
-{
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkPersistenceUnitItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkPersistenceUnitItemContentProvider.java
new file mode 100644
index 0000000000..1163e50266
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistencexml/details/EclipseLinkPersistenceUnitItemContentProvider.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.persistencexml.details;
+
+import java.util.ArrayList;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.context.JpaContextNode;
+import org.eclipse.jpt.jpa.core.context.MappingFile;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
+import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkPersistenceUnitItemContentProvider.ImpliedEclipseLinkMappingFileRefModel;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistenceUnitItemContentProvider;
+
+/**
+ * Item content provider for project explorer.
+ */
+public class EclipseLinkPersistenceUnitItemContentProvider
+ extends PersistenceUnitItemContentProvider
+{
+ public EclipseLinkPersistenceUnitItemContentProvider(EclipseLinkPersistenceUnit persistenceUnit, Manager manager) {
+ super(persistenceUnit, manager);
+ }
+
+ @Override
+ protected void addChildrenModelsTo(ArrayList<CollectionValueModel<? extends JpaContextNode>> list) {
+ super.addChildrenModelsTo(list);
+ // add after the implied mapping file
+ list.add(3, this.buildImpliedEclipseLinkMappingFilesModel());
+ }
+
+
+ // ********** implied EclipseLink mapping file **********
+
+ /**
+ * No need to filter this list model as it will be empty if the wrapped
+ * property model is <code>null</code>.
+ */
+ protected CollectionValueModel<MappingFile> buildImpliedEclipseLinkMappingFilesModel() {
+ return new PropertyCollectionValueModelAdapter<MappingFile>(this.buildImpliedEclipseLinkMappingFileModel());
+ }
+
+ protected PropertyValueModel<MappingFile> buildImpliedEclipseLinkMappingFileModel() {
+ return new ImpliedEclipseLinkMappingFileModel(this.buildImpliedEclipseLinkMappingFileRefModel());
+ }
+
+ public static class ImpliedEclipseLinkMappingFileModel
+ extends PropertyAspectAdapter<MappingFileRef, MappingFile>
+ {
+ public ImpliedEclipseLinkMappingFileModel(PropertyValueModel<MappingFileRef> refModel) {
+ super(refModel, MappingFileRef.MAPPING_FILE_PROPERTY);
+ }
+ @Override
+ protected MappingFile buildValue_() {
+ return this.subject.getMappingFile();
+ }
+ }
+
+ protected PropertyValueModel<MappingFileRef> buildImpliedEclipseLinkMappingFileRefModel() {
+ return new ImpliedEclipseLinkMappingFileRefModel((EclipseLinkPersistenceUnit) this.item);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_1JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_1JpaPlatformUiFactory.java
index f067405e3e..723109ddd2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_1JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_1JpaPlatformUiFactory.java
@@ -1,9 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -12,9 +12,9 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
-public class EclipseLink1_1JpaPlatformUiFactory implements JpaPlatformUiFactory
+public class EclipseLink1_1JpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
-
/**
* Zero arg constructor for extension point
*/
@@ -24,8 +24,8 @@ public class EclipseLink1_1JpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLinkJpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink1_1JpaPlatformUiProvider.instance()
- );
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink1_1JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_2JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_2JpaPlatformUiFactory.java
index d749b1df11..d023a8197e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_2JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink1_2JpaPlatformUiFactory.java
@@ -1,9 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -12,9 +12,9 @@ package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
-public class EclipseLink1_2JpaPlatformUiFactory implements JpaPlatformUiFactory
+public class EclipseLink1_2JpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
-
/**
* Zero arg constructor for extension point
*/
@@ -24,8 +24,8 @@ public class EclipseLink1_2JpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLinkJpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink1_2JpaPlatformUiProvider.instance()
- );
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink1_2JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUi.java
index 546cfd520b..7db752d361 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUi.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUi.java
@@ -1,28 +1,29 @@
/*******************************************************************************
-* Copyright (c) 2009, 2011 Oracle. All rights reserved.
-* This program and the accompanying materials are made available under the
-* terms of the Eclipse Public License v1.0, which accompanies this distribution
-* and is available at http://www.eclipse.org/legal/epl-v10.html.
-*
-* Contributors:
-* Oracle - initial API and implementation
-*******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.wizards.EclipseLink2_0DDLGeneratorUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiProvider;
import org.eclipse.jpt.jpa.ui.internal.platform.base.BaseJpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
-public class EclipseLink2_0JpaPlatformUi extends BaseJpaPlatformUi
+public class EclipseLink2_0JpaPlatformUi
+ extends BaseJpaPlatformUi
{
public EclipseLink2_0JpaPlatformUi(
- JpaNavigatorProvider navigatorProvider,
- JpaPlatformUiProvider platformUiProvider) {
-
- super(navigatorProvider, platformUiProvider);
+ ItemTreeStateProviderFactoryProvider navigatorFactoryProvider,
+ JpaPlatformUiProvider platformUiProvider
+ ) {
+ super(navigatorFactoryProvider, platformUiProvider);
}
// ********** DDL generation **********
@@ -30,5 +31,4 @@ public class EclipseLink2_0JpaPlatformUi extends BaseJpaPlatformUi
public void generateDDL(JpaProject project, IStructuredSelection selection) {
EclipseLink2_0DDLGeneratorUi.generate(project);
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUiFactory.java
index 5223f78b26..8ca8cdbb9c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_0JpaPlatformUiFactory.java
@@ -1,23 +1,20 @@
/*******************************************************************************
-* Copyright (c) 2009, 2011 Oracle. All rights reserved.
-* This program and the accompanying materials are made available under the
-* terms of the Eclipse Public License v1.0, which accompanies this distribution
-* and is available at http://www.eclipse.org/legal/epl-v10.html.
-*
-* Contributors:
-* Oracle - initial API and implementation
-*******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
-/**
- * EclipseLink2_0JpaPlatformUiFactory
- */
-public class EclipseLink2_0JpaPlatformUiFactory implements JpaPlatformUiFactory
+public class EclipseLink2_0JpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
-
/**
* Zero arg constructor for extension point
*/
@@ -27,8 +24,8 @@ public class EclipseLink2_0JpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLink2_0JpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink2_0JpaPlatformUiProvider.instance()
- );
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink2_0JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_1JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_1JpaPlatformUiFactory.java
index 854c15ca58..be41d483ac 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_1JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_1JpaPlatformUiFactory.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
@@ -21,11 +20,12 @@ public class EclipseLink2_1JpaPlatformUiFactory
public EclipseLink2_1JpaPlatformUiFactory() {
super();
}
+
@Override
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLink2_0JpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink2_1JpaPlatformUiProvider.instance()
- );
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink2_1JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_2JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_2JpaPlatformUiFactory.java
index e22dc7b0ee..7007063acf 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_2JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_2JpaPlatformUiFactory.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
@@ -21,11 +20,12 @@ public class EclipseLink2_2JpaPlatformUiFactory
public EclipseLink2_2JpaPlatformUiFactory() {
super();
}
+
@Override
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLink2_0JpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink2_2JpaPlatformUiProvider.instance()
- );
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink2_2JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_3JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_3JpaPlatformUiFactory.java
index 02b0751109..a0271e5b14 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_3JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_3JpaPlatformUiFactory.java
@@ -1,32 +1,31 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-
public class EclipseLink2_3JpaPlatformUiFactory
- extends EclipseLink2_0JpaPlatformUiFactory {
-
+ extends EclipseLink2_0JpaPlatformUiFactory
+{
/**
* Zero arg constructor for extension point
*/
public EclipseLink2_3JpaPlatformUiFactory() {
super();
}
-
-
+
@Override
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLink2_0JpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink2_3JpaPlatformUiProvider.instance());
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink2_3JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_4JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_4JpaPlatformUiFactory.java
index 92526cd664..742d891617 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_4JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLink2_4JpaPlatformUiFactory.java
@@ -1,20 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-
public class EclipseLink2_4JpaPlatformUiFactory
- extends EclipseLink2_0JpaPlatformUiFactory {
-
+ extends EclipseLink2_0JpaPlatformUiFactory
+{
/**
* Zero arg constructor for extension point
*/
@@ -22,11 +21,11 @@ public class EclipseLink2_4JpaPlatformUiFactory
super();
}
-
@Override
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLink2_0JpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLink2_4JpaPlatformUiProvider.instance());
+ EclipseLinkJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLink2_4JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java
index 067df3d6ca..a6a66a4026 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,20 +10,20 @@
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.ddlgen.EclipseLinkDDLGeneratorUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiProvider;
import org.eclipse.jpt.jpa.ui.internal.platform.base.BaseJpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
public class EclipseLinkJpaPlatformUi
extends BaseJpaPlatformUi
{
public EclipseLinkJpaPlatformUi(
- JpaNavigatorProvider navigatorProvider,
- JpaPlatformUiProvider platformUiProvider)
- {
- super(navigatorProvider, platformUiProvider);
+ ItemTreeStateProviderFactoryProvider navigatorFactoryProvider,
+ JpaPlatformUiProvider platformUiProvider
+ ) {
+ super(navigatorFactoryProvider, platformUiProvider);
}
// ********** DDL generation **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUiFactory.java
index b82e236966..98c0a55f33 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUiFactory.java
@@ -1,20 +1,23 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericNavigatorItemLabelProviderFactory;
-public class EclipseLinkJpaPlatformUiFactory implements JpaPlatformUiFactory
+public class EclipseLinkJpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
-
/**
* Zero arg constructor for extension point
*/
@@ -24,8 +27,14 @@ public class EclipseLinkJpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new EclipseLinkJpaPlatformUi(
- new EclipseLinkNavigatorProvider(),
- EclipseLinkJpaPlatformUiProvider.instance()
- );
+ NAVIGATOR_FACTORY_PROVIDER,
+ EclipseLinkJpaPlatformUiProvider.instance()
+ );
}
+
+ public static final ItemTreeStateProviderFactoryProvider NAVIGATOR_FACTORY_PROVIDER =
+ new SimpleItemTreeStateProviderFactoryProvider(
+ EclipseLinkNavigatorItemContentProviderFactory.instance(),
+ GenericNavigatorItemLabelProviderFactory.instance()
+ );
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorItemContentProviderFactory.java
new file mode 100644
index 0000000000..bdc48a5057
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorItemContentProviderFactory.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
+
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
+import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistencexml.details.EclipseLinkPersistenceUnitItemContentProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericNavigatorItemContentProviderFactory;
+
+public class EclipseLinkNavigatorItemContentProviderFactory
+ extends GenericNavigatorItemContentProviderFactory
+{
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new EclipseLinkNavigatorItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected EclipseLinkNavigatorItemContentProviderFactory() {
+ super();
+ }
+
+ @Override
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof EclipseLinkPersistenceUnit) {
+ return new EclipseLinkPersistenceUnitItemContentProvider((EclipseLinkPersistenceUnit) item, manager);
+ }
+ return super.buildProvider(item, manager);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorProvider.java
deleted file mode 100644
index c4c575831e..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/platform/EclipseLinkNavigatorProvider.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.eclipselink.ui.internal.platform;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistencexml.details.EclipseLinkNavigatorItemContentProviderFactory;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistencexml.details.EclipseLinkNavigatorItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
-
-/**
- * EclipseLinkNavigatorProvider
- */
-public class EclipseLinkNavigatorProvider implements JpaNavigatorProvider
-{
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new EclipseLinkNavigatorItemLabelProviderFactory();
- }
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new EclipseLinkNavigatorItemContentProviderFactory();
- }
-
- public void dispose() {
-
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java
deleted file mode 100644
index 7d167938b2..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.eclipselink.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.OrmItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.OrmItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-
-public class EclipseLinkOrmResourceModelStructureProvider
- implements JpaStructureProvider
-{
- // singleton
- private static final JpaStructureProvider INSTANCE = new EclipseLinkOrmResourceModelStructureProvider();
-
-
- /**
- * Return the singleton
- */
- public static JpaStructureProvider instance() {
- return INSTANCE;
- }
-
-
- /**
- * Enforce singleton usage
- */
- private EclipseLinkOrmResourceModelStructureProvider() {
- super();
- }
-
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new OrmItemContentProviderFactory();
- }
-
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new OrmItemLabelProviderFactory();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceItemContentProviderFactory.java
deleted file mode 100644
index 38f730a9b0..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceItemContentProviderFactory.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.eclipselink.ui.internal.structure;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
-import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
-import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceItemContentProviderFactory;
-
-public class EclipseLinkPersistenceItemContentProviderFactory
- extends PersistenceItemContentProviderFactory
-{
- @Override
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider;
- if (item instanceof EclipseLinkPersistenceUnit) {
- return new EclipseLinkPersistenceUnitItemContentProvider((EclipseLinkPersistenceUnit) item, treeContentProvider);
- }
- return super.buildItemContentProvider(item, contentAndLabelProvider);
- }
-
-
- public static class EclipseLinkPersistenceUnitItemContentProvider
- extends PersistenceUnitItemContentProvider
- {
- public EclipseLinkPersistenceUnitItemContentProvider(
- EclipseLinkPersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistenceUnit, contentProvider);
- }
-
- @Override
- public EclipseLinkPersistenceUnit getModel() {
- return (EclipseLinkPersistenceUnit) super.getModel();
- }
-
- @Override
- protected CollectionValueModel<JpaStructureNode> buildChildrenModel() {
- CollectionValueModel<MappingFileRef> specifiedMappingFileCvm =
- new ListCollectionValueModelAdapter<MappingFileRef>(
- new ListAspectAdapter<PersistenceUnit, MappingFileRef>(
- PersistenceUnit.SPECIFIED_MAPPING_FILE_REFS_LIST,
- getModel()) {
- @Override
- protected ListIterable<MappingFileRef> getListIterable() {
- return subject.getSpecifiedMappingFileRefs();
- }
- @Override
- protected int size_() {
- return subject.getSpecifiedMappingFileRefsSize();
- }
- });
-
- CollectionValueModel<MappingFileRef> impliedMappingFileCvm =
- new PropertyCollectionValueModelAdapter<MappingFileRef>(
- new PropertyAspectAdapter<PersistenceUnit, MappingFileRef>(
- PersistenceUnit.IMPLIED_MAPPING_FILE_REF_PROPERTY,
- getModel()) {
- @Override
- protected MappingFileRef buildValue_() {
- return subject.getImpliedMappingFileRef();
- }
- }
- );
- CollectionValueModel<MappingFileRef> impliedEclipseLinkMappingFileCvm =
- new PropertyCollectionValueModelAdapter<MappingFileRef>(
- new PropertyAspectAdapter<EclipseLinkPersistenceUnit, MappingFileRef>(
- EclipseLinkPersistenceUnit.IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY,
- getModel()) {
- @Override
- protected MappingFileRef buildValue_() {
- return subject.getImpliedEclipseLinkMappingFileRef();
- }
- }
- );
- CollectionValueModel<ClassRef> specifiedClassCvm =
- new ListCollectionValueModelAdapter<ClassRef>(
- new ListAspectAdapter<PersistenceUnit, ClassRef>(
- PersistenceUnit.SPECIFIED_CLASS_REFS_LIST,
- getModel()) {
- @Override
- protected ListIterable<ClassRef> getListIterable() {
- return subject.getSpecifiedClassRefs();
- }
- @Override
- protected int size_() {
- return subject.getSpecifiedClassRefsSize();
- }
- });
- CollectionValueModel<ClassRef> impliedClassCvm =
- new CollectionAspectAdapter<PersistenceUnit, ClassRef>(
- PersistenceUnit.IMPLIED_CLASS_REFS_COLLECTION,
- getModel()) {
- @Override
- protected Iterable<ClassRef> getIterable() {
- return subject.getImpliedClassRefs();
- }
- @Override
- protected int size_() {
- return subject.getImpliedClassRefsSize();
- }
- };
- List<CollectionValueModel<? extends JpaStructureNode>> list = new ArrayList<CollectionValueModel<? extends JpaStructureNode>>(4);
- list.add(specifiedMappingFileCvm);
- list.add(impliedMappingFileCvm);
- list.add(impliedEclipseLinkMappingFileCvm);
- list.add(specifiedClassCvm);
- list.add(impliedClassCvm);
-
- return new CompositeCollectionValueModel<CollectionValueModel<? extends JpaStructureNode>, JpaStructureNode>(list);
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java
deleted file mode 100644
index 7fc3e6dafe..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.eclipselink.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-
-public class EclipseLinkPersistenceResourceModelStructureProvider
- implements JpaStructureProvider
-{
- // singleton
- private static final JpaStructureProvider INSTANCE = new EclipseLinkPersistenceResourceModelStructureProvider();
-
-
- /**
- * Return the singleton
- */
- public static JpaStructureProvider instance() {
- return INSTANCE;
- }
-
-
- /**
- * Enforce singleton usage
- */
- private EclipseLinkPersistenceResourceModelStructureProvider() {
- super();
- }
-
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new EclipseLinkPersistenceItemContentProviderFactory();
- }
-
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new PersistenceItemLabelProviderFactory();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceStructureItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceStructureItemContentProviderFactory.java
new file mode 100644
index 0000000000..8d6ce1855c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceStructureItemContentProviderFactory.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceStructureItemContentProviderFactory;
+
+public class EclipseLinkPersistenceStructureItemContentProviderFactory
+ extends PersistenceStructureItemContentProviderFactory
+{
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new EclipseLinkPersistenceStructureItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected EclipseLinkPersistenceStructureItemContentProviderFactory() {
+ super();
+ }
+
+ @Override
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof EclipseLinkPersistenceUnit) {
+ return new EclipseLinkPersistenceUnitItemContentProvider((EclipseLinkPersistenceUnit) item, manager);
+ }
+ return super.buildProvider(item, manager);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceUnitItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceUnitItemContentProvider.java
new file mode 100644
index 0000000000..ea9cbd8924
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/structure/EclipseLinkPersistenceUnitItemContentProvider.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.eclipselink.ui.internal.structure;
+
+import java.util.ArrayList;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.EclipseLinkPersistenceUnit;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceUnitItemContentProvider;
+
+/**
+ * Item content provider for structure view.
+ */
+public class EclipseLinkPersistenceUnitItemContentProvider
+ extends PersistenceUnitItemContentProvider
+{
+ public EclipseLinkPersistenceUnitItemContentProvider(EclipseLinkPersistenceUnit persistenceUnit, Manager manager) {
+ super(persistenceUnit, manager);
+ }
+ @Override
+ protected void addChildrenModelsTo(ArrayList<ListValueModel<? extends JpaStructureNode>> list) {
+ super.addChildrenModelsTo(list);
+ // add after the implied mapping file
+ list.add(3, this.buildImpliedEclipseLinkMappingFileRefsModel());
+ }
+
+ protected ListValueModel<MappingFileRef> buildImpliedEclipseLinkMappingFileRefsModel() {
+ return new PropertyListValueModelAdapter<MappingFileRef>(this.buildImpliedEclipseLinkMappingFileRefModel());
+ }
+
+ protected PropertyValueModel<MappingFileRef> buildImpliedEclipseLinkMappingFileRefModel() {
+ return new ImpliedEclipseLinkMappingFileRefModel((EclipseLinkPersistenceUnit) this.item);
+ }
+
+ public static class ImpliedEclipseLinkMappingFileRefModel
+ extends PropertyAspectAdapter<EclipseLinkPersistenceUnit, MappingFileRef>
+ {
+ public ImpliedEclipseLinkMappingFileRefModel(EclipseLinkPersistenceUnit persistenceUnit) {
+ super(EclipseLinkPersistenceUnit.IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY, persistenceUnit);
+ }
+ @Override
+ protected MappingFileRef buildValue_() {
+ return this.subject.getImpliedEclipseLinkMappingFileRef();
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/v2_0/persistence/EclipseLinkPersistenceXml2_0UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/v2_0/persistence/EclipseLinkPersistenceXml2_0UiDefinition.java
index 90b226fb38..df03c31cdf 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/v2_0/persistence/EclipseLinkPersistenceXml2_0UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/v2_0/persistence/EclipseLinkPersistenceXml2_0UiDefinition.java
@@ -1,24 +1,24 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.ui.internal.v2_0.persistence;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.eclipselink.ui.internal.structure.EclipseLinkPersistenceResourceModelStructureProvider;
+import org.eclipse.jpt.jpa.eclipselink.ui.internal.persistence.EclipseLinkPersistenceXmlUiDefinition;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.persistence.details.AbstractPersistenceXmlResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.persistence.details.PersistenceXmlUiFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-public class EclipseLinkPersistenceXml2_0UiDefinition extends AbstractPersistenceXmlResourceUiDefinition
+public class EclipseLinkPersistenceXml2_0UiDefinition
+ extends AbstractPersistenceXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new EclipseLinkPersistenceXml2_0UiDefinition();
@@ -49,7 +49,7 @@ public class EclipseLinkPersistenceXml2_0UiDefinition extends AbstractPersistenc
return resourceType.equals(JptJpaCorePlugin.PERSISTENCE_XML_2_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return EclipseLinkPersistenceResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return EclipseLinkPersistenceXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java
index 9dba602a26..99905e1ebb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/PackageGenerator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -139,30 +139,26 @@ public class PackageGenerator {
return;
}
- resource.modify(new Runnable() {
- public void run() {
- Persistence persistence = PackageGenerator.this.jpaProject.getRootContextNode().getPersistenceXml().getPersistence();
- if (persistence == null) {
- // invalid content, do not attempt to update
- return;
- }
- PersistenceUnit persistenceUnit;
- // create a persistence unit if one doesn't already exist
- if (persistence.getPersistenceUnitsSize() == 0) {
- persistenceUnit = persistence.addPersistenceUnit();
- persistenceUnit.setName(PackageGenerator.this.jpaProject.getName());
- } else {
- // we only support one persistence unit - take the first one
- persistenceUnit = persistence.getPersistenceUnits().iterator().next();
- }
- for (Iterator<String> stream = genClasses.iterator(); stream.hasNext();) {
- String className = stream.next();
- if (CollectionTools.isEmpty(persistenceUnit.getMappingFileRefsContaining(className)) && !persistenceUnit.specifiesPersistentType(className)) {
- persistenceUnit.addSpecifiedClassRef(className);
- }
- }
+ Persistence persistence = this.jpaProject.getRootContextNode().getPersistenceXml().getPersistence();
+ if (persistence == null) {
+ // invalid content, do not attempt to update
+ return;
+ }
+ PersistenceUnit persistenceUnit;
+ // create a persistence unit if one doesn't already exist
+ if (persistence.getPersistenceUnitsSize() == 0) {
+ persistenceUnit = persistence.addPersistenceUnit();
+ persistenceUnit.setName(PackageGenerator.this.jpaProject.getName());
+ } else {
+ // we only support one persistence unit - take the first one
+ persistenceUnit = persistence.getPersistenceUnit(0);
+ }
+ for (String className : genClasses) {
+ if (CollectionTools.isEmpty(persistenceUnit.getMappingFileRefsContaining(className)) && !persistenceUnit.specifiesPersistentType(className)) {
+ persistenceUnit.addSpecifiedClassRef(className);
}
- });
+ }
+ resource.save();
}
private File prepareTemplatesFolder() throws IOException, Exception,
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF
index 18c3ab1397..629f0b1fb5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/META-INF/MANIFEST.MF
@@ -77,11 +77,11 @@ Export-Package: org.eclipse.jpt.jpa.ui,
org.eclipse.jpt.jpa.ui.internal.platform.base;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.platform.generic;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.preferences;x-internal:=true,
+ org.eclipse.jpt.jpa.ui.internal.prefs;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.properties;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.selection;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.structure;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.views;x-internal:=true,
- org.eclipse.jpt.jpa.ui.internal.views.structure;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.wizards;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.wizards.entity;x-internal:=true,
org.eclipse.jpt.jpa.ui.internal.wizards.entity.data.model;x-internal:=true,
@@ -92,6 +92,5 @@ Export-Package: org.eclipse.jpt.jpa.ui,
org.eclipse.jpt.jpa.ui.internal.wizards.proj.model;x-internal:=true,
org.eclipse.jpt.jpa.ui.jpa2.details.java,
org.eclipse.jpt.jpa.ui.jpa2.details.orm,
- org.eclipse.jpt.jpa.ui.navigator,
- org.eclipse.jpt.jpa.ui.structure
+ org.eclipse.jpt.jpa.ui.selection
Import-Package: com.ibm.icu.text;version="4.0.1"
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
index 94d10fced7..c83601910a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
- Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ Copyright (c) 2007, 2012 Oracle. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0, which accompanies this distribution
and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,12 +12,16 @@
<plugin>
- <extension-point
- id="jpaPlatformUis"
- name="%JPA_PLATFORM_UI"
+ <!-- ***** extension points ***** -->
+
+ <extension-point
+ id="jpaPlatformUis"
+ name="%JPA_PLATFORM_UI"
schema="schema/jpaPlatformUis.exsd"/>
+ <!-- ***** expressions ***** -->
+
<extension
point="org.eclipse.core.expressions.definitions">
@@ -35,29 +39,99 @@
</definition>
</extension>
-
-
+
+
+ <!-- ***** adapters ***** -->
+
<extension
point="org.eclipse.core.runtime.adapters">
+ <!-- JpaPlatform -> JpaPlatformUi -->
<factory
- adaptableType="org.eclipse.ui.IWorkbenchPart"
- class="org.eclipse.jpt.jpa.ui.internal.selection.WorkbenchPartAdapterFactory">
- <adapter type="org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionParticipant"/>
+ adaptableType="org.eclipse.jpt.jpa.core.JpaPlatform"
+ class="org.eclipse.jpt.jpa.ui.internal.JpaPlatformAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.JpaPlatformUi"/>
</factory>
-
+
+ <!-- IProject
+ -> JpaProjectModel
+ -> JpaRootContextNodeModel
+ -->
<factory
- adaptableType="org.eclipse.ui.IEditorPart"
- class="org.eclipse.jpt.jpa.ui.internal.EditorPartAdapterFactory">
- <adapter type="org.eclipse.jpt.jpa.core.JpaFile"/>
+ adaptableType="org.eclipse.core.resources.IProject"
+ class="org.eclipse.jpt.jpa.ui.internal.ProjectAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.JpaProjectModel"/>
+ <adapter type="org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel"/>
</factory>
+
+ <!-- IFile -> JpaFileModel -->
+ <factory
+ adaptableType="org.eclipse.core.resources.IFile"
+ class="org.eclipse.jpt.jpa.ui.internal.FileAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.JpaFileModel"/>
+ </factory>
+
+ <!-- JpaFile -> JpaStructureViewFactoryProvider -->
+ <factory
+ adaptableType="org.eclipse.jpt.jpa.core.JpaFile"
+ class="org.eclipse.jpt.jpa.ui.internal.JpaFileAdapterFactory">
+ <adapter type="org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider"/>
+ </factory>
+
+ <!-- JpaStructureNode -> JpaDetailsPageManager.Factory -->
+ <factory
+ adaptableType="org.eclipse.jpt.jpa.core.JpaStructureNode"
+ class="org.eclipse.jpt.jpa.ui.internal.JpaStructureNodeAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager$Factory"/>
+ </factory>
+
+ <!-- IWorkbench -> JpaSelectionManager -->
+ <factory
+ adaptableType="org.eclipse.ui.IWorkbench"
+ class="org.eclipse.jpt.jpa.ui.internal.selection.WorkbenchAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager"/>
+ </factory>
+
+ <!-- IWorkbenchWindow -> JpaSelectionManager -->
+ <factory
+ adaptableType="org.eclipse.ui.IWorkbenchWindow"
+ class="org.eclipse.jpt.jpa.ui.internal.selection.WorkbenchWindowAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager"/>
+ </factory>
+
+ <!-- ITextEditor -> JpaEditorManager -->
+ <factory
+ adaptableType="org.eclipse.ui.texteditor.ITextEditor"
+ class="org.eclipse.jpt.jpa.ui.internal.selection.TextEditorAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.selection.JpaEditorManager"/>
+ </factory>
+
+ <!-- IViewPart -> JpaViewManager.PageManager -->
+ <factory
+ adaptableType="org.eclipse.ui.IViewPart"
+ class="org.eclipse.jpt.jpa.ui.internal.selection.ViewPartAdapterFactory">
+ <adapter type="org.eclipse.jpt.jpa.ui.selection.JpaViewManager$PageManager"/>
+ </factory>
+
+ </extension>
+
+
+ <!-- ***** property testers ***** -->
+
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+
+ <propertyTester
+ id="org.eclipse.jpt.jpa.ui.propertyTester.jptResourceModel"
+ type="org.eclipse.jpt.common.core.JptResourceModel"
+ namespace="org.eclipse.jpt.jpa.ui"
+ properties="isLatestSupportedVersion, isNotLatestSupportedVersion"
+ class="org.eclipse.jpt.jpa.ui.internal.JptResourceModelPropertyTester"/>
</extension>
+
-
-<!-- =================================================================================== -->
-<!-- Extension: Java Completion Proposal Computer -->
-<!-- =================================================================================== -->
+ <!-- ***** Java/XML completion proposal computers ***** -->
<extension
point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
@@ -74,20 +148,12 @@
<extension
point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
- id="jpaProposalCategory"
- name="%JpaProposalCategory">
- <proposalCategory
- icon="$nl$/icons/full/eview16/jpa_perspective.gif"/>
- </extension>
-
- <extension
- point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
id="JpaJpqlCompletionProposalComputer">
<javaCompletionProposalComputer
- activate="true"
- categoryId="org.eclipse.jpt.jpa.ui.jpaProposalCategory"
- class="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlJavaCompletionProposalComputer">
+ class="org.eclipse.jpt.jpa.ui.internal.jpql.JpaJpqlJavaCompletionProposalComputer"
+ activate="true"
+ categoryId="org.eclipse.jpt.jpa.ui.jpaProposalCategory">
<partition type="__dftl_partition_content_type"/>
<partition type="__java_string"/>
</javaCompletionProposalComputer>
@@ -95,8 +161,8 @@
</extension>
<extension
- id="org.eclipse.jpt.jpa.ui.xml.jpqlCompletionProposal"
- point="org.eclipse.wst.sse.ui.completionProposal">
+ point="org.eclipse.wst.sse.ui.completionProposal"
+ id="org.eclipse.jpt.jpa.ui.xml.jpqlCompletionProposal">
<proposalCategory
icon="$nl$/icons/full/eview16/jpa_perspective.gif"
@@ -116,6 +182,18 @@
</extension>
+ <extension
+ point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
+ id="jpaProposalCategory"
+ name="%JpaProposalCategory">
+
+ <proposalCategory
+ icon="$nl$/icons/full/eview16/jpa_perspective.gif"/>
+
+ </extension>
+
+
+ <!-- ***** Dali extensions (eat our own dogfood) ***** -->
<extension
point="org.eclipse.jpt.jpa.ui.jpaPlatformUis">
@@ -133,6 +211,8 @@
</extension>
+ <!-- ***** action sets ***** -->
+
<extension
point="org.eclipse.ui.actionSets">
@@ -154,6 +234,8 @@
</extension>
+ <!-- ***** commands ***** -->
+
<extension
point="org.eclipse.ui.commands">
@@ -232,9 +314,7 @@
</extension>
-<!-- =================================================================================== -->
-<!-- Extension: Persistence Editor -->
-<!-- =================================================================================== -->
+ <!-- ***** persitence.xml editor ***** -->
<extension
point="org.eclipse.ui.editors">
@@ -250,9 +330,11 @@
</editor>
</extension>
-
-
- <extension
+
+
+ <!-- ***** handlers ***** -->
+
+ <extension
point="org.eclipse.ui.handlers">
<handler
@@ -261,17 +343,11 @@
<enabledWhen>
<iterate>
<or>
- <adapt
- type="org.eclipse.jpt.jpa.core.context.XmlFile">
- <test
- property="org.eclipse.jpt.jpa.core.isLatestSupportedVersion"
- value="false"/>
+ <adapt type="org.eclipse.jpt.jpa.core.context.XmlFile">
+ <test property="org.eclipse.jpt.jpa.core.isNotLatestSupportedVersion"/>
</adapt>
- <adapt
- type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource">
- <test
- property="org.eclipse.jpt.jpa.core.isLatestSupportedVersion"
- value="false"/>
+ <adapt type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource">
+ <test property="org.eclipse.jpt.jpa.ui.isNotLatestSupportedVersion"/>
</adapt>
</or>
</iterate>
@@ -323,8 +399,8 @@
<iterate>
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="true"/>
- <test property="org.eclipse.jpt.jpa.core.isMapped" value="true"/>
+ <test property="org.eclipse.jpt.jpa.core.isVirtual"/>
+ <test property="org.eclipse.jpt.jpa.core.isMapped"/>
</and>
</iterate>
</enabledWhen>
@@ -342,7 +418,7 @@
<iterate>
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="true"/>
+ <test property="org.eclipse.jpt.jpa.core.isVirtual"/>
</and>
</iterate>
</enabledWhen>
@@ -360,7 +436,7 @@
<iterate>
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="false"/>
+ <test property="org.eclipse.jpt.jpa.core.isNotVirtual"/>
</and>
</iterate>
</enabledWhen>
@@ -391,7 +467,7 @@
<iterate>
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="false"/>
+ <test property="org.eclipse.jpt.jpa.core.isNotVirtual"/>
</and>
</iterate>
</enabledWhen>
@@ -400,6 +476,8 @@
</extension>
+ <!-- ***** menus ***** -->
+
<extension
point="org.eclipse.ui.menus">
@@ -409,7 +487,8 @@
<!-- "JPA Tools" submenu for
- anything that adapts to JpaXmlResource (IFile objects, mostly)
- - anything that adapts to IProject and has a JPA facet -->
+ - anything that adapts to IProject and has a JPA facet
+ -->
<menu
id="org.eclipse.jpt.jpa.ui.menu.JpaTools"
label="%jpaMenuName">
@@ -418,23 +497,19 @@
variable="selection">
<iterate ifEmpty="false">
<or>
- <adapt
- type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource"/>
- <adapt
- type="org.eclipse.core.resources.IProject">
+ <adapt type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource"/>
+ <adapt type="org.eclipse.core.resources.IProject">
<test
- property="org.eclipse.wst.common.project.facet.core.projectFacet"
+ property="org.eclipse.wst.common.project.facet.core.projectFacet"
value="jpt.jpa"/>
</adapt>
<and>
- <adapt
- type="org.eclipse.core.resources.IResource">
+ <adapt type="org.eclipse.core.resources.IResource">
<test
- property="org.eclipse.wst.common.project.facet.core.projectFacet"
+ property="org.eclipse.wst.common.project.facet.core.projectFacet"
value="jpt.jpa"/>
</adapt>
- <adapt
- type="org.eclipse.jdt.core.IJavaElement"/>
+ <adapt type="org.eclipse.jdt.core.IJavaElement"/>
</and>
</or>
</iterate>
@@ -449,11 +524,8 @@
<with
variable="selection">
<iterate ifEmpty="false">
- <adapt
- type="org.eclipse.jpt.jpa.core.context.XmlFile">
- <test
- property="org.eclipse.jpt.jpa.core.isLatestSupportedVersion"
- value="false"/>
+ <adapt type="org.eclipse.jpt.jpa.core.context.XmlFile">
+ <test property="org.eclipse.jpt.jpa.core.isNotLatestSupportedVersion"/>
</adapt>
</iterate>
</with>
@@ -470,11 +542,8 @@
<with
variable="selection">
<iterate ifEmpty="false">
- <adapt
- type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource">
- <test
- property="org.eclipse.jpt.jpa.core.isLatestSupportedVersion"
- value="false"/>
+ <adapt type="org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource">
+ <test property="org.eclipse.jpt.jpa.ui.isNotLatestSupportedVersion"/>
</adapt>
</iterate>
</with>
@@ -510,6 +579,7 @@
<!-- contributions to objects in the JPA structure view -->
<menuContribution
locationURI="popup:org.eclipse.jpt.ui.jpaStructureView">
+
<command
commandId="org.eclipse.jpt.jpa.ui.entityMappingsAddPersistentClass">
<visibleWhen>
@@ -540,7 +610,7 @@
<iterate ifEmpty="false">
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="true"/>
+ <test property="org.eclipse.jpt.jpa.core.isVirtual"/>
</and>
</iterate>
</with>
@@ -554,7 +624,7 @@
<iterate ifEmpty="false">
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="true"/>
+ <test property="org.eclipse.jpt.jpa.core.isVirtual"/>
</and>
</iterate>
</with>
@@ -568,7 +638,7 @@
<iterate ifEmpty="false">
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="false"/>
+ <test property="org.eclipse.jpt.jpa.core.isNotVirtual"/>
</and>
</iterate>
</with>
@@ -603,7 +673,7 @@
<iterate ifEmpty="false">
<and>
<instanceof value="org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute"/>
- <test property="org.eclipse.jpt.jpa.core.isVirtual" value="false"/>
+ <test property="org.eclipse.jpt.jpa.core.isNotVirtual"/>
</and>
</iterate>
</with>
@@ -619,6 +689,8 @@
</extension>
+ <!-- ***** Project Explorer contribution ***** -->
+
<extension
point="org.eclipse.ui.navigator.viewer">
@@ -632,6 +704,8 @@
</extension>
+ <!-- ***** navigator content ***** -->
+
<extension
point="org.eclipse.ui.navigator.navigatorContent">
@@ -643,26 +717,23 @@
icon="icons/full/obj16/jpa-content.gif"
activeByDefault="true"
contentProvider="org.eclipse.jpt.jpa.ui.internal.navigator.JpaNavigatorContentProvider"
- labelProvider="org.eclipse.jpt.jpa.ui.internal.navigator.JpaNavigatorLabelProvider">
+ labelProvider="org.eclipse.jpt.common.ui.internal.jface.NavigatorLabelProvider">
<triggerPoints>
<or>
- <instanceof
- value="org.eclipse.jpt.jpa.core.context.JpaContextNode"/>
- <and>
- <adapt type="org.eclipse.core.resources.IProject">
- <test
- forcePluginActivation="true"
- property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa" />
- </adapt>
- </and>
+ <instanceof value="org.eclipse.jpt.jpa.core.context.JpaContextNode"/>
+ <instanceof value="org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel"/>
+ <adapt type="org.eclipse.core.resources.IProject">
+ <test
+ property="org.eclipse.wst.common.project.facet.core.projectFacet"
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
+ </adapt>
</or>
</triggerPoints>
<possibleChildren>
- <instanceof
- value="org.eclipse.jpt.jpa.core.context.JpaContextNode"/>
+ <instanceof value="org.eclipse.jpt.jpa.core.context.JpaContextNode"/>
</possibleChildren>
<actionProvider
@@ -670,8 +741,7 @@
id="org.eclipse.jpt.jpa.ui.jpaActionProvider">
<enablement>
<and>
- <instanceof
- value="org.eclipse.jpt.jpa.core.context.JpaContextNode"/>
+ <instanceof value="org.eclipse.jpt.jpa.core.context.JpaContextNode"/>
</and>
</enablement>
</actionProvider>
@@ -683,18 +753,15 @@
<enablement>
<and>
<or>
- <instanceof
- value="org.eclipse.core.resources.IProject"/>
- <instanceof
- value="org.eclipse.jdt.core.IPackageFragment"/>
- <instanceof
- value="org.eclipse.jdt.core.IPackageFragmentRoot"/>
+ <instanceof value="org.eclipse.core.resources.IProject"/>
+ <instanceof value="org.eclipse.jdt.core.IPackageFragment"/>
+ <instanceof value="org.eclipse.jdt.core.IPackageFragmentRoot"/>
</or>
<adapt type="org.eclipse.core.resources.IResource">
<test
- forcePluginActivation="true"
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa" />
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
</adapt>
</and>
</enablement>
@@ -714,20 +781,18 @@
</or>
<adapt type="org.eclipse.core.resources.IResource">
<test
- forcePluginActivation="true"
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa" />
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
</adapt>
</and>
</enablement>
</commonWizard>
<!--
-
<commonSorter
id="org.eclipse.jst.j2ee.navigator.internal.J2EEViewerSorter"
class="org.eclipse.jst.j2ee.navigator.internal.J2EEViewerSorter" />
-
-->
<commonWizard
@@ -737,18 +802,15 @@
<enablement>
<and>
<or>
- <instanceof
- value="org.eclipse.core.resources.IProject"/>
- <instanceof
- value="org.eclipse.jdt.core.IPackageFragment"/>
- <instanceof
- value="org.eclipse.jdt.core.IPackageFragmentRoot"/>
+ <instanceof value="org.eclipse.core.resources.IProject"/>
+ <instanceof value="org.eclipse.jdt.core.IPackageFragment"/>
+ <instanceof value="org.eclipse.jdt.core.IPackageFragmentRoot"/>
</or>
<adapt type="org.eclipse.core.resources.IResource">
<test
- forcePluginActivation="true"
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa" />
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
</adapt>
</and>
</enablement>
@@ -759,6 +821,8 @@
</extension>
+ <!-- ***** "New Dialog" wizards ***** -->
+
<extension
point="org.eclipse.ui.newWizards">
@@ -818,10 +882,8 @@
</extension>
-<!-- =================================================================================== -->
-<!-- Extension: Persistence Perspective -->
-<!-- =================================================================================== -->
-
+ <!-- ***** JPA Perspective ***** -->
+
<extension
point="org.eclipse.ui.perspectives">
@@ -832,6 +894,7 @@
name="%jpaPerspective">
<description>%jpaPerspectiveDescription</description>
</perspective>
+
</extension>
@@ -889,6 +952,8 @@
</extension>
+ <!-- ***** pop-up menus ***** -->
+
<extension
point="org.eclipse.ui.popupMenus">
@@ -897,8 +962,11 @@
objectClass="org.eclipse.core.resources.IProject"
adaptable="true">
+ <!-- ignore the warning - see bug 247250 -->
<enablement>
- <test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jpt.jpa"/>
+ <test
+ property="org.eclipse.wst.common.project.facet.core.projectFacet"
+ value="jpt.jpa"/>
</enablement>
<action
@@ -937,6 +1005,7 @@
</or>
</enablement>
</action>
+
</objectContribution>
<objectContribution
@@ -967,6 +1036,8 @@
</extension>
+ <!-- ***** preferences ***** -->
+
<extension
point="org.eclipse.ui.preferencePages">
@@ -990,7 +1061,20 @@
</extension>
+
+ <extension
+ point="org.eclipse.core.runtime.preferences"
+ id="org.eclipse.jpt.jpa.ui">
+
+ <initializer
+ class="org.eclipse.jpt.jpa.ui.internal.prefs.JpaUiPreferenceInitializer">
+ </initializer>
+
+ </extension>
+
+ <!-- ***** JPA project properties pages ***** -->
+
<extension
point="org.eclipse.ui.propertyPages">
@@ -1001,9 +1085,9 @@
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
<test
- forcePluginActivation="true"
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa"/>
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
</adapt>
</enabledWhen>
</page>
@@ -1016,9 +1100,9 @@
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
<test
- forcePluginActivation="true"
property="org.eclipse.wst.common.project.facet.core.projectFacet"
- value="jpt.jpa"/>
+ value="jpt.jpa"
+ forcePluginActivation="true"/>
</adapt>
</enabledWhen>
</page>
@@ -1026,6 +1110,8 @@
</extension>
+ <!-- ***** views ***** -->
+
<extension
point="org.eclipse.ui.views">
@@ -1036,7 +1122,7 @@
<view
id="org.eclipse.jpt.ui.jpaStructureView"
category="org.eclipse.jpt.jpa.ui"
- class="org.eclipse.jpt.jpa.ui.internal.views.structure.JpaStructureView"
+ class="org.eclipse.jpt.jpa.ui.internal.views.JpaStructureView"
icon="icons/full/eview16/jpa_structure.gif"
name="%jpaStructure"/>
@@ -1050,6 +1136,8 @@
</extension>
+ <!-- ***** WTP facet framework ***** -->
+
<extension
point="org.eclipse.wst.common.project.facet.ui.images">
@@ -1070,12 +1158,5 @@
</wizard-pages>
</extension>
- <extension
- id="org.eclipse.jpt.jpa.ui"
- point="org.eclipse.core.runtime.preferences">
- <initializer
- class="org.eclipse.jpt.jpa.ui.internal.prefs.JpaUiPreferenceInitializer">
- </initializer>
- </extension>
-
+
</plugin>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
index 17c0f01854..61dc00551f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
@@ -1,5 +1,5 @@
################################################################################
-# Copyright (c) 2006, 2011 Oracle. All rights reserved.
+# Copyright (c) 2006, 2012 Oracle. All rights reserved.
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0, which accompanies this distribution
# and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -67,13 +67,14 @@ GenericPlatformUiDialog_notSupportedMessageText=Generate Tables from Entities is
JpaContent_label=JPA Content
-JpaStructureView_structureNotAvailable=JPA structure is not available.
+JpaStructureView_structureNotAvailable=A JPA structure is not available.
+JpaStructureView_structureProviderNotAvailable=A JPA structure provider is not available: {0}:{1}
JpaStructureView_linkWithEditorText=Link with Editor
JpaStructureView_linkWithEditorDesc=Link with Active Editor
JpaStructureView_linkWithEditorTooltip=Link with Editor
JpaStructureView_numItemsSelected={0} items selected
-JpaDetailsView_viewNotAvailable=Details are not available for the current selection.
+JpaDetailsView_viewNotAvailable=JPA details are not available for the current selection.
JpaFacetWizardPage_title=JPA Facet
JpaFacetWizardPage_description=Configure JPA settings.
@@ -166,3 +167,5 @@ OverwriteConfirmerDialog_text=Overwrite source code for the class ''{0}''?
SelectJpaOrmMappingFileDialog_newButton=New...
SelectJpaOrmMappingFileDialog_toolTip=Create a new mapping file
+
+SynchronizingClasses_TaskName=Synchronizing classes...
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java
new file mode 100644
index 0000000000..8ad990cb48
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaFileModel.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+
+/**
+ * Standard adapter for retrieving a {@link JpaFile JPA file} model
+ * with change notification when the JPA file is created or destroyed
+ * (or its JPA project is created or destroyed):
+ * <pre>
+ * IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember("Foo.java");
+ * JpaFileModel jpaFileModel = (JpaFileModel) file.getAdapter(JpaFileModel.class);
+ * JpaFile jpaFile = jpaFileModel.getValue();
+ * </pre>
+ * @see org.eclipse.jpt.jpa.ui.internal.FileAdapterFactory
+ */
+public interface JpaFileModel
+ extends PropertyValueModel<JpaFile>
+{
+ /**
+ * Return the file corresponding to the JPA file model.
+ */
+ IFile getFile();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaPlatformUi.java
index 44e2db91fc..88b19b3e05 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaPlatformUi.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaPlatformUi.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,6 +13,7 @@ import java.util.Iterator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaPlatform;
@@ -24,52 +25,50 @@ import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
import org.eclipse.jpt.jpa.ui.details.DefaultMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.JpaComposite;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.MappingUiDefinition;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
import org.eclipse.swt.widgets.Composite;
/**
* This interface is to be implemented by a JPA vendor to provide extensions to
- * JPA UI functionality. This is intended to work in conjunction with a core
- * JPA platform ({@link JpaPlatform}) implementation with the same ID.
+ * JPA UI functionality. This is intended to work in conjunction with a core
+ * {@link JpaPlatform JPA platform} implementation with the same ID.
* <p>
- * Any implementation should be <em>stateless</em> in nature.
+ * Any implementation's state should be <em>static</em>.
* <p>
* The "generic" extension supplies UI for the core platform extension with the same
* ID.
- *
- * See the extension point: org.eclipse.jpt.jpa.ui.jpaPlatform
- *
+ * <p>
+ * See the extension point: <code>org.eclipse.jpt.jpa.ui.jpaPlatform</code>
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface JpaPlatformUi
-{
+public interface JpaPlatformUi {
// ********** navigator provider **********
/**
- * Return the {@link JpaNavigatorProvider} for this platform,
- * which determines Project Explorer content and look
+ * Return the platform's Navigator factory provider.
+ * This is used by the Common Navigator to build and maintain the JPA
+ * content and labels.
*/
- JpaNavigatorProvider getNavigatorProvider();
+ ItemTreeStateProviderFactoryProvider getNavigatorFactoryProvider();
- // ********** structure providers **********
+ // ********** structure view factory providers **********
/**
* Return a structure provider for the specified JPA file.
*/
- JpaStructureProvider getStructureProvider(JpaFile jpaFile);
+ ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider(JpaFile jpaFile);
// ********** details providers **********
- JpaDetailsPage<? extends JpaStructureNode> buildJpaDetailsPage(
+ JpaDetailsPageManager<? extends JpaStructureNode> buildJpaDetailsPageManager(
Composite parent,
JpaStructureNode structureNode,
WidgetFactory widgetFactory);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java
new file mode 100644
index 0000000000..af63d17873
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaProjectModel.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaProject;
+
+/**
+ * Standard adapter for retrieving a {@link JpaProject JPA project} model
+ * with change notification when the JPA project is created or destroyed:
+ * <pre>
+ * IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Foo Project");
+ * JpaProjectModel jpaProjectModel = (JpaProjectModel) project.getAdapter(JpaProjectModel.class);
+ * JpaProject jpaProject = jpaProjectModel.getValue();
+ * </pre>
+ * @see org.eclipse.jpt.jpa.ui.internal.ProjectAdapterFactory
+ */
+public interface JpaProjectModel
+ extends PropertyValueModel<JpaProject>
+{
+ /**
+ * Return the project corresponding to the JPA project model.
+ */
+ IProject getProject();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaRootContextNodeModel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaRootContextNodeModel.java
new file mode 100644
index 0000000000..e5553618b0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JpaRootContextNodeModel.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+
+/**
+ * Standard adapter for retrieving a {@link JpaRootContextNode JPA root
+ * context node} model with change notification when the JPA root context
+ * node is created or destroyed:
+ * <pre>
+ * IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Foo Project");
+ * JpaRootContextNodeModel jpaRootContextNodeModel = (JpaJpaRootContextNodeModel) project.getAdapter(JpaJpaRootContextNodeModel.class);
+ * JpaRootContextNode jpaRootContextNode = jpaRootContextNodeModel.getValue();
+ * </pre>
+ * @see org.eclipse.jpt.jpa.ui.internal.ProjectAdapterFactory
+ */
+public interface JpaRootContextNodeModel
+ extends PropertyValueModel<JpaRootContextNode>
+{
+ /**
+ * Return the project corresponding to the JPA root context model.
+ */
+ IProject getProject();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiPlugin.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiPlugin.java
index 0ca0e6a600..f70a5ad608 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiPlugin.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/JptJpaUiPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,14 +9,13 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.jpt.jpa.core.JpaPlatform;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.ui.internal.platform.JpaPlatformUiRegistry;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
+import org.eclipse.jpt.common.utility.internal.AbstractBooleanReference;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
@@ -39,6 +38,10 @@ import org.osgi.framework.BundleContext;
public class JptJpaUiPlugin
extends AbstractUIPlugin
{
+ /**
+ * @see #focusIn(Control)
+ */
+ private final AsyncEventListenerFlag asyncEventListenerFlag = new AsyncEventListenerFlag();
private final Listener focusListener;
@@ -50,8 +53,8 @@ public class JptJpaUiPlugin
public static final String PLUGIN_ID = "org.eclipse.jpt.jpa.ui";
public static final String PLUGIN_ID_ = PLUGIN_ID + '.';
- private static final String FOCUS_DATA_KEY = PLUGIN_ID_ + "focus";
- private static final Object FOCUS_DATA = new Object();
+ private static final String DALI_UI_KEY = PLUGIN_ID;
+ private static final Object DALI_UI_DATA = new Object();
// ********** Preference keys **********
@@ -169,70 +172,58 @@ public class JptJpaUiPlugin
// ********** focus handling **********
/**
- * This method is called whenever a "focus in" event is generated.
- * If the control gaining focus is part of one of our composites (typically
- * a JPA Details View), we stop listening to Java change events
- * (and assume all changes to the Java model are generated by us).
- * If the control gaining focus is *not* part of one of our composites,
- * we start listening to the Java change events again.
+ * This method is called whenever a {@link SWT#FocusIn} event is generated.
+ * <p>
+ * If the control gaining focus is part of one the Dali composites
+ * (typically the JPA Details View), we deactivate the Dali Java change
+ * listener so we ignore any changes to the Java source code that probably
+ * originated from Dali. This means we will miss any changes to the Java
+ * source code that is caused by non-UI activity; but, we hope, these
+ * changes are unrelated to JPA annotations etc.
+ * <p>
+ * If the control gaining focus is <em>not</em> part of one of the Dali
+ * composites, we start listening to the Java change events again. This
+ * method is called whenever a non-Dali UI control gains the UI focus. When
+ * this happens we activate the Dali Java change listener so that we begin
+ * to keep the Dali model synchronized with the Java source code.
*/
- void focusIn(Control control) {
- while (control != null) {
- if (control.getData(FOCUS_DATA_KEY) == FOCUS_DATA) {
- this.focusIn();
- return;
- }
- control = control.getParent();
- }
- this.focusOut();
+ /* CU private */ void focusIn(Control control) {
+ this.asyncEventListenerFlag.setValue(this.controlIsNonDali(control));
}
/**
- * This method is called whenever a Dali UI control that affects Java
- * source code gains the UI focus. When this happens we deactivate
- * the Dali Java change listener so we ignore any changes to the Java
- * source code that probably originated from Dali. This means we will miss
- * any changes to the Java source code that is caused by non-UI activity;
- * but, we hope, these changes are unrelated to JPA annotations etc.
- * @see #focusOut()
+ * Return whether the specified control is <em><b>neither</b></em>
+ * a Dali UI component <em><b>nor</b></em> contained by a Dali UI component.
*/
- private void focusIn() {
- JptJpaCorePlugin.setJavaElementChangeListenerIsActive(false);
+ private boolean controlIsNonDali(Control control) {
+ return ! this.controlIsDali(control);
}
/**
- * This method is called whenever a non-Dali UI control gains the UI focus.
- * When this happens we activate the Dali Java change listener so that we
- * begin to keep the Dali model synchronized with the Java source code.
- * @see #focusIn()
+ * Return whether the specified control, or any of its ancestors, is a Dali
+ * UI component.
+ *
+ * @see #controlAffectsJavaSource(Control)
*/
- private void focusOut() {
- JptJpaCorePlugin.setJavaElementChangeListenerIsActive(true);
+ private boolean controlIsDali(Control control) {
+ while (control != null) {
+ if (control.getData(DALI_UI_KEY) == DALI_UI_DATA) {
+ return true;
+ }
+ control = control.getParent();
+ }
+ return false;
}
/**
- * Tag the specified control so that whenever it (or any of its children,
- * grandchildren, etc.) has the focus, the Dali model ignores any Java
- * change events. This method is to be called when the control is first
- * constructed.
+ * Tag the specified control so that whenever it (or any of its descendants)
+ * has the focus, the Dali model ignores any Java change events. This method
+ * is to be called when the control is first constructed.
+ *
+ * @see #controlIsDali(Control)
*/
public void controlAffectsJavaSource(Control control) {
- control.setData(FOCUS_DATA_KEY, FOCUS_DATA);
- }
-
-
- // ********** platform **********
-
- /**
- * Return the JPA platform UI corresponding to the specified JPA platform.
- */
- public JpaPlatformUi getJpaPlatformUi(JpaPlatform jpaPlatform) {
- return JpaPlatformUiRegistry.instance().getJpaPlatformUi(jpaPlatform.getId());
- }
-
- public JpaNavigatorProvider getJpaNavigatorProvider(JpaPlatform jpaPlatform) {
- JpaPlatformUi platform = this.getJpaPlatformUi(jpaPlatform);
- return (platform == null) ? null : platform.getNavigatorProvider();
+ control.setData(DALI_UI_KEY, DALI_UI_DATA);
}
@@ -245,9 +236,14 @@ public class JptJpaUiPlugin
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
+ this.getJpaProjectManager().addAsyncEventListenerFlag(this.asyncEventListenerFlag);
Display.getDefault().addFilter(SWT.FocusIn, this.focusListener);
}
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
/**
* Unregister our SWT listener with the display.
*/
@@ -255,9 +251,46 @@ public class JptJpaUiPlugin
public void stop(BundleContext context) throws Exception {
try {
Display.getDefault().removeFilter(SWT.FocusIn, this.focusListener);
+ this.getJpaProjectManager().removeAsyncEventListenerFlag(this.asyncEventListenerFlag);
} finally {
super.stop(context);
}
}
+
+ /**
+ * This flag's value depends on the current thread. If the current thread is
+ * the background Java Reconciler thread, the flag's value is determined by
+ * the current UI focus (i.e. whether the focus is somewhere other than a
+ * Dali view); otherwise the flag's value is <code>true</code>.
+ * In other words, if a Dali view has the focus and a Java event is fired
+ * on the Java Reconciler thread, the event is ignored; if the event is
+ * fired on some other thread (typically synchronously on the Main thread),
+ * the event is forwarded to the JPA projects.
+ */
+ /* CU private */ static class AsyncEventListenerFlag
+ extends AbstractBooleanReference
+ {
+ private volatile boolean value = true;
+
+ @SuppressWarnings("restriction")
+ private static final String JAVA_RECONCILER_THREAD_NAME = org.eclipse.jdt.internal.ui.text.JavaReconciler.class.getName();
+
+ AsyncEventListenerFlag() {
+ super();
+ }
+
+ public boolean getValue() {
+ if (Thread.currentThread().getName().equals(JAVA_RECONCILER_THREAD_NAME)) {
+ return this.value;
+ }
+ return true;
+ }
+
+ public boolean setValue(boolean value) {
+ boolean old = this.value;
+ this.value = value;
+ return old;
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/ResourceUiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/ResourceUiDefinition.java
index 6f7a2e817b..fb55b620d5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/ResourceUiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/ResourceUiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,25 +10,28 @@
package org.eclipse.jpt.jpa.ui;
import org.eclipse.jpt.common.core.JptResourceType;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
/**
- *
+ * Resource UI definition.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*/
-public interface ResourceUiDefinition
-{
+public interface ResourceUiDefinition {
/**
- * Return whether this definition provides UI for resource of the given type
+ * Return whether the definition provides UI for resource of the specified
+ * type.
*/
boolean providesUi(JptResourceType resourceType);
-
+
/**
- * Return the structure provider association with this mapping file type.
+ * Return the resource definition's JPA Structure View factory provider.
+ * This is used by the view to build and maintain its tree's content and
+ * labels.
*/
- JpaStructureProvider getStructureProvider();
+ ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsPageManager.java
index b24d4d9a3e..131c54f36a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsPageManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,43 +9,50 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.details;
+import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
- * A details page is used to show the property pane for a given context node. The
- * {@link JpaDetailsProvider} is responsible for creating the pane.
- *
- * @see JpaDetailsProvider
- *
- * @version 2.0
- * @since 2.0
- *
+ * A details page manager is used to display the property page for a structure
+ * node. The {@link JpaDetailsProvider} is responsible for creating the manager.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @param <T> the type of the details page manager's model
+ *
+ * @version 2.0
+ * @since 2.0
+ * @see JpaDetailsProvider
*/
-public interface JpaDetailsPage<T extends JpaStructureNode>
-{
+public interface JpaDetailsPageManager<T extends JpaStructureNode> {
/**
- * Returns this details' page's widget.
- *
- * @return The container of the widgets shown by this details page
+ * Return the details page manager's page.
*/
- Control getControl();
+ Control getPage();
/**
- * Sets the subject for this details page.
- *
- * @param subject Either the new subject or <code>null</code> if the subject
- * needs to be removed
+ * Return the details page manager's subject.
*/
- void setSubject(T subject);
-
+ T getSubject();
+
/**
- * Dispose the details page and any resources it holds.
+ * Set the details page manager's subject.
+ * The subject must be of type <code>T</code>.
+ */
+ void setSubject(Object subject);
+
+ /**
+ * Dispose the details page manager and any resources it holds.
*/
void dispose();
-} \ No newline at end of file
+
+ interface Factory {
+ <T extends JpaStructureNode> JpaDetailsPageManager<T> buildPageManager(Composite parent, WidgetFactory widgetFactory);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsProvider.java
index a7c11cf787..e9427862c1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/details/JpaDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,37 +14,33 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible to create the {@link JpaDetailsPage}
- * responsible to show the information for a given content node id.
- *
- * @see JpaDetailsPage
- *
- * @version 3.0
- * @since 2.0
- *
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
+ * responsible for showing the information for a structure node ID.
+ * <p>
* Provisional API: This interface is part of an interim API that is still
* under development and expected to change significantly before reaching
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 3.0
+ * @since 2.0
+ *
+ * @see JpaDetailsPageManager
*/
-public interface JpaDetailsProvider
-{
+public interface JpaDetailsProvider {
/**
- * Return whether this provider returns a details page for the given structure node
+ * Return whether the provider can build a details page manager for the
+ * specified JPA structure node.
*/
boolean providesDetails(JpaStructureNode structureNode);
-
+
/**
- * Creates a new details page based on the given content node id.
- *
- * @param parent The parent container
- * @param contentNodeId The unique identifier used to determine which details
- * page to create
- * @param widgetFactory The factory used to create various widgets
+ * Build a new details page manager with the specified parent and widget
+ * factory.
*/
- //TODO Should we pass in JpaUiFactory so these pages can be built using the factory and overriden?
- JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(
+ // TODO pass in JpaUiFactory so these pages can be built using the factory and overridden?
+ JpaDetailsPageManager<? extends JpaStructureNode> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/EditorPartAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/EditorPartAdapterFactory.java
deleted file mode 100644
index f17567c28c..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/EditorPartAdapterFactory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-
-/**
- * Factory to build adapters for a editor part:
- * - JPA file (if the editor part is a file editor etc.)
- *
- * See org.eclipse.jpt.jpa.ui plugin.xml.
- */
-public class EditorPartAdapterFactory
- implements IAdapterFactory
-{
- private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaFile.class };
-
- public Class<?>[] getAdapterList() {
- return ADAPTER_LIST;
- }
-
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) {
- if (adaptableObject instanceof IEditorPart) {
- return this.getAdapter((IEditorPart) adaptableObject, adapterType);
- }
- return null;
- }
-
- private Object getAdapter(IEditorPart editorPart, Class<?> adapterType) {
- if (adapterType == JpaFile.class) {
- return this.getJpaFile(editorPart);
- }
- return null;
- }
-
- private JpaFile getJpaFile(IEditorPart editorPart) {
- IEditorInput editorInput = editorPart.getEditorInput();
- if (editorInput instanceof IFileEditorInput) {
- return this.getJpaFile((IFileEditorInput) editorInput);
- }
- return null;
- }
-
- private JpaFile getJpaFile(IFileEditorInput fileEditorInput) {
- return this.getJpaFile(fileEditorInput.getFile());
- }
-
- private JpaFile getJpaFile(IFile file) {
- return JptJpaCorePlugin.getJpaFile(file);
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java
new file mode 100644
index 0000000000..388e1ec0dc
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/FileAdapterFactory.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.common.utility.internal.SimpleFilter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ElementPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.ui.JpaFileModel;
+import org.eclipse.jpt.jpa.ui.JpaProjectModel;
+
+/**
+ * Factory to build Dali adapters for an {@link IFile}
+ * (The comments for the adapters produced by {@link ProjectAdapterFactory}
+ * are applicable here also):<ul>
+ * <li>{@link org.eclipse.jpt.jpa.ui.JpaFileModel JpaFileModel}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ *
+ * @see ProjectAdapterFactory
+ */
+public class FileAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaFileModel.class,
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IFile) {
+ return this.getAdapter((IFile) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IFile file, Class<?> adapterType) {
+ if (adapterType == JpaFileModel.class) {
+ return this.getJpaFileModel(file);
+ }
+ return null;
+ }
+
+ private JpaFileModel getJpaFileModel(IFile file) {
+ return new JpaFileModelAdapter(this.buildJpaFilesModel(file.getProject()), file);
+ }
+
+ private CollectionValueModel<JpaFile> buildJpaFilesModel(IProject project) {
+ return new JpaFilesModel(this.getJpaProjectModel(project));
+ }
+
+ private JpaProjectModel getJpaProjectModel(IProject project) {
+ return (JpaProjectModel) project.getAdapter(JpaProjectModel.class);
+ }
+
+
+ // ********** JPA files model **********
+
+ /**
+ * Adapt a JPA project's JPA files collection to the collection value model
+ * interface.
+ */
+ /* CU private */ static class JpaFilesModel
+ extends CollectionAspectAdapter<JpaProject, JpaFile>
+ {
+ JpaFilesModel(PropertyValueModel<JpaProject> jpaProjectModel) {
+ super(jpaProjectModel, JpaProject.JPA_FILES_COLLECTION);
+ }
+
+ @Override
+ protected Iterable<JpaFile> getIterable() {
+ return this.subject.getJpaFiles();
+ }
+
+ @Override
+ protected int size_() {
+ return this.subject.getJpaFilesSize();
+ }
+ }
+
+
+ // ********** JPA file model **********
+
+ /**
+ * Implement a property value model for the JPA file corresponding to a
+ * {@link IFile file}. The model will fire change events when the
+ * corresponding JPA file is added or removed from the JPA project
+ * or when the JPA project is created or destroyed.
+ * This is useful for UI code that does not want to wait to
+ * retrieve a JPA file but wants to be notified when it is available.
+ * <p>
+ * Subclass {@link ElementPropertyValueModelAdapter} so we can
+ * implement {@link org.eclipse.jpt.jpa.ui.JpaFileModel}.
+ *
+ * @see JpaProjectModel
+ */
+ /* CU private */ static class JpaFileModelAdapter
+ extends ElementPropertyValueModelAdapter<JpaFile>
+ implements JpaFileModel
+ {
+ JpaFileModelAdapter(CollectionValueModel<JpaFile> jpaFilesModel, IFile file) {
+ super(jpaFilesModel, new Predicate(file));
+ }
+
+ public IFile getFile() {
+ return ((Predicate) this.predicate).getCriterion();
+ }
+
+ /* class private */ static class Predicate
+ extends SimpleFilter<JpaFile, IFile>
+ {
+ Predicate(IFile file) {
+ super(file);
+ }
+ @Override
+ public boolean accept(JpaFile jpaFile) {
+ return jpaFile.getFile().equals(this.criterion);
+ }
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaFileAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaFileAdapterFactory.java
new file mode 100644
index 0000000000..7f2622f4ab
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaFileAdapterFactory.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
+
+/**
+ * Factory to build adapters for a {@link JpaFile}:<ul>
+ * <li>{@link ItemTreeStateProviderFactoryProvider}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class JpaFileAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { ItemTreeStateProviderFactoryProvider.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof JpaFile) {
+ return this.getAdapter((JpaFile) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(JpaFile jpaFile, Class<?> adapterType) {
+ if (adapterType == ItemTreeStateProviderFactoryProvider.class) {
+ return this.getJpaStructureViewFactoryProvider(jpaFile);
+ }
+ return null;
+ }
+
+ private ItemTreeStateProviderFactoryProvider getJpaStructureViewFactoryProvider(JpaFile jpaFile) {
+ return this.getPlatformUi(jpaFile).getStructureViewFactoryProvider(jpaFile);
+ }
+
+ private JpaPlatformUi getPlatformUi(JpaFile jpaFile) {
+ return (JpaPlatformUi) jpaFile.getJpaProject().getJpaPlatform().getAdapter(JpaPlatformUi.class);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java
index 8e49cc725e..64118423b7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -30,14 +30,15 @@ import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
/**
* JPA Java code-completion proposal computer
*/
-public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposalComputer {
-
+public class JpaJavaCompletionProposalComputer
+ implements IJavaCompletionProposalComputer
+{
public JpaJavaCompletionProposalComputer() {
super();
}
@@ -46,11 +47,10 @@ public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposa
// do nothing
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({ "unchecked", "rawtypes" })
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return (context instanceof JavaContentAssistInvocationContext) ?
- this.computeCompletionProposals((JavaContentAssistInvocationContext) context)
- :
+ this.computeCompletionProposals((JavaContentAssistInvocationContext) context) :
Collections.emptyList();
}
@@ -88,8 +88,8 @@ public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposa
private List<ICompletionProposal> computeCompletionProposals(JavaContentAssistInvocationContext context) {
try {
return this.computeCompletionProposals_(context);
- } catch (Exception ex) {
- // JptJpaCorePlugin.log(ex); // don't log "expected" exceptions (?)
+ } catch (RuntimeException ex) {
+ // JptJpaUiPlugin.log(ex); // don't log "expected" exceptions (?)
return Collections.emptyList();
}
}
@@ -105,7 +105,7 @@ public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposa
return Collections.emptyList();
}
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile jpaFile = this.getJpaFile(file);
if (jpaFile == null) {
return Collections.emptyList();
}
@@ -120,7 +120,7 @@ public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposa
// the context's "token" is really a sort of "prefix" - it does NOT
// correspond to the "start" and "end" we get below...
char[] prefix = cc.getToken();
- Filter<String> filter = ((prefix == null) ? Filter.Null.<String>instance() : new IgnoreCasePrefixFilter(prefix));
+ Filter<String> filter = this.buildPrefixFilter(prefix);
// the token "start" is the offset of the token's first character
int tokenStart = cc.getTokenStart();
// the token "end" is the offset of the token's last character (yuk)
@@ -153,12 +153,16 @@ public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposa
try {
return (IFile) cu.getCorrespondingResource();
} catch (JavaModelException ex) {
- JptJpaCorePlugin.log(ex);
+ JptJpaUiPlugin.log(ex);
return null;
}
}
- @SuppressWarnings("unchecked")
+ private JpaFile getJpaFile(IFile file) {
+ return (JpaFile) file.getAdapter(JpaFile.class);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
return Collections.emptyList();
}
@@ -171,15 +175,22 @@ public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposa
// do nothing
}
- private static class IgnoreCasePrefixFilter implements Filter<String> {
- private final char[] prefix;
+ private Filter<String> buildPrefixFilter(char[] prefix) {
+ return (prefix == null) ?
+ Filter.Transparent.<String>instance() :
+ new IgnoreCasePrefixFilter(prefix);
+ }
+
+ private static class IgnoreCasePrefixFilter
+ implements Filter<String>
+ {
+ private final String prefix;
IgnoreCasePrefixFilter(char[] prefix) {
super();
- this.prefix = prefix;
+ this.prefix = new String(prefix);
}
public boolean accept(String s) {
- return StringTools.stringStartsWithIgnoreCase(s.toCharArray(), this.prefix);
+ return StringTools.stringStartsWithIgnoreCase(s, this.prefix);
}
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaPlatformAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaPlatformAdapterFactory.java
new file mode 100644
index 0000000000..bc1de165e0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaPlatformAdapterFactory.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.core.JpaPlatform;
+import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
+import org.eclipse.jpt.jpa.ui.internal.platform.JpaPlatformUiRegistry;
+
+/**
+ * Factory to build adapters for a {@link JpaPlatform}:<ul>
+ * <li>{@link JpaPlatformUi}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ *
+ * @see JpaPlatformUiRegistry
+ */
+public class JpaPlatformAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaPlatformUi.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof JpaPlatform) {
+ return this.getAdapter((JpaPlatform) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(JpaPlatform jpaPlatform, Class<?> adapterType) {
+ if (adapterType == JpaPlatformUi.class) {
+ return this.getJpaPlatformUi(jpaPlatform);
+ }
+ return null;
+ }
+
+ private JpaPlatformUi getJpaPlatformUi(JpaPlatform jpaPlatform) {
+ return JpaPlatformUiRegistry.instance().getJpaPlatformUi(jpaPlatform.getId());
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaStructureNodeAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaStructureNodeAdapterFactory.java
new file mode 100644
index 0000000000..220c128fbc
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaStructureNodeAdapterFactory.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.common.ui.WidgetFactory;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Factory to build adapters for a {@link JpaStructureNode}:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager.Factory}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class JpaStructureNodeAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaDetailsPageManager.Factory.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof JpaStructureNode) {
+ return this.getAdapter((JpaStructureNode) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(JpaStructureNode jpaStructureNode, Class<?> adapterType) {
+ if (adapterType == JpaDetailsPageManager.Factory.class) {
+ return this.getJpaDetailsPageManagerFactory(jpaStructureNode);
+ }
+ return null;
+ }
+
+ private JpaDetailsPageManager.Factory getJpaDetailsPageManagerFactory(JpaStructureNode jpaStructureNode) {
+ return new JpaDetailsPageManagerFactory(jpaStructureNode);
+ }
+
+ /* CU private */ static class JpaDetailsPageManagerFactory
+ implements JpaDetailsPageManager.Factory
+ {
+ private final JpaStructureNode jpaStructureNode;
+
+ JpaDetailsPageManagerFactory(JpaStructureNode jpaStructureNode) {
+ super();
+ this.jpaStructureNode = jpaStructureNode;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends JpaStructureNode> JpaDetailsPageManager<T> buildPageManager(Composite parent, WidgetFactory widgetFactory) {
+ return (JpaDetailsPageManager<T>) this.getJpaPlatformUi().buildJpaDetailsPageManager(parent, this.jpaStructureNode, widgetFactory);
+ }
+
+ private JpaPlatformUi getJpaPlatformUi() {
+ return (JpaPlatformUi) this.jpaStructureNode.getJpaPlatform().getAdapter(JpaPlatformUi.class);
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.jpaStructureNode);
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptResourceModelPropertyTester.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptResourceModelPropertyTester.java
new file mode 100644
index 0000000000..d8263de31c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptResourceModelPropertyTester.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.common.core.JptResourceModel;
+import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.jpa.core.JpaProject;
+
+/**
+ * Property tester for {@link JptResourceModel}.
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>
+ */
+public class JptResourceModelPropertyTester
+ extends PropertyTester
+{
+ public static final String IS_LATEST_SUPPORTED_VERSION = "isLatestSupportedVersion"; //$NON-NLS-1$
+ public static final String IS_NOT_LATEST_SUPPORTED_VERSION = "isNotLatestSupportedVersion"; //$NON-NLS-1$
+
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof JptResourceModel) {
+ return this.test((JptResourceModel) receiver, property, expectedValue);
+ }
+ return false;
+ }
+
+ private boolean test(JptResourceModel resourceModel, String property, Object expectedValue) {
+ if (property.equals(IS_NOT_LATEST_SUPPORTED_VERSION)) {
+ return ! this.test(resourceModel, IS_LATEST_SUPPORTED_VERSION, expectedValue);
+ }
+ if (property.equals(IS_LATEST_SUPPORTED_VERSION)) {
+ boolean expected = (expectedValue == null) ? true : ((Boolean) expectedValue).booleanValue();
+ boolean actual = this.isLatestSupportedVersion(resourceModel);
+ return actual == expected;
+ }
+ return false;
+ }
+
+ private boolean isLatestSupportedVersion(JptResourceModel resourceModel) {
+ JpaProject jpaProject = this.getJpaProject(resourceModel.getFile().getProject());
+ if (jpaProject == null) {
+ // if we get to this tester, the JPA project should be there;
+ // so this will probably never happen
+ return true; // effectively disable "upgrade"
+ }
+ JptResourceType resourceType = resourceModel.getResourceType();
+ String latestVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(resourceType.getContentType()).getVersion();
+ return Tools.valuesAreEqual(resourceType.getVersion(), latestVersion);
+ }
+
+ private JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
index 41f3e45d53..40a46d0a90 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -17,6 +17,7 @@ import org.eclipse.osgi.util.NLS;
* @version 3.0
* @since 1.0
*/
+// TODO bjv rename...
public class JptUiMessages {
public static String AccessTypeComposite_access;
@@ -110,6 +111,7 @@ public class JptUiMessages {
public static String JpaStructureView_linkWithEditorText;
public static String JpaStructureView_linkWithEditorTooltip;
public static String JpaStructureView_structureNotAvailable;
+ public static String JpaStructureView_structureProviderNotAvailable;
public static String JpaStructureView_numItemsSelected;
public static String JpqlContentProposalProvider_Description;
public static String MappingFileWizard_title;
@@ -150,6 +152,7 @@ public class JptUiMessages {
public static String JpaProblemSeveritiesPage_Warning;
public static String SelectJpaOrmMappingFileDialog_newButton;
public static String SelectJpaOrmMappingFileDialog_toolTip;
+ public static String SynchronizingClasses_TaskName;
private static final String BUNDLE_NAME = "jpt_ui"; //$NON-NLS-1$
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java
new file mode 100644
index 0000000000..89b4bb4bc9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/ProjectAdapterFactory.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.SimpleFilter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ElementPropertyValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+import org.eclipse.jpt.jpa.ui.JpaProjectModel;
+import org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel;
+
+/**
+ * Factory to build Dali adapters for an {@link IProject}:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.ui.JpaProjectModel JpaProjectModel} -
+ * This adapter will only return a JPA project if it is immediately
+ * available; but it will also notify listeners if the JPA project is
+ * ever created.
+ * This adapter should be used by any process that can temporarily ignore
+ * any uncreated JPA projects but should be notified if the JPA project
+ * <em>is</em> ever created (e.g. UI views).
+ * <li>{@link org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel JpaRootContextNodeModel} -
+ * This adapter is much like the {@link org.eclipse.jpt.jpa.ui.JpaProjectModel JpaProjectModel}
+ * adapter described above.
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class ProjectAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] {
+ JpaProjectModel.class,
+ JpaRootContextNodeModel.class,
+ };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IProject) {
+ return this.getAdapter((IProject) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IProject project, Class<?> adapterType) {
+ if (adapterType == JpaProjectModel.class) {
+ return this.getJpaProjectModel(project);
+ }
+ if (adapterType == JpaRootContextNodeModel.class) {
+ return this.getJpaRootContextNodeModel(project);
+ }
+ return null;
+ }
+
+ private JpaProjectModel getJpaProjectModel(IProject project) {
+ return new JpaProjectModelAdapter(this.getJpaProjectsModel(project.getWorkspace()), project);
+ }
+
+ private CollectionValueModel<JpaProject> getJpaProjectsModel(IWorkspace workspace) {
+ return new JpaProjectsModel(this.getJpaProjectManager(workspace));
+ }
+
+ private JpaProjectManager getJpaProjectManager(IWorkspace workspace) {
+ return (JpaProjectManager) workspace.getAdapter(JpaProjectManager.class);
+ }
+
+ private JpaRootContextNodeModel getJpaRootContextNodeModel(IProject project) {
+ return new JpaRootContextNodeModelAdapter(this.getJpaProjectModel(project));
+ }
+
+
+ // ********** JPA projects model **********
+
+ /**
+ * Adapt the JPA project manager's JPA projects list to the collection value
+ * model interface.
+ */
+ /* CU private */ static class JpaProjectsModel
+ extends CollectionAspectAdapter<JpaProjectManager, JpaProject>
+ {
+ JpaProjectsModel(JpaProjectManager jpaProjectManager) {
+ super(JpaProjectManager.JPA_PROJECTS_COLLECTION, jpaProjectManager);
+ }
+
+ @Override
+ protected Iterable<JpaProject> getIterable() {
+ return this.subject.getJpaProjects();
+ }
+
+ @Override
+ protected int size_() {
+ return this.subject.getJpaProjectsSize();
+ }
+ }
+
+
+ // ********** JPA project model **********
+
+ /**
+ * Implement a property value model for the JPA project corresponding to a
+ * {@link IProject project}. The model will fire change events when the
+ * corresponding JPA project is added or removed from the JPA project
+ * manager. This is useful for UI code that does not want to wait to
+ * retrieve a JPA project but wants to be notified when it is available.
+ * <p>
+ * Subclass {@link ElementPropertyValueModelAdapter} so we can
+ * implement {@link org.eclipse.jpt.jpa.ui.JpaProjectModel}.
+ * <p>
+ * <strong>NB:</strong> This model operates outside of all the other
+ * activity synchronized by the JPA project manager; but that should be OK
+ * since it will be kept synchronized with the JPA manager's collection of
+ * JPA projects in the end.
+ */
+ /* CU private */ static class JpaProjectModelAdapter
+ extends ElementPropertyValueModelAdapter<JpaProject>
+ implements JpaProjectModel
+ {
+ JpaProjectModelAdapter(CollectionValueModel<JpaProject> jpaProjectsModel, IProject project) {
+ super(jpaProjectsModel, new Predicate(project));
+ }
+
+ public IProject getProject() {
+ return ((Predicate) this.predicate).getCriterion();
+ }
+
+ /* class private */ static class Predicate
+ extends SimpleFilter<JpaProject, IProject>
+ {
+ Predicate(IProject project) {
+ super(project);
+ }
+ @Override
+ public boolean accept(JpaProject jpaProject) {
+ return jpaProject.getProject().equals(this.criterion);
+ }
+ }
+ }
+
+
+ // ********** JPA root context node model **********
+
+ /**
+ * Implement a property value model for the JPA root context node
+ * corresponding to a {@link JpaProject JPA project}. The model will fire
+ * change events when the corresponding JPA project is added or removed
+ * from the JPA project manager. This is useful for UI code that does not
+ * want to wait to retrieve a JPA root context node but wants to be notified
+ * when it is available.
+ * <p>
+ * Subclass {@link TransformationPropertyValueModel} so we can
+ * implement {@link org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel}.
+ * <p>
+ * <strong>NB:</strong> This model operates outside of all the other
+ * activity synchronized by the JPA project manager; but that should be OK
+ * since it will be kept synchronized with the JPA manager's collection of
+ * JPA projects in the end.
+ */
+ /* CU private */ static class JpaRootContextNodeModelAdapter
+ extends TransformationPropertyValueModel<JpaProject, JpaRootContextNode>
+ implements JpaRootContextNodeModel
+ {
+ JpaRootContextNodeModelAdapter(JpaProjectModel jpaProjectsModel) {
+ super(jpaProjectsModel, TRANSFORMER);
+ }
+
+ public IProject getProject() {
+ return ((JpaProjectModel) this.valueModel).getProject();
+ }
+
+ private static final Transformer TRANSFORMER = new Transformer();
+
+ /* class private */ static class Transformer
+ extends AbstractTransformer<JpaProject, JpaRootContextNode>
+ {
+ @Override
+ protected JpaRootContextNode transform_(JpaProject jpaProject) {
+ return jpaProject.getRootContextNode();
+ }
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java
index d1e156202a..e04fa66e5e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java
@@ -1,13 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.actions;
import org.eclipse.core.resources.IFile;
@@ -15,13 +14,12 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.JpaContextNode;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
@@ -30,9 +28,14 @@ import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
+/**
+ * The selection will be a JPA context node.
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
public class OpenJpaResourceAction
- extends BaseSelectionListenerAction {
-
+ extends BaseSelectionListenerAction
+{
private JpaContextNode selectedNode;
@@ -43,7 +46,7 @@ public class OpenJpaResourceAction
@Override
public boolean updateSelection(IStructuredSelection s) {
- selectedNode = null;
+ this.selectedNode = null;
if (! super.updateSelection(s)) {
return false;
@@ -57,27 +60,25 @@ public class OpenJpaResourceAction
return false;
}
- selectedNode = (JpaContextNode) s.getFirstElement();
+ this.selectedNode = (JpaContextNode) s.getFirstElement();
return true;
}
@Override
public void run() {
- if (! isEnabled()) {
- return;
+ if (this.isEnabled()) {
+ this.run_();
}
-
- IResource resource = selectedNode.getResource();
-
- if (resource != null && resource.exists() && resource.getType() == IResource.FILE) {
- openEditor((IFile) resource);
-
-
- if (selectedNode instanceof JpaStructureNode) {
- JpaSelectionManager selectionManager =
- SelectionManagerFactory.getSelectionManager(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
- selectionManager.select(new DefaultJpaSelection((JpaStructureNode) selectedNode), null);
+ }
+
+ private void run_() {
+ IResource resource = this.selectedNode.getResource();
+ if ((resource != null) && resource.exists() && (resource.getType() == IResource.FILE)) {
+ this.openEditor((IFile) resource);
+ if (this.selectedNode instanceof JpaStructureNode) {
+ JpaSelectionManager selectionManager = PlatformTools.getAdapter(PlatformUI.getWorkbench(), JpaSelectionManager.class);
+ selectionManager.setSelection((JpaStructureNode) this.selectedNode);
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java
index a91b6381f2..488b81e641 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/ProjectAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,14 +9,12 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.actions;
-import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.internal.platform.JpaPlatformUiRegistry;
import org.eclipse.ui.IObjectActionDelegate;
@@ -25,8 +23,9 @@ import org.eclipse.ui.IWorkbenchPart;
/**
* Override any of the #execute() methods.
*/
-public abstract class ProjectAction implements IObjectActionDelegate {
-
+public abstract class ProjectAction
+ implements IObjectActionDelegate
+{
private ISelection currentSelection;
@@ -51,8 +50,8 @@ public abstract class ProjectAction implements IObjectActionDelegate {
public void run(IAction action) {
if (this.currentSelection instanceof IStructuredSelection) {
- for (Iterator stream = ((IStructuredSelection) this.currentSelection).iterator(); stream.hasNext(); ) {
- this.execute(stream.next());
+ for (Object each : ((IStructuredSelection) this.currentSelection).toArray()) {
+ this.execute(each);
}
}
}
@@ -75,20 +74,19 @@ public abstract class ProjectAction implements IObjectActionDelegate {
}
protected JpaPlatformUi getJpaPlatformUi(JpaProject project) {
- String coreJpaPlatformId = project.getJpaPlatform().getId();
- return JpaPlatformUiRegistry.instance().getJpaPlatformUi(coreJpaPlatformId);
+ return (JpaPlatformUi) project.getJpaPlatform().getAdapter(JpaPlatformUi.class);
}
-
+
protected void execute(IProject project) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
- if (jpaProject == null) {
- return;
+ JpaProject jpaProject = this.getJpaProject(project);
+ if (jpaProject != null) {
+ this.execute(jpaProject);
}
- this.execute(jpaProject);
}
- protected void execute(JpaProject project) {
- throw new UnsupportedOperationException();
+ protected JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
}
+ protected abstract void execute(JpaProject project);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java
index 9f16d7a440..759f96733a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/SynchronizeClassesAction.java
@@ -1,49 +1,242 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.actions;
+import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.jpa.core.internal.synch.SynchronizeClassesJob;
+import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
+/**
+ * This action is contributed for:<ul>
+ * <li>any {@link IFile} named <code>"persistence.xml"</code>
+ * <li>any instance of {@link PersistenceXml}
+ * </ul>
+ */
public class SynchronizeClassesAction
implements IObjectActionDelegate
{
- private IFile file;
-
+ private IFile persistenceXmlFile;
+
+
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
// no-op for now
}
+ /**
+ * Determine whether we can calculate the <code>persistence.xml</code> file
+ * from the current selection and save it for use in {@link #run(IAction)}.
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ // There is always only one element in the actual selection.
+ Object sel = ((StructuredSelection) selection).getFirstElement();
+ this.persistenceXmlFile = this.buildPersistenceXmlFile(sel);
+ }
+
+ private IFile buildPersistenceXmlFile(Object selection) {
+ if (selection instanceof IFile) {
+ return (IFile) selection;
+ }
+ if (selection instanceof PersistenceXml) {
+ return (IFile) ((PersistenceXml) selection).getResource();
+ }
+ return null;
+ }
+
public void run(IAction action) {
- SynchronizeClassesJob job = new SynchronizeClassesJob(file);
- job.schedule();
+ try {
+ IRunnableWithProgress runnable = new SyncRunnable(this.persistenceXmlFile);
+ this.buildProgressMonitorDialog().run(true, true, runnable); // true => fork; true => cancellable
+ } catch (InvocationTargetException ex) {
+ JptJpaUiPlugin.log(ex);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ JptJpaUiPlugin.log(ex);
+ }
}
- public void selectionChanged(IAction action, ISelection selection) {
- // Action is contributed for IFile's named "persistence.xml" and
- // for PeristenceXml objects.
- // There is always only one element in actual selection.
- Object selectedObject = ((StructuredSelection) selection).getFirstElement();
-
- if (selectedObject instanceof IFile) {
- file = (IFile) selectedObject;
- }
- else if (selectedObject instanceof PersistenceXml) {
- file = (IFile) ((PersistenceXml) selectedObject).getResource();
+ private ProgressMonitorDialog buildProgressMonitorDialog() {
+ return new ProgressMonitorDialog(null);
+ }
+
+
+ // ********** sync runnable **********
+
+ /**
+ * This is dispatched to the progress monitor dialog.
+ */
+ /* CU private */ static class SyncRunnable
+ implements IRunnableWithProgress
+ {
+ private IFile persistenceXmlFile;
+
+ SyncRunnable(IFile persistenceXmlFile) {
+ super();
+ this.persistenceXmlFile = persistenceXmlFile;
+ }
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ this.run_(monitor);
+ } catch (CoreException ex) {
+ throw new InvocationTargetException(ex);
+ }
+ }
+
+ private void run_(IProgressMonitor monitor) throws CoreException {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ // lock the entire project, since we might modify the metamodel classes
+ ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.persistenceXmlFile.getProject());
+ workspace.run(
+ new SyncWorkspaceRunnable(this.persistenceXmlFile),
+ rule,
+ IWorkspace.AVOID_UPDATE,
+ monitor
+ );
+ }
+ }
+
+
+ // ********** sync workspace runnable **********
+
+ /**
+ * This is dispatched to the Eclipse workspace.
+ */
+ /* CU private */ static class SyncWorkspaceRunnable
+ implements IWorkspaceRunnable
+ {
+ private IFile persistenceXmlFile;
+
+ SyncWorkspaceRunnable(IFile persistenceXmlFile) {
+ super();
+ this.persistenceXmlFile = persistenceXmlFile;
+ }
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ SubMonitor sm = SubMonitor.convert(monitor, JptUiMessages.SynchronizingClasses_TaskName, 20);
+
+ JpaProject jpaProject = this.getJpaProject();
+ if (jpaProject == null) {
+ return;
+ }
+
+ JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
+ if (resource == null) {
+ // the resource can be null if the persistence.xml file has an invalid content type
+ return;
+ }
+
+ if (sm.isCanceled()) {
+ return;
+ }
+ sm.worked(1);
+
+ PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
+ if (persistenceXml == null) {
+ return; // unlikely...
+ }
+
+ Persistence persistence = persistenceXml.getPersistence();
+ if (persistence == null) {
+ return; // unlikely...
+ }
+
+ PersistenceUnit persistenceUnit = (persistence.getPersistenceUnitsSize() == 0) ?
+ persistence.addPersistenceUnit() :
+ persistence.getPersistenceUnit(0);
+ if (sm.isCanceled()) {
+ return;
+ }
+ sm.worked(1);
+
+ Command syncCommand = new SyncCommand(persistenceUnit, sm.newChild(17));
+ try {
+ this.getJpaProjectManager().execute(syncCommand, SynchronousUiCommandExecutor.instance());
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt(); // skip save?
+ throw new RuntimeException(ex);
+ }
+
+ resource.save();
+ sm.worked(1);
+ }
+
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) this.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
+ private IProject getProject() {
+ return this.persistenceXmlFile.getProject();
+ }
+
+ private JpaProject getJpaProject() {
+ return (JpaProject) this.getProject().getAdapter(JpaProject.class);
+ }
+
+ private IWorkspace getWorkspace() {
+ return this.persistenceXmlFile.getWorkspace();
+ }
+ }
+
+
+ // ********** sync command **********
+
+ /**
+ * This is dispatched to the JPA project manager.
+ */
+ /* CU private */ static class SyncCommand
+ implements Command
+ {
+ private final PersistenceUnit persistenceUnit;
+ private final IProgressMonitor monitor;
+
+ SyncCommand(PersistenceUnit persistenceUnit, IProgressMonitor monitor) {
+ super();
+ this.persistenceUnit = persistenceUnit;
+ this.monitor = monitor;
+ }
+
+ public void execute() {
+ this.persistenceUnit.synchronizeClasses(this.monitor);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.persistenceUnit);
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java
index 9507ee9bad..e45cd328f8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,60 +10,61 @@
package org.eclipse.jpt.jpa.ui.internal.commands;
import java.util.ArrayList;
-import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.ui.internal.dialogs.AddPersistentAttributeToXmlAndMapDialog;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
-public class AddPersistentAttributeToXmlAndMapHandler extends AbstractHandler
+/**
+ * Convert a list of <code>orm.xml</code> <em>virtual</em> attributes to
+ * <em>specified</em> and <em>mapped</em>.
+ * This handler is only active if <em>all</em> the selected nodes are
+ * virtual attributes.
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class AddPersistentAttributeToXmlAndMapHandler
+ extends AbstractHandler
{
- @SuppressWarnings("unchecked")
- public Object execute(ExecutionEvent executionEvent) throws ExecutionException {
- final IWorkbenchWindow window =
- HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent);
-
- final List<OrmReadOnlyPersistentAttribute> newAttributes = new ArrayList<OrmReadOnlyPersistentAttribute>();
-
- IStructuredSelection selection
- = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent);
-
-
- // only applies for multiply selected OrmReadOnlyPersistentAttribute objects in a tree
- for (OrmReadOnlyPersistentAttribute attribute : (Iterable<OrmReadOnlyPersistentAttribute>) CollectionTools.iterable(selection.iterator())) {
- OrmPersistentType type = attribute.getOwningPersistentType();
- String attributeName = attribute.getName();
-
- AddPersistentAttributeToXmlAndMapDialog dialog = new AddPersistentAttributeToXmlAndMapDialog(window.getShell(), attribute);
- dialog.create();
- dialog.setBlockOnOpen(true);
- dialog.open();
-
- OrmReadOnlyPersistentAttribute newAttribute = type.getAttributeNamed(attributeName);
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ this.execute_(event);
+ return null;
+ }
+
+ private void execute_(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ ArrayList<OrmReadOnlyPersistentAttribute> newAttributes = new ArrayList<OrmReadOnlyPersistentAttribute>();
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ for (Object each : selection.toList()) {
+ OrmReadOnlyPersistentAttribute attribute = (OrmReadOnlyPersistentAttribute) each;
+ OrmReadOnlyPersistentAttribute newAttribute = this.addAndMap(attribute, window);
if (newAttribute != null) {
newAttributes.add(newAttribute);
}
}
if (newAttributes.size() == 1) {
- window.getShell().getDisplay().asyncExec(
- new Runnable() {
- public void run() {
- JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window);
- selectionManager.select(new DefaultJpaSelection(newAttributes.get(0)), null);
- }
- });
+ JpaSelectionManager selectionManager = PlatformTools.getAdapter(window, JpaSelectionManager.class);
+ selectionManager.setSelection(newAttributes.get(0));
}
+ }
+
+ private OrmReadOnlyPersistentAttribute addAndMap(OrmReadOnlyPersistentAttribute attribute, IWorkbenchWindow window) {
+ OrmPersistentType type = attribute.getOwningPersistentType();
+ String attributeName = attribute.getName();
- return null;
+ AddPersistentAttributeToXmlAndMapDialog dialog = new AddPersistentAttributeToXmlAndMapDialog(window.getShell(), attribute);
+ dialog.create();
+ dialog.setBlockOnOpen(true);
+ dialog.open();
+
+ return type.getAttributeNamed(attributeName);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlHandler.java
index 7880e2371d..fcd6164610 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentAttributeToXmlHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,47 +10,45 @@
package org.eclipse.jpt.jpa.ui.internal.commands;
import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
-public class AddPersistentAttributeToXmlHandler extends AbstractHandler
+/**
+ * Convert a list of <code>orm.xml</code> <em>virtual</em> attributes to
+ * <em>specified</em>.
+ * This handler is only active if <em>all</em> the selected nodes are
+ * virtual attributes that have some sort of Java mapping (either specified
+ * or default).
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class AddPersistentAttributeToXmlHandler
+ extends AbstractHandler
{
- @SuppressWarnings("unchecked")
- public Object execute(ExecutionEvent executionEvent) throws ExecutionException {
- final IWorkbenchWindow window =
- HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent);
-
- final List<OrmReadOnlyPersistentAttribute> newAttributes = new ArrayList<OrmReadOnlyPersistentAttribute>();
-
- IStructuredSelection selection =
- (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent);
-
- // only applies for multiply selected OrmReadOnlyPersistentAttribute objects in a tree
- for (OrmReadOnlyPersistentAttribute attribute : (Iterable<OrmReadOnlyPersistentAttribute>) CollectionTools.iterable(selection.iterator())) {
- newAttributes.add(attribute.convertToSpecified());
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ this.execute_(event);
+ return null;
+ }
+
+ private void execute_(ExecutionEvent event) throws ExecutionException {
+ ArrayList<OrmReadOnlyPersistentAttribute> specifiedAttributes = new ArrayList<OrmReadOnlyPersistentAttribute>();
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ for (Object each : selection.toList()) {
+ OrmReadOnlyPersistentAttribute attribute = (OrmReadOnlyPersistentAttribute) each;
+ specifiedAttributes.add(attribute.convertToSpecified());
}
-
- if (newAttributes.size() == 1) {
- window.getShell().getDisplay().asyncExec(
- new Runnable() {
- public void run() {
- JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window);
- selectionManager.select(new DefaultJpaSelection(newAttributes.get(0)), null);
- }
- });
+
+ if (specifiedAttributes.size() == 1) {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ JpaSelectionManager selectionManager = PlatformTools.getAdapter(window, JpaSelectionManager.class);
+ selectionManager.setSelection(specifiedAttributes.get(0));
}
-
- return null;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java
index 1068d7fd75..3c070571f3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/AddPersistentClassHandler.java
@@ -1,57 +1,53 @@
/*******************************************************************************
- * Copyright (c) 2008 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.commands;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.ui.internal.dialogs.AddPersistentClassDialog;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
-public class AddPersistentClassHandler extends AbstractHandler
+/**
+ * Add an <code>orm.xml</code> type to the selected entity mappings.
+ * This handler is only active if <em>one</em> entity mappings is selected.
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class AddPersistentClassHandler
+ extends AbstractHandler
{
- public Object execute(ExecutionEvent executionEvent) throws ExecutionException {
- final IWorkbenchWindow window =
- HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent);
-
- IStructuredSelection selection
- = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent);
-
- // only applies for a singly selected EntityMappings object in a tree
- EntityMappings entityMappings =
- (EntityMappings) selection.getFirstElement();
-
- AddPersistentClassDialog dialog =
- new AddPersistentClassDialog(window.getShell(), entityMappings);
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ this.execute_(event);
+ return null;
+ }
+
+ private void execute_(ExecutionEvent event) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ EntityMappings entityMappings = (EntityMappings) selection.getFirstElement();
+
+ AddPersistentClassDialog dialog = new AddPersistentClassDialog(window.getShell(), entityMappings);
dialog.create();
dialog.setBlockOnOpen(true);
- final OrmPersistentType type = dialog.openAndReturnType();
-
+ OrmPersistentType type = dialog.openAndReturnType();
+
if (type != null) {
- window.getShell().getDisplay().asyncExec(
- new Runnable() {
- public void run() {
- JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window);
- selectionManager.select(new DefaultJpaSelection(type), null);
- }
- });
+ JpaSelectionManager selectionManager = PlatformTools.getAdapter(window, JpaSelectionManager.class);
+ selectionManager.setSelection(type);
}
-
- return null;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java
index 66f9eaaefb..6f8a2d9022 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/ConvertJavaProjectToJpaCommandHandler.java
@@ -1,15 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.commands;
-import static org.eclipse.wst.common.project.facet.core.util.internal.FileUtil.*;
+import static org.eclipse.wst.common.project.facet.core.util.internal.FileUtil.FILE_DOT_PROJECT;
+import static org.eclipse.wst.common.project.facet.core.util.internal.FileUtil.validateEdit;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@@ -18,14 +19,14 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
@@ -39,8 +40,12 @@ import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.internal.FacetedProjectNature;
import org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard;
+/**
+ * See org.eclipse.jpt.jpa.ui/plugin.xml
+ */
public class ConvertJavaProjectToJpaCommandHandler
- extends AbstractHandler {
+ extends AbstractHandler
+{
public Object execute(ExecutionEvent event)
throws ExecutionException {
@@ -50,7 +55,7 @@ public class ConvertJavaProjectToJpaCommandHandler
if (currentSelection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) currentSelection).getFirstElement();
- project = (IProject) Platform.getAdapterManager().getAdapter(element, IProject.class);
+ project = PlatformTools.getAdapter(element, IProject.class);
}
if (project == null) {
@@ -86,14 +91,16 @@ public class ConvertJavaProjectToJpaCommandHandler
= new ModifyFacetedProjectWizard(runnable.getFacetedProjectWorkingCopy());
WizardDialog dialog = new WizardDialog(shell, wizard);
- if (dialog.open() == Dialog.CANCEL) {
+ if (dialog.open() == Window.CANCEL) {
throw new InterruptedException();
}
}
- catch (InvocationTargetException e) {
- JptJpaUiPlugin.log(e);
+ catch (InvocationTargetException ex) {
+ JptJpaUiPlugin.log(ex);
}
- catch(InterruptedException e) {
+ catch(InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ JptJpaUiPlugin.log(ex);
removeFacetNature(project);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java
index 49e4e16826..1c09482abd 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,51 +10,48 @@
package org.eclipse.jpt.jpa.ui.internal.commands;
import java.util.ArrayList;
-import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
-public class RemovePersistentAttributeFromXmlHandler extends AbstractHandler
-{
- @SuppressWarnings("unchecked")
- public Object execute(ExecutionEvent executionEvent) throws ExecutionException {
- final IWorkbenchWindow window =
- HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent);
-
- final List<OrmReadOnlyPersistentAttribute> virtualAttributes = new ArrayList<OrmReadOnlyPersistentAttribute>();
-
- IStructuredSelection selection =
- (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent);
-
- // only applies for multiply selected OrmPersistentAttribute objects in a tree
- for (OrmPersistentAttribute attribute : (Iterable<OrmPersistentAttribute>) CollectionTools.iterable(selection.iterator())) {
+/**
+ * Convert a list of <code>orm.xml</code> <em>specified</em> attributes to
+ * <em>virtual</em>.
+ * This handler is only active if <em>all</em> the selected nodes are
+ * specified attributes.
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class RemovePersistentAttributeFromXmlHandler
+ extends AbstractHandler
+{
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ this.execute_(event);
+ return null;
+ }
+
+ private void execute_(ExecutionEvent event) throws ExecutionException {
+ ArrayList<OrmReadOnlyPersistentAttribute> virtualAttributes = new ArrayList<OrmReadOnlyPersistentAttribute>();
+ IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ for (Object each : selection.toList()) {
+ OrmPersistentAttribute attribute = (OrmPersistentAttribute) each;
OrmReadOnlyPersistentAttribute newAttribute = attribute.convertToVirtual();
if (newAttribute != null) {
virtualAttributes.add(newAttribute);
}
}
-
+
if (virtualAttributes.size() == 1) {
- window.getShell().getDisplay().asyncExec(
- new Runnable() {
- public void run() {
- JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window);
- selectionManager.select(new DefaultJpaSelection(virtualAttributes.get(0)), null);
- }
- });
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ JpaSelectionManager selectionManager = PlatformTools.getAdapter(window, JpaSelectionManager.class);
+ selectionManager.setSelection(virtualAttributes.get(0));
}
-
- return null;
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/UpgradeXmlFileVersionHandler.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/UpgradeXmlFileVersionHandler.java
index b56c54c3cd..75c2d39a7d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/UpgradeXmlFileVersionHandler.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/commands/UpgradeXmlFileVersionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,17 +12,21 @@ package org.eclipse.jpt.jpa.ui.internal.commands;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.XmlFile;
import org.eclipse.jpt.jpa.core.resource.xml.JpaRootEObject;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.ui.handlers.HandlerUtil;
-public class UpgradeXmlFileVersionHandler extends AbstractHandler
+/**
+ * See org.eclipse.jpt.jpa.ui/plugin.xml
+ */
+public class UpgradeXmlFileVersionHandler
+ extends AbstractHandler
{
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection
@@ -35,11 +39,9 @@ public class UpgradeXmlFileVersionHandler extends AbstractHandler
}
protected void upgradeXmlFileVersion(Object selectedObject) {
- JpaXmlResource xmlResource =
- (JpaXmlResource) Platform.getAdapterManager().getAdapter(selectedObject, JpaXmlResource.class);
+ JpaXmlResource xmlResource = PlatformTools.getAdapter(selectedObject, JpaXmlResource.class);
if (xmlResource == null) {
- XmlFile xmlFile =
- (XmlFile) Platform.getAdapterManager().getAdapter(selectedObject, XmlFile.class);
+ XmlFile xmlFile = PlatformTools.getAdapter(selectedObject, XmlFile.class);
if (xmlFile != null) {
xmlResource = xmlFile.getXmlResource();
}
@@ -48,16 +50,15 @@ public class UpgradeXmlFileVersionHandler extends AbstractHandler
return;
}
- final JpaRootEObject root = xmlResource.getRootObject();
+ JpaRootEObject root = xmlResource.getRootObject();
IContentType contentType = xmlResource.getContentType();
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(xmlResource.getProject());
- final String newVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(contentType).getVersion();
+ JpaProject jpaProject = this.getJpaProject(xmlResource.getFile().getProject());
+ String newVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(contentType).getVersion();
+ root.setVersion(newVersion);
+ xmlResource.save();
+ }
- xmlResource.modify(
- new Runnable() {
- public void run() {
- root.setVersion(newVersion);
- }
- });
+ private JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractEntityMappingsDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractEntityMappingsDetailsProvider.java
index 163c5f8163..1f281c3c81 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractEntityMappingsDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractEntityMappingsDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2009 Oracle. All rights reserved.
+* Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.jpa.ui.internal.details;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
public abstract class AbstractEntityMappingsDetailsProvider
@@ -24,7 +24,7 @@ public abstract class AbstractEntityMappingsDetailsProvider
public final boolean providesDetails(JpaStructureNode structureNode) {
- return Tools.valuesAreEqual(structureNode.getId(), OrmStructureNodes.ENTITY_MAPPINGS_ID)
+ return Tools.valuesAreEqual(structureNode.getType(), EntityMappings.class)
&& providesDetails(structureNode.getResourceType());
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractJpaDetailsPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractJpaDetailsPage.java
index 92261db5f3..c8d117a818 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractJpaDetailsPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractJpaDetailsPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,9 +15,10 @@ import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueMo
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.internal.platform.JpaPlatformUiRegistry;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
/**
* The base class for the details view.
@@ -29,25 +30,23 @@ import org.eclipse.swt.widgets.Composite;
*/
public abstract class AbstractJpaDetailsPage<T extends JpaStructureNode>
extends Pane<T>
- implements JpaDetailsPage<T>
+ implements JpaDetailsPageManager<T>
{
- /**
- * Creates a new <code>BaseJpaDetailsPage</code>.
- *
- * @param parent The parent container
- * @param widgetFactory The factory used to create various common widgets
- */
protected AbstractJpaDetailsPage(Composite parent, WidgetFactory widgetFactory) {
super(new SimplePropertyValueModel<T>(), parent, widgetFactory);
}
+ public Control getPage() {
+ return this.getControl();
+ }
+
protected JpaPlatformUi getJpaPlatformUi() {
- String platformId = getSubject().getJpaProject().getJpaPlatform().getId();
- return JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
+ return (JpaPlatformUi) getSubject().getJpaPlatform().getAdapter(JpaPlatformUi.class);
}
- public final void setSubject(T subject) {
+ @SuppressWarnings("unchecked")
+ public final void setSubject(Object subject) {
WritablePropertyValueModel<T> subjectHolder = (WritablePropertyValueModel<T>) getSubjectHolder();
- subjectHolder.setValue(subject);
+ subjectHolder.setValue((T) subject);
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractOverridesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractOverridesComposite.java
index 8446dc0b8f..ec80072431 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractOverridesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractOverridesComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -23,8 +23,6 @@ import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.Transformer;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
@@ -166,10 +164,10 @@ public abstract class AbstractOverridesComposite<T extends JpaContextNode>
}
private PropertyValueModel<Boolean> buildOverrideBooleanHolder(PropertyValueModel<? extends ReadOnlyOverride> overrideHolder) {
- return new CachingTransformationPropertyValueModel<ReadOnlyOverride, Boolean>(overrideHolder) {
+ return new TransformationPropertyValueModel<ReadOnlyOverride, Boolean>(overrideHolder) {
@Override
- protected Boolean transform_(ReadOnlyOverride value) {
- return Boolean.valueOf(!value.isVirtual());
+ protected Boolean transform_(ReadOnlyOverride v) {
+ return Boolean.valueOf( ! v.isVirtual());
}
};
}
@@ -203,8 +201,8 @@ public abstract class AbstractOverridesComposite<T extends JpaContextNode>
private WritablePropertyValueModel<ReadOnlyAssociationOverride> buildAssociationOverrideHolder() {
return new TransformationWritablePropertyValueModel<ReadOnlyOverride, ReadOnlyAssociationOverride>(this.selectedOverrideHolder) {
@Override
- protected ReadOnlyAssociationOverride transform_(ReadOnlyOverride value) {
- return (value instanceof ReadOnlyAssociationOverride) ? (ReadOnlyAssociationOverride) value : null;
+ protected ReadOnlyAssociationOverride transform_(ReadOnlyOverride v) {
+ return (v instanceof ReadOnlyAssociationOverride) ? (ReadOnlyAssociationOverride) v : null;
}
};
}
@@ -212,8 +210,8 @@ public abstract class AbstractOverridesComposite<T extends JpaContextNode>
private WritablePropertyValueModel<ReadOnlyAttributeOverride> buildAttributeOverrideHolder() {
return new TransformationWritablePropertyValueModel<ReadOnlyOverride, ReadOnlyAttributeOverride>(this.selectedOverrideHolder) {
@Override
- protected ReadOnlyAttributeOverride transform_(ReadOnlyOverride value) {
- return (value instanceof ReadOnlyAttributeOverride) ? (ReadOnlyAttributeOverride) value : null;
+ protected ReadOnlyAttributeOverride transform_(ReadOnlyOverride v) {
+ return (v instanceof ReadOnlyAttributeOverride) ? (ReadOnlyAttributeOverride) v : null;
}
};
}
@@ -254,15 +252,15 @@ public abstract class AbstractOverridesComposite<T extends JpaContextNode>
}
private WritablePropertyValueModel<Boolean> buildOverrideVirtualOverrideHolder() {
- return new CachingTransformationWritablePropertyValueModel<ReadOnlyOverride, Boolean>(this.selectedOverrideHolder) {
+ return new TransformationWritablePropertyValueModel<ReadOnlyOverride, Boolean>(this.selectedOverrideHolder) {
@Override
public void setValue(Boolean value) {
updateOverride(value.booleanValue());
}
@Override
- protected Boolean transform_(ReadOnlyOverride value) {
- return Boolean.valueOf(!value.isVirtual());
+ protected Boolean transform_(ReadOnlyOverride v) {
+ return Boolean.valueOf( ! v.isVirtual());
}
};
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java
index 66b2b626bd..9509b50428 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/AbstractPrimaryKeyJoinColumnsComposite.java
@@ -321,7 +321,7 @@ public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity> e
@Override
protected Boolean buildValue() {
- return listHolder.size() > 0;
+ return listModel.size() > 0;
}
public void setValue(Boolean value) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java
index c00a0c46d6..21eae43d60 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinTableComposite.java
@@ -13,12 +13,13 @@ import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyWritablePropertyValueModelWrapper;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.StateChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -340,7 +341,7 @@ public class JoinTableComposite
@Override
protected Boolean buildValue() {
- return Boolean.valueOf(this.listHolder.size() > 0);
+ return Boolean.valueOf(this.listModel.size() > 0);
}
public void setValue(Boolean value) {
@@ -350,9 +351,9 @@ public class JoinTableComposite
private class InverseJoinColumnPaneEnablerHolder
- extends CachingTransformationPropertyValueModel<ReadOnlyJoinTable, Boolean>
+ extends TransformationPropertyValueModel<ReadOnlyJoinTable, Boolean>
{
- private StateChangeListener stateChangeListener;
+ private StateChangeListener stateListener;
public InverseJoinColumnPaneEnablerHolder() {
@@ -360,44 +361,43 @@ public class JoinTableComposite
new ValueListAdapter<ReadOnlyJoinTable>(
new ReadOnlyWritablePropertyValueModelWrapper<ReadOnlyJoinTable>(getSubjectHolder()),
ReadOnlyJoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST));
- this.stateChangeListener = buildStateChangeListener();
+ this.stateListener = new StateListener();
}
-
-
- private StateChangeListener buildStateChangeListener() {
- return new StateChangeListener() {
- public void stateChanged(StateChangeEvent event) {
- valueStateChanged();
- }
- };
+
+ class StateListener
+ extends StateChangeAdapter
+ {
+ @Override
+ public void stateChanged(StateChangeEvent event) {
+ wrappedValueStateChanged();
+ }
}
- void valueStateChanged() {
- Object oldValue = this.cachedValue;
- Object newValue = transformNew(this.valueHolder.getValue());
- firePropertyChanged(VALUE, oldValue, newValue);
+ void wrappedValueStateChanged() {
+ Object old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = this.transform(this.valueModel.getValue()));
}
@Override
- protected Boolean transform(ReadOnlyJoinTable value) {
- return (value == null) ? Boolean.FALSE : super.transform(value);
+ protected Boolean transform(ReadOnlyJoinTable table) {
+ return (table == null) ? Boolean.FALSE : super.transform(table);
}
@Override
- protected Boolean transform_(ReadOnlyJoinTable value) {
- boolean virtual = JoinTableComposite.this.tableIsVirtual(value);
- return Boolean.valueOf(! virtual && value.getSpecifiedInverseJoinColumnsSize() > 0);
+ protected Boolean transform_(ReadOnlyJoinTable table) {
+ boolean virtual = JoinTableComposite.this.tableIsVirtual(table);
+ return Boolean.valueOf(! virtual && table.getSpecifiedInverseJoinColumnsSize() > 0);
}
@Override
protected void engageModel() {
super.engageModel();
- this.valueHolder.addStateChangeListener(this.stateChangeListener);
+ this.valueModel.addStateChangeListener(this.stateListener);
}
@Override
protected void disengageModel() {
- this.valueHolder.removeStateChangeListener(this.stateChangeListener);
+ this.valueModel.removeStateChangeListener(this.stateListener);
super.disengageModel();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsComposite.java
index 722ca90970..d1a758dc6b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsComposite.java
@@ -12,8 +12,8 @@ package org.eclipse.jpt.jpa.ui.internal.details;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyWritablePropertyValueModelWrapper;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
@@ -144,58 +144,56 @@ public class JoiningStrategyJoinColumnsComposite
stateObject.updateJoinColumn(stateObject.getJoinColumn());
}
- private class JoinColumnPaneEnablerHolder
- extends CachingTransformationPropertyValueModel<ReadOnlyJoinColumnRelationshipStrategy, Boolean>
+ /* CU private */ class JoinColumnPaneEnablerHolder
+ extends TransformationPropertyValueModel<ReadOnlyJoinColumnRelationshipStrategy, Boolean>
{
private StateChangeListener stateChangeListener;
-
- public JoinColumnPaneEnablerHolder() {
+ JoinColumnPaneEnablerHolder() {
super(
new ValueListAdapter<ReadOnlyJoinColumnRelationshipStrategy>(
new ReadOnlyWritablePropertyValueModelWrapper<ReadOnlyJoinColumnRelationshipStrategy>(getSubjectHolder()),
- ReadOnlyJoinColumnRelationshipStrategy.SPECIFIED_JOIN_COLUMNS_LIST));
- this.stateChangeListener = buildStateChangeListener();
+ ReadOnlyJoinColumnRelationshipStrategy.SPECIFIED_JOIN_COLUMNS_LIST
+ )
+ );
+ this.stateChangeListener = this.buildStateChangeListener();
}
private StateChangeListener buildStateChangeListener() {
return new StateChangeListener() {
public void stateChanged(StateChangeEvent event) {
- valueStateChanged();
+ JoinColumnPaneEnablerHolder.this.valueStateChanged();
}
};
}
void valueStateChanged() {
- Object oldValue = this.cachedValue;
- Object newValue = transformNew(this.valueHolder.getValue());
- firePropertyChanged(VALUE, oldValue, newValue);
+ Object old = this.value;
+ this.value = this.transform(this.valueModel.getValue());
+ this.firePropertyChanged(VALUE, old, this.value);
}
@Override
- protected Boolean transform(ReadOnlyJoinColumnRelationshipStrategy value) {
- if (value == null) {
- return Boolean.FALSE;
- }
- return super.transform(value);
+ protected Boolean transform(ReadOnlyJoinColumnRelationshipStrategy v) {
+ return (v == null) ? Boolean.FALSE : super.transform(v);
}
@Override
- protected Boolean transform_(ReadOnlyJoinColumnRelationshipStrategy value) {
- boolean virtual = value.getRelationship().isVirtual();
- return Boolean.valueOf(! virtual && value.getSpecifiedJoinColumnsSize() > 0);
+ protected Boolean transform_(ReadOnlyJoinColumnRelationshipStrategy v) {
+ boolean virtual = v.getRelationship().isVirtual();
+ return Boolean.valueOf(! virtual && v.getSpecifiedJoinColumnsSize() > 0);
}
@Override
protected void engageModel() {
super.engageModel();
- this.valueHolder.addStateChangeListener(this.stateChangeListener);
+ this.valueModel.addStateChangeListener(this.stateChangeListener);
}
@Override
protected void disengageModel() {
- this.valueHolder.removeStateChangeListener(this.stateChangeListener);
+ this.valueModel.removeStateChangeListener(this.stateChangeListener);
super.disengageModel();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java
index c08ab5ccd5..8f399998e9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoiningStrategyJoinColumnsWithOverrideOptionComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -104,7 +104,7 @@ public class JoiningStrategyJoinColumnsWithOverrideOptionComposite
@Override
protected Boolean buildValue() {
- return Boolean.valueOf(this.listHolder.size() > 0);
+ return Boolean.valueOf(this.listModel.size() > 0);
}
public void setValue(Boolean value) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MapAsComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MapAsComposite.java
index 4d4b5d968d..86fc2fad6d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MapAsComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MapAsComposite.java
@@ -100,8 +100,7 @@ public abstract class MapAsComposite<T extends JpaNode> extends Pane<T> {
* @return The UI platform of the JPT plug-in
*/
protected JpaPlatformUi getJpaPlatformUi() {
- String platformId = getSubject().getJpaProject().getJpaPlatform().getId();
- return JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
+ return (JpaPlatformUi) getSubject().getJpaProject().getJpaPlatform().getAdapter(JpaPlatformUi.class);
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
index 1df7456098..342ff33576 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
@@ -391,7 +391,7 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends Pane<ReadOnl
protected boolean buildValue_() {
ReadOnlySecondaryTable table = getSubject();
- return (table != null) && ! table.isVirtual() && listHolder.size() > 0;
+ return (table != null) && ! table.isVirtual() && listModel.size() > 0;
}
public void setValue(Boolean value) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java
index 38e81fcad5..fdb6e5a9d0 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/ReferenceTableComposite.java
@@ -14,10 +14,10 @@ import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ReadOnlyWritablePropertyValueModelWrapper;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ValueListAdapter;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
@@ -354,7 +354,7 @@ public abstract class ReferenceTableComposite<T extends ReadOnlyReferenceTable>
@Override
protected Boolean buildValue() {
- return Boolean.valueOf(this.listHolder.size() > 0);
+ return Boolean.valueOf(this.listModel.size() > 0);
}
public void setValue(Boolean value) {
@@ -363,17 +363,19 @@ public abstract class ReferenceTableComposite<T extends ReadOnlyReferenceTable>
}
- private class JoinColumnPaneEnablerHolder
- extends CachingTransformationPropertyValueModel<T, Boolean>
+ /* CU private */ class JoinColumnPaneEnablerHolder
+ extends TransformationPropertyValueModel<T, Boolean>
{
private StateChangeListener stateChangeListener;
- public JoinColumnPaneEnablerHolder() {
+ JoinColumnPaneEnablerHolder() {
super(
new ValueListAdapter<T>(
new ReadOnlyWritablePropertyValueModelWrapper<T>(getSubjectHolder()),
- ReadOnlyReferenceTable.SPECIFIED_JOIN_COLUMNS_LIST));
+ ReadOnlyReferenceTable.SPECIFIED_JOIN_COLUMNS_LIST
+ )
+ );
this.stateChangeListener = buildStateChangeListener();
}
@@ -381,40 +383,36 @@ public abstract class ReferenceTableComposite<T extends ReadOnlyReferenceTable>
private StateChangeListener buildStateChangeListener() {
return new StateChangeListener() {
public void stateChanged(StateChangeEvent event) {
- valueStateChanged();
+ JoinColumnPaneEnablerHolder.this.valueStateChanged();
}
};
}
void valueStateChanged() {
- Object oldValue = this.cachedValue;
- Object newValue = transformNew(this.valueHolder.getValue());
- firePropertyChanged(VALUE, oldValue, newValue);
+ Object old = this.value;
+ this.firePropertyChanged(VALUE, old, this.value = this.transform(this.valueModel.getValue()));
}
@Override
- protected Boolean transform(T value) {
- if (value == null) {
- return Boolean.FALSE;
- }
- return super.transform(value);
+ protected Boolean transform(T v) {
+ return (v == null) ? Boolean.FALSE : super.transform(v);
}
@Override
- protected Boolean transform_(T value) {
- boolean virtual = ReferenceTableComposite.this.tableIsVirtual(value);
- return Boolean.valueOf(! virtual && value.getSpecifiedJoinColumnsSize() > 0);
+ protected Boolean transform_(T v) {
+ boolean virtual = ReferenceTableComposite.this.tableIsVirtual(v);
+ return Boolean.valueOf(! virtual && v.getSpecifiedJoinColumnsSize() > 0);
}
@Override
protected void engageModel() {
super.engageModel();
- this.valueHolder.addStateChangeListener(this.stateChangeListener);
+ this.valueModel.addStateChangeListener(this.stateChangeListener);
}
@Override
protected void disengageModel() {
- this.valueHolder.removeStateChangeListener(this.stateChangeListener);
+ this.valueModel.removeStateChangeListener(this.stateChangeListener);
super.disengageModel();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/AbstractJavaResourceUiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/AbstractJavaResourceUiDefinition.java
index 6fc1e31081..7fc8e2dc81 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/AbstractJavaResourceUiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/AbstractJavaResourceUiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,6 +16,8 @@ import java.util.ListIterator;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayListIterator;
@@ -32,8 +34,8 @@ import org.eclipse.jpt.jpa.ui.details.java.DefaultJavaTypeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.java.JavaAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.java.JavaTypeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.java.JavaUiFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.JavaResourceModelStructureProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.structure.JavaStructureItemContentProviderFactory;
+import org.eclipse.jpt.jpa.ui.internal.structure.JavaStructureItemLabelProviderFactory;
import org.eclipse.swt.widgets.Composite;
/**
@@ -70,10 +72,16 @@ public abstract class AbstractJavaResourceUiDefinition
return resourceType.equals(JptCommonCorePlugin.JAVA_SOURCE_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return JavaResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return STRUCTURE_VIEW_FACTORY_PROVIDER;
}
+ public static final ItemTreeStateProviderFactoryProvider STRUCTURE_VIEW_FACTORY_PROVIDER =
+ new SimpleItemTreeStateProviderFactoryProvider(
+ JavaStructureItemContentProviderFactory.instance(),
+ JavaStructureItemLabelProviderFactory.instance()
+ );
+
// ********** type mapping ui definitions **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentAttributeDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentAttributeDetailsProvider.java
index b5b7691d46..1e009461ec 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentAttributeDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentAttributeDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,8 +14,7 @@ import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.java.JavaStructureNodes;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.swt.widgets.Composite;
@@ -47,11 +46,11 @@ public class JavaPersistentAttributeDetailsProvider
public boolean providesDetails(JpaStructureNode structureNode) {
- return Tools.valuesAreEqual(structureNode.getId(), JavaStructureNodes.PERSISTENT_ATTRIBUTE_ID)
+ return Tools.valuesAreEqual(structureNode.getType(), JavaPersistentAttribute.class)
&& structureNode.getResourceType().getContentType().equals(JptCommonCorePlugin.JAVA_SOURCE_CONTENT_TYPE);
}
- public JpaDetailsPage<JavaPersistentAttribute> buildDetailsPage(
+ public JpaDetailsPageManager<JavaPersistentAttribute> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentTypeDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentTypeDetailsProvider.java
index f44c213cce..ff85ccc133 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentTypeDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/java/JavaPersistentTypeDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,8 +14,8 @@ import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.PersistentType;
-import org.eclipse.jpt.jpa.core.context.java.JavaStructureNodes;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.PersistentTypeDetailsPage;
import org.eclipse.swt.widgets.Composite;
@@ -48,11 +48,11 @@ public class JavaPersistentTypeDetailsProvider
public boolean providesDetails(JpaStructureNode structureNode) {
- return Tools.valuesAreEqual(structureNode.getId(), JavaStructureNodes.PERSISTENT_TYPE_ID)
+ return Tools.valuesAreEqual(structureNode.getType(), JavaPersistentType.class)
&& structureNode.getResourceType().getContentType().equals(JptCommonCorePlugin.JAVA_SOURCE_CONTENT_TYPE);
}
- public JpaDetailsPage<PersistentType> buildDetailsPage(
+ public JpaDetailsPageManager<PersistentType> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsDetailsProvider.java
index 0d9435573c..c6fe8e4a0f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/EntityMappingsDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,13 +13,13 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.AbstractEntityMappingsDetailsProvider;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible for creating the {@link JpaDetailsPage}
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
* when the information comes from the XML file (either from the persistence
* configuration or from the Mappings Descriptor).
*/
@@ -51,7 +51,7 @@ public class EntityMappingsDetailsProvider
return resourceType.equals(JptJpaCorePlugin.ORM_XML_1_0_RESOURCE_TYPE);
}
- public JpaDetailsPage<EntityMappings> buildDetailsPage(
+ public JpaDetailsPageManager<EntityMappings> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentAttributeDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentAttributeDetailsProvider.java
index 9527d29496..b4411fcaf4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentAttributeDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentAttributeDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,14 +13,14 @@ import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible for creating the {@link JpaDetailsPage}
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
* when the information comes from the XML file (either from the persistence
* configuration or from the Mappings Descriptor).
*/
@@ -48,11 +48,11 @@ public class OrmPersistentAttributeDetailsProvider
public boolean providesDetails(JpaStructureNode structureNode) {
- return Tools.valuesAreEqual(structureNode.getId(), OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID)
+ return Tools.valuesAreEqual(structureNode.getType(), OrmPersistentAttribute.class)
&& structureNode.getResourceType().getContentType().isKindOf(JptJpaCorePlugin.MAPPING_FILE_CONTENT_TYPE);
}
- public JpaDetailsPage<OrmReadOnlyPersistentAttribute> buildDetailsPage(
+ public JpaDetailsPageManager<OrmReadOnlyPersistentAttribute> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentTypeDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentTypeDetailsProvider.java
index 4dd48709d9..c9e82513d4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentTypeDetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmPersistentTypeDetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,14 +14,14 @@ import org.eclipse.jpt.common.utility.internal.Tools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.PersistentType;
-import org.eclipse.jpt.jpa.core.context.orm.OrmStructureNodes;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.PersistentTypeDetailsPage;
import org.eclipse.swt.widgets.Composite;
/**
- * This provider is responsible for creating the {@link JpaDetailsPage}
+ * This provider is responsible for creating the {@link JpaDetailsPageManager}
* when the information comes from the XML file (either from the persistence
* configuration or from the Mappings Descriptor).
*/
@@ -49,11 +49,11 @@ public class OrmPersistentTypeDetailsProvider
public boolean providesDetails(JpaStructureNode structureNode) {
- return Tools.valuesAreEqual(structureNode.getId(), OrmStructureNodes.PERSISTENT_TYPE_ID)
+ return Tools.valuesAreEqual(structureNode.getType(), OrmPersistentType.class)
&& structureNode.getResourceType().getContentType().isKindOf(JptJpaCorePlugin.MAPPING_FILE_CONTENT_TYPE);
}
- public JpaDetailsPage<PersistentType> buildDetailsPage(
+ public JpaDetailsPageManager<PersistentType> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmXmlUiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmXmlUiDefinition.java
index f2758cb785..19af51e450 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmXmlUiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/orm/OrmXmlUiDefinition.java
@@ -1,17 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
@@ -19,10 +20,11 @@ import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmAttributeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmTypeMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.orm.OrmXmlUiFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.OrmResourceModelStructureProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.structure.OrmStructureItemContentProviderFactory;
+import org.eclipse.jpt.jpa.ui.internal.structure.OrmStructureItemLabelProviderFactory;
-public class OrmXmlUiDefinition extends AbstractOrmXmlResourceUiDefinition
+public class OrmXmlUiDefinition
+ extends AbstractOrmXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new OrmXmlUiDefinition();
@@ -53,10 +55,16 @@ public class OrmXmlUiDefinition extends AbstractOrmXmlResourceUiDefinition
return resourceType.equals(JptJpaCorePlugin.ORM_XML_1_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return OrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return STRUCTURE_VIEW_FACTORY_PROVIDER;
}
+ public static final ItemTreeStateProviderFactoryProvider STRUCTURE_VIEW_FACTORY_PROVIDER =
+ new SimpleItemTreeStateProviderFactoryProvider(
+ OrmStructureItemContentProviderFactory.instance(),
+ OrmStructureItemLabelProviderFactory.instance()
+ );
+
@Override
protected void addOrmAttributeMappingUiDefinitionsTo(
List<OrmAttributeMappingUiDefinition<? extends AttributeMapping>> definitions) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java
index b35e5c58e7..3b6b47cd0b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -108,7 +108,7 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog
validate();
}
});
- JpaPlatformUi jpaPlatformUi = JptJpaUiPlugin.instance().getJpaPlatformUi(this.unmappedPersistentAttribute.getJpaProject().getJpaPlatform());
+ JpaPlatformUi jpaPlatformUi = (JpaPlatformUi) this.unmappedPersistentAttribute.getJpaProject().getAdapter(JpaPlatformUi.class);
mappingCombo.setInput(jpaPlatformUi);
mappingCombo.getCombo().select(0); // select Basic to begin
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/PersistenceEditor.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/PersistenceEditor.java
index 77cc201fe1..d08bbadc07 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/PersistenceEditor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/editors/PersistenceEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,7 +10,7 @@
package org.eclipse.jpt.jpa.ui.internal.editors;
import java.util.ListIterator;
-
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
@@ -24,7 +24,6 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.common.ui.internal.widgets.FormWidgetFactory;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
@@ -34,7 +33,6 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
@@ -65,13 +63,12 @@ import org.eclipse.wst.sse.ui.StructuredTextEditor;
* The pages shown before the XML source editor are retrieved from the
* <code>JpaUiFactory</code>.
*
- * @see JpaUiFactory
- *
* @version 2.3
* @since 2.0
*/
@SuppressWarnings("nls")
-public class PersistenceEditor extends FormEditor
+public class PersistenceEditor
+ extends FormEditor
{
/**
* The XML text editor.
@@ -89,7 +86,7 @@ public class PersistenceEditor extends FormEditor
*/
private WidgetFactory widgetFactory;
- private final ResourceManager resourceManager;
+ final ResourceManager resourceManager;
/**
* Creates a new <code>PersistenceEditor</code>.
@@ -99,20 +96,16 @@ public class PersistenceEditor extends FormEditor
this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
initialize();
}
-
+
+ /**
+ * Delegate to the {@link #editor} if necessary.
+ */
@Override
- @SuppressWarnings("unchecked")
- public Object getAdapter(Class adapterClass) {
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapterClass) {
Object adapter = super.getAdapter(adapterClass);
- if (adapter == null) {
- adapter = editor.getAdapter(adapterClass);
- }
- return adapter;
+ return (adapter != null) ? adapter : this.editor.getAdapter(adapterClass);
}
- /**
- * {@inheritDoc}
- */
@Override
protected void addPages() {
addPersistenceUnitPages();
@@ -140,19 +133,18 @@ public class PersistenceEditor extends FormEditor
if (resourceType == null) {
return; // might not ever get here... (if we have a p.xml, it probably has a resource type...)
}
- String platformId = jpaProject.getJpaPlatform().getId();
- JpaPlatformUi jpaPlatformUI = JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
+ JpaPlatformUi jpaPlatformUI = (JpaPlatformUi) jpaProject.getJpaPlatform().getAdapter(JpaPlatformUi.class);
PersistenceXmlResourceUiDefinition definition =
(PersistenceXmlResourceUiDefinition) jpaPlatformUI.getResourceUiDefinition(resourceType);
- ListIterator<JpaPageComposite> pages = definition.buildPersistenceUnitComposites(
+ ListIterator<JpaPageComposite> puPages = definition.buildPersistenceUnitComposites(
buildPersistenceUnitHolder(),
getContainer(),
this.widgetFactory
);
- while (pages.hasNext()) {
- JpaPageComposite page = pages.next();
+ while (puPages.hasNext()) {
+ JpaPageComposite page = puPages.next();
try {
FormPage formPage = new Page(page);
@@ -184,10 +176,10 @@ public class PersistenceEditor extends FormEditor
}
private PropertyValueModel<JpaProject> buildJpaProjectHolder() {
- return new CachingTransformationPropertyValueModel<IFileEditorInput, JpaProject>(this.editorInputHolder) {
+ return new TransformationPropertyValueModel<IFileEditorInput, JpaProject>(this.editorInputHolder) {
@Override
protected JpaProject transform_(IFileEditorInput fileEditorInput) {
- return JptJpaCorePlugin.getJpaProject(fileEditorInput.getFile().getProject());
+ return PersistenceEditor.this.getJpaProject(fileEditorInput.getFile().getProject());
}
};
}
@@ -205,7 +197,7 @@ public class PersistenceEditor extends FormEditor
return new ListPropertyValueModelAdapter<PersistenceUnit>(buildPersistenceUnitListHolder()) {
@Override
protected PersistenceUnit buildValue() {
- return listHolder.size() > 0 ? (PersistenceUnit) listHolder.get(0) : null;
+ return listModel.size() > 0 ? (PersistenceUnit) listModel.get(0) : null;
}
};
}
@@ -262,6 +254,7 @@ public class PersistenceEditor extends FormEditor
@Override
public void doSaveAs() {
+ // do nothing
}
@Override
@@ -299,15 +292,20 @@ public class PersistenceEditor extends FormEditor
* @return The JPA project
*/
protected JpaProject getJpaProject() {
- return JptJpaCorePlugin.getJpaProject(getEditorInput().getFile().getProject());
+ return this.getJpaProject(getEditorInput().getFile().getProject());
+ }
+
+ protected JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
}
/**
* This extension over <code>FormPage</code> simply complete the layout by
* using the <code>JpaPageComposite</code>'s control as its form content.
*/
- private class Page extends FormPage {
-
+ class Page
+ extends FormPage
+ {
/**
* The wrapped page that actually contains the widgets to show with this
* form page.
@@ -321,7 +319,7 @@ public class PersistenceEditor extends FormEditor
*
* @param page The wrapped <code>JpaPageComposite</code>
*/
- private Page(JpaPageComposite page) {
+ Page(JpaPageComposite page) {
super(PersistenceEditor.this,
page.getClass().getName(),
@@ -413,9 +411,10 @@ public class PersistenceEditor extends FormEditor
}
}
- private class HelpAction extends Action {
-
- private final String helpID;
+ private class HelpAction
+ extends Action
+ {
+ final String helpID;
HelpAction(String helpID) {
super(JptUiPersistenceMessages.PersistenceEditor_page_help,
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/JarFileItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/JarFileItemLabelProvider.java
deleted file mode 100644
index 9bb9e7cdeb..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/JarFileItemLabelProvider.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.jface;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.java.JarFile;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.swt.graphics.Image;
-
-public class JarFileItemLabelProvider extends AbstractItemLabelProvider
-{
- public JarFileItemLabelProvider(
- JarFile jarFile, DelegatingContentAndLabelProvider labelProvider) {
- super(jarFile, labelProvider);
- }
-
- @Override
- public JarFile getModel() {
- return (JarFile) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.JAR_FILE));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(getModel().getResource().getName());
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(getModel().getResource().getName());
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getParent().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/XmlMappingFileViewerFilter.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/XmlMappingFileViewerFilter.java
index b9f63a083e..b094cd4453 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/XmlMappingFileViewerFilter.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jface/XmlMappingFileViewerFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,7 +16,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
@@ -50,7 +50,8 @@ public class XmlMappingFileViewerFilter
else if (element instanceof IContainer) {
IContainer container = (IContainer) element;
IProject project = this.jpaProject.getProject();
- if (JptCommonCorePlugin.getResourceLocator(project).acceptResourceLocation(project, container)) {
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ if (locator.resourceLocationIsValid(container)) {
try {
for (IResource resource : container.members()) {
if (select(viewer, container, resource)) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0FlagTransformer.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0FlagTransformer.java
new file mode 100644
index 0000000000..3e71baf8ef
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0FlagTransformer.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpa2;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.Transformer;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaNode;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+
+/**
+ * Transform a JPA node into a
+ * flag indicating whether the node supports JPA 2.0.
+ * The flag is <code>null</code> if the JPA node is <code>null</code>.
+ */
+public final class Jpa2_0FlagTransformer<T extends JpaNode>
+ extends AbstractTransformer<T, Boolean>
+ implements Serializable
+{
+ /**
+ * Convert the specified JPA node model into a boolean model that returns
+ * whether the JPA node supports JPA 2.0.
+ * The flag is <code>null</code> if the JPA node is <code>null</code>.
+ */
+ public static <T extends JpaNode> PropertyValueModel<Boolean> convertToFlagModel(PropertyValueModel<T> jpaNodeModel) {
+ return new TransformationPropertyValueModel<T, Boolean>(jpaNodeModel, Jpa2_0FlagTransformer.<T>instance());
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static final Transformer INSTANCE = new Jpa2_0FlagTransformer();
+
+ @SuppressWarnings("unchecked")
+ public static <T extends JpaNode> Transformer<T, Boolean> instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private Jpa2_0FlagTransformer() {
+ super();
+ }
+
+ @Override
+ protected Boolean transform_(T jpaNode) {
+ return Boolean.valueOf(JptJpaCorePlugin.nodeIsJpa2_0Compatible(jpaNode));
+ }
+
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0ProjectFlagModel.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0ProjectFlagModel.java
deleted file mode 100644
index 182674ef75..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/Jpa2_0ProjectFlagModel.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.jpa2;
-
-import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.JpaNode;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-
-/**
- * Flag indicating whether the JPA project supports JPA 2.0.
- */
-public class Jpa2_0ProjectFlagModel<T extends JpaNode>
- extends TransformationPropertyValueModel<T, Boolean>
-{
- public Jpa2_0ProjectFlagModel(PropertyValueModel<T> jpaProjectModel) {
- super(jpaProjectModel);
- }
-
- @Override
- protected Boolean transform_(T value) {
- return Boolean.valueOf(JptJpaCorePlugin.nodeIsJpa2_0Compatible(value));
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/EntityMappings2_0DetailsProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/EntityMappings2_0DetailsProvider.java
index 128a9e6b54..cda365b761 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/EntityMappings2_0DetailsProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/EntityMappings2_0DetailsProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2009 Oracle. All rights reserved.
+* Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -13,7 +13,7 @@ import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.internal.details.AbstractEntityMappingsDetailsProvider;
import org.eclipse.swt.widgets.Composite;
@@ -49,7 +49,7 @@ public class EntityMappings2_0DetailsProvider
return resourceType.equals(JptJpaCorePlugin.ORM_XML_2_0_RESOURCE_TYPE);
}
- public JpaDetailsPage<EntityMappings> buildDetailsPage(
+ public JpaDetailsPageManager<EntityMappings> buildDetailsPageManager(
Composite parent,
WidgetFactory widgetFactory) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/OrmXml2_0UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/OrmXml2_0UiDefinition.java
index c9bd67284d..c3b0db29e3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/OrmXml2_0UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/details/orm/OrmXml2_0UiDefinition.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.jpa.ui.internal.jpa2.details.orm;
import java.util.List;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.TypeMapping;
@@ -32,11 +33,11 @@ import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToManyMappingUiDefiniti
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmOneToOneMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmTransientMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmVersionMappingUiDefinition;
+import org.eclipse.jpt.jpa.ui.internal.details.orm.OrmXmlUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.jpa2.GenericOrmXml2_0UiFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.OrmResourceModelStructureProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-public class OrmXml2_0UiDefinition extends AbstractOrmXmlResourceUiDefinition
+public class OrmXml2_0UiDefinition
+ extends AbstractOrmXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new OrmXml2_0UiDefinition();
@@ -67,8 +68,8 @@ public class OrmXml2_0UiDefinition extends AbstractOrmXmlResourceUiDefinition
return resourceType.equals(JptJpaCorePlugin.ORM_XML_2_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return OrmResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return OrmXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceXml2_0UiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceXml2_0UiDefinition.java
index c57412685f..d40763d589 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceXml2_0UiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/persistence/PersistenceXml2_0UiDefinition.java
@@ -1,24 +1,24 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.jpa2.persistence;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.persistence.details.AbstractPersistenceXmlResourceUiDefinition;
+import org.eclipse.jpt.jpa.ui.internal.persistence.details.PersistenceXmlUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.persistence.details.PersistenceXmlUiFactory;
-import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceResourceModelStructureProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-public class PersistenceXml2_0UiDefinition extends AbstractPersistenceXmlResourceUiDefinition
+public class PersistenceXml2_0UiDefinition
+ extends AbstractPersistenceXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new PersistenceXml2_0UiDefinition();
@@ -49,7 +49,7 @@ public class PersistenceXml2_0UiDefinition extends AbstractPersistenceXmlResourc
return resourceType.equals(JptJpaCorePlugin.PERSISTENCE_XML_2_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return PersistenceResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return PersistenceXmlUiDefinition.STRUCTURE_VIEW_FACTORY_PROVIDER;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/platform/generic/Generic2_0JpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/platform/generic/Generic2_0JpaPlatformUiFactory.java
index c18b25f18c..5351f6a3e1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/platform/generic/Generic2_0JpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpa2/platform/generic/Generic2_0JpaPlatformUiFactory.java
@@ -1,9 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -13,11 +13,11 @@ import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
import org.eclipse.jpt.jpa.ui.internal.jpa2.Generic2_0JpaPlatformUiProvider;
import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericJpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericNavigatorProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericJpaPlatformUiFactory;
-public class Generic2_0JpaPlatformUiFactory implements JpaPlatformUiFactory
+public class Generic2_0JpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
-
/**
* Zero arg constructor for extension point
*/
@@ -27,8 +27,8 @@ public class Generic2_0JpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new GenericJpaPlatformUi(
- new GenericNavigatorProvider(),
- Generic2_0JpaPlatformUiProvider.instance()
- );
+ GenericJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ Generic2_0JpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlJavaCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlJavaCompletionProposalComputer.java
index 1e88f98f75..ef062f909c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlJavaCompletionProposalComputer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlJavaCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -146,7 +146,7 @@ public final class JpaJpqlJavaCompletionProposalComputer extends JpqlCompletionP
IFile file = getCorrespondingResource(compilationUnit);
if (file == null) return Collections.emptyList();
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile jpaFile = (JpaFile) file.getAdapter(JpaFile.class);
if (jpaFile == null) return Collections.emptyList();
monitor.worked(80);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlSseCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlSseCompletionProposalComputer.java
index 4a307c9fc3..ef77e87353 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlSseCompletionProposalComputer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlSseCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -109,7 +109,7 @@ public final class JpaJpqlSseCompletionProposalComputer extends JpqlCompletionPr
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFile(buffer.getLocation());
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile jpaFile = (JpaFile) file.getAdapter(JpaFile.class);
if (jpaFile == null) return Collections.emptyList();
monitor.worked(80);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/listeners/SWTConnectionListenerWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/listeners/SWTConnectionListenerWrapper.java
index 9368bf286f..4c5a5e2ade 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/listeners/SWTConnectionListenerWrapper.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/listeners/SWTConnectionListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.listeners;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
import org.eclipse.jpt.jpa.db.Catalog;
import org.eclipse.jpt.jpa.db.Column;
import org.eclipse.jpt.jpa.db.ConnectionListener;
@@ -18,7 +20,6 @@ import org.eclipse.jpt.jpa.db.ForeignKey;
import org.eclipse.jpt.jpa.db.Schema;
import org.eclipse.jpt.jpa.db.Sequence;
import org.eclipse.jpt.jpa.db.Table;
-import org.eclipse.swt.widgets.Display;
/**
* Wrap another connection listener and forward events to it on the SWT
@@ -39,310 +40,298 @@ public class SWTConnectionListenerWrapper
}
public void opened(ConnectionProfile profile) {
- if (this.isExecutingOnUIThread()) {
- this.opened_(profile);
- } else {
- this.executeOnUIThread(this.buildOpenedRunnable(profile));
- }
- }
-
- public void modified(ConnectionProfile profile) {
- if (this.isExecutingOnUIThread()) {
- this.modified_(profile);
- } else {
- this.executeOnUIThread(this.buildModifiedRunnable(profile));
- }
- }
-
- public boolean okToClose(ConnectionProfile profile) {
- if (this.isExecutingOnUIThread()) {
- return this.okToClose_(profile);
- }
- this.executeOnUIThread(this.buildOkToCloseRunnable(profile));
- return true;
+ this.execute(new OpenedRunnable(profile));
}
- public void aboutToClose(ConnectionProfile profile) {
- if (this.isExecutingOnUIThread()) {
- this.aboutToClose_(profile);
- } else {
- this.executeOnUIThread(this.buildAboutToCloseRunnable(profile));
+ /* CU private */ class OpenedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ OpenedRunnable(ConnectionProfile profile) {
+ super();
+ this.profile = profile;
}
- }
-
- public void closed(ConnectionProfile profile) {
- if (this.isExecutingOnUIThread()) {
- this.closed_(profile);
- } else {
- this.executeOnUIThread(this.buildClosedRunnable(profile));
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.opened_(this.profile);
}
}
- public void databaseChanged(ConnectionProfile profile, Database database) {
- if (this.isExecutingOnUIThread()) {
- this.databaseChanged_(profile, database);
- } else {
- this.executeOnUIThread(this.buildDatabaseChangedRunnable(profile, database));
- }
+ void opened_(ConnectionProfile profile) {
+ this.listener.opened(profile);
}
- public void catalogChanged(ConnectionProfile profile, Catalog catalog) {
- if (this.isExecutingOnUIThread()) {
- this.catalogChanged_(profile, catalog);
- } else {
- this.executeOnUIThread(this.buildCatalogChangedRunnable(profile, catalog));
- }
+ public void modified(ConnectionProfile profile) {
+ this.execute(new ModifiedRunnable(profile));
}
- public void schemaChanged(ConnectionProfile profile, Schema schema) {
- if (this.isExecutingOnUIThread()) {
- this.schemaChanged_(profile, schema);
- } else {
- this.executeOnUIThread(this.buildSchemaChangedRunnable(profile, schema));
+ /* CU private */ class ModifiedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ ModifiedRunnable(ConnectionProfile profile) {
+ super();
+ this.profile = profile;
}
- }
-
- public void sequenceChanged(ConnectionProfile profile, Sequence sequence) {
- if (this.isExecutingOnUIThread()) {
- this.sequenceChanged_(profile, sequence);
- } else {
- this.executeOnUIThread(this.buildSequenceChangedRunnable(profile, sequence));
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.modified_(this.profile);
}
}
- public void tableChanged(ConnectionProfile profile, Table table) {
- if (this.isExecutingOnUIThread()) {
- this.tableChanged_(profile, table);
- } else {
- this.executeOnUIThread(this.buildTableChangedRunnable(profile, table));
- }
+ void modified_(ConnectionProfile profile) {
+ this.listener.modified(profile);
}
- public void columnChanged(ConnectionProfile profile, Column column) {
- if (this.isExecutingOnUIThread()) {
- this.columnChanged_(profile, column);
- } else {
- this.executeOnUIThread(this.buildColumnChangedRunnable(profile, column));
+ public boolean okToClose(ConnectionProfile profile) {
+ OkToCloseRunnable r = new OkToCloseRunnable(profile);
+ this.execute(r);
+ return r.result; // result is unpredictable...
+ }
+
+ /* CU private */ class OkToCloseRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ volatile boolean result = true;
+ OkToCloseRunnable(ConnectionProfile profile) {
+ super();
+ this.profile = profile;
}
- }
-
- public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey) {
- if (this.isExecutingOnUIThread()) {
- this.foreignKeyChanged_(profile, foreignKey);
- } else {
- this.executeOnUIThread(this.buildForeignKeyChangedRunnable(profile, foreignKey));
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.okToClose_(this.profile);
}
}
- private Runnable buildOpenedRunnable(final ConnectionProfile profile) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.opened_(profile);
- }
- @Override
- public String toString() {
- return "opened runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildModifiedRunnable(final ConnectionProfile profile) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.modified_(profile);
- }
- @Override
- public String toString() {
- return "modified runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildOkToCloseRunnable(final ConnectionProfile profile) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.okToClose_(profile);
- }
- @Override
- public String toString() {
- return "OK to close runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildAboutToCloseRunnable(final ConnectionProfile profile) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.aboutToClose_(profile);
- }
- @Override
- public String toString() {
- return "about to close runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildClosedRunnable(final ConnectionProfile profile) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.closed_(profile);
- }
- @Override
- public String toString() {
- return "closed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildDatabaseChangedRunnable(final ConnectionProfile profile, final Database database) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.databaseChanged_(profile, database);
- }
- @Override
- public String toString() {
- return "database changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildCatalogChangedRunnable(final ConnectionProfile profile, final Catalog catalog) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.catalogChanged_(profile, catalog);
- }
- @Override
- public String toString() {
- return "catalog changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildSchemaChangedRunnable(final ConnectionProfile profile, final Schema schema) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.schemaChanged_(profile, schema);
- }
- @Override
- public String toString() {
- return "schema changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildSequenceChangedRunnable(final ConnectionProfile profile, final Sequence sequence) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.sequenceChanged_(profile, sequence);
- }
- @Override
- public String toString() {
- return "sequence changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildTableChangedRunnable(final ConnectionProfile profile, final Table table) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.tableChanged_(profile, table);
- }
- @Override
- public String toString() {
- return "table changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildColumnChangedRunnable(final ConnectionProfile profile, final Column column) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.columnChanged_(profile, column);
- }
- @Override
- public String toString() {
- return "column changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private Runnable buildForeignKeyChangedRunnable(final ConnectionProfile profile, final ForeignKey foreignKey) {
- return new Runnable() {
- public void run() {
- SWTConnectionListenerWrapper.this.foreignKeyChanged_(profile, foreignKey);
- }
- @Override
- public String toString() {
- return "foreign key changed runnable"; //$NON-NLS-1$
- }
- };
- }
-
- private boolean isExecutingOnUIThread() {
- return Display.getCurrent() != null;
+ boolean okToClose_(ConnectionProfile profile) {
+ return this.listener.okToClose(profile);
}
- /**
- * {@link Display#asyncExec(Runnable)} seems to work OK;
- * but using {@link Display#syncExec(Runnable)} can somtimes make things
- * more predictable when debugging, at the risk of deadlocks.
- */
- private void executeOnUIThread(Runnable r) {
- Display.getDefault().asyncExec(r);
-// Display.getDefault().syncExec(r);
+ public void aboutToClose(ConnectionProfile profile) {
+ this.execute(new AboutToCloseRunnable(profile));
}
- void opened_(ConnectionProfile profile) {
- this.listener.opened(profile);
+ /* CU private */ class AboutToCloseRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ AboutToCloseRunnable(ConnectionProfile profile) {
+ super();
+ this.profile = profile;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.aboutToClose_(this.profile);
+ }
}
- void modified_(ConnectionProfile profile) {
- this.listener.modified(profile);
+ void aboutToClose_(ConnectionProfile profile) {
+ this.listener.aboutToClose(profile);
}
- boolean okToClose_(ConnectionProfile profile) {
- return this.listener.okToClose(profile);
+ public void closed(ConnectionProfile profile) {
+ this.execute(new ClosedRunnable(profile));
}
- void aboutToClose_(ConnectionProfile profile) {
- this.listener.aboutToClose(profile);
+ /* CU private */ class ClosedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ ClosedRunnable(ConnectionProfile profile) {
+ super();
+ this.profile = profile;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.closed_(this.profile);
+ }
}
void closed_(ConnectionProfile profile) {
this.listener.closed(profile);
}
+ public void databaseChanged(ConnectionProfile profile, Database database) {
+ this.execute(new DatabaseChangedRunnable(profile, database));
+ }
+
+ /* CU private */ class DatabaseChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final Database database;
+ DatabaseChangedRunnable(ConnectionProfile profile, Database database) {
+ super();
+ this.profile = profile;
+ this.database = database;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.databaseChanged_(this.profile, this.database);
+ }
+ }
+
void databaseChanged_(ConnectionProfile profile, Database database) {
this.listener.databaseChanged(profile, database);
}
+ public void catalogChanged(ConnectionProfile profile, Catalog catalog) {
+ this.execute(new CatalogChangedRunnable(profile, catalog));
+ }
+
+ /* CU private */ class CatalogChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final Catalog catalog;
+ CatalogChangedRunnable(ConnectionProfile profile, Catalog catalog) {
+ super();
+ this.profile = profile;
+ this.catalog = catalog;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.catalogChanged_(this.profile, this.catalog);
+ }
+ }
+
void catalogChanged_(ConnectionProfile profile, Catalog catalog) {
this.listener.catalogChanged(profile, catalog);
}
+ public void schemaChanged(ConnectionProfile profile, Schema schema) {
+ this.execute(new SchemaChangedRunnable(profile, schema));
+ }
+
+ /* CU private */ class SchemaChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final Schema schema;
+ SchemaChangedRunnable(ConnectionProfile profile, Schema schema) {
+ super();
+ this.profile = profile;
+ this.schema = schema;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.schemaChanged_(this.profile, this.schema);
+ }
+ }
+
void schemaChanged_(ConnectionProfile profile, Schema schema) {
this.listener.schemaChanged(profile, schema);
}
+ public void sequenceChanged(ConnectionProfile profile, Sequence sequence) {
+ this.execute(new SequenceChangedRunnable(profile, sequence));
+ }
+
+ /* CU private */ class SequenceChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final Sequence sequence;
+ SequenceChangedRunnable(ConnectionProfile profile, Sequence sequence) {
+ super();
+ this.profile = profile;
+ this.sequence = sequence;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.sequenceChanged_(this.profile, this.sequence);
+ }
+ }
+
void sequenceChanged_(ConnectionProfile profile, Sequence sequence) {
this.listener.sequenceChanged(profile, sequence);
}
+ public void tableChanged(ConnectionProfile profile, Table table) {
+ this.execute(new TableChangedRunnable(profile, table));
+ }
+
+ /* CU private */ class TableChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final Table table;
+ TableChangedRunnable(ConnectionProfile profile, Table table) {
+ super();
+ this.profile = profile;
+ this.table = table;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.tableChanged_(this.profile, this.table);
+ }
+ }
+
void tableChanged_(ConnectionProfile profile, Table table) {
this.listener.tableChanged(profile, table);
}
+ public void columnChanged(ConnectionProfile profile, Column column) {
+ this.execute(new ColumnChangedRunnable(profile, column));
+ }
+
+ /* CU private */ class ColumnChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final Column column;
+ ColumnChangedRunnable(ConnectionProfile profile, Column column) {
+ super();
+ this.profile = profile;
+ this.column = column;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.columnChanged_(this.profile, this.column);
+ }
+ }
+
void columnChanged_(ConnectionProfile profile, Column column) {
this.listener.columnChanged(profile, column);
}
+ public void foreignKeyChanged(ConnectionProfile profile, ForeignKey foreignKey) {
+ this.execute(new ForeignKeyChangedRunnable(profile, foreignKey));
+ }
+
+ /* CU private */ class ForeignKeyChangedRunnable
+ extends RunnableAdapter
+ {
+ private final ConnectionProfile profile;
+ private final ForeignKey foreignKey;
+ ForeignKeyChangedRunnable(ConnectionProfile profile, ForeignKey foreignKey) {
+ super();
+ this.profile = profile;
+ this.foreignKey = foreignKey;
+ }
+ @Override
+ public void run() {
+ SWTConnectionListenerWrapper.this.foreignKeyChanged_(this.profile, this.foreignKey);
+ }
+ }
+
void foreignKeyChanged_(ConnectionProfile profile, ForeignKey foreignKey) {
this.listener.foreignKeyChanged(profile, foreignKey);
}
+ /**
+ * {@link SWTUtil#execute(Runnable)} seems to work OK;
+ * but using {@link SWTUtil#syncExec(Runnable)} can somtimes make things
+ * more predictable when debugging, at the risk of deadlocks.
+ */
+ private void execute(Runnable r) {
+ SWTUtil.execute(r);
+// SWTUtil.syncExec(r);
+ }
+
@Override
public String toString() {
- return "SWT(" + this.listener.toString() + ')'; //$NON-NLS-1$
+ return "SWT(" + this.listener + ')'; //$NON-NLS-1$
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/menus/MapAsContribution.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/menus/MapAsContribution.java
index 054e7ab34b..a77968e76a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/menus/MapAsContribution.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/menus/MapAsContribution.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -25,7 +25,6 @@ import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator;
import org.eclipse.jpt.jpa.core.JpaPlatform;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.details.DefaultMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.MappingUiDefinition;
import org.eclipse.ui.ISources;
@@ -92,8 +91,9 @@ public abstract class MapAsContribution<T extends JpaStructureNode>
return createContributionItem(next);
}
},
- new IContributionItem[0]);
+ EMPTY_CONTRIBUTION_ITEM_ARRAY);
}
+ protected static final IContributionItem[] EMPTY_CONTRIBUTION_ITEM_ARRAY = new IContributionItem[0];
protected Comparator<MappingUiDefinition<T, ?>> getDefinitionsComparator() {
@@ -115,8 +115,7 @@ public abstract class MapAsContribution<T extends JpaStructureNode>
* @return The list of registered {@link MappingUiDefinition}s
*/
protected <U extends T> Iterator<? extends MappingUiDefinition<T, ?>> mappingUiDefinitions(final T node) {
- JpaPlatform jpaPlatform = node.getJpaProject().getJpaPlatform();
- JpaPlatformUi jpaPlatformUi = JptJpaUiPlugin.instance().getJpaPlatformUi(jpaPlatform);
+ JpaPlatformUi jpaPlatformUi = (JpaPlatformUi) node.getJpaPlatform().getAdapter(JpaPlatformUi.class);
Iterator<? extends MappingUiDefinition<T, ?>> sortedMappingUiDefinitions =
CollectionTools.sort(
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java
deleted file mode 100644
index 9075967581..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.navigator;
-
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-
-public class JpaNavigatorContentAndLabelProvider extends DelegatingTreeContentAndLabelProvider
-{
- public JpaNavigatorContentAndLabelProvider() {
- super(new JpaNavigatorTreeItemContentProviderFactory(), new JpaNavigatorItemLabelProviderFactory());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentProvider.java
index 12e0ae7fc6..3c6cf5ef0b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorContentProvider.java
@@ -1,216 +1,72 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.navigator;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.viewers.StructuredViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jpt.jpa.core.JpaFacet;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.navigator.ICommonContentExtensionSite;
-import org.eclipse.ui.navigator.ICommonContentProvider;
-import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent;
-import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener;
-import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent;
+import org.eclipse.jpt.common.ui.internal.jface.NavigatorContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel;
/**
- * This extension of navigator content provider delegates to the platform UI
- * (see the org.eclipse.jpt.jpa.ui.jpaPlatform extension point) for navigator content.
- *
- * If there is a platform UI for the given project, this content provider will
- * provide a root "JPA Content" node (child of the project), otherwise there
- * will be no content. For children of the "JPA Content" node (or for any other
- * sub-node), this provider will delegate to the content provider returned by the
- * platform UI implementation.
+ * This provider is invoked for:<ul>
+ * <li>Eclipse projects with a JPA facet
+ * <li>JPA root context node models
+ * <li>JPA context nodes
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
*/
public class JpaNavigatorContentProvider
- implements ICommonContentProvider {
-
- private JpaNavigatorContentAndLabelProvider delegate;
-
- private IFacetedProjectListener facetListener;
-
- private StructuredViewer viewer;
-
-
+ extends NavigatorContentProvider
+{
public JpaNavigatorContentProvider() {
super();
- facetListener = new FacetListener();
- FacetedProjectFramework.addListener(
- facetListener,
- IFacetedProjectEvent.Type.POST_INSTALL,
- IFacetedProjectEvent.Type.POST_UNINSTALL,
- IFacetedProjectEvent.Type.PROJECT_MODIFIED);
- }
-
-
- public JpaNavigatorContentAndLabelProvider delegate() {
- return delegate;
- }
-
-
- // **************** IContentProvider implementation ************************
-
- public void dispose() {
- FacetedProjectFramework.removeListener(facetListener);
- if (delegate != null) {
- delegate.dispose();
- }
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (delegate != null) {
- delegate.inputChanged(viewer, oldInput, newInput);
- }
- this.viewer = (StructuredViewer) viewer;
- }
-
-
- // **************** IStructuredContentProvider implementation **************
-
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
-
- // **************** ITreeContentProvider implementation ********************
-
- public Object getParent(Object element) {
- if (delegate != null) {
- return delegate.getParent(element);
- }
-
- return null;
}
-
- public boolean hasChildren(Object element) {
- if (element instanceof IAdaptable) {
- IProject project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
-
- if (project != null) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
- if (jpaProject != null) {
- JpaPlatformUi platformUi = JptJpaUiPlugin.instance().getJpaPlatformUi(jpaProject.getJpaPlatform());
-
- return platformUi != null;
- }
- }
- }
-
- if (delegate != null) {
- return delegate.hasChildren(element);
- }
-
- return false;
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof IAdaptable) {
- IProject project = (IProject) ((IAdaptable) parentElement).getAdapter(IProject.class);
-
- if (project != null) {
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
- if (jpaProject != null) {
- JpaPlatformUi platformUi = JptJpaUiPlugin.instance().getJpaPlatformUi(jpaProject.getJpaPlatform());
-
- if (platformUi != null) {
- return new Object[] {jpaProject.getRootContextNode()};
- }
- }
- }
- }
-
- if (delegate != null) {
- return delegate.getChildren(parentElement);
- }
-
- return new Object[0];
+
+ @Override
+ protected ItemTreeContentProviderFactory buildItemContentProviderFactory() {
+ return new JpaNavigatorItemContentProviderFactory();
}
-
-
- // **************** IMementoAware implementation ***************************
-
- public void saveState(IMemento memento) {
- // no op
+
+ @Override
+ protected ItemExtendedLabelProviderFactory buildItemLabelProviderFactory() {
+ return new JpaNavigatorItemLabelProviderFactory();
}
-
- public void restoreState(IMemento memento) {
- // no op
+
+ @Override
+ protected boolean hasChildren_(Object element) {
+ return this.getRootContextNodeModel(element) != null;
}
-
-
- // **************** ICommonContentProvider implementation ******************
-
- public void init(ICommonContentExtensionSite config) {
- if (delegate == null) {
- JpaNavigatorLabelProvider labelProvider = (JpaNavigatorLabelProvider) config.getExtension().getLabelProvider();
- if (labelProvider != null && labelProvider.delegate() != null) {
- delegate = labelProvider.delegate();
- }
- else {
- delegate = new JpaNavigatorContentAndLabelProvider();
- }
- }
+
+ /**
+ * We handle the children for an {@link IProject} here and delegate
+ * all others.
+ */
+ @Override
+ protected Object[] getChildren_(Object element) {
+ JpaRootContextNodeModel child = this.getRootContextNodeModel(element);
+ return (child == null) ? null : new Object[] {child};
}
-
-
- // **************** member classes *****************************************
-
- private class FacetListener
- implements IFacetedProjectListener
- {
- public void handleEvent(IFacetedProjectEvent event) {
- if (event.getType() == IFacetedProjectEvent.Type.PROJECT_MODIFIED) {
- refreshViewer(event.getProject().getProject());
- }
- else if (event.getType() == IFacetedProjectEvent.Type.POST_INSTALL
- || event.getType() == IFacetedProjectEvent.Type.POST_UNINSTALL) {
- IProjectFacetActionEvent ipaEvent = (IProjectFacetActionEvent) event;
- if (ipaEvent.getProjectFacet().equals(JpaFacet.FACET)) {
- refreshViewer(ipaEvent.getProject().getProject());
- }
- }
- }
-
- private void refreshViewer(final IProject project) {
- if (viewer != null
- && viewer.getControl() != null
- && !viewer.getControl().isDisposed()) {
- // Using job here so that project model update (which also uses
- // a job) will complete first
- Job refreshJob = new Job("Refresh viewer") {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- // Using runnable here so that refresh will go on correct thread
- viewer.getControl().getDisplay().asyncExec(new Runnable() {
- public void run() {
- viewer.refresh(project);
- }
- });
- return Status.OK_STATUS;
- }
- };
- refreshJob.setRule(project);
- refreshJob.schedule();
- }
- }
+
+ /**
+ * This provider should only be invoked for projects that have the
+ * JPA facet; so we return a JPA root context node model for any
+ * project passed in.
+ * <p>
+ * <strong>NB:</strong> There is no way to refresh the navigator when the
+ * JPA facet is added to a project. The view must be explicitly refreshed,
+ * forcing it to re-examine the provider trigger points.
+ */
+ private JpaRootContextNodeModel getRootContextNodeModel(Object element) {
+ return (element instanceof IProject) ?
+ (JpaRootContextNodeModel) ((IProject) element).getAdapter(JpaRootContextNodeModel.class) :
+ null;
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java
new file mode 100644
index 0000000000..fd67193daa
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemContentProviderFactory.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.navigator;
+
+import java.util.HashMap;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaPlatform;
+import org.eclipse.jpt.jpa.core.context.JpaContextNode;
+import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
+import org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel;
+
+/**
+ * This factory can be used by a item tree content provider that must provide
+ * content for a tree that can contain items from multiple JPA platforms (e.g.
+ * the Project Explorer). This factory will delegate to the factory appropriate
+ * to the item's JPA platform. The cache of JPA platform-specific factories is
+ * populated as needed and is never purged. Theoretically, this could be a
+ * singleton....
+ */
+public class JpaNavigatorItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
+{
+ /**
+ * Delegate factories, keyed by JPA platform.
+ */
+ private HashMap<JpaPlatform, ItemTreeContentProviderFactory> delegates = new HashMap<JpaPlatform, ItemTreeContentProviderFactory>();
+
+
+ public JpaNavigatorItemContentProviderFactory() {
+ super();
+ }
+
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof JpaRootContextNodeModel) {
+ return this.buildRootContextNodeModelProvider((JpaRootContextNodeModel) item, manager);
+ }
+ ItemTreeContentProviderFactory delegate = this.getDelegate(item);
+ return (delegate == null) ? null : delegate.buildProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildRootContextNodeModelProvider(JpaRootContextNodeModel item, Manager manager) {
+ return new RootContextNodeModelItemContentProvider(item, manager);
+ }
+
+ private ItemTreeContentProviderFactory getDelegate(Object element) {
+ return (element instanceof JpaContextNode) ? this.getDelegate((JpaContextNode) element) : null;
+ }
+
+ private synchronized ItemTreeContentProviderFactory getDelegate(JpaContextNode contextNode) {
+ JpaPlatform jpaPlatform = contextNode.getJpaProject().getJpaPlatform();
+ ItemTreeContentProviderFactory delegate = this.delegates.get(jpaPlatform);
+ if (delegate == null) {
+ if ( ! this.delegates.containsKey(jpaPlatform)) { // null is an allowed value
+ delegate = this.buildDelegate(jpaPlatform);
+ this.delegates.put(jpaPlatform, delegate);
+ }
+ }
+ return delegate;
+ }
+
+ private ItemTreeContentProviderFactory buildDelegate(JpaPlatform jpaPlatform) {
+ JpaPlatformUi platformUI = (JpaPlatformUi) jpaPlatform.getAdapter(JpaPlatformUi.class);
+ if (platformUI == null) {
+ return null;
+ }
+ ItemTreeStateProviderFactoryProvider factoryProvider = platformUI.getNavigatorFactoryProvider();
+ return (factoryProvider == null) ? null : factoryProvider.getItemContentProviderFactory();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java
index 77a06d342f..2cb8203aa9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java
@@ -1,75 +1,79 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.navigator;
import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaPlatform;
import org.eclipse.jpt.jpa.core.context.JpaContextNode;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
+import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
+import org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel;
+/**
+ * @see JpaNavigatorItemContentProviderFactory
+ */
public class JpaNavigatorItemLabelProviderFactory
- implements ItemLabelProviderFactory
+ implements ItemExtendedLabelProviderFactory
{
/**
- * Exactly *one* of these factories is created for each view that utilizes it.
- * Therefore, as we delegate to the platform UI for each project, we should
- * maintain the same multiplicity. That is, if there is a delegate for each
- * platform UI, we should maintain *one* delegate for each view.
- *
- * Key: platform id, Value: delegate content provider factory
+ * Delegate factories, keyed by JPA platform.
*/
- private final Map<String, ItemLabelProviderFactory> delegates;
-
-
+ private final HashMap<JpaPlatform, ItemExtendedLabelProviderFactory> delegates = new HashMap<JpaPlatform, ItemExtendedLabelProviderFactory>();
+
+
public JpaNavigatorItemLabelProviderFactory() {
super();
- this.delegates = new HashMap<String, ItemLabelProviderFactory>();
}
-
- public ItemLabelProvider buildItemLabelProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- ItemLabelProviderFactory delegate = getDelegate(item);
- if (delegate != null) {
- return delegate.buildItemLabelProvider(item, contentAndLabelProvider);
+
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ if (item instanceof JpaRootContextNodeModel) {
+ return this.buildRootContextNodeModelProvider((JpaRootContextNodeModel) item, manager);
}
- return null;
+ ItemExtendedLabelProviderFactory delegate = this.getDelegate(item);
+ return (delegate == null) ? null : delegate.buildProvider(item, manager);
}
-
-
- private ItemLabelProviderFactory getDelegate(Object element) {
- if (! (element instanceof IAdaptable)) {
- return null;
+
+ protected ItemExtendedLabelProvider buildRootContextNodeModelProvider(JpaRootContextNodeModel item, ItemExtendedLabelProvider.Manager manager) {
+ return new RootContextNodeModelItemLabelProvider(item, manager);
+ }
+
+ private ItemExtendedLabelProviderFactory getDelegate(Object item) {
+ return (item instanceof JpaContextNode) ? this.getDelegate((JpaContextNode) item) : null;
+ }
+
+ private synchronized ItemExtendedLabelProviderFactory getDelegate(JpaContextNode item) {
+ JpaPlatform jpaPlatform = item.getJpaProject().getJpaPlatform();
+ ItemExtendedLabelProviderFactory delegate = this.delegates.get(jpaPlatform);
+ if (delegate == null) {
+ if ( ! this.delegates.containsKey(jpaPlatform)) { // null is an allowed value
+ delegate = this.buildDelegate(jpaPlatform);
+ this.delegates.put(jpaPlatform, delegate);
+ }
}
-
- JpaContextNode contextNode = (JpaContextNode) ((IAdaptable) element).getAdapter(JpaContextNode.class);
-
- if (contextNode == null) {
+ return delegate;
+ }
+
+ private ItemExtendedLabelProviderFactory buildDelegate(JpaPlatform jpaPlatform) {
+ JpaPlatformUi platformUI = (JpaPlatformUi) jpaPlatform.getAdapter(JpaPlatformUi.class);
+ if (platformUI == null) {
return null;
}
-
- JpaPlatform platform = contextNode.getJpaProject().getJpaPlatform();
- String platformId = platform.getId();
- if (delegates.containsKey(platformId)) {
- return delegates.get(platformId);
- }
- JpaNavigatorProvider navigatorProvider = JptJpaUiPlugin.instance().getJpaNavigatorProvider(platform);
- ItemLabelProviderFactory delegate = null;
- if (navigatorProvider != null) {
- delegate = navigatorProvider.getItemLabelProviderFactory();
- }
- delegates.put(platformId, delegate);
- return delegate;
+ ItemTreeStateProviderFactoryProvider factoryProvider = platformUI.getNavigatorFactoryProvider();
+ return (factoryProvider == null) ? null : factoryProvider.getItemLabelProviderFactory();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorLabelProvider.java
deleted file mode 100644
index 8066e9ff12..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorLabelProvider.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.navigator;
-
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IMemento;
-import org.eclipse.ui.navigator.ICommonContentExtensionSite;
-import org.eclipse.ui.navigator.ICommonLabelProvider;
-
-/**
- * This extension of navigator label provider delegates to the platform UI
- * (see the org.eclipse.jpt.jpa.ui.jpaPlatform extension point) for navigator labels.
- *
- * This label provider provides a label for the root "JPA Content" node provided
- * by the content provider (see {@link JpaNavigatorContentProvider}) and delegates
- * to the label provider returned by the platform UI implementation for labels
- * for children of the "JPA Content" node (or for any other sub-node).
- */
-public class JpaNavigatorLabelProvider
- extends LabelProvider
- implements ICommonLabelProvider {
-
- private JpaNavigatorContentAndLabelProvider delegate;
-
-
- public JpaNavigatorLabelProvider() {
- super();
- }
-
-
- public JpaNavigatorContentAndLabelProvider delegate() {
- return delegate;
- }
-
-
- // **************** IBaseLabelProvider implementation **********************
-
- @Override
- public void addListener(ILabelProviderListener listener) {
- if (delegate != null) {
- delegate.addListener(listener);
- }
- super.addListener(listener);
- }
-
- @Override
- public void removeListener(ILabelProviderListener listener) {
- super.removeListener(listener);
- if (delegate != null) {
- delegate.removeListener(listener);
- }
- }
-
- @Override
- public boolean isLabelProperty(Object element, String property) {
- if (delegate != null) {
- return delegate.isLabelProperty(element, property);
- }
-
- return super.isLabelProperty(element, property);
- }
-
- @Override
- public void dispose() {
- if (delegate != null) {
- delegate.dispose();
- }
- super.dispose();
- }
-
-
- // **************** ILabelProvider implementation **************************
-
- @Override
- public Image getImage(Object element) {
- if (delegate != null) {
- return delegate.getImage(element);
- }
-
- return super.getImage(element);
- }
-
- @Override
- public String getText(Object element) {
- if (delegate != null) {
- return delegate.getText(element);
- }
-
- return super.getText(element);
- }
-
-
- // **************** IDescriptionProvider implementation ********************
-
- public String getDescription(Object element) {
- if (delegate != null) {
- return delegate.getDescription(element);
- }
-
- return super.getText(element);
- }
-
-
- // **************** IMementoAware implementation ***************************
-
- public void saveState(IMemento memento) {
- // no op
- }
-
- public void restoreState(IMemento memento) {
- // no op
- }
-
-
- // **************** ICommonLabelProvider implementation ********************
-
- public void init(ICommonContentExtensionSite config) {
- if (delegate == null) {
- JpaNavigatorContentProvider contentProvider = (JpaNavigatorContentProvider) config.getExtension().getContentProvider();
- if (contentProvider != null && contentProvider.delegate() != null) {
- delegate = contentProvider.delegate();
- }
- else {
- delegate = new JpaNavigatorContentAndLabelProvider();
- }
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java
deleted file mode 100644
index 604f912622..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.navigator;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.core.JpaPlatform;
-import org.eclipse.jpt.jpa.core.context.JpaContextNode;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
-
-public class JpaNavigatorTreeItemContentProviderFactory
- implements TreeItemContentProviderFactory
-{
- /**
- * Exactly *one* of these factories is created for each view that utilizes it.
- * Therefore, as we delegate to the platform UI for each project, we should
- * maintain the same multiplicity. That is, if there is a delegate for each
- * platform UI, we should maintain *one* delegate for each view.
- *
- * Key: platform id, Value: delegate content provider factory
- */
- private Map<String, TreeItemContentProviderFactory> delegates;
-
-
- public JpaNavigatorTreeItemContentProviderFactory() {
- super();
- this.delegates = new HashMap<String, TreeItemContentProviderFactory>();
- }
-
- public TreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- TreeItemContentProviderFactory delegate = getDelegate(item);
- if (delegate != null) {
- return delegate.buildItemContentProvider(item, contentAndLabelProvider);
- }
- return null;
- }
-
-
- private TreeItemContentProviderFactory getDelegate(Object element) {
- if (! (element instanceof IAdaptable)) {
- return null;
- }
-
- JpaContextNode contextNode = (JpaContextNode) ((IAdaptable) element).getAdapter(JpaContextNode.class);
-
- if (contextNode == null) {
- return null;
- }
-
- JpaPlatform platform = contextNode.getJpaProject().getJpaPlatform();
- String platformId = platform.getId();
- if (delegates.containsKey(platformId)) {
- return delegates.get(platformId);
- }
- JpaNavigatorProvider navigatorProvider = JptJpaUiPlugin.instance().getJpaNavigatorProvider(platform);
- TreeItemContentProviderFactory delegate = null;
- if (navigatorProvider != null) {
- delegate = navigatorProvider.getTreeItemContentProviderFactory();
- }
- delegates.put(platformId, delegate);
- return delegate;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemContentProvider.java
new file mode 100644
index 0000000000..72737540fe
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemContentProvider.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.navigator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel;
+
+public class RootContextNodeModelItemContentProvider
+ extends AbstractItemTreeContentProvider<JpaRootContextNodeModel, PersistenceXml>
+{
+ public RootContextNodeModelItemContentProvider(JpaRootContextNodeModel rootContextModel, Manager manager) {
+ super(rootContextModel, manager);
+ }
+
+ public IProject getParent() {
+ return this.item.getProject();
+ }
+
+ @Override
+ protected CollectionValueModel<PersistenceXml> buildChildrenModel() {
+ return new PropertyCollectionValueModelAdapter<PersistenceXml>(this.buildPersistenceXmlModel());
+ }
+
+ protected PropertyValueModel<PersistenceXml> buildPersistenceXmlModel() {
+ return new PersistenceXmlModel(this.item);
+ }
+
+ public static class PersistenceXmlModel
+ extends PropertyAspectAdapter<JpaRootContextNode, PersistenceXml>
+ {
+ public PersistenceXmlModel(PropertyValueModel<JpaRootContextNode> rootContextNodeModel) {
+ super(rootContextNodeModel, JpaRootContextNode.PERSISTENCE_XML_PROPERTY);
+ }
+ @Override
+ protected PersistenceXml buildValue_() {
+ return this.subject.getPersistenceXml();
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemLabelProvider.java
new file mode 100644
index 0000000000..a46fe977c5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/navigator/RootContextNodeModelItemLabelProvider.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.navigator;
+
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
+import org.eclipse.jpt.common.utility.internal.Transformer;
+import org.eclipse.jpt.common.utility.internal.TransformerAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+import org.eclipse.jpt.jpa.ui.JpaRootContextNodeModel;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+import org.eclipse.swt.graphics.Image;
+
+public class RootContextNodeModelItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<JpaRootContextNodeModel>
+{
+ public RootContextNodeModelItemLabelProvider(JpaRootContextNodeModel rootContextNodeModel, ItemLabelProvider.Manager manager) {
+ super(rootContextNodeModel, manager);
+ }
+
+ @Override
+ protected PropertyValueModel<Image> buildImageModel() {
+ return new TransformationPropertyValueModel<JpaRootContextNode, Image>(this.item, IMAGE_TRANSFORMER);
+ }
+
+ protected static final Transformer<JpaRootContextNode, Image> IMAGE_TRANSFORMER = new ImageTransformer();
+
+ protected static class ImageTransformer
+ extends TransformerAdapter<JpaRootContextNode, Image>
+ {
+ @Override
+ public Image transform(JpaRootContextNode root) {
+ return (root != null) ?
+ JptJpaUiPlugin.getImage(JptUiIcons.JPA_CONTENT) :
+ JptUiIcons.ghost(JptUiIcons.JPA_CONTENT);
+ }
+ }
+
+ @Override
+ protected PropertyValueModel<String> buildTextModel() {
+ return new TransformationPropertyValueModel<JpaRootContextNode, String>(this.item, TEXT_TRANSFORMER);
+ }
+
+ protected static final Transformer<JpaRootContextNode, String> TEXT_TRANSFORMER = new TextTransformer();
+
+ protected static class TextTransformer
+ extends TransformerAdapter<JpaRootContextNode, String>
+ {
+ @Override
+ public String transform(JpaRootContextNode root) {
+ String text = JptUiMessages.JpaContent_label;
+ return (root != null) ? text : "[" + text + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ @Override
+ protected PropertyValueModel<String> buildDescriptionModel() {
+ return new TransformationPropertyValueModel<JpaRootContextNode, String>(this.item, DESCRIPTION_TRANSFORMER);
+ }
+
+ protected static final Transformer<JpaRootContextNode, String> DESCRIPTION_TRANSFORMER = new DescriptionTransformer();
+
+ protected static class DescriptionTransformer
+ extends TransformerAdapter<JpaRootContextNode, String>
+ {
+ @Override
+ public String transform(JpaRootContextNode root) {
+ if (root == null) {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(JptUiMessages.JpaContent_label);
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(root.getResource().getFullPath().makeRelative());
+ return sb.toString();
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java
index 89a4670acc..0c6567d7d9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java
@@ -18,7 +18,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.common.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
@@ -119,7 +119,8 @@ public abstract class PersistenceUnitMappingFilesComposite
for (Object result : dialog.getResult()) {
IFile file = (IFile) result;
IProject project = file.getProject();
- IPath runtimePath = JptCommonCorePlugin.getResourceLocator(project).getRuntimePath(project, file.getFullPath());
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ IPath runtimePath = locator.getRuntimePath(file.getFullPath());
String fileName = runtimePath.toPortableString();
if (mappingFileRefExists(fileName)) {
continue;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceXmlUiDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceXmlUiDefinition.java
index ee2d04c5bb..7b69456b2e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceXmlUiDefinition.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/persistence/details/PersistenceXmlUiDefinition.java
@@ -1,22 +1,24 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.persistence.details;
import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
-import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceResourceModelStructureProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceStructureItemContentProviderFactory;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceStructureItemLabelProviderFactory;
-public class PersistenceXmlUiDefinition extends AbstractPersistenceXmlResourceUiDefinition
+public class PersistenceXmlUiDefinition
+ extends AbstractPersistenceXmlResourceUiDefinition
{
// singleton
private static final ResourceUiDefinition INSTANCE = new PersistenceXmlUiDefinition();
@@ -47,7 +49,13 @@ public class PersistenceXmlUiDefinition extends AbstractPersistenceXmlResourceUi
return resourceType.equals(JptJpaCorePlugin.PERSISTENCE_XML_1_0_RESOURCE_TYPE);
}
- public JpaStructureProvider getStructureProvider() {
- return PersistenceResourceModelStructureProvider.instance();
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider() {
+ return STRUCTURE_VIEW_FACTORY_PROVIDER;
}
+
+ public static final ItemTreeStateProviderFactoryProvider STRUCTURE_VIEW_FACTORY_PROVIDER =
+ new SimpleItemTreeStateProviderFactoryProvider(
+ PersistenceStructureItemContentProviderFactory.instance(),
+ PersistenceStructureItemLabelProviderFactory.instance()
+ );
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/BaseJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/BaseJpaPlatformUi.java
index a01135e3a4..567f09e21a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/BaseJpaPlatformUi.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/base/BaseJpaPlatformUi.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jpt.common.core.JptResourceType;
import org.eclipse.jpt.common.ui.WidgetFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaFile;
@@ -31,11 +32,9 @@ import org.eclipse.jpt.jpa.ui.MappingResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.ResourceUiDefinition;
import org.eclipse.jpt.jpa.ui.details.DefaultMappingUiDefinition;
import org.eclipse.jpt.jpa.ui.details.JpaComposite;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.details.JpaDetailsProvider;
import org.eclipse.jpt.jpa.ui.details.MappingUiDefinition;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
@@ -43,54 +42,52 @@ import org.eclipse.swt.widgets.Shell;
public abstract class BaseJpaPlatformUi
implements JpaPlatformUi
{
- private final JpaNavigatorProvider navigatorProvider;
+ private final ItemTreeStateProviderFactoryProvider navigatorFactoryProvider;
private final JpaPlatformUiProvider platformUiProvider;
protected BaseJpaPlatformUi(
- JpaNavigatorProvider navigatorProvider, JpaPlatformUiProvider platformUiProvider) {
-
+ ItemTreeStateProviderFactoryProvider navigatorFactoryProvider,
+ JpaPlatformUiProvider platformUiProvider
+ ) {
super();
- this.navigatorProvider = navigatorProvider;
+ this.navigatorFactoryProvider = navigatorFactoryProvider;
this.platformUiProvider = platformUiProvider;
}
// ********** navigator provider **********
- public JpaNavigatorProvider getNavigatorProvider() {
- return this.navigatorProvider;
+ public ItemTreeStateProviderFactoryProvider getNavigatorFactoryProvider() {
+ return this.navigatorFactoryProvider;
}
- // ********** structure providers **********
+ // ********** structure view factory providers **********
- public JpaStructureProvider getStructureProvider(JpaFile jpaFile) {
+ public ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider(JpaFile jpaFile) {
JptResourceType resourceType = jpaFile.getResourceModel().getResourceType();
- return (resourceType == null) ? null : this.getStructureProvider(resourceType);
+ return (resourceType == null) ? null : this.getStructureViewFactoryProvider(resourceType);
}
- protected JpaStructureProvider getStructureProvider(JptResourceType resourceType) {
- ResourceUiDefinition definition;
+ protected ItemTreeStateProviderFactoryProvider getStructureViewFactoryProvider(JptResourceType resourceType) {
try {
- definition = getResourceUiDefinition(resourceType);
- }
- catch (IllegalArgumentException iae) {
+ return this.getResourceUiDefinition(resourceType).getStructureViewFactoryProvider();
+ } catch (IllegalArgumentException iae) {
JptJpaUiPlugin.log(iae);
return null;
}
- return definition.getStructureProvider();
}
// ********** details providers **********
- public JpaDetailsPage<? extends JpaStructureNode> buildJpaDetailsPage(
+ public JpaDetailsPageManager<? extends JpaStructureNode> buildJpaDetailsPageManager(
Composite parent, JpaStructureNode structureNode, WidgetFactory widgetFactory) {
JpaDetailsProvider jpaDetailsProvider = getDetailsProvider(structureNode);
- return jpaDetailsProvider == null ? null : jpaDetailsProvider.buildDetailsPage(parent, widgetFactory);
+ return jpaDetailsProvider == null ? null : jpaDetailsProvider.buildDetailsPageManager(parent, widgetFactory);
}
protected JpaDetailsProvider getDetailsProvider(JpaStructureNode structureNode) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/ClassRefItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/ClassRefItemLabelProvider.java
index 4df9c503b2..e13eaa0ab1 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/ClassRefItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/ClassRefItemLabelProvider.java
@@ -1,72 +1,66 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
import org.eclipse.swt.graphics.Image;
-public class ClassRefItemLabelProvider extends AbstractItemLabelProvider
+public class ClassRefItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<ClassRef>
{
- public ClassRefItemLabelProvider(
- ClassRef classRef, DelegatingContentAndLabelProvider labelProvider) {
- super(classRef, labelProvider);
+ protected final Image image;
+
+ public ClassRefItemLabelProvider(ClassRef classRef, ItemLabelProvider.Manager manager) {
+ super(classRef, manager);
+ this.image = this.buildImage();
}
-
+
@Override
- public ClassRef getModel() {
- return (ClassRef) super.getModel();
+ public Image getImage() {
+ return this.image;
}
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- Image image;
- if (getModel().isVirtual()) {
- image = JptUiIcons.ghost(JptUiIcons.CLASS_REF);
- }
- else {
- image = JptJpaUiPlugin.getImage(JptUiIcons.CLASS_REF);
- }
- return new StaticPropertyValueModel<Image>(image);
+ protected Image buildImage() {
+ return this.item.isVirtual() ?
+ JptUiIcons.ghost(JptUiIcons.CLASS_REF) :
+ JptJpaUiPlugin.getImage(JptUiIcons.CLASS_REF);
}
-
+
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<ClassRef, String>(ClassRef.CLASS_NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- return this.subject.getClassName();
- }
- };
+ return new TextModel(this.item);
}
-
+
+ protected static class TextModel
+ extends PropertyAspectAdapter<ClassRef, String>
+ {
+ public TextModel(ClassRef subject) {
+ super(ClassRef.CLASS_NAME_PROPERTY, subject);
+ }
+ @Override
+ protected String buildValue_() {
+ return this.subject.getClassName();
+ }
+ }
+
@Override
protected PropertyValueModel<String> buildDescriptionModel() {
- //TODO also need to listen to the PersistenceUnit name property since this value depends on it
- return new PropertyAspectAdapter<ClassRef, String>(ClassRef.CLASS_NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- StringBuilder sb = new StringBuilder();
- sb.append(this.subject.getPersistenceUnit().getName());
- sb.append("/\""); //$NON-NLS-1$
- sb.append(this.subject.getClassName());
- sb.append("\" - "); //$NON-NLS-1$
- sb.append(this.subject.getResource().getFullPath().makeRelative());
- return sb.toString();
- }
- };
+ return PersistenceUnitItemLabelProvider.buildQuotedComponentDescriptionModel(
+ this.item,
+ this.textModel
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java
deleted file mode 100644
index 186cead056..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.swt.graphics.Image;
-
-public class EntityMappingsItemLabelProvider extends AbstractItemLabelProvider
-{
- public EntityMappingsItemLabelProvider(
- EntityMappings entityMappings, DelegatingContentAndLabelProvider labelProvider) {
- super(entityMappings, labelProvider);
- }
-
- @Override
- public EntityMappings getModel() {
- return (EntityMappings) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(
- JptJpaUiPlugin.getImage(JptUiIcons.ENTITY_MAPPINGS));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(
- JptUiMessages.OrmItemLabelProviderFactory_entityMappingsLabel);
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(JptUiMessages.OrmItemLabelProviderFactory_entityMappingsLabel);
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUi.java
index d0baf65cac..ff4c5160b5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUi.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUi.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,24 +10,24 @@
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiProvider;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
import org.eclipse.jpt.jpa.ui.internal.platform.base.BaseJpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
public class GenericJpaPlatformUi
extends BaseJpaPlatformUi
{
public GenericJpaPlatformUi(
- JpaNavigatorProvider navigatorProvider, JpaPlatformUiProvider platformUiProvider) {
-
- super(navigatorProvider, platformUiProvider);
+ ItemTreeStateProviderFactoryProvider navigatorFactoryProvider,
+ JpaPlatformUiProvider platformUiProvider
+ ) {
+ super(navigatorFactoryProvider, platformUiProvider);
}
-
-
+
// ********** DDL generation **********
-
+
public void generateDDL(JpaProject project, IStructuredSelection selection) {
this.displayMessage(JptUiMessages.GenericPlatformUiDialog_notSupportedMessageTitle, JptUiMessages.GenericPlatformUiDialog_notSupportedMessageText);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUiFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUiFactory.java
index 263287fe77..f6a32b83ac 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUiFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericJpaPlatformUiFactory.java
@@ -1,19 +1,22 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
import org.eclipse.jpt.jpa.ui.internal.GenericJpaPlatformUiProvider;
-public class GenericJpaPlatformUiFactory implements JpaPlatformUiFactory
+public class GenericJpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
/**
@@ -25,8 +28,14 @@ public class GenericJpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new GenericJpaPlatformUi(
- new GenericNavigatorProvider(),
- GenericJpaPlatformUiProvider.instance()
- );
+ NAVIGATOR_FACTORY_PROVIDER,
+ GenericJpaPlatformUiProvider.instance()
+ );
}
+
+ public static final ItemTreeStateProviderFactoryProvider NAVIGATOR_FACTORY_PROVIDER =
+ new SimpleItemTreeStateProviderFactoryProvider(
+ GenericNavigatorItemContentProviderFactory.instance(),
+ GenericNavigatorItemLabelProviderFactory.instance()
+ );
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java
index 1f5c107a91..d14343d11a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java
@@ -1,253 +1,90 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
-import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.TransformationListValueModel;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.jpa.core.context.JpaContextNode;
-import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
-import org.eclipse.jpt.jpa.core.context.MappingFile;
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.PersistentType;
-import org.eclipse.jpt.jpa.core.context.java.JarFile;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmXml;
-import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
-import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+/**
+ * This factory builds item content providers for the JPA content in the
+ * Common Navigator.
+ */
public class GenericNavigatorItemContentProviderFactory
- implements TreeItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
{
- public TreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider;
-
- if (item instanceof JpaRootContextNode) {
- return new RootContextItemContentProvider((JpaRootContextNode) item, treeContentAndLabelProvider);
- }
- else if (item instanceof PersistenceXml) {
- return new PersistenceXmlItemContentProvider((PersistenceXml) item, treeContentAndLabelProvider);
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new GenericNavigatorItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected GenericNavigatorItemContentProviderFactory() {
+ super();
+ }
+
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof PersistenceXml) {
+ return this.buildPersistenceXmlProvider((PersistenceXml) item, manager);
}
- else if (item instanceof PersistenceUnit) {
- return new PersistenceUnitItemContentProvider((PersistenceUnit) item, treeContentAndLabelProvider);
+ if (item instanceof PersistenceUnit) {
+ return this.buildPersistenceUnitProvider((PersistenceUnit) item, manager);
}
- else if (item instanceof OrmXml) {
- return new OrmXmlItemContentProvider((OrmXml) item, treeContentAndLabelProvider);
+ if (item instanceof OrmXml) {
+ return this.buildOrmXmlProvider((OrmXml) item, manager);
}
- else if (item instanceof OrmPersistentType) {
- return new OrmPersistentTypeItemContentProvider((OrmPersistentType) item, treeContentAndLabelProvider);
+ if (item instanceof OrmPersistentType) {
+ return this.buildOrmPersistentTypeProvider((OrmPersistentType) item, manager);
}
- else if (item instanceof JavaPersistentType) {
- return new JavaPersistentTypeItemContentProvider((JavaPersistentType) item, treeContentAndLabelProvider);
+ if (item instanceof JavaPersistentType) {
+ return this.buildJavaPersistentTypeProvider((JavaPersistentType) item, manager);
}
- else if (item instanceof PersistentAttribute) {
- return new PersistentAttributeItemContentProvider((PersistentAttribute) item, treeContentAndLabelProvider);
+ if (item instanceof PersistentAttribute) {
+ return this.buildPersistentAttributeProvider((PersistentAttribute) item, manager);
}
return null;
}
-
-
- public static class PersistenceUnitItemContentProvider extends AbstractTreeItemContentProvider<JpaContextNode>
- {
- public PersistenceUnitItemContentProvider(
- PersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistenceUnit, contentProvider);
- }
-
- @Override
- public PersistenceUnit getModel() {
- return (PersistenceUnit) super.getModel();
- }
-
- @Override
- public PersistenceXml getParent() {
- return getModel().getParent().getParent();
- }
-
- @Override
- protected CollectionValueModel<JpaContextNode> buildChildrenModel() {
- List<CollectionValueModel<? extends JpaContextNode>> list = new ArrayList<CollectionValueModel<? extends JpaContextNode>>();
- list.add(buildSpecifiedOrmXmlCvm());
- list.add(buildImpliedMappingFileCvm());
- list.add(buildPersistentTypeCvm());
- list.add(buildJarFileCvm());
- return new CompositeCollectionValueModel<CollectionValueModel<? extends JpaContextNode>, JpaContextNode>(list);
- }
-
- protected CollectionValueModel<JpaContextNode> buildSpecifiedOrmXmlCvm() {
- return new FilteringCollectionValueModel<JpaContextNode>(
- new ListCollectionValueModelAdapter<MappingFile>(
- new TransformationListValueModel<MappingFileRef, MappingFile>(
- new ItemPropertyListValueModelAdapter<MappingFileRef>(
- new ListAspectAdapter<PersistenceUnit, MappingFileRef>(
- PersistenceUnit.SPECIFIED_MAPPING_FILE_REFS_LIST,
- getModel()) {
- @Override
- protected ListIterable<MappingFileRef> getListIterable() {
- return subject.getSpecifiedMappingFileRefs();
- }
- @Override
- protected int size_() {
- return subject.getSpecifiedMappingFileRefsSize();
- }
- }, MappingFileRef.MAPPING_FILE_PROPERTY)) {
- @Override
- protected MappingFile transformItem(MappingFileRef item) {
- return item.getMappingFile();
- }
- })) {
- @Override
- protected Iterable<JpaContextNode> filter(Iterable<? extends JpaContextNode> items) {
- return new FilteringIterable<JpaContextNode>(items) {
- @Override
- protected boolean accept(JpaContextNode o) {
- return o != null;
- }
- };
- }
- };
- }
-
- protected CollectionValueModel<MappingFile> buildImpliedMappingFileCvm() {
- return new PropertyCollectionValueModelAdapter<MappingFile>(
- new PropertyAspectAdapter<MappingFileRef, MappingFile>(
- new PropertyAspectAdapter<PersistenceUnit, MappingFileRef>(
- PersistenceUnit.IMPLIED_MAPPING_FILE_REF_PROPERTY,
- getModel()) {
- @Override
- protected MappingFileRef buildValue_() {
- return subject.getImpliedMappingFileRef();
- }
- },
- MappingFileRef.MAPPING_FILE_PROPERTY) {
- @Override
- protected MappingFile buildValue_() {
- return subject.getMappingFile();
- }
- }
- );
- }
-
- protected CollectionValueModel<JpaContextNode> buildPersistentTypeCvm() {
- return new FilteringCollectionValueModel<JpaContextNode>(
- new ListCollectionValueModelAdapter<PersistentType>(
- new TransformationListValueModel<ClassRef, PersistentType>(
- new ItemPropertyListValueModelAdapter<ClassRef>(buildClassRefCvm(), ClassRef.JAVA_PERSISTENT_TYPE_PROPERTY)) {
- @Override
- protected PersistentType transformItem(ClassRef item) {
- return item.getJavaPersistentType();
- }
- })) {
- @Override
- protected Iterable<JpaContextNode> filter(Iterable<? extends JpaContextNode> items) {
- return new FilteringIterable<JpaContextNode>(items) {
- @Override
- protected boolean accept(JpaContextNode o) {
- return o != null;
- }
- };
- }
- };
- }
-
- protected CollectionValueModel<ClassRef> buildClassRefCvm() {
- ArrayList<CollectionValueModel<ClassRef>> holders = new ArrayList<CollectionValueModel<ClassRef>>(2);
- holders.add(buildSpecifiedClassRefCvm());
- holders.add(buildImpliedClassRefCvm());
- return new CompositeCollectionValueModel<CollectionValueModel<ClassRef>, ClassRef>(holders);
- }
-
- protected CollectionValueModel<ClassRef> buildSpecifiedClassRefCvm() {
- return new ListCollectionValueModelAdapter<ClassRef>(
- new ListAspectAdapter<PersistenceUnit, ClassRef>(
- PersistenceUnit.SPECIFIED_CLASS_REFS_LIST, getModel()) {
- @Override
- protected ListIterable<ClassRef> getListIterable() {
- return subject.getSpecifiedClassRefs();
- }
- @Override
- protected int size_() {
- return subject.getSpecifiedClassRefsSize();
- }
- });
- }
-
- protected CollectionValueModel<ClassRef> buildImpliedClassRefCvm() {
- return new CollectionAspectAdapter<PersistenceUnit, ClassRef>(
- PersistenceUnit.IMPLIED_CLASS_REFS_COLLECTION, getModel()) {
- @Override
- protected Iterable<ClassRef> getIterable() {
- return subject.getImpliedClassRefs();
- }
- @Override
- protected int size_() {
- return subject.getImpliedClassRefsSize();
- }
- };
- }
-
- protected CollectionValueModel<JpaContextNode> buildJarFileCvm() {
- return new FilteringCollectionValueModel<JpaContextNode>(
- new ListCollectionValueModelAdapter<JarFile>(
- new TransformationListValueModel<JarFileRef, JarFile>(
- new ItemPropertyListValueModelAdapter<JarFileRef>(buildJarFileRefCvm(), JarFileRef.JAR_FILE_PROPERTY)) {
- @Override
- protected JarFile transformItem(JarFileRef item) {
- return item.getJarFile();
- }
- })) {
- @Override
- protected Iterable<JpaContextNode> filter(Iterable<? extends JpaContextNode> items) {
- return new FilteringIterable<JpaContextNode>(items) {
- @Override
- protected boolean accept(JpaContextNode o) {
- return o != null;
- }
- };
- }
- };
- }
-
- protected CollectionValueModel<JarFileRef> buildJarFileRefCvm() {
- return new ListCollectionValueModelAdapter<JarFileRef>(
- new ListAspectAdapter<PersistenceUnit, JarFileRef>(
- PersistenceUnit.JAR_FILE_REFS_LIST, getModel()) {
- @Override
- protected ListIterable<JarFileRef> getListIterable() {
- return subject.getJarFileRefs();
- }
- @Override
- protected int size_() {
- return subject.getJarFileRefsSize();
- }
- });
- }
+
+ protected ItemTreeContentProvider buildPersistenceXmlProvider(PersistenceXml item, Manager manager) {
+ return new PersistenceXmlItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildPersistenceUnitProvider(PersistenceUnit item, Manager manager) {
+ return new PersistenceUnitItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildOrmXmlProvider(OrmXml item, Manager manager) {
+ return new OrmXmlItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildOrmPersistentTypeProvider(OrmPersistentType item, Manager manager) {
+ return new OrmPersistentTypeItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildJavaPersistentTypeProvider(JavaPersistentType item, Manager manager) {
+ return new JavaPersistentTypeItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildPersistentAttributeProvider(PersistentAttribute item, @SuppressWarnings("unused") Manager manager) {
+ return new StaticItemTreeContentProvider(item.getParent());
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java
index 72880ead31..fcfca88c24 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java
@@ -1,51 +1,121 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jpt.common.core.ResourceReference;
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JarFile;
import org.eclipse.jpt.jpa.core.context.orm.OrmXml;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.jpa.ui.internal.jface.JarFileItemLabelProvider;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
+/**
+ * This factory builds item label providers for the JPA content in the
+ * Common Navigator.
+ */
public class GenericNavigatorItemLabelProviderFactory
- implements ItemLabelProviderFactory
+ implements ItemExtendedLabelProviderFactory
{
- public ItemLabelProvider buildItemLabelProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- if (item instanceof JpaRootContextNode) {
- return new RootContextItemLabelProvider((JpaRootContextNode) item, contentAndLabelProvider);
- }
- else if (item instanceof PersistenceXml) {
- return new PersistenceXmlItemLabelProvider((PersistenceXml) item, contentAndLabelProvider);
+ // singleton
+ private static final ItemExtendedLabelProviderFactory INSTANCE = new GenericNavigatorItemLabelProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemExtendedLabelProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected GenericNavigatorItemLabelProviderFactory() {
+ super();
+ }
+
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ if (item instanceof PersistenceXml) {
+ return this.buildPersistenceXmlProvider((PersistenceXml) item, manager);
}
- else if (item instanceof PersistenceUnit) {
- return new PersistenceUnitItemLabelProvider((PersistenceUnit) item, contentAndLabelProvider);
+ if (item instanceof PersistenceUnit) {
+ return this.buildPersistenceUnitProvider((PersistenceUnit) item, manager);
}
- else if (item instanceof OrmXml) {
- return new OrmXmlItemLabelProvider((OrmXml) item, contentAndLabelProvider);
+ if (item instanceof OrmXml) {
+ return this.buildOrmXmlProvider((OrmXml) item, manager);
}
- else if (item instanceof PersistentType) {
- return new PersistentTypeItemLabelProvider((PersistentType) item, contentAndLabelProvider);
+ if (item instanceof PersistentType) {
+ return this.buildPersistentTypeProvider((PersistentType) item, manager);
}
- else if (item instanceof ReadOnlyPersistentAttribute) {
- return new PersistentAttributeItemLabelProvider((ReadOnlyPersistentAttribute) item, contentAndLabelProvider);
+ if (item instanceof ReadOnlyPersistentAttribute) {
+ return this.buildPersistentAttributeProvider((ReadOnlyPersistentAttribute) item, manager);
}
- else if (item instanceof JarFile) {
- return new JarFileItemLabelProvider((JarFile) item, contentAndLabelProvider);
+ if (item instanceof JarFile) {
+ return this.buildJarFileProvider((JarFile) item, manager);
}
return null;
}
+
+ protected ItemExtendedLabelProvider buildPersistenceXmlProvider(PersistenceXml item, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return this.buildResourceItemLabelProvider(item);
+ }
+
+ protected ItemExtendedLabelProvider buildPersistenceUnitProvider(PersistenceUnit item, ItemExtendedLabelProvider.Manager manager) {
+ return new PersistenceUnitItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildOrmXmlProvider(OrmXml item, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return this.buildResourceItemLabelProvider(item);
+ }
+
+ protected ItemExtendedLabelProvider buildPersistentTypeProvider(PersistentType item, ItemExtendedLabelProvider.Manager manager) {
+ return new PersistentTypeItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildPersistentAttributeProvider(ReadOnlyPersistentAttribute item, ItemExtendedLabelProvider.Manager manager) {
+ return new PersistentAttributeItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildJarFileProvider(JarFile item, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return this.buildResourceItemLabelProvider(item, JptUiIcons.JAR_FILE);
+ }
+
+ protected ItemExtendedLabelProvider buildResourceItemLabelProvider(ResourceReference ref) {
+ return this.buildResourceItemLabelProvider(ref.getResource());
+ }
+
+ protected ItemExtendedLabelProvider buildResourceItemLabelProvider(ResourceReference ref, String imageKey) {
+ return this.buildResourceItemLabelProvider(ref.getResource(), imageKey);
+ }
+
+ protected ItemExtendedLabelProvider buildResourceItemLabelProvider(IResource resource) {
+ return this.buildResourceItemLabelProvider(resource, JptUiIcons.JPA_FILE);
+ }
+
+ protected ItemExtendedLabelProvider buildResourceItemLabelProvider(IResource resource, String imageKey) {
+ return new StaticItemExtendedLabelProvider(
+ JptJpaUiPlugin.getImage(imageKey),
+ resource.getName(),
+ this.buildResourceDescription(resource)
+ );
+ }
+
+ protected String buildResourceDescription(IResource resource) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(resource.getName());
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(resource.getParent().getFullPath().makeRelative());
+ return sb.toString();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorProvider.java
deleted file mode 100644
index a1d3997bf3..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/GenericNavigatorProvider.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.navigator.JpaNavigatorProvider;
-
-public class GenericNavigatorProvider implements JpaNavigatorProvider
-{
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new GenericNavigatorItemLabelProviderFactory();
- }
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new GenericNavigatorItemContentProviderFactory();
- }
-
- public void dispose() {
- // TODO Auto-generated method stub
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JarFileRefItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JarFileRefItemLabelProvider.java
index 13e65e9c8a..ed19a519c4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JarFileRefItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JarFileRefItemLabelProvider.java
@@ -1,65 +1,64 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
import org.eclipse.swt.graphics.Image;
-public class JarFileRefItemLabelProvider extends AbstractItemLabelProvider
+public class JarFileRefItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<JarFileRef>
{
- public JarFileRefItemLabelProvider(
- JarFileRef jarFileRef, DelegatingContentAndLabelProvider labelProvider) {
- super(jarFileRef, labelProvider);
+ protected final Image image;
+
+ public JarFileRefItemLabelProvider(JarFileRef jarFileRef, ItemLabelProvider.Manager manager) {
+ super(jarFileRef, manager);
+ this.image = this.buildImage();
}
-
+
@Override
- public JarFileRef getModel() {
- return (JarFileRef) super.getModel();
+ public Image getImage() {
+ return this.image;
+ }
+
+ protected Image buildImage() {
+ return JptJpaUiPlugin.getImage(JptUiIcons.JAR_FILE_REF);
}
-
+
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<JarFileRef, String>(JarFileRef.FILE_NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- return this.subject.getFileName();
- }
- };
+ return new TextModel(this.item);
}
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.JAR_FILE_REF));
+
+ protected static class TextModel
+ extends PropertyAspectAdapter<JarFileRef, String>
+ {
+ public TextModel(JarFileRef subject) {
+ super(JarFileRef.FILE_NAME_PROPERTY, subject);
+ }
+ @Override
+ protected String buildValue_() {
+ return this.subject.getFileName();
+ }
}
-
+
@Override
protected PropertyValueModel<String> buildDescriptionModel() {
- return new PropertyAspectAdapter<JarFileRef, String>(JarFileRef.FILE_NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- StringBuilder sb = new StringBuilder();
- sb.append(this.subject.getPersistenceUnit().getName());
- sb.append("/\""); //$NON-NLS-1$
- sb.append(this.subject.getFileName());
- sb.append("\" - "); //$NON-NLS-1$
- sb.append(this.subject.getResource().getFullPath().makeRelative());
- return sb.toString();
- }
- };
+ return PersistenceUnitItemLabelProvider.buildQuotedComponentDescriptionModel(
+ this.item,
+ this.textModel
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java
index e24497c35e..1441c40530 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,8 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
@@ -18,36 +17,37 @@ import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
-public class JavaPersistentTypeItemContentProvider extends AbstractTreeItemContentProvider<JavaPersistentAttribute>
+public class JavaPersistentTypeItemContentProvider
+ extends AbstractItemTreeContentProvider<JavaPersistentType, JavaPersistentAttribute>
{
- public JavaPersistentTypeItemContentProvider(
- JavaPersistentType persistentType, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistentType, contentProvider);
+ public JavaPersistentTypeItemContentProvider(JavaPersistentType persistentType, Manager manager) {
+ super(persistentType, manager);
}
-
- @Override
- public JavaPersistentType getModel() {
- return (JavaPersistentType) super.getModel();
- }
-
- @Override
+
public Object getParent() {
- return getModel().getParent();
+ return this.item.getParent();
}
@Override
protected CollectionValueModel<JavaPersistentAttribute> buildChildrenModel() {
- return new ListCollectionValueModelAdapter<JavaPersistentAttribute>(
- new ListAspectAdapter<JavaPersistentType, JavaPersistentAttribute>(JavaPersistentType.ATTRIBUTES_LIST, getModel()) {
- @Override
- protected ListIterable<JavaPersistentAttribute> getListIterable() {
- return subject.getAttributes();
- }
-
- @Override
- protected int size_() {
- return subject.getAttributesSize();
- }
- });
+ return new ListCollectionValueModelAdapter<JavaPersistentAttribute>(new ChildrenModel(this.item));
+ }
+
+ protected static class ChildrenModel
+ extends ListAspectAdapter<JavaPersistentType, JavaPersistentAttribute>
+ {
+ ChildrenModel(JavaPersistentType javaPersistentType) {
+ super(JavaPersistentType.ATTRIBUTES_LIST, javaPersistentType);
+ }
+
+ @Override
+ protected ListIterable<JavaPersistentAttribute> getListIterable() {
+ return this.subject.getAttributes();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getAttributesSize();
+ }
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java
index 5694795ac4..1a16a48ba6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java
@@ -1,71 +1,66 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
import org.eclipse.swt.graphics.Image;
-public class MappingFileRefItemLabelProvider extends AbstractItemLabelProvider
+public class MappingFileRefItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<MappingFileRef>
{
- public MappingFileRefItemLabelProvider(
- MappingFileRef mappingFileRef, DelegatingContentAndLabelProvider labelProvider) {
- super(mappingFileRef, labelProvider);
+ protected final Image image;
+
+ public MappingFileRefItemLabelProvider(MappingFileRef mappingFileRef, ItemLabelProvider.Manager manager) {
+ super(mappingFileRef, manager);
+ this.image = this.buildImage();
}
@Override
- public MappingFileRef getModel() {
- return (MappingFileRef) super.getModel();
+ public Image getImage() {
+ return this.image;
}
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- Image image;
- if (getModel().isImplied()) {
- image = JptUiIcons.ghost(JptUiIcons.MAPPING_FILE_REF);
- }
- else {
- image = JptJpaUiPlugin.getImage(JptUiIcons.MAPPING_FILE_REF);
- }
- return new StaticPropertyValueModel<Image>(image);
+
+ protected Image buildImage() {
+ return this.item.isImplied() ?
+ JptUiIcons.ghost(JptUiIcons.MAPPING_FILE_REF) :
+ JptJpaUiPlugin.getImage(JptUiIcons.MAPPING_FILE_REF);
}
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<MappingFileRef, String>(MappingFileRef.FILE_NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- return this.subject.getFileName();
- }
- };
+ return new TextModel(this.item);
+ }
+
+ protected static class TextModel
+ extends PropertyAspectAdapter<MappingFileRef, String>
+ {
+ public TextModel(MappingFileRef subject) {
+ super(MappingFileRef.FILE_NAME_PROPERTY, subject);
+ }
+ @Override
+ protected String buildValue_() {
+ return this.subject.getFileName();
+ }
}
@Override
protected PropertyValueModel<String> buildDescriptionModel() {
- return new PropertyAspectAdapter<MappingFileRef, String>(MappingFileRef.FILE_NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- StringBuilder sb = new StringBuilder();
- sb.append(this.subject.getPersistenceUnit().getName());
- sb.append("/\""); //$NON-NLS-1$
- sb.append(this.subject.getFileName());
- sb.append("\" - "); //$NON-NLS-1$
- sb.append(this.subject.getResource().getFullPath().makeRelative());
- return sb.toString();
- }
- };
+ return PersistenceUnitItemLabelProvider.buildQuotedComponentDescriptionModel(
+ this.item,
+ this.textModel
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java
index b70c79b58e..02767fb4e7 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,8 +11,7 @@ package org.eclipse.jpt.jpa.ui.internal.platform.generic;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SuperListIterableWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
@@ -24,59 +23,69 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute;
public class OrmPersistentTypeItemContentProvider
- extends AbstractTreeItemContentProvider<OrmReadOnlyPersistentAttribute>
+ extends AbstractItemTreeContentProvider<OrmPersistentType, OrmReadOnlyPersistentAttribute>
{
- public OrmPersistentTypeItemContentProvider(
- OrmPersistentType persistentType, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistentType, contentProvider);
+ public OrmPersistentTypeItemContentProvider(OrmPersistentType persistentType, Manager manager) {
+ super(persistentType, manager);
}
-
- @Override
- public OrmPersistentType getModel() {
- return (OrmPersistentType) super.getModel();
- }
-
- @Override
+
public Object getParent() {
- return getModel().getParent();
+ return this.item.getParent();
}
-
+
@Override
protected CollectionValueModel<OrmReadOnlyPersistentAttribute> buildChildrenModel() {
List<CollectionValueModel<OrmReadOnlyPersistentAttribute>> list = new ArrayList<CollectionValueModel<OrmReadOnlyPersistentAttribute>>(2);
- list.add(buildSpecifiedPersistentAttributesModel());
- list.add(buildVirtualPersistentAttributesModel());
+ list.add(this.buildSpecifiedPersistentAttributesModel());
+ list.add(this.buildVirtualPersistentAttributesModel());
return new CompositeCollectionValueModel<CollectionValueModel<OrmReadOnlyPersistentAttribute>, OrmReadOnlyPersistentAttribute>(list);
}
-
+
protected CollectionValueModel<OrmReadOnlyPersistentAttribute> buildSpecifiedPersistentAttributesModel() {
- return new ListCollectionValueModelAdapter<OrmReadOnlyPersistentAttribute>(
- new ListAspectAdapter<OrmPersistentType, OrmReadOnlyPersistentAttribute>(OrmPersistentType.SPECIFIED_ATTRIBUTES_LIST, getModel()) {
- @Override
- protected ListIterable<OrmReadOnlyPersistentAttribute> getListIterable() {
- return new SuperListIterableWrapper<OrmReadOnlyPersistentAttribute>(this.getSpecifiedAttributes());
- }
- protected ListIterable<OrmPersistentAttribute> getSpecifiedAttributes() {
- return this.subject.getSpecifiedAttributes();
- }
- @Override
- protected int size_() {
- return this.subject.getSpecifiedAttributesSize();
- }
- });
+ return new ListCollectionValueModelAdapter<OrmReadOnlyPersistentAttribute>(new SpecifiedPersistentAttributesModel(this.item));
+ }
+
+ protected static class SpecifiedPersistentAttributesModel
+ extends ListAspectAdapter<OrmPersistentType, OrmReadOnlyPersistentAttribute>
+ {
+ SpecifiedPersistentAttributesModel(OrmPersistentType ormPersistentType) {
+ super(OrmPersistentType.SPECIFIED_ATTRIBUTES_LIST, ormPersistentType);
+ }
+
+ @Override
+ protected ListIterable<OrmReadOnlyPersistentAttribute> getListIterable() {
+ return new SuperListIterableWrapper<OrmReadOnlyPersistentAttribute>(this.getSpecifiedAttributes());
+ }
+
+ protected ListIterable<OrmPersistentAttribute> getSpecifiedAttributes() {
+ return this.subject.getSpecifiedAttributes();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getSpecifiedAttributesSize();
+ }
}
-
+
protected CollectionValueModel<OrmReadOnlyPersistentAttribute> buildVirtualPersistentAttributesModel() {
- return new ListCollectionValueModelAdapter<OrmReadOnlyPersistentAttribute>(
- new ListAspectAdapter<OrmPersistentType, OrmReadOnlyPersistentAttribute>(OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST, getModel()) {
- @Override
- protected ListIterable<OrmReadOnlyPersistentAttribute> getListIterable() {
- return this.subject.getVirtualAttributes();
- }
- @Override
- protected int size_() {
- return this.subject.getVirtualAttributesSize();
- }
- });
+ return new ListCollectionValueModelAdapter<OrmReadOnlyPersistentAttribute>(new VirtualPersistentAttributesModel(this.item));
+ }
+
+ protected static class VirtualPersistentAttributesModel
+ extends ListAspectAdapter<OrmPersistentType, OrmReadOnlyPersistentAttribute>
+ {
+ VirtualPersistentAttributesModel(OrmPersistentType ormPersistentType) {
+ super(OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST, ormPersistentType);
+ }
+
+ @Override
+ protected ListIterable<OrmReadOnlyPersistentAttribute> getListIterable() {
+ return this.subject.getVirtualAttributes();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getVirtualAttributesSize();
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemContentProvider.java
index 7e29fc2532..2153137241 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemContentProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,8 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
@@ -23,47 +22,48 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmXml;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
public class OrmXmlItemContentProvider
- extends AbstractTreeItemContentProvider<OrmPersistentType>
+ extends AbstractItemTreeContentProvider<OrmXml, OrmPersistentType>
{
- public OrmXmlItemContentProvider(
- OrmXml ormXml, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(ormXml, contentProvider);
+ public OrmXmlItemContentProvider(OrmXml ormXml, Manager manager) {
+ super(ormXml, manager);
}
-
- @Override
- public OrmXml getModel() {
- return (OrmXml) super.getModel();
- }
-
- @Override
+
public PersistenceUnit getParent() {
- return getModel().getPersistenceUnit();
+ return this.item.getPersistenceUnit();
}
@Override
protected CollectionValueModel<OrmPersistentType> buildChildrenModel() {
- return new ListCollectionValueModelAdapter<OrmPersistentType>(
- new ListAspectAdapter<EntityMappings, OrmPersistentType>(
- buildEntityMappingsHolder(),
- EntityMappings.PERSISTENT_TYPES_LIST) {
- @Override
- protected ListIterable<OrmPersistentType> getListIterable() {
- return subject.getPersistentTypes();
- }
- @Override
- protected int size_() {
- return subject.getPersistentTypesSize();
- }
- });
+ return new ListCollectionValueModelAdapter<OrmPersistentType>(new ChildrenModel(this.item));
}
-
- protected PropertyValueModel<EntityMappings> buildEntityMappingsHolder() {
- return new PropertyAspectAdapter<OrmXml, EntityMappings>(
- OrmXml.ROOT_PROPERTY, getModel()) {
- @Override
- protected EntityMappings buildValue_() {
- return subject.getRoot();
- }
- };
+
+ protected static class ChildrenModel
+ extends ListAspectAdapter<EntityMappings, OrmPersistentType>
+ {
+ ChildrenModel(OrmXml ormXml) {
+ super(new EntityMappingsModel(ormXml), EntityMappings.PERSISTENT_TYPES_LIST);
+ }
+
+ @Override
+ protected ListIterable<OrmPersistentType> getListIterable() {
+ return subject.getPersistentTypes();
+ }
+
+ @Override
+ protected int size_() {
+ return subject.getPersistentTypesSize();
+ }
+ }
+
+ protected static class EntityMappingsModel
+ extends PropertyAspectAdapter<OrmXml, EntityMappings>
+ {
+ public EntityMappingsModel(OrmXml subject) {
+ super(OrmXml.ROOT_PROPERTY, subject);
+ }
+ @Override
+ protected EntityMappings buildValue_() {
+ return this.subject.getRoot();
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemLabelProvider.java
deleted file mode 100644
index 0cf2cb69dd..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/OrmXmlItemLabelProvider.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.orm.OrmXml;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.swt.graphics.Image;
-
-public class OrmXmlItemLabelProvider extends AbstractItemLabelProvider
-{
- public OrmXmlItemLabelProvider(
- OrmXml ormXml, DelegatingContentAndLabelProvider labelProvider) {
- super(ormXml, labelProvider);
- }
-
- @Override
- public OrmXml getModel() {
- return (OrmXml) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.JPA_FILE));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(getModel().getResource().getName());
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(getModel().getResource().getName());
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getParent().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceItemLabelProvider.java
deleted file mode 100644
index 1c757607d1..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceItemLabelProvider.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.swt.graphics.Image;
-
-public class PersistenceItemLabelProvider extends AbstractItemLabelProvider
-{
- public PersistenceItemLabelProvider(
- Persistence persistence, DelegatingContentAndLabelProvider labelProvider) {
- super(persistence, labelProvider);
- }
-
- @Override
- public Persistence getModel() {
- return (Persistence) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.PERSISTENCE));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(
- JptUiMessages.PersistenceItemLabelProviderFactory_persistenceLabel);
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(JptUiMessages.PersistenceItemLabelProviderFactory_persistenceLabel);
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemContentProvider.java
new file mode 100644
index 0000000000..e14aae60b8
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemContentProvider.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.platform.generic;
+
+import java.util.ArrayList;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.NotNullFilter;
+import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationListValueModel;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.context.JpaContextNode;
+import org.eclipse.jpt.jpa.core.context.MappingFile;
+import org.eclipse.jpt.jpa.core.context.java.JarFile;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceUnitItemContentProvider.ImpliedClassRefsModel;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceUnitItemContentProvider.ImpliedMappingFileRefModel;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceUnitItemContentProvider.JarFileRefsModel;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceUnitItemContentProvider.SpecifiedClassRefsModel;
+import org.eclipse.jpt.jpa.ui.internal.structure.PersistenceUnitItemContentProvider.SpecifiedMappingFileRefsModel;
+
+/**
+ * Item content provider for project explorer.
+ */
+public class PersistenceUnitItemContentProvider
+ extends AbstractItemTreeContentProvider<PersistenceUnit, JpaContextNode>
+{
+ public PersistenceUnitItemContentProvider(PersistenceUnit persistenceUnit, Manager manager) {
+ super(persistenceUnit, manager);
+ }
+
+ public PersistenceXml getParent() {
+ // skip the root 'persistence' element and return the persistence.xml file
+ return this.item.getParent().getParent();
+ }
+
+ @Override
+ protected CollectionValueModel<JpaContextNode> buildChildrenModel() {
+ ArrayList<CollectionValueModel<? extends JpaContextNode>> list = new ArrayList<CollectionValueModel<? extends JpaContextNode>>(4);
+ this.addChildrenModelsTo(list);
+ return new CompositeCollectionValueModel<CollectionValueModel<? extends JpaContextNode>, JpaContextNode>(list);
+ }
+
+ protected void addChildrenModelsTo(ArrayList<CollectionValueModel<? extends JpaContextNode>> list) {
+ list.add(this.buildNotNullSpecifiedMappingFilesModel());
+ list.add(this.buildImpliedMappingFilesModel());
+ list.add(this.buildNotNullPersistentTypesModel());
+ list.add(this.buildNotNullJarFilesModel());
+ }
+
+
+ // ********** specified mapping files **********
+
+ protected CollectionValueModel<MappingFile> buildNotNullSpecifiedMappingFilesModel() {
+ return new FilteringCollectionValueModel<MappingFile>(
+ this.buildSpecifiedMappingFilesModel(),
+ NotNullFilter.<MappingFile>instance()
+ );
+ }
+
+ protected ListValueModel<MappingFile> buildSpecifiedMappingFilesModel() {
+ return new TransformationListValueModel<MappingFileRef, MappingFile>(
+ this.buildSpecifiedMappingFileRefsModel(),
+ MappingFileRef.MAPPING_FILE_TRANSFORMER
+ );
+ }
+
+ protected ListValueModel<MappingFileRef> buildSpecifiedMappingFileRefsModel() {
+ return new ItemPropertyListValueModelAdapter<MappingFileRef>(
+ this.buildSpecifiedMappingFileRefsModel_(),
+ MappingFileRef.MAPPING_FILE_PROPERTY
+ );
+ }
+
+ protected ListValueModel<MappingFileRef> buildSpecifiedMappingFileRefsModel_() {
+ return new SpecifiedMappingFileRefsModel(this.item);
+ }
+
+
+ // ********** implied mapping file **********
+
+ /**
+ * No need to filter this list model as it will be empty if the wrapped
+ * property model is <code>null</code>.
+ */
+ protected CollectionValueModel<MappingFile> buildImpliedMappingFilesModel() {
+ return new PropertyCollectionValueModelAdapter<MappingFile>(this.buildImpliedMappingFileModel());
+ }
+
+ protected PropertyValueModel<MappingFile> buildImpliedMappingFileModel() {
+ return new ImpliedMappingFileModel(this.buildImpliedMappingFileRefModel());
+ }
+
+ public static class ImpliedMappingFileModel
+ extends PropertyAspectAdapter<MappingFileRef, MappingFile>
+ {
+ public ImpliedMappingFileModel(PropertyValueModel<MappingFileRef> refModel) {
+ super(refModel, MappingFileRef.MAPPING_FILE_PROPERTY);
+ }
+ @Override
+ protected MappingFile buildValue_() {
+ return this.subject.getMappingFile();
+ }
+ }
+
+ protected PropertyValueModel<MappingFileRef> buildImpliedMappingFileRefModel() {
+ return new ImpliedMappingFileRefModel(this.item);
+ }
+
+
+ // ********** persistent types **********
+
+ protected CollectionValueModel<JavaPersistentType> buildNotNullPersistentTypesModel() {
+ return new FilteringCollectionValueModel<JavaPersistentType>(
+ this.buildPersistentTypesModel(),
+ NotNullFilter.<JavaPersistentType>instance()
+ );
+ }
+
+ protected ListValueModel<JavaPersistentType> buildPersistentTypesModel() {
+ return new TransformationListValueModel<ClassRef, JavaPersistentType>(
+ this.buildClassRefsModel(),
+ ClassRef.JAVA_PERSISTENT_TYPE_TRANSFORMER
+ );
+ }
+
+ protected ListValueModel<ClassRef> buildClassRefsModel() {
+ return new ItemPropertyListValueModelAdapter<ClassRef>(
+ this.buildClassRefsModel_(),
+ ClassRef.JAVA_PERSISTENT_TYPE_PROPERTY
+ );
+ }
+
+ protected CollectionValueModel<ClassRef> buildClassRefsModel_() {
+ ArrayList<CollectionValueModel<ClassRef>> list = new ArrayList<CollectionValueModel<ClassRef>>(2);
+ list.add(this.buildSpecifiedClassRefsModel());
+ list.add(this.buildImpliedClassRefsModel());
+ return new CompositeCollectionValueModel<CollectionValueModel<ClassRef>, ClassRef>(list);
+ }
+
+ protected CollectionValueModel<ClassRef> buildSpecifiedClassRefsModel() {
+ return new ListCollectionValueModelAdapter<ClassRef>(this.buildSpecifiedClassRefsModel_());
+ }
+
+ protected ListValueModel<ClassRef> buildSpecifiedClassRefsModel_() {
+ return new SpecifiedClassRefsModel(this.item);
+ }
+
+ protected CollectionValueModel<ClassRef> buildImpliedClassRefsModel() {
+ return new ImpliedClassRefsModel(this.item);
+ }
+
+
+ // ********** jar files **********
+
+ protected CollectionValueModel<JarFile> buildNotNullJarFilesModel() {
+ return new FilteringCollectionValueModel<JarFile>(
+ this.buildJarFilesModel(),
+ NotNullFilter.<JarFile>instance()
+ );
+ }
+
+ protected ListValueModel<JarFile> buildJarFilesModel() {
+ return new TransformationListValueModel<JarFileRef, JarFile>(
+ this.buildJarFileRefsModel(),
+ JarFileRef.JAR_FILE_TRANSFORMER
+ );
+ }
+
+ protected ListValueModel<JarFileRef> buildJarFileRefsModel() {
+ return new ItemPropertyListValueModelAdapter<JarFileRef>(
+ this.buildJarFileRefsModel_(),
+ JarFileRef.JAR_FILE_PROPERTY
+ );
+ }
+
+ protected ListValueModel<JarFileRef> buildJarFileRefsModel_() {
+ return new JarFileRefsModel(this.item);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java
index 3f07076449..56a2990a1a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java
@@ -1,62 +1,162 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.internal.model.value.CompositePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.context.JpaContextNode;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
import org.eclipse.swt.graphics.Image;
-public class PersistenceUnitItemLabelProvider extends AbstractItemLabelProvider
+public class PersistenceUnitItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<PersistenceUnit>
{
- public PersistenceUnitItemLabelProvider(
- PersistenceUnit persistenceUnit, DelegatingContentAndLabelProvider labelProvider) {
- super(persistenceUnit, labelProvider);
+ protected final Image image;
+
+ public PersistenceUnitItemLabelProvider(PersistenceUnit persistenceUnit, ItemLabelProvider.Manager manager) {
+ super(persistenceUnit, manager);
+ this.image = this.buildImage();
}
-
+
@Override
- public PersistenceUnit getModel() {
- return (PersistenceUnit) super.getModel();
+ public Image getImage() {
+ return this.image;
}
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.PERSISTENCE_UNIT));
+ protected Image buildImage() {
+ return JptJpaUiPlugin.getImage(JptUiIcons.PERSISTENCE_UNIT);
}
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<PersistenceUnit, String>(PersistenceUnit.NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- return this.subject.getName();
- }
- };
+ return new TextModel(this.item);
+ }
+
+ protected static class TextModel
+ extends PropertyAspectAdapter<PersistenceUnit, String>
+ {
+ public TextModel(PersistenceUnit subject) {
+ super(PersistenceUnit.NAME_PROPERTY, subject);
+ }
+ @Override
+ protected String buildValue_() {
+ return this.subject.getName();
+ }
}
@Override
protected PropertyValueModel<String> buildDescriptionModel() {
- return new PropertyAspectAdapter<PersistenceUnit, String>(PersistenceUnit.NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- StringBuilder sb = new StringBuilder();
- sb.append(this.subject.getName());
- sb.append(" - "); //$NON-NLS-1$
- sb.append(this.subject.getResource().getFullPath().makeRelative());
- return sb.toString();
+ return new DescriptionModel(this.item);
+ }
+
+ protected static class DescriptionModel
+ extends TextModel
+ {
+ public DescriptionModel(PersistenceUnit subject) {
+ super(subject);
+ }
+ @Override
+ protected String buildValue_() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.buildValue_());
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(this.subject.getResource().getFullPath().makeRelative());
+ return sb.toString();
+ }
+ }
+
+
+ // ********** component description model **********
+
+ @SuppressWarnings("unchecked")
+ public static PropertyValueModel<String> buildQuotedComponentDescriptionModel(JpaContextNode node, PropertyValueModel<String> nodeTextModel) {
+ return buildComponentDescriptionModel(node, true, nodeTextModel);
+ }
+
+ public static PropertyValueModel<String> buildNonQuotedComponentDescriptionModel(JpaContextNode node, PropertyValueModel<String>... nodeTextModels) {
+ return buildComponentDescriptionModel(node, false, nodeTextModels);
+ }
+
+ protected static PropertyValueModel<String> buildComponentDescriptionModel(JpaContextNode node, boolean quote, PropertyValueModel<String>... nodeTextModel) {
+ return new ComponentDescriptionModel(
+ nodeTextModel,
+ new TextModel(node.getPersistenceUnit()),
+ node.getResource().getFullPath().makeRelative().toString(),
+ quote
+ );
+ }
+
+ public static class ComponentDescriptionModel
+ extends CompositePropertyValueModel<String, Object>
+ {
+ protected final PropertyValueModel<String>[] nodeTextModels;
+ protected final PropertyValueModel<String> persistenceUnitNameModel;
+ protected final String path;
+ protected final boolean quote;
+
+ @SuppressWarnings("unchecked")
+ ComponentDescriptionModel(
+ PropertyValueModel<String> nodeTextModel,
+ PropertyValueModel<String> persistenceUnitNameModel,
+ String path,
+ boolean quote
+ ) {
+ this(
+ new PropertyValueModel[] {nodeTextModel},
+ persistenceUnitNameModel,
+ path,
+ quote
+ );
+ }
+
+ ComponentDescriptionModel(
+ PropertyValueModel<String>[] nodeTextModels,
+ PropertyValueModel<String> persistenceUnitNameModel,
+ String path,
+ boolean quote
+ ) {
+ super(ArrayTools.add(nodeTextModels, persistenceUnitNameModel));
+ if (nodeTextModels.length < 1) {
+ throw new IllegalArgumentException();
+ }
+ this.nodeTextModels = nodeTextModels;
+ this.persistenceUnitNameModel = persistenceUnitNameModel;
+ this.path = path;
+ this.quote = quote;
+ }
+
+ @Override
+ protected String buildValue() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(this.persistenceUnitNameModel.getValue());
+ sb.append('/');
+ if (this.quote) {
+ sb.append('\"');
+ }
+ sb.append(this.nodeTextModels[0].getValue());
+ for (int i = 1; i < this.nodeTextModels.length; i++) {
+ sb.append('/');
+ sb.append(this.nodeTextModels[i].getValue());
+ }
+ if (this.quote) {
+ sb.append('\"');
}
- };
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(this.path);
+ return sb.toString();
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java
index 8cc30503a8..a84ff17038 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,8 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
@@ -22,39 +21,48 @@ import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
public class PersistenceXmlItemContentProvider
- extends AbstractTreeItemContentProvider<PersistenceUnit>
+ extends AbstractItemTreeContentProvider<PersistenceXml, PersistenceUnit>
{
- public PersistenceXmlItemContentProvider(
- PersistenceXml persistenceXml, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistenceXml, contentProvider);
+ public PersistenceXmlItemContentProvider(PersistenceXml persistenceXml, Manager manager) {
+ super(persistenceXml, manager);
}
- @Override
- public PersistenceXml getModel() {
- return (PersistenceXml) super.getModel();
- }
-
- @Override
public JpaRootContextNode getParent() {
- return (JpaRootContextNode) getModel().getParent();
+ return (JpaRootContextNode) this.item.getParent();
}
@Override
protected CollectionValueModel<PersistenceUnit> buildChildrenModel() {
- return new ListCollectionValueModelAdapter<PersistenceUnit>(
- new ListAspectAdapter<Persistence, PersistenceUnit>(
- new PropertyAspectAdapter<PersistenceXml, Persistence>(
- PersistenceXml.PERSISTENCE_PROPERTY, getModel()) {
- @Override
- protected Persistence buildValue_() {
- return subject.getPersistence();
- }
- },
- Persistence.PERSISTENCE_UNITS_LIST) {
- @Override
- protected ListIterable<PersistenceUnit> getListIterable() {
- return subject.getPersistenceUnits();
- }
- });
+ return new ListCollectionValueModelAdapter<PersistenceUnit>(new ChildrenModel(this.item));
+ }
+
+ protected static class ChildrenModel
+ extends ListAspectAdapter<Persistence, PersistenceUnit>
+ {
+ ChildrenModel(PersistenceXml subject) {
+ super(new PersistenceModel(subject), Persistence.PERSISTENCE_UNITS_LIST);
+ }
+
+ @Override
+ protected ListIterable<PersistenceUnit> getListIterable() {
+ return subject.getPersistenceUnits();
+ }
+
+ @Override
+ protected int size_() {
+ return subject.getPersistenceUnitsSize();
+ }
+ }
+
+ protected static class PersistenceModel
+ extends PropertyAspectAdapter<PersistenceXml, Persistence>
+ {
+ public PersistenceModel(PersistenceXml subject) {
+ super(PersistenceXml.PERSISTENCE_PROPERTY, subject);
+ }
+ @Override
+ protected Persistence buildValue_() {
+ return this.subject.getPersistence();
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java
deleted file mode 100644
index c8c8b9a2fd..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.swt.graphics.Image;
-
-public class PersistenceXmlItemLabelProvider extends AbstractItemLabelProvider
-{
- public PersistenceXmlItemLabelProvider(
- PersistenceXml persistenceXml, DelegatingContentAndLabelProvider labelProvider) {
- super(persistenceXml, labelProvider);
- }
-
- @Override
- public PersistenceXml getModel() {
- return (PersistenceXml) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.JPA_FILE));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(getModel().getResource().getName());
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(getModel().getResource().getName());
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getParent().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java
deleted file mode 100644
index bdde1fde4e..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
-
-@SuppressWarnings("unchecked")
-public class PersistentAttributeItemContentProvider extends AbstractTreeItemContentProvider
-{
- public PersistentAttributeItemContentProvider(
- PersistentAttribute persistentAttribute, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistentAttribute, contentProvider);
- }
-
- @Override
- public PersistentAttribute getModel() {
- return (PersistentAttribute) super.getModel();
- }
-
- @Override
- public Object getParent() {
- return getModel().getParent();
- }
-
- @Override
- public boolean hasChildren() {
- return false;
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java
index 874c05c1ae..cffa203c34 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java
@@ -1,17 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
@@ -20,61 +19,60 @@ import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
import org.eclipse.swt.graphics.Image;
public class PersistentAttributeItemLabelProvider
- extends AbstractItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<ReadOnlyPersistentAttribute>
{
- public PersistentAttributeItemLabelProvider(
- ReadOnlyPersistentAttribute persistentAttribute, DelegatingContentAndLabelProvider labelProvider) {
- super(persistentAttribute, labelProvider);
+ public PersistentAttributeItemLabelProvider(ReadOnlyPersistentAttribute persistentAttribute, ItemLabelProvider.Manager manager) {
+ super(persistentAttribute, manager);
}
-
- @Override
- public ReadOnlyPersistentAttribute getModel() {
- return (ReadOnlyPersistentAttribute) super.getModel();
- }
-
+
@Override
protected PropertyValueModel<Image> buildImageModel() {
- return new PropertyAspectAdapter<ReadOnlyPersistentAttribute, Image>(
- new String[] {ReadOnlyPersistentAttribute.DEFAULT_MAPPING_KEY_PROPERTY, ReadOnlyPersistentAttribute.MAPPING_PROPERTY},
- getModel()) {
- @Override
- protected Image buildValue_() {
- if (getModel().isVirtual()) {
- return JptUiIcons.ghost(JpaMappingImageHelper.iconKeyForAttributeMapping(this.subject.getMappingKey()));
- }
- return JpaMappingImageHelper.imageForAttributeMapping(this.subject.getMappingKey());
- }
- };
+ return new ImageModel(this.item);
}
-
+
+ protected static class ImageModel
+ extends PropertyAspectAdapter<ReadOnlyPersistentAttribute, Image>
+ {
+ public ImageModel(ReadOnlyPersistentAttribute subject) {
+ super(ReadOnlyPersistentAttribute.MAPPING_PROPERTY, subject);
+ }
+ @Override
+ protected Image buildValue_() {
+ String mappingKey = this.subject.getMappingKey();
+ return this.subject.isVirtual() ?
+ JptUiIcons.ghost(JpaMappingImageHelper.iconKeyForAttributeMapping(mappingKey)) :
+ JpaMappingImageHelper.imageForAttributeMapping(mappingKey);
+ }
+ }
+
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<ReadOnlyPersistentAttribute, String>(ReadOnlyPersistentAttribute.NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- return this.subject.getName();
- }
- };
+ return new TextModel(this.item);
}
-
+
+ protected static class TextModel
+ extends PropertyAspectAdapter<ReadOnlyPersistentAttribute, String>
+ {
+ public TextModel(ReadOnlyPersistentAttribute subject) {
+ super(ReadOnlyPersistentAttribute.NAME_PROPERTY, subject);
+ }
+ @Override
+ protected String buildValue_() {
+ return this.subject.getName();
+ }
+ }
+
@Override
+ @SuppressWarnings("unchecked")
protected PropertyValueModel<String> buildDescriptionModel() {
- return new PropertyAspectAdapter<ReadOnlyPersistentAttribute, String>(ReadOnlyPersistentAttribute.NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- StringBuilder sb = new StringBuilder();
- sb.append(this.subject.getPersistenceUnit().getName());
- sb.append('/');
- sb.append(this.subject.getOwningPersistentType().getName());
- sb.append('/');
- sb.append(this.subject.getName());
- IResource resource = this.subject.getResource();
- if (resource != null) {
- sb.append(" - "); //$NON-NLS-1$
- sb.append(resource.getFullPath().makeRelative());
- }
- return sb.toString();
- }
- };
+ return PersistenceUnitItemLabelProvider.buildNonQuotedComponentDescriptionModel(
+ this.item,
+ this.buildTypeTextModel(),
+ this.textModel
+ );
+ }
+
+ protected PropertyValueModel<String> buildTypeTextModel() {
+ return new PersistentTypeItemLabelProvider.TextModel(this.item.getOwningPersistentType());
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java
index 91fbab1338..f1742adf2b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java
@@ -1,71 +1,69 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.ui.internal.JpaMappingImageHelper;
import org.eclipse.swt.graphics.Image;
-public class PersistentTypeItemLabelProvider extends AbstractItemLabelProvider
+public class PersistentTypeItemLabelProvider
+ extends AbstractItemExtendedLabelProvider<PersistentType>
{
- public PersistentTypeItemLabelProvider(
- PersistentType persistentType, DelegatingContentAndLabelProvider labelProvider) {
- super(persistentType, labelProvider);
+ public PersistentTypeItemLabelProvider(PersistentType persistentType, ItemLabelProvider.Manager manager) {
+ super(persistentType, manager);
}
@Override
- public PersistentType getModel() {
- return (PersistentType) super.getModel();
+ protected PropertyValueModel<Image> buildImageModel() {
+ return new ImageModel(this.item);
}
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new PropertyAspectAdapter<PersistentType, Image>(PersistentType.MAPPING_PROPERTY, getModel()) {
- @Override
- protected Image buildValue_() {
- return JpaMappingImageHelper.imageForTypeMapping(this.subject.getMappingKey());
- }
- };
+ protected static class ImageModel
+ extends PropertyAspectAdapter<PersistentType, Image>
+ {
+ public ImageModel(PersistentType subject) {
+ super(PersistentType.MAPPING_PROPERTY, subject);
+ }
+ @Override
+ protected Image buildValue_() {
+ return JpaMappingImageHelper.imageForTypeMapping(this.subject.getMappingKey());
+ }
}
@Override
protected PropertyValueModel<String> buildTextModel() {
- return new PropertyAspectAdapter<PersistentType, String>(PersistentType.NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- return this.subject.getSimpleName();
- }
- };
+ return new TextModel(this.item);
+ }
+
+ protected static class TextModel
+ extends PropertyAspectAdapter<PersistentType, String>
+ {
+ public TextModel(PersistentType subject) {
+ super(PersistentType.NAME_PROPERTY, subject);
+ }
+ @Override
+ protected String buildValue_() {
+ return this.subject.getSimpleName();
+ }
}
@Override
+ @SuppressWarnings("unchecked")
protected PropertyValueModel<String> buildDescriptionModel() {
- return new PropertyAspectAdapter<PersistentType, String>(PersistentType.NAME_PROPERTY, getModel()) {
- @Override
- protected String buildValue_() {
- StringBuilder sb = new StringBuilder();
- sb.append(this.subject.getPersistenceUnit().getName());
- sb.append('/');
- sb.append(this.subject.getName());
- IResource resource = this.subject.getResource();
- if (resource != null) {
- sb.append(" - "); //$NON-NLS-1$
- sb.append(resource.getFullPath().makeRelative());
- }
- return sb.toString();
- }
- };
+ return PersistenceUnitItemLabelProvider.buildNonQuotedComponentDescriptionModel(
+ this.item,
+ this.textModel
+ );
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemContentProvider.java
deleted file mode 100644
index ef65255289..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemContentProvider.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
-
-public class RootContextItemContentProvider
- extends AbstractTreeItemContentProvider<PersistenceXml>
-{
- public RootContextItemContentProvider(
- JpaRootContextNode rootContext, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(rootContext, contentProvider);
- }
-
- @Override
- public JpaRootContextNode getModel() {
- return (JpaRootContextNode) super.getModel();
- }
-
- @Override
- public IProject getParent() {
- return getModel().getJpaProject().getProject();
- }
-
- @Override
- protected CollectionValueModel<PersistenceXml> buildChildrenModel() {
- return new PropertyCollectionValueModelAdapter<PersistenceXml>(
- new PropertyAspectAdapter<JpaRootContextNode, PersistenceXml>(
- JpaRootContextNode.PERSISTENCE_XML_PROPERTY,
- getModel()) {
- @Override
- protected PersistenceXml buildValue_() {
- return subject.getPersistenceXml();
- }
- });
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemLabelProvider.java
deleted file mode 100644
index 306a90a75e..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/RootContextItemLabelProvider.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.platform.generic;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.StaticPropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
-import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.swt.graphics.Image;
-
-public class RootContextItemLabelProvider extends AbstractItemLabelProvider
-{
- public RootContextItemLabelProvider(
- JpaRootContextNode rootContextNode, DelegatingContentAndLabelProvider labelProvider) {
- super(rootContextNode, labelProvider);
- }
-
- @Override
- public JpaRootContextNode getModel() {
- return (JpaRootContextNode) super.getModel();
- }
-
- @Override
- protected PropertyValueModel<Image> buildImageModel() {
- return new StaticPropertyValueModel<Image>(JptJpaUiPlugin.getImage(JptUiIcons.JPA_CONTENT));
- }
-
- @Override
- protected PropertyValueModel<String> buildTextModel() {
- return new StaticPropertyValueModel<String>(JptUiMessages.JpaContent_label);
- }
-
- @Override
- protected PropertyValueModel<String> buildDescriptionModel() {
- StringBuilder sb = new StringBuilder();
- sb.append(JptUiMessages.JpaContent_label);
- sb.append(" - "); //$NON-NLS-1$
- sb.append(getModel().getResource().getFullPath().makeRelative());
- return new StaticPropertyValueModel<String>(sb.toString());
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java
index 82bb18aee2..0891871651 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/preferences/JpaProblemSeveritiesPage.java
@@ -831,6 +831,8 @@ public class JpaProblemSeveritiesPage extends PropertyAndPreferencePage {
this.buildOkProgressMonitorDialog().run(true, false, this.buildOkRunnableWithProgress());
}
catch (InterruptedException ex) {
+ // should *not* happen...
+ Thread.currentThread().interrupt();
return false;
}
catch (InvocationTargetException ex) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java
index 9b89e05d06..280ca69750 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -17,7 +17,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.IJavaElement;
@@ -31,9 +33,12 @@ import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
import org.eclipse.jpt.common.ui.internal.utility.swt.SWTTools;
import org.eclipse.jpt.common.utility.internal.BitTools;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.FilterAdapter;
import org.eclipse.jpt.common.utility.internal.NotBooleanTransformer;
import org.eclipse.jpt.common.utility.internal.StringConverter;
import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.Transformer;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
@@ -41,9 +46,9 @@ import org.eclipse.jpt.common.utility.internal.model.value.AbstractCollectionVal
import org.eclipse.jpt.common.utility.internal.model.value.AspectCollectionValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.BufferedWritablePropertyValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.CachingTransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.CompositeCollectionValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.CompositePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.ExtendedListValueModelWrapper;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter;
@@ -53,10 +58,8 @@ import org.eclipse.jpt.common.utility.internal.model.value.StaticCollectionValue
import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
import org.eclipse.jpt.common.utility.internal.model.value.TransformationWritablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.Model;
-import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
-import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
-import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
@@ -65,10 +68,8 @@ import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaDataSource;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
-import org.eclipse.jpt.jpa.core.internal.platform.JpaPlatformDescriptionImpl;
import org.eclipse.jpt.jpa.core.jpa2.JpaProject2_0;
import org.eclipse.jpt.jpa.core.libprov.JpaLibraryProviderInstallOperationConfig;
import org.eclipse.jpt.jpa.core.platform.JpaPlatformDescription;
@@ -83,9 +84,11 @@ import org.eclipse.jpt.jpa.db.Database;
import org.eclipse.jpt.jpa.db.JptJpaDbPlugin;
import org.eclipse.jpt.jpa.db.SchemaContainer;
import org.eclipse.jpt.jpa.db.ui.internal.DTPUiTools;
+import org.eclipse.jpt.jpa.ui.JpaProjectModel;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.jpa2.Jpa2_0ProjectFlagModel;
+import org.eclipse.jpt.jpa.ui.internal.jpa2.Jpa2_0FlagTransformer;
import org.eclipse.jst.common.project.facet.core.libprov.ILibraryProvider;
import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate;
import org.eclipse.jst.common.project.facet.core.libprov.LibraryProviderOperationConfig;
@@ -93,7 +96,6 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -112,41 +114,42 @@ import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
* Way more complicated UI than you would think....
*/
public class JpaProjectPropertiesPage
- extends JptProjectPropertiesPage {
-
+ extends JptProjectPropertiesPage
+{
public static final String PROP_ID = "org.eclipse.jpt.jpa.ui.jpaProjectProperties"; //$NON-NLS-1$
-
+
private PropertyValueModel<JpaProject> jpaProjectModel;
-
+ private PropertyValueModel<Boolean> jpaProjectNotNullFlagModel;
+
private BufferedWritablePropertyValueModel<String> platformIdModel;
private PropertyChangeListener platformIdListener;
-
+
private BufferedWritablePropertyValueModel<String> connectionModel;
private PropertyValueModel<ConnectionProfile> connectionProfileModel;
private PropertyValueModel<Boolean> disconnectedModel;
private PropertyChangeListener disconnectedModelListener;
private Link connectLink;
-
+
private BufferedWritablePropertyValueModel<Boolean> userOverrideDefaultCatalogFlagModel;
private BufferedWritablePropertyValueModel<String> userOverrideDefaultCatalogModel;
private WritablePropertyValueModel<String> defaultCatalogModel;
private ListValueModel<String> catalogChoicesModel;
-
+
private BufferedWritablePropertyValueModel<Boolean> userOverrideDefaultSchemaFlagModel;
private BufferedWritablePropertyValueModel<String> userOverrideDefaultSchemaModel;
private WritablePropertyValueModel<String> defaultSchemaModel;
private ListValueModel<String> schemaChoicesModel;
-
+
private BufferedWritablePropertyValueModel<Boolean> discoverAnnotatedClassesModel;
private WritablePropertyValueModel<Boolean> listAnnotatedClassesModel;
-
+
private PropertyValueModel<Boolean> jpa2_0ProjectFlagModel;
-
+
private BufferedWritablePropertyValueModel<String> metamodelSourceFolderModel;
private ListValueModel<String> javaSourceFolderChoicesModel;
-
+
private static final String BUILD_PATHS_PROPERTY_PAGE_ID = "org.eclipse.jdt.ui.propertyPages.BuildPathsPropertyPage"; //$NON-NLS-1$
-
+
/* private */ static final Comparator<String> STRING_COMPARATOR = new ICUStringCollator();
// ************ construction ************
@@ -154,18 +157,19 @@ public class JpaProjectPropertiesPage
public JpaProjectPropertiesPage() {
super();
}
-
+
@Override
protected void buildModels() {
- this.jpaProjectModel = new JpaProjectModel(this.projectModel);
-
+ this.jpaProjectModel = this.buildJpaProjectModel();
+ this.jpaProjectNotNullFlagModel = this.buildJpaProjectNotNullFlagModel();
+
this.platformIdModel = this.buildPlatformIdModel();
this.platformIdListener = this.buildPlatformIdListener();
-
+
this.connectionModel = this.buildConnectionModel();
this.connectionProfileModel = this.buildConnectionProfileModel();
this.disconnectedModel = this.buildDisconnectedModel();
- this.disconnectedModelListener = buildDisconnectedModelListener();
+ this.disconnectedModelListener = this.buildDisconnectedModelListener();
this.userOverrideDefaultCatalogFlagModel = this.buildUserOverrideDefaultCatalogFlagModel();
this.userOverrideDefaultCatalogModel = this.buildUserOverrideDefaultCatalogModel();
@@ -186,24 +190,65 @@ public class JpaProjectPropertiesPage
this.javaSourceFolderChoicesModel = this.buildJavaSourceFolderChoicesModel();
}
+ // ***** JPA project model
+ private PropertyValueModel<JpaProject> buildJpaProjectModel() {
+ return new DoublePropertyValueModel<JpaProject>(this.buildJpaProjectModelModel());
+ }
+
+ private PropertyValueModel<PropertyValueModel<JpaProject>> buildJpaProjectModelModel() {
+ return new TransformationPropertyValueModel<IProject, PropertyValueModel<JpaProject>>(this.projectModel, JPA_PROJECT_MODEL_TRANSFORMER);
+ }
+
+ private static final Transformer<IProject, PropertyValueModel<JpaProject>> JPA_PROJECT_MODEL_TRANSFORMER = new JpaProjectModelTransformer();
+
+ /* CU private */ static class JpaProjectModelTransformer
+ extends AbstractTransformer<IProject, PropertyValueModel<JpaProject>>
+ {
+ @Override
+ protected PropertyValueModel<JpaProject> transform_(IProject project) {
+ return (JpaProjectModel) project.getAdapter(JpaProjectModel.class);
+ }
+ }
+
+ // ***** JPA project not null model
+ private PropertyValueModel<Boolean> buildJpaProjectNotNullFlagModel() {
+ return new TransformationPropertyValueModel<JpaProject, Boolean>(this.jpaProjectModel, JPA_PROJECT_NOT_NULL_TRANSFORMER);
+ }
+
+ private static final Transformer<JpaProject, Boolean> JPA_PROJECT_NOT_NULL_TRANSFORMER = new JpaProjectNotNullTransformer();
+
+ /* CU private */ static class JpaProjectNotNullTransformer
+ extends AbstractTransformer<JpaProject, Boolean>
+ {
+ @Override
+ protected Boolean transform_(JpaProject jpaProject) {
+ return Boolean.TRUE; // if we get here, the JPA project is not null
+ }
+ }
+
// ***** platform ID model
private BufferedWritablePropertyValueModel<String> buildPlatformIdModel() {
return new BufferedWritablePropertyValueModel<String>(new PlatformIdModel(this.jpaProjectModel), this.trigger);
}
private PropertyChangeListener buildPlatformIdListener(){
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- JpaProjectPropertiesPage.this.platformIdChanged((String) event.getNewValue());
- }
- };
+ return new PlatformIdListener();
}
- void platformIdChanged(String newPlatformId) {
+ /* CU private */ class PlatformIdListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaProjectPropertiesPage.this.platformIdChanged();
+ }
+ }
+
+ void platformIdChanged() {
if ( ! this.getControl().isDisposed()) {
// handle null, in the case the jpa facet is changed via the facets page,
// the library install delegate is temporarily null
- adjustLibraryProviders();
+ this.adjustLibraryProviders();
}
}
@@ -316,12 +361,12 @@ public class JpaProjectPropertiesPage
* The opposite of the "discover annotated classes" flag.
*/
private WritablePropertyValueModel<Boolean> buildListAnnotatedClassesModel() {
- return new TransformationWritablePropertyValueModel<Boolean, Boolean>(this.discoverAnnotatedClassesModel, NotBooleanTransformer.instance());
+ return new TransformationWritablePropertyValueModel<Boolean, Boolean>(this.discoverAnnotatedClassesModel, NotBooleanTransformer.instance(), NotBooleanTransformer.instance());
}
-
+
// ***** JPA 2.0 project flag
private PropertyValueModel<Boolean> buildJpa2_0ProjectFlagModel() {
- return new Jpa2_0ProjectFlagModel<JpaProject>(this.jpaProjectModel);
+ return Jpa2_0FlagTransformer.convertToFlagModel(this.jpaProjectModel);
}
// ***** metamodel models
@@ -367,7 +412,7 @@ public class JpaProjectPropertiesPage
}
private IWorkbenchPreferenceContainer getWorkbenchPreferenceContainer() {
- IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer) getContainer();
+ IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer) this.getContainer();
return container;
}
@@ -377,64 +422,67 @@ public class JpaProjectPropertiesPage
public IProjectFacetVersion getProjectFacetVersion() {
return this.getFacetedProject().getInstalledVersion(JpaFacet.FACET);
}
-
+
@Override
protected LibraryInstallDelegate createLibraryInstallDelegate(IFacetedProject project, IProjectFacetVersion fv) {
Map<String, Object> enablementVariables = new HashMap<String, Object>();
-
+
//TODO Ask Paul about these empty enablement variables - trying to reproduce Helios functionality
enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, ""); //$NON-NLS-1$
- enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, new JpaPlatformDescription() {
-
- public boolean supportsJpaFacetVersion(IProjectFacetVersion jpaFacetVersion) {
- return false;
- }
-
- public boolean isDefault() {
- return false;
- }
-
- public String getPluginId() {
- return null;
- }
-
- public String getLabel() {
- return null;
- }
-
- public String getId() {
- return null;
- }
-
- public JpaPlatformGroupDescription getGroup() {
- return null;
- }
-
- public String getFactoryClassName() {
- return null;
- }
- });
-
+ enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, new EmptyJpaPlatformDescription());
+
LibraryInstallDelegate lid = new LibraryInstallDelegate(project, fv, enablementVariables);
- lid.addListener(buildLibraryProviderListener());
+ lid.addListener(this.buildLibraryProviderListener());
return lid;
}
+ /* CU private */ class EmptyJpaPlatformDescription
+ implements JpaPlatformDescription
+ {
+ public boolean supportsJpaFacetVersion(IProjectFacetVersion jpaFacetVersion) {
+ return false;
+ }
+
+ public boolean isDefault() {
+ return false;
+ }
+
+ public String getPluginId() {
+ return null;
+ }
+
+ public String getLabel() {
+ return null;
+ }
+
+ public String getId() {
+ return null;
+ }
+
+ public JpaPlatformGroupDescription getGroup() {
+ return null;
+ }
+
+ public String getFactoryClassName() {
+ return null;
+ }
+ }
+
@Override
protected void adjustLibraryProviders() {
LibraryInstallDelegate lid = this.getLibraryInstallDelegate();
-
+
if (lid != null) {
- JpaPlatformDescription jpaPlatform =
+ JpaPlatformDescription jpaPlatform =
JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatform(this.platformIdModel.getValue());
- String jpaPlatformId = (jpaPlatform == null) ? "" : jpaPlatform.getId();
-
+ String jpaPlatformId = (jpaPlatform == null) ? "" : jpaPlatform.getId(); //$NON-NLS-1$
+
lid.setEnablementContextVariable(
JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, jpaPlatformId);
lid.setEnablementContextVariable(
JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, jpaPlatform);
-
- List<JpaLibraryProviderInstallOperationConfig> jpaConfigs
+
+ List<JpaLibraryProviderInstallOperationConfig> jpaConfigs
= new ArrayList<JpaLibraryProviderInstallOperationConfig>();
// add the currently selected one first
JpaLibraryProviderInstallOperationConfig currentJpaConfig = null;
@@ -445,7 +493,7 @@ public class JpaProjectPropertiesPage
}
for (ILibraryProvider lp : lid.getLibraryProviders()) {
config = lid.getLibraryProviderOperationConfig(lp);
- if (config instanceof JpaLibraryProviderInstallOperationConfig
+ if ((config instanceof JpaLibraryProviderInstallOperationConfig)
&& ! config.equals(currentJpaConfig)) {
jpaConfigs.add((JpaLibraryProviderInstallOperationConfig) config);
}
@@ -455,43 +503,44 @@ public class JpaProjectPropertiesPage
}
}
}
-
-
+
+
// ********** page **********
-
+
@Override
protected void createWidgets(Composite parent) {
this.buildPlatformGroup(parent);
-
+
Control libraryProviderComposite = createInstallLibraryPanel(
- parent,
- this.getLibraryInstallDelegate(),
+ parent,
+ this.getLibraryInstallDelegate(),
JptUiMessages.JpaFacetWizardPage_jpaImplementationLabel);
-
+
libraryProviderComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
+ SWTTools.controlEnabledState(this.jpaProjectNotNullFlagModel, libraryProviderComposite);
+
this.buildConnectionGroup(parent);
this.buildPersistentClassManagementGroup(parent);
this.buildMetamodelGroup(parent);
-
+
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE);
}
-
+
@Override
protected void engageListeners() {
super.engageListeners();
this.platformIdModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.platformIdListener);
this.disconnectedModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.disconnectedModelListener);
}
-
+
@Override
protected void disengageListeners() {
this.platformIdModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.platformIdListener);
this.disconnectedModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.disconnectedModelListener);
super.disengageListeners();
}
-
-
+
+
// ********** platform group **********
private void buildPlatformGroup(Composite composite) {
@@ -499,15 +548,17 @@ public class JpaProjectPropertiesPage
group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel);
group.setLayout(new GridLayout());
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- Combo platformDropDown = buildDropDown(group);
+
+ Combo platformDropDown = this.buildDropDown(group);
SWTTools.bind(
- buildPlatformChoicesModel(),
+ this.buildPlatformChoicesModel(),
this.platformIdModel,
platformDropDown,
JPA_PLATFORM_LABEL_CONVERTER);
-
- buildFacetsPageLink(group, JptUiMessages.JpaFacetWizardPage_facetsPageLink);
+
+ Link facetsPageLink = this.buildFacetsPageLink(group, JptUiMessages.JpaFacetWizardPage_facetsPageLink);
+
+ SWTTools.controlEnabledState(this.jpaProjectNotNullFlagModel, group, platformDropDown, facetsPageLink);
}
/**
@@ -534,22 +585,37 @@ public class JpaProjectPropertiesPage
}
private CollectionValueModel<String> buildRegistryPlatformsModel() {
- Iterable<String> enabledPlatformIds =
+ Iterable<String> enabledPlatformIds =
new TransformationIterable<JpaPlatformDescription, String>(
- new FilteringIterable<JpaPlatformDescription>(JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatforms()) {
- @Override
- protected boolean accept(JpaPlatformDescription o) {
- return o.supportsJpaFacetVersion(getProjectFacetVersion());
- }
- }) {
- @Override
- protected String transform(JpaPlatformDescription o) {
- return o.getId();
- }
- };
+ new FilteringIterable<JpaPlatformDescription>(
+ JptJpaCorePlugin.getJpaPlatformManager().getJpaPlatforms(),
+ new JpaPlatformDescriptionFilter()
+ ),
+ JPA_PLATFORM_DESCRIPTION_ID_TRANSFORMER
+ );
return new StaticCollectionValueModel<String>(enabledPlatformIds);
}
+ /* CU private */ class JpaPlatformDescriptionFilter
+ extends FilterAdapter<JpaPlatformDescription>
+ {
+ @Override
+ public boolean accept(JpaPlatformDescription o) {
+ return o.supportsJpaFacetVersion(JpaProjectPropertiesPage.this.getProjectFacetVersion());
+ }
+ }
+
+ private static final Transformer<JpaPlatformDescription, String> JPA_PLATFORM_DESCRIPTION_ID_TRANSFORMER = new JpaPlatformDescriptionIdTransformer();
+
+ /* CU private */ static class JpaPlatformDescriptionIdTransformer
+ extends AbstractTransformer<JpaPlatformDescription, String>
+ {
+ @Override
+ public String transform_(JpaPlatformDescription o) {
+ return o.getId();
+ }
+ }
+
private static final Comparator<String> JPA_PLATFORM_COMPARATOR =
new Comparator<String>() {
public int compare(String id1, String id2) {
@@ -590,12 +656,12 @@ public class JpaProjectPropertiesPage
);
Link addConnectionLink = this.buildLink(group, JptUiMessages.JpaFacetWizardPage_connectionLink);
- addConnectionLink.addSelectionListener(this.buildAddConnectionLinkListener()); // the link will be GCed
+ addConnectionLink.addSelectionListener(new AddConnectionLinkListener()); // the link will be GCed
- this.connectLink = this.buildLink(group, buildConnectLinkText());
+ this.connectLink = this.buildLink(group, this.buildConnectLinkText());
SWTTools.controlEnabledState(this.disconnectedModel, this.connectLink);
- this.connectLink.addSelectionListener(this.buildConnectLinkListener()); // the link will be GCed
-
+ this.connectLink.addSelectionListener(new ConnectLinkListener()); // the link will be GCed
+
// override default catalog
Button overrideDefaultCatalogCheckBox = this.buildCheckBox(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultCatalogLabel);
SWTTools.bind(this.userOverrideDefaultCatalogFlagModel, overrideDefaultCatalogCheckBox);
@@ -615,6 +681,8 @@ public class JpaProjectPropertiesPage
SWTTools.bind(this.schemaChoicesModel, this.defaultSchemaModel, defaultSchemaDropDown);
SWTTools.controlEnabledState(this.userOverrideDefaultSchemaFlagModel, defaultSchemaLabel, defaultSchemaDropDown);
+
+ SWTTools.controlEnabledState(this.jpaProjectNotNullFlagModel, group, connectionDropDown, addConnectionLink, overrideDefaultCatalogCheckBox, overrideDefaultSchemaButton);
}
private static final StringConverter<String> SIMPLE_STRING_CONVERTER =
@@ -625,44 +693,45 @@ public class JpaProjectPropertiesPage
};
private PropertyChangeListener buildDisconnectedModelListener() {
- return new SWTPropertyChangeListenerWrapper(buildDisconnectedModelListener_());
+ return new SWTPropertyChangeListenerWrapper(new DisconnectedModelListener());
}
-
- private PropertyChangeListener buildDisconnectedModelListener_() {
- return new PropertyChangeListener() {
-
- public void propertyChanged(PropertyChangeEvent event) {
- JpaProjectPropertiesPage.this.updateConnectLinkText(buildConnectLinkText());
- }
- };
- }
-
- private String buildConnectLinkText(){
- ConnectionProfile connectionProfile = getConnectionProfile();
- if (connectionProfile != null && connectionProfile.isConnected()) {
- return JptUiMessages.JpaFacetWizardPage_connectedText;
- }
- else {
- return JptUiMessages.JpaFacetWizardPage_connectLink;
+
+ /* CU private */ class DisconnectedModelListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaProjectPropertiesPage.this.updateConnectLinkText();
}
}
-
+
+ /* CU private */ void updateConnectLinkText() {
+ this.updateConnectLinkText(this.buildConnectLinkText());
+ }
+
+ private String buildConnectLinkText() {
+ ConnectionProfile connectionProfile = this.getConnectionProfile();
+ return ((connectionProfile != null) && connectionProfile.isConnected()) ?
+ JptUiMessages.JpaFacetWizardPage_connectedText :
+ JptUiMessages.JpaFacetWizardPage_connectLink;
+ }
+
private void updateConnectLinkText(String text) {
- connectLink.setText(text);
- SWTUtil.reflow(connectLink.getParent());
+ this.connectLink.setText(text);
+ SWTUtil.reflow(this.connectLink.getParent());
}
- private SelectionListener buildAddConnectionLinkListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- JpaProjectPropertiesPage.this.openNewConnectionWizard();
- }
- @Override
- public String toString() {
- return "connection link listener"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class AddConnectionLinkListener
+ extends SelectionAdapter
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ JpaProjectPropertiesPage.this.openNewConnectionWizard();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
void openNewConnectionWizard() {
@@ -672,17 +741,17 @@ public class JpaProjectPropertiesPage
}
}
- private SelectionListener buildConnectLinkListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- JpaProjectPropertiesPage.this.openConnectionProfile();
- }
- @Override
- public String toString() {
- return "connect link listener"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class ConnectLinkListener
+ extends SelectionAdapter
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ JpaProjectPropertiesPage.this.openConnectionProfile();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
void openConnectionProfile() {
@@ -706,6 +775,8 @@ public class JpaProjectPropertiesPage
Button listClassesRadioButton = this.buildRadioButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton);
SWTTools.bind(this.listAnnotatedClassesModel, listClassesRadioButton);
+
+ SWTTools.controlEnabledState(this.jpaProjectNotNullFlagModel, group, discoverClassesRadioButton, listClassesRadioButton);
}
@@ -718,7 +789,7 @@ public class JpaProjectPropertiesPage
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Link metamodelSourceFolderLink = this.buildLink(group, JptUiMessages.JpaFacetWizardPage_metamodelSourceFolderLink);
- metamodelSourceFolderLink.addSelectionListener(buildMetamodelSourceFolderLinkListener());
+ metamodelSourceFolderLink.addSelectionListener(new MetamodelSourceFolderLinkListener()); // the link will be GCed
Combo metamodelSourceFolderDropDown = this.buildDropDown(group);
SWTTools.bind(
this.javaSourceFolderChoicesModel,
@@ -726,43 +797,55 @@ public class JpaProjectPropertiesPage
metamodelSourceFolderDropDown,
SIMPLE_STRING_CONVERTER
);
-
+
PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_METAMODEL);
SWTTools.controlVisibleState(this.jpa2_0ProjectFlagModel, group, metamodelSourceFolderLink, metamodelSourceFolderDropDown);
}
- private SelectionListener buildMetamodelSourceFolderLinkListener() {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- JpaProjectPropertiesPage.this.openJavaBuildPathPage();
- }
- @Override
- public String toString() {
- return "metamodel source folder link listener"; //$NON-NLS-1$
- }
- };
+ /* CU private */ class MetamodelSourceFolderLinkListener
+ extends SelectionAdapter
+ {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ JpaProjectPropertiesPage.this.openJavaBuildPathPage();
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
void openJavaBuildPathPage() {
- IWorkbenchPreferenceContainer container = getWorkbenchPreferenceContainer();
+ IWorkbenchPreferenceContainer container = this.getWorkbenchPreferenceContainer();
container.openPage(BUILD_PATHS_PROPERTY_PAGE_ID, null);
}
-
+
// ********** OK/Revert/Apply behavior **********
-
+
@Override
protected boolean projectRebuildRequired() {
return this.platformIdModel.isBuffering();
}
-
+
@Override
- protected void rebuildProject() {
+ protected void rebuildProject() throws CoreException {
// if the JPA platform is changed, we need to completely rebuild the JPA project
- JptJpaCorePlugin.rebuildJpaProject(this.getProject());
+ try {
+ this.rebuildProject_();
+ } catch (InterruptedException ex) {
+ throw new CoreException(new Status(IStatus.CANCEL, JptJpaUiPlugin.PLUGIN_ID, null, ex));
+ }
}
-
+
+ private void rebuildProject_() throws InterruptedException {
+ this.getJpaProjectReference().rebuild();
+ }
+
+ private JpaProject.Reference getJpaProjectReference() {
+ return ((JpaProject.Reference) this.getProject().getAdapter(JpaProject.Reference.class));
+ }
+
@Override
protected BufferedWritablePropertyValueModel<?>[] buildBufferedModels() {
return new BufferedWritablePropertyValueModel[] {
@@ -776,8 +859,8 @@ public class JpaProjectPropertiesPage
this.metamodelSourceFolderModel
};
}
-
-
+
+
// ********** validation **********
@Override
@@ -792,19 +875,19 @@ public class JpaProjectPropertiesPage
this.discoverAnnotatedClassesModel
};
}
-
+
@Override
- protected void performValidation(Map<Integer, ArrayList<IStatus>> statuses) {
+ protected void performValidation(Map<Integer, ArrayList<IStatus>> statuses) {
+ JpaProject jpaProject = this.jpaProjectModel.getValue();
+ if (jpaProject == null) {
+ return;
+ }
/* platform */
// user is unable to unset the platform, so no validation necessary
-
+
/* library provider */
- IStatus lpStatus = validateLibraryProvider();
- if (lpStatus != null){
- statuses.get(Integer.valueOf(lpStatus.getSeverity())).add(lpStatus);
- }
- super.performValidation(statuses);
-
+ this.validateLibraryProvider(statuses);
+
/* connection */
ConnectionProfile connectionProfile = this.getConnectionProfile();
String connectionName = this.getConnectionName();
@@ -851,85 +934,26 @@ public class JpaProjectPropertiesPage
}
}
}
-
- private IStatus validateLibraryProvider() {
- LibraryInstallDelegate libInstallDelegate = getLibraryInstallDelegate();
- if( libInstallDelegate != null ) {
- Map<String, Object> enablementVariables = new HashMap<String, Object>();
- enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, this.platformIdModel.getValue());
- enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, this.jpaProjectModel.getValue().getJpaPlatform().getDescription());
-
- if (! libInstallDelegate.getLibraryProvider().isEnabledFor(
- getFacetedProject(), getProjectFacetVersion(), enablementVariables)) {
- return buildErrorStatus(JptCoreMessages.VALIDATE_LIBRARY_PROVIDER_INVALID);
- }
+ private void validateLibraryProvider(Map<Integer, ArrayList<IStatus>> statuses) {
+ LibraryInstallDelegate libInstallDelegate = this.getLibraryInstallDelegate();
+ if (libInstallDelegate == null) {
+ return;
}
- return null;
- }
-
-
- // ********** UI model adapters **********
- /**
- * Treat the JPA project as an "aspect" of the Eclipse project (IProject);
- * but the JPA project is stored in the JPA model, not the Eclipse project
- * itself....
- * We also need to listen for the JPA project to be rebuilt if the user
- * changes the Eclipse project's JPA platform (which is stored in the
- * Eclipse project's preferences).
- */
- static class JpaProjectModel
- extends AspectPropertyValueModelAdapter<IProject, JpaProject> {
-
- /**
- * The JPA project may also change via another page (notably, the project facets page).
- * In that case, the preference change occurs before we actually have another project,
- * so we must listen to the projects manager
- */
- private final CollectionChangeListener projectManagerListener;
-
-
- JpaProjectModel(PropertyValueModel<IProject> projectModel) {
- super(projectModel);
- this.projectManagerListener = buildProjectManagerListener();
- }
-
- private CollectionChangeListener buildProjectManagerListener() {
- return new CollectionChangeAdapter() {
- // we are only looking for the project rebuild *add* event here so we can
- // determine if the platform has changed.
- // the other events are unimportant in this case
- @Override
- public void itemsAdded(CollectionAddEvent event) {
- JpaProjectModel.this.platformChanged();
- }
- };
- }
-
- void platformChanged() {
- this.propertyChanged();
- }
-
- @Override
- protected void engageSubject_() {
- JptJpaCorePlugin.getJpaProjectManager().addCollectionChangeListener(
- JpaProjectManager.JPA_PROJECTS_COLLECTION, this.projectManagerListener);
- }
-
- @Override
- protected void disengageSubject_() {
- JptJpaCorePlugin.getJpaProjectManager().removeCollectionChangeListener(
- JpaProjectManager.JPA_PROJECTS_COLLECTION, this.projectManagerListener);
- }
-
- @Override
- protected JpaProject buildValue_() {
- return JptJpaCorePlugin.getJpaProject(this.subject);
+ Map<String, Object> enablementVariables = new HashMap<String, Object>();
+ enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_ENABLEMENT_EXP, this.platformIdModel.getValue());
+ enablementVariables.put(JpaLibraryProviderInstallOperationConfig.JPA_PLATFORM_DESCRIPTION_ENABLEMENT_EXP, this.jpaProjectModel.getValue().getJpaPlatform().getDescription());
+
+ if ( ! libInstallDelegate.getLibraryProvider().isEnabledFor(
+ this.getFacetedProject(), this.getProjectFacetVersion(), enablementVariables)) {
+ this.addStatus(this.buildErrorStatus(JptCoreMessages.VALIDATE_LIBRARY_PROVIDER_INVALID), statuses);
}
}
-
-
+
+
+ // ********** UI model adapters **********
+
/**
* The JPA project's data source is an auxiliary object that never changes;
* so if we have a JPA project, we have a JPA data source also.
@@ -942,8 +966,8 @@ public class JpaProjectPropertiesPage
}
@Override
- protected JpaDataSource transform_(JpaProject value) {
- return value.getDataSource();
+ protected JpaDataSource transform_(JpaProject v) {
+ return v.getDataSource();
}
}
@@ -975,7 +999,7 @@ public class JpaProjectPropertiesPage
* Convert the selected connection profile name to a connection profile
*/
static class ConnectionProfileModel
- extends CachingTransformationPropertyValueModel<String, ConnectionProfile>
+ extends TransformationPropertyValueModel<String, ConnectionProfile>
{
ConnectionProfileModel(PropertyValueModel<String> connectionModel) {
super(connectionModel);
@@ -1036,6 +1060,7 @@ public class JpaProjectPropertiesPage
)
);
+
/**
* Wrap the connection profile names held by the connection profile
* factory singleton.
@@ -1048,25 +1073,25 @@ public class JpaProjectPropertiesPage
ConnectionChoicesModel() {
super();
- this.connectionProfileListener = this.buildConnectionProfileListener();
+ this.connectionProfileListener = new LocalConnectionProfileListener();
}
- private ConnectionProfileListener buildConnectionProfileListener() {
- return new ConnectionProfileListener() {
- public void connectionProfileAdded(String name) {
- ConnectionChoicesModel.this.collectionChanged();
- }
- public void connectionProfileRemoved(String name) {
- ConnectionChoicesModel.this.collectionChanged();
- }
- public void connectionProfileRenamed(String oldName, String newName) {
- // Ignore this event for now. Connecting a profile actually
- // throws a connection renamed event, which messes up the
- // list selection. There shouldn't be a connection renamed
- // within the scope of this dialog anyhow.
- // ConnectionChoicesModel.this.collectionChanged();
- }
- };
+ /* class private */ class LocalConnectionProfileListener
+ implements ConnectionProfileListener
+ {
+ public void connectionProfileAdded(String name) {
+ ConnectionChoicesModel.this.collectionChanged();
+ }
+ public void connectionProfileRemoved(String name) {
+ ConnectionChoicesModel.this.collectionChanged();
+ }
+ public void connectionProfileRenamed(String oldName, String newName) {
+ // Ignore this event for now. Connecting a profile actually
+ // throws a connection renamed event, which messes up the
+ // list selection. There shouldn't be a connection renamed
+ // within the scope of this dialog anyhow.
+ // ConnectionChoicesModel.this.collectionChanged();
+ }
}
void collectionChanged() {
@@ -1164,7 +1189,7 @@ public class JpaProjectPropertiesPage
static class UserOverrideDefaultCatalogModel
extends PropertyAspectAdapter<JpaProject, String>
{
- UserOverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) {
+ UserOverrideDefaultCatalogModel(PropertyValueModel<JpaProject> jpaProjectModel) {
super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY);
}
@@ -1186,7 +1211,7 @@ public class JpaProjectPropertiesPage
static class UserOverrideDefaultSchemaModel
extends PropertyAspectAdapter<JpaProject, String>
{
- UserOverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) {
+ UserOverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) {
super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY);
}
@@ -1209,7 +1234,7 @@ public class JpaProjectPropertiesPage
static class DiscoverAnnotatedClassesModel
extends PropertyAspectAdapter<JpaProject, Boolean>
{
- DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) {
+ DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) {
super(jpaProjectModel, JpaProject.DISCOVERS_ANNOTATED_CLASSES_PROPERTY);
}
@@ -1224,6 +1249,7 @@ public class JpaProjectPropertiesPage
}
}
+
/**
* The folder where the source for the generated Canonical Metamodel
* is written.
@@ -1237,7 +1263,7 @@ public class JpaProjectPropertiesPage
@Override
protected String buildValue_() {
- return jpaProjectIsJpa2_0() ? ((JpaProject2_0) this.subject).getMetamodelSourceFolderName() : null;
+ return this.jpaProjectIsJpa2_0() ? ((JpaProject2_0) this.subject).getMetamodelSourceFolderName() : null;
}
@Override
@@ -1255,7 +1281,7 @@ public class JpaProjectPropertiesPage
/**
* Java project source folders.
- * We keep the metamodel source folder in synch with the Java source folders
+ * We keep the metamodel source folder in sync with the Java source folders
* (i.e. if a Java source folder is deleted or removed from the build path,
* we remove the metamodel source folder); therefore the list of folder
* choices does not need to be augmented with the current folder (as we do
@@ -1266,17 +1292,21 @@ public class JpaProjectPropertiesPage
{
private final IElementChangedListener javaElementChangedListener;
- JavaSourceFolderChoicesModel(PropertyValueModel<JpaProject> jpaProjectModel) {
+ JavaSourceFolderChoicesModel(PropertyValueModel<JpaProject> jpaProjectModel) {
super(jpaProjectModel);
- this.javaElementChangedListener = this.buildJavaElementChangedListener();
+ this.javaElementChangedListener = new JavaElementChangedListener();
}
- private IElementChangedListener buildJavaElementChangedListener() {
- return new IElementChangedListener() {
- public void elementChanged(ElementChangedEvent event) {
- JavaSourceFolderChoicesModel.this.processJavaDelta(event.getDelta());
- }
- };
+ /* class private */ class JavaElementChangedListener
+ implements IElementChangedListener
+ {
+ public void elementChanged(ElementChangedEvent event) {
+ JavaSourceFolderChoicesModel.this.processJavaDelta(event.getDelta());
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
void processJavaDelta(IJavaElementDelta delta) {
@@ -1352,17 +1382,21 @@ public class JpaProjectPropertiesPage
// the connection opening is probably the only thing that will happen...
private ConnectionListener buildConnectionListener() {
- return new ConnectionAdapter() {
- @Override
- public void opened(ConnectionProfile profile) {
- ConnectionProfilePropertyAspectAdapter.this.connectionOpened(profile);
- }
- };
+ return new LocalConnectionListener();
+ }
+
+ class LocalConnectionListener
+ extends ConnectionAdapter
+ {
+ @Override
+ public void opened(ConnectionProfile profile) {
+ ConnectionProfilePropertyAspectAdapter.this.connectionOpened(profile);
+ }
}
void connectionOpened(ConnectionProfile profile) {
if (profile.equals(this.subject)) {
- this.propertyChanged();
+ this.aspectChanged();
}
}
@@ -1431,19 +1465,20 @@ public class JpaProjectPropertiesPage
) {
super(connectionProfileModel);
this.defaultCatalogModel = defaultCatalogModel;
- this.catalogListener = this.buildCatalogListener();
+ this.catalogListener = new CatalogListener();
}
- private PropertyChangeListener buildCatalogListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- DatabaseDefaultSchemaModel.this.catalogChanged();
- }
- };
+ /* class private */ class CatalogListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DatabaseDefaultSchemaModel.this.catalogChanged();
+ }
}
void catalogChanged() {
- this.propertyChanged();
+ this.aspectChanged();
}
@Override
@@ -1500,17 +1535,21 @@ public class JpaProjectPropertiesPage
// the connection opening is probably the only thing that will happen...
private ConnectionListener buildConnectionListener() {
- return new ConnectionAdapter() {
- @Override
- public void opened(ConnectionProfile profile) {
- ConnectionProfileCollectionAspectAdapter.this.connectionOpened(profile);
- }
- };
+ return new LocalConnectionListener();
+ }
+
+ class LocalConnectionListener
+ extends ConnectionAdapter
+ {
+ @Override
+ public void opened(ConnectionProfile profile) {
+ ConnectionProfileCollectionAspectAdapter.this.connectionOpened(profile);
+ }
}
void connectionOpened(ConnectionProfile profile) {
if (profile.equals(this.subject)) {
- this.collectionChanged();
+ this.aspectChanged();
}
}
@@ -1563,19 +1602,20 @@ public class JpaProjectPropertiesPage
) {
super(connectionProfileModel);
this.defaultCatalogModel = defaultCatalogModel;
- this.catalogListener = this.buildCatalogListener();
+ this.catalogListener = new CatalogListener();
}
- private PropertyChangeListener buildCatalogListener() {
- return new PropertyChangeListener() {
- public void propertyChanged(PropertyChangeEvent event) {
- DatabaseSchemaChoicesModel.this.catalogChanged();
- }
- };
+ /* class private */ class CatalogListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ DatabaseSchemaChoicesModel.this.catalogChanged();
+ }
}
void catalogChanged() {
- this.collectionChanged();
+ this.aspectChanged();
}
@Override
@@ -1617,6 +1657,7 @@ public class JpaProjectPropertiesPage
}
}
+
/**
* Combine various models to determine the default catalog or schema.
* If the user has checked the "Override Default" check-box, the default
@@ -1624,13 +1665,14 @@ public class JpaProjectPropertiesPage
* determined by the database.
*/
static class DefaultModel
- extends CompositePropertyValueModel<String>
+ extends CompositePropertyValueModel<String, Object>
implements WritablePropertyValueModel<String>
{
private final PropertyValueModel<Boolean> userOverrideDefaultFlagModel;
private final WritablePropertyValueModel<String> userOverrideDefaultModel;
private final PropertyValueModel<String> databaseDefaultModel;
+ @SuppressWarnings("unchecked")
DefaultModel(
PropertyValueModel<Boolean> userOverrideDefaultFlagModel,
WritablePropertyValueModel<String> userOverrideDefaultModel,
@@ -1647,8 +1689,8 @@ public class JpaProjectPropertiesPage
* project's user override.
*/
@Override
- protected void propertyChanged(PropertyChangeEvent event) {
- super.propertyChanged(event);
+ protected void componentChanged(PropertyChangeEvent event) {
+ super.componentChanged(event);
if (event.getSource() == this.userOverrideDefaultFlagModel) {
if ( ! this.userOverrideDefaultFlagIsSet()) {
this.userOverrideDefaultModel.setValue(null);
@@ -1680,11 +1722,5 @@ public class JpaProjectPropertiesPage
private boolean userOverrideDefaultFlagIsSet() {
return flagIsSet(this.userOverrideDefaultFlagModel);
}
-
- @Override
- public void toString(StringBuilder sb) {
- sb.append(this.getValue());
- }
}
-
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelection.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelection.java
deleted file mode 100644
index 20b5e9c322..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelection.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-
-/**
- * Straightforward implementation of the JpaSelection interface.
- */
-public class DefaultJpaSelection
- implements JpaSelection
-{
- private final JpaStructureNode selectedNode;
-
-
- public DefaultJpaSelection(JpaStructureNode selectedNode) {
- super();
- if (selectedNode == null) {
- throw new NullPointerException("A 'selectedNode' is required; otherwise use NULL_SELECTION.");
- }
- this.selectedNode = selectedNode;
- }
-
- public JpaStructureNode getSelectedNode() {
- return this.selectedNode;
- }
-
- public boolean isEmpty() {
- // by definition, this selection is never empty
- // use IJpaSelection.NULL_SELECTION for empty selections
- return false;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (! (obj instanceof JpaSelection)) {
- return false;
- }
- JpaSelection other = (JpaSelection) obj;
- return ( ! other.isEmpty()) && this.selectedNode.equals(other.getSelectedNode());
- }
-
- @Override
- public int hashCode() {
- return this.selectedNode.hashCode();
- }
-
- @Override
- public String toString() {
- return this.selectedNode.toString();
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelectionManager.java
deleted file mode 100644
index 8538d64fa7..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/DefaultJpaSelectionManager.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import org.eclipse.jpt.common.utility.internal.iterators.CloneIterator;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IPageListener;
-import org.eclipse.ui.IPartListener2;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchPartReference;
-import org.eclipse.ui.IWorkbenchWindow;
-
-/**
- * A {@link JpaSelectionManager} stores the current {@link JpaSelection} and
- * notifies <code>ISelectionListener</code>s when the selection changes.
- */
-public class DefaultJpaSelectionManager
- implements JpaSelectionManager
-{
- /* The window for which this object manages selections */
- private IWorkbenchWindow window;
-
- /* The set of pages for which this object is managing selections */
- private Set<IWorkbenchPage> pages;
-
- /* The active editor part */
- private IEditorPart activeEditor;
-
- private JpaSelection currentSelection;
-
- /* The map of <code>IJpaSelectionParticipant</code>s (keyed by part) */
- private Map<IWorkbenchPart, JpaSelectionParticipant> selectionParticipants;
-
- private IPageListener pageListener;
-
- private IPartListener2 partListener;
-
-
- public DefaultJpaSelectionManager() {
- super();
- pages = Collections.synchronizedSet(new HashSet<IWorkbenchPage>());
- selectionParticipants = Collections.synchronizedMap(new HashMap<IWorkbenchPart, JpaSelectionParticipant>());
- pageListener = new PageListener();
- partListener = new PartListener();
- currentSelection = DefaultJpaSelection.NULL_SELECTION;
- }
-
- void init(IWorkbenchWindow aWindow) {
- window = aWindow;
- aWindow.addPageListener(pageListener);
- initPage(aWindow.getActivePage());
- }
-
- private void initPage(IWorkbenchPage page) {
- if ((page != null) && (! pages.contains(page))) {
- page.addPartListener(partListener);
- pages.add(page);
- activateEditor(page.getActiveEditor());
- }
- }
-
- private void disposePage(IWorkbenchPage page) {
- if ((page != null) && (pages.contains(page))) {
- page.removePartListener(partListener);
- pages.remove(page);
- }
- }
-
- private void activateEditor(IEditorPart editor) {
- if (editor == activeEditor) {
- return;
- }
- if (activeEditor != null) {
- inactivateEditor(activeEditor);
- }
- initPart(editor);
- activeEditor = editor;
- selectEditor(activeEditor);
- }
-
- private void inactivateEditor(IEditorPart editor) {
-
- }
-
- void initPart(IWorkbenchPart part) {
- if (part != null) {
- if (selectionParticipants.get(part) == null) {
- JpaSelectionParticipant selectionParticipant =
- (JpaSelectionParticipant) part.getAdapter(JpaSelectionParticipant.class);
- if (selectionParticipant != null) {
- selectionParticipants.put(part, selectionParticipant);
- }
- }
- }
- }
-
- private void selectEditor(IEditorPart editor) {
- selectPart(editor);
- }
-
- void selectPart(IWorkbenchPart part) {
- JpaSelectionParticipant selectionParticipant = getSelectionParticipant(part);
- if (selectionParticipant != null) {
- select(selectionParticipant.getSelection(), selectionParticipant);
- }
- }
-
- void hidePart(IWorkbenchPart part) {
- JpaSelectionParticipant selectionParticipant = getSelectionParticipant(part);
- if ((selectionParticipant != null) && (selectionParticipant.disposeOnHide())) {
- closePart(part);
- }
- }
-
- void closePart(IWorkbenchPart part) {
- JpaSelectionParticipant selectionParticipant = getSelectionParticipant(part);
- if (selectionParticipant != null) {
- disposePart(part);
- checkForNoEditors();
- }
- }
-
- void disposePart(IWorkbenchPart part) {
- if ((part != null) && (selectionParticipants.containsKey(part))) {
- selectionParticipants.remove(part).dispose();
- }
- }
-
- void checkForNoEditors() {
- IWorkbenchPage activePage = window.getActivePage();
- if ((activePage == null)
- || (activePage.getEditorReferences().length == 0)) {
- select(DefaultJpaSelection.NULL_SELECTION, null);
- }
- }
-
- public void register(IWorkbenchPart part) {
- initPart(part);
- }
-
- public boolean isRegistered(IWorkbenchPart part) {
- return selectionParticipants.get(part) != null;
- }
-
- public void select(JpaSelection newSelection, JpaSelectionParticipant source) {
- if (currentSelection.equals(newSelection)) {
- return;
- }
-
- currentSelection = newSelection;
- Object nonNullSource = (source == null) ? this : source;
- fireSelectionChange(
- new JpaSelectionEvent(newSelection, JpaSelectionEvent.SELECTION, nonNullSource)
- );
- }
-
- public void deselect(JpaSelection oldSelection, JpaSelectionParticipant source) {
- if (currentSelection.equals(oldSelection)) {
- currentSelection = DefaultJpaSelection.NULL_SELECTION;
- Object nonNullSource = (source == null) ? this : source;
- fireSelectionChange(
- new JpaSelectionEvent(oldSelection, JpaSelectionEvent.DESELECTION, nonNullSource)
- );
- }
- }
-
- private void fireSelectionChange(JpaSelectionEvent event) {
- for (JpaSelectionParticipant sp : selectionParticipants.values()) {
- sp.selectionChanged(event);
- }
- }
-
- private JpaSelectionParticipant getSelectionParticipant(IWorkbenchPart part) {
- return selectionParticipants.get(part);
- }
-
- public JpaSelection getCurrentSelection() {
- return currentSelection;
- }
-
- public void dispose() {
- window.removePageListener(pageListener);
- selectionParticipants.clear();
-
- for (Iterator<IWorkbenchPage> stream = new CloneIterator<IWorkbenchPage>(this.pages); stream.hasNext(); ) {
- this.disposePage(stream.next());
- }
-
- for (Iterator<IWorkbenchPart> stream = new CloneIterator<IWorkbenchPart>(selectionParticipants.keySet()); stream.hasNext(); ) {
- this.disposePart(stream.next());
- }
- }
-
-
- private class PageListener implements IPageListener
- {
- public void pageActivated(IWorkbenchPage page) {
- // nop
- }
-
- PageListener() {
- super();
- }
-
- public void pageClosed(IWorkbenchPage page) {
- DefaultJpaSelectionManager.this.disposePage(page);
- }
-
- public void pageOpened(IWorkbenchPage page) {
- DefaultJpaSelectionManager.this.initPage(page);
- }
- }
-
-
- private class PartListener implements IPartListener2
- {
- PartListener() {
- super();
- }
-
- public void partActivated(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part != null) {
- DefaultJpaSelectionManager.this.initPart(part);
- DefaultJpaSelectionManager.this.selectPart(part);
- }
- }
-
- public void partBroughtToTop(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part != null) {
- initPart(part);
- }
- }
-
- public void partClosed(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part != null) {
- DefaultJpaSelectionManager.this.closePart(part);
- DefaultJpaSelectionManager.this.disposePart(part);
- DefaultJpaSelectionManager.this.checkForNoEditors();
- }
- }
-
- public void partDeactivated(IWorkbenchPartReference partRef) {
- // nop
- }
-
- public void partHidden(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part != null) {
- DefaultJpaSelectionManager.this.hidePart(part);
- }
- }
-
- public void partInputChanged(IWorkbenchPartReference partRef) {
- // nop
- }
-
- public void partOpened(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part != null) {
- initPart(part);
- }
- }
-
- public void partVisible(IWorkbenchPartReference partRef) {
- IWorkbenchPart part = partRef.getPart(false);
- if (part != null) {
- initPart(part);
- }
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaDetailsSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaDetailsSelectionParticipant.java
deleted file mode 100644
index 7ac9003d2c..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaDetailsSelectionParticipant.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.jpt.jpa.ui.internal.views.JpaDetailsView;
-
-
-public class JpaDetailsSelectionParticipant
- implements JpaSelectionParticipant
-{
- private final JpaDetailsView detailsView;
-
-
- public JpaDetailsSelectionParticipant(JpaDetailsView detailsView) {
- super();
- this.detailsView = detailsView;
- }
-
- public JpaSelection getSelection() {
- return this.detailsView.getSelection();
- }
-
- public void selectionChanged(JpaSelectionEvent evt) {
- this.detailsView.select(evt.getSelection());
- }
-
- public boolean disposeOnHide() {
- return false;
- }
-
- public void dispose() {
- // NOP
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaPageManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaPageManager.java
new file mode 100644
index 0000000000..f187e7b394
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaPageManager.java
@@ -0,0 +1,296 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import org.eclipse.jpt.common.ui.internal.utility.PartAdapter2;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.Transformer;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.model.value.DoubleModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.selection.JpaEditorManager;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
+import org.eclipse.jpt.jpa.ui.selection.JpaViewManager;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+
+/**
+ * Maintain:<ul>
+ * <li>a collection of {@link JpaEditorManager JPA editor managers}
+ * for the page's {@link IEditorPart editors}: The page manager creates
+ * and disposes the editor managers. The editor manager is the <em>master</em>
+ * part manager and holds the JPA file and JPA selection models that can be
+ * used by the {@link #viewManagers view managers} and/or the page manager.
+ * <li>a collection of {@link JpaViewManager JPA view managers}
+ * for the page's JPA {@link IViewPart views}: The JPA views themselves create
+ * and dispose the {@link #viewManagers view managers}.
+ * </ul>
+ * Forward the JPA selection to the active editor manager's JPA selection model,
+ * which should notify the appropriate view managers etc.
+ */
+class JpaPageManager
+ implements JpaSelectionManager, JpaViewManager.PageManager
+{
+ /**
+ * The manager's parent window manager.
+ */
+ private final JpaWindowManager windowManager;
+
+ /**
+ * The manager's page.
+ */
+ private final IWorkbenchPage page;
+
+ /**
+ * Editor managers keyed by corresponding editor.
+ * Lazily populated as managers are requested by
+ * {@link #viewManagers view managers}.
+ */
+ private final HashMap<IEditorPart, JpaEditorManager> editorManagers = new HashMap<IEditorPart, JpaEditorManager>();
+
+ /**
+ * Model that holds the editor manager corresponding to the active editor.
+ */
+ private final SimplePropertyValueModel<JpaEditorManager> editorManagerModel = new SimplePropertyValueModel<JpaEditorManager>();
+
+ /**
+ * The page's current JPA file. This wraps the current editor manager's
+ * JPA file model. It can be modified only by the editor manager.
+ */
+ private final PropertyValueModel<JpaFile> jpaFileModel;
+
+ /**
+ * The page's current JPA selection. This wraps the current editor manager's
+ * JPA selection model. It can be modified by either the editor manager or
+ * any view manager.
+ */
+ private final WritablePropertyValueModel<JpaStructureNode> jpaSelectionModel;
+
+ /**
+ * Listen to {@link #page} to maintain {@link #editorManagers}.
+ */
+ private final IPartListener2 partListener = new PartListener();
+
+ /**
+ * List of view managers for the page's JPA views.
+ * This is maintained by the JPA views themselves.
+ * It should be empty only immediately after construction
+ * and immediately before disposal.
+ */
+ private final HashSet<JpaViewManager> viewManagers = new HashSet<JpaViewManager>();
+
+ private volatile boolean disposed = false;
+
+
+ JpaPageManager(JpaWindowManager windowManager, IWorkbenchPage page) {
+ super();
+ if (page == null) {
+ throw new NullPointerException();
+ }
+ this.windowManager = windowManager;
+ this.page = page;
+ this.jpaFileModel = this.buildJpaFileModel();
+ this.jpaSelectionModel = this.buildJpaSelectionModel();
+ this.page.addPartListener(this.partListener);
+ this.updateEditorManagerModel();
+ }
+
+
+ // ********** JPA file model **********
+
+ public PropertyValueModel<JpaFile> getJpaFileModel() {
+ return this.jpaFileModel;
+ }
+
+ private PropertyValueModel<JpaFile> buildJpaFileModel() {
+ return new DoublePropertyValueModel<JpaFile>(this.buildEditorManagerJpaFileModel());
+ }
+
+ private PropertyValueModel<PropertyValueModel<JpaFile>> buildEditorManagerJpaFileModel() {
+ return new TransformationPropertyValueModel<JpaEditorManager, PropertyValueModel<JpaFile>>(this.editorManagerModel, JPA_FILE_MODEL_TRANSFORMER);
+ }
+
+ private static final Transformer<JpaEditorManager, PropertyValueModel<JpaFile>> JPA_FILE_MODEL_TRANSFORMER = new JpaFileModelTransformer();
+
+ /* CU private */ static class JpaFileModelTransformer
+ extends AbstractTransformer<JpaEditorManager, PropertyValueModel<JpaFile>>
+ {
+ @Override
+ public PropertyValueModel<JpaFile> transform_(JpaEditorManager editorManager) {
+ return editorManager.getJpaFileModel();
+ }
+ }
+
+
+ // ********** JPA selection model **********
+
+ public WritablePropertyValueModel<JpaStructureNode> getJpaSelectionModel() {
+ return this.jpaSelectionModel;
+ }
+
+ private WritablePropertyValueModel<JpaStructureNode> buildJpaSelectionModel() {
+ return new DoubleModifiablePropertyValueModel<JpaStructureNode>(this.buildEditorManagerJpaSelectionModel());
+ }
+
+ private PropertyValueModel<WritablePropertyValueModel<JpaStructureNode>> buildEditorManagerJpaSelectionModel() {
+ return new TransformationPropertyValueModel<JpaEditorManager, WritablePropertyValueModel<JpaStructureNode>>(this.editorManagerModel, JPA_SELECTION_MODEL_TRANSFORMER);
+ }
+
+ private static final Transformer<JpaEditorManager, WritablePropertyValueModel<JpaStructureNode>> JPA_SELECTION_MODEL_TRANSFORMER = new JpaSelectionModelTransformer();
+
+ /* CU private */ static class JpaSelectionModelTransformer
+ extends AbstractTransformer<JpaEditorManager, WritablePropertyValueModel<JpaStructureNode>>
+ {
+ @Override
+ public WritablePropertyValueModel<JpaStructureNode> transform_(JpaEditorManager editorManager) {
+ return editorManager.getJpaSelectionModel();
+ }
+ }
+
+
+ // ********** selection **********
+
+ /**
+ * This should only be called from the
+ * {@link #windowManager window manager}.
+ */
+ public void setSelection(JpaStructureNode selection) {
+ this.jpaSelectionModel.setValue(selection);
+ }
+
+
+ // ********** editor managers **********
+
+ public JpaEditorManager getEditorManager(IEditorPart editor) {
+ return (editor == null) ? null : this.getEditorManager_(editor);
+ }
+
+ private synchronized JpaEditorManager getEditorManager_(IEditorPart editor) {
+ JpaEditorManager editorManager = this.editorManagers.get(editor);
+ if (editorManager == null) {
+ editorManager = this.buildEditorManager(editor);
+ if (editorManager != null) {
+ JpaWorkbenchManager.debug("add editor manager:", editor); //$NON-NLS-1$
+ this.editorManagers.put(editor, editorManager);
+ }
+ }
+ return editorManager;
+ }
+
+ /**
+ * <strong>NB:</strong> The editor manager is built once (when first
+ * requested by a view manager) and not disposed until all the view
+ * managers are removed from the page manager. As a result, the editor
+ * manager is most likely driven by the class of the editor, as opposed
+ * to the editor's content....
+ */
+ private JpaEditorManager buildEditorManager(IEditorPart editor) {
+ return (JpaEditorManager) editor.getAdapter(JpaEditorManager.class);
+ }
+
+
+ // ********** view managers **********
+
+ public synchronized void addViewManager(JpaViewManager viewManager) {
+ JpaWorkbenchManager.debug("add view manager:", viewManager); //$NON-NLS-1$
+ if (this.disposed) {
+ // This can happen if the page manager's last view manager is removed
+ // after a page manager was returned to a new view manager but before that
+ // view manager adds itself to the page manager....
+ throw new IllegalStateException("page manager is disposed: " + this); //$NON-NLS-1$
+ }
+ if ( ! this.viewManagers.add(viewManager)) {
+ throw new IllegalArgumentException("duplicate view manager: " + viewManager); //$NON-NLS-1$
+ }
+ }
+
+ public synchronized void removeViewManager(JpaViewManager viewManager) {
+ JpaWorkbenchManager.debug("remove view manager:", viewManager); //$NON-NLS-1$
+ if ( ! this.viewManagers.remove(viewManager)) {
+ throw new IllegalArgumentException("missing view manager: " + viewManager); //$NON-NLS-1$
+ }
+ if (this.viewManagers.isEmpty()) {
+ this.dispose();
+ }
+ }
+
+
+ // ********** misc **********
+
+ /**
+ * When all the view managers are gone we get rid of the page manager.
+ */
+ private void dispose() {
+ this.disposed = true;
+ this.page.removePartListener(this.partListener);
+ for (JpaEditorManager editorManager : this.editorManagers.values()) {
+ editorManager.dispose();
+ }
+ this.windowManager.removePageManager(this.page);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.page);
+ }
+
+
+ // ********** part listener **********
+
+ /**
+ * Remove the corresponding editor manager whenever an editor is closed.
+ */
+ /* CU private */ class PartListener
+ extends PartAdapter2
+ {
+ @Override
+ public void partActivated(IWorkbenchPartReference partRef) {
+ JpaPageManager.this.updateEditorManagerModel();
+ }
+
+ @Override
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {
+ JpaPageManager.this.updateEditorManagerModel();
+ }
+
+ @Override
+ public void partClosed(IWorkbenchPartReference partRef) {
+ IWorkbenchPart part = partRef.getPart(false);
+ if (part != null) {
+ JpaPageManager.this.partClosed(part);
+ }
+ }
+ }
+
+ /* CU private */ synchronized void partClosed(IWorkbenchPart part) {
+ JpaEditorManager editorManager = this.editorManagers.remove(part);
+ if (editorManager != null) {
+ JpaWorkbenchManager.debug("removed editor manager:", part); //$NON-NLS-1$
+ editorManager.dispose();
+ }
+ this.updateEditorManagerModel();
+ }
+
+ /* CU private */ void updateEditorManagerModel() {
+ this.editorManagerModel.setValue(this.getEditorManager(this.page.getActiveEditor()));
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelection.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelection.java
deleted file mode 100644
index 667ead1c58..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelection.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-
-@SuppressWarnings("nls")
-public interface JpaSelection extends ISelection
-{
- static JpaSelection NULL_SELECTION =
- new JpaSelection() {
- public JpaStructureNode getSelectedNode() {
- return null;
- }
-
- public boolean isEmpty() {
- return true;
- }
-
- @Override
- public String toString() {
- return "NULL SELECTION";
- }
- };
-
-
- JpaStructureNode getSelectedNode();
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionEvent.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionEvent.java
deleted file mode 100644
index 81e4aac5b9..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionEvent.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- *
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import java.util.EventObject;
-
-public class JpaSelectionEvent extends EventObject
-{
- /**
- * Serializable uid
- * @since 0.5
- */
- private static final long serialVersionUID = 1L;
-
-
- /**
- * Indicates that the selection object is now selected
- */
- public static int SELECTION = 1;
-
- /**
- * Indicates that the selection object has now been deselected
- */
- public static int DESELECTION = 2;
-
-
- /**
- * The selection object whose selection status has changed
- */
- private JpaSelection selection;
-
- /**
- * The type of the selection event, either a SELECTION or a DESELECTION
- */
- private int type;
-
-
- public JpaSelectionEvent(JpaSelection theSelection, int theType, Object source) {
- super(source);
- selection = theSelection;
- type = theType;
- }
-
- /**
- * Return the selection object whose selection status has changed
- */
- public JpaSelection getSelection() {
- return selection;
- }
-
- /**
- * Return the type of selection event, either a SELECTION or a DESELECTION
- */
- public int getType() {
- return type;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionManager.java
deleted file mode 100644
index daa17b7801..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionManager.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.ui.IWorkbenchPart;
-
-public interface JpaSelectionManager
-{
- /**
- * Return the current selection.
- * This will never be null, but it may be empty.
- */
- public JpaSelection getCurrentSelection();
-
- /**
- * Not to be called lightly, this will affect the selection for all interested
- * objects in a window.
- * @param newSelection The new selection for the current window.
- * @param source The selection participant (if any) that is causing the
- * selection. May be null.
- */
- public void select(JpaSelection newSelection, JpaSelectionParticipant source);
-
- /**
- * Not to be called lightly, this will affect the selection for all interested
- * objects in a window.
- * @param oldSelection The oldSelection will be deselected, iff it matches
- * the current selection. If so, the new selection will be an empty JpaSelection.
- * @param source The selection participant (if any) that is causing the
- * selection. May be null.
- */
- public void deselect(JpaSelection oldSelection, JpaSelectionParticipant source);
-
- /**
- * This may be used to register a part with the selection manager if the part
- * is known to need access to the selection manager before it is ever activated
- * or in the case it may be activated prior to the selection manager being
- * created.
- *
- * It should not be necessary to deregister a part, as that happens when the
- * part is closed.
- */
- public void register(IWorkbenchPart part);
-
- /**
- * Returns true if the part is currently registered to respond to selections
- * from this selection manager
- */
- public boolean isRegistered(IWorkbenchPart part);
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionParticipant.java
deleted file mode 100644
index 4145c013ac..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaSelectionParticipant.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-public interface JpaSelectionParticipant
-{
- /**
- * Return the current selection of the participant
- */
- JpaSelection getSelection();
-
- /**
- * The selection has changed in the central selection manager.
- * Update this participant accordingly.
- */
- void selectionChanged(JpaSelectionEvent evt);
-
- /**
- * Return whether this selection participant should disconnect itself from
- * its part when its part is hidden from view.
- * <b>Typically</b> editor participants will return true and view participants will
- * return false.
- */
- boolean disposeOnHide();
-
- /**
- * This participant is no longer needed (most likely because its part has
- * closed). Dispose of it.
- */
- void dispose();
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaStructureSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaStructureSelectionParticipant.java
deleted file mode 100644
index aded24a836..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaStructureSelectionParticipant.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jpt.jpa.ui.internal.views.structure.JpaStructureView;
-
-public class JpaStructureSelectionParticipant
- implements JpaSelectionParticipant
-{
- final JpaStructureView structureView;
-
-
- public JpaStructureSelectionParticipant(JpaSelectionManager selectionManager, JpaStructureView structureView) {
- super();
- this.structureView = structureView;
- structureView.addSelectionChangedListener(new StructureViewSelectionListener(selectionManager, structureView));
- }
-
- public JpaSelection getSelection() {
- return this.structureView.getJpaSelection();
- }
-
- public void selectionChanged(JpaSelectionEvent evt) {
- if (evt.getSource() != this) {
- this.structureView.select(evt.getSelection());
- }
- }
-
- public boolean disposeOnHide() {
- return false;
- }
-
- public void dispose() {
- // NOP
- }
-
-
- // ********** listener **********
-
- private class StructureViewSelectionListener
- implements ISelectionChangedListener
- {
- private final JpaSelectionManager selectionManager;
-
- StructureViewSelectionListener(JpaSelectionManager selectionManager, JpaStructureView structureView) {
- super();
- this.selectionManager = selectionManager;
- }
-
- public void selectionChanged(SelectionChangedEvent event) {
- if (structureView.getViewSite().getWorkbenchWindow().getPartService().getActivePart() == structureView) {
- selectionManager.select(this.structureViewSelection(), JpaStructureSelectionParticipant.this);
- }
- }
-
- private JpaSelection structureViewSelection() {
- return JpaStructureSelectionParticipant.this.structureView.getJpaSelection();
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java
new file mode 100644
index 0000000000..b2f0c08678
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaTextEditorManager.java
@@ -0,0 +1,336 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.ui.internal.jface.SelectionChangedAdapter;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.internal.utility.PropertyAdapter;
+import org.eclipse.jpt.common.utility.internal.AbstractTransformer;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.Transformer;
+import org.eclipse.jpt.common.utility.internal.model.value.DoublePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.JpaFileModel;
+import org.eclipse.jpt.jpa.ui.selection.JpaEditorManager;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * JPA editor manager for a {@link ITextEditor text editor}.
+ * <p>
+ * If the JPA selection model changes, set the text editor's selection
+ * accordingly. If the {@link #textEditor text editor}'s selection changes,
+ * forward the corresponding JPA selection to the {@link #jpaSelectionModel
+ * JPA selection model}.
+ */
+class JpaTextEditorManager
+ implements JpaEditorManager
+{
+ /**
+ * The manager's text editor
+ */
+ private final ITextEditor textEditor;
+
+ /**
+ * Listen for the {@link #textEditor text editor}'s input to change.
+ * This can happen if the text editor is re-usable.
+ */
+ private final IPropertyListener textEditorInputListener = new TextEditorInputListener();
+
+ /**
+ * Listen for the {@link #textEditor text editor}'s selection to change.
+ */
+ private final ISelectionChangedListener textEditorSelectionListener = new TextEditorSelectionListener();
+
+ private final WritablePropertyValueModel<IFile> fileModel = new SimplePropertyValueModel<IFile>();
+
+ /**
+ * We use the JPA file to calculate the JPA selection.
+ * We update the JPA file model's file model whenever the text editor's
+ * file changes.
+ */
+ private final PropertyValueModel<JpaFile> jpaFileModel;
+
+ /**
+ * Listen for the model or ourselves (via the file model) to change the
+ * JPA file.
+ */
+ private final PropertyChangeListener jpaFileListener = new JpaFileListener();
+
+ /**
+ * We update the JPA selection model whenever the text editor's selection
+ * changes.
+ */
+ private final WritablePropertyValueModel<JpaStructureNode> jpaSelectionModel = new SimplePropertyValueModel<JpaStructureNode>();
+
+ /**
+ * Listen for other views to change the JPA selection.
+ */
+ private final PropertyChangeListener jpaSelectionListener = new JpaSelectionListener();
+
+
+ // ********** constructor **********
+
+ /* CU private */ JpaTextEditorManager(ITextEditor textEditor) {
+ super();
+ this.textEditor = textEditor;
+ this.textEditor.addPropertyListener(this.textEditorInputListener);
+ this.getTextEditorSelectionProvider().addPostSelectionChangedListener(this.textEditorSelectionListener);
+
+ this.jpaFileModel = this.buildJpaFileModel();
+ this.jpaFileModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.jpaFileListener);
+
+ this.jpaSelectionModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.jpaSelectionListener);
+
+ // this will trigger a new JPA file
+ // which will trigger us to set the JPA selection
+ this.setFileModel();
+ }
+
+ /**
+ * The <em>public</em> JPA selection model will not allow clients to set the
+ * JPA selection to <code>null</code>. Only the editor manager can set the
+ * selection to <code>null</code>. A client may set the JPA selection to
+ * <code>null</code> when it does not have appropriate input. It is OK
+ * for the <em>client's</em> JPA selection be <code>null</code>; but the
+ * editor manager's JPA selection is the <em>master</em> JPA selection for
+ * the workbench page/window and drives the JPA selection for potentially
+ * multiple clients. As a result, clients can only modify the editor
+ * manager's JPA selection to be some non-<code>null</code> value.
+ */
+
+ // ********** JPA file **********
+
+ public PropertyValueModel<JpaFile> getJpaFileModel() {
+ return this.jpaFileModel;
+ }
+
+ private PropertyValueModel<JpaFile> buildJpaFileModel() {
+ return new DoublePropertyValueModel<JpaFile>(this.buildJpaFileModelModel());
+ }
+
+ private PropertyValueModel<PropertyValueModel<JpaFile>> buildJpaFileModelModel() {
+ return new TransformationPropertyValueModel<IFile, PropertyValueModel<JpaFile>>(this.fileModel, JPA_FILE_MODEL_TRANSFORMER);
+ }
+
+ private static final Transformer<IFile, PropertyValueModel<JpaFile>> JPA_FILE_MODEL_TRANSFORMER = new JpaFileModelTransformer();
+
+ /* CU private */ static class JpaFileModelTransformer
+ extends AbstractTransformer<IFile, PropertyValueModel<JpaFile>>
+ {
+ @Override
+ protected PropertyValueModel<JpaFile> transform_(IFile file) {
+ return (JpaFileModel) file.getAdapter(JpaFileModel.class);
+ }
+ }
+
+ /* CU private */ class JpaFileListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaTextEditorManager.this.jpaFileChanged();
+ }
+ }
+
+ /**
+ * Dispatch to the UI thread.
+ */
+ /* CU private */ void jpaFileChanged() {
+ this.execute(new JpaFileChangedRunnable());
+ }
+
+ /* CU private */ class JpaFileChangedRunnable
+ implements Runnable
+ {
+ public void run() {
+ JpaTextEditorManager.this.jpaFileChanged_();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+ /**
+ * Pre-condition: executing on the UI thread.
+ */
+ /* CU private */ void jpaFileChanged_() {
+ this.jpaSelectionModel.setValue(this.getTextEditorJpaSelection());
+ }
+
+
+ // ********** JPA selection **********
+
+ public WritablePropertyValueModel<JpaStructureNode> getJpaSelectionModel() {
+ return this.jpaSelectionModel;
+ }
+
+ /* CU private */ class JpaSelectionListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaTextEditorManager.this.setTextEditorJpaSelection((JpaStructureNode) event.getNewValue());
+ }
+ }
+
+ /* CU private */ void setJpaSelection(ISelection selection) {
+ this.jpaSelectionModel.setValue(this.getTextEditorJpaSelection(selection));
+ }
+
+
+ // ********** text editor selection **********
+
+ /* CU private */ class TextEditorSelectionListener
+ extends SelectionChangedAdapter
+ {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ JpaTextEditorManager.this.setJpaSelection(event.getSelection());
+ }
+ }
+
+ /**
+ * Dispatch to the UI thread.
+ */
+ /* CU private */ void setTextEditorJpaSelection(JpaStructureNode selection) {
+ this.execute(new SetTextEditorSelectionRunnable(selection));
+ }
+
+ /* CU private */ class SetTextEditorSelectionRunnable
+ implements Runnable
+ {
+ private final JpaStructureNode selection;
+
+ SetTextEditorSelectionRunnable(JpaStructureNode selection) {
+ super();
+ this.selection = selection;
+ }
+
+ public void run() {
+ JpaTextEditorManager.this.setTextEditorJpaSelection_(this.selection);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.selection);
+ }
+ }
+
+ /**
+ * Pre-condition: executing on the UI thread.
+ * If the new JPA selection is not <code>null</code> and it is different
+ * from the text editor's current JPA selection, modify the text editor's
+ * selection.
+ */
+ /* CU private */ void setTextEditorJpaSelection_(JpaStructureNode selection) {
+ if ((selection != null) && (selection != this.getTextEditorJpaSelection())) {
+ this.setTextEditorSelection(selection.getSelectionTextRange());
+ }
+ }
+
+ private void setTextEditorSelection(TextRange textRange) {
+ if (textRange != null) {
+ // no need for a disposed check...
+ this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength());
+ }
+ }
+
+ /**
+ * Return the JPA selection corresponding to the text editor's current
+ * selection.
+ * Pre-condition: executing on the UI thread.
+ */
+ private JpaStructureNode getTextEditorJpaSelection() {
+ // the selection provider can be null if the text editor was disposed
+ // before we get a chance to [asynchronously] handle the event
+ IPostSelectionProvider selProvider = this.getTextEditorSelectionProvider();
+ return (selProvider == null) ? null : this.getTextEditorJpaSelection(selProvider.getSelection());
+ }
+
+ private JpaStructureNode getTextEditorJpaSelection(ISelection selection) {
+ return (selection instanceof ITextSelection) ? this.getTextEditorJpaSelection((ITextSelection) selection) : null;
+ }
+
+ private JpaStructureNode getTextEditorJpaSelection(ITextSelection selection) {
+ JpaFile jpaFile = this.jpaFileModel.getValue();
+ return (jpaFile == null) ? null : jpaFile.getStructureNode(selection.getOffset());
+ }
+
+
+ // ********** text editor input **********
+
+ /* CU private */ class TextEditorInputListener
+ extends PropertyAdapter
+ {
+ @Override
+ public void propertyChanged(Object source, int propertyID) {
+ if (propertyID == IEditorPart.PROP_INPUT) {
+ JpaTextEditorManager.this.setFileModel();
+ }
+ }
+ }
+
+
+ // ********** misc **********
+
+ public IEditorPart getEditor() {
+ return this.textEditor;
+ }
+
+ /* CU private */ void setFileModel() {
+ this.fileModel.setValue(this.getTextEditorFile());
+ }
+
+ private IFile getTextEditorFile() {
+ IEditorInput input = this.textEditor.getEditorInput();
+ return (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
+ }
+
+ private IPostSelectionProvider getTextEditorSelectionProvider() {
+ return (IPostSelectionProvider) this.textEditor.getSelectionProvider();
+ }
+
+ private void execute(Runnable runnable) {
+ SWTUtil.execute(this.textEditor.getSite().getShell().getDisplay(), runnable);
+ }
+
+ public void dispose() {
+ this.jpaFileModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.jpaFileListener);
+ this.jpaSelectionModel.removePropertyChangeListener(PropertyValueModel.VALUE, this.jpaSelectionListener);
+ this.getTextEditorSelectionProvider().removePostSelectionChangedListener(this.textEditorSelectionListener);
+ this.textEditor.removePropertyListener(this.textEditorInputListener);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.textEditor);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWindowManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWindowManager.java
new file mode 100644
index 0000000000..813eb87f43
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWindowManager.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import java.util.Hashtable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+
+/**
+ * Maintain a collection of
+ * {@link JpaSelectionManager JPA selection managers}
+ * keyed by {@link IWorkbenchPage workbench page}.
+ * Forward the selection to the manager for the active page.
+ */
+class JpaWindowManager
+ implements JpaSelectionManager
+{
+ /**
+ * The manager's parent workbench manager.
+ */
+ private final JpaWorkbenchManager workbenchManager;
+
+ /**
+ * The manager's window.
+ */
+ private final IWorkbenchWindow window;
+
+ /**
+ * Map workbench pages to JPA workbench page selection managers.
+ * This is lazily populated and cleaned up by
+ * the page managers themselves.
+ */
+ private final Hashtable<IWorkbenchPage, JpaPageManager> pageManagers = new Hashtable<IWorkbenchPage, JpaPageManager>();
+
+
+ JpaWindowManager(JpaWorkbenchManager workbenchManager, IWorkbenchWindow window) {
+ super();
+ if (window == null) {
+ throw new NullPointerException();
+ }
+ this.workbenchManager = workbenchManager;
+ this.window = window;
+ }
+
+
+ // ********** selection **********
+
+ /**
+ * Forward to the manager for the window's active page.
+ */
+ public void setSelection(JpaStructureNode selection) {
+ this.getPageManager(this.window.getActivePage()).setSelection(selection);
+ }
+
+
+ // ********** page managers **********
+
+ /**
+ * Return the JPA selection manager for the specified
+ * workbench page.
+ */
+ private JpaSelectionManager getPageManager(IWorkbenchPage page) {
+ return (page == null) ?
+ JpaSelectionManager.Null.instance() :
+ this.getPageManager_(page);
+ }
+
+ private JpaSelectionManager getPageManager_(IWorkbenchPage page) {
+ JpaPageManager manager = this.pageManagers.get(page);
+ return (manager == null) ?
+ JpaSelectionManager.Null.instance() :
+ manager;
+ }
+
+ /**
+ * <strong>NB:</strong> May trigger construction of page manager.
+ */
+ JpaPageManager getPageManager(IViewPart view) {
+ IWorkbenchPage page = view.getSite().getPage();
+ synchronized (this.pageManagers) {
+ JpaPageManager manager = this.pageManagers.get(page);
+ if (manager == null) {
+ JpaWorkbenchManager.debug("add page manager:", page); //$NON-NLS-1$
+ manager = new JpaPageManager(this, page);
+ this.pageManagers.put(page, manager);
+ }
+ return manager;
+ }
+ }
+
+ /**
+ * @see JpaPageManager#dispose()
+ */
+ void removePageManager(IWorkbenchPage page) {
+ synchronized (this.pageManagers) {
+ JpaWorkbenchManager.debug("remove page manager:", page); //$NON-NLS-1$
+ this.pageManagers.remove(page);
+ if (this.pageManagers.isEmpty()) {
+ this.dispose();
+ }
+ }
+ }
+
+
+ // ********** misc **********
+
+ private void dispose() {
+ this.workbenchManager.removeWindowManager(this.window);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.window);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWorkbenchManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWorkbenchManager.java
new file mode 100644
index 0000000000..804ccadb6e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/JpaWorkbenchManager.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Hashtable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
+import org.eclipse.jpt.jpa.ui.selection.JpaViewManager;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+
+/**
+ * Maintain a collection of
+ * {@link JpaSelectionManager JPA selection managers}
+ * keyed by {@link IWorkbenchWindow workbench window}.
+ * Forward the selection to the manager for the active window.
+ *
+ * @see WorkbenchWindowAdapterFactory
+ */
+class JpaWorkbenchManager
+ implements JpaSelectionManager
+{
+ /**
+ * The manager's workbench.
+ */
+ private final IWorkbench workbench;
+
+ /**
+ * Map workbench windows to JPA managers.
+ * This is lazily populated and cleaned up as necessary.
+ */
+ private final Hashtable<IWorkbenchWindow, JpaWindowManager> windowManagers = new Hashtable<IWorkbenchWindow, JpaWindowManager>();
+
+
+ /**
+ * @see #forWorkbench(IWorkbench)
+ * @see #getPageManager(IViewPart)
+ */
+ private JpaWorkbenchManager(IWorkbench workbench) {
+ super();
+ this.workbench = workbench;
+ }
+
+
+ // ********** selection **********
+
+ /**
+ * Forward to the manager for the workbench's active window.
+ */
+ public void setSelection(JpaStructureNode selection) {
+ this.getWindowManager(this.workbench.getActiveWorkbenchWindow()).setSelection(selection);
+ }
+
+
+ // ********** window managers **********
+
+ /**
+ * Return the JPA selection manager for the specified
+ * workbench window. Return a "null" manager if the specified window
+ * is <code>null</code> or contains no JPA views.
+ *
+ * @see #getPageManager_(IViewPart)
+ */
+ private JpaSelectionManager getWindowManager(IWorkbenchWindow window) {
+ return (window == null) ?
+ JpaSelectionManager.Null.instance() :
+ this.getWindowManager_(window);
+ }
+
+ private JpaSelectionManager getWindowManager_(IWorkbenchWindow window) {
+ JpaWindowManager manager = this.windowManagers.get(window);
+ return (manager != null) ? manager : JpaSelectionManager.Null.instance();
+ }
+
+ /**
+ * Return the page manager for the specified view.
+ * Construct a new manager for the view's window and page if necessary.
+ *
+ * @see #getWindowManager(IWorkbenchWindow)
+ */
+ private JpaViewManager.PageManager getPageManager_(IViewPart view) {
+ return this.getWindowManager(view).getPageManager(view);
+ }
+
+ /**
+ * <strong>NB:</strong> May trigger construction of window manager.
+ */
+ private JpaWindowManager getWindowManager(IViewPart view) {
+ IWorkbenchWindow window = view.getSite().getWorkbenchWindow();
+ synchronized (this.windowManagers) {
+ JpaWindowManager manager = this.windowManagers.get(window);
+ if (manager == null) {
+ debug("add window manager:", window); //$NON-NLS-1$
+ manager = new JpaWindowManager(this, window);
+ this.windowManagers.put(window, manager);
+ }
+ return manager;
+ }
+ }
+
+ /**
+ * @see JpaWindowManager#dispose()
+ */
+ void removeWindowManager(IWorkbenchWindow window) {
+ synchronized (this.windowManagers) {
+ debug("remove window manager:", window); //$NON-NLS-1$
+ this.windowManagers.remove(window);
+ if (this.windowManagers.isEmpty()) {
+ this.dispose();
+ }
+ }
+ }
+
+
+ // ********** misc **********
+
+ private void dispose() {
+ debug("remove workbench manager:", this.workbench); //$NON-NLS-1$
+ WORKBENCH_MANAGERS.remove(this.workbench);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.workbench);
+ }
+
+
+ // ********** static cache **********
+
+ /**
+ * Probably only a single manager in this cache....
+ */
+ private static final Hashtable<IWorkbench, JpaWorkbenchManager> WORKBENCH_MANAGERS = new Hashtable<IWorkbench, JpaWorkbenchManager>();
+
+ /**
+ * Return a <em>null</em> manager if a manager does not exist.
+ * @see WorkbenchAdapterFactory
+ */
+ static JpaSelectionManager forWorkbench(IWorkbench workbench) {
+ return (workbench == null) ?
+ JpaSelectionManager.Null.instance() :
+ forWorkbench_(workbench);
+ }
+
+ private static JpaSelectionManager forWorkbench_(IWorkbench workbench) {
+ JpaWorkbenchManager manager = WORKBENCH_MANAGERS.get(workbench);
+ return (manager != null) ? manager : JpaSelectionManager.Null.instance();
+ }
+
+ /**
+ * Return a <em>null</em> manager if a manager does not exist.
+ * @see WorkbenchWindowAdapterFactory
+ */
+ static JpaSelectionManager forWindow(IWorkbenchWindow window) {
+ return (window == null) ?
+ JpaSelectionManager.Null.instance() :
+ forWindow_(window);
+ }
+
+ private static JpaSelectionManager forWindow_(IWorkbenchWindow window) {
+ JpaWorkbenchManager manager = WORKBENCH_MANAGERS.get(window.getWorkbench());
+ return (manager == null) ?
+ JpaSelectionManager.Null.instance() :
+ manager.getWindowManager_(window);
+ }
+
+ /**
+ * Construct a new manager if a manager does not exist.
+ * @see ViewPartAdapterFactory
+ */
+ static JpaViewManager.PageManager getPageManager(IViewPart view) {
+ if (view == null) {
+ throw new NullPointerException();
+ }
+ return getWorkbenchManager(view).getPageManager_(view);
+ }
+
+ /**
+ * <strong>NB:</strong> May trigger construction of workbench manager.
+ */
+ private static JpaWorkbenchManager getWorkbenchManager(IViewPart view) {
+ IWorkbench workbench = view.getSite().getWorkbenchWindow().getWorkbench();
+ synchronized (WORKBENCH_MANAGERS) {
+ JpaWorkbenchManager manager = WORKBENCH_MANAGERS.get(workbench);
+ if (manager == null) {
+ debug("add workbench manager:", workbench); //$NON-NLS-1$
+ manager = new JpaWorkbenchManager(workbench);
+ WORKBENCH_MANAGERS.put(workbench, manager);
+ }
+ return manager;
+ }
+ }
+
+
+ // ********** DEBUG **********
+
+ private static final boolean DEBUG = false;
+
+ static void debug(String message) {
+ debug(message, null);
+ }
+
+ static void debug(String message, Object object) {
+ debug(message, object, null);
+ }
+
+ static void debug(String message, Object object, Object additionalInfo) {
+ if (DEBUG) {
+ // lock System.out so the strings are printed out contiguously
+ synchronized (System.out) {
+ debug_(message, object, additionalInfo);
+ }
+ }
+ }
+
+ private static void debug_(String message, Object object, Object additionalInfo) {
+ System.out.print(buildTimestamp());
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.print(Thread.currentThread().getName());
+ System.out.print(": "); //$NON-NLS-1$
+ System.out.print(message);
+ if (object != null) {
+ System.out.print(" "); //$NON-NLS-1$
+ System.out.print(object);
+ if (additionalInfo != null) {
+ System.out.print(" ("); //$NON-NLS-1$
+ System.out.print(additionalInfo);
+ System.out.print(")"); //$NON-NLS-1$
+ }
+ }
+ System.out.println();
+ }
+
+ private static synchronized String buildTimestamp() {
+ return DATE_FORMAT.format(new Date());
+ }
+ private static final String DATE_FORMAT_PATTERN = "yyyy.MM.dd HH:mm:ss.SSS"; //$NON-NLS-1$
+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_PATTERN);
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/SelectionManagerFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/SelectionManagerFactory.java
deleted file mode 100644
index b9bc9b9140..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/SelectionManagerFactory.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.ui.IWindowListener;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-public class SelectionManagerFactory
-{
- private static volatile SelectionManagerFactory INSTANCE;
-
- private static Object MUTEX = new Object();
-
-
- /**
- * Each <code>IWorkbenchWindow</code> has its own <code>JpaSelectionManager</code>
- * to track the selection events in the <code>IWorkbenchWindow</code>. All
- * <code>ISelectionListener</code>s in the same <code>IWorkbenchWindow</code>
- * share the same <code>JpaSelectionManager</code>.
- *
- * @return The <code>JpaSelectionManager</code> associated with the current
- * <code>IWorkbenchWindow</code>
- */
- public static JpaSelectionManager getSelectionManager(IWorkbenchWindow window) {
- if (INSTANCE == null) {
- // this is thread safe for now. you never know whats comming
- synchronized (MUTEX) {
- if(INSTANCE == null) {
- INSTANCE = new SelectionManagerFactory();
- // if we do the init inside the constructor we end up in a loop
- // because the addWindowListener(this) does a callback to us
- INSTANCE.init();
- }
- }
- }
- return INSTANCE.internalGetSelectionManager(window);
- }
-
-
- Map<IWorkbenchWindow, DefaultJpaSelectionManager> managers;
-
- private WindowListener windowListener;
-
-
- private SelectionManagerFactory() {
- managers = new HashMap<IWorkbenchWindow, DefaultJpaSelectionManager>();
- windowListener = new WindowListener();
- }
-
- private void init() {
- IWorkbench workbench = PlatformUI.getWorkbench();
- workbench.addWindowListener(windowListener);
- }
-
- /**
- * Returns the JpaSelectionManager for the IWorkbenchWindow.
- * Creates a new one if none exists yet.
- */
- DefaultJpaSelectionManager internalGetSelectionManager(IWorkbenchWindow window) {
- if (window == null) {
- throw new IllegalArgumentException("The IWorkbenchWindow cannot be null"); //$NON-NLS-1$
- }
-
- if (! managers.containsKey(window)) {
- DefaultJpaSelectionManager manager = new DefaultJpaSelectionManager();
- this.managers.put(window, manager);
- manager.init(window);
- }
-
- return managers.get(window);
- }
-
-
- class WindowListener implements IWindowListener
- {
- public void windowOpened(IWorkbenchWindow aWindow) {
- // do nothing
- }
-
- public void windowClosed(IWorkbenchWindow aWindow) {
- DefaultJpaSelectionManager manager = internalGetSelectionManager(aWindow);
- manager.dispose();
- managers.remove(aWindow);
- }
-
- public void windowActivated(IWorkbenchWindow aWindow) {
- // do nothing
- }
-
- public void windowDeactivated(IWorkbenchWindow aWindow) {
- // do nothing
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorAdapterFactory.java
new file mode 100644
index 0000000000..789308a2c5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorAdapterFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaEditorManager;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Factory to build JPA selection adapters for a {@link ITextEditor}:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.ui.selection.JpaEditorManager}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class TextEditorAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaEditorManager.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof ITextEditor) {
+ return this.getAdapter((ITextEditor) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(ITextEditor editor, Class<?> adapterType) {
+ if (adapterType == JpaEditorManager.class) {
+ return this.buildJpaTextEditorManager(editor);
+ }
+ return null;
+ }
+
+ private JpaEditorManager buildJpaTextEditorManager(ITextEditor editor) {
+ return new JpaTextEditorManager(editor);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorSelectionParticipant.java
deleted file mode 100644
index dbc24cc8b2..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/TextEditorSelectionParticipant.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.IPostSelectionProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jpt.common.core.utility.TextRange;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-public class TextEditorSelectionParticipant
- implements JpaSelectionParticipant
-{
- private final JpaSelectionManager selectionManager;
-
- final ITextEditor textEditor;
-
- private final IPropertyListener editorInputListener;
-
- private final ISelectionChangedListener editorSelectionListener;
-
- private JpaSelection currentSelection;
-
- private boolean forwardSelection = true; // TODO this just smells wrong ~bjv
-
-
- public TextEditorSelectionParticipant(JpaSelectionManager selectionManager, ITextEditor textEditor) {
- super();
- this.selectionManager = selectionManager;
- this.textEditor = textEditor;
- this.editorInputListener = new EditorInputListener();
- this.textEditor.addPropertyListener(this.editorInputListener);
- this.editorSelectionListener = new EditorSelectionListener();
- this.getPostSelectionProvider().addPostSelectionChangedListener(this.editorSelectionListener);
- this.currentSelection = this.calculateSelection();
- }
-
- // ********** IJpaSelectionParticipant implementation **********
-
- public JpaSelection getSelection() {
- return this.currentSelection;
- }
-
- public void selectionChanged(JpaSelectionEvent evt) {
- JpaSelection newSelection = evt.getSelection();
-
- if ((newSelection == JpaSelection.NULL_SELECTION)
- || newSelection.equals(this.currentSelection)) {
- return;
- }
-
- if (getActiveTextEditor() != this.textEditor) {
- return;
- }
-
- this.forwardSelection = false;
- TextRange textRange = newSelection.getSelectedNode().getSelectionTextRange();
- if (textRange != null) {
- this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength());
- this.currentSelection = newSelection;
- }
- this.forwardSelection = true;
- }
-
- public boolean disposeOnHide() {
- return true;
- }
-
- public void dispose() {
- this.textEditor.removePropertyListener(this.editorInputListener);
- this.getPostSelectionProvider().removePostSelectionChangedListener(this.editorSelectionListener);
- }
-
-
- // ********** internal methods **********
-
- protected JpaSelection calculateSelection() {
- ISelection selection = this.textEditor.getSelectionProvider().getSelection();
- if (! (selection instanceof ITextSelection)) {
- return JpaSelection.NULL_SELECTION;
- }
-
- JpaFile jpaFile = this.getJpaFile();
- if (jpaFile == null) {
- return JpaSelection.NULL_SELECTION;
- }
-
- return this.buildSelection(jpaFile.getStructureNode(((ITextSelection) selection).getOffset()));
- }
-
- protected JpaSelection buildSelection(JpaStructureNode selectedNode) {
- return (selectedNode == null) ? JpaSelection.NULL_SELECTION : new DefaultJpaSelection(selectedNode);
- }
-
- protected IWorkbenchPage getActivePage() {
- return this.textEditor.getEditorSite().getWorkbenchWindow().getActivePage();
- }
-
- protected IWorkbenchPart getActivePart() {
- IWorkbenchPage activePage = getActivePage();
- return (activePage == null) ? null: activePage.getActivePart();
- }
-
- protected IEditorPart getActiveEditor() {
- IWorkbenchPage activePage = getActivePage();
- return (activePage == null) ? null: activePage.getActiveEditor();
- }
-
- protected ITextEditor getActiveTextEditor() {
- return getTextEditor(getActiveEditor());
- }
-
- protected ITextEditor getTextEditor(IWorkbenchPart part) {
- return (part == null) ? null : (ITextEditor) part.getAdapter(ITextEditor.class);
- }
-
- protected JpaFile getJpaFile() {
- IEditorInput input = this.textEditor.getEditorInput();
- if ( ! (input instanceof IFileEditorInput)) {
- return null;
- }
- return JptJpaCorePlugin.getJpaFile(((IFileEditorInput) input).getFile());
- }
-
- protected IPostSelectionProvider getPostSelectionProvider() {
- return (IPostSelectionProvider) this.textEditor.getSelectionProvider();
- }
-
-
- // ********** listener callbacks **********
-
- protected void editorInputChanged() {
- this.selectionChanged();
- }
-
- protected void editorSelectionChanged(SelectionChangedEvent event) {
- // This is a bit kludgey. We check to see if the selection event
- // occurred when a participating part is active (and so, ostensibly,
- // *because* of the participating part). If so, we reselect the valid
- // text.
- IWorkbenchPart activePart = getActivePart();
- if (getTextEditor(activePart) != this.textEditor && this.selectionManager.isRegistered(activePart)) {
- if (this.currentSelection.isEmpty()) {
- return;
- }
-
- this.forwardSelection = false;
- TextRange textRange = this.currentSelection.getSelectedNode().getSelectionTextRange();
- if (textRange != null) {
- this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength());
- }
- this.forwardSelection = true;
-
- return;
- }
-
- this.selectionChanged();
- }
-
- protected void selectionChanged() {
- JpaSelection newSelection = this.calculateSelection();
- if (newSelection.equals(this.currentSelection)) {
- return;
- }
- this.currentSelection = newSelection;
-
- if (this.forwardSelection) {
- this.selectionManager.select(newSelection, this);
- }
- }
-
-
- // ********** listeners **********
-
- protected class EditorInputListener implements IPropertyListener {
- protected EditorInputListener() {
- super();
- }
- public void propertyChanged(Object source, int propId) {
- if ((source == TextEditorSelectionParticipant.this.textEditor)
- && (propId == IEditorPart.PROP_INPUT)) {
- TextEditorSelectionParticipant.this.editorInputChanged();
- }
- }
- }
-
-
- protected class EditorSelectionListener implements ISelectionChangedListener {
- protected EditorSelectionListener() {
- super();
- }
- public void selectionChanged(SelectionChangedEvent event) {
- TextEditorSelectionParticipant.this.editorSelectionChanged(event);
- }
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/ViewPartAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/ViewPartAdapterFactory.java
new file mode 100644
index 0000000000..4901832937
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/ViewPartAdapterFactory.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaViewManager;
+import org.eclipse.ui.IViewPart;
+
+/**
+ * Factory to build JPA selection adapters for a {@link IViewPart}:<ul>
+ * <li>{@link org.eclipse.jpt.jpa.ui.selection.JpaViewManager.PageManager}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class ViewPartAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaViewManager.PageManager.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IViewPart) {
+ return this.getAdapter((IViewPart) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IViewPart view, Class<?> adapterType) {
+ if (adapterType == JpaViewManager.PageManager.class) {
+ return this.getPageManager(view);
+ }
+ return null;
+ }
+
+ /**
+ * This will trigger the creation of the appropriate page manager if it does
+ * not already exist.
+ */
+ private JpaViewManager.PageManager getPageManager(IViewPart view) {
+ return JpaWorkbenchManager.getPageManager(view);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchAdapterFactory.java
new file mode 100644
index 0000000000..66cbca6d5c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchAdapterFactory.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * Factory to build JPA selection adapters for a {@link IWorkbench}:<ul>
+ * <li>{@link JpaSelectionManager}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ *
+ * @see JpaWorkbenchManager
+ */
+public class WorkbenchAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaSelectionManager.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IWorkbench) {
+ return this.getAdapter((IWorkbench) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IWorkbench workbench, Class<?> adapterType) {
+ if (adapterType == JpaSelectionManager.class) {
+ return this.getJpaSelectionManager(workbench);
+ }
+ return null;
+ }
+
+ /**
+ * Never return <code>null</code>.
+ */
+ private JpaSelectionManager getJpaSelectionManager(IWorkbench workbench) {
+ return JpaWorkbenchManager.forWorkbench(workbench);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchPartAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchPartAdapterFactory.java
deleted file mode 100644
index bea07321cd..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchPartAdapterFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.selection;
-
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.jpt.jpa.ui.internal.views.JpaDetailsView;
-import org.eclipse.jpt.jpa.ui.internal.views.structure.JpaStructureView;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.texteditor.ITextEditor;
-
-/**
- * Factory to build adapters for a workbench part:
- * - JPA selection participant (if the editor part is a text editor etc.)
- *
- * See org.eclipse.jpt.jpa.ui plugin.xml.
- */
-public class WorkbenchPartAdapterFactory
- implements IAdapterFactory
-{
- private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaSelectionParticipant.class };
-
- public Class<?>[] getAdapterList() {
- return ADAPTER_LIST;
- }
-
- public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) {
- if (adaptableObject instanceof IWorkbenchPart) {
- return this.getAdapter((IWorkbenchPart) adaptableObject, adapterType);
- }
- return null;
- }
-
- private Object getAdapter(IWorkbenchPart workbenchPart, Class<?> adapterType) {
- if (adapterType == JpaSelectionParticipant.class) {
- return this.buildJpaSelectionParticipant(workbenchPart);
- }
- return null;
- }
-
- private JpaSelectionParticipant buildJpaSelectionParticipant(IWorkbenchPart workbenchPart) {
- JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(workbenchPart.getSite().getWorkbenchWindow());
- if (workbenchPart instanceof ITextEditor) {
- return new TextEditorSelectionParticipant(selectionManager, (ITextEditor) workbenchPart);
- }
- if (workbenchPart instanceof JpaStructureView) {
- return new JpaStructureSelectionParticipant(selectionManager, (JpaStructureView) workbenchPart);
- }
- if (workbenchPart instanceof JpaDetailsView) {
- return new JpaDetailsSelectionParticipant((JpaDetailsView) workbenchPart);
- }
- return null;
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchWindowAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchWindowAdapterFactory.java
new file mode 100644
index 0000000000..9a7f125703
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/selection/WorkbenchWindowAdapterFactory.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.selection;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
+import org.eclipse.ui.IWorkbenchWindow;
+
+/**
+ * Factory to build JPA selection adapters for a {@link IWorkbenchWindow}:<ul>
+ * <li>{@link JpaSelectionManager}
+ * </ul>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ *
+ * @see JpaWorkbenchManager
+ */
+public class WorkbenchWindowAdapterFactory
+ implements IAdapterFactory
+{
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaSelectionManager.class };
+
+ public Class<?>[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(Object adaptableObject, @SuppressWarnings("rawtypes") Class adapterType) {
+ if (adaptableObject instanceof IWorkbenchWindow) {
+ return this.getAdapter((IWorkbenchWindow) adaptableObject, adapterType);
+ }
+ return null;
+ }
+
+ private Object getAdapter(IWorkbenchWindow workbenchWindow, Class<?> adapterType) {
+ if (adapterType == JpaSelectionManager.class) {
+ return this.getJpaSelectionManager(workbenchWindow);
+ }
+ return null;
+ }
+
+ /**
+ * Never return <code>null</code>.
+ */
+ private JpaSelectionManager getJpaSelectionManager(IWorkbenchWindow workbenchWindow) {
+ return JpaWorkbenchManager.forWindow(workbenchWindow);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/EntityMappingsItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/EntityMappingsItemContentProvider.java
new file mode 100644
index 0000000000..13d494741d
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/EntityMappingsItemContentProvider.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+
+public class EntityMappingsItemContentProvider
+ extends AbstractItemTreeContentProvider<EntityMappings, OrmPersistentType>
+{
+ public EntityMappingsItemContentProvider(EntityMappings entityMappings, Manager manager) {
+ super(entityMappings, manager);
+ }
+
+ public Object getParent() {
+ // I'd like to return the resource model here, but that involves a hefty
+ // API change - we'll see what happens with this code first
+ return null;
+ }
+
+ @Override
+ protected CollectionValueModel<OrmPersistentType> buildChildrenModel() {
+ return new ListCollectionValueModelAdapter<OrmPersistentType>(new ChildrenModel(this.item));
+ }
+
+ protected static class ChildrenModel
+ extends ListAspectAdapter<EntityMappings, OrmPersistentType>
+ {
+ ChildrenModel(EntityMappings entityMappings) {
+ super(EntityMappings.PERSISTENT_TYPES_LIST, entityMappings);
+ }
+
+ @Override
+ protected ListIterable<OrmPersistentType> getListIterable() {
+ return this.subject.getPersistentTypes();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getPersistentTypesSize();
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java
deleted file mode 100644
index e18da9c246..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.core.context.PersistentType;
-import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistentAttributeItemLabelProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistentTypeItemLabelProvider;
-
-public abstract class GeneralJpaMappingItemLabelProviderFactory
- implements ItemLabelProviderFactory
-{
- public ItemLabelProvider buildItemLabelProvider(
- Object item, DelegatingContentAndLabelProvider labelProvider) {
- if (item instanceof PersistentType) {
- return new PersistentTypeItemLabelProvider((PersistentType) item, labelProvider);
- }
- if (item instanceof ReadOnlyPersistentAttribute) {
- return new PersistentAttributeItemLabelProvider((ReadOnlyPersistentAttribute) item, labelProvider);
- }
- return null;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemContentProviderFactory.java
deleted file mode 100644
index c9d19d7812..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemContentProviderFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.JavaPersistentTypeItemContentProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistentAttributeItemContentProvider;
-
-
-public class JavaItemContentProviderFactory implements TreeItemContentProviderFactory
-{
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentProvider) {
- DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentProvider;
- if (item instanceof JpaFile) {
- return new ResourceModelItemContentProvider((JpaFile) item, treeContentProvider);
- }
- if (item instanceof JavaPersistentType) {
- return new JavaPersistentTypeItemContentProvider((JavaPersistentType) item, treeContentProvider);
- }
- if (item instanceof JavaPersistentAttribute) {
- return new PersistentAttributeItemContentProvider((JavaPersistentAttribute) item, treeContentProvider);
- }
- return null;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemLabelProviderFactory.java
deleted file mode 100644
index ed3c54199f..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaItemLabelProviderFactory.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-
-public class JavaItemLabelProviderFactory extends GeneralJpaMappingItemLabelProviderFactory
-{
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaResourceModelStructureProvider.java
deleted file mode 100644
index 0d07161408..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaResourceModelStructureProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-
-public class JavaResourceModelStructureProvider
- implements JpaStructureProvider
-{
- // singleton
- private static final JpaStructureProvider INSTANCE = new JavaResourceModelStructureProvider();
-
-
- /**
- * Return the singleton
- */
- public static JpaStructureProvider instance() {
- return INSTANCE;
- }
-
-
- /**
- * Enforce singleton usage
- */
- private JavaResourceModelStructureProvider() {
- super();
- }
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new JavaItemContentProviderFactory();
- }
-
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new JavaItemLabelProviderFactory();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemContentProviderFactory.java
new file mode 100644
index 0000000000..69a03e3888
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemContentProviderFactory.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.JavaPersistentTypeItemContentProvider;
+
+/**
+ * This factory builds item content providers for a Java source file
+ * JPA Structure View.
+ */
+public class JavaStructureItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
+{
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new JavaStructureItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected JavaStructureItemContentProviderFactory() {
+ super();
+ }
+
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof JpaFile) {
+ return this.buildJpaFileProvider((JpaFile) item, manager);
+ }
+ if (item instanceof JavaPersistentType) {
+ return this.buildJavaPersistentTypeProvider((JavaPersistentType) item, manager);
+ }
+ if (item instanceof JavaPersistentAttribute) {
+ return this.buildJavaPersistentAttributeProvider((JavaPersistentAttribute) item, manager);
+ }
+ return null;
+ }
+
+ protected ItemTreeContentProvider buildJpaFileProvider(JpaFile item, Manager manager) {
+ return new JpaFileItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildJavaPersistentTypeProvider(JavaPersistentType item, Manager manager) {
+ return new JavaPersistentTypeItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildJavaPersistentAttributeProvider(JavaPersistentAttribute item, @SuppressWarnings("unused") Manager manager) {
+ return new StaticItemTreeContentProvider(item.getParent());
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemLabelProviderFactory.java
new file mode 100644
index 0000000000..afd851dd07
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JavaStructureItemLabelProviderFactory.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+
+/**
+ * This factory builds item label providers for a Java source file
+ * JPA Structure View.
+ */
+public class JavaStructureItemLabelProviderFactory
+ extends MappingStructureItemLabelProviderFactory
+{
+ // singleton
+ private static final ItemExtendedLabelProviderFactory INSTANCE = new JavaStructureItemLabelProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemExtendedLabelProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected JavaStructureItemLabelProviderFactory() {
+ super();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JpaFileItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JpaFileItemContentProvider.java
new file mode 100644
index 0000000000..52947eca67
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/JpaFileItemContentProvider.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+
+public class JpaFileItemContentProvider
+ extends AbstractItemTreeContentProvider<JpaFile, JpaStructureNode>
+{
+ public JpaFileItemContentProvider(JpaFile jpaFile, Manager manager) {
+ super(jpaFile, manager);
+ }
+
+ public Object getParent() {
+ return null;
+ }
+
+ @Override
+ protected CollectionValueModel<JpaStructureNode> buildChildrenModel() {
+ return new ChildrenModel(this.item);
+ }
+
+ public static class ChildrenModel
+ extends CollectionAspectAdapter<JpaFile, JpaStructureNode>
+ {
+ public ChildrenModel(JpaFile jpaFile) {
+ super(JpaFile.ROOT_STRUCTURE_NODES_COLLECTION, jpaFile);
+ }
+
+ @Override
+ protected Iterable<JpaStructureNode> getIterable() {
+ return this.subject.getRootStructureNodes();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getRootStructureNodesSize();
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/MappingStructureItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/MappingStructureItemLabelProviderFactory.java
new file mode 100644
index 0000000000..856807d598
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/MappingStructureItemLabelProviderFactory.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistentAttributeItemLabelProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistentTypeItemLabelProvider;
+
+/**
+ * This factory builds item label providers for the persistent types and
+ * attributes in a JPA Structure View.
+ */
+public abstract class MappingStructureItemLabelProviderFactory
+ implements ItemExtendedLabelProviderFactory
+{
+ protected MappingStructureItemLabelProviderFactory() {
+ super();
+ }
+
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ if (item instanceof PersistentType) {
+ return this.buildPersistentTypeProvider((PersistentType) item, manager);
+ }
+ if (item instanceof ReadOnlyPersistentAttribute) {
+ return this.buildPersistentAttributeProvider((ReadOnlyPersistentAttribute) item, manager);
+ }
+ return null;
+ }
+
+ protected ItemExtendedLabelProvider buildPersistentTypeProvider(PersistentType item, ItemExtendedLabelProvider.Manager manager) {
+ return new PersistentTypeItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildPersistentAttributeProvider(ReadOnlyPersistentAttribute item, ItemExtendedLabelProvider.Manager manager) {
+ return new PersistentAttributeItemLabelProvider(item, manager);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemContentProviderFactory.java
deleted file mode 100644
index 5b3de90068..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemContentProviderFactory.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
-import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
-import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
-import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.OrmPersistentTypeItemContentProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistentAttributeItemContentProvider;
-
-public class OrmItemContentProviderFactory implements TreeItemContentProviderFactory
-{
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentProvider) {
- DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentProvider;
- if (item instanceof JpaFile) {
- return new ResourceModelItemContentProvider((JpaFile) item, treeContentProvider);
- }
- if (item instanceof EntityMappings) {
- return new EntityMappingsItemContentProvider((EntityMappings) item, treeContentProvider);
- }
- if (item instanceof OrmPersistentType) {
- return new OrmPersistentTypeItemContentProvider((OrmPersistentType) item, treeContentProvider);
- }
- if (item instanceof OrmPersistentAttribute) {
- return new PersistentAttributeItemContentProvider((OrmPersistentAttribute) item, treeContentProvider);
- }
- return null;
- }
-
- public static class EntityMappingsItemContentProvider extends AbstractTreeItemContentProvider<OrmPersistentType>
- {
- public EntityMappingsItemContentProvider(
- EntityMappings entityMappings, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(entityMappings, contentProvider);
- }
-
- @Override
- public EntityMappings getModel() {
- return (EntityMappings) super.getModel();
- }
-
- @Override
- public Object getParent() {
- // I'd like to return the resource model here, but that involves a hefty
- // API change - we'll see what happens with this code first
- return null;
- }
-
- @Override
- protected CollectionValueModel<OrmPersistentType> buildChildrenModel() {
- return new ListCollectionValueModelAdapter<OrmPersistentType>(
- new ListAspectAdapter<EntityMappings, OrmPersistentType>(
- EntityMappings.PERSISTENT_TYPES_LIST, getModel()) {
- @Override
- protected ListIterable<OrmPersistentType> getListIterable() {
- return this.subject.getPersistentTypes();
- }
- });
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemLabelProviderFactory.java
deleted file mode 100644
index b4d21ac29a..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmItemLabelProviderFactory.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.EntityMappingsItemLabelProvider;
-
-public class OrmItemLabelProviderFactory extends GeneralJpaMappingItemLabelProviderFactory
-{
- @Override
- public ItemLabelProvider buildItemLabelProvider(
- Object item, DelegatingContentAndLabelProvider labelProvider) {
- if (item instanceof EntityMappings) {
- return new EntityMappingsItemLabelProvider((EntityMappings) item, labelProvider);
- }
- return super.buildItemLabelProvider(item, labelProvider);
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmResourceModelStructureProvider.java
deleted file mode 100644
index b48afb9177..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmResourceModelStructureProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-
-public class OrmResourceModelStructureProvider
- implements JpaStructureProvider
-{
- // singleton
- private static final JpaStructureProvider INSTANCE = new OrmResourceModelStructureProvider();
-
-
- /**
- * Return the singleton
- */
- public static JpaStructureProvider instance() {
- return INSTANCE;
- }
-
-
- /**
- * Enforce singleton usage
- */
- private OrmResourceModelStructureProvider() {
- super();
- }
-
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new OrmItemContentProviderFactory();
- }
-
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new OrmItemLabelProviderFactory();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemContentProviderFactory.java
new file mode 100644
index 0000000000..ca79e13441
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemContentProviderFactory.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.OrmPersistentTypeItemContentProvider;
+
+/**
+ * This factory builds item content providers for an <code>orm.xml</code> file
+ * JPA Structure View.
+ */
+public class OrmStructureItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
+{
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new OrmStructureItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected OrmStructureItemContentProviderFactory() {
+ super();
+ }
+
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof JpaFile) {
+ return this.buildJpaFileProvider((JpaFile) item, manager);
+ }
+ if (item instanceof EntityMappings) {
+ return this.buildEntityMappingsProvider((EntityMappings) item, manager);
+ }
+ if (item instanceof OrmPersistentType) {
+ return this.buildOrmPersistentTypeProvider((OrmPersistentType) item, manager);
+ }
+ if (item instanceof OrmPersistentAttribute) {
+ return this.buildOrmPersistentAttributeProvider((OrmPersistentAttribute) item, manager);
+ }
+ return null;
+ }
+
+ protected ItemTreeContentProvider buildJpaFileProvider(JpaFile item, Manager manager) {
+ return new JpaFileItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildEntityMappingsProvider(EntityMappings item, Manager manager) {
+ return new EntityMappingsItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildOrmPersistentTypeProvider(OrmPersistentType item, Manager manager) {
+ return new OrmPersistentTypeItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildOrmPersistentAttributeProvider(OrmPersistentAttribute item, @SuppressWarnings("unused") Manager manager) {
+ return new StaticItemTreeContentProvider(item.getParent());
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemLabelProviderFactory.java
new file mode 100644
index 0000000000..4b22ce324a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/OrmStructureItemLabelProviderFactory.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+
+/**
+ * This factory builds item label providers for an <code>orm.xml</code> file
+ * JPA Structure View.
+ */
+public class OrmStructureItemLabelProviderFactory
+ extends MappingStructureItemLabelProviderFactory
+{
+ // singleton
+ private static final ItemExtendedLabelProviderFactory INSTANCE = new OrmStructureItemLabelProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemExtendedLabelProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected OrmStructureItemLabelProviderFactory() {
+ super();
+ }
+
+ @Override
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ if (item instanceof EntityMappings) {
+ return this.buildEntityMappingsProvider((EntityMappings) item, manager);
+ }
+ return super.buildProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildEntityMappingsProvider(EntityMappings entityMappings, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return new StaticItemExtendedLabelProvider(
+ JptJpaUiPlugin.getImage(JptUiIcons.ENTITY_MAPPINGS),
+ JptUiMessages.OrmItemLabelProviderFactory_entityMappingsLabel,
+ this.buildEntityMappingsDescription(entityMappings)
+ );
+ }
+
+ protected String buildEntityMappingsDescription(EntityMappings entityMappings) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(JptUiMessages.OrmItemLabelProviderFactory_entityMappingsLabel);
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(entityMappings.getResource().getFullPath().makeRelative());
+ return sb.toString();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProvider.java
new file mode 100644
index 0000000000..3aff0fd408
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProvider.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+
+public class PersistenceItemContentProvider
+ extends AbstractItemTreeContentProvider<Persistence, PersistenceUnit>
+{
+ public PersistenceItemContentProvider(Persistence persistence, Manager manager) {
+ super(persistence, manager);
+ }
+
+ public Object getParent() {
+ // I'd like to return the resource model here, but that involves a hefty
+ // API change - we'll see what happens with this code first
+ return null;
+ }
+
+ @Override
+ protected CollectionValueModel<PersistenceUnit> buildChildrenModel() {
+ return new ListCollectionValueModelAdapter<PersistenceUnit>(new ChildrenModel(this.item));
+ }
+
+ protected static class ChildrenModel
+ extends ListAspectAdapter<Persistence, PersistenceUnit>
+ {
+ ChildrenModel(Persistence persistence) {
+ super(Persistence.PERSISTENCE_UNITS_LIST, persistence);
+ }
+
+ @Override
+ protected ListIterable<PersistenceUnit> getListIterable() {
+ return this.subject.getPersistenceUnits();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getPersistenceUnitsSize();
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProviderFactory.java
deleted file mode 100644
index 248910a404..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemContentProviderFactory.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionListValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
-import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.ListValueModel;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
-import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
-
-public class PersistenceItemContentProviderFactory
- implements TreeItemContentProviderFactory
-{
- public TreeItemContentProvider buildItemContentProvider(
- Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider;
- if (item instanceof JpaFile) {
- return new ResourceModelItemContentProvider((JpaFile) item, treeContentProvider);
- }
- else if (item instanceof Persistence) {
- return new PersistenceItemContentProvider((Persistence) item, treeContentProvider);
- }
- else if (item instanceof PersistenceUnit) {
- return new PersistenceUnitItemContentProvider((PersistenceUnit) item, treeContentProvider);
- }
- else if (item instanceof MappingFileRef) {
- return new MappingFileRefItemContentProvider((MappingFileRef) item, treeContentProvider);
- }
- else if (item instanceof ClassRef) {
- return new ClassRefItemContentProvider((ClassRef) item, treeContentProvider);
- }
- else if (item instanceof JarFileRef) {
- return new JarFileRefItemContentProvider((JarFileRef) item, treeContentProvider);
- }
- return null;
- }
-
-
- public static class PersistenceItemContentProvider extends AbstractTreeItemContentProvider<PersistenceUnit>
- {
- public PersistenceItemContentProvider(
- Persistence persistence, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistence, contentProvider);
- }
-
- @Override
- public Persistence getModel() {
- return (Persistence) super.getModel();
- }
-
- @Override
- public Object getParent() {
- // I'd like to return the resource model here, but that involves a hefty
- // API change - we'll see what happens with this code first
- return null;
- }
-
- @Override
- protected CollectionValueModel<PersistenceUnit> buildChildrenModel() {
- return new ListCollectionValueModelAdapter<PersistenceUnit>(
- new ListAspectAdapter<Persistence, PersistenceUnit>(Persistence.PERSISTENCE_UNITS_LIST, getModel()) {
- @Override
- protected ListIterable<PersistenceUnit> getListIterable() {
- return subject.getPersistenceUnits();
- }
- @Override
- protected int size_() {
- return subject.getPersistenceUnitsSize();
- }
- });
- }
- }
-
-
- public static class PersistenceUnitItemContentProvider extends AbstractTreeItemContentProvider<JpaStructureNode>
- {
- public PersistenceUnitItemContentProvider(
- PersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(persistenceUnit, contentProvider);
- }
-
- @Override
- public PersistenceUnit getModel() {
- return (PersistenceUnit) super.getModel();
- }
-
- @Override
- public Persistence getParent() {
- return getModel().getParent();
- }
-
- @Override
- protected CollectionValueModel<JpaStructureNode> buildChildrenModel() {
- ListValueModel<MappingFileRef> specifiedMappingFileLvm =
- new ListAspectAdapter<PersistenceUnit, MappingFileRef>(
- PersistenceUnit.SPECIFIED_MAPPING_FILE_REFS_LIST,
- getModel()) {
- @Override
- protected ListIterable<MappingFileRef> getListIterable() {
- return subject.getSpecifiedMappingFileRefs();
- }
- @Override
- protected int size_() {
- return subject.getSpecifiedMappingFileRefsSize();
- }
- };
-
- ListValueModel<MappingFileRef> impliedMappingFileCvm =
- new PropertyListValueModelAdapter<MappingFileRef>(
- new PropertyAspectAdapter<PersistenceUnit, MappingFileRef>(
- PersistenceUnit.IMPLIED_MAPPING_FILE_REF_PROPERTY,
- getModel()) {
- @Override
- protected MappingFileRef buildValue_() {
- return subject.getImpliedMappingFileRef();
- }
- }
- );
- ListValueModel<ClassRef> specifiedClassCvm =
- new ListAspectAdapter<PersistenceUnit, ClassRef>(
- PersistenceUnit.SPECIFIED_CLASS_REFS_LIST,
- getModel()) {
- @Override
- protected ListIterable<ClassRef> getListIterable() {
- return subject.getSpecifiedClassRefs();
- }
- @Override
- protected int size_() {
- return subject.getSpecifiedClassRefsSize();
- }
- };
- ListValueModel<ClassRef> impliedClassCvm =
- new CollectionListValueModelAdapter<ClassRef>(
- new CollectionAspectAdapter<PersistenceUnit, ClassRef>(
- PersistenceUnit.IMPLIED_CLASS_REFS_COLLECTION,
- getModel()) {
- @Override
- protected Iterable<ClassRef> getIterable() {
- return subject.getImpliedClassRefs();
- }
- @Override
- protected int size_() {
- return subject.getImpliedClassRefsSize();
- }
- });
- ListValueModel<JarFileRef> jarFileCvm =
- new ListAspectAdapter<PersistenceUnit, JarFileRef>(
- PersistenceUnit.JAR_FILE_REFS_LIST,
- getModel()) {
- @Override
- protected ListIterable<JarFileRef> getListIterable() {
- return subject.getJarFileRefs();
- }
- @Override
- protected int size_() {
- return subject.getJarFileRefsSize();
- }
- };
- List<ListValueModel<? extends JpaStructureNode>> list = new ArrayList<ListValueModel<? extends JpaStructureNode>>(4);
- list.add(specifiedMappingFileLvm);
- list.add(impliedMappingFileCvm);
- list.add(specifiedClassCvm);
- list.add(impliedClassCvm);
- list.add(jarFileCvm);
-
- return new ListCollectionValueModelAdapter<JpaStructureNode>(
- new CompositeListValueModel
- <ListValueModel<? extends JpaStructureNode>, JpaStructureNode>
- (list));
- }
- }
-
-
- public static class MappingFileRefItemContentProvider extends AbstractTreeItemContentProvider<MappingFileRef>
- {
- public MappingFileRefItemContentProvider(
- MappingFileRef mappingFileRef, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(mappingFileRef, contentProvider);
- }
-
- @Override
- public MappingFileRef getModel() {
- return (MappingFileRef) super.getModel();
- }
-
- @Override
- public Object getParent() {
- return getModel().getPersistenceUnit();
- }
-
- @Override
- public boolean hasChildren() {
- return false;
- }
- }
-
-
- public static class ClassRefItemContentProvider extends AbstractTreeItemContentProvider<ClassRef>
- {
- public ClassRefItemContentProvider(
- ClassRef classRef, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(classRef, contentProvider);
- }
-
- @Override
- public ClassRef getModel() {
- return (ClassRef) super.getModel();
- }
-
- @Override
- public Object getParent() {
- return getModel().getPersistenceUnit();
- }
-
- @Override
- public boolean hasChildren() {
- return false;
- }
- }
-
-
- public static class JarFileRefItemContentProvider extends AbstractTreeItemContentProvider<JarFileRef>
- {
- public JarFileRefItemContentProvider(
- JarFileRef jarFileRef, DelegatingTreeContentAndLabelProvider contentProvider) {
- super(jarFileRef, contentProvider);
- }
-
- @Override
- public JarFileRef getModel() {
- return (JarFileRef) super.getModel();
- }
-
- @Override
- public Object getParent() {
- return getModel().getPersistenceUnit();
- }
-
- @Override
- public boolean hasChildren() {
- return false;
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemLabelProviderFactory.java
deleted file mode 100644
index f7b35ae415..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceItemLabelProviderFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
-import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
-import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.ClassRefItemLabelProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.JarFileRefItemLabelProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.MappingFileRefItemLabelProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistenceItemLabelProvider;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistenceUnitItemLabelProvider;
-
-public class PersistenceItemLabelProviderFactory
- implements ItemLabelProviderFactory
-{
- public ItemLabelProvider buildItemLabelProvider(
- Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) {
- if (item instanceof Persistence) {
- return new PersistenceItemLabelProvider((Persistence) item, contentAndLabelProvider);
- }
- else if (item instanceof PersistenceUnit) {
- return new PersistenceUnitItemLabelProvider((PersistenceUnit) item, contentAndLabelProvider);
- }
- else if (item instanceof MappingFileRef) {
- return new MappingFileRefItemLabelProvider((MappingFileRef) item, contentAndLabelProvider);
- }
- else if (item instanceof ClassRef) {
- return new ClassRefItemLabelProvider((ClassRef) item, contentAndLabelProvider);
- }
- else if (item instanceof JarFileRef) {
- return new JarFileRefItemLabelProvider((JarFileRef) item, contentAndLabelProvider);
- }
- return null;
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceResourceModelStructureProvider.java
deleted file mode 100644
index f69524ca05..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceResourceModelStructureProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-
-public class PersistenceResourceModelStructureProvider
- implements JpaStructureProvider
-{
- // singleton
- private static final JpaStructureProvider INSTANCE = new PersistenceResourceModelStructureProvider();
-
-
- /**
- * Return the singleton
- */
- public static JpaStructureProvider instance() {
- return INSTANCE;
- }
-
-
- /**
- * Enforce singleton usage
- */
- private PersistenceResourceModelStructureProvider() {
- super();
- }
-
-
- public TreeItemContentProviderFactory getTreeItemContentProviderFactory() {
- return new PersistenceItemContentProviderFactory();
- }
-
- public ItemLabelProviderFactory getItemLabelProviderFactory() {
- return new PersistenceItemLabelProviderFactory();
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemContentProviderFactory.java
new file mode 100644
index 0000000000..1a35f06fa5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemContentProviderFactory.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProvider.Manager;
+import org.eclipse.jpt.common.ui.jface.ItemTreeContentProviderFactory;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistenceUnitItemContentProvider;
+
+/**
+ * This factory builds item content providers for a <code>persistence.xml</code>
+ * file JPA Structure View.
+ */
+public class PersistenceStructureItemContentProviderFactory
+ implements ItemTreeContentProviderFactory
+{
+ // singleton
+ private static final ItemTreeContentProviderFactory INSTANCE = new PersistenceStructureItemContentProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemTreeContentProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected PersistenceStructureItemContentProviderFactory() {
+ super();
+ }
+
+ public ItemTreeContentProvider buildProvider(Object item, ItemTreeContentProvider.Manager manager) {
+ if (item instanceof JpaFile) {
+ return this.buildJpaFileProvider((JpaFile) item, manager);
+ }
+ if (item instanceof Persistence) {
+ return this.buildPersistenceProvider((Persistence) item, manager);
+ }
+ if (item instanceof PersistenceUnit) {
+ return this.buildPersistenceUnitProvider((PersistenceUnit) item, manager);
+ }
+ if (item instanceof MappingFileRef) {
+ return this.buildMappingFileRefProvider((MappingFileRef) item, manager);
+ }
+ if (item instanceof ClassRef) {
+ return this.buildClassRefProvider((ClassRef) item, manager);
+ }
+ if (item instanceof JarFileRef) {
+ return this.buildJarFileRefProvider((JarFileRef) item, manager);
+ }
+ return null;
+ }
+
+ protected ItemTreeContentProvider buildJpaFileProvider(JpaFile item, Manager manager) {
+ return new JpaFileItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildPersistenceProvider(Persistence item, Manager manager) {
+ return new PersistenceItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildPersistenceUnitProvider(PersistenceUnit item, Manager manager) {
+ return new PersistenceUnitItemContentProvider(item, manager);
+ }
+
+ protected ItemTreeContentProvider buildMappingFileRefProvider(MappingFileRef item, @SuppressWarnings("unused") Manager manager) {
+ return new StaticItemTreeContentProvider(item.getPersistenceUnit());
+ }
+
+ protected ItemTreeContentProvider buildClassRefProvider(ClassRef item, @SuppressWarnings("unused") Manager manager) {
+ return new StaticItemTreeContentProvider(item.getPersistenceUnit());
+ }
+
+ protected ItemTreeContentProvider buildJarFileRefProvider(JarFileRef item, @SuppressWarnings("unused") Manager manager) {
+ return new StaticItemTreeContentProvider(item.getPersistenceUnit());
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java
new file mode 100644
index 0000000000..3200f1e098
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceStructureItemLabelProviderFactory.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import org.eclipse.jpt.common.ui.internal.jface.StaticItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProvider;
+import org.eclipse.jpt.common.ui.jface.ItemExtendedLabelProviderFactory;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
+import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.ClassRefItemLabelProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.JarFileRefItemLabelProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.MappingFileRefItemLabelProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.PersistenceUnitItemLabelProvider;
+
+/**
+ * This factory builds item label providers for a <code>persistence.xml</code> file
+ * JPA Structure View.
+ */
+public class PersistenceStructureItemLabelProviderFactory
+ implements ItemExtendedLabelProviderFactory
+{
+ // singleton
+ private static final ItemExtendedLabelProviderFactory INSTANCE = new PersistenceStructureItemLabelProviderFactory();
+
+ /**
+ * Return the singleton
+ */
+ public static ItemExtendedLabelProviderFactory instance() {
+ return INSTANCE;
+ }
+
+
+ protected PersistenceStructureItemLabelProviderFactory() {
+ super();
+ }
+
+ public ItemExtendedLabelProvider buildProvider(Object item, ItemExtendedLabelProvider.Manager manager) {
+ if (item instanceof Persistence) {
+ return this.buildPersistenceProvider((Persistence) item, manager);
+ }
+ if (item instanceof PersistenceUnit) {
+ return this.buildPersistenceUnitProvider((PersistenceUnit) item, manager);
+ }
+ if (item instanceof MappingFileRef) {
+ return this.buildMappingFileRefProvider((MappingFileRef) item, manager);
+ }
+ if (item instanceof ClassRef) {
+ return this.buildClassRefProvider((ClassRef) item, manager);
+ }
+ if (item instanceof JarFileRef) {
+ return this.buildJarFileRefProvider((JarFileRef) item, manager);
+ }
+ return null;
+ }
+
+ protected ItemExtendedLabelProvider buildPersistenceProvider(Persistence item, @SuppressWarnings("unused") ItemExtendedLabelProvider.Manager manager) {
+ return new StaticItemExtendedLabelProvider(
+ JptJpaUiPlugin.getImage(JptUiIcons.PERSISTENCE),
+ JptUiMessages.PersistenceItemLabelProviderFactory_persistenceLabel,
+ this.buildPersistenceDescription(item)
+ );
+ }
+
+ protected String buildPersistenceDescription(Persistence item) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(JptUiMessages.PersistenceItemLabelProviderFactory_persistenceLabel);
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(item.getResource().getFullPath().makeRelative());
+ return sb.toString();
+ }
+
+ protected ItemExtendedLabelProvider buildPersistenceUnitProvider(PersistenceUnit item, ItemExtendedLabelProvider.Manager manager) {
+ return new PersistenceUnitItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildMappingFileRefProvider(MappingFileRef item, ItemExtendedLabelProvider.Manager manager) {
+ return new MappingFileRefItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildClassRefProvider(ClassRef item, ItemExtendedLabelProvider.Manager manager) {
+ return new ClassRefItemLabelProvider(item, manager);
+ }
+
+ protected ItemExtendedLabelProvider buildJarFileRefProvider(JarFileRef item, ItemExtendedLabelProvider.Manager manager) {
+ return new JarFileRefItemLabelProvider(item, manager);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceUnitItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceUnitItemContentProvider.java
new file mode 100644
index 0000000000..1a9121a10f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/PersistenceUnitItemContentProvider.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.structure;
+
+import java.util.ArrayList;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractItemTreeContentProvider;
+import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CollectionListValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.CompositeListValueModel;
+import org.eclipse.jpt.common.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.ListCollectionValueModelAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.common.utility.internal.model.value.PropertyListValueModelAdapter;
+import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
+import org.eclipse.jpt.common.utility.model.value.ListValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.core.context.persistence.ClassRef;
+import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+
+/**
+ * Item content provider for structure view.
+ */
+public class PersistenceUnitItemContentProvider
+ extends AbstractItemTreeContentProvider<PersistenceUnit, JpaStructureNode>
+{
+ public PersistenceUnitItemContentProvider(PersistenceUnit persistenceUnit, Manager manager) {
+ super(persistenceUnit, manager);
+ }
+
+ public Persistence getParent() {
+ return this.item.getParent();
+ }
+
+ @Override
+ protected CollectionValueModel<JpaStructureNode> buildChildrenModel() {
+ return new ListCollectionValueModelAdapter<JpaStructureNode>(this.buildChildrenModel_());
+ }
+
+ protected ListValueModel<JpaStructureNode> buildChildrenModel_() {
+ ArrayList<ListValueModel<? extends JpaStructureNode>> list = new ArrayList<ListValueModel<? extends JpaStructureNode>>();
+ this.addChildrenModelsTo(list);
+ return new CompositeListValueModel<ListValueModel<? extends JpaStructureNode>, JpaStructureNode>(list);
+ }
+
+ protected void addChildrenModelsTo(ArrayList<ListValueModel<? extends JpaStructureNode>> list) {
+ list.add(this.buildSpecifiedMappingFileRefsModel());
+ list.add(this.buildImpliedMappingFileRefsModel());
+ list.add(this.buildSpecifiedClassRefsModel());
+ list.add(this.buildImpliedClassRefsModel());
+ list.add(this.buildJarFileRefsModel());
+ }
+
+ protected ListValueModel<MappingFileRef> buildSpecifiedMappingFileRefsModel() {
+ return new SpecifiedMappingFileRefsModel(this.item);
+ }
+
+ public static class SpecifiedMappingFileRefsModel
+ extends ListAspectAdapter<PersistenceUnit, MappingFileRef>
+ {
+ public SpecifiedMappingFileRefsModel(PersistenceUnit persistenceUnit) {
+ super(PersistenceUnit.SPECIFIED_MAPPING_FILE_REFS_LIST, persistenceUnit);
+ }
+
+ @Override
+ protected ListIterable<MappingFileRef> getListIterable() {
+ return this.subject.getSpecifiedMappingFileRefs();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getSpecifiedMappingFileRefsSize();
+ }
+ }
+
+ protected ListValueModel<MappingFileRef> buildImpliedMappingFileRefsModel() {
+ return new PropertyListValueModelAdapter<MappingFileRef>(this.buildImpliedMappingFileRefModel());
+ }
+
+ protected PropertyValueModel<MappingFileRef> buildImpliedMappingFileRefModel() {
+ return new ImpliedMappingFileRefModel(this.item);
+ }
+
+ public static class ImpliedMappingFileRefModel
+ extends PropertyAspectAdapter<PersistenceUnit, MappingFileRef>
+ {
+ public ImpliedMappingFileRefModel(PersistenceUnit persistenceUnit) {
+ super(PersistenceUnit.IMPLIED_MAPPING_FILE_REF_PROPERTY, persistenceUnit);
+ }
+ @Override
+ protected MappingFileRef buildValue_() {
+ return this.subject.getImpliedMappingFileRef();
+ }
+ }
+
+ protected ListValueModel<ClassRef> buildSpecifiedClassRefsModel() {
+ return new SpecifiedClassRefsModel(this.item);
+ }
+
+ public static class SpecifiedClassRefsModel
+ extends ListAspectAdapter<PersistenceUnit, ClassRef>
+ {
+ public SpecifiedClassRefsModel(PersistenceUnit persistenceUnit) {
+ super(PersistenceUnit.SPECIFIED_CLASS_REFS_LIST, persistenceUnit);
+ }
+
+ @Override
+ protected ListIterable<ClassRef> getListIterable() {
+ return this.subject.getSpecifiedClassRefs();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getSpecifiedClassRefsSize();
+ }
+ }
+
+ protected ListValueModel<ClassRef> buildImpliedClassRefsModel() {
+ return new CollectionListValueModelAdapter<ClassRef>(this.buildImpliedClassRefsModel_());
+ }
+
+ protected CollectionValueModel<ClassRef> buildImpliedClassRefsModel_() {
+ return new ImpliedClassRefsModel(this.item);
+ }
+
+ public static class ImpliedClassRefsModel
+ extends CollectionAspectAdapter<PersistenceUnit, ClassRef>
+ {
+ public ImpliedClassRefsModel(PersistenceUnit persistenceUnit) {
+ super(PersistenceUnit.IMPLIED_CLASS_REFS_COLLECTION, persistenceUnit);
+ }
+
+ @Override
+ protected Iterable<ClassRef> getIterable() {
+ return this.subject.getImpliedClassRefs();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getImpliedClassRefsSize();
+ }
+ }
+
+ protected ListValueModel<JarFileRef> buildJarFileRefsModel() {
+ return new JarFileRefsModel(this.item);
+ }
+
+ public static class JarFileRefsModel
+ extends ListAspectAdapter<PersistenceUnit, JarFileRef>
+ {
+ public JarFileRefsModel(PersistenceUnit persistenceUnit) {
+ super(PersistenceUnit.JAR_FILE_REFS_LIST, persistenceUnit);
+ }
+
+ @Override
+ protected ListIterable<JarFileRef> getListIterable() {
+ return this.subject.getJarFileRefs();
+ }
+
+ @Override
+ public int size_() {
+ return this.subject.getJarFileRefsSize();
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/ResourceModelItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/ResourceModelItemContentProvider.java
deleted file mode 100644
index 65dceed9f9..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/structure/ResourceModelItemContentProvider.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.structure;
-
-import org.eclipse.jpt.common.ui.internal.jface.AbstractTreeItemContentProvider;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
-import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
-import org.eclipse.jpt.common.utility.model.value.CollectionValueModel;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-
-public class ResourceModelItemContentProvider extends AbstractTreeItemContentProvider<JpaStructureNode>
-{
- public ResourceModelItemContentProvider(
- JpaFile jpaFile,
- DelegatingTreeContentAndLabelProvider contentProvider) {
- super(jpaFile, contentProvider);
- }
-
- @Override
- public Object getParent() {
- return null;
- }
-
- @Override
- public JpaFile getModel() {
- return (JpaFile) super.getModel();
- }
-
- @Override
- protected CollectionValueModel<JpaStructureNode> buildChildrenModel() {
- return new CollectionAspectAdapter<JpaFile, JpaStructureNode>(
- buildJpaFileValueModel(), JpaFile.ROOT_STRUCTURE_NODES_COLLECTION) {
- @Override
- protected Iterable<JpaStructureNode> getIterable() {
- return this.subject.getRootStructureNodes();
- }
- };
- }
-
- protected PropertyValueModel<JpaFile> buildJpaFileValueModel() {
- return new SimplePropertyValueModel<JpaFile>(this.getModel());
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/AbstractJpaView.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/AbstractJpaView.java
deleted file mode 100644
index 9c4a2e4be4..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/AbstractJpaView.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/********************************************************************************
- * Copyright (c) 2006, 2009 Versant. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Versant and Others. - initial API and implementation
- ********************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.views;
-
-import org.eclipse.jpt.common.ui.WidgetFactory;
-import org.eclipse.jpt.common.ui.internal.widgets.FormWidgetFactory;
-import org.eclipse.jpt.common.ui.internal.widgets.PropertySheetWidgetFactory;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.ui.part.ViewPart;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-
-/**
- * This is the abstract implementation of the JPA view. The selection is changed
- * by receiving a <code>IJpaSelection</code>.
- *
- * @see JpaSelection
- *
- * @version 2.0
- * @since 1.0
- */
-public abstract class AbstractJpaView extends ViewPart
-{
- /**
- * The default page used when nothing can be shown.
- */
- private Composite defaultComposite;
-
- /**
- * The string to display when there is no view content
- */
- private String defaultLabel;
-
- /**
- * The container of the current page.
- */
- private PageBook pageBook;
-
- private ScrolledForm scrolledForm;
-
-
- /**
- * The factory used to create the various widgets.
- */
- private WidgetFactory widgetFactory;
-
- /**
- * Creates a new <code>AbstractJpaView</code>.
- *
- * @param defaultLabel
- */
- public AbstractJpaView(String defaultLabel) {
- super();
- this.defaultLabel = defaultLabel;
- this.initialize();
- }
-
- private Composite buildDefaultComposite() {
- Composite composite = widgetFactory.createComposite(pageBook);
- composite.setLayout(new FillLayout(SWT.VERTICAL));
- getWidgetFactory().createLabel(composite, defaultLabel);
- return composite;
- }
-
- @Override
- public final void createPartControl(Composite parent) {
- this.scrolledForm = getFormWidgetFactory().createScrolledForm(parent);
- JptJpaUiPlugin.instance().controlAffectsJavaSource(this.scrolledForm);
- this.scrolledForm.getBody().setLayout(new GridLayout());
-
- this.pageBook = new PageBook(this.scrolledForm.getBody(), SWT.NONE);
- GridData gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.horizontalAlignment = SWT.FILL;
- this.pageBook.setLayoutData(gridData);
- this.scrolledForm.setContent(this.pageBook);
-
- this.defaultComposite = buildDefaultComposite();
- this.pageBook.showPage(this.defaultComposite);
-
- subcreatePartControl(parent);
-
- JpaSelectionManager selectionManager =
- SelectionManagerFactory.getSelectionManager(getViewSite().getWorkbenchWindow());
-
- selectionManager.register(this);
- select(selectionManager.getCurrentSelection());
- }
-
- protected final PageBook getPageBook() {
- return this.pageBook;
- }
-
- public final WidgetFactory getWidgetFactory() {
- return this.widgetFactory;
- }
-
- /**
- * Initializes this JPA view.
- */
- protected void initialize() {
- this.widgetFactory = new PropertySheetWidgetFactory(
- new TabbedPropertySheetWidgetFactory()
- );
- }
-
- private FormToolkit getFormWidgetFactory() {
- return ((FormWidgetFactory) widgetFactory).getWidgetFactory();
- }
-
- /**
- * The selection has changed, update the current page by using the given
- * selection state.
- *
- * @param jpaSelection The new selection used to update this JPA view
- */
- public abstract void select(JpaSelection jpaSelection);
-
- /*
- * (non-Javadoc)
- */
- @Override
- public void setFocus() {
- pageBook.setFocus();
- }
-
- /**
- * Changes the current page and show the default one.
- */
- protected void showDefaultPage() {
- showPage(defaultComposite);
- }
-
- /**
- * Changes the current page and show the given one.
- *
- * @param page The new page to show, <code>null</code> can't be passed
- */
- protected final void showPage(Control page) {
- page.setParent(this.pageBook);
- this.pageBook.showPage(page);
- this.scrolledForm.reflow(true);
- }
-
- protected void subcreatePartControl(@SuppressWarnings("unused") Composite parent) {
- // no op - for subclasses to override if wished
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaDetailsView.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaDetailsView.java
index 2cd756e9e4..15f299e4f8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaDetailsView.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaDetailsView.java
@@ -1,190 +1,318 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.views;
import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.internal.widgets.PropertySheetWidgetFactory;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.details.JpaDetailsPage;
+import org.eclipse.jpt.jpa.ui.details.JpaDetailsPageManager;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.platform.JpaPlatformUiRegistry;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelection;
+import org.eclipse.jpt.jpa.ui.selection.JpaViewManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.ViewPart;
/**
- * The JPA view that shows the details of a structure node
+ * The JPA details view has a page book that displays the JPA details page
+ * corresponding to the current JPA selection. The JPA details only listens to
+ * the JPA selection; it will never change the JPA selection.
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
*
- * @version 2.2
+ * @version 3.0
* @since 1.0
*/
-public class JpaDetailsView extends AbstractJpaView
+public class JpaDetailsView
+ extends ViewPart
{
/**
- * The current <code>JpaDetailsPage</code> that was retrieve based on the
- * current selection.
+ * The factory used by the details view and its page managers
+ * to create the their widgets.
+ */
+ private final PropertySheetWidgetFactory widgetFactory = new PropertySheetWidgetFactory();
+
+ /**
+ * The scrolled form that holds the {@link #pageBook page book}.
+ * We need to force it to reflow whenever we change the page book's
+ * current page.
*/
- private JpaDetailsPage<JpaStructureNode> currentPage;
+ private volatile ScrolledForm scrolledForm;
/**
- * The current selection used to show the right <code>IJpaDetailsPage</code>.
+ * The container of all the details pages.
*/
- private JpaSelection currentSelection;
+ private volatile PageBook pageBook;
- //TODO this is crap, a Map of Maps of Maps. Needs to be done differently, the factory/platform should handle caching instead
- // key1 platform id
- // key2 JpaResourceType
- // key3 structure node type
- // value Composite page
- private Map<String, Map<JptResourceType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>> detailsPages;
+ /**
+ * The page displayed by the {@link #pageBook page book}
+ * when nothing can be shown.
+ */
+ private volatile Control defaultPage;
/**
- * Creates a new <code>JpaDetailsView</code>.
+ * The current JPA details page manager that was built based on the
+ * current JPA selection.
*/
+ private volatile JpaDetailsPageManager<? extends JpaStructureNode> currentPageManager;
+
+ /**
+ * The manager is created when the view's control is
+ * {@link #createPartControl(Composite) created}
+ * and disposed, if necessary, when the view is
+ * {@link #dispose() disposed}.
+ */
+ private volatile Manager manager;
+
+ /**
+ * Listen for changes to the JPA selection.
+ */
+ private final PropertyChangeListener jpaSelectionListener = new JpaSelectionListener();
+
+ /**
+ * Cache of JPA details page managers
+ * keyed by JPA structure node context type.
+ */
+ private final HashMap<JpaStructureNode.ContextType, JpaDetailsPageManager<? extends JpaStructureNode>> pageManagers =
+ new HashMap<JpaStructureNode.ContextType, JpaDetailsPageManager<? extends JpaStructureNode>>();
+
+
public JpaDetailsView() {
- super(JptUiMessages.JpaDetailsView_viewNotAvailable);
+ super();
}
@Override
- protected void initialize() {
- super.initialize();
-
- this.currentSelection = JpaSelection.NULL_SELECTION;
- this.detailsPages = new HashMap<String, Map<JptResourceType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>>();
- }
-
- private JpaPlatformUi getJpaPlatformUi(JpaStructureNode structureNode) {
- String platformId = structureNode.getJpaProject().getJpaPlatform().getId();
- return JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
- }
-
- public JpaSelection getSelection() {
- return this.currentSelection;
- }
-
- private JpaDetailsPage<? extends JpaStructureNode> getDetailsPage(JpaStructureNode structureNode) {
- String platformId = structureNode.getJpaProject().getJpaPlatform().getId();
- if (this.detailsPages.containsKey(platformId)) {
- Map<JptResourceType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> platformDetailsPages = this.detailsPages.get(platformId);
- Map<String, JpaDetailsPage<? extends JpaStructureNode>> contentTypeDetailsPages = platformDetailsPages.get(structureNode.getResourceType());
- if (contentTypeDetailsPages != null) {
- JpaDetailsPage<? extends JpaStructureNode> page = contentTypeDetailsPages.get(structureNode.getId());
- if (page != null) {
- if (page.getControl().isDisposed()) {
- platformDetailsPages.remove(structureNode.getId());
- } else {
- return page;
+ public void createPartControl(Composite parent) {
+ this.scrolledForm = this.widgetFactory.getWidgetFactory().createScrolledForm(parent);
+ JptJpaUiPlugin.instance().controlAffectsJavaSource(this.scrolledForm);
+ this.scrolledForm.getBody().setLayout(new GridLayout());
+
+ this.pageBook = new PageBook(this.scrolledForm.getBody(), SWT.NONE);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = SWT.FILL;
+ this.pageBook.setLayoutData(gridData);
+
+ this.defaultPage = this.buildDefaultPage();
+ this.pageBook.showPage(this.defaultPage);
+
+ this.manager = this.buildManager();
+ this.manager.getJpaSelectionModel().addPropertyChangeListener(PropertyValueModel.VALUE, this.jpaSelectionListener);
+ this.setJpaSelection(this.manager.getJpaSelectionModel().getValue());
+ }
+
+ private Control buildDefaultPage() {
+ Composite composite = this.widgetFactory.createComposite(this.pageBook);
+ composite.setLayout(new FillLayout(SWT.VERTICAL));
+ this.widgetFactory.createLabel(composite, JptUiMessages.JpaDetailsView_viewNotAvailable);
+ return composite;
+ }
+
+ private Manager buildManager() {
+ return new Manager(this.getPageManager());
+ }
+
+ /**
+ * Go to the singleton in the sky.
+ * <p>
+ * <strong>NB:</strong> This will trigger the creation of the appropriate
+ * page manager if it does not already exist.
+ */
+ private JpaViewManager.PageManager getPageManager() {
+ return (JpaViewManager.PageManager) this.getAdapter(JpaViewManager.PageManager.class);
+ }
+
+
+ // ********** JPA selection **********
+
+ /* CU private */ class JpaSelectionListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaDetailsView.this.setJpaSelection((JpaStructureNode) event.getNewValue());
+ }
+ }
+
+ /* CU private */ void setJpaSelection(JpaStructureNode node) {
+ boolean pageChange = false;
+ if (node == null) {
+ if (this.currentPageManager == null) { // null => null
+ // do nothing
+ } else { // node => null
+ try {
+ this.currentPageManager.setSubject(null);
+ } catch (RuntimeException ex) {
+ JptJpaUiPlugin.log(ex);
+ }
+ this.currentPageManager = null;
+ pageChange = true;
+ }
+ } else {
+ if (this.currentPageManager == null) { // null => node
+ this.currentPageManager = this.getPageManager(node);
+ if (this.currentPageManager != null) {
+ try {
+ this.currentPageManager.setSubject(node);
+ pageChange = true;
+ } catch (RuntimeException ex) {
+ JptJpaUiPlugin.log(ex);
+ this.currentPageManager = null; // leave default page
+ }
+ }
+ } else { // node => node
+ JpaDetailsPageManager<? extends JpaStructureNode> pageManager = this.getPageManager(node);
+ if (pageManager != this.currentPageManager) {
+ try {
+ this.currentPageManager.setSubject(null);
+ } catch (RuntimeException ex) {
+ JptJpaUiPlugin.log(ex);
+ }
+ this.currentPageManager = pageManager;
+ pageChange = true;
+ }
+ if (this.currentPageManager != null) {
+ try {
+ this.currentPageManager.setSubject(node);
+ } catch (RuntimeException ex) {
+ JptJpaUiPlugin.log(ex);
+ this.currentPageManager = null; // show default page
+ pageChange = true;
}
}
}
}
- return buildDetailsPage(structureNode);
+
+ if (pageChange) {
+ this.pageBook.showPage(this.getCurrentPage());
+ this.scrolledForm.reflow(true); // true => flush cache
+ }
+ }
+
+ private Control getCurrentPage() {
+ return (this.currentPageManager != null) ? this.currentPageManager.getPage() : this.defaultPage;
}
- private JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(JpaStructureNode structureNode) {
- JpaPlatformUi jpaPlatformUi = getJpaPlatformUi(structureNode);
-
- Composite container = getWidgetFactory().createComposite(getPageBook());
- container.setLayout(new FillLayout(SWT.HORIZONTAL));
- JpaDetailsPage<? extends JpaStructureNode> page = jpaPlatformUi.buildJpaDetailsPage(container, structureNode, getWidgetFactory());
- if (page == null) {
- return null;
- }
+ // ********** page managers **********
- String platformId = structureNode.getJpaProject().getJpaPlatform().getId();
- Map<JptResourceType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> platformDetailsPages = this.detailsPages.get(platformId);
- if (platformDetailsPages == null) {
- platformDetailsPages = new HashMap<JptResourceType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>();
- this.detailsPages.put(platformId, platformDetailsPages);
- }
- JptResourceType resourceType = structureNode.getResourceType();
- Map<String, JpaDetailsPage<? extends JpaStructureNode>> contentTypeDetailsPages = platformDetailsPages.get(resourceType);
- if (contentTypeDetailsPages == null) {
- contentTypeDetailsPages = new HashMap<String, JpaDetailsPage<? extends JpaStructureNode>>();
- platformDetailsPages.put(resourceType, contentTypeDetailsPages);
+ /**
+ * @see org.eclipse.jpt.jpa.core.JpaStructureNode.ContextType
+ */
+ private JpaDetailsPageManager<? extends JpaStructureNode> getPageManager(JpaStructureNode node) {
+ JpaStructureNode.ContextType nodeType = node.getContextType();
+ JpaDetailsPageManager<? extends JpaStructureNode> pageManager = this.pageManagers.get(nodeType);
+ if (pageManager == null) {
+ pageManager = this.buildPageManager(node);
+ if (pageManager != null) {
+ this.pageManagers.put(nodeType, pageManager);
+ }
}
- contentTypeDetailsPages.put(structureNode.getId(), page);
+ return pageManager;
+ }
- return page;
+ private JpaDetailsPageManager<? extends JpaStructureNode> buildPageManager(JpaStructureNode node) {
+ return this.getJpaDetailsPageManagerFactory(node).buildPageManager(this.pageBook, this.widgetFactory);
}
+ private JpaDetailsPageManager.Factory getJpaDetailsPageManagerFactory(JpaStructureNode node) {
+ return (JpaDetailsPageManager.Factory) node.getAdapter(JpaDetailsPageManager.Factory.class);
+ }
+
+
+ // ********** misc **********
+
@Override
- @SuppressWarnings("unchecked")
- public void select(JpaSelection jpaSelection) {
- if (jpaSelection.equals(this.currentSelection)) {
- return;
- }
+ public void setFocus() {
+ this.pageBook.setFocus();
+ }
- this.currentSelection = jpaSelection;
- if (jpaSelection == JpaSelection.NULL_SELECTION) {
- if (this.currentPage != null) {
- this.currentPage.setSubject(null);
- this.setCurrentPage(null);
- }
- return;
+ @Override
+ public void dispose() {
+ if (this.manager != null) {
+ this.dispose_();
}
- JpaStructureNode newNode = jpaSelection.getSelectedNode();
- JpaDetailsPage<JpaStructureNode> newPage = (JpaDetailsPage<JpaStructureNode>) getDetailsPage(newNode);
- if (this.currentPage != null && this.currentPage != newPage){
- try {
- this.currentPage.setSubject(null);
- } catch (Exception e) {
- JptJpaUiPlugin.log(e);
- }
+ super.dispose();
+ }
+
+ private void dispose_() {
+ this.manager.getJpaSelectionModel().removePropertyChangeListener(PropertyValueModel.VALUE, this.jpaSelectionListener);
+ this.manager.dispose();
+
+ if (this.currentPageManager != null) {
+ this.currentPageManager.setSubject(null);
+ this.currentPageManager = null;
}
- if (newPage != null) {
- try {
- newPage.setSubject(newNode);
- } catch (Exception e) {
- newPage = null;// Show error page
- JptJpaUiPlugin.log(e);
- }
+ for (JpaDetailsPageManager<? extends JpaStructureNode> detailsPage : this.pageManagers.values()) {
+ detailsPage.dispose();
}
- setCurrentPage(newPage);
+ this.pageManagers.clear();
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
}
+
+ // ********** JPA view manager **********
+
/**
- * Changes the current page and shows the given page.
- *
- * @param newPage The new page to display
+ * Adapter to the view's page manager.
*/
- private void setCurrentPage(JpaDetailsPage<JpaStructureNode> newPage) {
- this.currentPage = newPage;
+ /* CU private */ class Manager
+ implements JpaViewManager
+ {
+ /**
+ * The manager for the structure view's workbench page.
+ */
+ private final JpaViewManager.PageManager pageManager;
+
- // Show new page
- if (newPage == null) {
- showDefaultPage();
+ Manager(JpaViewManager.PageManager pageManager) {
+ super();
+ if (pageManager == null) {
+ throw new NullPointerException(); // shouldn't happen...
+ }
+ this.pageManager = pageManager;
+ this.pageManager.addViewManager(this);
}
- else {
- showPage(newPage.getControl());
+
+ public IViewPart getView() {
+ return JpaDetailsView.this;
}
- }
- @Override
- public void dispose() {
- for (Map<JptResourceType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> resourceTypeMap : this.detailsPages.values()) {
- for (Map<String, JpaDetailsPage<? extends JpaStructureNode>> detailsPageMap : resourceTypeMap.values()) {
- for (JpaDetailsPage<? extends JpaStructureNode> detailsPage : detailsPageMap.values()) {
- detailsPage.dispose();
- }
- }
+ WritablePropertyValueModel<JpaStructureNode> getJpaSelectionModel() {
+ return this.pageManager.getJpaSelectionModel();
}
- this.detailsPages.clear();
- this.currentSelection = JpaSelection.NULL_SELECTION;
- this.currentPage = null;
+ void dispose() {
+ this.pageManager.removeViewManager(this);
+ }
- super.dispose();
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
}
-} \ No newline at end of file
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java
new file mode 100644
index 0000000000..3a55a04199
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java
@@ -0,0 +1,505 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.views;
+
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jpt.common.core.JptResourceType;
+import org.eclipse.jpt.common.ui.internal.jface.AbstractSelectionProvider;
+import org.eclipse.jpt.common.ui.internal.jface.ItemTreeStateProviderManager;
+import org.eclipse.jpt.common.ui.internal.jface.SelectionChangedAdapter;
+import org.eclipse.jpt.common.ui.internal.jface.SimpleMessageTreeContent;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
+import org.eclipse.jpt.common.ui.jface.ItemTreeStateProviderFactoryProvider;
+import org.eclipse.jpt.common.ui.jface.TreeStateProvider;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
+import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+import org.eclipse.jpt.jpa.ui.selection.JpaEditorManager;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.navigator.IDescriptionProvider;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
+
+/**
+ * The {@link JpaStructureView JPA structure view} is a page book view that
+ * maintains a JPA structure page per editor.
+ */
+public class JpaStructurePage
+ extends Page
+{
+ /**
+ * The structure page's parent page book.
+ * Never <code>null</code>.
+ */
+ private final JpaStructureView structureView;
+
+ /**
+ * The manager corresponding to the editor
+ * the structure page is associated with.
+ * Never <code>null</code>.
+ */
+ private final JpaEditorManager editorManager;
+
+ /**
+ * Listen for the model or the editor manager to change the
+ * JPA file.
+ */
+ private final PropertyChangeListener jpaFileListener = new JpaFileListener();
+
+ /**
+ * Listen for others to change the JPA selection.
+ */
+ private final PropertyChangeListener jpaSelectionListener = new JpaSelectionListener();
+
+ /**
+ * Adapt the tree selection provider to the page's selection provider,
+ * which is adapted to the (page book) view's selection provider.
+ */
+ private final SelectionProvider selectionProvider = new SelectionProvider();
+
+ /**
+ * The page's main control.
+ */
+ private /* virtually final */ Composite control;
+
+ /**
+ * The page's tree viewer.
+ */
+ private /* virtually final */ TreeViewer treeViewer;
+
+ /**
+ * Listen for changes to the tree's selection.
+ */
+ private final ISelectionChangedListener treePostSelectionListener = new TreePostSelectionChangedListener();
+
+
+ public JpaStructurePage(JpaStructureView structureView, JpaEditorManager editorManager) {
+ super();
+ this.structureView = structureView;
+ this.editorManager = editorManager;
+ }
+
+ @Override
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ pageSite.setSelectionProvider(this.selectionProvider);
+ }
+
+ // TODO use problem decorator
+ @Override
+ public void createControl(Composite parent) {
+ this.control = new Composite(parent, SWT.NULL);
+ this.control.setLayout(new FillLayout());
+ this.treeViewer = new TreeViewer(this.control, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ this.treeViewer.setAutoExpandLevel(2);
+ this.setTreeViewerJpaFile(this.getEditorJpaFile());
+ this.engageListeners();
+ this.initializeContextMenu();
+ }
+
+ private void engageListeners() {
+ this.getEditorJpaFileModel().addPropertyChangeListener(PropertyValueModel.VALUE, this.jpaFileListener);
+ this.getEditorJpaSelectionModel().addPropertyChangeListener(PropertyValueModel.VALUE, this.jpaSelectionListener);
+ this.treeViewer.addSelectionChangedListener(this.selectionProvider);
+ this.treeViewer.addPostSelectionChangedListener(this.treePostSelectionListener);
+ }
+
+ @Override
+ public void dispose() {
+ this.disengageListeners();
+ super.dispose();
+ }
+
+ private void disengageListeners() {
+ this.treeViewer.removePostSelectionChangedListener(this.treePostSelectionListener);
+ this.treeViewer.removeSelectionChangedListener(this.selectionProvider);
+ this.getEditorJpaSelectionModel().removePropertyChangeListener(PropertyValueModel.VALUE, this.jpaSelectionListener);
+ this.getEditorJpaFileModel().removePropertyChangeListener(PropertyValueModel.VALUE, this.jpaFileListener);
+ }
+
+
+ // ********** context menu **********
+
+ /**
+ * A dynamic menu manager is required to support action contributions.
+ */
+ private void initializeContextMenu() {
+ MenuManager menuManager = new MenuManager();
+ menuManager.setRemoveAllWhenShown(true);
+ menuManager.addMenuListener(new MenuListener()); // no need to remove listener(?)
+ Tree tree = this.treeViewer.getTree();
+ tree.setMenu(menuManager.createContextMenu(tree));
+ this.structureView.getSite().registerContextMenu(menuManager, this.treeViewer);
+ }
+
+ /* CU private */ class MenuListener
+ implements IMenuListener
+ {
+ public void menuAboutToShow(IMenuManager menuManager) {
+ // Delegates to the action group using the viewer's selection as the action context.
+ menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** editor JPA file **********
+
+ private JpaFile getEditorJpaFile() {
+ return this.getEditorJpaFileModel().getValue();
+ }
+
+ private PropertyValueModel<JpaFile> getEditorJpaFileModel() {
+ return this.editorManager.getJpaFileModel();
+ }
+
+ /* CU private */ class JpaFileListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaStructurePage.this.setTreeViewerInput((JpaFile) event.getNewValue());
+ }
+ }
+
+
+ // ********** tree input **********
+
+ /* CU private */ void setTreeViewerInput(JpaFile jpaFile) {
+ this.execute(new SetTreeViewerInputRunnable(jpaFile));
+ }
+
+ /* CU private */ class SetTreeViewerInputRunnable
+ implements Runnable
+ {
+ private final JpaFile jpaFile;
+
+ SetTreeViewerInputRunnable(JpaFile jpaFile) {
+ super();
+ this.jpaFile = jpaFile;
+ }
+
+ public void run() {
+ JpaStructurePage.this.setTreeViewerInput_(this.jpaFile);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.jpaFile);
+ }
+ }
+
+ /**
+ * Pre-condition: executing on the UI thread.
+ */
+ /* CU private */ void setTreeViewerInput_(JpaFile jpaFile) {
+ // not sure why TreeViewer.setInput(...) requires a dispose check,
+ // while TreeViewer.setSelection(...) does not...
+ if (this.treeViewer.getControl().isDisposed()) {
+ return;
+ }
+
+ // clear the tree before we change the providers
+ this.treeViewer.setInput(null);
+ this.setTreeViewerJpaFile(jpaFile);
+ }
+
+ private void setTreeViewerJpaFile(JpaFile jpaFile) {
+ if (jpaFile == null) {
+ this.setTreeViewerMessage(JptUiMessages.JpaStructureView_structureNotAvailable);
+ } else {
+ ItemTreeStateProviderFactoryProvider sp = (ItemTreeStateProviderFactoryProvider) jpaFile.getAdapter(ItemTreeStateProviderFactoryProvider.class);
+ if (sp == null) {
+ this.setTreeViewerMessage(this.buildMissingStructureProviderMessage(jpaFile));
+ } else {
+ this.setTreeViewerJpaFile(jpaFile, sp);
+ this.setTreeViewerJpaSelection_(this.getEditorJpaSelection());
+ }
+ }
+ }
+
+ private String buildMissingStructureProviderMessage(JpaFile jpaFile) {
+ JptResourceType resourceType = jpaFile.getResourceModel().getResourceType();
+ String contentType = resourceType.getContentType().getName();
+ String version = resourceType.getVersion();
+ return NLS.bind(JptUiMessages.JpaStructureView_structureProviderNotAvailable, contentType, version);
+ }
+
+ private void setTreeViewerJpaFile(JpaFile jpaFile, ItemTreeStateProviderFactoryProvider sp) {
+ TreeStateProvider provider = this.buildStateProvider(sp);
+ this.treeViewer.setContentProvider(provider);
+ this.treeViewer.setLabelProvider(provider);
+ this.treeViewer.setInput(jpaFile);
+ }
+
+ private TreeStateProvider buildStateProvider(ItemTreeStateProviderFactoryProvider structureProvider) {
+ return new ItemTreeStateProviderManager(
+ structureProvider.getItemContentProviderFactory(),
+ structureProvider.getItemLabelProviderFactory()
+ );
+ }
+
+ private void setTreeViewerMessage(String message) {
+ this.treeViewer.setContentProvider(SimpleMessageTreeContent.contentProvider());
+ this.treeViewer.setLabelProvider(SimpleMessageTreeContent.labelProvider());
+ this.treeViewer.setInput(new SimpleMessageTreeContent(message));
+ }
+
+
+ // ********** editor JPA selection **********
+
+ private JpaStructureNode getEditorJpaSelection() {
+ return this.getEditorJpaSelectionModel().getValue();
+ }
+
+ private void setEditorJpaSelection(JpaStructureNode selection) {
+ this.getEditorJpaSelectionModel().setValue(selection);
+ }
+
+ private WritablePropertyValueModel<JpaStructureNode> getEditorJpaSelectionModel() {
+ return this.editorManager.getJpaSelectionModel();
+ }
+
+ /* CU private */ class JpaSelectionListener
+ extends PropertyChangeAdapter
+ {
+ @Override
+ public void propertyChanged(PropertyChangeEvent event) {
+ JpaStructurePage.this.setTreeViewerJpaSelection((JpaStructureNode) event.getNewValue());
+ }
+ }
+
+
+ // ********** tree selection **********
+
+ /**
+ * If the new JPA selection is different
+ * from the tree's current JPA selection, modify the tree's selection.
+ */
+ /* CU private */ void setTreeViewerJpaSelection(JpaStructureNode selection) {
+ this.execute(new SetTreeViewerSelectionRunnable(selection));
+ }
+
+ /* CU private */ class SetTreeViewerSelectionRunnable
+ implements Runnable
+ {
+ private final JpaStructureNode selection;
+
+ SetTreeViewerSelectionRunnable(JpaStructureNode selection) {
+ super();
+ this.selection = selection;
+ }
+
+ public void run() {
+ JpaStructurePage.this.setTreeViewerJpaSelection_(this.selection);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.selection);
+ }
+ }
+
+ /**
+ * Pre-condition: executing on the UI thread.
+ */
+ /* CU private */ void setTreeViewerJpaSelection_(JpaStructureNode selection) {
+ if (selection != this.getTreeViewerJpaSelection()) {
+ this.setTreeViewerSelection((selection == null) ? null : new StructuredSelection(selection));
+ }
+ }
+
+ /* CU private */ void setTreeViewerSelection(ISelection selection) {
+ if (this.treeViewer != null) {
+ this.treeViewer.setSelection(selection, true); // true => reveal
+ }
+ }
+
+ private JpaStructureNode getTreeViewerJpaSelection() {
+ return this.convertToJpaSelection_(this.getTreeViewerSelection());
+ }
+
+ /**
+ * Return a tree selection that is either empty or contains a single
+ * {@link JpaStructureNode JPA structure node}.
+ */
+ /* CU private */ IStructuredSelection getTreeViewerSelection() {
+ return (this.treeViewer == null) ?
+ TreeSelection.EMPTY :
+ this.filterSelection((ITreeSelection) this.treeViewer.getSelection());
+ }
+
+ /* CU private */ IStructuredSelection filterSelection(IStructuredSelection selection) {
+ // the selection could be a message
+ return ((selection.size() == 1) && (selection.getFirstElement() instanceof JpaStructureNode)) ?
+ selection :
+ StructuredSelection.EMPTY;
+ }
+
+ private JpaStructureNode convertToJpaSelection(IStructuredSelection selection) {
+ return this.convertToJpaSelection_(this.filterSelection(selection));
+ }
+
+ private JpaStructureNode convertToJpaSelection_(IStructuredSelection filterSelection) {
+ return filterSelection.isEmpty() ? null : (JpaStructureNode) filterSelection.getFirstElement();
+ }
+
+
+ // ********** tree post selection **********
+
+ /**
+ * "Post" listeners are notified with a bit of a delay when the selection
+ * is modified via the keyboard (as opposed to the mouse).
+ */
+ /* CU private */ class TreePostSelectionChangedListener
+ extends SelectionChangedAdapter
+ {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ JpaStructurePage.this.treePostSelectionChanged(event.getSelection());
+ }
+ }
+
+ /**
+ * <ul>
+ * <li>Forward the new selection to the editor manager
+ * (and on to other JPA views).
+ * <li>Update the status bar.
+ * </ul>
+ */
+ /* CU private */ void treePostSelectionChanged(ISelection selection) {
+ this.setEditorJpaSelection(this.convertToJpaSelection(selection));
+ this.updateStatusLine(selection);
+ }
+
+ private JpaStructureNode convertToJpaSelection(ISelection selection) {
+ return (selection instanceof IStructuredSelection) ?
+ this.convertToJpaSelection((IStructuredSelection) selection) :
+ null;
+ }
+
+
+ // ********** status line **********
+
+ private void updateStatusLine(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ this.updateStatusLine((IStructuredSelection) selection);
+ } else {
+ this.getStatusLineManager().setMessage(""); //$NON-NLS-1$
+ }
+ }
+
+ private void updateStatusLine(IStructuredSelection selection) {
+ if (selection.isEmpty()) {
+ this.getStatusLineManager().setMessage(""); //$NON-NLS-1$
+ } else {
+ if (selection.size() > 1) {
+ Integer size = Integer.valueOf(selection.size());
+ String msg = NLS.bind(JptUiMessages.JpaStructureView_numItemsSelected, size);
+ this.getStatusLineManager().setMessage(msg);
+ } else {
+ Object first = selection.getFirstElement();
+ ILabelProvider labelProvider = (ILabelProvider) this.treeViewer.getLabelProvider();
+ Image image = labelProvider.getImage(first);
+ String msg = labelProvider.getText(first);
+ if (first instanceof JpaStructureNode) {
+ msg = ((IDescriptionProvider) labelProvider).getDescription(first);
+ }
+ this.getStatusLineManager().setMessage(image, msg);
+ }
+ }
+ }
+
+ private IStatusLineManager getStatusLineManager() {
+ return this.getSite().getActionBars().getStatusLineManager();
+ }
+
+
+ // ********** selection provider **********
+
+ /**
+ * Selection provider - adapt the structure page's
+ * {@link #treeViewer tree viewer} for the page book view.
+ * The selection is {@link JpaStructurePage#filterSelection(IStructuredSelection) filtered}.
+ */
+ /* CU private */ class SelectionProvider
+ extends AbstractSelectionProvider
+ implements ISelectionChangedListener
+ {
+ public ISelection getSelection() {
+ return JpaStructurePage.this.getTreeViewerSelection();
+ }
+
+ public void setSelection(ISelection selection) {
+ JpaStructurePage.this.setTreeViewerSelection(selection);
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ this.fireSelectionChanged(this.filterSelection(event.getSelection()));
+ }
+
+ private ISelection filterSelection(ISelection selection) {
+ return (selection instanceof IStructuredSelection) ?
+ JpaStructurePage.this.filterSelection((IStructuredSelection) selection) :
+ TreeSelection.EMPTY;
+ }
+ }
+
+
+ // ********** misc **********
+
+ @Override
+ public Control getControl() {
+ return this.control;
+ }
+
+ @Override
+ public void setFocus() {
+ this.control.setFocus();
+ }
+
+ private void execute(Runnable runnable) {
+ SWTUtil.execute(this.getSite().getShell().getDisplay(), runnable);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.getEditorJpaFile());
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructureView.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructureView.java
new file mode 100644
index 0000000000..e4594034c1
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructureView.java
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.views;
+
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+import org.eclipse.jpt.jpa.ui.selection.JpaEditorManager;
+import org.eclipse.jpt.jpa.ui.selection.JpaViewManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.IPage;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.PageBookView;
+
+/**
+ * The JPA structure view is a page book view that maintains a
+ * {@link JpaStructurePage JPA structure page}
+ * per editor and a default page when the editor does not contain JPA
+ * content.
+ * <p>
+ * See <code>org.eclipse.jpt.jpa.ui/plugin.xml</code>.
+ */
+public class JpaStructureView
+ extends PageBookView
+{
+ /**
+ * The manager is created when the view's control is
+ * {@link #createPartControl(Composite) created}
+ * and disposed, if necessary, when the view is
+ * {@link #dispose() disposed}.
+ */
+ private volatile Manager manager;
+
+
+ public JpaStructureView() {
+ super();
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ this.manager = this.buildManager();
+ super.createPartControl(parent);
+ }
+
+ private Manager buildManager() {
+ return new Manager(this.getPageManager());
+ }
+
+ /**
+ * Go to the singleton in the sky.
+ * <p>
+ * <strong>NB:</strong> This will trigger the creation of the appropriate
+ * page manager if it does not already exist.
+ */
+ private JpaViewManager.PageManager getPageManager() {
+ return (JpaViewManager.PageManager) this.getAdapter(JpaViewManager.PageManager.class);
+ }
+
+ @Override
+ protected IPage createDefaultPage(PageBook book) {
+ DefaultPage page = new DefaultPage();
+ this.initPage(page);
+ page.createControl(book);
+ return page;
+ }
+
+ /**
+ * Start with the currently active editor.
+ */
+ @Override
+ protected IWorkbenchPart getBootstrapPart() {
+ IWorkbenchPage page = this.getSite().getPage();
+ return (page == null) ? null : page.getActiveEditor();
+ }
+
+ /**
+ * Behave the same way as {@link #partActivated(IWorkbenchPart)};
+ * i.e. {@link #isImportant(IWorkbenchPart) check whether the specified
+ * part is an editor} and display the appropriate page if it is.
+ */
+ @Override
+ public void partBroughtToTop(IWorkbenchPart part) {
+ super.partBroughtToTop(part);
+ this.partActivated(part);
+ }
+
+ /**
+ * Display the appropriate page if an editor is
+ * {@link #partActivated(IWorkbenchPart) activated}
+ * or {@link #partBroughtToTop(IWorkbenchPart) brought to the top}.
+ */
+ @Override
+ protected boolean isImportant(IWorkbenchPart part) {
+ return part instanceof IEditorPart;
+ }
+
+ /**
+ * The specified part is an editor (see {@link #isImportant(IWorkbenchPart)}.
+ */
+ @Override
+ protected PageRec doCreatePage(IWorkbenchPart part) {
+ IEditorPart editor = (IEditorPart) part;
+ JpaEditorManager editorManager = this.manager.getEditorManager(editor);
+ if (editorManager == null) {
+ // if there is no editor manager corresponding to the current
+ // editor return null so the default page is displayed
+ return null;
+ }
+ JpaStructurePage page = new JpaStructurePage(this, editorManager);
+ this.initPage(page);
+ page.createControl(this.getPageBook());
+ return new PageRec(editor, page);
+ }
+
+ @Override
+ protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
+ JpaStructurePage page = (JpaStructurePage) pageRecord.page;
+ page.dispose();
+ pageRecord.dispose();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ if (this.manager != null) {
+ this.manager.dispose();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+
+ // ********** JPA view manager **********
+
+ /**
+ * Adapter to the view's page manager.
+ */
+ /* CU private */ class Manager
+ implements JpaViewManager
+ {
+ /**
+ * The manager for the structure view's workbench page.
+ */
+ private final JpaViewManager.PageManager pageManager;
+
+
+ Manager(JpaViewManager.PageManager pageManager) {
+ super();
+ if (pageManager == null) {
+ throw new NullPointerException(); // shouldn't happen...
+ }
+ this.pageManager = pageManager;
+ this.pageManager.addViewManager(this);
+ }
+
+ public IViewPart getView() {
+ return JpaStructureView.this;
+ }
+
+ JpaEditorManager getEditorManager(IEditorPart editor) {
+ return this.pageManager.getEditorManager(editor);
+ }
+
+ void dispose() {
+ this.pageManager.removeViewManager(this);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+ }
+
+
+ // ********** default page **********
+
+ /**
+ * Simply display a message stating the JPA structure is not available.
+ * @see org.eclipse.ui.part.MessagePage
+ */
+ /* CU private */ static class DefaultPage
+ extends Page
+ {
+ private /* virtually final */ Composite composite;
+
+ DefaultPage() {
+ super();
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ // a composite will put some margins around the label
+ this.composite = new Composite(parent, SWT.NULL);
+ this.composite.setLayout(new FillLayout());
+ Label label = new Label(this.composite, SWT.LEFT | SWT.TOP | SWT.WRAP);
+ label.setText(JptUiMessages.JpaStructureView_structureNotAvailable);
+ }
+
+ @Override
+ public Control getControl() {
+ return this.composite;
+ }
+
+ @Override
+ public void setFocus() {
+ this.composite.setFocus();
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructurePage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructurePage.java
deleted file mode 100644
index dffa843989..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructurePage.java
+++ /dev/null
@@ -1,412 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.views.structure;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IStatusLineManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.util.SafeRunnable;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jpt.common.ui.internal.jface.DelegatingTreeContentAndLabelProvider;
-import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
-import org.eclipse.jpt.common.ui.jface.DelegatingContentAndLabelProvider;
-import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent;
-import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent;
-import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JpaProjectManager;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelection;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.part.IPageSite;
-import org.eclipse.ui.part.Page;
-
-public class JpaStructurePage
- extends Page
- implements ISelectionProvider
-{
- private final JpaStructureView jpaStructureView;
-
- JpaFile jpaFile;
-
- private final IFile file;
-
- private JpaProject jpaProject;
-
- private final JpaStructureProvider structureProvider;
-
- private Composite control;
-
- private DelegatingContentAndLabelProvider contentAndLabelProvider;
-
- TreeViewer viewer;
-
- private final ListenerList selectionChangedListenerList;
-
- private final ISelectionChangedListener treeSelectionListener;
-
- private final ISelectionChangedListener treePostSelectionListener;
-
- private final CollectionChangeListener projectsListener;
-
- private final CollectionChangeListener jpaFilesListener;
-
-
- public JpaStructurePage(
- JpaStructureView jpaStructureView, JpaFile jpaFile, JpaStructureProvider structureProvider) {
-
- this.jpaStructureView = jpaStructureView;
- this.jpaFile = jpaFile;
- this.jpaProject = jpaFile.getJpaProject();
- this.file = jpaFile.getFile();
- this.structureProvider = structureProvider;
- this.selectionChangedListenerList = new ListenerList();
- this.treeSelectionListener = new TreeSelectionChangedListener();
- this.treePostSelectionListener = new TreePostSelectionChangedListener();
- this.projectsListener = buildProjectsListener();
- this.jpaFilesListener = buildJpaFilesListener();
- }
-
-
- private CollectionChangeListener buildProjectsListener() {
- return new CollectionChangeListener(){
-
- public void itemsRemoved(CollectionRemoveEvent event) {
- JpaStructurePage.this.projectsRemoved(event);
- }
-
- public void itemsAdded(CollectionAddEvent event) {
- JpaStructurePage.this.projectsAdded(event);
- }
-
- public void collectionCleared(CollectionClearEvent event) {
- JpaStructurePage.this.projectsCleared(event);
- }
-
- public void collectionChanged(CollectionChangeEvent event) {
- JpaStructurePage.this.projectsChanged(event);
- }
- };
- }
-
- @SuppressWarnings("unchecked")
- void projectsRemoved(CollectionRemoveEvent event) {
- for (JpaProject item : (Iterable<JpaProject>) event.getItems()) {
- if (item.getProject() == JpaStructurePage.this.file.getProject()) {
- setJpaProject(null);
- break;
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- void projectsAdded(CollectionAddEvent event) {
- for (JpaProject item : (Iterable<JpaProject>) event.getItems()) {
- if (item.getProject() == JpaStructurePage.this.file.getProject()) {
- setJpaProject(item);
- break;
- }
- }
- }
-
- void projectsCleared(@SuppressWarnings("unused") CollectionClearEvent event) {
- setJpaProject(null);
- }
-
- void projectsChanged(@SuppressWarnings("unused") CollectionChangeEvent event) {
- setJpaProject(JptJpaCorePlugin.getJpaProject(this.file.getProject()));
- }
-
- private CollectionChangeListener buildJpaFilesListener() {
- return new CollectionChangeListener(){
-
- public void itemsRemoved(CollectionRemoveEvent event) {
- JpaStructurePage.this.jpaFilesRemoved(event);
- }
-
- public void itemsAdded(CollectionAddEvent event) {
- JpaStructurePage.this.jpaFilesAdded(event);
- }
-
- public void collectionCleared(CollectionClearEvent event) {
- JpaStructurePage.this.jpaFilesCleared(event);
- }
-
- public void collectionChanged(CollectionChangeEvent event) {
- JpaStructurePage.this.jpaFilesChanged(event);
- }
- };
- }
-
- @SuppressWarnings("unchecked")
- void jpaFilesRemoved(CollectionRemoveEvent event) {
- for (JpaFile item : (Iterable<JpaFile>) event.getItems()) {
- if (item == JpaStructurePage.this.jpaFile) {
- setJpaFile(null);
- break;
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- void jpaFilesAdded(CollectionAddEvent event) {
- for (JpaFile item : (Iterable<JpaFile>) event.getItems()) {
- if (item.getFile() != null && item.getFile().equals(JpaStructurePage.this.file)) {
- setJpaFile(item);
- break;
- }
- }
- }
-
- void jpaFilesCleared(@SuppressWarnings("unused") CollectionClearEvent event) {
- setJpaFile(null);
- }
-
- void jpaFilesChanged(@SuppressWarnings("unused") CollectionChangeEvent event) {
- setJpaFile(this.jpaProject.getJpaFile(this.file));
- }
-
- private void setJpaProject(JpaProject jpaProject) {
- if (this.jpaProject == jpaProject) {
- return;
- }
- if (this.jpaProject != null) {
- this.jpaProject.removeCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, this.jpaFilesListener);
- }
- this.jpaProject = jpaProject;
- if (this.jpaProject != null) {
- this.jpaProject.addCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, this.jpaFilesListener);
- setJpaFile(this.jpaProject.getJpaFile(JpaStructurePage.this.file));
- }
- else {
- setJpaFile(null);
- }
- }
-
- private void setJpaFile(JpaFile jpaFile) {
- if (this.jpaFile == jpaFile) {
- return;
- }
- this.jpaFile = jpaFile;
- SWTUtil.asyncExec(new Runnable(){
- public void run() {
- if (JpaStructurePage.this.viewer.getControl().isDisposed()) {
- return;
- }
- JpaStructurePage.this.viewer.setInput(JpaStructurePage.this.jpaFile);
- }
- });
- }
-
- @Override
- public void init(IPageSite pageSite) {
- super.init(pageSite);
- pageSite.setSelectionProvider(this);
- }
-
- @Override
- public void createControl(Composite parent) {
- control = new Composite(parent, SWT.NULL);
- control.setLayout(new FillLayout());
- viewer = new TreeViewer(control, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- viewer.setAutoExpandLevel(2);
- DelegatingTreeContentAndLabelProvider provider
- = new DelegatingTreeContentAndLabelProvider(
- structureProvider.getTreeItemContentProviderFactory(),
- structureProvider.getItemLabelProviderFactory());
- this.contentAndLabelProvider = provider;
- viewer.setContentProvider(provider);
- // TODO Use problem decorator
- viewer.setLabelProvider(provider);
- this.viewer.setInput(this.jpaFile);
- engageListeners();
- initContextMenu();
- }
-
- protected void engageListeners() {
- this.viewer.addSelectionChangedListener(this.treeSelectionListener);
- this.viewer.addPostSelectionChangedListener(this.treePostSelectionListener);
- this.jpaProject.addCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, this.jpaFilesListener);
- JptJpaCorePlugin.getJpaProjectManager().addCollectionChangeListener(JpaProjectManager.JPA_PROJECTS_COLLECTION, this.projectsListener);
- }
-
- @Override
- public void dispose() {
- disengageListeners();
- super.dispose();
- }
-
- protected void disengageListeners() {
- JptJpaCorePlugin.getJpaProjectManager().removeCollectionChangeListener(JpaProjectManager.JPA_PROJECTS_COLLECTION, this.projectsListener);
- if (this.jpaProject != null) {
- this.jpaProject.removeCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, this.jpaFilesListener);
- }
- this.viewer.removePostSelectionChangedListener(this.treePostSelectionListener);
- this.viewer.removeSelectionChangedListener(this.treeSelectionListener);
- }
-
- protected void initContextMenu() {
- // Create dynamic menu mgr. Dynamic is currently required to
- // support action contributions.
- MenuManager mgr = new MenuManager();
- mgr.setRemoveAllWhenShown(true);
- mgr.addMenuListener(new IMenuListener() {
- public void menuAboutToShow(IMenuManager menuManager) {
- JpaStructurePage.this.fillContextMenu(menuManager);
- }
- });
- Menu menu = mgr.createContextMenu(viewer.getControl());
- viewer.getControl().setMenu(menu);
- this.jpaStructureView.getSite().registerContextMenu(mgr, viewer);
- }
-
- /**
- * Called when the context menu is about to open.
- * Delegates to the action group using the viewer's selection as the action context.
- * @since 2.0
- */
- protected void fillContextMenu(IMenuManager manager) {
- manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- }
-
- @Override
- public Control getControl() {
- return control;
- }
-
- @Override
- public void setFocus() {
- control.setFocus();
- }
-
-
-
- void select(JpaSelection selection) {
- if (selection.isEmpty()) {
- viewer.setSelection(StructuredSelection.EMPTY);
- }
- else {
- viewer.setSelection(new StructuredSelection(selection.getSelectedNode()), true);
- }
- }
-
-
- // **************** ISelectionProvider impl ********************************
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- selectionChangedListenerList.add(listener);
- }
-
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- selectionChangedListenerList.remove(listener);
- }
-
- public ITreeSelection getSelection() {
- return (ITreeSelection) viewer.getSelection();
- }
-
- public JpaSelection getJpaSelection() {
- ITreeSelection viewerSelection = getSelection();
-
- if (viewerSelection.isEmpty() || viewerSelection.size() > 1) {
- return JpaSelection.NULL_SELECTION;
- }
- return new DefaultJpaSelection((JpaStructureNode) viewerSelection.getFirstElement());
- }
-
-
- public void setSelection(ISelection selection) {
- if (viewer != null) {
- viewer.setSelection(selection);
- }
- }
-
- /*
- * relays tree selection event to listeners of this page
- */
- protected void fireSelectionChanged(ISelection selection) {
- // create an event
- final SelectionChangedEvent event =
- new SelectionChangedEvent(this, selection);
-
- // fire the event
- Object[] listeners = selectionChangedListenerList.getListeners();
- for (int i = 0; i < listeners.length; ++i) {
- final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
- SafeRunner.run(
- new SafeRunnable() {
- public void run() {
- l.selectionChanged(event);
- }
- });
- }
- }
-
- protected void updateStatusBar(ISelection selection) {
- IStatusLineManager statusLineManager = getSite().getActionBars().getStatusLineManager();
- if (! (selection instanceof IStructuredSelection) || selection.isEmpty()) {
- statusLineManager.setMessage(""); //$NON-NLS-1$
- return;
- }
- IStructuredSelection sselection = (IStructuredSelection) selection;
- if (sselection.size() > 1) {
- statusLineManager.setMessage(NLS.bind(JptUiMessages.JpaStructureView_numItemsSelected, sselection.size()));
- }
- else {
- Object selObj = sselection.getFirstElement();
- statusLineManager.setMessage(
- this.contentAndLabelProvider.getImage(selObj),
- this.contentAndLabelProvider.getDescription(selObj));
- }
- }
-
-
- class TreeSelectionChangedListener
- implements ISelectionChangedListener
- {
- public void selectionChanged(SelectionChangedEvent event) {
- JpaStructurePage.this.fireSelectionChanged(event.getSelection());
- }
- }
-
-
- class TreePostSelectionChangedListener
- implements ISelectionChangedListener
- {
- public void selectionChanged(SelectionChangedEvent event) {
- JpaStructurePage.this.updateStatusBar(event.getSelection());
- }
- }
-} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructureView.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructureView.java
deleted file mode 100644
index 4fbde058c2..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/structure/JpaStructureView.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.internal.views.structure;
-
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jpt.jpa.core.JpaFile;
-import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
-import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
-import org.eclipse.jpt.jpa.ui.structure.JpaStructureProvider;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.part.IPage;
-import org.eclipse.ui.part.MessagePage;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.ui.part.PageBookView;
-
-public class JpaStructureView
- extends PageBookView
-{
- public JpaStructureView() {
- super();
- }
-
- @Override
- public void createPartControl(Composite parent) {
- super.createPartControl(parent);
-
- JpaSelectionManager selectionManager =
- SelectionManagerFactory.getSelectionManager(this.getViewSite().getWorkbenchWindow());
-
- selectionManager.register(this);
- this.select(selectionManager.getCurrentSelection());
- }
-
- @Override
- public void partBroughtToTop(IWorkbenchPart part) {
- // do same thing as partActivated, which will check to see if the
- // part is an editor, in which case, we want to show the right page
- partActivated(part);
- }
-
- @Override
- protected boolean isImportant(IWorkbenchPart part) {
- return part instanceof IEditorPart;
- }
-
- @Override
- protected IWorkbenchPart getBootstrapPart() {
- IWorkbenchPage page = this.getSite().getPage();
- return (page == null) ? null : page.getActiveEditor();
- }
-
- @Override
- protected IPage createDefaultPage(PageBook book) {
- MessagePage page = new MessagePage();
- this.initPage(page);
- page.createControl(book);
- page.setMessage(JptUiMessages.JpaStructureView_structureNotAvailable);
- return page;
- }
-
- @Override
- protected PageRec doCreatePage(IWorkbenchPart part) {
- // use the platform adapter service so the structure view can be
- // associated with any IEditorPart that has an associated adapter
- // factory that can give us the JPA file associated with the editor part
- // @see org.eclipse.jpt.jpa.ui.internal.EditorPartAdapterFactory
- JpaFile jpaFile = (JpaFile) part.getAdapter(JpaFile.class);
- if (jpaFile == null) {
- return null;
- }
-
- JpaStructureProvider structureProvider = this.getStructureProvider(jpaFile);
- if (structureProvider == null) {
- return null;
- }
-
- JpaStructurePage page = new JpaStructurePage(this, jpaFile, structureProvider);
- this.initPage(page);
- page.createControl(this.getPageBook());
- return new PageRec(part, page);
- }
-
- private JpaStructureProvider getStructureProvider(JpaFile jpaFile) {
- return this.getPlatformUi(jpaFile).getStructureProvider(jpaFile);
- }
-
- private JpaPlatformUi getPlatformUi(JpaFile jpaFile) {
- return JptJpaUiPlugin.instance().getJpaPlatformUi(jpaFile.getJpaProject().getJpaPlatform());
- }
-
- @Override
- protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
- JpaStructurePage page = (JpaStructurePage) pageRecord.page;
- page.dispose();
- pageRecord.dispose();
- }
-
- public JpaSelection getJpaSelection() {
- if (this.getCurrentPage() != this.getDefaultPage()) {
- return ((JpaStructurePage) this.getCurrentPage()).getJpaSelection();
- }
- return JpaSelection.NULL_SELECTION;
- }
-
- public void select(JpaSelection newSelection) {
- // correct page should be shown
- if (this.getCurrentPage() != this.getDefaultPage()) {
- ((JpaStructurePage) this.getCurrentPage()).select(newSelection);
- }
- }
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- this.getSelectionProvider().addSelectionChangedListener(listener);
- }
-
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- this.getSelectionProvider().removeSelectionChangedListener(listener);
- }
-
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java
index 3c2abe3ebb..87a4e07b16 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,6 +14,7 @@ import java.util.EventListener;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
import org.eclipse.jpt.common.utility.internal.ListenerList;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.jpa.core.JpaProject;
@@ -135,7 +136,7 @@ public class DatabaseSchemaWizardPage extends WizardPage {
*/
class DatabaseGroup {
- // these are kept in synch with the selection
+ // these are kept in sync with the selection
private Schema selectedSchema;
private final Combo schemaComboBox;
@@ -351,29 +352,29 @@ public class DatabaseSchemaWizardPage extends WizardPage {
}
private ConnectionListener buildConnectionListener() {
- return new ConnectionAdapter() {
- @Override
- public void opened(ConnectionProfile cp) {
- this.connectionChanged();
- }
- @Override // this probably won't ever get called...
- public void closed(ConnectionProfile cp) {
- this.connectionChanged();
- }
- private void connectionChanged() {
- Display.getDefault().asyncExec(
- new Runnable() {
- public void run() {
- DatabaseGroup.this.connectionChanged();
- }
+ return new LocalConnectionListener();
+ }
+
+ class LocalConnectionListener
+ extends ConnectionAdapter
+ {
+ @Override
+ public void opened(ConnectionProfile cp) {
+ this.connectionChanged();
+ }
+ @Override // this probably won't ever get called...
+ public void closed(ConnectionProfile cp) {
+ this.connectionChanged();
+ }
+ private void connectionChanged() {
+ SWTUtil.asyncExec(
+ new Runnable() {
+ public void run() {
+ DatabaseGroup.this.connectionChanged();
}
- );
- }
- @Override
- public String toString() {
- return "DatabaseSchemaWizardPage connection listener"; //$NON-NLS-1$
- }
- };
+ }
+ );
+ }
}
private SelectionListener buildAddJpaProjectConnectionLinkListener() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
index ffec27442f..d81e9fc4be 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,13 +11,13 @@
package org.eclipse.jpt.jpa.ui.internal.wizards;
import java.util.List;
+import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
@@ -48,7 +48,8 @@ public class JpaMakePersistentWizard extends Wizard {
public void addPages() {
setForcePreviousAndNextButtons(true);
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.selectedTypes.get(0).getResource().getProject());
+ IProject project = this.selectedTypes.get(0).getResource().getProject();
+ JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
this.makePersistentWizardPage = new JpaMakePersistentWizardPage(jpaProject, this.selectedTypes, HELP_CONTEXT_ID);
this.addPage(this.makePersistentWizardPage);
return;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
index a8554fba2b..6c31d5de6f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -146,8 +146,7 @@ public class JpaMakePersistentWizardPage extends WizardPage {
}
protected JpaPlatformUi getJpaPlatformUi() {
- String platformId = this.getJpaProject().getJpaPlatform().getId();
- return JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
+ return (JpaPlatformUi) this.getJpaProject().getJpaPlatform().getAdapter(JpaPlatformUi.class);
}
public void createControl(Composite parent) {
@@ -453,6 +452,7 @@ public class JpaMakePersistentWizardPage extends WizardPage {
PlatformUI.getWorkbench().getHelpSystem().displayHelp( this.helpContextId );
}
+ // TODO use JpaProjectManager.execute(Command, ...)
protected void performFinish() {
boolean modifiedPersistenceXml = false;
for (Type type : this.selectedTypes) {
@@ -512,7 +512,7 @@ public class JpaMakePersistentWizardPage extends WizardPage {
protected void setMappingKey(String mappingKey) {
this.mappingKey = mappingKey;
}
-
+ // TODO modify the context model
protected boolean makePersistent() {
if (JpaMakePersistentWizardPage.this.isAnnotateInJavaModel()) {
PersistenceUnit persistenceUnit = this.getPersistenceUnit();
@@ -524,15 +524,9 @@ public class JpaMakePersistentWizardPage extends WizardPage {
return true;
}
}
- }
- else {
- JpaXmlResource ormXmlResource = getOrmXmlResource();
- final EntityMappings entityMappings = getEntityMappings();
- ormXmlResource.modify(new Runnable() {
- public void run() {
- entityMappings.addPersistentType(Type.this.mappingKey, Type.this.jdtType.getFullyQualifiedName());
- }
- });
+ } else {
+ getEntityMappings().addPersistentType(Type.this.mappingKey, Type.this.jdtType.getFullyQualifiedName());
+ getOrmXmlResource().save();
}
return false;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java
index e5af28977f..58d008be28 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/SelectJpaOrmMappingFileDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -22,7 +22,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
import org.eclipse.jpt.jpa.ui.internal.wizards.orm.MappingFileWizard;
@@ -96,7 +96,7 @@ public class SelectJpaOrmMappingFileDialog extends ElementTreeSelectionDialog
} else {
resourcePath = ((IFile) element).getFullPath();
}
- String runtimePath = JptCommonCorePlugin.getResourceLocator(this.project).getRuntimePath(this.project, resourcePath).toOSString();
+ String runtimePath = this.getProjectResourceLocator().getRuntimePath(resourcePath).toOSString();
return runtimePath.replace(File.separatorChar, '/');
}
@@ -122,8 +122,12 @@ public class SelectJpaOrmMappingFileDialog extends ElementTreeSelectionDialog
//these are disabled if the tree is empty when the dialog is created.
this.messageLabel.setEnabled(true);
this.treeWidget.setEnabled(true);
- IFile file = JptCommonCorePlugin.getPlatformFile(this.project, path);
+ IFile file = this.getProjectResourceLocator().getPlatformFile(path);
getTreeViewer().setSelection(new StructuredSelection(file), true);
}
}
-} \ No newline at end of file
+
+ protected ProjectResourceLocator getProjectResourceLocator() {
+ return (ProjectResourceLocator) this.project.getAdapter(ProjectResourceLocator.class);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityClassWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityClassWizardPage.java
index abb624ad15..07f7983f9b 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityClassWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityClassWizardPage.java
@@ -1,5 +1,5 @@
/***********************************************************************
- * Copyright (c) 2008, 2010 by SAP AG, Walldorf.
+ * Copyright (c) 2008, 2012 by SAP AG, Walldorf and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -140,9 +140,13 @@ public class EntityClassWizardPage
protected JpaProject getTargetJpaProject() {
IProject project = getProject();
- return project != null ? JptJpaCorePlugin.getJpaProject(project) : null;
+ return (project == null) ? null : this.getJpaProject(project);
}
+ protected JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
@Override
protected ISelectionStatusValidator getContainerDialogSelectionValidator() {
return new ISelectionStatusValidator() {
@@ -334,7 +338,7 @@ public class EntityClassWizardPage
if (project == null) {
return;
}
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ JpaProject jpaProject = this.getJpaProject(project);
ViewerFilter filter = getDialogViewerFilter(jpaProject);
ITreeContentProvider contentProvider = new WorkbenchContentProvider();
ILabelProvider labelProvider = new WorkbenchLabelProvider();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityWizard.java
index 9f302520ec..db0dffad25 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityWizard.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/EntityWizard.java
@@ -1,5 +1,5 @@
/***********************************************************************
- * Copyright (c) 2008, 2010 by SAP AG, Walldorf.
+ * Copyright (c) 2008, 2012 by SAP AG, Walldorf and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,15 +11,17 @@
***********************************************************************/
package org.eclipse.jpt.jpa.ui.internal.wizards.entity;
-import static org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.*;
+import static org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.OPEN_IN_EDITOR;
+import static org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.PROJECT;
+import static org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.QUALIFIED_CLASS_NAME;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.context.JpaContextNode;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.JptUiIcons;
@@ -157,19 +159,17 @@ public class EntityWizard
return ((JpaContextNode) selectedObj).getJpaProject().getProject().getName();
}
- if (selectedObj instanceof IAdaptable) {
- IResource resource = (IResource) ((IAdaptable) selectedObj).getAdapter(IResource.class);
- if (resource != null) {
- return resource.getProject().getName();
- }
- IJavaElement javaElement = (IJavaElement) ((IAdaptable) selectedObj).getAdapter(IJavaElement.class);
- if (javaElement != null) {
- return javaElement.getJavaProject().getProject().getName();
- }
- JpaContextNode node = (JpaContextNode) ((IAdaptable) selectedObj).getAdapter(JpaContextNode.class);
- if (node != null) {
- return node.getJpaProject().getProject().getName();
- }
+ IResource resource = PlatformTools.getAdapter(selectedObj, IResource.class);
+ if (resource != null) {
+ return resource.getProject().getName();
+ }
+ IJavaElement javaElement = PlatformTools.getAdapter(selectedObj, IJavaElement.class);
+ if (javaElement != null) {
+ return javaElement.getJavaProject().getProject().getName();
+ }
+ JpaContextNode node = PlatformTools.getAdapter(selectedObj, JpaContextNode.class);
+ if (node != null) {
+ return node.getJpaProject().getProject().getName();
}
return null;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java
index ea1289c18c..30d1304520 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java
@@ -1,5 +1,5 @@
/***********************************************************************
- * Copyright (c) 2008, 2010 by SAP AG, Walldorf.
+ * Copyright (c) 2008, 2012 by SAP AG, Walldorf and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,7 +32,6 @@ import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.wizards.entity.EntityWizardMsg;
@@ -456,12 +455,15 @@ public class EntityDataModelProvider extends NewJavaClassDataModelProvider imple
protected JpaProject getTargetJpaProject() {
IProject project = getTargetProject();
- if (project != null && JpaFacet.isInstalled(project)) {
- return JptJpaCorePlugin.getJpaProject(project);
- }
- return null;
+ return ((project != null) && JpaFacet.isInstalled(project)) ?
+ this.getJpaProject(project) :
+ null;
}
+ protected JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
protected IContainer getJavaSourceContainer() {
String containerFullPath = getStringProperty(SOURCE_FOLDER);
JpaProject jpaProject = getTargetJpaProject();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
index f734428923..a17ac000da 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java
@@ -1,16 +1,17 @@
-/***********************************************************************
- * Copyright (c) 2008, 2012 by SAP AG, Walldorf.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+/*******************************************************************************
+ * Copyright (c) 2008, 2012 SAP AG, Walldorf and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* SAP AG - initial API and implementation
* Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation
+ * Oracle - additional maintenance
***********************************************************************/
package org.eclipse.jpt.jpa.ui.internal.wizards.entity.data.operation;
+import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
@@ -21,6 +22,9 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IAdaptable;
@@ -40,22 +44,20 @@ import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
+import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.Entity;
import org.eclipse.jpt.jpa.core.context.InheritanceType;
-import org.eclipse.jpt.jpa.core.context.MappedSuperclass;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
+import org.eclipse.jpt.jpa.core.context.orm.OrmIdTypeMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory;
import org.eclipse.jpt.jpa.core.resource.persistence.XmlJavaClassRef;
@@ -97,6 +99,7 @@ import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
*
* The use of this class is EXPERIMENTAL and is subject to substantial changes.
*/
+// TODO use JpaProjectManager.execute(Command...) and modify the context model
public class NewEntityClassOperation extends AbstractDataModelOperation {
private static final String DOT_JAVA = ".java"; //$NON-NLS-1$
@@ -258,18 +261,32 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
}
}
- if (!tempModel.isArtifactsAnnotated()) {
- if (tempModel.isNonEntitySuperclass()) {
- addMappedSuperclassToXML(tempModel, project).schedule();
- } else {
- addEntityToXML(tempModel, project).schedule();
- }
- }
- if (tempModel.isArtifactsAnnotated() && !JptJpaCorePlugin.discoverAnnotatedClasses(project)) {
- registerClassInPersistenceXml(tempModel, project).schedule();
+ if (tempModel.isArtifactsAnnotated()) {
+ if ( ! JptJpaCorePlugin.discoverAnnotatedClasses(project)) {
+ registerClassInPersistenceXml(tempModel, project).schedule();
+ }
+ } else {
+ Command command = tempModel.isNonEntitySuperclass() ?
+ new AddTypeMappingToXMLCommand(tempModel, project, MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY) :
+ new AddEntityToXMLCommand(tempModel, project);
+ this.run(new DaliRunnable(project.getWorkspace(), command));
}
}
+ private void run(IWorkspaceRunnable runnable) {
+ IWorkspace ws = ResourcesPlugin.getWorkspace();
+ try {
+ ws.run(
+ runnable,
+ ws.getRuleFactory().modifyRule(ws.getRoot()),
+ IWorkspace.AVOID_UPDATE,
+ null // no monitor
+ );
+ } catch (CoreException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
/**
* This method is intended for internal use only. This method will create an
* instance of the CreateEntityTemplateModel model to be used in conjunction
@@ -383,172 +400,134 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
return ProjectUtilities.getProject(projectName);
}
- /**
- * Adds entity to ORM XML in separate job
- *
- * Set the jpaProject synchronizers to synchronous so that the model
- * has a chance to fully update before we attempt to set things on it. (bug 348143)
- *
- * @param model entity data model
- * @param project JPA project in which the entity will be created
- * @return
- */
- private Job addEntityToXML(final CreateEntityTemplateModel model, final IProject project) {
- Job job = new Job(EntityWizardMsg.ADD_ENTITY_TO_XML) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- JpaProject jpaProject = getJpaProject();
- Synchronizer contextModelSynchronizer = jpaProject.getContextModelSynchronizer();
- CallbackSynchronizer updateSynchronizer = jpaProject.getUpdateSynchronizer();
- jpaProject.setContextModelSynchronizer(buildSynchronousContextModelSynchronizer());
- jpaProject.setUpdateSynchronizer(buildSynchronousUpdateSynchronizer());
- try {
- final JpaXmlResource xmlResource = getOrmXmlResource(model, project);
- EntityMappings entityMappings = (EntityMappings) JptJpaCorePlugin.getJpaProject(project).getJpaFile(xmlResource.getFile()).getRootStructureNodes().iterator().next();
- OrmPersistentType persistentType = entityMappings.addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, model.getQualifiedJavaClassName());
- Entity entity = (Entity) persistentType.getMapping();
- if (model.isInheritanceSet()) {
- entity.setSpecifiedInheritanceStrategy(getModelInheritanceType(model));
- }
-
- if (model.isEntityNameSet()) {
- entity.setSpecifiedName(model.getEntityName());
- }
- if (model.isTableNameSet()) {
- entity.getTable().setSpecifiedName(model.getTableName());
- }
- if (model.isCompositePK()) {
- entity.getIdClassReference().setSpecifiedIdClassName(model.getOrmIdClassName());
- }
- for (String fieldName : model.getPKFields()) {
- persistentType.getAttributeNamed(fieldName).convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
- }
-
- persistentType.setSpecifiedAccess(getModelAccessType(model));
-
- try {
- xmlResource.saveIfNecessary();
- }
- catch (Exception e) {
- JptJpaUiPlugin.log(e);
- }
- return Status.OK_STATUS;
- } finally {
- jpaProject.setContextModelSynchronizer(contextModelSynchronizer);
- jpaProject.setUpdateSynchronizer(updateSynchronizer);
- }
- }
- };
- return job;
- }
- protected JpaXmlResource getOrmXmlResource(CreateEntityTemplateModel model, IProject project) {
- if (model.isMappingXMLDefault()) {
- return JptJpaCorePlugin.getJpaProject(project).getDefaultOrmXmlResource();
+ protected static class DaliRunnable
+ implements IWorkspaceRunnable
+ {
+ protected final IWorkspace workspace;
+ protected final Command command;
+
+ DaliRunnable(IWorkspace workspace, Command command) {
+ super();
+ this.workspace = workspace;
+ this.command = command;
}
- return JptJpaCorePlugin.getJpaProject(project).getMappingFileXmlResource(new Path(model.getMappingXMLName()));
- }
-
- /**
- * Adds mapped superclass to ORM XML in separate job
- *
- * Set the jpaProject synchronizers to synchronous so that the model
- * has a chance to fully update before we attempt to set things on it. (bug 348143)
- *
- * @param model entity data model
- * @param project JPA project in which the entity will be created
- * @return the created job
- */
- private Job addMappedSuperclassToXML(final CreateEntityTemplateModel model, final IProject project) {
- Job job = new Job(EntityWizardMsg.ADD_MAPPED_SUPERCLASS_TO_XML) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- JpaProject jpaProject = getJpaProject();
- Synchronizer contextModelSynchronizer = jpaProject.getContextModelSynchronizer();
- CallbackSynchronizer updateSynchronizer = jpaProject.getUpdateSynchronizer();
- jpaProject.setContextModelSynchronizer(buildSynchronousContextModelSynchronizer());
- jpaProject.setUpdateSynchronizer(buildSynchronousUpdateSynchronizer());
- try {
- final JpaXmlResource xmlResource = getOrmXmlResource(model, project);
- EntityMappings entityMappings = (EntityMappings) JptJpaCorePlugin.getJpaProject(project).getJpaFile(xmlResource.getFile()).getRootStructureNodes().iterator().next();
- OrmPersistentType persistentType = entityMappings.addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, model.getQualifiedJavaClassName());
- MappedSuperclass mappedSuperclass = (MappedSuperclass) persistentType.getMapping();
-
- if (model.isCompositePK()) {
- mappedSuperclass.getIdClassReference().setSpecifiedIdClassName(model.getOrmIdClassName());
- }
-
- for (String fieldName : model.getPKFields()) {
- persistentType.getAttributeNamed(fieldName).convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
- }
-
- persistentType.setSpecifiedAccess(getModelAccessType(model));
-
- try {
- xmlResource.saveIfNecessary();
- }
- catch (Exception e) {
- JptJpaUiPlugin.log(e);
- }
- return Status.OK_STATUS;
- } finally {
- jpaProject.setContextModelSynchronizer(contextModelSynchronizer);
- jpaProject.setUpdateSynchronizer(updateSynchronizer);
- }
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ try {
+ this.run();
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
}
- };
- return job;
- }
+ }
- protected Synchronizer buildSynchronousContextModelSynchronizer() {
- return new SynchronousSynchronizer(this.buildSynchronousContextModelSynchronizerCommand());
- }
+ protected void run() throws InterruptedException {
+ this.getJpaProjectManager().execute(this.command, SynchronousUiCommandExecutor.instance());
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) this.workspace.getAdapter(JpaProjectManager.class);
+ }
- protected Command buildSynchronousContextModelSynchronizerCommand() {
- return new SynchronousContextModelSynchronizerCommand();
}
- protected class SynchronousContextModelSynchronizerCommand implements Command {
+
+ protected static class AddTypeMappingToXMLCommand
+ implements Command
+ {
+ protected final CreateEntityTemplateModel model;
+ protected final IProject project;
+ protected final String typeMappingKey;
+
+ protected AddTypeMappingToXMLCommand(CreateEntityTemplateModel model, IProject project, String typeMappingKey) {
+ super();
+ this.model = model;
+ this.project = project;
+ this.typeMappingKey = typeMappingKey;
+ }
+
public void execute() {
- getJpaProject().synchronizeContextModel(new NullProgressMonitor());
+ JpaXmlResource xmlResource = this.getOrmXmlResource();
+ EntityMappings entityMappings = (EntityMappings) this.getJpaProject().getJpaFile(xmlResource.getFile()).getRootStructureNodes().iterator().next();
+ OrmPersistentType persistentType = entityMappings.addPersistentType(this.typeMappingKey, this.model.getQualifiedJavaClassName());
+
+ this.updatePersistentType(persistentType);
+
+ try {
+ xmlResource.saveIfNecessary();
+ } catch (Exception e) {
+ JptJpaUiPlugin.log(e);
+ }
}
- }
- protected CallbackSynchronizer buildSynchronousUpdateSynchronizer() {
- return new CallbackSynchronousSynchronizer(this.buildSynchronousUpdateSynchronizerCommand());
- }
+ protected void updatePersistentType(OrmPersistentType persistentType) {
+ this.updateTypeMapping(persistentType.getMapping());
- protected Command buildSynchronousUpdateSynchronizerCommand() {
- return new SynchronousUpdateSynchronizerCommand();
- }
+ for (String fieldName : this.model.getPKFields()) {
+ persistentType.getAttributeNamed(fieldName).convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ }
- protected class SynchronousUpdateSynchronizerCommand implements Command {
- public void execute() {
- getJpaProject().update(new NullProgressMonitor());
+ persistentType.setSpecifiedAccess(this.getModelAccessType());
}
- }
- protected JpaProject getJpaProject() {
- IProject project = getTargetProject();
- return JptJpaCorePlugin.getJpaProject(project);
- }
-
- protected AccessType getModelAccessType(CreateEntityTemplateModel model) {
- String accessTypeString = FIELD;
- if (!model.isFieldAccess()) {
- accessTypeString = PROPERTY;
+ protected void updateTypeMapping(OrmTypeMapping typeMapping) {
+ if (this.model.isCompositePK()) {
+ ((OrmIdTypeMapping) typeMapping).getIdClassReference().setSpecifiedIdClassName(this.model.getOrmIdClassName());
+ }
+ }
+
+ protected JpaXmlResource getOrmXmlResource() {
+ return this.model.isMappingXMLDefault() ?
+ this.getJpaProject().getDefaultOrmXmlResource() :
+ this.getJpaProject().getMappingFileXmlResource(new Path(this.model.getMappingXMLName()));
+ }
+
+ protected AccessType getModelAccessType() {
+ String accessTypeString = FIELD;
+ if ( ! this.model.isFieldAccess()) {
+ accessTypeString = PROPERTY;
+ }
+ return AccessType.fromOrmResourceModel(accessTypeString, getJpaProject().getJpaPlatform(), JptCommonCorePlugin.JAVA_SOURCE_RESOURCE_TYPE);// TODO
+ }
+
+ protected JpaProject getJpaProject() {
+ return (JpaProject) this.project.getAdapter(JpaProject.class);
}
- return AccessType.fromOrmResourceModel(accessTypeString, getJpaProject().getJpaPlatform(), JptCommonCorePlugin.JAVA_SOURCE_RESOURCE_TYPE);// TODO
}
- protected InheritanceType getModelInheritanceType(CreateEntityTemplateModel model) {
- String inheritanceStrategy = model.getInheritanceStrategyName();
- if (inheritanceStrategy.equals(EMPTY_STRING)) {
- inheritanceStrategy = SINGLE_TABLE;
+
+ protected static class AddEntityToXMLCommand
+ extends AddTypeMappingToXMLCommand
+ {
+ protected AddEntityToXMLCommand(CreateEntityTemplateModel model, IProject project) {
+ super(model, project, MappingKeys.ENTITY_TYPE_MAPPING_KEY);
+ }
+
+ @Override
+ protected void updateTypeMapping(OrmTypeMapping typeMapping) {
+ super.updateTypeMapping(typeMapping);
+ Entity entity = (Entity) typeMapping;
+ if (this.model.isInheritanceSet()) {
+ entity.setSpecifiedInheritanceStrategy(this.getModelInheritanceType());
+ }
+ if (this.model.isEntityNameSet()) {
+ entity.setSpecifiedName(this.model.getEntityName());
+ }
+ if (this.model.isTableNameSet()) {
+ entity.getTable().setSpecifiedName(this.model.getTableName());
+ }
+ }
+
+ protected InheritanceType getModelInheritanceType() {
+ String strategy = this.model.getInheritanceStrategyName();
+ if (strategy.equals(EMPTY_STRING)) {
+ strategy = SINGLE_TABLE;
+ }
+ return InheritanceType.fromOrmResourceModel(OrmFactory.eINSTANCE.createInheritanceTypeFromString(null, strategy));//TODO
}
- return InheritanceType.fromOrmResourceModel(OrmFactory.eINSTANCE.createInheritanceTypeFromString(null, inheritanceStrategy));//TODO
}
+
/**
* Regist the class in the persistence.xml
*
@@ -560,27 +539,23 @@ public class NewEntityClassOperation extends AbstractDataModelOperation {
Job job = new Job(EntityWizardMsg.APPLY_CHANGES_TO_PERSISTENCE_XML) {
@Override
protected IStatus run(IProgressMonitor monitor) {
- final JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(project);
- final JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
- resource.modify(new Runnable() {
- public void run() {
- XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
- EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
- XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0);// Multiply persistence unit support
-
- if (!model.isNonEntitySuperclass()) {
- XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
- classRef.setJavaClass(model.getQualifiedJavaClassName());
- persistenceUnit.getClasses().add(classRef);
- }
- }
- });
+ JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
+ JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
+ XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
+ EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
+ XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0);// Multiply persistence unit support
+
+ if (!model.isNonEntitySuperclass()) {
+ XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
+ classRef.setJavaClass(model.getQualifiedJavaClassName());
+ persistenceUnit.getClasses().add(classRef);
+ }
+ resource.save();
return Status.OK_STATUS;
}
};
return job;
-
}
/**
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java
index 61de9be2e9..df49880c86 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -17,7 +17,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.SortedSet;
-
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ResourceManager;
@@ -46,7 +45,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
/**
@@ -61,7 +59,7 @@ public class DatabaseGroup
private final JpaProject jpaProject;
private final Set<Listener> listeners = Collections.synchronizedSet(new HashSet<Listener>());
- // these are kept in synch with the selection
+ // these are kept in sync with the selection
private ConnectionProfile selectedConnectionProfile;
private Schema selectedSchema;
@@ -367,7 +365,7 @@ public class DatabaseGroup
* - the connection was closed (never happens?)
* we need to update the schema stuff and the reconnect link
*/
- private void connectionChanged() {
+ /* CU private */ void connectionChanged() {
Schema old = this.selectedSchema;
this.selectedSchema = this.getDefaultSchema();
if(this.selectedSchema != old) {
@@ -439,29 +437,29 @@ public class DatabaseGroup
}
private ConnectionListener buildConnectionListener() {
- return new ConnectionAdapter() {
- @Override
- public void opened(ConnectionProfile cp) {
- this.connectionChanged();
- }
- @Override // this probably won't ever get called...
- public void closed(ConnectionProfile cp) {
- this.connectionChanged();
- }
- private void connectionChanged() {
- Display.getDefault().asyncExec(
- new Runnable() {
- public void run() {
- DatabaseGroup.this.connectionChanged();
- }
+ return new LocalConnectionListener();
+ }
+
+ class LocalConnectionListener
+ extends ConnectionAdapter
+ {
+ @Override
+ public void opened(ConnectionProfile cp) {
+ this.connectionChanged();
+ }
+ @Override // this probably won't ever get called...
+ public void closed(ConnectionProfile cp) {
+ this.connectionChanged();
+ }
+ private void connectionChanged() {
+ org.eclipse.jpt.common.ui.internal.util.SWTUtil.asyncExec(
+ new Runnable() {
+ public void run() {
+ DatabaseGroup.this.connectionChanged();
}
- );
- }
- @Override
- public String toString() {
- return "DatabaseConnectionWizardPage connection listener"; //$NON-NLS-1$
- }
- };
+ }
+ );
+ }
}
// ********** listeners **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
index 231b9c74af..8936b10f1c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/GenerateEntitiesFromSchemaWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,6 @@ package org.eclipse.jpt.jpa.ui.internal.wizards.gen;
import java.io.File;
import java.io.IOException;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceRuleFactory;
@@ -21,7 +20,6 @@ import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -35,11 +33,11 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jpt.common.core.internal.utility.JDTTools;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.ui.internal.dialogs.OptionalMessageDialog;
import org.eclipse.jpt.jpa.core.EntityGeneratorDatabaseAnnotationNameBuilder;
import org.eclipse.jpt.jpa.core.JpaPlatform;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.db.Column;
import org.eclipse.jpt.jpa.db.ConnectionProfile;
import org.eclipse.jpt.jpa.db.ForeignKey;
@@ -153,8 +151,8 @@ public class GenerateEntitiesFromSchemaWizard extends Wizard
*/
public ORMGenCustomizer createORMGenCustomizer(Schema schema){
JpaPlatform jpaPlatform = this.jpaProject.getJpaPlatform();
- Object obj = Platform.getAdapterManager().getAdapter( jpaPlatform, ORMGenCustomizer.class );
- if (obj != null && obj instanceof ORMGenCustomizer) {
+ ORMGenCustomizer obj = PlatformTools.getAdapter( jpaPlatform, ORMGenCustomizer.class );
+ if (obj != null) {
this.customizer = (ORMGenCustomizer) obj;
this.customizer.init(getCustomizationFile(), schema);
} else{
@@ -266,7 +264,7 @@ public class GenerateEntitiesFromSchemaWizard extends Wizard
private boolean promptUser(final String className) {
// get on the UI thread synchronously, need feedback before continuing
final boolean ret[]=new boolean[1];
- Display.getDefault().syncExec(new Runnable() {
+ org.eclipse.jpt.common.ui.internal.util.SWTUtil.syncExec(new Runnable() {
public void run() {
final OverwriteConfirmerDialog dialog = new OverwriteConfirmerDialog(Display.getCurrent().getActiveShell(), className);
dialog.open();
@@ -469,17 +467,17 @@ public class GenerateEntitiesFromSchemaWizard extends Wizard
Object sel = selection.getFirstElement();
if ( sel instanceof IResource ) {
IProject proj = ((IResource) sel).getProject();
- JpaProject jpaProj = JptJpaCorePlugin.getJpaProject(proj);
+ JpaProject jpaProj = this.getJpaProject(proj);
this.jpaProject = jpaProj;
} else if( sel instanceof org.eclipse.jdt.core.IPackageFragmentRoot ) {
org.eclipse.jdt.core.IPackageFragmentRoot root = (org.eclipse.jdt.core.IPackageFragmentRoot) sel;
IProject proj = root.getJavaProject().getProject();
- JpaProject jpaProj = JptJpaCorePlugin.getJpaProject(proj);
+ JpaProject jpaProj = this.getJpaProject(proj);
this.jpaProject = jpaProj;
} else if( sel instanceof org.eclipse.jdt.core.IPackageFragment) {
org.eclipse.jdt.core.IPackageFragment frag = (org.eclipse.jdt.core.IPackageFragment) sel;
IProject proj = frag.getJavaProject().getProject();
- JpaProject jpaProj = JptJpaCorePlugin.getJpaProject(proj);
+ JpaProject jpaProj = this.getJpaProject(proj);
this.jpaProject = jpaProj;
}
@@ -487,6 +485,10 @@ public class GenerateEntitiesFromSchemaWizard extends Wizard
this.setWindowTitle(JptUiEntityGenMessages.GenerateEntitiesWizard_generateEntities);
}
+ protected JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
@Override
public void dispose() {
this.resourceManager.dispose();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
index ef248f04ea..689a670163 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/PromptJPAProjectWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,13 +7,11 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-
package org.eclipse.jpt.jpa.ui.internal.wizards.gen;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -23,7 +21,7 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -89,7 +87,7 @@ public class PromptJPAProjectWizardPage extends WizardPage {
TableItem item = projTable.getItem(projTable.getSelectionIndex());
String projName = item.getText(0);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
- JpaProject jpaProj = JptJpaCorePlugin.getJpaProject( project );
+ JpaProject jpaProj = this.getJpaProject( project );
((GenerateEntitiesFromSchemaWizard)getWizard()).setJpaProject(jpaProj);
validate();
}
@@ -100,7 +98,7 @@ public class PromptJPAProjectWizardPage extends WizardPage {
List<String> projNames = new ArrayList<String>();
for ( IProject project : projects )
{
- JpaProject jpaProj = JptJpaCorePlugin.getJpaProject( project );
+ JpaProject jpaProj = this.getJpaProject( project );
if ( jpaProj != null ) {
projNames.add(project.getName());
}
@@ -108,6 +106,10 @@ public class PromptJPAProjectWizardPage extends WizardPage {
projTableViewer.setInput(projNames);
}
+ private JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
private void validate() {
if (projTable.getSelectionIndex() != -1)
setPageComplete(true);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java
index 8d9741d8e7..3a86ee2918 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -608,7 +608,7 @@ class TablesSelectorWizardPage extends WizardPage {
@Override
public void done(final IJobChangeEvent event) {
- Display.getDefault().asyncExec(new Runnable() {
+ SWTUtil.asyncExec(new Runnable() {
public void run() {
updateTablesListViewer(tables);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/orm/MappingFileWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/orm/MappingFileWizard.java
index 4530efed86..26d28dd9be 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/orm/MappingFileWizard.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/orm/MappingFileWizard.java
@@ -1,29 +1,30 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle.
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Oracle - initial API and implementation
- *******************************************************************************/
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.wizards.orm;
-import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.*;
-import static org.eclipse.jpt.jpa.core.internal.operations.OrmFileCreationDataModelProperties.*;
+import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.CONTAINER_PATH;
+import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.FILE_NAME;
+import static org.eclipse.jpt.jpa.core.internal.operations.OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT;
+import static org.eclipse.jpt.jpa.core.internal.operations.OrmFileCreationDataModelProperties.PERSISTENCE_UNIT;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -31,8 +32,8 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
+import org.eclipse.jpt.common.core.resource.ProjectResourceLocator;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.context.JpaContextNode;
@@ -112,35 +113,42 @@ public class MappingFileWizard extends Wizard
if (selection instanceof JpaContextNode) {
// may be null if node is above level of persistence unit, but in those cases
// null is the expected result
- try {
- return ((JpaContextNode) selection).getPersistenceUnit();
- }
- catch (Exception e) { /* do nothing, just continue */ }
+ return ((JpaContextNode) selection).getPersistenceUnit();
}
-
- if (selection instanceof IAdaptable) {
- JpaContextNode node = (JpaContextNode) ((IAdaptable) selection).getAdapter(JpaContextNode.class);
- if (node != null) {
- return node.getPersistenceUnit();
- }
- }
-
- //also get the persistence unit for a given jpa project selection
- if (selection instanceof IAdaptable) {
- JpaProject jpaProject = (JpaProject) ((IAdaptable) selection).getAdapter(JpaProject.class);
- if (jpaProject != null) {
- PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
- if (persistenceXml != null){
- Persistence persistence = persistenceXml.getPersistence();
- if (persistence != null && persistence.getPersistenceUnitsSize() > 0) {
- return persistence.getPersistenceUnits().iterator().next();
- }
+
+ // also get the persistence unit for a given jpa project selection
+ JpaProject jpaProject = this.getJpaProject(selection);
+ if (jpaProject != null) {
+ PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
+ if (persistenceXml != null){
+ Persistence persistence = persistenceXml.getPersistence();
+ if ((persistence != null) && (persistence.getPersistenceUnitsSize() > 0)) {
+ return persistence.getPersistenceUnit(0);
}
}
}
return null;
}
+ private JpaProject getJpaProject(Object selection) {
+ IProject project = this.getProject(selection);
+ return (project == null) ? null : this.getJpaProject(project);
+ }
+
+ private IProject getProject(Object selection) {
+ if (selection instanceof IJavaProject) {
+ return ((IJavaProject) selection).getProject();
+ }
+ if (selection instanceof IProject) {
+ return (IProject) selection;
+ }
+ return null;
+ }
+
+ private JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
private IContainer extractContainer(PersistenceUnit pUnit, Object selection) {
if (pUnit != null) {
return pUnit.getResource().getParent();
@@ -155,27 +163,26 @@ public class MappingFileWizard extends Wizard
return getDefaultContainer(((JpaContextNode) selection).getJpaProject().getProject());
}
- if (selection instanceof IAdaptable) {
- IResource resource = (IResource) ((IAdaptable) selection).getAdapter(IResource.class);
- if (resource != null) {
- if (resource instanceof IProject) {
- return getDefaultContainer((IProject) resource);
- }
- else if (resource instanceof IContainer) {
- return (IContainer) resource;
- }
+ IResource resource = PlatformTools.getAdapter(selection, IResource.class);
+ if (resource != null) {
+ if (resource instanceof IProject) {
+ return getDefaultContainer((IProject) resource);
}
- JpaContextNode node = (JpaContextNode) ((IAdaptable) selection).getAdapter(JpaContextNode.class);
- if (node != null) {
- return getDefaultContainer(node.getJpaProject().getProject());
+ if (resource instanceof IContainer) {
+ return (IContainer) resource;
}
}
+ JpaContextNode node = PlatformTools.getAdapter(selection, JpaContextNode.class);
+ if (node != null) {
+ return getDefaultContainer(node.getJpaProject().getProject());
+ }
return null;
}
private IContainer getDefaultContainer(IProject project) {
if (JpaFacet.isInstalled(project)) {
- return JptCommonCorePlugin.getResourceLocator(project).getDefaultResourceLocation(project);
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ return locator.getDefaultResourceLocation();
}
return project;
}
@@ -349,7 +356,8 @@ public class MappingFileWizard extends Wizard
IContainer container = PlatformTools.getContainer(containerPath);
IPath filePath = container.getFullPath().append(fileName);
IProject project = container.getProject();
- IPath runtimePath = JptCommonCorePlugin.getResourceLocator(project).getRuntimePath(project, filePath);
+ ProjectResourceLocator locator = (ProjectResourceLocator) project.getAdapter(ProjectResourceLocator.class);
+ IPath runtimePath = locator.getRuntimePath(filePath);
return runtimePath;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/navigator/JpaNavigatorProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/navigator/JpaNavigatorProvider.java
deleted file mode 100644
index b221d6f1dd..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/navigator/JpaNavigatorProvider.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.navigator;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-
-/**
- * This provider is responsible to create the Project Navigator view contents and
- * labels for a given JPA project.
- *
- * @version 2.0
- * @since 2.0
- *
- * Provisional API: This interface is part of an interim API that is still
- * under development and expected to change significantly before reaching
- * stability. It is available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- */
-public interface JpaNavigatorProvider
-{
- /**
- * Build an factory to create {@link TreeItemContentProvider}s
- */
- TreeItemContentProviderFactory getTreeItemContentProviderFactory();
-
- /**
- * Build a factory to create {@link ItemLabelProvider}s
- */
- ItemLabelProviderFactory getItemLabelProviderFactory();
-
- void dispose();
-}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaEditorManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaEditorManager.java
new file mode 100644
index 0000000000..ed71bdd6ae
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaEditorManager.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.selection;
+
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * JPA manager implemented for any editor that can affect a page's
+ * JPA file and/or selection.
+ */
+public interface JpaEditorManager {
+ /**
+ * Return the manager's editor.
+ */
+ IEditorPart getEditor();
+
+ /**
+ * Return the manager's JPA file model.
+ * This can be monitored by the corresponding view managers.
+ */
+ PropertyValueModel<JpaFile> getJpaFileModel();
+
+ /**
+ * Return the manager's JPA selection model.
+ * This can be monitored and changed by the corresponding view managers.
+ */
+ WritablePropertyValueModel<JpaStructureNode> getJpaSelectionModel();
+
+ /**
+ * Dispose the manager. Remove any listeners from the manager's editor
+ * and the JPA selection model and JPA file model.
+ */
+ void dispose();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaSelectionManager.java
new file mode 100644
index 0000000000..8d1179f87a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaSelectionManager.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.selection;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+
+/**
+ * Each {@link org.eclipse.ui.IWorkbench workbench}
+ * and {@link org.eclipse.ui.IWorkbenchWindow workbench window} has a corresponding
+ * {@link JpaSelectionManager JPA selection manager}
+ * that can be used to set the JPA selection in that workbench or window.
+ * <p>
+ * To access a workbench's JPA selection manager:
+ * <pre>
+ * JpaStructureNode structureNode = ...;
+ * IWorkbenchWindow window = ...;
+ * IWorkbench workbench = window.getWorkbench();
+ * // even though IWorkbench extends IAdaptable, it does not delegate to the
+ * // Platform adapter manager; so registered adapter factories are *not* used... :-(
+ * // JpaSelectionManager selectionManager = (JpaSelectionManager) workbench.getAdapter(JpaSelectionManager.class);
+ * JpaSelectionManager selectionManager = PlatformTools.getAdapter(workbench, JpaSelectionManager.class);
+ * selectionManager.setSelection(structureNode);
+ * </pre>
+ * <p>
+ * To access a workbench window's JPA selection manager:
+ * <pre>
+ * JpaStructureNode structureNode = ...;
+ * IWorkbenchWindow window = ...;
+ * // IWorkbenchWindow does not extend IAdaptable(!)
+ * JpaSelectionManager selectionManager = PlatformTools.getAdapter(window, JpaSelectionManager.class);
+ * selectionManager.setSelection(structureNode);
+ * </pre>
+ *
+ * @see org.eclipse.jpt.jpa.ui.internal.selection.WorkbenchAdapterFactory
+ * @see org.eclipse.jpt.jpa.ui.internal.selection.WorkbenchWindowAdapterFactory
+ * @see org.eclipse.jpt.jpa.ui.internal.selection.JpaWorkbenchManager
+ */
+public interface JpaSelectionManager {
+ /**
+ * Set the JPA selection for the selection manager's subject.
+ */
+ public void setSelection(JpaStructureNode selection);
+
+
+ /**
+ * A "null" JPA selection manager does nothing.
+ */
+ final class Null
+ implements JpaSelectionManager, Serializable
+ {
+ public static final JpaSelectionManager INSTANCE = new Null();
+ public static JpaSelectionManager instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Null() {
+ super();
+ }
+ public void setSelection(JpaStructureNode selection) {
+ // do nothing
+ }
+ @Override
+ public String toString() {
+ return StringTools.buildSingletonToString(this);
+ }
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaViewManager.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaViewManager.java
new file mode 100644
index 0000000000..6d3fb383f4
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/selection/JpaViewManager.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.selection;
+
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IViewPart;
+
+/**
+ * JPA view manager implemented for any view that can affect a page's
+ * JPA selection.
+ * <p>
+ * Implementations are to be created by their corresponding views when the
+ * views are created and {@link PageManager#addViewManager(JpaViewManager) added
+ * to the page manager} if the view is to participate in the JPA selection
+ * framework.
+ * <p>
+ * To retrieve the appropriate JPA page manager for a JPA view:
+ * <pre>
+ * IViewPart view = ...;
+ * PageManager pageManager = (PageManager) view.getAdapter(PageManager.class);
+ * </pre>
+ * @see org.eclipse.jpt.jpa.ui.internal.selection.ViewPartAdapterFactory
+ */
+public interface JpaViewManager {
+ /**
+ * Return the manager's view.
+ */
+ IViewPart getView();
+
+
+ // ********** page manager **********
+
+ /**
+ * A view manager's parent page manager.
+ */
+ interface PageManager {
+ /**
+ * Add the specified view manager to the page manager. Each view
+ * manager must add itself to its page manager upon the construction
+ * of its view.
+ */
+ void addViewManager(JpaViewManager viewManager);
+
+ /**
+ * Remove the specified view manager from the page manager.
+ * Each view manager must remove itself from its page manager upon
+ * disposal of its view.
+ */
+ void removeViewManager(JpaViewManager viewManager);
+
+ /**
+ * Return the JPA editor manager for the specified editor.
+ * Return <code>null</code> if the specified editor does not have a
+ * corresponding manager.
+ * This method can be used by a view manager whose view maintains state
+ * for each editor (e.g. an "outline"-type view usually maintains a
+ * separate tree for each editor page, so the trees' states do not
+ * change as different editor pages are brought to the top of the editor
+ * page book).
+ *
+ * @see #getJpaFileModel()
+ * @see #getJpaSelectionModel()
+ */
+ JpaEditorManager getEditorManager(IEditorPart editor);
+
+ /**
+ * Return the manager's JPA file model.
+ * This can be monitored by the corresponding view managers.
+ * This method can used by a view manager whose view maintains state
+ * only for the current editor page.
+ *
+ * @see #getJpaSelectionModel()
+ * @see #getEditorManager(IEditorPart)
+ */
+ PropertyValueModel<JpaFile> getJpaFileModel();
+
+ /**
+ * Return the manager's JPA selection model.
+ * This can be monitored and changed by the corresponding view managers.
+ * This method can used by a view manager whose view maintains state
+ * only for the current editor page.
+ *
+ * @see #getJpaFileModel()
+ * @see #getEditorManager(IEditorPart)
+ */
+ WritablePropertyValueModel<JpaStructureNode> getJpaSelectionModel();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/structure/JpaStructureProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/structure/JpaStructureProvider.java
deleted file mode 100644
index 5b6579d22b..0000000000
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/structure/JpaStructureProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.jpa.ui.structure;
-
-import org.eclipse.jpt.common.ui.jface.ItemLabelProvider;
-import org.eclipse.jpt.common.ui.jface.ItemLabelProviderFactory;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProvider;
-import org.eclipse.jpt.common.ui.jface.TreeItemContentProviderFactory;
-
-/**
- * This provider is responsible to create the JPA Structure view contents and
- * labels for a given JPA resource.
- *
- * @version 3.0
- * @since 2.0
- *
- * Provisional API: This interface is part of an interim API that is still
- * under development and expected to change significantly before reaching
- * stability. It is available at this early stage to solicit feedback from
- * pioneering adopters on the understanding that any code that uses this API
- * will almost certainly be broken (repeatedly) as the API evolves.
- */
-public interface JpaStructureProvider
-{
- /**
- * Build an factory to create {@link TreeItemContentProvider}s
- */
- TreeItemContentProviderFactory getTreeItemContentProviderFactory();
-
- /**
- * Build a factory to create {@link ItemLabelProvider}s
- */
- ItemLabelProviderFactory getItemLabelProviderFactory();
-}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests.extension.resource/src/org/eclipse/jpt/jpa/core/tests/extension/resource/TestJpaPlatformUiFactory.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests.extension.resource/src/org/eclipse/jpt/jpa/core/tests/extension/resource/TestJpaPlatformUiFactory.java
index 32db21485c..7bdf7f9ad3 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests.extension.resource/src/org/eclipse/jpt/jpa/core/tests/extension/resource/TestJpaPlatformUiFactory.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests.extension.resource/src/org/eclipse/jpt/jpa/core/tests/extension/resource/TestJpaPlatformUiFactory.java
@@ -1,9 +1,9 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
+ *
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
@@ -13,11 +13,11 @@ import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JpaPlatformUiFactory;
import org.eclipse.jpt.jpa.ui.internal.GenericJpaPlatformUiProvider;
import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericJpaPlatformUi;
-import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericNavigatorProvider;
+import org.eclipse.jpt.jpa.ui.internal.platform.generic.GenericJpaPlatformUiFactory;
-public class TestJpaPlatformUiFactory implements JpaPlatformUiFactory
+public class TestJpaPlatformUiFactory
+ implements JpaPlatformUiFactory
{
-
/**
* Zero arg constructor for extension point
*/
@@ -27,7 +27,8 @@ public class TestJpaPlatformUiFactory implements JpaPlatformUiFactory
public JpaPlatformUi buildJpaPlatformUi() {
return new GenericJpaPlatformUi(
- new GenericNavigatorProvider(),
- GenericJpaPlatformUiProvider.instance());
+ GenericJpaPlatformUiFactory.NAVIGATOR_FACTORY_PROVIDER,
+ GenericJpaPlatformUiProvider.instance()
+ );
}
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
index f9168afacd..dd1ef03c55 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/JptJpaCoreTestsPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.tests;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
import org.eclipse.jpt.jpa.core.JpaProjectManager;
@@ -24,8 +25,7 @@ import org.osgi.framework.BundleContext;
@SuppressWarnings("nls")
public class JptJpaCoreTestsPlugin
extends Plugin
-{
-
+{
private static JptJpaCoreTestsPlugin INSTANCE;
public static JptJpaCoreTestsPlugin instance() {
@@ -48,14 +48,18 @@ public class JptJpaCoreTestsPlugin
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- JpaProjectManager jpaProjectManager = JptJpaCorePlugin.getJpaProjectManager();
- ReflectionTools.executeMethod(jpaProjectManager, "handleEventsSynchronously");
+ JpaProjectManager jpaProjectManager = this.getJpaProjectManager();
+ ReflectionTools.executeMethod(jpaProjectManager, "executeCommandsSynchronously");
+ ReflectionTools.setFieldValue(jpaProjectManager, "test", Boolean.TRUE);
ReflectionTools.executeStaticMethod(JptJpaCorePlugin.class, "doNotFlushPreferences");
}
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
@Override
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
-
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java
index 2b03132660..a1f71f623d 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/JpaFileTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,6 +14,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
import org.eclipse.jpt.jpa.core.JpaFile;
+import org.eclipse.jpt.jpa.core.JpaNode;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.MappingKeys;
@@ -28,7 +29,8 @@ import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
@SuppressWarnings("nls")
-public class JpaFileTests extends ContextModelTestCase
+public class JpaFileTests
+ extends ContextModelTestCase
{
public JpaFileTests(String name) {
super(name);
@@ -43,6 +45,27 @@ public class JpaFileTests extends ContextModelTestCase
getPersistenceXmlResource().save(null);
}
+ private JpaFile getJpaFile(ICompilationUnit cu) {
+ return this.getJpaFile((IFile) cu.getResource());
+ }
+
+ private JpaFile getJpaFile(IFile file) {
+ try {
+ return this.getJpaFile_(file);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private JpaFile getJpaFile_(IFile file) throws InterruptedException {
+ return this.getJpaFileReference(file).getValue();
+ }
+
+ private JpaFile.Reference getJpaFileReference(IFile file) {
+ return (JpaFile.Reference) file.getAdapter(JpaFile.Reference.class);
+ }
+
private ICompilationUnit createTestEntity() throws Exception {
return this.createTestType(new DefaultAnnotationWriter() {
@Override
@@ -60,13 +83,13 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
IFile file = getOrmXmlResource().getFile();
- JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile ormXmlJpaFile = this.getJpaFile(file);
assertEquals(getEntityMappings(), ormXmlJpaFile.getRootStructureNodes().iterator().next());
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -86,7 +109,7 @@ public class JpaFileTests extends ContextModelTestCase
public void testEntityMappingsRootStructureNodeRemoved() throws Exception {
IFile file = getOrmXmlResource().getFile();
- JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile ormXmlJpaFile = this.getJpaFile(file);
assertEquals(getEntityMappings(), ormXmlJpaFile.getRootStructureNodes().iterator().next());
JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel();
@@ -97,7 +120,7 @@ public class JpaFileTests extends ContextModelTestCase
public void testImpliedEntityMappingsRootStructureNodeRemoved() throws Exception {
IFile file = getOrmXmlResource().getFile();
- JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile ormXmlJpaFile = this.getJpaFile(file);
assertNull(getPersistenceUnit().getImpliedMappingFileRef());
@@ -113,7 +136,7 @@ public class JpaFileTests extends ContextModelTestCase
public void testEntityMappingsRootStructureNodeRemovedFromResourceModel() throws Exception {
IFile file = getOrmXmlResource().getFile();
- JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile ormXmlJpaFile = this.getJpaFile(file);
assertEquals(getEntityMappings(), ormXmlJpaFile.getRootStructureNodes().iterator().next());
getOrmXmlResource().getContents().remove(getOrmXmlResource().getRootObject());
@@ -123,7 +146,7 @@ public class JpaFileTests extends ContextModelTestCase
public void testUpdatePersistenceRootStructureNodePersistenceRemoved() throws Exception {
IFile file = getPersistenceXmlResource().getFile();
- JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile persistenceXmlJpaFile = this.getJpaFile(file);
assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.getRootStructureNodes().iterator().next());
JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel();
@@ -134,11 +157,11 @@ public class JpaFileTests extends ContextModelTestCase
public void testUpdateOrmJavaRootStructureNodePersistenceRemoved() throws Exception {
IFile file = getPersistenceXmlResource().getFile();
- JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile persistenceXmlJpaFile = this.getJpaFile(file);
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -150,11 +173,11 @@ public class JpaFileTests extends ContextModelTestCase
public void testUpdateJavaRootStructureNodePersistenceRemoved() throws Exception {
IFile file = getPersistenceXmlResource().getFile();
- JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile persistenceXmlJpaFile = this.getJpaFile(file);
ICompilationUnit cu = createTestEntity();
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -166,7 +189,7 @@ public class JpaFileTests extends ContextModelTestCase
public void testPersistenceRootStructureNodeRemovedFromResourceModel() throws Exception {
IFile file = getPersistenceXmlResource().getFile();
- JpaFile persistenceXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile persistenceXmlJpaFile = this.getJpaFile(file);
getRootContextNode().getPersistenceXml().getPersistence();
assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.getRootStructureNodes().iterator().next());
@@ -179,7 +202,7 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -191,7 +214,7 @@ public class JpaFileTests extends ContextModelTestCase
ICompilationUnit cu = createTestEntity();
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -203,16 +226,18 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
- assertTrue(javaJpaFile.getRootStructureNodes().iterator().next().getParent() instanceof OrmPersistentType);
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertTrue(node.getParent() instanceof OrmPersistentType);
getEntityMappings().removePersistentType(0);
assertEquals(1, javaJpaFile.getRootStructureNodesSize());
- assertTrue(javaJpaFile.getRootStructureNodes().iterator().next().getParent() instanceof ClassRef);
+ node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertTrue(node.getParent() instanceof ClassRef);
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
}
@@ -220,54 +245,59 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
- assertTrue(javaJpaFile.getRootStructureNodes().iterator().next().getParent() instanceof OrmPersistentType);
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertTrue(node.getParent() instanceof OrmPersistentType);
getXmlEntityMappings().getEntities().remove(0);
assertEquals(1, javaJpaFile.getRootStructureNodesSize());
- assertTrue(javaJpaFile.getRootStructureNodes().iterator().next().getParent() instanceof ClassRef);
+ node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertTrue(node.getParent() instanceof ClassRef);
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
}
public void testJavaPersistentTypeRootStructureNodeRemoved() throws Exception {
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
JavaPersistentType javaPersistentType = getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
- assertEquals(getEntityMappings().getPersistenceUnit().getSpecifiedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getEntityMappings().getPersistenceUnit().getSpecifiedClassRefs().iterator().next(), node.getParent());
getEntityMappings().getPersistenceUnit().removeSpecifiedClassRef(0);
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
- assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), node.getParent());
}
public void testJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception {
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
JavaPersistentType javaPersistentType = getJavaPersistentType();
Iterator<JpaStructureNode> rootStructureNodes = javaJpaFile.getRootStructureNodes().iterator();
JpaStructureNode rootStructureNode = rootStructureNodes.next();
assertEquals(javaPersistentType, rootStructureNode);
- assertEquals(getEntityMappings().getPersistenceUnit().getSpecifiedClassRefs().iterator().next(), rootStructureNode.getParent());
+ assertEquals(getEntityMappings().getPersistenceUnit().getSpecifiedClassRefs().iterator().next(), ((JpaNode) rootStructureNode).getParent());
assertFalse(rootStructureNodes.hasNext());
removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
- assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), node.getParent());
}
public void testImpliedJavaPersistentTypeRootStructureNodeRemoved() throws Exception {
getJpaProject().setDiscoversAnnotatedClasses(true);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = getPersistenceUnit().getImpliedClassRefs().iterator().next().getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -281,7 +311,7 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -289,14 +319,15 @@ public class JpaFileTests extends ContextModelTestCase
getOrmXmlResource().getContents().remove(getXmlEntityMappings());
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
assertEquals(1, javaJpaFile.getRootStructureNodesSize());
- assertEquals(getPersistenceUnit().getImpliedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getPersistenceUnit().getImpliedClassRefs().iterator().next(), node.getParent());
}
public void testJavaRootStructureNodesPersistenceUnitRemovedFromResourceModel() throws Exception {
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -311,7 +342,7 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -326,7 +357,7 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -334,14 +365,15 @@ public class JpaFileTests extends ContextModelTestCase
getEntityMappings().removePersistentType(0);
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
assertEquals(1, javaJpaFile.getRootStructureNodesSize());
- assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), node.getParent());
}
public void testJavaRootStructureNodesOrmTypeMappingMorphed() throws Exception {
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -354,14 +386,15 @@ public class JpaFileTests extends ContextModelTestCase
getEntityMappings().removePersistentType(0);
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
assertEquals(1, javaJpaFile.getRootStructureNodesSize());
- assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getEntityMappings().getPersistenceUnit().getImpliedClassRefs().iterator().next(), node.getParent());
}
public void testUpdateOrmJavaRootStructureNodeMappingFileRefChanged() throws Exception {
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -372,7 +405,7 @@ public class JpaFileTests extends ContextModelTestCase
assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
IFile file = getPersistenceXmlResource().getFile();
- JpaFile ormXmlJpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile ormXmlJpaFile = this.getJpaFile(file);
assertEquals(1, ormXmlJpaFile.getRootStructureNodesSize());
}
@@ -381,7 +414,7 @@ public class JpaFileTests extends ContextModelTestCase
ICompilationUnit cu = createTestEntity();
addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
assertEquals(getJavaPersistentType(), javaJpaFile.getRootStructureNodes().iterator().next());
@@ -395,7 +428,7 @@ public class JpaFileTests extends ContextModelTestCase
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
ICompilationUnit cu = createTestEntity();
- JpaFile javaJpaFile = JptJpaCorePlugin.getJpaFile((IFile) cu.getResource());
+ JpaFile javaJpaFile = this.getJpaFile(cu);
JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType();
assertEquals(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
@@ -405,7 +438,8 @@ public class JpaFileTests extends ContextModelTestCase
assertNotSame(javaPersistentType, javaJpaFile.getRootStructureNodes().iterator().next());
assertEquals(1, javaJpaFile.getRootStructureNodesSize());
- assertEquals(getPersistenceUnit().getImpliedClassRefs().iterator().next(), javaJpaFile.getRootStructureNodes().iterator().next().getParent());
+ JpaNode node = (JpaNode) javaJpaFile.getRootStructureNodes().iterator().next();
+ assertEquals(getPersistenceUnit().getImpliedClassRefs().iterator().next(), node.getParent());
}
//TODO test rootStructureNodes with a static inner class
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceTests.java
index d7655ef4db..32f258e6c5 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/persistence/PersistenceTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -68,7 +68,7 @@ public class PersistenceTests extends ContextModelTestCase
try {
persistence.addPersistenceUnit();
}
- catch (IllegalStateException e) {
+ catch (IndexOutOfBoundsException e) {
exception = true;
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JpaProjectManagerTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JpaProjectManagerTests.java
index ea45687534..2891c9cea6 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JpaProjectManagerTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/model/JpaProjectManagerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,22 +20,26 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.jpt.common.core.tests.internal.projects.TestFacetedProject;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject;
import org.eclipse.jpt.common.core.tests.internal.projects.TestPlatformProject;
-import org.eclipse.jpt.common.utility.internal.ReflectionTools;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties;
import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider;
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
@SuppressWarnings("nls")
-public class JpaProjectManagerTests extends TestCase {
-
+public class JpaProjectManagerTests
+ extends TestCase
+{
/** carriage return */
public static final String CR = System.getProperty("line.separator");
- protected TestFacetedProject testProject;
+ private TestFacetedProject testProjectHarness;
+
+
public JpaProjectManagerTests(String name) {
super(name);
}
@@ -46,17 +50,20 @@ public class JpaProjectManagerTests extends TestCase {
if (this.debug()) {
this.printName();
}
- this.testProject = this.buildTestProject();
+ this.testProjectHarness = this.buildTestProjectHarness();
}
private boolean debug() {
- Boolean debug = (Boolean) ReflectionTools.getStaticFieldValue(this.getGenericJpaProjectManagerClass(), "DEBUG");
- return debug.booleanValue();
+ return TestTools.debug(this.getGenericJpaProjectManagerClass());
}
// GenericJpaProjectManager is package-private
private Class<?> getGenericJpaProjectManagerClass() {
- return JptJpaCorePlugin.getJpaProjectManager().getClass();
+ return this.getJpaProjectManager().getClass();
+ }
+
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
}
private void printName() {
@@ -77,16 +84,40 @@ public class JpaProjectManagerTests extends TestCase {
@Override
protected void tearDown() throws Exception {
- this.testProject.getProject().delete(true, true, null);
- this.testProject = null;
+ this.testProjectHarness.getProject().delete(true, true, null);
+ this.testProjectHarness = null;
super.tearDown();
}
+ private JpaProject getJpaProject() {
+ return this.getJpaProject(this.getProject());
+ }
+
+ private JpaProject getJpaProject(IProject project) {
+ try {
+ return this.getJpaProject_(project);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private JpaProject getJpaProject_(IProject project) throws InterruptedException {
+ return this.getJpaProjectReference(project).getValue();
+ }
+
+ private JpaProject.Reference getJpaProjectReference(IProject project) {
+ return (JpaProject.Reference) project.getAdapter(JpaProject.Reference.class);
+ }
+
+ private IProject getProject() {
+ return this.testProjectHarness.getProject();
+ }
+
/**
* Builds a project with the java and utility facets installed, and with
* pre-existing entities added.
*/
- private TestFacetedProject buildTestProject() throws Exception {
+ private TestFacetedProject buildTestProjectHarness() throws Exception {
TestJavaProject tjp = TestJavaProject.buildJavaProject(this.getClass().getSimpleName(), true);
tjp.createCompilationUnit("test.pkg", "TestEntity.java", "@Entity public class TestEntity {}");
tjp.createCompilationUnit("test.pkg", "TestEntity2.java", "@Entity public class TestEntity2 {}");
@@ -101,99 +132,94 @@ public class JpaProjectManagerTests extends TestCase {
* make sure the DEBUG constants are 'false' before checking in the code
*/
public void testDEBUG() {
- this.verifyDEBUG(this.getGenericJpaProjectManagerClass());
+ TestTools.assertFalseDEBUG(this.getGenericJpaProjectManagerClass());
}
- private void verifyDEBUG(Class<?> clazz) {
- assertFalse("Recompile with \"DEBUG = false\": " + clazz.getName(),
- ((Boolean) ReflectionTools.getStaticFieldValue(clazz, "DEBUG")).booleanValue());
- }
-
public void testJpaProjectManager() {
- assertNotNull(JptJpaCorePlugin.getJpaProjectManager());
+ assertNotNull(this.getJpaProjectManager());
}
- protected IDataModel buildJpaConfigDataModel() {
+ private IDataModel buildJpaConfigDataModel() {
IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE);
return dataModel;
}
public void testProjectCloseReopen() throws Exception {
- this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
+ JpaProject jpaProject = this.getJpaProject();
assertNotNull(jpaProject);
- this.testProject.getProject().close(null);
- assertFalse("Project is not closed", this.testProject.getProject().isOpen());
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.getProject().close(null);
+ assertFalse("Project is not closed", this.testProjectHarness.getProject().isOpen());
+ jpaProject = this.getJpaProject();
assertNull("JpaProject is not null", jpaProject);
- this.testProject.getProject().open(null);
- assertTrue(this.testProject.getProject().isOpen());
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.getProject().open(null);
+ assertTrue(this.testProjectHarness.getProject().isOpen());
+ jpaProject = this.getJpaProject();
assertNotNull("JpaProject is null", jpaProject);
assertEquals(4, jpaProject.getJpaFilesSize());
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity2.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/persistence.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/orm.xml")));
}
public void testProjectDeleteReimport() throws Exception {
- this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
+ JpaProject jpaProject = this.getJpaProject();
assertNotNull(jpaProject);
- assertEquals(1, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
+ assertEquals(1, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
- this.testProject.getProject().delete(false, true, null);
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.getProject().delete(false, true, null);
+ jpaProject = this.getJpaProject();
assertNull(jpaProject);
- assertEquals(0, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
+ assertEquals(0, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
assertEquals(0, ResourcesPlugin.getWorkspace().getRoot().getProjects().length);
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(this.testProject.getProject().getName());
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(this.testProjectHarness.getProject().getName());
project.create(null);
assertEquals(1, ResourcesPlugin.getWorkspace().getRoot().getProjects().length);
project.open(null);
assertTrue(project.isOpen());
assertTrue(JpaFacet.isInstalled(project));
- jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ jpaProject = this.getJpaProject(project);
assertNotNull(jpaProject);
assertEquals(4, jpaProject.getJpaFilesSize());
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity2.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/persistence.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/orm.xml")));
}
public void testFacetInstallUninstall() throws Exception {
- assertNull(JptJpaCorePlugin.getJpaProject(this.testProject.getProject()));
+ assertNull(this.getJpaProject());
- this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
- assertEquals(1, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
+ assertEquals(1, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
+ JpaProject jpaProject = this.getJpaProject();
assertNotNull(jpaProject);
assertEquals(4, jpaProject.getJpaFilesSize());
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity2.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/persistence.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/orm.xml")));
- this.testProject.uninstallFacet(JpaFacet.ID, "1.0");
- assertEquals(0, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.uninstallFacet(JpaFacet.ID, "1.0");
+ assertEquals(0, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
+ jpaProject = this.getJpaProject();
assertNull(jpaProject);
}
public void testEditFacetSettingsFileAddThenRemoveJpaFacet() throws Exception {
- assertNull(JptJpaCorePlugin.getJpaProject(this.testProject.getProject()));
+ assertNull(this.getJpaProject());
// add the JPA facet by modifying the facet settings file directly
- IFile facetSettingsFile = this.getFile(this.testProject, ".settings/org.eclipse.wst.common.project.facet.core.xml");
+ IFile facetSettingsFile = this.getFile(this.testProjectHarness, ".settings/org.eclipse.wst.common.project.facet.core.xml");
InputStream inStream = new BufferedInputStream(facetSettingsFile.getContents());
int fileSize = inStream.available();
byte[] buf = new byte[fileSize];
@@ -207,31 +233,31 @@ public class JpaProjectManagerTests extends TestCase {
facetSettingsFile.setContents(new ByteArrayInputStream(newDocument.getBytes()), false, false, null);
- assertEquals(1, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ assertEquals(1, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
+ JpaProject jpaProject = this.getJpaProject();
assertNotNull(jpaProject);
// persistence.xml and orm.xml do not get created in this situation (?)
assertEquals(2, jpaProject.getJpaFilesSize());
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity2.java")));
// assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml")));
// assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml")));
// now remove the JPA facet
facetSettingsFile.setContents(new ByteArrayInputStream(oldDocument.getBytes()), false, false, null);
- assertEquals(0, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ assertEquals(0, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
+ jpaProject = this.getJpaProject();
assertNull(jpaProject);
}
public void testEditFacetSettingsFileRemoveThenAddJpaFacet() throws Exception {
- this.testProject.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
- JpaProject jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ this.testProjectHarness.installFacet(JpaFacet.ID, "1.0", buildJpaConfigDataModel());
+ JpaProject jpaProject = this.getJpaProject();
assertNotNull(jpaProject);
// remove the JPA facet by modifying the facet settings file directly
- IFile facetSettingsFile = this.getFile(this.testProject, ".settings/org.eclipse.wst.common.project.facet.core.xml");
+ IFile facetSettingsFile = this.getFile(this.testProjectHarness, ".settings/org.eclipse.wst.common.project.facet.core.xml");
InputStream inStream = new BufferedInputStream(facetSettingsFile.getContents());
int fileSize = inStream.available();
byte[] buf = new byte[fileSize];
@@ -244,19 +270,19 @@ public class JpaProjectManagerTests extends TestCase {
String newDocument = oldDocument.replaceAll(oldString, newString);
facetSettingsFile.setContents(new ByteArrayInputStream(newDocument.getBytes()), false, false, null);
- assertEquals(0, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ assertEquals(0, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
+ jpaProject = this.getJpaProject();
assertNull(jpaProject);
// now add the JPA facet back
facetSettingsFile.setContents(new ByteArrayInputStream(oldDocument.getBytes()), false, false, null);
- assertEquals(1, JptJpaCorePlugin.getJpaProjectManager().getJpaProjectsSize());
- jpaProject = JptJpaCorePlugin.getJpaProject(this.testProject.getProject());
+ assertEquals(1, CollectionTools.size(this.getJpaProjectManager().waitToGetJpaProjects()));
+ jpaProject = this.getJpaProject();
assertNotNull(jpaProject);
assertEquals(4, jpaProject.getJpaFilesSize());
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/test/pkg/TestEntity2.java")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/persistence.xml")));
- assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProject, "src/META-INF/orm.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/test/pkg/TestEntity2.java")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/persistence.xml")));
+ assertNotNull(jpaProject.getJpaFile(this.getFile(this.testProjectHarness, "src/META-INF/orm.xml")));
}
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/projects/TestJpaProject.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/projects/TestJpaProject.java
index 32ec238dc5..25a39ccccb 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/projects/TestJpaProject.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/projects/TestJpaProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,15 +11,8 @@ package org.eclipse.jpt.jpa.core.tests.internal.projects;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject;
-import org.eclipse.jpt.common.utility.Command;
-import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer;
-import org.eclipse.jpt.common.utility.synchronizers.Synchronizer;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jpt.jpa.core.JpaFacet;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
@@ -31,9 +24,9 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
* controlled by building a data model and passing it into the constructor.
*/
@SuppressWarnings("nls")
-public class TestJpaProject extends TestJavaProject {
- final JpaProject jpaProject;
-
+public class TestJpaProject
+ extends TestJavaProject
+{
public static final String JPA_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.jpa.jar";
public static final String ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.eclipselink.jar";
@@ -72,38 +65,7 @@ public class TestJpaProject extends TestJavaProject {
if (eclipseLinkJarName() != null) {
this.addJar(eclipseLinkJarName());
}
- this.jpaProject = JptJpaCorePlugin.getJpaProject(this.getProject());
- this.jpaProject.setDiscoversAnnotatedClasses(true);
- this.jpaProject.setContextModelSynchronizer(this.buildSynchronousContextModelSynchronizer());
- this.jpaProject.setUpdateSynchronizer(this.buildSynchronousUpdateSynchronizer());
- }
-
- protected Synchronizer buildSynchronousContextModelSynchronizer() {
- return new SynchronousSynchronizer(this.buildSynchronousContextModelSynchronizerCommand());
- }
-
- protected Command buildSynchronousContextModelSynchronizerCommand() {
- return new SynchronousContextModelSynchronizerCommand();
- }
-
- protected class SynchronousContextModelSynchronizerCommand implements Command {
- public void execute() {
- TestJpaProject.this.jpaProject.synchronizeContextModel(new NullProgressMonitor());
- }
- }
-
- protected CallbackSynchronizer buildSynchronousUpdateSynchronizer() {
- return new CallbackSynchronousSynchronizer(this.buildSynchronousUpdateSynchronizerCommand());
- }
-
- protected Command buildSynchronousUpdateSynchronizerCommand() {
- return new SynchronousUpdateSynchronizerCommand();
- }
-
- protected class SynchronousUpdateSynchronizerCommand implements Command {
- public void execute() {
- TestJpaProject.this.jpaProject.update(new NullProgressMonitor());
- }
+ this.getJpaProject().setDiscoversAnnotatedClasses(true);
}
public static String jpaJarName() {
@@ -122,7 +84,18 @@ public class TestJpaProject extends TestJavaProject {
// ********** public methods **********
public JpaProject getJpaProject() {
- return this.jpaProject;
+ try {
+ return this.getJpaProject_();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ private JpaProject getJpaProject_() throws InterruptedException {
+ return this.getJpaProjectReference().getValue();
}
+ private JpaProject.Reference getJpaProjectReference() {
+ return (JpaProject.Reference) this.getProject().getAdapter(JpaProject.Reference.class);
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java
index 3573fa84e0..00701545e0 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -24,7 +24,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase;
-import org.eclipse.jpt.common.utility.CommandExecutor;
+import org.eclipse.jpt.common.utility.command.CommandExecutor;
import org.eclipse.jpt.common.utility.internal.BitTools;
import org.eclipse.jpt.common.utility.internal.ReflectionTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
index 847814eaa4..99dad592f8 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF
@@ -8,7 +8,7 @@ Bundle-Activator: org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorP
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)",
org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)",
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
index 095a8d7845..e008d5cc69 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/JPADiagramEditor.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,7 +18,6 @@ package org.eclipse.jpt.jpadiagrameditor.ui.internal;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -45,12 +44,11 @@ import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.jpa.ui.internal.selection.DefaultJpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.SelectionManagerFactory;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.ui.JPADiagramEditorInput;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
@@ -286,8 +284,7 @@ public class JPADiagramEditor extends DiagramEditor {
(PictogramElement) m);
if ((bo == null) || (!(bo instanceof JpaStructureNode)))
return;
- selectionManager.select(new DefaultJpaSelection(
- (JpaStructureNode) bo), null);
+ selectionManager.setSelection((JpaStructureNode) bo);
return;
}
}
@@ -306,7 +303,7 @@ public class JPADiagramEditor extends DiagramEditor {
ISelectionManagerFactory {
public JpaSelectionManager getSelectionManager(IWorkbenchWindow window) {
- return SelectionManagerFactory.getSelectionManager(window);
+ return PlatformTools.getAdapter(window, JpaSelectionManager.class);
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
index ea7ca502ac..c9e4c146f5 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
@@ -174,7 +174,8 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
final IJPAEditorFeatureProvider fp) {
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
- pu.getJpaProject().updateAndWait();
+ // TODO figure out why this was necessary:
+ // pu.getJpaProject().updateAndWait();
final int x = pict.getGraphicsAlgorithm().getX();
final int y = pict.getGraphicsAlgorithm().getY();
final int width = pict.getGraphicsAlgorithm().getWidth();
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
index 2196274861..086de3b17b 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/modelintegration/util/ModelIntegrationUtil.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -270,11 +270,7 @@ public class ModelIntegrationUtil {
public static JpaProject getProjectByDiagram(String diagramName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(diagramName);
- try {
- return JpaArtifactFactory.instance().getJpaProject(project);
- } catch (CoreException e) {
- return null;
- }
+ return JpaArtifactFactory.instance().getJpaProject(project);
}
public static boolean isDiagramOpen(String diagramName) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
index fac5383172..fe09b1dee6 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPAEditorUtil.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2011 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -290,15 +290,11 @@ public class JPAEditorUtil {
return null;
IType tp = cu.findPrimaryType();
if (tp == null)
- return null;;
+ return null;
name = tp.getFullyQualifiedName();
IJavaProject jp = cu.getJavaProject();
JpaProject proj = null;
- try {
- proj = JpaArtifactFactory.instance().getJpaProject(jp.getProject());
- } catch (CoreException e) {
- JPADiagramEditorPlugin.logError("Cannot obtain the JPA project.", e); //$NON-NLS-1$
- }
+ proj = JpaArtifactFactory.instance().getJpaProject(jp.getProject());
if (proj == null)
return null;
PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(proj);
@@ -394,45 +390,38 @@ public class JPAEditorUtil {
public static void createRegisterEntityInXMLJob(final JpaProject jpaProject, final String classFQN) {
final JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
- resource.modify(new Runnable() {
- public void run() {
- XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
- EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
- XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0); // Multiply persistence unit support
- boolean registered = false;
- Iterator<XmlJavaClassRef> it = persistenceUnit.getClasses().iterator();
- while (it.hasNext()) {
- String className = it.next().getJavaClass();
- if (classFQN.equals(className)) {
- registered = true;
- break;
- }
- }
- if (!registered) {
- XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
- classRef.setJavaClass(classFQN);
- persistenceUnit.getClasses().add(classRef);
- }
+ XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
+ EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
+ XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0); // Multiply persistence unit support
+ boolean registered = false;
+ for (XmlJavaClassRef ref : persistenceUnit.getClasses()) {
+ String className = ref.getJavaClass();
+ if (classFQN.equals(className)) {
+ registered = true;
+ break;
}
- });
+ }
+ if (!registered) {
+ XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef();
+ classRef.setJavaClass(classFQN);
+ persistenceUnit.getClasses().add(classRef);
+ }
+ resource.save();
}
public static void createUnregisterEntityFromXMLJob(final JpaProject jpaProject, final String classFQN) {
- final JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
-
- resource.modify(new Runnable() {
- public void run() {
- XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
- EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
- XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0);// Multiply persistence unit support
- EList<XmlJavaClassRef> cRefs = persistenceUnit.getClasses();
- for (XmlJavaClassRef cRef : cRefs)
- if (cRef.getJavaClass().equals(classFQN)) {
- cRefs.remove(cRef);
- break;
- }
+ JpaXmlResource resource = jpaProject.getPersistenceXmlResource();
+ XmlPersistence xmlPersistence = (XmlPersistence) resource.getRootObject();
+ EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits();
+ XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0);// Multiply persistence unit support
+ EList<XmlJavaClassRef> cRefs = persistenceUnit.getClasses();
+ for (XmlJavaClassRef ref : cRefs) {
+ if (ref.getJavaClass().equals(classFQN)) {
+ cRefs.remove(ref);
+ break;
}
- });
+ }
+ resource.save();
}
public static void createImports(ICompilationUnit cu, String typeFQN) {
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
index 6e68ace118..2a55ae729f 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2011 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -50,16 +50,15 @@ import org.eclipse.jdt.ui.refactoring.RenameSupport;
import org.eclipse.jpt.common.core.JptResourceModel;
import org.eclipse.jpt.common.core.resource.java.Annotation;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
+import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind;
import org.eclipse.jpt.common.utility.internal.iterables.ArrayListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.Embeddable;
@@ -447,7 +446,6 @@ public class JpaArtifactFactory {
ICompilationUnit cu = fp.getCompilationUnit(jpt);
try {
JpaProject jpaProject = jpt.getJpaProject();
- jpaProject.updateAndWait();
JPAEditorUtil.discardWorkingCopy(cu);
cu.delete(true, new NullProgressMonitor());
return true;
@@ -1363,7 +1361,6 @@ public class JpaArtifactFactory {
*/
public JavaPersistentType getJPT(String name, PersistenceUnit pu) {
- pu.getJpaProject().updateAndWait();
JavaPersistentType jpt = (JavaPersistentType) pu.getPersistentType(name);
int cnt = 0;
while ((jpt == null) && (cnt < MAX_NUM_OF_ITERATIONS)) {
@@ -2229,8 +2226,8 @@ public class JpaArtifactFactory {
return relTypeName;
}
- public JpaProject getJpaProject(IProject project) throws CoreException {
- return JptJpaCorePlugin.getJpaProject(project);
+ public JpaProject getJpaProject(IProject project) {
+ return (JpaProject) project.getAdapter(JpaProject.class);
}
public String getIdType(JavaPersistentType jpt) {
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF
index 5c6885618e..16845b34e9 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@ Bundle-Version: 1.0.100.qualifier
Bundle-Activator: org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPAEditorTestsActivator
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.easymock;bundle-version="[2.4.0,3.0.0)",
org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)",
org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)",
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java
index 2704eb6efd..e892d936b0 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java
@@ -46,7 +46,6 @@ import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
@@ -122,7 +121,7 @@ public class JPACreateFactory {
addJar(javaProject, eclipseLinkJarName());
}
project.refreshLocal(IResource.DEPTH_INFINITE, null);
- jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ jpaProject = this.getJpaProject(project);
int cnt = 0;
while ((jpaProject == null) && (cnt < 1000)){
try {
@@ -130,7 +129,7 @@ public class JPACreateFactory {
} catch (InterruptedException e) {
e.printStackTrace();
}
- jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ jpaProject = this.getJpaProject(project);
cnt++;
}
jpaProject.setDiscoversAnnotatedClasses(true);
@@ -138,6 +137,10 @@ public class JPACreateFactory {
return jpaProject;
}
+ private JpaProject getJpaProject(IProject p) {
+ return (JpaProject) p.getAdapter(JpaProject.class);
+ }
+
public static String eclipseLinkJarName() {
return getSystemProperty(ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY);
}
@@ -539,7 +542,7 @@ public class JPACreateFactory {
}
public static PersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile jpaFile = getJpaFile(file);
for (JpaStructureNode node : getRootNodes(jpaFile)) {
PersistentType entity = (PersistentType) node;
return entity;
@@ -556,7 +559,7 @@ public class JPACreateFactory {
public static Set<ReadOnlyPersistentAttribute> getEntityFields(IFile file){
Set<ReadOnlyPersistentAttribute> result = new HashSet<ReadOnlyPersistentAttribute>();
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ JpaFile jpaFile = getJpaFile(file);
if(jpaFile == null){
return result;
}
@@ -568,6 +571,10 @@ public class JPACreateFactory {
}
return result;
}
+
+ private static JpaFile getJpaFile(IFile file) {
+ return (JpaFile) file.getAdapter(JpaFile.class);
+ }
public void addAttributes(IFile entity, String attName, String attType, String annotation, String attActName, boolean isCollection){
JavaPersistentType javaPersistentType = (JavaPersistentType)getPersistentType(entity);
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java
index 0986bff109..7571ee0ddb 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2011 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,7 +15,11 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jpt.common.utility.internal.ReflectionTools;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.osgi.framework.BundleContext;
public class JPAEditorTestsActivator extends Plugin {
@@ -29,19 +33,19 @@ public class JPAEditorTestsActivator extends Plugin {
// The shared instance
private static JPAEditorTestsActivator plugin;
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ JpaProjectManager jpaProjectManager = this.getJpaProjectManager();
+ ReflectionTools.executeMethod(jpaProjectManager, "executeCommandsSynchronously"); //$NON-NLS-1$
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
+ protected JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
+ @Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java
index d16b031506..b6484a2b10 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java
@@ -15,22 +15,18 @@
*******************************************************************************/
package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.editor;
-import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertNotNull;
-
import org.easymock.EasyMock;
import org.eclipse.gef.EditPart;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelection;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
-import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionParticipant;
+import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditor;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -94,8 +90,7 @@ public class EditorTest {
// test
JpaSelectionManager manager = EasyMock
.createMock(JpaSelectionManager.class);
- manager.select(isA(JpaSelection.class),
- (JpaSelectionParticipant) eq(null));
+ manager.setSelection(isA(JpaStructureNode.class));
replay(manager);
JPADiagramEditor.ISelectionManagerFactory factory = EasyMock
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java
index a700ef5c66..018126740e 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java
@@ -19,7 +19,6 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertNotNull;
-
import org.easymock.EasyMock;
import org.eclipse.core.resources.IFile;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
@@ -30,7 +29,6 @@ import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddAttributeButtonFeature;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
@@ -54,7 +52,6 @@ public class ClickAddFeatureTest {
@Before
public void setUp() throws Exception {
System.setProperty(JPACreateFactory.JPA_JAR_NAME_SYSTEM_PROPERTY, "C:\\lib\\persistence-api-1.0.jar");
- JptJpaCorePlugin.getJpaProjectManager();
factory = JPACreateFactory.instance();
jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
assertNotNull(jpaProject);
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java
index 3ac34cc448..9d6264b2b0 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java
@@ -22,10 +22,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-
import org.easymock.EasyMock;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -46,7 +44,6 @@ import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
@@ -65,7 +62,6 @@ public class CreateDeleteOnlyAttributeTest {
@Before
public void setUp() throws Exception{
- JptJpaCorePlugin.getJpaProjectManager();
factory = JPACreateFactory.instance();
jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
assertNotNull(jpaProject);
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java
index 7ed4a57752..2406595dd6 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java
@@ -549,22 +549,6 @@ public class CreateRelationFeaturesTest {
}
- public static JavaPersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node : getRootNodes(jpaFile)) {
- JavaPersistentType entity = (JavaPersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
return JavaCore.createCompilationUnitFrom(file);
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java
index 5367a27c13..2e90717f4f 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java
@@ -96,22 +96,6 @@ public class SaveEntityFeatureTest {
ft.execute(ctx);
}
- public static JavaPersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node : getRootNodes(jpaFile)) {
- JavaPersistentType entity = (JavaPersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
return JavaCore.createCompilationUnitFrom(file);
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java
index 84b5695802..d6195301f1 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java
@@ -65,26 +65,10 @@ public class JPAProjectListenerTest {
IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1");
Thread.sleep(2000);
featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
- expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(getPersistentType(entity));
+ expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity));
expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
}
- public static JavaPersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node : getRootNodes(jpaFile)) {
- JavaPersistentType entity = (JavaPersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
return JavaCore.createCompilationUnitFrom(file);
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java
index 80f7416c95..34e3ba1189 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java
@@ -74,7 +74,7 @@ public class ModelIntegrationTest {
entityFile = factory.createEntity(jpaProject, "org.eclipse.Entity1");
Thread.sleep(2000);
featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
- expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(getPersistentType(entityFile));
+ expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entityFile));
expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entityFile)).anyTimes();
}
@@ -87,7 +87,7 @@ public class ModelIntegrationTest {
ICompilationUnit cu = createCompilationUnitFrom(entityFile);
IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class);
- JavaPersistentType inputJptType = getPersistentType(entityFile);
+ JavaPersistentType inputJptType = (JavaPersistentType) JPACreateFactory.getPersistentType(entityFile);
expect(ut.getJPType(cu)).andStubReturn(inputJptType);
expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut);
Diagram d = EasyMock.createMock(Diagram.class);
@@ -124,7 +124,7 @@ public class ModelIntegrationTest {
ICompilationUnit cu = createCompilationUnitFrom(entityFile);
IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class);
- JavaPersistentType inputJptType = getPersistentType(entityFile);
+ JavaPersistentType inputJptType = (JavaPersistentType) JPACreateFactory.getPersistentType(entityFile);
expect(ut.getJPType(cu)).andStubReturn(inputJptType);
expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut);
Diagram d = EasyMock.createMock(Diagram.class);
@@ -197,22 +197,6 @@ public class ModelIntegrationTest {
- public static JavaPersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node : getRootNodes(jpaFile)) {
- JavaPersistentType entity = (JavaPersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
return JavaCore.createCompilationUnitFrom(file);
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java
index 4d947ab6c1..4c8dfe3d51 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java
@@ -17,7 +17,6 @@ package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.util
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
import org.easymock.EasyMock;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
@@ -26,7 +25,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.util.BasicInternalEList;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferenceInitializer;
@@ -77,7 +75,6 @@ public class ModelIntegrationUtilTest {
JPADiagramEditorPlugin p = new JPADiagramEditorPlugin();
p.start(bc);
- JptJpaCorePlugin.getJpaProjectManager();
IPreferenceStore store = JPADiagramEditorPlugin.getDefault().getPreferenceStore();
store.putValue(JPAEditorPreferenceInitializer.PROPERTY_DIAGRAM_FOLDER, "diagrams");
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java
index 5a5312c80c..d2cc65a4d5 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java
@@ -68,27 +68,11 @@ public class CreateRelationAttributesTest {
IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1");
Thread.sleep(2000);
featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
- expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(getPersistentType(entity));
+ expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity));
expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
replay(featureProvider);
}
- public static PersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node : getRootNodes(jpaFile)) {
- PersistentType entity = (PersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
if (!cu.isWorkingCopy())
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java
index 1bad2f4de7..f313512e5d 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java
@@ -74,27 +74,11 @@ public class CreateRelationsInFieldAnnotatedEntitiesTest {
IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1");
Thread.sleep(2000);
featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
- expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(getPersistentType(entity));
+ expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity));
expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
replay(featureProvider);
}
- public static JavaPersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node: getRootNodes(jpaFile)) {
- JavaPersistentType entity = (JavaPersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
return JavaCore.createCompilationUnitFrom(file);
}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java
index ffcc157fed..7f420ed395 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2011 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,15 +18,13 @@ package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.relation;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
-import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-
import java.util.Iterator;
import java.util.Properties;
-
import org.easymock.EasyMock;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IncrementalProjectBuilder;
@@ -36,12 +34,8 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.NestableAnnotation;
-import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper;
-import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JpaStructureNode;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.AttributeMapping;
import org.eclipse.jpt.jpa.core.context.Embeddable;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
@@ -69,7 +63,7 @@ import org.junit.Before;
import org.junit.Test;
-@SuppressWarnings({ "unused" })
+@SuppressWarnings({ "unused", "nls" })
public class CreateRelationsTest {
private IJPAEditorFeatureProvider featureProvider;
@@ -89,15 +83,13 @@ public class CreateRelationsTest {
@Before
public void setUp() throws Exception {
- JptJpaCorePlugin.getJpaProjectManager();
factory = JPACreateFactory.instance();
jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
assertNotNull(jpaProject);
IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1");
- Thread.sleep(2000);
featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
- expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(getPersistentType(entity));
+ expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity));
expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
assertNotNull(jpaProject);
@@ -113,13 +105,6 @@ public class CreateRelationsTest {
t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
- int c = 0;
- while ((t1 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- jpaProject.update(null);
- Thread.sleep(200);
- t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
- c++;
- }
expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(isA(Shape.class));
cu1 = JavaCore.createCompilationUnitFrom(customerFile);
@@ -131,13 +116,6 @@ public class CreateRelationsTest {
t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
- c = 0;
- while ((t2 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- jpaProject.update(null);
- Thread.sleep(200);
- t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
- c++;
- }
expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(isA(Shape.class));
cu2 = JavaCore.createCompilationUnitFrom(addressFile);
@@ -155,27 +133,11 @@ public class CreateRelationsTest {
IFile entity20 = factory.createEntity(jpa20Project, "org.eclipse.Entity1");
Thread.sleep(2000);
featureProvider20 = EasyMock.createMock(IJPAEditorFeatureProvider.class);
- expect(featureProvider20.getBusinessObjectForPictogramElement(null)).andReturn(getPersistentType(entity20));
+ expect(featureProvider20.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity20));
expect(featureProvider20.getCompilationUnit(isA(JavaPersistentType.class)))
.andReturn(JavaCore.createCompilationUnitFrom(entity20)).anyTimes();
}
- public static JavaPersistentType getPersistentType(IFile file){
- JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
- for (JpaStructureNode node: getRootNodes(jpaFile)) {
- JavaPersistentType entity = (JavaPersistentType) node;
- return entity;
- }
- return null;
- }
-
- private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
- if(jpaFile == null){
- return EmptyIterable.instance();
- }
- return jpaFile.getRootStructureNodes();
- }
-
public ICompilationUnit createCompilationUnitFrom(IFile file) {
return JavaCore.createCompilationUnitFrom(file);
}
@@ -339,13 +301,6 @@ public class CreateRelationsTest {
assertNotNull(customerType);
JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, customerType.getQualifiedName());
- int c = 0;
- while ((t1 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- t1 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, customerType.getQualifiedName());
- c++;
- }
expect(featureProvider20.getPictogramElementForBusinessObject(t1)).andStubReturn(isA(Shape.class));
ICompilationUnit cu1 = JavaCore.createCompilationUnitFrom(customerFile);
@@ -357,12 +312,7 @@ public class CreateRelationsTest {
JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, addressType.getQualifiedName());
- while ((t2 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- t2 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, addressType.getQualifiedName());
- c++;
- }
+
expect(featureProvider20.getPictogramElementForBusinessObject(t2)).andStubReturn(isA(Shape.class));
ICompilationUnit cu2 = JavaCore.createCompilationUnitFrom(addressFile);
expect(featureProvider20.getCompilationUnit(t2)).andStubReturn(cu2);
@@ -417,13 +367,6 @@ public class CreateRelationsTest {
assertNotNull(employeeType);
JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, employeeType.getQualifiedName());
- int c = 0;
- while ((t1 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- t1 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, employeeType.getQualifiedName());
- c++;
- }
expect(featureProvider20.getPictogramElementForBusinessObject(t1)).andStubReturn(isA(Shape.class));
ICompilationUnit cu1 = JavaCore.createCompilationUnitFrom(employeeFile);
@@ -435,12 +378,7 @@ public class CreateRelationsTest {
JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, projectType.getQualifiedName());
- while ((t2 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- t2 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, projectType.getQualifiedName());
- c++;
- }
+
expect(featureProvider20.getPictogramElementForBusinessObject(t2)).andStubReturn(isA(Shape.class));
ICompilationUnit cu2 = JavaCore.createCompilationUnitFrom(projectFile);
expect(featureProvider20.getCompilationUnit(t2)).andStubReturn(cu2);
@@ -488,13 +426,6 @@ public class CreateRelationsTest {
JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, employeeType.getQualifiedName());
- int c = 0;
- while ((t1 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- t1 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, employeeType.getQualifiedName());
- c++;
- }
expect(featureProvider20.getPictogramElementForBusinessObject(t1)).andStubReturn(isA(Shape.class));
ICompilationUnit cu1 = JavaCore.createCompilationUnitFrom(employeeFile);
@@ -503,14 +434,6 @@ public class CreateRelationsTest {
Embeddable emb = JpaArtifactFactory.instance().getPersistenceUnit(t1).getEmbeddable("com.test.EmployeerId");
Iterator<AttributeMapping> embIt = emb.getAllAttributeMappings().iterator();
- int c1 = 0;
- while ((embIt.hasNext() == false) && (c1 < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- emb.update();
- embIt = emb.getAllAttributeMappings().iterator();
- c1++;
- }
assertTrue(projectFile.exists());
JavaResourceAbstractType projectType = jpa20Project.getJavaResourceType("com.Person");
@@ -518,12 +441,6 @@ public class CreateRelationsTest {
JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, projectType.getQualifiedName());
- while ((t2 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
- Thread.sleep(200);
- jpa20Project.update(null);
- t2 = JpaArtifactFactory.instance().getContextPersistentType(jpa20Project, projectType.getQualifiedName());
- c++;
- }
expect(featureProvider20.getPictogramElementForBusinessObject(t2)).andStubReturn(isA(Shape.class));
ICompilationUnit cu2 = JavaCore.createCompilationUnitFrom(projectFile);
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java
index 79dc0715c8..668cf6eb16 100644
--- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java
@@ -19,13 +19,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.jpa.core.JpaProject;
-import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
@@ -45,7 +43,6 @@ public class CreateDeleteEntity {
@Before
public void setUp() throws Exception {
- JptJpaCorePlugin.getJpaProjectManager();
factory = JPACreateFactory.instance();
jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
assertNotNull(jpaProject);
@@ -107,12 +104,10 @@ public class CreateDeleteEntity {
// updater = new SynchronousJpaProjectUpdater(jpaProject);
// updater.start();
jpaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
- JptJpaCorePlugin.rebuildJpaProject(jpaProject.getProject());
persistenceType = jpaProject.getJavaResourceType("com.Entity1");
c = 0;
while ((persistenceType != null) && (c < 250)) {
Thread.sleep(500);
- jpaProject = JptJpaCorePlugin.getJpaProject(jpaProject.getProject());
persistenceType = jpaProject.getJavaResourceType("com.Entity1");
c++;
}

Back to the top