diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse')
243 files changed, 23500 insertions, 15282 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java index b94a63b279..94cdd29f33 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java @@ -1,85 +1,196 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal; -import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; +import org.eclipse.jpt.core.internal.context.base.IEmbeddable; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping; +import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping; +import org.eclipse.jpt.core.internal.context.base.IMappedSuperclass; +import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping; +import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping; +import org.eclipse.jpt.core.internal.context.base.ITransientMapping; +import org.eclipse.jpt.core.internal.context.base.IVersionMapping; import org.eclipse.jpt.ui.internal.details.IJpaComposite; -import org.eclipse.jpt.ui.internal.mappings.details.BasicComposite; +import org.eclipse.jpt.ui.internal.mappings.details.BasicMappingComposite; import org.eclipse.jpt.ui.internal.mappings.details.EmbeddableComposite; -import org.eclipse.jpt.ui.internal.mappings.details.EmbeddedComposite; -import org.eclipse.jpt.ui.internal.mappings.details.EmbeddedIdComposite; +import org.eclipse.jpt.ui.internal.mappings.details.EmbeddedIdMappingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.EmbeddedMappingComposite; import org.eclipse.jpt.ui.internal.mappings.details.EntityComposite; -import org.eclipse.jpt.ui.internal.mappings.details.IdComposite; -import org.eclipse.jpt.ui.internal.mappings.details.ManyToManyComposite; -import org.eclipse.jpt.ui.internal.mappings.details.ManyToOneComposite; +import org.eclipse.jpt.ui.internal.mappings.details.IdMappingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.ManyToManyMappingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.ManyToOneMappingComposite; import org.eclipse.jpt.ui.internal.mappings.details.MappedSuperclassComposite; -import org.eclipse.jpt.ui.internal.mappings.details.OneToManyComposite; -import org.eclipse.jpt.ui.internal.mappings.details.OneToOneComposite; -import org.eclipse.jpt.ui.internal.mappings.details.TransientComposite; +import org.eclipse.jpt.ui.internal.mappings.details.OneToManyMappingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.OneToOneMappingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.TransientMappingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.VersionMappingComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - +/** + * The default implementation of the UI factory required to show the information + * related to a JPA mapping (type or attribute). + * + * @see IJpaUiFactory + * + * @version 2.0 + * @since 1.0 + */ public abstract class BaseJpaUiFactory implements IJpaUiFactory { - - public IJpaComposite createBasicMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new BasicComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IBasicMapping> createBasicMappingComposite( + PropertyValueModel<IBasicMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new BasicMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createEmbeddableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EmbeddableComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IEmbeddable> createEmbeddableComposite( + PropertyValueModel<IEmbeddable> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new EmbeddableComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createEmbeddedIdMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EmbeddedIdComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IEmbeddedIdMapping> createEmbeddedIdMappingComposite( + PropertyValueModel<IEmbeddedIdMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new EmbeddedIdMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createEmbeddedMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EmbeddedComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IEmbeddedMapping> createEmbeddedMappingComposite( + PropertyValueModel<IEmbeddedMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new EmbeddedMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createEntityComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EntityComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IEntity> createEntityComposite( + PropertyValueModel<IEntity> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new EntityComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createIdMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new IdComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IIdMapping> createIdMappingComposite( + PropertyValueModel<IIdMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new IdMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createManyToManyMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new ManyToManyComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IManyToManyMapping> createManyToManyMappingComposite( + PropertyValueModel<IManyToManyMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new ManyToManyMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createManyToOneMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new ManyToOneComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IManyToOneMapping> createManyToOneMappingComposite( + PropertyValueModel<IManyToOneMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new ManyToOneMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createMappedSuperclassComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new MappedSuperclassComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IMappedSuperclass> createMappedSuperclassComposite( + PropertyValueModel<IMappedSuperclass> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new MappedSuperclassComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createOneToManyMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new OneToManyComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IOneToManyMapping> createOneToManyMappingComposite( + PropertyValueModel<IOneToManyMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new OneToManyMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createOneToOneMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new OneToOneComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IOneToOneMapping> createOneToOneMappingComposite( + PropertyValueModel<IOneToOneMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new OneToOneMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createTransientMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new TransientComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<ITransientMapping> createTransientMappingComposite( + PropertyValueModel<ITransientMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new TransientMappingComposite(subjectHolder, parent, widgetFactory); } - public IJpaComposite createVersionMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new BasicComposite(parent, commandStack, widgetFactory); + /* + * (non-Javadoc) + */ + public IJpaComposite<IVersionMapping> createVersionMappingComposite( + PropertyValueModel<IVersionMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + return new VersionMappingComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java index 9d3edce4f6..734d484241 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java @@ -3,14 +3,21 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal; - +/** + * The default implementation of the UI factory required to show the information + * related to a JPA mapping (type or attribute). + * + * @see IJpaUiFactory + * + * @version 1.0 + * @since 1.0 + */ public class GenericJpaUiFactory extends BaseJpaUiFactory { - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaPlatformUi.java index 342ac51de2..f998e3ddb1 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaPlatformUi.java @@ -3,55 +3,79 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal; -import java.util.Iterator; -import java.util.ListIterator; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.internal.IJpaProject; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; import org.eclipse.jpt.ui.internal.details.IJpaDetailsProvider; -import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; -import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; - +import org.eclipse.ui.navigator.ICommonContentProvider; +import org.eclipse.ui.navigator.ICommonLabelProvider; +/** + * 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 IJpaPlatform}) implementation with the same ID. + * <p> + * Any implementation should be <i>stateless</i> in nature. + * <p> + * The "generic" extension supplies UI for the core platform extension with the same + * ID. + * + * @see the org.eclipse.jpt.ui.jpaPlatform extension point + */ public interface IJpaPlatformUi { - Iterator<IJpaStructureProvider> structureProviders(); - - IJpaStructureProvider structureProvider(String fileContentType); - - Iterator<IJpaDetailsProvider> detailsProviders(); - - IJpaDetailsProvider detailsProvider(String fileContentType); - - /** - * Return the type mapping UI providers for java. This will populate - * the type mapping combo box in order and displaying ITypeMappingUiProvider.label(). - * It will also be used to create the appropriate composite given a type mapping. - */ - ListIterator<ITypeMappingUiProvider> javaTypeMappingUiProviders(); - /** - * Return the attribute mapping UI providers for java. This will populate - * the attribute mapping combo box in order and display IAttributeMappingUiProvider.label(). - * It will also be used to create the appropriate composite given an attribute mapping. + * Return a *new* navigator content provider. There will be (at most) one + * of these per view that uses it. */ - ListIterator<IAttributeMappingUiProvider> javaAttributeMappingUiProviders(); + ICommonContentProvider buildNavigatorContentProvider(); /** - * Return the default attribute mapping UI providers for java. These will be used - * to provide a default mapping option if one applies in java. + * Return a *new* navigator label provider. There will be (at most) one + * of these per view that uses it. */ - ListIterator<IAttributeMappingUiProvider> defaultJavaAttributeMappingUiProviders(); + ICommonLabelProvider buildNavigatorLabelProvider(); - IJpaUiFactory getJpaUiFactory(); void generateDDL(IJpaProject project, IStructuredSelection selection); - + void generateEntities(IJpaProject project, IStructuredSelection selection); + + +// Iterator<IJpaStructureProvider> structureProviders(); +// +// IJpaStructureProvider structureProvider(String fileContentType); +// +// Iterator<IJpaDetailsProvider> detailsProviders(); +// + IJpaDetailsProvider detailsProvider(IJpaContextNode contextNode); +// +// /** +// * Return the type mapping UI providers for java. This will populate +// * the type mapping combo box in order and displaying ITypeMappingUiProvider.label(). +// * It will also be used to create the appropriate composite given a type mapping. +// */ +// ListIterator<ITypeMappingUiProvider> javaTypeMappingUiProviders(); +// +// /** +// * Return the attribute mapping UI providers for java. This will populate +// * the attribute mapping combo box in order and display IAttributeMappingUiProvider.label(). +// * It will also be used to create the appropriate composite given an attribute mapping. +// */ +// ListIterator<IAttributeMappingUiProvider> javaAttributeMappingUiProviders(); +// +// /** +// * Return the default attribute mapping UI providers for java. These will be used +// * to provide a default mapping option if one applies in java. +// */ +// ListIterator<IAttributeMappingUiProvider> defaultJavaAttributeMappingUiProviders(); +// +// IJpaUiFactory getJpaUiFactory(); + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaUiFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaUiFactory.java index 2939cdfec2..5f1cdeab22 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaUiFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/IJpaUiFactory.java @@ -3,20 +3,33 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal; -import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; +import org.eclipse.jpt.core.internal.context.base.IEmbeddable; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping; +import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping; +import org.eclipse.jpt.core.internal.context.base.IMappedSuperclass; +import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping; +import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping; +import org.eclipse.jpt.core.internal.context.base.ITransientMapping; +import org.eclipse.jpt.core.internal.context.base.IVersionMapping; import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; /** * Use IJpaFactory to create any IJavaTypeMapping or IJavaAttributeMappings. This is necessary - * so that platforms can extend the java model with their own annotations. + * so that platforms can extend the java model with their own annotations. * IJavaTypeMappingProvider and IJavaAttributeMappingProvider use this factory. * See IJpaPlatform.javaTypeMappingProviders() and IJpaPlatform.javaAttributeMappingProviders() * for creating new mappings types. @@ -24,29 +37,29 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; */ public interface IJpaUiFactory { - IJpaComposite createEntityComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createEmbeddableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createMappedSuperclassComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createBasicMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createEmbeddedMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createEmbeddedIdMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createIdMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createManyToManyMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createManyToOneMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createOneToManyMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createOneToOneMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createTransientMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - - IJpaComposite createVersionMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); -} + IJpaComposite<IBasicMapping> createBasicMappingComposite(PropertyValueModel<IBasicMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IEmbeddable> createEmbeddableComposite(PropertyValueModel<IEmbeddable> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IEmbeddedIdMapping> createEmbeddedIdMappingComposite(PropertyValueModel<IEmbeddedIdMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IEmbeddedMapping> createEmbeddedMappingComposite(PropertyValueModel<IEmbeddedMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IEntity> createEntityComposite(PropertyValueModel<IEntity> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IIdMapping> createIdMappingComposite(PropertyValueModel<IIdMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IManyToManyMapping> createManyToManyMappingComposite(PropertyValueModel<IManyToManyMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IManyToOneMapping> createManyToOneMappingComposite(PropertyValueModel<IManyToOneMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IMappedSuperclass> createMappedSuperclassComposite(PropertyValueModel<IMappedSuperclass> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IOneToManyMapping> createOneToManyMappingComposite(PropertyValueModel<IOneToManyMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IOneToOneMapping> createOneToOneMappingComposite(PropertyValueModel<IOneToOneMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<ITransientMapping> createTransientMappingComposite(PropertyValueModel<ITransientMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); + + IJpaComposite<IVersionMapping> createVersionMappingComposite(PropertyValueModel<IVersionMapping> subjectHolder, Composite parent, TabbedPropertySheetWidgetFactory widgetFactory); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java index b59161c202..5958cc8195 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaCompletionProposalComputer.java @@ -13,12 +13,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.CompletionContext; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext; import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer; import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; @@ -26,7 +26,9 @@ import org.eclipse.jface.text.contentassist.CompletionProposal; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jpt.core.internal.IJpaFile; import org.eclipse.jpt.core.internal.JptCorePlugin; -import org.eclipse.jpt.core.internal.content.java.JpaCompilationUnit; +import org.eclipse.jpt.core.internal.context.java.JavaPersistentType; +import org.eclipse.jpt.core.internal.jdtutility.JDTTools; +import org.eclipse.jpt.core.internal.resource.java.JavaResourceModel; import org.eclipse.jpt.utility.internal.Filter; import org.eclipse.jpt.utility.internal.StringTools; @@ -67,7 +69,13 @@ public class JpaCompletionProposalComputer implements IJavaCompletionProposalCom return Collections.emptyList(); } - JpaCompilationUnit jpaCU = (JpaCompilationUnit) jpaFile.getContent(); + JavaResourceModel javaResourceModel = (JavaResourceModel) jpaFile.getResourceModel(); + + //TODO A bit of hackery for now just to get this compiling and working good enough, + //we need to have a way to get the context model given an IFile or IJpaFile + //instead of having to ask the IResourceModel for it + JavaPersistentType contextNode = (JavaPersistentType) javaResourceModel.rootContextNodes().next(); + CompletionContext cc = context.getCoreContext(); // the context's "token" is really a sort of "prefix" - it does NOT @@ -88,8 +96,9 @@ public class JpaCompletionProposalComputer implements IJavaCompletionProposalCom // String snippet = source.substring(Math.max(0, tokenStart - 20), Math.min(source.length(), tokenEnd + 21)); // System.out.println("surrounding snippet: =>" + snippet + "<="); + CompilationUnit astRoot = JDTTools.buildASTRoot(cu); List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); - for (Iterator<String> stream = jpaCU.candidateValuesFor(context.getInvocationOffset(), filter); stream.hasNext(); ) { + for (Iterator<String> stream = contextNode.candidateValuesFor(context.getInvocationOffset(), filter, astRoot); stream.hasNext(); ) { String s = stream.next(); proposals.add(new CompletionProposal(s, tokenStart, tokenEnd - tokenStart + 1, s.length())); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaMappingImageHelper.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaMappingImageHelper.java new file mode 100644 index 0000000000..8145695deb --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaMappingImageHelper.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.ui.internal; + +import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.swt.graphics.Image; + +public class JpaMappingImageHelper +{ + public static Image imageForTypeMapping(String mappingKey) { + if (IMappingKeys.NULL_TYPE_MAPPING_KEY == mappingKey) { + return JptUiPlugin.getImage(JptUiIcons.NULL_TYPE_MAPPING); + } + else if (IMappingKeys.ENTITY_TYPE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.ENTITY); + } + else if (IMappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.EMBEDDABLE); + } + else if (IMappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.MAPPED_SUPERCLASS); + } + return null; + } + + public static Image imageForAttributeMapping(String mappingKey) { + if (IMappingKeys.NULL_ATTRIBUTE_MAPPING_KEY == mappingKey) { + return JptUiPlugin.getImage(JptUiIcons.NULL_ATTRIBUTE_MAPPING); + } + else if (IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.BASIC); + } + else if (IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.ID); + } + else if (IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.VERSION); + } + else if (IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.EMBEDDED_ID); + } + else if (IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.EMBEDDED); + } + else if (IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.ONE_TO_ONE); + } + else if (IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.ONE_TO_MANY); + } + else if (IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.MANY_TO_ONE); + } + else if (IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.MANY_TO_MANY); + } + else if (IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { + return JptUiPlugin.getImage(JptUiIcons.TRANSIENT); + } + return null; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiIcons.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiIcons.java index abdd525cf2..e04747e58e 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiIcons.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiIcons.java @@ -12,5 +12,60 @@ package org.eclipse.jpt.ui.internal; public class JptUiIcons { + // **************** General JPA icons ************************************** + public static final String JPA_WIZ_BANNER = "full/wizban/jpa_facet_wizban"; //$NON-NLS-1$ + + public static final String JPA_CONTENT = "full/obj16/jpa-content"; //$NON-NLS-1$ + + public static final String JPA_FILE = "full/obj16/jpa-file"; //$NON-NLS-1$ + + + // **************** Persistence icons ************************************** + + public static final String PERSISTENCE = "full/obj16/persistence"; //$NON-NLS-1$ + + public static final String PERSISTENCE_UNIT = "full/obj16/persistence-unit"; //$NON-NLS-1$ + + public static final String MAPPING_FILE_REF = "full/obj16/jpa-file"; //$NON-NLS-1$ + + public static final String CLASS_REF = "full/obj16/null-type-mapping"; //$NON-NLS-1$ + + + // **************** Orm icons ********************************************** + + public static final String ENTITY_MAPPINGS = "full/obj16/entity-mappings"; //$NON-NLS-1$ + + + // **************** Orm/Java common icons ********************************** + + public static final String ENTITY = "full/obj16/entity"; //$NON-NLS-1$ + + public static final String EMBEDDABLE = "full/obj16/embeddable"; //$NON-NLS-1$ + + public static final String MAPPED_SUPERCLASS = "full/obj16/mapped-superclass"; //$NON-NLS-1$ + + public static final String NULL_TYPE_MAPPING = "full/obj16/null-type-mapping"; //$NON-NLS-1$ + + public static final String BASIC = "full/obj16/basic"; //$NON-NLS-1$ + + public static final String VERSION = "full/obj16/version"; //$NON-NLS-1$ + + public static final String ID = "full/obj16/id"; //$NON-NLS-1$ + + public static final String EMBEDDED_ID = "full/obj16/embedded-id"; //$NON-NLS-1$ + + public static final String EMBEDDED = "full/obj16/embedded"; //$NON-NLS-1$ + + public static final String ONE_TO_ONE = "full/obj16/one-to-one"; //$NON-NLS-1$ + + public static final String ONE_TO_MANY = "full/obj16/one-to-many"; //$NON-NLS-1$ + + public static final String MANY_TO_ONE = "full/obj16/many-to-one"; //$NON-NLS-1$ + + public static final String MANY_TO_MANY = "full/obj16/many-to-many"; //$NON-NLS-1$ + + public static final String TRANSIENT = "full/obj16/transient"; //$NON-NLS-1$ + + public static final String NULL_ATTRIBUTE_MAPPING = "full/obj16/null-attribute-mapping"; //$NON-NLS-1$ } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java index cdc142e820..95ed06f070 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java @@ -1,151 +1,102 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the 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) 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.ui.internal; import org.eclipse.osgi.util.NLS; -public class JptUiMessages extends NLS -{ - private static final String BUNDLE_NAME = "jpt_ui"; //$NON-NLS-1$ - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, JptUiMessages.class); - } - - public static String AddPersistentAttributeDialog_title; - +/** + * The resource strings used by the JPT UI classes. + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public class JptUiMessages extends NLS +{ + private static final String BUNDLE_NAME = "jpt_ui"; + public static String AddPersistentAttributeDialog_attributeLabel; - public static String AddPersistentAttributeDialog_mappingLabel; - public static String AddPersistentAttributeDialog_noMappingKeyError; - - public static String AddPersistentClassDialog_title; - - public static String AddPersistentClassDialog_classLabel; - - public static String AddPersistentClassDialog_classDialog_title; - + public static String AddPersistentAttributeDialog_title; public static String AddPersistentClassDialog_classDialog_message; - + public static String AddPersistentClassDialog_classDialog_title; + public static String AddPersistentClassDialog_classLabel; + public static String AddPersistentClassDialog_classNotFoundWarning; + public static String AddPersistentClassDialog_duplicateClassWarning; public static String AddPersistentClassDialog_mappingLabel; - public static String AddPersistentClassDialog_noClassError; - - public static String AddPersistentClassDialog_duplicateClassWarning; - - public static String AddPersistentClassDialog_classNotFoundWarning; - public static String AddPersistentClassDialog_noMappingKeyError; - + public static String AddPersistentClassDialog_title; + public static String AddRemovePane_AddButtonText; + public static String AddRemovePane_RemoveButtonText; + public static String DatabaseReconnectWizardPage_addConnectionLink; + public static String DatabaseReconnectWizardPage_connection; public static String DatabaseReconnectWizardPage_database; - public static String DatabaseReconnectWizardPage_databaseConnection; - + public static String DatabaseReconnectWizardPage_reconnectLink; public static String DatabaseReconnectWizardPage_reconnectToDatabase; - - public static String DatabaseReconnectWizardPage_connection; - public static String DatabaseReconnectWizardPage_schema; - public static String DatabaseReconnectWizardPage_schemaInfo; - - public static String DatabaseReconnectWizardPage_addConnectionLink; - - public static String DatabaseReconnectWizardPage_reconnectLink; - + public static String EnumComboViewer_default; + public static String EnumComboViewer_defaultWithDefault; public static String General_browse; - public static String General_deselectAll; - public static String General_selectAll; - public static String GenerateEntitiesWizard_generateEntities; - public static String GenerateEntitiesWizardPage_chooseEntityTable; - + public static String GenerateEntitiesWizardPage_entityNameColumn; public static String GenerateEntitiesWizardPage_generateEntities; - public static String GenerateEntitiesWizardPage_synchronizeClasses; - - public static String GenerateEntitiesWizardPage_tables; - public static String GenerateEntitiesWizardPage_tableColumn; - - public static String GenerateEntitiesWizardPage_entityNameColumn; - - public static String GenericPlatformUiDialog_notSupportedMessageTitle; - + public static String GenerateEntitiesWizardPage_tables; public static String GenericPlatformUiDialog_notSupportedMessageText; - - public static String JpaPreferencePage_defaultJpaLib; - - public static String JpaPreferencePage_userLibsLink; - - public static String JpaPreferencePage_invalidJpaLib; - - public static String JpaStructureView_viewNotAvailable; - - public static String JpaStructureView_linkWithEditorText; - - public static String JpaStructureView_linkWithEditorDesc; - - public static String JpaStructureView_linkWithEditorTooltip; - + public static String GenericPlatformUiDialog_notSupportedMessageTitle; public static String JpaDetailsView_viewNotAvailable; - - public static String NewJpaProjectWizard_title; - - public static String NewJpaProjectWizard_firstPage_title; - - public static String NewJpaProjectWizard_firstPage_description; - - public static String JpaFacetWizardPage_title; - - public static String JpaFacetWizardPage_description; - - public static String JpaFacetWizardPage_platformLabel; - public static String JpaFacetWizardPage_connectionLabel; - public static String JpaFacetWizardPage_connectionLink; - + public static String JpaFacetWizardPage_createOrmXmlButton; + public static String JpaFacetWizardPage_description; + public static String JpaFacetWizardPage_discoverClassesButton; public static String JpaFacetWizardPage_jpaImplementationLabel; - - public static String JpaFacetWizardPage_userServerLibLabel; - - public static String JpaFacetWizardPage_specifyLibLabel; - public static String JpaFacetWizardPage_jpaPrefsLink; - - public static String JpaFacetWizardPage_userLibsLink; - - public static String JpaFacetWizardPage_persistentClassManagementLabel; - - public static String JpaFacetWizardPage_discoverClassesButton; - public static String JpaFacetWizardPage_listClassesButton; - - public static String JpaFacetWizardPage_createOrmXmlButton; - + public static String JpaFacetWizardPage_persistentClassManagementLabel; + public static String JpaFacetWizardPage_platformLabel; + public static String JpaFacetWizardPage_specifyLibLabel; + public static String JpaFacetWizardPage_title; + public static String JpaFacetWizardPage_userLibsLink; + public static String JpaFacetWizardPage_userServerLibLabel; + public static String JpaPreferencePage_defaultJpaLib; + public static String JpaPreferencePage_invalidJpaLib; + public static String JpaPreferencePage_userLibsLink; + public static String JpaStructureView_linkWithEditorDesc; + public static String JpaStructureView_linkWithEditorText; + public static String JpaStructureView_linkWithEditorTooltip; + public static String JpaStructureView_structureNotAvailable; + public static String NewJpaProjectWizard_firstPage_description; + public static String NewJpaProjectWizard_firstPage_title; + public static String NewJpaProjectWizard_title; + public static String OrmItemLabelProviderFactory_entityMappingsLabel; + public static String OverwriteConfirmerDialog_text; + public static String OverwriteConfirmerDialog_title; + public static String PersistenceItemLabelProviderFactory_persistenceLabel; public static String PersistentAttributePage_mapAs; - public static String PersistentTypePage_mapAs; - - public static String OverwriteConfirmerDialog_title; - public static String OverwriteConfirmerDialog_text; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, JptUiMessages.class); + } - private JptUiMessages() { throw new UnsupportedOperationException(); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiPlugin.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiPlugin.java index 77e697c5d8..693b62143c 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiPlugin.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiPlugin.java @@ -11,6 +11,9 @@ package org.eclipse.jpt.ui.internal; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jpt.core.internal.IJpaPlatform; +import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; +import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; public class JptUiPlugin extends AbstractUIPlugin @@ -43,15 +46,12 @@ public class JptUiPlugin extends AbstractUIPlugin } - public JptUiPlugin() { - super(); - INSTANCE = this; - } + // **************** Image API ********************************************** /** * This gets a .gif from the icons folder. */ - public ImageDescriptor getImageDescriptor(String key) { + public static ImageDescriptor getImageDescriptor(String key) { if (! key.startsWith("icons/")) { key = "icons/" + key; } @@ -60,4 +60,28 @@ public class JptUiPlugin extends AbstractUIPlugin } return imageDescriptorFromPlugin(PLUGIN_ID, key); } + + /** + * This returns an image for a .gif from the icons folder + */ + public static Image getImage(String key) { + ImageDescriptor desc = getImageDescriptor(key); + return (desc == null) ? null : desc.createImage(); + } + + + // **************** Construction ******************************************* + + public JptUiPlugin() { + super(); + INSTANCE = this; + } + + + /** + * Return the JPA platform UI corresponding to the given JPA platform + */ + public IJpaPlatformUi jpaPlatformUi(IJpaPlatform jpaPlatform) { + return JpaPlatformUiRegistry.instance().jpaPlatform(jpaPlatform.getId()); + } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/Tracing.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/Tracing.java new file mode 100644 index 0000000000..4589e13b95 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/Tracing.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * 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.ui.internal; + +import org.eclipse.core.runtime.Platform; + +/** + * This tracing class manages to convert the string value into boolean values or + * integer values that are associated with the tracing debug flags. Those flags + * are specified in the .options file. The supported keys are defined here as + * constants for quick reference. + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class Tracing +{ + /** + * A constant used to retrieve the value associated with "/debug". + */ + public static final String DEBUG = "/debug"; + + /** + * A constant used to retrieve the value associated with "/debug/ui/db". + */ + public static final String UI_DB = "/debug/ui/db"; + + /** + * A constant used to retrieve the value associated with "/debug/ui/detailsView". + */ + public static final String UI_DETAILS_VIEW = "/debug/ui/detailsView"; + + /** + * A constant used to retrieve the value associated with "/debug/ui/layout". + */ + public static final String UI_LAYOUT = "/debug/ui/layout"; + + /** + * A constant used to retrieve the value associated with "/unit-tests". + */ + public static final String UNIT_TESTS = "/unit-tests"; + + /** + * Can't instantiate this <code>Tracing</code> class. + */ + private Tracing() + { + super(); + throw new UnsupportedOperationException("Tracing cannot be instantiated"); + } + + /** + * Retrieves the debug value associated with the given flag. The default + * value is <code>false</code>. + * + * @param flag The flag to retrieve the debug value, which should be + * contained in the .options file, the flag should start with "/" + * @return <code>true</code> if the given flag is active; <code>false</code> + * otherwise + */ + public static boolean booleanDebugOption(String flag) + { + return booleanDebugOption(flag, false); + } + + /** + * Retrieves the debug value associated with the given flag. + * + * @param flag The flag to retrieve the debug value, which should be + * contained in the .options file, the flag should start with "/" + * @param defaultValue The default value if the value associated with the + * given flag could not be found + * @return <code>true</code> if the given flag is active; <code>false</code> + * otherwise + */ + public static boolean booleanDebugOption(String flag, boolean defaultValue) + { + String result = Platform.getDebugOption(JptUiPlugin.PLUGIN_ID + flag); + + if (result == null) + { + return defaultValue; + } + + return Boolean.valueOf(result.trim()); + } + + /** + * Retrieves the debug value associated with the given flag. The default value + * is 0. + * + * @param flag The flag to retrieve the debug value, which should be + * contained in the .options file, the flag should start with "/" + * @return The value associated with the given flag, or the given default + * value + */ + public static int intDebugOption(String flag) + { + return intDebugOption(flag, 0); + } + + /** + * Retrieves the debug value associated with the given flag. + * + * @param flag The flag to retrieve the debug value, which should be + * contained in the .options file, the flag should start with "/" + * @param defaultValue The default value if the value associated with the + * given flag could not be found + * @return The value associated with the given flag, or the given default + * value + */ + public static int intDebugOption(String flag, int defaultValue) + { + String result = Platform.getDebugOption(JptUiPlugin.PLUGIN_ID + flag); + + if (result == null) + { + return defaultValue; + } + + return Integer.valueOf(result); + } + + /** + * Logs the given messages, appends it with this plug-in id. + * + * @param message The message to be logged + */ + public static void log(String message) + { + System.out.print("[" + JptUiPlugin.PLUGIN_ID + "] "); + System.out.println(message); + } + + /** + * Retrieves the debug value associated with the given flag. The default value + * is an empty string. + * + * @param flag The flag to retrieve the debug value, which should be + * contained in the .options file, the flag should start with "/" + * @return The value associated with the given flag, or the given default + * value + */ + public static String stringDebugOption(String flag) + { + return stringDebugOption(flag, ""); + } + + /** + * Retrieves the debug value associated with the given flag. + * + * @param flag The flag to retrieve the debug value, which should be + * contained in the .options file, the flag should start with "/" + * @param defaultValue The default value if the value associated with the + * given flag could not be found + * @return The value associated with the given flag, or the given default + * value + */ + public static String stringDebugOption(String flag, String defaultValue) + { + String result = Platform.getDebugOption(JptUiPlugin.PLUGIN_ID + flag); + + if (result == null) + { + result = defaultValue; + } + + return result; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAction.java index f38efd98b4..4a26ae0b84 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAction.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAction.java @@ -13,7 +13,7 @@ import java.util.Iterator; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; import org.eclipse.ui.actions.ActionDelegate; public class AddPersistentAttributeToXmlAction extends ActionDelegate diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAndMapAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAndMapAction.java index f8ee7458a8..2a7377678e 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAndMapAction.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentAttributeToXmlAndMapAction.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.ui.internal.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; import org.eclipse.jpt.ui.internal.dialogs.AddPersistentAttributeToXmlAndMapDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentClassAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentClassAction.java index 23b4deba52..79328635fa 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentClassAction.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/AddPersistentClassAction.java @@ -13,7 +13,7 @@ package org.eclipse.jpt.ui.internal.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; import org.eclipse.jpt.ui.internal.dialogs.AddPersistentClassDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; @@ -24,7 +24,7 @@ public class AddPersistentClassAction { private Shell shell; - private EntityMappingsInternal entityMappings; + private EntityMappings entityMappings; public AddPersistentClassAction() { @@ -40,10 +40,10 @@ public class AddPersistentClassAction } public void selectionChanged(IAction action, ISelection selection) { - entityMappings = (EntityMappingsInternal) ((StructuredSelection) selection).getFirstElement(); + this.entityMappings = (EntityMappings) ((StructuredSelection) selection).getFirstElement(); } public void setActivePart(IAction action, IWorkbenchPart targetPart) { - shell = targetPart.getSite().getShell(); + this.shell = targetPart.getSite().getShell(); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/PersistentAttributeActionFilter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/PersistentAttributeActionFilter.java index 243055089e..8a61c71abc 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/PersistentAttributeActionFilter.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/PersistentAttributeActionFilter.java @@ -11,7 +11,7 @@ package org.eclipse.jpt.ui.internal.actions; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.jpt.core.internal.IMappingKeys; -import org.eclipse.jpt.core.internal.IPersistentAttribute; +import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute; import org.eclipse.ui.IActionFilter; public class PersistentAttributeActionFilter diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/ProjectAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/ProjectAction.java index 96bd1d9ff6..8189b0b7b4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/ProjectAction.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/ProjectAction.java @@ -18,7 +18,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.internal.IJpaProject; import org.eclipse.jpt.core.internal.JptCorePlugin; import org.eclipse.jpt.ui.internal.IJpaPlatformUi; -import org.eclipse.jpt.ui.internal.PlatformRegistry; +import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; @@ -76,7 +76,7 @@ public abstract class ProjectAction implements IObjectActionDelegate { protected IJpaPlatformUi jpaPlatformUi(IJpaProject project) { String coreJpaPlatformId = project.jpaPlatform().getId(); - return PlatformRegistry.instance().jpaPlatform(coreJpaPlatformId); + return JpaPlatformUiRegistry.instance().jpaPlatform(coreJpaPlatformId); } protected void execute(IProject project) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentAttributeFromXmlAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentAttributeFromXmlAction.java index 849f0eacd0..6a074289ad 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentAttributeFromXmlAction.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentAttributeFromXmlAction.java @@ -13,8 +13,7 @@ import java.util.Iterator; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentType; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; import org.eclipse.ui.actions.ActionDelegate; public class RemovePersistentAttributeFromXmlAction extends ActionDelegate @@ -32,8 +31,7 @@ public class RemovePersistentAttributeFromXmlAction extends ActionDelegate if (this.selection instanceof StructuredSelection) { for (Iterator<XmlPersistentAttribute> i = ((StructuredSelection) selection).iterator(); i.hasNext(); ) { XmlPersistentAttribute xmlPersistentAttribute = i.next(); - XmlPersistentType xmlPersistentType = xmlPersistentAttribute.typeMapping().getPersistentType(); - xmlPersistentType.getSpecifiedAttributeMappings().remove(xmlPersistentAttribute.getMapping()); + xmlPersistentAttribute.setVirtual(true); } } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentClassAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentClassAction.java index 3d8a55a236..2ca72027cd 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentClassAction.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/RemovePersistentClassAction.java @@ -13,16 +13,14 @@ package org.eclipse.jpt.ui.internal.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentType; -import org.eclipse.jpt.core.internal.content.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; public class RemovePersistentClassAction implements IObjectActionDelegate { - private XmlPersistentType persistentClass; + private XmlPersistentType persistentType; public RemovePersistentClassAction() { @@ -30,12 +28,11 @@ public class RemovePersistentClassAction } public void run(IAction action) { - XmlTypeMapping mapping = persistentClass.getMapping(); - ((EntityMappingsInternal) mapping.getEntityMappings()).getTypeMappings().remove(mapping); + this.persistentType.entityMappings().removeXmlPersistentType(this.persistentType); } public void selectionChanged(IAction action, ISelection selection) { - persistentClass = (XmlPersistentType) ((StructuredSelection) selection).getFirstElement(); + this.persistentType = (XmlPersistentType) ((StructuredSelection) selection).getFirstElement(); } public void setActivePart(IAction action, IWorkbenchPart targetPart) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/XmlPersistentAttributeActionFilter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/XmlPersistentAttributeActionFilter.java index 736953be85..084bf44654 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/XmlPersistentAttributeActionFilter.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/XmlPersistentAttributeActionFilter.java @@ -10,7 +10,7 @@ package org.eclipse.jpt.ui.internal.actions; import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; import org.eclipse.ui.IActionFilter; public class XmlPersistentAttributeActionFilter @@ -19,6 +19,7 @@ public class XmlPersistentAttributeActionFilter public static final String IS_VIRTUAL = "isVirtual"; + @Override public boolean testAttribute(Object target, String name, String value) { if (! IS_VIRTUAL.equals(name)) { return super.testAttribute(target, name, value); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaComposite.java index 6c3ff8ba80..a53cfa156d 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaComposite.java @@ -3,45 +3,94 @@ * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: Oracle. - initial API and implementation *******************************************************************************/ package org.eclipse.jpt.ui.internal.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.node.Node; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public abstract class BaseJpaComposite extends BaseJpaController - implements IJpaComposite +/** + * @deprecated Extend directly BaseJpaController, this pane will go away the + * moment I have a sec. ~PF + */ +@Deprecated +public abstract class BaseJpaComposite<T extends Node> extends BaseJpaController<T> { - private Composite composite; - - public BaseJpaComposite(Composite parent, int style, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, style, theCommandStack, widgetFactory); + /** + * Creates a new <code>BaseJpaComposite</code>. + * + * @param parentController The parent container of this one + * @param parent The parent container + */ + protected BaseJpaComposite(BaseJpaController<? extends T> parentController, + Composite parent) { + + super(parentController, parent); } - - public BaseJpaComposite(Composite parent, CommandStack theCommandStack,TabbedPropertySheetWidgetFactory widgetFactory) { - this(parent, SWT.NULL, theCommandStack, widgetFactory); + + /** + * Creates a new <code>BaseJpaComposite</code>. + * + * @param parentController The parent container of this one + * @param parent The parent container + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + */ + protected BaseJpaComposite(BaseJpaController<? extends T> parentController, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentController, parent, automaticallyAlignWidgets); } - - @Override - protected void buildWidget(Composite parent, int style) { - super.buildWidget(parent); - this.composite = createComposite(parent, style); - initializeLayout(this.composite); + + /** + * Creates a new <code>BaseJpaComposite</code>. + * + * @param parentController The parent container of this one + * @param subjectHolder The holder of the subject + * @param parent The parent container + */ + protected BaseJpaComposite(BaseJpaController<?> parentController, + PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + super(parentController, subjectHolder, parent); } - - protected Composite createComposite(Composite parent, int style) { - return this.widgetFactory.createComposite(parent, style); + + /** + * Creates a new <code>BaseJpaComposite</code>. + * + * @param parentController The parent container of this one + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + */ + protected BaseJpaComposite(BaseJpaController<?> parentController, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentController, subjectHolder, parent, automaticallyAlignWidgets); } - - protected abstract void initializeLayout(Composite composite); - public Control getControl() { - return this.composite; + /** + * Creates a new <code>BaseJpaComposite</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + protected BaseJpaComposite(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaController.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaController.java index 84ac1dca1b..0806931ac4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaController.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaController.java @@ -1,110 +1,114 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public abstract class BaseJpaController +/** + * The abstract class used to create a pane. (TODO) + * + * @deprecated Remove this pane and extend directly AbstractFormPane. + * + * @version 2.0 + * @since 1.0 + */ +@Deprecated +public abstract class BaseJpaController<T extends Model> extends AbstractFormPane<T> + implements IJpaComposite<T> { - //****** we are using this commandStack in 0 places ******** - //do we plan to use it in the future? *should* we be using it? are we removing emf? - protected CommandStack commandStack; - - protected TabbedPropertySheetWidgetFactory widgetFactory; + /** + * Creates a new <code>BaseJpaController</code>. + * + * @param parentController The parent controller of this one + * @param parent The parent container + * + * @category Constructor + */ + protected BaseJpaController(BaseJpaController<? extends T> parentController, + Composite parent) { - //put in the populating flag to stop the circular population of the entity name combo - //populateEntityNameCombo is calling select() which causes entityNameComboModified() to be called - //this sets the name in the model which starts the circle over again. We should probably - //short-circuit this differently, like in the emf model, keep the property change from being fired if - //a change did not actually occur - KFM - private boolean populating; - - - public BaseJpaController(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(); - this.widgetFactory = widgetFactory; - buildWidget(parent); - this.commandStack = theCommandStack; + super(parentController, parent); } - - public BaseJpaController(Composite parent, int style, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(); - this.widgetFactory = widgetFactory; - buildWidget(parent, style); - this.commandStack = theCommandStack; - } - - + /** - * Override this method if using the constructor without the style bit + * Creates a new <code>BaseJpaController</code>. + * + * @param parentController The parent container of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + * + * @category Constructor */ - protected void buildWidget(Composite parent) { - // no op + protected BaseJpaController(BaseJpaController<? extends T> parentController, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentController, parent, automaticallyAlignWidgets); } - + /** - * Override this method if using the constructor with the style bit + * Creates a new <code>BaseJpaController</code>. + * + * @param parentController The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * + * @category Constructor */ - protected void buildWidget(Composite parent, int style) { - // no op + protected BaseJpaController(BaseJpaController<?> parentController, + PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + super(parentController, subjectHolder, parent); } - + /** - * This method is called from outside when setting the object of interest + * Creates a new <code>BaseJpaController</code>. + * + * @param parentController The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + * + * @category Constructor */ - public final void populate(EObject obj) { - if (getControl().isDisposed()) { - return; - } - this.populating = true; - disengageListeners(); - doPopulate(obj); - engageListeners(); - this.populating = false; + protected BaseJpaController(BaseJpaController<?> parentController, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentController, subjectHolder, parent, automaticallyAlignWidgets); } - + /** - * This method is called (perhaps internally) when this needs to repopulate - * but the object of interest has not changed + * Creates a new <code>BaseJpaController</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + * + * @category Constructor */ - public final void populate() { - if (getControl().isDisposed()) { - return; - } - this.populating = true; - doPopulate(); - this.populating = false; - } - - protected abstract void doPopulate(EObject obj); - - protected abstract void doPopulate(); - - protected abstract void engageListeners(); - - protected abstract void disengageListeners(); - - protected boolean isPopulating() { - return this.populating; - } - - public TabbedPropertySheetWidgetFactory getWidgetFactory() { - return this.widgetFactory; - } - - public void dispose() { - disengageListeners(); + protected BaseJpaController(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - - public abstract Control getControl(); -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaDetailsPage.java index d57e13f02a..86154fc78a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BaseJpaDetailsPage.java @@ -1,63 +1,56 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public abstract class BaseJpaDetailsPage extends BaseJpaComposite - implements IJpaDetailsPage +/** + * The base class for the details view. + * + * @see IJpaContextNode + * + * @version 2.0 + * @since 1.0 + */ +public abstract class BaseJpaDetailsPage<T extends IJpaContextNode> + extends AbstractFormPane<T> + implements IJpaDetailsPage<T> { - private Composite control; + /** + * Creates a new <code>BaseJpaDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + protected BaseJpaDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { - public BaseJpaDetailsPage( - Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); + super(new SimplePropertyValueModel<T>(), parent, widgetFactory); } - public BaseJpaDetailsPage( - Composite parent, int style, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, style, theCommandStack, widgetFactory); - } - - @Override - //using this to get a Scroll bar on the JpaDetailsView - protected Composite createComposite(Composite parent, int style) { - ScrolledForm scrolledForm = this.widgetFactory.createScrolledForm(parent); - //Nesting another composite because combos on the ScrolledForm didn't have a border - scrolledForm.getBody().setLayout(new FillLayout()); - Composite composite = super.createComposite(scrolledForm.getBody(), style); - this.control = scrolledForm; - return composite; - } + /* + * (non-Javadoc) + */ + public final void setSubject(T subject) { + WritablePropertyValueModel<T> subjectHolder = (WritablePropertyValueModel<T>) getSubjectHolder(); + subjectHolder.setValue(subject); - public final void populate(IJpaContentNode contentNode) { - super.populate(contentNode); - } - - @Override - protected final void doPopulate(EObject obj) { - doPopulate((IJpaContentNode) obj); + if (subject != null) { + populate(); + } + else { + dispose(); + } } - - protected abstract void doPopulate(IJpaContentNode contentNode); - - - @Override - public Control getControl() { - return this.control; - } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaComposite.java index bd09fed9d7..80eb8d52fd 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaComposite.java @@ -1,22 +1,38 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 Oracle. All rights reserved. This + * Copyright (c) 2005, 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.ui.internal.details; -import org.eclipse.emf.ecore.EObject; import org.eclipse.swt.widgets.Control; +/** + * A <code>IJpaComposite</code> defines the common behavior of the JPA related + * widgets. + */ +public interface IJpaComposite<T> { -public interface IJpaComposite<E extends EObject> { + /** + * Notifies this composite it should populates its widgets using the given + * model object. + * + * @param model The model used to retrieve the information to be displayed + */ + void populate(); - void populate(E model); - + /** + * Returns the actual <code>Composite</code>. + * + * @return This composite's actual widget + */ Control getControl(); - + + /** + * Notifies this composite it should dispose any resources. + */ void dispose(); -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsPage.java index ae78d2fc38..a370d5e440 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsPage.java @@ -1,28 +1,39 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.details; -import org.eclipse.jpt.core.internal.IJpaContentNode; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; import org.eclipse.swt.widgets.Control; -public interface IJpaDetailsPage +/** + * A details page is used to show the propery pane for a given context node. The + * <code>IJpaDetailsProvider</code> is responsible for creating the pane. + * + * @see IJpaDetailsProvider + * + * @version 2.0 + * @since 2.0 + */ +public interface IJpaDetailsPage<T extends IJpaContextNode> { - Control getControl(); - /** - * Set the content for the page and populate widgets + * Returns this details' page's widget. + * + * @return The container of the widgets shown by this details page */ - void populate(IJpaContentNode contentNode); - - + Control getControl(); + /** - * Perform any other disposal needed + * Sets the subject for this details page. + * + * @param subject Either the new subject or <code>null</code> if the subject + * needs to be removed */ - void dispose(); -} + void setSubject(T subject); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsProvider.java index aab2f6f721..e125c62fcd 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IJpaDetailsProvider.java @@ -1,27 +1,38 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.details; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public interface IJpaDetailsProvider +/** + * This provider is responsible to create the <code>IJpaDetailsPage</code> + * responsible to show the information for a given content node id. + * + * @see IJpaDetailsPage + * + * @version 2.0 + * @since 2.0 + */ +public interface IJpaDetailsProvider { - - String fileContentType(); - /** - * Build a properties page given the parent Composite and the - * content node id. - * It is legal to set the layout for the given Composite. + * 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 */ - IJpaDetailsPage buildDetailsPage(Composite parentComposite, Object contentNodeId, TabbedPropertySheetWidgetFactory widgetFactory); - - void dispose(); -} + IJpaDetailsPage<? extends IJpaContextNode> buildDetailsPage( + Composite parent, + Object contentNodeId, + TabbedPropertySheetWidgetFactory widgetFactory); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PageBookManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PageBookManager.java index 80c583ba2c..993b8f88f4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PageBookManager.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PageBookManager.java @@ -3,14 +3,12 @@ * program and the accompanying materials are made available under the terms 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. - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.details; -import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; @@ -23,30 +21,30 @@ import org.eclipse.ui.part.PageBook; */ public class PageBookManager extends PageBook { - private Map pageRecords; + private Map<Object, Composite> pageRecords; private Object active; private PageBook pageBook; private Composite defaultComposite; - + /** * A <code>PageBookManager<code> is a wrapper for a <code>PageBook</code>. It provides * convenience methods to add, remove, activate and inactive pages in the internal <code>PageBook</code>. * If a page gets deactivated, the manager activates a default page. - * + * * @param parent The parent composite to this manager * @param aDefaultLabel The label on the the default page. */ public PageBookManager(Composite parent, String aDefaultLabel) { super(parent, SWT.NULL); this.setLayout(new FillLayout()); - this.pageRecords = new HashMap(); + this.pageRecords = new HashMap<Object, Composite>(); this.pageBook = new PageBook(this, SWT.NONE); this.defaultComposite = new DefaultComposite(pageBook, aDefaultLabel); this.pageBook.showPage(this.defaultComposite); } /** - * @param anObj Activates (flips to top in the <code>PageBook</code>) the associated <code>Composite</code> + * @param anObj Activates (flips to top in the <code>PageBook</code>) the associated <code>Composite</code> * for the given <code>Object</code>. Activates the <code>DefaultComposite</code> if there is no association * for the given <code>Object</code>. * @return Return false if there is no <code>Composite</code> association to the given <code>Object</code> or @@ -54,7 +52,7 @@ public class PageBookManager extends PageBook { */ public boolean activate(Object anObj) { if(anObj != null && !anObj.equals(this.active) && this.pageRecords.containsKey(anObj)) { - Composite composite = (Composite) this.pageRecords.get(anObj); + Composite composite = this.pageRecords.get(anObj); this.pageBook.showPage(composite); this.active = anObj; return true; @@ -64,7 +62,7 @@ public class PageBookManager extends PageBook { } return false; } - + /** * @param anObj * @return Returns true if the associated <code>Composite</code> has been deactivated. @@ -86,19 +84,19 @@ public class PageBookManager extends PageBook { * in this <code>PageBookManager</code>. * If this manager previously contained a mapping for the <code>Object</code>, the old * <code>Composite</code> is replaced by the specified <code>Composite</code>. - * + * * @param anObj <code>Object</code> with which the specified <code>Composite</code> is to be associated. * @param aComposite <code>Composite</code> to be associated with the specified <code>Object</code>. - * + * * @return previous <code>Composite</code> associated with specified <code>Object</code>, * or <tt>null</tt> if there was no mapping for <code>Object</code>. */ public Composite put(Object anObj, Composite aComposite) { - Composite composite = (Composite) this.pageRecords.put(anObj, aComposite); + Composite composite = this.pageRecords.put(anObj, aComposite); this.activate(anObj); return composite; } - + /** * Removes the mapping for this <code>Object</code> from this pagebookmanager if it is present. * @@ -109,8 +107,8 @@ public class PageBookManager extends PageBook { if(anObj.equals(this.active)) { this.active = null; this.pageBook.showPage(this.defaultComposite); - } - return (Composite) this.pageRecords.remove(anObj); + } + return this.pageRecords.remove(anObj); } /** @@ -121,9 +119,9 @@ public class PageBookManager extends PageBook { public boolean contains(Object anObj) { return this.pageRecords.containsKey(anObj); } - + public Composite get(Object key) { - return (Composite) pageRecords.get(key); + return pageRecords.get(key); } /** @@ -133,12 +131,12 @@ public class PageBookManager extends PageBook { if(this.active == null) { return this.defaultComposite; } else { - return (Composite) this.pageRecords.get(this.active); + return this.pageRecords.get(this.active); } } /** - * @return The internal <code>PageBook</code> of this <code>PageBookManager</code>. + * @return The internal <code>PageBook</code> of this <code>PageBookManager</code>. * <code>Composite</code>s which should work with this manager needs to be created * with this <code>Composite</code> as their parent composite. */ @@ -156,12 +154,12 @@ public class PageBookManager extends PageBook { label.setText(aDefaultLabel); } } - + + @Override public void dispose() { super.dispose(); - Collection composites = this.pageRecords.values(); - for (Iterator i = composites.iterator(); i.hasNext(); ) { - ((Composite) i.next()).dispose(); + for (Composite pane : this.pageRecords.values()) { + pane.dispose(); } } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentAttributeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentAttributeDetailsPage.java index 870e35677c..0505cd01a3 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentAttributeDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentAttributeDetailsPage.java @@ -1,22 +1,18 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.details; +import java.util.Collection; import java.util.HashMap; import java.util.ListIterator; import java.util.Map; - -import org.eclipse.emf.common.command.BasicCommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.IContentProvider; @@ -26,276 +22,365 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.internal.IAttributeMapping; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.jpt.core.internal.IPersistentAttribute; -import org.eclipse.jpt.core.internal.JpaCorePackage; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; +import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute; import org.eclipse.jpt.ui.internal.IJpaPlatformUi; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.PlatformRegistry; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +import org.eclipse.jpt.ui.internal.Tracing; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; +import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; +import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.Filter; +import org.eclipse.jpt.utility.internal.model.value.FilteringPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public abstract class PersistentAttributeDetailsPage extends BaseJpaDetailsPage +/** + * The abstract definition of the details page responsible to show the + * information for an persistent attribute. + * + * @see IPersistentAttribute + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public abstract class PersistentAttributeDetailsPage<T extends IPersistentAttribute> extends BaseJpaDetailsPage<T> { - private IPersistentAttribute attribute; - private IAttributeMapping attributeMapping; - private Adapter persistentAttributeListener; - + private IJpaComposite<IAttributeMapping> currentMappingComposite; private String currentMappingKey; - private ComboViewer mappingCombo; - private Map<String, IJpaComposite<IAttributeMapping>> mappingComposites; - protected PageBook mappingPageBook; - private IJpaComposite<IAttributeMapping> currentMappingComposite; - - public PersistentAttributeDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NONE, new BasicCommandStack(), widgetFactory); - this.persistentAttributeListener = buildAttributeListener(); - this.mappingComposites = new HashMap<String, IJpaComposite<IAttributeMapping>>(); - } - - protected IJpaPlatformUi jpaPlatformUi() { - String platformId = getAttribute().jpaPlatform().getId(); - return PlatformRegistry.instance().jpaPlatform(platformId); + private PageBook mappingPageBook; + + /** + * Creates a new <code>PersistentAttributeDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + protected PersistentAttributeDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(parent, widgetFactory); } - protected IJpaUiFactory jpaUiFactory() { - return jpaPlatformUi().getJpaUiFactory(); + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IPersistentAttribute.DEFAULT_MAPPING_PROPERTY); + propertyNames.add(IPersistentAttribute.SPECIFIED_MAPPING_PROPERTY); } - - protected abstract ListIterator<IAttributeMappingUiProvider> attributeMappingUiProviders(); - - protected abstract ListIterator<IAttributeMappingUiProvider> defaultAttributeMappingUiProviders(); - - protected IAttributeMappingUiProvider attributeMappingUiProvider(String key) { - for (ListIterator<IAttributeMappingUiProvider> i = attributeMappingUiProviders(); i.hasNext(); ) { - IAttributeMappingUiProvider provider = i.next(); + + protected IAttributeMappingUiProvider<? extends IAttributeMapping> attributeMappingUiProvider(String key) { + for (ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> i = attributeMappingUiProviders(); i.hasNext(); ) { + IAttributeMappingUiProvider<? extends IAttributeMapping> provider = i.next(); if (provider.attributeMappingKey() == key) { return provider; } } throw new IllegalArgumentException("Unsupported attribute mapping UI provider key: "); } - - protected abstract IAttributeMappingUiProvider defaultAttributeMappingUiProvider(String key); - - private Adapter buildAttributeListener() { - return new AdapterImpl() { - @Override - public void notifyChanged(Notification notification) { - persistentAttributeChanged(notification); - } - }; - } - - protected void persistentAttributeChanged(Notification notification) { - switch (notification.getFeatureID(IPersistentAttribute.class)) { - case JpaCorePackage.IPERSISTENT_ATTRIBUTE__MAPPING: - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - break; - } - } - - protected Label buildMappingLabel(Composite parent) { - return getWidgetFactory().createLabel(parent, JptUiMessages.PersistentAttributePage_mapAs); - } - - protected ComboViewer buildMappingCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - this.mappingCombo = new ComboViewer(combo); - this.mappingCombo.setContentProvider(buildContentProvider()); - this.mappingCombo.setLabelProvider(buildLabelProvider()); - this.mappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - mappingChanged(event); - } - }); - return this.mappingCombo; - } + + protected abstract ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> + attributeMappingUiProviders(); + + protected abstract IAttributeMappingUiProvider<? extends IAttributeMapping>[] + attributeMappingUiProvidersFor(IPersistentAttribute persistentAttribute); private IContentProvider buildContentProvider() { return new IStructuredContentProvider() { public void dispose() { // do nothing } - + public Object[] getElements(Object inputElement) { if (inputElement == null) { - return new Object[]{}; + return new Object[0]; } return attributeMappingUiProvidersFor((IPersistentAttribute) inputElement); } - + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing } }; } - - protected abstract IAttributeMappingUiProvider[] attributeMappingUiProvidersFor(IPersistentAttribute persistentAttribute); - + + private PropertyAspectAdapter<IPersistentAttribute, IAttributeMapping> buildGenericMappingHolder() { + return new PropertyAspectAdapter<IPersistentAttribute, IAttributeMapping>( + getSubjectHolder(), + IPersistentAttribute.DEFAULT_MAPPING_PROPERTY, + IPersistentAttribute.SPECIFIED_MAPPING_PROPERTY) + { + @Override + protected IAttributeMapping buildValue_() { + return subject.getMapping(); + } + }; + } + private IBaseLabelProvider buildLabelProvider() { return new LabelProvider() { @Override public String getText(Object element) { - return ((IAttributeMappingUiProvider) element).label(); + return ((IAttributeMappingUiProvider<?>) element).label(); } }; } - + + protected ComboViewer buildMappingCombo(Composite parent) { + + this.mappingCombo = buildComboViewer(parent, buildLabelProvider()); + this.mappingCombo.getCCombo().setVisibleItemCount(Integer.MAX_VALUE); + this.mappingCombo.setContentProvider(buildContentProvider()); + this.mappingCombo.addSelectionChangedListener(buildMappingComboModifyListener()); + return this.mappingCombo; + } + + private ISelectionChangedListener buildMappingComboModifyListener() { + return new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent e) { + mappingChanged(e); + } + }; + } + + @SuppressWarnings("unchecked") + protected IJpaComposite<IAttributeMapping> buildMappingComposite(PageBook pageBook, + String key) { + + IAttributeMappingUiProvider<IAttributeMapping> uiProvider = (IAttributeMappingUiProvider<IAttributeMapping>) mappingUIProvider(key); + + return uiProvider.buildAttributeMappingComposite( + jpaUiFactory(), + buildMappingHolder(key), + pageBook, + getFormWidgetFactory() + ); + } + + private Filter<IAttributeMapping> buildMappingFilter(final String key) { + return new Filter<IAttributeMapping>() { + public boolean accept(IAttributeMapping value) { + return (value == null) || key.equals(value.getKey()); + } + }; + } + + private PropertyValueModel<IAttributeMapping> buildMappingHolder(final String key) { + return new FilteringPropertyValueModel<IAttributeMapping>( + buildGenericMappingHolder(), + buildMappingFilter(key) + ); + } + + protected Label buildMappingLabel(Composite parent) { + return buildLabel(parent, JptUiMessages.PersistentAttributePage_mapAs); + } + protected PageBook buildMappingPageBook(Composite parent) { this.mappingPageBook = new PageBook(parent, SWT.NONE); return this.mappingPageBook; } - - protected IJpaComposite<IAttributeMapping> buildMappingComposite(PageBook pageBook, String key) { - if (this.attributeMapping == null || this.attributeMapping.isDefault()) { - return defaultAttributeMappingUiProvider(key).buildAttributeMappingComposite(jpaUiFactory(), pageBook, this.commandStack, getWidgetFactory()); - } - return attributeMappingUiProvider(key).buildAttributeMappingComposite(jpaUiFactory(), pageBook, this.commandStack, getWidgetFactory()); - } - - void mappingChanged(SelectionChangedEvent event) { - if (isPopulating()) { - return; - } - if (event.getSelection() instanceof StructuredSelection) { - IAttributeMappingUiProvider provider = (IAttributeMappingUiProvider) ((StructuredSelection) event.getSelection()).getFirstElement(); - String key = (CollectionTools.contains(defaultAttributeMappingUiProviders(), provider) ? null : provider.attributeMappingKey()); - this.attribute.setSpecifiedMappingKey(key); - } - } - + protected abstract IAttributeMappingUiProvider<? extends IAttributeMapping> + defaultAttributeMappingUiProvider(String key); + + protected abstract ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> + defaultAttributeMappingUiProviders(); + + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(IJpaContentNode persistentAttributeNode) { - this.attribute = (IPersistentAttribute) persistentAttributeNode; - populateMappingComboAndPage(); + protected void doDispose() { + log("PersistentAttributeDetailsPage.doDispose()"); + + this.currentMappingComposite = null; + + for (IJpaComposite<IAttributeMapping> composite : this.mappingComposites.values()) { + try { + composite.dispose(); + } + catch (Exception e) { + JptUiPlugin.log(e); + } + } + + this.mappingComposites.clear(); + super.doDispose(); } - + + /* + * (non-Javadoc) + */ @Override protected void doPopulate() { + super.doPopulate(); populateMappingComboAndPage(); } - + + /* + * (non-Javadoc) + */ @Override - protected void engageListeners() { - if (this.attribute != null) { - this.attribute.eAdapters().add(this.persistentAttributeListener); - } + protected void initialize() { + super.initialize(); + this.mappingComposites = new HashMap<String, IJpaComposite<IAttributeMapping>>(); } - - @Override - protected void disengageListeners() { - if (this.attribute != null) { - this.attribute.eAdapters().remove(this.persistentAttributeListener); - } + + protected IJpaPlatformUi jpaPlatformUi() { + String platformId = subject().jpaProject().jpaPlatform().getId(); + return JpaPlatformUiRegistry.instance().jpaPlatform(platformId); } - - private void populateMappingComboAndPage() { - if (this.attribute == null) { - this.attributeMapping = null; - this.currentMappingKey = null; - this.mappingCombo.setInput(null); - this.mappingCombo.setSelection(StructuredSelection.EMPTY); - - if (this.currentMappingComposite != null) { - this.currentMappingComposite.populate(null); - this.currentMappingComposite = null; - } - - return; - } - this.attributeMapping = this.attribute.getMapping(); - setComboData(); - - populateMappingPage(this.attributeMapping == null ? null : this.attributeMapping.getKey()); + + protected IJpaUiFactory jpaUiFactory() { + // TODO: Remove the type cast, used for testing + return ((BaseJpaPlatformUi) jpaPlatformUi()).getJpaUiFactory(); } - - private void populateMappingPage(String mappingKey) { - if (this.currentMappingComposite != null) { - if (mappingKey == this.currentMappingKey) { - if (this.currentMappingComposite != null) { - this.currentMappingComposite.populate(this.attributeMapping); - return; - } - } - else { - this.currentMappingComposite.populate(null); - // don't return - } + + private void log(String message) { + if (Tracing.booleanDebugOption(Tracing.UI_DETAILS_VIEW)) { + Tracing.log(message); } - - this.currentMappingKey = mappingKey; - - IJpaComposite<IAttributeMapping> composite = mappingCompositeFor(mappingKey); - this.mappingPageBook.showPage(composite.getControl()); - - this.currentMappingComposite = composite; - this.currentMappingComposite.populate(this.attributeMapping); } - - private void setComboData() { - if (this.attribute != this.mappingCombo.getInput()) { - this.mappingCombo.setInput(this.attribute); - } - if (this.attributeMapping == null || this.attributeMapping.isDefault()) { - this.mappingCombo.setSelection(new StructuredSelection(this.mappingCombo.getElementAt(0))); - } - else { - IAttributeMappingUiProvider provider = attributeMappingUiProvider(this.attribute.mappingKey()); - if (provider != null && ! provider.equals(((StructuredSelection) this.mappingCombo.getSelection()).getFirstElement())) { - this.mappingCombo.setSelection(new StructuredSelection(provider)); - } + + private void mappingChanged(SelectionChangedEvent event) { + if (event.getSelection() instanceof StructuredSelection) { + IAttributeMappingUiProvider<?> provider = (IAttributeMappingUiProvider<?>) ((StructuredSelection) event.getSelection()).getFirstElement(); + String key = (CollectionTools.contains(defaultAttributeMappingUiProviders(), provider) ? null : provider.attributeMappingKey()); + this.subject().setSpecifiedMappingKey(key); } } - + private IJpaComposite<IAttributeMapping> mappingCompositeFor(String key) { IJpaComposite<IAttributeMapping> composite = this.mappingComposites.get(key); if (composite != null) { return composite; } - + composite = buildMappingComposite(this.mappingPageBook, key); - + if (composite != null) { this.mappingComposites.put(key, composite); } - + return composite; } - + + private IAttributeMappingUiProvider<? extends IAttributeMapping> mappingUIProvider(String key) { + + if (this.subject().getMapping() == null || + this.subject().getMapping().isDefault()) { + + return defaultAttributeMappingUiProvider(key); + } + + return attributeMappingUiProvider(key); + } + + private void populateMapAsCombo() { + if (this.subject() != this.mappingCombo.getInput()) { + this.mappingCombo.setInput(this.subject()); + } + if (this.subject() != null) { + if (this.subject().getMapping() == null || this.subject().getMapping().isDefault()) { + this.mappingCombo.setSelection(new StructuredSelection(this.mappingCombo.getElementAt(0))); + } + else { + IAttributeMappingUiProvider<? extends IAttributeMapping> provider = attributeMappingUiProvider(this.subject().mappingKey()); + if (provider != null && ! provider.equals(((StructuredSelection) this.mappingCombo.getSelection()).getFirstElement())) { + this.mappingCombo.setSelection(new StructuredSelection(provider)); + } + } + } + } + + private void populateMappingComboAndPage() { + populateMapAsCombo(); + updateMappingPage(); + } + + private void populateMappingPage(String mappingKey) { + + // Nothing to update + if (this.currentMappingKey == mappingKey) { + return; + } + else if (this.currentMappingComposite != null) { + this.log("PersistentAttributeDetailsPage.populateMappingPage() disposing of current page: " + this.currentMappingKey); + this.currentMappingComposite.dispose(); + } + + this.currentMappingKey = mappingKey; + + if (this.currentMappingKey != null) { + this.currentMappingComposite = mappingCompositeFor(mappingKey); + + try { + this.log("PersistentAttributeDetailsPage.populateMappingPage() populating new page: " + this.currentMappingKey); + + this.currentMappingComposite.populate(); + this.mappingPageBook.showPage(this.currentMappingComposite.getControl()); +// this.mappingPageBook.getParent().layout(true); + } + catch (Exception e) { + this.log("PersistentAttributeDetailsPage.populateMappingPage() error encountered"); + this.mappingComposites.remove(this.currentMappingComposite); + this.currentMappingComposite = null; + this.mappingPageBook.showPage(new Label(this.mappingPageBook, SWT.NULL)); + JptUiPlugin.log(e); + } + } + else { + this.log("PersistentAttributeDetailsPage.populateMappingPage() no page to show"); + this.currentMappingComposite = null; + this.mappingPageBook.showPage(new Label(this.mappingPageBook, SWT.NULL)); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == IPersistentAttribute.DEFAULT_MAPPING_PROPERTY || + propertyName == IPersistentAttribute.SPECIFIED_MAPPING_PROPERTY) { + + populateMappingComboAndPage(); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected boolean repopulateWithNullSubject() { + return false; + } + //TODO focus?? // public boolean setFocus() { // super.setFocus(); // return mappingCombo.getCombo().setFocus(); // } - - @Override - public void dispose() { - disengageListeners(); - for (IJpaComposite<IAttributeMapping> composite : this.mappingComposites.values()) { - composite.dispose(); - } - super.dispose(); - } - - public IPersistentAttribute getAttribute() { - return this.attribute; + + private void updateMappingPage() { + IAttributeMapping mapping = (this.subject() != null) ? this.subject().getMapping() : null; + populateMappingPage(mapping == null ? null : mapping.getKey()); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentTypeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentTypeDetailsPage.java index 6656cb43c0..28e2c3b44b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentTypeDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentTypeDetailsPage.java @@ -3,20 +3,16 @@ * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: Oracle. - initial API and implementation - ******************************************************************************/ + ******************************************************************************/ package org.eclipse.jpt.ui.internal.details; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.ListIterator; import java.util.Map; - -import org.eclipse.emf.common.command.BasicCommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.IContentProvider; @@ -26,229 +22,265 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.jpt.core.internal.IPersistentType; -import org.eclipse.jpt.core.internal.ITypeMapping; -import org.eclipse.jpt.core.internal.JpaCorePackage; +import org.eclipse.jpt.core.internal.context.base.IPersistentType; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.Filter; +import org.eclipse.jpt.utility.internal.model.value.FilteringPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public abstract class PersistentTypeDetailsPage extends BaseJpaDetailsPage -{ - private IPersistentType persistentType; - private Adapter persistentTypeListener; - +/** + * The abstract definition of the details page responsible to show the + * information for an persistent type. + * + * @see IPersistentType + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public abstract class PersistentTypeDetailsPage<T extends IPersistentType> extends BaseJpaDetailsPage<T> +{ + private Map<String, IJpaComposite<ITypeMapping>> composites; + private IJpaComposite<ITypeMapping> currentMappingComposite; private String currentMappingKey; - private ComboViewer typeMappingCombo; - - private Map<String, IJpaComposite<ITypeMapping>> composites; - - protected PageBook typeMappingPageBook; - - private IJpaComposite<ITypeMapping> visibleMappingComposite; - - public PersistentTypeDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NONE, new BasicCommandStack(), widgetFactory); - this.persistentTypeListener = buildPersistentTypeListener(); + private PageBook typeMappingPageBook; + + /** + * Creates a new <code>PersistentTypeDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public PersistentTypeDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(parent, widgetFactory); this.composites = new HashMap<String, IJpaComposite<ITypeMapping>>(); } - - protected abstract ListIterator<ITypeMappingUiProvider> typeMappingUiProviders(); - - private ITypeMappingUiProvider typeMappingUiProvider(String key) { - for (ListIterator<ITypeMappingUiProvider> i = this.typeMappingUiProviders(); i.hasNext();) { - ITypeMappingUiProvider provider = i.next(); - if (provider.mappingKey() == key) { - return provider; - } - } - throw new IllegalArgumentException("Unsupported type mapping UI provider key: " + key); - } - private Adapter buildPersistentTypeListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - persistentTypeChanged(notification); - } - }; - } - - private void persistentTypeChanged(Notification notification) { - switch (notification.getFeatureID(IPersistentType.class)) { - case JpaCorePackage.IPERSISTENT_TYPE__MAPPING_KEY: - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - break; - } + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IPersistentType.MAPPING_PROPERTY); } - protected Label buildTypeMappingLabel(Composite parent) { - return getWidgetFactory().createLabel(parent, JptUiMessages.PersistentTypePage_mapAs); - } - - protected ComboViewer buildTypeMappingCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - this.typeMappingCombo = new ComboViewer(combo); - this.typeMappingCombo.setContentProvider(buildContentProvider()); - this.typeMappingCombo.setLabelProvider(buildLabelProvider()); - this.typeMappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - typeMappingChanged(event); - } - }); - return this.typeMappingCombo; - } - private IContentProvider buildContentProvider() { return new IStructuredContentProvider() { public void dispose() { // do nothing } - + public Object[] getElements(Object inputElement) { - return (persistentType == null) ? + return (subject() == null) ? new String[] {}: CollectionTools.array(PersistentTypeDetailsPage.this.typeMappingUiProviders()); } - + public void inputChanged( Viewer viewer, Object oldInput, Object newInput) { // do nothing } }; } + private IBaseLabelProvider buildLabelProvider() { return new LabelProvider() { @Override public String getText(Object element) { - return ((ITypeMappingUiProvider) element).label(); + return ((ITypeMappingUiProvider<?>) element).label(); } }; } - + + @SuppressWarnings("unchecked") + protected IJpaComposite<ITypeMapping> buildMappingComposite(PageBook pageBook, + String key) { + + ITypeMappingUiProvider<ITypeMapping> uiProvider = + (ITypeMappingUiProvider<ITypeMapping>) typeMappingUiProvider(key); + + return uiProvider.buildPersistentTypeMappingComposite( + buildMappingHolder(key), + pageBook, + getFormWidgetFactory() + ); + } + + private PropertyValueModel<ITypeMapping> buildMappingHolder(String key) { + return new FilteringPropertyValueModel<ITypeMapping>( + buildGenericMappingHolder(), + buildMappingFilter(key) + ); + } + + private PropertyAspectAdapter<IPersistentType, ITypeMapping> buildGenericMappingHolder() { + return new PropertyAspectAdapter<IPersistentType, ITypeMapping>(getSubjectHolder(), IPersistentType.MAPPING_PROPERTY) { + @Override + protected ITypeMapping buildValue_() { + return subject.getMapping(); + } + }; + } + + private Filter<ITypeMapping> buildMappingFilter(final String key) { + return new Filter<ITypeMapping>() { + public boolean accept(ITypeMapping value) { + return (value == null) || key.equals(value.getKey()); + } + }; + } + + protected ComboViewer buildTypeMappingCombo(Composite parent) { + CCombo combo = buildCombo(parent); + this.typeMappingCombo = new ComboViewer(combo); + this.typeMappingCombo.getCCombo().setVisibleItemCount(Integer.MAX_VALUE); + this.typeMappingCombo.setContentProvider(buildContentProvider()); + this.typeMappingCombo.setLabelProvider(buildLabelProvider()); + this.typeMappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + typeMappingChanged(event); + } + }); + return this.typeMappingCombo; + } + + protected Label buildTypeMappingLabel(Composite parent) { + return buildLabel(parent, JptUiMessages.PersistentTypePage_mapAs); + } + protected PageBook buildTypeMappingPageBook(Composite parent) { this.typeMappingPageBook = new PageBook(parent, SWT.NONE); return this.typeMappingPageBook; } - - - private void typeMappingChanged(SelectionChangedEvent event) { - if (isPopulating()) { - return; - } - if (event.getSelection() instanceof StructuredSelection) { - ITypeMappingUiProvider provider = (ITypeMappingUiProvider) ((StructuredSelection) event.getSelection()).getFirstElement(); - this.persistentType.setMappingKey(provider.mappingKey()); - } - } - + + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(IJpaContentNode persistentTypeNode) { - this.persistentType = (IPersistentType) persistentTypeNode; - populateMappingComboAndPage(); + protected void doDispose() { + + for (Iterator<IJpaComposite<ITypeMapping>> iter = this.composites.values().iterator(); iter.hasNext(); ) { + iter.next().dispose(); + } + + super.doDispose(); } - + + /* + * (non-Javadoc) + */ @Override protected void doPopulate() { + super.doPopulate(); populateMappingComboAndPage(); } - - protected void engageListeners() { - if (this.persistentType != null) { - this.persistentType.eAdapters().add(this.persistentTypeListener); + + private IJpaComposite<ITypeMapping> mappingCompositeFor(String key) { + IJpaComposite<ITypeMapping> mappingComposite = this.composites.get(key); + if (mappingComposite != null) { + return mappingComposite; } - } - - protected void disengageListeners() { - if (this.persistentType != null) { - this.persistentType.eAdapters().remove(this.persistentTypeListener); + + mappingComposite = buildMappingComposite(this.typeMappingPageBook, key); + + if (mappingComposite != null) { + this.composites.put(key, mappingComposite); } + + return mappingComposite; } - + private void populateMappingComboAndPage() { - if (this.persistentType == null) { + if (this.subject() == null) { this.currentMappingKey = null; this.typeMappingCombo.setInput(null); this.typeMappingCombo.setSelection(StructuredSelection.EMPTY); - - if (this.visibleMappingComposite != null) { - this.visibleMappingComposite.populate(null); - this.visibleMappingComposite = null; + + if (this.currentMappingComposite != null) { + this.currentMappingComposite.populate(); + this.currentMappingComposite = null; } - + return; } - - String mappingKey = this.persistentType.getMapping().getKey(); + + String mappingKey = this.subject().getMapping().getKey(); setComboData(mappingKey); - + populateMappingPage(mappingKey); } - + private void populateMappingPage(String mappingKey) { - if (this.visibleMappingComposite != null) { - if (mappingKey == this.currentMappingKey) { - if (this.visibleMappingComposite != null) { - this.visibleMappingComposite.populate(this.persistentType.getMapping()); - return; - } + if (this.currentMappingComposite != null && + this.currentMappingKey == mappingKey) { + + this.currentMappingComposite.populate(); + return; + } + + this.currentMappingKey = mappingKey; + + if (this.currentMappingKey != null) { + this.currentMappingComposite = mappingCompositeFor(mappingKey); + + try { + this.currentMappingComposite.populate(); } - else { - this.visibleMappingComposite.populate(null); - // don't return + finally { + // Log or show error } + + this.typeMappingPageBook.showPage(this.currentMappingComposite.getControl()); + this.typeMappingPageBook.layout(true); + } + else { + this.currentMappingComposite = null; + this.typeMappingPageBook.showPage(new Label(this.typeMappingPageBook, SWT.NULL)); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == IPersistentType.MAPPING_PROPERTY) { + populateMappingComboAndPage(); } - - this.currentMappingKey = mappingKey; - - IJpaComposite mappingComposite = mappingCompositeFor(mappingKey); - this.typeMappingPageBook.showPage(mappingComposite.getControl()); - - this.visibleMappingComposite = mappingComposite; - this.visibleMappingComposite.populate(this.persistentType.getMapping()); } - + private void setComboData(String mappingKey) { - if (this.persistentType != this.typeMappingCombo.getInput()) { - this.typeMappingCombo.setInput(this.persistentType); + if (this.subject() != this.typeMappingCombo.getInput()) { + this.typeMappingCombo.setInput(this.subject()); } - - ITypeMappingUiProvider provider = typeMappingUiProvider(mappingKey); + + ITypeMappingUiProvider<? extends ITypeMapping> provider = typeMappingUiProvider(mappingKey); if (! provider.equals(((StructuredSelection) this.typeMappingCombo.getSelection()).getFirstElement())) { this.typeMappingCombo.setSelection(new StructuredSelection(provider)); } } - - private IJpaComposite<ITypeMapping> mappingCompositeFor(String key) { - IJpaComposite<ITypeMapping> mappingComposite = this.composites.get(key); - if (mappingComposite != null) { - return mappingComposite; - } - - mappingComposite = buildMappingComposite(this.typeMappingPageBook, key); - - if (mappingComposite != null) { - this.composites.put(key, mappingComposite); + + private void typeMappingChanged(SelectionChangedEvent event) { + if (event.getSelection() instanceof StructuredSelection) { + ITypeMappingUiProvider<?> provider = (ITypeMappingUiProvider<?>) ((StructuredSelection) event.getSelection()).getFirstElement(); + this.subject().setMappingKey(provider.mappingKey()); } - - return mappingComposite; - } - - protected IJpaComposite<ITypeMapping> buildMappingComposite(PageBook pageBook, String key) { - return typeMappingUiProvider(key).buildPersistentTypeMappingComposite(pageBook, this.commandStack, getWidgetFactory()); } //TODO focus?? @@ -256,17 +288,16 @@ public abstract class PersistentTypeDetailsPage extends BaseJpaDetailsPage // super.setFocus(); // return typeMappingCombo.getCombo().setFocus(); // } - - public void dispose() { - disengageListeners(); - for (Iterator<IJpaComposite<ITypeMapping>> i = this.composites.values().iterator(); i.hasNext(); ) { - i.next().dispose(); + + private ITypeMappingUiProvider<? extends ITypeMapping> typeMappingUiProvider(String key) { + for (ListIterator<ITypeMappingUiProvider<? extends ITypeMapping>> iter = this.typeMappingUiProviders(); iter.hasNext();) { + ITypeMappingUiProvider<? extends ITypeMapping> provider = iter.next(); + if (provider.mappingKey() == key) { + return provider; + } } - super.dispose(); - } - - public IPersistentType getPersistentType() { - return this.persistentType; + throw new IllegalArgumentException("Unsupported type mapping UI provider key: " + key); } -} + protected abstract ListIterator<ITypeMappingUiProvider<? extends ITypeMapping>> typeMappingUiProviders(); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java index 9db8842e31..2725d9cb5d 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java @@ -10,7 +10,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.JptUiPlugin; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; @@ -37,27 +37,25 @@ import org.eclipse.swt.widgets.Text; public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog { private XmlPersistentAttribute unmappedPersistentAttribute; - private Text attributeText; - private ComboViewer mappingCombo; - - + public AddPersistentAttributeToXmlAndMapDialog(Shell parentShell, XmlPersistentAttribute unmappedPersistentAttribute) { super(parentShell); this.unmappedPersistentAttribute = unmappedPersistentAttribute; setTitle(JptUiMessages.AddPersistentAttributeDialog_title); } - + + @Override protected Control createDialogArea(Composite parent) { Composite dialogArea = (Composite) super.createDialogArea(parent); - + Composite composite = new Composite(dialogArea, SWT.NULL); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout()); - + createLabel(composite, 1, JptUiMessages.AddPersistentAttributeDialog_attributeLabel); - + attributeText = createText(composite, 1); // attributeText.addModifyListener( // new ModifyListener() { @@ -68,14 +66,14 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog // ); attributeText.setText(unmappedPersistentAttribute.getName()); attributeText.setEditable(false); - + createLabel(composite, 1, JptUiMessages.AddPersistentClassDialog_mappingLabel); - + mappingCombo = new ComboViewer(createCombo(composite, 1)); mappingCombo.setContentProvider( new IStructuredContentProvider() { public void dispose() {} - + public Object[] getElements(Object inputElement) { return new Object[] { BasicMappingUiProvider.instance(), @@ -90,7 +88,7 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog VersionMappingUiProvider.instance() }; } - + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} }); mappingCombo.setLabelProvider( @@ -107,18 +105,18 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog }); mappingCombo.setInput("FOO"); mappingCombo.getCombo().select(0); // select Basic to begin - + // TODO - F1 Help // PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IDaliHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); - + //getButton(IDialogConstants.OK_ID).setEnabled(false); // disabled to start - applyDialogFont(dialogArea); - + applyDialogFont(dialogArea); + validate(); - + return dialogArea; } - + private Label createLabel(Composite container, int span, String text) { Label label = new Label(container, SWT.NONE); label.setText(text); @@ -127,7 +125,7 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog label.setLayoutData(gd); return label; } - + private Text createText(Composite container, int span) { Text text = new Text(container, SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); @@ -136,7 +134,7 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog text.setLayoutData(gd); return text; } - + private Combo createCombo(Composite container, int span) { Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); GridData gd = new GridData(GridData.FILL_HORIZONTAL); @@ -144,25 +142,25 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog combo.setLayoutData(gd); return combo; } - + public String getAttributeName() { return attributeText.getText(); } - + public String getMappingKey() { StructuredSelection selection = (StructuredSelection) mappingCombo.getSelection(); return (selection.isEmpty()) ? null : ((IAttributeMappingUiProvider) selection.getFirstElement()).attributeMappingKey(); } - + private void validate() { // if (entityMappings.containsPersistentType(type)) { // updateStatus( // new Status( -// IStatus.WARNING, JptUiPlugin.PLUGIN_ID, +// IStatus.WARNING, JptUiPlugin.PLUGIN_ID, // JptUiMessages.AddPersistentClassDialog_duplicateClassWarning)); // return; // } -// +// String mappingKey = getMappingKey(); if (mappingKey == null) { updateStatus( @@ -171,10 +169,10 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog JptUiMessages.AddPersistentAttributeDialog_noMappingKeyError)); return; } - + updateStatus(Status.OK_STATUS); } - + @Override protected void okPressed() { unmappedPersistentAttribute.setSpecifiedMappingKey(getMappingKey()); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentClassDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentClassDialog.java index df5f48df2a..5d74a0bc5b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentClassDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentClassDialog.java @@ -28,7 +28,7 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.JptUiPlugin; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; @@ -56,7 +56,7 @@ import org.eclipse.ui.progress.IProgressService; public class AddPersistentClassDialog extends StatusDialog { - private EntityMappingsInternal entityMappings; + private EntityMappings entityMappings; private Text classText; @@ -65,12 +65,13 @@ public class AddPersistentClassDialog extends StatusDialog private ComboViewer mappingCombo; - public AddPersistentClassDialog(Shell parentShell, EntityMappingsInternal entityMappings) { + public AddPersistentClassDialog(Shell parentShell, EntityMappings entityMappings) { super(parentShell); this.entityMappings = entityMappings; setTitle(JptUiMessages.AddPersistentClassDialog_title); } + @Override protected Control createDialogArea(Composite parent) { Composite dialogArea = (Composite) super.createDialogArea(parent); @@ -80,8 +81,8 @@ public class AddPersistentClassDialog extends StatusDialog createLabel(composite, 2, JptUiMessages.AddPersistentClassDialog_classLabel); - classText = createText(composite, 1); - classText.addModifyListener( + this.classText = createText(composite, 1); + this.classText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { validate(); @@ -89,8 +90,8 @@ public class AddPersistentClassDialog extends StatusDialog } ); - classBrowseButton = createButton(composite, 1, JptUiMessages.General_browse); - classBrowseButton.addSelectionListener(new SelectionListener() { + this.classBrowseButton = createButton(composite, 1, JptUiMessages.General_browse); + this.classBrowseButton.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { IType type = chooseType(); if (type != null) { @@ -104,8 +105,8 @@ public class AddPersistentClassDialog extends StatusDialog createLabel(composite, 2, JptUiMessages.AddPersistentClassDialog_mappingLabel); - mappingCombo = new ComboViewer(createCombo(composite, 2)); - mappingCombo.setContentProvider( + this.mappingCombo = new ComboViewer(createCombo(composite, 2)); + this.mappingCombo.setContentProvider( new IStructuredContentProvider() { public void dispose() {} @@ -119,20 +120,20 @@ public class AddPersistentClassDialog extends StatusDialog public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} }); - mappingCombo.setLabelProvider( + this.mappingCombo.setLabelProvider( new LabelProvider() { @Override public String getText(Object element) { - return ((ITypeMappingUiProvider) element).label(); + return ((ITypeMappingUiProvider<?>) element).label(); } }); - mappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { + this.mappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { validate(); } }); - mappingCombo.setInput("FOO"); - mappingCombo.getCombo().select(1); // select Entity to begin + this.mappingCombo.setInput("FOO"); + this.mappingCombo.getCombo().select(1); // select Entity to begin // TODO - F1 Help // PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IDaliHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); @@ -181,16 +182,16 @@ public class AddPersistentClassDialog extends StatusDialog } private IJpaProject getJpaProject() { - return entityMappings.getJpaProject(); + return this.entityMappings.jpaProject(); } public String getClassName() { - return classText.getText(); + return this.classText.getText(); } public String getMappingKey() { - StructuredSelection selection = (StructuredSelection) mappingCombo.getSelection(); - return (selection.isEmpty()) ? null : ((ITypeMappingUiProvider) selection.getFirstElement()).mappingKey(); + StructuredSelection selection = (StructuredSelection) this.mappingCombo.getSelection(); + return (selection.isEmpty()) ? null : ((ITypeMappingUiProvider<?>) selection.getFirstElement()).mappingKey(); } protected IType chooseType() { @@ -246,7 +247,7 @@ public class AddPersistentClassDialog extends StatusDialog return; } - if (entityMappings.containsPersistentType(type)) { + if (this.entityMappings.containsPersistentType(className)) { updateStatus( new Status( IStatus.WARNING, JptUiPlugin.PLUGIN_ID, @@ -268,7 +269,7 @@ public class AddPersistentClassDialog extends StatusDialog @Override protected void okPressed() { - entityMappings.addMapping(getClassName(), getMappingKey()); + this.entityMappings.addXmlPersistentType(getMappingKey(), getClassName()); super.okPressed(); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/IAttributeMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/IAttributeMappingUiProvider.java index 4493c0c794..c3960c40a4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/IAttributeMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/IAttributeMappingUiProvider.java @@ -3,21 +3,20 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.jpt.core.internal.IAttributeMapping; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public interface IAttributeMappingUiProvider +public interface IAttributeMappingUiProvider<T extends IAttributeMapping> { /** * A unique string that corresponds to the key of a MappingProvider in the core @@ -26,23 +25,24 @@ public interface IAttributeMappingUiProvider String attributeMappingKey(); /** - * A label to be displayed to the label as an option in the mapping type combo box - * @return - */ - String label(); - - /** * The IJpaComposite that correponds to this mapping type. This will be displayed * by the PersistentAttributeDetailsPage when the mapping key matches the key given * by this provider. The composites will be stored in a Map with the mapping key as the key. * @param factory * @param parent - * @param commandStack * @param widgetFactory - * + * * @return */ - IJpaComposite<IAttributeMapping> buildAttributeMappingComposite( - IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - -} + IJpaComposite<T> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<T> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory); + + /** + * A label to be displayed to the label as an option in the mapping type combo box + * @return + */ + String label(); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/ITypeMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/ITypeMappingUiProvider.java index 51318e9568..b97cba51cf 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/ITypeMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/ITypeMappingUiProvider.java @@ -3,27 +3,27 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.jpt.core.internal.ITypeMapping; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public interface ITypeMappingUiProvider +public interface ITypeMappingUiProvider<T extends ITypeMapping> { /** * A unique string that corresponds to the key of a MappingProvider in the core */ String mappingKey(); - + /** - * A label to be displayed to the label as an option in the mapping type combo box + * A label to be displayed to the label as an option in the mapping type combo box * @return */ String label(); @@ -32,13 +32,14 @@ public interface ITypeMappingUiProvider * The IJpaComposite that correponds to this mapping type. This will be displayed * by the PersistentTypeDetailsPage when the mapping key matches the key given * by this provider. The composites will be stored in a Map with the mapping key as the key. - * + * * @param parent - * @param commandStack * @param widgetFactory * @return */ - IJpaComposite<ITypeMapping> buildPersistentTypeMappingComposite( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory); - + IJpaComposite<T> buildPersistentTypeMappingComposite( + PropertyValueModel<T> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory); + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java index 314f1c505c..796f36a4b2 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java @@ -1,45 +1,55 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.java.details; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.internal.content.java.IJavaContentNodes; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.core.internal.context.java.IJavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.IJavaPersistentType; import org.eclipse.jpt.ui.internal.details.IJpaDetailsPage; import org.eclipse.jpt.ui.internal.details.IJpaDetailsProvider; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class JavaDetailsProvider +/** + * This provider is responsible for creating the <code>IJpaDetailsPage</code> + * when the information comes from the Java source file. + * + * @version 2.0 + * @since 1.0 + */ +public class JavaDetailsProvider implements IJpaDetailsProvider { + /** + * Creates a new <code>JavaDetailsProvider</code>. + */ public JavaDetailsProvider() { super(); } - - public String fileContentType() { - return JavaCore.JAVA_SOURCE_CONTENT_TYPE; - } - - public IJpaDetailsPage buildDetailsPage( - Composite parentComposite, Object contentNodeId, TabbedPropertySheetWidgetFactory widgetFactory) { - if (contentNodeId.equals(IJavaContentNodes.PERSISTENT_TYPE_ID)) { - return new JavaPersistentTypeDetailsPage(parentComposite, widgetFactory); + + /* + * (non-Javadoc) + */ + public IJpaDetailsPage<? extends IJpaContextNode> buildDetailsPage( + Composite parent, + Object contentNodeId, + TabbedPropertySheetWidgetFactory widgetFactory) { + + if (contentNodeId instanceof IJavaPersistentType) { + return new JavaPersistentTypeDetailsPage(parent, widgetFactory); } - else if (contentNodeId.equals(IJavaContentNodes.PERSISTENT_ATTRIBUTE_ID)) { - return new JavaPersistentAttributeDetailsPage(parentComposite, widgetFactory); + + if (contentNodeId instanceof IJavaPersistentAttribute) { + return new JavaPersistentAttributeDetailsPage(parent, widgetFactory); } - - return null; - } - public void dispose() { - // no op ... for now + return null; } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeDetailsPage.java index ba03040b85..54926f49b8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeDetailsPage.java @@ -3,100 +3,126 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.details; import java.util.ListIterator; - -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jpt.core.internal.IPersistentAttribute; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; +import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.IJavaPersistentAttribute; import org.eclipse.jpt.ui.internal.details.PersistentAttributeDetailsPage; import org.eclipse.jpt.ui.internal.java.mappings.properties.NullAttributeMappingUiProvider; +import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class JavaPersistentAttributeDetailsPage - extends PersistentAttributeDetailsPage +/** + * The default implementation of the details page used for the Java persistent + * attribute. + * + * @see IPersistentAttribute + * + * @version 2.0 + * @since 2.0 + */ +public class JavaPersistentAttributeDetailsPage extends PersistentAttributeDetailsPage<IJavaPersistentAttribute> { - public JavaPersistentAttributeDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { + /** + * Creates a new <code>JavaPersistentAttributeDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JavaPersistentAttributeDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + super(parent, widgetFactory); } - - - @Override - protected ListIterator<IAttributeMappingUiProvider> attributeMappingUiProviders() { - return jpaPlatformUi().javaAttributeMappingUiProviders(); - } - - protected IAttributeMappingUiProvider nullAttributeMappingUiProvider() { - return NullAttributeMappingUiProvider.instance(); - } + /* + * (non-Javadoc) + */ @Override - protected ListIterator<IAttributeMappingUiProvider> defaultAttributeMappingUiProviders() { - return jpaPlatformUi().defaultJavaAttributeMappingUiProviders(); + protected ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> attributeMappingUiProviders() { + // TODO + return ((BaseJpaPlatformUi) jpaPlatformUi()).javaAttributeMappingUiProviders(); } - /** * These IAtttributeMappingUiProviders will be used as elements in the attributeMapping combo * The first element in the combo will be one of the defaultAttributeMappingUiProviders or * if none of those apply the nullAttributeMappingUiProvider will be used. The rest of the elements * will be the attributeMappingUiProviders. The defaultAttributeMappingUiProvider is - * determined by matching its key with the key of the current attributeMapping. + * determined by matching its key with the key of the current attributeMapping. */ @Override - protected IAttributeMappingUiProvider[] attributeMappingUiProvidersFor(IPersistentAttribute persistentAttribute) { - IAttributeMappingUiProvider[] providers = new IAttributeMappingUiProvider[CollectionTools.size(attributeMappingUiProviders()) + 1]; + protected IAttributeMappingUiProvider<? extends IAttributeMapping>[] attributeMappingUiProvidersFor(IPersistentAttribute persistentAttribute) { + IAttributeMappingUiProvider<? extends IAttributeMapping>[] providers = new IAttributeMappingUiProvider<?>[CollectionTools.size(attributeMappingUiProviders()) + 1]; providers[0] = defaultAttributeMappingUiProvider(persistentAttribute.defaultMappingKey()); int i = 1; - for (ListIterator<IAttributeMappingUiProvider> iterator = attributeMappingUiProviders(); iterator.hasNext(); ) { + for (ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> iterator = attributeMappingUiProviders(); iterator.hasNext(); ) { providers[i++] = iterator.next(); } return providers; } - + + /* + * (non-Javadoc) + */ @Override - protected IAttributeMappingUiProvider defaultAttributeMappingUiProvider(String key) { - for (ListIterator<IAttributeMappingUiProvider> i = defaultAttributeMappingUiProviders(); i.hasNext(); ) { - IAttributeMappingUiProvider provider = i.next(); + protected IAttributeMappingUiProvider<? extends IAttributeMapping> defaultAttributeMappingUiProvider(String key) { + for (ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> i = defaultAttributeMappingUiProviders(); i.hasNext(); ) { + IAttributeMappingUiProvider<? extends IAttributeMapping> provider = i.next(); if (provider.attributeMappingKey() == key) { return provider; } } return this.nullAttributeMappingUiProvider(); } - + + /* + * (non-Javadoc) + */ + @Override + protected ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> defaultAttributeMappingUiProviders() { + // TODO +// return jpaPlatformUi().defaultJavaAttributeMappingUiProviders(); + return ((BaseJpaPlatformUi) jpaPlatformUi()).defaultJavaAttributeMappingUiProviders(); + } + + /* + * (non-Javadoc) + */ @Override - protected void initializeLayout(Composite composite) { - composite.setLayout(new GridLayout(2, false)); - - GridData gridData; - - buildMappingLabel(composite); - - ComboViewer mappingCombo = buildMappingCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - mappingCombo.getCombo().setLayoutData(gridData); - - PageBook book = buildMappingPageBook(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; + protected void initializeLayout(Composite container) { + + // Note: The combo's parent is a container fixing the issue with the + // border not being painted + buildLabeledComposite( + container, + buildMappingLabel(container), + buildMappingCombo(container).getControl().getParent() + ); + + PageBook mappingPane = buildMappingPageBook(container); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.verticalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - book.setLayoutData(gridData); + gridData.grabExcessVerticalSpace = true; + + mappingPane.setLayoutData(gridData); + } + + protected IAttributeMappingUiProvider<IAttributeMapping> nullAttributeMappingUiProvider() { + return NullAttributeMappingUiProvider.instance(); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentTypeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentTypeDetailsPage.java index 29e70c383e..7661a106ac 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentTypeDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentTypeDetailsPage.java @@ -1,67 +1,85 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.java.details; import java.util.ListIterator; - -import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; +import org.eclipse.jpt.core.internal.context.java.IJavaPersistentType; import org.eclipse.jpt.ui.internal.IJpaPlatformUi; -import org.eclipse.jpt.ui.internal.PlatformRegistry; import org.eclipse.jpt.ui.internal.details.PersistentTypeDetailsPage; +import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; +import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class JavaPersistentTypeDetailsPage extends - PersistentTypeDetailsPage -{ - - public JavaPersistentTypeDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { +/** + * The default implementation of the details page used for the Java persistent + * type. + * + * @see IJavaPersistentType + * + * @version 2.0 + * @since 2.0 + */ +public class JavaPersistentTypeDetailsPage extends PersistentTypeDetailsPage<IJavaPersistentType> +{ + /** + * Creates a new <code>JavaPersistentTypeDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JavaPersistentTypeDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + super(parent, widgetFactory); } - + protected IJpaPlatformUi jpaPlatformUi() { - String platformId = getPersistentType().jpaPlatform().getId(); - return PlatformRegistry.instance().jpaPlatform(platformId); + String platformId = subject().jpaProject().jpaPlatform().getId(); + return JpaPlatformUiRegistry.instance().jpaPlatform(platformId); } - + + /* + * (non-Javadoc) + */ @Override - protected ListIterator<ITypeMappingUiProvider> typeMappingUiProviders() { - return jpaPlatformUi().javaTypeMappingUiProviders(); + protected ListIterator<ITypeMappingUiProvider<? extends ITypeMapping>> typeMappingUiProviders() { + // TODO + return ((BaseJpaPlatformUi) jpaPlatformUi()).javaTypeMappingUiProviders(); } + /* + * (non-Javadoc) + */ @Override - protected void initializeLayout(Composite composite) { - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - buildTypeMappingLabel(composite); - - ComboViewer typeMappingCombo = buildTypeMappingCombo(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - typeMappingCombo.getCombo().setLayoutData(gridData); + protected void initializeLayout(Composite container) { + + // Entity Type widgets + buildLabeledComposite( + container, + buildTypeMappingLabel(container), + buildTypeMappingCombo(container).getControl().getParent() + ); - PageBook typeMappingPageBook = buildTypeMappingPageBook(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; + PageBook typeMappingPageBook = buildTypeMappingPageBook(container); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.verticalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - typeMappingPageBook.setLayoutData(gridData); - } + gridData.grabExcessVerticalSpace = true; -} + typeMappingPageBook.setLayoutData(gridData); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/BasicMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/BasicMappingUiProvider.java index f9882fb990..fc8a7ac928 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/BasicMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/BasicMappingUiProvider.java @@ -3,32 +3,33 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class BasicMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IBasicMapping> { - + // singleton private static final BasicMappingUiProvider INSTANCE = new BasicMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IBasicMapping> instance() { return INSTANCE; } @@ -38,16 +39,21 @@ public class BasicMappingUiProvider private BasicMappingUiProvider() { super(); } - + public String attributeMappingKey() { return IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_BasicLabel; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createBasicMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IBasicMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IBasicMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createBasicMappingComposite(subjectHolder, parent, widgetFactory); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultBasicMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultBasicMappingUiProvider.java index 5eee3a03f9..e6d91b2ab2 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultBasicMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultBasicMappingUiProvider.java @@ -3,23 +3,25 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class DefaultBasicMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IBasicMapping> { // singleton private static final DefaultBasicMappingUiProvider INSTANCE = new DefaultBasicMappingUiProvider(); @@ -27,7 +29,7 @@ public class DefaultBasicMappingUiProvider /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IBasicMapping> instance() { return INSTANCE; } @@ -37,16 +39,23 @@ public class DefaultBasicMappingUiProvider private DefaultBasicMappingUiProvider() { super(); } - + public String attributeMappingKey() { return IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; } - + public String label() { - return "Default (" + JptUiMappingsMessages.PersistentAttributePage_BasicLabel + ")"; + return NLS.bind( + JptUiMappingsMessages.DefaultBasicMappingUiProvider_Default, + JptUiMappingsMessages.PersistentAttributePage_BasicLabel + ); } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createBasicMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IBasicMapping> buildAttributeMappingComposite(IJpaUiFactory factory, + PropertyValueModel<IBasicMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createBasicMappingComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultEmbeddedMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultEmbeddedMappingUiProvider.java index f8c882dba3..0f7f9c8146 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultEmbeddedMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/DefaultEmbeddedMappingUiProvider.java @@ -3,23 +3,25 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class DefaultEmbeddedMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IEmbeddedMapping> { // singleton private static final DefaultEmbeddedMappingUiProvider INSTANCE = new DefaultEmbeddedMappingUiProvider(); @@ -27,7 +29,7 @@ public class DefaultEmbeddedMappingUiProvider /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IEmbeddedMapping> instance() { return INSTANCE; } @@ -37,16 +39,24 @@ public class DefaultEmbeddedMappingUiProvider private DefaultEmbeddedMappingUiProvider() { super(); } - + public String attributeMappingKey() { return IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; } - + public String label() { - return "Default (" + JptUiMappingsMessages.PersistentAttributePage_EmbeddedLabel + ")"; + return NLS.bind( + JptUiMappingsMessages.DefaultEmbeddedMappingUiProvider_Default, + JptUiMappingsMessages.PersistentAttributePage_EmbeddedLabel + ); } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createEmbeddedMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IEmbeddedMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IEmbeddedMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createEmbeddedMappingComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddableUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddableUiProvider.java index b15444d07a..62dc32fa34 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddableUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddableUiProvider.java @@ -3,22 +3,23 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IEmbeddable; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; import org.eclipse.jpt.ui.internal.mappings.details.EmbeddableComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class EmbeddableUiProvider implements ITypeMappingUiProvider +public class EmbeddableUiProvider implements ITypeMappingUiProvider<IEmbeddable> { // singleton private static final EmbeddableUiProvider INSTANCE = new EmbeddableUiProvider(); @@ -26,7 +27,7 @@ public class EmbeddableUiProvider implements ITypeMappingUiProvider /** * Return the singleton. */ - public static ITypeMappingUiProvider instance() { + public static ITypeMappingUiProvider<IEmbeddable> instance() { return INSTANCE; } @@ -40,13 +41,16 @@ public class EmbeddableUiProvider implements ITypeMappingUiProvider public String mappingKey() { return IMappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentTypePage_EmbeddableLabel; } - - public IJpaComposite buildPersistentTypeMappingComposite( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EmbeddableComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IEmbeddable> buildPersistentTypeMappingComposite( + PropertyValueModel<IEmbeddable> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new EmbeddableComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedIdMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedIdMappingUiProvider.java index 65b4665844..ea5c609e89 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedIdMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedIdMappingUiProvider.java @@ -3,32 +3,33 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class EmbeddedIdMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IEmbeddedIdMapping> { - + // singleton private static final EmbeddedIdMappingUiProvider INSTANCE = new EmbeddedIdMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IEmbeddedIdMapping> instance() { return INSTANCE; } @@ -42,12 +43,17 @@ public class EmbeddedIdMappingUiProvider public String attributeMappingKey() { return IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_EmbeddedIdLabel; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createEmbeddedIdMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IEmbeddedIdMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IEmbeddedIdMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createEmbeddedIdMappingComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedMappingUiProvider.java index e5387c4290..47c3688b22 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EmbeddedMappingUiProvider.java @@ -3,32 +3,33 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class EmbeddedMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IEmbeddedMapping> { - + // singleton private static final EmbeddedMappingUiProvider INSTANCE = new EmbeddedMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IEmbeddedMapping> instance() { return INSTANCE; } @@ -42,12 +43,17 @@ public class EmbeddedMappingUiProvider public String attributeMappingKey() { return IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_EmbeddedLabel; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createEmbeddedMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IEmbeddedMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IEmbeddedMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createEmbeddedMappingComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EntityUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EntityUiProvider.java index 64c4c2a55e..feb4242d7d 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EntityUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/EntityUiProvider.java @@ -3,22 +3,23 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IEntity; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; import org.eclipse.jpt.ui.internal.mappings.details.EntityComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class EntityUiProvider implements ITypeMappingUiProvider +public class EntityUiProvider implements ITypeMappingUiProvider<IEntity> { // singleton private static final EntityUiProvider INSTANCE = new EntityUiProvider(); @@ -26,7 +27,7 @@ public class EntityUiProvider implements ITypeMappingUiProvider /** * Return the singleton. */ - public static ITypeMappingUiProvider instance() { + public static ITypeMappingUiProvider<IEntity> instance() { return INSTANCE; } @@ -40,13 +41,16 @@ public class EntityUiProvider implements ITypeMappingUiProvider public String mappingKey() { return IMappingKeys.ENTITY_TYPE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentTypePage_EntityLabel; } - - public IJpaComposite buildPersistentTypeMappingComposite( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EntityComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IEntity> buildPersistentTypeMappingComposite( + PropertyValueModel<IEntity> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new EntityComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/IdMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/IdMappingUiProvider.java index 2d1dafd6f7..996b1b7e08 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/IdMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/IdMappingUiProvider.java @@ -3,23 +3,24 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class IdMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IIdMapping> { // singleton private static final IdMappingUiProvider INSTANCE = new IdMappingUiProvider(); @@ -27,7 +28,7 @@ public class IdMappingUiProvider /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IIdMapping> instance() { return INSTANCE; } @@ -41,12 +42,17 @@ public class IdMappingUiProvider public String attributeMappingKey() { return IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_IdLabel; } - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createIdMappingComposite(parent, commandStack, widgetFactory); + public IJpaComposite<IIdMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IIdMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createIdMappingComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToManyMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToManyMappingUiProvider.java index 286c454427..a76292585c 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToManyMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToManyMappingUiProvider.java @@ -3,23 +3,24 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class ManyToManyMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IManyToManyMapping> { // singleton private static final ManyToManyMappingUiProvider INSTANCE = new ManyToManyMappingUiProvider(); @@ -27,7 +28,7 @@ public class ManyToManyMappingUiProvider /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IManyToManyMapping> instance() { return INSTANCE; } @@ -41,12 +42,17 @@ public class ManyToManyMappingUiProvider public String attributeMappingKey() { return IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_ManyToManyLabel; } - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createManyToManyMappingComposite(parent, commandStack, widgetFactory); + public IJpaComposite<IManyToManyMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IManyToManyMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createManyToManyMappingComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToOneMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToOneMappingUiProvider.java index ea619de917..8c002cc4f8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToOneMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/ManyToOneMappingUiProvider.java @@ -3,23 +3,24 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class ManyToOneMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IManyToOneMapping> { // singleton private static final ManyToOneMappingUiProvider INSTANCE = new ManyToOneMappingUiProvider(); @@ -27,7 +28,7 @@ public class ManyToOneMappingUiProvider /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IManyToOneMapping> instance() { return INSTANCE; } @@ -41,12 +42,17 @@ public class ManyToOneMappingUiProvider public String attributeMappingKey() { return IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_ManyToOneLabel; } - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createManyToOneMappingComposite(parent, commandStack, widgetFactory); + public IJpaComposite<IManyToOneMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IManyToOneMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createManyToOneMappingComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/MappedSuperclassUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/MappedSuperclassUiProvider.java index e15397c483..13db3419e4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/MappedSuperclassUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/MappedSuperclassUiProvider.java @@ -3,22 +3,23 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IMappedSuperclass; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; import org.eclipse.jpt.ui.internal.mappings.details.MappedSuperclassComposite; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class MappedSuperclassUiProvider implements ITypeMappingUiProvider +public class MappedSuperclassUiProvider implements ITypeMappingUiProvider<IMappedSuperclass> { // singleton private static final MappedSuperclassUiProvider INSTANCE = new MappedSuperclassUiProvider(); @@ -26,7 +27,7 @@ public class MappedSuperclassUiProvider implements ITypeMappingUiProvider /** * Return the singleton. */ - public static ITypeMappingUiProvider instance() { + public static ITypeMappingUiProvider<IMappedSuperclass> instance() { return INSTANCE; } @@ -40,12 +41,16 @@ public class MappedSuperclassUiProvider implements ITypeMappingUiProvider public String mappingKey() { return IMappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentTypePage_MappedSuperclassLabel; } - public IJpaComposite buildPersistentTypeMappingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new MappedSuperclassComposite(parent, commandStack, widgetFactory); + public IJpaComposite<IMappedSuperclass> buildPersistentTypeMappingComposite( + PropertyValueModel<IMappedSuperclass> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new MappedSuperclassComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullAttributeMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullAttributeMappingUiProvider.java index ca2907b5ce..511e925934 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullAttributeMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullAttributeMappingUiProvider.java @@ -1,35 +1,35 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +@SuppressWarnings("nls") public class NullAttributeMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IAttributeMapping> { - + // singleton private static final NullAttributeMappingUiProvider INSTANCE = new NullAttributeMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IAttributeMapping> instance() { return INSTANCE; } @@ -41,36 +41,47 @@ public class NullAttributeMappingUiProvider } + /* + * (non-Javadoc) + */ public String attributeMappingKey() { return null; } - + + /* + * (non-Javadoc) + */ public String label() { return ""; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new NullComposite(parent); + + /* + * (non-Javadoc) + */ + public IJpaComposite<IAttributeMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IAttributeMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return new NullComposite(subjectHolder, parent, widgetFactory); } - - - public static class NullComposite extends Composite - implements IJpaComposite - { - NullComposite(Composite parent) { - super(parent, SWT.NONE); - } - - public void populate(EObject model) { - // no op + + public static class NullComposite extends AbstractFormPane<IAttributeMapping> + implements IJpaComposite<IAttributeMapping>{ + + NullComposite(PropertyValueModel<IAttributeMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - + + /* + * (non-Javadoc) + */ @Override - public void dispose() { - super.dispose(); - } - public Control getControl() { - return this; + protected void initializeLayout(Composite container) { } - } + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullTypeMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullTypeMappingUiProvider.java index 1b44936878..88356d1735 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullTypeMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/NullTypeMappingUiProvider.java @@ -3,22 +3,23 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class NullTypeMappingUiProvider implements ITypeMappingUiProvider +@SuppressWarnings("nls") +public class NullTypeMappingUiProvider implements ITypeMappingUiProvider<ITypeMapping> { // singleton private static final NullTypeMappingUiProvider INSTANCE = new NullTypeMappingUiProvider(); @@ -26,7 +27,7 @@ public class NullTypeMappingUiProvider implements ITypeMappingUiProvider /** * Return the singleton. */ - public static ITypeMappingUiProvider instance() { + public static ITypeMappingUiProvider<ITypeMapping> instance() { return INSTANCE; } @@ -36,39 +37,42 @@ public class NullTypeMappingUiProvider implements ITypeMappingUiProvider private NullTypeMappingUiProvider() { super(); } - + public String mappingKey() { return null; } - + public String label() { return ""; } - - public IJpaComposite buildPersistentTypeMappingComposite( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { + + public IJpaComposite<ITypeMapping> buildPersistentTypeMappingComposite( + PropertyValueModel<ITypeMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + return new NullComposite(parent); } - - - public static class NullComposite extends Composite - implements IJpaComposite + + + public static class NullComposite extends Composite + implements IJpaComposite<ITypeMapping> { private Composite composite; NullComposite(Composite parent) { super(parent, SWT.NONE); this.composite = new Composite(parent, SWT.NONE); } - - public void populate(EObject model) { + + public void populate() { // no op } - + @Override public void dispose() { super.dispose(); } - + public Control getControl() { return this.composite; } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToManyMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToManyMappingUiProvider.java index cc9fd85c26..cc53b9ff90 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToManyMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToManyMappingUiProvider.java @@ -3,23 +3,24 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class OneToManyMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IOneToManyMapping> { // singleton private static final OneToManyMappingUiProvider INSTANCE = new OneToManyMappingUiProvider(); @@ -27,7 +28,7 @@ public class OneToManyMappingUiProvider /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IOneToManyMapping> instance() { return INSTANCE; } @@ -41,12 +42,17 @@ public class OneToManyMappingUiProvider public String attributeMappingKey() { return IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_OneToManyLabel; } - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createOneToManyMappingComposite(parent, commandStack, widgetFactory); + public IJpaComposite<IOneToManyMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IOneToManyMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createOneToManyMappingComposite(subjectHolder, parent, widgetFactory); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToOneMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToOneMappingUiProvider.java index d59e50ca32..5911e92c98 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToOneMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/OneToOneMappingUiProvider.java @@ -3,32 +3,33 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class OneToOneMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IOneToOneMapping> { - + // singleton private static final OneToOneMappingUiProvider INSTANCE = new OneToOneMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IOneToOneMapping> instance() { return INSTANCE; } @@ -42,12 +43,17 @@ public class OneToOneMappingUiProvider public String attributeMappingKey() { return IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_OneToOneLabel; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createOneToOneMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IOneToOneMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IOneToOneMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createOneToOneMappingComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/TransientMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/TransientMappingUiProvider.java index 10d679d8da..12de4a399a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/TransientMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/TransientMappingUiProvider.java @@ -3,32 +3,33 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.ITransientMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class TransientMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<ITransientMapping> { - + // singleton private static final TransientMappingUiProvider INSTANCE = new TransientMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<ITransientMapping> instance() { return INSTANCE; } @@ -42,12 +43,17 @@ public class TransientMappingUiProvider public String attributeMappingKey() { return IMappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_TransientLabel; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createTransientMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<ITransientMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<ITransientMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createTransientMappingComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/VersionMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/VersionMappingUiProvider.java index 67f4d523f1..35950bf8fe 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/VersionMappingUiProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/mappings/properties/VersionMappingUiProvider.java @@ -3,32 +3,33 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.java.mappings.properties; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.jpt.core.internal.IMappingKeys; +import org.eclipse.jpt.core.internal.context.base.IVersionMapping; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; public class VersionMappingUiProvider - implements IAttributeMappingUiProvider + implements IAttributeMappingUiProvider<IVersionMapping> { - + // singleton private static final VersionMappingUiProvider INSTANCE = new VersionMappingUiProvider(); /** * Return the singleton. */ - public static IAttributeMappingUiProvider instance() { + public static IAttributeMappingUiProvider<IVersionMapping> instance() { return INSTANCE; } @@ -42,12 +43,17 @@ public class VersionMappingUiProvider public String attributeMappingKey() { return IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; } - + public String label() { return JptUiMappingsMessages.PersistentAttributePage_VersionLabel; } - - public IJpaComposite buildAttributeMappingComposite(IJpaUiFactory factory, Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return factory.createVersionMappingComposite(parent, commandStack, widgetFactory); + + public IJpaComposite<IVersionMapping> buildAttributeMappingComposite( + IJpaUiFactory factory, + PropertyValueModel<IVersionMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + return factory.createVersionMappingComposite(subjectHolder, parent, widgetFactory); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaCompilationUnitItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaCompilationUnitItemProvider.java deleted file mode 100644 index ba60ac46d8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaCompilationUnitItemProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.structure; - -import java.util.Collection; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jpt.core.internal.content.java.JpaCompilationUnit; -import org.eclipse.jpt.core.internal.content.java.JpaJavaPackage; - -public class JavaCompilationUnitItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public JavaCompilationUnitItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - @Override - protected Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) { - if (this.childrenFeatures == null) { - super.getChildrenFeatures(object); - this.childrenFeatures.add(JpaJavaPackage.Literals.JPA_COMPILATION_UNIT__TYPES); - } - return this.childrenFeatures; - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(JpaCompilationUnit.class)) { - case JpaJavaPackage.JPA_COMPILATION_UNIT__TYPES: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), true, false)); - return; - } - - super.notifyChanged(notification); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaPersistentAttributeItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaPersistentAttributeItemProvider.java deleted file mode 100644 index 902c83233e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaPersistentAttributeItemProvider.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.structure; - -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jpt.core.internal.IAttributeMapping; -import org.eclipse.jpt.core.internal.IPersistentAttribute; -import org.eclipse.jpt.core.internal.JpaCorePackage; -import org.eclipse.jpt.core.internal.mappings.IBasic; -import org.eclipse.jpt.core.internal.mappings.IEmbedded; -import org.eclipse.jpt.core.internal.mappings.IEmbeddedId; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.IManyToMany; -import org.eclipse.jpt.core.internal.mappings.IManyToOne; -import org.eclipse.jpt.core.internal.mappings.IOneToMany; -import org.eclipse.jpt.core.internal.mappings.IOneToOne; -import org.eclipse.jpt.core.internal.mappings.ITransient; -import org.eclipse.jpt.core.internal.mappings.IVersion; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsImages; - -public class JavaPersistentAttributeItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public JavaPersistentAttributeItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - @Override - public Object getImage(Object object) { - IAttributeMapping mapping = ((IPersistentAttribute) object).getMapping(); - - if (mapping instanceof IBasic) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.BASIC); - } - else if (mapping instanceof IId) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.ID); - } - else if (mapping instanceof IVersion) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.VERSION); - } - else if (mapping instanceof IEmbedded) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.EMBEDDED); - } - else if (mapping instanceof IEmbeddedId) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.EMBEDDED_ID); - } - else if (mapping instanceof IOneToOne) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.ONE_TO_ONE); - } - else if (mapping instanceof IOneToMany) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.ONE_TO_MANY); - } - else if (mapping instanceof IManyToOne) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.MANY_TO_ONE); - } - else if (mapping instanceof IManyToMany) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.MANY_TO_MANY); - } - else if (mapping instanceof ITransient) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.TRANSIENT); - } - else { - return JptUiMappingsImages.getImage(JptUiMappingsImages.NULL_ATTRIBUTE_MAPPING); - } - } - - @Override - public String getText(Object object) { - return ((IPersistentAttribute) object).getName(); - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(IPersistentAttribute.class)) { - case JpaCorePackage.IPERSISTENT_ATTRIBUTE__MAPPING: - fireNotifyChanged(new ViewerNotification(notification, notification - .getNotifier(), false, true)); - return; - } - super.notifyChanged(notification); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaPersistentTypeItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaPersistentTypeItemProvider.java deleted file mode 100644 index c1cd5bb875..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaPersistentTypeItemProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.structure; - -import java.util.Collection; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jdt.core.IType; -import org.eclipse.jpt.core.internal.IPersistentType; -import org.eclipse.jpt.core.internal.ITypeMapping; -import org.eclipse.jpt.core.internal.JpaCorePackage; -import org.eclipse.jpt.core.internal.content.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.content.java.JpaJavaPackage; -import org.eclipse.jpt.core.internal.mappings.IEmbeddable; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IMappedSuperclass; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsImages; - -public class JavaPersistentTypeItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public JavaPersistentTypeItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - - @Override - protected Collection getChildrenFeatures(Object object) { - if (childrenFeatures == null) { - super.getChildrenFeatures(object); - childrenFeatures.add(JpaJavaPackage.Literals.JAVA_PERSISTENT_TYPE__ATTRIBUTES); - } - return childrenFeatures; - } - - @Override - public Object getImage(Object object) { - ITypeMapping mapping = ((IPersistentType) object).getMapping(); - - - if (mapping instanceof IEntity) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.ENTITY); - } - else if (mapping instanceof IEmbeddable) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.EMBEDDABLE); - } - else if (mapping instanceof IMappedSuperclass) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.MAPPED_SUPERCLASS); - } - else { - return null; - } - } - - @Override - public String getText(Object object) { - IType type = ((IPersistentType) object).findJdtType(); - return (type == null) ? "" : type.getElementName(); - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(JavaPersistentType.class)) { - case JpaCorePackage.IPERSISTENT_TYPE__MAPPING_KEY: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), false, true)); - return; - - case JpaJavaPackage.JAVA_PERSISTENT_TYPE__ATTRIBUTES: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), true, false)); - return; - } - - super.notifyChanged(notification); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaStructureProvider.java deleted file mode 100644 index a1af28c175..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JavaStructureProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.structure; - -import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; -import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; - -public class JavaStructureProvider implements IJpaStructureProvider -{ - public String fileContentType() { - return JavaCore.JAVA_SOURCE_CONTENT_TYPE; - } - - public ITreeContentProvider buildContentProvider() { - return new AdapterFactoryContentProvider(new JpaCoreJavaItemProviderAdapterFactory()); - } - - public ILabelProvider buildLabelProvider() { - return new AdapterFactoryLabelProvider(new JpaCoreJavaItemProviderAdapterFactory()); - } - - public void dispose() { - // TODO Auto-generated method stub - - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JpaCoreJavaItemProviderAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JpaCoreJavaItemProviderAdapterFactory.java deleted file mode 100644 index 730853482c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/structure/JpaCoreJavaItemProviderAdapterFactory.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.structure; - -import java.util.ArrayList; -import java.util.Collection; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.edit.provider.ChangeNotifier; -import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; -import org.eclipse.emf.edit.provider.ComposedAdapterFactory; -import org.eclipse.emf.edit.provider.IChangeNotifier; -import org.eclipse.emf.edit.provider.IDisposable; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.INotifyChangedListener; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.jpt.core.internal.content.java.util.JpaJavaAdapterFactory; - -/** - * This is the factory that is used to provide the interfaces needed to support Viewers. - * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}. - * The adapters also support Eclipse property sheets. - * Note that most of the adapters are shared among multiple instances. - */ -public class JpaCoreJavaItemProviderAdapterFactory - extends JpaJavaAdapterFactory - implements ComposeableAdapterFactory, - IChangeNotifier, - IDisposable -{ - /** - * This keeps track of the root adapter factory that delegates to this adapter factory. - */ - protected ComposedAdapterFactory parentAdapterFactory; - - /** - * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}. - */ - protected IChangeNotifier changeNotifier = new ChangeNotifier(); - - /** - * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}. - */ - protected Collection supportedTypes = new ArrayList(); - - - public JpaCoreJavaItemProviderAdapterFactory() { - supportedTypes.add(IEditingDomainItemProvider.class); - supportedTypes.add(IStructuredItemContentProvider.class); - supportedTypes.add(ITreeItemContentProvider.class); - supportedTypes.add(IItemLabelProvider.class); - } - - - protected JavaCompilationUnitItemProvider javaCompilationUnitItemProvider; - - public Adapter createJpaCompilationUnitAdapter() { - if (javaCompilationUnitItemProvider == null) { - javaCompilationUnitItemProvider = new JavaCompilationUnitItemProvider(this); - } - - return javaCompilationUnitItemProvider; - } - - protected JavaPersistentTypeItemProvider javaPersistentTypeItemProvider; - - public Adapter createJavaPersistentTypeAdapter() { - if (javaPersistentTypeItemProvider == null) { - javaPersistentTypeItemProvider = new JavaPersistentTypeItemProvider(this); - } - - return javaPersistentTypeItemProvider; - } - - protected JavaPersistentAttributeItemProvider javaPersistentAttributeItemProvider; - - public Adapter createJavaPersistentAttributeAdapter() { - if (javaPersistentAttributeItemProvider == null) { - javaPersistentAttributeItemProvider = new JavaPersistentAttributeItemProvider( - this); - } - - return javaPersistentAttributeItemProvider; - } - - /** - * This returns the root adapter factory that contains this factory. - */ - public ComposeableAdapterFactory getRootAdapterFactory() { - return parentAdapterFactory == null ? - this : - parentAdapterFactory.getRootAdapterFactory(); - } - - /** - * This sets the composed adapter factory that contains this factory. - */ - public void setParentAdapterFactory( - ComposedAdapterFactory parentAdapterFactory) { - this.parentAdapterFactory = parentAdapterFactory; - } - - public boolean isFactoryForType(Object type) { - return supportedTypes.contains(type) || super.isFactoryForType(type); - } - - /** - * This implementation substitutes the factory itself as the key for the adapter. - */ - public Adapter adapt(Notifier notifier, Object type) { - return super.adapt(notifier, this); - } - - public Object adapt(Object object, Object type) { - if (isFactoryForType(type)) { - Object adapter = super.adapt(object, type); - if (!(type instanceof Class) - || (((Class) type).isInstance(adapter))) { - return adapter; - } - } - - return null; - } - - /** - * This adds a listener. - */ - public void addListener(INotifyChangedListener notifyChangedListener) { - changeNotifier.addListener(notifyChangedListener); - } - - /** - * This removes a listener. - */ - public void removeListener(INotifyChangedListener notifyChangedListener) { - changeNotifier.removeListener(notifyChangedListener); - } - - /** - * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}. - */ - public void fireNotifyChanged(Notification notification) { - changeNotifier.fireNotifyChanged(notification); - - if (parentAdapterFactory != null) { - parentAdapterFactory.fireNotifyChanged(notification); - } - } - - /** - * This disposes all of the item providers created by this factory. - */ - public void dispose() { - if (javaCompilationUnitItemProvider != null) { - javaCompilationUnitItemProvider.dispose(); - } - if (javaPersistentTypeItemProvider != null) { - javaPersistentTypeItemProvider.dispose(); - } - if (javaPersistentAttributeItemProvider != null) { - javaPersistentAttributeItemProvider.dispose(); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java new file mode 100644 index 0000000000..f1471b3148 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java @@ -0,0 +1,153 @@ +package org.eclipse.jpt.ui.internal.jface; + +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.graphics.Image; + +/** + * Implementation of {@link IItemLabelProvider} that provides updating + * label information for a Model object. + * + * The typical subclass will override the following methods: + * #buildTextModel() + * return a {@link PropertyValueModel} that represents the text for the represented + * model object. + * #buildImageModel() + * return a {@link PropertyValueModel} that represents the image 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 IItemLabelProvider +{ + private DelegatingContentAndLabelProvider labelProvider; + + private Model model; + + private PropertyValueModel<String> textModel; + + private PropertyValueModel<Image> imageModel; + + 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) { + labelProvider().updateLabel(model()); + } + }; + } + + /** + * Return the text value model + * (lazy and just-in-time initialized) + */ + protected PropertyValueModel<String> textModel() { + if (textModel == null) { + textModel = buildTextModel(); + engageTextModel(); + } + return 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() { + textModel.addPropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); + } + + /** + * Should only be overridden with a call to super.disengageTextModel() after + * subclass logic + */ + protected void disengageTextModel() { + if (textModel != null) { + textModel.removePropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); + } + } + + /** + * Return the image value model + * (lazy and just-in-time initialized) + */ + protected PropertyValueModel<Image> imageModel() { + if (imageModel == null) { + imageModel = buildImageModel(); + engageImageModel(); + } + return 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() { + imageModel.addPropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); + } + + /** + * Should only be overridden with a call to super.disengageImageModel() after + * subclass logic + */ + protected void disengageImageModel() { + if (imageModel != null) { + imageModel.removePropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); + } + } + + /** + * Return the model object represented by this item + */ + public Model model() { + return model; + } + + /** + * Return the label provider that delegates to this item + */ + public DelegatingContentAndLabelProvider labelProvider() { + return labelProvider; + } + + public String text() { + return textModel().value(); + } + + public Image image() { + return imageModel().value(); + } + + public void dispose() { + disengageTextModel(); + disengageImageModel(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java new file mode 100644 index 0000000000..c20cfaf1bf --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.jface; + +import java.util.Iterator; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.ListChangeListener; +import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.NullListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyCollectionValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; + +/** + * Implementation of {@link ITreeItemContentProvider} 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 ITreeItemContentProvider +{ + private DelegatingTreeContentAndLabelProvider treeContentProvider; + + private Model model; + + private ListValueModel<E> childrenModel; + + private ListChangeListener 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 ListChangeListener buildChildrenListener() { + return new ListChangeListener() { + public void itemsAdded(ListChangeEvent event) { + treeContentProvider().updateContent(model()); + } + + public void itemsMoved(ListChangeEvent event) { + treeContentProvider().updateContent(model()); + } + + public void itemsRemoved(ListChangeEvent event) { + treeContentProvider().updateContent(model()); + for (Iterator<?> stream = event.items(); stream.hasNext(); ) { + treeContentProvider().dispose(stream.next()); + } + } + + public void itemsReplaced(ListChangeEvent event) { + treeContentProvider().updateContent(model()); + for (Iterator<?> stream = event.replacedItems(); stream.hasNext(); ) { + treeContentProvider().dispose(stream.next()); + } + } + + public void listChanged(ListChangeEvent event) { + treeContentProvider().updateContent(model()); + // 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 listCleared(ListChangeEvent event) { + treeContentProvider().updateContent(model()); + // 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 ListValueModel<E> childrenModel() { + if (childrenModel == null) { + childrenModel = buildChildrenModel(); + engageChildren(); + } + return childrenModel; + } + + /** + * Construct a children model + */ + @SuppressWarnings("unchecked") + protected ListValueModel<E> buildChildrenModel() { + return new NullListValueModel(); + } + + /** + * 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 ListValueModel<E> buildChildrenModel(CollectionValueModel<E> childrenModel) { + return new CollectionListValueModelAdapter<E>(childrenModel); + } + + /** + * 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> childrenModel) { + return buildChildrenModel(new PropertyCollectionValueModelAdapter<E>(childrenModel)); + } + + /** + * Return the model object represented by this node + */ + public Model model() { + return model; + } + + /** + * Return the tree content provider that delegates to this node + */ + public DelegatingTreeContentAndLabelProvider treeContentProvider() { + return treeContentProvider; + } + + public Object getParent() { + return null; + } + + public Object[] getElements() { + return getChildren(); + } + + public Object[] getChildren() { + return CollectionTools.array(childrenModel().listIterator()); + } + + /** + * Override with potentially more efficient logic + */ + public boolean hasChildren() { + return childrenModel().listIterator().hasNext(); + } + + /** + * Should only be overridden with a call to super.dispose() + */ + public void dispose() { + for (Object child : getChildren()) { + treeContentProvider().dispose(child); + } + disengageChildren(); + } + + /** + * Should only be overridden with a call to super.engageChildren() before + * subclass logic + */ + protected void engageChildren() { + childrenModel.addListChangeListener(ListValueModel.LIST_VALUES, childrenListener); + } + + /** + * Should only be overridden with a call to super.disengageChildren() after + * subclass logic + */ + protected void disengageChildren() { + if (childrenModel != null) { + childrenModel.removeListChangeListener(ListValueModel.LIST_VALUES, childrenListener); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingContentAndLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingContentAndLabelProvider.java new file mode 100644 index 0000000000..35294e85ea --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingContentAndLabelProvider.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * 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.ui.internal.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; + +/** + * Implementation of {@link IStructuredContentProvider} and {@link ILabelProvider} that + * maintains a collection (Map, actually) of {@link IItemContentProvider} + * 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. + */ +public abstract class DelegatingContentAndLabelProvider extends BaseLabelProvider + implements IStructuredContentProvider, ILabelProvider +{ + private final IItemContentProviderFactory itemContentProviderFactory; + + private final IItemLabelProviderFactory itemLabelProviderFactory; + + private final Map<Object, IItemContentProvider> itemContentProviders; + + private final Map<Object, IItemLabelProvider> itemLabelProviders; + + private StructuredViewer viewer; + + + protected DelegatingContentAndLabelProvider( + IItemContentProviderFactory itemContentProviderFactory) { + this(itemContentProviderFactory, null); + } + + protected DelegatingContentAndLabelProvider( + IItemContentProviderFactory itemContentProviderFactory, + IItemLabelProviderFactory itemLabelProviderFactory) { + super(); + this.itemContentProviderFactory = itemContentProviderFactory; + this.itemLabelProviderFactory = itemLabelProviderFactory; + this.itemContentProviders = new HashMap<Object, IItemContentProvider>(); + this.itemLabelProviders = new HashMap<Object, IItemLabelProvider>(); + } + + + protected IItemContentProvider itemContentProvider(Object item) { + IItemContentProvider itemContentProvider = itemContentProviders.get(item); + if (itemContentProvider != null) { + return itemContentProvider; + } + itemContentProvider = itemContentProviderFactory.buildItemContentProvider(item, this); + if (itemContentProvider == null) { + return null; + } + itemContentProviders.put(item, itemContentProvider); + return itemContentProvider; + } + + protected IItemLabelProvider itemLabelProvider(Object item) { + if (viewer == null) { + throw new IllegalStateException( + "This provider must be used as a content" + + "provider *as well as* a label provider."); + } + IItemLabelProvider itemLabelProvider = itemLabelProviders.get(item); + if (itemLabelProvider != null) { + return itemLabelProvider; + } + itemLabelProvider = itemLabelProviderFactory.buildItemLabelProvider(item, this); + if (itemLabelProvider == null) { + return null; + } + itemLabelProviders.put(item, itemLabelProvider); + return itemLabelProvider; + } + + + public Object[] getElements(Object inputElement) { + return itemContentProvider(inputElement).getElements(); + } + + public Image getImage(Object element) { + return itemLabelProvider(element).image(); + } + + public String getText(Object element) { + return itemLabelProvider(element).text(); + } + + /** + * Disposes all items + */ + public void dispose() { + // coded this way to allow some item providers to dispose of their child + // elements without disrupting the entire process + while (! itemContentProviders.isEmpty()) { + dispose(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 (! itemLabelProviders.isEmpty()) { + dispose(itemLabelProviders.keySet().iterator().next()); + } + } + + /** + * Disposes item + */ + protected void dispose(Object item) { + if (itemContentProviders.containsKey(item)) { + itemContentProviders.get(item).dispose(); + itemContentProviders.remove(item); + } + if (itemLabelProviders.containsKey(item)) { + itemLabelProviders.get(item).dispose(); + itemLabelProviders.remove(item); + } + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (oldInput != newInput) { + dispose(); + } + this.viewer = (StructuredViewer) viewer; + } + + /** + * 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); + } + } + }; + viewer.getControl().getDisplay().asyncExec(runnable); + } + + /** + * 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)); + } + } + }; + viewer.getControl().getDisplay().asyncExec(runnable); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java new file mode 100644 index 0000000000..b400887ccb --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.jface; + +import org.eclipse.jface.viewers.ITreeContentProvider; + +/** + * Extension of {@link DelegatingContentAndLabelProvider} that provides an extension + * to provide tree content + */ +public class DelegatingTreeContentAndLabelProvider extends DelegatingContentAndLabelProvider + implements ITreeContentProvider +{ + public DelegatingTreeContentAndLabelProvider( + ITreeItemContentProviderFactory treeItemContentProviderFactory) { + super(treeItemContentProviderFactory); + } + + public DelegatingTreeContentAndLabelProvider( + ITreeItemContentProviderFactory treeItemContentProviderFactory, + IItemLabelProviderFactory itemLabelProviderFactory) { + super(treeItemContentProviderFactory, itemLabelProviderFactory); + } + + + protected ITreeItemContentProvider itemContentProvider(Object item) { + return (ITreeItemContentProvider) super.itemContentProvider(item); + } + + public Object[] getChildren(Object parentElement) { + return itemContentProvider(parentElement).getChildren(); + } + + public Object getParent(Object element) { + return itemContentProvider(element).getParent(); + } + + public boolean hasChildren(Object element) { + return itemContentProvider(element).hasChildren(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemContentProvider.java new file mode 100644 index 0000000000..06589c7da7 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemContentProvider.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.ui.internal.jface; + +/** + * Marker interface used in conjunction with DelegatingContentProvider to return + * content information for a particular item. + * @see DelegatingContentProvider + * @see IItemContentProviderFactory + */ +public interface IItemContentProvider +{ + /** + * Return the elements of the represented item. + * Note that when this is called, the represented item is an input element. + */ + Object[] getElements(); + + /** + * Dispose of this content provider, cleaning up all references, listeners, etc. + */ + void dispose(); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemContentProviderFactory.java new file mode 100644 index 0000000000..4237b9b707 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemContentProviderFactory.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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.ui.internal.jface; + +/** + * Factory interface used to describe how to build {@link IItemContentProvider}s + * for a {@link DelegatingContentAndLabelProvider} + */ +public interface IItemContentProviderFactory +{ + IItemContentProvider buildItemContentProvider(Object item, + DelegatingContentAndLabelProvider contentAndLabelProvider); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemLabelProvider.java new file mode 100644 index 0000000000..d59afdd16e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemLabelProvider.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.ui.internal.jface; + +import org.eclipse.swt.graphics.Image; + +/** + * Interface used in conjunction with DelegatingLabelProvider to return + * label information for a particular item. + * @see DelegatingLabelProvider + * @see IItemLabelProviderFactory + */ +public interface IItemLabelProvider +{ + /** + * Return the image for the item + */ + Image image(); + + /** + * Return the text for the item + */ + public String text(); + + /** + * Dispose of this label provider, cleaning up all references, listeners, etc. + */ + void dispose(); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemLabelProviderFactory.java new file mode 100644 index 0000000000..4979ee32b7 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/IItemLabelProviderFactory.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * 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.ui.internal.jface; + +/** + * Factory interface used to describe how to build IItemLabelProviders + * for a DelegatingContentAndLabelProvider + */ +public interface IItemLabelProviderFactory +{ + IItemLabelProvider buildItemLabelProvider( + Object item, DelegatingContentAndLabelProvider contentAndLabelProvider); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ITreeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ITreeItemContentProvider.java new file mode 100644 index 0000000000..520f966ef4 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ITreeItemContentProvider.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.jface; + +/** + * Interface used in conjunction with DelegatingTreeContentProvider to return + * tree information for a particular item. + * @see DelegatingTreeContentProvider + * @see ITreeItemContentProviderFactory + */ +public interface ITreeItemContentProvider extends IItemContentProvider +{ + /** + * 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 + */ + Object[] getChildren(); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ITreeItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ITreeItemContentProviderFactory.java new file mode 100644 index 0000000000..9d0b0009d0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ITreeItemContentProviderFactory.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.jface; + +/** + * Extension of {@link IItemContentProviderFactory} that extends functionality + * for tree content + */ +public interface ITreeItemContentProviderFactory extends IItemContentProviderFactory +{ + public ITreeItemContentProvider buildItemContentProvider(Object item, + DelegatingContentAndLabelProvider contentAndLabelProvider); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java index 7fb66541d9..22fad41590 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java @@ -1,43 +1,60 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License 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, 2007 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.ui.internal.jface; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.swt.graphics.Image; -public class NullLabelProvider +/** + * Null implementation of the ILabelProvider interface. + * Implemented as a singleton. + */ +public final class NullLabelProvider implements ILabelProvider { - public static NullLabelProvider INSTANCE = new NullLabelProvider(); - - + 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) {} - - public void dispose() {} - + + 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) {} + + public void removeListener(ILabelProviderListener listener) { + // do nothing + } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java index 864a29b08f..2a53f274de 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java @@ -1,44 +1,60 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License 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, 2007 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.ui.internal.jface; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; -public class NullTreeContentProvider +/** + * Null implementation of the ILabelProvider interface. + * Implemented as a singleton. + */ +public final class NullTreeContentProvider implements ITreeContentProvider { - public static NullTreeContentProvider INSTANCE = new NullTreeContentProvider(); - - + 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 new Object[0]; + return EMPTY_ARRAY; } - + public Object getParent(Object element) { return null; } - + public boolean hasChildren(Object element) { return false; } - + public Object[] getElements(Object inputElement) { - return new Object[0]; + return EMPTY_ARRAY; + } + + public void dispose() { + // do nothing + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // do nothing } - - public void dispose() {} - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsImages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsImages.java deleted file mode 100644 index 7acab93e34..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsImages.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings; - -import org.eclipse.jpt.ui.internal.JptUiPlugin; -import org.eclipse.swt.graphics.Image; - -public class JptUiMappingsImages -{ - public final static String BASIC = "full/obj16/basic"; - - public final static String EMBEDDABLE = "full/obj16/embeddable"; - - public final static String EMBEDDED = "full/obj16/embedded"; - - public final static String EMBEDDED_ID = "full/obj16/embedded-id"; - - public final static String ENTITY = "full/obj16/entity"; - - public final static String ENTITY_MAPPINGS = "full/obj16/entity-mappings"; - - public final static String ID = "full/obj16/id"; - - public final static String NULL_ATTRIBUTE_MAPPING = "full/obj16/null-attribute-mapping"; - - public final static String MANY_TO_MANY = "full/obj16/many-to-many"; - - public final static String MANY_TO_ONE = "full/obj16/many-to-one"; - - public final static String MAPPED_SUPERCLASS = "full/obj16/mapped-superclass"; - - public final static String NULL_TYPE_MAPPING = "full/obj16/null-type-mapping"; - - public final static String ONE_TO_MANY = "full/obj16/one-to-many"; - - public final static String ONE_TO_ONE = "full/obj16/one-to-one"; - - public final static String TEMPORAL = "full/obj16/temporal"; - - public final static String TRANSIENT = "full/obj16/transient"; - - public final static String VERSION = "full/obj16/version"; - - - public static Image getImage(String imageLocator) { - return JptUiPlugin.getPlugin().getImageDescriptor(imageLocator).createImage(); - } - - - private JptUiMappingsImages() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java index 03380e75d7..a59bea443a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java @@ -1,20 +1,23 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings; import org.eclipse.osgi.util.NLS; -public class JptUiMappingsMessages extends NLS +public class JptUiMappingsMessages extends NLS { private static final String BUNDLE_NAME = "jpt_ui_mappings"; //$NON-NLS-1$ - + + public static String Boolean_True; + public static String Boolean_False; + public static String PersistentTypePage_EntityLabel; public static String PersistentTypePage_EmbeddableLabel; public static String PersistentTypePage_MappedSuperclassLabel; @@ -30,40 +33,44 @@ public class JptUiMappingsMessages extends NLS public static String PersistentAttributePage_EmbeddedIdLabel; public static String PersistentAttributePage_OneToOneLabel; - public static String EntityGeneralSection_nameDefaultWithOneParam; public static String EntityGeneralSection_nameDefaultEmpty; public static String EntityGeneralSection_name; - + public static String BasicGeneralSection_name; public static String BasicGeneralSection_nameDefault; public static String BasicGeneralSection_fetchLabel; public static String BasicGeneralSection_optionalLabel; + public static String BasicGeneralSection_optionalLabelDefault; public static String BasicGeneralSection_lobLabel; public static String BasicGeneralSection_temporalLabel; public static String BasicGeneralSection_enumeratedLabel; + public static String DefaultBasicMappingUiProvider_Default; + public static String DefaultEmbeddedMappingUiProvider_Default; + public static String EntityComposite_tableDefault; public static String EntityComposite_tableNoDefaultSpecified; public static String EntityComposite_inheritance; public static String TableComposite_tableSection; public static String TableComposite_defaultEmpty; public static String TableComposite_defaultWithOneParam; - + public static String TableChooser_label; public static String CatalogChooser_label; public static String SchemaChooser_label; public static String ColumnChooser_label; public static String ColumnTableChooser_label; - + public static String TargetEntityChooser_label; public static String TargetEntityChooser_defaultEmpty; public static String TargetEntityChooser_defaultWithOneParam; public static String TargetEntityChooser_browse; - + public static String TargetEntityChooser_selectTypeTitle; + public static String NonOwningMapping_mappedByLabel; - + public static String JoinTableComposite_add; public static String JoinTableComposite_defaultEmpty; public static String JoinTableComposite_defaultWithOneParam; @@ -88,11 +95,10 @@ public class JptUiMappingsMessages extends NLS public static String JoinColumnDialog_defaultWithOneParam; public static String JoinColumnDialog_referencedColumnName; public static String JoinColumnDialog_table; - + public static String InverseJoinColumnDialog_defaultWithOneParam; public static String InverseJoinColumnDialog_editInverseJoinColumn; - public static String MultiRelationshipMappingComposite_cascadeType; public static String MultiRelationshipMappingComposite_fetchType; public static String MultiRelationshipMappingComposite_general; @@ -103,8 +109,10 @@ public class JptUiMappingsMessages extends NLS public static String ColumnComposite_columnSection; public static String ColumnComposite_defaultWithOneParam; public static String ColumnComposite_defaultEmpty; - public static String ColumnComposite_insertable; + public static String ColumnComposite_insertable; + public static String ColumnComposite_insertableWithDefault; public static String ColumnComposite_updatable; + public static String ColumnComposite_updatableWithDefault; public static String JoinColumnComposite_defaultEmpty; public static String JoinColumnComposite_defaultWithOneParam; @@ -121,9 +129,7 @@ public class JptUiMappingsMessages extends NLS public static String JoinColumnComposite_overrideDefaultJoinColumns; public static String PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns; - public static String PrimaryKeyJoinColumnsComposite_add; public static String PrimaryKeyJoinColumnsComposite_edit; - public static String PrimaryKeyJoinColumnsComposite_remove; public static String PrimaryKeyJoinColumnsComposite_defaultEmpty; public static String PrimaryKeyJoinColumnsComposite_defaultWithOneParam; public static String PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn; @@ -132,18 +138,18 @@ public class JptUiMappingsMessages extends NLS public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault; public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault; public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault; - + public static String AttributeOverridesComposite_attributeOverrides; - public static String AttributeOverridesComposite_overridDefault; + public static String AttributeOverridesComposite_overrideDefault; public static String OverridesComposite_joinColumn; - public static String InheritanceComposite_default; - public static String InheritanceComposite_strategy; - public static String InheritanceComposite_discriminatorValue; + public static String InheritanceComposite_default; + public static String InheritanceComposite_strategy; + public static String InheritanceComposite_discriminatorValue; public static String InheritanceComposite_discriminatorValueDefaultWithOneParam; - public static String DiscriminatorColumnComposite_defaultEmpty; - public static String DiscriminatorColumnComposite_column; + public static String DiscriminatorColumnComposite_defaultEmpty; + public static String DiscriminatorColumnComposite_column; public static String DiscriminatorColumnComposite_discriminatorType; public static String GeneratedValueComposite_generatedValue; @@ -163,35 +169,65 @@ public class JptUiMappingsMessages extends NLS public static String SequenceGeneratorComposite_sequence; public static String SequenceGeneratorComposite_default; - public static String IdMappingComposite_pk_generation; - public static String IdMappingComposite_primaryKeyGeneration; + public static String IdMappingComposite_pk_generation; + public static String IdMappingComposite_primaryKeyGeneration; public static String IdMappingComposite_tableGenerator; public static String IdMappingComposite_sequenceGenerator; - public static String OrderByComposite_orderByGroup; - public static String OrderByComposite_noOrdering; - public static String OrderByComposite_primaryKeyOrdering; + public static String OrderByComposite_orderByGroup; + public static String OrderByComposite_noOrdering; + public static String OrderByComposite_primaryKeyOrdering; public static String OrderByComposite_customOrdering; public static String OrderByComposite_orderByLabel; public static String SecondaryTablesComposite_secondaryTables; - public static String SecondaryTablesComposite_add; public static String SecondaryTablesComposite_edit; - public static String SecondaryTablesComposite_remove; public static String SecondaryTableDialog_editSecondaryTable; public static String SecondaryTableDialog_name; public static String SecondaryTableDialog_catalog; public static String SecondaryTableDialog_schema; public static String SecondaryTableDialog_defaultSchema; - public static String SecondaryTableDialog_defaultCatalog; - + public static String SecondaryTableDialog_defaultCatalog; + public static String AccessTypeCombo_default; - public static String EnumComboViewer_default; public static String MetaDataCompleteCombo_Default; public static String JoinColumnDialog_defaultTrue; public static String InheritanceComposite_defaultDiscriminatorType; - public static String GeneratedValueComposite_default; + public static String GeneratedValueComposite_auto; + public static String GeneratedValueComposite_identity; + public static String GeneratedValueComposite_sequence; + public static String GeneratedValueComposite_table; + + public static String OptionalComposite_false; + public static String OptionalComposite_true; + + public static String EnumTypeComposite_ordinal; + public static String EnumTypeComposite_string; + + public static String TemporalTypeComposite_date; + public static String TemporalTypeComposite_time; + public static String TemporalTypeComposite_timestamp; + + public static String FetchTypeComposite_eager; + public static String FetchTypeComposite_lazy; + + public static String CascadeComposite_all; + public static String CascadeComposite_cascadeTitle; + public static String CascadeComposite_merge; + public static String CascadeComposite_persist; + public static String CascadeComposite_refresh; + public static String CascadeComposite_remove; + + public static String InheritanceComposite_single_table; + public static String InheritanceComposite_joined; + public static String InheritanceComposite_table_per_class; + public static String InheritanceComposite_string; + public static String InheritanceComposite_char; + public static String InheritanceComposite_integer; + + public static String MetaDataCompleteComboViewer_true; + public static String MetaDataCompleteComboViewer_false; static { // initialize resource bundle @@ -201,5 +237,4 @@ public class JptUiMappingsMessages extends NLS private JptUiMappingsMessages() { throw new UnsupportedOperationException(); } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java new file mode 100644 index 0000000000..fd885df523 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java @@ -0,0 +1,462 @@ +/******************************************************************************* + * 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.ui.internal.mappings.db; + +import java.util.Iterator; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.db.internal.ConnectionListener; +import org.eclipse.jpt.db.internal.ConnectionProfile; +import org.eclipse.jpt.db.internal.Database; +import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.ui.internal.Tracing; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.util.SWTUtil; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.ClassTools; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; + +/** + * This abstract implementation keeps a combo in sync with the database objects + * when a connection is active. + * + * @see CatalogCombo + * @see ColumnCombo + * @see SchemaCombo + * @see TableCombo + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public abstract class AbstractDatabaseObjectCombo<T extends IJpaNode> extends AbstractFormPane<T> +{ + /** + * The main widget of this pane. + */ + private CCombo combo; + + /** + * The listener added to the <code>ConnectionProfile</code> responsible to + * keep the combo in sync with the database metadata. + */ + private ConnectionListener connectionListener; + + /** + * Creates a new <code>AbstractDatabaseObjectCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + protected AbstractDatabaseObjectCombo(AbstractFormPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>AbstractDatabaseObjectCombo</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + protected AbstractDatabaseObjectCombo(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) + { + super(subjectHolder, parent, widgetFactory); + } + + private void addConnectionListener(T column) { + if (column != null) { + column.jpaProject().connectionProfile().addConnectionListener(this.connectionListener); + } + } + + private ConnectionListener buildConnectionListener() { + + return new ConnectionListener() { + + public void aboutToClose(ConnectionProfile profile) { + log("aboutToClose"); + } + + public void closed(ConnectionProfile profile) { + + SWTUtil.asyncExec(new Runnable() { + public void run() { + log("closed"); + + if (!getCombo().isDisposed()) { + AbstractDatabaseObjectCombo.this.repopulate(); + } + } + }); + } + + public void databaseChanged(ConnectionProfile profile, + Database database) { + + log("databaseChanged"); + } + + public void modified(ConnectionProfile profile) { + SWTUtil.asyncExec(new Runnable() { + public void run() { + log("modified"); + + if (!getCombo().isDisposed()) { + AbstractDatabaseObjectCombo.this.repopulate(); + } + } + }); + } + + public boolean okToClose(ConnectionProfile profile) { + log("okToClose"); + return true; + } + + public void opened(ConnectionProfile profile) { + + SWTUtil.asyncExec(new Runnable() { + public void run() { + log("opened"); + + if (!getCombo().isDisposed()) { + AbstractDatabaseObjectCombo.this.repopulate(); + } + } + }); + } + + public void schemaChanged(ConnectionProfile profile, + final Schema schema) { + + SWTUtil.asyncExec(new Runnable() { + public void run() { + log("schemaChanged: " + schema.getName()); + + if (!getCombo().isDisposed()) { + AbstractDatabaseObjectCombo.this.schemaChanged(schema); + } + } + }); + } + + public void tableChanged(ConnectionProfile profile, + final Table table) { + + SWTUtil.asyncExec(new Runnable() { + public void run() { + log("tableChanged: " + table.getName()); + + if (!getCombo().isDisposed()) { + AbstractDatabaseObjectCombo.this.tableChanged(table); + } + } + }); + } + }; + } + + private ModifyListener buildModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (!isPopulating()) { + CCombo combo = (CCombo) e.widget; + valueChanged(combo.getText()); + } + } + }; + } + + /** + * Returns the JPA project's connection profile, which is never + * <code>null</code>. + * + * @return The connection set in the project's properties or a <code>null</code> + * connection + */ + protected final ConnectionProfile connectionProfile() { + return subject().jpaProject().connectionProfile(); + } + + /** + * Returns the database associated with the active connection profile. + * + * @return The online database or a <code>null</code> instance if no + * connection profile was set or the + */ + protected final Database database() { + return connectionProfile().getDatabase(); + } + + /** + * Returns the default value, or <code>null</code> if no default is + * specified. + * + * @return The value that represents the default when no value was specified + */ + protected abstract String defaultValue(); + + /* + * (non-Javadoc) + */ + @Override + protected void disengageListeners(T subject) { + super.disengageListeners(subject); + removeConnectionListener(subject); + } + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + + this.combo.removeAll(); + + if (subject() != null) { + populateCombo(); + } + } + + /* + * (non-Javadoc) + */ + @Override + public void enableWidgets(boolean enabled) { + + super.enableWidgets(enabled); + + if (!this.combo.isDisposed()) { + this.combo.setEnabled(enabled); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void engageListeners(T subject) { + super.engageListeners(subject); + addConnectionListener(subject); + } + + public final CCombo getCombo() { + return this.combo; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initialize() { + super.initialize(); + this.connectionListener = buildConnectionListener(); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + this.combo = buildCombo(container); + this.combo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); + this.combo.addModifyListener(buildModifyListener()); + } + + private void log(String message) { + if (Tracing.booleanDebugOption(Tracing.UI_DB)) { + Class<?> thisClass = getClass(); + String className = ClassTools.shortNameFor(thisClass); + + if (thisClass.isAnonymousClass()) { + className = className.substring(0, className.indexOf('$')); + className += "->" + ClassTools.shortNameFor(thisClass.getSuperclass()); + } + + Tracing.log(className + ": " + message); + } + } + + /** + * Populates the combo's list by adding first the default value is available + * and then the possible choices. + */ + private void populateCombo() { + + populateDefaultValue(); + + if (connectionProfile().isConnected()) { + + for (Iterator<String> iter = CollectionTools.sort(values()); iter.hasNext(); ) { + this.combo.add(iter.next()); + } + } + + updateSelectedItem(); + } + + /** + * Adds the default value to the combo if one exists. + */ + private void populateDefaultValue() { + + String defaultValue = defaultValue(); + + if (defaultValue != null) { + this.combo.add(NLS.bind( + JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, + defaultValue + )); + } + else { + this.combo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (CollectionTools.contains(propertyNames(), propertyName)) { + updateSelectedItem(); + } + } + + private void removeConnectionListener(T value) { + if (value != null) { + value.jpaProject().connectionProfile().removeConnectionListener(this.connectionListener); + } + } + + /** + * The + * + * @param schema + */ + protected void schemaChanged(Schema schema) { + } + + /** + * Sets the given value as the new value. + * + * @param value The new value to send to the model object + */ + protected abstract void setValue(String value); + + /** + * The + * + * @param catalog + */ + protected void tableChanged(Table table) { + } + + /** + * Updates the selected item by selected the current value, if not + * <code>null</code>, or select the default value if one is available, + * otherwise remove the selection. + * <p> + * <b>Note:</b> It seems the text can be shown as truncated, changing the + * selection to (0, 0) makes the entire text visible. + */ + private void updateSelectedItem() { + String value = value(); + + if (value != null) { + this.combo.setText(value); + this.combo.setSelection(new Point(0, 0)); + } + else { + String defaultValue = defaultValue(); + String displayString = NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultValue); + + if (!this.combo.getText().equals(displayString)) { + this.combo.setText(displayString); + this.combo.setSelection(new Point(0, 0)); + } + else { + this.combo.select(-1); + } + } + } + + /** + * Requests the current value from the model object. + * + * @return The current value + */ + protected abstract String value(); + + /** + * The selection has changed, update the model if required. + * + * @param value The new value + */ + protected void valueChanged(String value) { + + IJpaNode subject = subject(); + + if (subject == null) { + return; + } + + String oldValue = value(); + + // Check for null value + if (StringTools.stringIsEmpty(value)) { + value = null; + + if (StringTools.stringIsEmpty(oldValue)) { + return; + } + } + + // The default value + if (value != null && + getCombo().getItemCount() > 0 && + value.equals(getCombo().getItem(0))) + { + value = null; + } + + // Set the new value + if ((value != null) && (oldValue == null)) { + setValue(value); + } + else if ((oldValue != null) && !oldValue.equals(value)) { + setValue(value); + } + } + + /** + * Retrieves the possible values, which will be added to the combo during + * population. + * + * @return A non-<code>null</code> <code>Iterator</code> of the possible + * choices to be added to the combo + */ + protected abstract Iterator<String> values(); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/CatalogCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/CatalogCombo.java new file mode 100644 index 0000000000..c5473562ac --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/CatalogCombo.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * 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.ui.internal.mappings.db; + +import java.util.Iterator; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.db.internal.Database; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * This database object combo handles showing the database's catalogs. + * + * @version 2.0 + * @since 2.0 + */ +public abstract class CatalogCombo<T extends IJpaNode> extends AbstractDatabaseObjectCombo<T> +{ + /** + * Creates a new <code>CatalogCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public CatalogCombo(AbstractFormPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>CatalogCombo</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public CatalogCombo(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected Iterator<String> values() { + + Database database = database(); + + if (database != null) { + return database.catalogNames(); + } + + return EmptyIterator.instance(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java new file mode 100644 index 0000000000..63d298356d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * 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.ui.internal.mappings.db; + +import java.util.Iterator; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * This database object combo handles showing a table's columns. + * + * @version 2.0 + * @since 2.0 + */ +public abstract class ColumnCombo<T extends IJpaNode> extends AbstractDatabaseObjectCombo<T> +{ + /** + * Creates a new <code>ColumnCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public ColumnCombo(AbstractFormPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>ColumnCombo</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public ColumnCombo(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + protected abstract Table table(); + + /* + * (non-Javadoc) + */ + @Override + protected void tableChanged(Table table) { + super.tableChanged(table); + + if (table == table()) { + this.doPopulate(); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected Iterator<String> values() { + + Table table = table(); + + if (table != null) { + return table.columnNames(); + } + + return EmptyIterator.instance(); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SchemaCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SchemaCombo.java new file mode 100644 index 0000000000..31924eab52 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SchemaCombo.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.ui.internal.mappings.db; + +import java.util.Iterator; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.db.internal.Database; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * This database object combo handles showing the database's schemas. + * + * @version 2.0 + * @since 2.0 + */ +public abstract class SchemaCombo<T extends IJpaNode> extends AbstractDatabaseObjectCombo<T> +{ + /** + * Creates a new <code>SchemaCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public SchemaCombo(AbstractFormPane<? extends T> parentPane, + Composite parent) + { + super(parentPane, parent); + } + + /** + * Creates a new <code>SchemaCombo</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public SchemaCombo(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) + { + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected Iterator<String> values() { + + Database database = this.database(); + + if (database != null) { + return database.schemaNames(); + } + + return EmptyIterator.instance(); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SequenceCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SequenceCombo.java new file mode 100644 index 0000000000..3f5773bd9b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SequenceCombo.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.ui.internal.mappings.db; + +import java.util.Iterator; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * This database object combo handles showing the database's sequences for a + * given <code>Schema</code>. + * + * @version 2.0 + * @since 2.0 + */ +public abstract class SequenceCombo<T extends IJpaNode> extends AbstractDatabaseObjectCombo<T> +{ + /** + * Creates a new <code>SequenceCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public SequenceCombo(AbstractFormPane<? extends T> parentPane, Composite parent) + { + super(parentPane, parent); + } + + /** + * Creates a new <code>SequenceCombo</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public SequenceCombo(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) + { + super(subjectHolder, parent, widgetFactory); + } + + protected abstract Schema schema(); + + /* + * (non-Javadoc) + */ + @Override + protected Iterator<String> values() { + Schema schema = schema(); + + if (schema != null) { + return schema.sequenceNames(); + } + + return EmptyIterator.instance(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java new file mode 100644 index 0000000000..1e56a97bcb --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.ui.internal.mappings.db; + +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * This database object combo handles showing the database's tables. + * + * @version 2.0 + * @since 2.0 + */ +public abstract class TableCombo<T extends IJpaNode> extends AbstractDatabaseObjectCombo<T> +{ + /** + * Creates a new <code>TableCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public TableCombo(AbstractFormPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>TableCombo</code>. + * + * @param subjectHolder The holder of the subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public TableCombo(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) + { + super(subjectHolder, parent, widgetFactory); + } + + protected abstract Table table(); + + /* + * (non-Javadoc) + */ + @Override + protected void tableChanged(Table table) { + super.tableChanged(table); + + if (table == table()) { + this.doPopulate(); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialog.java index 2435c30c6f..60c269d3af 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialog.java @@ -1,183 +1,72 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn; -import org.eclipse.jpt.db.internal.Table; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.core.internal.context.base.IAbstractJoinColumn; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; +import org.eclipse.jpt.ui.internal.widgets.AbstractDialog; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -//if there is only 1 joinColumn and the user is editing it, they should be -//able to define defaults. otherwise, we probably shouldn't allow it. -public abstract class AbstractJoinColumnDialog<E extends IAbstractJoinColumn> extends Dialog { +/** + * @see AbstractJoinColumnStateObject + * + * TODO: If there is only 1 join column and the user is editing it, they should + * be able to define defaults. otherwise, we probably shouldn't allow it. + * + * @version 2.0 + * @since 1.0 + */ +public abstract class AbstractJoinColumnDialog<T extends AbstractJoinColumnStateObject> extends AbstractDialog<T> { - //if creating a new JoinColumn, this will be null, - //specify the JoinColumnOwner instead in the appropriate construtor - private E joinColumn; - - private Combo nameCombo; - private Combo referencedColumnNameCombo; - - private boolean defaultNameSelected; - private String selectedName; - private boolean defaultReferencedColumnNameSelected; - private String selectedReferencedColumnName; - - AbstractJoinColumnDialog(Shell parent) { + private IAbstractJoinColumn joinColumn; + + /** + * Creates a new <code>AbstractJoinColumnDialog</code>. + * + * @param parent The parent shell + */ + public AbstractJoinColumnDialog(Shell parent) { super(parent); } - AbstractJoinColumnDialog(Shell parent, E joinColumn) { - super(parent); + /** + * Creates a new <code>AbstractJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public AbstractJoinColumnDialog(Shell parent, + IAbstractJoinColumn joinColumn) { + + this(parent); this.joinColumn = joinColumn; } - - protected String getAddTitle() { - return JptUiMappingsMessages.JoinColumnDialog_addJoinColumn; - } - protected String getEditTitle() { - return JptUiMappingsMessages.JoinColumnDialog_editJoinColumn; + /** + * Returns + * + * @return + */ + public IAbstractJoinColumn getJoinColumn() { + return joinColumn; } - - protected Control createDialogArea(Composite parent) { - if (this.joinColumn == null) { - getShell().setText(getAddTitle()); - } - else { - getShell().setText(getEditTitle()); - } - Composite composite = (Composite) super.createDialogArea(parent); - GridLayout gridLayout = (GridLayout) composite.getLayout(); - gridLayout.numColumns = 2; - - Label nameLabel = new Label(composite, SWT.LEFT); - nameLabel.setText(JptUiMappingsMessages.JoinColumnDialog_name); - GridData gridData = new GridData(); - nameLabel.setLayoutData(gridData); - - this.nameCombo = new Combo(composite, SWT.LEFT); - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.nameCombo.setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.nameCombo, IJpaHelpContextIds.MAPPING_JOIN_COLUMN_NAME); - populateNameCombo(); - - Label referencedColumnNameLabel = new Label(composite, SWT.LEFT); - referencedColumnNameLabel.setText(JptUiMappingsMessages.JoinColumnDialog_referencedColumnName); - gridData = new GridData(); - referencedColumnNameLabel.setLayoutData(gridData); - this.referencedColumnNameCombo = new Combo(composite, SWT.LEFT); - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.referencedColumnNameCombo.setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.referencedColumnNameCombo, IJpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN); - populateReferencedNameCombo(); - - return composite; - } - - protected void populateNameCombo() { - this.nameCombo.removeAll(); - if (getJoinColumn() != null) { - this.nameCombo.add(NLS.bind(JptUiMappingsMessages.JoinColumnDialog_defaultWithOneParam, getJoinColumn().getDefaultName())); - } - Table table = getNameTable(); - if (table != null) { - for (Iterator i = table.columnNames(); i.hasNext(); ) { - this.nameCombo.add((String) i.next()); - } + /* + * (non-Javadoc) + */ + @Override + protected String title() { + if (joinColumn == null) { + return JptUiMappingsMessages.JoinColumnDialog_addJoinColumn; } - if (getJoinColumn() != null) { - if (getJoinColumn().getSpecifiedName() != null) { - this.nameCombo.setText(getJoinColumn().getSpecifiedName()); - } - else { - this.nameCombo.select(0); - } - } - } - - protected Combo getNameCombo() { - return this.nameCombo; - } - - protected Combo getReferencedColumnNameCombo() { - return this.referencedColumnNameCombo; - } - - protected abstract Table getNameTable(); - - protected abstract Table getReferencedNameTable(); - protected void populateReferencedNameCombo() { - if (getJoinColumn() != null) { - this.referencedColumnNameCombo.add(NLS.bind(JptUiMappingsMessages.JoinColumnDialog_defaultWithOneParam, getJoinColumn().getDefaultReferencedColumnName())); - } - Table referencedNameTable = getReferencedNameTable(); - if (referencedNameTable != null) { - for (Iterator i = referencedNameTable.columnNames(); i.hasNext(); ) { - this.referencedColumnNameCombo.add((String) i.next()); - } - } - if (getJoinColumn() != null) { - if (getJoinColumn().getSpecifiedReferencedColumnName() != null) { - this.referencedColumnNameCombo.setText(getJoinColumn().getSpecifiedReferencedColumnName()); - } - else { - this.referencedColumnNameCombo.select(0); - } - } - } - - protected E getJoinColumn() { - return this.joinColumn; - } - - protected boolean isDefaultNameSelected() { - return this.defaultNameSelected; - } - - protected String getSelectedName() { - return this.selectedName; - } - - protected boolean isDefaultReferencedColumnNameSelected() { - return this.defaultReferencedColumnNameSelected; - } - - protected String getReferencedColumnName() { - return this.selectedReferencedColumnName; - } - - public boolean close() { - this.defaultNameSelected = this.nameCombo.getSelectionIndex() == 0; - this.selectedName = this.nameCombo.getText(); - this.defaultReferencedColumnNameSelected = this.referencedColumnNameCombo.getSelectionIndex() == 0; - this.selectedReferencedColumnName = this.referencedColumnNameCombo.getText(); - return super.close(); + return JptUiMappingsMessages.JoinColumnDialog_editJoinColumn; } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java new file mode 100644 index 0000000000..2e0dc4c1ab --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java @@ -0,0 +1,204 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------- | + * | Name: | |v| | + * | ------------------------------------------------- | + * | ------------------------------------------------- | + * | Referenced Column Name: | |v| | + * | ------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see AbstractJoinColumnStateObject + * @see JoinColumnInJoinTableDialog - A container of this pane + * @see PrimaryKeyJoinColumnInSecondaryTableDialog - A container of this pane + * + * @version 2.0 + * @since 2.0 + */ +public class AbstractJoinColumnDialogPane<T extends AbstractJoinColumnStateObject> extends AbstractDialogPane<T> +{ + private CCombo nameCombo; + private CCombo referencedColumnNameCombo; + + /** + * Creates a new <code>AbstractJoinColumnDialogPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public AbstractJoinColumnDialogPane(PropertyValueModel<? extends T> subjectHolder, + Composite parent) + { + super(subjectHolder, parent); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(AbstractJoinColumnStateObject.SELECTED_REFERENCED_COLUMN_NAME_PROPERTY); + propertyNames.add(AbstractJoinColumnStateObject.SELECTED_NAME_PROPERTY); + } + + private ModifyListener buildNameComboListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + CCombo combo = (CCombo) e.widget; + subject().setSelectedName(combo.getText()); + subject().setDefaultNameSelected(combo.getSelectionIndex() == 0); + } + }; + } + + private ModifyListener buildReferencedColumnNameComboListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + CCombo combo = (CCombo) e.widget; + subject().setSelectedReferencedColumnName(combo.getText()); + subject().setDefaultReferencedColumnNameSelected(combo.getSelectionIndex() == 0); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + populateNameCombo(); + } + + public final CCombo getNameCombo() { + return nameCombo; + } + + public final CCombo getReferencedColumnNameCombo() { + return referencedColumnNameCombo; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Name widgets + nameCombo = buildCombo(container); + nameCombo.addModifyListener(buildNameComboListener()); + + buildLabeledComposite( + container, + JptUiMappingsMessages.JoinColumnDialog_name, + nameCombo, + IJpaHelpContextIds.MAPPING_JOIN_COLUMN_NAME + ); + + // Referenced Column Name widgets + referencedColumnNameCombo = buildCombo(container); + referencedColumnNameCombo.addModifyListener(buildReferencedColumnNameComboListener()); + + buildLabeledComposite( + container, + JptUiMappingsMessages.JoinColumnDialog_referencedColumnName, + referencedColumnNameCombo, + IJpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN + ); + } + + public void populateNameCombo() { + + AbstractJoinColumnStateObject subject = subject(); + this.nameCombo.removeAll(); + + if (subject.getDefaultName() != null) { + this.nameCombo.add(NLS.bind(JptUiMappingsMessages.JoinColumnDialog_defaultWithOneParam, subject.getDefaultName())); + } + + Table table = subject.getNameTable(); + + if (table != null) { + for (Iterator<String> iter = table.columnNames(); iter.hasNext(); ) { + this.nameCombo.add(iter.next()); + } + } + + if (subject.getJoinColumn() != null) { + if (subject.getSpecifiedName() != null) { + this.nameCombo.setText(subject.getSpecifiedName()); + } + else { + this.nameCombo.select(0); + } + } + } + + public void populateReferencedNameCombo() { + + AbstractJoinColumnStateObject subject = subject(); + + if (subject.getDefaultReferencedColumnName() != null) { + this.referencedColumnNameCombo.add(NLS.bind(JptUiMappingsMessages.JoinColumnDialog_defaultWithOneParam, subject.getDefaultReferencedColumnName())); + } + + Table referencedNameTable = subject.getReferencedNameTable(); + + if (referencedNameTable != null) { + for (Iterator<String> iter = referencedNameTable.columnNames(); iter.hasNext(); ) { + this.referencedColumnNameCombo.add(iter.next()); + } + } + + if (subject.getJoinColumn() != null) { + if (subject.getSpecifiedReferencedColumnName() != null) { + this.referencedColumnNameCombo.setText(subject().getSpecifiedReferencedColumnName()); + } + else { + this.referencedColumnNameCombo.select(0); + } + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == AbstractJoinColumnStateObject.SELECTED_NAME_PROPERTY) { + populateNameCombo(); + } + else if (propertyName == AbstractJoinColumnStateObject.SELECTED_REFERENCED_COLUMN_NAME_PROPERTY) { + populateReferencedNameCombo(); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java new file mode 100644 index 0000000000..f999da130b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IAbstractJoinColumn; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.utility.internal.node.AbstractNode; +import org.eclipse.jpt.utility.internal.node.Node; + +/** + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public abstract class AbstractJoinColumnStateObject extends AbstractNode +{ + private boolean defaultNameSelected; + private boolean defaultReferencedColumnNameSelected; + private IAbstractJoinColumn joinColumn; + private String selectedName; + private String selectedReferencedColumnName; + private Validator validator; + + static final String DEFAULT_NAME_SELECTED_PROPERTY = "defaultNameSelected"; + static final String DEFAULT_REFERENCE_COLUMN_NAME_SELECTED_PROPERTY = "defaultReferencedColumnNameSelected"; + static final String SELECTED_NAME_PROPERTY = "selectedName"; + static final String SELECTED_REFERENCED_COLUMN_NAME_PROPERTY = "selectedReferencedColumnName"; + + /** + * Creates a new <code>AbstractJoinColumnStateObject</code>. + */ + public AbstractJoinColumnStateObject() { + super(null); + } + + /** + * Creates a new <code>AbstractJoinColumnStateObject</code>. + * + * @param joinColumn + */ + public AbstractJoinColumnStateObject(IAbstractJoinColumn joinColumn) { + super(null); + this.joinColumn = joinColumn; + } + + /* + * (non-Javadoc) + */ + @Override + protected void checkParent(Node parentNode) { + // This is the root of the Join Column state object + } + + /* + * (non-Javadoc) + */ + public String displayString() { + return ""; + } + + public String getDefaultName() { + if (this.joinColumn == null) { + return null; + } + + return this.joinColumn.getDefaultName(); + } + + public String getDefaultReferencedColumnName() { + if (this.joinColumn == null) { + return null; + } + + return this.joinColumn.getDefaultReferencedColumnName(); + } + + public IAbstractJoinColumn getJoinColumn() { + return this.joinColumn; + } + + public abstract Table getNameTable(); + + public abstract Table getReferencedNameTable(); + + public String getSelectedName() { + return this.selectedName; + } + + public String getSelectedReferencedColumnName() { + return this.selectedReferencedColumnName; + } + + public String getSpecifiedName() { + if (this.joinColumn == null) { + return null; + } + + return this.joinColumn.getSpecifiedName(); + } + + public String getSpecifiedReferencedColumnName() { + if (this.joinColumn == null) { + return null; + } + + return this.joinColumn.getSpecifiedReferencedColumnName(); + } + + public boolean isDefaultNameSelected() { + return this.defaultNameSelected; + } + + public boolean isDefaultReferencedColumnNameSelected() { + return this.defaultReferencedColumnNameSelected; + } + + public void setDefaultNameSelected(boolean defaultNameSelected) { + boolean oldDefaultNameSelected = this.defaultNameSelected; + this.defaultNameSelected = defaultNameSelected; + firePropertyChanged(DEFAULT_NAME_SELECTED_PROPERTY, oldDefaultNameSelected, defaultNameSelected); + } + + public void setDefaultReferencedColumnNameSelected(boolean defaultReferencedColumnNameSelected) { + boolean oldDefaultReferencedColumnNameSelected = this.defaultReferencedColumnNameSelected; + this.defaultReferencedColumnNameSelected = defaultReferencedColumnNameSelected; + firePropertyChanged(DEFAULT_REFERENCE_COLUMN_NAME_SELECTED_PROPERTY, oldDefaultReferencedColumnNameSelected, defaultReferencedColumnNameSelected); + } + + public void setSelectedName(String selectedName) { + String oldSelectedName = this.selectedName; + this.selectedName = selectedName; + firePropertyChanged(SELECTED_NAME_PROPERTY, oldSelectedName, selectedName); + } + + public void setSelectedReferencedColumnName(String selectedReferencedColumnName) { + String oldSelectedReferencedColumnName = this.selectedReferencedColumnName; + this.selectedReferencedColumnName = selectedReferencedColumnName; + firePropertyChanged(SELECTED_REFERENCED_COLUMN_NAME_PROPERTY, oldSelectedReferencedColumnName, selectedReferencedColumnName); + } + + /* + * (non-Javadoc) + */ + @Override + public void setValidator(Validator validator) { + this.validator = validator; + } + + /* + * (non-Javadoc) + */ + @Override + public Validator validator() { + return this.validator; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicComposite.java deleted file mode 100644 index 1ba80cdb67..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicComposite.java +++ /dev/null @@ -1,357 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.EObjectImpl; -import org.eclipse.jpt.core.internal.mappings.DefaultEagerFetchType; -import org.eclipse.jpt.core.internal.mappings.DefaultTrueBoolean; -import org.eclipse.jpt.core.internal.mappings.EnumType; -import org.eclipse.jpt.core.internal.mappings.IBasic; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.core.internal.mappings.TemporalType; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.jpt.ui.internal.mappings.details.EnumComboViewer.EnumHolder; -import org.eclipse.swt.SWT; -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.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class BasicComposite extends BaseJpaComposite -{ - private IBasic basic; - - private ColumnComposite columnComposite; - - private EnumComboViewer fetchTypeComboViewer; - private EnumComboViewer optionalComboViewer; - private LobCheckBox lobCheckBox; - private EnumComboViewer temporalTypeViewer; - private EnumComboViewer enumeratedTypeViewer; - - public BasicComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - } - - private Control buildGeneralComposite(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - this.columnComposite = new ColumnComposite(generalComposite, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.columnComposite.getControl().setLayoutData(gridData); - - CommonWidgets.buildFetchLabel(generalComposite, getWidgetFactory()); - this.fetchTypeComboViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.fetchTypeComboViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(fetchTypeComboViewer.getControl(), IJpaHelpContextIds.MAPPING_FETCH_TYPE); - - CommonWidgets.buildOptionalLabel(generalComposite, getWidgetFactory()); - this.optionalComboViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.optionalComboViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(optionalComboViewer.getControl(), IJpaHelpContextIds.MAPPING_OPTIONAL); - - CommonWidgets.buildTemporalLabel(generalComposite, getWidgetFactory()); - this.temporalTypeViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.temporalTypeViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(temporalTypeViewer.getControl(), IJpaHelpContextIds.MAPPING_TEMPORAL); - - CommonWidgets.buildEnumeratedLabel(generalComposite, getWidgetFactory()); - this.enumeratedTypeViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.enumeratedTypeViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(enumeratedTypeViewer.getControl(), IJpaHelpContextIds.MAPPING_ENUMERATED); - - this.lobCheckBox = buildLobCheckBox(generalComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.lobCheckBox.getControl().setLayoutData(gridData); - helpSystem.setHelp(lobCheckBox.getControl(), IJpaHelpContextIds.MAPPING_LOB); - - return generalComposite; - } - - private LobCheckBox buildLobCheckBox(Composite parent) { - return new LobCheckBox(parent, this.commandStack, getWidgetFactory()); - } - - public void doPopulate(EObject obj) { - this.basic = (IBasic) obj; - if (this.basic != null) { - this.columnComposite.populate(this.basic.getColumn()); - } - else { - this.columnComposite.populate(null); - } - this.fetchTypeComboViewer.populate(new FetchHolder(this.basic)); - this.optionalComboViewer.populate(new OptionalHolder(this.basic)); - this.lobCheckBox.populate(this.basic); - this.temporalTypeViewer.populate(new TemporalTypeHolder(this.basic)); - this.enumeratedTypeViewer.populate(new EnumeratedTypeHolder(this.basic)); - } - - public void doPopulate() { - this.columnComposite.populate(); - this.fetchTypeComboViewer.populate(); - this.optionalComboViewer.populate(); - this.lobCheckBox.populate(); - this.temporalTypeViewer.populate(); - this.enumeratedTypeViewer.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.columnComposite.dispose(); - this.fetchTypeComboViewer.dispose(); - this.optionalComboViewer.dispose(); - this.lobCheckBox.dispose(); - this.temporalTypeViewer.dispose(); - this.enumeratedTypeViewer.dispose(); - super.dispose(); - } - - protected IBasic getBasic() { - return this.basic; - } - - private class FetchHolder extends EObjectImpl implements EnumHolder { - - private IBasic basic; - - FetchHolder(IBasic basic) { - super(); - this.basic = basic; - } - - public Object get() { - return this.basic.getFetch(); - } - - public void set(Object enumSetting) { - this.basic.setFetch((DefaultEagerFetchType) enumSetting); - - } - - public Class featureClass() { - return IBasic.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IBASIC__FETCH; - } - - public EObject wrappedObject() { - return this.basic; - } - - public Object[] enumValues() { - return DefaultEagerFetchType.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultEagerFetchType.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "Eager"; - } - } - - - private class OptionalHolder extends EObjectImpl implements EnumHolder { - - private IBasic basic; - - OptionalHolder(IBasic basic) { - super(); - this.basic = basic; - } - - public Object get() { - return this.basic.getOptional(); - } - - public void set(Object enumSetting) { - this.basic.setOptional((DefaultTrueBoolean) enumSetting); - } - - public Class featureClass() { - return IBasic.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IBASIC__OPTIONAL; - } - - public EObject wrappedObject() { - return this.basic; - } - - public Object[] enumValues() { - return DefaultTrueBoolean.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultTrueBoolean.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "True"; - } - - } - - - private class TemporalTypeHolder extends EObjectImpl implements EnumHolder { - - private IBasic basic; - - TemporalTypeHolder(IBasic basic) { - super(); - this.basic = basic; - } - - public Object get() { - return this.basic.getTemporal(); - } - - public void set(Object enumSetting) { - this.basic.setTemporal((TemporalType) enumSetting); - } - - public Class featureClass() { - return IBasic.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IBASIC__TEMPORAL; - } - - public EObject wrappedObject() { - return this.basic; - } - - public Object[] enumValues() { - return TemporalType.VALUES.toArray(); - } - - /** - * TemporalType has no Default, return null - */ - public Object defaultValue() { - return null; - } - - /** - * TemporalType has no Default, return null - */ - public String defaultString() { - return null; - } - } - - private class EnumeratedTypeHolder extends EObjectImpl implements EnumHolder { - - private IBasic basic; - - EnumeratedTypeHolder(IBasic basic) { - super(); - this.basic = basic; - } - - public Object get() { - return this.basic.getEnumerated(); - } - - public void set(Object enumSetting) { - this.basic.setEnumerated((EnumType) enumSetting); - } - - public Class featureClass() { - return IBasic.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IBASIC__ENUMERATED; - } - - public EObject wrappedObject() { - return this.basic; - } - - public Object[] enumValues() { - return EnumType.VALUES.toArray(); - } - - public Object defaultValue() { - return EnumType.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "Ordinal"; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicMappingComposite.java new file mode 100644 index 0000000000..28372d1f8f --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicMappingComposite.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; +import org.eclipse.jpt.core.internal.context.base.IColumn; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | ColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | TemporalTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | EnumTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OptionalComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | LobComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IBasicMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see ColumnComposite + * @see EnumTypeComposite + * @see FetchTypeComposite + * @see LobComposite + * @see OptionalComposite + * @see TemporalTypeComposite + * + * @version 2.0 + * @since 1.0 + */ +public class BasicMappingComposite extends AbstractFormPane<IBasicMapping> + implements IJpaComposite<IBasicMapping> +{ + /** + * Creates a new <code>BasicMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IBasicMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public BasicMappingComposite(PropertyValueModel<IBasicMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<IColumn> buildColumnHolder() { + return new TransformationPropertyValueModel<IBasicMapping, IColumn>(getSubjectHolder()) { + @Override + protected IColumn transform_(IBasicMapping value) { + return value.getColumn(); + } + }; + } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Column widgets + new ColumnComposite(this, buildColumnHolder(), container); + + // Fetch Type widgets + new FetchTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Temporal Type widgets + new TemporalTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Enumerated widgets + new EnumTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Optional widgets + new OptionalComposite(this, buildPane(container, groupBoxMargin)); + + // Lob check box + new LobComposite(this, buildPane(container, groupBoxMargin)); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CascadeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CascadeComposite.java index a2eb0eb160..e5e246c0d4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CascadeComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CascadeComposite.java @@ -3,376 +3,192 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.ICascade; -import org.eclipse.jpt.core.internal.mappings.IRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; +import org.eclipse.jpt.core.internal.context.base.ICascade; +import org.eclipse.jpt.core.internal.context.base.IRelationshipMapping; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class CascadeComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | - Cascade --------------------------------------------------------------- | + * | | | | + * | | x All x Persist x Merge x Remove x Refresh | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see ICascade + * @see IRelationshipMapping + * @see ManyToManyMappingComposite - A container of this pane + * @see ManyToOneMappingComposite - A container of this pane + * @see OneToManyMappingComposite - A container of this pane + * @see OneToOneMappingComposite - A container of this pane + * + * @version 2.0 + * @since 1.0 + */ +public class CascadeComposite extends AbstractFormPane<ICascade> { - private IRelationshipMapping relationshipMapping; - private ICascade cascade; - - private Adapter relationshipMappingListener; - private Adapter cascadeListener; - - - private Button allCheckBox; - private Button persistCheckBox; - private Button mergeCheckBox; - private Button removeCheckBox; - private Button refreshCheckBox; - - public CascadeComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.relationshipMappingListener = buildRelationshipMappingListener(); - this.cascadeListener = buildCascadeListener(); - } + /** + * Creates a new <code>CascadeComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject <code>ICascade</code> + * @param parent The parent container + */ + public CascadeComposite(AbstractFormPane<? extends IRelationshipMapping> parentPane, + PropertyValueModel<? extends ICascade> subjectHolder, + Composite parent) { - private Adapter buildRelationshipMappingListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - relationshipMappingChanged(notification); - } - }; + super(parentPane, subjectHolder, parent, false); } - private Adapter buildCascadeListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - cascadeChanged(notification); - } - }; - } - - @Override - protected void initializeLayout(Composite composite) { - composite.setLayout(new FillLayout()); - - Group cascadeGroup = getWidgetFactory().createGroup(composite, "Cascade"); - GridLayout layout = new GridLayout(5, false); - cascadeGroup.setLayout(layout); - - GridData gridData; - - this.allCheckBox = createAllCheckBox(cascadeGroup); - gridData = new GridData(); - this.allCheckBox.setLayoutData(gridData); + /** + * Creates a new <code>ColumnComposite</code>. + * + * @param subjectHolder The holder of the subject <code>ICascade</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public CascadeComposite(PropertyValueModel<? extends ICascade> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { - this.persistCheckBox = createPersistCheckBox(cascadeGroup); - gridData = new GridData(); - this.persistCheckBox.setLayoutData(gridData); - - this.mergeCheckBox = createMergeCheckBox(cascadeGroup); - gridData = new GridData(); - this.mergeCheckBox.setLayoutData(gridData); - - this.removeCheckBox = createRemoveCheckBox(cascadeGroup); - gridData = new GridData(); - this.removeCheckBox.setLayoutData(gridData); - - this.refreshCheckBox = createRefreshCheckBox(cascadeGroup); - gridData = new GridData(); - this.refreshCheckBox.setLayoutData(gridData); - } - - private Button createAllCheckBox(Composite composite) { - Button button = getWidgetFactory().createButton(composite, "All", SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - CascadeComposite.this.allSelected(e); - } - public void widgetSelected(SelectionEvent e) { - CascadeComposite.this.allSelected(e); - } - }); - return button; + super(subjectHolder, parent, widgetFactory); } - - protected void allSelected(SelectionEvent e) { - boolean setSelection = initializeCascade(); - if (setSelection) { - this.cascade.setAll(this.allCheckBox.getSelection()); - } - } - - private boolean initializeCascade() { - if (allCheckBoxesFalse() && this.cascade != null) { - disengageCascadeListener(); - this.relationshipMapping.setCascade(null); - return false; - } - if (this.cascade == null) { - this.cascade = this.relationshipMapping.createCascade(); - this.relationshipMapping.setCascade(this.cascade); - engageCascadeListener(); - } - return true; - } - - private Button createPersistCheckBox(Composite composite) { - Button button = getWidgetFactory().createButton(composite, "Persist", SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - CascadeComposite.this.persistSelected(e); + + private WritablePropertyValueModel<Boolean> buildCascadeTypeAllHolder() { + return new PropertyAspectAdapter<ICascade, Boolean>(getSubjectHolder(), ICascade.ALL_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isAll(); } - public void widgetSelected(SelectionEvent e) { - CascadeComposite.this.persistSelected(e); + + @Override + protected void setValue_(Boolean value) { + subject.setAll(value); } - }); - return button; - } - - protected void persistSelected(SelectionEvent e) { - boolean setSelection = initializeCascade(); - if (setSelection) { - this.cascade.setPersist(this.persistCheckBox.getSelection()); - } + }; } - private Button createMergeCheckBox(Composite composite) { - Button button = getWidgetFactory().createButton(composite, "Merge", SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - CascadeComposite.this.mergeSelected(e); + private WritablePropertyValueModel<Boolean> buildCascadeTypeMergeHolder() { + return new PropertyAspectAdapter<ICascade, Boolean>(getSubjectHolder(), ICascade.MERGE_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isMerge(); } - public void widgetSelected(SelectionEvent e) { - CascadeComposite.this.mergeSelected(e); + + @Override + protected void setValue_(Boolean value) { + subject.setMerge(value); } - }); - return button; - } - - protected void mergeSelected(SelectionEvent e) { - boolean setSelection = initializeCascade(); - if (setSelection) { - this.cascade.setMerge(this.mergeCheckBox.getSelection()); - } + }; } - - private Button createRemoveCheckBox(Composite composite) { - Button button = getWidgetFactory().createButton(composite, "Remove", SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - CascadeComposite.this.removeSelected(e); + + private WritablePropertyValueModel<Boolean> buildCascadeTypePersistHolder() { + return new PropertyAspectAdapter<ICascade, Boolean>(getSubjectHolder(), ICascade.PERSIST_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isPersist(); } - public void widgetSelected(SelectionEvent e) { - CascadeComposite.this.removeSelected(e); + + @Override + protected void setValue_(Boolean value) { + subject.setPersist(value); } - }); - return button; - } - - protected void removeSelected(SelectionEvent e) { - boolean setSelection = initializeCascade(); - if (setSelection) { - this.cascade.setRemove(this.removeCheckBox.getSelection()); - } + }; } - - private Button createRefreshCheckBox(Composite composite) { - Button button = getWidgetFactory().createButton(composite, "Refresh", SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - CascadeComposite.this.refreshSelected(e); + + private WritablePropertyValueModel<Boolean> buildCascadeTypeRefreshHolder() { + return new PropertyAspectAdapter<ICascade, Boolean>(getSubjectHolder(), ICascade.REFRESH_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isRefresh(); } - public void widgetSelected(SelectionEvent e) { - CascadeComposite.this.refreshSelected(e); + + @Override + protected void setValue_(Boolean value) { + subject.setRefresh(value); } - }); - return button; - } - - protected void refreshSelected(SelectionEvent e) { - boolean setSelection = initializeCascade(); - if (setSelection) { - this.cascade.setRefresh(this.refreshCheckBox.getSelection()); - } - } - - private boolean allCheckBoxesFalse() { - return !(this.allCheckBox.getSelection() - || this.persistCheckBox.getSelection() - || this.mergeCheckBox.getSelection() - || this.removeCheckBox.getSelection() - || this.refreshCheckBox.getSelection()); - - - } - - private void relationshipMappingChanged(Notification notification) { - if (notification.getFeatureID(IRelationshipMapping.class) == - JpaCoreMappingsPackage.IRELATIONSHIP_MAPPING__CASCADE) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - if (CascadeComposite.this.cascade != null) { - disengageCascadeListener(); - } - CascadeComposite.this.cascade = CascadeComposite.this.relationshipMapping.getCascade(); - populateCascade(); - - if (CascadeComposite.this.cascade != null) { - engageCascadeListener(); - } - } - }); - } - } - - private void cascadeChanged(final Notification notification) { - switch (notification.getFeatureID(ICascade.class)) { - case JpaCoreMappingsPackage.ICASCADE__ALL : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CascadeComposite.this.allCheckBox.setSelection(notification.getNewBooleanValue()); - } - }); - break; - case JpaCoreMappingsPackage.ICASCADE__PERSIST : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CascadeComposite.this.persistCheckBox.setSelection(notification.getNewBooleanValue()); - } - }); - break; - case JpaCoreMappingsPackage.ICASCADE__MERGE : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CascadeComposite.this.mergeCheckBox.setSelection(notification.getNewBooleanValue()); - } - }); - break; - case JpaCoreMappingsPackage.ICASCADE__REMOVE : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CascadeComposite.this.removeCheckBox.setSelection(notification.getNewBooleanValue()); - } - }); - break; - case JpaCoreMappingsPackage.ICASCADE__REFRESH : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CascadeComposite.this.refreshCheckBox.setSelection(notification.getNewBooleanValue()); - } - }); - break; - default : - break; - } - if (notification.getFeatureID(ICascade.class) == - JpaCoreMappingsPackage.ICASCADE__ALL) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CascadeComposite.this.allCheckBox.setSelection(notification.getNewBooleanValue()); - } - }); - } - + }; } - - public void doPopulate(EObject obj) { - this.relationshipMapping = (IRelationshipMapping) obj; - - if (this.relationshipMapping != null) { - this.cascade = this.relationshipMapping.getCascade(); - populateCascade(); - } - } - - private void populateCascade() { - if (this.cascade != null) { - this.allCheckBox.setSelection(this.cascade.isAll()); - this.persistCheckBox.setSelection(this.cascade.isPersist()); - this.mergeCheckBox.setSelection(this.cascade.isMerge()); - this.removeCheckBox.setSelection(this.cascade.isRemove()); - this.refreshCheckBox.setSelection(this.cascade.isRefresh()); - } - else { - this.allCheckBox.setSelection(false); - this.persistCheckBox.setSelection(false); - this.mergeCheckBox.setSelection(false); - this.removeCheckBox.setSelection(false); - this.refreshCheckBox.setSelection(false); - } - } - - public void doPopulate() { - } - - protected void engageListeners() { - if (this.relationshipMapping != null) { - this.relationshipMapping.eAdapters().add(this.relationshipMappingListener); - if (this.cascade != null) { - engageCascadeListener(); + private WritablePropertyValueModel<Boolean> buildCascadeTypeRemoveHolder() { + return new PropertyAspectAdapter<ICascade, Boolean>(getSubjectHolder(), ICascade.REMOVE_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isRemove(); } - } - } - - protected void engageCascadeListener() { - this.cascade.eAdapters().add(this.cascadeListener); - } - - protected void disengageCascadeListener() { - this.cascade.eAdapters().remove(this.cascadeListener); - } - - protected void disengageListeners() { - if (this.relationshipMapping != null) { - this.relationshipMapping.eAdapters().remove(this.relationshipMappingListener); - if (this.cascade != null) { - disengageCascadeListener(); + + @Override + protected void setValue_(Boolean value) { + subject.setRemove(value); } - } + }; } -} + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Cascade group + Group cascadeGroup = buildTitledPane( + container, + JptUiMappingsMessages.CascadeComposite_cascadeTitle + ); + + // Container of the check boxes + container = buildSubPane(cascadeGroup, 5, 8, 0, 0, 0); + + // All check box + buildCheckBox( + container, + JptUiMappingsMessages.CascadeComposite_all, + buildCascadeTypeAllHolder() + ); + + // Persist check box + buildCheckBox( + container, + JptUiMappingsMessages.CascadeComposite_persist, + buildCascadeTypePersistHolder() + ); + + // Merge check box + buildCheckBox( + container, + JptUiMappingsMessages.CascadeComposite_merge, + buildCascadeTypeMergeHolder() + ); + + // Remove check box + buildCheckBox( + container, + JptUiMappingsMessages.CascadeComposite_remove, + buildCascadeTypeRemoveHolder() + ); + + // Refresh check box + buildCheckBox( + container, + JptUiMappingsMessages.CascadeComposite_refresh, + buildCascadeTypeRefreshHolder() + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java deleted file mode 100644 index 0544782356..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java +++ /dev/null @@ -1,304 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.ITable; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionListener; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.Database; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class CatalogCombo extends BaseJpaController -{ - private ITable table; - - private Adapter listener; - - /** - * Caching the connectionProfile so we can remove the listener. If the - * cached table object has been removed from the model then we no longer - * have access to the parent and cannot find the connectionProfile - */ - private ConnectionProfile connectionProfile; - - private ConnectionListener connectionListener; - - private CCombo combo; - - public CatalogCombo(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - this.listener = this.buildTableListener(); - this.connectionListener = this.buildConnectionListener(); - } - - private Adapter buildTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - CatalogCombo.this.catalogChanged(notification); - } - }; - } - - private ConnectionListener buildConnectionListener() { - return new ConnectionListener() { - public void aboutToClose(ConnectionProfile profile) { - // not interested to this event. - } - - public void closed(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CatalogCombo.this.populateCatalogCombo(); - } - }); - } - - public void modified(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CatalogCombo.this.populateCatalogCombo(); - } - }); - } - - public boolean okToClose(ConnectionProfile profile) { - // not interested to this event. - return true; - } - - public void opened(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CatalogCombo.this.populateCatalogCombo(); - } - }); - } - - public void databaseChanged(ConnectionProfile profile, final Database database) { - getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if (database == CatalogCombo.this.getDatabase()) { - if (!getControl().isDisposed()) { - CatalogCombo.this.populateCatalogCombo(); - } - } - } - }); - } - - public void schemaChanged(ConnectionProfile profile, final Schema schema) { - // not interested to this event. - } - - public void tableChanged(ConnectionProfile profile, final Table table) { - // not interested to this event. - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT | SWT.READ_ONLY); - this.combo.add(JptUiMappingsMessages.TableComposite_defaultEmpty); - this.combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String catalogText = ((CCombo) e.getSource()).getText(); - if (catalogText.equals("")) { //$NON-NLS-1$ - catalogText = null; - if (CatalogCombo.this.table.getSpecifiedCatalog() == null || CatalogCombo.this.table.getSpecifiedCatalog().equals("")) { //$NON-NLS-1$ - return; - } - } - if (catalogText != null && combo.getItemCount() > 0 && catalogText.equals(combo.getItem(0))) { - catalogText = null; - } - if (CatalogCombo.this.table.getSpecifiedCatalog() == null && catalogText != null) { - CatalogCombo.this.setSpecifiedCatalog(catalogText); - } - if (CatalogCombo.this.table.getSpecifiedCatalog() != null && !CatalogCombo.this.table.getSpecifiedCatalog().equals(catalogText)) { - CatalogCombo.this.setSpecifiedCatalog(catalogText); - } - } - }); - } - - private void setSpecifiedCatalog(String catalogName) { - this.table.setSpecifiedCatalog(catalogName); - this.getConnectionProfile().setCatalogName(catalogName); - } - - protected void catalogChanged(Notification notification) { - if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CatalogCombo.this.populateCatalogName(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - CatalogCombo.this.populateDefaultCatalogName(); - } - }); - } - } - - public void doPopulate(EObject obj) { - this.table = (ITable) obj; - if (this.table != null) { - this.populateCatalogCombo(); - } - else { - this.connectionProfile = null; - } - } - - public void doPopulate() { - this.populateCatalogCombo(); - } - - protected Database getDatabase() { - return this.getConnectionProfile().getDatabase(); - } - - private ConnectionProfile getConnectionProfile() { - if (this.connectionProfile == null) { - this.connectionProfile = this.table.getJpaProject().connectionProfile(); - } - return this.connectionProfile; - } - - private void populateCatalogCombo() { - if (this.table == null) { - return; - } - this.populateDefaultCatalogName(); - if (this.getConnectionProfile().isConnected()) { - this.combo.remove(1, this.combo.getItemCount() - 1); - Database database = this.getDatabase(); - if (database != null) { - Iterator<String> catalogs = database.catalogNames(); - for (Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext();) { - this.combo.add(stream.next()); - } - } - } - else { - this.combo.remove(1, this.combo.getItemCount() - 1); - } - this.populateCatalogName(); - } - - protected void populateDefaultCatalogName() { - // String defaultCatalogName = this.table.getDefaultCatalog(); // - // DefaultCatalog cannot be initialized if DB not online - String defaultCatalogName = this.getDatabase().getDefaultCatalogName(); // TOREVIEW - int selectionIndex = combo.getSelectionIndex(); - combo.setItem(0, NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultCatalogName)); - if (selectionIndex == 0) { - combo.clearSelection(); - combo.select(0); - } - } - - protected void populateCatalogName() { - if (this.table == null) { - return; - } - String catalogName = this.table.getSpecifiedCatalog(); - // String defaultCatalogName = this.table.getDefaultCatalog(); // - // DefaultCatalog cannot be initialized if DB not online - String defaultCatalogName = this.getDatabase().getDefaultCatalogName(); // TOREVIEW - if (!StringTools.stringIsEmpty(catalogName)) { - if (!this.combo.getText().equals(catalogName)) { - this.combo.setText(catalogName); - } - } - else { - if (!this.combo.getText().equals(NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultCatalogName))) { - this.combo.select(0); - } - } - } - - public CCombo getCombo() { - return this.combo; - } - - @Override - public Control getControl() { - return getCombo(); - } - - @Override - protected void disengageListeners() { - if (this.table != null) { - this.removeConnectionListener(); - this.table.eAdapters().remove(this.listener); - } - } - - @Override - protected void engageListeners() { - if (this.table != null) { - this.table.eAdapters().add(this.listener); - this.addConnectionListener(); - } - } - - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); - } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java index 3c55a6524b..88a64b254d 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java @@ -1,566 +1,319 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. This + * 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.ui.internal.mappings.details; +import java.util.Collection; import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.EObjectImpl; -import org.eclipse.jpt.core.internal.mappings.DefaultTrueBoolean; -import org.eclipse.jpt.core.internal.mappings.IAbstractColumn; -import org.eclipse.jpt.core.internal.mappings.IColumn; -import org.eclipse.jpt.core.internal.mappings.INamedColumn; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionListener; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.Database; -import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.core.internal.context.base.IColumn; +import org.eclipse.jpt.core.internal.context.base.INamedColumn; import org.eclipse.jpt.db.internal.Table; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.EnumComboViewer.EnumHolder; -import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; +import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.TriStateCheckBox; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -//TODO repopulate this panel based on the Entity table changing -public class ColumnComposite extends BaseJpaComposite + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | ColumnCombo | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | TableCombo | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | x Insertable | + * | | + * | x Updatable | + * | | + * -----------------------------------------------------------------------------</pre> + * + * @see IColumn + * @see ColumnCombo + * @see TableCombo + * @see BasicMappingComposite - A container of this pane + * @see EmbeddedAttributeOverridesComposite - A container of this pane + * @see IdMappingComposite - A container of this pane + * @see VersionMappingComposite - A container of this pane + * + * @TODO repopulate this panel based on the Entity table changing + * + * @version 2.0 + * @since 1.0 + */ +public class ColumnComposite extends AbstractFormPane<IColumn> { - - private IColumn column; - - private Adapter columnListener; - private ConnectionListener connectionListener; - - protected CCombo columnCombo; - protected CCombo tableCombo; - protected EnumComboViewer insertableComboViewer; - protected EnumComboViewer updatableComboViewer; - - private ConnectionProfile connectionProfile; - - public ColumnComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.columnListener = buildColumnListener(); - this.connectionListener = buildConnectionListener(); + private TriStateCheckBox insertableCheckBox; + private TriStateCheckBox updatableCheckBox; + + /** + * Creates a new <code>ColumnComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject <code>IColumn</code> + * @param parent The parent container + */ + public ColumnComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends IColumn> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); } - - private Adapter buildColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - columnChanged(notification); - } - }; + + /** + * Creates a new <code>ColumnComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IColumn</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public ColumnComposite(PropertyValueModel<? extends IColumn> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - private ConnectionListener buildConnectionListener() { - return new ConnectionListener() { + private ColumnCombo<IColumn> buildColumnCombo(Composite container) { - public void aboutToClose(ConnectionProfile profile) { - // not interested to this event. - } + return new ColumnCombo<IColumn>(this, container) { - public void closed(ConnectionProfile profile) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - ColumnComposite.this.populateColumnCombo(); - } - }); + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(INamedColumn.DEFAULT_NAME_PROPERTY); + propertyNames.add(INamedColumn.SPECIFIED_NAME_PROPERTY); } - public void modified(ConnectionProfile profile) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - ColumnComposite.this.populateColumnCombo(); - } - }); + @Override + protected String defaultValue() { + return subject().getDefaultName(); } - public boolean okToClose(ConnectionProfile profile) { - // not interested to this event. - return true; + @Override + protected void setValue(String value) { + subject().setSpecifiedName(value); } - public void opened(ConnectionProfile profile) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - ColumnComposite.this.populateColumnCombo(); - } - }); + @Override + protected Table table() { + return subject().dbTable(); } - public void databaseChanged(ConnectionProfile profile, final Database database) { - return; + @Override + protected String value() { + return subject().getSpecifiedName(); } + }; + } - public void schemaChanged(ConnectionProfile profile, final Schema schema) { - return; + private WritablePropertyValueModel<Boolean> buildInsertableHolder() { + return new PropertyAspectAdapter<IColumn, Boolean>( + getSubjectHolder(), + IColumn.DEFAULT_INSERTABLE_PROPERTY, + IColumn.SPECIFIED_INSERTABLE_PROPERTY) + { + @Override + protected Boolean buildValue_() { + return subject.getSpecifiedInsertable(); } - public void tableChanged(ConnectionProfile profile, final Table table) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if(table == getDbTable()) { - if (!getControl().isDisposed()) { - ColumnComposite.this.populateColumnCombo(); - } - } - } - }); + @Override + protected void setValue_(Boolean value) { + subject.setSpecifiedInsertable(value); } }; - } - - @Override - protected void initializeLayout(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - composite.setLayout(layout); - - Group columnGroup = getWidgetFactory().createGroup(composite, JptUiMappingsMessages.ColumnComposite_columnSection); - layout = new GridLayout(); - layout.marginHeight = 0; - columnGroup.setLayout(layout); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - columnGroup.setLayoutData(gridData); - - //created this composite because combos as direct children of a Group do not have a border, no clue why - Composite intermediaryComposite = getWidgetFactory().createComposite(columnGroup); - layout = new GridLayout(2, false); - layout.marginWidth = 0; - intermediaryComposite.setLayout(layout); - - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - intermediaryComposite.setLayoutData(gridData); - - - CommonWidgets.buildColumnLabel(intermediaryComposite, getWidgetFactory()); - - this.columnCombo = buildColumnCombo(intermediaryComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.columnCombo.setLayoutData(gridData); - helpSystem.setHelp(columnCombo, IJpaHelpContextIds.MAPPING_COLUMN); - - - CommonWidgets.buildColumnTableLabel(intermediaryComposite, getWidgetFactory()); - - this.tableCombo = buildTableCombo(intermediaryComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.tableCombo.setLayoutData(gridData); - helpSystem.setHelp(tableCombo, IJpaHelpContextIds.MAPPING_COLUMN_TABLE); - - getWidgetFactory().createLabel(intermediaryComposite, JptUiMappingsMessages.ColumnComposite_insertable); - - this.insertableComboViewer = new EnumComboViewer(intermediaryComposite, this.commandStack, getWidgetFactory()); - this.insertableComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - helpSystem.setHelp(this.insertableComboViewer.getControl(), IJpaHelpContextIds.MAPPING_COLUMN_INSERTABLE); - - getWidgetFactory().createLabel(intermediaryComposite, JptUiMappingsMessages.ColumnComposite_updatable); - - this.updatableComboViewer = new EnumComboViewer(intermediaryComposite, this.commandStack, getWidgetFactory()); - this.updatableComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - helpSystem.setHelp(this.updatableComboViewer.getControl(), IJpaHelpContextIds.MAPPING_COLUMN_UPDATABLE); } - - - private CCombo buildColumnCombo(Composite parent) { - final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); - combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String columnText = ((CCombo) e.getSource()).getText(); - if (columnText.equals("")) { //$NON-NLS-1$ - columnText = null; - if (column.getSpecifiedName() == null || column.getSpecifiedName().equals("")) { //$NON-NLS-1$ - return; - } - } - - if (columnText != null && combo.getItemCount() > 0 && columnText.equals(combo.getItem(0))) { - columnText = null; - } - if (column.getSpecifiedName() == null && columnText != null) { - column.setSpecifiedName(columnText); - } - if (column.getSpecifiedName() != null && !column.getSpecifiedName().equals(columnText)) { - column.setSpecifiedName(columnText); - } - } - }); - return combo; - } - - private CCombo buildTableCombo(Composite parent) { - final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); - combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String tableText = ((CCombo) e.getSource()).getText(); - if (tableText.equals("")) { //$NON-NLS-1$ - tableText = null; - if (column.getSpecifiedTable() == null || column.getSpecifiedTable().equals("")) { //$NON-NLS-1$ - return; + private PropertyValueModel<String> buildInsertableStringHolder() { + + return new TransformationPropertyValueModel<Boolean, String>(buildInsertableHolder()) { + + @Override + protected String transform(Boolean value) { + + if ((subject() != null) && (value == null)) { + + Boolean defaultValue = subject().getDefaultInsertable(); + + if (defaultValue != null) { + + String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : + JptUiMappingsMessages.Boolean_False; + + return NLS.bind( + JptUiMappingsMessages.ColumnComposite_insertableWithDefault, + defaultStringValue + ); } } - - if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) { - tableText = null; - } - if (column.getSpecifiedTable() == null && tableText != null) { - column.setSpecifiedTable(tableText); - } - if (column.getSpecifiedTable() != null && !column.getSpecifiedTable().equals(tableText)) { - column.setSpecifiedTable(tableText); - } + return JptUiMappingsMessages.ColumnComposite_insertable; } - }); - return combo; - - } - - protected void columnChanged(Notification notification) { - if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed() || isPopulating()) { - return; - } - populateColumnName(); - } - }); - } - else if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateDefaultColumnName(); - } - }); - } - else if (notification.getFeatureID(IAbstractColumn.class) == JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateDefaultColumnTable(); - populateColumnCombo(); - } - }); - } - else if (notification.getFeatureID(IAbstractColumn.class) == JpaCoreMappingsPackage.IABSTRACT_COLUMN__SPECIFIED_TABLE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateColumnTable(); - populateColumnCombo(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.column != null) { - this.column.eAdapters().add(this.columnListener); - this.addConnectionListener(); - } + }; } - @Override - protected void disengageListeners() { - if (this.column != null) { - this.removeConnectionListener(); - this.column.eAdapters().remove(this.columnListener); - } - } + private TableCombo<IColumn> buildTableCombo(Composite container) { - private ConnectionProfile getConnectionProfile() { - if (this.connectionProfile == null) { - this.connectionProfile = this.column.getJpaProject().connectionProfile(); - } - return this.connectionProfile; - } - - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); - } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); - } - - private Table getDbTable() { - return this.column.dbTable(); - } + return new TableCombo<IColumn>(this, container) { - private void populateColumnCombo() { - //TODO don't do instanceof check here - check on Table, or isRoot check on Entity - //this.tableCombo.setEnabled(!(this.table instanceof SingleTableInheritanceChildTableImpl)); - populateDefaultColumnName(); - - if (this.getConnectionProfile().isConnected()) { - this.columnCombo.remove(1, this.columnCombo.getItemCount()-1); - Table table = getDbTable(); - if (table != null) { - for (Iterator i = CollectionTools.sort(CollectionTools.list(table.columnNames())).iterator(); i.hasNext();) { - this.columnCombo.add((String) i.next()); - } + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IColumn.DEFAULT_TABLE_PROPERTY); + propertyNames.add(IColumn.SPECIFIED_TABLE_PROPERTY); } - } - else { - this.columnCombo.remove(1, this.columnCombo.getItemCount()-1); - } - populateColumnName(); - } - - protected void populateDefaultColumnName() { - String defaultTableName = column.getDefaultName(); - int selectionIndex = columnCombo.getSelectionIndex(); - columnCombo.setItem(0, NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName)); - if (selectionIndex == 0) { - //combo text does not update when switching between 2 mappings of the same type - //that both have a default column name. clear the selection and then set it again - columnCombo.clearSelection(); - columnCombo.select(0); - } - } - - protected void populateColumnName() { - String specifiedColumnName = this.column.getSpecifiedName(); - if (specifiedColumnName != null) { - if (!this.columnCombo.getText().equals(specifiedColumnName)) { - this.columnCombo.setText(specifiedColumnName); + + @Override + protected String defaultValue() { + return subject().getDefaultTable(); } - } - else { - String defaultColumnName = this.column.getDefaultName(); - if (!this.columnCombo.getText().equals(NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultColumnName))) { - this.columnCombo.select(0); + + @Override + protected void setValue(String value) { + subject().setSpecifiedTable(value); } - } - } - - private void populateTableCombo() { - //TODO don't do instanceof check here - check on Table, or isRoot check on Entity - //this.tableCombo.setEnabled(!(this.table instanceof SingleTableInheritanceChildTableImpl)); - populateDefaultColumnTable(); - this.tableCombo.remove(1, this.tableCombo.getItemCount()-1); - - if (this.column != null) { - for (Iterator i = this.column.getOwner().getTypeMapping().associatedTableNamesIncludingInherited(); i.hasNext(); ) { - this.tableCombo.add((String) i.next()); + + @Override + protected Table table() { + return subject().dbTable(); } - } - populateColumnTable(); - } - - protected void populateDefaultColumnTable() { - String defaultTableName = column.getDefaultTable(); - int selectionIndex = tableCombo.getSelectionIndex(); - tableCombo.setItem(0, NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName)); - if (selectionIndex == 0) { - //combo text does not update when switching between 2 mappings of the same type - //that both have a default column name. clear the selection and then set it again - tableCombo.clearSelection(); - tableCombo.select(0); - } - } - - protected void populateColumnTable() { - String tableName = this.column.getSpecifiedTable(); - String defaultTableName = this.column.getDefaultTable(); - if (tableName != null) { - if (!this.tableCombo.getText().equals(tableName)) { - this.tableCombo.setText(tableName); + + @Override + protected String value() { + return subject().getSpecifiedTable(); } - } - else { - if (!this.tableCombo.getText().equals(NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName))) { - this.tableCombo.select(0); + + @Override + protected Iterator<String> values() { + return subject().owner().typeMapping().associatedTableNamesIncludingInherited(); } - } + }; } - public void doPopulate(EObject obj) { - this.column = (IColumn) obj; - if (this.column != null) { - populateColumnCombo(); - populateTableCombo(); - } - this.insertableComboViewer.populate(new InsertableHolder(this.column)); - this.updatableComboViewer.populate(new UpdatableHolder(this.column)); - } - - public void doPopulate() { - if (this.column != null) { - populateColumnCombo(); - populateTableCombo(); - } - else { - this.connectionProfile = null; - } - this.insertableComboViewer.populate(); - this.updatableComboViewer.populate(); + private WritablePropertyValueModel<Boolean> buildUpdatableHolder() { + return new PropertyAspectAdapter<IColumn, Boolean>( + getSubjectHolder(), + IColumn.DEFAULT_UPDATABLE_PROPERTY, + IColumn.SPECIFIED_UPDATABLE_PROPERTY) + { + @Override + protected Boolean buildValue_() { + return subject.getSpecifiedUpdatable(); + } + + @Override + protected void setValue_(Boolean value) { + subject.setSpecifiedUpdatable(value); + } + }; } - - protected void enableWidgets(boolean enabled) { - this.columnCombo.setEnabled(enabled); - this.tableCombo.setEnabled(enabled); - this.insertableComboViewer.getControl().setEnabled(enabled); - this.updatableComboViewer.getControl().setEnabled(enabled); + + private PropertyValueModel<String> buildUpdatableStringHolder() { + + return new TransformationPropertyValueModel<Boolean, String>(buildUpdatableHolder()) { + + @Override + protected String transform(Boolean value) { + + if ((subject() != null) && (value == null)) { + + Boolean defaultValue = subject().getDefaultUpdatable(); + + if (defaultValue != null) { + + String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : + JptUiMappingsMessages.Boolean_False; + + return NLS.bind( + JptUiMappingsMessages.ColumnComposite_updatableWithDefault, + defaultStringValue + ); + } + } + + return JptUiMappingsMessages.ColumnComposite_updatable; + } + }; } - + + /* + * (non-Javadoc) + */ @Override - public void dispose() { - this.insertableComboViewer.dispose(); - this.updatableComboViewer.dispose(); - super.dispose(); - } - - private class InsertableHolder extends EObjectImpl implements EnumHolder { - - private IAbstractColumn column; - - InsertableHolder(IAbstractColumn column) { - super(); - this.column = column; - } - - public Object get() { - return this.column.getInsertable(); - } - - public void set(Object enumSetting) { - this.column.setInsertable((DefaultTrueBoolean) enumSetting); - - } - - public Class featureClass() { - return IAbstractColumn.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IABSTRACT_COLUMN__INSERTABLE; - } - - public EObject wrappedObject() { - return this.column; - } - - public Object[] enumValues() { - return DefaultTrueBoolean.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultTrueBoolean.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "True"; - } + public void enableWidgets(boolean enabled) { + super.enableWidgets(enabled); + insertableCheckBox.setEnabled(enabled); + updatableCheckBox.setEnabled(enabled); } - private class UpdatableHolder extends EObjectImpl implements EnumHolder { - - private IAbstractColumn column; - - UpdatableHolder(IAbstractColumn column) { - super(); - this.column = column; - } - - public Object get() { - return this.column.getUpdatable(); - } - - public void set(Object enumSetting) { - this.column.setUpdatable((DefaultTrueBoolean) enumSetting); - - } - - public Class featureClass() { - return IAbstractColumn.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IABSTRACT_COLUMN__UPDATABLE; - } - - public EObject wrappedObject() { - return this.column; - } - - public Object[] enumValues() { - return DefaultTrueBoolean.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultTrueBoolean.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "True"; - } + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Column group pane + container = buildTitledPane( + container, + JptUiMappingsMessages.ColumnComposite_columnSection + ); + + // Column widgets + ColumnCombo<IColumn> columnCombo = buildColumnCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.ColumnChooser_label, + columnCombo.getControl(), + IJpaHelpContextIds.MAPPING_COLUMN + ); + + // Table widgets + TableCombo<IColumn> tableCombo = buildTableCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.ColumnTableChooser_label, + tableCombo.getControl(), + IJpaHelpContextIds.MAPPING_COLUMN_TABLE + ); + + // Insertable widgets + insertableCheckBox = buildTriStateCheckBoxWithDefault( + container, + JptUiMappingsMessages.ColumnComposite_insertable, + buildInsertableHolder(), + buildInsertableStringHolder(), + IJpaHelpContextIds.MAPPING_COLUMN_INSERTABLE + ); + + // Updatable widgets + updatableCheckBox = buildTriStateCheckBoxWithDefault( + container, + JptUiMappingsMessages.ColumnComposite_updatable, + buildUpdatableHolder(), + buildUpdatableStringHolder(), + IJpaHelpContextIds.MAPPING_COLUMN_UPDATABLE + ); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CommonWidgets.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CommonWidgets.java index 14fd1119c0..04239dfad1 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CommonWidgets.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CommonWidgets.java @@ -3,302 +3,24 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.EObjectImpl; -import org.eclipse.jpt.core.internal.mappings.DefaultEagerFetchType; -import org.eclipse.jpt.core.internal.mappings.DefaultLazyFetchType; -import org.eclipse.jpt.core.internal.mappings.DefaultTrueBoolean; -import org.eclipse.jpt.core.internal.mappings.IAbstractColumn; -import org.eclipse.jpt.core.internal.mappings.IColumn; -import org.eclipse.jpt.core.internal.mappings.IMultiRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.ISingleRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.EnumComboViewer.EnumHolder; -import org.eclipse.jpt.ui.internal.mappings.details.StringWithDefaultChooser.StringHolder; -import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class CommonWidgets +public class CommonWidgets { - public static Label buildEntityNameLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.EntityGeneralSection_name); - } - - public static EntityNameCombo buildEntityNameCombo( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EntityNameCombo(parent, commandStack, widgetFactory); - } - - public static Label buildTableLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.TableChooser_label); - } - public static Label buildCatalogLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { return widgetFactory.createLabel(parent, JptUiMappingsMessages.CatalogChooser_label); } - + public static Label buildSchemaLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { return widgetFactory.createLabel(parent, JptUiMappingsMessages.SchemaChooser_label); } - - public static StringWithDefaultChooser buildStringWithDefaultChooser( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new StringWithDefaultChooser(parent, commandStack, widgetFactory); - } - - - public static Label buildFetchLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.BasicGeneralSection_fetchLabel); - } - - public static Label buildTargetEntityLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.TargetEntityChooser_label); - } - - public static Label buildOptionalLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.BasicGeneralSection_optionalLabel); - } - - public static Label buildTemporalLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.BasicGeneralSection_temporalLabel); - } - - public static Label buildEnumeratedLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.BasicGeneralSection_enumeratedLabel); - } - - public static Label buildMappedByLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.NonOwningMapping_mappedByLabel); - } - - public static EnumComboViewer buildEnumComboViewer( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new EnumComboViewer(parent, commandStack, widgetFactory); - } - - public static EnumHolder buildMultiRelationshipMappingFetchEnumHolder(IMultiRelationshipMapping mapping) { - return new FetchHolder(mapping); - } - - public static EnumHolder buildSingleRelationshipMappingFetchEnumHolder(ISingleRelationshipMapping mapping) { - return new SingleRelationshipMappingFetchHolder(mapping); - } - - public static EnumHolder buildOptionalHolder(ISingleRelationshipMapping mapping) { - return new OptionalHolder(mapping); - } - - public static Label buildColumnLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.ColumnChooser_label); - } - - public static Label buildColumnTableLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiMappingsMessages.ColumnTableChooser_label); - } - - public static ColumnTableHolder buildColumnTableHolder(IColumn column) { - return new ColumnTableHolder(column); - } - - public static TargetEntityChooser buildTargetEntityChooser(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new TargetEntityChooser(parent, commandStack, widgetFactory); - } - private static class FetchHolder extends EObjectImpl implements EnumHolder { - - private IMultiRelationshipMapping mapping; - - FetchHolder(IMultiRelationshipMapping mapping) { - super(); - this.mapping = mapping; - } - - public Object get() { - return this.mapping.getFetch(); - } - - public void set(Object enumSetting) { - this.mapping.setFetch((DefaultLazyFetchType) enumSetting); - - } - - public Class featureClass() { - return IMultiRelationshipMapping.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IMULTI_RELATIONSHIP_MAPPING__FETCH; - } - - public EObject wrappedObject() { - return this.mapping; - } - - public Object[] enumValues() { - return DefaultLazyFetchType.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultLazyFetchType.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "Lazy"; - } - } - - private static class SingleRelationshipMappingFetchHolder extends EObjectImpl implements EnumHolder { - - private ISingleRelationshipMapping mapping; - - SingleRelationshipMappingFetchHolder(ISingleRelationshipMapping mapping) { - super(); - this.mapping = mapping; - } - - public Object get() { - return this.mapping.getFetch(); - } - - public void set(Object enumSetting) { - this.mapping.setFetch((DefaultEagerFetchType) enumSetting); - - } - - public Class featureClass() { - return ISingleRelationshipMapping.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.ISINGLE_RELATIONSHIP_MAPPING__FETCH; - } - - public EObject wrappedObject() { - return this.mapping; - } - - public Object[] enumValues() { - return DefaultEagerFetchType.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultEagerFetchType.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "Eager"; - } - } - private static abstract class ColumnHolder extends EObjectImpl implements StringHolder { - private IAbstractColumn column; - - ColumnHolder(IAbstractColumn column) { - super(); - this.column = column; - } - - public Class featureClass() { - return IAbstractColumn.class; - } - - public boolean supportsDefault() { - return true; - } - - public EObject wrappedObject() { - return this.column; - } - - protected IAbstractColumn getColumn() { - return this.column; - } - } - - public static class ColumnTableHolder extends ColumnHolder implements StringHolder { - - ColumnTableHolder(IAbstractColumn column) { - super(column); - } - - public int featureId() { - return JpaCoreMappingsPackage.IABSTRACT_COLUMN__SPECIFIED_TABLE; - } - - public int defaultFeatureId() { - return JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE; - } - - public String defaultItem() { - String defaultName = getColumn().getDefaultTable(); - if (defaultName != null) { - return NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultName); - } - return JptUiMappingsMessages.ColumnComposite_defaultEmpty; - } - - public String getString() { - return getColumn().getSpecifiedTable(); - } - - public void setString(String newName) { - getColumn().setSpecifiedTable(newName); - } - } - - private static class OptionalHolder extends EObjectImpl implements EnumHolder { - - private ISingleRelationshipMapping mapping; - - OptionalHolder(ISingleRelationshipMapping mapping) { - super(); - this.mapping = mapping; - } - - public Object get() { - return this.mapping.getOptional(); - } - - public void set(Object enumSetting) { - this.mapping.setOptional((DefaultTrueBoolean) enumSetting); - } - - public Class featureClass() { - return ISingleRelationshipMapping.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.ISINGLE_RELATIONSHIP_MAPPING__OPTIONAL; - } - - public EObject wrappedObject() { - return this.mapping; - } - - public Object[] enumValues() { - return DefaultTrueBoolean.VALUES.toArray(); - } - - public Object defaultValue() { - return DefaultTrueBoolean.DEFAULT; - } - - public String defaultString() { - //TODO move this out of the UI into the model - return "True"; - } - - } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddableComposite.java index b7c98a5e16..658156b652 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddableComposite.java @@ -1,114 +1,51 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. This + * 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.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.jpt.core.internal.context.base.IEmbeddable; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class EmbeddableComposite extends BaseJpaComposite +/** + * This pane does not have any widgets. + * + * @see IEmbeddable + * @see BaseJpaUiFactory - The factory creating this pane + * @see EmbeddableUiProvider + * + * @version 2.0 + * @since 2.0 + */ +public class EmbeddableComposite extends AbstractFormPane<IEmbeddable> + implements IJpaComposite<IEmbeddable> { -// private IEmbeddable embeddable; -// private Adapter mappedSuperclassListener; - - public EmbeddableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - //this.mappedSuperclassListener = buildMappedSuperclassListener(); - } - -// private Adapter buildMappedSuperclassListener() { -// return new AdapterImpl() { -// @Override -// public void notifyChanged(Notification notification) { -// mappedSuperclassChanged(notification); -// } -// }; -// } - - @Override - protected void initializeLayout(Composite composite) { - composite.setLayout(new FillLayout(SWT.VERTICAL)); - -// Label accessTypeLabel = new Label(composite, SWT.LEFT); -// accessTypeLabel.setText(DaliUiMessages.MappedSuperclassComposite_accessType); -// this.accessTypeComboViewer = buildAccessTypeCombo(composite); -// //eventually this will be enabled if editing xml instead of java -// this.accessTypeComboViewer.getCombo().setEnabled(false); -// GridData gridData = new GridData(); -// gridData.horizontalAlignment = GridData.FILL; -// gridData.grabExcessHorizontalSpace = true; -// this.accessTypeComboViewer.getCombo().setLayoutData(gridData); -// PlatformUI.getWorkbench().getHelpSystem().setHelp(this.accessTypeComboViewer.getCombo(), IDaliHelpContextIds.ENTITY_ACCESS_TYPE); - - } - -// private ComboViewer buildAccessTypeCombo(Composite parent) { -// ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY); -// viewer.add(AccessType.VALUES.toArray()); -// viewer.addSelectionChangedListener(new ISelectionChangedListener() { -// public void selectionChanged(SelectionChangedEvent event) { -// if (populating) { -// return; -// } -// if (event.getSelection() instanceof StructuredSelection) { -// StructuredSelection selection = (StructuredSelection) event.getSelection(); -// editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, persistentType, OrmPackage.eINSTANCE.getPersistentType_AccessType(), selection.getFirstElement())); -// } -// } -// }); -// return viewer; -// } - - @Override - protected void doPopulate(EObject model) { - //this.embeddable = (IEmbeddable) model; - } - - @Override - protected void doPopulate() { - - } - - - protected void engageListeners() { -// this.persistentTypeItemProvider.addListener(getPersistentTypeListener()); -// this.persistentType.eAdapters().add(this.persistentTypeItemProvider); + /** + * Creates a new <code>EmbeddableComposite</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EmbeddableComposite(PropertyValueModel<? extends IEmbeddable> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - protected void disengageListeners() { -// if (this.persistentType != null){ -// this.persistentType.eAdapters().remove(this.persistentTypeItemProvider); -// this.persistentTypeItemProvider.removeListener(getPersistentTypeListener()); -// } + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { } - -// private INotifyChangedListener getPersistentTypeListener() { -// if (this.persistentTypeListener == null) { -// this.persistentTypeListener = new INotifyChangedListener() { -// public void notifyChanged(Notification notification) { -// if (notification.getFeatureID(PersistentType.class) == OrmPackage.PERSISTENT_TYPE__ACCESS_TYPE) { -// final AccessType accessType = (AccessType) notification.getNewValue(); -// Display.getDefault().syncExec(new Runnable() { -// public void run() { -// if (((StructuredSelection) accessTypeComboViewer.getSelection()).getFirstElement() != accessType) { -// accessTypeComboViewer.setSelection(new StructuredSelection(accessType)); -// } -// } -// }); -// } -// } -// }; -// } -// return this.persistentTypeListener; -// } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java index d0da0632d9..197bf3fb04 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java @@ -3,336 +3,341 @@ * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: Oracle. - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; import java.util.Iterator; -import java.util.List; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.internal.mappings.IAttributeOverride; -import org.eclipse.jpt.core.internal.mappings.IEmbedded; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.core.internal.context.base.IAttributeOverride; +import org.eclipse.jpt.core.internal.context.base.IColumn; +import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter; +import org.eclipse.jpt.ui.internal.util.ControlEnabler; +import org.eclipse.jpt.ui.internal.util.PaneEnabler; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationWritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; +import org.eclipse.swt.widgets.List; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class EmbeddedAttributeOverridesComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | x Override Default | + * | | + * | ------------------------------------------------------------------------- | + * | | | | + * | | ColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IEmbeddedMapping + * @see EmbeddedMappingComposite - The parent container + * @see ColumnComposite + * + * @version 2.0 + * @since 1.0 + */ +public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<IEmbeddedMapping> { - private ListViewer listViewer; - - private IEmbedded embedded; - private Adapter embeddedListener; - - private IAttributeOverride attributeOverride; - private Adapter attributeOverrideListener; - - protected ColumnComposite columnComposite; - - private Button overrideDefaultButton; - - public EmbeddedAttributeOverridesComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.embeddedListener = buildEmbeddedListener(); - this.attributeOverrideListener = buildAttributeOverrideListener(); + private WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder; + private List list; + + /** + * Creates a new <code>EmbeddedAttributeOverridesComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public EmbeddedAttributeOverridesComposite(AbstractFormPane<? extends IEmbeddedMapping> parentPane, + Composite parent) { + + super(parentPane, parent); } - - private Adapter buildEmbeddedListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - embeddedChanged(notification); - } - }; + + /** + * Creates a new <code>EmbeddedAttributeOverridesComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEmbeddedMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EmbeddedAttributeOverridesComposite(PropertyValueModel<? extends IEmbeddedMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - - private Adapter buildAttributeOverrideListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - attributeOverrideChanged(notification); + + private WritablePropertyValueModel<IAttributeOverride> buildAttributeOverrideHolder() { + return new SimplePropertyValueModel<IAttributeOverride>(); + } + + private CollectionValueModel<IAttributeOverride> buildAttributeOverridesCollectionHolder() { + return new CollectionAspectAdapter<IEmbeddedMapping, IAttributeOverride>( + this.getSubjectHolder(), + IEmbeddedMapping.DEFAULT_ATTRIBUTE_OVERRIDES_LIST, + IEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST) + { + @Override + protected Iterator<IAttributeOverride> iterator_() { + return subject.attributeOverrides(); } }; } - - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - Group attributeOverridesGroup = getWidgetFactory().createGroup( - composite, JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides); - attributeOverridesGroup.setLayout(new GridLayout(2, true)); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - attributeOverridesGroup.setLayoutData(gridData); - - this.listViewer = buildAttributeOverridesListViewer(attributeOverridesGroup); - gridData = new GridData(); - gridData.verticalSpan = 2; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - this.listViewer.getList().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.listViewer.getList(), IJpaHelpContextIds.MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES); - - this.overrideDefaultButton = getWidgetFactory().createButton(attributeOverridesGroup, "Override Default", SWT.CHECK); - this.overrideDefaultButton.addSelectionListener(buildOverrideDefaultSelectionListener()); - gridData = new GridData(); - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.overrideDefaultButton.setLayoutData(gridData); - - - this.columnComposite = new ColumnComposite(attributeOverridesGroup, commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.columnComposite.getControl().setLayoutData(gridData); + private List buildAttributeOverridesList(Composite parent, + WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + + WritablePropertyValueModel<String> selectedItemHolder = + buildSelectedAttributeOverrideHolder(attributeOverrideHolder); + + List list = buildList( + parent, + selectedItemHolder, + IJpaHelpContextIds.MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES + ); + + ListBoxModelAdapter.adapt( + buildAttributeOverridesStringListHolder(), + selectedItemHolder, + list + ); + + return list; } - - private SelectionListener buildOverrideDefaultSelectionListener() { - return new SelectionListener(){ - - public void widgetSelected(SelectionEvent e) { - overrideDefaultButtonSelected(e); - } - - public void widgetDefaultSelected(SelectionEvent e) { - overrideDefaultButtonSelected(e); + + private ListValueModel<IAttributeOverride> buildAttributeOverridesListHolder() { + return new SortedListValueModelAdapter<IAttributeOverride>( + buildAttributeOverridesCollectionHolder() + ); + } + + private ListValueModel<String> buildAttributeOverridesStringListHolder() { + return new TransformationListValueModelAdapter<IAttributeOverride, String>(buildAttributeOverridesListHolder()) { + @Override + protected String transformItem(IAttributeOverride item) { + return item.getName(); } }; } - - private void overrideDefaultButtonSelected(SelectionEvent e) { - boolean selection = this.overrideDefaultButton.getSelection(); - if (selection) { - int index = this.embedded.getSpecifiedAttributeOverrides().size(); - IAttributeOverride attributeOverride = this.embedded.createAttributeOverride(index); - this.embedded.getSpecifiedAttributeOverrides().add(attributeOverride); - attributeOverride.setName(this.attributeOverride.getName()); - attributeOverride.getColumn().setSpecifiedName(this.attributeOverride.getColumn().getName()); - } - else { - this.embedded.getSpecifiedAttributeOverrides().remove(this.attributeOverride); - } - } - - - private ListViewer buildAttributeOverridesListViewer(Composite parent) { - ListViewer listViewer = new ListViewer(parent, SWT.SINGLE | SWT.BORDER); - listViewer.setLabelProvider(buildAttributeOverridesLabelProvider()); - listViewer.setContentProvider(buildAttributeOverridesContentProvider()); - - listViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - attributeOverridesListSelectionChanged(event); - } - }); - return listViewer; + private PropertyValueModel<Boolean> buildColumnEnablementHolder(PropertyValueModel<IColumn> columnHolder) { + return new TransformationPropertyValueModel<IColumn, Boolean>(columnHolder) { + @Override + protected Boolean transform(IColumn value) { + return (value != null); + } + }; } - - protected void attributeOverridesListSelectionChanged(SelectionChangedEvent event) { - if (((StructuredSelection) event.getSelection()).isEmpty()) { - this.columnComposite.populate(null); - this.columnComposite.enableWidgets(false); - this.overrideDefaultButton.setSelection(false); - this.overrideDefaultButton.setEnabled(false); - } - else { - this.attributeOverride = getSelectedAttributeOverride(); - boolean specifiedOverride = this.embedded.getSpecifiedAttributeOverrides().contains(this.attributeOverride); - this.overrideDefaultButton.setSelection(specifiedOverride); - this.columnComposite.populate(this.attributeOverride.getColumn()); - this.columnComposite.enableWidgets(specifiedOverride); - this.overrideDefaultButton.setEnabled(true); - } + + private PropertyValueModel<IColumn> buildColumnHolder(WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + return new TransformationPropertyValueModel<IAttributeOverride, IColumn>(attributeOverrideHolder) { + @Override + protected IColumn transform_(IAttributeOverride value) { + return value.getColumn(); + } + }; } - - private ILabelProvider buildAttributeOverridesLabelProvider() { - return new LabelProvider() { - public String getText(Object element) { - //TODO also display column name somehow - return ((IAttributeOverride) element).getName(); + + private PropertyValueModel<Boolean> buildOverrideDefaultButtonBooleanHolder(PropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + return new TransformationPropertyValueModel<IAttributeOverride, Boolean>(attributeOverrideHolder) { + @Override + protected Boolean transform(IAttributeOverride value) { + return (value != null); } }; } - - private IContentProvider buildAttributeOverridesContentProvider() { - return new IStructuredContentProvider() { - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder(WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + return new TransformationWritablePropertyValueModel<IAttributeOverride, Boolean>(attributeOverrideHolder) { + @Override + public void setValue(Boolean value) { + // Not done here } - - public void dispose() { + + @Override + protected Boolean transform_(IAttributeOverride value) { + return !value.isVirtual(); } - - public Object[] getElements(Object inputElement) { - return ((IEmbedded) inputElement).getAttributeOverrides().toArray(); + }; + } + + private SelectionListener buildOverrideDefaultSelectionListener() { + return new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + Button button = (Button) e.widget; + overrideDefaultButtonSelected(button.getSelection()); } }; } - private IAttributeOverride getSelectedAttributeOverride() { - return (IAttributeOverride) ((StructuredSelection) this.listViewer.getSelection()).getFirstElement(); + private void buildPropertiesPane(Composite container, + WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + + // Override Default check box + Button overrideDefaultButton = buildCheckBox( + container, + JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault, + buildOverrideDefaultHolder(attributeOverrideHolder) + ); + + GridData data = new GridData(); + data.horizontalIndent = groupBoxMargin(); + data.verticalIndent = 0; + overrideDefaultButton.setLayoutData(data); + + overrideDefaultButton.addSelectionListener( + buildOverrideDefaultSelectionListener() + ); + + installOverrideDefaultButtonEnabler( + attributeOverrideHolder, + overrideDefaultButton + ); + + // Column widgets + PropertyValueModel<IColumn> columnHolder = buildColumnHolder(attributeOverrideHolder); + + ColumnComposite columnComposite = new ColumnComposite( + this, + columnHolder, + container + ); + + data = new GridData(); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = GridData.FILL; + columnComposite.getControl().setLayoutData(data); + + installColumnCompositeEnabler(columnHolder, columnComposite); } - - - public void doPopulate(EObject obj) { - this.embedded = (IEmbedded) obj; - if (this.embedded == null) { - this.attributeOverride = null; - this.columnComposite.populate(null); - this.listViewer.setInput(null); - return; - } - - if (this.listViewer.getInput() != this.embedded) { - this.listViewer.setInput(this.embedded); - } - if (!this.embedded.getAttributeOverrides().isEmpty()) { - if (this.listViewer.getSelection().isEmpty()) { - IAttributeOverride attributeOverride = this.embedded.getAttributeOverrides().get(0); - this.listViewer.setSelection(new StructuredSelection(attributeOverride)); + + private WritablePropertyValueModel<String> buildSelectedAttributeOverrideHolder(WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + return new TransformationWritablePropertyValueModel<IAttributeOverride, String>(attributeOverrideHolder) { + @Override + protected IAttributeOverride reverseTransform_(String value) { + for (Iterator<IAttributeOverride> iter = subject().attributeOverrides(); iter.hasNext(); ) { + IAttributeOverride attributeOverride = iter.next(); + if (attributeOverride.getName().equals(value)) { + return attributeOverride; + } + } + return null; } - else { - this.columnComposite.enableWidgets(true); - this.columnComposite.populate(((IAttributeOverride)((StructuredSelection) this.listViewer.getSelection()).getFirstElement()).getColumn()); + + @Override + protected String transform_(IAttributeOverride value) { + return value.getName(); } - } - else { - this.columnComposite.populate(null); - this.columnComposite.enableWidgets(false); - } + }; } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { - this.columnComposite.doPopulate(); + protected void initialize() { + super.initialize(); + this.attributeOverrideHolder = buildAttributeOverrideHolder(); } - + + /* + * (non-Javadoc) + */ @Override - protected void engageListeners() { - if (this.embedded != null) { - this.embedded.eAdapters().add(this.embeddedListener); - for (IAttributeOverride attributeOverride : this.embedded.getAttributeOverrides()) { - attributeOverride.eAdapters().add(this.attributeOverrideListener); - } - } + protected void initializeLayout(Composite container) { + + WritablePropertyValueModel<IAttributeOverride> attributeOverrideHolder = + buildAttributeOverrideHolder(); + + // Attribute Overrides group box + Composite groupBox = buildTitledPane( + container, + JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides + ); + + // Sub-pane to align the check box and ColumnComposite + // to the right of the list + container = buildSubPane(groupBox, 1, 5, 0, 0, 0); + + // Attribute Overrides list + list = buildAttributeOverridesList( + container, + attributeOverrideHolder + ); + + GridData data = new GridData(); + data.verticalSpan = 2; + data.grabExcessVerticalSpace = true; + data.horizontalAlignment = GridData.FILL; + data.verticalAlignment = GridData.FILL; + list.setLayoutData(data); + + // Properties for the selected attribute overrides + buildPropertiesPane( + buildSubPane(container, 5, 0), + attributeOverrideHolder + ); } - - @Override - protected void disengageListeners() { - if (this.embedded != null) { - this.embedded.eAdapters().remove(this.embeddedListener); - for (IAttributeOverride attributeOverride : this.embedded.getAttributeOverrides()) { - attributeOverride.eAdapters().remove(this.attributeOverrideListener); - } - } + + private void installColumnCompositeEnabler(PropertyValueModel<IColumn> columnHolder, + ColumnComposite columnComposite) { + + new PaneEnabler( + buildColumnEnablementHolder(columnHolder), + columnComposite + ); } - - protected void embeddedChanged(Notification notification) { - switch (notification.getFeatureID(IEmbedded.class)) { - case JpaCoreMappingsPackage.IEMBEDDED__SPECIFIED_ATTRIBUTE_OVERRIDES : - case JpaCoreMappingsPackage.IEMBEDDED__DEFAULT_ATTRIBUTE_OVERRIDES : - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (listViewer.getList().isDisposed()) { - return; - } - listViewer.refresh(); - columnComposite.enableWidgets(!listViewer.getSelection().isEmpty()); - if (listViewer.getSelection().isEmpty()) { - columnComposite.populate(null); - } - } - }); - if (notification.getEventType() == Notification.ADD) { - ((IAttributeOverride) notification.getNewValue()).eAdapters().add(this.attributeOverrideListener); - final Object newValue = notification.getNewValue(); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (listViewer.getList().isDisposed()) { - return; - } - listViewer.setSelection(new StructuredSelection(newValue)); - } - }); - } - else if (notification.getEventType() == Notification.ADD_MANY) { - List addedList = (List) notification.getNewValue(); - for (Iterator<IAttributeOverride> i = addedList.iterator(); i.hasNext(); ) { - IAttributeOverride override = i.next(); - override.eAdapters().add(this.attributeOverrideListener); - } - } - else if (notification.getEventType() == Notification.REMOVE) { - ((IAttributeOverride) notification.getOldValue()).eAdapters().remove(this.attributeOverrideListener); - } - else if (notification.getEventType() == Notification.REMOVE_MANY) { - List removedList = (List) notification.getOldValue(); - for (Iterator<IAttributeOverride> i = removedList.iterator(); i.hasNext(); ) { - IAttributeOverride override = i.next(); - override.eAdapters().remove(this.attributeOverrideListener); - } - } - break; - default : - break; - } + private void installOverrideDefaultButtonEnabler(PropertyValueModel<IAttributeOverride> attributeOverrideHolder, + Button overrideDefaultButton) { + + new ControlEnabler( + this.buildOverrideDefaultButtonBooleanHolder(attributeOverrideHolder), + overrideDefaultButton + ); } - protected void attributeOverrideChanged(Notification notification) { - switch (notification.getFeatureID(IAttributeOverride.class)) { - case JpaCoreMappingsPackage.IATTRIBUTE_OVERRIDE__NAME : - final IAttributeOverride attributeOverride = (IAttributeOverride) notification.getNotifier(); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - listViewer.refresh(attributeOverride); - } - }); - break; - default : - break; + private void overrideDefaultButtonSelected(boolean overrideDefault) { + + if (overrideDefault) { + int index = this.subject().specifiedAttributeOverridesSize(); + + IAttributeOverride defaultAttributeOverride = this.attributeOverrideHolder.value(); + IAttributeOverride attributeOverride = this.subject().addSpecifiedAttributeOverride(index); + + attributeOverride.setName(defaultAttributeOverride.getName()); + attributeOverride.getColumn().setSpecifiedName(defaultAttributeOverride.getColumn().getName()); + } + else { + this.subject().removeSpecifiedAttributeOverride(this.list.getSelectionIndex()); } } - - public void dispose() { - this.columnComposite.dispose(); - super.dispose(); - } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedComposite.java deleted file mode 100644 index 3ad33eb5a1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedComposite.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class EmbeddedComposite extends BaseJpaComposite -{ - private EmbeddedAttributeOverridesComposite attributeOverridesComposite; - - public EmbeddedComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - composite.setLayout(layout); - - GridData gridData; - - this.attributeOverridesComposite = new EmbeddedAttributeOverridesComposite(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.attributeOverridesComposite.getControl().setLayoutData(gridData); - } - - - public void doPopulate(EObject obj) { - this.attributeOverridesComposite.populate(obj); - } - - public void doPopulate() { - this.attributeOverridesComposite.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.attributeOverridesComposite.dispose(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdComposite.java deleted file mode 100644 index 13111065c2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdComposite.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class EmbeddedIdComposite extends BaseJpaComposite -{ - public EmbeddedIdComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - @Override - protected void initializeLayout(Composite composite) { - - } - - - public void doPopulate(EObject obj) { - } - - public void doPopulate() { - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdMappingComposite.java new file mode 100644 index 0000000000..33b424858b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdMappingComposite.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * This pane does not have any widgets. + * + * @see IEmbeddedIdMapping + * @see BaseJpaUiFactory - The factory creating this pane + * + * @version 2.0 + * @since 1.0 + */ +public class EmbeddedIdMappingComposite extends AbstractFormPane<IEmbeddedIdMapping> + implements IJpaComposite<IEmbeddedIdMapping> +{ + /** + * Creates a new <code>EmbeddedIdMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEmbeddedIdMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EmbeddedIdMappingComposite(PropertyValueModel<? extends IEmbeddedIdMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite composite) { + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedMappingComposite.java new file mode 100644 index 0000000000..4f520202c9 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedMappingComposite.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | EmbeddedAttributeOverridesComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IEmbeddedMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see EmbeddedAttributeOverridesComposite + * + * @version 2.0 + * @since 1.0 + */ +public class EmbeddedMappingComposite extends AbstractFormPane<IEmbeddedMapping> + implements IJpaComposite<IEmbeddedMapping> +{ + /** + * Creates a new <code>EmbeddedMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEmbeddedMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EmbeddedMappingComposite(PropertyValueModel<? extends IEmbeddedMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + new EmbeddedAttributeOverridesComposite( + this, + container + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java index e81b6f23a7..8f3d63b076 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java @@ -1,213 +1,156 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.ITable; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.help.IWorkbenchHelpSystem; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class EntityComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | EntityNameCombo | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | TableComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - v Attribute Overrides ------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OverridesComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - v Secondary Tables ---------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | SecondaryTablesComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - v Inheritance --------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | InheritanceComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IBasicMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see EntityNameCombo + * @see InheritanceComposite + * @see OverridesComposite + * @see SecondaryTablesComposite + * @see TableComposite + * + * TODO talk to JavaEditor people about what we can do to hook in TabbedProperties for the JavaEditor + * + * @version 2.0 + * @since 1.0 + */ +public class EntityComposite extends AbstractFormPane<IEntity> + implements IJpaComposite<IEntity> { - private IEntity entity; - - private EntityNameCombo entityNameCombo; - - private TableComposite tableComposite; - private InheritanceComposite inheritanceComposite; - private SecondaryTablesComposite secondaryTablesComposite; - private OverridesComposite attributeOverridesComposite; - - public EntityComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - Control attributeOverridesControl = buildAttributeOverridesComposite(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - attributeOverridesControl.setLayoutData(gridData); - - Control secondaryTablesControl = buildSecondaryTablesComposite(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - secondaryTablesControl.setLayoutData(gridData); - - Control inheritanceControl = buildInheritanceComposite(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - inheritanceControl.setLayoutData(gridData); - } - - private Control buildGeneralComposite(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - CommonWidgets.buildEntityNameLabel(generalComposite, getWidgetFactory()); - - this.entityNameCombo = - CommonWidgets.buildEntityNameCombo(generalComposite, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.entityNameCombo.getCombo().setLayoutData(gridData); - helpSystem.setHelp(this.entityNameCombo.getCombo(), IJpaHelpContextIds.ENTITY_NAME); - - - this.tableComposite = new TableComposite(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.tableComposite.getControl().setLayoutData(gridData); - - return generalComposite; - } - - private Control buildSecondaryTablesComposite(Composite composite) { - Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - section.setText(JptUiMappingsMessages.SecondaryTablesComposite_secondaryTables); - - Composite client = getWidgetFactory().createComposite(section); - section.setClient(client); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - client.setLayout(layout); - - this.secondaryTablesComposite = new SecondaryTablesComposite(client, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.secondaryTablesComposite.getControl().setLayoutData(gridData); - - return section; - } + /** + * Creates a new <code>EntityComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEntity</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EntityComposite(PropertyValueModel<? extends IEntity> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { - private Control buildInheritanceComposite(Composite composite) { - Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - section.setText(JptUiMappingsMessages.EntityComposite_inheritance); - - Composite inheritanceClient = getWidgetFactory().createComposite(section); - section.setClient(inheritanceClient); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - inheritanceClient.setLayout(layout); - - this.inheritanceComposite = new InheritanceComposite(inheritanceClient, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.inheritanceComposite.getControl().setLayoutData(gridData); - - return section; + super(subjectHolder, parent, widgetFactory); } - private Control buildAttributeOverridesComposite(Composite composite) { - Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - section.setText(JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides); - //section.setExpanded(true); //not going to expand this for now, it causes the scroll bar not to appear - Composite client = getWidgetFactory().createComposite(section); - section.setClient(client); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - client.setLayout(layout); - - this.attributeOverridesComposite = new OverridesComposite(client, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.attributeOverridesComposite.getControl().setLayoutData(gridData); - - return section; + private PropertyValueModel<ITable> buildTableHolder() { + return new TransformationPropertyValueModel<IEntity, ITable>(getSubjectHolder()) { + @Override + protected ITable transform_(IEntity value) { + return value.getTable(); + } + }; } - //TODO talk to JavaEditor people about what we can do to hook in TabbedProperties for the JavaEditor - - public void doPopulate(EObject obj) { - this.entity = (IEntity) obj; - this.entityNameCombo.populate(obj); - this.attributeOverridesComposite.populate(obj); - this.secondaryTablesComposite.populate(obj); - this.inheritanceComposite.populate(obj); - if (this.entity != null) { - this.tableComposite.populate(this.entity.getTable()); - } - else { - this.tableComposite.populate(null); - } - } - - public void doPopulate() { - this.entityNameCombo.populate(); - this.tableComposite.populate(); - this.attributeOverridesComposite.populate(); - this.secondaryTablesComposite.populate(); - this.inheritanceComposite.populate(); + private void initializeAttributeOverridesPane(Composite container) { + + container = buildSection( + container, + JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides + ); + + new OverridesComposite(this, container); } - - protected void engageListeners() { + + private void initializeGeneralPane(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + EntityNameCombo entityNameCombo = new EntityNameCombo(this, container); + + // Entity Name widgets + buildLabeledComposite( + buildSubPane(container, 1, 0, groupBoxMargin, 0, groupBoxMargin), + JptUiMappingsMessages.EntityGeneralSection_name, + entityNameCombo.getControl(), + IJpaHelpContextIds.ENTITY_NAME + ); + + // Table widgets + new TableComposite(this, buildTableHolder(), container); } - - protected void disengageListeners() { + + private void initializeInheritancePane(Composite container) { + + container = buildSection( + container, + JptUiMappingsMessages.EntityComposite_inheritance + ); + + new InheritanceComposite(this, container); } - + + /* + * (non-Javadoc) + */ @Override - public void dispose() { - this.entityNameCombo.dispose(); - this.tableComposite.dispose(); - this.attributeOverridesComposite.dispose(); - this.secondaryTablesComposite.dispose(); - this.inheritanceComposite.dispose(); - super.dispose(); - } - - protected IEntity getEntity() { - return this.entity; + protected void initializeLayout(Composite container) { + + initializeGeneralPane(container); + initializeAttributeOverridesPane(container); + initializeSecondaryTablesPane(container); + initializeInheritancePane(container); } -} + private void initializeSecondaryTablesPane(Composite container) { + + container = buildSection( + container, + JptUiMappingsMessages.SecondaryTablesComposite_secondaryTables + ); + + new SecondaryTablesComposite(this, container); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityNameCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityNameCombo.java index 8fe0ffcf4c..90bbfcaac8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityNameCombo.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityNameCombo.java @@ -1,165 +1,143 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; import java.util.Arrays; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; +import org.eclipse.jpt.core.internal.context.base.IEntity; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -// TODO get Default updating appropriately based on Entity name default - -public class EntityNameCombo extends BaseJpaController +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------ | + * | Entity Name: | I |v| | + * | ------------------------------------------------------------ | + * -----------------------------------------------------------------------------</pre> + * + * @see IEntity + * @see EntityComposite - The parent container + * + * @version 2.0 + * @since 1.0 + */ +public class EntityNameCombo extends AbstractFormPane<IEntity> { - private IEntity entity; - private Adapter entityListener; - private CCombo combo; - - - public EntityNameCombo(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, commandStack, widgetFactory); - buildEntityListener(); + + /** + * Creates a new <code>EntityNameCombo</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public EntityNameCombo(AbstractFormPane<? extends IEntity> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(java.util.Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IEntity.DEFAULT_NAME_PROPERTY); + propertyNames.add(IEntity.SPECIFIED_NAME_PROPERTY); } - - - private void buildEntityListener() { - entityListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - entityChanged(notification); + + private ModifyListener buildComboModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + comboModified(e); } }; } - - @Override - protected void buildWidget(Composite parent) { - combo = this.widgetFactory.createCCombo(parent, SWT.FLAT); - combo.addModifyListener( - new ModifyListener() { - public void modifyText(ModifyEvent e) { - comboModified(e); - } - }); - } - + private void comboModified(ModifyEvent e) { - if (isPopulating()) { - return; - } - String text = ((CCombo) e.getSource()).getText(); + if (text.equals(combo.getItem(0))) { text = null; } - - entity.setSpecifiedName(text); - + + subject().setSpecifiedName(text); + // TODO Does this need to be done? //this.editingDomain.getCommandStack().execute(SetCommand.create(this.editingDomain, this.entity, MappingsPackage.eINSTANCE.getEntity_SpecifiedName(), text)); } - - private void entityChanged(Notification notification) { - switch (notification.getFeatureID(IEntity.class)) { - case JpaCoreMappingsPackage.IENTITY__SPECIFIED_NAME : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - break; - case JpaCoreMappingsPackage.IENTITY__DEFAULT_NAME : - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - break; - } - } - - @Override - protected void engageListeners() { - if (entity != null) { - entity.eAdapters().add(entityListener); - } - } - - @Override - protected void disengageListeners() { - if (entity != null) { - entity.eAdapters().remove(entityListener); - } - } - + + /* + * (non-Javadoc) + */ @Override - public void doPopulate(EObject obj) { - entity = (IEntity) obj; + protected void doPopulate() { + super.doPopulate(); populateCombo(); } - + + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { - populateCombo(); + protected void initializeLayout(Composite container) { + combo = buildCombo(container); + combo.addModifyListener(buildComboModifyListener()); } - + private void populateCombo() { - if (entity == null) { + if (subject() == null) { combo.clearSelection(); - combo.setItems(new String[] {}); - return; - } - - String defaultItem = NLS.bind(JptUiMappingsMessages.EntityGeneralSection_nameDefaultWithOneParam, entity.getDefaultName()); - String specifiedName = entity.getSpecifiedName(); - - if (specifiedName == null) { - setComboData(defaultItem, new String[] {defaultItem}); + combo.setItems(new String[0]); } else { - setComboData(specifiedName, new String[] {defaultItem}); + String defaultItem = NLS.bind(JptUiMappingsMessages.EntityGeneralSection_nameDefaultWithOneParam, subject().getDefaultName()); + String specifiedName = subject().getSpecifiedName(); + + if (specifiedName == null) { + setComboData(defaultItem, new String[] { defaultItem }); + } + else { + setComboData(specifiedName, new String[] { defaultItem }); + } } } - + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == IEntity.DEFAULT_NAME_PROPERTY || + propertyName == IEntity.SPECIFIED_NAME_PROPERTY) { + + populateCombo(); + } + } + private void setComboData(String text, String[] items) { if (! Arrays.equals(items, combo.getItems())) { combo.setItems(items); } - + if (! text.equals(combo.getText())) { combo.setText(text); } } - - public CCombo getCombo() { - return combo; - } - - @Override - public Control getControl() { - return getCombo(); - } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumComboViewer.java deleted file mode 100644 index 7cb415f359..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumComboViewer.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class EnumComboViewer extends BaseJpaController -{ - private EnumHolder enumHolder; - private Adapter enumListener; - - private ComboViewer comboViewer; - - - public EnumComboViewer(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildListener(); - } - - - private void buildListener() { - this.enumListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - modelChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - this.comboViewer = new ComboViewer(combo); - this.comboViewer.setLabelProvider(buildLabelProvider()); - this.comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - EnumComboViewer.this.selectionChanged(event.getSelection()); - } - }); - } - protected IBaseLabelProvider buildLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - if (element == enumHolder.defaultValue()) { - return NLS.bind(JptUiMappingsMessages.EnumComboViewer_default, enumHolder.defaultString()); - } - return super.getText(element); - } - }; - } - - void selectionChanged(ISelection sel) { - if (sel instanceof IStructuredSelection) { - Object selection = ((IStructuredSelection) sel).getFirstElement(); - if ( ! this.enumHolder.get().equals(selection)) { - this.enumHolder.set(selection); -// this.editingDomain.getCommandStack().execute( -// SetCommand.create( -// this.editingDomain, -// this.basicMapping, -// OrmPackage.eINSTANCE.getBasicMapping_Optional(), -// optional -// ) -// ); - } - } - } - - private void modelChanged(Notification notification) { - if (notification.getFeatureID(this.enumHolder.featureClass()) == - this.enumHolder.featureId()) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.enumHolder != null && this.enumHolder.wrappedObject() != null) { - this.enumHolder.wrappedObject().eAdapters().add(this.enumListener); - } - } - - @Override - protected void disengageListeners() { - if (this.enumHolder != null && this.enumHolder.wrappedObject() != null) { - this.enumHolder.wrappedObject().eAdapters().remove(this.enumListener); - } - } - - public final void populate(EnumHolder enumHolder) { - super.populate(enumHolder); - } - - @Override - public void doPopulate(EObject obj) { - this.enumHolder = (EnumHolder) obj; - populateCombo(); - } - - @Override - protected void doPopulate() { - populateCombo(); - } - - private void populateCombo() { - this.comboViewer.getCombo().removeAll(); - if (this.enumHolder.wrappedObject() == null) { - return; - } - - this.comboViewer.add(this.enumHolder.enumValues()); - - Object modelSetting = this.enumHolder.get(); - - if (((IStructuredSelection) this.comboViewer.getSelection()).getFirstElement() != modelSetting) { - this.comboViewer.setSelection(new StructuredSelection(modelSetting)); - } - } - - - @Override - public Control getControl() { - return this.comboViewer.getCombo(); - } - - - /** - * An interface to wrap an object that supports accessType - * An object of this type must be passed in to populate(EObject) - */ - public static interface EnumHolder extends EObject { - /** - * Return the num setting from the wrapped object - * @return - */ - Object get(); - - /** - * Set the enum setting on the wrapped object - * @param fetch - */ - void set(Object enumSetting); - - /** - * Return the Class of the wrapped object - * @return - */ - Class featureClass(); - - /** - * Return the feature id of enum setting on the wrapped object - * @return - */ - int featureId(); - - /** - * The wrapped EObject that the enum setting is stored on - * @return - */ - EObject wrappedObject(); - - Object[] enumValues(); - - /** - * Return the Default Enumerator object - */ - Object defaultValue(); - - /** - * Return the String to be displayed to the user - * Deafult ([defaultString()]) - */ - String defaultString(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumTypeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumTypeComposite.java new file mode 100644 index 0000000000..685bc25def --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumTypeComposite.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.EnumType; +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | -------------------------------------------------------------- | + * | Enum Type: | |v| | + * | -------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IBasicMapping + * @see BasicMappingComposite - A container of this widget + * + * @version 2.0 + * @since 1.0 + */ +public class EnumTypeComposite extends AbstractFormPane<IBasicMapping> +{ + /** + * Creates a new <code>FetchTypeComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public EnumTypeComposite(AbstractFormPane<? extends IBasicMapping> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + private EnumComboViewer<IBasicMapping, EnumType> buildEnumTypeCombo(Composite container) { + + return new EnumComboViewer<IBasicMapping, EnumType>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IBasicMapping.DEFAULT_ENUMERATED_PROPERTY); + propertyNames.add(IBasicMapping.SPECIFIED_ENUMERATED_PROPERTY); + } + + @Override + protected EnumType[] choices() { + return EnumType.values(); + } + + @Override + protected EnumType defaultValue() { + return subject().getDefaultEnumerated(); + } + + @Override + protected String displayString(EnumType value) { + return buildDisplayString( + JptUiMappingsMessages.class, + EnumTypeComposite.this, + value + ); + } + + @Override + protected EnumType getValue() { + return subject().getSpecifiedEnumerated(); + } + + @Override + protected void setValue(EnumType value) { + subject().setSpecifiedEnumerated(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + EnumComboViewer<IBasicMapping, EnumType> enumTypeCombo = + buildEnumTypeCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.BasicGeneralSection_enumeratedLabel, + enumTypeCombo.getControl(), + IJpaHelpContextIds.MAPPING_ENUMERATED + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/FetchTypeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/FetchTypeComposite.java new file mode 100644 index 0000000000..7d8e17482b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/FetchTypeComposite.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.FetchType; +import org.eclipse.jpt.core.internal.context.base.IFetchable; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------ | + * | Fetch: | |v| | + * | ------------------------------------------------------------------ | + * -----------------------------------------------------------------------------</pre> + * + * @see IFetchable + * @see BasicMappingComposite - A container of this widget + * @see ManyToManyMappingComposite - A container of this widget + * @see ManyToOneMappingComposite - A container of this widget + * @see OneToManyMappingComposite - A container of this widget + * @see OneToOneMappingComposite - A container of this widget + * + * @version 2.0 + * @since 1.0 + */ +public class FetchTypeComposite extends AbstractFormPane<IFetchable> { + + /** + * Creates a new <code>FetchTypeComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public FetchTypeComposite(AbstractFormPane<? extends IFetchable> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + private EnumComboViewer<IFetchable, FetchType> buildFetchTypeCombo(Composite container) { + + return new EnumComboViewer<IFetchable, FetchType>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IFetchable.DEFAULT_FETCH_PROPERTY); + propertyNames.add(IFetchable.SPECIFIED_FETCH_PROPERTY); + } + + @Override + protected FetchType[] choices() { + return FetchType.values(); + } + + @Override + protected FetchType defaultValue() { + return subject().getDefaultFetch(); + } + + @Override + protected String displayString(FetchType value) { + return buildDisplayString( + JptUiMappingsMessages.class, + FetchTypeComposite.this, + value + ); + } + + @Override + protected FetchType getValue() { + return subject().getSpecifiedFetch(); + } + + @Override + protected void setValue(FetchType value) { + subject().setSpecifiedFetch(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + EnumComboViewer<IFetchable, FetchType> fetchTypeCombo = + buildFetchTypeCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.BasicGeneralSection_fetchLabel, + fetchTypeCombo.getControl(), + IJpaHelpContextIds.MAPPING_FETCH_TYPE + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratedValueComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratedValueComposite.java index 11285beeed..33b5289eed 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratedValueComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratedValueComposite.java @@ -1,288 +1,351 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.mappings.GenerationType; -import org.eclipse.jpt.core.internal.mappings.IGeneratedValue; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.core.internal.platform.IGeneratorRepository; -import org.eclipse.jpt.core.internal.platform.NullGeneratorRepository; +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.GenerationType; +import org.eclipse.jpt.core.internal.context.base.IGeneratedValue; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; +import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class GeneratedValueComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | --------------------------------------------------------- | + * | Strategy: | I |v| | + * | --------------------------------------------------------- | + * | --------------------------------------------------------- | + * | Generator Name: | I |v| | + * | --------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IIdMapping + * @see IGeneratedValue + * @see GenerationComposite - The parent container + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public class GeneratedValueComposite extends AbstractFormPane<IIdMapping> { - private IId id; - private IGeneratedValue generatedValue; - private Adapter generatedValueListener; + private PropertyChangeListener generatedValueChangeListener; + private PropertyChangeListener generatorNameChangeListener; + private CCombo generatorNameCombo; + private PropertyChangeListener subjectChangeListener; - private ComboViewer strategyComboViewer; + /** + * Creates a new <code>GeneratedValueComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public GeneratedValueComposite(AbstractFormPane<? extends IIdMapping> parentPane, + Composite parent) { - private CCombo generatorNameCombo; + super(parentPane, parent); + } - protected boolean populating; + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IGeneratedValue.SPECIFIED_GENERATOR_PROPERTY); + } - public GeneratedValueComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.generatedValueListener = buildGeneratedValueListener(); + private PropertyChangeListener buildGeneratedValueChangeListener() { + return new SWTPropertyChangeListenerWrapper(buildGeneratedValueChangeListener_()); } - private Adapter buildGeneratedValueListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - generatedValueChanged(notification); + private PropertyChangeListener buildGeneratedValueChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + + IGeneratedValue oldValue = (IGeneratedValue) e.oldValue(); + IGeneratedValue newValue = (IGeneratedValue) e.newValue(); + + uninstallGeneratedValueListeners(oldValue); + repopulate(); + installGeneratedValueListeners(newValue); } }; } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - composite.setLayout(layout); - - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.GeneratedValueComposite_strategy); - - this.strategyComboViewer = buildStrategyComboViewer(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.strategyComboViewer.getCombo().setLayoutData(gridData); - helpSystem.setHelp(this.strategyComboViewer.getCombo(), IJpaHelpContextIds.MAPPING_GENERATED_VALUE_STRATEGY); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.GeneratedValueComposite_generatorName); - - this.generatorNameCombo = buildGeneratorNameCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.generatorNameCombo.setLayoutData(gridData); - helpSystem.setHelp(this.generatorNameCombo, IJpaHelpContextIds.MAPPING_GENERATED_VALUE_GENERATOR_NAME); - - // TODO - // buildGeneratorNameSelectionButton( this); - } - private ComboViewer buildStrategyComboViewer(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - ComboViewer viewer = new ComboViewer(combo); - viewer.setLabelProvider(buildStrategyLabelProvider()); - viewer.add(GenerationType.VALUES.toArray()); - viewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if (populating) { - return; - } - if (event.getSelection() instanceof StructuredSelection) { - StructuredSelection selection = (StructuredSelection) event.getSelection(); - GenerationType selectedType = (GenerationType) selection.getFirstElement(); - if (generatedValue == null) { - createGeneratedValue(); - } - if (!generatedValue.getStrategy().equals(selectedType)) { - generatedValue.setStrategy(selectedType); - } - } - } - }); - return viewer; + private PropertyChangeListener buildGeneratorNameChangeListener() { + return new SWTPropertyChangeListenerWrapper(buildGeneratorNameChangeListener_()); } - private IBaseLabelProvider buildStrategyLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - if (element == GenerationType.DEFAULT) { - //TODO need to move this to the model, don't want hardcoded String - return NLS.bind(JptUiMappingsMessages.GeneratedValueComposite_default, "Auto"); + private PropertyChangeListener buildGeneratorNameChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + if (isPopulating()) { + return; } - return super.getText(element); + + populateGeneratorName(); } }; } - - protected CCombo buildGeneratorNameCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); + private CCombo buildGeneratorNameCombo(Composite parent) { + + CCombo combo = buildCombo(parent); combo.add(JptUiMappingsMessages.TableComposite_defaultEmpty); - combo.addModifyListener(new ModifyListener() { + combo.addModifyListener(buildGeneratorNameModifyListener()); + return combo; + } + + private ModifyListener buildGeneratorNameModifyListener() { + return new ModifyListener() { public void modifyText(ModifyEvent e) { if (isPopulating()) { return; } + String generatorName = ((CCombo) e.getSource()).getText(); - - if (generatorName.equals("")) { //$NON-NLS-1$ - if (generatedValue.getGenerator() == null || generatedValue.getGenerator().equals("")) { + IGeneratedValue generatedValue = subject().getGeneratedValue(); + + if (StringTools.stringIsEmpty(generatorName)) { + + if ((generatedValue == null) || + StringTools.stringIsEmpty(generatedValue.getGenerator())) + { return; } + generatorName = null; } + if (generatedValue == null) { - createGeneratedValue(); + generatedValue = subject().addGeneratedValue(); } - generatedValue.setGenerator(generatorName); + + generatedValue.setSpecifiedGenerator(generatorName); } - }); - return combo; + }; } - private void createGeneratedValue() { - this.generatedValue = this.id.createGeneratedValue(); - this.id.setGeneratedValue(this.generatedValue); + private PropertyValueModel<IGeneratedValue> buildGeneratorValueHolder() { + return new PropertyAspectAdapter<IIdMapping, IGeneratedValue>(getSubjectHolder(), IIdMapping.GENERATED_VALUE_PROPERTY) { + @Override + protected IGeneratedValue buildValue_() { + return subject().getGeneratedValue(); + } + }; } - - protected void generatedValueChanged(Notification notification) { - if (notification.getFeatureID(IGeneratedValue.class) == JpaCoreMappingsPackage.IGENERATED_VALUE__STRATEGY) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - if (selectedStrategy() != generatedValue.getStrategy()) { - strategyComboViewer.setSelection(new StructuredSelection(generatedValue.getStrategy())); - } - } - }); - } - else if (notification.getFeatureID(IGeneratedValue.class) == JpaCoreMappingsPackage.IGENERATED_VALUE__GENERATOR) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateGeneratorName(); + private EnumComboViewer<IGeneratedValue, GenerationType> buildStrategyComboViewer(Composite parent) { + return new EnumComboViewer<IGeneratedValue, GenerationType>(this, buildGeneratorValueHolder(), parent) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IGeneratedValue.DEFAULT_STRATEGY_PROPERTY); + propertyNames.add(IGeneratedValue.SPECIFIED_STRATEGY_PROPERTY); + } + + @Override + protected GenerationType[] choices() { + return GenerationType.values(); + } + + @Override + protected GenerationType defaultValue() { + return subject().getDefaultStrategy(); + } + + @Override + protected String displayString(GenerationType value) { + return buildDisplayString( + JptUiMappingsMessages.class, + GeneratedValueComposite.this, + value + ); + } + + @Override + protected GenerationType getValue() { + return subject().getSpecifiedStrategy(); + } + + @Override + protected void setValue(GenerationType value) { + IGeneratedValue generatedValue = subject(); + + if (generatedValue == null) { + generatedValue = GeneratedValueComposite.this.subject().addGeneratedValue(); } - }); - } + + subject().setSpecifiedStrategy(value); + } + }; } + private PropertyChangeListener buildSubjectChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + uninstallListeners((IIdMapping) e.oldValue()); + installListeners((IIdMapping) e.newValue()); + } + }; + } + + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(EObject obj) { - this.id = (IId) obj; - if (this.id == null) { - this.generatedValue= null; - } - else { - this.generatedValue = this.id.getGeneratedValue(); - } - if (this.generatedValue == null) { - this.strategyComboViewer.getCombo().setText(""); - this.generatorNameCombo.setText(""); - this.populating = false; - return; - } - populateStrategyCombo(); - populateGeneratorNameCombo(); + protected void disengageListeners() { + super.disengageListeners(); + getSubjectHolder().removePropertyChangeListener(PropertyValueModel.VALUE, subjectChangeListener); + uninstallListeners(subject()); } + /* + * (non-Javadoc) + */ @Override protected void doPopulate() { - + super.doPopulate(); + populateGeneratorNameCombo(); } - + +// private IGeneratorRepository getGeneratorRepository() { +// return NullGeneratorRepository.instance(); //this.id.getJpaProject().getPlatform().generatorRepository(this.id.typeMapping().getPersistentType()); +// } + + /* + * (non-Javadoc) + */ + @Override protected void engageListeners() { - if (this.generatedValue != null) { - this.generatedValue.eAdapters().add(this.generatedValueListener); - } + super.engageListeners(); + getSubjectHolder().addPropertyChangeListener(PropertyValueModel.VALUE, subjectChangeListener); + installListeners(subject()); } - protected void disengageListeners() { - if (this.generatedValue != null) { - this.generatedValue.eAdapters().remove(this.generatedValueListener); - } + @Override + protected void initialize() { + super.initialize(); + + subjectChangeListener = buildSubjectChangeListener(); + generatedValueChangeListener = buildGeneratedValueChangeListener(); + generatorNameChangeListener = buildGeneratorNameChangeListener(); } - private IGeneratorRepository getGeneratorRepository() { - return NullGeneratorRepository.instance(); //this.id.getJpaProject().getPlatform().generatorRepository(this.id.typeMapping().getPersistentType()); + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Strategy widgets + EnumComboViewer<IGeneratedValue, GenerationType> strategyComboViewer = + buildStrategyComboViewer(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.GeneratedValueComposite_strategy, + strategyComboViewer.getControl(), + IJpaHelpContextIds.MAPPING_GENERATED_VALUE_STRATEGY + ); + + // Generator Name widgets + generatorNameCombo = buildGeneratorNameCombo(container); + + // Note: The combo's parent is a container fixing the issue with the + // border not being painted + buildLabeledComposite( + container, + JptUiMappingsMessages.GeneratedValueComposite_generatorName, + generatorNameCombo.getParent(), + IJpaHelpContextIds.MAPPING_GENERATED_VALUE_STRATEGY + ); + + // TODO + // buildGeneratorNameSelectionButton( this); } - - private void populateGeneratorNameCombo() { - this.generatorNameCombo.removeAll(); - for (Iterator<String> i = getGeneratorRepository().generatorNames(); i.hasNext(); ){ - this.generatorNameCombo.add(i.next()); + + private void installGeneratedValueListeners(IGeneratedValue generatedValue) { + if (generatedValue != null) { + generatedValue.addPropertyChangeListener(IGeneratedValue.DEFAULT_GENERATOR_PROPERTY, generatorNameChangeListener); + generatedValue.addPropertyChangeListener(IGeneratedValue.SPECIFIED_GENERATOR_PROPERTY, generatorNameChangeListener); } + } - populateGeneratorName(); + private void installListeners(IIdMapping idMapping) { + if (idMapping != null) { + idMapping.addPropertyChangeListener(IIdMapping.GENERATED_VALUE_PROPERTY, generatedValueChangeListener); + installGeneratedValueListeners(idMapping.getGeneratedValue()); + } } + private void populateGeneratorName() { - String generatorName = this.generatedValue.getGenerator(); - if (generatorName == null || generatorName.equals("")) { + if (subject() == null) { this.generatorNameCombo.setText(""); } - else if (!this.generatorNameCombo.getText().equals(generatorName)) { - this.generatorNameCombo.setText(generatorName); - } - } - - private void populateStrategyCombo() { - GenerationType selectedType = selectedStrategy(); - GenerationType strategy = this.generatedValue.getStrategy(); - if (strategy == GenerationType.AUTO) { - if (selectedType != GenerationType.AUTO) { - this.strategyComboViewer.setSelection(new StructuredSelection(GenerationType.AUTO)); - } - } - else if (strategy == GenerationType.SEQUENCE) { - if (selectedType != GenerationType.SEQUENCE) { - this.strategyComboViewer.setSelection(new StructuredSelection(GenerationType.SEQUENCE)); - } - } - else if (strategy == GenerationType.IDENTITY) { - if (selectedType != GenerationType.IDENTITY) { - this.strategyComboViewer.setSelection(new StructuredSelection(GenerationType.IDENTITY)); + else { + IGeneratedValue generatedValue = subject().getGeneratedValue(); + + if (generatedValue == null) { + this.generatorNameCombo.setText(""); } - } - else if (strategy == GenerationType.TABLE) { - if (selectedType != GenerationType.TABLE) { - this.strategyComboViewer.setSelection(new StructuredSelection(GenerationType.TABLE)); + else { + String generatorName = generatedValue.getGenerator(); + + if (StringTools.stringIsEmpty(generatorName)) { + this.generatorNameCombo.setText(""); + } + else if (!this.generatorNameCombo.getText().equals(generatorName)) { + this.generatorNameCombo.setText(generatorName); + } } } - else { - if (selectedType != GenerationType.DEFAULT) { - this.strategyComboViewer.setSelection(new StructuredSelection(GenerationType.DEFAULT)); - } + } + + private void populateGeneratorNameCombo() { + this.generatorNameCombo.removeAll(); + //TODO +// for (Iterator<String> i = getGeneratorRepository().generatorNames(); i.hasNext(); ){ +// this.generatorNameCombo.add(i.next()); +// } + + populateGeneratorName(); + } + + private void uninstallGeneratedValueListeners(IGeneratedValue generatedValue) { + if (generatedValue != null) { + generatedValue.removePropertyChangeListener(IGeneratedValue.DEFAULT_GENERATOR_PROPERTY, generatorNameChangeListener); + generatedValue.removePropertyChangeListener(IGeneratedValue.SPECIFIED_GENERATOR_PROPERTY, generatorNameChangeListener); } - // TODO first initialization } - private GenerationType selectedStrategy() { - return (GenerationType) ((StructuredSelection) this.strategyComboViewer.getSelection()).getFirstElement(); + private void uninstallListeners(IIdMapping idMapping) { + if (idMapping != null) { + idMapping.removePropertyChangeListener(IIdMapping.GENERATED_VALUE_PROPERTY, generatedValueChangeListener); + uninstallGeneratedValueListeners(idMapping.getGeneratedValue()); + } } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java new file mode 100644 index 0000000000..6263dee02a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java @@ -0,0 +1,268 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IGeneratedValue; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.core.internal.context.base.ISequenceGenerator; +import org.eclipse.jpt.core.internal.context.base.ITableGenerator; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | v Primary Key Generation | + * | | + * | x Primary Key Generation | + * | --------------------------------------------------------------------- | + * | | | | + * | | GeneratedValueComposite | | + * | | | | + * | --------------------------------------------------------------------- | + * | | + * | v Table Generator | + * | | + * | x Table Generator | + * | --------------------------------------------------------------------- | + * | | | | + * | | TableGeneratorComposite | | + * | | | | + * | --------------------------------------------------------------------- | + * | | + * | v Sequence Generator | + * | | + * | x Sequence Generator | + * | --------------------------------------------------------------------- | + * | | | | + * | | SequenceGeneratorComposite | | + * | | | | + * | --------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IIdMapping + * @see GeneratedValueComposite + * @see TableGeneratorComposite + * @see SequenceGeneratorComposite + * @see IdMappingComposite - The parent container + * + * @version 2.0 + * @since 1.0 + */ +public class GenerationComposite extends AbstractFormPane<IIdMapping> +{ + private WritablePropertyValueModel<Boolean> sequenceGeneratorExpansionStateHolder; + private WritablePropertyValueModel<Boolean> tableGeneratorExpansionStateHolder; + + /** + * Creates a new <code>GenerationComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public GenerationComposite(AbstractFormPane<? extends IIdMapping> parentPane, + Composite parent) + { + super(parentPane, parent, false); + } + + private WritablePropertyValueModel<Boolean> buildPrimaryKeyGenerationHolder() { + return new PropertyAspectAdapter<IIdMapping, Boolean>(getSubjectHolder(), IIdMapping.GENERATED_VALUE_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject().getGeneratedValue() != null; + } + + @Override + protected void setValue_(Boolean value) { + + if (value && (subject.getGeneratedValue() == null)) { + subject.addGeneratedValue(); + } + else if (!value && (subject.getGeneratedValue() != null)) { + subject.removeGeneratedValue(); + } + } + }; + } + + private WritablePropertyValueModel<Boolean> buildSequenceGeneratorBooleanHolder() { + return new PropertyAspectAdapter<IIdMapping, Boolean>(getSubjectHolder(), IIdMapping.SEQUENCE_GENERATOR_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject().getSequenceGenerator() != null; + } + + @Override + protected void setValue_(Boolean value) { + + if (value && (subject.getSequenceGenerator() == null)) { + + ISequenceGenerator sequenceGenerator = subject.addSequenceGenerator(); + IGeneratedValue generatedValue = subject.getGeneratedValue(); + + if ((generatedValue != null) && + (generatedValue.getGenerator() != null)) + { + sequenceGenerator.setName(generatedValue.getGenerator()); + } + } + else if (!value && (subject.getSequenceGenerator() != null)) { + subject.removeSequenceGenerator(); + } + } + }; + } + + private WritablePropertyValueModel<Boolean> buildTableGeneratorBooleanHolder() { + return new PropertyAspectAdapter<IIdMapping, Boolean>(getSubjectHolder(), IIdMapping.TABLE_GENERATOR_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.getTableGenerator() != null; + } + + @Override + protected void setValue_(Boolean value) { + + if (value && (subject.getTableGenerator() == null)) { + + ITableGenerator tableGenerator = subject.addTableGenerator(); + IGeneratedValue generatedValue = subject.getGeneratedValue(); + + if ((generatedValue != null) && + (generatedValue.getGenerator() != null)) + { + tableGenerator.setName(generatedValue.getGenerator()); + } + } + else if (!value && (subject.getTableGenerator() != null)) { + subject.removeTableGenerator(); + } + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() + { + super.doPopulate(); + + sequenceGeneratorExpansionStateHolder.setValue(subject() != null && subject().getSequenceGenerator() != null); + tableGeneratorExpansionStateHolder .setValue(subject() != null && subject().getTableGenerator() != null); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initialize() { + super.initialize(); + + sequenceGeneratorExpansionStateHolder = new SimplePropertyValueModel<Boolean>(false); + tableGeneratorExpansionStateHolder = new SimplePropertyValueModel<Boolean>(false); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Primary Key Generation section + container = buildSection( + container, + JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration + ); + + // Primary Key Generation check box + Button primaryKeyGenerationCheckBox = buildCheckBox( + container, + JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration, + buildPrimaryKeyGenerationHolder(), + IJpaHelpContextIds.MAPPING_PRIMARY_KEY_GENERATION + ); + + // Generated Value widgets + GeneratedValueComposite generatedValueComposite = new GeneratedValueComposite( + this, + container + ); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalIndent = primaryKeyGenerationCheckBox.getBorderWidth() + 16; + + generatedValueComposite.getControl().setLayoutData(gridData); + + // Table Generator pane + initializeTableGeneratorPane(container); + + // Sequence Generator pane + initializeSequenceGeneratorPane(container); + } + + private void initializeSequenceGeneratorPane(Composite container) { + + // Sequence Generator sub-section + container = buildSubSection( + container, + JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, + sequenceGeneratorExpansionStateHolder + ); + + // Sequence Generator check box + Button sequenceGeneratorCheckBox = buildCheckBox( + container, + JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, + buildSequenceGeneratorBooleanHolder(), + IJpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR + ); + + // Sequence Generator pane + new SequenceGeneratorComposite( + this, + buildSubPane(container, 0, sequenceGeneratorCheckBox.getBorderWidth() + 16) + ); + } + + private void initializeTableGeneratorPane(Composite container) { + + // Table Generator sub-section + container = buildSubSection( + container, + JptUiMappingsMessages.IdMappingComposite_tableGenerator, + tableGeneratorExpansionStateHolder + ); + + Button tableGeneratorCheckBox = buildCheckBox( + container, + JptUiMappingsMessages.IdMappingComposite_tableGenerator, + buildTableGeneratorBooleanHolder(), + IJpaHelpContextIds.MAPPING_TABLE_GENERATOR + ); + + new TableGeneratorComposite( + this, + buildSubPane(container, 0, tableGeneratorCheckBox.getBorderWidth() + 16) + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java index a9f0227daf..2d968ddb7f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java @@ -3,149 +3,222 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IGenerator; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.core.internal.context.base.IGenerator; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; /** - * GeneratorComposite + * This is the generic pane for a generator. + * + * @see IIdMapping + * @see IGenerator + * @see SequenceGeneratorComposite - A sub-pane + * @see TalbeGeneratorComposite - A sub-pane + * + * @version 2.0 + * @since 1.0 */ -public abstract class GeneratorComposite<E extends IGenerator> extends BaseJpaComposite +@SuppressWarnings("nls") +public abstract class GeneratorComposite<T extends IGenerator> extends AbstractFormPane<IIdMapping> { - private IId id; - private E generator; - private Adapter generatorListener; + private PropertyChangeListener generatorChangeListener; + private PropertyValueModel<T> generatorHolder; + private PropertyChangeListener namePropertyChangeListener; + private Text nameText; - protected Text nameTextWidget; + /** + * Creates a new <code>GeneratorComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public GeneratorComposite(AbstractFormPane<? extends IIdMapping> parentPane, + Composite parent) { - public GeneratorComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.generatorListener = buildGeneratorListner(); + super(parentPane, parent); } - - private Adapter buildGeneratorListner() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - generatorChanged(notification); + + /** + * Creates the new <code>IGenerator</code>. + * + * @return The newly created <code>IGenerator</code> + */ + protected abstract T buildGenerator(); + + private PropertyChangeListener buildGeneratorChangeListener() { + return new SWTPropertyChangeListenerWrapper(this.buildGeneratorChangeListener_()); + } + + @SuppressWarnings("unchecked") + private PropertyChangeListener buildGeneratorChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + + GeneratorComposite.this.uninstallListeners((T) e.oldValue()); + + if (!isPopulating()) { + GeneratorComposite.this.repopulate(); + } + + GeneratorComposite.this.installListeners((T) e.newValue()); } }; } - /** - * Builds the Generator specifiedName viewer. - * - * @param parent - * @return - */ - protected Text buildNameText(Composite parent) { - final Text text = getWidgetFactory().createText(parent, null); - text.addModifyListener(new ModifyListener() { - public void modifyText(org.eclipse.swt.events.ModifyEvent e) { + private PropertyValueModel<T> buildGeneratorHolder() { + return new PropertyAspectAdapter<IIdMapping, T>(getSubjectHolder(), propertyName()) { + @Override + protected T buildValue_() { + return GeneratorComposite.this.getGenerator(subject); + } + }; + } + + private ModifyListener buildGeneratorNameModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (!isPopulating()) { + String name = ((Text) e.getSource()).getText(); + updateGeneratorName(name); + } + } + }; + } + + private PropertyChangeListener buildNamePropertyChangeListener() { + return new SWTPropertyChangeListenerWrapper(buildNamePropertyChangeListener_()); + } + + private PropertyChangeListener buildNamePropertyChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { if (isPopulating()) { return; } - - String name = text.getText(); - if (name.equals("")) { //$NON-NLS-1$ - if (getGenerator().getName() == null) { - return; - } - name = null; + + GeneratorComposite.this.setPopulating(true); + try { + GeneratorComposite.this.populateNameViewer(); } - IGenerator generator = getGenerator(); - if (generator == null) { - generator = createGenerator(); + finally { + GeneratorComposite.this.setPopulating(false); } - generator.setName(name); } - }); + }; + } + + /** + * Builds the Generator specifiedName viewer. + * + * @param parent + * @return + */ + protected final Text buildNameText(Composite parent) { + Text text = this.buildText(parent); + text.addModifyListener(this.buildGeneratorNameModifyListener()); return text; } - protected abstract E createGenerator(); + protected void clearNameViewer() { + this.nameText.setText(""); + } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(EObject obj) { - this.id = (IId) obj; - if (this.id == null) { - this.generator = null; - return; - } - this.generator = generator(this.id); - if (this.generator == null) { - clear(); - return; - } - populateNameViewer(); - return; + protected void disengageListeners() { + super.disengageListeners(); + + this.generatorHolder.removePropertyChangeListener( + PropertyValueModel.VALUE, + this.generatorChangeListener + ); + + this.uninstallListeners(this.getGenerator(this.subject())); } + /* + * (non-Javadoc) + */ @Override protected void doPopulate() { - populateNameViewer(); + super.doPopulate(); + this.populateNameViewer(); } - + + /* + * (non-Javadoc) + */ + @Override protected void engageListeners() { - if (this.generator != null) { - this.generator.eAdapters().add(this.generatorListener); - } + super.engageListeners(); + + this.generatorHolder.addPropertyChangeListener( + PropertyValueModel.VALUE, + this.generatorChangeListener + ); + + this.installListeners(this.getGenerator(this.subject())); } - protected void disengageListeners() { - if (this.generator != null) { - this.generator.eAdapters().remove(this.generatorListener); - } + /** + * Retrieves without creating the <code>IGenerator</code> from the subject. + * + * @param subject The subject used to retrieve the generator + * @return The <code>IGenerator</code> or <code>null</code> if it doesn't + * exists + */ + protected abstract T getGenerator(IIdMapping subject); + + /* + * (non-Javadoc) + */ + @Override + protected void initialize() { + super.initialize(); + + this.generatorHolder = buildGeneratorHolder(); + this.generatorChangeListener = buildGeneratorChangeListener(); + this.namePropertyChangeListener = buildNamePropertyChangeListener(); } - protected abstract E generator(IId id); - - protected IId idMapping() { - return this.id; - } - - protected void generatorChanged(Notification notification) { - if (notification.getFeatureID(IGenerator.class) == JpaCoreMappingsPackage.IGENERATOR__NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - if (nameTextWidget.getText() == null || !nameTextWidget.getText().equals(getGenerator().getName())) { - if (getGenerator().getName() == null) { - clearNameViewer(); - } - else { - nameTextWidget.setText(getGenerator().getName()); - } - } - } - }); + protected void installListeners(T generator) { + if (generator != null) { + generator.addPropertyChangeListener(IGenerator.NAME_PROPERTY, this.namePropertyChangeListener); } } private void populateNameViewer() { - String name = this.getGenerator().getName(); - if (name != null) { - if (!this.nameTextWidget.getText().equals(name)) { - this.nameTextWidget.setText(name); + IGenerator generator = this.getGenerator(this.subject()); + + if (generator != null) { + String name = generator.getName(); + + if (name != null) { + if (!this.nameText.getText().equals(name)) { + this.nameText.setText(name); + this.nameText.setSelection(0, 0); + } + } + else { + this.clearNameViewer(); } } else { @@ -153,15 +226,48 @@ public abstract class GeneratorComposite<E extends IGenerator> extends BaseJpaCo } } - protected E getGenerator() { - return this.generator; + /** + * Returns the property name used to listen to the ID mapping when the + * generator changes. + * + * @return The property name associated with the generator + */ + protected abstract String propertyName(); + + protected final void setNameText(Text nameText) { + this.nameText = nameText; } - protected void clear() { - this.clearNameViewer(); + protected void uninstallListeners(T generator) { + if (generator != null) { + generator.removePropertyChangeListener(IGenerator.NAME_PROPERTY, this.namePropertyChangeListener); + } } - protected void clearNameViewer() { - this.nameTextWidget.setText(""); //$NON-NLS-1$ + private void updateGeneratorName(String name) { + + if (StringTools.stringIsEmpty(name)) { + + if (getGenerator(subject()).getName() == null) { + return; + } + + name = null; + } + + IGenerator generator = getGenerator(subject()); + + if (generator == null) { + setPopulating(true); + + try { + generator = buildGenerator(); + } + finally { + setPopulating(false); + } + } + + generator.setName(name); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdComposite.java deleted file mode 100644 index b71d4cfffe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdComposite.java +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.EObjectImpl; -import org.eclipse.jpt.core.internal.mappings.IGeneratedValue; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.ISequenceGenerator; -import org.eclipse.jpt.core.internal.mappings.ITableGenerator; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.core.internal.mappings.TemporalType; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.EnumComboViewer.EnumHolder; -import org.eclipse.swt.SWT; -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; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class IdComposite extends BaseJpaComposite -{ - private IId id; - private Adapter idListener; - - private ColumnComposite columnComposite; - - private EnumComboViewer temporalTypeViewer; - - private Section pkGenerationSection; - private Button primaryKeyGenerationCheckBox; - private GeneratedValueComposite generatedValueComposite; - - private Section tableGenSection; - private Button tableGeneratorCheckBox; - private TableGeneratorComposite tableGeneratorComposite; - - private Section sequenceGenSection; - private Button sequenceGeneratorCheckBox; - private SequenceGeneratorComposite sequenceGeneratorComposite; - - - public IdComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.idListener = buildIdListener(); - } - - private Adapter buildIdListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - idMappingChanged(notification); - } - }; - } - void idMappingChanged(Notification notification) { - switch (notification.getFeatureID(IId.class)) { - case JpaCoreMappingsPackage.IID__TABLE_GENERATOR : - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - IdComposite.this.populateTableGeneratorComposite(); - } - }); - break; - case JpaCoreMappingsPackage.IID__SEQUENCE_GENERATOR : - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - IdComposite.this.populateSequenceGeneratorComposite(); - } - }); - break; - case JpaCoreMappingsPackage.IID__GENERATED_VALUE : - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - IdComposite.this.populateGeneratedValueComposite(); - } - }); - break; - } - } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - Control generationControl = buildGenerationComposite(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generationControl.setLayoutData(gridData); - } - - private Control buildGeneralComposite(Composite composite) { - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - this.columnComposite = new ColumnComposite(generalComposite, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.columnComposite.getControl().setLayoutData(gridData); - - CommonWidgets.buildTemporalLabel(generalComposite, getWidgetFactory()); - this.temporalTypeViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.temporalTypeViewer.getControl().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(temporalTypeViewer.getControl(), IJpaHelpContextIds.MAPPING_TEMPORAL); - - return generalComposite; - } - - private Control buildGenerationComposite(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - this.pkGenerationSection = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - this.pkGenerationSection.setText(JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration); - - Composite generationClient = getWidgetFactory().createComposite(this.pkGenerationSection); - this.pkGenerationSection.setClient(generationClient); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - generationClient.setLayout(layout); - - this.primaryKeyGenerationCheckBox = buildPrimaryKeyGenerationCheckBox(generationClient); - GridData gridData = new GridData(); - this.primaryKeyGenerationCheckBox.setLayoutData(gridData); - helpSystem.setHelp(primaryKeyGenerationCheckBox, IJpaHelpContextIds.MAPPING_PRIMARY_KEY_GENERATION); - - this.generatedValueComposite = new GeneratedValueComposite(generationClient, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalIndent = 20; - this.generatedValueComposite.getControl().setLayoutData(gridData); - - this.tableGenSection = getWidgetFactory().createSection(generationClient, SWT.FLAT | ExpandableComposite.TWISTIE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.tableGenSection.setLayoutData(gridData); - - this.tableGenSection.setText(JptUiMappingsMessages.IdMappingComposite_tableGenerator); - - Composite tableGenClient = getWidgetFactory().createComposite(this.tableGenSection); - this.tableGenSection.setClient(tableGenClient); - - layout = new GridLayout(); - layout.marginWidth = 0; - tableGenClient.setLayout(layout); - - this.tableGeneratorCheckBox = buildTableGeneratorCheckBox(tableGenClient); - gridData = new GridData(); - this.tableGeneratorCheckBox.setLayoutData(gridData); - helpSystem.setHelp(tableGeneratorCheckBox, IJpaHelpContextIds.MAPPING_TABLE_GENERATOR); - - this.tableGeneratorComposite = new TableGeneratorComposite(tableGenClient, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalIndent = 20; - this.tableGeneratorComposite.getControl().setLayoutData(gridData); - - - - this.sequenceGenSection = getWidgetFactory().createSection(generationClient, SWT.FLAT | ExpandableComposite.TWISTIE); - this.sequenceGenSection.setText(JptUiMappingsMessages.IdMappingComposite_sequenceGenerator); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.sequenceGenSection.setLayoutData(gridData); - - Composite sequenceGenClient = getWidgetFactory().createComposite(this.sequenceGenSection); - this.sequenceGenSection.setClient(sequenceGenClient); - - layout = new GridLayout(); - layout.marginWidth = 0; - sequenceGenClient.setLayout(layout); - - this.sequenceGeneratorCheckBox = buildSequenceGeneratorCheckBox(sequenceGenClient); - gridData = new GridData(); - this.sequenceGeneratorCheckBox.setLayoutData(gridData); - helpSystem.setHelp(sequenceGeneratorCheckBox, IJpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR); - - this.sequenceGeneratorComposite = new SequenceGeneratorComposite(sequenceGenClient, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalIndent = 20; - this.sequenceGeneratorComposite.getControl().setLayoutData(gridData); - - return this.pkGenerationSection; - } - - private Button buildPrimaryKeyGenerationCheckBox(Composite parent) { - Button button = getWidgetFactory().createButton(parent,JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration, SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - - public void widgetSelected(SelectionEvent e) { - IdComposite.this.primaryKeyGenerationCheckBoxClicked(e); - } - }); - return button; - } - - void primaryKeyGenerationCheckBoxClicked(SelectionEvent e) { - boolean mappingHasGeneratedValue = this.id.getGeneratedValue() != null; - boolean checked = this.primaryKeyGenerationCheckBox.getSelection(); - if (checked == mappingHasGeneratedValue) { - return; - } - IGeneratedValue generatedValue = null; - if (checked) { - generatedValue = this.id.createGeneratedValue(); - } - this.id.setGeneratedValue(generatedValue); - } - - private Button buildTableGeneratorCheckBox(Composite parent) { - Button button = getWidgetFactory().createButton(parent,JptUiMappingsMessages.IdMappingComposite_tableGenerator, SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - - public void widgetSelected(SelectionEvent e) { - IdComposite.this.tableGeneratorCheckBoxClicked(e); - } - }); - return button; - } - - void tableGeneratorCheckBoxClicked(SelectionEvent e) { - boolean mappingHasTableGenerator = this.id.getTableGenerator() != null; - boolean checked = this.tableGeneratorCheckBox.getSelection(); - if (checked == mappingHasTableGenerator) { - return; - } - ITableGenerator tableGenerator = null; - if (checked) { - tableGenerator = this.id.createTableGenerator(); - } - this.id.setTableGenerator(tableGenerator); - if (checked) { - IGeneratedValue generatedValue = this.id.getGeneratedValue(); - if (generatedValue != null && generatedValue.getGenerator() != null) { - tableGenerator.setName(generatedValue.getGenerator()); - } - } - } - - private Button buildSequenceGeneratorCheckBox(Composite parent) { - Button button = getWidgetFactory().createButton(parent,JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, SWT.CHECK); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - - public void widgetSelected(SelectionEvent e) { - IdComposite.this.sequenceGeneratorCheckBoxClicked(e); - } - }); - return button; - } - - void sequenceGeneratorCheckBoxClicked(SelectionEvent e) { - boolean mappingHasSequenceGenerator = this.id.getSequenceGenerator() != null; - boolean checked = this.sequenceGeneratorCheckBox.getSelection(); - if (checked == mappingHasSequenceGenerator) { - return; - } - ISequenceGenerator sequenceGenerator = null; - if (checked) { - sequenceGenerator = this.id.createSequenceGenerator(); - } - this.id.setSequenceGenerator(sequenceGenerator); - if (checked) { - IGeneratedValue generatedValue = this.id.getGeneratedValue(); - if (generatedValue != null && generatedValue.getGenerator() != null) { - sequenceGenerator.setName(generatedValue.getGenerator()); - } - } - } - - - - public void doPopulate(EObject obj) { - this.id = (IId) obj; - if (this.id != null) { - this.columnComposite.populate(this.id.getColumn()); - } - else { - this.columnComposite.populate(null); - this.generatedValueComposite.populate(null); - this.tableGeneratorComposite.populate(null); - this.sequenceGeneratorComposite.populate(null); - return; - } - this.pkGenerationSection.setExpanded(true); - this.temporalTypeViewer.populate(new TemporalTypeHolder(this.id)); - populateGeneratedValueComposite(); - populateSequenceGeneratorComposite(); - populateTableGeneratorComposite(); - } - - public void doPopulate() { - this.columnComposite.populate(); - this.temporalTypeViewer.populate(); - this.generatedValueComposite.populate(); - this.tableGeneratorComposite.populate(); - this.sequenceGeneratorComposite.populate(); - } - - private void populateTableGeneratorComposite() { - this.tableGeneratorComposite.populate(this.id); - boolean tableGeneratorExists = this.id.getTableGenerator() != null; - this.tableGeneratorCheckBox.setSelection(tableGeneratorExists); - if (tableGeneratorExists) { - this.tableGenSection.setExpanded(true); - } - } - - private void populateSequenceGeneratorComposite() { - this.sequenceGeneratorComposite.populate(this.id); - boolean sequenceGeneratorExists = this.id.getSequenceGenerator() != null; - this.sequenceGeneratorCheckBox.setSelection(sequenceGeneratorExists); - if (sequenceGeneratorExists) { - this.sequenceGenSection.setExpanded(true); - } - } - - private void populateGeneratedValueComposite() { - this.generatedValueComposite.populate(this.id); - this.primaryKeyGenerationCheckBox.setSelection(this.id.getGeneratedValue() != null); - } - - - protected void engageListeners() { - if (this.id !=null) { - this.id.eAdapters().add(this.idListener); - } - } - - protected void disengageListeners() { - if (this.id !=null) { - this.id.eAdapters().remove(this.idListener); - } - } - - @Override - public void dispose() { - this.columnComposite.dispose(); - this.temporalTypeViewer.dispose(); - this.generatedValueComposite.dispose(); - this.tableGeneratorComposite.dispose(); - this.sequenceGeneratorComposite.dispose(); - super.dispose(); - } - - protected IId getId() { - return this.id; - } - - private class TemporalTypeHolder extends EObjectImpl implements EnumHolder { - - private IId id; - - TemporalTypeHolder(IId id) { - super(); - this.id = id; - } - - public Object get() { - return this.id.getTemporal(); - } - - public void set(Object enumSetting) { - this.id.setTemporal((TemporalType) enumSetting); - } - - public Class featureClass() { - return IId.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IID__TEMPORAL; - } - - public EObject wrappedObject() { - return this.id; - } - - public Object[] enumValues() { - return TemporalType.VALUES.toArray(); - } - - /** - * TemporalType has no Default, return null - */ - public Object defaultValue() { - return null; - } - - /** - * TemporalType has no Default, return null - */ - public String defaultString() { - return null; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdMappingComposite.java new file mode 100644 index 0000000000..a6a3fae5af --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdMappingComposite.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IColumn; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | ColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | TemporalTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | GenerationComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IIdMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see ColumnComposite + * @see TemporalTypeComposite + * @see GenerationComposite + * + * @version 2.0 + * @since 1.0 + */ +public class IdMappingComposite extends AbstractFormPane<IIdMapping> + implements IJpaComposite<IIdMapping> +{ + /** + * Creates a new <code>IdMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IIdMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public IdMappingComposite(PropertyValueModel<? extends IIdMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<? extends IColumn> buildColumnHolder() { + return new TransformationPropertyValueModel<IIdMapping, IColumn>(getSubjectHolder()) { + @Override + protected IColumn transform_(IIdMapping value) { + return value.getColumn(); + } + }; + } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Column widgets + new ColumnComposite(this, buildColumnHolder(), container); + + // Temporal Type widgets + new TemporalTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Generation pane + new GenerationComposite(this, buildSubPane(container, 10)); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java index 77bcdbaf86..9b61d85b1e 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java @@ -1,99 +1,143 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.mappings.DiscriminatorType; -import org.eclipse.jpt.core.internal.mappings.IDiscriminatorColumn; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.INamedColumn; -import org.eclipse.jpt.core.internal.mappings.InheritanceType; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.DiscriminatorType; +import org.eclipse.jpt.core.internal.context.base.IDiscriminatorColumn; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.InheritanceType; import org.eclipse.jpt.db.internal.ConnectionListener; import org.eclipse.jpt.db.internal.ConnectionProfile; import org.eclipse.jpt.db.internal.Database; import org.eclipse.jpt.db.internal.Schema; import org.eclipse.jpt.db.internal.Table; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class InheritanceComposite extends BaseJpaComposite { - - private IEntity entity; - private IDiscriminatorColumn discriminatorColumn; - private final Adapter entityListener; - private final Adapter discriminatorColumnListener; - - private ComboViewer strategyViewer; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ---------------------------------------------------- | + * | Strategy: | EnumComboViewer | | + * | ---------------------------------------------------- | + * | ---------------------------------------------------- | + * | Column: | I |v| | + * | ---------------------------------------------------- | + * | ---------------------------------------------------- | + * | Discriminator Type: | EnumComboViewer |v| | + * | ---------------------------------------------------- | + * | ---------------------------------------------------- | + * | Discriminator Value: | I |v| | + * | ---------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | PrimaryKeyJoinColumnsComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IEntity + * @see EntityComposite - The parent container + * @see EnumComboViewer + * @see PrimaryKeyJoinColumnsComposite + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public class InheritanceComposite extends AbstractFormPane<IEntity> { + private CCombo columnCombo; - private ComboViewer discriminatorTypeViewer; private CCombo discriminatorValueCombo; - - private ConnectionListener connectionListener; - - private ConnectionProfile connectionProfile; - - - private PrimaryKeyJoinColumnsComposite pkJoinColumnsComposite; - - public InheritanceComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.entityListener = buildEntityListener(); - this.discriminatorColumnListener = buildDiscriminatorColumnListener(); - this.connectionListener = buildConnectionListener(); + + /** + * Creates a new <code>InheritanceComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public InheritanceComposite(AbstractFormPane<? extends IEntity> parentPane, + Composite parent) { + + super(parentPane, parent); } - - private Adapter buildEntityListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - entityChanged(notification); - } - }; + + /** + * Creates a new <code>InheritanceComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEntity</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public InheritanceComposite(PropertyValueModel<? extends IEntity> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent,widgetFactory); + } + + private void addConnectionListener() { +// this.getConnectionProfile().addConnectionListener(this.connectionListener); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + + propertyNames.add(IEntity.DEFAULT_DISCRIMINATOR_VALUE_PROPERTY); + propertyNames.add(IEntity.SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY); } - private Adapter buildDiscriminatorColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - discriminatorColumnChanged(notification); + private ModifyListener buildColumnComboSelectionListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + CCombo combo = (CCombo) e.widget; + IDiscriminatorColumn discriminatorColumn = subject().getDiscriminatorColumn(); + String tableText = combo.getText(); + + if (tableText.equals("")) { + tableText = null; + if (discriminatorColumn.getSpecifiedName() == null || discriminatorColumn.getSpecifiedName().equals("")) { + return; + } + } + + if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) { + tableText = null; + } + + if (discriminatorColumn.getSpecifiedName() == null && tableText != null) { + discriminatorColumn.setSpecifiedName(tableText); + } + if (discriminatorColumn.getSpecifiedName() != null && !discriminatorColumn.getSpecifiedName().equals(tableText)) { + discriminatorColumn.setSpecifiedName(tableText); + } } }; } - - private ConnectionListener buildConnectionListener() { + + private ConnectionListener buildConnectionListener() { return new ConnectionListener() { public void aboutToClose(ConnectionProfile profile) { @@ -111,6 +155,10 @@ public class InheritanceComposite extends BaseJpaComposite { }); } + public void databaseChanged(ConnectionProfile profile, final Database database) { + return; + } + public void modified(ConnectionProfile profile) { getControl().getDisplay().asyncExec( new Runnable() { public void run() { @@ -138,10 +186,6 @@ public class InheritanceComposite extends BaseJpaComposite { }); } - public void databaseChanged(ConnectionProfile profile, final Database database) { - return; - } - public void schemaChanged(ConnectionProfile profile, final Schema schema) { return; } @@ -158,291 +202,222 @@ public class InheritanceComposite extends BaseJpaComposite { }); } }; - } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - GridData gridData; - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.InheritanceComposite_strategy); - - this.strategyViewer = buildStrategyCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.strategyViewer.getCombo().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.strategyViewer.getCombo(), IJpaHelpContextIds.ENTITY_INHERITANCE_STRATEGY); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.DiscriminatorColumnComposite_column); - - this.columnCombo = buildColumnCombo(composite); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.columnCombo.setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.columnCombo, IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.DiscriminatorColumnComposite_discriminatorType); - - this.discriminatorTypeViewer = buildDiscriminatorTypeCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.discriminatorTypeViewer.getCombo().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.discriminatorTypeViewer.getCombo(), IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_TYPE); - - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.InheritanceComposite_discriminatorValue); - - this.discriminatorValueCombo = buildDiscriminatorValueCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.discriminatorValueCombo.setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.discriminatorValueCombo, IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_VALUE); - - this.pkJoinColumnsComposite = new PrimaryKeyJoinColumnsComposite(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalSpan = 2; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessVerticalSpace = true; - this.pkJoinColumnsComposite.getControl().setLayoutData(gridData); - } - - private ComboViewer buildStrategyCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - ComboViewer strategyViewer = new ComboViewer(combo); - strategyViewer.setLabelProvider(buildStrategyLabelProvider()); - strategyViewer.add(InheritanceType.VALUES.toArray()); - strategyViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - InheritanceComposite.this.strategySelectionChanged(event.getSelection()); - } - }); - - return strategyViewer; - } - - private IBaseLabelProvider buildStrategyLabelProvider() { - return new LabelProvider() { + } + + private PropertyValueModel<IDiscriminatorColumn> buildDiscriminatorColumnHolder() { + return new TransformationPropertyValueModel<IEntity, IDiscriminatorColumn>(getSubjectHolder()) { @Override - public String getText(Object element) { - if (element == InheritanceType.DEFAULT) { - //TODO need to move this to the model, don't want hardcoded String - return NLS.bind(JptUiMappingsMessages.InheritanceComposite_default, "Single Table"); - } - return super.getText(element); + protected IDiscriminatorColumn transform_(IEntity value) { + return value.getDiscriminatorColumn(); } }; } - - void strategySelectionChanged(ISelection selection) { - if (selection instanceof IStructuredSelection) { - InheritanceType inheritanceType = (InheritanceType) ((IStructuredSelection) selection).getFirstElement(); - if ( ! this.entity.getInheritanceStrategy().equals(inheritanceType)) { - this.entity.setInheritanceStrategy(inheritanceType); + + private EnumComboViewer<IDiscriminatorColumn, DiscriminatorType> buildDiscriminatorTypeCombo(Composite container) { + + return new EnumComboViewer<IDiscriminatorColumn, DiscriminatorType>( + this, + buildDiscriminatorColumnHolder(), + container) + { + @Override + protected DiscriminatorType[] choices() { + return DiscriminatorType.values(); } - } - } - - private CCombo buildColumnCombo(Composite parent) { - final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); - combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String tableText = ((CCombo) e.getSource()).getText(); - if (tableText.equals("")) { //$NON-NLS-1$ - tableText = null; - if (discriminatorColumn.getSpecifiedName() == null || discriminatorColumn.getSpecifiedName().equals("")) { //$NON-NLS-1$ - return; - } - } - - if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) { - tableText = null; - } - if (discriminatorColumn.getSpecifiedName() == null && tableText != null) { - discriminatorColumn.setSpecifiedName(tableText); - } - if (discriminatorColumn.getSpecifiedName() != null && !discriminatorColumn.getSpecifiedName().equals(tableText)) { - discriminatorColumn.setSpecifiedName(tableText); - } + @Override + protected DiscriminatorType defaultValue() { + return subject().getDefaultDiscriminatorType(); } - }); - return combo; - - } - - private ComboViewer buildDiscriminatorTypeCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - ComboViewer discriminatorTypeViewer = new ComboViewer(combo); - discriminatorTypeViewer.setLabelProvider(buildDiscriminatorTypeLabelProvider()); - discriminatorTypeViewer.add(DiscriminatorType.VALUES.toArray()); - - discriminatorTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - InheritanceComposite.this.discriminatorTypeSelectionChanged(event.getSelection()); + + @Override + protected String displayString(DiscriminatorType value) { + return buildDisplayString( + JptUiMappingsMessages.class, + InheritanceComposite.this, + value + ); } - }); - - return discriminatorTypeViewer; - } - - private IBaseLabelProvider buildDiscriminatorTypeLabelProvider() { - return new LabelProvider() { + @Override - public String getText(Object element) { - if (element == DiscriminatorType.DEFAULT) { - //TODO need to move this to the model, don't want hardcoded String - return NLS.bind(JptUiMappingsMessages.InheritanceComposite_defaultDiscriminatorType, "String"); - } - return super.getText(element); + protected DiscriminatorType getValue() { + return subject().getSpecifiedDiscriminatorType(); } - }; - } - - void discriminatorTypeSelectionChanged(ISelection selection) { - if (selection instanceof IStructuredSelection) { - DiscriminatorType discriminatorType = (DiscriminatorType) ((IStructuredSelection) selection).getFirstElement(); - if ( ! this.discriminatorColumn.getDiscriminatorType().equals(discriminatorType)) { - this.discriminatorColumn.setDiscriminatorType(discriminatorType); + + @Override + protected String propertyName() { + return IDiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY; } - } + + @Override + protected void setValue(DiscriminatorType value) { + subject().setSpecifiedDiscriminatorType(value); + } + }; } - - private CCombo buildDiscriminatorValueCombo(Composite parent) { - final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.addModifyListener(new ModifyListener() { + + private ModifyListener buildDiscriminatorValueComboSelectionListener() { + return new ModifyListener() { public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String discriminatorValue = entity.getSpecifiedDiscriminatorValue(); - String value = ((CCombo) e.getSource()).getText(); - if (value.equals("")) { //$NON-NLS-1$ + CCombo combo = (CCombo) e.widget; + String value = combo.getText(); + String discriminatorValue = subject().getSpecifiedDiscriminatorValue(); + + if (value.equals("")) { value = null; - if (discriminatorValue == null || discriminatorValue.equals("")) { //$NON-NLS-1$ + if (discriminatorValue == null || discriminatorValue.equals("")) { return; } } - + if (value != null && combo.getItemCount() > 0 && value.equals(combo.getItem(0))) { value = null; } if (discriminatorValue == null || !discriminatorValue.equals(value)) { - entity.setSpecifiedDiscriminatorValue(value); + subject().setSpecifiedDiscriminatorValue(value); } } - }); - return combo; + }; } - public void doPopulate(EObject obj) { - this.entity = (IEntity) obj; - if (this.entity != null) { - this.discriminatorColumn = this.entity.getDiscriminatorColumn(); - populateColumnCombo(); - popuplateDiscriminatorTypeComboViewer(); - populateStrategyComboViewer(); - populateDiscriminatorValueCombo(); - this.pkJoinColumnsComposite.populate(this.entity); - } - else { - this.discriminatorColumn = null; - this.connectionProfile = null; - } - } - - public void doPopulate() { - if (this.entity != null) { - populateColumnCombo(); -// popuplateStrategyComboViewer(); -// popuplateDiscriminatorValueCombo(); - } - } + private EnumComboViewer<IEntity, InheritanceType> buildStrategyCombo(Composite container) { - @Override - protected void engageListeners() { - if (this.entity != null) { - this.entity.eAdapters().add(this.entityListener); - this.discriminatorColumn.eAdapters().add(this.discriminatorColumnListener); - this.addConnectionListener(); - } + return new EnumComboViewer<IEntity, InheritanceType>(this, container) { + @Override + protected InheritanceType[] choices() { + return InheritanceType.values(); + } + + @Override + protected InheritanceType defaultValue() { + return subject().getDefaultInheritanceStrategy(); + } + + @Override + protected String displayString(InheritanceType value) { + return buildDisplayString( + JptUiMappingsMessages.class, + InheritanceComposite.this, + value + ); + } + + @Override + protected InheritanceType getValue() { + return subject().getSpecifiedInheritanceStrategy(); + } + + @Override + protected String propertyName() { + return IEntity.SPECIFIED_INHERITANCE_STRATEGY_PROPERTY; + } + + @Override + protected void setValue(InheritanceType value) { + subject().setSpecifiedInheritanceStrategy(value); + } + }; } - + + /* + * (non-Javadoc) + */ @Override - protected void disengageListeners() { - if (this.entity != null) { - this.entity.eAdapters().remove(this.entityListener); - this.removeConnectionListener(); - this.discriminatorColumn.eAdapters().remove(this.discriminatorColumnListener); - } + protected void doPopulate() { + super.doPopulate(); + populateColumnCombo(); + populateDiscriminatorValueCombo(); } - private ConnectionProfile getConnectionProfile() { - if(this.connectionProfile == null) { - this.connectionProfile = this.entity.getJpaProject().connectionProfile(); - } - return this.connectionProfile; + private Table getDbTable() { + return this.subject().primaryDbTable(); } - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); - } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Strategy widgets + EnumComboViewer<IEntity, InheritanceType> strategyViewer = + buildStrategyCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.InheritanceComposite_strategy, + strategyViewer.getControl(), + IJpaHelpContextIds.ENTITY_INHERITANCE_STRATEGY + ); + + // Column widgets + columnCombo = buildCombo(container); + columnCombo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); + columnCombo.addModifyListener(buildColumnComboSelectionListener()); + + buildLabeledComposite( + container, + JptUiMappingsMessages.DiscriminatorColumnComposite_column, + columnCombo, + IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN + ); + + // Discriminator Type widgets + EnumComboViewer<IDiscriminatorColumn, DiscriminatorType> discriminatorTypeViewer = + buildDiscriminatorTypeCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.DiscriminatorColumnComposite_discriminatorType, + discriminatorTypeViewer.getControl(), + IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_TYPE + ); + + // Discrinator Value widgets + discriminatorValueCombo = buildCombo(container); + discriminatorValueCombo.addModifyListener(buildDiscriminatorValueComboSelectionListener()); + + buildLabeledComposite( + container, + JptUiMappingsMessages.InheritanceComposite_discriminatorValue, + discriminatorValueCombo, + IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_VALUE + ); + + // Primary Key Join Columns widgets + new PrimaryKeyJoinColumnsComposite( + this, + container + ); } - private Table getDbTable() { - return this.entity.primaryDbTable(); - } - private void populateColumnCombo() { //TODO don't do instanceof check here - check on Table, or isRoot check on Entity //this.tableCombo.setEnabled(!(this.table instanceof SingleTableInheritanceChildTableImpl)); populateDefaultColumnName(); - if (this.getConnectionProfile().isConnected()) { - this.columnCombo.remove(1, this.columnCombo.getItemCount()-1); - Table table = getDbTable(); - if (table != null) { - for (Iterator i = CollectionTools.sort(CollectionTools.list(table.columnNames())).iterator(); i.hasNext();) { - this.columnCombo.add((String) i.next()); - } - } - } - else { - this.columnCombo.remove(1, this.columnCombo.getItemCount()-1); - } +// if (this.getConnectionProfile().isConnected()) { +// this.columnCombo.remove(1, this.columnCombo.getItemCount()-1); +// Table table = getDbTable(); +// if (table != null) { +// for (Iterator i = CollectionTools.sort(CollectionTools.list(table.columnNames())).iterator(); i.hasNext();) { +// this.columnCombo.add((String) i.next()); +// } +// } +// } +// else { +// this.columnCombo.remove(1, this.columnCombo.getItemCount()-1); +// } + populateColumnName(); } - - protected void populateDefaultColumnName() { - String defaultTableName = discriminatorColumn.getDefaultName(); - int selectionIndex = columnCombo.getSelectionIndex(); - columnCombo.setItem(0, NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName)); - if (selectionIndex == 0) { - //combo text does not update when switching between 2 mappings of the same type - //that both have a default column name. clear the selection and then set it again - columnCombo.clearSelection(); - columnCombo.select(0); - } - } - - protected void populateColumnName() { - String tableName = this.discriminatorColumn.getSpecifiedName(); - String defaultName = this.discriminatorColumn.getDefaultName(); + + private void populateColumnName() { + IDiscriminatorColumn discriminatorColumn = subject().getDiscriminatorColumn(); + String tableName = discriminatorColumn.getSpecifiedName(); + String defaultName = discriminatorColumn.getDefaultName(); + if (tableName != null) { if (!this.columnCombo.getText().equals(tableName)) { this.columnCombo.setText(tableName); @@ -455,57 +430,24 @@ public class InheritanceComposite extends BaseJpaComposite { } } - private void popuplateDiscriminatorTypeComboViewer() { - if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.DEFAULT) { - if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.DEFAULT) { - this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.DEFAULT)); - } - } - else if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.CHAR) { - if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.CHAR) { - this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.CHAR)); - } - } - else if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.INTEGER) { - if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.INTEGER) { - this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.INTEGER)); - } - } - else { - if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.STRING) { - this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.STRING)); - } - } - } - - private void populateStrategyComboViewer() { - if (this.entity.getInheritanceStrategy() == InheritanceType.DEFAULT) { - if (((StructuredSelection) this.strategyViewer.getSelection()).getFirstElement() != InheritanceType.DEFAULT) { - this.strategyViewer.setSelection(new StructuredSelection(InheritanceType.DEFAULT)); - } - } - else if (this.entity.getInheritanceStrategy() == InheritanceType.JOINED) { - if (((StructuredSelection) this.strategyViewer.getSelection()).getFirstElement() != InheritanceType.JOINED) { - this.strategyViewer.setSelection(new StructuredSelection(InheritanceType.JOINED)); - } - } - else if (this.entity.getInheritanceStrategy() == InheritanceType.SINGLE_TABLE) { - if (((StructuredSelection) this.strategyViewer.getSelection()).getFirstElement() != InheritanceType.SINGLE_TABLE) { - this.strategyViewer.setSelection(new StructuredSelection(InheritanceType.SINGLE_TABLE)); - } + private void populateDefaultColumnName() { + IDiscriminatorColumn discriminatorColumn = subject().getDiscriminatorColumn(); + String defaultTableName = discriminatorColumn.getDefaultName(); + int selectionIndex = columnCombo.getSelectionIndex(); + columnCombo.setItem(0, NLS.bind(JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName)); + if (selectionIndex == 0) { + //combo text does not update when switching between 2 mappings of the same type + //that both have a default column name. clear the selection and then set it again + columnCombo.clearSelection(); + columnCombo.select(0); } - else { - if (((StructuredSelection) this.strategyViewer.getSelection()).getFirstElement() != InheritanceType.TABLE_PER_CLASS) { - this.strategyViewer.setSelection(new StructuredSelection(InheritanceType.TABLE_PER_CLASS)); - } - } } private void populateDiscriminatorValueCombo() { - String specifiedValue = this.entity.getSpecifiedDiscriminatorValue(); - String defaultValue = this.entity.getDefaultDiscriminatorValue(); + String specifiedValue = this.subject().getSpecifiedDiscriminatorValue(); + String defaultValue = this.subject().getDefaultDiscriminatorValue(); - if (this.entity.discriminatorValueIsAllowed()) { + if (true) { // TODO this.subject().discriminatorValueIsAllowed()) { this.discriminatorValueCombo.setEnabled(true); if (this.discriminatorValueCombo.getItemCount() == 0) { this.discriminatorValueCombo.add(JptUiMappingsMessages.DiscriminatorColumnComposite_defaultEmpty); @@ -524,97 +466,35 @@ public class InheritanceComposite extends BaseJpaComposite { this.discriminatorValueCombo.removeAll(); } } - + if (specifiedValue != null) { if (!this.discriminatorValueCombo.getText().equals(specifiedValue)) { this.discriminatorValueCombo.setText(specifiedValue); } } else { - //combo text does not update when switching between 2 entities that both have a default discriminator value. + //combo text does not update when switching between 2 entities that both have a default discriminator value. //clear the selection and then set it again this.discriminatorValueCombo.clearSelection(); this.discriminatorValueCombo.select(0); } } - - private void entityChanged(Notification notification) { - if (notification.getFeatureID(IEntity.class) == JpaCoreMappingsPackage.IENTITY__INHERITANCE_STRATEGY) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - InheritanceType inheritanceType = entity.getInheritanceStrategy(); - if (((StructuredSelection) strategyViewer.getSelection()).getFirstElement() != inheritanceType) { - strategyViewer.setSelection(new StructuredSelection(inheritanceType)); - } - } - }); - } - else if (notification.getFeatureID(IEntity.class) == JpaCoreMappingsPackage.IENTITY__SPECIFIED_DISCRIMINATOR_VALUE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - String discriminatorValue = entity.getSpecifiedDiscriminatorValue(); - if (discriminatorValueCombo.getText() == null || !discriminatorValueCombo.getText().equals(discriminatorValue)) { - if (discriminatorValue == null) { - discriminatorValueCombo.select(0); - } - else { - discriminatorValueCombo.setText(discriminatorValue); - } - } - } - }); - } - else if (notification.getFeatureID(IEntity.class) == JpaCoreMappingsPackage.IENTITY__DEFAULT_DISCRIMINATOR_VALUE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateDiscriminatorValueCombo(); - } - }); - } - } - protected void discriminatorColumnChanged(Notification notification) { - if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateColumnName(); - } - }); - } - else if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateDefaultColumnName(); - } - }); - } + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); - else if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__DISCRIMINATOR_TYPE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - DiscriminatorType discriminatorType = discriminatorColumn.getDiscriminatorType(); - if (((StructuredSelection) discriminatorTypeViewer.getSelection()).getFirstElement() != discriminatorType) { - discriminatorTypeViewer.setSelection(new StructuredSelection(discriminatorType)); - } - } - }); + if (propertyName == IEntity.DEFAULT_DISCRIMINATOR_VALUE_PROPERTY || + propertyName == IEntity.SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY) + { + populateDiscriminatorValueCombo(); } } - public void dispose() { - this.pkJoinColumnsComposite.dispose(); - super.dispose(); + private void removeConnectionListener() { +// this.getConnectionProfile().removeConnectionListener(this.connectionListener); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialog.java index 4d45d3732b..8c7ad7696d 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialog.java @@ -1,81 +1,71 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IJoinTable; -import org.eclipse.jpt.core.internal.mappings.IMultiRelationshipMapping; -import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IJoinTable; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; +/** + * TODO + * + * @see JoinColumnInJoinTableStateObject + * @see InverseJoinColumnDialogPane + * + * @version 2.0 + * @since 2.0 + */ public class InverseJoinColumnDialog extends JoinColumnInJoinTableDialog { - InverseJoinColumnDialog(Shell parent, IJoinTable joinTable) { - super(parent, joinTable); - } + /** + * Creates a new <code>InverseJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public InverseJoinColumnDialog(Shell parent, IJoinColumn joinColumn) { - InverseJoinColumnDialog(Shell parent, IJoinColumn joinColumn) { super(parent, joinColumn); } - - protected String getTitle() { - return JptUiMappingsMessages.InverseJoinColumnDialog_editInverseJoinColumn; + + /** + * Creates a new <code>InverseJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinTable + */ + public InverseJoinColumnDialog(Shell parent, IJoinTable joinTable) { + + super(parent, joinTable); } - - protected void populateNameCombo() { - if (getJoinTable() == null) { - return; - } - if (getJoinColumn() != null) { - getNameCombo().add(NLS.bind(JptUiMappingsMessages.InverseJoinColumnDialog_defaultWithOneParam, getJoinColumn().getDefaultName())); - } - Table joinDBTable = getJoinTable().dbTable(); - if (joinDBTable != null) { - for (Iterator i = joinDBTable.columnNames(); i.hasNext(); ) { - getNameCombo().add((String) i.next()); - } - } - if (getJoinColumn() != null && getJoinColumn().getSpecifiedName() != null) { - getNameCombo().setText(getJoinColumn().getSpecifiedName()); - } - else { - getNameCombo().select(0); - } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeMainPane(Composite container) { + new InverseJoinColumnDialogPane(getSubjectHolder(), container); } - protected void populateReferencedNameCombo() { - if (getJoinTable() == null) { - return; - } + /* + * (non-Javadoc) + */ + @Override + protected String title() { + if (getJoinColumn() != null) { - getReferencedColumnNameCombo().add(NLS.bind(JptUiMappingsMessages.InverseJoinColumnDialog_defaultWithOneParam, getJoinColumn().getDefaultReferencedColumnName())); - } - IMultiRelationshipMapping multiRelationshipMapping = (IMultiRelationshipMapping) getJoinTable().eContainer(); - IEntity targetEntity = multiRelationshipMapping.getResolvedTargetEntity(); - if (targetEntity != null) { - Table referencedDbTable = targetEntity.primaryDbTable(); - if (referencedDbTable != null) { - for (Iterator i = referencedDbTable.columnNames(); i.hasNext(); ) { - getReferencedColumnNameCombo().add((String) i.next()); - } - } - } - if (getJoinColumn() != null && getJoinColumn().getSpecifiedReferencedColumnName() != null) { - getReferencedColumnNameCombo().setText(getJoinColumn().getSpecifiedReferencedColumnName()); - } - else { - getReferencedColumnNameCombo().select(0); + return JptUiMappingsMessages.InverseJoinColumnDialog_editInverseJoinColumn; } + + return super.title(); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialogPane.java new file mode 100644 index 0000000000..7cd7dbf523 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnDialogPane.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Iterator; +import org.eclipse.jpt.core.internal.context.base.IAbstractJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IMultiRelationshipMapping; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Composite; + +/** + * See <code>AbstractJoinColumnDialogPane</code> for the layout. + * + * @see JoinColumnInJoinTableStateObject + * + * @version 2.0 + * @since 2.0 + */ +public class InverseJoinColumnDialogPane extends AbstractJoinColumnDialogPane<JoinColumnInJoinTableStateObject> +{ + /** + * Creates a new <code>InverseJoinColumnDialogPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public InverseJoinColumnDialogPane(PropertyValueModel<JoinColumnInJoinTableStateObject> subjectHolder, + Composite parent) + { + super(subjectHolder, parent); + } + + /* + * (non-Javadoc) + */ + @Override + public void populateNameCombo() { + + JoinColumnInJoinTableStateObject subject = subject(); + IAbstractJoinColumn joinColumn = subject.getJoinColumn(); + + if (subject.getJoinTable() == null) { + return; + } + + if (joinColumn != null) { + getNameCombo().add(NLS.bind(JptUiMappingsMessages.InverseJoinColumnDialog_defaultWithOneParam, joinColumn.getDefaultName())); + } + + Table joinDBTable = subject.getJoinTable().dbTable(); + + if (joinDBTable != null) { + for (Iterator<String> iter = joinDBTable.columnNames(); iter.hasNext(); ) { + getNameCombo().add(iter.next()); + } + } + + if (joinColumn != null && + joinColumn.getSpecifiedName() != null) + { + getNameCombo().setText(joinColumn.getSpecifiedName()); + } + else { + getNameCombo().select(0); + } + } + + /* + * (non-Javadoc) + */ + @Override + public void populateReferencedNameCombo() { + + JoinColumnInJoinTableStateObject subject = subject(); + IAbstractJoinColumn joinColumn = subject.getJoinColumn(); + + if (subject.getJoinTable() == null) { + return; + } + + if (joinColumn != null) { + getReferencedColumnNameCombo().add(NLS.bind(JptUiMappingsMessages.InverseJoinColumnDialog_defaultWithOneParam, joinColumn.getDefaultReferencedColumnName())); + } + + IMultiRelationshipMapping multiRelationshipMapping = subject.relationshipMapping(); + IEntity targetEntity = multiRelationshipMapping.getResolvedTargetEntity(); + + if (targetEntity != null) { + Table referencedDbTable = targetEntity.primaryDbTable(); + + if (referencedDbTable != null) { + for (Iterator<String> iter = referencedDbTable.columnNames(); iter.hasNext(); ) { + getReferencedColumnNameCombo().add(iter.next()); + } + } + } + + if (joinColumn != null && + joinColumn.getSpecifiedReferencedColumnName() != null) + { + getReferencedColumnNameCombo().setText(joinColumn.getSpecifiedReferencedColumnName()); + } + else { + getReferencedColumnNameCombo().select(0); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java index 98b52e4fc1..82d06c2652 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java @@ -1,428 +1,401 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 Oracle. All rights reserved. + * Copyright (c) 2005, 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.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; +import java.util.ListIterator; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.mappings.DefaultTrueBoolean; -import org.eclipse.jpt.core.internal.mappings.IAbstractColumn; -import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.INamedColumn; -import org.eclipse.jpt.core.internal.mappings.ISingleRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISingleRelationshipMapping; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; 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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class JoinColumnComposite - extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | x Override Default | + * | | + * | ------------------------------------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see ISingleRelationshipMapping + * @see IJoinColumn + * @see ManyToOneMappingComposite - A container of this pane + * @see OneToOneMappingComposite - A container of this pane + * @see JoinColumnInRelationshipMappingDialog + * + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMapping> { - private ISingleRelationshipMapping singleRelationshipMapping; - private final Adapter singleRelationshipMappingListener; - private final Adapter joinColumnListener; - - - private Group joinColumnsGroup; - Button overrideDefaultJoinColumnsCheckBox; - ListViewer joinColumnsListViewer; - private Button joinColumnsRemoveButton; - private Button joinColumnsEditButton; - - - - public JoinColumnComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.singleRelationshipMappingListener = buildSingleRelationshipMappingListener(); - this.joinColumnListener = buildJoinColumnListener(); + private Button overrideDefaultJoinColumnsCheckBox; + + /** + * Creates a new <code>JoinColumnComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + protected JoinColumnComposite(AbstractFormPane<? extends ISingleRelationshipMapping> parentPane, + Composite parent) { + + super(parentPane, parent); } - - private Adapter buildSingleRelationshipMappingListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - singleRelationshipMappingChanged(notification); - } - }; + /** + * Creates a new <code>JoinColumnComposite</code>. + * + * @param subjectHolder The holder of the subject <code>ISingleRelationshipMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JoinColumnComposite(PropertyValueModel<? extends ISingleRelationshipMapping> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private void addJoinColumn() { + + JoinColumnInRelationshipMappingDialog dialog = + new JoinColumnInRelationshipMappingDialog(shell(), subject()); + + dialog.openDialog(buildAddJoinColumnPostExecution()); } - - private Adapter buildJoinColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - joinColumnChanged(notification); + + private void addJoinColumn(JoinColumnInRelationshipMappingStateObject stateObject) { + + int index = subject().specifiedJoinColumnsSize(); + + IJoinColumn joinColumn = subject().addSpecifiedJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); + + if (!stateObject.isDefaultTableSelected()) { + // Not checking this for name and referenced column name because + // there is no default option when you are adding a second join + // column. There is always at least 1 join column (the default) + joinColumn.setSpecifiedTable(stateObject.getSelectedTable()); + } + } + + private PostExecution<JoinColumnInRelationshipMappingDialog> buildAddJoinColumnPostExecution() { + return new PostExecution<JoinColumnInRelationshipMappingDialog>() { + public void execute(JoinColumnInRelationshipMappingDialog dialog) { + if (dialog.wasConfirmed()) { + JoinColumnInRelationshipMappingStateObject stateObject = dialog.subject(); + addJoinColumn(stateObject); + } } }; } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - this.overrideDefaultJoinColumnsCheckBox = - getWidgetFactory().createButton( - composite, - JptUiMappingsMessages.JoinColumnComposite_overrideDefaultJoinColumns, - SWT.CHECK); - this.overrideDefaultJoinColumnsCheckBox.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - if (JoinColumnComposite.this.overrideDefaultJoinColumnsCheckBox.getSelection()) { - IJoinColumn defaultJoinColumn = JoinColumnComposite.this.singleRelationshipMapping.getDefaultJoinColumns().get(0); - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IJoinColumn joinColumn = JoinColumnComposite.this.singleRelationshipMapping.createJoinColumn(0); - JoinColumnComposite.this.singleRelationshipMapping.getSpecifiedJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } else { - JoinColumnComposite.this.singleRelationshipMapping.getSpecifiedJoinColumns().clear(); + + private String buildDefaultJoinColumnLabel(IJoinColumn joinColumn) { + return NLS.bind( + JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + private PostExecution<JoinColumnInRelationshipMappingDialog> buildEditJoinColumnPostExecution() { + return new PostExecution<JoinColumnInRelationshipMappingDialog>() { + public void execute(JoinColumnInRelationshipMappingDialog dialog) { + if (dialog.wasConfirmed()) { + updateJoinColumn(dialog.subject()); } } - }); - - this.joinColumnsGroup = - getWidgetFactory().createGroup( - composite, - JptUiMappingsMessages.JoinColumnComposite_joinColumn); - this.joinColumnsGroup.setLayout(new GridLayout(2, false)); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.joinColumnsGroup.setLayoutData(gridData); - - this.joinColumnsListViewer = new ListViewer(this.joinColumnsGroup, SWT.BORDER | SWT.MULTI); - this.joinColumnsListViewer.setContentProvider(buildJoinColumnsListContentProvider()); - this.joinColumnsListViewer.setLabelProvider(buildJoinColumnsListLabelProvider()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.verticalSpan = 3; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.joinColumnsListViewer.getList().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.joinColumnsListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS); - - Button addJoinColumnButton = getWidgetFactory().createButton(this.joinColumnsGroup, JptUiMappingsMessages.JoinColumnComposite_add, SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - addJoinColumnButton.setLayoutData(gridData); - addJoinColumnButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { + }; + } + + private WritablePropertyValueModel<IJoinColumn> buildJoinColumnHolder() { + return new SimplePropertyValueModel<IJoinColumn>(); + } + + private String buildJoinColumnLabel(IJoinColumn joinColumn) { + if (joinColumn.getSpecifiedName() == null) { + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind( + JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsBothDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); } - - public void widgetSelected(SelectionEvent e) { + + return NLS.bind( + JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsFirstDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + else if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind( + JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsSecDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + else { + return NLS.bind( + JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParams, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + } + + private Adapter buildJoinColumnsAdapter() { + return new AddRemovePane.AbstractAdapter() { + + public void addNewItem(ObjectListSelectionModel listSelectionModel) { addJoinColumn(); } - }); - - this.joinColumnsEditButton = getWidgetFactory().createButton(this.joinColumnsGroup, JptUiMappingsMessages.JoinColumnComposite_edit, SWT.NONE); - this.joinColumnsEditButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - - public void widgetSelected(SelectionEvent e) { - editJoinColumn(); - } - }); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.joinColumnsEditButton.setLayoutData(gridData); - - this.joinColumnsRemoveButton = getWidgetFactory().createButton(this.joinColumnsGroup, JptUiMappingsMessages.JoinColumnComposite_remove, SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.BEGINNING; - this.joinColumnsRemoveButton.setLayoutData(gridData); - this.joinColumnsRemoveButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - - public void widgetSelected(SelectionEvent e) { - removeJoinColumn(); + + @Override + public boolean hasOptionalButton() { + return true; } - }); - - this.joinColumnsListViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateEnablement(); + + @Override + public String optionalButtonText() { + return JptUiMappingsMessages.JoinColumnComposite_edit; } - }); - } - private IContentProvider buildJoinColumnsListContentProvider() { - return new IStructuredContentProvider(){ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + editJoinColumn(listSelectionModel); } - public void dispose() { - // do nothing + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + removeJoinColumn(listSelectionModel); } - public Object[] getElements(Object inputElement) { - return ((ISingleRelationshipMapping) inputElement).getJoinColumns().toArray(); + }; + } + + private ListValueModel<IJoinColumn> buildJoinColumnsListHolder() { + return new ListAspectAdapter<ISingleRelationshipMapping, IJoinColumn>( + getSubjectHolder(), + ISingleRelationshipMapping.DEFAULT_JOIN_COLUMNS_LIST, + ISingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST) + { + @Override + protected ListIterator<IJoinColumn> listIterator_() { + return subject.joinColumns(); } }; } - + private ILabelProvider buildJoinColumnsListLabelProvider() { return new LabelProvider() { + @Override public String getText(Object element) { IJoinColumn joinColumn = (IJoinColumn) element; - return (JoinColumnComposite.this.singleRelationshipMapping.getSpecifiedJoinColumns().size() == 0) ? - buildDefaultJoinColumnLabel(joinColumn) - : + + return (subject().specifiedJoinColumnsSize() == 0) ? + buildDefaultJoinColumnLabel(joinColumn) : buildJoinColumnLabel(joinColumn); } }; } - - String buildDefaultJoinColumnLabel(IJoinColumn joinColumn) { - return NLS.bind(JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - - String buildJoinColumnLabel(IJoinColumn joinColumn) { - if (joinColumn.getSpecifiedName() == null) { - if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName()); - } - return NLS.bind(JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsFirstDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else { - return NLS.bind(JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - } - - protected void joinColumnChanged(Notification notification) { - if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME - || notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME - || notification.getFeatureID(IAbstractColumn.class) == JpaCoreMappingsPackage.IABSTRACT_COLUMN__SPECIFIED_TABLE - || notification.getFeatureID(IAbstractColumn.class) == JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__SPECIFIED_REFERENCED_COLUMN_NAME - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__DEFAULT_REFERENCED_COLUMN_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; + + private SelectionAdapter buildOverrideDefaultJoinColumnsSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + + if (isPopulating()) { + return; + } + + if (overrideDefaultJoinColumnsCheckBox.getSelection()) { + IJoinColumn defaultJoinColumn = subject().defaultJoinColumns().next(); + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IJoinColumn joinColumn = subject().addSpecifiedJoinColumn(0); + joinColumn.setSpecifiedName(columnName); + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + else { + for (int index = subject().specifiedJoinColumnsSize(); --index >= 0; ) { + subject().removeSpecifiedJoinColumn(index); } - joinColumnsListViewer.refresh(); } - }); - } + } + }; } - void addJoinColumn() { - JoinColumnDialog dialog = new JoinColumnInRelationshipMappingDialog(this.getControl().getShell(), this.singleRelationshipMapping); - this.addJoinColumnFromDialog(dialog); + private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinsColumnHolder() { + // TODO + return new SimplePropertyValueModel<Boolean>(); } - - private void addJoinColumnFromDialog(JoinColumnDialog dialog) { - if (dialog.open() != Window.OK) { - return; - } - int index = this.singleRelationshipMapping.getJoinColumns().size(); - IJoinColumn joinColumn = this.singleRelationshipMapping.createJoinColumn(index); - this.singleRelationshipMapping.getSpecifiedJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(dialog.getSelectedName()); - joinColumn.setSpecifiedReferencedColumnName(dialog.getReferencedColumnName()); - if (!dialog.isDefaultTableSelected()) { - //not checking this for name and referenced column name because there is no - //default option when you are adding a second join column. There is always - //at least 1 join column (the default) - joinColumn.setSpecifiedTable(dialog.getSelectedTable()); - } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + private ListValueModel<IJoinColumn> buildSortedJoinColumnsListHolder() { + return new SortedListValueModelAdapter<IJoinColumn>( + buildJoinColumnsListHolder() + ); + } + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + overrideDefaultJoinColumnsCheckBox.setSelection(subject() != null && subject().containsSpecifiedJoinColumns()); } - - void editJoinColumn() { - IJoinColumn joinColumn = getSelectedJoinColumn(); - JoinColumnDialog dialog = new JoinColumnInRelationshipMappingDialog(this.getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); + + private void editJoinColumn(ObjectListSelectionModel listSelectionModel) { + + IJoinColumn joinColumn = (IJoinColumn) listSelectionModel.selectedValue(); + + JoinColumnInRelationshipMappingDialog dialog = + new JoinColumnInRelationshipMappingDialog(shell(), joinColumn); + + dialog.openDialog(buildEditJoinColumnPostExecution()); } - - private IJoinColumn getSelectedJoinColumn() { - return (IJoinColumn) ((StructuredSelection) this.joinColumnsListViewer.getSelection()).getFirstElement(); + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Override Default Join Columns check box + overrideDefaultJoinColumnsCheckBox = buildCheckBox( + buildPane(container, groupBoxMargin), + JptUiMappingsMessages.JoinColumnComposite_overrideDefaultJoinColumns, + buildOverrideDefaultJoinsColumnHolder() + ); + + overrideDefaultJoinColumnsCheckBox.addSelectionListener( + buildOverrideDefaultJoinColumnsSelectionListener() + ); + + // Join Columns group + Group joinColumnsGroup = buildTitledPane( + container, + JptUiMappingsMessages.JoinColumnComposite_joinColumn + ); + + // Join Columns list pane + new AddRemoveListPane<ISingleRelationshipMapping>( + this, + joinColumnsGroup, + buildJoinColumnsAdapter(), + buildSortedJoinColumnsListHolder(), + buildJoinColumnHolder(), + buildJoinColumnsListLabelProvider(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS + ); } - private void editJoinColumnFromDialog(JoinColumnDialog dialog, IJoinColumn joinColumn) { - if (dialog.open() == Window.OK) { - editJoinColumnDialogOkd(dialog, joinColumn); + private void removeJoinColumn(ObjectListSelectionModel listSelectionModel) { + + int[] selectedIndices = listSelectionModel.selectedIndices(); + + for (int index = selectedIndices.length; --index >= 0; ) { + subject().removeSpecifiedJoinColumn(selectedIndices[index]); } } - - private void editJoinColumnDialogOkd(JoinColumnDialog dialog, IJoinColumn joinColumn) { - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - String table = dialog.getSelectedTable(); - if (dialog.isDefaultNameSelected()) { + private void updateJoinColumn(JoinColumnInRelationshipMappingStateObject stateObject) { + + IJoinColumn joinColumn = stateObject.getJoinColumn(); + String name = stateObject.getSelectedName(); + String referencedColumnName = stateObject.getSpecifiedReferencedColumnName(); + String table = stateObject.getSelectedTable(); + + // Name + if (stateObject.isDefaultNameSelected()) { + if (joinColumn.getSpecifiedName() != null) { joinColumn.setSpecifiedName(null); } } - else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){ + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + joinColumn.setSpecifiedName(name); } - if (dialog.isDefaultReferencedColumnNameSelected()) { + + // Referenced Column Name + if (stateObject.isDefaultReferencedColumnNameSelected()) { + if (joinColumn.getSpecifiedReferencedColumnName() != null) { joinColumn.setSpecifiedReferencedColumnName(null); } } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + else if (joinColumn.getSpecifiedReferencedColumnName() == null || + !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } - - if (dialog.isDefaultTableSelected()) { + + // Specified Table + if (stateObject.isDefaultTableSelected()) { + if (joinColumn.getSpecifiedTable() != null) { joinColumn.setSpecifiedTable(null); } } - else if (joinColumn.getSpecifiedTable() == null || !joinColumn.getSpecifiedTable().equals(table)){ + else if (joinColumn.getSpecifiedTable() == null || + !joinColumn.getSpecifiedTable().equals(table)){ + joinColumn.setSpecifiedTable(table); } - DefaultTrueBoolean insertable = dialog.getInsertable(); + // Insertable + Boolean insertable = stateObject.getInsertable(); + if (joinColumn.getInsertable() != insertable) { - joinColumn.setInsertable(insertable); + joinColumn.setSpecifiedInsertable(insertable); } - DefaultTrueBoolean updatable = dialog.getUpdatable(); - if (joinColumn.getUpdatable() != updatable) { - joinColumn.setUpdatable(updatable); - } - } - - void removeJoinColumn() { - ISelection selection = this.joinColumnsListViewer.getSelection(); - if (selection instanceof StructuredSelection) { - for (Iterator stream = ((StructuredSelection) selection).iterator(); stream.hasNext(); ) { - this.singleRelationshipMapping.getJoinColumns().remove(stream.next()); - } - } - } - - protected void singleRelationshipMappingChanged(Notification notification) { - if (notification.getFeatureID(ISingleRelationshipMapping.class) == JpaCoreMappingsPackage.ISINGLE_RELATIONSHIP_MAPPING__SPECIFIED_JOIN_COLUMNS) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - JoinColumnComposite.this.joinColumnsListViewer.refresh(); - JoinColumnComposite.this.overrideDefaultJoinColumnsCheckBox.setSelection(singleRelationshipMapping.containsSpecifiedJoinColumns()); - JoinColumnComposite.this.updateEnablement(); - } - }); - if (notification.getEventType() == Notification.ADD) { - ((IJoinColumn) notification.getNewValue()).eAdapters().add(this.joinColumnListener); - } - else if (notification.getEventType() == Notification.REMOVE) { - ((IJoinColumn) notification.getOldValue()).eAdapters().remove(this.joinColumnListener); - } - } - } - - private void enableGroup(Group group, boolean enabled) { - group.setEnabled(enabled); - for (int i = 0; i < group.getChildren().length; i++) { - group.getChildren()[i].setEnabled(enabled); - } - } + // Updatable + Boolean updatable = stateObject.getUpdatable(); - - - protected void engageListeners() { - if (this.singleRelationshipMapping != null) { - this.singleRelationshipMapping.eAdapters().add(this.singleRelationshipMappingListener); - for (Iterator i = this.singleRelationshipMapping.getJoinColumns().iterator(); i.hasNext(); ) { - ((IJoinColumn) i.next()).eAdapters().add(this.joinColumnListener); - } - } - } - - protected void disengageListeners() { - if (this.singleRelationshipMapping != null) { - for (Iterator i = this.singleRelationshipMapping.getJoinColumns().iterator(); i.hasNext(); ) { - ((IJoinColumn) i.next()).eAdapters().remove(this.joinColumnListener); - } - this.singleRelationshipMapping.eAdapters().remove(this.singleRelationshipMappingListener); - } - } - - public void doPopulate(EObject obj) { - this.singleRelationshipMapping = (ISingleRelationshipMapping) obj; - if (this.singleRelationshipMapping == null) { - this.joinColumnsListViewer.setInput(null); - return; + if (joinColumn.getUpdatable() != updatable) { + joinColumn.setSpecifiedUpdatable(updatable); } - - this.joinColumnsListViewer.setInput(this.singleRelationshipMapping); - - - updateEnablement(); - this.overrideDefaultJoinColumnsCheckBox.setSelection(this.singleRelationshipMapping.containsSpecifiedJoinColumns()); - } - - @Override - protected void doPopulate() { - this.joinColumnsListViewer.setInput(this.singleRelationshipMapping); - } - - void updateEnablement() { - boolean groupEnabledState = this.singleRelationshipMapping.containsSpecifiedJoinColumns(); - enableGroup(this.joinColumnsGroup, groupEnabledState); - - this.joinColumnsRemoveButton.setEnabled(groupEnabledState && !((StructuredSelection) this.joinColumnsListViewer.getSelection()).isEmpty()); - this.joinColumnsEditButton.setEnabled(groupEnabledState && ((StructuredSelection) this.joinColumnsListViewer.getSelection()).size() == 1); - } - - public void dispose() { - disengageListeners(); - super.dispose(); } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialog.java index ff716ce124..f78c8e79d6 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialog.java @@ -3,206 +3,59 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.mappings.DefaultTrueBoolean; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Combo; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -public abstract class JoinColumnDialog extends AbstractJoinColumnDialog<IJoinColumn> { - - private Combo tableCombo; - private ComboViewer insertableComboViewer; - private ComboViewer updatableComboViewer; - - private boolean defaultTableSelected; - private String selectedTable; - private DefaultTrueBoolean insertable; - private DefaultTrueBoolean updatable; - - JoinColumnDialog(Shell parent) { +/** + * TODO + * + * @see JoinColumnStateObject + * @see JoinColumnDialogPane + * + * @version 2.0 + * @since 2.0 + */ +public abstract class JoinColumnDialog<T extends JoinColumnStateObject> extends AbstractJoinColumnDialog<T> { + + /** + * Creates a new <code>AbstractJoinColumnDialog</code>. + * + * @param parent The parent shell + */ + public JoinColumnDialog(Shell parent) { super(parent); } - JoinColumnDialog(Shell parent, IJoinColumn joinColumn) { + /** + * Creates a new <code>AbstractJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public JoinColumnDialog(Shell parent, IJoinColumn joinColumn) { super(parent, joinColumn); } - protected Control createDialogArea(Composite parent) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - Composite composite = (Composite) super.createDialogArea(parent); - - Label tableLabel = new Label(composite, SWT.LEFT); - tableLabel.setText(JptUiMappingsMessages.JoinColumnDialog_table); - GridData gridData = new GridData(); - tableLabel.setLayoutData(gridData); - - this.tableCombo = new Combo(composite, SWT.LEFT); - this.tableCombo.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - populateNameCombo(); - } - public void widgetDefaultSelected(SelectionEvent e) { - populateNameCombo(); - } - }); - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.tableCombo.setLayoutData(gridData); - //PlatformUI.getWorkbench().getHelpSystem().setHelp(this.tableCombo, IJpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN); - populateTableCombo(); - - Label insertableLabel = new Label(composite, SWT.LEFT); - insertableLabel.setText(JptUiMappingsMessages.JoinColumnDialog_insertable); - insertableLabel.setLayoutData(new GridData()); - - this.insertableComboViewer = this.buildInsertableComboViewer(composite); - this.insertableComboViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - helpSystem.setHelp(this.insertableComboViewer.getCombo(), IJpaHelpContextIds.MAPPING_COLUMN_INSERTABLE); - - Label updatableLabel = new Label(composite, SWT.LEFT); - updatableLabel.setText(JptUiMappingsMessages.JoinColumnDialog_updatable); - updatableLabel.setLayoutData(new GridData()); - - this.updatableComboViewer = this.buildUpdatableComboViewer(composite); - this.updatableComboViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - helpSystem.setHelp(this.updatableComboViewer.getCombo(), IJpaHelpContextIds.MAPPING_COLUMN_UPDATABLE); - - return composite; - } - - private ComboViewer buildInsertableComboViewer(Composite parent) { - ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY); - viewer.setLabelProvider(buildDefaultTrueLabelProvider()); - viewer.add(DefaultTrueBoolean.VALUES.toArray()); - - DefaultTrueBoolean sel = (this.joinColumn() == null) ? DefaultTrueBoolean.DEFAULT : this.joinColumn().getInsertable(); - viewer.setSelection(new StructuredSelection(sel)); - return viewer; - } - - private IBaseLabelProvider buildDefaultTrueLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - if (element == DefaultTrueBoolean.DEFAULT) { - //TODO need to move this to the model, don't want hardcoded String - return NLS.bind(JptUiMappingsMessages.JoinColumnDialog_defaultTrue, "True"); - } - return super.getText(element); - } - }; - } - - private ComboViewer buildUpdatableComboViewer(Composite parent) { - ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY); - viewer.setLabelProvider(buildDefaultTrueLabelProvider()); - viewer.add(DefaultTrueBoolean.VALUES.toArray()); - DefaultTrueBoolean sel = (this.joinColumn() == null) ? DefaultTrueBoolean.DEFAULT : this.joinColumn().getUpdatable(); - viewer.setSelection(new StructuredSelection(sel)); - return viewer; - } - - protected void populateTableCombo() { - this.tableCombo.add(NLS.bind(JptUiMappingsMessages.JoinColumnDialog_defaultWithOneParam, defaultTableName())); - Schema schema = this.getSchema(); - if (schema != null) { - Iterator<String> tables = schema.tableNames(); - for (Iterator<String> stream = CollectionTools.sort( tables); stream.hasNext(); ) { - this.tableCombo.add(stream.next()); - } - } - if (specifiedTableName() != null) { - this.tableCombo.setText(specifiedTableName()); - } - else { - this.tableCombo.select(0); - } - } - - protected abstract String defaultTableName(); - - protected String specifiedTableName() { - if (getJoinColumn() != null) { - return getJoinColumn().getSpecifiedTable(); - } - return null; - } - - protected String tableName() { - if (this.tableCombo != null) { - if (this.tableCombo.getSelectionIndex() == 0) { - return defaultTableName(); - } - return this.tableCombo.getText(); - } - return (this.specifiedTableName() == null) ? defaultTableName() : this.specifiedTableName(); - } - - protected abstract Schema getSchema(); - - private IJoinColumn joinColumn() { - return this.getJoinColumn(); - } - - protected boolean isDefaultTableSelected() { - return this.defaultTableSelected; - } - - public String getSelectedTable() { - return this.selectedTable; - } - - public DefaultTrueBoolean getInsertable() { - return this.insertable; + /* + * (non-Javadoc) + */ + @Override + public IJoinColumn getJoinColumn() { + return (IJoinColumn) super.getJoinColumn(); } - public DefaultTrueBoolean getUpdatable() { - return this.updatable; + /* + * (non-Javadoc) + */ + @Override + protected void initializeMainPane(Composite container) { + new JoinColumnDialogPane(getSubjectHolder(), container); } - - public boolean close() { - this.defaultTableSelected = this.tableCombo.getSelectionIndex() == 0; - this.selectedTable = this.tableCombo.getText(); - - ISelection selection = this.insertableComboViewer.getSelection(); - if (selection instanceof IStructuredSelection) { - this.insertable = (DefaultTrueBoolean) ((IStructuredSelection) selection).getFirstElement(); - } - - selection = this.updatableComboViewer.getSelection(); - if (selection instanceof IStructuredSelection) { - this.updatable = (DefaultTrueBoolean) ((IStructuredSelection) selection).getFirstElement(); - } - - return super.close(); - } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java new file mode 100644 index 0000000000..b47feacc53 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------ | + * | Table: | TableCombo |v| | + * | ------------------------------------------------------------------ | + * | ------------------------------------------------------------------------- | + * | | | | + * | | EnumComboViewer | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | EnumComboViewer | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see JoinColumnStateObject + * @see EnumComboViewer + * @see JoinColumnDialog - The parent container + * + * @version 2.0 + * @since 1.0 + */ +public class JoinColumnDialogPane extends AbstractJoinColumnDialogPane<JoinColumnStateObject> +{ + private CCombo tableCombo; + + /** + * Creates a new <code>JoinColumnDialogPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public JoinColumnDialogPane(PropertyValueModel<? extends JoinColumnStateObject> subjectHolder, + Composite parent) + { + super(subjectHolder, parent); + } + + private EnumComboViewer<JoinColumnStateObject, Boolean> buildInsertableCombo(Composite container) { + + return new EnumComboViewer<JoinColumnStateObject, Boolean>(this, container) { + + @Override + protected Boolean[] choices() { + return new Boolean[] { Boolean.TRUE, Boolean.FALSE }; + } + + @Override + protected Boolean defaultValue() { + return null; + } + + @Override + protected String displayString(Boolean value) { + return buildDisplayString( + JptUiMappingsMessages.class, + JoinColumnDialogPane.this, + value + ); + } + + @Override + protected Boolean getValue() { + return subject().getInsertable(); + } + + @Override + protected String propertyName() { + return JoinColumnStateObject.INSERTABLE_PROPERTY; + } + + @Override + protected void setValue(Boolean value) { + subject().setInsertable(value); + } + }; + } + + private SelectionListener buildTableComboSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + populateNameCombo(); + } + }; + } + + private EnumComboViewer<JoinColumnStateObject, Boolean> buildUpdatableCombo(Composite container) { + + return new EnumComboViewer<JoinColumnStateObject, Boolean>(this, container) { + + @Override + protected Boolean[] choices() { + return new Boolean[] { Boolean.TRUE, Boolean.FALSE }; + } + + @Override + protected Boolean defaultValue() { + return true; + } + + @Override + protected String displayString(Boolean value) { + return buildDisplayString( + JptUiMappingsMessages.class, + JoinColumnDialogPane.this, + value + ); + } + + @Override + protected Boolean getValue() { + return subject().getUpdatable(); + } + + @Override + protected String propertyName() { + return JoinColumnStateObject.UPDATABLE_PROPERTY; + } + + @Override + protected void setValue(Boolean value) { + subject().setUpdatable(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + super.initializeLayout(container); + + // Join Referenced Column widgets + tableCombo = buildCombo(container); + tableCombo.addSelectionListener(buildTableComboSelectionListener()); + + buildLabeledComposite( + container, + JptUiMappingsMessages.JoinColumnDialog_table, + tableCombo, + IJpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN + ); + + // Insertable widgets + EnumComboViewer<JoinColumnStateObject, Boolean> insertableCombo = + buildInsertableCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.JoinColumnDialog_insertable, + insertableCombo.getControl(), + IJpaHelpContextIds.MAPPING_COLUMN_INSERTABLE + ); + + // Updatable widgets + EnumComboViewer<JoinColumnStateObject, Boolean> updatableCombo = + buildUpdatableCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.JoinColumnDialog_updatable, + updatableCombo.getControl(), + IJpaHelpContextIds.MAPPING_COLUMN_UPDATABLE + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java index c324a95b34..6007374426 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java @@ -1,62 +1,67 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import org.eclipse.jpt.core.internal.IAttributeMapping; -import org.eclipse.jpt.core.internal.mappings.IAssociationOverride; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IRelationshipMapping; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.core.internal.context.base.IAssociationOverride; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; import org.eclipse.swt.widgets.Shell; -public class JoinColumnInAssociationOverrideDialog extends JoinColumnDialog { +/** + * TODO + * + * @see JoinColumnInAssociationOverrideStateObject + * @see JoinColumnDialogPane + * + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnInAssociationOverrideDialog extends JoinColumnDialog<JoinColumnInAssociationOverrideStateObject> { private IAssociationOverride associationOverride; - - JoinColumnInAssociationOverrideDialog(Shell parent, IAssociationOverride associationOverride) { + + /** + * Creates a new <code>JoinColumnInAssociationOverrideDialog</code>. + * + * @param parent The parent shell + * @param associationOverride + */ + public JoinColumnInAssociationOverrideDialog(Shell parent, + IAssociationOverride associationOverride) { + super(parent); this.associationOverride = associationOverride; } - JoinColumnInAssociationOverrideDialog(Shell parent, IJoinColumn joinColumn) { + /** + * Creates a new <code>JoinColumnInAssociationOverrideDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public JoinColumnInAssociationOverrideDialog(Shell parent, + IJoinColumn joinColumn) { + super(parent, joinColumn); - this.associationOverride = (IAssociationOverride) joinColumn.eContainer(); - } - - protected Schema getSchema() { - return this.associationOverride.typeMapping().dbSchema(); - } - - protected String defaultTableName() { - if (getJoinColumn() != null) { - return getJoinColumn().getDefaultTable(); - } - return this.associationOverride.typeMapping().getTableName(); + this.associationOverride = (IAssociationOverride) joinColumn.parent(); } - protected Table getNameTable() { - return this.associationOverride.typeMapping().primaryDbTable(); - } - - protected Table getReferencedNameTable() { - IAttributeMapping attributeMapping = this.associationOverride.getOwner().attributeMapping(this.associationOverride.getName()); - if (attributeMapping == null || !(attributeMapping instanceof IRelationshipMapping)) { - return null; - } - IEntity targetEntity = ((IRelationshipMapping) attributeMapping).getResolvedTargetEntity(); - if (targetEntity != null) { - return targetEntity.primaryDbTable(); + /* + * (non-Javadoc) + */ + @Override + protected JoinColumnInAssociationOverrideStateObject buildStateObject() { + + if (associationOverride != null) { + return new JoinColumnInAssociationOverrideStateObject(associationOverride); } - return null; - } -} + return new JoinColumnInAssociationOverrideStateObject(getJoinColumn()); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideStateObject.java new file mode 100644 index 0000000000..be0b0f153c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideStateObject.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IAssociationOverride; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IRelationshipMapping; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; +import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.db.internal.Table; + +/** + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnInAssociationOverrideStateObject extends JoinColumnStateObject +{ + private IAssociationOverride associationOverride; + + /** + * Creates a new <code>JoinColumnInAssociationOverrideStateObject</code>. + */ + public JoinColumnInAssociationOverrideStateObject(IAssociationOverride associationOverride) { + super(); + this.associationOverride = associationOverride; + } + + /** + * Creates a new <code>JoinColumnInAssociationOverrideStateObject</code>. + * + * @param joinColumn + */ + public JoinColumnInAssociationOverrideStateObject(IJoinColumn joinColumn) { + super(joinColumn); + } + + /* + * (non-Javadoc) + */ + @Override + public String defaultTableName() { + if (getJoinColumn() != null) { + return getJoinColumn().getDefaultTable(); + } + + return typeMapping().getTableName(); + } + + public IAssociationOverride getAssociationOverride() { + return associationOverride; + } + + /* + * (non-Javadoc) + */ + @Override + public Table getNameTable() { + return typeMapping().primaryDbTable(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getReferencedNameTable() { + IAttributeMapping attributeMapping = null;// TODO: this.associationOverride.getOwner().attributeMapping(this.associationOverride.getName()); + + if (attributeMapping == null || + !(attributeMapping instanceof IRelationshipMapping)) + { + return null; + } + + IEntity targetEntity = ((IRelationshipMapping) attributeMapping).getResolvedTargetEntity(); + + if (targetEntity != null) { + return targetEntity.primaryDbTable(); + } + + return null; + } + + /* + * (non-Javadoc) + */ + @Override + public Schema getSchema() { + return typeMapping().dbSchema(); + } + + public ITypeMapping typeMapping() { + return null; //TODO (ITypeMapping) associationOverride.parent(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableDialog.java index 5a8a7479c2..6c15d9c161 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableDialog.java @@ -1,45 +1,87 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IJoinTable; -import org.eclipse.jpt.core.internal.mappings.IMultiRelationshipMapping; -import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IJoinTable; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; -//if there is only 1 joinColumn and the user is editing it, they should be -//able to define defaults. otherwise, we probably shouldn't allow it. -public class JoinColumnInJoinTableDialog extends AbstractJoinColumnDialog<IJoinColumn> { +/** + * TODO + * + * @see JoinColumnInJoinTableStateObject + * @see AbstractJoinColumnDialogPane + * + * TODO: If there is only 1 join column and the user is editing it, they should + * be able to define defaults. otherwise, we probably shouldn't allow it. + * + * @version 2.0 + * @since 1.0 + */ +public class JoinColumnInJoinTableDialog extends AbstractJoinColumnDialog<JoinColumnInJoinTableStateObject> { private IJoinTable joinTable; - - JoinColumnInJoinTableDialog(Shell parent, IJoinTable joinTable) { + + /** + * Creates a new <code>JoinColumnInJoinTableDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public JoinColumnInJoinTableDialog(Shell parent, IJoinColumn joinColumn) { + + super(parent, joinColumn); + } + + /** + * Creates a new <code>JoinColumnInJoinTableDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public JoinColumnInJoinTableDialog(Shell parent, IJoinTable joinTable) { + super(parent); this.joinTable = joinTable; } - JoinColumnInJoinTableDialog(Shell parent, IJoinColumn joinColumn) { - super(parent, joinColumn); - this.joinTable = (IJoinTable) joinColumn.eContainer(); - } - protected IJoinTable getJoinTable() { - return this.joinTable; + /* + * (non-Javadoc) + */ + @Override + protected JoinColumnInJoinTableStateObject buildStateObject() { + + if (joinTable != null) { + return new JoinColumnInJoinTableStateObject(joinTable); + } + + return new JoinColumnInJoinTableStateObject(getJoinColumn()); } - - protected Table getNameTable() { - return getJoinTable().dbTable(); + + /* + * (non-Javadoc) + */ + @Override + public IJoinColumn getJoinColumn() { + return (IJoinColumn) super.getJoinColumn(); } - - protected Table getReferencedNameTable() { - IMultiRelationshipMapping multiRelationshipMapping = (IMultiRelationshipMapping) getJoinTable().eContainer(); - return multiRelationshipMapping.typeMapping().primaryDbTable(); + + /* + * non-Javadoc) + */ + @Override + protected void initializeMainPane(Composite container) { + new AbstractJoinColumnDialogPane<JoinColumnInJoinTableStateObject>( + getSubjectHolder(), + container + ); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableStateObject.java new file mode 100644 index 0000000000..27bf69bf41 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableStateObject.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IJoinTable; +import org.eclipse.jpt.core.internal.context.base.IMultiRelationshipMapping; +import org.eclipse.jpt.db.internal.Table; + +/** + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnInJoinTableStateObject extends AbstractJoinColumnStateObject +{ + private IJoinTable joinTable; + + /** + * Creates a new <code>JoinColumnInJoinTableStateObject</code>. + * + * @param joinColumn + */ + public JoinColumnInJoinTableStateObject(IJoinColumn joinColumn) { + super(joinColumn); + } + + /** + * Creates a new <code>JoinColumnInJoinTableStateObject</code>. + * + * @param joinTable + */ + public JoinColumnInJoinTableStateObject(IJoinTable joinTable) { + super(); + this.joinTable = joinTable; + } + + /* + * (non-Javadoc) + */ + @Override + public IJoinColumn getJoinColumn() { + return (IJoinColumn) super.getJoinColumn(); + } + + public final IJoinTable getJoinTable() { + return joinTable; + } + + /* + * (non-Javadoc) + */ + @Override + public Table getNameTable() { + if (getJoinColumn() == null) { + return null; + } + + return joinTable.dbTable(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getReferencedNameTable() { + return relationshipMapping().typeMapping().primaryDbTable(); + } + + public IMultiRelationshipMapping relationshipMapping() { + return (IMultiRelationshipMapping) joinTable.parent(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingDialog.java index e60a047663..ef4552b48f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingDialog.java @@ -1,56 +1,64 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.ISingleRelationshipMapping; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISingleRelationshipMapping; import org.eclipse.swt.widgets.Shell; -public class JoinColumnInRelationshipMappingDialog extends JoinColumnDialog { +/** + * TODO + * + * @see JoinColumnInRelationshipMappingStateObject + * @see JoinColumnDialogPane + * + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnInRelationshipMappingDialog extends JoinColumnDialog<JoinColumnInRelationshipMappingStateObject> { - private ISingleRelationshipMapping singleRelationshipMapping; - - JoinColumnInRelationshipMappingDialog(Shell parent, ISingleRelationshipMapping singleRelationshipMapping) { - super(parent); - this.singleRelationshipMapping = singleRelationshipMapping; - } + private ISingleRelationshipMapping relationshipMapping; + /** + * Creates a new <code>AbstractJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ JoinColumnInRelationshipMappingDialog(Shell parent, IJoinColumn joinColumn) { super(parent, joinColumn); - this.singleRelationshipMapping = (ISingleRelationshipMapping) joinColumn.eContainer(); - } - - protected String defaultTableName() { - if (getJoinColumn() != null) { - return getJoinColumn().getDefaultTable(); - } - return this.singleRelationshipMapping.typeMapping().getTableName(); - } - - protected Schema getSchema() { - return this.singleRelationshipMapping.typeMapping().dbSchema(); } - - protected Table getNameTable() { - Schema schema = this.getSchema(); - return (schema == null) ? null : schema.tableNamed(tableName()); + + /** + * Creates a new <code>AbstractJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param relationshipMapping + */ + JoinColumnInRelationshipMappingDialog(Shell parent, + ISingleRelationshipMapping relationshipMapping) { + + super(parent); + this.relationshipMapping = relationshipMapping; } - - protected Table getReferencedNameTable() { - IEntity targetEntity = this.singleRelationshipMapping.getResolvedTargetEntity(); - if (targetEntity != null) { - return targetEntity.primaryDbTable(); + + /* + * (non-Javadoc) + */ + @Override + protected JoinColumnInRelationshipMappingStateObject buildStateObject() { + + if (relationshipMapping != null) { + return new JoinColumnInRelationshipMappingStateObject(relationshipMapping); } - return null; + + return new JoinColumnInRelationshipMappingStateObject(getJoinColumn()); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingStateObject.java new file mode 100644 index 0000000000..dc8946e06e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingStateObject.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISingleRelationshipMapping; +import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.db.internal.Table; + +/** + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnInRelationshipMappingStateObject extends JoinColumnStateObject +{ + private ISingleRelationshipMapping relationshipMapping; + + /** + * Creates a new <code>JoinColumnInRelationshipMappingStateObject</code>. + * + * @param joinColumn + */ + public JoinColumnInRelationshipMappingStateObject(IJoinColumn joinColumn) { + super(joinColumn); + this.relationshipMapping = (ISingleRelationshipMapping) joinColumn.parent(); + } + + /** + * Creates a new <code>JoinColumnInRelationshipMappingStateObject</code>. + */ + public JoinColumnInRelationshipMappingStateObject(ISingleRelationshipMapping relationshipMapping) { + super(); + this.relationshipMapping = relationshipMapping; + } + + /* + * (non-Javadoc) + */ + @Override + public String defaultTableName() { + + if (getJoinColumn() != null) { + return getJoinColumn().getDefaultTable(); + } + + return relationshipMapping.typeMapping().getTableName(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getNameTable() { + Schema schema = getSchema(); + return (schema == null) ? null : schema.tableNamed(tableName()); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getReferencedNameTable() { + IEntity targetEntity = relationshipMapping.getResolvedTargetEntity(); + + if (targetEntity != null) { + return targetEntity.primaryDbTable(); + } + + return null; + } + + /** + * Returns + * + * @return + */ + public ISingleRelationshipMapping getRelationshipMapping() { + return relationshipMapping; + } + + /* + * (non-Javadoc) + */ + @Override + public Schema getSchema() { + return relationshipMapping.typeMapping().dbSchema(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java new file mode 100644 index 0000000000..6bc67e139b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.db.internal.Table; + +/** + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public abstract class JoinColumnStateObject extends AbstractJoinColumnStateObject +{ + private boolean defaultTableSelected; + private Boolean insertable; + private String selectedTable; + private Boolean updatable; + + public static final String INSERTABLE_PROPERTY = "insertable"; + public static final String UPDATABLE_PROPERTY = "updatable"; + + /** + * Creates a new <code>JoinColumnStateObject</code>. + */ + public JoinColumnStateObject() { + super(); + } + + /** + * Creates a new <code>JoinColumnStateObject</code>. + * + * @param joinColumn + */ + public JoinColumnStateObject(IJoinColumn joinColumn) { + super(joinColumn); + } + + public abstract String defaultTableName(); + + public Boolean getInsertable() { + return insertable; + } + + /* + * (non-Javadoc) + */ + @Override + public IJoinColumn getJoinColumn() { + return (IJoinColumn) super.getJoinColumn(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getNameTable() { + return null; + } + + /* + * (non-Javadoc) + */ + @Override + public Table getReferencedNameTable() { + return null; + } + + public abstract Schema getSchema(); + + public String getSelectedTable() { + return selectedTable; + } + + public Boolean getUpdatable() { + return updatable; + } + + public boolean isDefaultTableSelected() { + return defaultTableSelected; + } + + public void setInsertable(Boolean insertable) { + Boolean oldInsertable = this.insertable; + this.insertable = insertable; + firePropertyChanged(INSERTABLE_PROPERTY, oldInsertable, insertable); + } + + public void setUpdatable(Boolean updatable) { + Boolean oldUpdatable = this.updatable; + this.updatable = updatable; + firePropertyChanged(UPDATABLE_PROPERTY, oldUpdatable, updatable); + } + + public String specifiedTableName() { + + if (getJoinColumn() != null) { + return getJoinColumn().getSpecifiedTable(); + } + + return null; + } + + public String tableName() { + return (specifiedTableName() == null) ? defaultTableName() : specifiedTableName(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java index 886e200383..c85332a246 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java @@ -1,348 +1,238 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; -import java.util.List; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; +import java.util.ListIterator; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.internal.mappings.IAbstractColumn; -import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.INamedColumn; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.AbstractAdapter; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class JoinColumnsComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see JoinTableComposite - A container of this pane + * @see OverridesComposite - A container of this pane + * + * @version 2.0 + * @since 2.0 + */ +public class JoinColumnsComposite<T extends IJpaNode> extends AbstractFormPane<T> { - - private Owner owner; - private final Adapter joinColumnsOwnerListener; + private IJoinColumnsEditor<T> joinColumnsEditor; - private ListViewer joinColumnsListViewer; - - private final Adapter joinColumnListener; - - private Group joinColumnsGroup; - private Button joinColumnsAddButton; - private Button joinColumnsRemoveButton; - private Button joinColumnsEditButton; - + /** + * Creates a new <code>JoinColumnsComposite</code>. + * + * @param parentPane The parent controller of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JoinColumnsComposite(AbstractFormPane<? extends T> parentPane, + Composite parent, + IJoinColumnsEditor<T> joinColumnsEditor) { - public JoinColumnsComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory, String groupTitle) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.joinColumnsOwnerListener = buildJoinColumnsOwnerListener(); - this.joinColumnListener = buildJoinColumnListener(); - this.joinColumnsGroup.setText(groupTitle); + super(parentPane, parent); + this.joinColumnsEditor = joinColumnsEditor; + initializeLayout2(); } - - private Adapter buildJoinColumnsOwnerListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - joinColumnsOwnerChanged(notification); - } - }; + + /** + * Creates a new <code>JoinColumnsComposite</code>. + * + * @param parentPane The parent controller of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JoinColumnsComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IJoinColumnsEditor<T> joinColumnsEditor) { + + super(parentPane, subjectHolder, parent); + this.joinColumnsEditor = joinColumnsEditor; + initializeLayout2(); } - - private Adapter buildJoinColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - joinColumnChanged(notification, joinColumnsListViewer); - } - }; + + /** + * Creates a new <code>JoinColumnsComposite</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JoinColumnsComposite(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory, + IJoinColumnsEditor<T> joinColumnsEditor) { + + super(subjectHolder, parent, widgetFactory); + this.joinColumnsEditor = joinColumnsEditor; + initializeLayout2(); } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - this.joinColumnsGroup = - getWidgetFactory().createGroup( - composite, - ""); - this.joinColumnsGroup.setLayout(new GridLayout(2, false)); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.joinColumnsGroup.setLayoutData(gridData); - - this.joinColumnsListViewer = new ListViewer(this.joinColumnsGroup, SWT.BORDER | SWT.MULTI); - this.joinColumnsListViewer.setContentProvider(buildJoinColumnsListContentProvider()); - this.joinColumnsListViewer.setLabelProvider(buildJoinColumnsListLabelProvider()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.verticalSpan = 3; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.joinColumnsListViewer.getList().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.joinColumnsListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS); - - this.joinColumnsAddButton = getWidgetFactory().createButton(this.joinColumnsGroup, JptUiMappingsMessages.JoinTableComposite_add, SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.joinColumnsAddButton.setLayoutData(gridData); - this.joinColumnsAddButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - - public void widgetSelected(SelectionEvent e) { - owner.addJoinColumn(); + private String buildDefaultJoinColumnLabel(IJoinColumn joinColumn) { + return NLS.bind( + JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + private WritablePropertyValueModel<IJoinColumn> buildJoinColumnHolder() { + return new SimplePropertyValueModel<IJoinColumn>(); + } + + private String buildJoinColumnLabel(IJoinColumn joinColumn) { + + if (joinColumn.getSpecifiedName() == null) { + + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind( + JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsBothDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); } - }); - - this.joinColumnsEditButton = getWidgetFactory().createButton(this.joinColumnsGroup, JptUiMappingsMessages.JoinTableComposite_edit, SWT.NONE); - this.joinColumnsEditButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { + + return NLS.bind( + JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsFirstDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind( + JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsSecDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + return NLS.bind( + JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParams, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + private Adapter buildJoinColumnsAdapter() { + return new AbstractAdapter() { + + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + joinColumnsEditor.addJoinColumn(subject()); } - - public void widgetSelected(SelectionEvent e) { - editJoinColumn(); + + @Override + public boolean hasOptionalButton() { + return true; } - }); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.joinColumnsEditButton.setLayoutData(gridData); - this.joinColumnsRemoveButton = getWidgetFactory().createButton(this.joinColumnsGroup, JptUiMappingsMessages.JoinTableComposite_remove, SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.BEGINNING; - this.joinColumnsRemoveButton.setLayoutData(gridData); - this.joinColumnsRemoveButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { + @Override + public String optionalButtonText() { + return JptUiMappingsMessages.JoinColumnComposite_edit; } - - public void widgetSelected(SelectionEvent e) { - removeJoinColumn(); + + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + IJoinColumn joinColumn = (IJoinColumn) listSelectionModel.selectedValue(); + joinColumnsEditor.editJoinColumn(subject(), joinColumn); } - }); - - this.joinColumnsListViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateJoinColumnsEnablement(); + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + joinColumnsEditor.removeJoinColumns(subject(), listSelectionModel.selectedIndices()); } - }); + }; } - private IContentProvider buildJoinColumnsListContentProvider() { - return new IStructuredContentProvider(){ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public void dispose() { - - } - - public Object[] getElements(Object inputElement) { - return ((Owner) inputElement).getJoinColumns().toArray(); + private ListValueModel<IJoinColumn> buildJoinColumnsListHolder() { + return new ListAspectAdapter<T, IJoinColumn>(getSubjectHolder(), joinColumnsEditor.propertyNames()) { + @Override + protected ListIterator<IJoinColumn> listIterator_() { + return joinColumnsEditor.joinColumns(subject); } }; } - + private ILabelProvider buildJoinColumnsListLabelProvider() { return new LabelProvider() { + @Override public String getText(Object element) { IJoinColumn joinColumn = (IJoinColumn) element; - return (JoinColumnsComposite.this.owner.containsSpecifiedJoinColumns()) ? - buildJoinColumnLabel(joinColumn) - : + + return joinColumnsEditor.hasSpecifiedJoinColumns(subject()) ? + buildJoinColumnLabel(joinColumn) : buildDefaultJoinColumnLabel(joinColumn); } }; } - - private String buildDefaultJoinColumnLabel(IJoinColumn joinColumn) { - return NLS.bind(JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - - private String buildJoinColumnLabel(IJoinColumn joinColumn) { - if (joinColumn.getSpecifiedName() == null) { - if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName()); - } - return NLS.bind(JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsFirstDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else { - return NLS.bind(JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - } - void editJoinColumn() { - this.owner.editJoinColumn(getSelectedJoinColumn()); - } - - void removeJoinColumn() { - ISelection selection = this.joinColumnsListViewer.getSelection(); - if (selection instanceof StructuredSelection) { - for (Iterator stream = ((StructuredSelection) selection).iterator(); stream.hasNext(); ) { - this.owner.getJoinColumns().remove(stream.next()); - } - } - } - - private IJoinColumn getSelectedJoinColumn() { - return (IJoinColumn) ((StructuredSelection) this.joinColumnsListViewer.getSelection()).getFirstElement(); - } - - protected void joinColumnsOwnerChanged(Notification notification) { - if (notification.getFeatureID(owner.owningFeatureClass()) == owner.specifiedJoinColumnsFeatureId()) { - if (notification.getEventType() == Notification.ADD) { - ((IJoinColumn) notification.getNewValue()).eAdapters().add(this.joinColumnListener); - } - else if (notification.getEventType() == Notification.REMOVE) { - ((IJoinColumn) notification.getOldValue()).eAdapters().remove(this.joinColumnListener); - } - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - joinColumnsListViewer.refresh(); - updateJoinColumnsEnablement(); - } - }); - } - } - - private void enableGroup(Group group, boolean enabled) { - group.setEnabled(enabled); - for (int i = 0; i < group.getChildren().length; i++) { - group.getChildren()[i].setEnabled(enabled); - } - } - protected void joinColumnChanged(Notification notification, final ListViewer listViewer) { - if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME - || notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME - || notification.getFeatureID(IAbstractColumn.class) == JpaCoreMappingsPackage.IABSTRACT_COLUMN__SPECIFIED_TABLE - || notification.getFeatureID(IAbstractColumn.class) == JpaCoreMappingsPackage.IABSTRACT_COLUMN__DEFAULT_TABLE - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__SPECIFIED_REFERENCED_COLUMN_NAME - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__DEFAULT_REFERENCED_COLUMN_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - listViewer.refresh(); - } - }); - } - } - - protected void engageListeners() { - if (this.owner != null) { - this.owner.getEObject().eAdapters().add(this.joinColumnsOwnerListener); - for (IJoinColumn joinColumn : this.owner.getJoinColumns()) { - joinColumn.eAdapters().add(this.joinColumnListener); - } - } - } - - protected void disengageListeners() { - if (this.owner != null) { - for (IJoinColumn joinColumn : this.owner.getJoinColumns()) { - joinColumn.eAdapters().remove(this.joinColumnListener); - } - this.owner.getEObject().eAdapters().remove(this.joinColumnsOwnerListener); - } - } - - public void doPopulate(EObject obj) { - this.owner = (Owner) obj; - if (this.owner == null) { - this.joinColumnsListViewer.setInput(null); - return; - } - - this.joinColumnsListViewer.setInput(this.owner); - - updateEnablement(); + private ListValueModel<IJoinColumn> buildSortedJoinColumnsListHolder() { + return new SortedListValueModelAdapter<IJoinColumn>( + buildJoinColumnsListHolder() + ); } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { + protected void initializeLayout(Composite container) { } - private void updateEnablement() { - updateJoinColumnsEnablement(); - } - - void updateJoinColumnsEnablement() { - boolean groupEnabledState = this.owner.containsSpecifiedJoinColumns(); - enableGroup(this.joinColumnsGroup, groupEnabledState); + private void initializeLayout2() { - this.joinColumnsRemoveButton.setEnabled(groupEnabledState && !((StructuredSelection) this.joinColumnsListViewer.getSelection()).isEmpty()); - this.joinColumnsEditButton.setEnabled(groupEnabledState && ((StructuredSelection) this.joinColumnsListViewer.getSelection()).size() == 1); - } - - protected void enableWidgets(boolean enabled) { - enableGroup(this.joinColumnsGroup, enabled); - this.joinColumnsAddButton.setEnabled(enabled); - this.joinColumnsEditButton.setEnabled(enabled); - this.joinColumnsRemoveButton.setEnabled(enabled); - this.joinColumnsListViewer.getList().setEnabled(enabled); + // Join Columns list pane + new AddRemoveListPane<T>( + this, + getControl(), + buildJoinColumnsAdapter(), + buildSortedJoinColumnsListHolder(), + buildJoinColumnHolder(), + buildJoinColumnsListLabelProvider(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS + ); } - public interface Owner { - int specifiedJoinColumnsFeatureId(); - - Class owningFeatureClass(); + public static interface IJoinColumnsEditor<T> { - EObject getEObject(); - - boolean containsSpecifiedJoinColumns(); - - List<IJoinColumn> getJoinColumns(); - - List<IJoinColumn> getSpecifiedJoinColumns(); - - IJoinColumn createJoinColumn(int index); - - void addJoinColumn(); - - void editJoinColumn(IJoinColumn joinColumn); + void addJoinColumn(T subject); + void editJoinColumn(T subject, IJoinColumn joinColumn); + boolean hasSpecifiedJoinColumns(T subject); + ListIterator<IJoinColumn> joinColumns(T subject); + String[] propertyNames(); + void removeJoinColumns(T subject, int[] selectedIndices); } - }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java index 1f2f436c05..9bbe104cf8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java @@ -3,470 +3,457 @@ * This program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0, which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; -import java.util.List; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.core.internal.JpaEObject; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IJoinTable; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionListener; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.Database; +import java.util.Collection; +import java.util.Iterator; +import java.util.ListIterator; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IJoinTable; import org.eclipse.jpt.db.internal.Schema; import org.eclipse.jpt.db.internal.Table; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.Owner; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; +import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.IJoinColumnsEditor; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +import org.eclipse.swt.widgets.Group; -public class JoinTableComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | --------------------------------------------------------------- | + * | Name: | |v| | + * | --------------------------------------------------------------- | + * | | + * | x Override Default Join Columns | + * | | + * | ------------------------------------------------------------------------- | + * | | | | + * | | JoinColumnsComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | x Override Default Inverse Join Columns | + * | | + * | ------------------------------------------------------------------------- | + * | | | | + * | | JoinColumnsComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IJoinTable + * @see OneToManyMappingComposite - A container of this pane + * @see ManyToManyMappingComposite - A container of this pane + * @see JoinColumnsComposite + * + * @version 2.0 + * @since 1.0 + */ +public class JoinTableComposite extends AbstractFormPane<IJoinTable> { - - private IJoinTable joinTable; - private final Adapter joinTableListener; + private Button overrideDefaultInverseJoinColumnsCheckBox; + private Button overrideDefaultJoinColumnsCheckBox; - protected TableCombo tableCombo; + /** + * Creates a new <code>JoinTableComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public JoinTableComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends IJoinTable> subjectHolder, + Composite parent) { - private ConnectionProfile connectionProfile; - private ConnectionListener connectionListener; - - private Button overrideDefaultJoinColumnsCheckBox; - private JoinColumnsComposite joinColumnsComposite; - - private Button overrideDefaultInverseJoinColumnsCheckBox; - private JoinColumnsComposite inverseJoinColumnsComposite; + super(parentPane, subjectHolder, parent); + } - public JoinTableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.joinTableListener = buildJoinTableListener(); - this.connectionListener = buildConnectionListener(); + /** + * Creates a new <code>JoinTableComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IJoinTable</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public JoinTableComposite(PropertyValueModel<? extends IJoinTable> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - - private Adapter buildJoinTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - joinTableChanged(notification); - } - }; + + private void addInverseJoinColumn(IJoinTable joinTable) { + + InverseJoinColumnDialog dialog = new InverseJoinColumnDialog(shell(), joinTable); + dialog.openDialog(buildAddInverseJoinColumnPostExecution()); } - - private ConnectionListener buildConnectionListener() { - return new ConnectionListener() { - public void aboutToClose(ConnectionProfile profile) { - // not interested to this event. - } + private void addInverseJoinColumnFromDialog(JoinColumnInJoinTableStateObject stateObject) { - public void closed(ConnectionProfile profile) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - JoinTableComposite.this.tableCombo.populate(); - } - }); - } + int index = subject().specifiedInverseJoinColumnsSize(); + IJoinColumn joinColumn = subject().addSpecifiedInverseJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); + } - public void modified(ConnectionProfile profile) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - JoinTableComposite.this.tableCombo.populate(); - } - }); - } + private void addJoinColumn(IJoinTable joinTable) { - public boolean okToClose(ConnectionProfile profile) { - // not interested to this event. - return true; - } + JoinColumnInJoinTableDialog dialog = new JoinColumnInJoinTableDialog(shell(), joinTable); + dialog.openDialog(buildAddJoinColumnPostExecution()); + } - public void opened(ConnectionProfile profile) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - JoinTableComposite.this.tableCombo.populate(); - } - }); + private void addJoinColumnFromDialog(JoinColumnInJoinTableStateObject stateObject) { + + int index = subject().specifiedJoinColumnsSize(); + IJoinColumn joinColumn = subject().addSpecifiedJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); + } + + private PostExecution<InverseJoinColumnDialog> buildAddInverseJoinColumnPostExecution() { + return new PostExecution<InverseJoinColumnDialog>() { + public void execute(InverseJoinColumnDialog dialog) { + if (dialog.wasConfirmed()) { + addInverseJoinColumnFromDialog(dialog.subject()); + } } + }; + } - public void databaseChanged(ConnectionProfile profile, final Database database) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if(database == JoinTableComposite.this.tableCombo.getDatabase()) { - if (!getControl().isDisposed()) { - JoinTableComposite.this.tableCombo.populate(); - } - } - } - }); + private PostExecution<JoinColumnInJoinTableDialog> buildAddJoinColumnPostExecution() { + return new PostExecution<JoinColumnInJoinTableDialog>() { + public void execute(JoinColumnInJoinTableDialog dialog) { + if (dialog.wasConfirmed()) { + addJoinColumnFromDialog(dialog.subject()); + } } - - public void schemaChanged(ConnectionProfile profile, final Schema schema) { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if(schema == JoinTableComposite.this.tableCombo.getTableSchema()) { - if (!getControl().isDisposed()) { - JoinTableComposite.this.tableCombo.populate(); - } - } - } - }); + }; + } + + private PostExecution<JoinColumnInJoinTableDialog> buildEditInverseJoinColumnPostExecution() { + return new PostExecution<JoinColumnInJoinTableDialog>() { + public void execute(JoinColumnInJoinTableDialog dialog) { + if (dialog.wasConfirmed()) { + editJoinColumn(dialog.subject()); + } } + }; + } - public void tableChanged(ConnectionProfile profile, final Table table) { - // not interested to this event. + private PostExecution<JoinColumnInJoinTableDialog> buildEditJoinColumnPostExecution() { + return new PostExecution<JoinColumnInJoinTableDialog>() { + public void execute(JoinColumnInJoinTableDialog dialog) { + if (dialog.wasConfirmed()) { + editJoinColumn(dialog.subject()); + } } }; - } + } - private ConnectionProfile getConnectionProfile() { - if(this.connectionProfile == null) { - IJpaProject jpaProject = this.joinTable.getJpaProject(); - this.connectionProfile = jpaProject.connectionProfile(); - } - return this.connectionProfile; + private InverseJoinColumnsProvider buildInverseJoinColumnsEditor() { + return new InverseJoinColumnsProvider(); } - - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); + + private JoinColumnsProvider buildJoinColumnsEditor() { + return new JoinColumnsProvider(); } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); + + private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { + // TODO + return new SimplePropertyValueModel<Boolean>(); } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.JoinTableComposite_name); - - this.tableCombo = new TableCombo(composite, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.tableCombo.getCombo().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.tableCombo.getCombo(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_NAME); - - this.overrideDefaultJoinColumnsCheckBox = - getWidgetFactory().createButton( - composite, - JptUiMappingsMessages.JoinTableComposite_overrideDefaultJoinColumns, - SWT.CHECK); - this.overrideDefaultJoinColumnsCheckBox.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - + + private SelectionListener buildOverrideDefaultInverseSelectionListener() { + return new SelectionAdapter() { + @Override public void widgetSelected(SelectionEvent e) { - if (JoinTableComposite.this.overrideDefaultJoinColumnsCheckBox.getSelection()) { - IJoinColumn defaultJoinColumn = JoinTableComposite.this.joinTable.getDefaultJoinColumns().get(0); + Button button = (Button) e.widget; + IJoinTable joinTable = subject(); + + if (button.getSelection()) { + IJoinColumn defaultJoinColumn = joinTable.defaultInverseJoinColumns().next(); String columnName = defaultJoinColumn.getDefaultName(); String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - IJoinColumn joinColumn = JoinTableComposite.this.joinTable.createJoinColumn(0); - JoinTableComposite.this.joinTable.getSpecifiedJoinColumns().add(joinColumn); + + IJoinColumn joinColumn = joinTable.addSpecifiedInverseJoinColumn(0); joinColumn.setSpecifiedName(columnName); joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } else { - JoinTableComposite.this.joinTable.getSpecifiedJoinColumns().clear(); + } + else { + for (int index = joinTable.specifiedInverseJoinColumnsSize(); --index >= 0; ) { + joinTable.removeSpecifiedJoinColumn(index); + } } } - }); - - this.joinColumnsComposite = new JoinColumnsComposite(composite, this.commandStack, getWidgetFactory(), JptUiMappingsMessages.JoinTableComposite_joinColumn); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.joinColumnsComposite.getControl().setLayoutData(gridData); - - this.overrideDefaultInverseJoinColumnsCheckBox = getWidgetFactory().createButton(composite, JptUiMappingsMessages.JoinTableComposite_overrideDefaultInverseJoinColumns, SWT.CHECK); - this.overrideDefaultInverseJoinColumnsCheckBox.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - + }; + } + + private SelectionListener buildOverrideDefaultSelectionListener() { + return new SelectionAdapter() { + @Override public void widgetSelected(SelectionEvent e) { - if (JoinTableComposite.this.overrideDefaultInverseJoinColumnsCheckBox.getSelection()) { - IJoinColumn defaultJoinColumn = JoinTableComposite.this.joinTable.getDefaultInverseJoinColumns().get(0); + Button button = (Button) e.widget; + IJoinTable joinTable = subject(); + + if (button.getSelection()) { + IJoinColumn defaultJoinColumn = joinTable.defaultJoinColumns().next(); String columnName = defaultJoinColumn.getDefaultName(); String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - IJoinColumn joinColumn = JoinTableComposite.this.joinTable.createInverseJoinColumn(0); - JoinTableComposite.this.joinTable.getSpecifiedInverseJoinColumns().add(joinColumn); + + IJoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); joinColumn.setSpecifiedName(columnName); joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } else { - JoinTableComposite.this.joinTable.getSpecifiedInverseJoinColumns().clear(); + } + else { + for (int index = joinTable.specifiedJoinColumnsSize(); --index >= 0; ) { + joinTable.removeSpecifiedJoinColumn(index); + } } } - }); - this.inverseJoinColumnsComposite = new JoinColumnsComposite(composite, this.commandStack, getWidgetFactory(), JptUiMappingsMessages.JoinTableComposite_inverseJoinColumn); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.inverseJoinColumnsComposite.getControl().setLayoutData(gridData); - } - - void addJoinColumn() { - JoinColumnInJoinTableDialog dialog = new JoinColumnInJoinTableDialog(this.getControl().getShell(), this.joinTable); - this.addJoinColumnFromDialog(dialog); - } - - private void addJoinColumnFromDialog(JoinColumnInJoinTableDialog dialog) { - if (dialog.open() != Window.OK) { - return; - } - int index = this.joinTable.getJoinColumns().size(); - IJoinColumn joinColumn = this.joinTable.createJoinColumn(index); - this.joinTable.getSpecifiedJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(dialog.getSelectedName()); - joinColumn.setSpecifiedReferencedColumnName(dialog.getReferencedColumnName()); + }; } - - void addInverseJoinColumn() { - InverseJoinColumnDialog dialog = new InverseJoinColumnDialog(this.getControl().getShell(), this.joinTable); - this.addInverseJoinColumnFromDialog(dialog); + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, groupBoxMargin, 0, groupBoxMargin, 0, groupBoxMargin); } - - private void addInverseJoinColumnFromDialog(InverseJoinColumnDialog dialog) { - if (dialog.open() != Window.OK) { - return; - } - int index = this.joinTable.getInverseJoinColumns().size(); - IJoinColumn joinColumn = this.joinTable.createInverseJoinColumn(index); - this.joinTable.getSpecifiedInverseJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(dialog.getSelectedName()); - joinColumn.setSpecifiedReferencedColumnName(dialog.getReferencedColumnName()); + + + private TableCombo<IJoinTable> buildTableCombo(Composite container) { + + return new TableCombo<IJoinTable>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IJoinTable.DEFAULT_NAME_PROPERTY); + propertyNames.add(IJoinTable.SPECIFIED_NAME_PROPERTY); + } + + @Override + protected String defaultValue() { + return subject().getDefaultName(); + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedName(value); + } + + @Override + protected Table table() { + return subject().dbTable(); + } + + private Schema tableSchema() { + return database().schemaNamed(subject().getSchema()); + } + + @Override + protected String value() { + return subject().getSpecifiedName(); + } + + @Override + protected Iterator<String> values() { + Schema schema = tableSchema(); + + if (schema != null) { + return schema.tableNames(); + } + + return EmptyIterator.instance(); + } + }; } - void editJoinColumn(IJoinColumn joinColumn) { - JoinColumnInJoinTableDialog dialog = new JoinColumnInJoinTableDialog(this.getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); + private void editInverseJoinColumn(IJoinColumn joinColumn) { + + InverseJoinColumnDialog dialog = + new InverseJoinColumnDialog(shell(), joinColumn); + + dialog.openDialog(buildEditInverseJoinColumnPostExecution()); } - - private void editJoinColumnFromDialog(JoinColumnInJoinTableDialog dialog, IJoinColumn joinColumn) { - if (dialog.open() == Window.OK) { - editJoinColumnDialogOkd(dialog, joinColumn); - } + + private void editJoinColumn(IJoinColumn joinColumn) { + + JoinColumnInJoinTableDialog dialog = + new JoinColumnInJoinTableDialog(shell(), joinColumn); + + dialog.openDialog(buildEditJoinColumnPostExecution()); } - - private void editJoinColumnDialogOkd(JoinColumnInJoinTableDialog dialog, IJoinColumn joinColumn) { - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - if (dialog.isDefaultNameSelected()) { + private void editJoinColumn(JoinColumnInJoinTableStateObject stateObject) { + + IJoinColumn joinColumn = stateObject.getJoinColumn(); + String name = stateObject.getSelectedName(); + String referencedColumnName = stateObject.getSpecifiedReferencedColumnName(); + + if (stateObject.isDefaultNameSelected()) { if (joinColumn.getSpecifiedName() != null) { joinColumn.setSpecifiedName(null); } } - else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){ + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + joinColumn.setSpecifiedName(name); } - - if (dialog.isDefaultReferencedColumnNameSelected()) { + + if (stateObject.isDefaultReferencedColumnNameSelected()) { if (joinColumn.getSpecifiedReferencedColumnName() != null) { joinColumn.setSpecifiedReferencedColumnName(null); } } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - - - void editInverseJoinColumn(IJoinColumn joinColumn) { - InverseJoinColumnDialog dialog = new InverseJoinColumnDialog(getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); - } - - protected void joinTableChanged(Notification notification) { - if (notification.getFeatureID(IJoinTable.class) == JpaCoreMappingsPackage.IJOIN_TABLE__SPECIFIED_JOIN_COLUMNS) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - overrideDefaultJoinColumnsCheckBox.setSelection(joinTable.containsSpecifiedJoinColumns()); - } - }); - } - else if (notification.getFeatureID(IJoinTable.class) == JpaCoreMappingsPackage.IJOIN_TABLE__SPECIFIED_INVERSE_JOIN_COLUMNS) { + else if (joinColumn.getSpecifiedReferencedColumnName() == null || + !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - overrideDefaultInverseJoinColumnsCheckBox.setSelection(joinTable.containsSpecifiedInverseJoinColumns()); - } - }); - } - } - - protected void engageListeners() { - if (this.joinTable != null) { - this.joinTable.eAdapters().add(this.joinTableListener); - this.addConnectionListener(); - } - } - - protected void disengageListeners() { - if (this.joinTable != null) { - this.joinTable.eAdapters().remove(this.joinTableListener); - this.removeConnectionListener(); - } - } - - public void doPopulate(EObject obj) { - this.joinTable = (IJoinTable) obj; - if (this.joinTable == null) { - this.joinColumnsComposite.populate(null); - this.inverseJoinColumnsComposite.populate(null); - this.connectionProfile = null; - return; + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } - - this.tableCombo.populate(this.joinTable); - this.joinColumnsComposite.populate(new JoinColumnsOwner(this.joinTable)); - this.inverseJoinColumnsComposite.populate(new InverseJoinColumnsOwner(this.joinTable)); - - this.overrideDefaultJoinColumnsCheckBox.setSelection(this.joinTable.containsSpecifiedJoinColumns()); - this.overrideDefaultInverseJoinColumnsCheckBox.setSelection(this.joinTable.containsSpecifiedInverseJoinColumns()); } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { - this.tableCombo.populate(); - this.joinColumnsComposite.populate(); - this.inverseJoinColumnsComposite.populate(); - } - - @Override - public void dispose() { - this.tableCombo.dispose(); - this.joinColumnsComposite.dispose(); - this.inverseJoinColumnsComposite.dispose(); - super.dispose(); + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Name widgets + TableCombo<IJoinTable> tableCombo = buildTableCombo(container); + + buildLabeledComposite( + buildPane(container, groupBoxMargin), + JptUiMappingsMessages.JoinTableComposite_name, + tableCombo.getControl(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_NAME + ); + + // Override Default Join Columns check box + overrideDefaultJoinColumnsCheckBox = buildCheckBox( + buildPane(container, groupBoxMargin), + JptUiMappingsMessages.JoinTableComposite_overrideDefaultJoinColumns, + buildOverrideDefaultHolder() + ); + + overrideDefaultJoinColumnsCheckBox.addSelectionListener( + buildOverrideDefaultSelectionListener() + ); + + // Join Columns widgets + Group joinColumnGroupPane = buildTitledPane( + container, + JptUiMappingsMessages.JoinTableComposite_joinColumn + ); + + new JoinColumnsComposite<IJoinTable>( + this, + joinColumnGroupPane, + buildJoinColumnsEditor() + ); + + // Override Default Inverse Join Columns check box + overrideDefaultInverseJoinColumnsCheckBox = buildCheckBox( + buildPane(container, groupBoxMargin), + JptUiMappingsMessages.JoinTableComposite_overrideDefaultInverseJoinColumns, + buildOverrideDefaultHolder() + ); + + overrideDefaultInverseJoinColumnsCheckBox.addSelectionListener( + buildOverrideDefaultInverseSelectionListener() + ); + + // Inverse Join Columns widgets + Group inverseJoinColumnGroupPane = buildTitledPane( + container, + JptUiMappingsMessages.JoinTableComposite_inverseJoinColumn + ); + + new JoinColumnsComposite<IJoinTable>( + this, + inverseJoinColumnGroupPane, + buildInverseJoinColumnsEditor() + ); } - private class JoinColumnsOwner extends JpaEObject implements Owner { - - private IJoinTable joinTable; - - public JoinColumnsOwner(IJoinTable joinTable) { - super(); - this.joinTable = joinTable; - } - - public void addJoinColumn() { - JoinTableComposite.this.addJoinColumn(); - } - - public boolean containsSpecifiedJoinColumns() { - return this.joinTable.containsSpecifiedJoinColumns(); - } - - public IJoinColumn createJoinColumn(int index) { - return this.joinTable.createJoinColumn(index); - } - - public List<IJoinColumn> getJoinColumns() { - return this.joinTable.getJoinColumns(); + private class InverseJoinColumnsProvider implements IJoinColumnsEditor<IJoinTable> { + + public void addJoinColumn(IJoinTable subject) { + JoinTableComposite.this.addInverseJoinColumn(subject); } - - public List<IJoinColumn> getSpecifiedJoinColumns() { - return this.joinTable.getSpecifiedJoinColumns(); + + public void editJoinColumn(IJoinTable subject, IJoinColumn joinColumn) { + JoinTableComposite.this.editInverseJoinColumn(joinColumn); } - - public int specifiedJoinColumnsFeatureId() { - return JpaCoreMappingsPackage.IJOIN_TABLE__SPECIFIED_JOIN_COLUMNS; + + public boolean hasSpecifiedJoinColumns(IJoinTable subject) { + return subject.containsSpecifiedInverseJoinColumns(); } - - public Class owningFeatureClass() { - return IJoinTable.class; + + public ListIterator<IJoinColumn> joinColumns(IJoinTable subject) { + return subject.inverseJoinColumns(); } - - public void editJoinColumn(IJoinColumn joinColumn) { - JoinTableComposite.this.editJoinColumn(joinColumn); + + public String[] propertyNames() { + return new String[] { + IJoinTable.DEFAULT_INVERSE_JOIN_COLUMNS_LIST, + IJoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST + }; } - - public EObject getEObject() { - return this.joinTable; + + public void removeJoinColumns(IJoinTable subject, int[] selectedIndices) { + for (int index = selectedIndices.length; --index >= 0; ) { + subject.removeSpecifiedInverseJoinColumn(selectedIndices[index]); + } } } - - private class InverseJoinColumnsOwner extends JpaEObject implements Owner { - - private IJoinTable joinTable; - - public InverseJoinColumnsOwner(IJoinTable joinTable) { - super(); - this.joinTable = joinTable; - } - - public void addJoinColumn() { - JoinTableComposite.this.addInverseJoinColumn(); - } - - public boolean containsSpecifiedJoinColumns() { - return this.joinTable.containsSpecifiedInverseJoinColumns(); - } - - public IJoinColumn createJoinColumn(int index) { - return this.joinTable.createJoinColumn(index); - } - - public List<IJoinColumn> getJoinColumns() { - return this.joinTable.getInverseJoinColumns(); + + private class JoinColumnsProvider implements IJoinColumnsEditor<IJoinTable> { + + public void addJoinColumn(IJoinTable subject) { + JoinTableComposite.this.addJoinColumn(subject); } - - public List<IJoinColumn> getSpecifiedJoinColumns() { - return this.joinTable.getSpecifiedInverseJoinColumns(); + + public void editJoinColumn(IJoinTable subject, IJoinColumn joinColumn) { + JoinTableComposite.this.editJoinColumn(joinColumn); } - - public int specifiedJoinColumnsFeatureId() { - return JpaCoreMappingsPackage.IJOIN_TABLE__SPECIFIED_INVERSE_JOIN_COLUMNS; + + public boolean hasSpecifiedJoinColumns(IJoinTable subject) { + return subject.containsSpecifiedJoinColumns(); } - - public Class owningFeatureClass() { - return IJoinTable.class; + + public ListIterator<IJoinColumn> joinColumns(IJoinTable subject) { + return subject.joinColumns(); } - - public void editJoinColumn(IJoinColumn joinColumn) { - JoinTableComposite.this.editInverseJoinColumn(joinColumn); + + public String[] propertyNames() { + return new String[] { + IJoinTable.DEFAULT_JOIN_COLUMNS_LIST, + IJoinTable.SPECIFIED_JOIN_COLUMNS_LIST + }; } - - public EObject getEObject() { - return this.joinTable; + + public void removeJoinColumns(IJoinTable subject, int[] selectedIndices) { + for (int index = selectedIndices.length; --index >= 0; ) { + subject.removeSpecifiedJoinColumn(selectedIndices[index]); + } } } - }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobCheckBox.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobCheckBox.java deleted file mode 100644 index ab6f383ac9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobCheckBox.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IBasic; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class LobCheckBox extends BaseJpaController -{ - private IBasic basicMapping; - private Adapter basicMappingListener; - - private Button button; - - - public LobCheckBox(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildBasicMappingListener(); - } - - private void buildBasicMappingListener() { - this.basicMappingListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - basicMappingChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.button = getWidgetFactory().createButton( - parent, - JptUiMappingsMessages.BasicGeneralSection_lobLabel, - SWT.CHECK); - - this.button.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - LobCheckBox.this.lobSelectionChanged(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - LobCheckBox.this.lobSelectionChanged(); - } - }); - } - - void lobSelectionChanged() { - boolean lob = this.button.getSelection(); - if (this.basicMapping.isLob() != lob) { - this.basicMapping.setLob(lob); - } - } - - private void basicMappingChanged(Notification notification) { - // ui thread - if (notification.getFeatureID(IBasic.class) == - JpaCoreMappingsPackage.IBASIC__LOB) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.basicMapping != null) { - this.basicMapping.eAdapters().add(this.basicMappingListener); - } - } - - @Override - protected void disengageListeners() { - if (this.basicMapping != null) { - this.basicMapping.eAdapters().remove(this.basicMappingListener); - } - } - - @Override - public void doPopulate(EObject obj) { - this.basicMapping = (IBasic) obj; - populateButton(); - } - - @Override - protected void doPopulate() { - populateButton(); - } - - private void populateButton() { - boolean lob = false; - if (this.basicMapping != null) { - lob = this.basicMapping.isLob(); - } - - if (this.button.getSelection() != lob) { - this.button.setSelection(lob); - } - } - - - @Override - public Control getControl() { - return this.button; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobComposite.java new file mode 100644 index 0000000000..ef7f13a811 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobComposite.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IBasicMapping; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * This composite simply shows the Lob check box. + * + * @see IBasicMapping + * + * @version 2.0 + * @since 1.0 + */ +public class LobComposite extends AbstractFormPane<IBasicMapping> +{ + /** + * Creates a new <code>LobComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public LobComposite(AbstractFormPane<? extends IBasicMapping> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>LobComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IBasicMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public LobComposite(PropertyValueModel<? extends IBasicMapping> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyAspectAdapter<IBasicMapping, Boolean> buildLobHolder() { + + return new PropertyAspectAdapter<IBasicMapping, Boolean>(getSubjectHolder(), IBasicMapping.LOB_PROPERTY) { + + @Override + protected Boolean buildValue_() { + return subject.isLob(); + } + + @Override + protected void setValue_(Boolean value) { + subject.setLob(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + buildCheckBox( + container, + JptUiMappingsMessages.BasicGeneralSection_lobLabel, + buildLobHolder(), + IJpaHelpContextIds.MAPPING_LOB + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyComposite.java deleted file mode 100644 index eafd64e845..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyComposite.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IManyToMany; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -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.ExpandableComposite; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class ManyToManyComposite extends BaseJpaComposite -{ - private IManyToMany manyToMany; - - private TargetEntityChooser targetEntityChooser; - - private EnumComboViewer fetchTypeComboViewer; - - private MappedByCombo mappedByCombo; - - private CascadeComposite cascadeComposite; - - private OrderingComposite orderingComposite; - - private JoinTableComposite joinTableComposite; - - - public ManyToManyComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - Control joinTableControl = buildJoinTableControl(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - joinTableControl.setLayoutData(gridData); - } - - private Control buildGeneralComposite(Composite composite) { -// IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - this.targetEntityChooser = CommonWidgets.buildTargetEntityChooser(generalComposite, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.targetEntityChooser.getControl().setLayoutData(gridData); - - - CommonWidgets.buildFetchLabel(generalComposite, getWidgetFactory()); - this.fetchTypeComboViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.fetchTypeComboViewer.getControl().setLayoutData(gridData); - - - CommonWidgets.buildMappedByLabel(generalComposite, getWidgetFactory()); - this.mappedByCombo = new MappedByCombo(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.mappedByCombo.getControl().setLayoutData(gridData); - - this.cascadeComposite = new CascadeComposite(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.cascadeComposite.getControl().setLayoutData(gridData); - - - this.orderingComposite = new OrderingComposite(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.orderingComposite.getControl().setLayoutData(gridData); - - return generalComposite; - } - - private Control buildJoinTableControl(Composite composite) { - Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - section.setText(JptUiMappingsMessages.MultiRelationshipMappingComposite_joinTable); - - Composite joinTableClient = getWidgetFactory().createComposite(section); - section.setClient(joinTableClient); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - joinTableClient.setLayout(layout); - - this.joinTableComposite = new JoinTableComposite(joinTableClient, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.joinTableComposite.getControl().setLayoutData(gridData); - - return section; - } - - public void doPopulate(EObject obj) { - this.manyToMany = (IManyToMany) obj; - this.targetEntityChooser.populate(this.manyToMany); - this.fetchTypeComboViewer.populate(CommonWidgets.buildMultiRelationshipMappingFetchEnumHolder(this.manyToMany)); - this.mappedByCombo.populate(this.manyToMany); - this.cascadeComposite.populate(this.manyToMany); - if (this.manyToMany != null) { - this.joinTableComposite.populate(this.manyToMany.getJoinTable()); - this.orderingComposite.populate(this.manyToMany); - } - else { - this.joinTableComposite.populate(null); - this.orderingComposite.populate(null); - } - } - - public void doPopulate() { - this.targetEntityChooser.populate(); - this.fetchTypeComboViewer.populate(); - this.mappedByCombo.populate(); - this.cascadeComposite.populate(); - this.joinTableComposite.populate(); - this.orderingComposite.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.targetEntityChooser.dispose(); - this.fetchTypeComboViewer.dispose(); - this.mappedByCombo.dispose(); - this.cascadeComposite.dispose(); - this.joinTableComposite.dispose(); - this.orderingComposite.dispose(); - super.dispose(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyMappingComposite.java new file mode 100644 index 0000000000..7078d6e0ac --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyMappingComposite.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.ICascade; +import org.eclipse.jpt.core.internal.context.base.IJoinTable; +import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | TargetEntityComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | CascadeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OrderingComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - Join Table ------------------------------------------------------------ | + * | | | | + * | | JoinTableComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IManyToManyMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see CascadeComposite + * @see FetchTypeComposite + * @see JoinTableComposite + * @see OrderingComposite + * @see TargetEntityComposite + * + * @version 2.0 + * @since 1.0 + */ +public class ManyToManyMappingComposite extends AbstractFormPane<IManyToManyMapping> + implements IJpaComposite<IManyToManyMapping> +{ + /** + * Creates a new <code>ManyToManyMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IManyToManyMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public ManyToManyMappingComposite(PropertyValueModel<? extends IManyToManyMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<ICascade> buildCascadeHolder() { + return new TransformationPropertyValueModel<IManyToManyMapping, ICascade>(getSubjectHolder()) { + @Override + protected ICascade transform_(IManyToManyMapping value) { + return value.getCascade(); + } + }; + } + + private PropertyValueModel<IJoinTable> buildJointTableHolder() { + return new TransformationPropertyValueModel<IManyToManyMapping, IJoinTable>(getSubjectHolder()) { + @Override + protected IJoinTable transform_(IManyToManyMapping value) { + return value.getJoinTable(); + } + }; + } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + private void initializeGeneralPane(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Target Entity widgets + new TargetEntityComposite(this, buildPane(container, groupBoxMargin)); + + // Fetch Type widgets + new FetchTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Mapped By widgets + new MappedByComposite(this, buildPane(container, groupBoxMargin)); + + // Cascade widgets + new CascadeComposite(this, buildCascadeHolder(), container); + + // Ordering widgets + new OrderingComposite(this, container); + } + + private void initializeJoinTablePane(Composite container) { + + container = buildSection( + container, + JptUiMappingsMessages.MultiRelationshipMappingComposite_joinTable + ); + + new JoinTableComposite( + this, + buildJointTableHolder(), + container + ); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // General sub pane + initializeGeneralPane(container); + + // Join Table sub pane + initializeJoinTablePane(container); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneComposite.java deleted file mode 100644 index 9fb170b369..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneComposite.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IManyToOne; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -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.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class ManyToOneComposite extends BaseJpaComposite -{ - private IManyToOne manyToOne; - - private TargetEntityChooser targetEntityChooser; - - private EnumComboViewer fetchTypeComboViewer; - - private EnumComboViewer optionalComboViewer; - - private CascadeComposite cascadeComposite; - - private JoinColumnComposite joinColumnComposite; - - public ManyToOneComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - } - - private Control buildGeneralComposite(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - this.targetEntityChooser = CommonWidgets.buildTargetEntityChooser(generalComposite, commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.targetEntityChooser.getControl().setLayoutData(gridData); - helpSystem.setHelp(targetEntityChooser.getControl(), IJpaHelpContextIds.MAPPING_TARGET_ENTITY); - - CommonWidgets.buildFetchLabel(generalComposite, getWidgetFactory()); - this.fetchTypeComboViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.fetchTypeComboViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(fetchTypeComboViewer.getControl(), IJpaHelpContextIds.MAPPING_FETCH_TYPE); - - CommonWidgets.buildOptionalLabel(generalComposite, getWidgetFactory()); - this.optionalComboViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.optionalComboViewer.getControl().setLayoutData(gridData); - - this.cascadeComposite = new CascadeComposite(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.cascadeComposite.getControl().setLayoutData(gridData); - - this.joinColumnComposite = new JoinColumnComposite(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.joinColumnComposite.getControl().setLayoutData(gridData); - - return generalComposite; - } - - public void doPopulate(EObject obj) { - this.manyToOne = (IManyToOne) obj; - this.targetEntityChooser.populate(this.manyToOne); - this.fetchTypeComboViewer.populate(CommonWidgets.buildSingleRelationshipMappingFetchEnumHolder(this.manyToOne)); - this.optionalComboViewer.populate(CommonWidgets.buildOptionalHolder(this.manyToOne)); - this.cascadeComposite.populate(this.manyToOne); - this.joinColumnComposite.populate(this.manyToOne); - } - - public void doPopulate() { - this.targetEntityChooser.populate(); - this.fetchTypeComboViewer.populate(); - this.optionalComboViewer.populate(); - this.cascadeComposite.populate(); - this.joinColumnComposite.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.targetEntityChooser.dispose(); - this.fetchTypeComboViewer.dispose(); - this.optionalComboViewer.dispose(); - this.cascadeComposite.dispose(); - this.joinColumnComposite.dispose(); - super.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneMappingComposite.java new file mode 100644 index 0000000000..8fa41e1ad3 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneMappingComposite.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.ICascade; +import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | TargetEntityComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OptionalComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | CascadeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | JoinColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IManyToOneMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see CascadeComposite + * @see FetchTypeComposite + * @see JoinColumnComposite + * @see OptionalComposite + * @see TargetEntityComposite + * + * @version 2.0 + * @since 1.0 + */ +public class ManyToOneMappingComposite extends AbstractFormPane<IManyToOneMapping> + implements IJpaComposite<IManyToOneMapping> +{ + /** + * Creates a new <code>ManyToOneMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IManyToOneMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public ManyToOneMappingComposite(PropertyValueModel<? extends IManyToOneMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<ICascade> buildCascadeHolder() { + return new TransformationPropertyValueModel<IManyToOneMapping, ICascade>(getSubjectHolder()) { + @Override + protected ICascade transform_(IManyToOneMapping value) { + return value.getCascade(); + } + }; + } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Target Entity widgets + new TargetEntityComposite(this, buildPane(container, groupBoxMargin)); + + // Fetch Type widgets + new FetchTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Optional check box + new OptionalComposite(this, buildPane(container, groupBoxMargin)); + + // Cascade widgets + new CascadeComposite(this, buildCascadeHolder(), container); + + // Join Column widgets + new JoinColumnComposite(this, container); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByCombo.java deleted file mode 100644 index 593988c654..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByCombo.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.INonOwningMapping; -import org.eclipse.jpt.core.internal.mappings.IRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class MappedByCombo extends BaseJpaController -{ - private INonOwningMapping nonOwningMapping; - private Adapter nonOwningMappingListener; - - private CCombo combo; - - public MappedByCombo(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, commandStack, widgetFactory); - this.nonOwningMappingListener = buildListener(); - } - - private Adapter buildListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - nonOwningMappingChanged(notification); - } - }; - } - @Override - protected void buildWidget(Composite parent) { - this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - PlatformUI.getWorkbench().getHelpSystem().setHelp(combo,IJpaHelpContextIds.MAPPING_MAPPED_BY); - this.combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String mappedBy = ((CCombo) e.getSource()).getText(); - if (mappedBy.equals("")) { //$NON-NLS-1$ - mappedBy = null; - if (getNonOwningMapping().getMappedBy() == null || getNonOwningMapping().getMappedBy().equals("")) { //$NON-NLS-1$ - return; - } - } - if (getNonOwningMapping().getMappedBy() == null || !getNonOwningMapping().getMappedBy().equals(mappedBy)) { - getNonOwningMapping().setMappedBy(mappedBy); - } - } - }); - } - - private INonOwningMapping getNonOwningMapping() { - return this.nonOwningMapping; - } - - @Override - protected void doPopulate(EObject obj) { - this.nonOwningMapping = (INonOwningMapping) obj; - - if (this.nonOwningMapping == null) { - return; - } - - populateCombo(); - } - - private void populateCombo() { - populateChoices(); - populateMappedByText(); - } - - private void populateChoices() { - if (this.combo.getItemCount() > 0) { - this.combo.removeAll(); - } - for (Iterator<String> i = this.nonOwningMapping.candidateMappedByAttributeNames(); i.hasNext(); ) { - this.combo.add(i.next()); - } - } - - private void populateMappedByText() { - String mappedBy = this.nonOwningMapping.getMappedBy(); - if (mappedBy != null) { - if (!this.combo.getText().equals(mappedBy)) { - this.combo.setText(mappedBy); - } - } - else { - this.combo.setText(""); - } - } - - @Override - protected void doPopulate() { - } - - @Override - protected void engageListeners() { - if (this.nonOwningMapping != null) { - this.nonOwningMapping.eAdapters().add(this.nonOwningMappingListener); - } - } - - @Override - protected void disengageListeners() { - if (this.nonOwningMapping != null) { - this.nonOwningMapping.eAdapters().remove(this.nonOwningMappingListener); - } - } - - protected void nonOwningMappingChanged(Notification notification) { - if (notification.getFeatureID(INonOwningMapping.class) == JpaCoreMappingsPackage.INON_OWNING_MAPPING__MAPPED_BY) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateMappedByText(); - } - }); - } - else if (notification.getFeatureID(IRelationshipMapping.class) == JpaCoreMappingsPackage.IRELATIONSHIP_MAPPING__RESOLVED_TARGET_ENTITY) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateChoices(); - } - }); - } - } - - @Override - public Control getControl() { - return this.combo; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByComposite.java new file mode 100644 index 0000000000..55dd58b0c6 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByComposite.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.core.internal.context.base.INonOwningMapping; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | -------------------------------------------------------------- | + * | Mapped By: | |v| | + * | -------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see INonOwningMapping + * @see ManyToManyMappingComposite - A container of this pane + * @see OneToManyMappingComposite - A container of this pane + * @see OneToOneMappingComposite - A container of this pane + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public class MappedByComposite extends AbstractFormPane<INonOwningMapping> +{ + private CCombo combo; + + /** + * Creates a new <code>MappedByComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + protected MappedByComposite(AbstractFormPane<? extends INonOwningMapping> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>MappedByComposite</code>. + * + * @param subjectHolder The holder of the subject <code>INonOwningMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public MappedByComposite(PropertyValueModel<? extends INonOwningMapping> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(INonOwningMapping.MAPPED_BY_PROPERTY); + } + + private ModifyListener buildComboModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (isPopulating()) { + return; + } + + String mappedBy = ((CCombo) e.getSource()).getText(); + String currentMappedBy = subject().getMappedBy(); + + if (StringTools.stringIsEmpty(mappedBy)) { + mappedBy = null; + + if (StringTools.stringIsEmpty(currentMappedBy)) { + return; + } + } + + if (currentMappedBy == null || !currentMappedBy.equals(mappedBy)) { + subject().setMappedBy(mappedBy); + } + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + populateChoices(); + populateMappedByText(); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + combo = buildCombo(container); + combo.addModifyListener(buildComboModifyListener()); + + buildLabeledComposite( + container, + JptUiMappingsMessages.NonOwningMapping_mappedByLabel, + combo.getParent(), + IJpaHelpContextIds.MAPPING_MAPPED_BY + ); + } + + private void populateChoices() { + combo.removeAll(); + + if (subject() != null) { + for (Iterator<String> iter = subject().candidateMappedByAttributeNames(); iter.hasNext(); ) { + combo.add(iter.next()); + } + } + } + + private void populateMappedByText() { + if (subject() == null) { + return; + } + + if (subject() != null) { + String mappedBy = subject().getMappedBy(); + + if (mappedBy != null) { + if (!combo.getText().equals(mappedBy)) { + combo.setText(mappedBy); + } + } + else { + combo.setText(""); + } + } + else { + combo.setText(""); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == INonOwningMapping.MAPPED_BY_PROPERTY) { + populateMappedByText(); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedSuperclassComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedSuperclassComposite.java index 4f9f7186a8..24ec4f562e 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedSuperclassComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedSuperclassComposite.java @@ -1,57 +1,45 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 Oracle. All rights reserved. This + * Copyright (c) 2005, 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.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.jpt.core.internal.context.base.IMappedSuperclass; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class MappedSuperclassComposite extends BaseJpaComposite +/** + * @see IMappedSuperclass + * @see BaseJpaUiFactory - The factory creating this pane + * + * @version 2.0 + * @since 2.0 + */ +public class MappedSuperclassComposite extends AbstractFormPane<IMappedSuperclass> + implements IJpaComposite<IMappedSuperclass> { -// private IMappedSuperclass mappedSuperclass; -// private Adapter mappedSuperclassListener; - - public MappedSuperclassComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); -// this.mappedSuperclassListener = buildMappedSuperclassListener(); - } -// -// private Adapter buildMappedSuperclassListener() { -// return new AdapterImpl() { -// @Override -// public void notifyChanged(Notification notification) { -// mappedSuperclassChanged(notification); -// } -// }; -// } - - @Override - protected void initializeLayout(Composite composite) { - composite.setLayout(new FillLayout(SWT.VERTICAL)); - -// Label accessTypeLabel = new Label(composite, SWT.LEFT); -// accessTypeLabel.setText(DaliUiMessages.MappedSuperclassComposite_accessType); -// this.accessTypeComboViewer = buildAccessTypeCombo(composite); -// //eventually this will be enabled if editing xml instead of java -// this.accessTypeComboViewer.getCombo().setEnabled(false); -// GridData gridData = new GridData(); -// gridData.horizontalAlignment = GridData.FILL; -// gridData.grabExcessHorizontalSpace = true; -// this.accessTypeComboViewer.getCombo().setLayoutData(gridData); -// PlatformUI.getWorkbench().getHelpSystem().setHelp(this.accessTypeComboViewer.getCombo(), IDaliHelpContextIds.ENTITY_ACCESS_TYPE); - + /** + * Creates a new <code>MappedSuperclassComposite</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public MappedSuperclassComposite(PropertyValueModel<? extends IMappedSuperclass> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - + + // private ComboViewer buildAccessTypeCombo(Composite parent) { // ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY); // viewer.add(AccessType.VALUES.toArray()); @@ -68,47 +56,21 @@ public class MappedSuperclassComposite extends BaseJpaComposite // }); // return viewer; // } - - @Override - protected void doPopulate(EObject model) { -// this.mappedSuperclass = (IMappedSuperclass) model; - } - + + @Override - protected void doPopulate() { - - } - - - protected void engageListeners() { -// this.persistentTypeItemProvider.addListener(getPersistentTypeListener()); -// this.persistentType.eAdapters().add(this.persistentTypeItemProvider); - } + protected void initializeLayout(Composite composite) { + +// Label accessTypeLabel = new Label(composite, SWT.LEFT); +// accessTypeLabel.setText(DaliUiMessages.MappedSuperclassComposite_accessType); +// this.accessTypeComboViewer = buildAccessTypeCombo(composite); +// //eventually this will be enabled if editing xml instead of java +// this.accessTypeComboViewer.getCombo().setEnabled(false); +// GridData gridData = new GridData(); +// gridData.horizontalAlignment = GridData.FILL; +// gridData.grabExcessHorizontalSpace = true; +// this.accessTypeComboViewer.getCombo().setLayoutData(gridData); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(this.accessTypeComboViewer.getCombo(), IDaliHelpContextIds.ENTITY_ACCESS_TYPE); - protected void disengageListeners() { -// if (this.persistentType != null){ -// this.persistentType.eAdapters().remove(this.persistentTypeItemProvider); -// this.persistentTypeItemProvider.removeListener(getPersistentTypeListener()); -// } } - -// private INotifyChangedListener getPersistentTypeListener() { -// if (this.persistentTypeListener == null) { -// this.persistentTypeListener = new INotifyChangedListener() { -// public void notifyChanged(Notification notification) { -// if (notification.getFeatureID(PersistentType.class) == OrmPackage.PERSISTENT_TYPE__ACCESS_TYPE) { -// final AccessType accessType = (AccessType) notification.getNewValue(); -// Display.getDefault().syncExec(new Runnable() { -// public void run() { -// if (((StructuredSelection) accessTypeComboViewer.getSelection()).getFirstElement() != accessType) { -// accessTypeComboViewer.setSelection(new StructuredSelection(accessType)); -// } -// } -// }); -// } -// } -// }; -// } -// return this.persistentTypeListener; -// } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyComposite.java deleted file mode 100644 index d7193b6db2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyComposite.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IOneToMany; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -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.PlatformUI; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class OneToManyComposite extends BaseJpaComposite -{ - private IOneToMany oneToMany; - - private EnumComboViewer fetchTypeComboViewer; - - private TargetEntityChooser targetEntityChooser; - - private MappedByCombo mappedByCombo; - - private CascadeComposite cascadeComposite; - - private OrderingComposite orderingComposite; - - private JoinTableComposite joinTableComposite; - - public OneToManyComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralControl(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - Control joinTableControl = buildJoinTableControl(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - joinTableControl.setLayoutData(gridData); - } - - private Control buildGeneralControl(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - GridData gridData; - - this.targetEntityChooser = CommonWidgets.buildTargetEntityChooser(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.targetEntityChooser.getControl().setLayoutData(gridData); - - CommonWidgets.buildFetchLabel(generalComposite, getWidgetFactory()); - this.fetchTypeComboViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.fetchTypeComboViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(this.fetchTypeComboViewer.getControl(), IJpaHelpContextIds.MAPPING_FETCH_TYPE); - - CommonWidgets.buildMappedByLabel(generalComposite, getWidgetFactory()); - this.mappedByCombo = new MappedByCombo(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.mappedByCombo.getControl().setLayoutData(gridData); - helpSystem.setHelp(this.mappedByCombo.getControl(), IJpaHelpContextIds.MAPPING_MAPPED_BY); - - this.cascadeComposite = new CascadeComposite(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.cascadeComposite.getControl().setLayoutData(gridData); - - this.orderingComposite = new OrderingComposite(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.orderingComposite.getControl().setLayoutData(gridData); - - - return generalComposite; - } - - private Control buildJoinTableControl(Composite composite) { - Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - section.setText(JptUiMappingsMessages.MultiRelationshipMappingComposite_joinTable); - - Composite joinTableClient = getWidgetFactory().createComposite(section); - section.setClient(joinTableClient); - - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - joinTableClient.setLayout(layout); - - this.joinTableComposite = new JoinTableComposite(joinTableClient, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.joinTableComposite.getControl().setLayoutData(gridData); - - return section; - } - - public void doPopulate(EObject obj) { - this.oneToMany = (IOneToMany) obj; - this.fetchTypeComboViewer.populate(CommonWidgets.buildMultiRelationshipMappingFetchEnumHolder(this.oneToMany)); - this.targetEntityChooser.populate(this.oneToMany); - this.mappedByCombo.populate(this.oneToMany); - this.cascadeComposite.populate(this.oneToMany); - if (this.oneToMany != null) { - this.joinTableComposite.populate(this.oneToMany.getJoinTable()); - this.orderingComposite.populate(this.oneToMany); - } - else { - this.joinTableComposite.populate(null); - this.orderingComposite.populate(null); - } - } - - public void doPopulate() { - this.fetchTypeComboViewer.populate(); - this.targetEntityChooser.populate(); - this.mappedByCombo.populate(); - this.cascadeComposite.populate(); - this.joinTableComposite.populate(); - this.orderingComposite.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.fetchTypeComboViewer.dispose(); - this.targetEntityChooser.dispose(); - this.mappedByCombo.dispose(); - this.cascadeComposite.dispose(); - this.joinTableComposite.dispose(); - this.orderingComposite.dispose(); - super.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyMappingComposite.java new file mode 100644 index 0000000000..fa4b69fcb1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyMappingComposite.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.ICascade; +import org.eclipse.jpt.core.internal.context.base.IJoinTable; +import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | TargetEntityComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | CascadeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OrderingComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - Join Table ------------------------------------------------------------ | + * | | | | + * | | JoinTableComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IOneToManyMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see CascadeComposite + * @see FetchTypeComposite + * @see JoinTableComposite + * @see OrderingComposite + * @see TargetEntityComposite + * + * @version 2.0 + * @since 1.0 + */ +public class OneToManyMappingComposite extends AbstractFormPane<IOneToManyMapping> + implements IJpaComposite<IOneToManyMapping> +{ + /** + * Creates a new <code>OneToManyMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IOneToManyMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public OneToManyMappingComposite(PropertyValueModel<? extends IOneToManyMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<ICascade> buildCascadeHolder() { + return new TransformationPropertyValueModel<IOneToManyMapping, ICascade>(getSubjectHolder()) { + @Override + protected ICascade transform_(IOneToManyMapping value) { + return value.getCascade(); + } + }; + } + + private PropertyValueModel<IJoinTable> buildJointTableHolder() { + return new TransformationPropertyValueModel<IOneToManyMapping, IJoinTable>(getSubjectHolder()) { + @Override + protected IJoinTable transform_(IOneToManyMapping value) { + return value.getJoinTable(); + } + }; + } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + private void initializeGeneralPane(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Target Entity widgets + new TargetEntityComposite(this, buildPane(container, groupBoxMargin)); + + // Fetch Type widgets + new FetchTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Mapped By widgets + new MappedByComposite(this, buildPane(container, groupBoxMargin)); + + // Cascade widgets + new CascadeComposite(this, buildCascadeHolder(), container); + + // Ordering widgets + new OrderingComposite(this, container); + } + + private void initializeJoinTablePane(Composite container) { + + container = buildSection( + container, + JptUiMappingsMessages.MultiRelationshipMappingComposite_joinTable + ); + + new JoinTableComposite( + this, + buildJointTableHolder(), + container + ); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // General sub pane + initializeGeneralPane(container); + + // Join Table sub pane + initializeJoinTablePane(container); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneComposite.java deleted file mode 100644 index 6894ac5836..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneComposite.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.IOneToOne; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -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.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class OneToOneComposite extends BaseJpaComposite -{ - private IOneToOne oneToOne; - - private TargetEntityChooser targetEntityChooser; - - private EnumComboViewer fetchTypeComboViewer; - - private MappedByCombo mappedByCombo; - - private EnumComboViewer optionalComboViewer; - - private CascadeComposite cascadeComposite; - - private JoinColumnComposite joinColumnComposite; - - public OneToOneComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - protected IOneToOne getOneToOne() { - return this.oneToOne; - } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - } - - protected Control buildGeneralComposite(Composite composite) { -// IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - TargetEntityChooser targetEntityChooser = getTargetEntityChooser(generalComposite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - targetEntityChooser.getControl().setLayoutData(gridData); - - - CommonWidgets.buildFetchLabel(generalComposite, getWidgetFactory()); - EnumComboViewer fetchTypeComboViewer = getFetchTypeComboViewer(generalComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - fetchTypeComboViewer.getControl().setLayoutData(gridData); - - CommonWidgets.buildMappedByLabel(generalComposite, getWidgetFactory()); - MappedByCombo mappedByCombo = getMappedByCombo(generalComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - mappedByCombo.getControl().setLayoutData(gridData); - - CommonWidgets.buildOptionalLabel(generalComposite, getWidgetFactory()); - EnumComboViewer optionalComboViewer = getOptionalComboViewer(generalComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - optionalComboViewer.getControl().setLayoutData(gridData); - - CascadeComposite cascadeComposite = getCascadeComposite(generalComposite); - gridData = new GridData(); - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - cascadeComposite.getControl().setLayoutData(gridData); - - JoinColumnComposite joinColumnComposite = getJoinColumnComposite(generalComposite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - joinColumnComposite.getControl().setLayoutData(gridData); - - return generalComposite; - } - - protected TargetEntityChooser getTargetEntityChooser(Composite parentComposite) { - if (this.targetEntityChooser == null) { - this.targetEntityChooser = createTargetEntityChooser(parentComposite); - } - return this.targetEntityChooser; - } - - protected TargetEntityChooser createTargetEntityChooser(Composite parentComposite) { - return CommonWidgets.buildTargetEntityChooser(parentComposite, this.commandStack, getWidgetFactory()); - } - - protected EnumComboViewer getFetchTypeComboViewer(Composite parentComposite) { - if (this.fetchTypeComboViewer == null) { - this.fetchTypeComboViewer = createFetchTypeComboViewer(parentComposite); - } - return this.fetchTypeComboViewer; - } - - protected EnumComboViewer createFetchTypeComboViewer(Composite parentComposite) { - return CommonWidgets.buildEnumComboViewer(parentComposite, this.commandStack, getWidgetFactory()); - } - - protected MappedByCombo getMappedByCombo(Composite parentComposite) { - if (this.mappedByCombo == null) { - this.mappedByCombo = createMappedByCombo(parentComposite); - } - return this.mappedByCombo; - } - - protected MappedByCombo createMappedByCombo(Composite parentComposite) { - return new MappedByCombo(parentComposite, this.commandStack, getWidgetFactory()); - } - - protected EnumComboViewer getOptionalComboViewer(Composite parentComposite) { - if (this.optionalComboViewer == null) { - this.optionalComboViewer = createOptionalComboViewer(parentComposite); - } - return this.optionalComboViewer; - } - - protected EnumComboViewer createOptionalComboViewer(Composite parentComposite) { - return CommonWidgets.buildEnumComboViewer(parentComposite, this.commandStack, getWidgetFactory()); - } - - protected CascadeComposite getCascadeComposite(Composite parentComposite) { - if (this.cascadeComposite == null) { - this.cascadeComposite = createCascadeComposite(parentComposite); - } - return this.cascadeComposite; - } - - protected CascadeComposite createCascadeComposite(Composite parentComposite) { - return new CascadeComposite(parentComposite, this.commandStack, getWidgetFactory()); - } - - protected JoinColumnComposite getJoinColumnComposite(Composite parentComposite) { - if (this.joinColumnComposite == null) { - this.joinColumnComposite = createJoinColumnComposite(parentComposite); - } - return this.joinColumnComposite; - } - - protected JoinColumnComposite createJoinColumnComposite(Composite parentComposite) { - return new JoinColumnComposite(parentComposite, this.commandStack, getWidgetFactory()); - } - - - public void doPopulate(EObject obj) { - this.oneToOne = (IOneToOne) obj; - this.targetEntityChooser.populate(getOneToOne()); - this.fetchTypeComboViewer.populate(CommonWidgets.buildSingleRelationshipMappingFetchEnumHolder(getOneToOne())); - this.mappedByCombo.populate(getOneToOne()); - this.optionalComboViewer.populate(CommonWidgets.buildOptionalHolder(getOneToOne())); - this.cascadeComposite.populate(getOneToOne()); - this.joinColumnComposite.populate(getOneToOne()); - } - - public void doPopulate() { - this.targetEntityChooser.populate(); - this.fetchTypeComboViewer.populate(); - this.mappedByCombo.populate(); - this.optionalComboViewer.populate(); - this.cascadeComposite.populate(); - this.joinColumnComposite.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.targetEntityChooser.dispose(); - this.fetchTypeComboViewer.dispose(); - this.mappedByCombo.dispose(); - this.optionalComboViewer.dispose(); - this.cascadeComposite.dispose(); - this.joinColumnComposite.dispose(); - super.dispose(); - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneMappingComposite.java new file mode 100644 index 0000000000..d9ae3a72c1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneMappingComposite.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.ICascade; +import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | TargetEntityComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | MappedByComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OptionalComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | CascadeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | JoinColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IOneToOneMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see CascadeComposite + * @see FetchTypeComposite + * @see JoinColumnComposite + * @see MappedByComposite + * @see OptionalComposite + * @see TargetEntityComposite + * + * @version 2.0 + * @since 1.0 + */ +public class OneToOneMappingComposite extends AbstractFormPane<IOneToOneMapping> + implements IJpaComposite<IOneToOneMapping> +{ + /** + * Creates a new <code>OneToOneMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IOneToOneMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public OneToOneMappingComposite(PropertyValueModel<? extends IOneToOneMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<ICascade> buildCascadeHolder() { + return new TransformationPropertyValueModel<IOneToOneMapping, ICascade>(getSubjectHolder()) { + @Override + protected ICascade transform_(IOneToOneMapping value) { + return value.getCascade(); + } + }; + } + + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Target Entity widgets + new TargetEntityComposite(this, buildPane(container, groupBoxMargin)); + + // Fetch Type widgets + new FetchTypeComposite(this, buildPane(container, groupBoxMargin)); + + // Mapped By widgets + new MappedByComposite(this, buildPane(container, groupBoxMargin)); + + // Optional check box + new OptionalComposite(this, buildPane(container, groupBoxMargin)); + + // Cascade widgets + new CascadeComposite(this, buildCascadeHolder(), container); + + // Join Column widgets + new JoinColumnComposite(this, container); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OptionalComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OptionalComposite.java new file mode 100644 index 0000000000..ee65ff8050 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OptionalComposite.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.INullable; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Composite; + +/** + * This composite simply shows a tri-state check box for the Optional option. + * + * @see IBasicMapping + * @see BasicMappingComposite - A container of this pane + * @see ManyToOneMappingComposite - A container of this pane + * @see OneToOneMappingComposite - A container of this pane + * + * @version 1.0 + * @since 2.0 + */ +public class OptionalComposite extends AbstractFormPane<INullable> +{ + /** + * Creates a new <code>OptionalComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public OptionalComposite(AbstractFormPane<? extends INullable> parentPane, + Composite parent) + { + super(parentPane, parent); + } + + private WritablePropertyValueModel<Boolean> buildOptionalHolder() { + return new PropertyAspectAdapter<INullable, Boolean>(getSubjectHolder(), INullable.SPECIFIED_OPTIONAL_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.getSpecifiedOptional(); + } + + @Override + protected void setValue_(Boolean value) { + subject.setSpecifiedOptional(value); + } + }; + } + + private PropertyValueModel<String> buildOptionalStringHolder() { + + return new TransformationPropertyValueModel<Boolean, String>(buildOptionalHolder()) { + + @Override + protected String transform(Boolean value) { + + if ((subject() != null) && (value == null)) { + + Boolean defaultValue = subject().getDefaultOptional(); + + if (defaultValue != null) { + + String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : + JptUiMappingsMessages.Boolean_False; + + return NLS.bind( + JptUiMappingsMessages.BasicGeneralSection_optionalLabelDefault, + defaultStringValue + ); + } + } + + return JptUiMappingsMessages.BasicGeneralSection_optionalLabel; + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + buildTriStateCheckBoxWithDefault( + container, + JptUiMappingsMessages.BasicGeneralSection_optionalLabel, + buildOptionalHolder(), + buildOptionalStringHolder(), + IJpaHelpContextIds.MAPPING_OPTIONAL + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java index 95b1bc6284..623f358380 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java @@ -1,309 +1,236 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextViewer; -import org.eclipse.jpt.core.internal.mappings.IMultiRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.IMultiRelationshipMapping; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -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; +import org.eclipse.jpt.ui.internal.util.ControlEnabler; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +import org.eclipse.swt.widgets.Text; /** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | - Order By -------------------------------------------------------------- | + * | | | | + * | | o No Ordering | | + * | | | | + * | | o Primary Key Ordering | | + * | | | | + * | | o Custom Ordering | | + * | | ------------------------------------------------------------------- | | + * | | | | | | + * | | ------------------------------------------------------------------- | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IMultiRelationshipMapping + * @see ManyToManyMappingComposite - A container of this pane + * @see OneToManyMappingComposite - A container of this pane * + * @version 2.0 + * @since 1.0 */ -public class OrderingComposite extends BaseJpaComposite { - - private IMultiRelationshipMapping mapping; - private Adapter mappingListener; - - private Button noOrderingRadioButton; - private Button primaryKeyOrderingRadioButton; - private Button customOrderingRadioButton; - - private ITextViewer orderingTextViewer; - - // short circuit flag for user typing - private boolean updatingCustomOrderBy = false; - - - public OrderingComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, commandStack, widgetFactory); - this.mappingListener = buildMappingListener(); +@SuppressWarnings("nls") +public class OrderingComposite extends AbstractFormPane<IMultiRelationshipMapping> +{ + private Text customOrderingText; + + /** + * Creates a new <code>OrderingComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + protected OrderingComposite(AbstractFormPane<? extends IMultiRelationshipMapping> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>OrderingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IMultiRelationshipMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public OrderingComposite(PropertyValueModel<? extends IMultiRelationshipMapping> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IMultiRelationshipMapping.ORDER_BY_PROPERTY); } - private Adapter buildMappingListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - mappingChanged(notification); + private WritablePropertyValueModel<Boolean> buildCustomOrderingHolder() { + return new PropertyAspectAdapter<IMultiRelationshipMapping, Boolean>(getSubjectHolder(), IMultiRelationshipMapping.ORDER_BY_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isCustomOrdering(); + } + + @Override + protected void setValue_(Boolean value) { + if (value) { + subject.setOrderBy(""); + } } }; } - @Override - protected void initializeLayout(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - composite.setLayout(layout); - - Group orderByGroup = getWidgetFactory().createGroup(composite, JptUiMappingsMessages.OrderByComposite_orderByGroup); - orderByGroup.setLayout(new GridLayout(1, false)); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - orderByGroup.setLayoutData(gridData); - helpSystem.setHelp(orderByGroup, IJpaHelpContextIds.MAPPING_ORDER_BY); - - - this.noOrderingRadioButton = buildNoOrderingRadioButton(orderByGroup); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.noOrderingRadioButton.setLayoutData(gridData); -// helpSystem().setHelp(this.noOrderingRadioButton, IJpaHelpContextIds.MAPPING_ORDER_BY_NO_ORDERING); - - - this.primaryKeyOrderingRadioButton = buildPrimaryKeyOrderingRadioButton(orderByGroup); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.primaryKeyOrderingRadioButton.setLayoutData(gridData); -// helpSystem().setHelp(this.primaryKeyOrderingRadioButton, IJpaHelpContextIds.MAPPING_ORDER_BY_PRIMARY_KEY_ORDERING); - - this.customOrderingRadioButton = buildCustomOrderingRadioButton(orderByGroup); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.customOrderingRadioButton.setLayoutData(gridData); -// helpSystem().setHelp(this.customOrderingRadioButton, IJpaHelpContextIds.MAPPING_ORDER_BY_CUSTOM_ORDERING); + private ModifyListener buildCustomTextModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + if (isPopulating()) { + return; + } - - this.orderingTextViewer = buildOrderByTestViewer(orderByGroup); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalIndent = 15; - this.orderingTextViewer.getTextWidget().setLayoutData(gridData); - helpSystem.setHelp(this.orderingTextViewer.getTextWidget(), IJpaHelpContextIds.MAPPING_ORDER_BY); - } - - private Button buildNoOrderingRadioButton(Composite parent) { - Button button = getWidgetFactory().createButton( - parent, - JptUiMappingsMessages.OrderByComposite_noOrdering, - SWT.RADIO); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - public void widgetSelected(SelectionEvent e) { - OrderingComposite.this.noOrderingRadioButtonSelected(e); + Text text = (Text) e.widget; + subject().setOrderBy(text.getText()); } - }); - - return button; + }; } - void noOrderingRadioButtonSelected(SelectionEvent e) { - if (!((Button) e.widget).getSelection()) { - //ignore case where radio button is deselected - return; - } - if (this.mapping.isNoOrdering()) { - return; - } - this.mapping.setNoOrdering(); - } - - private Button buildPrimaryKeyOrderingRadioButton(Composite parent) { - Button button = getWidgetFactory().createButton( - parent, - JptUiMappingsMessages.OrderByComposite_primaryKeyOrdering, - SWT.RADIO); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore + private WritablePropertyValueModel<Boolean> buildNoOrderingHolder() { + return new PropertyAspectAdapter<IMultiRelationshipMapping, Boolean>(getSubjectHolder(), IMultiRelationshipMapping.ORDER_BY_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isNoOrdering(); } - public void widgetSelected(SelectionEvent e) { - OrderingComposite.this.primaryKeyOrderingRadioButtonSelected(e); + + @Override + protected void setValue_(Boolean value) { + if (value) { + subject.setNoOrdering(); + } } - }); - return button; - } - - void primaryKeyOrderingRadioButtonSelected(SelectionEvent e) { - if (!((Button) e.widget).getSelection()) { - //ignore case where radio button is deselected - return; - } - if (! this.mapping.isOrderByPk()) { - this.mapping.setOrderByPk(); - } - setTextViewerEnabled(false); + }; } - private Button buildCustomOrderingRadioButton(Composite parent) { - Button button = getWidgetFactory().createButton( - parent, - JptUiMappingsMessages.OrderByComposite_customOrdering, - SWT.RADIO); - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - public void widgetSelected(SelectionEvent e) { - OrderingComposite.this.customOrderingRadioButtonSelected(e); + private WritablePropertyValueModel<Boolean> buildPrimaryKeyOrderingHolder() { + return new PropertyAspectAdapter<IMultiRelationshipMapping, Boolean>(getSubjectHolder(), IMultiRelationshipMapping.ORDER_BY_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isOrderByPk(); } - }); - return button; - } - - void customOrderingRadioButtonSelected(SelectionEvent e) { - if (!((Button) e.widget).getSelection()) { - //ignore case where radio button is deselected - return; - } - setTextViewerEnabled(true); - } - - private ITextViewer buildOrderByTestViewer(Composite parent) { - final TextViewer textViewer = new TextViewer(parent, SWT.SINGLE | SWT.BORDER); - textViewer.setDocument(new Document()); - textViewer.addTextListener(new ITextListener() { - public void textChanged(TextEvent event) { - orderingTextViewerChanged(); + @Override + protected void setValue_(Boolean value) { + if (value) { + subject.setOrderByPk(); + } } - }); - return textViewer; - } - - private void orderingTextViewerChanged() { - if (isPopulating()) { - return; - } - String orderByValue = this.orderingTextViewer.getDocument().get(); - if (orderByValue.equals(this.mapping.getOrderBy())) { - return; - } - - this.updatingCustomOrderBy = true; - this.mapping.setOrderBy(orderByValue); - } - - private void setTextViewerEnabled(boolean enabled) { - this.orderingTextViewer.setEditable(enabled); - this.orderingTextViewer.getTextWidget().setEnabled(enabled); + }; } - private void mappingChanged(Notification notification) { - if (notification.getFeatureID(IMultiRelationshipMapping.class) == JpaCoreMappingsPackage.IMULTI_RELATIONSHIP_MAPPING__ORDER_BY) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - populate(); - } - }); - } + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + populateCustomOrdering(); } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(EObject obj) { - this.mapping = (IMultiRelationshipMapping) obj; - if (this.mapping == null) { + protected void initializeLayout(Composite container) { + + // Order By group + Group orderByGroup = buildTitledPane( + container, + JptUiMappingsMessages.OrderByComposite_orderByGroup, + IJpaHelpContextIds.MAPPING_ORDER_BY); + + // No Ordering radio button + buildRadioButton( + orderByGroup, + JptUiMappingsMessages.OrderByComposite_noOrdering, + buildNoOrderingHolder(), + IJpaHelpContextIds.MAPPING_ORDER_BY_NO_ORDERING + ); + + // Order by Primary Key radio button + buildRadioButton( + orderByGroup, + JptUiMappingsMessages.OrderByComposite_primaryKeyOrdering, + buildPrimaryKeyOrderingHolder(), + IJpaHelpContextIds.MAPPING_ORDER_BY_PRIMARY_KEY_ORDERING + ); + + // Custom Ordering radio button + buildRadioButton( + orderByGroup, + JptUiMappingsMessages.OrderByComposite_customOrdering, + buildCustomOrderingHolder(), + IJpaHelpContextIds.MAPPING_ORDER_BY_CUSTOM_ORDERING + ); + + // Custom Ordering text field + customOrderingText = buildText( + buildSubPane(orderByGroup, 0, 16), + IJpaHelpContextIds.MAPPING_ORDER_BY + ); + + customOrderingText.addModifyListener(buildCustomTextModifyListener()); + installCustomTextEnabler(customOrderingText); + } + + private void installCustomTextEnabler(Text text) { + new ControlEnabler(buildCustomOrderingHolder(), text); + } + + private void populateCustomOrdering() { + + if (customOrderingText.isDisposed()) { return; } - populateOrderingRadioButtons(); - } - - @Override - protected void doPopulate() { - populateOrderingRadioButtons(); - } - @Override - protected void engageListeners() { - if (this.mapping != null) { - this.mapping.eAdapters().add(this.mappingListener); + if ((subject() != null) && subject().isCustomOrdering()) { + customOrderingText.setText(subject().getOrderBy()); + } + else { + customOrderingText.setText(""); } } + /* + * (non-Javadoc) + */ @Override - protected void disengageListeners() { - if (this.mapping != null) { - this.mapping.eAdapters().remove(this.mappingListener); - } - } - - private void populateOrderingRadioButtons() { - // short circuit if user is typing - if (updatingCustomOrderBy) { - updatingCustomOrderBy = false; - return; - } - - if (this.mapping.isNoOrdering()) { - this.primaryKeyOrderingRadioButton.setSelection(false); - this.customOrderingRadioButton.setSelection(false); - this.noOrderingRadioButton.setSelection(true); - if (! "".equals(this.orderingTextViewer.getDocument().get())) { - this.orderingTextViewer.getDocument().set(""); - } - } - else if (this.mapping.isOrderByPk()) { - this.customOrderingRadioButton.setSelection(false); - this.noOrderingRadioButton.setSelection(false); - this.primaryKeyOrderingRadioButton.setSelection(true); -// String value = this.ordering.getValue(); -// if (value != null && !value.equals(this.orderingTextViewer.getDocument().get())) { -// this.orderingTextViewer.getDocument().set(value); -// } -// else { - if (!"".equals(this.orderingTextViewer.getDocument().get())) { - this.orderingTextViewer.getDocument().set(""); - } -// } - } - else if (this.mapping.isCustomOrdering()) { - this.noOrderingRadioButton.setSelection(false); - this.primaryKeyOrderingRadioButton.setSelection(false); - this.customOrderingRadioButton.setSelection(true); - String value = this.mapping.getOrderBy(); - if (value != null && !value.equals(this.orderingTextViewer.getDocument().get())) { - this.orderingTextViewer.getDocument().set(value); - } + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == IMultiRelationshipMapping.ORDER_BY_PROPERTY) { + populateCustomOrdering(); } - - setTextViewerEnabled(this.mapping.isCustomOrdering()); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java index 986aab26e1..6e11bd46ff 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java @@ -1,501 +1,447 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License 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, 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.ui.internal.mappings.details; -import java.util.List; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; +import java.util.ListIterator; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.JpaEObject; -import org.eclipse.jpt.core.internal.mappings.IAssociationOverride; -import org.eclipse.jpt.core.internal.mappings.IAttributeOverride; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IOverride; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.core.internal.context.base.IAssociationOverride; +import org.eclipse.jpt.core.internal.context.base.IAttributeOverride; +import org.eclipse.jpt.core.internal.context.base.IColumn; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IOverride; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.Owner; +import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.IJoinColumnsEditor; +import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.StringConverter; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; 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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; +import org.eclipse.swt.widgets.List; import org.eclipse.ui.part.PageBook; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class OverridesComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | - Attribute Overrides --------------------------------------------------- | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | + * | | | | + * | | x Override Default | | + * | | | | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | JoinColumnsComposite | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IEntity + * @see EntityComposite - The parent container + * @see JoinColumnsComposite + * + * @version 2.0 + * @since 1.0 + */ +public class OverridesComposite extends AbstractFormPane<IEntity> { - private ListViewer listViewer; - - private IEntity entity; - private Adapter entityListener; - - private IOverride selectedOverride; - private Adapter overrideListener; - - protected PageBook overridePageBook; - - protected ColumnComposite columnComposite; - protected JoinColumnsComposite joinColumnsComposite; - - private Button overrideDefaultButton; - - public OverridesComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.entityListener = buildEntityListener(); - this.overrideListener = buildOverrideListener(); + /** + * Creates a new <code>OverridesComposite</code>. + * + * @param parentPane The parent controller of this one + * @param parent The parent container + */ + public OverridesComposite(AbstractFormPane<? extends IEntity> parentPane, + Composite parent) { + + super(parentPane, parent); } - - private Adapter buildEntityListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - entityChanged(notification); - } - }; + + /** + * Creates a new <code>OverridesComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEntity</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public OverridesComposite(PropertyValueModel<? extends IEntity> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private void addJoinColumn(IAssociationOverride subject) { + + JoinColumnInAssociationOverrideDialog dialog = + new JoinColumnInAssociationOverrideDialog(shell(), subject); + + dialog.openDialog(buildAddJoinColumnPostExecution()); + } + + private void addJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) { + + IAssociationOverride associationOverride = stateObject.getAssociationOverride(); + int index = associationOverride.specifiedJoinColumnsSize(); + + IJoinColumn joinColumn = associationOverride.addSpecifiedJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); } - - private Adapter buildOverrideListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - overrideChanged(notification); + + private PostExecution<JoinColumnInAssociationOverrideDialog> buildAddJoinColumnPostExecution() { + return new PostExecution<JoinColumnInAssociationOverrideDialog>() { + public void execute(JoinColumnInAssociationOverrideDialog dialog) { + if (dialog.wasConfirmed()) { + addJoinColumn(dialog.subject()); + } } }; } - - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - Group attributeOverridesGroup = getWidgetFactory().createGroup( - composite, JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides); - attributeOverridesGroup.setLayout(new GridLayout(2, true)); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - attributeOverridesGroup.setLayoutData(gridData); - - this.listViewer = buildAttributeOverridesListViewer(attributeOverridesGroup); - gridData = new GridData(); - gridData.verticalSpan = 2; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - this.listViewer.getList().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.listViewer.getList(), IJpaHelpContextIds.ENTITY_ATTRIBUTE_OVERRIDES); - - this.overrideDefaultButton = - getWidgetFactory().createButton( - attributeOverridesGroup, - JptUiMappingsMessages.AttributeOverridesComposite_overridDefault, - SWT.CHECK); - this.overrideDefaultButton.addSelectionListener(buildOverrideDefaultSelectionListener()); - gridData = new GridData(); - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.overrideDefaultButton.setLayoutData(gridData); - - - this.overridePageBook = buildOverridePageBook(attributeOverridesGroup); - gridData = new GridData(); - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.overridePageBook.setLayoutData(gridData); - - this.joinColumnsComposite = new JoinColumnsComposite(this.overridePageBook, this.commandStack, getWidgetFactory(), JptUiMappingsMessages.OverridesComposite_joinColumn); - this.columnComposite = new ColumnComposite(this.overridePageBook, this.commandStack, getWidgetFactory()); - this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); - } - - protected PageBook buildOverridePageBook(Composite parent) { - return new PageBook(parent, SWT.NONE); + + private WritablePropertyValueModel<IAssociationOverride> buildAssociationOverrideHolder() { + return new SimplePropertyValueModel<IAssociationOverride>(); } - private SelectionListener buildOverrideDefaultSelectionListener() { - return new SelectionListener(){ - - public void widgetSelected(SelectionEvent e) { - overrideDefaultButtonSelected(e); - } - - public void widgetDefaultSelected(SelectionEvent e) { - overrideDefaultButtonSelected(e); + private PropertyValueModel<IColumn> buildColumnHolder() { + return new TransformationPropertyValueModel<IEntity, IColumn>(getSubjectHolder()) { + @Override + protected IColumn transform_(IEntity value) { + return null; //TODO } }; } - - private void overrideDefaultButtonSelected(SelectionEvent e) { - boolean selection = this.overrideDefaultButton.getSelection(); - if (selection) { - if (getSelectedOverride() instanceof IAttributeOverride) { - int index = this.entity.getSpecifiedAttributeOverrides().size(); - IAttributeOverride attributeOverride = this.entity.createAttributeOverride(index); - this.entity.getSpecifiedAttributeOverrides().add(attributeOverride); - attributeOverride.setName(this.selectedOverride.getName()); - attributeOverride.getColumn().setSpecifiedName(((IAttributeOverride) this.selectedOverride).getColumn().getName()); - } - else { - int index = this.entity.getSpecifiedAssociationOverrides().size(); - IAssociationOverride associationOverride = this.entity.createAssociationOverride(index); - String name = this.selectedOverride.getName(); - this.entity.getSpecifiedAssociationOverrides().add(associationOverride); - associationOverride.setName(name); - //attributeOverride.getColumn().setSpecifiedName(this.attributeOverride.getColumn().getName()); - } - } - else { - if (getSelectedOverride() instanceof IAttributeOverride) { - this.entity.getSpecifiedAttributeOverrides().remove(this.selectedOverride); - } - else { - this.entity.getSpecifiedAssociationOverrides().remove(this.selectedOverride); + + private PostExecution<JoinColumnInAssociationOverrideDialog> buildEditJoinColumnPostExecution() { + return new PostExecution<JoinColumnInAssociationOverrideDialog>() { + public void execute(JoinColumnInAssociationOverrideDialog dialog) { + if (dialog.wasConfirmed()) { + editJoinColumn(dialog.subject()); + } } - } + }; } - - - private ListViewer buildAttributeOverridesListViewer(Composite parent) { - ListViewer listViewer = new ListViewer(parent, SWT.SINGLE | SWT.BORDER); - listViewer.setLabelProvider(buildAttributeOverridesLabelProvider()); - listViewer.setContentProvider(buildAttributeOverridesContentProvider()); - - listViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - overridesListSelectionChanged(event); - } - }); - return listViewer; + private JoinColumnsProvider buildJoinColumnsEditor() { + return new JoinColumnsProvider(); } - - protected void overridesListSelectionChanged(SelectionChangedEvent event) { - if (((StructuredSelection) event.getSelection()).isEmpty()) { - this.columnComposite.populate(null); - this.columnComposite.enableWidgets(false); - this.overrideDefaultButton.setSelection(false); - this.overrideDefaultButton.setEnabled(false); - } - else { - this.selectedOverride = getSelectedOverride(); - if (this.selectedOverride instanceof IAttributeOverride) { - boolean specifiedOverride = this.entity.getSpecifiedAttributeOverrides().contains(this.selectedOverride); - this.overrideDefaultButton.setSelection(specifiedOverride); - this.overridePageBook.showPage(this.columnComposite.getControl()); - this.columnComposite.populate(((IAttributeOverride) this.selectedOverride).getColumn()); - this.columnComposite.enableWidgets(specifiedOverride); - this.overrideDefaultButton.setEnabled(true); - } - else { - boolean specifiedOverride = this.entity.getSpecifiedAssociationOverrides().contains(this.selectedOverride); - this.overrideDefaultButton.setSelection(specifiedOverride); - this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); - this.joinColumnsComposite.populate(new JoinColumnsOwner((IAssociationOverride) getSelectedOverride())); - this.joinColumnsComposite.enableWidgets(specifiedOverride); - this.overrideDefaultButton.setEnabled(true); + + private ListValueModel<IAssociationOverride> buildOverrideAttributesListHolder() { + return new ListAspectAdapter<IEntity, IAssociationOverride>( + getSubjectHolder(), + IEntity.DEFAULT_ASSOCIATION_OVERRIDES_LIST, + IEntity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST) + { + @Override + protected ListIterator<IAssociationOverride> listIterator_() { + return subject.associationOverrides(); } - } + }; } - - private ILabelProvider buildAttributeOverridesLabelProvider() { - return new LabelProvider() { - public String getText(Object element) { - //TODO also display column name somehow - return ((IOverride) element).getName(); + + private StringConverter<IAssociationOverride> buildOverrideAttributesStringConverter() { + return new StringConverter<IAssociationOverride>() { + public String convertToString(IAssociationOverride item) { + return item.displayString(); } }; } - - private IContentProvider buildAttributeOverridesContentProvider() { - return new IStructuredContentProvider() { - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public void dispose() { + private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { + return new PropertyAspectAdapter<IEntity, Boolean>(getSubjectHolder(), "") { + @Override + protected Boolean buildValue_() { + return true; } - - public Object[] getElements(Object inputElement) { - IEntity entity = (IEntity) inputElement; - return CollectionTools.addAll( - entity.getAttributeOverrides().toArray(new IOverride[entity.getAttributeOverrides().size()]), - entity.getAssociationOverrides()); + + @Override + protected void setValue_(Boolean value) { + // Not done here } }; } - private IOverride getSelectedOverride() { - return (IOverride) ((StructuredSelection) this.listViewer.getSelection()).getFirstElement(); - } - - - public void doPopulate(EObject obj) { - this.entity = (IEntity) obj; - if (this.entity == null) { - this.selectedOverride = null; - this.columnComposite.populate(null); - this.joinColumnsComposite.populate(null); - this.listViewer.setInput(null); - return; - } - - if (this.listViewer.getInput() != entity) { - this.listViewer.setInput(entity); - } - if (!this.entity.getAttributeOverrides().isEmpty()) { - if (this.listViewer.getSelection().isEmpty()) { - IOverride override = this.entity.getAttributeOverrides().get(0); - this.listViewer.setSelection(new StructuredSelection(override)); - } - else { - Object selection = ((StructuredSelection) this.listViewer.getSelection()).getFirstElement(); - if (selection instanceof IAttributeOverride) { - this.overridePageBook.showPage(this.columnComposite.getControl()); - this.columnComposite.enableWidgets(true); - this.columnComposite.populate(((IAttributeOverride) selection).getColumn()); - } - else { - this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); - this.joinColumnsComposite.enableWidgets(true); - this.joinColumnsComposite.populate(new JoinColumnsOwner((IAssociationOverride) selection)); - } + private SelectionListener buildOverrideDefaultSelectionListener() { + return new SelectionAdapter(){ + @Override + public void widgetSelected(SelectionEvent e) { + Button button = (Button) e.widget; + overrideDefaultButtonSelected(button.getSelection()); } - } - else { - this.columnComposite.populate(null); - this.columnComposite.enableWidgets(false); - } + }; } - @Override - protected void doPopulate() { - this.columnComposite.doPopulate(); - this.joinColumnsComposite.doPopulate(); - } - - @Override - protected void engageListeners() { - if (this.entity != null) { - this.entity.eAdapters().add(this.entityListener); - for (IOverride attributeOverride : this.entity.getAttributeOverrides()) { - attributeOverride.eAdapters().add(this.overrideListener); - } - for (IOverride attributeOverride : this.entity.getAssociationOverrides()) { - attributeOverride.eAdapters().add(this.overrideListener); - } - } - } - - @Override - protected void disengageListeners() { - if (this.entity != null) { - this.entity.eAdapters().remove(this.entityListener); - for (IOverride attributeOverride : this.entity.getAttributeOverrides()) { - attributeOverride.eAdapters().remove(this.overrideListener); - } - for (IOverride attributeOverride : this.entity.getAssociationOverrides()) { - attributeOverride.eAdapters().remove(this.overrideListener); - } - } + private PageBook buildOverridePageBook(Composite parent) { + return new PageBook(parent, SWT.NONE); } - - protected void entityChanged(Notification notification) { - switch (notification.getFeatureID(IEntity.class)) { - case JpaCoreMappingsPackage.IENTITY__SPECIFIED_ATTRIBUTE_OVERRIDES : - case JpaCoreMappingsPackage.IENTITY__SPECIFIED_ASSOCIATION_OVERRIDES : - case JpaCoreMappingsPackage.IENTITY__DEFAULT_ATTRIBUTE_OVERRIDES : - case JpaCoreMappingsPackage.IENTITY__DEFAULT_ASSOCIATION_OVERRIDES : - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (listViewer.getList().isDisposed()) { - return; - } - listViewer.refresh(); - } - }); - - if (notification.getEventType() == Notification.ADD) { - ((IOverride) notification.getNewValue()).eAdapters().add(this.overrideListener); - final Object newValue = notification.getNewValue(); - ((IOverride) newValue).eAdapters().add(this.overrideListener); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (listViewer.getList().isDisposed()) { - return; - } - listViewer.setSelection(new StructuredSelection(newValue)); - } - }); - } - else if (notification.getEventType() == Notification.ADD_MANY) { - List<IOverride> addedList = (List<IOverride>) notification.getNewValue(); - for (IOverride override : addedList) { - override.eAdapters().add(this.overrideListener); - } - } - else if (notification.getEventType() == Notification.REMOVE) { - ((IOverride) notification.getOldValue()).eAdapters().remove(this.overrideListener); - } - else if (notification.getEventType() == Notification.REMOVE_MANY) { - List<IOverride> removedList = (List<IOverride>) notification.getOldValue(); - for (IOverride override : removedList) { - override.eAdapters().remove(this.overrideListener); - } - } - break; - } + private ListValueModel<IAssociationOverride> buildSortedOverrideAttributesListHolder() { + return new SortedListValueModelAdapter<IAssociationOverride>( + buildOverrideAttributesListHolder() + ); } - protected void overrideChanged(Notification notification) { - switch (notification.getFeatureID(IOverride.class)) { - case JpaCoreMappingsPackage.IOVERRIDE__NAME : - final IOverride override = (IOverride) notification.getNotifier(); - Display.getDefault().asyncExec(new Runnable() { - public void run() { - OverridesComposite.this.listViewer.update(override, null); - } - }); - break; - default : - break; - } - } - - public void dispose() { - this.columnComposite.dispose(); - this.joinColumnsComposite.dispose(); - super.dispose(); - } - +// public void doPopulate(EObject obj) { +// this.entity = (IEntity) obj; +// if (this.entity == null) { +// this.selectedOverride = null; +// this.columnComposite.populate(null); +// this.joinColumnsComposite.populate(null); +// this.listViewer.setInput(null); +// return; +// } +// +// if (this.listViewer.getInput() != entity) { +// this.listViewer.setInput(entity); +// } +// if (!this.subject().getAttributeOverrides().isEmpty()) { +// if (this.listViewer.getSelection().isEmpty()) { +// IOverride override = this.subject().getAttributeOverrides().get(0); +// this.listViewer.setSelection(new StructuredSelection(override)); +// } +// else { +// Object selection = ((StructuredSelection) this.listViewer.getSelection()).getFirstElement(); +// if (selection instanceof IAttributeOverride) { +// this.overridePageBook.showPage(this.columnComposite.getControl()); +// this.columnComposite.enableWidgets(true); +// this.columnComposite.populate(((IAttributeOverride) selection).getColumn()); +// } +// else { +// this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); +// this.joinColumnsComposite.enableWidgets(true); +// this.joinColumnsComposite.populate(new JoinColumnsOwner((IAssociationOverride) selection)); +// } +// } +// } +// else { +// this.columnComposite.populate(null); +// this.ge.enableWidgets(false); +// } +// } - void addJoinColumn() { - JoinColumnInAssociationOverrideDialog dialog = new JoinColumnInAssociationOverrideDialog(this.getControl().getShell(), (IAssociationOverride) getSelectedOverride()); - this.addJoinColumnFromDialog(dialog); - } - - private void addJoinColumnFromDialog(JoinColumnInAssociationOverrideDialog dialog) { - if (dialog.open() != Window.OK) { - return; - } - int index = ((IAssociationOverride) getSelectedOverride()).getJoinColumns().size(); - IJoinColumn joinColumn = ((IAssociationOverride) getSelectedOverride()).createJoinColumn(index); - ((IAssociationOverride) getSelectedOverride()).getSpecifiedJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(dialog.getSelectedName()); - joinColumn.setSpecifiedReferencedColumnName(dialog.getReferencedColumnName()); - } + private void editJoinColumn(IJoinColumn joinColumn) { - void editJoinColumn(IJoinColumn joinColumn) { - JoinColumnInAssociationOverrideDialog dialog = new JoinColumnInAssociationOverrideDialog(this.getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); - } - - private void editJoinColumnFromDialog(JoinColumnInAssociationOverrideDialog dialog, IJoinColumn joinColumn) { - if (dialog.open() == Window.OK) { - editJoinColumnDialogOkd(dialog, joinColumn); - } + JoinColumnInAssociationOverrideDialog dialog = + new JoinColumnInAssociationOverrideDialog(shell(), joinColumn); + + dialog.openDialog(buildEditJoinColumnPostExecution()); } - - private void editJoinColumnDialogOkd(JoinColumnInAssociationOverrideDialog dialog, IJoinColumn joinColumn) { - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - if (dialog.isDefaultNameSelected()) { + private void editJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) { + + IJoinColumn joinColumn = stateObject.getJoinColumn(); + String name = stateObject.getSelectedName(); + String referencedColumnName = stateObject.getSpecifiedReferencedColumnName(); + + // Name + if (stateObject.isDefaultNameSelected()) { if (joinColumn.getSpecifiedName() != null) { joinColumn.setSpecifiedName(null); } } - else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){ + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + joinColumn.setSpecifiedName(name); } - - if (dialog.isDefaultReferencedColumnNameSelected()) { + + // Referenced Column Name + if (stateObject.isDefaultReferencedColumnNameSelected()) { if (joinColumn.getSpecifiedReferencedColumnName() != null) { joinColumn.setSpecifiedReferencedColumnName(null); } } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + else if (joinColumn.getSpecifiedReferencedColumnName() == null || + !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)) { + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } } - - private class JoinColumnsOwner extends JpaEObject implements Owner { - - IAssociationOverride associationOverride; - - public JoinColumnsOwner(IAssociationOverride associationOverride) { - super(); - this.associationOverride = associationOverride; - } - - public void addJoinColumn() { - OverridesComposite.this.addJoinColumn(); - } - - public boolean containsSpecifiedJoinColumns() { - return this.associationOverride.containsSpecifiedJoinColumns(); + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + WritablePropertyValueModel<IAssociationOverride> associationOverrideHolder = + buildAssociationOverrideHolder(); + + // Attribute Overrides group pane + container = buildTitledPane( + container, + JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides + ); + + List list = buildList( + container, + IJpaHelpContextIds.ENTITY_ATTRIBUTE_OVERRIDES + ); + + ListBoxModelAdapter.adapt( + buildSortedOverrideAttributesListHolder(), + associationOverrideHolder, + list, + buildOverrideAttributesStringConverter() + ); + + // Override Default check box + Button overrideDefaultButton = buildCheckBox( + container, + JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault, + buildOverrideDefaultHolder() + ); + + overrideDefaultButton.addSelectionListener( + buildOverrideDefaultSelectionListener() + ); + + // Override sub-pane +// PageBook overridePane = buildOverridePageBook(container); + + // Join Columns widgets + Group joinColumnGroupPane = buildTitledPane( + container, + JptUiMappingsMessages.OverridesComposite_joinColumn + ); + +// overridePane.showPage(joinColumnGroupPane); + + JoinColumnsComposite<IAssociationOverride> joinColumnsComposite = + new JoinColumnsComposite<IAssociationOverride>( + this, + associationOverrideHolder, + joinColumnGroupPane, + buildJoinColumnsEditor() + ); + + // Column widgets + new ColumnComposite( + this, + buildColumnHolder(), + joinColumnGroupPane + ); + +// overridePane.showPage(joinColumnsComposite.getControl()); + } + + private void overrideDefaultButtonSelected(boolean selected) { + + IEntity entity = subject(); + IOverride override = null; + + if (selected) { + if (override instanceof IAttributeOverride) { + int index = entity.specifiedAttributeOverridesSize(); + IAttributeOverride attributeOverride = entity.addSpecifiedAttributeOverride(index); + attributeOverride.setName(override.getName()); + attributeOverride.getColumn().setSpecifiedName(((IAttributeOverride) override).getColumn().getName()); + } + else { + int index = entity.specifiedAssociationOverridesSize(); + IAssociationOverride associationOverride = entity.addSpecifiedAssociationOverride(index); + associationOverride.setName(override.getName()); + //attributeOverride.getColumn().setSpecifiedName(this.attributeOverride.getColumn().getName()); + } } - - public IJoinColumn createJoinColumn(int index) { - return this.associationOverride.createJoinColumn(index); + else { + if (override instanceof IAttributeOverride) { + int index = CollectionTools.indexOf(entity.specifiedAttributeOverrides(), override); + this.subject().removeSpecifiedAttributeOverride(index); + } + else { + int index = CollectionTools.indexOf(entity.specifiedAssociationOverrides(), override); + this.subject().removeSpecifiedAssociationOverride(index); + } } - - public List<IJoinColumn> getJoinColumns() { - return this.associationOverride.getJoinColumns(); + } + + protected void overridesListSelectionChanged(SelectionChangedEvent event) { +// if (((StructuredSelection) event.getSelection()).isEmpty()) { +// this.columnComposite.populate(null); +// this.columnComposite.enableWidgets(false); +// this.overrideDefaultButton.setSelection(false); +// this.overrideDefaultButton.setEnabled(false); +// } +// else { +// this.selectedOverride = getSelectedOverride(); +// if (this.selectedOverride instanceof IAttributeOverride) { +// boolean specifiedOverride = this.subject().getSpecifiedAttributeOverrides().contains(this.selectedOverride); +// this.overrideDefaultButton.setSelection(specifiedOverride); +// this.overridePageBook.showPage(this.columnComposite.getControl()); +// this.columnComposite.populate(((IAttributeOverride) this.selectedOverride).getColumn()); +// this.columnComposite.enableWidgets(specifiedOverride); +// this.overrideDefaultButton.setEnabled(true); +// } +// else { +// boolean specifiedOverride = this.subject().getSpecifiedAssociationOverrides().contains(this.selectedOverride); +// this.overrideDefaultButton.setSelection(specifiedOverride); +// this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); +// this.joinColumnsComposite.populate(new JoinColumnsOwner((IAssociationOverride) getSelectedOverride())); +// this.joinColumnsComposite.enableWidgets(specifiedOverride); +// this.overrideDefaultButton.setEnabled(true); +// } +// } + } + + private class JoinColumnsProvider implements IJoinColumnsEditor<IAssociationOverride> { + + public void addJoinColumn(IAssociationOverride subject) { + OverridesComposite.this.addJoinColumn(subject); } - - public List<IJoinColumn> getSpecifiedJoinColumns() { - return this.associationOverride.getSpecifiedJoinColumns(); + + public void editJoinColumn(IAssociationOverride subject, IJoinColumn joinColumn) { + OverridesComposite.this.editJoinColumn(joinColumn); } - - public int specifiedJoinColumnsFeatureId() { - return JpaCoreMappingsPackage.IASSOCIATION_OVERRIDE__SPECIFIED_JOIN_COLUMNS; + + public boolean hasSpecifiedJoinColumns(IAssociationOverride subject) { + return subject.containsSpecifiedJoinColumns(); } - - public Class owningFeatureClass() { - return IAssociationOverride.class; + + public ListIterator<IJoinColumn> joinColumns(IAssociationOverride subject) { + return subject.joinColumns(); } - - public void editJoinColumn(IJoinColumn joinColumn) { - OverridesComposite.this.editJoinColumn(joinColumn); + + public String[] propertyNames() { + return new String[] { + IAssociationOverride.DEFAULT_JOIN_COLUMNS_LIST, + IAssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST + }; } - - public EObject getEObject() { - return this.associationOverride; + + public void removeJoinColumns(IAssociationOverride subject, int[] selectedIndices) { + for (int index = selectedIndices.length; --index >= 0; ) { + subject.removeSpecifiedJoinColumn(selectedIndices[index]); + } } } - - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialog.java index f7aa9653e9..0730af9ab2 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialog.java @@ -1,37 +1,81 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.mappings.details; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; -import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IPrimaryKeyJoinColumn; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; -public class PrimaryKeyJoinColumnDialog extends AbstractJoinColumnDialog<IPrimaryKeyJoinColumn> { +/** + * TODO + * + * @see PrimaryKeyJoinColumnStateObject + * @see PrimaryKeyJoinColumnDialogPane + * + * @version 2.0 + * @since 2.0 + */ +public class PrimaryKeyJoinColumnDialog extends AbstractJoinColumnDialog<PrimaryKeyJoinColumnStateObject> { private IEntity entity; - - PrimaryKeyJoinColumnDialog(Shell parent, IEntity entity) { + + /** + * Creates a new <code>PrimaryKeyJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param entity + */ + public PrimaryKeyJoinColumnDialog(Shell parent, IEntity entity) { + super(parent); this.entity = entity; } - PrimaryKeyJoinColumnDialog(Shell parent, IPrimaryKeyJoinColumn joinColumn) { + /** + * Creates a new <code>PrimaryKeyJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public PrimaryKeyJoinColumnDialog(Shell parent, + IPrimaryKeyJoinColumn joinColumn) { + super(parent, joinColumn); - this.entity = (IEntity) joinColumn.eContainer(); } - protected Table getNameTable() { - return this.entity.primaryDbTable(); + /* + * (non-Javadoc) + */ + @Override + protected PrimaryKeyJoinColumnStateObject buildStateObject() { + + if (entity != null) { + return new PrimaryKeyJoinColumnStateObject(entity); + } + + return new PrimaryKeyJoinColumnStateObject(getJoinColumn()); + } + + /* + * (non-Javadoc) + */ + @Override + public IPrimaryKeyJoinColumn getJoinColumn() { + return (IPrimaryKeyJoinColumn) super.getJoinColumn(); } - - protected Table getReferencedNameTable() { - return this.entity.parentEntity().primaryDbTable(); + + /* + * (non-Javadoc) + */ + @Override + protected void initializeMainPane(Composite container) { + new PrimaryKeyJoinColumnDialogPane(getSubjectHolder(), container); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialogPane.java new file mode 100644 index 0000000000..daf01a4d83 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialogPane.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * TODO: + * + * @see PrimaryKeyJoinColumnStateObject + * @see PrimaryKeyJoinColumnDialog - The parent container + * + * @version 2.0 + * @since 2.0 + */ +public final class PrimaryKeyJoinColumnDialogPane extends AbstractJoinColumnDialogPane<PrimaryKeyJoinColumnStateObject> +{ + /** + * Creates a new <code>PrimaryKeyJoinColumnDialogPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public PrimaryKeyJoinColumnDialogPane(PropertyValueModel<PrimaryKeyJoinColumnStateObject> subjectHolder, + Composite parent) { + + super(subjectHolder, parent); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + super.initializeLayout(container); + + // TODO + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java index 51a220df88..9330f4d6a2 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java @@ -1,37 +1,85 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. This + * 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.ui.internal.mappings.details; -import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; -import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.core.internal.context.base.IPrimaryKeyJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISecondaryTable; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; -public class PrimaryKeyJoinColumnInSecondaryTableDialog extends AbstractJoinColumnDialog<IPrimaryKeyJoinColumn> { +/** + * TODO + * + * @see PrimaryKeyJoinColumnInSecondaryTableStateObject + * @see AbstractJoinColumnDialogPane + * + * @version 2.0 + * @since 2.0 + */ +public class PrimaryKeyJoinColumnInSecondaryTableDialog extends AbstractJoinColumnDialog<PrimaryKeyJoinColumnInSecondaryTableStateObject> { private ISecondaryTable secondaryTable; - - PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, ISecondaryTable secondaryTable) { + + /** + * Creates a new <code>PrimaryKeyJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param joinColumn + */ + public PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, + IPrimaryKeyJoinColumn joinColumn) { + + super(parent, joinColumn); + } + + /** + * Creates a new <code>PrimaryKeyJoinColumnDialog</code>. + * + * @param parent The parent shell + * @param secondaryTable + */ + public PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, + ISecondaryTable secondaryTable) { + super(parent); this.secondaryTable = secondaryTable; } - PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, IPrimaryKeyJoinColumn joinColumn) { - super(parent, joinColumn); - this.secondaryTable = (ISecondaryTable) joinColumn.eContainer(); + /* + * (non-Javadoc) + */ + @Override + protected PrimaryKeyJoinColumnInSecondaryTableStateObject buildStateObject() { + + if (secondaryTable != null) { + return new PrimaryKeyJoinColumnInSecondaryTableStateObject(secondaryTable); + } + + return new PrimaryKeyJoinColumnInSecondaryTableStateObject(getJoinColumn()); } - protected Table getNameTable() { - return this.secondaryTable.dbTable(); + /* + * (non-Javadoc) + */ + @Override + public IPrimaryKeyJoinColumn getJoinColumn() { + return (IPrimaryKeyJoinColumn) super.getJoinColumn(); } - - protected Table getReferencedNameTable() { - return this.secondaryTable.typeMapping().primaryDbTable(); + + /* + * (non-Javadoc) + */ + @Override + protected void initializeMainPane(Composite container) { + new AbstractJoinColumnDialogPane<PrimaryKeyJoinColumnInSecondaryTableStateObject>( + getSubjectHolder(), + container + ); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableStateObject.java new file mode 100644 index 0000000000..1ddea501df --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableStateObject.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IPrimaryKeyJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISecondaryTable; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; +import org.eclipse.jpt.db.internal.Table; + +/** + * @version 2.0 + * @since 2.0 + */ +public final class PrimaryKeyJoinColumnInSecondaryTableStateObject extends AbstractJoinColumnStateObject +{ + private ISecondaryTable secondaryTable; + + /** + * Creates a new <code>PrimaryKeyJoinColumnInSecondaryTableStateObject</code>. + * + * @param joinColumn + */ + public PrimaryKeyJoinColumnInSecondaryTableStateObject(IPrimaryKeyJoinColumn joinColumn) { + super(joinColumn); + this.secondaryTable = (ISecondaryTable) joinColumn.parent(); + } + + /** + * Creates a new <code>PrimaryKeyJoinColumnInSecondaryTableStateObject</code>. + * + * @param secondaryTable + */ + public PrimaryKeyJoinColumnInSecondaryTableStateObject(ISecondaryTable secondaryTable) { + super(); + this.secondaryTable = secondaryTable; + } + + /* + * (non-Javadoc) + */ + @Override + public IPrimaryKeyJoinColumn getJoinColumn() { + return (IPrimaryKeyJoinColumn) super.getJoinColumn(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getNameTable() { + return secondaryTable.dbTable(); + } + + /* (non-Javadoc) + */ + @Override + public Table getReferencedNameTable() { + ITypeMapping type = (ITypeMapping) secondaryTable.parent(); + return type.primaryDbTable(); + } + + public ISecondaryTable getSecondaryTable() { + return secondaryTable; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnStateObject.java new file mode 100644 index 0000000000..0a584ed815 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnStateObject.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IPrimaryKeyJoinColumn; +import org.eclipse.jpt.db.internal.Table; + +/** + * @version 2.0 + * @since 2.0 + */ +final class PrimaryKeyJoinColumnStateObject extends AbstractJoinColumnStateObject +{ + private IEntity entity; + + /** + * Creates a new <code>PrimaryKeyJoinColumnStateObject</code>. + * + * @param entity + */ + public PrimaryKeyJoinColumnStateObject(IEntity entity) { + super(); + this.entity = entity; + } + + /** + * Creates a new <code>PrimaryKeyJoinColumnStateObject</code>. + * + * @param joinColumn + */ + public PrimaryKeyJoinColumnStateObject(IPrimaryKeyJoinColumn joinColumn) { + super(joinColumn); + this.entity = (IEntity) joinColumn.parent(); + } + + /* + * (non-Javadoc) + */ + @Override + public IPrimaryKeyJoinColumn getJoinColumn() { + return (IPrimaryKeyJoinColumn) super.getJoinColumn(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getNameTable() { + return entity.primaryDbTable(); + } + + /* + * (non-Javadoc) + */ + @Override + public Table getReferencedNameTable() { + return entity.parentEntity().primaryDbTable(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java index e870bfcac8..d307c8559f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java @@ -1,405 +1,341 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; +import java.util.ListIterator; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.INamedColumn; -import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.IJoinColumn; +import org.eclipse.jpt.core.internal.context.base.IPrimaryKeyJoinColumn; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.AbstractAdapter; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; 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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class PrimaryKeyJoinColumnsComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | x Override Default Join Columns | + * | | + * | - Primary Key Join Columns ---------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IEntity + * @see InheritanceComposite - The container of this pane + * + * @version 2.0 + * @since 2.0 + */ +public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> { - private IEntity entity; - private final Adapter entityListener; - private final Adapter pkJoinColumnListener; - - ListViewer pkJoinColumnsListViewer; - - private Group pkJoinColumnsGroup; - Button overrideDefaultJoinColumnsCheckBox; - private Button pkJoinColumnsRemoveButton; - private Button pkJoinColumnsEditButton; - - - public PrimaryKeyJoinColumnsComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.entityListener = buildEntityListener(); - this.pkJoinColumnListener = buildPkJoinColumnListener(); + private Button overrideDefaultJoinColumnsCheckBox; + + /** + * Creates a new <code>PrimaryKeyJoinColumnsComposite</code>. + * + * @param parentPane The parent controller of this one + * @param parent The parent container + */ + public PrimaryKeyJoinColumnsComposite(AbstractFormPane<? extends IEntity> subjectHolder, + Composite parent) { + + super(subjectHolder, parent); } - - private Adapter buildEntityListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - entityChanged(notification); - } - }; + + /** + * Creates a new <code>PrimaryKeyJoinColumnsComposite</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public PrimaryKeyJoinColumnsComposite(PropertyValueModel<? extends IEntity> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - - private Adapter buildPkJoinColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - pkJoinColumnChanged(notification); + + private void addJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { + + int index = subject().specifiedPrimaryKeyJoinColumnsSize(); + + IPrimaryKeyJoinColumn joinColumn = subject().addSpecifiedPrimaryKeyJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); + } + + private void addPrimaryKeyJoinColumn() { + PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog(shell(), subject()); + dialog.openDialog(buildAddPrimaryKeyJoinColumnPostExecution()); + } + + private PostExecution<PrimaryKeyJoinColumnDialog> buildAddPrimaryKeyJoinColumnPostExecution() { + return new PostExecution<PrimaryKeyJoinColumnDialog>() { + public void execute(PrimaryKeyJoinColumnDialog dialog) { + if (dialog.wasConfirmed()) { + addJoinColumn(dialog.subject()); + } } }; } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - GridData gridData = new GridData(); - this.overrideDefaultJoinColumnsCheckBox = getWidgetFactory().createButton( - composite, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, - SWT.CHECK); - this.overrideDefaultJoinColumnsCheckBox.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - if (PrimaryKeyJoinColumnsComposite.this.overrideDefaultJoinColumnsCheckBox.getSelection()) { - IPrimaryKeyJoinColumn defaultJoinColumn = PrimaryKeyJoinColumnsComposite.this.entity.getDefaultPrimaryKeyJoinColumns().get(0); - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IPrimaryKeyJoinColumn pkJoinColumn = PrimaryKeyJoinColumnsComposite.this.entity.createPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumnsComposite.this.entity.getSpecifiedPrimaryKeyJoinColumns().add(pkJoinColumn); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } else { - PrimaryKeyJoinColumnsComposite.this.entity.getSpecifiedPrimaryKeyJoinColumns().clear(); + + String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + } + + private PostExecution<PrimaryKeyJoinColumnDialog> buildEditPrimaryKeyJoinColumnPostExecution() { + return new PostExecution<PrimaryKeyJoinColumnDialog>() { + public void execute(PrimaryKeyJoinColumnDialog dialog) { + if (dialog.wasConfirmed()) { + editJoinColumn(dialog.subject()); } } - }); - - this.pkJoinColumnsGroup = - getWidgetFactory().createGroup( - composite, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn); - this.pkJoinColumnsGroup.setLayout(new GridLayout(2, false)); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.pkJoinColumnsGroup.setLayoutData(gridData); - - this.pkJoinColumnsListViewer = new ListViewer(this.pkJoinColumnsGroup, SWT.BORDER | SWT.MULTI); - this.pkJoinColumnsListViewer.setContentProvider(buildJoinColumnsListContentProvider()); - this.pkJoinColumnsListViewer.setLabelProvider(buildJoinColumnsListLabelProvider()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.verticalSpan = 3; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.pkJoinColumnsListViewer.getList().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.pkJoinColumnsListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS); - - Button addJoinColumnButton = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_add, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - addJoinColumnButton.setLayoutData(gridData); - addJoinColumnButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing + }; + } + + private WritablePropertyValueModel<IJoinColumn> buildJoinColumnHolder() { + return new SimplePropertyValueModel<IJoinColumn>(); + } + + private String buildJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { + if (joinColumn.getSpecifiedName() == null) { + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind( + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); } - - public void widgetSelected(SelectionEvent e) { + + return NLS.bind( + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind( + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + return NLS.bind( + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); + } + + private Adapter buildJoinColumnsAdapter() { + return new AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { addPrimaryKeyJoinColumn(); } - }); - - this.pkJoinColumnsEditButton = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit, - SWT.NONE); - this.pkJoinColumnsEditButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - editPrimaryKeyJoinColumn(); + + @Override + public boolean hasOptionalButton() { + return true; } - }); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.pkJoinColumnsEditButton.setLayoutData(gridData); - - this.pkJoinColumnsRemoveButton = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_remove, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.BEGINNING; - this.pkJoinColumnsRemoveButton.setLayoutData(gridData); - this.pkJoinColumnsRemoveButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing + + @Override + public String optionalButtonText() { + return JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit; } - - public void widgetSelected(SelectionEvent e) { - removePrimaryKeyJoinColumn(); + + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + editPrimaryKeyJoinColumn(listSelectionModel); } - }); - - this.pkJoinColumnsListViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updatePrimaryKeyJoinColumnsEnablement(); + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + + int[] selectedIndices = listSelectionModel.selectedIndices(); + IEntity entity = subject(); + + for (int index = selectedIndices.length; --index >= 0; ) { + entity.removeSpecifiedPrimaryKeyJoinColumn(selectedIndices[index]); + } } - }); + }; } - - private IContentProvider buildJoinColumnsListContentProvider() { - return new IStructuredContentProvider(){ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public Object[] getElements(Object inputElement) { - return ((IEntity) inputElement).getPrimaryKeyJoinColumns().toArray(); + + private ListValueModel<IPrimaryKeyJoinColumn> buildJoinColumnsListHolder() { + return new ListAspectAdapter<IEntity, IPrimaryKeyJoinColumn>( + getSubjectHolder(), + IEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST, + IEntity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) + { + @Override + protected ListIterator<IPrimaryKeyJoinColumn> listIterator_() { + return subject.primaryKeyJoinColumns(); } }; } - + private ILabelProvider buildJoinColumnsListLabelProvider() { return new LabelProvider() { + @Override public String getText(Object element) { IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) element; - return (PrimaryKeyJoinColumnsComposite.this.entity.containsSpecifiedPrimaryKeyJoinColumns()) ? - buildJoinColumnLabel(joinColumn) - : + return subject().specifiedPrimaryKeyJoinColumnsSize() > 0 ? + buildJoinColumnLabel(joinColumn) : buildDefaultJoinColumnLabel(joinColumn); } }; } - - String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + + private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() { + // TODO + return new SimplePropertyValueModel<Boolean>(); } - - String buildJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - if (joinColumn.getSpecifiedName() == null) { - if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName()); + + private SelectionAdapter buildOverrideDefaultJoinColumnSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Button button = (Button) e.widget; + IEntity entity = subject(); + + if (button.getSelection()) { + IPrimaryKeyJoinColumn defaultJoinColumn = entity.specifiedPrimaryKeyJoinColumns().next(); + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IPrimaryKeyJoinColumn pkJoinColumn = entity.addSpecifiedPrimaryKeyJoinColumn(0); + pkJoinColumn.setSpecifiedName(columnName); + pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + else { + for (int index = entity.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { + entity.removeSpecifiedPrimaryKeyJoinColumn(index); + } + } } - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } + }; } - - void addPrimaryKeyJoinColumn() { - PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog(this.getControl().getShell(), this.entity); - addJoinColumnFromDialog(dialog); - } - - private void addJoinColumnFromDialog(PrimaryKeyJoinColumnDialog dialog) { - if (dialog.open() == Window.OK) { - int index = this.entity.getSpecifiedPrimaryKeyJoinColumns().size(); - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - IPrimaryKeyJoinColumn joinColumn = this.entity.createPrimaryKeyJoinColumn(index); - this.entity.getSpecifiedPrimaryKeyJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(name); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - - private IPrimaryKeyJoinColumn getSelectedJoinColumn() { - return (IPrimaryKeyJoinColumn) ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).getFirstElement(); + private ListValueModel/*<IPrimaryKeyJoinColumn>*/ buildSortedJoinColumnsListHolder() { + return new SortedListValueModelAdapter<IPrimaryKeyJoinColumn>( + buildJoinColumnsListHolder() + ); } - void editPrimaryKeyJoinColumn() { - IPrimaryKeyJoinColumn joinColumn = getSelectedJoinColumn(); - PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog(this.getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); - } - - private void editJoinColumnFromDialog(PrimaryKeyJoinColumnDialog dialog, IPrimaryKeyJoinColumn joinColumn) { - if (dialog.open() == Window.OK) { - editJoinColumnDialogOkd(dialog, joinColumn); - } + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + overrideDefaultJoinColumnsCheckBox.setSelection(subject().specifiedPrimaryKeyJoinColumnsSize() > 0); } - - private void editJoinColumnDialogOkd(PrimaryKeyJoinColumnDialog dialog, IPrimaryKeyJoinColumn joinColumn) { - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - if (dialog.isDefaultNameSelected()) { + private void editJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { + + IPrimaryKeyJoinColumn joinColumn = stateObject.getJoinColumn(); + + String name = stateObject.getSelectedName(); + String referencedColumnName = stateObject.getSpecifiedReferencedColumnName(); + + // Name + if (stateObject.isDefaultNameSelected()) { if (joinColumn.getSpecifiedName() != null) { joinColumn.setSpecifiedName(null); } } - else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){ + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + joinColumn.setSpecifiedName(name); } - - if (dialog.isDefaultReferencedColumnNameSelected()) { + + // Referenced Column Name + if (stateObject.isDefaultReferencedColumnNameSelected()) { if (joinColumn.getSpecifiedReferencedColumnName() != null) { joinColumn.setSpecifiedReferencedColumnName(null); } } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + else if (joinColumn.getSpecifiedReferencedColumnName() == null || + !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } } - - void removePrimaryKeyJoinColumn() { - ISelection selection = this.pkJoinColumnsListViewer.getSelection(); - if (selection instanceof StructuredSelection) { - for (Iterator i = ((StructuredSelection) selection).iterator(); i.hasNext(); ) { - this.entity.getPrimaryKeyJoinColumns().remove(i.next()); - } - } - } - - void updatePrimaryKeyJoinColumnsEnablement() { - boolean groupEnabledState = this.entity.containsSpecifiedPrimaryKeyJoinColumns(); - enableGroup(this.pkJoinColumnsGroup, groupEnabledState); - this.pkJoinColumnsRemoveButton.setEnabled(groupEnabledState && !((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).isEmpty()); - this.pkJoinColumnsEditButton.setEnabled(groupEnabledState && ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).size() == 1); - } - - private void enableGroup(Group group, boolean enabled) { - group.setEnabled(enabled); - for (int i = 0; i < group.getChildren().length; i++) { - group.getChildren()[i].setEnabled(enabled); - } - } - - - public void doPopulate(EObject obj) { - this.entity = (IEntity) obj; - if (this.entity == null) { - this.pkJoinColumnsListViewer.setInput(null); - return; - } - - this.pkJoinColumnsListViewer.setInput(this.entity); - + private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { - updatePrimaryKeyJoinColumnsEnablement(); - this.overrideDefaultJoinColumnsCheckBox.setSelection(this.entity.containsSpecifiedPrimaryKeyJoinColumns()); + IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) listSelectionModel.selectedValue(); + + PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog(shell(), joinColumn); + dialog.openDialog(buildEditPrimaryKeyJoinColumnPostExecution()); } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { - } + protected void initializeLayout(Composite container) { - protected void engageListeners() { - if (this.entity != null) { - this.entity.eAdapters().add(this.entityListener); - for (IPrimaryKeyJoinColumn pkJoinColumn : this.entity.getPrimaryKeyJoinColumns()) { - pkJoinColumn.eAdapters().add(this.pkJoinColumnListener); - } - //this.addConnectionListener(); - } - } - - protected void disengageListeners() { - if (this.entity != null) { - //this.removeConnectionListener(); - for (IPrimaryKeyJoinColumn pkJoinColumn : this.entity.getPrimaryKeyJoinColumns()) { - pkJoinColumn.eAdapters().remove(this.pkJoinColumnListener); - } - this.entity.eAdapters().remove(this.entityListener); - } - } - - protected void entityChanged(Notification notification) { - if (notification.getFeatureID(IEntity.class) == JpaCoreMappingsPackage.IENTITY__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS) { - if (notification.getEventType() == Notification.ADD) { - ((IPrimaryKeyJoinColumn) notification.getNewValue()).eAdapters().add(this.pkJoinColumnListener); - } - else if (notification.getEventType() == Notification.REMOVE) { - ((IPrimaryKeyJoinColumn) notification.getOldValue()).eAdapters().remove(this.pkJoinColumnListener); - } - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - pkJoinColumnsListViewer.refresh(); - overrideDefaultJoinColumnsCheckBox.setSelection(entity.containsSpecifiedPrimaryKeyJoinColumns()); - updatePrimaryKeyJoinColumnsEnablement(); - } - }); - } - } + int groupBoxMargin = groupBoxMargin(); - protected void pkJoinColumnChanged(Notification notification) { - if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__SPECIFIED_REFERENCED_COLUMN_NAME - || notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__DEFAULT_REFERENCED_COLUMN_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - pkJoinColumnsListViewer.refresh(); - } - }); - } + // Override Default Join Columns check box + overrideDefaultJoinColumnsCheckBox = buildCheckBox( + buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, + buildOverrideDefaultJoinColumnHolder()); + + overrideDefaultJoinColumnsCheckBox.addSelectionListener( + buildOverrideDefaultJoinColumnSelectionListener() + ); + + // Primary Key Join Columns group pane + Group pkJoinColumnsGroup = buildTitledPane( + container, + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn + ); + + // Primary Key Join Columns list pane + new AddRemoveListPane<IEntity>( + this, + pkJoinColumnsGroup, + buildJoinColumnsAdapter(), + buildSortedJoinColumnsListHolder(), + buildJoinColumnHolder(), + buildJoinColumnsListLabelProvider(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS + ); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java index 8b06e17166..17266c904c 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java @@ -1,413 +1,415 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; +import java.util.ListIterator; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn; -import org.eclipse.jpt.core.internal.mappings.INamedColumn; -import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.core.internal.context.base.IPrimaryKeyJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISecondaryTable; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.util.ControlEnabler; +import org.eclipse.jpt.ui.internal.util.PaneEnabler; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -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; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | x Override Default | + * | | + * | - Primary Key Join Columns ---------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see ISecondaryTable + * @see EntityComposite - The container of this pane + * @see AddRemoveListPane + * + * @version 2.0 + * @since 1.0 + */ +public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractFormPane<ISecondaryTable> { - private ISecondaryTable secondaryTable; - private final Adapter secondaryTableListener; - private final Adapter pkJoinColumnListener; - - ListViewer pkJoinColumnsListViewer; - - private Group pkJoinColumnsGroup; - Button overrideDefaultJoinColumnsCheckBox; - private Button pkJoinColumnsAddButton; - private Button pkJoinColumnsRemoveButton; - private Button pkJoinColumnsEditButton; - - - public PrimaryKeyJoinColumnsInSecondaryTableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.secondaryTableListener = buildSecondaryTableListener(); - this.pkJoinColumnListener = buildPkJoinColumnListener(); + /** + * Creates a new <code>PrimaryKeyJoinColumnsInSecondaryTableComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public PrimaryKeyJoinColumnsInSecondaryTableComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends ISecondaryTable> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + /** + * Creates a new <code>PrimaryKeyJoinColumnsInSecondaryTableComposite</code>. + * + * @param subjectHolder The holder of the subject <code>ISecondaryTable</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public PrimaryKeyJoinColumnsInSecondaryTableComposite(PropertyValueModel<? extends ISecondaryTable> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private void addJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { + + ISecondaryTable secondaryTable = stateObject.getSecondaryTable(); + int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); + + IPrimaryKeyJoinColumn joinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); } - - private Adapter buildSecondaryTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - secondaryTableChanged(notification); + + private void addPrimaryKeyJoinColumn() { + + PrimaryKeyJoinColumnInSecondaryTableDialog dialog = + new PrimaryKeyJoinColumnInSecondaryTableDialog(shell(), subject()); + + dialog.openDialog(buildAddPrimaryKeyJoinColumnPostExecution()); + } + + private PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog> buildAddPrimaryKeyJoinColumnPostExecution() { + return new PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog>() { + public void execute(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { + if (dialog.wasConfirmed()) { + addJoinColumn(dialog.subject()); + } } }; } - - private Adapter buildPkJoinColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - pkJoinColumnChanged(notification); + + private PropertyValueModel<Boolean> buildControlBooleanHolder() { + return new TransformationPropertyValueModel<ISecondaryTable, Boolean>(getSubjectHolder()) { + @Override + protected Boolean transform(ISecondaryTable value) { + return (value != null); } }; } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - GridData gridData = new GridData(); - this.overrideDefaultJoinColumnsCheckBox = getWidgetFactory().createButton( - composite, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, - SWT.CHECK); - this.overrideDefaultJoinColumnsCheckBox.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - if (PrimaryKeyJoinColumnsInSecondaryTableComposite.this.overrideDefaultJoinColumnsCheckBox.getSelection()) { - IPrimaryKeyJoinColumn defaultJoinColumn = PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.getDefaultPrimaryKeyJoinColumns().get(0); - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IPrimaryKeyJoinColumn pkJoinColumn = PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.createPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().add(pkJoinColumn); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } else { - PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().clear(); + + private String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + } + + private PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog> buildEditPrimaryKeyJoinColumnPostExecution() { + return new PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog>() { + public void execute(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { + if (dialog.wasConfirmed()) { + editPrimaryKeyJoinColumn(dialog.subject()); } } - }); - - this.pkJoinColumnsGroup = - getWidgetFactory().createGroup( - composite, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn); - this.pkJoinColumnsGroup.setLayout(new GridLayout(2, false)); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - this.pkJoinColumnsGroup.setLayoutData(gridData); - - this.pkJoinColumnsListViewer = new ListViewer(this.pkJoinColumnsGroup, SWT.BORDER | SWT.MULTI); - this.pkJoinColumnsListViewer.setContentProvider(buildJoinColumnsListContentProvider()); - this.pkJoinColumnsListViewer.setLabelProvider(buildJoinColumnsListLabelProvider()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.verticalSpan = 3; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.pkJoinColumnsListViewer.getList().setLayoutData(gridData); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.pkJoinColumnsListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS); - - this.pkJoinColumnsAddButton = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_add, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.pkJoinColumnsAddButton.setLayoutData(gridData); - this.pkJoinColumnsAddButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - addPrimaryKeyJoinColumn(); - } - }); - - this.pkJoinColumnsEditButton = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit, - SWT.NONE); - this.pkJoinColumnsEditButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - editPrimaryKeyJoinColumn(); - } - }); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.pkJoinColumnsEditButton.setLayoutData(gridData); - - this.pkJoinColumnsRemoveButton = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_remove, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.BEGINNING; - this.pkJoinColumnsRemoveButton.setLayoutData(gridData); - this.pkJoinColumnsRemoveButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - removePrimaryKeyJoinColumn(); - } - }); - - this.pkJoinColumnsListViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updatePrimaryKeyJoinColumnsEnablement(); - } - }); + }; } - - private IContentProvider buildJoinColumnsListContentProvider() { - return new IStructuredContentProvider(){ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public Object[] getElements(Object inputElement) { - return ((ISecondaryTable) inputElement).getPrimaryKeyJoinColumns().toArray(); + + private String buildJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { + if (joinColumn.getSpecifiedName() == null) { + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName()); } - }; + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + } + + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + } + + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName()); } - + private ILabelProvider buildJoinColumnsListLabelProvider() { return new LabelProvider() { + @Override public String getText(Object element) { IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) element; - return (PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns()) ? - buildJoinColumnLabel(joinColumn) - : + return subject().specifiedPrimaryKeyJoinColumnsSize() > 0 ? + buildJoinColumnLabel(joinColumn) : buildDefaultJoinColumnLabel(joinColumn); } }; } - - String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + + private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { + return new OverrideDefaultValueModel(getSubjectHolder()); } - - String buildJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - if (joinColumn.getSpecifiedName() == null) { - if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName()); + + private AddRemovePane.Adapter buildPrimaryKeyJoinColumnAdapter() { + return new AddRemovePane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPrimaryKeyJoinColumn(); + } + + @Override + public boolean hasOptionalButton() { + return true; + } + + @Override + public String optionalButtonText() { + return JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit; } - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - else { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName()); - } - } - - void addPrimaryKeyJoinColumn() { - PrimaryKeyJoinColumnInSecondaryTableDialog dialog = new PrimaryKeyJoinColumnInSecondaryTableDialog(this.getControl().getShell(), this.secondaryTable); - addJoinColumnFromDialog(dialog); + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + editPrimaryKeyJoinColumn(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + removePrimaryKeyJoinColumn(listSelectionModel); + } + }; } - - private void addJoinColumnFromDialog(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { - if (dialog.open() == Window.OK) { - int index = this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().size(); - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - IPrimaryKeyJoinColumn joinColumn = this.secondaryTable.createPrimaryKeyJoinColumn(index); - this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().add(joinColumn); - joinColumn.setSpecifiedName(name); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } + + private WritablePropertyValueModel<IPrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnHolder() { + return new SimplePropertyValueModel<IPrimaryKeyJoinColumn>(); } - - private IPrimaryKeyJoinColumn getSelectedJoinColumn() { - return (IPrimaryKeyJoinColumn) ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).getFirstElement(); + + private ListValueModel<IPrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnListHolder() { + return new ListAspectAdapter<ISecondaryTable, IPrimaryKeyJoinColumn>( + getSubjectHolder(), + ISecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST, + ISecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) + { + @Override + protected ListIterator<IPrimaryKeyJoinColumn> listIterator_() { + return subject.primaryKeyJoinColumns(); + } + }; } - void editPrimaryKeyJoinColumn() { - IPrimaryKeyJoinColumn joinColumn = getSelectedJoinColumn(); - PrimaryKeyJoinColumnInSecondaryTableDialog dialog = new PrimaryKeyJoinColumnInSecondaryTableDialog(this.getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); + private ListValueModel<IPrimaryKeyJoinColumn> buildSortedPrimaryKeyJoinColumnListHolder() { + return new SortedListValueModelAdapter<IPrimaryKeyJoinColumn>( + buildPrimaryKeyJoinColumnListHolder() + ); } - - private void editJoinColumnFromDialog(PrimaryKeyJoinColumnInSecondaryTableDialog dialog, IPrimaryKeyJoinColumn joinColumn) { - if (dialog.open() == Window.OK) { - editJoinColumnDialogOkd(dialog, joinColumn); - } + + private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { + + IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) listSelectionModel.selectedValue(); + + PrimaryKeyJoinColumnInSecondaryTableDialog dialog = + new PrimaryKeyJoinColumnInSecondaryTableDialog(shell(), joinColumn); + + dialog.openDialog(buildEditPrimaryKeyJoinColumnPostExecution()); } - - private void editJoinColumnDialogOkd(PrimaryKeyJoinColumnInSecondaryTableDialog dialog, IPrimaryKeyJoinColumn joinColumn) { - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - if (dialog.isDefaultNameSelected()) { + private void editPrimaryKeyJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { + IPrimaryKeyJoinColumn joinColumn = stateObject.getJoinColumn(); + String name = stateObject.getSelectedName(); + String referencedColumnName = stateObject.getSpecifiedReferencedColumnName(); + + // Name + if (stateObject.isDefaultNameSelected()) { if (joinColumn.getSpecifiedName() != null) { joinColumn.setSpecifiedName(null); } } - else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){ + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + joinColumn.setSpecifiedName(name); } - - if (dialog.isDefaultReferencedColumnNameSelected()) { + + // Referenced Column Name + if (stateObject.isDefaultReferencedColumnNameSelected()) { if (joinColumn.getSpecifiedReferencedColumnName() != null) { joinColumn.setSpecifiedReferencedColumnName(null); } } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + else if (joinColumn.getSpecifiedReferencedColumnName() == null || + !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } } - - void removePrimaryKeyJoinColumn() { - ISelection selection = this.pkJoinColumnsListViewer.getSelection(); - if (selection instanceof StructuredSelection) { - for (Iterator i = ((StructuredSelection) selection).iterator(); i.hasNext(); ) { - this.secondaryTable.getPrimaryKeyJoinColumns().remove(i.next()); - } - } - } - - void updatePrimaryKeyJoinColumnsEnablement() { - boolean groupEnabledState = this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns(); - enableGroup(this.pkJoinColumnsGroup, groupEnabledState); - this.pkJoinColumnsRemoveButton.setEnabled(groupEnabledState && !((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).isEmpty()); - this.pkJoinColumnsEditButton.setEnabled(groupEnabledState && ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).size() == 1); - } - - private void enableGroup(Group group, boolean enabled) { - group.setEnabled(enabled); - for (int i = 0; i < group.getChildren().length; i++) { - group.getChildren()[i].setEnabled(enabled); - } + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Override Default check box + Button overrideDefaultButton = buildCheckBox( + buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, + buildOverrideDefaultHolder() + ); + + installOverrideDefaultButtonEnabler(overrideDefaultButton); + + // Primary Key Join Columns group pane + container = buildTitledPane( + container, + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn + ); + + // Primary Key Join Columns add/remove list pane + AddRemoveListPane<ISecondaryTable> pkJoinColumnListPane = new AddRemoveListPane<ISecondaryTable>( + this, + container, + buildPrimaryKeyJoinColumnAdapter(), + buildSortedPrimaryKeyJoinColumnListHolder(), + buildPrimaryKeyJoinColumnHolder(), + buildJoinColumnsListLabelProvider() + ); + + helpSystem().setHelp( + pkJoinColumnListPane.getControl(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS + ); + + installPrimaryKeyJoinColumnListPaneEnabler(pkJoinColumnListPane); } - - - public void doPopulate(EObject obj) { - this.secondaryTable = (ISecondaryTable) obj; - if (this.secondaryTable == null) { - this.pkJoinColumnsListViewer.setInput(null); - return; - } - - this.pkJoinColumnsListViewer.setInput(this.secondaryTable); - - updatePrimaryKeyJoinColumnsEnablement(); - this.overrideDefaultJoinColumnsCheckBox.setSelection(this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns()); + private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) { + + new ControlEnabler( + buildControlBooleanHolder(), + overrideDefaultButton + ); } - @Override - protected void doPopulate() { + private void installPrimaryKeyJoinColumnListPaneEnabler(AddRemoveListPane<ISecondaryTable> pkJoinColumnListPane) { + + new PaneEnabler( + buildControlBooleanHolder(), + pkJoinColumnListPane + ); } - protected void engageListeners() { - if (this.secondaryTable != null) { - this.secondaryTable.eAdapters().add(this.secondaryTableListener); - for (IPrimaryKeyJoinColumn pkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) { - pkJoinColumn.eAdapters().add(this.pkJoinColumnListener); - } + private void removePrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { + int[] selectedIndices = listSelectionModel.selectedIndices(); + + for (int index = selectedIndices.length; --index > 0; ) { + subject().removeSpecifiedPrimaryKeyJoinColumn(selectedIndices[index]); } } - - protected void disengageListeners() { - if (this.secondaryTable != null) { - for (IPrimaryKeyJoinColumn pkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) { - pkJoinColumn.eAdapters().remove(this.pkJoinColumnListener); - } - this.secondaryTable.eAdapters().remove(this.secondaryTableListener); + + private class OverrideDefaultValueModel extends TransformationPropertyValueModel<ISecondaryTable, Boolean> + implements WritablePropertyValueModel<Boolean> + { + OverrideDefaultValueModel(PropertyValueModel<ISecondaryTable> valueHolder) { + super(valueHolder); + engageListChangeListener(valueHolder); } - } - - protected void secondaryTableChanged(Notification notification) { - if (notification.getFeatureID(ISecondaryTable.class) == JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS) { - if (notification.getEventType() == Notification.ADD) { - ((IPrimaryKeyJoinColumn) notification.getNewValue()).eAdapters().add(this.pkJoinColumnListener); - } - else if (notification.getEventType() == Notification.REMOVE) { - ((IPrimaryKeyJoinColumn) notification.getOldValue()).eAdapters().remove(this.pkJoinColumnListener); - } - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - pkJoinColumnsListViewer.refresh(); - overrideDefaultJoinColumnsCheckBox.setSelection(secondaryTable.containsSpecifiedPrimaryKeyJoinColumns()); - updatePrimaryKeyJoinColumnsEnablement(); + + private void engageListChangeListener(PropertyValueModel<ISecondaryTable> valueHolder) { + new ListAspectAdapter<ISecondaryTable, IPrimaryKeyJoinColumn>(valueHolder, ISecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) { + @Override + protected void itemsAdded(ListChangeEvent e) { + super.itemsAdded(e); + valueChanged(e); + } + + @Override + protected void itemsMoved(ListChangeEvent e) { + super.itemsMoved(e); + valueChanged(e); + } + + @Override + protected void itemsRemoved(ListChangeEvent e) { + super.itemsRemoved(e); + valueChanged(e); + } + + @Override + protected void itemsReplaced(ListChangeEvent e) { + super.itemsReplaced(e); + valueChanged(e); + } + + @Override + protected void listChanged(ListChangeEvent e) { + super.listChanged(e); + valueChanged(e); + } + + @Override + protected void listCleared(ListChangeEvent e) { + super.listCleared(e); + valueChanged(e); } - }); + + @Override + protected ListIterator<IPrimaryKeyJoinColumn> listIterator_() { + return subject.specifiedPrimaryKeyJoinColumns(); + } + + @Override + protected int size_() { + return subject.specifiedPrimaryKeyJoinColumnsSize(); + } + + private void valueChanged(ListChangeEvent e) { + PropertyChangeEvent event = new PropertyChangeEvent(e.getSource(), e.aspectName(), null, subject); + OverrideDefaultValueModel.this.valueChanged(event); + } + }; } - } - protected void pkJoinColumnChanged(Notification notification) { - if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__SPECIFIED_REFERENCED_COLUMN_NAME - || notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME - || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__DEFAULT_REFERENCED_COLUMN_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - pkJoinColumnsListViewer.refresh(); + public void setValue(Boolean value) { + ISecondaryTable secondaryTable = subject(); + + if (value) { + IPrimaryKeyJoinColumn defaultJoinColumn = secondaryTable.defaultPrimaryKeyJoinColumns().next(); + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IPrimaryKeyJoinColumn pkJoinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); + pkJoinColumn.setSpecifiedName(columnName); + pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + else { + for (int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { + secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(index); } - }); + } } - } - - protected void enableWidgets(boolean enabled) { - this.pkJoinColumnsListViewer.getControl().setEnabled(enabled); - this.overrideDefaultJoinColumnsCheckBox.setEnabled(enabled); - this.pkJoinColumnsEditButton.setEnabled(enabled); - this.pkJoinColumnsRemoveButton.setEnabled(enabled); - this.pkJoinColumnsAddButton.setEnabled(enabled); - } -} + @Override + protected Boolean transform_(ISecondaryTable value) { + return value.specifiedPrimaryKeyJoinColumnsSize() > 0; + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java deleted file mode 100644 index f5b11b34b4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java +++ /dev/null @@ -1,327 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.ITable; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionListener; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.Database; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class SchemaCombo extends BaseJpaController -{ - private ITable table; - - private Adapter listener; - - /** - * Caching the connectionProfile so we can remove the listener. If the - * cached table object has been removed from the model then we no longer - * have access to the parent and cannot find the connectionProfile - */ - private ConnectionProfile connectionProfile; - - private ConnectionListener connectionListener; - - private CCombo combo; - - public SchemaCombo(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - this.listener = this.buildTableListener(); - this.connectionListener = this.buildConnectionListener(); - } - - private Adapter buildTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - SchemaCombo.this.schemaChanged(notification); - } - }; - } - - private ConnectionListener buildConnectionListener() { - return new ConnectionListener() { - public void aboutToClose(ConnectionProfile profile) { - // not interested to this event. - } - - public void closed(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateShemaCombo(); - } - }); - } - - public void modified(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateShemaCombo(); - } - }); - } - - public boolean okToClose(ConnectionProfile profile) { - // not interested to this event. - return true; - } - - public void opened(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateShemaCombo(); - } - }); - } - - public void databaseChanged(ConnectionProfile profile, final Database database) { - getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if (database == SchemaCombo.this.getDatabase()) { - if (!getControl().isDisposed()) { - SchemaCombo.this.populateShemaCombo(); - } - } - } - }); - } - - public void schemaChanged(ConnectionProfile profile, final Schema schema) { - getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if (schema == SchemaCombo.this.getTableSchema()) { - if (!getControl().isDisposed()) { - SchemaCombo.this.populateShemaCombo(); - } - } - } - }); - } - - public void tableChanged(ConnectionProfile profile, final Table table) { - // not interested to this event. - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - this.combo.add(JptUiMappingsMessages.TableComposite_defaultEmpty); - this.combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String schemaText = ((CCombo) e.getSource()).getText(); - if (schemaText.equals("")) { //$NON-NLS-1$ - schemaText = null; - if (SchemaCombo.this.table.getSpecifiedSchema() == null || SchemaCombo.this.table.getSpecifiedSchema().equals("")) { //$NON-NLS-1$ - return; - } - } - if (schemaText != null && combo.getItemCount() > 0 && schemaText.equals(combo.getItem(0))) { - schemaText = null; - } - if (SchemaCombo.this.table.getSpecifiedSchema() == null && schemaText != null) { - SchemaCombo.this.table.setSpecifiedSchema(schemaText); - } - if (SchemaCombo.this.table.getSpecifiedSchema() != null && !SchemaCombo.this.table.getSpecifiedSchema().equals(schemaText)) { - SchemaCombo.this.table.setSpecifiedSchema(schemaText); - } - } - }); - } - - protected void schemaChanged(Notification notification) { - if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_SCHEMA) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateSchemaName(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_SCHEMA) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateDefaultSchemaName(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateShemaCombo(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - SchemaCombo.this.populateShemaCombo(); - } - }); - } - } - - public void doPopulate(EObject obj) { - this.table = (ITable) obj; - if (this.table != null) { - this.populateShemaCombo(); - } - else { - this.connectionProfile = null; - } - } - - public void doPopulate() { - this.populateShemaCombo(); - } - - protected Database getDatabase() { - return this.getConnectionProfile().getDatabase(); - } - - private ConnectionProfile getConnectionProfile() { - if (this.connectionProfile == null) { - this.connectionProfile = this.table.getJpaProject().connectionProfile(); - } - return this.connectionProfile; - } - - private void populateShemaCombo() { - if (this.table == null) { - return; - } - this.populateDefaultSchemaName(); - if (this.getConnectionProfile().isConnected()) { - this.combo.remove(1, this.combo.getItemCount() - 1); - Database database = this.getDatabase(); - if (database != null) { - Iterator<String> schemata = database.schemaNames(); - for (Iterator<String> stream = CollectionTools.sort(schemata); stream.hasNext();) { - this.combo.add(stream.next()); - } - } - } - else { - this.combo.remove(1, this.combo.getItemCount() - 1); - } - this.populateSchemaName(); - } - - protected void populateDefaultSchemaName() { - String defaultSchemaName = this.table.getDefaultSchema(); - int selectionIndex = combo.getSelectionIndex(); - combo.setItem(0, NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultSchemaName)); - if (selectionIndex == 0) { - combo.clearSelection(); - combo.select(0); - } - } - - protected void populateSchemaName() { - if (this.table == null) { - return; - } - String schemaName = this.table.getSpecifiedSchema(); - String defaultSchemaName = this.table.getDefaultSchema(); - if (!StringTools.stringIsEmpty(schemaName)) { - if (!this.combo.getText().equals(schemaName)) { - this.combo.setText(schemaName); - } - } - else { - if (!this.combo.getText().equals(NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultSchemaName))) { - this.combo.select(0); - } - } - } - - public CCombo getCombo() { - return this.combo; - } - - @Override - public Control getControl() { - return getCombo(); - } - - protected Schema getTableSchema() { - return this.getConnectionProfile().getDatabase().schemaNamed(table.getSchema()); - } - - @Override - protected void disengageListeners() { - if (this.table != null) { - this.removeConnectionListener(); - this.table.eAdapters().remove(this.listener); - } - } - - @Override - protected void engageListeners() { - if (this.table != null) { - this.table.eAdapters().add(this.listener); - this.addConnectionListener(); - } - } - - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); - } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java index 14be07b492..4c91240e66 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java @@ -3,16 +3,16 @@ * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: Oracle. - initial API and implementation - ******************************************************************************/ + ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; import java.util.Iterator; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.ISecondaryTable; import org.eclipse.jpt.db.internal.ConnectionProfile; import org.eclipse.jpt.db.internal.Database; import org.eclipse.jpt.db.internal.Schema; @@ -30,22 +30,22 @@ import org.eclipse.swt.widgets.Shell; public class SecondaryTableDialog extends Dialog { - //if creating a new JoinColumn, this will be null, + //if creating a new JoinColumn, this will be null, //specify the JoinColumnOwner instead in the appropriate construtor private ISecondaryTable secondaryTable; private IEntity entity; - + protected Combo nameCombo; protected Combo catalogCombo; protected Combo schemaCombo; - + private String selectedName; private String selectedSchema; private String selectedCatalog; - + private boolean defaultSchemaSelected; private boolean defaultCatalogSelected; - + SecondaryTableDialog(Shell parent, IEntity entity) { super(parent); this.entity = entity; @@ -56,38 +56,40 @@ public class SecondaryTableDialog extends Dialog { this.secondaryTable = secondaryTable; this.entity = entity; } - + + @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(getTitle()); } - + protected String getTitle() { return JptUiMappingsMessages.SecondaryTableDialog_editSecondaryTable; } - + + @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); GridLayout gridLayout = (GridLayout) composite.getLayout(); gridLayout.numColumns = 2; - + Label nameLabel = new Label(composite, SWT.LEFT); nameLabel.setText(JptUiMappingsMessages.SecondaryTableDialog_name); GridData gridData = new GridData(); nameLabel.setLayoutData(gridData); - + this.nameCombo = new Combo(composite, SWT.LEFT); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; this.nameCombo.setLayoutData(gridData); populateNameCombo(); - + Label catalogLabel = new Label(composite, SWT.LEFT); catalogLabel.setText(JptUiMappingsMessages.SecondaryTableDialog_catalog); gridData = new GridData(); catalogLabel.setLayoutData(gridData); - + this.catalogCombo = new Combo(composite, SWT.LEFT); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; @@ -99,7 +101,7 @@ public class SecondaryTableDialog extends Dialog { schemaLabel.setText(JptUiMappingsMessages.SecondaryTableDialog_schema); gridData = new GridData(); schemaLabel.setLayoutData(gridData); - + this.schemaCombo = new Combo(composite, SWT.LEFT); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; @@ -109,16 +111,16 @@ public class SecondaryTableDialog extends Dialog { return composite; } - + protected Database getDatabase() { return this.getConnectionProfile().getDatabase(); } - + private ConnectionProfile getConnectionProfile() { - IJpaProject project = (this.secondaryTable == null) ? this.entity.getJpaProject() : this.secondaryTable.getJpaProject(); + IJpaProject project = (this.secondaryTable == null) ? this.entity.jpaProject() : this.secondaryTable.jpaProject(); return project.connectionProfile(); } - + protected Schema getTableSchema() { Database database = this.getDatabase(); if (database != null) { @@ -129,7 +131,7 @@ public class SecondaryTableDialog extends Dialog { } return null; } - + protected void populateNameCombo() { Schema schema = this.getTableSchema(); if (schema != null) { @@ -150,9 +152,9 @@ public class SecondaryTableDialog extends Dialog { if (getSecondaryTable() != null) { this.schemaCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultSchema, getSecondaryTable().getDefaultSchema())); } - + Database database = this.getDatabase(); - + if (database != null) { Iterator<String> schemata = database.schemaNames(); for (Iterator<String> stream = CollectionTools.sort(schemata); stream.hasNext(); ) { @@ -169,13 +171,13 @@ public class SecondaryTableDialog extends Dialog { } } } - + protected void populateCatalogCombo() { if (getSecondaryTable() != null) { this.catalogCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultCatalog, getSecondaryTable().getDefaultCatalog())); } Database database = this.getDatabase(); - + if (database != null) { Iterator<String> catalogs = database.catalogNames(); for (Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext(); ) { @@ -191,45 +193,46 @@ public class SecondaryTableDialog extends Dialog { this.catalogCombo.select(0); } } - } - + } + protected Combo getNameCombo() { return this.nameCombo; } - + protected Combo getSchemaCombo() { return this.schemaCombo; } - + protected Combo getCatalogCombo() { return this.catalogCombo; } - + protected ISecondaryTable getSecondaryTable() { return this.secondaryTable; } - - + + protected String getSelectedName() { return this.selectedName; } - + protected String getSelectedCatalog() { return this.selectedCatalog; } - + protected String getSelectedSchema() { return this.selectedSchema; } - + protected boolean isDefaultSchemaSelected() { return this.defaultSchemaSelected; } - + protected boolean isDefaultCatalogSelected() { return this.defaultCatalogSelected; } - + + @Override public boolean close() { this.selectedName = this.nameCombo.getText(); this.selectedSchema = this.schemaCombo.getText(); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java index 052cd72f48..7cf03aa774 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java @@ -1,268 +1,174 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.IContentProvider; +import java.util.ListIterator; import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; -import org.eclipse.jpt.core.internal.mappings.ITable; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; +import org.eclipse.jpt.core.internal.context.base.IEntity; +import org.eclipse.jpt.core.internal.context.base.ISecondaryTable; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -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; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -//TODO handle xml, how to handle virtual secondaryTables, adding them to xml, are they overriden, etc?? -public class SecondaryTablesComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | PrimaryKeyJoinColumnsInSecondaryTableComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IEntity + * @see EntityComposite - The container of this pane + * @see AddRemoveListPane + * @see PrimaryKeyJoinColumnsInSecondaryTableComposite + * + * @TODO handle xml, how to handle virtual secondaryTables, adding them to xml, are they overriden, etc?? + * @version 2.0 + * @since 1.0 + */ +public class SecondaryTablesComposite extends AbstractFormPane<IEntity> { - private IEntity entity; - private final Adapter entityListener; - private final Adapter secondaryTableListener; - - ListViewer secondaryTablesListViewer; + /** + * Creates a new <code>SecondaryTablesComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public SecondaryTablesComposite(AbstractFormPane<? extends IEntity> parentPane, + Composite parent) { - private Button addButton; - private Button editButton; - private Button removeButton; - - private PrimaryKeyJoinColumnsInSecondaryTableComposite pkJoinColumnsComposite; - - public SecondaryTablesComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - this.entityListener = buildEntityListener(); - this.secondaryTableListener = buildSecondaryTableListener(); + super(parentPane, parent); } - - private Adapter buildEntityListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - entityChanged(notification); - } - }; + + /** + * Creates a new <code>SecondaryTablesComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IEntity</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public SecondaryTablesComposite(PropertyValueModel<? extends IEntity> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent,widgetFactory); } - - private Adapter buildSecondaryTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - seoncaryTableChanged(notification); + + private void addSecondaryTableFromDialog(SecondaryTableDialog dialog, + ObjectListSelectionModel listSelectionModel) { + if (dialog.open() == Window.OK) { + int index = this.subject().specifiedSecondaryTablesSize(); + String name = dialog.getSelectedName(); + String catalog = dialog.getSelectedCatalog(); + String schema = dialog.getSelectedSchema(); + ISecondaryTable secondaryTable = this.subject().addSpecifiedSecondaryTable(index); + secondaryTable.setSpecifiedName(name); + secondaryTable.setSpecifiedCatalog(catalog); + secondaryTable.setSpecifiedSchema(schema); + + listSelectionModel.setSelectedValue(secondaryTable); + } + } + + private WritablePropertyValueModel<ISecondaryTable> buildSecondaryTableHolder() { + return new SimplePropertyValueModel<ISecondaryTable>(); + } + + private ILabelProvider buildSecondaryTableLabelProvider() { + return new LabelProvider() { + @Override + public String getText(Object element) { + // TODO display a qualified name instead + ISecondaryTable secondaryTable = (ISecondaryTable) element; + return secondaryTable.getName(); } }; } - - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - composite.setLayout(layout); - - GridData gridData = new GridData(); - - Composite secondaryTablesComposite = new Composite(composite, SWT.NONE); - layout = new GridLayout(3, false); - layout.marginWidth = 0; - secondaryTablesComposite.setLayout(layout); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - secondaryTablesComposite.setLayoutData(gridData); - - this.secondaryTablesListViewer = buildSecondaryTablesListViewer(secondaryTablesComposite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.horizontalSpan = 3; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.secondaryTablesListViewer.getList().setLayoutData(gridData); - //PlatformUI.getWorkbench().getHelpSystem().setHelp(this.secondaryTablesListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS); - - Composite buttonsComposite = new Composite(secondaryTablesComposite, SWT.NONE); - layout = new GridLayout(3, false); - layout.marginWidth = 0; - buttonsComposite.setLayout(layout); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.END; - buttonsComposite.setLayoutData(gridData); - - this.addButton = getWidgetFactory().createButton( - buttonsComposite, - JptUiMappingsMessages.SecondaryTablesComposite_add, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.addButton.setLayoutData(gridData); - this.addButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - addSecondaryTable(); - } - }); - - this.editButton = getWidgetFactory().createButton( - buttonsComposite, - JptUiMappingsMessages.SecondaryTablesComposite_edit, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - this.editButton.setLayoutData(gridData); - this.editButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - editSecondaryTable(); + + private AddRemoveListPane.Adapter buildSecondaryTablesAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + SecondaryTableDialog dialog = new SecondaryTableDialog(getControl().getShell(), subject()); + addSecondaryTableFromDialog(dialog, listSelectionModel); } - }); - this.removeButton = getWidgetFactory().createButton( - buttonsComposite, - JptUiMappingsMessages.SecondaryTablesComposite_remove, - SWT.NONE); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.BEGINNING; - this.removeButton.setLayoutData(gridData); - this.removeButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing + @Override + public boolean hasOptionalButton() { + return true; } - - public void widgetSelected(SelectionEvent e) { - removeSecondaryTable(); + + @Override + public String optionalButtonText() { + return JptUiMappingsMessages.SecondaryTablesComposite_edit; } - }); - - this.pkJoinColumnsComposite = new PrimaryKeyJoinColumnsInSecondaryTableComposite(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - this.pkJoinColumnsComposite.getControl().setLayoutData(gridData); - } - - private ListViewer buildSecondaryTablesListViewer(Composite parent) { - ListViewer listViewer = new ListViewer(parent, SWT.SINGLE | SWT.BORDER); - listViewer.setLabelProvider(buildSecondaryTablesListLabelProvider()); - listViewer.setContentProvider(buildSecondaryTablesListContentProvider()); - - listViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateEnablement(); - secondaryTablesListSelectionChanged(event); + + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + ISecondaryTable secondaryTable = (ISecondaryTable) listSelectionModel.selectedValue(); + SecondaryTableDialog dialog = new SecondaryTableDialog(getControl().getShell(), secondaryTable, subject()); + editSecondaryTableFromDialog(dialog, secondaryTable); } - }); - return listViewer; - } - - protected void secondaryTablesListSelectionChanged(SelectionChangedEvent event) { - if (((StructuredSelection) event.getSelection()).isEmpty()) { - this.pkJoinColumnsComposite.populate(null); - this.pkJoinColumnsComposite.enableWidgets(false); - } - else { - ISecondaryTable selectedSecondaryTable = getSelectedSecondaryTable(); - this.pkJoinColumnsComposite.populate(selectedSecondaryTable); - this.pkJoinColumnsComposite.enableWidgets(true); - } - } + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + IEntity entity = subject(); + int[] selectedIndices = listSelectionModel.selectedIndices(); - private IContentProvider buildSecondaryTablesListContentProvider() { - return new IStructuredContentProvider(){ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public Object[] getElements(Object inputElement) { - return ((IEntity) inputElement).getSecondaryTables().toArray(); + for (int index = selectedIndices.length; --index >= 0; ) { + entity.removeSpecifiedSecondaryTable(selectedIndices[index]); + } } }; } - - private ILabelProvider buildSecondaryTablesListLabelProvider() { - return new LabelProvider() { - public String getText(Object element) { - //TODO display a qualified name instead - ISecondaryTable secondaryTable = (ISecondaryTable) element; - return secondaryTable.getName(); + + private ListValueModel<ISecondaryTable> buildSecondaryTablesListHolder() { + return new ListAspectAdapter<IEntity, ISecondaryTable>(getSubjectHolder(), IEntity.SPECIFIED_SECONDARY_TABLES_LIST) { + @Override + protected ListIterator<ISecondaryTable> listIterator_() { + return subject.secondaryTables(); + } + + @Override + protected int size_() { + return subject.secondaryTablesSize(); } }; } - - void addSecondaryTable() { - SecondaryTableDialog dialog = new SecondaryTableDialog(this.getControl().getShell(), this.entity); - addSecondaryTableFromDialog(dialog); - } - - private void addSecondaryTableFromDialog(SecondaryTableDialog dialog) { - if (dialog.open() == Window.OK) { - int index = this.entity.getSpecifiedSecondaryTables().size(); - String name = dialog.getSelectedName(); - String catalog = dialog.getSelectedCatalog(); - String schema = dialog.getSelectedSchema(); - ISecondaryTable secondaryTable = this.entity.createSecondaryTable(index); - this.entity.getSpecifiedSecondaryTables().add(secondaryTable); - secondaryTable.setSpecifiedName(name); - secondaryTable.setSpecifiedCatalog(catalog); - secondaryTable.setSpecifiedSchema(schema); - - this.secondaryTablesListViewer.setSelection(new StructuredSelection(secondaryTable)); - } - } - - void editSecondaryTable() { - ISecondaryTable secondaryTable = getSelectedSecondaryTable(); - SecondaryTableDialog dialog = new SecondaryTableDialog(this.getControl().getShell(), secondaryTable, this.entity); - editSecondaryTableFromDialog(dialog, secondaryTable); - } - - private void editSecondaryTableFromDialog(SecondaryTableDialog dialog, ISecondaryTable secondaryTable) { - if (dialog.open() == Window.OK) { - editSecondaryTableDialogOkd(dialog, secondaryTable); - } + + private ListValueModel<ISecondaryTable> buildSortedSecondaryTablesListHolder() { + return new SortedListValueModelAdapter<ISecondaryTable>( + buildSecondaryTablesListHolder() + ); } - + private void editSecondaryTableDialogOkd(SecondaryTableDialog dialog, ISecondaryTable secondaryTable) { String name = dialog.getSelectedName(); String catalog = dialog.getSelectedCatalog(); @@ -271,7 +177,7 @@ public class SecondaryTablesComposite extends BaseJpaComposite if (secondaryTable.getSpecifiedName() == null || !secondaryTable.getSpecifiedName().equals(name)){ secondaryTable.setSpecifiedName(name); } - + if (dialog.isDefaultCatalogSelected()) { if (secondaryTable.getSpecifiedCatalog() != null) { secondaryTable.setSpecifiedCatalog(null); @@ -280,7 +186,7 @@ public class SecondaryTablesComposite extends BaseJpaComposite else if (secondaryTable.getSpecifiedCatalog() == null || !secondaryTable.getSpecifiedCatalog().equals(catalog)){ secondaryTable.setSpecifiedCatalog(catalog); } - + if (dialog.isDefaultSchemaSelected()) { if (secondaryTable.getSpecifiedSchema() != null) { secondaryTable.setSpecifiedSchema(null); @@ -291,98 +197,39 @@ public class SecondaryTablesComposite extends BaseJpaComposite } } - private ISecondaryTable getSelectedSecondaryTable() { - return (ISecondaryTable) ((StructuredSelection) this.secondaryTablesListViewer.getSelection()).getFirstElement(); - } - - - void removeSecondaryTable() { - ISelection selection = this.secondaryTablesListViewer.getSelection(); - if (selection instanceof StructuredSelection) { - for (Iterator<ISecondaryTable> i = ((StructuredSelection) selection).iterator(); i.hasNext(); ) { - this.entity.getSpecifiedSecondaryTables().remove(i.next()); - } - } - } - - void updateEnablement() { - this.editButton.setEnabled(!((StructuredSelection) this.secondaryTablesListViewer.getSelection()).isEmpty()); - this.removeButton.setEnabled(!((StructuredSelection) this.secondaryTablesListViewer.getSelection()).isEmpty()); - } - - public void doPopulate(EObject obj) { - this.entity = (IEntity) obj; - if (this.entity == null) { - this.secondaryTablesListViewer.setInput(null); - return; - } - - this.secondaryTablesListViewer.setInput(this.entity); - if (!this.entity.getSecondaryTables().isEmpty()) { - this.secondaryTablesListViewer.setSelection(new StructuredSelection(this.entity.getSecondaryTables().get(0))); - } - else { - this.secondaryTablesListViewer.setSelection(null); + private void editSecondaryTableFromDialog(SecondaryTableDialog dialog, ISecondaryTable secondaryTable) { + if (dialog.open() == Window.OK) { + editSecondaryTableDialogOkd(dialog, secondaryTable); } - updateEnablement(); } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { - } + protected void initializeLayout(Composite container) { - protected void engageListeners() { - if (this.entity != null) { - this.entity.eAdapters().add(this.entityListener); - for (ISecondaryTable secondaryTable : this.entity.getSecondaryTables()) { - secondaryTable.eAdapters().add(this.secondaryTableListener); - } - } - } - - protected void disengageListeners() { - if (this.entity != null) { - for (ISecondaryTable secondaryTable : this.entity.getSecondaryTables()) { - secondaryTable.eAdapters().remove(this.secondaryTableListener); - } - this.entity.eAdapters().remove(this.entityListener); - } - } - - protected void entityChanged(Notification notification) { - if (notification.getFeatureID(IEntity.class) == JpaCoreMappingsPackage.IENTITY__SPECIFIED_SECONDARY_TABLES) { - if (notification.getEventType() == Notification.ADD) { - ((ISecondaryTable) notification.getNewValue()).eAdapters().add(this.secondaryTableListener); - } - else if (notification.getEventType() == Notification.REMOVE) { - ((ISecondaryTable) notification.getOldValue()).eAdapters().remove(this.secondaryTableListener); - } - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - secondaryTablesListViewer.refresh(); - updateEnablement(); - } - }); - } - } + int groupBoxMargin = groupBoxMargin(); - protected void seoncaryTableChanged(Notification notification) { - if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_NAME - || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG - || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_SCHEMA - || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG - || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_SCHEMA) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - secondaryTablesListViewer.refresh(); - } - }); - } - } -} + WritablePropertyValueModel<ISecondaryTable> secondaryTableHolder = + buildSecondaryTableHolder(); + + // Secondary Tables add/remove list pane + new AddRemoveListPane<IEntity>( + this, + buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), + buildSecondaryTablesAdapter(), + buildSortedSecondaryTablesListHolder(), + secondaryTableHolder, + buildSecondaryTableLabelProvider(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS + ); + + // Primary Key Join Columns pane + new PrimaryKeyJoinColumnsInSecondaryTableComposite( + this, + secondaryTableHolder, + container + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java index 9be54c3668..66af2c9b69 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java @@ -1,185 +1,160 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.ISequenceGenerator; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionProfile; +import org.eclipse.jpt.core.internal.IJpaNode; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.core.internal.context.base.ISequenceGenerator; +import org.eclipse.jpt.db.internal.Schema; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.jpt.ui.internal.mappings.db.SequenceCombo; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +import org.eclipse.swt.widgets.Text; /** - * SequenceGeneratorComposite + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ----------------------------------------------------- | + * | Name: | I | | + * | ----------------------------------------------------- | + * | ----------------------------------------------------- | + * | Sequence Generator: | SequenceCombo | | + * | ----------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IIdMapping + * @see ISequenceGenerator + * @see GenerationComposite - The parent container + * @see SequenceCombo + * + * @version 2.0 + * @since 1.0 */ public class SequenceGeneratorComposite extends GeneratorComposite<ISequenceGenerator> { - private CCombo sequenceNameCombo; + /** + * Creates a new <code>SequenceGeneratorComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public SequenceGeneratorComposite(AbstractFormPane<? extends IIdMapping> parentPane, + Composite parent) { - private ModifyListener sequenceNameComboListener; - - private ConnectionProfile connectionProfile; - - public SequenceGeneratorComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, commandStack, widgetFactory); - } - - protected ISequenceGenerator createGenerator() { - ISequenceGenerator sequenceGenerator = idMapping().createSequenceGenerator(); - idMapping().setSequenceGenerator(sequenceGenerator); - return sequenceGenerator; - } - - protected ISequenceGenerator generator(IId idMapping) { - return idMapping.getSequenceGenerator(); + super(parentPane, parent); } + /* + * (non-Javadoc) + */ @Override - protected void initializeLayout(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - GridLayout layout = new GridLayout(2, false); - composite.setLayout(layout); - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.SequenceGeneratorComposite_name); - - this.nameTextWidget = buildNameText(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.nameTextWidget.setLayoutData(gridData); - helpSystem.setHelp(this.nameTextWidget, IJpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_NAME); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.SequenceGeneratorComposite_sequence); - - this.sequenceNameCombo = buildSequenceNameCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.sequenceNameCombo.setLayoutData(gridData); - helpSystem.setHelp(sequenceNameCombo, IJpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_SEQUENCE); + protected ISequenceGenerator buildGenerator() { + return subject().addSequenceGenerator(); } - private CCombo buildSequenceNameCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(""); //$NON-NLS-1$ - combo.select(0); - combo.addModifyListener(getSequenceNameListener()); - return combo; - } + private SequenceCombo<IJpaNode> buildSequenceNameCombo(Composite parent) { - private ModifyListener getSequenceNameListener() { - if (this.sequenceNameComboListener == null) { - this.sequenceNameComboListener = new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String text = ((CCombo) e.getSource()).getText(); - if (text != null && sequenceNameCombo.getItemCount() > 0 && text.equals(sequenceNameCombo.getItem(0))) { - text = null; - } - ISequenceGenerator generator = getGenerator(); - if (generator == null) { - generator = createGenerator(); - } - generator.setSpecifiedSequenceName(text); + return new SequenceCombo<IJpaNode>(this, parent) { + + @Override + protected String defaultValue() { + return JptUiMappingsMessages.SequenceGeneratorComposite_default; + } + + @Override + protected Schema schema() { + return null; + // TODO +// return database().schemaNamed(subject().jpaProject().getSchemaName()); + } + + @Override + protected void setValue(String value) { + ISequenceGenerator generator = getGenerator((IIdMapping) super.subject()); + + if (generator == null) { + generator = buildGenerator(); } - }; - } - return this.sequenceNameComboListener; - } - protected void generatorChanged(Notification notification) { - super.generatorChanged(notification); - if (notification.getFeatureID(ISequenceGenerator.class) == JpaCoreMappingsPackage.ISEQUENCE_GENERATOR__SPECIFIED_SEQUENCE_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - String sequenceName = getGenerator().getSpecifiedSequenceName(); - if (sequenceName == null) { - sequenceNameCombo.select(0); - } - else if (!sequenceNameCombo.getText().equals(sequenceName)) { - sequenceNameCombo.setText(sequenceName); - } + generator.setSpecifiedSequenceName(value); + } + + @Override + protected IJpaNode subject() { + IJpaNode subject = super.subject(); + + if (subject == null) { + subject = SequenceGeneratorComposite.this.subject(); + } + + return subject; + } + + @Override + protected String value() { + ISequenceGenerator generator = getGenerator((IIdMapping) super.subject()); + + if (generator != null) { + return generator.getSpecifiedSequenceName(); } - }); - } + + return null; + } + }; } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(EObject obj) { - super.doPopulate(obj); - if (obj == null) { - return; - } - populateSequenceNameCombo(); + protected ISequenceGenerator getGenerator(IIdMapping subject) { + return (subject != null) ? subject.getSequenceGenerator() : null; } + /* + * (non-Javadoc) + */ @Override - protected void doPopulate() { - populateSequenceNameCombo(); - } - - private ConnectionProfile getConnectionProfile() { - if(this.connectionProfile == null) { - IJpaProject jpaProject = getGenerator().getJpaProject(); - this.connectionProfile = jpaProject.connectionProfile(); - } - return this.connectionProfile; - } + protected void initializeLayout(Composite container) { - private void populateSequenceNameCombo() { - if (this.getGenerator() == null) { - return; - } - this.sequenceNameCombo.setItem(0, JptUiMappingsMessages.SequenceGeneratorComposite_default); - if (this.getConnectionProfile().isConnected()) { -// this.sequenceNameCombo.remove(1, this.sequenceNameCombo.getItemCount() - 1); -// Schema schema = getConnectionProfile().getDatabase().schemaNamed(getGenerator().getJpaProject().getSchemaName()); -// if (schema != null) { -// for (Iterator stream = CollectionTools.sort(schema.sequenceNames()); stream.hasNext();) { -// this.sequenceNameCombo.add((String) stream.next()); -// } -// } - } - String sequenceName = this.getGenerator().getSpecifiedSequenceName(); - if (sequenceName != null) { - if (!this.sequenceNameCombo.getText().equals(sequenceName)) { - this.sequenceNameCombo.setText(sequenceName); - } - } - else { - this.sequenceNameCombo.select(0); - } + // Name widgets + Text nameText = buildNameText(container); + setNameText(nameText); + + buildLabeledComposite( + container, + JptUiMappingsMessages.SequenceGeneratorComposite_name, + nameText, + IJpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_NAME + ); + + // Sequence Generator widgets + SequenceCombo<IJpaNode> sequenceNameCombo = + buildSequenceNameCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.SequenceGeneratorComposite_sequence, + sequenceNameCombo.getControl(), + IJpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_SEQUENCE + ); } - protected void clear() { - super.clear(); - this.sequenceNameCombo.select(0); + /* + * (non-Javadoc) + */ + @Override + protected String propertyName() { + return IIdMapping.SEQUENCE_GENERATOR_PROPERTY; } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/StringWithDefaultChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/StringWithDefaultChooser.java deleted file mode 100644 index 330f39594a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/StringWithDefaultChooser.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class StringWithDefaultChooser extends BaseJpaController -{ - private StringHolder stringHolder; - private Adapter stringHolderListener; - - private ComboViewer comboViewer; - - private static final String DEFAULT = "default"; - - - public StringWithDefaultChooser(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildStringHolderListener(); - } - - - private void buildStringHolderListener() { - this.stringHolderListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - stringHolderChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - this.comboViewer = new ComboViewer(combo); - this.comboViewer.setContentProvider(buildContentProvider()); - this.comboViewer.setLabelProvider(buildLabelProvider()); - - this.comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - StringWithDefaultChooser.this.selectionChanged(event.getSelection()); - } - }); - - combo.addModifyListener( - new ModifyListener() { - public void modifyText(ModifyEvent e) { - comboModified(e); - } - }); - } - - private IContentProvider buildContentProvider() { - return new IStructuredContentProvider(){ - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public void dispose() { - } - - public Object[] getElements(Object inputElement) { - return new String[] {DEFAULT}; - } - }; - } - - - private IBaseLabelProvider buildLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - if (element == DEFAULT && stringHolder.wrappedObject() != null) { - return stringHolder.defaultItem(); - } - return super.getText(element); - } - }; - } - void selectionChanged(ISelection sel) { - if (isPopulating()) { - return; - } - - if (sel instanceof IStructuredSelection) { - String selection = (String) ((IStructuredSelection) sel).getFirstElement(); - if (this.comboViewer.getCombo().getSelectionIndex() == 0) { - selection = null; - } - if (this.stringHolder.getString() == null) { - if (selection != null) { - this.stringHolder.setString(selection); - } - } - else if (!this.stringHolder.getString().equals(selection)) { - this.stringHolder.setString(selection); - } - } - } - - private void comboModified(ModifyEvent e) { - if (isPopulating()) { - return; - } - CCombo combo = (CCombo) e.getSource(); - combo.getSelectionIndex(); - String text = combo.getText(); - - if (text != null && combo.getItemCount() > 0 && text.equals(combo.getItem(0))) { - text = null; - } - if (this.stringHolder.getString() != text) { - this.stringHolder.setString(text); - } - } - - private void stringHolderChanged(Notification notification) { - if (notification.getFeatureID(this.stringHolder.featureClass()) == - this.stringHolder.featureId()) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getCombo().isDisposed()) { - return; - } - populate(); - } - }); - } - else if (this.stringHolder.supportsDefault()) { - if (notification.getFeatureID(this.stringHolder.featureClass()) == - this.stringHolder.defaultFeatureId()) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - if (getCombo().isDisposed()) { - return; - } - populate(); - } - }); - - } - } - } - - @Override - protected void engageListeners() { - if (this.stringHolder != null && this.stringHolder.wrappedObject() != null) { - this.stringHolder.wrappedObject().eAdapters().add(this.stringHolderListener); - } - } - - @Override - protected void disengageListeners() { - if (this.stringHolder != null && this.stringHolder.wrappedObject() != null) { - this.stringHolder.wrappedObject().eAdapters().remove(this.stringHolderListener); - } - } - - @Override - public void doPopulate(EObject obj) { - this.stringHolder = (StringHolder) obj; - this.comboViewer.setInput(this.stringHolder); - populateCombo(); - } - - @Override - protected void doPopulate() { - populateCombo(); - } - - private void populateCombo() { - if (this.stringHolder.wrappedObject() == null) { - this.comboViewer.setSelection(StructuredSelection.EMPTY); - return; - } - this.comboViewer.update(this.comboViewer.getElementAt(0), null); - - String string = this.stringHolder.getString(); - if (string == null) { - if (((StructuredSelection) this.comboViewer.getSelection()).getFirstElement() == DEFAULT) { - this.comboViewer.refresh(); - } - else { - this.comboViewer.setSelection(new StructuredSelection(DEFAULT)); - } - } - else { - if (!this.comboViewer.getCombo().getText().equals(string)) { - this.comboViewer.getCombo().setText(string); - } - } - } - - public CCombo getCombo() { - return this.comboViewer.getCCombo(); - } - - @Override - public Control getControl() { - return getCombo(); - } - /** - * An interface to wrap an object that supports a string with a default setting - * An object of this type must be passed in to populate(EObject) - */ - public static interface StringHolder extends EObject { - /** - * Return the string setting from the wrapped object - * @return - */ - String getString(); - - /** - * Set the string setting on the wrapped object - * @param string - */ - void setString(String string); - - /** - * Return the Class of the wrapped object - * @return - */ - Class featureClass(); - - /** - * Return the feature id of string setting on the wrapped object - * @return - */ - int featureId(); - - boolean supportsDefault(); - - int defaultFeatureId(); - - /** - * The wrapped EObject that the enum setting is stored on - * @return - */ - EObject wrappedObject(); - - String defaultItem(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java deleted file mode 100644 index 68e148bc9a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableCombo.java +++ /dev/null @@ -1,338 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.ITable; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionListener; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.Database; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class TableCombo extends BaseJpaController -{ - private ITable table; - - private Adapter listener; - - /** - * Caching the connectionProfile so we can remove the listener. If the - * cached table object has been removed from the model then we no longer - * have access to parent and cannot find the connectionProfile - */ - private ConnectionProfile connectionProfile; - - private ConnectionListener connectionListener; - - private CCombo combo; - - public TableCombo(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - this.listener = buildTableListener(); - this.connectionListener = buildConnectionListener(); - } - - private Adapter buildTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - tableChanged(notification); - } - }; - } - - private ConnectionListener buildConnectionListener() { - return new ConnectionListener() { - public void aboutToClose(ConnectionProfile profile) { - // not interested to this event. - } - - public void closed(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - TableCombo.this.populateTableCombo(); - } - }); - } - - public void modified(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - TableCombo.this.populateTableCombo(); - } - }); - } - - public boolean okToClose(ConnectionProfile profile) { - // not interested to this event. - return true; - } - - public void opened(ConnectionProfile profile) { - getCombo().getDisplay().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - TableCombo.this.populateTableCombo(); - } - }); - } - - public void databaseChanged(ConnectionProfile profile, final Database database) { - getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if (database == TableCombo.this.getDatabase()) { - if (!getControl().isDisposed()) { - TableCombo.this.populateTableCombo(); - } - } - } - }); - } - - public void schemaChanged(ConnectionProfile profile, final Schema schema) { - getControl().getDisplay().asyncExec(new Runnable() { - public void run() { - if (schema == TableCombo.this.getTableSchema()) { - if (!getControl().isDisposed()) { - TableCombo.this.populateTableCombo(); - } - } - } - }); - } - - public void tableChanged(ConnectionProfile profile, final Table table) { - // not interested to this event. - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - this.combo.add(JptUiMappingsMessages.TableComposite_defaultEmpty); - this.combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String tableText = ((CCombo) e.getSource()).getText(); - if (tableText.equals("")) { //$NON-NLS-1$ - tableText = null; - if (table.getSpecifiedName() == null || table.getSpecifiedName().equals("")) { //$NON-NLS-1$ - return; - } - } - if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) { - tableText = null; - } - if (table.getSpecifiedName() == null && tableText != null) { - table.setSpecifiedName(tableText); - } - if (table.getSpecifiedName() != null && !table.getSpecifiedName().equals(tableText)) { - table.setSpecifiedName(tableText); - } - } - }); - } - - protected void tableChanged(Notification notification) { - if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateTableName(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateDefaultTableName(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_SCHEMA) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateTableCombo(); - } - }); - } - else if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_SCHEMA) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateTableCombo(); - } - }); - } - } - - public void doPopulate(EObject obj) { - this.table = (ITable) obj; - if (this.table != null) { - populateTableCombo(); - } - else { - this.connectionProfile = null; - } - } - - public void doPopulate() { - if (this.table != null) { - populateTableCombo(); - } - } - - protected Database getDatabase() { - return getConnectionProfile().getDatabase(); - } - - protected Schema getTableSchema() { - return getConnectionProfile().getDatabase().schemaNamed(table.getSchema()); - } - - private ConnectionProfile getConnectionProfile() { - if (this.connectionProfile == null) { - this.connectionProfile = this.table.getJpaProject().connectionProfile(); - } - return this.connectionProfile; - } - - private void populateTableCombo() { - if (this.table == null) { - return; - } - // TODO don't do instanceof check here - check on Table, or isRoot check - // on Entity - // this.tableCombo.setEnabled(!(this.table instanceof - // SingleTableInheritanceChildTableImpl)); - populateDefaultTableName(); - if (getConnectionProfile().isConnected()) { - this.combo.remove(1, this.combo.getItemCount() - 1); - Schema schema = this.getTableSchema(); - if (schema != null) { - Iterator<String> tables = schema.tableNames(); - for (Iterator<String> stream = CollectionTools.sort(tables); stream.hasNext();) { - this.combo.add(stream.next()); - } - } - } - else { - this.combo.remove(1, this.combo.getItemCount() - 1); - } - populateTableName(); - } - - protected void populateDefaultTableName() { - if (this.table == null) { - return; - } - String defaultTableName = table.getDefaultName(); - int selectionIndex = combo.getSelectionIndex(); - combo.setItem(0, NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultTableName)); - if (selectionIndex == 0) { - // combo text does not update when switching between 2 mappings of - // the same type - // that both have a default column name. clear the selection and - // then set it again - combo.clearSelection(); - combo.select(0); - } - } - - protected void populateTableName() { - if (this.table == null) { - return; - } - String tableName = this.table.getSpecifiedName(); - String defaultTableName = this.table.getDefaultName(); - if (tableName != null) { - if (!this.combo.getText().equals(tableName)) { - this.combo.setText(tableName); - } - } - else { - if (!this.combo.getText().equals(NLS.bind(JptUiMappingsMessages.TableComposite_defaultWithOneParam, defaultTableName))) { - this.combo.select(0); - } - } - } - - public CCombo getCombo() { - return this.combo; - } - - @Override - public Control getControl() { - return getCombo(); - } - - @Override - protected void disengageListeners() { - if (this.table != null) { - this.removeConnectionListener(); - this.table.eAdapters().remove(this.listener); - } - } - - @Override - protected void engageListeners() { - if (this.table != null) { - this.table.eAdapters().add(this.listener); - this.addConnectionListener(); - } - } - - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); - } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java index cc6f99ae00..0718203988 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java @@ -1,129 +1,232 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. This + * 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.ui.internal.mappings.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.mappings.ITable; +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.core.internal.context.base.ITable; +import org.eclipse.jpt.db.internal.Schema; +import org.eclipse.jpt.db.internal.Table; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.jpt.ui.internal.mappings.db.CatalogCombo; +import org.eclipse.jpt.ui.internal.mappings.db.SchemaCombo; +import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -//TODO repopulate this panel based on the Entity table changing -public class TableComposite extends BaseJpaComposite +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | - Table ----------------------------------------------------------------- | + * | | ------------------------------------------------------------ | | + * | | Table: | TableCombo | | | + * | | ------------------------------------------------------------ | | + * | | ------------------------------------------------------------ | | + * | | Catalog: | CatalogCombo | | | + * | | ------------------------------------------------------------ | | + * | | ------------------------------------------------------------ | | + * | | Schema: | SchemaCombo | | | + * | | ------------------------------------------------------------ | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IBasicMapping + * @see BaseJpaUiFactory + * @see TableCombo + * @see CatalogCombo + * @see SchemaCombo + * + * @TODO repopulate this panel based on the Entity table changing + * + * @version 2.0 + * @since 1.0 + */ +public class TableComposite extends AbstractFormPane<ITable> { - private ITable table; - - protected TableCombo tableCombo; - - protected CatalogCombo catalogCombo; - protected SchemaCombo schemaCombo; - - public TableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } + /** + * Creates a new <code>TableComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject + * @param parent The parent container + */ + public TableComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends ITable> subjectHolder, + Composite parent) { - @Override - protected void initializeLayout(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - composite.setLayout(layout); - - Group columnGroup = getWidgetFactory().createGroup(composite, JptUiMappingsMessages.TableComposite_tableSection); - layout = new GridLayout(); - layout.marginHeight = 0; - columnGroup.setLayout(layout); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - columnGroup.setLayoutData(gridData); - - //created this composite because combos as direct children of a Group do not have a border, no clue why - Composite intermediaryComposite = getWidgetFactory().createComposite(columnGroup); - layout = new GridLayout(2, false); - layout.marginWidth = 0; - intermediaryComposite.setLayout(layout); - - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace= true; - intermediaryComposite.setLayoutData(gridData); - - CommonWidgets.buildTableLabel(intermediaryComposite, getWidgetFactory()); - - this.tableCombo = new TableCombo(intermediaryComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.tableCombo.getCombo().setLayoutData(gridData); - helpSystem.setHelp(tableCombo.getCombo(), IJpaHelpContextIds.ENTITY_TABLE); - - CommonWidgets.buildCatalogLabel(intermediaryComposite, getWidgetFactory()); - this.catalogCombo = new CatalogCombo(intermediaryComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.catalogCombo.getCombo().setLayoutData(gridData); - helpSystem.setHelp(catalogCombo.getCombo(), IJpaHelpContextIds.ENTITY_CATALOG); - - CommonWidgets.buildSchemaLabel(intermediaryComposite, getWidgetFactory()); - this.schemaCombo = new SchemaCombo(intermediaryComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.schemaCombo.getCombo().setLayoutData(gridData); - helpSystem.setHelp(schemaCombo.getCombo(), IJpaHelpContextIds.ENTITY_SCHEMA); + super(parentPane, subjectHolder, parent); } - - @Override - protected void engageListeners() { + + /** + * Creates a new <code>TableComposite</code>. + * + * @param subjectHolder The holder of the subject <code>ITable</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public TableComposite(PropertyValueModel<? extends ITable> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - @Override - protected void disengageListeners() { + private CatalogCombo<ITable> buildCatalogCombo(Composite container) { + + return new CatalogCombo<ITable>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(ITable.DEFAULT_CATALOG_PROPERTY); + propertyNames.add(ITable.SPECIFIED_CATALOG_PROPERTY); + } + + @Override + protected String defaultValue() { + return subject().getDefaultCatalog(); + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedCatalog(value); + } + + @Override + protected String value() { + return subject().getSpecifiedCatalog(); + } + }; } - - public void doPopulate(EObject obj) { - this.table = (ITable) obj; - this.tableCombo.populate(this.table); - this.catalogCombo.populate(this.table); - this.schemaCombo.populate(this.table); + + private SchemaCombo<ITable> buildSchemaCombo(Composite container) { + + return new SchemaCombo<ITable>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(ITable.DEFAULT_SCHEMA_PROPERTY); + propertyNames.add(ITable.SPECIFIED_SCHEMA_PROPERTY); + } + + @Override + protected String defaultValue() { + return subject().getDefaultSchema(); + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedSchema(value); + } + + @Override + protected String value() { + return subject().getSpecifiedSchema(); + } + }; } - - public void doPopulate() { - this.tableCombo.populate(); - this.catalogCombo.populate(); - this.schemaCombo.populate(); + + private TableCombo<ITable> buildTableCombo(Composite container) { + + return new TableCombo<ITable>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(ITable.DEFAULT_NAME_PROPERTY); + propertyNames.add(ITable.SPECIFIED_NAME_PROPERTY); + } + + @Override + protected String defaultValue() { + return subject().getDefaultName(); + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedName(value); + } + + @Override + protected Table table() { + return subject().dbTable(); + } + + private Schema tableSchema() { + return database().schemaNamed(subject().getSchema()); + } + + @Override + protected String value() { + return subject().getSpecifiedName(); + } + + @Override + protected Iterator<String> values() { + Schema schema = tableSchema(); + + if (schema != null) { + return schema.tableNames(); + } + + return EmptyIterator.instance(); + } + }; } - + + /* + * (non-Javadoc) + */ @Override - public void dispose() { - this.catalogCombo.dispose(); - this.schemaCombo.dispose(); - this.tableCombo.dispose(); - super.dispose(); - } + protected void initializeLayout(Composite container) { + + // Table group pane + Group tableGroupPane = buildTitledPane( + container, + JptUiMappingsMessages.TableComposite_tableSection + ); + + // Table widgets + TableCombo<ITable> tableCombo = buildTableCombo(tableGroupPane); + + buildLabeledComposite( + tableGroupPane, + JptUiMappingsMessages.TableChooser_label, + tableCombo.getControl(), + IJpaHelpContextIds.ENTITY_TABLE + ); -} + // Catalog widgets + CatalogCombo<ITable> catalogCombo = buildCatalogCombo(tableGroupPane); + + buildLabeledComposite( + tableGroupPane, + JptUiMappingsMessages.CatalogChooser_label, + catalogCombo.getControl(), + IJpaHelpContextIds.ENTITY_CATALOG + ); + + // Schema widgets + SchemaCombo<ITable> schemaCombo = buildSchemaCombo(tableGroupPane); + + buildLabeledComposite( + tableGroupPane, + JptUiMappingsMessages.SchemaChooser_label, + schemaCombo.getControl(), + IJpaHelpContextIds.ENTITY_SCHEMA + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java index 7426882c70..fca4a2607a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java @@ -1,535 +1,388 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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.ui.internal.mappings.details; -import java.util.Iterator; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.ITableGenerator; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.db.internal.ConnectionListener; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.Database; +import org.eclipse.jpt.core.internal.context.base.IIdMapping; +import org.eclipse.jpt.core.internal.context.base.ITableGenerator; import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +import org.eclipse.swt.widgets.Text; +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ----------------------------------------------- | + * | Name: | I | | + * | ----------------------------------------------- | + * | ----------------------------------------------- | + * | Table: | I |v| | + * | ----------------------------------------------- | + * | ----------------------------------------------- | + * | Primary Key Column: | I |v| | + * | ----------------------------------------------- | + * | ----------------------------------------------- | + * | Value Column: | I |v| | + * | ----------------------------------------------- | + * | ----------------------------------------------- | + * | Primary Key Column Value: | I |v| | + * | ----------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IIdMapping + * @see ITableGenerator + * @see GenerationComposite - The parent container + * + * @version 2.0 + * @since 1.0 + */ public class TableGeneratorComposite extends GeneratorComposite<ITableGenerator> { - private CCombo tableNameCombo; private CCombo pkColumnNameCombo; - private CCombo valueColumnNameCombo; private CCombo pkColumnValueCombo; + private CCombo tableNameCombo; + private CCombo valueColumnNameCombo; - private ConnectionListener connectionListener; - - private ConnectionProfile connectionProfile; + /** + * Creates a new <code>TableGeneratorComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public TableGeneratorComposite(AbstractFormPane<? extends IIdMapping> parentPane, + Composite parent) { - public TableGeneratorComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, commandStack, widgetFactory); - this.connectionListener = this.buildConnectionListener(); - } - - protected ITableGenerator createGenerator() { - ITableGenerator tableGenerator = idMapping().createTableGenerator(); - idMapping().setTableGenerator(tableGenerator); - return tableGenerator; - } - - protected ITableGenerator generator(IId idMapping) { - return idMapping.getTableGenerator(); + super(parentPane, parent); } + /* + * (non-Javadoc) + */ @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(2, false); - composite.setLayout(layout); - - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.TableGeneratorComposite_name); - - this.nameTextWidget = buildNameText(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.nameTextWidget.setLayoutData(gridData); - helpSystem.setHelp(this.nameTextWidget, IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_NAME); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.TableGeneratorComposite_table); - - this.tableNameCombo = buildTableNameCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.tableNameCombo.setLayoutData(gridData); - helpSystem.setHelp(this.tableNameCombo, IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_TABLE); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.TableGeneratorComposite_pkColumn); - - this.pkColumnNameCombo = buildPkColumnNameCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.pkColumnNameCombo.setLayoutData(gridData); - helpSystem.setHelp(this.pkColumnNameCombo, IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.TableGeneratorComposite_valueColumn); - - this.valueColumnNameCombo = buildValueColumnNameCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.valueColumnNameCombo.setLayoutData(gridData); - helpSystem.setHelp(this.valueColumnNameCombo, IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_VALUE_COLUMN); - - getWidgetFactory().createLabel(composite, JptUiMappingsMessages.TableGeneratorComposite_pkColumnValue); - - this.pkColumnValueCombo = buildPkColumnValueCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.pkColumnValueCombo.setLayoutData(gridData); - helpSystem.setHelp(this.pkColumnValueCombo, IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE); - } - - private CCombo buildTableNameCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(JptUiMappingsMessages.TableGeneratorComposite_default); - combo.select(0); - combo.addModifyListener(buildTableNameListener()); - return combo; + protected ITableGenerator buildGenerator() { + return subject().addTableGenerator(); } private CCombo buildPkColumnNameCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); + CCombo combo = buildCombo(parent); combo.add(JptUiMappingsMessages.TableGeneratorComposite_default); combo.select(0); combo.addModifyListener(buildPkColumnNameListener()); return combo; } - private CCombo buildValueColumnNameCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(JptUiMappingsMessages.TableGeneratorComposite_default); - combo.select(0); - combo.addModifyListener(buildValueColumnNameListener()); - return combo; + private ModifyListener buildPkColumnNameListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + String text = ((CCombo) e.getSource()).getText(); + if (text != null && pkColumnNameCombo.getItemCount() > 0 && text.equals(pkColumnNameCombo.getItem(0))) { + text = null; + } + ITableGenerator generator = retrieveTableGenerator(); + generator.setSpecifiedPkColumnName(text); + } + }; } private CCombo buildPkColumnValueCombo(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); + CCombo combo = buildCombo(parent); combo.add(JptUiMappingsMessages.TableGeneratorComposite_default); combo.select(0); combo.addModifyListener(buildPkColumnValueListener()); return combo; } - private ModifyListener buildTableNameListener() { + private ModifyListener buildPkColumnValueListener() { return new ModifyListener() { public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } String text = ((CCombo) e.getSource()).getText(); - if (text != null && tableNameCombo.getItemCount() > 0 && text.equals(tableNameCombo.getItem(0))) { + if (text != null && pkColumnValueCombo.getItemCount() > 0 && text.equals(pkColumnValueCombo.getItem(0))) { text = null; } - ITableGenerator generator = getGenerator(); - if (generator == null) { - generator = createGenerator(); - } - generator.setSpecifiedTable(text); + ITableGenerator generator = retrieveTableGenerator(); + generator.setSpecifiedPkColumnValue(text); } }; } - private ModifyListener buildPkColumnNameListener() { + private CCombo buildTableNameCombo(Composite parent) { + CCombo combo = buildCombo(parent); + combo.add(JptUiMappingsMessages.TableGeneratorComposite_default); + combo.select(0); + combo.addModifyListener(buildTableNameListener()); + return combo; + } + + private ModifyListener buildTableNameListener() { return new ModifyListener() { public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } String text = ((CCombo) e.getSource()).getText(); - if (text != null && pkColumnNameCombo.getItemCount() > 0 && text.equals(pkColumnNameCombo.getItem(0))) { + if (text != null && tableNameCombo.getItemCount() > 0 && text.equals(tableNameCombo.getItem(0))) { text = null; } - ITableGenerator generator = getGenerator(); - if (generator == null) { - generator = createGenerator(); - } - generator.setSpecifiedPkColumnName(text); + ITableGenerator generator = retrieveTableGenerator(); + generator.setSpecifiedTable(text); } }; } + private CCombo buildValueColumnNameCombo(Composite parent) { + CCombo combo = buildCombo(parent); + combo.add(JptUiMappingsMessages.TableGeneratorComposite_default); + combo.select(0); + combo.addModifyListener(buildValueColumnNameListener()); + return combo; + } + private ModifyListener buildValueColumnNameListener() { return new ModifyListener() { public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } String text = ((CCombo) e.getSource()).getText(); if (text != null && valueColumnNameCombo.getItemCount() > 0 && text.equals(valueColumnNameCombo.getItem(0))) { text = null; } - ITableGenerator generator = getGenerator(); - if (generator == null) { - generator = createGenerator(); - } + ITableGenerator generator = retrieveTableGenerator(); generator.setSpecifiedValueColumnName(text); } }; } - private ModifyListener buildPkColumnValueListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String text = ((CCombo) e.getSource()).getText(); - if (text != null && pkColumnValueCombo.getItemCount() > 0 && text.equals(pkColumnValueCombo.getItem(0))) { - text = null; - } - ITableGenerator generator = getGenerator(); - if (generator == null) { - generator = createGenerator(); - } - generator.setSpecifiedPkColumnValue(text); - } - }; - } - - protected void generatorChanged(Notification notification) { - super.generatorChanged(notification); - if (notification.getFeatureID(ITableGenerator.class) == JpaCoreMappingsPackage.ITABLE_GENERATOR__SPECIFIED_TABLE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - String tableName = getGenerator().getSpecifiedTable(); - if (tableName == null) { - tableNameCombo.select(0); - } - else if (!tableNameCombo.getText().equals(tableName)) { - tableNameCombo.setText(tableName); - } - populatePkColumnNameCombo(); - populateValueColumnNameCombo(); - } - }); - } - else if (notification.getFeatureID(ITableGenerator.class) == JpaCoreMappingsPackage.ITABLE_GENERATOR__SPECIFIED_PK_COLUMN_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populatePkColumnName(); - - } - }); - } - else if (notification.getFeatureID(ITableGenerator.class) == JpaCoreMappingsPackage.ITABLE_GENERATOR__SPECIFIED_VALUE_COLUMN_NAME) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - String columnName = getGenerator().getSpecifiedValueColumnName(); - if (columnName == null) { - valueColumnNameCombo.select(0); - } - else if (!valueColumnNameCombo.getText().equals(columnName)) { - valueColumnNameCombo.setText(columnName); - } - } - }); - } - else if (notification.getFeatureID(ITableGenerator.class) == JpaCoreMappingsPackage.ITABLE_GENERATOR__SPECIFIED_PK_COLUMN_VALUE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - String columnValue = getGenerator().getSpecifiedPkColumnValue(); - if (columnValue == null) { - pkColumnValueCombo.select(0); - } - else if (!pkColumnValueCombo.getText().equals(columnValue)) { - pkColumnValueCombo.setText(columnValue); - } - } - }); - } - } - - @Override - protected void doPopulate(EObject obj) { - super.doPopulate(obj); - if (obj == null) { - this.connectionProfile = null; - return; - } - populateTableNameCombo(); - populatePkColumnNameCombo(); - populateValueColumnNameCombo(); - populatePkColumnValueCombo(); - } - + /* + * (non-Javadoc) + */ @Override protected void doPopulate() { super.doPopulate(); + populateTableNameCombo(); populatePkColumnNameCombo(); populateValueColumnNameCombo(); populatePkColumnValueCombo(); } - - @Override - protected void engageListeners() { - super.engageListeners(); - if (getGenerator() != null) { - addConnectionListener(); - } - } + /* + * (non-Javadoc) + */ @Override - protected void disengageListeners() { - if (getGenerator() != null) { - removeConnectionListener(); - } - super.disengageListeners(); + protected ITableGenerator getGenerator(IIdMapping subject) { + return (subject != null) ? subject.getTableGenerator() : null; } - - private ConnectionProfile getConnectionProfile() { - if(this.connectionProfile == null) { - IJpaProject jpaProject = idMapping().getJpaProject(); - this.connectionProfile = jpaProject.connectionProfile(); + + protected Schema getSchema() { + if (getGenerator(subject()) != null) { + return null;// this.getConnectionProfile().getDatabase().schemaNamed(getGenerator().getSchema()); } - return this.connectionProfile; + return null; } - - private void addConnectionListener() { - this.getConnectionProfile().addConnectionListener(this.connectionListener); - } - - private void removeConnectionListener() { - this.getConnectionProfile().removeConnectionListener(this.connectionListener); + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Name widgets + Text nameText = this.buildNameText(container); + this.setNameText(nameText); + + this.buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_name, + nameText, + IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_NAME + ); + + // Table widgets + this.tableNameCombo = buildTableNameCombo(container); + + this.buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_table, + tableNameCombo.getParent(), + IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_TABLE + ); + + // Primary Key Column widgets + this.pkColumnNameCombo = buildPkColumnNameCombo(container); + + this.buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_pkColumn, + pkColumnNameCombo.getParent(), + IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN + ); + + // Value Column widgets + this.valueColumnNameCombo = buildValueColumnNameCombo(container); + + this.buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_valueColumn, + valueColumnNameCombo.getParent(), + IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_VALUE_COLUMN + ); + + // Primary Key Column Value widgets + this.pkColumnValueCombo = buildPkColumnValueCombo(container); + + this.buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_pkColumnValue, + pkColumnValueCombo.getParent(), + IJpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE + ); } - protected Schema getSchema() { - if (getGenerator() != null) { - return this.getConnectionProfile().getDatabase().schemaNamed(getGenerator().getSchema()); - } - return null; + private void populatePkColumnChoices() { + this.pkColumnNameCombo.remove(1, this.pkColumnNameCombo.getItemCount() - 1); + +// if (this.getConnectionProfile().isConnected()) { +// if (!this.tableNameCombo.getText().equals(JptUiMappingsMessages.TableGeneratorComposite_default)) { // hmm, +// // if they actually set the table to Default?? +// String tableName = this.tableNameCombo.getText(); +// Schema schema = getSchema(); +// if (schema != null) { +// Table table = schema.tableNamed(tableName); +// if (table != null) { +// for (Iterator<String> stream = CollectionTools.sort(table.columnNames()); stream.hasNext();) { +// this.pkColumnNameCombo.add(stream.next()); +// } +// } +// } +// } +// } } - private void populateTableNameCombo() { - if (this.getGenerator() == null) { - return; - } - if (this.getConnectionProfile().isConnected()) { - this.tableNameCombo.remove(1, this.tableNameCombo.getItemCount()-1); - Schema schema = this.getSchema(); - if (schema != null) { - Iterator<String> tables = schema.tableNames(); - for (Iterator<String> stream = CollectionTools.sort(tables); stream.hasNext(); ) { - this.tableNameCombo.add(stream.next()); - } - } - } - String tableName = this.getGenerator().getSpecifiedTable(); - if (tableName != null) { - if (!this.tableNameCombo.getText().equals(tableName)) { - this.tableNameCombo.setText(tableName); + + private void populatePkColumnName() { + String pkColumnName = this.tableGenerator().getSpecifiedPkColumnName(); + if (pkColumnName != null) { + if (!this.pkColumnNameCombo.getText().equals(pkColumnName)) { + this.pkColumnNameCombo.setText(pkColumnName); } } else { - this.tableNameCombo.select(0); + this.pkColumnNameCombo.select(0); } } private void populatePkColumnNameCombo() { - if (this.getGenerator() == null) { + if (this.tableGenerator() == null) { return; } populatePkColumnChoices(); populatePkColumnName(); } - private void populatePkColumnChoices() { - this.pkColumnNameCombo.remove(1, this.pkColumnNameCombo.getItemCount() - 1); - - if (this.getConnectionProfile().isConnected()) { - if (!this.tableNameCombo.getText().equals(JptUiMappingsMessages.TableGeneratorComposite_default)) { // hmm, - // if - // they - // actually - // set - // the - // table - // to - // Default?? - String tableName = this.tableNameCombo.getText(); - Schema schema = getSchema(); - if (schema != null) { - Table table = schema.tableNamed(tableName); - if (table != null) { - for (Iterator<String> stream = CollectionTools.sort(table.columnNames()); stream.hasNext();) { - this.pkColumnNameCombo.add(stream.next()); - } - } - } - } + + private void populatePkColumnValueCombo() { + if (this.tableGenerator() == null) { + return; } - } - - private void populatePkColumnName() { - String pkColumnName = this.getGenerator().getSpecifiedPkColumnName(); - if (pkColumnName != null) { - if (!this.pkColumnNameCombo.getText().equals(pkColumnName)) { - this.pkColumnNameCombo.setText(pkColumnName); + String pkColumnValue = this.tableGenerator().getSpecifiedPkColumnValue(); + if (pkColumnValue != null) { + if (!this.pkColumnValueCombo.getText().equals(pkColumnValue)) { + this.pkColumnValueCombo.setText(pkColumnValue); } } else { - this.pkColumnNameCombo.select(0); + this.pkColumnValueCombo.select(0); } } - private void populateValueColumnNameCombo() { - if (this.getGenerator() == null) { + private void populateTableNameCombo() { + if (this.tableGenerator() == null) { return; } - if (this.getConnectionProfile().isConnected()) { - this.valueColumnNameCombo.remove(1, this.valueColumnNameCombo.getItemCount() - 1); - if (!this.tableNameCombo.getText().equals(JptUiMappingsMessages.TableGeneratorComposite_default)) { // hmm, - // if - // they - // actually - // set - // the - // table - // to - // Default?? - String tableName = this.tableNameCombo.getText(); - Schema schema = getSchema(); - if (schema != null) { - Table table = schema.tableNamed(tableName); - if (table != null) { - for (Iterator<String> stream = CollectionTools.sort(table.columnNames()); stream.hasNext();) { - this.valueColumnNameCombo.add(stream.next()); - } - } - } - } - } - String valueColumnName = this.getGenerator().getSpecifiedValueColumnName(); - if (valueColumnName != null) { - if (!this.valueColumnNameCombo.getText().equals(valueColumnName)) { - this.valueColumnNameCombo.setText(valueColumnName); +// if (this.getConnectionProfile().isConnected()) { +// this.tableNameCombo.remove(1, this.tableNameCombo.getItemCount()-1); +// Schema schema = this.getSchema(); +// if (schema != null) { +// Iterator<String> tables = schema.tableNames(); +// for (Iterator<String> stream = CollectionTools.sort(tables); stream.hasNext(); ) { +// this.tableNameCombo.add(stream.next()); +// } +// } +// } + String tableName = this.tableGenerator().getSpecifiedTable(); + if (tableName != null) { + if (!this.tableNameCombo.getText().equals(tableName)) { + this.tableNameCombo.setText(tableName); } } else { - this.valueColumnNameCombo.select(0); + this.tableNameCombo.select(0); } } - private void populatePkColumnValueCombo() { - if (this.getGenerator() == null) { + private void populateValueColumnNameCombo() { + if (this.tableGenerator() == null) { return; } - String pkColumnValue = this.getGenerator().getSpecifiedPkColumnValue(); - if (pkColumnValue != null) { - if (!this.pkColumnValueCombo.getText().equals(pkColumnValue)) { - this.pkColumnValueCombo.setText(pkColumnValue); +// if (this.getConnectionProfile().isConnected()) { +// this.valueColumnNameCombo.remove(1, this.valueColumnNameCombo.getItemCount() - 1); +// if (!this.tableNameCombo.getText().equals(JptUiMappingsMessages.TableGeneratorComposite_default)) { // hmm, +// // if they actually set the table to Default?? +// String tableName = this.tableNameCombo.getText(); +// Schema schema = getSchema(); +// if (schema != null) { +// Table table = schema.tableNamed(tableName); +// if (table != null) { +// for (Iterator<String> stream = CollectionTools.sort(table.columnNames()); stream.hasNext();) { +// this.valueColumnNameCombo.add(stream.next()); +// } +// } +// } +// } +// } + String valueColumnName = this.tableGenerator().getSpecifiedValueColumnName(); + if (valueColumnName != null) { + if (!this.valueColumnNameCombo.getText().equals(valueColumnName)) { + this.valueColumnNameCombo.setText(valueColumnName); } } else { - this.pkColumnValueCombo.select(0); + this.valueColumnNameCombo.select(0); } } - protected void clear() { - super.clear(); - this.tableNameCombo.select(0); - this.pkColumnNameCombo.select(0); - this.pkColumnValueCombo.select(0); - this.valueColumnNameCombo.select(0); + /* + * (non-Javadoc) + */ + @Override + protected String propertyName() { + return IIdMapping.TABLE_GENERATOR_PROPERTY; } - - private ConnectionListener buildConnectionListener() { - return new ConnectionListener() { - public void closed(ConnectionProfile profile) { - populate(); - } - - public void modified(ConnectionProfile profile) { - populate(); - } - public void opened(ConnectionProfile profile) { - populate(); - } + private ITableGenerator retrieveTableGenerator() { + ITableGenerator generator = tableGenerator(); - public void databaseChanged(ConnectionProfile profile, final Database database) { - populate(); - } - - public void schemaChanged(ConnectionProfile profile, final Schema schema) { - populate(); - } + if (generator == null) { + setPopulating(true); - private void populate() { - getControl().getDisplay().asyncExec( new Runnable() { - public void run() { - if (getControl().isDisposed()) { - return; - } - populateTableNameCombo(); - populatePkColumnChoices(); - populateValueColumnNameCombo(); - } - }); - } - - public void aboutToClose(ConnectionProfile profile) { - // not interested to this event. - } - - public boolean okToClose(ConnectionProfile profile) { - // not interested to this event. - return true; + try { + generator = buildGenerator(); } - - public void tableChanged(ConnectionProfile profile, final Table table) { - // not interested to this event. + finally { + setPopulating(false); } - }; + } + + return generator; + } + + private ITableGenerator tableGenerator() { + return (subject() != null) ? subject().getTableGenerator() : null; } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityChooser.java deleted file mode 100644 index dc1ae25cfa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityChooser.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jdt.ui.IJavaElementSearchConstants; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.mappings.IRelationshipMapping; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class TargetEntityChooser extends BaseJpaController -{ - private IRelationshipMapping relationshipMapping; - private Adapter relationshipMappingListener; - - protected CCombo targetEntityCombo; - - - private Composite composite; - - public TargetEntityChooser(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildRelationshipMappingListener(); - } - - - private void buildRelationshipMappingListener() { - relationshipMappingListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - relationshipMappingChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.composite = getWidgetFactory().createComposite(parent); - GridLayout gridLayout = new GridLayout(); - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 0; - gridLayout.numColumns = 3; - this.composite.setLayout(gridLayout); - - CommonWidgets.buildTargetEntityLabel(this.composite, getWidgetFactory()); - - this.targetEntityCombo = buildTargetEntityCombo(this.composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - this.targetEntityCombo.setLayoutData(gridData); - - buildTargetEntitySelectionButton(this.composite); - - } - - protected CCombo buildTargetEntityCombo(Composite parent) { - final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT); - combo.add(JptUiMappingsMessages.TargetEntityChooser_defaultEmpty); - PlatformUI.getWorkbench().getHelpSystem().setHelp(combo, IJpaHelpContextIds.MAPPING_TARGET_ENTITY); - combo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - String targetEntityName = ((CCombo) e.getSource()).getText(); - if (targetEntityName.equals(combo.getItem(0)) || targetEntityName.equals("")) { //$NON-NLS-1$ - targetEntityName = null; - } - else if (!relationshipMapping.targetEntityIsValid(targetEntityName)) { - return; - } - relationshipMapping.setSpecifiedTargetEntity(targetEntityName); - } - }); - return combo; - } - - - private void relationshipMappingChanged(Notification notification) { - if (notification.getFeatureID(IRelationshipMapping.class) == - JpaCoreMappingsPackage.IRELATIONSHIP_MAPPING__SPECIFIED_TARGET_ENTITY) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - else if (notification.getFeatureID(IRelationshipMapping.class) == - JpaCoreMappingsPackage.IRELATIONSHIP_MAPPING__DEFAULT_TARGET_ENTITY) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (relationshipMapping != null) { - relationshipMapping.eAdapters().add(relationshipMappingListener); - } - } - - @Override - protected void disengageListeners() { - if (this.relationshipMapping != null) { - this.relationshipMapping.eAdapters().remove(relationshipMappingListener); - } - } - - @Override - public void doPopulate(EObject obj) { - this.relationshipMapping = (IRelationshipMapping) obj; - populateCombo(); - } - - @Override - protected void doPopulate() { - populateCombo(); - } - - private void populateCombo() { - if (relationshipMapping == null) { - targetEntityCombo.clearSelection(); - return; - } - String targetEntity = this.relationshipMapping.getSpecifiedTargetEntity(); - this.targetEntityCombo.setItem(0, NLS.bind(JptUiMappingsMessages.TargetEntityChooser_defaultWithOneParam, this.relationshipMapping.getDefaultTargetEntity())); - if (targetEntity != null) { - if (!this.targetEntityCombo.getText().equals(targetEntity)) { - this.targetEntityCombo.setText(targetEntity); - } - } - else { - if (this.targetEntityCombo.getSelectionIndex() != 0) { - this.targetEntityCombo.select(0); - } - } - } - - @Override - public Control getControl() { - return this.composite; - } - - //see org.eclipse.pde.internal.ui.editor.plugin.rows.ClassAttributeRow - //for example of the hyperlink opening a resource - protected Button buildTargetEntitySelectionButton(Composite parent) { - Button button = getWidgetFactory().createButton( - parent, - JptUiMappingsMessages.TargetEntityChooser_browse, - SWT.PUSH); - - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - browse(); - } - }); - return button; - } - - protected void browse() { - BusyIndicator.showWhile(this.targetEntityCombo.getDisplay(), new Runnable() { - public void run() { - doOpenSelectionDialog(); - } - }); - } - - private void doOpenSelectionDialog() { - SelectionDialog dialog; - try { - dialog = JavaUI.createTypeDialog(getControl().getShell(), - PlatformUI.getWorkbench().getProgressService(), - SearchEngine.createWorkspaceScope(), - IJavaElementSearchConstants.CONSIDER_ALL_TYPES, - false, - ""); //$NON-NLS-1$ - } - catch (JavaModelException e) { - throw new RuntimeException(e); - } - dialog.setTitle("Select Type"); //$NON-NLS-1$ - if (dialog.open() == Window.OK) { - IType type = (IType) dialog.getResult()[0]; - this.targetEntityCombo.setText(type.getFullyQualifiedName('$')); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityComposite.java new file mode 100644 index 0000000000..30d7a90859 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityComposite.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Collection; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.ui.IJavaElementSearchConstants; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jface.window.Window; +import org.eclipse.jpt.core.internal.context.base.IRelationshipMapping; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.ui.forms.widgets.Hyperlink; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ---------------------------------------------------------- | + * | Target Entity: | |v| | + * | ---------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IRelationshipMapping + * @see OneToOneMappingComposite - A container of this pane + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public class TargetEntityComposite extends AbstractFormPane<IRelationshipMapping> +{ + private CCombo targetEntityCombo; + + /** + * Creates a new <code>TargetEntityComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + protected TargetEntityComposite(AbstractFormPane<? extends IRelationshipMapping> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>TargetEntityComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IRelationshipMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public TargetEntityComposite(PropertyValueModel<? extends IRelationshipMapping> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IRelationshipMapping.DEFAULT_TARGET_ENTITY_PROPERTY); + propertyNames.add(IRelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY); + } + + private Runnable buildOpenTargetEntityAction() { + return new Runnable() { + public void run() { + System.out.println("TODO: Open Editor"); + } + }; + } + + private Runnable buildOpenTypeAction() { + return new Runnable() { + public void run() { + BusyIndicator.showWhile(targetEntityCombo.getDisplay(), new Runnable() { + public void run() { + doOpenSelectionDialog(); + } + }); + } + }; + } + + private ModifyListener buildTargetEntityModifyListener() { + return new ModifyListener() { + public void modifyText(ModifyEvent e) { + + String targetEntityName = targetEntityCombo.getText(); + + if (StringTools.stringIsEmpty(targetEntityName)) { + targetEntityName = null; + } + else if (targetEntityName.equals(targetEntityCombo.getItem(0)) || targetEntityName.equals("")) { //$NON-NLS-1$ + targetEntityName = null; + } + else if (!subject().targetEntityIsValid(targetEntityName)) { + return; + } + + if (targetEntityName != null) { + targetEntityName = targetEntityName.trim(); + } + + subject().setSpecifiedTargetEntity(targetEntityName); + } + }; + } + + private Button buildTargetEntitySelectionButton(Composite parent) { + return buildPushButton( + parent, + JptUiMappingsMessages.TargetEntityChooser_browse, + buildOpenTypeAction() + ); + } + + private void doOpenSelectionDialog() { + SelectionDialog dialog; + + try { + dialog = JavaUI.createTypeDialog( + getControl().getShell(), + PlatformUI.getWorkbench().getProgressService(), + SearchEngine.createWorkspaceScope(), + IJavaElementSearchConstants.CONSIDER_ALL_TYPES, + false + ); + } + catch (JavaModelException e) { + JptUiPlugin.log(e); + return; + } + + dialog.setTitle(JptUiMappingsMessages.TargetEntityChooser_selectTypeTitle); + + if (dialog.open() == Window.OK) { + IType type = (IType) dialog.getResult()[0]; + this.targetEntityCombo.setText(type.getFullyQualifiedName('$')); + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + this.populateCombo(); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + targetEntityCombo = buildCombo(container); + targetEntityCombo.add(JptUiMappingsMessages.TargetEntityChooser_defaultEmpty); + targetEntityCombo.addModifyListener(buildTargetEntityModifyListener()); + + Hyperlink labelLink = buildHyperLink(container, + JptUiMappingsMessages.TargetEntityChooser_label, + buildOpenTargetEntityAction() + ); + + buildLabeledComposite( + container, + labelLink, + targetEntityCombo, + buildTargetEntitySelectionButton(container), + IJpaHelpContextIds.MAPPING_TARGET_ENTITY + ); + } + + private void populateCombo() { + + if (targetEntityCombo.isDisposed()) { + return; + } + + targetEntityCombo.clearSelection(); + + if (subject() != null) { + String targetEntity = subject().getSpecifiedTargetEntity(); + targetEntityCombo.setItem(0, NLS.bind(JptUiMappingsMessages.TargetEntityChooser_defaultWithOneParam, subject().getDefaultTargetEntity())); + + if (targetEntity != null) { + if (!targetEntityCombo.getText().equals(targetEntity)) { + targetEntityCombo.setText(targetEntity); + } + } + else { + if (targetEntityCombo.getSelectionIndex() != 0) { + targetEntityCombo.select(0); + } + } + } + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + + if (propertyName == IRelationshipMapping.DEFAULT_TARGET_ENTITY_PROPERTY || + propertyName == IRelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY) { + + populateCombo(); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TemporalTypeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TemporalTypeComposite.java new file mode 100644 index 0000000000..9323beb2f1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TemporalTypeComposite.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.IColumnMapping; +import org.eclipse.jpt.core.internal.context.base.TemporalType; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | --------------------------------------------------------------- | + * | Temporal: | |v| | + * | --------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IColumnMapping + * @see BasicMappingComposite - A container of this widget + * @see IdMappingComposite - A container of this widget + * @see VersionMappingComposite - A container of this widget + * + * @version 2.0 + * @since 1.0 + */ +public class TemporalTypeComposite extends AbstractFormPane<IColumnMapping> { + + /** + * Creates a new <code>TemporalTypeComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public TemporalTypeComposite(AbstractFormPane<? extends IColumnMapping> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + private EnumComboViewer<IColumnMapping, TemporalType> buildTemporalCombo(Composite container) { + + return new EnumComboViewer<IColumnMapping, TemporalType>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(IColumnMapping.TEMPORAL_PROPERTY); + } + + @Override + protected TemporalType[] choices() { + return TemporalType.values(); + } + + @Override + protected TemporalType defaultValue() { + return null; + } + + @Override + protected String displayString(TemporalType value) { + return buildDisplayString( + JptUiMappingsMessages.class, + TemporalTypeComposite.this, + value.name() + ); + } + + @Override + protected TemporalType getValue() { + return subject().getTemporal(); + } + + @Override + protected void setValue(TemporalType value) { + subject().setTemporal(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + EnumComboViewer<IColumnMapping, TemporalType> temporalCombo = + buildTemporalCombo(container); + + buildLabeledComposite( + container, + JptUiMappingsMessages.BasicGeneralSection_temporalLabel, + temporalCombo.getControl(), + IJpaHelpContextIds.MAPPING_TEMPORAL + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientComposite.java deleted file mode 100644 index 3871e8ac4c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientComposite.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class TransientComposite extends BaseJpaComposite -{ - public TransientComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - - @Override - protected void initializeLayout(Composite composite) { - - } - - - public void doPopulate(EObject obj) { - } - - public void doPopulate() { - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientMappingComposite.java new file mode 100644 index 0000000000..7614db08c8 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientMappingComposite.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.ITransientMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * This pane does not have any widgets. + * + * @see ITransientMapping + * @see BaseJpaUiFactory - The factory creating this pane + * + * @version 2.0 + * @since 1.0 + */ +public class TransientMappingComposite extends AbstractFormPane<ITransientMapping> + implements IJpaComposite<ITransientMapping> +{ + /** + * Creates a new <code>TransientMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>ITransientMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public TransientMappingComposite(PropertyValueModel<? extends ITransientMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionComposite.java deleted file mode 100644 index fe7fb65ac2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionComposite.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.impl.EObjectImpl; -import org.eclipse.jpt.core.internal.mappings.IBasic; -import org.eclipse.jpt.core.internal.mappings.IVersion; -import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; -import org.eclipse.jpt.core.internal.mappings.TemporalType; -import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; -import org.eclipse.jpt.ui.internal.mappings.details.EnumComboViewer.EnumHolder; -import org.eclipse.swt.SWT; -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.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class VersionComposite extends BaseJpaComposite -{ - private IVersion version; - - private ColumnComposite columnComposite; - - private EnumComboViewer temporalTypeViewer; - - - public VersionComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, SWT.NULL, commandStack, widgetFactory); - } - @Override - protected void initializeLayout(Composite composite) { - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - - Control generalControl = buildGeneralComposite(composite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - generalControl.setLayoutData(gridData); - - } - - private Control buildGeneralComposite(Composite composite) { -// IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - - Composite generalComposite = getWidgetFactory().createComposite(composite); - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 0; - generalComposite.setLayout(layout); - - this.columnComposite = new ColumnComposite(generalComposite, this.commandStack, getWidgetFactory()); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.columnComposite.getControl().setLayoutData(gridData); - - CommonWidgets.buildTemporalLabel(generalComposite, getWidgetFactory()); - this.temporalTypeViewer = CommonWidgets.buildEnumComboViewer(generalComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.temporalTypeViewer.getControl().setLayoutData(gridData); - - return generalComposite; - } - - public void doPopulate(EObject obj) { - this.version = (IVersion) obj; - if (this.version != null) { - this.columnComposite.populate(this.version.getColumn()); - } - else { - this.columnComposite.populate(null); - } - this.temporalTypeViewer.populate(new TemporalTypeHolder(this.version)); - } - - public void doPopulate() { - this.columnComposite.populate(); - this.temporalTypeViewer.populate(); - } - - protected void engageListeners() { - } - - protected void disengageListeners() { - } - - @Override - public void dispose() { - this.columnComposite.dispose(); - this.temporalTypeViewer.dispose(); - super.dispose(); - } - - protected IVersion getVersion() { - return this.version; - } - - - - - private class TemporalTypeHolder extends EObjectImpl implements EnumHolder { - - private IVersion version; - - TemporalTypeHolder(IVersion version) { - super(); - this.version = version; - } - - public Object get() { - return this.version.getTemporal(); - } - - public void set(Object enumSetting) { - this.version.setTemporal((TemporalType) enumSetting); - } - - public Class featureClass() { - return IBasic.class; - } - - public int featureId() { - return JpaCoreMappingsPackage.IVERSION__TEMPORAL; - } - - public EObject wrappedObject() { - return this.version; - } - - public Object[] enumValues() { - return TemporalType.VALUES.toArray(); - } - - /** - * TemporalType has no Default, return null - */ - public Object defaultValue() { - return null; - } - - /** - * TemporalType has no Default, return null - */ - public String defaultString() { - return null; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionMappingComposite.java new file mode 100644 index 0000000000..1af0e0b84d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionMappingComposite.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.ui.internal.mappings.details; + +import org.eclipse.jpt.core.internal.context.base.IColumn; +import org.eclipse.jpt.core.internal.context.base.IVersionMapping; +import org.eclipse.jpt.ui.internal.details.IJpaComposite; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | ColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | TemporalTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see IBasicMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see ColumnComposite + * @see TemporalTypeComposite + * + * @version 2.0 + * @since 1.0 + */ +public class VersionMappingComposite extends AbstractFormPane<IVersionMapping> + implements IJpaComposite<IVersionMapping> +{ + /** + * Creates a new <code>VersionMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IVersionMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public VersionMappingComposite(PropertyValueModel<? extends IVersionMapping> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<IColumn> buildColumnHolder() { + return new TransformationPropertyValueModel<IVersionMapping, IColumn>(getSubjectHolder()) { + @Override + protected IColumn transform_(IVersionMapping value) { + return value.getColumn(); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Column widgets + new ColumnComposite(this, buildColumnHolder(), container); + + // Temporal Type widgets + new TemporalTypeComposite(this, container); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java new file mode 100644 index 0000000000..58ff3beae1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java @@ -0,0 +1,258 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.navigator; + +import java.util.HashMap; +import java.util.Map; +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.core.internal.IJpaPlatform; +import org.eclipse.jpt.core.internal.IJpaProject; +import org.eclipse.jpt.core.internal.JptCorePlugin; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.ui.internal.IJpaPlatformUi; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +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.ProjectFacetsManager; +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; + +/** + * This extension of navigator content provider delegates to the platform UI + * (see the org.eclipse.jpt.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. + */ +public class JpaNavigatorContentProvider + implements ICommonContentProvider +{ + private IFacetedProjectListener facetListener; + + private StructuredViewer viewer; + + /** + * Exactly *one* of these 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 + */ + private Map<String, ICommonContentProvider> delegateContentProviders; + + + public JpaNavigatorContentProvider() { + super(); + delegateContentProviders = new HashMap<String, ICommonContentProvider>(); + facetListener = new FacetListener(); + FacetedProjectFramework.addListener( + facetListener, + IFacetedProjectEvent.Type.POST_INSTALL, + IFacetedProjectEvent.Type.POST_UNINSTALL, + IFacetedProjectEvent.Type.PROJECT_MODIFIED); + } + + + // **************** IContentProvider implementation ************************ + + public void dispose() { + FacetedProjectFramework.removeListener(facetListener); + for (ICommonContentProvider delegate : delegateContentProviders.values()) { + delegate.dispose(); + } + delegateContentProviders.clear(); + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // should always be a StructuredViewer + this.viewer = (StructuredViewer) viewer; + for (ICommonContentProvider delegate : delegateContentProviders.values()) { + delegate.inputChanged(viewer, oldInput, newInput); + } + } + + + // **************** IStructuredContentProvider implementation ************** + + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + + // **************** ITreeContentProvider implementation ******************** + + public Object getParent(Object element) { + ICommonContentProvider delegate = getDelegate(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) { + IJpaProject jpaProject = JptCorePlugin.jpaProject(project); + if (jpaProject != null) { + IJpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaProject.jpaPlatform()); + + return platformUi != null; + } + } + } + + ICommonContentProvider delegate = getDelegate(element); + + 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) { + IJpaProject jpaProject = JptCorePlugin.jpaProject(project); + if (jpaProject != null) { + IJpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaProject.jpaPlatform()); + + if (platformUi != null) { + return new Object[] {jpaProject.contextModel()}; + } + } + } + } + + ICommonContentProvider delegate = getDelegate(parentElement); + + if (delegate != null) { + return delegate.getChildren(parentElement); + } + + return new Object[0]; + } + + + // **************** IMementoAware implementation *************************** + + public void saveState(IMemento memento) { + for (ICommonContentProvider delegate : delegateContentProviders.values()) { + delegate.saveState(memento); + } + } + + public void restoreState(IMemento memento) { + for (ICommonContentProvider delegate : delegateContentProviders.values()) { + delegate.restoreState(memento); + } + } + + + // **************** ICommonContentProvider implementation ****************** + + public void init(ICommonContentExtensionSite config) { + for (ICommonContentProvider delegate : delegateContentProviders.values()) { + delegate.init(config); + } + } + + + // *************** internal ************************************************ + + private ICommonContentProvider getDelegate(Object element) { + if (! (element instanceof IAdaptable)) { + return null; + } + + IJpaContextNode contextNode = (IJpaContextNode) ((IAdaptable) element).getAdapter(IJpaContextNode.class); + + if (contextNode == null) { + return null; + } + + IJpaPlatform platform = contextNode.jpaProject().jpaPlatform(); + IJpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(platform); + + ICommonContentProvider delegate = delegateContentProviders.get(platform.getId()); + + if (delegate == null && platform != null && ! delegateContentProviders.containsKey(platform.getId())) { + delegate = platformUi.buildNavigatorContentProvider(); + delegateContentProviders.put(platform.getId(), delegate); + } + + return delegate; + } + + + // **************** 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( + ProjectFacetsManager.getProjectFacet(JptCorePlugin.FACET_ID))) { + 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(); + } + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorLabelProvider.java new file mode 100644 index 0000000000..96714c09c0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorLabelProvider.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.navigator; + +import java.util.HashMap; +import java.util.Map; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.LabelProviderChangedEvent; +import org.eclipse.jpt.core.internal.IJpaPlatform; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.ui.internal.IJpaPlatformUi; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +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 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 +{ + /** + * Exactly *one* of these 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 label provider + */ + private Map<String, ICommonLabelProvider> delegateLabelProviders; + + private ILabelProviderListener delegateLabelProviderListener; + + + public JpaNavigatorLabelProvider() { + super(); + delegateLabelProviders = new HashMap<String, ICommonLabelProvider>(); + delegateLabelProviderListener = new DelegateLabelProviderListener(); + } + + + // **************** IBaseLabelProvider implementation ********************** + + public void addListener(ILabelProviderListener listener) { + super.addListener(listener); + } + + public void removeListener(ILabelProviderListener listener) { + super.removeListener(listener); + } + + public boolean isLabelProperty(Object element, String property) { + ICommonLabelProvider delegate = getDelegate(element); + + if (delegate != null) { + return delegate.isLabelProperty(element, property); + } + + return super.isLabelProperty(element, property); + } + + public void dispose() { + super.dispose(); + for (ICommonLabelProvider delegate : delegateLabelProviders.values()) { + delegate.dispose(); + } + delegateLabelProviders.clear(); + } + + + // **************** ILabelProvider implementation ************************** + + public Image getImage(Object element) { + ICommonLabelProvider delegate = getDelegate(element); + + if (delegate != null) { + return delegate.getImage(element); + } + + return super.getImage(element); + } + + public String getText(Object element) { + ICommonLabelProvider delegate = getDelegate(element); + + if (delegate != null) { + return delegate.getText(element); + } + + return super.getText(element); + } + + + // **************** IDescriptionProvider implementation ******************** + + public String getDescription(Object element) { + ICommonLabelProvider delegate = getDelegate(element); + + if (delegate != null) { + return delegate.getDescription(element); + } + + // no "super" implementation - default to getText(..) for description + return super.getText(element); + } + + + // **************** IMementoAware implementation *************************** + + public void saveState(IMemento memento) { + for (ICommonLabelProvider delegate : delegateLabelProviders.values()) { + delegate.saveState(memento); + } + } + + public void restoreState(IMemento memento) { + for (ICommonLabelProvider delegate : delegateLabelProviders.values()) { + delegate.restoreState(memento); + } + } + + + // **************** ICommonLabelProvider implementation ******************** + + public void init(ICommonContentExtensionSite config) { + for (ICommonLabelProvider delegate : delegateLabelProviders.values()) { + delegate.init(config); + } + } + + + // *************** internal ************************************************ + + private ICommonLabelProvider getDelegate(Object element) { + if (! (element instanceof IAdaptable)) { + return null; + } + + IJpaContextNode contextNode = (IJpaContextNode) ((IAdaptable) element).getAdapter(IJpaContextNode.class); + + if (contextNode == null) { + return null; + } + + IJpaPlatform platform = contextNode.jpaProject().jpaPlatform(); + IJpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(platform); + + ICommonLabelProvider delegate = delegateLabelProviders.get(platform.getId()); + + if (delegate == null && platform != null && ! delegateLabelProviders.containsKey(platform.getId())) { + delegate = platformUi.buildNavigatorLabelProvider(); + delegate.addListener(delegateLabelProviderListener); + delegateLabelProviders.put(platform.getId(), delegate); + } + + return delegate; + } + + + private class DelegateLabelProviderListener + implements ILabelProviderListener + { + public void labelProviderChanged(LabelProviderChangedEvent event) { + fireLabelProviderChanged(event); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/PlatformRegistry.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/JpaPlatformUiRegistry.java index ede93c3a73..b70eb5d893 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/PlatformRegistry.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/JpaPlatformUiRegistry.java @@ -6,7 +6,7 @@ * * Contributors: Oracle. - initial API and implementation *******************************************************************************/ -package org.eclipse.jpt.ui.internal; +package org.eclipse.jpt.ui.internal.platform; import java.util.HashMap; import java.util.Iterator; @@ -17,19 +17,21 @@ import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; +import org.eclipse.jpt.ui.internal.IJpaPlatformUi; +import org.eclipse.jpt.ui.internal.JptUiPlugin; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -public class PlatformRegistry +public class JpaPlatformUiRegistry { // singleton - private static final PlatformRegistry INSTANCE = new PlatformRegistry(); + private static final JpaPlatformUiRegistry INSTANCE = new JpaPlatformUiRegistry(); /** * Return the singleton. */ - public static PlatformRegistry instance() { + public static JpaPlatformUiRegistry instance() { return INSTANCE; } @@ -52,7 +54,7 @@ public class PlatformRegistry /* (non Java doc) * restrict access */ - private PlatformRegistry() { + private JpaPlatformUiRegistry() { buildJpaPlatforms(); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaNavigatorContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaNavigatorContentProvider.java new file mode 100644 index 0000000000..967c29ef8a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaNavigatorContentProvider.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.platform.base; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jpt.core.internal.context.base.IBaseJpaContent; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.navigator.ICommonContentExtensionSite; +import org.eclipse.ui.navigator.ICommonContentProvider; + +public class BaseJpaNavigatorContentProvider implements ICommonContentProvider +{ + public void init(ICommonContentExtensionSite config) { + // TODO Auto-generated method stub + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof IBaseJpaContent) { + IBaseJpaContent baseJpaContent = (IBaseJpaContent) parentElement; + if (baseJpaContent.getPersistenceXml() != null) { + return new Object[] {baseJpaContent.getPersistenceXml()}; + } + } + + return new Object[0]; + } + + public Object getParent(Object element) { + // TODO Auto-generated method stub + return null; + } + + public boolean hasChildren(Object element) { + return element instanceof IBaseJpaContent; + } + + public Object[] getElements(Object inputElement) { + // TODO Auto-generated method stub + return null; + } + + public void dispose() { + // TODO Auto-generated method stub + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method stub + } + + public void restoreState(IMemento memento) { + // TODO Auto-generated method stub + } + + public void saveState(IMemento memento) { + // TODO Auto-generated method stub + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaNavigatorLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaNavigatorLabelProvider.java new file mode 100644 index 0000000000..85c7aa3716 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaNavigatorLabelProvider.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.platform.base; + +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jpt.core.internal.IContextModel; +import org.eclipse.jpt.core.internal.context.base.PersistenceXml; +import org.eclipse.jpt.ui.internal.JptUiIcons; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.navigator.ICommonContentExtensionSite; +import org.eclipse.ui.navigator.ICommonLabelProvider; + +public class BaseJpaNavigatorLabelProvider extends LabelProvider + implements ICommonLabelProvider +{ + + // **************** IBaseLabelProvider implementation ********************** + + public void addListener(ILabelProviderListener listener) { + super.addListener(listener); + } + + public void removeListener(ILabelProviderListener listener) { + super.addListener(listener); + } + + public boolean isLabelProperty(Object element, String property) { + return super.isLabelProperty(element, property); + } + + public void dispose() { + super.dispose(); + } + + + // **************** ILabelProvider implementation ************************** + + public Image getImage(Object element) { + if (element instanceof IContextModel) { + return JptUiPlugin.getPlugin().getImage(JptUiIcons.JPA_CONTENT); + } + + if (element instanceof PersistenceXml) { + return JptUiPlugin.getPlugin().getImage(JptUiIcons.JPA_FILE); + } + + return super.getImage(element); + } + + public String getText(Object element) { + if (element instanceof IContextModel) { + return "JPA Content"; + } + + if (element instanceof PersistenceXml) { + return "persistence.xml"; + } + + return null; + } + + + // **************** IDescriptionProvider implementation ******************** + + public String getDescription(Object anElement) { + // TODO Auto-generated method stub + return getText(anElement); + } + + + // **************** IMementoAware implementation *************************** + + public void saveState(IMemento memento) { + // TODO Auto-generated method stub + } + + public void restoreState(IMemento memento) { + // TODO Auto-generated method stub + } + + + // **************** ICommonLabelProvider implementation ******************** + + public void init(ICommonContentExtensionSite config) { + // TODO Auto-generated method stub + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java index 9298773ef0..0c37db0aa6 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java @@ -3,11 +3,11 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ -package org.eclipse.jpt.ui.internal; +package org.eclipse.jpt.ui.internal.platform.base; import java.util.ArrayList; import java.util.Collection; @@ -16,8 +16,13 @@ import java.util.List; import java.util.ListIterator; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.internal.IJpaProject; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; +import org.eclipse.jpt.core.internal.context.java.IJavaJpaContextNode; +import org.eclipse.jpt.ui.internal.IJpaPlatformUi; +import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.details.IJpaDetailsProvider; -import org.eclipse.jpt.ui.internal.generic.EntitiesGenerator; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; import org.eclipse.jpt.ui.internal.java.details.JavaDetailsProvider; @@ -37,31 +42,45 @@ import org.eclipse.jpt.ui.internal.java.mappings.properties.OneToManyMappingUiPr import org.eclipse.jpt.ui.internal.java.mappings.properties.OneToOneMappingUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.TransientMappingUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.VersionMappingUiProvider; -import org.eclipse.jpt.ui.internal.java.structure.JavaStructureProvider; import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; import org.eclipse.jpt.ui.internal.xml.details.XmlDetailsProvider; -import org.eclipse.jpt.ui.internal.xml.structure.XmlStructureProvider; import org.eclipse.jpt.utility.internal.iterators.CloneIterator; import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; +import org.eclipse.ui.navigator.ICommonContentProvider; +import org.eclipse.ui.navigator.ICommonLabelProvider; public abstract class BaseJpaPlatformUi implements IJpaPlatformUi { - private Collection<IJpaDetailsProvider> detailsProviders; + // TODO: Transformed into a List for testing + private List<IJpaDetailsProvider> detailsProviders; private Collection<IJpaStructureProvider> structureProviders; - - private List<ITypeMappingUiProvider> javaTypeMappingUiProviders; - private List<IAttributeMappingUiProvider> javaAttributeMappingUiProviders; - private List<IAttributeMappingUiProvider> defaultJavaAttributeMappingUiProviders; - + + private List<ITypeMappingUiProvider<? extends ITypeMapping>> javaTypeMappingUiProviders; + private List<IAttributeMappingUiProvider<? extends IAttributeMapping>> javaAttributeMappingUiProviders; + private List<IAttributeMappingUiProvider<? extends IAttributeMapping>> defaultJavaAttributeMappingUiProviders; + private IJpaUiFactory jpaUiFactory; - + + protected BaseJpaPlatformUi() { super(); this.jpaUiFactory = createJpaUiFactory(); } + + // **************** navigator content ************************************** + + public ICommonContentProvider buildNavigatorContentProvider() { + return new BaseJpaNavigatorContentProvider(); + } + + public ICommonLabelProvider buildNavigatorLabelProvider() { + return new BaseJpaNavigatorLabelProvider(); + } + + // ********** behavior ********** - + protected abstract IJpaUiFactory createJpaUiFactory(); public IJpaUiFactory getJpaUiFactory() { @@ -75,7 +94,7 @@ public abstract class BaseJpaPlatformUi implements IJpaPlatformUi } return new CloneIterator<IJpaDetailsProvider>(this.detailsProviders); } - + /** * Override this to specify more or different details providers. * The default includes the JPA spec-defined java and orm.xml @@ -84,110 +103,96 @@ public abstract class BaseJpaPlatformUi implements IJpaPlatformUi providers.add(new JavaDetailsProvider()); providers.add(new XmlDetailsProvider()); } - - public IJpaDetailsProvider detailsProvider(String fileContentType) { - for (Iterator<IJpaDetailsProvider> i = this.detailsProviders(); i.hasNext(); ) { - IJpaDetailsProvider provider = i.next(); - if (provider.fileContentType().equals(fileContentType)) { - return provider; - } + + public IJpaDetailsProvider detailsProvider(IJpaContextNode contextNode) { + // TODO: To implement, this is written only for testing + detailsProviders(); + if (contextNode instanceof IJavaJpaContextNode) { + return detailsProviders.get(0); } - return null; - } - - public Iterator<IJpaStructureProvider> structureProviders() { - if (this.structureProviders == null) { - this.structureProviders = new ArrayList<IJpaStructureProvider>(); - this.addStructureProvidersTo(this.structureProviders); + else { + return detailsProviders.get(1); } - return new CloneIterator<IJpaStructureProvider>(this.structureProviders); - } - - /** - * Override this to specify more or different structure providers. - * The default includes the JPA spec-defined java and orm.xml - */ - protected void addStructureProvidersTo(Collection<IJpaStructureProvider> providers) { - providers.add(new JavaStructureProvider()); - providers.add(new XmlStructureProvider()); +// for (Iterator<IJpaDetailsProvider> i = this.detailsProviders(); i.hasNext(); ) { +// IJpaDetailsProvider provider = i.next(); +// if (provider.fileContentType().equals(fileContentType)) { +// return provider; +// } +// } +// return null; } - public IJpaStructureProvider structureProvider(String fileContentType) { - for (Iterator<IJpaStructureProvider> i = this.structureProviders(); i.hasNext(); ) { - IJpaStructureProvider provider = i.next(); - if (provider.fileContentType().equals(fileContentType)) { - return provider; - } - } - return null; - } - - public ListIterator<ITypeMappingUiProvider> javaTypeMappingUiProviders() { + public ListIterator<ITypeMappingUiProvider<? extends ITypeMapping>> javaTypeMappingUiProviders() { if (this.javaTypeMappingUiProviders == null) { - this.javaTypeMappingUiProviders = new ArrayList<ITypeMappingUiProvider>(); + this.javaTypeMappingUiProviders = new ArrayList<ITypeMappingUiProvider<? extends ITypeMapping>>(); this.addJavaTypeMappingUiProvidersTo(this.javaTypeMappingUiProviders); } - return new CloneListIterator<ITypeMappingUiProvider>(this.javaTypeMappingUiProviders); + return new CloneListIterator<ITypeMappingUiProvider<? extends ITypeMapping>>( + this.javaTypeMappingUiProviders + ); } - + /** * Override this to specify more or different type mapping ui providers * The default includes the JPA spec-defined entity, mapped superclass, embeddable, * and null (when the others don't apply) */ - protected void addJavaTypeMappingUiProvidersTo(List<ITypeMappingUiProvider> providers) { + protected void addJavaTypeMappingUiProvidersTo(List<ITypeMappingUiProvider<? extends ITypeMapping>> providers) { providers.add(NullTypeMappingUiProvider.instance()); providers.add(EntityUiProvider.instance()); - providers.add(MappedSuperclassUiProvider.instance()); - providers.add(EmbeddableUiProvider.instance()); + providers.add(MappedSuperclassUiProvider.instance()); + providers.add(EmbeddableUiProvider.instance()); } - - public ListIterator<IAttributeMappingUiProvider> javaAttributeMappingUiProviders() { + + public ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> javaAttributeMappingUiProviders() { if (this.javaAttributeMappingUiProviders == null) { - this.javaAttributeMappingUiProviders = new ArrayList<IAttributeMappingUiProvider>(); + this.javaAttributeMappingUiProviders = new ArrayList<IAttributeMappingUiProvider<? extends IAttributeMapping>>(); this.addJavaAttributeMappingUiProvidersTo(this.javaAttributeMappingUiProviders); } - return new CloneListIterator<IAttributeMappingUiProvider>(this.javaAttributeMappingUiProviders); + return new CloneListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>>( + this.javaAttributeMappingUiProviders + ); } - + /** * Override this to specify more or different java attribute mapping ui providers. - * The default includes the JPA spec-defined basic, embedded, embeddedId, id, + * The default includes the JPA spec-defined basic, embedded, embeddedId, id, * manyToMany, manyToOne, oneToMany, oneToOne, transient, and version */ - protected void addJavaAttributeMappingUiProvidersTo(List<IAttributeMappingUiProvider> providers) { + protected void addJavaAttributeMappingUiProvidersTo(List<IAttributeMappingUiProvider<? extends IAttributeMapping>> providers) { providers.add(BasicMappingUiProvider.instance()); providers.add(EmbeddedMappingUiProvider.instance()); providers.add(EmbeddedIdMappingUiProvider.instance()); - providers.add(IdMappingUiProvider.instance()); - providers.add(ManyToManyMappingUiProvider.instance()); - providers.add(ManyToOneMappingUiProvider.instance()); - providers.add(OneToManyMappingUiProvider.instance()); + providers.add(IdMappingUiProvider.instance()); + providers.add(ManyToManyMappingUiProvider.instance()); + providers.add(ManyToOneMappingUiProvider.instance()); + providers.add(OneToManyMappingUiProvider.instance()); providers.add(OneToOneMappingUiProvider.instance()); providers.add(TransientMappingUiProvider.instance()); providers.add(VersionMappingUiProvider.instance()); } - - public ListIterator<IAttributeMappingUiProvider> defaultJavaAttributeMappingUiProviders() { + + public ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> defaultJavaAttributeMappingUiProviders() { if (this.defaultJavaAttributeMappingUiProviders == null) { - this.defaultJavaAttributeMappingUiProviders = new ArrayList<IAttributeMappingUiProvider>(); + this.defaultJavaAttributeMappingUiProviders = new ArrayList<IAttributeMappingUiProvider<? extends IAttributeMapping>>(); this.addDefaultJavaAttributeMappingUiProvidersTo(this.defaultJavaAttributeMappingUiProviders); } - return new CloneListIterator<IAttributeMappingUiProvider>(this.defaultJavaAttributeMappingUiProviders); + return new CloneListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>>( + this.defaultJavaAttributeMappingUiProviders + ); } - + /** * Override this to specify more or different default java attribute mapping ui providers. * The default includes the JPA spec-defined basic, embedded */ - protected void addDefaultJavaAttributeMappingUiProvidersTo(List<IAttributeMappingUiProvider> providers) { + protected void addDefaultJavaAttributeMappingUiProvidersTo(List<IAttributeMappingUiProvider<? extends IAttributeMapping>> providers) { providers.add(DefaultBasicMappingUiProvider.instance()); providers.add(DefaultEmbeddedMappingUiProvider.instance()); } - public void generateEntities(IJpaProject project, IStructuredSelection selection) { EntitiesGenerator.generate(project, selection); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/generic/EntitiesGenerator.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/EntitiesGenerator.java index 8613951a8b..69653c833f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/generic/EntitiesGenerator.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/EntitiesGenerator.java @@ -7,9 +7,10 @@ * Contributors: * Oracle - initial API and implementation *******************************************************************************/ -package org.eclipse.jpt.ui.internal.generic; +package org.eclipse.jpt.ui.internal.platform.base; import java.util.Collection; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; @@ -22,9 +23,11 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jpt.core.internal.IJpaFile; import org.eclipse.jpt.core.internal.IJpaProject; +import org.eclipse.jpt.core.internal.context.base.IBaseJpaContent; +import org.eclipse.jpt.core.internal.context.base.IPersistenceXml; import org.eclipse.jpt.core.internal.synch.SynchronizeClassesJob; +import org.eclipse.jpt.db.internal.Table; import org.eclipse.jpt.gen.internal.EntityGenerator; import org.eclipse.jpt.gen.internal.PackageGenerator; import org.eclipse.jpt.ui.internal.JptUiMessages; @@ -80,7 +83,7 @@ public class EntitiesGenerator wizard.getEntityGeneratorConfig(), wizard.getSelectedTables(), wizard.synchronizePersistenceXml(), - project, + this.project, new OverwriteConfirmer(this.getCurrentShell()) ); @@ -97,7 +100,7 @@ public class EntitiesGenerator static class GenerateEntitiesRunnable extends WorkspaceJob { private final PackageGenerator.Config packageConfig; private final EntityGenerator.Config entityConfig; - private final Collection selectedTables; + private final Collection<Table> selectedTables; private final boolean synchronizePersistenceXml; private final EntityGenerator.OverwriteConfirmer overwriteConfirmer; private final IJpaProject project; @@ -105,7 +108,7 @@ public class EntitiesGenerator GenerateEntitiesRunnable( PackageGenerator.Config packageConfig, EntityGenerator.Config entityConfig, - Collection selectedTables, + Collection<Table> selectedTables, boolean synchronizePersistenceXml, IJpaProject project, EntityGenerator.OverwriteConfirmer overwriteConfirmer @@ -125,11 +128,14 @@ public class EntitiesGenerator PackageGenerator.generateEntities(this.packageConfig, this.entityConfig, this.selectedTables, this.overwriteConfirmer, monitor); //force resourceChangeEvents to be posted before synchronizing persistence.xml ResourcesPlugin.getWorkspace().checkpoint(false); - if (synchronizePersistenceXml) { + if (this.synchronizePersistenceXml) { // we currently only support *one* persistence.xml file per project - IJpaFile resource = project.jpaPlatform().validPersistenceXmlFiles().next(); - if (resource != null) { - SynchronizeClassesJob job = new SynchronizeClassesJob(resource.getFile()); + //TODO casting to IBaseJpaContent, IContextModel doesn't seem useful to me + //just trying to get rid of all compiler errors for now KFB + IPersistenceXml persistenceXml = ((IBaseJpaContent) this.project.contextModel()).getPersistenceXml(); + if (persistenceXml != null) { + //TODO casting to IFile - just trying to get rid of all compiler errors for now + SynchronizeClassesJob job = new SynchronizeClassesJob((IFile) persistenceXml.resource()); job.schedule(); } } @@ -165,7 +171,7 @@ public class EntitiesGenerator final OverwriteConfirmerDialog dialog = new OverwriteConfirmerDialog(this.shell, className); //get on the UI thread synchronously, need feedback before continuing - shell.getDisplay().syncExec(new Runnable() { + this.shell.getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); } @@ -203,11 +209,13 @@ public class EntitiesGenerator this.className = className; } + @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(JptUiMessages.OverwriteConfirmerDialog_title); } + @Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); GridLayout gridLayout = (GridLayout) composite.getLayout(); @@ -220,6 +228,7 @@ public class EntitiesGenerator return composite; } + @Override protected void createButtonsForButtonBar(Composite parent) { this.createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, false); this.createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.YES_TO_ALL_LABEL, false); @@ -228,6 +237,7 @@ public class EntitiesGenerator this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); } + @Override protected void buttonPressed(int buttonId) { switch (buttonId) { case IDialogConstants.YES_ID : diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/generic/GenericPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java index 1490e5fc21..22c391c871 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/generic/GenericPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java @@ -3,20 +3,20 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ -package org.eclipse.jpt.ui.internal.generic; +package org.eclipse.jpt.ui.internal.platform.generic; import java.text.MessageFormat; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.ui.internal.BaseJpaPlatformUi; import org.eclipse.jpt.ui.internal.GenericJpaUiFactory; import org.eclipse.jpt.ui.internal.IJpaUiFactory; import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -25,20 +25,19 @@ public class GenericPlatformUi extends BaseJpaPlatformUi public GenericPlatformUi() { super(); } - + @Override protected IJpaUiFactory createJpaUiFactory() { return new GenericJpaUiFactory(); } - + public void generateDDL(IJpaProject project, IStructuredSelection selection) { this.displayNotSupportedMessage(JptUiMessages.GenericPlatformUiDialog_notSupportedMessageTitle, JptUiMessages.GenericPlatformUiDialog_notSupportedMessageText); } protected void displayNotSupportedMessage(String title, String message) { - String formattedMessage = MessageFormat.format( message, (Object [])(new String [] { message})); + String formattedMessage = MessageFormat.format(message, message); Shell currentShell = Display.getCurrent().getActiveShell(); - MessageDialog.openInformation(currentShell, title, formattedMessage); + MessageDialog.openInformation(currentShell, title, formattedMessage); } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java index e59e78b77d..d82512e6b8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * 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. @@ -11,7 +11,6 @@ package org.eclipse.jpt.ui.internal.properties; import java.lang.reflect.InvocationTargetException; import java.util.Iterator; - import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; @@ -28,10 +27,10 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jpt.core.internal.IJpaProject; import org.eclipse.jpt.core.internal.JpaModelManager; -import org.eclipse.jpt.core.internal.JpaPlatformRegistry; import org.eclipse.jpt.core.internal.JptCorePlugin; import org.eclipse.jpt.core.internal.facet.IJpaFacetDataModelProperties; import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider; +import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; import org.eclipse.jpt.db.internal.ConnectionProfileRepository; import org.eclipse.jpt.db.ui.internal.DTPUiTools; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; @@ -168,7 +167,7 @@ public class JpaProjectPropertiesPage } String connection = this.model.getStringProperty(IJpaFacetDataModelProperties.CONNECTION); - if ( ! connection.equals(jpaProject.dataSource().getConnectionProfileName())) { + if ( ! connection.equals(jpaProject.dataSource().connectionProfileName())) { change = true; jpaProject.dataSource().setConnectionProfileName(connection); JptCorePlugin.setConnectionProfileName(project, connection); @@ -339,7 +338,7 @@ public class JpaProjectPropertiesPage } void performDefaults() { - String connectionName = getJpaProject().dataSource().getConnectionProfileName(); + String connectionName = getJpaProject().dataSource().connectionProfileName(); model.setProperty(CONNECTION, connectionName); if (connectionName == null) { connectionCombo.clearSelection(); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelection.java new file mode 100644 index 0000000000..3c0770a964 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelection.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.selection; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; + +@SuppressWarnings("nls") +public interface IJpaSelection extends ISelection +{ + static IJpaSelection NULL_SELECTION = + new IJpaSelection() { + public IJpaContextNode getSelectedNode() { + return null; + } + + public boolean isEmpty() { + return true; + } + + @Override + public String toString() { + return "NULL SELECTION"; + } + }; + + + IJpaContextNode getSelectedNode(); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/ISelectionManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelectionManager.java index 42e7dc2aef..294040971f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/ISelectionManager.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelectionManager.java @@ -11,27 +11,27 @@ package org.eclipse.jpt.ui.internal.selection; import org.eclipse.ui.IWorkbenchPart; -public interface ISelectionManager +public interface IJpaSelectionManager { /** * Return the current selection. - * This will never be null, but it may be <code>Selection.NULL_SELECTION</code>. + * This will never be null, but it may be <code>JpaSelection.NULL_SELECTION</code>. */ - public Selection getCurrentSelection(); + public IJpaSelection getCurrentSelection(); /** * Not to be called lightly, this will affect the selection for all interested * objects in a window. * The newSelection will be selected. */ - public void select(Selection newSelection); + public void select(IJpaSelection newSelection); /** * Not to be called lightly, this will affect the selection for all interested * objects in a window. * The oldSelection will be deselected, iff it matches the current selection. */ - public void deselect(Selection oldSelection); + public void deselect(IJpaSelection oldSelection); /** * This may be used to register a part with the selection manager if the part diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/ISelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelectionParticipant.java index 56fdb85040..249207026c 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/ISelectionParticipant.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/IJpaSelectionParticipant.java @@ -9,18 +9,18 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.selection; -public interface ISelectionParticipant +public interface IJpaSelectionParticipant { /** * Return the current selection of the participant */ - Selection getSelection(); + IJpaSelection getSelection(); /** * The selection has changed in the central selection manager. * Update this participant accordingly. */ - void selectionChanged(SelectionEvent evt); + void selectionChanged(JpaSelectionEvent evt); /** * Return whether this selection participant should disconnect itself from diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaDetailsSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaDetailsSelectionParticipant.java index da44c1d141..53f8b955f3 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaDetailsSelectionParticipant.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaDetailsSelectionParticipant.java @@ -13,7 +13,7 @@ import org.eclipse.jpt.ui.internal.views.JpaDetailsView; public class JpaDetailsSelectionParticipant - implements ISelectionParticipant + implements IJpaSelectionParticipant { private final JpaDetailsView detailsView; @@ -23,11 +23,11 @@ public class JpaDetailsSelectionParticipant this.detailsView = detailsView; } - public Selection getSelection() { + public IJpaSelection getSelection() { return this.detailsView.getSelection(); } - public void selectionChanged(SelectionEvent evt) { + public void selectionChanged(JpaSelectionEvent evt) { this.detailsView.select(evt.getSelection()); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/Selection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelection.java index e05032bdf0..a4e12ea25c 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/Selection.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelection.java @@ -3,69 +3,54 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.selection; -import org.eclipse.jpt.core.internal.IJpaContentNode; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; - -public class Selection +@SuppressWarnings("nls") +public class JpaSelection + implements IJpaSelection { - public static Selection NULL_SELECTION = new Selection(); - - private IJpaContentNode selectedNode; - - - /* Used internally - only for NULL_SELECTION */ - private Selection() { - super(); - } - - public Selection(IJpaContentNode selectedNode) { + private IJpaContextNode selectedNode; + + + public JpaSelection(IJpaContextNode selectedNode) { if (selectedNode == null) { throw new NullPointerException("A 'selectedNode' is required; otherwise use NULL_SELECTION."); } this.selectedNode = selectedNode; } - - public IJpaContentNode getSelectedNode() { + + public IJpaContextNode getSelectedNode() { return 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 Selection)) { - return false; - } - - if ((this == NULL_SELECTION) && (obj == NULL_SELECTION)) { - return true; - } - - if ((this == NULL_SELECTION) || (obj == NULL_SELECTION)) { + if (! (obj instanceof JpaSelection)) { return false; } - - return this.selectedNode.equals(((Selection) obj).selectedNode); + + return this.selectedNode.equals(((JpaSelection) obj).selectedNode); } - + @Override public int hashCode() { - return (this == NULL_SELECTION) ? - super.hashCode() - : - this.selectedNode.hashCode(); + return this.selectedNode.hashCode(); } @Override public String toString() { - return (this == NULL_SELECTION) ? - "NULL_SELECTION" - : - selectedNode.toString(); + return selectedNode.toString(); } - } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionEvent.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionEvent.java index 1020ef3ec1..44fbabad84 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionEvent.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionEvent.java @@ -11,7 +11,7 @@ package org.eclipse.jpt.ui.internal.selection; import java.util.EventObject; -public class SelectionEvent extends EventObject +public class JpaSelectionEvent extends EventObject { /** * Serializable uid @@ -34,7 +34,7 @@ public class SelectionEvent extends EventObject /** * The selection object whose selection status has changed */ - private Selection selection; + private IJpaSelection selection; /** * The type of the selection event, either a SELECTION or a DESELECTION @@ -42,7 +42,7 @@ public class SelectionEvent extends EventObject private int type; - public SelectionEvent(Selection theSelection, int theType, Object source) { + public JpaSelectionEvent(IJpaSelection theSelection, int theType, Object source) { super(source); selection = theSelection; type = theType; @@ -51,7 +51,7 @@ public class SelectionEvent extends EventObject /** * Return the selection object whose selection status has changed */ - public Selection getSelection() { + public IJpaSelection getSelection() { return selection; } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java index 108a700989..db47b79801 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManager.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java @@ -15,7 +15,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; - import org.eclipse.jpt.utility.internal.iterators.CloneIterator; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IPageListener; @@ -26,66 +25,82 @@ import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchWindow; /** - * A <code>SelectionManager</code> stores the current <code>Selection</code> and + * A <code>JpaSelectionManager</code> stores the current <code>JpaSelection</code> and * notifies <code>ISelectionListener</code>s when the selection changes. */ -public class SelectionManager - implements ISelectionManager +public class JpaSelectionManager + implements IJpaSelectionManager { + /* 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 map of <code>ISelectionParticipant</code>s (keyed by part) this object - is using to manage selections */ - private Map<IWorkbenchPart, ISelectionParticipant> selectionParticipants; + /* The active editor part */ + private IEditorPart activeEditor; - private IPageListener pageListener; + private IJpaSelection currentSelection; - private IPartListener2 partListener; + /* The map of <code>IJpaSelectionParticipant</code>s (keyed by part) */ + private Map<IWorkbenchPart, IJpaSelectionParticipant> selectionParticipants; - /* The window for which this object manages selections */ - private IWorkbenchWindow window; + private IPageListener pageListener; - private Selection currentSelection; + private IPartListener2 partListener; - public SelectionManager() { + public JpaSelectionManager() { super(); pages = Collections.synchronizedSet(new HashSet<IWorkbenchPage>()); - selectionParticipants = Collections.synchronizedMap(new HashMap<IWorkbenchPart, ISelectionParticipant>()); + selectionParticipants = Collections.synchronizedMap(new HashMap<IWorkbenchPart, IJpaSelectionParticipant>()); pageListener = new PageListener(); partListener = new PartListener(); - currentSelection = Selection.NULL_SELECTION; + currentSelection = JpaSelection.NULL_SELECTION; } - public void init(IWorkbenchWindow aWindow) { + void init(IWorkbenchWindow aWindow) { window = aWindow; aWindow.addPageListener(pageListener); initPage(aWindow.getActivePage()); } - void initPage(IWorkbenchPage page) { + private void initPage(IWorkbenchPage page) { if ((page != null) && (! pages.contains(page))) { page.addPartListener(partListener); pages.add(page); - IEditorPart activeEditor = page.getActiveEditor(); - initPart(activeEditor); - selectPart(activeEditor); + activateEditor(page.getActiveEditor()); } } - void disposePage(IWorkbenchPage page) { + 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) { - ISelectionParticipant selectionParticipant = - (ISelectionParticipant) part.getAdapter(ISelectionParticipant.class); + IJpaSelectionParticipant selectionParticipant = + (IJpaSelectionParticipant) part.getAdapter(IJpaSelectionParticipant.class); if (selectionParticipant != null) { selectionParticipants.put(part, selectionParticipant); } @@ -93,22 +108,26 @@ public class SelectionManager } } + private void selectEditor(IEditorPart editor) { + + } + void selectPart(IWorkbenchPart part) { - ISelectionParticipant selectionParticipant = getSelectionParticipant(part); + IJpaSelectionParticipant selectionParticipant = getSelectionParticipant(part); if (selectionParticipant != null) { select(selectionParticipant.getSelection()); } } void hidePart(IWorkbenchPart part) { - ISelectionParticipant selectionParticipant = getSelectionParticipant(part); + IJpaSelectionParticipant selectionParticipant = getSelectionParticipant(part); if ((selectionParticipant != null) && (selectionParticipant.disposeOnHide())) { closePart(part); } } void closePart(IWorkbenchPart part) { - ISelectionParticipant selectionParticipant = getSelectionParticipant(part); + IJpaSelectionParticipant selectionParticipant = getSelectionParticipant(part); if (selectionParticipant != null) { disposePart(part); checkForNoEditors(); @@ -125,7 +144,7 @@ public class SelectionManager IWorkbenchPage activePage = window.getActivePage(); if ((activePage == null) || (activePage.getActiveEditor() == null)) { - select(Selection.NULL_SELECTION); + select(JpaSelection.NULL_SELECTION); } } @@ -147,14 +166,14 @@ public class SelectionManager * objects in a window. * The newSelection will be selected. */ - public void select(Selection newSelection) { + public void select(IJpaSelection newSelection) { if (currentSelection.equals(newSelection)) { return; } currentSelection = newSelection; fireSelectionChange( - new SelectionEvent(newSelection, SelectionEvent.SELECTION, this) + new JpaSelectionEvent(newSelection, JpaSelectionEvent.SELECTION, this) ); } @@ -163,26 +182,26 @@ public class SelectionManager * objects in a window. * The oldSelection will be deselected, iff it matches the current selection. */ - public void deselect(Selection oldSelection) { + public void deselect(IJpaSelection oldSelection) { if (currentSelection.equals(oldSelection)) { - currentSelection = Selection.NULL_SELECTION; + currentSelection = JpaSelection.NULL_SELECTION; fireSelectionChange( - new SelectionEvent(oldSelection, SelectionEvent.DESELECTION, this) + new JpaSelectionEvent(oldSelection, JpaSelectionEvent.DESELECTION, this) ); } } - private void fireSelectionChange(SelectionEvent event) { - for (ISelectionParticipant sp : selectionParticipants.values()) { + private void fireSelectionChange(JpaSelectionEvent event) { + for (IJpaSelectionParticipant sp : selectionParticipants.values()) { sp.selectionChanged(event); } } - private ISelectionParticipant getSelectionParticipant(IWorkbenchPart part) { + private IJpaSelectionParticipant getSelectionParticipant(IWorkbenchPart part) { return selectionParticipants.get(part); } - public Selection getCurrentSelection() { + public IJpaSelection getCurrentSelection() { return currentSelection; } @@ -211,11 +230,11 @@ public class SelectionManager } public void pageClosed(IWorkbenchPage page) { - SelectionManager.this.disposePage(page); + JpaSelectionManager.this.disposePage(page); } public void pageOpened(IWorkbenchPage page) { - SelectionManager.this.initPage(page); + JpaSelectionManager.this.initPage(page); } } @@ -229,8 +248,8 @@ public class SelectionManager public void partActivated(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); if (part != null) { - SelectionManager.this.initPart(part); - SelectionManager.this.selectPart(part); + JpaSelectionManager.this.initPart(part); + JpaSelectionManager.this.selectPart(part); } } @@ -241,9 +260,9 @@ public class SelectionManager public void partClosed(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); if (part != null) { - SelectionManager.this.closePart(part); - SelectionManager.this.disposePart(part); - SelectionManager.this.checkForNoEditors(); + JpaSelectionManager.this.closePart(part); + JpaSelectionManager.this.disposePart(part); + JpaSelectionManager.this.checkForNoEditors(); } } @@ -254,7 +273,7 @@ public class SelectionManager public void partHidden(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); if (part != null) { - SelectionManager.this.hidePart(part); + JpaSelectionManager.this.hidePart(part); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaStructureSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaStructureSelectionParticipant.java index 749efdcf55..067e6d1713 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaStructureSelectionParticipant.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaStructureSelectionParticipant.java @@ -11,25 +11,25 @@ package org.eclipse.jpt.ui.internal.selection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jpt.ui.internal.views.JpaStructureView; +import org.eclipse.jpt.ui.internal.views.structure.JpaStructureView; public class JpaStructureSelectionParticipant - implements ISelectionParticipant + implements IJpaSelectionParticipant { final JpaStructureView structureView; - public JpaStructureSelectionParticipant(ISelectionManager selectionManager, JpaStructureView structureView) { + public JpaStructureSelectionParticipant(IJpaSelectionManager selectionManager, JpaStructureView structureView) { super(); this.structureView = structureView; structureView.addSelectionChangedListener(new StructureViewSelectionListener(selectionManager, structureView)); } - public Selection getSelection() { + public IJpaSelection getSelection() { return this.structureView.getSelection(); } - public void selectionChanged(SelectionEvent evt) { + public void selectionChanged(JpaSelectionEvent evt) { this.structureView.select(evt.getSelection()); } @@ -47,9 +47,9 @@ public class JpaStructureSelectionParticipant private class StructureViewSelectionListener implements ISelectionChangedListener { - private final ISelectionManager selectionManager; + private final IJpaSelectionManager selectionManager; - StructureViewSelectionListener(ISelectionManager selectionManager, JpaStructureView structureView) { + StructureViewSelectionListener(IJpaSelectionManager selectionManager, JpaStructureView structureView) { super(); this.selectionManager = selectionManager; } @@ -58,10 +58,8 @@ public class JpaStructureSelectionParticipant this.selectionManager.select(this.structureViewSelection()); } - private Selection structureViewSelection() { + private IJpaSelection structureViewSelection() { return JpaStructureSelectionParticipant.this.structureView.getSelection(); } - } - } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManagerFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManagerFactory.java index 7e96a1807f..8f3811b097 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManagerFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManagerFactory.java @@ -3,9 +3,9 @@ * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: Oracle. - initial API and implementation - * + * *******************************************************************************/ package org.eclipse.jpt.ui.internal.selection; @@ -16,23 +16,23 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; -public class SelectionManagerFactory +public class SelectionManagerFactory { private static SelectionManagerFactory INSTANCE; - + private static Object MUTEX = new Object(); - - + + /** - * Each <code>IWorkbenchWindow</code> has its own <code>SelectionManager</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>SelectionManager</code>. - * - * @return The <code>SelectionManager</code> associated with the current + * 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 ISelectionManager getSelectionManager(IWorkbenchWindow window) { + public static IJpaSelectionManager getSelectionManager(IWorkbenchWindow window) { if (INSTANCE == null) { // this is thread safe for now. you never know whats comming synchronized (MUTEX) { @@ -46,54 +46,54 @@ public class SelectionManagerFactory } return INSTANCE.internalGetSelectionManager(window); } - - - private Map managers; - + + + private Map<IWorkbenchWindow, JpaSelectionManager> managers; + private WindowListener windowListener; - - + + private SelectionManagerFactory() { - managers = new HashMap(); + managers = new HashMap<IWorkbenchWindow, JpaSelectionManager>(); windowListener = new WindowListener(); } - + private void init() { IWorkbench workbench = PlatformUI.getWorkbench(); workbench.addWindowListener(windowListener); } - + /** - * Returns the SelectionManager for the IWorkbenchWindow. + * Returns the JpaSelectionManager for the IWorkbenchWindow. * Creates a new one if none exists yet. */ - private SelectionManager internalGetSelectionManager(IWorkbenchWindow window) { + private JpaSelectionManager internalGetSelectionManager(IWorkbenchWindow window) { if (window == null) { - throw new IllegalArgumentException(window.toString()); + throw new IllegalArgumentException("The IWorkbenchWindow cannot be null"); } - + if (! managers.containsKey(window)) { - SelectionManager manager = new SelectionManager(); + JpaSelectionManager manager = new JpaSelectionManager(); this.managers.put(window, manager); manager.init(window); } - - return (SelectionManager) managers.get(window); + + return managers.get(window); } - - + + private class WindowListener implements IWindowListener { public void windowOpened(IWorkbenchWindow aWindow) {} - + public void windowClosed(IWorkbenchWindow aWindow) { - SelectionManager manager = internalGetSelectionManager(aWindow); + JpaSelectionManager manager = internalGetSelectionManager(aWindow); manager.dispose(); managers.remove(aWindow); } - + public void windowActivated(IWorkbenchWindow aWindow) {} - + public void windowDeactivated(IWorkbenchWindow aWindow) {} } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionParticipantFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionParticipantFactory.java index 0bd4ca3bee..906cc7e26b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionParticipantFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionParticipantFactory.java @@ -11,31 +11,33 @@ package org.eclipse.jpt.ui.internal.selection; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.jpt.ui.internal.views.JpaDetailsView; -import org.eclipse.jpt.ui.internal.views.JpaStructureView; +import org.eclipse.jpt.ui.internal.views.structure.JpaStructureView; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.texteditor.ITextEditor; public class SelectionParticipantFactory implements IAdapterFactory { - private static final Class[] ADAPTER_LIST = new Class[] { ISelectionParticipant.class }; - + @SuppressWarnings("unchecked") + private static final Class[] ADAPTER_LIST = new Class[] { IJpaSelectionParticipant.class }; + + @SuppressWarnings("unchecked") public Class[] getAdapterList() { return ADAPTER_LIST; } + @SuppressWarnings("unchecked") public Object getAdapter(Object adaptableObject, Class adapterType) { if (! (adaptableObject instanceof IWorkbenchPart)) { return null; } - ISelectionManager selectionManager = + IJpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(((IWorkbenchPart) adaptableObject).getSite().getWorkbenchWindow()); - // TODO turn this into extension point if (adaptableObject instanceof ITextEditor) { return new TextEditorSelectionParticipant(selectionManager, (ITextEditor) adaptableObject); } - else if (adaptableObject instanceof JpaStructureView) { + if (adaptableObject instanceof JpaStructureView) { return new JpaStructureSelectionParticipant(selectionManager, (JpaStructureView) adaptableObject); } else if (adaptableObject instanceof JpaDetailsView) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java index 3750cb371c..8cef83aa58 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.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 ******************************************************************************/ @@ -14,10 +14,10 @@ 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.core.internal.IJpaContentNode; import org.eclipse.jpt.core.internal.IJpaFile; import org.eclipse.jpt.core.internal.ITextRange; import org.eclipse.jpt.core.internal.JptCorePlugin; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; import org.eclipse.jpt.ui.internal.views.AbstractJpaView; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -25,23 +25,23 @@ import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.texteditor.ITextEditor; -public class TextEditorSelectionParticipant - implements ISelectionParticipant +public class TextEditorSelectionParticipant + implements IJpaSelectionParticipant { - private final ISelectionManager selectionManager; + private final IJpaSelectionManager selectionManager; final ITextEditor textEditor; - + private final IPropertyListener editorInputListener; - + private final ISelectionChangedListener editorSelectionListener; - - private Selection currentSelection; - + + private IJpaSelection currentSelection; + private boolean forwardSelection = true; // TODO this just smells wrong ~bjv - - - public TextEditorSelectionParticipant(ISelectionManager selectionManager, ITextEditor textEditor) { + + + public TextEditorSelectionParticipant(IJpaSelectionManager selectionManager, ITextEditor textEditor) { super(); this.selectionManager = selectionManager; this.textEditor = textEditor; @@ -52,20 +52,20 @@ public class TextEditorSelectionParticipant this.currentSelection = this.calculateSelection(); } - // ********** ISelectionParticipant implementation ********** + // ********** IJpaSelectionParticipant implementation ********** - public Selection getSelection() { + public IJpaSelection getSelection() { return this.currentSelection; } - - public void selectionChanged(SelectionEvent evt) { - Selection newSelection = evt.getSelection(); - - if ((newSelection == Selection.NULL_SELECTION) + + public void selectionChanged(JpaSelectionEvent evt) { + IJpaSelection newSelection = evt.getSelection(); + + if ((newSelection == IJpaSelection.NULL_SELECTION) || newSelection.equals(this.currentSelection)) { return; } - + this.forwardSelection = false; ITextRange textRange = newSelection.getSelectedNode().selectionTextRange(); if (textRange != null) { @@ -73,11 +73,11 @@ public class TextEditorSelectionParticipant } this.forwardSelection = true; } - + public boolean disposeOnHide() { return true; } - + public void dispose() { this.textEditor.removePropertyListener(this.editorInputListener); this.postSelectionProvider().removePostSelectionChangedListener(this.editorSelectionListener); @@ -86,25 +86,25 @@ public class TextEditorSelectionParticipant // ********** internal methods ********** - private Selection calculateSelection() { + private IJpaSelection calculateSelection() { ISelection selection = this.textEditor.getSelectionProvider().getSelection(); if (! (selection instanceof ITextSelection)) { - return Selection.NULL_SELECTION; + return IJpaSelection.NULL_SELECTION; } IJpaFile jpaFile = this.jpaFile(); if (jpaFile == null) { - return Selection.NULL_SELECTION; + return IJpaSelection.NULL_SELECTION; } - IJpaContentNode selectedNode = jpaFile.getContentNode(((ITextSelection) selection).getOffset()); + IJpaContextNode selectedNode = jpaFile.contextNode(((ITextSelection) selection).getOffset()); if (selectedNode == null) { - return Selection.NULL_SELECTION; + return IJpaSelection.NULL_SELECTION; } - return new Selection(selectedNode); + return new JpaSelection(selectedNode); } - + private IJpaFile jpaFile() { IEditorInput input = this.textEditor.getEditorInput(); if ( ! (input instanceof IFileEditorInput)) { @@ -112,7 +112,7 @@ public class TextEditorSelectionParticipant } return JptCorePlugin.jpaFile(((IFileEditorInput) input).getFile()); } - + private IPostSelectionProvider postSelectionProvider() { return (IPostSelectionProvider) this.textEditor.getSelectionProvider(); } @@ -121,7 +121,7 @@ public class TextEditorSelectionParticipant // ********** listener callbacks ********** void editorInputChanged() { - Selection newSelection = this.calculateSelection(); + IJpaSelection newSelection = this.calculateSelection(); if (newSelection.equals(this.currentSelection)) { return; } @@ -130,15 +130,15 @@ public class TextEditorSelectionParticipant this.selectionManager.select(newSelection); } } - + void editorSelectionChanged(SelectionChangedEvent event) { - Selection newSelection = this.calculateSelection(); + IJpaSelection newSelection = this.calculateSelection(); if (newSelection.equals(this.currentSelection)) { return; } this.currentSelection = newSelection; - // bug 188344 - won't actively change selection manager selection if + // bug 188344 - won't actively change selection manager selection if // a "JPA" view is the active (and presumably selecting) view if (this.textEditor.getEditorSite().getPage().getActivePart() instanceof AbstractJpaView) { return; @@ -148,7 +148,7 @@ public class TextEditorSelectionParticipant this.selectionManager.select(newSelection); } } - + // ********** listeners ********** @@ -163,8 +163,8 @@ public class TextEditorSelectionParticipant } } } - - + + private class EditorSelectionListener implements ISelectionChangedListener { EditorSelectionListener() { super(); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemContentProviderFactory.java new file mode 100644 index 0000000000..fc2127443c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemContentProviderFactory.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.ui.internal.structure; + +import java.util.ListIterator; +import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute; +import org.eclipse.jpt.core.internal.context.base.IPersistentType; +import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProvider; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; + +public abstract class GeneralJpaMappingItemContentProviderFactory + implements ITreeItemContentProviderFactory +{ + public ITreeItemContentProvider buildItemContentProvider( + Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { + DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider; + if (item instanceof IPersistentType) { + return new PersistentTypeItemContentProvider((IPersistentType) item, treeContentProvider); + } + else if (item instanceof IPersistentAttribute) { + return new PersistentAttributeItemContentProvider((IPersistentAttribute) item, treeContentProvider); + } + return null; + } + + + public static class PersistentTypeItemContentProvider extends AbstractTreeItemContentProvider<IPersistentAttribute> + { + public PersistentTypeItemContentProvider( + IPersistentType persistentType, DelegatingTreeContentAndLabelProvider contentProvider) { + super(persistentType, contentProvider); + } + + @Override + public Object getParent() { + return ((IPersistentType) model()).parent(); + } + + @Override + protected ListValueModel<IPersistentAttribute> buildChildrenModel() { + return new ListAspectAdapter<IPersistentType, IPersistentAttribute>(new String[]{IPersistentType.SPECIFIED_ATTRIBUTES_LIST, IPersistentType.VIRTUAL_ATTRIBUTES_LIST}, (IPersistentType) model()) { + @Override + protected ListIterator<IPersistentAttribute> listIterator_() { + return subject.attributes(); + } + }; + } + } + + + @SuppressWarnings("unchecked") + public static class PersistentAttributeItemContentProvider extends AbstractTreeItemContentProvider + { + public PersistentAttributeItemContentProvider( + IPersistentAttribute persistentAttribute, DelegatingTreeContentAndLabelProvider contentProvider) { + super(persistentAttribute, contentProvider); + } + + @Override + public Object getParent() { + return ((IPersistentAttribute) model()).parent(); + } + + @Override + public boolean hasChildren() { + return false; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java new file mode 100644 index 0000000000..a301febab4 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * 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.ui.internal.structure; + +import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute; +import org.eclipse.jpt.core.internal.context.base.IPersistentType; +import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; +import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProvider; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.graphics.Image; + +public abstract class GeneralJpaMappingItemLabelProviderFactory + implements IItemLabelProviderFactory +{ + public IItemLabelProvider buildItemLabelProvider( + Object item, DelegatingContentAndLabelProvider labelProvider) { + if (item instanceof IPersistentType) { + return new PersistentTypeItemLabelProvider((IPersistentType) item, labelProvider); + } + else if (item instanceof IPersistentAttribute) { + return new PersistentAttributeItemLabelProvider((IPersistentAttribute) item, labelProvider); + } + return null; + } + + + public static class PersistentTypeItemLabelProvider extends AbstractItemLabelProvider + { + public PersistentTypeItemLabelProvider( + IPersistentType persistentType, DelegatingContentAndLabelProvider labelProvider) { + super(persistentType, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new PropertyAspectAdapter<IPersistentType, String>(IPersistentType.NAME_PROPERTY, (IPersistentType) model()) { + @Override + protected String buildValue_() { + return subject.getName(); + } + }; + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new PropertyAspectAdapter<IPersistentType, Image>(IPersistentType.MAPPING_PROPERTY, (IPersistentType) model()) { + @Override + protected Image buildValue_() { + return JpaMappingImageHelper.imageForTypeMapping(subject.mappingKey()); + } + }; + } + } + + + public static class PersistentAttributeItemLabelProvider extends AbstractItemLabelProvider + { + public PersistentAttributeItemLabelProvider( + IPersistentAttribute persistentAttribute, DelegatingContentAndLabelProvider labelProvider) { + super(persistentAttribute, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new PropertyAspectAdapter<IPersistentAttribute, String>(IPersistentAttribute.NAME_PROPERTY, (IPersistentAttribute) model()) { + @Override + protected String buildValue_() { + return subject.getName(); + } + }; + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new PropertyAspectAdapter<IPersistentAttribute, Image>( + new String[] {IPersistentAttribute.DEFAULT_MAPPING_PROPERTY, IPersistentAttribute.SPECIFIED_MAPPING_PROPERTY}, + (IPersistentAttribute) model()) { + @Override + protected Image buildValue_() { + return JpaMappingImageHelper.imageForAttributeMapping(subject.mappingKey()); + } + }; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/IJpaStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/IJpaStructureProvider.java index 90899cac54..cea72b7589 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/IJpaStructureProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/IJpaStructureProvider.java @@ -3,29 +3,28 @@ * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: Oracle. - initial API and implementation *******************************************************************************/ package org.eclipse.jpt.ui.internal.structure; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; -public interface IJpaStructureProvider +public interface IJpaStructureProvider { + // TODO - change this + Object getInput(); - String fileContentType(); - /** - * Build an outline content provider. + * Build an factory to create {@link ITreeItemContentProvider}s */ - ITreeContentProvider buildContentProvider(); - + ITreeItemContentProviderFactory treeItemContentProviderFactory(); + /** - * Build an outline label provider. + * Build a factory to create {@link IItemLabelProvider}s */ - ILabelProvider buildLabelProvider(); - + IItemLabelProviderFactory itemLabelProviderFactory(); + void dispose(); - } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemContentProviderFactory.java new file mode 100644 index 0000000000..4329b4149c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemContentProviderFactory.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import java.util.ListIterator; +import org.eclipse.jpt.core.internal.IResourceModel; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.core.internal.resource.java.JavaResourceModel; +import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProvider; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; + + +public class JavaItemContentProviderFactory extends GeneralJpaMappingItemContentProviderFactory +{ + public ITreeItemContentProvider buildItemContentProvider( + Object item, DelegatingContentAndLabelProvider contentProvider) { + DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentProvider; + if (item instanceof JavaResourceModel) { + return new JavaResourceModelItemContentProvider((JavaResourceModel) item, treeContentProvider); + } + return super.buildItemContentProvider(item, treeContentProvider); + } + + + public static class JavaResourceModelItemContentProvider extends AbstractTreeItemContentProvider<IJpaContextNode> + { + public JavaResourceModelItemContentProvider( + JavaResourceModel javaResourceModel, DelegatingTreeContentAndLabelProvider contentProvider) { + super(javaResourceModel, contentProvider); + } + + @Override + public Object getParent() { + return null; + } + + @Override + protected ListValueModel<IJpaContextNode> buildChildrenModel() { + return new ListAspectAdapter<JavaResourceModel, IJpaContextNode>( + IResourceModel.ROOT_CONTEXT_NODE_LIST, (JavaResourceModel) model()) { + @Override + protected ListIterator<IJpaContextNode> listIterator_() { + return subject.rootContextNodes(); + } + }; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemLabelProviderFactory.java new file mode 100644 index 0000000000..82bc52ac7c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemLabelProviderFactory.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + + +public class JavaItemLabelProviderFactory extends GeneralJpaMappingItemLabelProviderFactory +{ + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java new file mode 100644 index 0000000000..22b7a499c2 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.jpt.core.internal.resource.java.JavaResourceModel; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; + +public class JavaResourceModelStructureProvider + extends ResourceModelStructureProvider +{ + public JavaResourceModelStructureProvider(JavaResourceModel resourceModel) { + super(resourceModel); + } + + public ITreeItemContentProviderFactory treeItemContentProviderFactory() { + return new JavaItemContentProviderFactory(); + } + + public IItemLabelProviderFactory itemLabelProviderFactory() { + return new JavaItemLabelProviderFactory(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JpaStructureProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JpaStructureProviderFactory.java new file mode 100644 index 0000000000..a1001d274b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JpaStructureProviderFactory.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.jpt.core.internal.IJpaFile; +import org.eclipse.jpt.core.internal.IJpaProject; +import org.eclipse.jpt.core.internal.IResourceModel; +import org.eclipse.jpt.core.internal.JptCorePlugin; +import org.eclipse.jpt.core.internal.resource.java.JavaResourceModel; +import org.eclipse.jpt.core.internal.resource.orm.OrmResourceModel; +import org.eclipse.jpt.core.internal.resource.persistence.PersistenceResourceModel; +import org.eclipse.jpt.ui.internal.views.structure.JpaStructurePage; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; + +public class JpaStructureProviderFactory + implements IAdapterFactory +{ + @SuppressWarnings("unchecked") + private static final Class[] ADAPTER_LIST = + new Class[] { JpaStructurePage.class }; + + @SuppressWarnings("unchecked") + public Class[] getAdapterList() { + return ADAPTER_LIST; + } + + @SuppressWarnings("unchecked") + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (! (adaptableObject instanceof IEditorPart)) { + return null; + } + + IEditorInput editorInput = ((IEditorPart) adaptableObject).getEditorInput(); + + if (! (editorInput instanceof IFileEditorInput)) { + return null; + } + + IFile file = ((IFileEditorInput) editorInput).getFile(); + IJpaProject jpaProject = JptCorePlugin.jpaProject(file.getProject()); + + if (jpaProject == null) { + return null; + } + + IJpaFile jpaFile = jpaProject.jpaFile(file); + + if (jpaFile == null) { + return null; + } + + IResourceModel resourceModel = jpaFile.getResourceModel(); + + if (resourceModel instanceof JavaResourceModel) { + return new JavaResourceModelStructureProvider((JavaResourceModel) resourceModel); + } + else if (resourceModel instanceof OrmResourceModel) { + return new OrmResourceModelStructureProvider((OrmResourceModel) resourceModel); + } + else if (resourceModel instanceof PersistenceResourceModel) { + return new PersistenceResourceModelStructureProvider((PersistenceResourceModel) resourceModel); + } + + return null; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemContentProviderFactory.java new file mode 100644 index 0000000000..961400b6e5 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemContentProviderFactory.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import java.util.ListIterator; +import org.eclipse.jpt.core.internal.IResourceModel; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType; +import org.eclipse.jpt.core.internal.resource.orm.OrmResourceModel; +import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProvider; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; + +public class OrmItemContentProviderFactory extends GeneralJpaMappingItemContentProviderFactory +{ + public ITreeItemContentProvider buildItemContentProvider( + Object item, DelegatingContentAndLabelProvider contentProvider) { + DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentProvider; + if (item instanceof OrmResourceModel) { + return new OrmResourceModelItemContentProvider((OrmResourceModel) item, treeContentProvider); + } + if (item instanceof EntityMappings) { + return new EntityMappingsItemContentProvider((EntityMappings) item, treeContentProvider); + } + else return super.buildItemContentProvider(item, treeContentProvider); + } + + + public static class OrmResourceModelItemContentProvider extends AbstractTreeItemContentProvider<IJpaContextNode> + { + public OrmResourceModelItemContentProvider( + OrmResourceModel ormResourceModel, DelegatingTreeContentAndLabelProvider contentProvider) { + super(ormResourceModel, contentProvider); + } + + @Override + public Object getParent() { + return null; + } + + @Override + protected ListValueModel<IJpaContextNode> buildChildrenModel() { + return new ListAspectAdapter<OrmResourceModel, IJpaContextNode>( + IResourceModel.ROOT_CONTEXT_NODE_LIST, (OrmResourceModel) model()) { + @Override + protected ListIterator<IJpaContextNode> listIterator_() { + return subject.rootContextNodes(); + } + }; + } + } + + + public static class EntityMappingsItemContentProvider extends AbstractTreeItemContentProvider<XmlPersistentType> + { + public EntityMappingsItemContentProvider( + EntityMappings entityMappings, DelegatingTreeContentAndLabelProvider contentProvider) { + super(entityMappings, contentProvider); + } + + + @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 ListValueModel<XmlPersistentType> buildChildrenModel() { + return new ListAspectAdapter<EntityMappings, XmlPersistentType>( + EntityMappings.PERSISTENT_TYPES_LIST, (EntityMappings) model()) { + @Override + protected ListIterator<XmlPersistentType> listIterator_() { + return subject.xmlPersistentTypes(); + } + }; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemLabelProviderFactory.java new file mode 100644 index 0000000000..6d743fe7af --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemLabelProviderFactory.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; +import org.eclipse.jpt.ui.internal.JptUiIcons; +import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProvider; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; +import org.eclipse.swt.graphics.Image; + +public class OrmItemLabelProviderFactory extends GeneralJpaMappingItemLabelProviderFactory +{ + public IItemLabelProvider buildItemLabelProvider( + Object item, DelegatingContentAndLabelProvider labelProvider) { + if (item instanceof EntityMappings) { + return new EntityMappingsItemLabelProvider((EntityMappings) item, labelProvider); + } + else return super.buildItemLabelProvider(item, labelProvider); + } + + + public static class EntityMappingsItemLabelProvider extends AbstractItemLabelProvider + { + public EntityMappingsItemLabelProvider( + EntityMappings entityMappings, DelegatingContentAndLabelProvider labelProvider) { + super(entityMappings, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new StaticPropertyValueModel<String>(JptUiMessages.OrmItemLabelProviderFactory_entityMappingsLabel); + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.ENTITY_MAPPINGS)); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java new file mode 100644 index 0000000000..95b1525ac1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.jpt.core.internal.resource.orm.OrmResourceModel; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; + +public class OrmResourceModelStructureProvider + extends ResourceModelStructureProvider +{ + public OrmResourceModelStructureProvider(OrmResourceModel resourceModel) { + super(resourceModel); + } + + public ITreeItemContentProviderFactory treeItemContentProviderFactory() { + return new OrmItemContentProviderFactory(); + } + + public IItemLabelProviderFactory itemLabelProviderFactory() { + return new OrmItemLabelProviderFactory(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemContentProviderFactory.java new file mode 100644 index 0000000000..6753568592 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemContentProviderFactory.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import java.util.ListIterator; +import org.eclipse.jpt.core.internal.IResourceModel; +import org.eclipse.jpt.core.internal.context.base.IClassRef; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.core.internal.context.base.IMappingFileRef; +import org.eclipse.jpt.core.internal.context.base.IPersistence; +import org.eclipse.jpt.core.internal.context.base.IPersistenceUnit; +import org.eclipse.jpt.core.internal.resource.persistence.PersistenceResourceModel; +import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProvider; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; +import org.eclipse.jpt.utility.internal.iterators.ReadOnlyCompositeListIterator; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; + +public class PersistenceItemContentProviderFactory + implements ITreeItemContentProviderFactory +{ + public ITreeItemContentProvider buildItemContentProvider( + Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { + DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider; + if (item instanceof PersistenceResourceModel) { + return new PersistenceResourceModelItemContentProvider((PersistenceResourceModel) item, treeContentProvider); + } + else if (item instanceof IPersistence) { + return new PersistenceItemContentProvider((IPersistence) item, treeContentProvider); + } + else if (item instanceof IPersistenceUnit) { + return new PersistenceUnitItemContentProvider((IPersistenceUnit) item, treeContentProvider); + } + else if (item instanceof IMappingFileRef) { + return new MappingFileRefItemContentProvider((IMappingFileRef) item, treeContentProvider); + } + else if (item instanceof IClassRef) { + return new ClassRefItemContentProvider((IClassRef) item, treeContentProvider); + } + return null; + } + + + public static class PersistenceResourceModelItemContentProvider extends AbstractTreeItemContentProvider<IJpaContextNode> + { + public PersistenceResourceModelItemContentProvider( + PersistenceResourceModel persistenceResourceModel, + DelegatingTreeContentAndLabelProvider contentProvider) { + super(persistenceResourceModel, contentProvider); + } + + @Override + public Object getParent() { + return null; + } + + @Override + protected ListValueModel<IJpaContextNode> buildChildrenModel() { + return new ListAspectAdapter<PersistenceResourceModel, IJpaContextNode>( + IResourceModel.ROOT_CONTEXT_NODE_LIST, (PersistenceResourceModel) model()) { + @Override + protected ListIterator<IJpaContextNode> listIterator_() { + return subject.rootContextNodes(); + } + }; + } + } + + + public static class PersistenceItemContentProvider extends AbstractTreeItemContentProvider<IPersistenceUnit> + { + public PersistenceItemContentProvider( + IPersistence persistence, DelegatingTreeContentAndLabelProvider contentProvider) { + super(persistence, contentProvider); + } + + + @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 ListValueModel<IPersistenceUnit> buildChildrenModel() { + return new ListAspectAdapter<IPersistence, IPersistenceUnit>( + IPersistence.PERSISTENCE_UNITS_LIST, (IPersistence) model()) { + @Override + protected ListIterator<IPersistenceUnit> listIterator_() { + return subject.persistenceUnits(); + } + }; + } + } + + + public static class PersistenceUnitItemContentProvider extends AbstractTreeItemContentProvider<IJpaContextNode> + { + public PersistenceUnitItemContentProvider( + IPersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) { + super(persistenceUnit, contentProvider); + } + + @Override + public Object getParent() { + return ((IPersistenceUnit) model()).persistence(); + } + + @Override + protected ListValueModel<IJpaContextNode> buildChildrenModel() { + return new ListAspectAdapter<IPersistenceUnit, IJpaContextNode>( + new String[] {IPersistenceUnit.SPECIFIED_MAPPING_FILE_REF_LIST, IPersistenceUnit.CLASS_REF_LIST}, + (IPersistenceUnit) model()) { + @Override + @SuppressWarnings("unchecked") + protected ListIterator<IJpaContextNode> listIterator_() { + return new ReadOnlyCompositeListIterator<IJpaContextNode>( + subject.mappingFileRefs(), subject.classRefs()); + } + }; + } + } + + + @SuppressWarnings("unchecked") + public static class MappingFileRefItemContentProvider extends AbstractTreeItemContentProvider + { + public MappingFileRefItemContentProvider( + IMappingFileRef mappingFileRef, DelegatingTreeContentAndLabelProvider contentProvider) { + super(mappingFileRef, contentProvider); + } + + @Override + public Object getParent() { + return ((IMappingFileRef) model()).persistenceUnit(); + } + + @Override + public boolean hasChildren() { + return false; + } + } + + + @SuppressWarnings("unchecked") + public static class ClassRefItemContentProvider extends AbstractTreeItemContentProvider + { + public ClassRefItemContentProvider( + IClassRef classRef, DelegatingTreeContentAndLabelProvider contentProvider) { + super(classRef, contentProvider); + } + + @Override + public Object getParent() { + return ((IClassRef) model()).persistenceUnit(); + } + + @Override + public boolean hasChildren() { + return false; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemLabelProviderFactory.java new file mode 100644 index 0000000000..e54ac6ff9c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemLabelProviderFactory.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.jpt.core.internal.context.base.IClassRef; +import org.eclipse.jpt.core.internal.context.base.IMappingFileRef; +import org.eclipse.jpt.core.internal.context.base.IPersistence; +import org.eclipse.jpt.core.internal.context.base.IPersistenceUnit; +import org.eclipse.jpt.ui.internal.JptUiIcons; +import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; +import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProvider; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; +import org.eclipse.swt.graphics.Image; + +public class PersistenceItemLabelProviderFactory + implements IItemLabelProviderFactory +{ + public IItemLabelProvider buildItemLabelProvider( + Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { + if (item instanceof IPersistence) { + return new PersistenceItemLabelProvider((IPersistence) item, contentAndLabelProvider); + } + else if (item instanceof IPersistenceUnit) { + return new PersistenceUnitItemLabelProvider((IPersistenceUnit) item, contentAndLabelProvider); + } + else if (item instanceof IMappingFileRef) { + return new MappingFileRefItemLabelProvider((IMappingFileRef) item, contentAndLabelProvider); + } + else if (item instanceof IClassRef) { + return new ClassRefItemLabelProvider((IClassRef) item, contentAndLabelProvider); + } + return null; + } + + + public static class PersistenceItemLabelProvider extends AbstractItemLabelProvider + { + public PersistenceItemLabelProvider( + IPersistence persistence, DelegatingContentAndLabelProvider labelProvider) { + super(persistence, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new StaticPropertyValueModel<String>(JptUiMessages.PersistenceItemLabelProviderFactory_persistenceLabel); + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.PERSISTENCE)); + } + } + + + public static class PersistenceUnitItemLabelProvider extends AbstractItemLabelProvider + { + public PersistenceUnitItemLabelProvider( + IPersistenceUnit persistenceUnit, DelegatingContentAndLabelProvider labelProvider) { + super(persistenceUnit, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new PropertyAspectAdapter<IPersistenceUnit, String>(IPersistenceUnit.NAME_PROPERTY, (IPersistenceUnit) model()) { + @Override + protected String buildValue_() { + return subject.getName(); + } + }; + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.PERSISTENCE_UNIT)); + } + } + + + public static class MappingFileRefItemLabelProvider extends AbstractItemLabelProvider + { + public MappingFileRefItemLabelProvider( + IMappingFileRef mappingFileRef, DelegatingContentAndLabelProvider labelProvider) { + super(mappingFileRef, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new PropertyAspectAdapter<IMappingFileRef, String>(IMappingFileRef.FILE_NAME_PROPERTY, (IMappingFileRef) model()) { + @Override + protected String buildValue_() { + return subject.getFileName(); + } + }; + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.MAPPING_FILE_REF)); + } + } + + + public static class ClassRefItemLabelProvider extends AbstractItemLabelProvider + { + public ClassRefItemLabelProvider( + IClassRef classRef, DelegatingContentAndLabelProvider labelProvider) { + super(classRef, labelProvider); + } + + @Override + protected PropertyValueModel<String> buildTextModel() { + return new PropertyAspectAdapter<IClassRef, String>(IClassRef.CLASS_NAME_PROPERTY, (IClassRef) model()) { + @Override + protected String buildValue_() { + return subject.getClassName(); + } + }; + } + + @Override + protected PropertyValueModel<Image> buildImageModel() { + return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.CLASS_REF)); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java new file mode 100644 index 0000000000..cbcb257fd0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.jpt.core.internal.resource.persistence.PersistenceResourceModel; +import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; +import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; + +public class PersistenceResourceModelStructureProvider + extends ResourceModelStructureProvider +{ + public PersistenceResourceModelStructureProvider(PersistenceResourceModel resourceModel) { + super(resourceModel); + } + + public ITreeItemContentProviderFactory treeItemContentProviderFactory() { + return new PersistenceItemContentProviderFactory(); + } + + public IItemLabelProviderFactory itemLabelProviderFactory() { + return new PersistenceItemLabelProviderFactory(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java new file mode 100644 index 0000000000..e2b2df4229 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.structure; + +import org.eclipse.jpt.core.internal.IResourceModel; + +public abstract class ResourceModelStructureProvider + implements IJpaStructureProvider +{ + protected IResourceModel resourceModel; + + + public ResourceModelStructureProvider(IResourceModel resourceModel) { + this.resourceModel = resourceModel; + } + + public Object getInput() { + return resourceModel; + } + + public void dispose() { + // TODO Auto-generated method stub + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/BooleanButtonModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/BooleanButtonModelAdapter.java new file mode 100644 index 0000000000..05c501b56b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/BooleanButtonModelAdapter.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.ui.internal.swt; + +import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; + +/** + * This adapter can be used to keep a check box or toggle button in synch with + * a model boolean. + */ +public class BooleanButtonModelAdapter { + + /** A value model on the underlying model boolean. */ + protected final WritablePropertyValueModel<Boolean> booleanHolder; + + /** + * A listener that allows us to synchronize the button's selection state with + * the model boolean. + */ + protected final PropertyChangeListener booleanChangeListener; + + /** The check box/toggle button we synchronize with the model boolean. */ + protected final Button button; + + /** + * A listener that allows us to synchronize the model boolean with + * the button's selection state. + */ + protected final SelectionListener buttonSelectionListener; + + /** + * A listener that allows us to stop listening to stuff when the button + * is disposed. + */ + protected final DisposeListener buttonDisposeListener; + + /** + * The default setting for the check box/toggle button; for when the + * underlying model is null. + * The default [default value] is false (i.e. the button is checked/popped out). + */ + protected final boolean defaultValue; + + + // ********** static methods ********** + + /** + * Adapt the specified boolean to the specified button. + * If the boolean is null, the button's value will be "unselected". + */ + public static BooleanButtonModelAdapter adapt(WritablePropertyValueModel<Boolean> booleanHolder, Button button) { + return new BooleanButtonModelAdapter(booleanHolder, button); + } + + /** + * Adapt the specified boolean to the specified button. + * If the boolean is null, the button's value will be the specified default value. + */ + public static BooleanButtonModelAdapter adapt(WritablePropertyValueModel<Boolean> booleanHolder, Button button, boolean defaultValue) { + return new BooleanButtonModelAdapter(booleanHolder, button, defaultValue); + } + + + // ********** constructors ********** + + /** + * Constructor - the boolean holder and button are required. + * The default value will be false. + */ + protected BooleanButtonModelAdapter(WritablePropertyValueModel<Boolean> booleanHolder, Button button) { + this(booleanHolder, button, false); + } + + /** + * Constructor - the boolean holder and button are required. + */ + protected BooleanButtonModelAdapter(WritablePropertyValueModel<Boolean> booleanHolder, Button button, boolean defaultValue) { + super(); + if ((booleanHolder == null) || (button == null)) { + throw new NullPointerException(); + } + this.booleanHolder = booleanHolder; + this.button = button; + this.defaultValue = defaultValue; + + this.booleanChangeListener = this.buildBooleanChangeListener(); + this.booleanHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.booleanChangeListener); + + this.buttonDisposeListener = this.buildButtonDisposeListener(); + this.button.addDisposeListener(this.buttonDisposeListener); + + this.buttonSelectionListener = this.buildButtonSelectionListener(); + this.button.addSelectionListener(this.buttonSelectionListener); + + this.setButtonSelection(this.booleanHolder.value()); + } + + + // ********** initialization ********** + + protected PropertyChangeListener buildBooleanChangeListener() { + return new SWTPropertyChangeListenerWrapper(this.buildBooleanChangeListener_()); + } + + protected PropertyChangeListener buildBooleanChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + BooleanButtonModelAdapter.this.booleanChanged(event); + } + @Override + public String toString() { + return "boolean listener"; + } + }; + } + + protected SelectionListener buildButtonSelectionListener() { + return new SelectionListener() { + public void widgetSelected(SelectionEvent event) { + BooleanButtonModelAdapter.this.buttonSelected(event); + } + public void widgetDefaultSelected(SelectionEvent event) { + // ignore + } + @Override + public String toString() { + return "button selection listener"; + } + }; + } + + protected DisposeListener buildButtonDisposeListener() { + return new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + BooleanButtonModelAdapter.this.buttonDisposed(event); + } + @Override + public String toString() { + return "button dispose listener"; + } + }; + } + + + // ********** behavior ********** + + /** + * The model has changed - synchronize the button. + * If the new model value is null, use the adapter's default value + * (which is typically false). + */ + protected void booleanChanged(PropertyChangeEvent event) { + this.setButtonSelection((Boolean) event.newValue()); + } + + protected void setButtonSelection(Boolean b) { + this.button.setSelection(this.booleanValue(b)); + } + + protected boolean booleanValue(Boolean b) { + return (b != null) ? b.booleanValue() : this.defaultValue(); + } + + protected boolean defaultValue() { + return this.defaultValue; + } + + /** + * The button has been "selected" - synchronize the model. + */ + protected void buttonSelected(SelectionEvent event) { + this.booleanHolder.setValue(Boolean.valueOf(button.getSelection())); + } + + + // ********** dispose ********** + + protected void buttonDisposed(DisposeEvent event) { + this.button.removeSelectionListener(this.buttonSelectionListener); + this.button.removeDisposeListener(this.buttonDisposeListener); + this.booleanHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.booleanChangeListener); + } + + + // ********** standard methods ********** + + @Override + public String toString() { + return StringTools.buildToStringFor(this, this.booleanHolder); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ListBoxModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ListBoxModelAdapter.java new file mode 100644 index 0000000000..dfdd0cd29e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ListBoxModelAdapter.java @@ -0,0 +1,588 @@ +/******************************************************************************* + * 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.ui.internal.swt; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.EventObject; +import java.util.Iterator; +import java.util.ListIterator; + +import org.eclipse.jpt.ui.internal.listeners.SWTCollectionChangeListenerWrapper; +import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.StringConverter; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.event.CollectionChangeEvent; +import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.CollectionChangeListener; +import org.eclipse.jpt.utility.internal.model.listener.ListChangeListener; +import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyCollectionValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.List; + +/** + * This adapter provides a more object-oriented interface to the items and + * selected items in a list box. + * 'listHolder' contains the items in the list box. + * 'selectedItemsHolder' contains the items in 'listHolder' that are selected + * in the list box. + */ +public class ListBoxModelAdapter<E> { + + // ********** model ********** + /** + * A value model on the underlying model list. + */ + protected final ListValueModel<E> listHolder; + + /** + * A listener that allows us to synchronize the list box's contents with + * the model list. + */ + protected final ListChangeListener listChangeListener; + + /** + * A value model on the underlying model selections. + */ + protected final CollectionValueModel<E> selectedItemsHolder; + + /** + * A listener that allows us to synchronize the list box's selection with + * the model selections. + */ + protected final CollectionChangeListener selectedItemsChangeListener; + + /** + * A converter that converts items in the model list + * to strings that can be put in the list box. + */ + protected StringConverter<E> stringConverter; + + // ********** UI ********** + /** + * The list box we keep synchronized with the model list. + */ + protected final List listBox; + + /** + * A listener that allows us to synchronize our selection list holder + * with the list box's selection. + */ + protected final SelectionListener listBoxSelectionListener; + + /** + * Clients that are interested in selection change events. + */ + protected SelectionChangeListener<E>[] selectionChangeListeners; + + /** + * Clients that are interested in double click events. + */ + protected DoubleClickListener<E>[] doubleClickListeners; + + /** + * A listener that allows us to stop listening to stuff when the list box + * is disposed. + */ + protected final DisposeListener listBoxDisposeListener; + + + // ********** static methods ********** + + /** + * Adapt the specified model list and selections to the specified list box. + * Use the default string converter to convert the model items to strings + * to be displayed in the list box, which calls #toString() on the + * items in the model list. + */ + public static <T> ListBoxModelAdapter<T> adapt( + ListValueModel<T> listHolder, + CollectionValueModel<T> selectedItemsHolder, + List listBox) + { + return adapt(listHolder, selectedItemsHolder, listBox, StringConverter.Default.<T>instance()); + } + + /** + * Adapt the specified model list and selections to the specified list box. + * Use the specified string converter to convert the model items to strings + * to be displayed in the list box. + */ + public static <T> ListBoxModelAdapter<T> adapt( + ListValueModel<T> listHolder, + CollectionValueModel<T> selectedItemsHolder, + List listBox, + StringConverter<T> stringConverter) + { + return new ListBoxModelAdapter<T>(listHolder, selectedItemsHolder, listBox, stringConverter); + } + + /** + * Adapt the specified model list and selection to the specified list box. + * Use the default string converter to convert the model items to strings + * to be displayed in the list box, which calls #toString() on the + * items in the model list. + */ + public static <T> ListBoxModelAdapter<T> adapt( + ListValueModel<T> listHolder, + PropertyValueModel<T> selectedItemHolder, + List listBox) + { + return adapt(listHolder, selectedItemHolder, listBox, StringConverter.Default.<T>instance()); + } + + /** + * Adapt the specified model list and selection to the specified list box. + * Use the specified string converter to convert the model items to strings + * to be displayed in the list box. + */ + public static <T> ListBoxModelAdapter<T> adapt( + ListValueModel<T> listHolder, + PropertyValueModel<T> selectedItemHolder, + List listBox, + StringConverter<T> stringConverter) + { + return new ListBoxModelAdapter<T>(listHolder, new PropertyCollectionValueModelAdapter<T>(selectedItemHolder), listBox, stringConverter); + } + + + // ********** constructors ********** + + /** + * Constructor - the list holder, selections holder, list box, and + * string converter are required. + */ + protected ListBoxModelAdapter( + ListValueModel<E> listHolder, + CollectionValueModel<E> selectedItemsHolder, + List listBox, + StringConverter<E> stringConverter) + { + super(); + if ((listHolder == null) || (selectedItemsHolder == null) || (listBox == null) || (stringConverter == null)) { + throw new NullPointerException(); + } + this.listHolder = listHolder; + this.selectedItemsHolder = selectedItemsHolder; + this.listBox = listBox; + this.stringConverter = stringConverter; + + this.listChangeListener = this.buildListChangeListener(); + this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); + + this.selectedItemsChangeListener = this.buildSelectedItemsChangeListener(); + this.selectedItemsHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.selectedItemsChangeListener); + + this.listBoxSelectionListener = this.buildListBoxSelectionListener(); + this.listBox.addSelectionListener(this.listBoxSelectionListener); + + this.selectionChangeListeners = this.buildSelectionChangeListeners(); + this.doubleClickListeners = this.buildDoubleClickListeners(); + + this.listBoxDisposeListener = this.buildListBoxDisposeListener(); + this.listBox.addDisposeListener(this.listBoxDisposeListener); + + this.synchronizeListBox(); + } + + + // ********** initialization ********** + + protected ListChangeListener buildListChangeListener() { + return new SWTListChangeListenerWrapper(this.buildListChangeListener_()); + } + + protected ListChangeListener buildListChangeListener_() { + return new ListChangeListener() { + public void itemsAdded(ListChangeEvent event) { + ListBoxModelAdapter.this.listItemsAdded(event); + } + public void itemsRemoved(ListChangeEvent event) { + ListBoxModelAdapter.this.listItemsRemoved(event); + } + public void itemsMoved(ListChangeEvent event) { + ListBoxModelAdapter.this.listItemsMoved(event); + } + public void itemsReplaced(ListChangeEvent event) { + ListBoxModelAdapter.this.listItemsReplaced(event); + } + public void listCleared(ListChangeEvent event) { + ListBoxModelAdapter.this.listCleared(event); + } + public void listChanged(ListChangeEvent event) { + ListBoxModelAdapter.this.listChanged(event); + } + @Override + public String toString() { + return "list listener"; + } + }; + } + + protected CollectionChangeListener buildSelectedItemsChangeListener() { + return new SWTCollectionChangeListenerWrapper(this.buildSelectedItemsChangeListener_()); + } + + protected CollectionChangeListener buildSelectedItemsChangeListener_() { + return new CollectionChangeListener() { + public void itemsAdded(CollectionChangeEvent event) { + ListBoxModelAdapter.this.selectedItemsAdded(event); + } + public void itemsRemoved(CollectionChangeEvent event) { + ListBoxModelAdapter.this.selectedItemsRemoved(event); + } + public void collectionCleared(CollectionChangeEvent event) { + ListBoxModelAdapter.this.selectedItemsCleared(event); + } + public void collectionChanged(CollectionChangeEvent event) { + ListBoxModelAdapter.this.selectedItemsChanged(event); + } + @Override + public String toString() { + return "selected items listener"; + } + }; + } + + protected SelectionListener buildListBoxSelectionListener() { + return new SelectionListener() { + public void widgetSelected(SelectionEvent event) { + ListBoxModelAdapter.this.listBoxSelectionChanged(event); + } + public void widgetDefaultSelected(SelectionEvent event) { + ListBoxModelAdapter.this.listBoxDoubleClicked(event); + } + @Override + public String toString() { + return "list box selection listener"; + } + }; + } + + @SuppressWarnings("unchecked") + protected DoubleClickListener<E>[] buildDoubleClickListeners() { + return new DoubleClickListener[0]; + } + + @SuppressWarnings("unchecked") + protected SelectionChangeListener<E>[] buildSelectionChangeListeners() { + return new SelectionChangeListener[0]; + } + + protected DisposeListener buildListBoxDisposeListener() { + return new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + ListBoxModelAdapter.this.listBoxDisposed(event); + } + @Override + public String toString() { + return "list box dispose listener"; + } + }; + } + + protected void synchronizeListBox() { + this.synchronizeListBoxItems(); + this.synchronizeListBoxSelection(); + } + + + // ********** string converter ********** + + public void setStringConverter(StringConverter<E> stringConverter) { + if (stringConverter == null) { + throw new NullPointerException(); + } + this.stringConverter = stringConverter; + this.synchronizeListBox(); + } + + + // ********** list ********** + + /** + * Use the string converter to convert the specified item to a + * string that can be added to the list box. + */ + protected String convert(E item) { + return this.stringConverter.convertToString(item); + } + + /** + * Brute force synchronization of list box with the model list. + */ + protected void synchronizeListBoxItems() { + int len = this.listHolder.size(); + String[] items = new String[len]; + for (int i = 0; i < len; i++) { + items[i] = this.convert(this.listHolder.get(i)); + } + this.listBox.setItems(items); + } + + /** + * The model has changed - synchronize the list box. + */ + protected void listItemsAdded(ListChangeEvent event) { + int i = event.index(); + for (ListIterator<E> stream = this.items(event); stream.hasNext(); ) { + this.listBox.add(this.convert(stream.next()), i++); + } + } + + /** + * The model has changed - synchronize the list box. + */ + protected void listItemsRemoved(ListChangeEvent event) { + this.listBox.remove(event.index(), event.index() + event.itemsSize() - 1); + } + + /** + * The model has changed - synchronize the list box. + */ + protected void listItemsMoved(ListChangeEvent event) { + int target = event.targetIndex(); + int source = event.sourceIndex(); + int len = event.moveLength(); + int loStart = Math.min(target, source); + int hiStart = Math.max(target, source); + // make a copy of the affected items... + String[] subArray = CollectionTools.subArray(this.listBox.getItems(), loStart, hiStart + len - loStart); + // ...move them around... + subArray = CollectionTools.move(subArray, target - loStart, source - loStart, len); + // ...and then put them back + for (int i = 0; i < subArray.length; i++) { + this.listBox.setItem(loStart + i, subArray[i]); + } + } + + /** + * The model has changed - synchronize the list box. + */ + protected void listItemsReplaced(ListChangeEvent event) { + int i = event.index(); + for (ListIterator<E> stream = this.items(event); stream.hasNext(); ) { + this.listBox.setItem(i++, this.convert(stream.next())); + } + } + + /** + * The model has changed - synchronize the list box. + */ + protected void listCleared(ListChangeEvent event) { + this.listBox.removeAll(); + } + + /** + * The model has changed - synchronize the list box. + */ + protected void listChanged(ListChangeEvent event) { + this.synchronizeListBoxItems(); + } + + // minimized unchecked code + @SuppressWarnings("unchecked") + protected ListIterator<E> items(ListChangeEvent event) { + return ((ListIterator<E>) event.items()); + } + + + // ********** selected items ********** + + protected int indexOf(E item) { + int len = this.listHolder.size(); + for (int i = 0; i < len; i++) { + if (this.listHolder.get(i) == item) { + return i; + } + } + return -1; + } + + protected void synchronizeListBoxSelection() { + int[] indices = new int[this.selectedItemsHolder.size()]; + int i = 0; + for (Iterator<E> stream = this.selectedItemsHolder.iterator(); stream.hasNext(); ) { + indices[i++] = this.indexOf(stream.next()); + } + this.listBox.deselectAll(); + this.listBox.select(indices); + } + + protected void selectedItemsAdded(CollectionChangeEvent event) { + int[] indices = new int[event.itemsSize()]; + int i = 0; + for (Iterator<E> stream = this.items(event); stream.hasNext(); ) { + indices[i++] = this.indexOf(stream.next()); + } + this.listBox.select(indices); + } + + protected void selectedItemsRemoved(CollectionChangeEvent event) { + int[] indices = new int[event.itemsSize()]; + int i = 0; + for (Iterator<E> stream = this.items(event); stream.hasNext(); ) { + indices[i++] = this.indexOf(stream.next()); + } + this.listBox.deselect(indices); + } + + protected void selectedItemsCleared(CollectionChangeEvent event) { + this.listBox.deselectAll(); + } + + protected void selectedItemsChanged(CollectionChangeEvent event) { + this.synchronizeListBoxSelection(); + } + + // minimized unchecked code + @SuppressWarnings("unchecked") + protected Iterator<E> items(CollectionChangeEvent event) { + return ((Iterator<E>) event.items()); + } + + + // ********** list box events ********** + + protected void listBoxSelectionChanged(SelectionEvent event) { + if (this.selectionChangeListeners.length > 0) { + @SuppressWarnings("unchecked") + SelectionChangeEvent<E> scEvent = new SelectionChangeEvent(this, this.selectedItems()); + for (SelectionChangeListener<E> selectionChangeListener : this.selectionChangeListeners) { + selectionChangeListener.selectionChanged(scEvent); + } + } + } + + protected Collection<E> selectedItems() { + @SuppressWarnings("unchecked") + ArrayList<E> selectedItems = new ArrayList(this.listBox.getSelectionCount()); + for (int selectionIndex : this.listBox.getSelectionIndices()) { + selectedItems.add(this.listHolder.get(selectionIndex)); + } + return selectedItems; + } + + protected void listBoxDoubleClicked(SelectionEvent event) { + if (this.doubleClickListeners.length > 0) { + // there should be only a single item selected during a double-click(?) + E selection = this.listHolder.get(this.listBox.getSelectionIndex()); + @SuppressWarnings("unchecked") + DoubleClickEvent<E> dcEvent = new DoubleClickEvent(this, selection); + for (DoubleClickListener<E> doubleClickListener : this.doubleClickListeners) { + doubleClickListener.doubleClick(dcEvent); + } + } + } + + + // ********** dispose ********** + + protected void listBoxDisposed(DisposeEvent event) { + this.listBox.removeDisposeListener(this.listBoxDisposeListener); + this.listBox.removeSelectionListener(this.listBoxSelectionListener); + this.selectedItemsHolder.removeCollectionChangeListener(CollectionValueModel.VALUES, this.selectedItemsChangeListener); + this.listHolder.removeListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); + } + + + // ********** standard methods ********** + + @Override + public String toString() { + return StringTools.buildToStringFor(this, this.listHolder); + } + + + // ********** double click support ********** + + public void addDoubleClickListener(DoubleClickListener<E> listener) { + this.doubleClickListeners = CollectionTools.add(this.doubleClickListeners, listener); + } + + public void removeDoubleClickListener(DoubleClickListener<E> listener) { + this.doubleClickListeners = CollectionTools.remove(this.doubleClickListeners, listener); + } + + public interface DoubleClickListener<E> { + void doubleClick(DoubleClickEvent<E> event); + } + + public static class DoubleClickEvent<E> extends EventObject { + private final E selection; + private static final long serialVersionUID = 1L; + + protected DoubleClickEvent(ListBoxModelAdapter<E> source, E selection) { + super(source); + if (selection == null) { + throw new NullPointerException(); + } + this.selection = selection; + } + + @Override + @SuppressWarnings("unchecked") + public ListBoxModelAdapter<E> getSource() { + return (ListBoxModelAdapter<E>) super.getSource(); + } + + public E selection() { + return this.selection; + } + + } + + + // ********** selection support ********** + + public void addSelectionChangeListener(SelectionChangeListener<E> listener) { + this.selectionChangeListeners = CollectionTools.add(this.selectionChangeListeners, listener); + } + + public void removeSelectionChangeListener(SelectionChangeListener<E> listener) { + this.selectionChangeListeners = CollectionTools.remove(this.selectionChangeListeners, listener); + } + + public interface SelectionChangeListener<E> { + void selectionChanged(SelectionChangeEvent<E> event); + } + + public static class SelectionChangeEvent<E> extends EventObject { + private final Collection<E> selection; + private static final long serialVersionUID = 1L; + + protected SelectionChangeEvent(ListBoxModelAdapter<E> source, Collection<E> selection) { + super(source); + if (selection == null) { + throw new NullPointerException(); + } + this.selection = selection; + } + + @Override + @SuppressWarnings("unchecked") + public ListBoxModelAdapter<E> getSource() { + return (ListBoxModelAdapter<E>) super.getSource(); + } + + public Iterator<E> selection() { + return this.selection.iterator(); + } + + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TriStateBooleanButtonModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TriStateBooleanButtonModelAdapter.java new file mode 100644 index 0000000000..f9bce7517d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TriStateBooleanButtonModelAdapter.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * 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.ui.internal.swt; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; +import org.eclipse.jpt.ui.internal.widgets.TriStateCheckBox; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; + +/** + * This adapter can be used to keep a tri-state check box in synch with + * a model Boolean where the value can be <code>null</code>. + */ +@SuppressWarnings("nls") +public class TriStateBooleanButtonModelAdapter { + + /** A value model on the underlying model boolean. */ + protected final WritablePropertyValueModel<Boolean> booleanHolder; + + /** + * A listener that allows us to synchronize the button's selection state with + * the model boolean. + */ + protected final PropertyChangeListener booleanChangeListener; + + /** The check box/toggle button we synchronize with the model boolean. */ + protected final TriStateCheckBox button; + + /** + * A listener that allows us to synchronize the model boolean with + * the button's selection state. + */ + protected final SelectionListener buttonSelectionListener; + + /** + * A listener that allows us to stop listening to stuff when the button + * is disposed. + */ + protected final DisposeListener buttonDisposeListener; + + + // ********** static methods ********** + + /** + * Adapt the specified boolean to the specified button. + * If the boolean is null, the button's value will be "unselected". + */ + public static TriStateBooleanButtonModelAdapter adapt(WritablePropertyValueModel<Boolean> booleanHolder, TriStateCheckBox button) { + return new TriStateBooleanButtonModelAdapter(booleanHolder, button); + } + + + // ********** constructors ********** + + /** + * Constructor - the boolean holder and button are required. + */ + protected TriStateBooleanButtonModelAdapter(WritablePropertyValueModel<Boolean> booleanHolder, TriStateCheckBox button) { + super(); + + Assert.isNotNull(booleanHolder, "The boolean holder cannot be null"); + Assert.isNotNull(button, "The check box cannot be null"); + + this.booleanHolder = booleanHolder; + this.button = button; + + this.booleanChangeListener = this.buildBooleanChangeListener(); + this.booleanHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.booleanChangeListener); + + this.buttonDisposeListener = this.buildButtonDisposeListener(); + this.button.addDisposeListener(this.buttonDisposeListener); + + this.buttonSelectionListener = this.buildButtonSelectionListener(); + this.button.addSelectionListener(this.buttonSelectionListener); + + this.setButtonSelection(this.booleanHolder.value()); + } + + + // ********** initialization ********** + + protected PropertyChangeListener buildBooleanChangeListener() { + return new SWTPropertyChangeListenerWrapper(this.buildBooleanChangeListener_()); + } + + protected PropertyChangeListener buildBooleanChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + TriStateBooleanButtonModelAdapter.this.booleanChanged(event); + } + @Override + public String toString() { + return "tri-state boolean listener"; + } + }; + } + + protected SelectionListener buildButtonSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + TriStateBooleanButtonModelAdapter.this.buttonSelected(event); + } + @Override + public String toString() { + return "tri-state button selection listener"; + } + }; + } + + protected DisposeListener buildButtonDisposeListener() { + return new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + TriStateBooleanButtonModelAdapter.this.buttonDisposed(event); + } + @Override + public String toString() { + return "tri-state button dispose listener"; + } + }; + } + + + // ********** behavior ********** + + /** + * The model has changed - synchronize the button. + * If the new model value is null, use the adapter's default value + * (which is typically false). + */ + protected void booleanChanged(PropertyChangeEvent event) { + this.setButtonSelection((Boolean) event.newValue()); + } + + protected void setButtonSelection(Boolean selection) { + this.button.setSelection(selection); + } + + /** + * The button has been "selected" - synchronize the model. + */ + protected void buttonSelected(SelectionEvent event) { + this.booleanHolder.setValue(button.getSelection()); + } + + + // ********** dispose ********** + + protected void buttonDisposed(DisposeEvent event) { + this.button.removeSelectionListener(this.buttonSelectionListener); + this.button.removeDisposeListener(this.buttonDisposeListener); + this.booleanHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.booleanChangeListener); + } + + + // ********** standard methods ********** + + @Override + public String toString() { + return StringTools.buildToStringFor(this, this.booleanHolder); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/AbstractControlEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/AbstractControlEnabler.java new file mode 100644 index 0000000000..2e19c58c62 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/AbstractControlEnabler.java @@ -0,0 +1,284 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; + +/** + * A <code>ControlEnabler</code> keeps the "enabled" state of a collection of + * widgets in synch with the provided boolean holder. + * + * @see BaseControllerEnabler + * @see ControlEnabler + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +class AbstractControlEnabler +{ + /** + * A listener that allows us to synchronize the controlHolders with changes made + * to the underlying boolean model. + */ + private PropertyChangeListener booleanChangeListener; + + /** + * A value model on the underlying boolean model + */ + private PropertyValueModel<Boolean> booleanHolder; + + /** + * The collection of <code>IControlHolder</code>s whose "enabled" state is + * kept in sync with the boolean holder's value. + */ + private Collection<IControlHolder> controlHolders; + + /** + * The default setting for the "enabled" state; for when the underlying model + * is <code>null</code>. The default [default value] is <code>false<code> + * (i.e. the controlHolders are disabled). + */ + private boolean defaultValue; + + /** + * Creates a new <code>AbstractControlEnabler</code>. + */ + AbstractControlEnabler() { + super(); + initialize(); + } + + /** + * Creates a new <code>AbstractControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders The collection of controlHolders whose "enabled" state is + * kept in sync with the boolean holder's value + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<IControlHolder> controlHolders) { + + this(booleanHolder, controlHolders, false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders The collection of <code>IControlHolder</code>s whose + * "enabled" state is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<IControlHolder> controlHolders, + boolean defaultValue) { + + this(); + initialize(booleanHolder, controlHolders, defaultValue); + } + + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolder The <code>IControlHolder</code> whose "enabled" state + * is kept in sync with the boolean holder's value + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + IControlHolder controlHolder) { + + this(booleanHolder, controlHolder, false); + } + + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders The collection of controlHolders whose "enabled" + * state is kept in sync with the boolean holder's value + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + IControlHolder... controlHolders) { + + this(booleanHolder, CollectionTools.collection(controlHolders), false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolder The <code>IControlHolder</code>s whose "enabled" state + * is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + IControlHolder controlHolder, + boolean defaultValue) { + + this(booleanHolder, new IControlHolder[] { controlHolder }, false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders The collection of controlHolders whose "enabled" state is + * kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + IControlHolder[] controlHolders, + boolean defaultValue) { + + this(); + this.initialize(booleanHolder, CollectionTools.collection(controlHolders), defaultValue); + } + + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders An iterator on the collection of controlHolders whose + * "enabled" state is kept in sync with the boolean holder's value + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<IControlHolder> controlHolders) { + + this(booleanHolder, CollectionTools.collection(controlHolders), false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders An iterator on the collection of controlHolders whose + * "enabled" state is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<IControlHolder> controlHolders, + boolean defaultValue) { + + this(); + initialize(booleanHolder, CollectionTools.collection(controlHolders), defaultValue); + } + + /** + * Returns the boolean primitive of the given <code>Boolean</code> value but + * also checks for <code>null</code>, if that is the case, then + * {@link #defaultValue} is returned. + * + * @param value The <code>Boolean</code> value to be returned as a primitive + * @return The primitive of the given value or {@link #defaultValue}when the + * value is <code>null</code> + */ + protected boolean booleanValue(Boolean value) { + return (value == null) ? this.defaultValue : value; + } + + /** + * Creates a listener for the boolean holder. + * + * @return A new <code>PropertyChangeListener</code> + */ + private PropertyChangeListener buildBooleanChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + updateEnableState(booleanValue(booleanHolder.value())); + } + + @Override + public String toString() { + return "boolean change listener"; + } + }; + } + + /** + * Returns an <code>Iterator</code> over the collection of + * <code>IControlHolder</code>s. + * + * @return The iteration of controlHolders + */ + final Iterator<IControlHolder> controlHolders() { + return this.controlHolders.iterator(); + } + + /** + * Initializes this <code>ControlEnabler</code> by building the + * appropriate listeners. + */ + protected void initialize() { + this.booleanChangeListener = this.buildBooleanChangeListener(); + } + + /** + * Initializes this <code>ControlEnabler</code> with the given state. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controlHolders A <code>IControlHolder</code>s whose enablement state + * is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + protected void initialize(PropertyValueModel<Boolean> booleanHolder, + Collection<IControlHolder> controlHolders, + boolean defaultValue) { + + Assert.isNotNull(booleanHolder, "The holder of the boolean value cannot be null"); + Assert.isNotNull(controlHolders, "The collection of ControlHolders cannot be null"); + + this.controlHolders = new ArrayList<IControlHolder>(controlHolders); + this.defaultValue = defaultValue; + this.booleanHolder = booleanHolder; + this.booleanHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.booleanChangeListener); + this.updateEnableState(); + } + + /** + * Updates the enablement state of the controlHolders. + */ + protected void updateEnableState() { + this.updateEnableState(booleanValue(booleanHolder.value())); + } + + /** + * Updates the enable state of the <code>IControlHolder</code>s. + * + * @param enabledState The new enable state the widgets need to have + */ + protected void updateEnableState(boolean enabled) { + for (IControlHolder controlHolder : this.controlHolders) { + controlHolder.setEnabled(enabled); + } + } + + /** + * This holder of the actual widget. + */ + static interface IControlHolder { + void setEnabled(boolean enabled); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java new file mode 100644 index 0000000000..89565f4d58 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java @@ -0,0 +1,912 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.ui.internal.util; + +import java.util.ArrayList; +import java.util.Collection; +import org.eclipse.jpt.utility.internal.ClassTools; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; + +/** + * This class is responsible to set a preferred width on the registered widgets + * (either <code>Control</code> or <code>ControlAligner</code>) based on the + * widest widget. + * <p> + * Important: The layout data has to be a <code>GridData</code>. If none is set, + * then a new <code>GridData</code> is automatically created. + * <p> + * Here an example of the result if this aligner is used to align controls + * within either one or two group boxes, the controls added are the labels in + * this case. + * <pre> + * -Group Box 1------------------------------ + * | ------------------ | + * | Name: | I | | + * | ------------------ | + * | --------- | + * | Preallocation Size: | |I| | + * | --------- | + * | ------------------ | + * | Descriptor: | |v| | + * | ------------------ | + * ------------------------------------------ + * -Group Box 2------------------------------ + * | ------------------ | + * | Mapping Type: | |V| | + * | ------------------ | + * | ------------------ | + * | Check in Script: |I | | + * | ------------------ | + * ------------------------------------------</pre> + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class ControlAligner +{ + /** + * <code>true</code> if the length of every control needs to be updated + * when control are added or removed; <code>false</code> to add or remove + * the control and then at the end invoke {@link #revalidateSize()}. + */ + private boolean autoValidate; + + /** + * The utility class used to support bound properties. + */ + private Collection<ControlListener> changeSupport; + + /** + * The listener added to each of the controls that listens only to a text + * change. + */ + private ControlListener controlListener; + + /** + * Prevents infinite recursion when recalculating the preferred width. + * This happens in an hierarchy of <code>ControlAligner</code>s. The lock + * has to be placed here and not in the {@link ControlAlignerWrapper}. + */ + private boolean locked; + + /** + * The length of the widest control. If the length was not calculated, then + * this value is -1. + */ + private int maximumWidth; + + /** + * The collection of {@link Wrapper}s encapsulating either <code>Control</code>s + * or {@link ControlAligner}s. + */ + private Collection<Wrapper> wrappers; + + /** + * A null-<code>Point</code> object used to clear the preferred size. + */ + private static final Point DEFAULT_SIZE = new Point(SWT.DEFAULT, SWT.DEFAULT); + + /** + * Creates a new <code>ControlAligner</code>. + */ + public ControlAligner() + { + super(); + initialize(); + } + + /** + * Creates a new <code>ControlAligner</code>. + * + * @param items The collection of <code>Component</code>s + */ + public ControlAligner(Collection<? extends Control> components) + { + this(); + addAllComponents(components); + } + + /** + * Adds the given control. Its preferred width will be used along with the + * width of all the other controls in order to get the widest control and + * use its width as the width for all the controls. + * + * @param control The control to be added + */ + public void add(Control control) + { + Wrapper wrapper = buildWrapper(control); + wrapper.addControlListener(controlListener); + wrappers.add(wrapper); + + revalidate(); + } + + /** + * Adds the given control. Its preferred width will be used along with the + * width of all the other controls in order to get the widest control and + * use its width as the width for all the controls. + * + * @param controlAligner The <code>ControlAligner</code> to be added + * @exception IllegalArgumentException Can't add the ControlAligner to itself + */ + public void add(ControlAligner controlAligner) + { + if (controlAligner == this) + { + throw new IllegalArgumentException("Can't add the ControlAligner to itself"); + } + + Wrapper wrapper = buildWrapper(controlAligner); + wrapper.addControlListener(controlListener); + wrappers.add(wrapper); + + if (!controlAligner.wrappers.isEmpty()) + { + revalidate(); + } + } + + /** + * Adds the items contained in the given collection into this + * <code>ControlAligner</code>. The preferred width of each item will be + * used along with the width of all the other items in order to get the + * widest control and use its width as the width for all the controls. + * + * @param items The collection of <code>Control</code>s + */ + public void addAll(Collection<? extends Control> items) + { + // Deactivate the auto validation while adding all the Controls + // in order to improve performance + boolean oldAutoValidate = autoValidate; + autoValidate = false; + + for (Control item : items) + { + add(item); + } + + autoValidate = oldAutoValidate; + revalidate(); + } + + /** + * Adds the items contained in the given collection into this + * <code>ControlAligner</code>. The preferred width of each item will be + * used along with the width of all the other items in order to get the + * widest component and use its width as the width for all the components. + * + * @param items The collection of <code>ControlAligner</code>s + */ + public void addAllComponentAligners(Collection<ControlAligner> aligners) + { + // Deactivate the auto validation while adding all the JComponents and/or + // ComponentAligners in order to improve performance + boolean oldAutoValidate = autoValidate; + autoValidate = false; + + for (ControlAligner aligner : aligners) + { + add(aligner); + } + + autoValidate = oldAutoValidate; + revalidate(); + } + + /** + * Adds the items contained in the given collection into this + * <code>ControlAligner</code>. The preferred width of each item will be + * used along with the width of all the other items in order to get the + * widest component and use its width as the width for all the components. + * + * @param items The collection of <code>Control</code>s + */ + public void addAllComponents(Collection<? extends Control> components) + { + // Deactivate the auto validation while adding all the JComponents and/or + // ComponentAligners in order to improve performance + boolean oldAutoValidate = autoValidate; + autoValidate = false; + + for (Control component : components) + { + add(component); + } + + autoValidate = oldAutoValidate; + revalidate(); + } + + /** + * Adds the given <code>ControListener</code>. + * + * @param listener The <code>ControlListener</code> to be added + */ + private void addControlListener(ControlListener listener) + { + if (changeSupport == null) + { + changeSupport = new ArrayList<ControlListener>(); + } + + changeSupport.add(listener); + } + + /** + * Creates a new <code>Wrapper</code> that encapsulates the given source. + * + * @param control The control to be wrapped + * @return A new {@link Wrapper} + */ + private Wrapper buildWrapper(Control control) + { + return new ControlWrapper(control); + } + + /** + * Creates a new <code>Wrapper</code> that encapsulates the given source. + * + * @param ControlAligner The <code>ControlAligner</code> to be wrapped + * @return A new {@link ControlAlignerWrapper} + */ + private Wrapper buildWrapper(ControlAligner ControlAligner) + { + return new ControlAlignerWrapper(ControlAligner); + } + + /** + * Reports a bound property change. + * + * @param oldValue the old value of the property (as an int) + * @param newValue the new value of the property (as an int) + */ + private void controlResized(int oldValue, int newValue) + { + if ((changeSupport != null) && (oldValue != newValue)) + { + // Set a dummy widget otherwise EventObject will + // throw a NPE for its source + Event event = new Event(); + event.widget = SWTUtil.getShell(); + + ControlEvent controlEvent = new ControlEvent(event); + + // It seems we need to use reflection so the source can properly be set + ClassTools.setFieldValue(controlEvent, "source", this); + + for (ControlListener listener : changeSupport) + { + listener.controlResized(controlEvent); + } + } + } + + /** + * Returns the length of the widest control. If the length was not + * calculated, then this value is -1. + * + * @return The width of the widest control or -1 if the length has not + * been calculated yet + */ + public int getMaximumWidth() + { + return maximumWidth; + } + + /** + * Returns the size by determining which control has the greatest + * width. + * + * @return The size of this <code>ControlAligner</code>, which is + * {@link #getMaximumWidth()} for the width + */ + private Point getPreferredSize() + { + if (maximumWidth == -1) + { + recalculateWidth(); + } + + return new Point(maximumWidth, 0); + } + + /** + * Initializes this <code>ControlAligner</code>. + */ + private void initialize() + { + this.autoValidate = true; + this.maximumWidth = -1; + this.controlListener = new ControlHandler(); + this.wrappers = new ArrayList<Wrapper>(); + } + + /** + * Invalidates the size of the given object. + * + * @param source The source object to be invalidated + */ + private void invalidate(Object source) + { + Wrapper wrapper = retrieveWrapper(source); + + if (wrapper.isLocked()) + { + return; + } + + Point size = wrapper.getCachedSize(); + size.x = 0; + size.y = 0; + + wrapper.setPreferredSize(DEFAULT_SIZE); + } + + /** + * Determines whether the length of each control should be set each time a + * control is added or removed. If the control's text is changed and + * {@link #isAutoValidate()} returns <code>true</code> then the length of + * each control is automatically updated. When <code>false</code> is returned, + * {@link #revalidateSize()}has to be called manually. + * + * @return <code>true</code> to recalculate the length of every control + * when a control is either added or removed; <code>false</code> to allow + * all the controls to be either added or removed before invoking + * {@link #revalidateSize()} + */ + public boolean isAutoValidate() + { + return autoValidate; + } + + /** + * Determines whether the wrapped component is visible or not, which will + * determine if its preferred width will be included in the calculation of + * this <code>ComponentAligner</code>'s minimum width. + * + * @return <code>true</code> if the source is visible; <code>false</code> + * otherwise + */ + private boolean isVisible() + { + boolean visible = true; + + for (Wrapper wrapper : wrappers) + { + visible &= wrapper.isVisible(); + } + + return visible; + } + + /** + * Updates the maximum length based on the widest control. This methods + * does not update the width of the controls. + */ + private void recalculateWidth() + { + int width = -1; + + for (Wrapper wrapper : wrappers) + { + Point size = wrapper.getCachedSize(); + + // The size has not been calculated yet + if ((size.y == 0) && wrapper.isVisible()) + { + Point newSize = wrapper.getPreferredSize(); + + size.x = newSize.x; + size.y = newSize.y; + } + + // Only keep the greatest width + width = Math.max(size.x, width); + } + + locked = true; + setMaximumWidth(width); + locked = false; + } + + /** + * Removes the given control. Its preferred width will not be used when + * calculating the widest control. + * + * @param control The control to be removed + */ + public void remove(Control control) + { + Wrapper wrapper = retrieveWrapper(control); + wrapper.removeControlListener(controlListener); + wrappers.remove(wrapper); + +// if (control.isPreferredSizeSet()) +// { +// control.setPreferredSize(null); +// } + + revalidate(); + } + + /** + * Removes the given <code>ControlAligner</code>. Its preferred width + * will not be used when calculating the widest control. + * + * @param controlAligner The <code>ControlAligner</code> to be removed + */ + public void remove(ControlAligner controlAligner) + { + Wrapper wrapper = retrieveWrapper(controlAligner); + wrapper.removeControlListener(controlListener); + wrappers.remove(wrapper); + + revalidate(); + } + + /** + * Removes the given <code>ControlListener</code>. + * + * @param listener The <code>ControlListener</code> to be removed + */ + private void removeControlListener(ControlListener listener) + { + changeSupport.remove(listener); + + if (changeSupport.isEmpty()) + { + changeSupport = null; + } + } + + /** + * Retrieves the <code>Wrapper</code> that is encapsulating the given object. + * + * @param source Either a <code>Control</code> or a <code>ControlAligner</code> + * @return Its <code>Wrapper</code> + */ + private Wrapper retrieveWrapper(Object source) + { + for (Wrapper wrapper : wrappers) + { + if (wrapper.getSource() == source) + { + return wrapper; + } + } + + throw new IllegalArgumentException("Can't retrieve the Wrapper for " + source); + } + + /** + * If the count of control is greater than one and {@link #isAutoValidate()} + * returns <code>true</code>, then the size of all the registered + * <code>Control</code>s will be udpated. + */ + private void revalidate() + { + if (autoValidate) + { + recalculateWidth(); + revalidatePreferredSizeImp(); + } + } + + /** + * Updates the preferred size of every component based on the widest + * component. + */ + private void revalidatePreferredSizeImp() + { + for (Wrapper wrapper : wrappers) + { + Point size = wrapper.getCachedSize(); + size = new Point(maximumWidth, size.y); + wrapper.setPreferredSize(size); + } + } + + /** + * Updates the size of every control based on the widest control. + */ + public void revalidateSize() + { + recalculateWidth(); + revalidateSizeImp(); + } + + /** + * Updates the size of every control based on the widest control. + */ + private void revalidateSizeImp() + { + // Set the preferred width for every control + for (Wrapper wrapper : wrappers) + { + Point size = wrapper.getCachedSize(); + size = new Point(maximumWidth, size.y); + wrapper.setPreferredSize(size); + } + } + + /** + * Sets the length of the widest control. If the length was not calulcated, + * then this value is -1. + * + * @param maximumWidth The width of the widest control + */ + private void setMaximumWidth(int maximumWidth) + { + int oldMaximumWidth = getMaximumWidth(); + this.maximumWidth = maximumWidth; + controlResized(oldMaximumWidth, maximumWidth); + } + + /** + * Returns a string representation of this <code>ControlAligner</code>. + * + * @return Information about this object + */ + @Override + public String toString() + { + StringBuffer sb = new StringBuffer(); + StringTools.buildToStringFor(this, sb); + sb.append("autoValidate="); + sb.append(autoValidate); + sb.append(", maximumWidth="); + sb.append(maximumWidth); + sb.append(", wrappers="); + sb.append(wrappers); + return sb.toString(); + } + + /** + * This <code>Wrapper</code> encapsulates a {@link ControlAligner}. + */ + private class ControlAlignerWrapper implements Wrapper + { + /** + * The cached size, which is {@link ControlAligner#maximumWidth}. + */ + private Point cachedSize; + + /** + * The <code>ControlAligner</code> encapsulated by this + * <code>Wrapper</code>. + */ + private final ControlAligner controlAligner; + + /** + * Creates a new <code>ControlAlignerWrapper</code> that encapsulates + * the given <code>ControlAligner</code>. + * + * @param controlAligner The <code>ControlAligner</code> to be + * encapsulated by this <code>Wrapper</code> + */ + private ControlAlignerWrapper(ControlAligner controlAligner) + { + super(); + + this.controlAligner = controlAligner; + cachedSize = new Point(controlAligner.maximumWidth, 0); + } + + /* + * (non-Javadoc) + */ + public void addControlListener(ControlListener listener) + { + controlAligner.addControlListener(listener); + } + + /* + * (non-Javadoc) + */ + public Point getCachedSize() + { + return cachedSize; + } + + /* + * (non-Javadoc) + */ + public Point getPreferredSize() + { + return controlAligner.getPreferredSize(); + } + + /* + * (non-Javadoc) + */ + public Object getSource() + { + return controlAligner; + } + + /* + * (non-Javadoc) + */ + public boolean isLocked() + { + return controlAligner.locked; + } + + /* + * (non-Javadoc) + */ + public boolean isVisible() + { + return controlAligner.isVisible(); + } + + /* + * (non-Javadoc) + */ + public void removeControlListener(ControlListener listener) + { + controlAligner.removeControlListener(listener); + } + + /* + * (non-Javadoc) + */ + public void setPreferredSize(Point size) + { + if (size == DEFAULT_SIZE) + { + controlAligner.maximumWidth = -1; + } + else if (controlAligner.maximumWidth != size.x) + { + controlAligner.maximumWidth = size.x; + controlAligner.revalidateSizeImp(); + } + } + + /* + * (non-Javadoc) + */ + @Override + public String toString() + { + StringBuffer sb = new StringBuffer(); + StringTools.buildToStringFor(this, sb); + sb.append("cachedSize="); + sb.append(cachedSize); + sb.append(", controlAligner="); + sb.append(controlAligner); + return sb.toString(); + } + } + + /** + * The listener added to each of the control that listens only to a text + * change. + */ + private class ControlHandler implements ControlListener + { + /* + * (non-Javadoc) + */ + public void controlMoved(ControlEvent e) + { + // Nothing to do + } + + /* + * (non-Javadoc) + */ + public void controlResized(ControlEvent e) + { + invalidate(e.getSource()); + revalidate(); + } + } + + /** + * This <code>Wrapper</code> encapsulates a {@link Control}. + */ + private class ControlWrapper implements Wrapper + { + /** + * The cached size, which is control's size. + */ + private Point cachedSize; + + /** + * The control to be encapsulated by this <code>Wrapper</code>. + */ + private final Control control; + + /** + * Creates a new <code>controlWrapper</code> that encapsulates the given + * control. + * + * @param control The control to be encapsulated by this <code>Wrapper</code> + */ + private ControlWrapper(Control control) + { + super(); + + this.control = control; + cachedSize = new Point(0, 0); + } + + /* + * (non-Javadoc) + */ + public void addControlListener(ControlListener listener) + { + control.addControlListener(listener); + } + + /* + * (non-Javadoc) + */ + public Point getCachedSize() + { + return cachedSize; + } + + /* + * (non-Javadoc) + */ + public Point getPreferredSize() + { + return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + } + + /* + * (non-Javadoc) + */ + public Object getSource() + { + return control; + } + + /* + * (non-Javadoc) + */ + public boolean isLocked() + { + return false; + } + + /* + * (non-Javadoc) + */ + public boolean isVisible() + { + return control.isVisible(); + } + + /* + * (non-Javadoc) + */ + public void removeControlListener(ControlListener listener) + { + control.removeControlListener(listener); + } + + /* + * (non-Javadoc) + */ + public void setPreferredSize(Point size) + { + GridData data = (GridData) control.getLayoutData(); + + if (data == null) + { + data = new GridData(); + data.horizontalAlignment = SWT.FILL; + control.setLayoutData(data); + } + + data.widthHint = size.x; + data.heightHint = size.y; + } + + /* + * (non-Javadoc) + */ + @Override + public String toString() + { + StringBuffer sb = new StringBuffer(); + StringTools.buildToStringFor(this, sb); + sb.append("cachedSize="); + sb.append(cachedSize); + sb.append(", control="); + sb.append(control); + return sb.toString(); + } + } + + /** + * This <code>Wrapper</code> helps to encapsulate heterogeneous objects and + * apply the same behavior on them. + */ + private interface Wrapper + { + /** + * Adds a <code>IPropertyChangeListener</code> for a specific property. + * The listener will be invoked only when a call on + * <code>firePropertyChange</code> names that specific property. + * + * @param listener The <code>ControlListener</code> to be added + */ + public void addControlListener(ControlListener listener); + + /** + * Returns the cached size of the encapsulated source. + * + * @return A non-<code>null</code> size + */ + public Point getCachedSize(); + + /** + * Returns the preferred size of the wrapped source. + * + * @return The preferred size + */ + public Point getPreferredSize(); + + /** + * Returns the encapsulated object. + * + * @return The object that is been wrapped + */ + public Object getSource(); + + /** + * Prevents infinite recursion when recalculating the preferred width. + * This happens in an hierarchy of <code>ControlAligner</code>s. + * + * @return <code>true</code> to prevent this <code>Wrapper</code> from + * being invalidated; otherwise <code>false</code> + */ + public boolean isLocked(); + + /** + * Determines whether the wrapped component is visible or not, which will + * determine if its preferred width will be included in the calculation of + * this <code>ComponentAligner</code>'s minimum width. + * + * @return <code>true</code> if the source is visible; <code>false</code> + * otherwise + */ + boolean isVisible(); + + /** + * Removes the given <code>ControlListener</code>. + * + * @param listener The <code>ControlListener</code> to be removed + */ + public void removeControlListener(ControlListener listener); + + /** + * Sets the size on the encapsulated source. + * + * @param size The new size + */ + public void setPreferredSize(Point size); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java new file mode 100644 index 0000000000..29465b0394 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java @@ -0,0 +1,170 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Control; + +/** + * This <code>ControlEnabler</code> keeps the "enabled" state of a collection of + * controls in synch with the provided boolean holder. + * + * @version 2.0 + * @since 2.0 + */ +public class ControlEnabler extends AbstractControlEnabler +{ + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "enabled" state is + * kept in sync with the boolean holder's value + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends Control> controls) { + + this(booleanHolder, controls, false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "enabled" state is + * kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends Control> controls, + boolean defaultValue) { + + this(booleanHolder, controls.iterator(), defaultValue); + } + + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param control The control whose "enabled" state is + * kept in sync with the boolean holder's value + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Control control) { + + this(booleanHolder, control, false); + } + + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "enabled" state is + * kept in sync with the boolean holder's value + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Control... controls) { + + this(booleanHolder, CollectionTools.iterator(controls), false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param control The control whose "enabled" state is + * kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Control control, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.singletonIterator(control), false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "enabled" state is + * kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Control[] controls, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.iterator(controls), defaultValue); + } + + /** + * Creates a new <code>ControlEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls An iterator on the collection of controls whose + * "enabled" state is kept in sync with the boolean holder's value + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends Control> controls) { + + this(booleanHolder, controls, false); + } + + /** + * Creates a new <code>ControlEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls An iterator on the collection of controls whose + * "enabled" state is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends Control> controls, + boolean defaultValue) { + + super(booleanHolder, wrap(controls), defaultValue); + } + + private static Collection<IControlHolder> wrap(Iterator<? extends Control> controls) { + return CollectionTools.collection(new TransformationIterator<Control, IControlHolder>(controls) { + @Override + protected IControlHolder transform(Control control) { + return new ControlHolder(control); + } + }); + } + + private static class ControlHolder implements IControlHolder { + private final Control control; + + ControlHolder(Control control) { + super(); + this.control = control; + } + + public void setEnabled(boolean enabled) { + if (!this.control.isDisposed()) { + this.control.setEnabled(enabled); + } + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java new file mode 100644 index 0000000000..ca87b1f9be --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Button; + +/** + * A default implementation of <code>LabeledControl</code> that updates a + * <code>Button</code> when required. + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class LabeledButton implements LabeledControl +{ + /** + * The button to be updated with a different icon and text. + */ + private final Button button; + + /** + * Creates a new <code>LabeledButton</code>. + * + * @param button The button that will have its text and icon updated when + * required + */ + public LabeledButton(Button button) { + super(); + Assert.isNotNull(button, "The button cannot be null"); + this.button = button; + } + + /* + * (non-Javadoc) + */ + public void setIcon(Image image) { + this.button.setImage(image); + } + + /* + * (non-Javadoc) + */ + public void setText(String text) { + this.button.setText(text); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java new file mode 100644 index 0000000000..508872b76a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import org.eclipse.swt.graphics.Image; + +/** + * This <code>LabeledControl</code> is used to encapsulate a widget and update + * its properties (icon and text). + * + * @see LabeledButton + * @see LabeledLabel + * + * @version 2.0 + * @since 2.0 + */ +public interface LabeledControl { + /** + * Passes the image so the wrapped component can receive it. + * + * @param image The new <code>Image</code> + */ + void setIcon(Image image); + + /** + * Passes the text so the wrapped component can receive it. + * + * @param text The new text + */ + void setText(String text); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java new file mode 100644 index 0000000000..1958bcdc44 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.graphics.Image; + +/** + * This updater is responsible to update the <code>LabeledControl</code> when + * the text and the icon need to change. + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class LabeledControlUpdater { + + /** + * The wrapper around a control that has text and icon. + */ + private LabeledControl labeledControl; + + /** + * Creates a new <code>LabeledControlUpdater</code>. + * + * @param labeledControl The wrapper around the control that needs to + * have its text updated + * @param textHolder The holder this class will listen for changes + */ + public LabeledControlUpdater(LabeledControl labeledControl, + PropertyValueModel<String> textHolder) + { + this(labeledControl, textHolder, null); + } + + /** + * Creates a new <code>LabeledControlUpdater</code>. + * + * @param labeledControl The wrapper around the control that needs to + * have its image and text updated + * @param imageHolder The holder this class will listen for changes + * @param textHolder The holder this class will listen for changes + */ + public LabeledControlUpdater(LabeledControl labeledControl, + PropertyValueModel<String> textHolder, + PropertyValueModel<Image> imageHolder) + { + super(); + initialize(labeledControl, imageHolder, textHolder); + } + + private PropertyChangeListener buildIconListener() { + return new SWTPropertyChangeListenerWrapper(buildIconListener_()); + } + + private PropertyChangeListener buildIconListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + LabeledControlUpdater.this.setImage((Image) e.newValue()); + } + + @Override + public String toString() { + return "LabeledControlUpdater.imageListener"; + } + }; + } + + private PropertyChangeListener buildTextListener() { + return new SWTPropertyChangeListenerWrapper(buildTextListener_()); + } + + private PropertyChangeListener buildTextListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + LabeledControlUpdater.this.setText((String) e.newValue()); + } + + @Override + public String toString() { + return "LabeledControlUpdater.textListener"; + } + }; + } + + private void initialize(LabeledControl labeledControl, + PropertyValueModel<Image> imageHolder, + PropertyValueModel<String> textHolder) + { + Assert.isNotNull(labeledControl, "The LabeledControl cannot be null"); + Assert.isNotNull(textHolder, "The text holder cannot be null"); + + this.labeledControl = labeledControl; + + textHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildTextListener()); + setText(textHolder.value()); + + if (imageHolder != null) { + imageHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildIconListener()); + setImage(imageHolder.value()); + } + } + + private void setImage(Image icon) { + labeledControl.setIcon(icon); + } + + private void setText(String text) { + labeledControl.setText(text); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java new file mode 100644 index 0000000000..a1230ae71c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Label; + +/** + * A default implementation of <code>LabeledControl</code> that updates an + * <code>Label</code> when required. + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class LabeledLabel implements LabeledControl +{ + /** + * The label to be updated with a different icon and text. + */ + private final Label label; + + /** + * Creates a new <code>LabeledButton</code>. + * + * @param label The label that will have its text and icon updated when + * required + */ + public LabeledLabel(Label label) { + super(); + Assert.isNotNull(label, "The label cannot be null"); + this.label = label; + } + + /* + * (non-Javadoc) + */ + public void setIcon(Image image) { + this.label.setImage(image); + } + + /* + * (non-Javadoc) + */ + public void setText(String text) { + this.label.setText(text); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java new file mode 100644 index 0000000000..fae134f714 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledTableItem.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +/** + * A default implementation of <code>LabeledControl</code> that updates a + * <code>TableItem</code> when required. + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class LabeledTableItem implements LabeledControl +{ + /** + * The table cell to be updated with a different icon and text. + */ + private TableItem tableItem; + + /** + * Creates a new <code>LabeledTableItem</code>. + * + * @param tableItem The <code>TableItem</code> that will have its text and + * icon updated when required + */ + public LabeledTableItem(TableItem tableItem) { + super(); + + Assert.isNotNull(tableItem, "The TableItem cannot be null"); + this.tableItem = tableItem; + } + + /* + * (non-Javadoc) + */ + public void setIcon(final Image image) { + + if (tableItem.isDisposed()) { + return; + } + + updateTableItem(tableItem.getText(), image); + } + + /* + * (non-Javadoc) + */ + public void setText(final String text) { + + if (tableItem.isDisposed()) { + return; + } + + updateTableItem(text, tableItem.getImage()); + } + + private void updateTableItem(String text, Image image) { + + if (text == null) { + text = ""; + } + + Table table = tableItem.getParent(); + table.setRedraw(false); + + boolean checked = tableItem.getChecked(); + boolean grayed = tableItem.getGrayed(); + boolean hasFocus = table.isFocusControl(); + + int index = table.indexOf(tableItem); + table.remove(index); + + tableItem = new TableItem(table, SWT.CHECK, index); + tableItem.setText(text); + tableItem.setImage(image); + tableItem.setChecked(checked); + tableItem.setGrayed(grayed); + + table.layout(true, true); + table.getParent().getParent().layout(true, true); + table.setRedraw(true); + + if (hasFocus) { + table.forceFocus(); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java new file mode 100644 index 0000000000..d30451fb20 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; + +/** + * This <code>PaneEnabler</code> keeps the "enabled" state of a collection of + * controls in synch with the provided boolean holder. + * + * @version 2.0 + * @since 2.0 + */ +public class PaneEnabler extends AbstractControlEnabler +{ + /** + * Creates a new <code>PaneEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param pane The pane whose "enabled" state is kept in sync with the + * boolean holder's value + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?> pane) { + + this(booleanHolder, pane, false); + } + + /** + * Creates a new <code>PaneEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "enabled" state is kept in sync + * with the boolean holder's value + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?>... panes) { + + this(booleanHolder, CollectionTools.collection(panes), false); + } + + /** + * Creates a new <code>PaneEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param pane The pane whose "enabled" state is kept in sync with the + * boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?> pane, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.singletonIterator(pane), false); + } + + /** + * Creates a new <code>PaneEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "enabled" state is kept in sync + * with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?>[] panes, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.iterator(panes), defaultValue); + } + + /** + * Creates a new <code>BaseJpaControllerEnabler</code> with a default value + * of* <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "enabled" state is kept in sync + * with the boolean holder's value + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends AbstractPane<?>> panes) { + + this(booleanHolder, panes, false); + } + + /** + * Creates a new <code>BaseJpaControllerEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "enabled" state is kept in sync + * with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends AbstractPane<?>> panes, + boolean defaultValue) { + + this(booleanHolder, panes.iterator(), defaultValue); + } + + /** + * Creates a new <code>BaseJpaControllerEnabler</code> with a default value of + * <code>false</code> (i.e. disabled). + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes An iterator on the collection of panes whose "enabled" state + * is kept in sync with the boolean holder's value + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends AbstractPane<?>> panes) { + + this(booleanHolder, panes, false); + } + + /** + * Creates a new <code>BaseJpaControllerEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes An iterator on the collection of panes whose "enabled" state + * is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends AbstractPane<?>> panes, + boolean defaultValue) { + + super(booleanHolder, wrap(panes), defaultValue); + } + + private static Collection<IControlHolder> wrap(Iterator<? extends AbstractPane<?>> panes) { + return CollectionTools.collection(new TransformationIterator<AbstractPane<?>, IControlHolder>(panes) { + @Override + protected IControlHolder transform(AbstractPane<?> pane) { + return new PaneHolder(pane); + } + }); + } + + private static class PaneHolder implements IControlHolder { + private final AbstractPane<?> pane; + + PaneHolder(AbstractPane<?> pane) { + super(); + this.pane = pane; + } + + public void setEnabled(boolean enabled) { + this.pane.enableWidgets(enabled); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java index 1f14002888..3585006bdb 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java @@ -1,28 +1,263 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.ui.internal.util; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.AssertionFailedException; +import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jpt.ui.internal.widgets.NullPostExecution; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; -//copied from jdt.internal.ui.util +/** + * A suite of utility methods related to the user interface. + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") public class SWTUtil { - public static int getTableHeightHint(Table table, int rows) { + /** + * 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 + */ + public static void asyncExec(Runnable runnable) { + getStandardDisplay().asyncExec(runnable); + } + + /** + * Creates the <code>Runnable</code> that will invoke the given + * <code>PostExecution</code> in order to its execution to be done in the + * UI thread. + * + * @param dialog The dialog that was just diposed + * @param postExecution The post execution once the dialog is disposed + * @return The <code>Runnable</code> that will invoke + * {@link PostExecution#execute(Dialog)} + */ + @SuppressWarnings("unchecked") + private static <D1 extends Dialog, D2 extends D1> + Runnable buildPostExecutionRunnable( + final D1 dialog, + final PostExecution<D2> postExecution) { + + return new Runnable() { + public void run() { + setUserInterfaceActive(false); + try { + postExecution.execute((D2) dialog); + } + finally { + setUserInterfaceActive(true); + } + } + }; + } + + /** + * Convenience method for getting the current shell. If the current thread is + * not the UI thread, then an invalid thread access exception will be thrown. + * + * @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()); + } + + return 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 + */ + public static Display getStandardDisplay() + { + Display display = Display.getCurrent(); + + if (display == null) { + display = Display.getDefault(); + } + + return display; + } + + public static int getTableHeightHint(Table table, int rows) { if (table.getFont().equals(JFaceResources.getDefaultFont())) table.setFont(JFaceResources.getDialogFont()); int result= table.getItemHeight() * rows + table.getHeaderHeight(); if (table.getLinesVisible()) result+= table.getGridLineWidth() * (rows - 1); - return result; - } -} + return result; + } + + /** + * Returns the Platform UI workbench. + * + * @return The workbench for this plug-in + */ + public static IWorkbench getWorkbench() { + return PlatformUI.getWorkbench(); + } + + /** + * Sets whether the entire shell and its widgets should be enabled or + * everything should be unaccessible. + * + * @param active <code>true</code> to make all the UI active otherwise + * <code>false</code> to deactivate it + */ + public static void setUserInterfaceActive(boolean active) { + Shell[] shells = getStandardDisplay().getShells(); + + for (Shell shell : shells) { + shell.setEnabled(active); + } + } + + /** + * Asynchronously launches the specified dialog in the UI thread. + * + * @param dialog The dialog to show on screen + */ + public static void show(Dialog dialog) { + show(dialog, NullPostExecution.<Dialog>instance()); + } + + /** + * Asynchronously launches the specified dialog in the UI thread. + * + * @param dialog The dialog to show on screen + * @param postExecution This interface let the caller to invoke a piece of + * code once the dialog is disposed + */ + public static <D1 extends Dialog, D2 extends D1> + void show(final D1 dialog, final PostExecution<D2> postExecution) { + + try { + Assert.isNotNull(dialog, "The dialog cannot be null"); + Assert.isNotNull(postExecution, "The PostExecution cannot be null"); + } + catch (AssertionFailedException e) { + // Make sure the UI is interactive + setUserInterfaceActive(true); + throw e; + } + + new Thread() { + @Override + public void run() { + asyncExec( + new Runnable() { public void run() { + showImp(dialog, postExecution); + } + } + ); + }}.start(); + } + + /** + * Asynchronously launches the specified dialog in the UI thread. + * + * @param dialog The dialog to show on screen + * @param postExecution This interface let the caller to invoke a piece of + * code once the dialog is disposed + */ + private static <D1 extends Dialog, D2 extends D1> + void showImp(D1 dialog, PostExecution<D2> postExecution) { + + setUserInterfaceActive(true); + dialog.open(); + + if (postExecution != NullPostExecution.<D2>instance()) { + asyncExec(buildPostExecutionRunnable(dialog, postExecution)); + } + } + + /** + * 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(); + } + + /** + * Determines if the current thread is the UI event thread by using the + * thread from which the given viewer's display was instantiated. + * + * @param viewer The viewer used to determine if the current thread + * is the UI event thread + * @return <code>true</code> if the current thread is the UI event thread; + * <code>false</code> otherwise + */ + public static boolean uiThread(Viewer viewer) { + return uiThread(viewer.getControl()); + } + + /** + * Determines if the current thread is the UI event thread by using the + * thread from which the given widget's display was instantiated. + * + * @param widget The widget used to determine if the current thread + * is the UI event thread + * @return <code>true</code> if the current thread is the UI event thread; + * <code>false</code> otherwise + */ + public static boolean uiThread(Widget widget) { + return widget.getDisplay().getThread() == Thread.currentThread(); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java index cd51349405..11bb2b2e57 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java @@ -13,9 +13,10 @@ package org.eclipse.jpt.ui.internal.util; import java.util.ArrayList; import java.util.List; - import org.eclipse.core.runtime.Assert; - +import org.eclipse.jface.viewers.ColumnLayoutData; +import org.eclipse.jface.viewers.ColumnPixelData; +import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; @@ -25,10 +26,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.jface.viewers.ColumnLayoutData; -import org.eclipse.jface.viewers.ColumnPixelData; -import org.eclipse.jface.viewers.ColumnWeightData; - /** * A special composite to layout columns inside a table. The composite is needed since we have * to layout the columns "before" the actual table gets layouted. Hence we can't use a normal diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/AbstractJpaView.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/AbstractJpaView.java index aaa185b234..96c28f489c 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/AbstractJpaView.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/AbstractJpaView.java @@ -3,77 +3,154 @@ * program and the accompanying materials are made available under the terms 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.ui.internal.views; -import org.eclipse.jpt.ui.internal.selection.ISelectionManager; -import org.eclipse.jpt.ui.internal.selection.Selection; +import org.eclipse.jpt.ui.internal.selection.IJpaSelection; +import org.eclipse.jpt.ui.internal.selection.IJpaSelectionManager; import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +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; -public abstract class AbstractJpaView extends ViewPart -{ - protected PageBook pageBook; - - protected Composite defaultComposite; - - +/** + * This is the abstract implementation of the JPA view. The selection is changed + * by receiving a <code>IJpaSelection</code>. + * + * @see IJpaSelection + * + * @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 TabbedPropertySheetWidgetFactory widgetFactory; - - - public AbstractJpaView(String aDefaultLabel) { + + /** + * Creates a new <code>AbstractJpaView</code>. + * + * @param defaultLabel + */ + public AbstractJpaView(String defaultLabel) { super(); - defaultLabel = aDefaultLabel; - this.widgetFactory = new TabbedPropertySheetWidgetFactory(); + this.defaultLabel = defaultLabel; + this.initialize(); } - + + private Composite buildDefaultComposite() { + Composite composite = getWidgetFactory().createComposite(pageBook, SWT.NONE); + composite.setLayout(new FillLayout(SWT.VERTICAL)); + getWidgetFactory().createLabel(composite, defaultLabel); + return composite; + } + + /* + * (non-Javadoc) + */ + @Override public final void createPartControl(Composite parent) { pageBook = new PageBook(parent, SWT.NONE); + defaultComposite = buildDefaultComposite(); pageBook.showPage(defaultComposite); - + subcreatePartControl(parent); - - ISelectionManager selectionManager = + + IJpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(getViewSite().getWorkbenchWindow()); + selectionManager.register(this); select(selectionManager.getCurrentSelection()); } - - protected void subcreatePartControl(Composite parent) { - // no op - for subclasses to override if wished + + protected final PageBook getPageBook() { + return pageBook; } - - private Composite buildDefaultComposite() { - Composite composite = getWidgetFactory().createComposite(pageBook, SWT.NONE); - composite.setLayout(new FillLayout(SWT.VERTICAL)); - getWidgetFactory().createLabel(composite, defaultLabel); - return composite; + + public final TabbedPropertySheetWidgetFactory getWidgetFactory() { + return this.widgetFactory; } - - public abstract void select(Selection aSelection); - - protected void showDefaultPage() { - pageBook.showPage(defaultComposite); + + /** + * Initializes this JPA view. + */ + protected void initialize() { + this.widgetFactory = new TabbedPropertySheetWidgetFactory(); } - + + /** + * 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(IJpaSelection jpaSelection); + + /* + * (non-Javadoc) + */ + @Override public void setFocus() { pageBook.setFocus(); } - - public TabbedPropertySheetWidgetFactory getWidgetFactory() { - return this.widgetFactory; + + /** + * 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) { + pageBook.getParent().setRedraw(false); + try { + // It seems the scroll pane has to be installed right before showing + // the page, if it is installed during the creation of the pane then + // its layout will not always revalidate correctly, i.e. will not show + // all the time the vertical scroll bar + ScrolledForm scrolledForm = widgetFactory.createScrolledForm(pageBook); + scrolledForm.getBody().setLayout(new GridLayout(1, false)); + page.setParent(scrolledForm.getBody()); + + pageBook.showPage(scrolledForm); + } + finally { + pageBook.getParent().setRedraw(true); + } + } + + protected void subcreatePartControl(Composite parent) { + // no op - for subclasses to override if wished } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java index 7aaa8548ff..6161215101 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java @@ -1,162 +1,217 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.views; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; -import org.eclipse.jpt.core.internal.IJpaContentNode; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; import org.eclipse.jpt.ui.internal.IJpaPlatformUi; import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.PlatformRegistry; +import org.eclipse.jpt.ui.internal.JptUiPlugin; +import org.eclipse.jpt.ui.internal.Tracing; import org.eclipse.jpt.ui.internal.details.IJpaDetailsPage; import org.eclipse.jpt.ui.internal.details.IJpaDetailsProvider; -import org.eclipse.jpt.ui.internal.selection.Selection; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; +import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; +import org.eclipse.jpt.ui.internal.selection.IJpaSelection; +import org.eclipse.jpt.ui.internal.selection.JpaSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; -public class JpaDetailsView extends AbstractJpaView -{ - private Selection currentSelection; - - private IJpaDetailsPage currentPage; - - /* key: String file content id, value: IJpaDetailsProvider */ - private Map<String, IJpaDetailsProvider> detailsProviders; - - /* key: Object content node id, value: Composite page */ - private Map<Object, IJpaDetailsPage> detailsPages; - +/** + * The JPA view that shows the details a mapping (either type or attribute). + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public class JpaDetailsView extends AbstractJpaView +{ + /** + * The current <code>IJpaDetailsPage</code> that was retrieve based on the + * current selection. + */ + private IJpaDetailsPage<IJpaContextNode> currentPage; + + /** + * The current selection used to show the right <code>IJpaDetailsPage</code>. + */ + private IJpaSelection currentSelection; + + /** + * key: Object content node id, value: Composite page. + */ + private Map<Object, IJpaDetailsPage<? extends IJpaContextNode>> detailsPages; + + /** + * Creates a new <code>JpaDetailsView</code>. + */ public JpaDetailsView() { super(JptUiMessages.JpaDetailsView_viewNotAvailable); - this.currentSelection = Selection.NULL_SELECTION; - this.detailsProviders = new HashMap<String, IJpaDetailsProvider>(); - this.detailsPages = new HashMap<Object, IJpaDetailsPage>(); } - - - public Selection getSelection() { + + private IJpaDetailsPage<? extends IJpaContextNode> buildDetailsPage(IJpaContextNode contextNode) { + IJpaDetailsProvider detailsProvider = getDetailsProvider(contextNode); + + if (detailsProvider == null) { + return null; + } + + String id = contextNode.jpaProject().jpaPlatform().getId(); + + Composite container = getWidgetFactory().createComposite(getPageBook()); + container.setLayout(new FillLayout(SWT.HORIZONTAL)); + + IJpaDetailsPage<? extends IJpaContextNode> page = detailsProvider.buildDetailsPage( + container, + contextNode, + getWidgetFactory() + ); + + if (page != null) { + detailsPages.put(id, page); + } + + return page; + } + + /* + * (non-Javadoc) + */ + @Override + public void dispose() { + + detailsPages.clear(); + + currentSelection = JpaSelection.NULL_SELECTION; + currentPage = null; + + super.dispose(); + } + + private IJpaDetailsPage<? extends IJpaContextNode> getDetailsPage(IJpaContextNode contextNode) { + //TODO commented out the caching of the details provider for the time being, + //someone should probably revist the possibility of caching +// String id = contextNode.jpaProject().jpaPlatform().getId(); +// +// if (detailsPages.containsKey(id)) { +// IJpaDetailsPage<? extends IJpaContextNode> page = detailsPages.get(id); +// +// if ((page != null) && page.getControl().isDisposed()) { +// detailsPages.remove(id); +// } +// else { +// return page; +// } +// } +// + return buildDetailsPage(contextNode); + } + + private IJpaDetailsProvider getDetailsProvider(IJpaContextNode contextNode) { + + String platformId = contextNode.jpaProject().jpaPlatform().getId(); + IJpaPlatformUi jpaPlatformUI = JpaPlatformUiRegistry.instance().jpaPlatform(platformId); + return jpaPlatformUI.detailsProvider(contextNode); + + //TODO this view and the detailsProviders Map is not created on a per project basis. + //the detailsProviders and their fileContentTypes could overlap across project, this would cause problems with storing this map. + } + + public IJpaSelection getSelection() { return currentSelection; } - - public void select(Selection newSelection) { - if (newSelection.equals(currentSelection)) { + + /* + * (non-Javadoc) + */ + @Override + protected void initialize() { + super.initialize(); + + this.currentSelection = IJpaSelection.NULL_SELECTION; + this.detailsPages = new HashMap<Object, IJpaDetailsPage<? extends IJpaContextNode>>(); + } + + private void log(String message) { + if (Tracing.booleanDebugOption(Tracing.UI_DETAILS_VIEW)) { + Tracing.log(message); + } + } + + /* + * (non-Javadoc) + */ + @Override + public void select(IJpaSelection jpaSelection) { + if (jpaSelection.equals(currentSelection)) { return; } - - currentSelection = newSelection; - - if (newSelection != Selection.NULL_SELECTION) { - IJpaContentNode newNode = newSelection.getSelectedNode(); - IJpaDetailsPage newPage = getDetailsPage(newNode); + + currentSelection = jpaSelection; + + if (jpaSelection != IJpaSelection.NULL_SELECTION) { + IJpaContextNode newNode = jpaSelection.getSelectedNode(); + IJpaDetailsPage<? extends IJpaContextNode> newPage = getDetailsPage(newNode); setCurrentPage(newPage); } - else if (currentSelection != Selection.NULL_SELECTION) { + else { setCurrentPage(null); } } - - private IJpaDetailsPage getDetailsPage(IJpaContentNode contentNode) { - if (detailsPages.containsKey(contentNode.getId())) { - IJpaDetailsPage page = detailsPages.get(contentNode.getId()); - - if ((page != null) && - (page.getControl().isDisposed())) { - detailsPages.remove(contentNode.getId()); + + /** + * Changes the current page and shows the given page. + * + * @param newPage The new page to display + */ + @SuppressWarnings("unchecked") + private void setCurrentPage(IJpaDetailsPage<? extends IJpaContextNode> page) { + + // Unpopulate old page + if (currentPage != null) { + try { + log("JpaDetailsView.setCurrentPage() : disposing of current page"); + + currentPage.setSubject(null); } - else { - return page; + catch (Exception e) { + JptUiPlugin.log(e); } } - - return buildDetailsPage(contentNode); - } - - private IJpaDetailsPage buildDetailsPage(IJpaContentNode contentNode) { - IJpaDetailsProvider detailsProvider = - getDetailsProvider(contentNode); - - if (detailsProvider == null) { - return null; - } - Composite parentComposite = getWidgetFactory().createComposite(pageBook, SWT.NONE); - parentComposite.setLayout(new FillLayout(SWT.VERTICAL)); - IJpaDetailsPage page = - detailsProvider.buildDetailsPage(parentComposite, contentNode.getId(), getWidgetFactory()); - + + IJpaDetailsPage<IJpaContextNode> newPage = (IJpaDetailsPage<IJpaContextNode>) page; + + // Populate new page if (page != null) { - detailsPages.put(contentNode.getId(), page); - } - - return page; - } - - private IJpaDetailsProvider getDetailsProvider(IJpaContentNode contentNode) { - String contentId = contentNode.getJpaFile().getContentId(); - IJpaDetailsProvider provider = detailsProviders.get(contentId); - - if (provider == null) { - String platformId = contentNode.jpaPlatform().getId(); - IJpaPlatformUi jpaPlatformUI = PlatformRegistry.instance().jpaPlatform(platformId); - provider = jpaPlatformUI.detailsProvider(contentId); - - //TODO this view and the detailsProviders Map is not created on a per project basis. - //the detailsProviders and their fileContentTypes could overlap across project, this would cause problems with storing this map. - - if (provider != null) { - detailsProviders.put(contentId, provider); + try { + log("JpaDetailsView.setCurrentPage() : populating new page"); + newPage.setSubject(currentSelection.getSelectedNode()); + } + catch (Exception e) { + // Show error page + page = null; + JptUiPlugin.log(e); } } - - return provider; - } - - private void setCurrentPage(IJpaDetailsPage newPage) { - // depopulate old page - if ((currentPage != null) && (currentPage != newPage)) { - currentPage.populate(null); - } - - // populate new page - if (newPage != null) { - newPage.populate(currentSelection.getSelectedNode()); + else { + log("JpaDetailsView.setCurrentPage() : No page to populate"); } - + currentPage = newPage; - - // show new page - if (newPage == null) { + + // Show new page + if (page == null) { showDefaultPage(); } else { - pageBook.showPage(newPage.getControl().getParent()); - } - } - - public void dispose() { - for (Iterator<String> stream = new CloneIterator<String>(detailsProviders.keySet()); stream.hasNext(); ) { - String key = stream.next(); - IJpaDetailsProvider provider = detailsProviders.remove(key); - provider.dispose(); + showPage(page.getControl()); } - - for (Iterator<Object> stream = new CloneIterator<Object>(detailsPages.keySet()); stream.hasNext(); ) { - Object key = stream.next(); - IJpaDetailsPage detailsPage = detailsPages.remove(key); - detailsPage.dispose(); - } - - currentSelection = Selection.NULL_SELECTION; - currentPage = null; - - super.dispose(); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaStructureView.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaStructureView.java deleted file mode 100644 index 4df3a6f498..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaStructureView.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.views; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.jpt.core.internal.IJpaFile; -import org.eclipse.jpt.ui.internal.IJpaPlatformUi; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.PlatformRegistry; -import org.eclipse.jpt.ui.internal.jface.NullLabelProvider; -import org.eclipse.jpt.ui.internal.jface.NullTreeContentProvider; -import org.eclipse.jpt.ui.internal.selection.Selection; -import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IWorkbenchActionConstants; - -public class JpaStructureView extends AbstractJpaView -{ - private StructureComposite structureComposite; - - - public JpaStructureView() { - super(JptUiMessages.JpaStructureView_viewNotAvailable); - } - - - @Override - public void subcreatePartControl(Composite parent) { - structureComposite = - new StructureComposite(pageBook, SWT.NULL); - } - - public Selection getSelection() { - if (structureComposite.isVisible()) { - return structureComposite.getSelection(); - } - else { - return Selection.NULL_SELECTION; - } - } - - @Override - public void select(Selection newSelection) { - Selection currentSelection = getSelection(); - - if (newSelection.equals(currentSelection)) { - return; - } - - if (newSelection == Selection.NULL_SELECTION) { - showDefaultPage(); - } - else { - pageBook.showPage(structureComposite); - } - - structureComposite.select(newSelection); - } - - - public void addSelectionChangedListener(ISelectionChangedListener listener) { - structureComposite.viewer.addSelectionChangedListener(listener); - } - - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - structureComposite.viewer.removeSelectionChangedListener(listener); - } - - - private class StructureComposite extends Composite - { - /* key: String file content id, value: IJpaStructureProvider */ - private Map structureProviders; - - private TreeViewer viewer; - - private StructureComposite(Composite parent, int style) { - super(parent, style); - - structureProviders = new HashMap(); - - this.setLayout(new FillLayout()); - - viewer = new TreeViewer(this, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - viewer.setAutoExpandLevel(2); - initContextMenu(); - } - - 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 mgr) { - fillContextMenu(mgr); - } - }); - Menu menu = mgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - 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)); - } - - private Selection getSelection() { - ITreeSelection viewerSelection = (ITreeSelection) viewer.getSelection(); - - if (viewerSelection.isEmpty() || viewerSelection.size() > 1) { - if (viewer.getInput() == null) { - return Selection.NULL_SELECTION; - } - else { - return new Selection((IJpaContentNode) viewer.getInput()); - } - } - - else { - return new Selection((IJpaContentNode) viewerSelection.getFirstElement()); - } - - } - - private void select(Selection selection) { - // note: checks for null and equals() selection have already been performed - - if (selection.equals(Selection.NULL_SELECTION)) { - clearViewer(); - return; - } - - Selection currentSelection = getSelection(); - IJpaContentNode newNode = selection.getSelectedNode(); - IJpaFile newFile = newNode.getJpaFile(); - IJpaContentNode currentNode = - (currentSelection == Selection.NULL_SELECTION) ? - null : getSelection().getSelectedNode(); - IJpaFile currentFile = - (currentNode == null) ? - null : currentNode.getJpaFile(); - - if (newFile.equals(currentFile)) { - viewer.setSelection(new StructuredSelection(newNode), true); - } - else if (currentFile != null && newFile.getContentId().equals(currentFile.getContentId())) { - viewer.setInput(newFile.getContent()); - viewer.setSelection(new StructuredSelection(newNode), true); - } - else { - // new content type - // replace composite and set selection of tree - IJpaStructureProvider provider = getStructureProvider(newNode); - - if (provider == null) { - clearViewer(); - } - else { - viewer.setContentProvider(provider.buildContentProvider()); - viewer.setLabelProvider(provider.buildLabelProvider()); - viewer.setInput(newFile.getContent()); - } - } - } - - private void clearViewer() { - viewer.setContentProvider(NullTreeContentProvider.INSTANCE); - viewer.setLabelProvider(NullLabelProvider.INSTANCE); - viewer.setInput(null); - } - - private IJpaStructureProvider getStructureProvider(IJpaContentNode contentNode) { - String contentId = contentNode.getJpaFile().getContentId(); - IJpaStructureProvider provider = - (IJpaStructureProvider) structureProviders.get(contentId); - - if (provider == null) { - String platformId = contentNode.jpaPlatform().getId(); - IJpaPlatformUi jpaPlatformUI = PlatformRegistry.instance().jpaPlatform(platformId); - provider = jpaPlatformUI.structureProvider(contentId); - - //TODO this view and the detailsProviders Map is not created on a per project basis. - //the detailsProviders and their fileContentTypes could overlap across project, this would cause problems with storing this map. - if (provider != null) { - structureProviders.put(contentId, provider); - } - } - - return provider; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java new file mode 100644 index 0000000000..97a0590156 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java @@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.views.structure; + +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.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.ITreeSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; +import org.eclipse.jpt.ui.internal.jface.NullLabelProvider; +import org.eclipse.jpt.ui.internal.jface.NullTreeContentProvider; +import org.eclipse.jpt.ui.internal.selection.IJpaSelection; +import org.eclipse.jpt.ui.internal.selection.JpaSelection; +import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; +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.IWorkbenchPart; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.part.Page; + +public class JpaStructurePage extends Page + implements ISelectionProvider, ISelectionChangedListener +{ + private IJpaStructureProvider structureProvider; + + private ListenerList selectionChangedListeners; + + private Composite control; + + private TreeViewer viewer; + + private IWorkbenchPart workbenchPart; + + public JpaStructurePage(IWorkbenchPart part, IJpaStructureProvider structureProvider) { + this.workbenchPart = part; + this.structureProvider = structureProvider; + this.selectionChangedListeners = new ListenerList(); + } + + @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 contentAndLabelProvider + = new DelegatingTreeContentAndLabelProvider( + structureProvider.treeItemContentProviderFactory(), + structureProvider.itemLabelProviderFactory()); + viewer.setContentProvider(contentAndLabelProvider); + // TODO Use problem decorator + viewer.setLabelProvider(contentAndLabelProvider); + viewer.setInput(structureProvider.getInput()); + viewer.addSelectionChangedListener(this); + initContextMenu(); + } + + @Override + public void dispose() { + viewer.removeSelectionChangedListener(this); + structureProvider.dispose(); + super.dispose(); + } + + //TODO this isn't really working. our jpa actions appear, but along with a bunch of other actions!! + 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 mgr) { + fillContextMenu(mgr); + } + }); + Menu menu = mgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + workbenchPart.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(IJpaSelection selection) { + // TODO + // // note: checks for null and equals() selection have already been performed + // + // if (selection.equals(IJpaSelection.NULL_SELECTION)) { + // clearViewer(); + // return; + // } + // + // IJpaSelection currentSelection = getSelection(); + // IJpaContentNode newNode = selection.getSelectedNode(); + // IJpaFile newFile = newNode.getJpaFile(); + // IJpaContentNode currentNode = + // (currentSelection == IJpaSelection.NULL_SELECTION) ? + // null : getSelection().getSelectedNode(); + // IJpaFile currentFile = + // (currentNode == null) ? + // null : currentNode.getJpaFile(); + // + // if (newFile.equals(currentFile)) { + // viewer.setSelection(new StructuredSelection(newNode), true); + // } + // else if (currentFile != null && newFile.getContentId().equals(currentFile.getContentId())) { + // viewer.setInput(newFile.getContent()); + // viewer.setSelection(new StructuredSelection(newNode), true); + // } + // else { + // // new content type + // // replace composite and set selection of tree + // IJpaStructureProvider provider = getStructureProvider(newNode); + // + // if (provider == null) { + // clearViewer(); + // } + // else { + // viewer.setContentProvider(provider.buildContentProvider()); + // viewer.setLabelProvider(provider.buildLabelProvider()); + // viewer.setInput(newFile.getContent()); + // } + // } + } + + private void clearViewer() { + viewer.setContentProvider(NullTreeContentProvider.INSTANCE); + viewer.setLabelProvider(NullLabelProvider.INSTANCE); + viewer.setInput(null); + } + + + // **************** ISelectionProvider impl ******************************** + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + selectionChangedListeners.add(listener); + } + + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + selectionChangedListeners.remove(listener); + } + + public IJpaSelection getSelection() { + ITreeSelection viewerSelection = (ITreeSelection) viewer.getSelection(); + + if (viewerSelection.isEmpty() || viewerSelection.size() > 1) { + return IJpaSelection.NULL_SELECTION; + } + else { + return new JpaSelection((IJpaContextNode) viewerSelection.getFirstElement()); + } + } + + public void setSelection(ISelection selection) { + if (viewer != null) { + viewer.setSelection(selection); + } + } + + + + // **************** ISelectionChangedListener impl ************************* + + public void selectionChanged(SelectionChangedEvent event) { + fireSelectionChanged(event.getSelection()); + } + + protected void fireSelectionChanged(ISelection selection) { + // create an event + final SelectionChangedEvent event = + new SelectionChangedEvent(this, selection); + + // fire the event + Object[] listeners = selectionChangedListeners.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); + } + }); + } + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java new file mode 100644 index 0000000000..2859ec9ef4 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Oracle. - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.views.structure; + +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.ui.internal.selection.IJpaSelection; +import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; +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; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +public class JpaStructureView extends PageBookView +{ + private TabbedPropertySheetWidgetFactory widgetFactory = + new TabbedPropertySheetWidgetFactory(); + + + public JpaStructureView() { + super(); + } + + + @Override + protected boolean isImportant(IWorkbenchPart part) { + return part instanceof IEditorPart; + } + + @Override + protected IWorkbenchPart getBootstrapPart() { + IWorkbenchPage page = getSite().getPage(); + if (page != null) { + return page.getActiveEditor(); + } + + return null; + } + + @Override + protected IPage createDefaultPage(PageBook book) { + MessagePage page = new MessagePage(); + initPage(page); + page.createControl(book); + page.setMessage(JptUiMessages.JpaStructureView_structureNotAvailable); + return page; + } + + @Override + protected PageRec doCreatePage(IWorkbenchPart part) { + IJpaStructureProvider structureProvider = + (IJpaStructureProvider) part.getAdapter(IJpaStructureProvider.class); + if (structureProvider != null) { + JpaStructurePage page = new JpaStructurePage(part, structureProvider); + initPage(page); + page.createControl(getPageBook()); + return new PageRec(part, page); + } + return null; + } + + @Override + protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { + JpaStructurePage page = (JpaStructurePage) pageRecord.page; + removeSelectionChangedListener(page); + page.dispose(); + pageRecord.dispose(); + } + + public IJpaSelection getSelection() { + if (getCurrentPage() != getDefaultPage()) { + return ((JpaStructurePage) getCurrentPage()).getSelection(); + } + else { + return IJpaSelection.NULL_SELECTION; + } + } + + public void select(IJpaSelection newSelection) { + // correct page should be shown + if (getCurrentPage() != getDefaultPage()) { + ((JpaStructurePage) getCurrentPage()).select(newSelection); + } + } + + public void addSelectionChangedListener(ISelectionChangedListener listener) { + getSelectionProvider().addSelectionChangedListener(listener); + } + + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + getSelectionProvider().removeSelectionChangedListener(listener); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialog.java new file mode 100644 index 0000000000..57eec4536a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialog.java @@ -0,0 +1,240 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jpt.ui.internal.util.SWTUtil; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.node.Node; +import org.eclipse.swt.SWT; +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.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.help.IWorkbenchHelpSystem; + +/** + * The abstract implementation of a dialog using a "state object" (model object) + * for behavior. + * <p> + * The main pane of this dialog should be extending <code>AbstractDialogPane</code> + * for creating the right type of widgets and it has the "state object" (subject) + * behavior built-in. + * + * @see Node + * @see AbstractDialogPane + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public abstract class AbstractDialog<T extends Node> extends TitleAreaDialog +{ + /** + * The holder of the "state object" used by this dialog. + */ + private WritablePropertyValueModel<T> subjectHolder; + + /** + * Caches the title text until the dialog is created and the dialog's shell + * needs to be configured. + */ + private String title; + + /** + * Creates a new <code>AbstractDialog</code>. + * + * @param parent The parent shell + */ + protected AbstractDialog(Shell parent) { + this(parent, ""); + } + + /** + * Creates a new <code>AbstractDialog</code>. + * + * @param parent The parent shell + * @param title The dialog's title + */ + protected AbstractDialog(Shell parent, String title) { + super(parent); + this.title = title; + initialize(); + } + + protected T buildStateObject() { + return null; + } + + Node.Validator buildValidator() { + return Node.NULL_VALIDATOR; + } + + /** + * {@inheritDoc} + */ + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(title()); + } + + /** + * {@inheritDoc} + */ + @Override + public void create() { + super.create(); + installSubject(); + getButton(OK).setEnabled(false); + } + + /* + * (non-Javadoc) + */ + @Override + protected Control createContents(Composite parent) { + if (hasTitleArea()) { + return super.createContents(parent); + } + + return createDefaultContent(parent); + } + + private Control createDefaultContent(Composite parent) { + + Composite composite = new Composite(parent, 0); + + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + applyDialogFont(composite); + initializeDialogUnits(composite); + this.dialogArea = createDialogArea(composite); + this.buttonBar = createButtonBar(composite); + + return composite; + } + + /* + * (non-Javadoc) + */ + @Override + protected Composite createDialogArea(Composite parent) { + + parent = (Composite) super.createDialogArea(parent); + + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginTop = 0; + layout.marginLeft = 0; + layout.marginBottom = 0; + layout.marginRight = 0; + + Composite dialogPane = new Composite(parent, SWT.NULL); + dialogPane.setLayout(layout); + initializeMainPane(dialogPane); + + return parent; + } + + protected final WritablePropertyValueModel<T> getSubjectHolder() { + return this.subjectHolder; + } + + boolean hasTitleArea() { + return false; + } + + /** + * Returns the helps system. + * + * @return The platform's help system + * + * @category Helper + */ + protected final IWorkbenchHelpSystem helpSystem() { + return PlatformUI.getWorkbench().getHelpSystem(); + } + + /** + * Initializes this dialog. + */ + protected void initialize() { + this.subjectHolder = new SimplePropertyValueModel<T>(); + } + + /** + * The dialog is built when the show() method is called not + * when the Dialog is constructed + */ + protected abstract void initializeMainPane(Composite container); + + private void installSubject() { + + T subject = this.buildStateObject(); + + if (subject != null) { + subject.setValidator(buildValidator()); + } + + this.subjectHolder.setValue(subject); + } + + /** + * Asynchronously launches this dialog in the UI thread. + */ + public final void openDialog() { + SWTUtil.setUserInterfaceActive(false); + SWTUtil.show(this); + } + + /** + * Asynchronously launches this dialog in the UI thread and invoke the given + * <code>PostExecution</code> to perform any post-task. + * + * @param postExecution This interface let the caller to invoke a piece of + * code once the dialog is disposed + */ + public final void openDialog(PostExecution<? extends AbstractDialog<T>> execution) { + SWTUtil.setUserInterfaceActive(false); + SWTUtil.show(this, execution); + } + + /** + * Returns the subject of this dialog. + * + * @return The subject of this dialog or <code>null</code> if no subject was + * used + */ + public T subject() { + return this.subjectHolder.value(); + } + + protected String title() { + return this.title; + } + + public boolean wasCancelled() { + return getReturnCode() == CANCEL; + } + + public boolean wasConfirmed() { + return getReturnCode() == OK; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialogPane.java new file mode 100644 index 0000000000..37a9830592 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialogPane.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.node.Node; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; + +/** + * The abstract pane to use when the pane is shown in an <code>AbstractDialog</code>. + * + * @see AbstractDialog + * + * @version 2.0 + * @since 2.0 + */ +public abstract class AbstractDialogPane<T extends Node> extends AbstractPane<T> { + + /** + * Creates a new <code>AbstractDialog</code>. + * + * @param parentPane The parent controller of this one + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractDialogPane(AbstractDialogPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>AbstractDialogPane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + * + * @category Constructor + */ + protected AbstractDialogPane(AbstractDialogPane<? extends T> parentPane, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentPane, parent, automaticallyAlignWidgets); + } + + /** + * Creates a new <code>AbstractDialogPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractDialogPane(AbstractDialogPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + /** + * Creates a new <code>AbstractDialogPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + * + * @category Constructor + */ + protected AbstractDialogPane(AbstractDialogPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentPane, subjectHolder, parent, automaticallyAlignWidgets); + } + + /** + * Creates a new <code>AbstractDialogPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractDialogPane(PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + super(subjectHolder, parent, WidgetFactory.instance()); + } + + private static class WidgetFactory implements IWidgetFactory { + + private static final IWidgetFactory INSTANCE = new WidgetFactory(); + + static IWidgetFactory instance() { + return INSTANCE; + } + + public Button createButton(Composite parent, String text, int style) { + Button button = new Button(parent, style); + button.setText(text); + return button; + } + + public CCombo createCombo(Composite parent) { + return new CCombo(parent, SWT.NULL); + } + + public Composite createComposite(Composite parent) { + return new Composite(parent, SWT.NULL); + } + + public Group createGroup(Composite parent, String title) { + Group group = new Group(parent, SWT.NULL); + group.setText(title); + return group; + } + + public Hyperlink createHyperlink(Composite parent, String text) { + Hyperlink hyperlink = new Hyperlink(parent, SWT.NULL); + hyperlink.setText(text); + return hyperlink; + } + + public Label createLabel(Composite container, String labelText) { + Label label = new Label(container, SWT.NULL); + label.setText(labelText); + return label; + } + + public List createList(Composite container, int style) { + return new List(container, style); + } + + public Section createSection(Composite parent, int style) { + return new Section(parent, style); + } + + public Text createText(Composite parent) { + return new Text(parent, SWT.NULL); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractFormPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractFormPane.java new file mode 100644 index 0000000000..bc8f01d9de --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractFormPane.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +/** + * The abstract pane to use when the pane is shown using the form look and feel, + * which is handled by <code>TabbedPropertySheetWidgetFactory</code>. + * + * @see TabbedPropertySheetWidgetFactory + * + * @version 2.0 + * @since 2.0 + */ +public abstract class AbstractFormPane<T extends Model> extends AbstractPane<T> +{ + /** + * Creates a new <code>BaseJpaController</code>. + * + * @param parentPane The parent controller of this one + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractFormPane(AbstractFormPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>AbstractFormPane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + * + * @category Constructor + */ + protected AbstractFormPane(AbstractFormPane<? extends T> parentPane, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentPane, parent, automaticallyAlignWidgets); + } + + /** + * Creates a new <code>AbstractFormPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractFormPane(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + /** + * Creates a new <code>AbstractFormPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent controller; + * <code>false</code> to not align them + * + * @category Constructor + */ + protected AbstractFormPane(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + boolean automaticallyAlignWidgets) { + + super(parentPane, subjectHolder, parent, automaticallyAlignWidgets); + } + + /** + * Creates a new <code>AbstractFormPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + * + * @category Constructor + */ + protected AbstractFormPane(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /** + * Creates a new <code>AbstractFormPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + * + * @category Constructor + */ + protected AbstractFormPane(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + this(subjectHolder, parent, new WidgetFactory(widgetFactory)); + } + + /** + * Returns + * + * @return + */ + protected final TabbedPropertySheetWidgetFactory getFormWidgetFactory() { + WidgetFactory widgetFactory = (WidgetFactory) getWidgetFactory(); + return widgetFactory.widgetFactory; + } + + private static class WidgetFactory implements IWidgetFactory { + + private final TabbedPropertySheetWidgetFactory widgetFactory; + + public WidgetFactory(TabbedPropertySheetWidgetFactory widgetFactory) { + super(); + this.widgetFactory = widgetFactory; + } + + public Button createButton(Composite parent, String text, int style) { + return widgetFactory.createButton(parent, text, style); + } + + public CCombo createCombo(Composite parent) { + return widgetFactory.createCCombo(parent, SWT.FLAT); + } + + public Composite createComposite(Composite parent) { + return widgetFactory.createComposite(parent); + } + + public Group createGroup(Composite parent, String title) { + return widgetFactory.createGroup(parent, title); + } + + public Hyperlink createHyperlink(Composite parent, String text) { + return widgetFactory.createHyperlink(parent, text, SWT.FLAT); + } + + public Label createLabel(Composite container, String labelText) { + return widgetFactory.createLabel(container, labelText); + } + + public List createList(Composite container, int style) { + return widgetFactory.createList(container, style | SWT.FLAT); + } + + public Section createSection(Composite parent, int style) { + return widgetFactory.createSection(parent, style | SWT.FLAT); + } + + public Text createText(Composite parent) { + return widgetFactory.createText(parent, null); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java new file mode 100644 index 0000000000..bd6f372460 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java @@ -0,0 +1,2108 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import java.util.ArrayList; +import java.util.Collection; +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.IBaseLabelProvider; +import org.eclipse.jpt.ui.internal.Tracing; +import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; +import org.eclipse.jpt.ui.internal.swt.BooleanButtonModelAdapter; +import org.eclipse.jpt.ui.internal.swt.TriStateBooleanButtonModelAdapter; +import org.eclipse.jpt.ui.internal.util.ControlAligner; +import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; +import org.eclipse.jpt.ui.internal.util.LabeledTableItem; +import org.eclipse.jpt.ui.internal.util.SWTUtil; +import org.eclipse.jpt.utility.internal.ClassTools; +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.help.IWorkbenchHelpSystem; + +/** + * The abstract definition of a pane which holds onto a <code>PropertyValueModel</code> + * that contains the subject of this pane. + * <p> + * It also contains convenience methods for building buttons, labels, check + * boxes, and radio buttons, etc. + * <p> + * It is possible to easily listen to any property changes coming from the + * subject, {@link #addPropertyNames(Collection)} is specify which properties + * are of interest and {@link #propertyChanged(String)} is used to notify the + * pane when the property has changed. + * + * @see AbstractFormPane + * @see AbstractDialogPane + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public abstract class AbstractPane<T extends Model> +{ + /** + * The listener registered with the subject in order to be notified when a + * property has changed, the property names are determined by + * {@link #propertyNames()}. + */ + private PropertyChangeListener aspectChangeListener; + + /** + * The container of this composite. + */ + private Composite container; + + /** + * The aligner responsible to align the left controls. + */ + private ControlAligner leftControlAligner; + + /** + * Flag used to stop the circular population of widgets. + */ + private boolean populating; + + /** + * The aligner responsible to align the left controls. + */ + private ControlAligner rightControlAligner; + + /** + * This listener is registered with the subject holder in order to + * automatically repopulate this pane with the new subject. + */ + private PropertyChangeListener subjectChangeListener; + + /** + * The subject of this pane. + */ + private PropertyValueModel<T> subjectHolder; + + /** + * The collection of registered sub-panes will be automatically notified + * when listeners need to be engaged or disengaged or when to populate its + * widgets. + */ + private Collection<AbstractPane<?>> subPanes; + + /** + * The factory used to create various common widgets. + */ + private IWidgetFactory widgetFactory; + + /** + * Creates a new <code>AbstractSubjectPane</code>. + * + * @category Constructor + */ + @SuppressWarnings("unused") + private AbstractPane() { + super(); + } + + /** + * Creates a new <code>AbstractSubjectPane</code>. + * + * @param parentPane The parent pane of this one + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractPane(AbstractPane<? extends T> parentPane, + Composite parent) { + + this(parentPane, parent, true); + } + + /** + * Creates a new <code>AbstractSubjectPane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent pane; + * <code>false</code> to not align them + * + * @category Constructor + */ + protected AbstractPane(AbstractPane<? extends T> parentPane, + Composite parent, + boolean automaticallyAlignWidgets) { + + this(parentPane, + parentPane.getSubjectHolder(), + parent, + automaticallyAlignWidgets); + } + + /** + * Creates a new <code>AbstractSubjectPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * + * @category Constructor + */ + protected AbstractPane(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + this(parentPane, subjectHolder, parent, true); + } + + /** + * Creates a new <code>AbstractSubjectPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent pane; + * <code>false</code> to not align them + * + * @category Constructor + */ + protected AbstractPane(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + boolean automaticallyAlignWidgets) { + + this(subjectHolder, + parent, + parentPane.getWidgetFactory()); + + initialize(parentPane, automaticallyAlignWidgets); + } + + /** + * Creates a new <code>AbstractSubjectPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + * + * @category Constructor + */ + protected AbstractPane(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(); + + this.initialize(subjectHolder, widgetFactory); + + try { + this.populating = true; + + this.container = this.buildContainer(parent); + this.initializeLayout(this.container); + } + finally { + this.populating = false; + } + } + + /** + * Adds the given pane's widgets (those that were registered with its + * left <code>ControlAligner</code>) to this pane's left + * <code>ControlAligner</code> so that their width can be adjusted to have + * the width of the widest widget. + * + * @param pane The pane containing the widgets to add + * + * @category Layout + */ + protected final void addAlignLeft(AbstractPane<?> container) { + this.leftControlAligner.add(container.leftControlAligner); + } + + /** + * Adds the given control to the collection of widgets that have their width + * adjust with the width of the widest widget. The left alignment is usually + * used for labels. + * + * @param pane The pane to add + * + * @category Layout + */ + protected final void addAlignLeft(Control control) { + this.leftControlAligner.add(control); + } + + /** + * Adds the given pane's widgets (those that were registered with its + * right <code>ControlAligner</code>) to this pane's right + * <code>ControlAligner</code> so that their width can be adjusted to have + * the width of the widest widget. + * + * @param pane The pane containing the widgets to add + * + * @category Layout + */ + protected final void addAlignRight(AbstractPane<?> container) { + this.rightControlAligner.add(container.rightControlAligner); + } + + /** + * Adds the given control to the collection of widgets that have their width + * adjust with the width of the widest widget. The left alignment is usually + * used for buttons. + * + * @param pane The pane to add + * + * @category Layout + */ + protected final void addAlignRight(Control control) { + this.rightControlAligner.add(control); + } + + /** + * Adds the given pane's controls (those that were registered for + * alignment) from this pane. + * + * @param pane The pane containing the widgets to add for + * alignment + * + * @category Layout + */ + protected final void addPaneForAlignment(AbstractPane<?> container) { + addAlignLeft(container); + addAlignRight(container); + } + + /** + * Adds any property names to the given collection in order to be notified + * when the actual property changes in the subject. + * + * @param propertyNames The collection of property names to register with the + * subject + */ + protected void addPropertyNames(Collection<String> propertyNames) { + } + + private PropertyChangeListener buildAspectChangeListener() { + return new SWTPropertyChangeListenerWrapper(buildAspectChangeListener_()); + } + + private PropertyChangeListener buildAspectChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + updatePane(e.propertyName()); + } + }; + } + + /** + * Creates a new button using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param buttonAction The action to be invoked when the button is pressed + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildButton(Composite container, + String text, + final Runnable buttonAction) { + + return this.buildButton(container, text, null, buttonAction); + } + + /** + * Creates a new button using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param helpId The topic help ID to be registered for the new check box + * @param buttonAction The action to be invoked when the button is pressed + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildButton(Composite container, + String text, + String helpId, + final Runnable buttonAction) { + + Button button = this.widgetFactory.createButton(container, text, SWT.NULL); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + SWTUtil.asyncExec(buttonAction); + } + }); + + if (helpId != null) { + helpSystem().setHelp(button, helpId); + } + + return button; + } + + /** + * Creates a new check box using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param booleanHolder The holder of the selection state + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildCheckBox(Composite parent, + String buttonText, + WritablePropertyValueModel<Boolean> booleanHolder) { + + return this.buildCheckBox(parent, buttonText, booleanHolder, null); + } + + /** + * Creates a new check box using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param booleanHolder The holder of the selection state + * @param helpId The topic help ID to be registered for the new check box + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildCheckBox(Composite parent, + String buttonText, + WritablePropertyValueModel<Boolean> booleanHolder, + String helpId) { + + return this.buildToggleButton( + parent, + buttonText, + booleanHolder, + helpId, + SWT.CHECK + ); + } + + /** + * Creates a new flat-style combo. + * + * @param container The parent container + * @return The newly created <code>Combo</code> + * + * @category Layout + */ + protected final CCombo buildCombo(Composite container) { + + container = this.fixBorderNotPainted(container); + CCombo combo = this.widgetFactory.createCombo(container); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + combo.setLayoutData(gridData); + + return combo; + } + + /** + * Creates a new flat-style <code>ComboViewer</code>. + * + * @param container The parent container + * @param labelProvider The provider responsible to convert the combo's items + * into human readable strings + * @return The newly created <code>ComboViewer</code> + * + * @category Layout + */ + protected final ComboViewer buildComboViewer(Composite container, + IBaseLabelProvider labelProvider) { + + CCombo combo = this.buildCombo(container); + ComboViewer viewer = new ComboViewer(combo); + viewer.setLabelProvider(labelProvider); + return viewer; + } + + protected Composite buildContainer(Composite parent) { + Composite container = this.buildPane(parent); + + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginTop = 0; + layout.marginLeft = 0; + layout.marginBottom = 0; + layout.marginRight = 0; + container.setLayout(layout); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + container.setLayoutData(gridData); + + return container; + } + + private PropertyChangeListener buildExpandedStateChangeListener(final Section section) { + return new SWTPropertyChangeListenerWrapper(buildExpandedStateChangeListener_(section)); + } + + private PropertyChangeListener buildExpandedStateChangeListener_(final Section section) { + return new PropertyChangeListener() { + public void propertyChanged(final PropertyChangeEvent e) { + Boolean value = (Boolean) e.newValue(); + if (value == null) { + value = Boolean.TRUE; + } + section.setExpanded(value); + } + }; + } + + /** + * Creates a new <code>Hyperlink</code> that will invoked the given + * <code>Runnable</code> when selected. The given action is always invoked + * from the UI thread. + * + * @param parent The parent container + * @param text The hyperlink's text + * @param hyperLinkAction The action to be invoked when the link was selected + * return The newly created <code>Hyperlink</code> + */ + protected final Hyperlink buildHyperLink(Composite parent, + String text, + final Runnable hyperLinkAction) { + + Hyperlink link = this.widgetFactory.createHyperlink(parent, text); + link.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + SWTUtil.asyncExec(hyperLinkAction); + } + }); + return link; + } + + /** + * Creates a new lable using the given information. + * + * @param parent The parent container + * @param labelText The label's text + * + * @category Layout + */ + protected final Label buildLabel(Composite container, + String labelText) { + + return this.widgetFactory.createLabel(container, labelText); + } + + /** + * Creates a new container that will have the given center control labeled + * with the given label. + * + * @param container The parent container + * @param leftControl The widget shown to the left of the main widget + * @param centerControl The main widget + * @param rightControl The control shown to the right of the main widget + * @param helpId The topic help ID to be registered for the given center + * compositer + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + Control leftControl, + Control centerControl, + Control rightControl, + String helpId) { + + // Container for the label and main composite + container = this.buildSubPane(container, 3, 5, 0, 0, 0); + + // Left control + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.BEGINNING; + gridData.grabExcessHorizontalSpace = false; + leftControl.setLayoutData(gridData); + + // Re-parent the left control to the new sub pane + leftControl.setParent(container); + this.leftControlAligner.add(leftControl); + + // Center control + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + centerControl.setLayoutData(gridData); + + // Re-parent the center control to the new sub pane + centerControl.setParent(container); + + // Register the help id for the center control + if (helpId != null) { + helpSystem().setHelp(centerControl, helpId); + } + + // Right control + if (rightControl == null) { + // TODO: Find a way to create a spacer that doesn't always + // have a size of (64, 64) (I tried with Composite and Canvas) ~PF + } + else { + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL_HORIZONTAL; + gridData.grabExcessHorizontalSpace = false; + + rightControl.setLayoutData(gridData); + rightControl.setParent(container); + + // Re-parent the right control to the new sub pane + this.rightControlAligner.add(rightControl); + + // Register the help id for the right control + if (helpId != null) { + helpSystem().setHelp(rightControl, helpId); + } + } + + return container; + } + + /** + * Creates a new container that will have the given center control labeled + * with the given label. + * + * @param container The parent container + * @param label The label used to describe the center control + * @param centerControl The main widget + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + Label label, + Control centerControl) { + + return this.buildLabeledComposite( + container, + label, + centerControl, + null + ); + } + + /** + * Creates a new container that will have the given center control labeled + * with the given label. + * + * @param container The parent container + * @param label The label used to describe the center control + * @param centerControl The main widget + * @param helpId The topic help ID to be registered for the given center + * control + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + Label label, + Control centerControl, + String helpId) { + + return this.buildLabeledComposite( + container, + label, + centerControl, + null, + helpId + ); + } + + /** + * Creates a new container that will have the given center composite labeled + * with the given label text. + * + * @param container The parent container + * @param labelText The text to label the main composite + * @param centerControl The main widget + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + String labelText, + Control centerControl) { + + + return this.buildLabeledComposite( + container, + labelText, + centerControl, + null, + null + ); + } + + /** + * Creates a new container that will have the given center composite labeled + * with the given label text. + * + * @param container The parent container + * @param labelText The text to label the main composite + * @param centerControl The main widget + * @param rightControl The control shown to the right of the main widget + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + String labelText, + Control centerControl, + Control rightControl) { + + + return this.buildLabeledComposite( + container, + labelText, + centerControl, + rightControl, + null + ); + } + + /** + * Creates a new container that will have the given center composite labeled + * with the given label text. + * + * @param container The parent container + * @param labelText The text to label the main composite + * @param centerControl The main widget + * @param rightControl The control shown to the right of the main widget + * @param helpId The topic help ID to be registered for the given center + * compositer + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + String labelText, + Control centerControl, + Control rightCentrol, + String helpId) { + + Label label = this.buildLabel(container, labelText); + + return this.buildLabeledComposite( + container, + label, + centerControl, + rightCentrol, + helpId + ); + } + + /** + * Creates a new container that will have the given center composite labeled + * with the given label text. + * + * @param container The parent container + * @param labelText The text to label the main composite + * @param centerControl The main widget + * @param helpId The topic help ID to be registered for the given center + * compositer + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledComposite(Composite container, + String labelText, + Control centerControl, + String helpId) { + + Label label = this.buildLabel(container, labelText); + + return this.buildLabeledComposite( + container, + label, + centerControl, + helpId + ); + } + + /** + * Creates a new container that will have a <code>Text</code> widget labeled + * with the given label text. + * + * @param container The parent container + * @param labelText The text to label the text field + * @return The container of the label and the given center control + * + * @category Layout + */ + protected final Composite buildLabeledText(Composite container, + String labelText) { + + return this.buildLabeledComposite( + container, + labelText, + this.buildText(container) + ); + } + + /** + * Creates a new list and notify the given selection holder when the + * selection changes. If the selection count is different than one than the + * holder will receive <code>null</code>. + * + * @param container The parent container + * @return The newly created <code>List</code> + * + * @category Layout + */ + protected final List buildList(Composite container) { + + return this.buildList(container, (String) null); + } + + /** + * Creates a new list and notify the given selection holder when the + * selection changes. If the selection count is different than one than the + * holder will receive <code>null</code>. + * + * @param container The parent container + * @param helpId The topic help ID to be registered for the new radio button + * @return The newly created <code>List</code> + * + * @category Layout + */ + protected final List buildList(Composite container, String helpId) { + + return this.buildList( + container, + new SimplePropertyValueModel<String>(), + helpId + ); + } + + /** + * Creates a new list and notify the given selection holder when the + * selection changes. If the selection count is different than one than the + * holder will receive <code>null</code>. + * + * @param container The parent container + * @param selectionHolder The holder of the unique selected item + * @return The newly created <code>List</code> + * + * @category Layout + */ + protected final List buildList(Composite container, + WritablePropertyValueModel<String> selectionHolder) { + + return this.buildList(container, selectionHolder, null); + } + + /** + * Creates a new list and notify the given selection holder when the + * selection changes. If the selection count is different than one than the + * holder will receive <code>null</code>. + * + * @param container The parent container + * @param selectionHolder The holder of the unique selected item + * @param helpId The topic help ID to be registered for the new radio button + * @return The newly created <code>List</code> + * + * @category Layout + */ + protected final List buildList(Composite container, + WritablePropertyValueModel<String> selectionHolder, + String helpId) { + + List list = this.widgetFactory.createList( + container, + SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI + ); + + list.addSelectionListener(buildSelectionListener(selectionHolder)); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + list.setLayoutData(gridData); + + if (helpId != null) { + helpSystem().setHelp(list, helpId); + } + + return list; + } + + /** + * Creates a new container without specifying any layout manager. + * + * @param container The parent of the new container + * @return The newly created <code>Composite</code> + * + * @category Layout + */ + protected final Composite buildPane(Composite parent) { + return this.widgetFactory.createComposite(parent); + } + + /** + * Creates a new container using the given layout manager. + * + * @param parent The parent of the new container + * @param layout The layout manager of the new container + * @return The newly created container + * + * @category Layout + */ + protected final Composite buildPane(Composite parent, Layout layout) { + + Composite container = this.widgetFactory.createComposite(parent); + container.setLayout(layout); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + container.setLayoutData(gridData); + + return container; + } + + /** + * Creates a new push button using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param buttonAction The action to be invoked when the button is pressed + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildPushButton(Composite parent, + String buttonText, + final Runnable buttonAction) { + + return this.buildPushButton(parent, buttonText, null, buttonAction); + } + + /** + * Creates a new push button using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param buttonAction The action to be invoked when the button is pressed + * @param helpId The topic help ID to be registered for the new radio button + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildPushButton(Composite parent, + String buttonText, + String helpId, + final Runnable buttonAction) { + + Button button = this.widgetFactory.createButton( + parent, + buttonText, + SWT.PUSH + ); + + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + SWTUtil.asyncExec(buttonAction); + } + }); + + button.setLayoutData(new GridData()); + + if (helpId != null) { + helpSystem().setHelp(button, helpId); + } + + return button; + } + + /** + * Creates a new radio button using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param booleanHolder The holder of the selection state + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildRadioButton(Composite parent, + String buttonText, + WritablePropertyValueModel<Boolean> booleanHolder) { + + return this.buildRadioButton(parent, buttonText, booleanHolder, null); + } + + /** + * Creates a new check box using the given information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param booleanHolder The holder of the selection state + * @param helpId The topic help ID to be registered for the new radio button + * @return The newly created <code>Button</code> + * + * @category Layout + */ + protected final Button buildRadioButton(Composite parent, + String buttonText, + WritablePropertyValueModel<Boolean> booleanHolder, + String helpId) { + + return this.buildToggleButton( + parent, + buttonText, + booleanHolder, + helpId, + SWT.RADIO + ); + } + + /** + * Creates a new <code>Section</code> with flat style. A sub-pane is + * automatically added as its client and is the returned <code>Composite</code>. + * + * @param container The container of the new widget + * @param sectionText The text of the new section + * @return The <code>Section</code>'s sub-pane + * + * @category Layout + */ + protected final Composite buildSection(Composite container, + String sectionText) { + + return this.buildSection( + container, + sectionText, + ExpandableComposite.TITLE_BAR + ); + } + + /** + * Creates a new <code>Section</code> with flat style. A sub-pane is + * automatically added as its client and is the returned <code>Composite</code>. + * + * @param container The container of the new widget + * @param sectionText The text of the new section + * @param type The type of section to create + * @return The <code>Section</code>'s sub-pane + * + * @category Layout + */ + private Composite buildSection(Composite container, + String sectionText, + int type) { + + return this.buildSection( + container, + sectionText, + type, + new SimplePropertyValueModel<Boolean>(Boolean.TRUE) + ); + } + + /** + * Creates a new <code>Section</code> with flat style. A sub-pane is + * automatically added as its client and is the returned <code>Composite</code>. + * + * @param container The container of the new widget + * @param sectionText The text of the new section + * @param type The type of section to create + * @param expandedStateHolder The holder of the boolean that will dictate + * when to expand or collapse the section + * @return The <code>Section</code>'s sub-pane + * + * @category Layout + */ + private Composite buildSection(Composite container, + String sectionText, + int type, + PropertyValueModel<Boolean> expandedStateHolder) { + + Section section = this.widgetFactory.createSection( + container, + ExpandableComposite.TWISTIE | type + ); + + section.setText(sectionText); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + section.setLayoutData(gridData); + + Composite subPane = this.buildSubPane(section, 5, 0); + section.setClient(subPane); + + expandedStateHolder.addPropertyChangeListener( + PropertyValueModel.VALUE, + buildExpandedStateChangeListener(section) + ); + + section.setExpanded( + expandedStateHolder.value() != null ? expandedStateHolder.value() : true + ); + + return subPane; + } + + /** + * Creates a new <code>Section</code> with flat style. A sub-pane is + * automatically added as its client and is the returned <code>Composite</code>. + * + * @param container The container of the new widget + * @param sectionText The text of the new section + * @param expandedStateHolder The holder of the boolean that will dictate + * when to expand or collapse the section + * @return The <code>Section</code>'s sub-pane + * + * @category Layout + */ + protected final Composite buildSection(Composite container, + String sectionText, + PropertyValueModel<Boolean> expandedStateHolder) { + + return this.buildSection( + container, + sectionText, + ExpandableComposite.TITLE_BAR, + expandedStateHolder + ); + } + + private SelectionListener buildSelectionListener(final WritablePropertyValueModel<String> selectionHolder) { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + List list = (List) e.widget; + String[] selectedItems = list.getSelection(); + if ((selectedItems == null) || (selectedItems.length != 1)) { + selectionHolder.setValue(null); + } + else { + selectionHolder.setValue(selectedItems[0]); + } + } + }; + } + + private PropertyChangeListener buildSubjectChangeListener() { + return new SWTPropertyChangeListenerWrapper(this.buildSubjectChangeListener_()); + } + + private PropertyChangeListener buildSubjectChangeListener_() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + AbstractPane.this.subjectChanged(e); + } + }; + } + + /** + * Creates a new <code>Composite</code> used as a sub-pane. + * + * @param container The parent container + * @return The newly created <code>Composite</code> used as a sub-pane + * + * @category Layout + */ + protected final Composite buildSubPane(Composite container) { + return this.buildSubPane(container, 0); + } + + /** + * Creates a new <code>Composite</code> used as a sub-pane. + * + * @param container The parent container + * @param topMargin The extra spacing to add at the top of the pane + * @return The newly created <code>Composite</code> used as a sub-pane + * + * @category Layout + */ + protected final Composite buildSubPane(Composite container, int topMargin) { + return this.buildSubPane(container, topMargin, 0); + } + + /** + * Creates a new <code>Composite</code> used as a sub-pane. + * + * @param container The parent container + * @param topMargin The extra spacing to add at the top of the pane + * @param leftMargin The extra spacing to add to the left of the pane + * @return The newly created <code>Composite</code> used as a sub-pane + * + * @category Layout + */ + protected final Composite buildSubPane(Composite container, + int topMargin, + int leftMargin) { + + return this.buildSubPane(container, topMargin, leftMargin, 0, 0); + } + + /** + * Creates a new <code>Composite</code> used as a sub-pane, the new widget + * will have its layout and layout data already initialized, the layout will + * be a <code>GridLayout</code> with 1 column. + * + * @param container The parent container + * @param topMargin The extra spacing to add at the top of the pane + * @param leftMargin The extra spacing to add to the left of the pane + * @param bottomMargin The extra spacing to add at the bottom of the pane + * @param rightMargin The extra spacing to add to the right of the pane + * @return The newly created <code>Composite</code> used as a sub-pane + * + * @category Layout + */ + protected final Composite buildSubPane(Composite container, + int topMargin, + int leftMargin, + int bottomMargin, + int rightMargin) { + + return this.buildSubPane( + container, + 1, + topMargin, + leftMargin, + bottomMargin, + rightMargin); + } + + /** + * Creates a new <code>Composite</code> used as a sub-pane, the new widget + * will have its layout and layout data already initialized, the layout will + * be a <code>GridLayout</code> with 1 column. + * + * @param container The parent container + * @param topMargin The extra spacing to add at the top of the pane + * @param leftMargin The extra spacing to add to the left of the pane + * @param bottomMargin The extra spacing to add at the bottom of the pane + * @param rightMargin The extra spacing to add to the right of the pane + * @return The newly created <code>Composite</code> used as a sub-pane + * + * @category Layout + */ + protected final Composite buildSubPane(Composite container, + int columnCount, + int topMargin, + int leftMargin, + int bottomMargin, + int rightMargin) { + + GridLayout layout = new GridLayout(columnCount, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginTop = topMargin; + layout.marginLeft = leftMargin; + layout.marginBottom = bottomMargin; + layout.marginRight = rightMargin; + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + + container = this.buildPane(container, layout); + container.setLayoutData(gridData); + + return container; + } + + /** + * Creates a new <code>Section</code> with flat style. A sub-pane is + * automatically added as its client which can be typed cast directly as a + * <code>Composite</code>. + * + * @param container The container of the new widget + * @param sectionText The text of the new section + * @return The <code>Section</code>'s sub-pane + * + * @category Layout + */ + protected final Composite buildSubSection(Composite container, + String sectionText) { + + return this.buildSubSection( + container, + sectionText, + new SimplePropertyValueModel<Boolean>(Boolean.TRUE) + ); + } + + /** + * Creates a new <code>Section</code> with flat style. A sub-pane is + * automatically added as its client which can be typed cast directly as a + * <code>Composite</code>. + * + * @param container The container of the new widget + * @param sectionText The text of the new section + * @param expandedStateHolder The holder of the boolean that will dictate + * when to expand or collapse the section + * @return The <code>Section</code>'s sub-pane + * + * @category Layout + */ + protected final Composite buildSubSection(Composite container, + String sectionText, + PropertyValueModel<Boolean> expandedStateHolder) { + + return this.buildSection( + container, + sectionText, + SWT.NULL, + expandedStateHolder + ); + } + + /** + * Creates a new <code>Text</code> widget, the widget is created with the + * flat-style look. + * + * @param container The parent container + * @return The newly created <code>Text</code> widget + * + * @category Layout + */ + protected final Text buildText(Composite container) { + return this.widgetFactory.createText(container); + } + + /** + * Creates a new <code>Text</code> widget, the widget is created with the + * flat-style look. + * + * @param container The parent container + * @param helpId The topic help ID to be registered for the new text + * @return The newly created <code>Text</code> widget + * + * @category Layout + */ + protected final Text buildText(Composite container, String helpId) { + Text text = this.widgetFactory.createText(container); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + text.setLayoutData(gridData); + + if (helpId != null) { + helpSystem().setHelp(text, helpId); + } + + return text; + } + + /** + * Creates a new container with a titled border. + * + * @param title The text of the titled border + * @param container The parent container + * @return The newly created <code>Composite</code> with a titled border + * + * @category Layout + */ + protected final Group buildTitledPane(Composite container, String title) { + return this.buildTitledPane(container, title, null); + } + + /** + * Creates a new container with a titled border. + * + * @param title The text of the titled border + * @param container The parent container + * @param helpId The topic help ID to be registered for the new group + * @return The newly created <code>Composite</code> with a titled border + * + * @category Layout + */ + protected final Group buildTitledPane(Composite container, + String title, + String helpId) { + + Group group = this.widgetFactory.createGroup(container, title); + + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginTop = 2; + layout.marginLeft = 5; + layout.marginBottom = 9; + layout.marginRight = 5; + group.setLayout(layout); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.verticalIndent = 0; + group.setLayoutData(gridData); + + if (helpId != null) { + helpSystem().setHelp(group, helpId); + } + + return group; + } + + /** + * Creates a new toggle button (radio button or check box) using the given + * information. + * + * @param parent The parent container + * @param buttonText The button's text + * @param booleanHolder The holder of the selection state + * @param helpId The topic help ID to be registered for the new button + * @return The newly created <code>Button</code> + * + * @category Layout + */ + private Button buildToggleButton(Composite parent, + String buttonText, + WritablePropertyValueModel<Boolean> booleanHolder, + String helpId, + int toggleButtonType) { + + Button button = this.widgetFactory.createButton( + parent, + buttonText, + toggleButtonType + ); + + button.setLayoutData(new GridData()); + BooleanButtonModelAdapter.adapt(booleanHolder, button); + + if (helpId != null) { + helpSystem().setHelp(button, helpId); + } + + return button; + } + + /** + * Creates a new check box that can have 3 selection states (selected, + * unselected and partially selected. + * + * @param parent The parent container + * @param text The button's text + * @param booleanHolder The holder of the boolean value where <code>null</code> + * means partially selected + * @return The newly created <code>TriStateCheckBox</code> + */ + protected final TriStateCheckBox buildTriStateCheckBox(Composite parent, + String text, + WritablePropertyValueModel<Boolean> booleanHolder) { + + return this.buildTriStateCheckBox(parent, text, booleanHolder, null); + } + + /** + * Creates a new check box that can have 3 selection states (selected, + * unselected and partially selected. + * + * @param parent The parent container + * @param text The button's text + * @param booleanHolder The holder of the boolean value where <code>null</code> + * means partially selected + * @param helpId The topic help ID to be registered for the new check box + * @return The newly created <code>TriStateCheckBox</code> + */ + protected final TriStateCheckBox buildTriStateCheckBox(Composite parent, + String text, + WritablePropertyValueModel<Boolean> booleanHolder, + String helpId) { + + TriStateCheckBox checkBox = new TriStateCheckBox(parent); + checkBox.setText(text); + + TriStateBooleanButtonModelAdapter.adapt( + booleanHolder, + checkBox + ); + + if (helpId != null) { + helpSystem().setHelp(checkBox.getControl(), helpId); + } + + return checkBox; + } + + /** + * Creates a new check box that can have 3 selection states (selected, + * unselected and partially selected. + * + * @param parent The parent container + * @param text The button's text + * @param booleanHolder The holder of the boolean value where <code>null</code> + * means partially selected + * @param stringHolder The holder of the string to put in parenthesis after + * the check box's text when it is partially selected + * @return The newly created <code>TriStateCheckBox</code> + */ + protected final TriStateCheckBox buildTriStateCheckBoxWithDefault(Composite parent, + String text, + WritablePropertyValueModel<Boolean> booleanHolder, + PropertyValueModel<String> stringHolder) { + + return this.buildTriStateCheckBoxWithDefault( + parent, + text, + booleanHolder, + stringHolder, + null + ); + } + + /** + * Creates a new check box that can have 3 selection states (selected, + * unselected and partially selected. + * + * @param parent The parent container + * @param text The button's text + * @param booleanHolder The holder of the boolean value where <code>null</code> + * means partially selected + * @param stringHolder The holder of the string to put in parenthesis after + * the check box's text when it is partially selected + * @param helpId The topic help ID to be registered for the new check box + * @return The newly created <code>TriStateCheckBox</code> + */ + protected final TriStateCheckBox buildTriStateCheckBoxWithDefault(Composite parent, + String text, + WritablePropertyValueModel<Boolean> booleanHolder, + PropertyValueModel<String> stringHolder, + String helpId) { + + TriStateCheckBox checkBox = this.buildTriStateCheckBox( + parent, + text, + booleanHolder, + helpId + ); + + new LabeledControlUpdater( + new LabeledTableItem(checkBox.getCheckBox()), + stringHolder + ); + + return checkBox; + } + + /** + * Uninstalls any listeners from the subject in order to stop being notified + * for changes made outside of this panes. + * + * @category Populate + */ + protected void disengageListeners() { + + this.log(" ->disengageListeners()"); + + this.subjectHolder.removePropertyChangeListener( + PropertyValueModel.VALUE, + this.subjectChangeListener + ); + + this.disengageListeners(this.subject()); + + for (AbstractPane<?> subPane : this.subPanes) { + subPane.disengageListeners(); + } + } + + /** + * Removes any property change listeners from the given subject. + * + * @param subject The old subject + * + * @category Populate + */ + protected void disengageListeners(T subject) { + if (subject != null) { +// this.log(" ->disengageListeners() from " + subject); + + for (String propertyName : this.propertyNames()) { + subject.removePropertyChangeListener(propertyName, this.aspectChangeListener); + } + } + } + + /** + * Notifies this pane is should dispose itself. + * + * @category Populate + */ + public final void dispose() { + if (!this.container.isDisposed()) { + this.log("dispose()"); + this.performDispose(); + this.disengageListeners(); + } + } + + /** + * Requests this pane to dispose itself. + * + * @category Populate + */ + protected void doDispose() { + this.log(" ->doDispose()"); + } + + /** + * Requests this pane to populate its widgets with the subject's values. + * + * @category Populate + */ + protected void doPopulate() { + this.log(" ->doPopulate()"); + } + + /** + * Changes the enablement state of the widgets of this pane. + * + * @param enabled <code>true</code> to enable the widgets or <code>false</code> + * to disable them + * + * @category Layout + */ + public void enableWidgets(boolean enabled) { + for (AbstractPane<?> subPane : this.subPanes) { + subPane.enableWidgets(enabled); + } + } + + /** + * Installs the listeners on the subject in order to be notified from changes + * made outside of this panes. + * + * @category Populate + */ + protected void engageListeners() { + + this.log(" ->engageListeners()"); + + this.subjectHolder.addPropertyChangeListener( + PropertyValueModel.VALUE, + this.subjectChangeListener + ); + + this.engageListeners(this.subject()); + + for (AbstractPane<?> subPane : this.subPanes) { + subPane.engageListeners(); + } + } + + /** + * TODO + * + * @param subject + * + * @category Populate + */ + protected void engageListeners(T subject) { + if (subject != null) { + +// this.log(" ->engageListeners() on " + subject); + + for (String propertyName : this.propertyNames()) { + subject.addPropertyChangeListener(propertyName, this.aspectChangeListener); + } + } + } + + /** + * Wraps the given <code>Composite</code> into a new <code>Composite</code> + * in order to have the widgets' border painted. This must be a bug in the + * <code>GridLayout</code> used in a form. + * + * @param container The parent of the sub-pane with 1 pixel border + * @return A new <code>Composite</code> that has the necessary space to paint + * the border + */ + protected final Composite fixBorderNotPainted(Composite container) { + return buildSubPane(container, 1, 1, 1, 1, 1); + } + + /** + * Returns the main <code>Control</code> of this pane. + * + * @return The main container + * + * @category Layout + */ + public Composite getControl() { + return this.container; + } + + /** + * Returns the subject holder used by this pane. + * + * @return The holder of the subject + * + * @category Populate + */ + protected final PropertyValueModel<T> getSubjectHolder() { + return this.subjectHolder; + } + + /** + * Returns + * + * @return + * + * @category Layout + */ + protected final IWidgetFactory getWidgetFactory() { + return this.widgetFactory; + } + + /** + * Returns the margin taken by a group box, which is the number of pixel the + * group box border and its margin takes before displaying its widgets plus + * 5 pixels since the widgets inside of the group box and the border should + * have that extra 5 pixels. + * + * @return The width taken by the group box border with its margin + * + * @category Layout + */ + protected final int groupBoxMargin() { + Group group = this.widgetFactory.createGroup(Display.getCurrent().getActiveShell(), ""); + Rectangle clientArea = group.getClientArea(); + group.dispose(); + return clientArea.x + 5; + } + + /** + * Returns the helps system. + * + * @return The platform's help system + * + * @category Helper + */ + protected final IWorkbenchHelpSystem helpSystem() { + return PlatformUI.getWorkbench().getHelpSystem(); + } + + /** + * Initializes this <code>AbstractSubjectPane</code>. + * + * @category Initialization + */ + protected void initialize() { + } + + /** + * Registers this pane with the parent pane. + * + * @param parentPane The parent pane + * @param automaticallyAlignWidgets <code>true</code> to make the widgets + * this pane aligned with the widgets of the given parent pane; + * <code>false</code> to not align them + * + * @category Initialization + */ + private void initialize(AbstractPane<?> parentPane, + boolean automaticallyAlignWidgets) { + + // Register this pane with the parent pane, it will call the methods + // automatically (engageListeners(), disengageListeners(), populate(), + // dispose(), etc) + parentPane.registerSubPane(this); + + // Align the left and right controls with the controls from the parent + // pane + if (automaticallyAlignWidgets) { + parentPane.leftControlAligner .add(this.leftControlAligner); + parentPane.rightControlAligner.add(this.rightControlAligner); + } + } + + /** + * Initializes this <code>AbstractSubjectPane</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param widgetFactory The factory used to create various widgets + * + * @category Initialization + */ + @SuppressWarnings("unchecked") + private void initialize(PropertyValueModel<? extends T> subjectHolder, + IWidgetFactory widgetFactory) + { + Assert.isNotNull(subjectHolder, "The subject holder cannot be null"); + + this.subjectHolder = (PropertyValueModel<T>) subjectHolder; + this.widgetFactory = widgetFactory; + this.subPanes = new ArrayList<AbstractPane<?>>(); + this.leftControlAligner = new ControlAligner(); + this.rightControlAligner = new ControlAligner(); + this.subjectChangeListener = this.buildSubjectChangeListener(); + this.aspectChangeListener = this.buildAspectChangeListener(); + + this.initialize(); + } + + /** + * Initializes the layout of this pane. + * + * @param container The parent container + * + * @category Layout + */ + protected abstract void initializeLayout(Composite container); + + /** + * Determines whether + * + * @return + * + * @category Populate + */ + protected final boolean isPopulating() { + return this.populating; + } + + /** + * Logs the given message if the <code>Tracing.DEBUG_LAYOUT</code> is enabled. + * + * @param message The logging message + */ + private void log(String message) { + + if (Tracing.booleanDebugOption(Tracing.UI_LAYOUT)) { + + Class<?> thisClass = getClass(); + String className = ClassTools.shortNameFor(thisClass); + + if (thisClass.isAnonymousClass()) { + className = className.substring(0, className.indexOf('$')); + className += "->" + ClassTools.shortNameFor(thisClass.getSuperclass()); + } + + Tracing.log(className + ": " + message); + } + } + + /** + * Notifies this pane is should dispose itself. + * + * @category Populate + */ + protected void performDispose() { + this.log(" ->performDispose()"); + + // Dispose this pane + doDispose(); + + // Ask the sub-panes to perform the dispose themselves + for (AbstractPane<?> subPane : this.subPanes) { + subPane.performDispose(); + } + } + + /** + * Notifies this pane to populate itself using the subject's information. + * + * @category Populate + */ + public final void populate() { + if (!this.container.isDisposed()) { + this.log("populate()"); + this.repopulate(); + this.engageListeners(); + } + } + + /** + * Notifies the subject's property associated with the given property name + * has changed. + * + * @param propertyName The property name associated with the property change + * + * @category Populate + */ + protected void propertyChanged(String propertyName) { + } + + /** + * Returns the list of names to listen for properties changing from the + * subject. + * + * @return A non-<code>null</code> list of property names + * + * @category Populate + */ + protected Collection<String> propertyNames() { + ArrayList<String> propertyNames = new ArrayList<String>(); + addPropertyNames(propertyNames); + return propertyNames; + } + + /** + * Registers another <code>AbstractSubjectPane</code> with this one so it can + * be automatically notified about certain events such as engaging or + * disengaging the listeners, etc. + * + * @param subPane The sub-pane to register + * + * @category Controller + */ + protected final void registerSubPane(AbstractPane<?> subPane) { + this.subPanes.add(subPane); + } + + /** + * Removes the given pane's widgets (those that were registered with + * its left <code>ControlAligner</code>) from this pane's left + * <code>ControlAligner</code> so that their width will no longer be adjusted + * with the width of the widest widget. + * + * @param pane The pane containing the widgets to remove + * + * @category Layout + */ + protected final void removeAlignLeft(AbstractPane<?> pane) { + this.leftControlAligner.remove(pane.leftControlAligner); + } + + /** + * Removes the given control from the collection of widgets that are aligned + * to have the same width when they are shown to the left side of the 3 + * widget colums. + * + * @param pane The pane to remove, its width will no longer be + * ajusted to be the width of the longest widget + * + * @category Layout + */ + protected final void removeAlignLeft(Control control) { + this.leftControlAligner.remove(control); + } + + /** + * Removes the given pane's widgets (those that were registered with + * its right <code>ControlAligner</code>) from this pane's right + * <code>ControlAligner</code> so that their width will no longer be adjusted + * with the width of the widest widget. + * + * @param pane The pane containing the widgets to remove + * + * @category Layout + */ + protected final void removeAlignRight(AbstractPane<?> pane) { + this.rightControlAligner.remove(pane.rightControlAligner); + } + + /** + * Removes the given control from the collection of widgets that are aligned + * to have the same width when they are shown to the right side of the 3 + * widget colums. + * + * @param pane The pane to remove, its width will no longer be + * ajusted to be the width of the longest widget + * + * @category Layout + */ + protected final void removeAlignRight(Control control) { + this.rightControlAligner.remove(control); + } + + /** + * Removes the given pane's controls (those that were registered for + * alignment) from this pane. + * + * @param pane The pane containing the widgets that no longer + * requires their width adjusted with the width of the longest widget + * + * @category Layout + */ + protected final void removePaneForAlignment(AbstractPane<?> pane) { + removeAlignLeft(pane); + removeAlignRight(pane); + } + + /** + * This method is called (perhaps internally) when this needs to repopulate + * but the object of interest has not changed. + * + * @category Populate + */ + protected final void repopulate() { + + this.log(" ->repopulate()"); + + // Populate this pane + try { + setPopulating(true); + doPopulate(); + } + finally { + setPopulating(false); + } + + // Ask the sub-panes to repopulate themselves + for (AbstractPane<?> subPane : this.subPanes) { + subPane.repopulate(); + } + } + + /** + * Determines whether this pane should be repopulate even if the subject if + * <code>null</code>. + * + * @return <code>true</code> is returned by default + */ + protected boolean repopulateWithNullSubject() { + return true; + } + + /** + * Sets (TODO) + * + * @param populating + * + * @category Populate + */ + protected final void setPopulating(boolean populating) { + this.populating = populating; + } + + /** + * Returns the nearest <code>Shell</code> displaying the main widget of this + * pane. + * + * @return The nearest window displaying this pane + */ + protected final Shell shell() { + return this.container.getShell(); + } + + /** + * Returns the subject of this pane. + * + * @return The subject if this pane was not disposed; <code>null</code> + * if it was + * + * @category Populate + */ + protected T subject() { + return this.subjectHolder.value(); + } + + /** + * The subject holder's value changed, disconnects any listeners from the + * old subject and connects those listeners onto the new subject. + * + * @param e The property change containing the old and new subjects + * + * @category Populate + */ + @SuppressWarnings("unchecked") + private void subjectChanged(PropertyChangeEvent e) { + if (!this.container.isDisposed()) { + T oldSubject = (T) e.oldValue(); + T newSubject = (T) e.newValue(); + + this.log("subjectChanged()"); + this.disengageListeners(oldSubject); + + // Only repopulate if it is allowed when the subject is null + if (newSubject != null || + (newSubject == null && repopulateWithNullSubject())) + { + this.repopulate(); + } + + this.engageListeners(newSubject); + } + } + + /** + * Unregisters the given <code>AbstractSubjectPane</code> from this one so it + * can no longer be automatically notified about certain events such as + * engaging or disengaging the listeners, etc. + * + * @param subPane The sub-pane to unregister + * + * @category Controller + */ + protected final void unregisterSubPane(AbstractPane<?> subPane) { + this.subPanes.remove(subPane); + } + + private void updatePane(String propertyName) { + if (!container.isDisposed()) { + populating = true; + try { + propertyChanged(propertyName); + } + finally { + populating = false; + } + } + } + + public static interface IWidgetFactory { + Button createButton(Composite parent, String text, int style); + CCombo createCombo(Composite parent); + Composite createComposite(Composite parent); + Group createGroup(Composite parent, String title); + Hyperlink createHyperlink(Composite parent, String text); + Label createLabel(Composite container, String labelText); + List createList(Composite container, int style); + Section createSection(Composite parent, int style); + Text createText(Composite parent); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractValidatingDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractValidatingDialog.java new file mode 100644 index 0000000000..1ff3f874cd --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractValidatingDialog.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jpt.utility.internal.node.Node; +import org.eclipse.jpt.utility.internal.node.Problem; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Shell; + +/** + * This dialog is similar to it superclass, <code>AbstractDialog</code>, with + * the added value of an error message label below the main panel. A subclass + * can set this error message as needed so that it can inform the user something + * incorrect has been entered. + * <p> + * If there is an error message, it will be shown. If there is a warning + * message, it will only be shown if there is no error message. Warning messages + * have a different icon than error messages. + * + * @version 2.0 + * @since 2.0 + */ +public abstract class AbstractValidatingDialog<T extends Node> extends AbstractDialog<T> { + + /** + * Creates a new <code>AbstractValidatingDialog</code>. + * + * @param parent The parent shell + */ + public AbstractValidatingDialog(Shell parent) { + super(parent); + } + + /** + * Creates a new <code>AbstractValidatingDialog</code>. + * + * @param parent The parent shell + * @param title The dialog's title + */ + public AbstractValidatingDialog(Shell parent, String title) { + super(parent, title); + } + + /* + * (non-Javadoc) + */ + @Override + Node.Validator buildValidator() { + return new Node.Validator() { + public void pause() { + } + + public void resume() { + } + + public void validate() { + AbstractValidatingDialog.this.validate(); + } + }; + } + + protected void clearErrorMessage() { + setErrorMessage(null); + } + + /* + * (non-Javadoc) + */ + @Override + boolean hasTitleArea() { + return true; + } + + /** + * convenience method for simple error message + */ + protected void setErrorMessageKey(String key, Object... argument) { + setErrorMessage(NLS.bind(key, argument)); + } + + /** + * Updates the error message, either shows the first error problem or hides + * the error pane. If the progress bar is shown, then the error message will + * not be shown. + */ + private void updateErrorMessage() { + if (subject().hasBranchProblems()) { + Problem problem = subject().branchProblems().next(); + setErrorMessageKey(problem.messageKey(), problem.messageArguments()); + } + // TODO: It would be nice to add warnings to the model +// else if (this.subject().hasBranchWarnings()) { +// Problem problem = this.subject().branchWarnings().next(); +// this.setWarningMessageKey(problem.getMessageKey(), problem.getMessageArguments()); +// } + else { + clearErrorMessage(); + } + } + + private void validate() { + subject().validateBranch(); + updateErrorMessage(); + getButton(OK).setEnabled(!subject().hasBranchProblems()); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java new file mode 100644 index 0000000000..953248882e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter; +import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter.SelectionChangeEvent; +import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter.SelectionChangeListener; +import org.eclipse.jpt.utility.internal.StringConverter; +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.List; + +/** + * This implementation of the <code>AddRemovePane</code> uses a <code>List</code> + * as its main widget. + * <p> + * Here the layot of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------- ----------- | + * | | Item 1 | | Add... | | + * | | ... | ----------- | + * | | Item n | ----------- | + * | | | | Edit... | | + * | | | ----------- | + * | | | ----------- | + * | | | | Remove | | + * | | | ----------- | + * | ------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @version 2.0 + * @since 1.0 + */ +public class AddRemoveListPane<T extends Model> extends AddRemovePane<T> +{ + /** + * The main widget of this add/remove pane. + */ + private List list; + + /** + * Creates a new <code>AddRemoveListPane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param adapter + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + */ + public AddRemoveListPane(AbstractPane<? extends T> parentPane, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider) { + + super(parentPane, + parent, + adapter, + listHolder, + selectedItemHolder, + labelProvider); + } + + /** + * Creates a new <code>AddRemoveListPane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param adapter + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * @param helpId The topic help ID to be registered with this pane + */ + public AddRemoveListPane(AbstractPane<? extends T> parentPane, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId) { + + super(parentPane, + parent, + adapter, + listHolder, + selectedItemHolder, + labelProvider, + helpId); + } + + /** + * Creates a new <code>AddRemoveListPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject + * @param adapter + * @param parent The parent container + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + */ + public AddRemoveListPane(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider) { + + super(parentPane, + subjectHolder, + parent, + adapter, + listHolder, + selectedItemHolder, + labelProvider); + } + + /** + * Creates a new <code>AddRemoveListPane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject + * @param adapter + * @param parent The parent container + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * @param helpId The topic help ID to be registered with this pane + */ + public AddRemoveListPane(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId) { + + super(parentPane, + subjectHolder, + parent, + adapter, + listHolder, + selectedItemHolder, + labelProvider, + helpId); + } + + private WritablePropertyValueModel<String> buildSelectedItemHolder() { + return new SimplePropertyValueModel<String>(); + } + + private SelectionChangeListener<Object> buildSelectionListener() { + return new SelectionChangeListener<Object>() { + public void selectionChanged(SelectionChangeEvent<Object> e) { + AddRemoveListPane.this.selectionChanged(); + } + }; + } + + private StringConverter<Object> buildStringConverter(final ILabelProvider labelProvider) { + return new StringConverter<Object>() { + public String convertToString(Object item) { + return labelProvider.getText(item); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + @SuppressWarnings("unchecked") + protected void initializeMainComposite(Composite container, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId) { + + list = buildList(container, buildSelectedItemHolder()); + + if (helpId != null) { + helpSystem().setHelp(list, helpId); + } + + ListBoxModelAdapter<Object> listModel = ListBoxModelAdapter.adapt( + (ListValueModel<Object>) listHolder, + new SimplePropertyValueModel<Object>(), + list, + buildStringConverter(labelProvider) + ); + + listModel.addSelectionChangeListener(buildSelectionListener()); + } + + /** + * The selection has changed, update (1) the selected item holder, (2) the + * selection model and (3) the buttons. + */ + private void selectionChanged() { + + WritablePropertyValueModel<Object> selectedItemHolder = getSelectedItemHolder(); + ObjectListSelectionModel selectionModel = getSelectionModel(); + int selectionCount = list.getSelectionCount(); + + if (selectionCount == 0) { + selectedItemHolder.setValue(null); + selectionModel.clearSelection(); + } + else if (selectionCount != 1) { + selectedItemHolder.setValue(null); + selectionModel.clearSelection(); + + for (int index : list.getSelectionIndices()) { + selectionModel.addSelectionInterval(index, index); + } + } + else { + int selectedIndex = list.getSelectionIndex(); + Object selectedItem = getListHolder().get(selectedIndex); + + selectedItemHolder.setValue(selectedItem); + selectionModel.setSelectedValue(selectedItem); + } + + updateButtons(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java new file mode 100644 index 0000000000..3c7f03ecd1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java @@ -0,0 +1,588 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +/** + * The abstract definition of a pane that has add/remove buttons, up/down + * buttons and an option button that is kept in sync with the selected items. + * + * @version 1.0 + * @since 2.0 + */ +public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> +{ + private Adapter adapter; + private Button addButton; + private Composite container; + private ILabelProvider labelProvider; + private ListValueModel<?> listHolder; + private Button optionalButton; + private Button removeButton; + private WritablePropertyValueModel<Object> selectedItemHolder; + private ObjectListSelectionModel selectionModel; + + /** + * Creates a new <code>AddRemovePane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + */ + protected AddRemovePane(AbstractPane<? extends T> parentPane, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider) { + + this(parentPane, + parent, + adapter, + listHolder, + selectedItemHolder, + labelProvider, + null); + } + + /** + * Creates a new <code>AddRemovePane</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * @param helpId The topic help ID to be registered with this pane + */ + protected AddRemovePane(AbstractPane<? extends T> parentPane, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId) { + + super(parentPane, parent); + + initialize( + adapter, + listHolder, + selectedItemHolder, + labelProvider + ); + + initializeLayout( + adapter, + listHolder, + selectedItemHolder, + labelProvider, + helpId + ); + } + + /** + * Creates a new <code>AddRemovePane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param parent The parent container + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + */ + protected AddRemovePane(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider) { + + this(parentPane, + subjectHolder, + parent, + adapter, + listHolder, + selectedItemHolder, + labelProvider, + null); + } + + /** + * Creates a new <code>AddRemovePane</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of the subject + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param parent The parent container + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * @param helpId The topic help ID to be registered with this pane + */ + protected AddRemovePane(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId) { + + super(parentPane, subjectHolder, parent); + + initialize( + adapter, + listHolder, + selectedItemHolder, + labelProvider + ); + + initializeLayout( + adapter, + listHolder, + selectedItemHolder, + labelProvider, + helpId + ); + } + + /** + * @category Add + */ + protected void addItem() { + adapter.addNewItem(selectionModel); + } + + /** + * @category Initialize + */ + protected Adapter buildAdapter() { + return adapter; + } + + /** + * @category Add + */ + protected Button buildAddButton(Composite parent) { + return buildButton( + parent, + adapter.addButtonText(), + buildAddItemAction() + ); + } + + /** + * @category Add + */ + private Runnable buildAddItemAction() { + return new Runnable() { + public void run() { + AddRemovePane.this.addItem(); + } + }; + } + +// private ListChangeListener/*<Object>*/ buildListChangeListener() { +// return new ListChangeAdapter/*<Object>*/() { +// @Override +// public void listChanged(ListChangeEvent/*<Object>*/ e) { +// AddRemovePane.this.updateButtons(); +// } +// }; +// } + + /** + * @category Option + */ + private Runnable buildOptionalAction() { + return new Runnable() { + public void run() { + } + }; + } + + /** + * @category Option + */ + protected Button buildOptionalButton(Composite container) { + return buildButton( + container, + adapter.optionalButtonText(), + buildOptionalAction() + ); + } + + /** + * @category Add + */ + protected Button buildRemoveButton(Composite parent) { + return buildButton( + parent, + adapter.removeButtonText(), + buildRemoveItemsAction() + ); + } + + /** + * @category Remove + */ + private Runnable buildRemoveItemsAction() { + return new Runnable() { + public void run() { + AddRemovePane.this.removeItems(); + } + }; + } + + protected ObjectListSelectionModel buildRowSelectionModel(ListValueModel<?> listModel) { + return new ObjectListSelectionModel(new ListModelAdapter(listModel)); + } + + /* + * (non-Javadoc) + */ + @Override + public void enableWidgets(boolean enabled) { + super.enableWidgets(enabled); + updateButtons(); + } + + protected final Composite getContainer() { + return container; + } + + protected final ILabelProvider getLabelProvider() { + return labelProvider; + } + + protected final ListValueModel<?> getListHolder() { + return listHolder; + } + + protected final WritablePropertyValueModel<Object> getSelectedItemHolder() { + return selectedItemHolder; + } + + public final ObjectListSelectionModel getSelectionModel() { + return selectionModel; + } + + @SuppressWarnings("unchecked") + protected void initialize(Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider) + { + this.listHolder = listHolder; + this.labelProvider = labelProvider; + this.adapter = (adapter == null) ? buildAdapter() : adapter; + this.selectedItemHolder = (WritablePropertyValueModel<Object>) selectedItemHolder; + this.selectionModel = new ObjectListSelectionModel(new ListModelAdapter(listHolder)); + } + + protected void initializeButtonPane(Composite container, String helpId) { + + container = buildPane(container); + + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginTop = 0; + layout.marginLeft = 0; + layout.marginBottom = 0; + layout.marginRight = 0; + container.setLayout(layout); + container.setLayoutData(new GridData()); + + // Add button + addButton = buildAddButton(container); + addAlignRight(addButton); + + // Optional button + if (adapter.hasOptionalButton()) { + optionalButton = buildOptionalButton(container); + addAlignRight(optionalButton); + } + + // Remove button + removeButton = buildRemoveButton(container); + addAlignRight(removeButton); + + // Update the help topic ID + if (helpId != null) { + helpSystem().setHelp(addButton, helpId); + helpSystem().setHelp(removeButton, helpId); + + if (optionalButton != null) { + helpSystem().setHelp(optionalButton, helpId); + } + } + +// upButton = buildUpButton((adapter instanceof UpDownAdapter) ? (UpDownAdapter) adapter : null); +// downButton = buildDownButton((adapter instanceof UpDownAdapter) ? (UpDownAdapter) adapter : null); +// gotoButton = buildGotoButton(); +// component = buildComponent(); + } + + protected void initializeLayout(Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId) { + + initializeMainComposite( + container, + adapter, + listHolder, + selectedItemHolder, + labelProvider, + helpId); + + initializeButtonPane(container, helpId); + enableWidgets(subject() != null); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + this.container = buildSubPane(container, 2, 0, 0, 0, 0); + } + + /** + * Initializes the main widget of this add/remove pane. + * + * @param container The parent container + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * @param helpId The topic help ID to be registered with this pane or + * <code>null</code> if it was not specified + */ + protected abstract void initializeMainComposite(Composite container, + Adapter adapter, + ListValueModel<?> listHolder, + WritablePropertyValueModel<?> selectedItemHolder, + ILabelProvider labelProvider, + String helpId); + + /** + * @category Remove + */ + protected void removeItems() { + adapter.removeSelectedItems(selectionModel); + } + + /** + * @category UpdateButtons + */ + protected void updateAddButton(Button addButton) { + addButton.setEnabled( + getControl().isEnabled() && + (subject() != null) + ); + } + + /** + * @category UpdateButtons + */ + protected void updateButtons() { + if (container.isDisposed()) { + return; + } + + updateAddButton(addButton); + updateRemoveButton(removeButton); + updateOptionalButton(optionalButton); + } + + /** + * @category UpdateButtons + */ + protected void updateOptionalButton(Button optionalButton) { + if (optionalButton != null) { + optionalButton.setEnabled( + getControl().isEnabled() && + adapter.enableOptionOnSelectionChange(selectionModel) + ); + } + } + + /** + * @category UpdateButtons + */ + protected void updateRemoveButton(Button removeButton) { + removeButton.setEnabled( + getControl().isEnabled() && + selectionModel.selectedValue() != null + ); + } + + /** + * An abstract implementation of <code>Adapter</code>. + */ + public static abstract class AbstractAdapter implements Adapter { + + private String addButtonText; + private boolean hasOptionalButton; + private String optionalButtonText; + private String removeButtonText; + + public AbstractAdapter() { + this(JptUiMessages.AddRemovePane_AddButtonText, + JptUiMessages.AddRemovePane_RemoveButtonText); + } + + public AbstractAdapter(boolean hasOptionalButton) { + super(); + this.hasOptionalButton = hasOptionalButton; + } + + public AbstractAdapter(String optionalButtonText) { + this(true); + this.optionalButtonText = optionalButtonText; + } + + public AbstractAdapter(String addButtonText, + String removeButtonText) { + + super(); + this.addButtonText = addButtonText; + this.removeButtonText = removeButtonText; + } + + public AbstractAdapter(String addButtonText, + String removeButtonText, + String optionalButtonText) { + + this(optionalButtonText); + this.addButtonText = addButtonText; + this.removeButtonText = removeButtonText; + } + + public String addButtonText() { + return addButtonText; + } + + public boolean enableOptionOnSelectionChange(ObjectListSelectionModel listSelectionModel) { + return listSelectionModel.selectedValuesSize() == 1; + } + + public boolean hasOptionalButton() { + return hasOptionalButton; + } + + public String optionalButtonText() { + return optionalButtonText; + } + + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + } + + public String removeButtonText() { + return removeButtonText; + } + + public void setAddButtonText(String addButtonText) { + this.addButtonText = addButtonText; + } + + public void setOptionalButtonText(String optionalButtonText) { + this.optionalButtonText = optionalButtonText; + } + + public void setRemoveButtonText(String removeButtonText) { + this.removeButtonText = removeButtonText; + } + } + + /** + * This adapter is used to perform the actual action when adding a new item + * or removing the selected items. It is possible to add an optional button. + */ + public static interface Adapter { + + /** + * + */ + String addButtonText(); + + /** + * Invoked when the user selects the Add button. + */ + void addNewItem(ObjectListSelectionModel listSelectionModel); + + /** + * Invoked when selection changes. Implementation dictates whether button + * should be enabled. + */ + boolean enableOptionOnSelectionChange(ObjectListSelectionModel listSelectionModel); + + /** + * + */ + boolean hasOptionalButton(); + + /** + * Resource string key for the optional button. + */ + String optionalButtonText(); + + /** + * Invoked when the user selects the optional button + */ + void optionOnSelection(ObjectListSelectionModel listSelectionModel); + + /** + * + */ + String removeButtonText(); + + /** + * Invoked when the user selects the Remove button. + */ + void removeSelectedItems(ObjectListSelectionModel listSelectionModel); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumComboViewer.java new file mode 100644 index 0000000000..5ad23152f0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumComboViewer.java @@ -0,0 +1,361 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import java.text.Collator; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import org.eclipse.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.utility.internal.ClassTools; +import org.eclipse.jpt.utility.internal.model.Model; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; + +/** + * This pane simply shows a combo where its data is populating through + * {@link #choices()} and a default value can also be added. + * <p> + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | I |v| | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @version 2.0 + * @since 1.0 + */ +@SuppressWarnings("nls") +public abstract class EnumComboViewer<T extends Model, V> extends AbstractPane<T> +{ + /** + * The main widget of this pane. + */ + private ComboViewer comboViewer; + + /** + * A constant used to represent the <code>null</code> value. + */ + private static final String NULL_VALUE = "null"; + + /** + * Creates a new <code>EnumComboViewer</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + */ + protected EnumComboViewer(AbstractPane<? extends T> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + /** + * Creates a new <code>EnumComboViewer</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + */ + protected EnumComboViewer(AbstractPane<?> parentPane, + PropertyValueModel<? extends T> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + /** + * Creates a new <code>EnumComboViewer</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various widgets + */ + protected EnumComboViewer(PropertyValueModel<? extends T> subjectHolder, + Composite parent, + IWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + /* + * (non-Javadoc) + */ + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(propertyName()); + } + + /** + * Creates the list of choices and add an extra element that represents the + * default value. + * + * @return The combo's choices including the default value + */ + private Object[] buildChoices() { + V[] choices = choices(); + Object[] extendedChoices; + + if (subject() != null) { + extendedChoices = new Object[choices.length + 1]; + System.arraycopy(choices, 0, extendedChoices, 1, choices.length); + extendedChoices[0] = NULL_VALUE; + } + else { + extendedChoices = choices(); + } + + Arrays.sort(extendedChoices, buildComparator()); + return extendedChoices; + } + + private Comparator<Object> buildComparator() { + return new Comparator<Object>() { + final LabelProvider labelProvider = buildLabelProvider(); + + public int compare(Object value1, Object value2) { + String displayString1 = labelProvider.getText(value1); + String displayString2 = labelProvider.getText(value2); + return Collator.getInstance().compare(displayString1, displayString2); + } + }; + } + + /** + * Retrieves the localized string from the given NLS class by creating the + * key. That key is the concatenation of the composite's short class name + * with the toString() of the given value separated by an underscore. + * + * @param nlsClass The NLS class used to retrieve the localized text + * @param compositeClass The class used for creating the key, its short class + * name is the beginning of the key + * @param value The value used to append its toString() to the generated key + * @return The localized text associated with the value + */ + protected final String buildDisplayString(Class<?> nlsClass, + Class<?> compositeClass, + Object value) { + + StringBuilder sb = new StringBuilder(); + sb.append(ClassTools.shortNameFor(compositeClass)); + sb.append("_"); + sb.append(value.toString().toLowerCase()); + + return (String) ClassTools.staticFieldValue(nlsClass, sb.toString()); + } + + /** + * Retrieves the localized string from the given NLS class by creating the + * key. That key is the concatenation of the composite's short class name + * with the toString() of the given value separated by an underscore. + * + * @param nlsClass The NLS class used to retrieve the localized text + * @param composite The object used to retrieve the short class name that is + * the beginning of the key + * @param value The value used to append its toString() to the generated key + * @return The localized text associated with the value + */ + protected final String buildDisplayString(Class<?> nlsClass, + Object composite, + Object value) { + + return this.buildDisplayString(nlsClass, composite.getClass(), value); + } + + /** + * Creates the display string for the given element. If the element is the + * virtual <code>null</code> value then its display string will be "Default" + * appended by the actual default value, if it exists. + * + * @param value The value to convert into a human readable string + * @return The string representation of the given element + */ + @SuppressWarnings("unchecked") + private String buildDisplayString(Object value) { + if (value == NULL_VALUE) { + V defaultValue = (subject() != null) ? defaultValue() : null; + + if (defaultValue != null) { + String displayString = displayString(defaultValue); + return NLS.bind(JptUiMessages.EnumComboViewer_defaultWithDefault, displayString); + } + else { + return JptUiMessages.EnumComboViewer_default; + } + } + + return displayString((V) value); + } + + private LabelProvider buildLabelProvider() { + return new LabelProvider() { + @Override + public String getText(Object element) { + return buildDisplayString(element); + } + }; + } + + private ISelection buildSelection() { + Object value = (subject() != null) ? getValue() : null; + + if (value == null) { + value = NULL_VALUE; + } + + return new StructuredSelection(value); + } + + @SuppressWarnings("unchecked") + private ISelectionChangedListener buildSelectionChangedListener() { + return new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent e) { + + if (isPopulating()) { + return; + } + + StructuredSelection selection = (StructuredSelection) e.getSelection(); + Object value = selection.getFirstElement(); + + // Convert the default "null" value to a real null + if (value == NULL_VALUE) { + value = null; + } + + EnumComboViewer.this.setValue((V) value); + } + }; + } + + /** + * Returns the possible choices to show in the viewer. + * + * @return The items to show in the combos + */ + protected abstract V[] choices(); + + /** + * Returns the default value, this method is not called if the subject is + * <code>null</code>. + * + * @return The value that is declared as being the default when it is not + * defined or <code>null</code> if there is no default value + */ + protected abstract V defaultValue(); + + /** + * Returns the displayable string for the given value. + * + * @param value The value to translate into a human readable string + * @return The localized text representing the given value + */ + protected abstract String displayString(V value); + + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + this.populateCombo(); + } + + /* + * (non-Javadoc) + */ + @Override + public void enableWidgets(boolean enabled) { + super.enableWidgets(enabled); + + if (!this.comboViewer.getCCombo().isDisposed()) { + this.comboViewer.getCCombo().setEnabled(enabled); + } + } + + protected final CCombo getCombo() { + return this.comboViewer.getCCombo(); + } + + /** + * Retrieves the subject's value. The subject is never <code>null</code>. + * + * @return The subject' value, which can be <code>null</code> + */ + protected abstract V getValue(); + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + this.comboViewer = buildComboViewer(container, buildLabelProvider()); + this.comboViewer.addSelectionChangedListener(buildSelectionChangedListener()); + } + + /** + * Populates + */ + private void populateCombo() { + this.getCombo().removeAll(); + this.comboViewer.add(this.buildChoices()); + this.updateSelection(); + } + + /* + * (non-Javadoc) + */ + @Override + protected void propertyChanged(String propertyName) { + super.propertyChanged(propertyName); + this.updateSelection(); + } + + /** + * Returns the property name used to listen for changes of the value when it + * is done outside of this viewer. + * + * @return The property name associated with the value being shown by this + * viewer + * @deprecated Use {@link #addPropertyNames(Collection)} + */ + @Deprecated + protected String propertyName() { + return ""; + } + + /** + * Requests the given new value be set on the subject. + * + * @param value The new value to be set + */ + protected abstract void setValue(V value); + + /** + * Updates the combo's selected item. + */ + private void updateSelection() { + this.comboViewer.setSelection(this.buildSelection()); + this.comboViewer.getCCombo().setSelection(new Point(0, 0)); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NullPostExecution.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NullPostExecution.java new file mode 100644 index 0000000000..1f5edba3ef --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NullPostExecution.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jface.dialogs.Dialog; + +/** + * A <code>null</code> instance of <code>PostExecution</code>. + * + * @version 2.0 + * @since 1.0 + */ +public final class NullPostExecution implements PostExecution<Dialog> { + + /** + * The singleton instance of this <code>NullPostExecution</code>. + */ + private static PostExecution<Dialog> INSTANCE; + + /** + * Creates a new <code>NullPostExecution</code>. + */ + private NullPostExecution() { + super(); + } + + /** + * Returns the singleton instance of this <code>NullPostExecution</code>. + * + * @param <T> The dialog where this <code>PostExecution</code> will be used + * @return The singleton instance with the proper type + */ + @SuppressWarnings("unchecked") + public static synchronized <T extends Dialog> PostExecution<T> instance() { + + if (INSTANCE == null) { + INSTANCE = new NullPostExecution(); + } + + return (PostExecution<T>) INSTANCE; + } + + /* + * (non-Javadoc) + */ + public void execute(Dialog dialog) { + // Nothing to do + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PostExecution.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PostExecution.java new file mode 100644 index 0000000000..0b6b920ba1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PostExecution.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.jface.dialogs.Dialog; + +/** + * This <code>PostExecution</code> is used to post execute a portion of code + * once a dialog, that was launched into a different UI thread, has been + * disposed. + * + * @version 2.0 + * @since 1.0 + */ +public interface PostExecution<T extends Dialog> { + + /** + * Notifies this post exection the dialog that was launched into a different + * UI thread has been disposed. + * + * @param dialog The dialog that was launched into a different thread + */ + public void execute(T dialog); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java new file mode 100644 index 0000000000..f655c12816 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java @@ -0,0 +1,351 @@ +/******************************************************************************* + * 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.ui.internal.widgets; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +/** + * This <code>TriStateCheckBox</code> is responsible to handle three states: + * unchecked, checked and partially selected. Either from a mouse selection, + * keyboard selection or programmatically, the selection state is using a + * <code>Boolean</code> value where a <code>null</code> value means partially + * selected. + * <p> + * The order of state state is: unchecked -> partially selected -> checked. + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public final class TriStateCheckBox { + + /** + * Flag used to prevent the selection listener from changing the selection + * state when the mouse is changing it since the selection state is called + * after the mouse down event and before the mouse up event. + */ + private boolean handledByMouseEvent; + + /** + * The current selection state. + */ + private TriState state; + + /** + * A tri-state check box can only be used within a tree or table, we used + * here the table widget. + */ + private Table table; + + /** + * Creates a new <code>TriStateCheckBox</code>. + * + * @param parent The parent composite + */ + public TriStateCheckBox(Composite parent) { + super(); + + this.state = TriState.UNCHECKED; + this.buildWidgets(parent); + } + + /** + * @see org.eclipse.swt.widgets.Widget#addDisposeListener(DisposeListener) + */ + public void addDisposeListener(DisposeListener disposeListener) { + this.table.addDisposeListener(disposeListener); + } + + /** + * @see Table#addSelectionListener(SelectionListener) + */ + public void addSelectionListener(SelectionListener selectionListener) { + this.table.addSelectionListener(selectionListener); + } + + private MouseAdapter buildMouseListener() { + + return new MouseAdapter() { + + @Override + public void mouseDown(MouseEvent e) { + + handledByMouseEvent = true; + + TriStateCheckBox.this.changeTriState(); + TriStateCheckBox.this.updateCheckBox(); + } + + @Override + public void mouseUp(MouseEvent e) { + + TriStateCheckBox.this.updateCheckBox(); + } + }; + } + + private SelectionAdapter buildSelectionListener() { + + return new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + if (handledByMouseEvent) { + handledByMouseEvent = false; + } + else { + TriStateCheckBox.this.changeTriState(); + TriStateCheckBox.this.updateCheckBox(); + } + } + }; + } + + private TriState buildState(Boolean selection) { + + if (selection == null) { + return TriState.PARTIALLY_CHECKED; + } + + return selection.booleanValue() ? TriState.CHECKED : TriState.UNCHECKED; + } + + private Layout buildTableLayout() { + + return new Layout() { + + @Override + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + Rectangle bounds = TriStateCheckBox.this.getCheckBox().getBounds(); + return new Point(bounds.x + bounds.width, bounds.y + bounds.height); + } + + private int indentation() { + if (Platform.OS_WIN32.equals(Platform.getOS())) { + try { + String version = System.getProperty("os.version"); + + // Under Vista, the check box has to be indented by -6 + // but under XP, it needs to remain 0 + if (Double.parseDouble(version) >= 6) { + return 6; + } + } + catch (Exception e) { + // Ignore and return 0 + } + } + + return 0; + } + + @Override + protected void layout(Composite composite, boolean flushCache) { + + Rectangle bounds = TriStateCheckBox.this.getCheckBox().getBounds(); + int indentation = indentation(); + + TriStateCheckBox.this.table.setBounds( + -indentation, + 0, + bounds.x + bounds.width + indentation, + bounds.y + bounds.height + ); + } + }; + } + + private void buildWidgets(Composite parent) { + + parent = new Composite(parent, SWT.NULL); + parent.setLayout(this.buildTableLayout()); + + this.table = new Table(parent, SWT.CHECK | SWT.SINGLE | SWT.TRANSPARENT); + this.table.addMouseListener(buildMouseListener()); + this.table.addSelectionListener(buildSelectionListener()); + this.table.getHorizontalBar().setVisible(false); + this.table.getVerticalBar().setVisible(false); + + new TableItem(this.table, SWT.CHECK); + } + + private void changeTriState() { + + if (this.state == TriState.UNCHECKED) { + this.state = TriState.PARTIALLY_CHECKED; + } + else if (this.state == TriState.CHECKED) { + this.state = TriState.UNCHECKED; + } + else { + this.state = TriState.CHECKED; + } + } + + /** + * Returns the actual <code>TableItem</code> used to show a tri-state check + * box. + * + * @return The unique item of the table that handles tri-state selection + */ + public TableItem getCheckBox() { + return this.table.getItem(0); + } + + /** + * Returns the main widget of the tri-state check box. + * + * @return The main composite used to display the tri-state check box + */ + public Control getControl() { + return this.table.getParent(); + } + + /** + * Returns the check box's image. + * + * @return The image of the check box + */ + public Image getImage() { + return this.getCheckBox().getImage(); + } + + /** + * Returns the selection state of the check box. + * + * @return Either <code>true</code> or <code>false</code> for checked and + * unchecked; or <code>null</code> for partially selected + */ + public Boolean getSelection() { + return (this.state == TriState.PARTIALLY_CHECKED) ? null : (this.state == TriState.CHECKED); + } + + /** + * Returns the check box's text. + * + * @return The text of the check box + */ + public String getText() { + return this.getCheckBox().getText(); + } + + /** + * Determines whether the check box is enabled or not. + * + * @return <code>true</code> if the check box is enabled; <code>false</code> + * otherwise + */ + public boolean isEnabled() { + return this.table.isEnabled(); + } + + /** + * @see org.eclipse.swt.widgets.Widget#removeDisposeListener(DisposeListener) + */ + public void removeDisposeListener(DisposeListener disposeListener) { + this.table.removeDisposeListener(disposeListener); + } + + /** + * @see Table#removeSelectionListener(SelectionListener) + */ + public void removeSelectionListener(SelectionListener selectionListener) { + this.table.removeSelectionListener(selectionListener); + } + + /** + * Changes the enablement state of the widgets of this pane. + * + * @param enabled <code>true</code> to enable the widgets or <code>false</code> + * to disable them + */ + public void setEnabled(boolean enabled) { + this.table.setEnabled(enabled); + } + + /** + * Sets the check box's image. + * + * @param image The new image of the check box + */ + public void setImage(Image image) { + // TODO: Not sure this will update the layout, if that is the case, + // then copy the code from LabeledTableItem.updateTableItem() + this.getCheckBox().setImage(image); + } + + /** + * Changes the selection state of the check box. + * + * @param selection Either <code>true</code> or <code>false</code> for + * checked and unchecked; or <code>null</code> for partially selected + */ + public void setSelection(Boolean selection) { + TriState oldState = this.state; + this.state = this.buildState(selection); + + if (oldState != this.state) { + this.updateCheckBox(); + } + } + + /** + * Sets the check box's text. + * + * @param text The new text of the check box + */ + public void setText(String text) { + // TODO: Not sure this will update the layout, if that is the case, + // then copy the code from LabeledTableItem.updateTableItem() + this.getCheckBox().setText(text); + } + + /** + * Updates the selection state of the of the check box based on the tri-state + * value. + */ + private void updateCheckBox() { + TableItem checkBox = this.getCheckBox(); + + if (this.state == TriState.PARTIALLY_CHECKED) { + checkBox.setChecked(true); + checkBox.setGrayed(true); + } + else { + checkBox.setGrayed(false); + checkBox.setChecked(this.state == TriState.CHECKED); + } + } + + /** + * An enum containing the possible selection. + */ + public enum TriState { + CHECKED, + PARTIALLY_CHECKED, + UNCHECKED + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseReconnectWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseReconnectWizardPage.java index 5344c188b7..80509f9f86 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseReconnectWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseReconnectWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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. @@ -121,6 +121,7 @@ public class DatabaseReconnectWizardPage extends WizardPage { generateEntitiesWizard.updatePossibleTables( CollectionTools.collection( schema.tables())); } + @Override public void dispose() { this.removeConnectionListener(); super.dispose(); @@ -137,13 +138,12 @@ public class DatabaseReconnectWizardPage extends WizardPage { ConnectionProfile getProjectConnectionProfile() { - String profileName = this.jpaProject.dataSource().getConnectionProfileName(); + String profileName = this.jpaProject.dataSource().connectionProfileName(); return JptDbPlugin.getDefault().getConnectionProfileRepository().profileNamed( profileName); } Schema getDefaultSchema() { - ConnectionProfile profile = getProjectConnectionProfile(); - return profile.getDatabase().schemaNamed( profile.getDefaultSchema()); + return getProjectConnectionProfile().defaultSchema(); } // ********** member classes ********** @@ -168,10 +168,12 @@ public class DatabaseReconnectWizardPage extends WizardPage { createLabel( this.group, 1, JptUiMessages.DatabaseReconnectWizardPage_connection); this.connectionCombo = createCombo( this.group, true); this.connectionCombo.addSelectionListener( new SelectionAdapter() { + @Override public void widgetDefaultSelected( SelectionEvent e) { widgetSelected( e); } + @Override public void widgetSelected( SelectionEvent e) { handleConnectionChange(); } @@ -179,10 +181,12 @@ public class DatabaseReconnectWizardPage extends WizardPage { createLabel( this.group, 1, JptUiMessages.DatabaseReconnectWizardPage_schema); this.schemaCombo = createCombo( this.group, true); this.schemaCombo.addSelectionListener( new SelectionAdapter() { + @Override public void widgetDefaultSelected( SelectionEvent e) { widgetSelected( e); } + @Override public void widgetSelected( SelectionEvent e) { handleSchemaChange(); } @@ -194,6 +198,7 @@ public class DatabaseReconnectWizardPage extends WizardPage { this.addConnectionLink.setLayoutData( data); this.addConnectionLink.setText( JptUiMessages.DatabaseReconnectWizardPage_addConnectionLink); this.addConnectionLink.addSelectionListener( new SelectionAdapter() { + @Override public void widgetSelected( SelectionEvent e) { openNewConnectionWizard(); } @@ -205,6 +210,7 @@ public class DatabaseReconnectWizardPage extends WizardPage { this.reconnectLink.setText( JptUiMessages.DatabaseReconnectWizardPage_reconnectLink); this.reconnectLink.setEnabled( false); this.reconnectLink.addSelectionListener( new SelectionAdapter() { + @Override public void widgetSelected( SelectionEvent e) { openConnectionProfileNamed( connectionCombo.getText()); } @@ -222,12 +228,11 @@ public class DatabaseReconnectWizardPage extends WizardPage { } private String getProjectConnectionProfileName() { - return jpaProject.dataSource().getConnectionProfileName(); + return jpaProject.dataSource().connectionProfileName(); } Schema getDefaultSchema() { - ConnectionProfile profile = getProjectConnectionProfile(); - return profile.getDatabase().schemaNamed( profile.getDefaultSchema()); + return getProjectConnectionProfile().defaultSchema(); } private void openConnectionProfileNamed( String connectionProfileName) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java index ed1392045c..46e5bea98f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java @@ -53,6 +53,7 @@ public class GenerateEntitiesWizard extends Wizard { this.setWindowTitle( JptUiMessages.GenerateEntitiesWizard_generateEntities); } + @Override public void addPages() { super.addPages(); this.dbSettingsPage = new DatabaseReconnectWizardPage( this.jpaProject); @@ -62,6 +63,7 @@ public class GenerateEntitiesWizard extends Wizard { this.generateEntitiesPage.init( this.selection); } + @Override public boolean performFinish() { this.packageGeneratorConfig.setPackageFragment( this.buildPackageFragment()); @@ -119,8 +121,7 @@ public class GenerateEntitiesWizard extends Wizard { } Schema getDefaultSchema() { - ConnectionProfile profile = getProjectConnectionProfile(); - return profile.getDatabase().schemaNamed( profile.getDefaultSchema()); + return getProjectConnectionProfile().defaultSchema(); } public PackageGenerator.Config getPackageGeneratorConfig() { @@ -139,7 +140,8 @@ public class GenerateEntitiesWizard extends Wizard { return this.synchronizePersistenceXml; } - public boolean canFinish() { + @Override + public boolean canFinish() { boolean canFinish = true; if ( ! this.generateEntitiesPage.isPageComplete()) { canFinish = false; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java index 5d695081d7..a200130029 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java @@ -22,8 +22,8 @@ import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.internal.JpaPlatformRegistry; import org.eclipse.jpt.core.internal.facet.IJpaFacetDataModelProperties; +import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; import org.eclipse.jpt.db.internal.ConnectionProfileRepository; import org.eclipse.jpt.db.ui.internal.DTPUiTools; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/JptUiXmlMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/JptUiXmlMessages.java index c6804dd5a9..042043b359 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/JptUiXmlMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/JptUiXmlMessages.java @@ -1,28 +1,31 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.xml; import org.eclipse.osgi.util.NLS; -public class JptUiXmlMessages +public class JptUiXmlMessages { private static final String BUNDLE_NAME = "jpt_ui_xml"; //$NON-NLS-1$ - + + public static String PersistentTypePage_javaClassLabel; public static String PersistentTypePage_MetadataCompleteLabel; public static String PersistentTypePage_AccessLabel; - + public static String PersistenceUnitMetadataSection_SchemaDefault; public static String PersistenceUnitMetadataSection_CatalogDefault; - + public static String PersistentAttributePage_javaAttributeLabel; - + + public static String XmlEntityMappingsDetailsPage_package; + public static String XMLEntityMappingsPage_XmlMappingMetadataCompleteCheckBox; public static String XMLEntityMappingsPage_CascadePersistCheckBox; public static String XMLEntityMappingsPage_PersistenceUnitSection; @@ -30,21 +33,22 @@ public class JptUiXmlMessages public static String XMLEntityMappingsPage_SchemaNoDefaultSpecified; public static String XMLEntityMappingsPage_CatalogDefault; public static String XMLEntityMappingsPage_CatalogNoDefaultSpecified; - + public static String XmlSchemaChooser_SchemaChooser; public static String XmlCatalogChooser_CatalogChooser; public static String XmlJavaClassChooser_XmlJavaClassDialog_title; public static String XmlJavaClassChooser_XmlJavaClassDialog_message; public static String XmlPackageChooser_PackageDialog_title; - public static String XmlPackageChooser_PackageDialog_message; - - + public static String XmlPackageChooser_PackageDialog_message; + + public static String AccessTypeComposite_field; + public static String AccessTypeComposite_property; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, JptUiXmlMessages.class); } - + private JptUiXmlMessages() { throw new UnsupportedOperationException(); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/AccessTypeComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/AccessTypeComboViewer.java deleted file mode 100644 index 7048b4f617..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/AccessTypeComboViewer.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.AccessType; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class AccessTypeComboViewer extends BaseJpaController -{ - private AccessHolder accessHolder; - private Adapter accessHolderListener; - - private ComboViewer comboViewer; - - - public AccessTypeComboViewer(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildAccessHolderListener(); - } - - - private void buildAccessHolderListener() { - this.accessHolderListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - accessHolderChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - this.comboViewer = new ComboViewer(combo); - this.comboViewer.setLabelProvider(buildAccessTypeLabelProvider()); - this.comboViewer.add(AccessType.VALUES.toArray()); - - this.comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - AccessTypeComboViewer.this.accessTypeSelectionChanged(event.getSelection()); - } - }); - } - - private IBaseLabelProvider buildAccessTypeLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - if (element == AccessType.DEFAULT) { - return JptUiMappingsMessages.AccessTypeCombo_default; - } - return super.getText(element); - } - }; - } - - void accessTypeSelectionChanged(ISelection selection) { - if (selection instanceof IStructuredSelection) { - AccessType access = (AccessType) ((IStructuredSelection) selection).getFirstElement(); - if ( ! this.accessHolder.getAccess().equals(access)) { - this.accessHolder.setAccess(access); - } - } - } - - private void accessHolderChanged(Notification notification) { - if (notification.getFeatureID(this.accessHolder.featureClass()) == - this.accessHolder.featureId()) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.accessHolder != null && this.accessHolder.wrappedObject() != null) { - this.accessHolder.wrappedObject().eAdapters().add(this.accessHolderListener); - } - } - - @Override - protected void disengageListeners() { - if (this.accessHolder != null && this.accessHolder.wrappedObject() != null) { - this.accessHolder.wrappedObject().eAdapters().remove(this.accessHolderListener); - } - } - - public final void populate(AccessHolder accessHolder) { - super.populate(accessHolder); - } - - @Override - public void doPopulate(EObject obj) { - this.accessHolder = (AccessHolder) obj; - populateCombo(); - } - - @Override - protected void doPopulate() { - populateCombo(); - } - - private void populateCombo() { - if (this.accessHolder.wrappedObject() == null) { - return; - } - - AccessType access = this.accessHolder.getAccess(); - - if (((IStructuredSelection) this.comboViewer.getSelection()).getFirstElement() != access) { - this.comboViewer.setSelection(new StructuredSelection(access)); - } - } - - - @Override - public Control getControl() { - return this.comboViewer.getCombo(); - } - - /** - * An interface to wrap an object that supports accessType - * An object of this type must be passed in to populate(EObject) - */ - public static interface AccessHolder extends EObject { - /** - * Return the AccessType from the wrapped object - * @return - */ - AccessType getAccess(); - - /** - * Set the AccessType on the wrapped object - * @param accessType - */ - void setAccess(AccessType accessType); - - /** - * Return the Class of the wrapped object - * @return - */ - Class featureClass(); - - /** - * Return the feature id of accessType on the wrapped object - * @return - */ - int featureId(); - - /** - * The wrapped EObject that the accessType is stored on - * @return - */ - EObject wrappedObject(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/AccessTypeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/AccessTypeComposite.java new file mode 100644 index 0000000000..4f1d4a512b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/AccessTypeComposite.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * 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.ui.internal.xml.details; + +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.base.AccessType; +import org.eclipse.jpt.core.internal.context.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.resource.orm.TypeMapping; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------ | + * | Access Type: | |v| | + * | ------------------------------------------------------------ | + * -----------------------------------------------------------------------------</pre> + * + * @see XmlTypeMapping + * @see XmlPersistentTypeDetailsPage - A container of this pane + * + * @version 2.0 + * @since 1.0 + */ +public class AccessTypeComposite extends AbstractFormPane<XmlTypeMapping<? extends TypeMapping>> { + + /** + * Creates a new <code>AccessTypeComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public AccessTypeComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends XmlTypeMapping<? extends TypeMapping>> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + private EnumComboViewer<XmlTypeMapping<? extends TypeMapping>, AccessType> buildAccessTypeComboViewer(Composite container) { + + return new EnumComboViewer<XmlTypeMapping<? extends TypeMapping>, AccessType>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(XmlTypeMapping.DEFAULT_ACCESS_PROPERTY); + propertyNames.add(XmlTypeMapping.SPECIFIED_ACCESS_PROPERTY); + } + + @Override + protected AccessType[] choices() { + return AccessType.values(); + } + + @Override + protected AccessType defaultValue() { + return subject().getDefaultAccess(); + } + + @Override + protected String displayString(AccessType value) { + return buildDisplayString( + JptUiXmlMessages.class, + AccessTypeComposite.this, + value + ); + } + + @Override + protected AccessType getValue() { + return subject().getSpecifiedAccess(); + } + + @Override + protected void setValue(AccessType value) { + subject().setSpecifiedAccess(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + EnumComboViewer<XmlTypeMapping<? extends TypeMapping>, AccessType> comboViewer = + buildAccessTypeComboViewer(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.PersistentTypePage_AccessLabel, + comboViewer.getControl() + ); + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/CascadePersistCheckBox.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/CascadePersistCheckBox.java deleted file mode 100644 index 332079a3f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/CascadePersistCheckBox.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class CascadePersistCheckBox extends BaseJpaController -{ - private PersistenceUnitDefaults persistenceUnitDefaults; - private Adapter persistenceUnitDefaultsListener; - - private Button button; - - - public CascadePersistCheckBox(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildPeristenceUnitDefaultsListener(); - } - - private void buildPeristenceUnitDefaultsListener() { - this.persistenceUnitDefaultsListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - persistenceUnitDefaultsChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.button = getWidgetFactory().createButton( - parent, - JptUiXmlMessages.XMLEntityMappingsPage_CascadePersistCheckBox, - SWT.CHECK); - - this.button.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - CascadePersistCheckBox.this.cascadePersistSelectionChanged(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - CascadePersistCheckBox.this.cascadePersistSelectionChanged(); - } - }); - } - - void cascadePersistSelectionChanged() { - boolean cascadePersist = this.button.getSelection(); - if (this.persistenceUnitDefaults.isCascadePersist() != cascadePersist) { - this.persistenceUnitDefaults.setCascadePersist(cascadePersist); - } - } - - private void persistenceUnitDefaultsChanged(Notification notification) { - if (notification.getFeatureID(PersistenceUnitDefaults.class) == - OrmPackage.PERSISTENCE_UNIT_DEFAULTS__CASCADE_PERSIST) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.persistenceUnitDefaults != null) { - this.persistenceUnitDefaults.eAdapters().add(this.persistenceUnitDefaultsListener); - } - } - - @Override - protected void disengageListeners() { - if (this.persistenceUnitDefaults != null) { - this.persistenceUnitDefaults.eAdapters().remove(this.persistenceUnitDefaultsListener); - } - } - - @Override - public void doPopulate(EObject obj) { - this.persistenceUnitDefaults = (PersistenceUnitDefaults) obj; - populateButton(); - } - - @Override - protected void doPopulate() { - populateButton(); - } - - private void populateButton() { - boolean cascadePersist = false; - if (this.persistenceUnitDefaults != null) { - cascadePersist = this.persistenceUnitDefaults.isCascadePersist(); - } - - if (this.button.getSelection() != cascadePersist) { - this.button.setSelection(cascadePersist); - } - } - - - @Override - public Control getControl() { - return this.button; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/CommonWidgets.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/CommonWidgets.java deleted file mode 100644 index 01e5c21461..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/CommonWidgets.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.jpt.ui.internal.mappings.details.StringWithDefaultChooser; -import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class CommonWidgets -{ - public static Label buildJavaClassLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - Label label = widgetFactory.createLabel(parent, JptUiXmlMessages.PersistentTypePage_javaClassLabel); - return label; - } - - public static XmlJavaClassChooser buildJavaClassChooser( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new XmlJavaClassChooser(parent, commandStack, widgetFactory); - } - - public static Label buildJavaAttributeNameLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - Label label = widgetFactory.createLabel(parent, JptUiXmlMessages.PersistentAttributePage_javaAttributeLabel); - return label; - } - - public static XmlJavaAttributeChooser buildJavaAttributeChooser( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new XmlJavaAttributeChooser(parent, commandStack, widgetFactory); - } - - - public static Label buildAccessLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiXmlMessages.PersistentTypePage_AccessLabel); - } - - public static AccessTypeComboViewer buildAccessTypeComboViewer( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new AccessTypeComboViewer(parent, commandStack, widgetFactory); - } - - - public static Label buildCatalogLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiXmlMessages.XmlCatalogChooser_CatalogChooser); - } - - public static StringWithDefaultChooser buildCatalogChooser( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new StringWithDefaultChooser(parent, commandStack, widgetFactory); - } - - - public static Label buildSchemaLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, JptUiXmlMessages.XmlSchemaChooser_SchemaChooser); - } - - public static StringWithDefaultChooser buildSchemaChooser( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new StringWithDefaultChooser(parent, commandStack, widgetFactory); - } - - - public static Label buildPackageLabel(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - return widgetFactory.createLabel(parent, "Package:"); - } - - public static XmlPackageChooser buildXmlPackageChooser( - Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - return new XmlPackageChooser(parent, commandStack, widgetFactory); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/MetaDataCompleteComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/MetaDataCompleteComboViewer.java index 62c6233cef..9390fd9c94 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/MetaDataCompleteComboViewer.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/MetaDataCompleteComboViewer.java @@ -1,154 +1,111 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.xml.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlTypeMapping; -import org.eclipse.jpt.core.internal.mappings.DefaultFalseBoolean; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; +import java.util.Collection; +import org.eclipse.jpt.core.internal.context.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.resource.orm.TypeMapping; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.custom.CCombo; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class MetaDataCompleteComboViewer extends BaseJpaController +/** + * Here the layout of this pane: + * <pre> + * </pre> + * + * @see XmlTypeMapping + * @see XmlPersistentTypeDetailsPage - The container of this pane + * + * @version 2.0 + * @since 2.0 + */ +public class MetaDataCompleteComboViewer extends AbstractFormPane<XmlTypeMapping<? extends TypeMapping>> { - private XmlTypeMapping mapping; - private Adapter typeMappingListener; - - private ComboViewer comboViewer; + /** + * Creates a new <code>MetaDataCompleteComboViewer</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public MetaDataCompleteComboViewer(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends XmlTypeMapping<? extends TypeMapping>> subjectHolder, + Composite parent) { + super(parentPane, subjectHolder, parent); + } + + /** + * Creates a new <code>MetaDataCompleteComboViewer</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public MetaDataCompleteComboViewer(PropertyValueModel<? extends XmlTypeMapping<? extends TypeMapping>> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { - public MetaDataCompleteComboViewer(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildTypeMappingListener(); + super(subjectHolder, parent, widgetFactory); } - - - private void buildTypeMappingListener() { - this.typeMappingListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - typeMappingChanged(notification); + + private EnumComboViewer<XmlTypeMapping<? extends TypeMapping>, Boolean> buildEnumTypeCombo(Composite container) { + + return new EnumComboViewer<XmlTypeMapping<? extends TypeMapping>, Boolean>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(XmlTypeMapping.DEFAULT_METADATA_COMPLETE_PROPERTY); + propertyNames.add(XmlTypeMapping.SPECIFIED_METADATA_COMPLETE_PROPERTY); } - }; - } - - @Override - protected void buildWidget(Composite parent) { - CCombo combo = getWidgetFactory().createCCombo(parent); - this.comboViewer = new ComboViewer(combo); - this.comboViewer.setLabelProvider(buildLabelProvider()); - this.comboViewer.add(DefaultFalseBoolean.VALUES.toArray()); - this.comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - MetaDataCompleteComboViewer.this.metadataCompleteSelectionChanged(event.getSelection()); + + @Override + protected Boolean[] choices() { + return new Boolean[] { Boolean.TRUE, Boolean.FALSE }; } - }); - } - private IBaseLabelProvider buildLabelProvider() { - return new LabelProvider() { + @Override - public String getText(Object element) { - if (element == DefaultFalseBoolean.DEFAULT) { - //TODO need to move this to the model, don't want hardcoded String - return NLS.bind(JptUiMappingsMessages.MetaDataCompleteCombo_Default, "False"); - } - return super.getText(element); + protected Boolean defaultValue() { + return null; + } + + @Override + protected String displayString(Boolean value) { + return buildDisplayString( + JptUiMappingsMessages.class, + MetaDataCompleteComboViewer.this, + value + ); } - }; - } - void metadataCompleteSelectionChanged(ISelection selection) { - if (selection instanceof IStructuredSelection) { - DefaultFalseBoolean metadataComplete = (DefaultFalseBoolean) ((IStructuredSelection) selection).getFirstElement(); - if ( ! this.mapping.getMetadataComplete().equals(metadataComplete)) { - this.mapping.setMetadataComplete(metadataComplete); -// this.editingDomain.getCommandStack().execute( -// SetCommand.create( -// this.editingDomain, -// this.basicMapping, -// OrmPackage.eINSTANCE.getBasicMapping_Optional(), -// optional -// ) -// ); + @Override + protected Boolean getValue() { + return subject().getSpecifiedMetadataComplete(); } - } - } - private void typeMappingChanged(Notification notification) { - if (notification.getFeatureID(XmlTypeMapping.class) == - OrmPackage.XML_TYPE_MAPPING__METADATA_COMPLETE) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.mapping != null) { - this.mapping.eAdapters().add(this.typeMappingListener); - } - } - - @Override - protected void disengageListeners() { - if (this.mapping != null) { - this.mapping.eAdapters().remove(this.typeMappingListener); - } - } - - @Override - public void doPopulate(EObject obj) { - this.mapping = (XmlTypeMapping) obj; - populateCombo(); - } - - @Override - protected void doPopulate() { - populateCombo(); - } - - private void populateCombo() { - if (this.mapping == null) { - return; - } - - DefaultFalseBoolean metadataComplete = this.mapping.getMetadataComplete(); - - if (((IStructuredSelection) this.comboViewer.getSelection()).getFirstElement() != metadataComplete) { - this.comboViewer.setSelection(new StructuredSelection(metadataComplete)); - } + @Override + protected void setValue(Boolean value) { + subject().setSpecifiedMetadataComplete(value); + } + }; } - + /* + * (non-Javadoc) + */ @Override - public Control getControl() { - return this.comboViewer.getCombo(); + protected void initializeLayout(Composite container) { + buildEnumTypeCombo(container); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/PersistenceUnitMetadataComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/PersistenceUnitMetadataComposite.java new file mode 100644 index 0000000000..64167255d1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/PersistenceUnitMetadataComposite.java @@ -0,0 +1,277 @@ +/******************************************************************************* + * 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.ui.internal.xml.details; + +import org.eclipse.jpt.core.internal.context.base.AccessType; +import org.eclipse.jpt.core.internal.context.orm.PersistenceUnitDefaults; +import org.eclipse.jpt.core.internal.context.orm.PersistenceUnitMetadata; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; +import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | - Persistence Unit ------------------------------------------------------ | + * | | + * | x XML Mapping Metadata Complete | + * | | + * | x Cascade Persist | + * | | + * | ------------------------------------------------------------ | + * | Schema: | |v| | + * | ------------------------------------------------------------ | + * | ------------------------------------------------------------ | + * | Catalog: | |v| | + * | ------------------------------------------------------------ | + * | ------------------------------------------------------------ | + * | Access Type: | |v| | + * | ------------------------------------------------------------ | + * -----------------------------------------------------------------------------</pre> + * + * @see PersistenceUnitMetadata + * @see PersistenceUnitDefaults + * @see XmlEntityMappingsDetailsPage - The parent container + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public class PersistenceUnitMetadataComposite extends AbstractFormPane<PersistenceUnitMetadata> +{ + /** + * Creates a new <code>PersistenceUnitMetadataComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public PersistenceUnitMetadataComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends PersistenceUnitMetadata> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + private EnumComboViewer<PersistenceUnitDefaults, AccessType> buildAccessTypeCombo(Composite container) { + + return new EnumComboViewer<PersistenceUnitDefaults, AccessType>(this, buildPersistenceUnitDefaultsHolder(), container) { + @Override + protected AccessType[] choices() { + return AccessType.values(); + } + + @Override + protected AccessType defaultValue() { + return null; + } + + @Override + protected String displayString(AccessType value) { + return buildDisplayString( + JptUiXmlMessages.class, + PersistenceUnitMetadataComposite.this, + value + ); + } + + @Override + protected AccessType getValue() { + return subject().getAccess(); + } + + @Override + protected String propertyName() { + return PersistenceUnitDefaults.ACCESS_PROPERTY; + } + + @Override + protected void setValue(AccessType value) { + subject().setAccess(value); + } + }; + } + + private WritablePropertyValueModel<Boolean> buildCascadePersistHolder() { + return new PropertyAspectAdapter<PersistenceUnitDefaults, Boolean>(buildPersistenceUnitDefaultsHolder(), PersistenceUnitDefaults.CASCADE_PERSIST_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isCascadePersist(); + } + + @Override + protected void setValue_(Boolean value) { + subject.setCascadePersist(value); + } + }; + } + + private EnumComboViewer<PersistenceUnitDefaults, String> buildCatalogComboViewer(Composite container) { + + return new EnumComboViewer<PersistenceUnitDefaults, String>(this, buildPersistenceUnitDefaultsHolder(), container) { + @Override + protected String[] choices() { + return new String[0]; + } + + @Override + protected String defaultValue() { + return "default"; + } + + @Override + protected String displayString(String value) { + return value; + } + + @Override + protected String getValue() { + return subject().getCatalog(); + } + + @Override + protected String propertyName() { + return PersistenceUnitDefaults.CATALOG_PROPERTY; + } + + @Override + protected void setValue(String value) { + subject().setCatalog(value); + } + }; + } + + private PropertyValueModel<PersistenceUnitDefaults> buildPersistenceUnitDefaultsHolder() { + return new TransformationPropertyValueModel<PersistenceUnitMetadata, PersistenceUnitDefaults>(getSubjectHolder()) { + @Override + protected PersistenceUnitDefaults transform_(PersistenceUnitMetadata value) { + return value.getPersistenceUnitDefaults(); + } + }; + } + + private EnumComboViewer<PersistenceUnitDefaults, String> buildSchemaComboViewer(Composite container) { + + return new EnumComboViewer<PersistenceUnitDefaults, String>(this, buildPersistenceUnitDefaultsHolder(), container) { + @Override + protected String[] choices() { + return new String[0]; + } + + @Override + protected String defaultValue() { + return "default"; + } + + @Override + protected String displayString(String value) { + return value; + } + + @Override + protected String getValue() { + return subject().getSchema(); + } + + @Override + protected String propertyName() { + return PersistenceUnitDefaults.SCHEMA_PROPERTY; + } + + @Override + protected void setValue(String value) { + subject().setSchema(value); + } + }; + } + + private WritablePropertyValueModel<Boolean> buildXmlMappingMetadataCompleteHolder() { + return new PropertyAspectAdapter<PersistenceUnitMetadata, Boolean>(getSubjectHolder(), PersistenceUnitMetadata.XML_MAPPING_METADATA_COMPLETE_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.isXmlMappingMetadataComplete(); + } + + @Override + protected void setValue_(Boolean value) { + subject.setXmlMappingMetadataComplete(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Section + container = buildSection( + container, + JptUiXmlMessages.XMLEntityMappingsPage_PersistenceUnitSection + ); + + // XML mapping metadata complete check box + buildCheckBox( + container, + JptUiXmlMessages.XMLEntityMappingsPage_XmlMappingMetadataCompleteCheckBox, + buildXmlMappingMetadataCompleteHolder(), + IJpaHelpContextIds.ENTITY_ORM_XML + ); + + // Cascade Persist widgets + buildCheckBox( + container, + JptUiXmlMessages.XMLEntityMappingsPage_CascadePersistCheckBox, + buildCascadePersistHolder(), + IJpaHelpContextIds.ENTITY_ORM_CASCADE + ); + + // Schema widgets + EnumComboViewer<PersistenceUnitDefaults, String> schemaComboViewer = + buildSchemaComboViewer(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.XmlSchemaChooser_SchemaChooser, + schemaComboViewer.getControl(), + IJpaHelpContextIds.ENTITY_ORM_SCHEMA + ); + + // Catalog widgets + EnumComboViewer<PersistenceUnitDefaults, String> catalogComboViewer = + buildCatalogComboViewer(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.XmlCatalogChooser_CatalogChooser, + catalogComboViewer.getControl(), + IJpaHelpContextIds.ENTITY_ORM_CATALOG + ); + + // Access Type widgets + EnumComboViewer<PersistenceUnitDefaults, AccessType> accessTypeComposite = + buildAccessTypeCombo(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.PersistentTypePage_AccessLabel, + accessTypeComposite.getControl(), + IJpaHelpContextIds.ENTITY_ORM_ACCESS + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/PersistenceUnitMetadataSection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/PersistenceUnitMetadataSection.java deleted file mode 100644 index 253d9c91c4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/PersistenceUnitMetadataSection.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.AccessType; -import org.eclipse.jpt.core.internal.XmlEObject; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.internal.content.orm.PersistenceUnitDefaultsInternal; -import org.eclipse.jpt.core.internal.content.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.mappings.details.StringWithDefaultChooser; -import org.eclipse.jpt.ui.internal.mappings.details.StringWithDefaultChooser.StringHolder; -import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; -import org.eclipse.jpt.ui.internal.xml.details.AccessTypeComboViewer.AccessHolder; -import org.eclipse.swt.SWT; -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.PlatformUI; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.help.IWorkbenchHelpSystem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class PersistenceUnitMetadataSection extends BaseJpaController -{ - - private Section section; - private XmlMappingMetadataCompleteCheckBox xmlMappingMetadataCompleteCheckBox; - private StringWithDefaultChooser xmlSchemaChooser; - private StringWithDefaultChooser xmlCatalogChooser; - private AccessTypeComboViewer accessComboViewer; - private CascadePersistCheckBox cascadePersistCheckBox; - - public PersistenceUnitMetadataSection(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, commandStack, widgetFactory); - } - - @Override - protected void buildWidget(Composite parent) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - this.section = getWidgetFactory().createSection(parent, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - this.section.setText(JptUiXmlMessages.XMLEntityMappingsPage_PersistenceUnitSection); - - Composite persistenceUnitComposite = getWidgetFactory().createComposite(this.section); - this.section.setClient(persistenceUnitComposite); - - GridLayout layout = new GridLayout(2, false); - layout.marginWidth = 1; - persistenceUnitComposite.setLayout(layout); - - - this.xmlMappingMetadataCompleteCheckBox = buildXmlMappingMetadataCompleteCheckBox(persistenceUnitComposite); - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.xmlMappingMetadataCompleteCheckBox.getControl().setLayoutData(gridData); - helpSystem.setHelp(xmlMappingMetadataCompleteCheckBox.getControl(), IJpaHelpContextIds.ENTITY_ORM_XML); - - CommonWidgets.buildSchemaLabel(persistenceUnitComposite, getWidgetFactory()); - - this.xmlSchemaChooser = CommonWidgets.buildSchemaChooser(persistenceUnitComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.xmlSchemaChooser.getCombo().setLayoutData(gridData); - helpSystem.setHelp(xmlSchemaChooser.getControl(), IJpaHelpContextIds.ENTITY_ORM_SCHEMA); - - CommonWidgets.buildCatalogLabel(persistenceUnitComposite, getWidgetFactory()); - - this.xmlCatalogChooser = CommonWidgets.buildCatalogChooser(persistenceUnitComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.xmlCatalogChooser.getCombo().setLayoutData(gridData); - helpSystem.setHelp(xmlCatalogChooser.getControl(), IJpaHelpContextIds.ENTITY_ORM_CATALOG); - - CommonWidgets.buildAccessLabel(persistenceUnitComposite, getWidgetFactory()); - - this.accessComboViewer = CommonWidgets.buildAccessTypeComboViewer(persistenceUnitComposite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.accessComboViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(accessComboViewer.getControl(), IJpaHelpContextIds.ENTITY_ORM_ACCESS); - - - this.cascadePersistCheckBox = buildCascadePersistCheckBox(persistenceUnitComposite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.cascadePersistCheckBox.getControl().setLayoutData(gridData); - helpSystem.setHelp(cascadePersistCheckBox.getControl(), IJpaHelpContextIds.ENTITY_ORM_CASCADE); - - } - - private XmlMappingMetadataCompleteCheckBox buildXmlMappingMetadataCompleteCheckBox(Composite parent) { - return new XmlMappingMetadataCompleteCheckBox(parent, this.commandStack, getWidgetFactory()); - } - - private CascadePersistCheckBox buildCascadePersistCheckBox(Composite parent) { - return new CascadePersistCheckBox(parent, this.commandStack, getWidgetFactory()); - } - - @Override - protected void engageListeners() { - } - - @Override - protected void disengageListeners() { - } - - @Override - public void doPopulate(EObject obj) { - PersistenceUnitMetadata persistenceUnitMetadata = (PersistenceUnitMetadata) obj; - this.xmlMappingMetadataCompleteCheckBox.populate(persistenceUnitMetadata); - if (persistenceUnitMetadata != null) { - this.accessComboViewer.populate(new MyAccessHolder(persistenceUnitMetadata.getPersistenceUnitDefaults())); - this.xmlSchemaChooser.populate(new SchemaHolder(persistenceUnitMetadata.getPersistenceUnitDefaults())); - this.xmlCatalogChooser.populate(new CatalogHolder(persistenceUnitMetadata.getPersistenceUnitDefaults())); - this.cascadePersistCheckBox.populate(persistenceUnitMetadata.getPersistenceUnitDefaults()); - } - else { - this.accessComboViewer.populate(new MyAccessHolder(null)); - this.xmlSchemaChooser.populate(new SchemaHolder(null)); - this.xmlCatalogChooser.populate(new CatalogHolder(null)); - this.cascadePersistCheckBox.populate(null); - } - } - private class MyAccessHolder extends XmlEObject implements AccessHolder{ - - private PersistenceUnitDefaultsInternal persistenceUnitDefaults; - MyAccessHolder(PersistenceUnitDefaults persistenceUnitDefaultsInternal) { - super(); - this.persistenceUnitDefaults = (PersistenceUnitDefaultsInternal) persistenceUnitDefaultsInternal; - } - public void setAccess(AccessType accessType) { - persistenceUnitDefaults.setAccess(accessType); - } - - public AccessType getAccess() { - return persistenceUnitDefaults.getAccess(); - } - - public Class featureClass() { - return PersistenceUnitDefaults.class; - } - - public int featureId() { - return OrmPackage.PERSISTENCE_UNIT_DEFAULTS__ACCESS; - } - - public EObject wrappedObject() { - return this.persistenceUnitDefaults; - } - } - - private class SchemaHolder extends XmlEObject implements StringHolder { - private PersistenceUnitDefaults persistenceUnitDefaults; - SchemaHolder(PersistenceUnitDefaults persistenceUnitDefaults) { - super(); - this.persistenceUnitDefaults = persistenceUnitDefaults; - } - - public Class featureClass() { - return PersistenceUnitDefaults.class; - } - - public int featureId() { - return OrmPackage.PERSISTENCE_UNIT_DEFAULTS__SCHEMA; - } - - public boolean supportsDefault() { - return false; - } - - public int defaultFeatureId() { - throw new UnsupportedOperationException(); - } - - public String defaultItem() { - return JptUiXmlMessages.PersistenceUnitMetadataSection_SchemaDefault; - } - - public String getString() { - return this.persistenceUnitDefaults.getSchema(); - } - - public void setString(String newSchema) { - this.persistenceUnitDefaults.setSchema(newSchema); - } - - public EObject wrappedObject() { - return this.persistenceUnitDefaults; - } - } - - private class CatalogHolder extends XmlEObject implements StringHolder { - private PersistenceUnitDefaults persistenceUnitDefaults; - CatalogHolder(PersistenceUnitDefaults persistenceUnitDefaults) { - super(); - this.persistenceUnitDefaults = persistenceUnitDefaults; - } - - public Class featureClass() { - return PersistenceUnitDefaults.class; - } - - public int featureId() { - return OrmPackage.PERSISTENCE_UNIT_DEFAULTS__CATALOG; - } - - public boolean supportsDefault() { - return false; - } - - public int defaultFeatureId() { - throw new UnsupportedOperationException(); - } - - public String defaultItem() { - return JptUiXmlMessages.PersistenceUnitMetadataSection_CatalogDefault; - } - - public String getString() { - return this.persistenceUnitDefaults.getCatalog(); - } - - public void setString(String string) { - this.persistenceUnitDefaults.setCatalog(string); - } - - public EObject wrappedObject() { - return this.persistenceUnitDefaults; - } - - } - - @Override - protected void doPopulate() { - this.xmlMappingMetadataCompleteCheckBox.populate(); - this.xmlSchemaChooser.populate(); - this.xmlCatalogChooser.populate(); - this.accessComboViewer.populate(); - this.cascadePersistCheckBox.populate(); - } - - @Override - public void dispose() { - this.xmlMappingMetadataCompleteCheckBox.dispose(); - this.xmlSchemaChooser.dispose(); - this.xmlCatalogChooser.dispose(); - this.accessComboViewer.dispose(); - this.cascadePersistCheckBox.dispose(); - super.dispose(); - } - - public Section getSection() { - return this.section; - } - - @Override - public Control getControl() { - return getSection(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlDetailsProvider.java index 0bcd70ded8..5bb58d7e8a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlDetailsProvider.java @@ -1,47 +1,60 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.xml.details; -import org.eclipse.jpt.core.internal.JptCorePlugin; -import org.eclipse.jpt.core.internal.content.orm.IXmlContentNodes; +import org.eclipse.jpt.core.internal.context.base.IJpaContextNode; +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType; import org.eclipse.jpt.ui.internal.details.IJpaDetailsPage; import org.eclipse.jpt.ui.internal.details.IJpaDetailsProvider; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class XmlDetailsProvider - implements IJpaDetailsProvider +/** + * This provider is responsible for creating the <code>IJpaDetailsPage</code> + * when the information comes from the XML file (either from the persistence + * configuration or from the Mappings Descriptor). + * + * @version 2.0 + * @since 1.0 + */ +public class XmlDetailsProvider + implements IJpaDetailsProvider { + /** + * Creates a new <code>XmlDetailsProvider</code>. + */ public XmlDetailsProvider() { super(); } - - public String fileContentType() { - return JptCorePlugin.ORM_XML_CONTENT_TYPE; - } - - public IJpaDetailsPage buildDetailsPage( - Composite parentComposite, Object contentNodeId, TabbedPropertySheetWidgetFactory widgetFactory) { - if (contentNodeId.equals(IXmlContentNodes.ENTITY_MAPPINGS_ID)) { - return new XmlEntityMappingsDetailsPage(parentComposite, widgetFactory); + + /* + * (non-Javadoc) + */ + public IJpaDetailsPage<? extends IJpaContextNode> buildDetailsPage( + Composite parent, + Object contentNodeId, + TabbedPropertySheetWidgetFactory widgetFactory) { + + if (contentNodeId instanceof EntityMappings) { + return new XmlEntityMappingsDetailsPage(parent, widgetFactory); } - else if (contentNodeId.equals(IXmlContentNodes.PERSISTENT_TYPE_ID)) { - return new XmlPersistentTypeDetailsPage(parentComposite, widgetFactory); + + if (contentNodeId instanceof XmlPersistentType) { + return new XmlPersistentTypeDetailsPage(parent, widgetFactory); } - else if (contentNodeId.equals(IXmlContentNodes.PERSISTENT_ATTRIBUTE_ID)) { - return new XmlPersistentAttributeDetailsPage(parentComposite, widgetFactory); + + if (contentNodeId instanceof XmlPersistentAttribute) { + return new XmlPersistentAttributeDetailsPage(parent, widgetFactory); } - + return null; } - - public void dispose() { - // no op ... for now - } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlEntityMappingsDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlEntityMappingsDetailsPage.java index b70bde8825..1f030753b0 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlEntityMappingsDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlEntityMappingsDetailsPage.java @@ -1,274 +1,245 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.xml.details; -import org.eclipse.emf.common.command.BasicCommandStack; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.AccessType; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.jpt.core.internal.XmlEObject; -import org.eclipse.jpt.core.internal.content.orm.EntityMappings; -import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; +import org.eclipse.jpt.core.internal.context.base.AccessType; +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; +import org.eclipse.jpt.core.internal.context.orm.PersistenceUnitMetadata; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; import org.eclipse.jpt.ui.internal.details.BaseJpaDetailsPage; -import org.eclipse.jpt.ui.internal.mappings.details.StringWithDefaultChooser; -import org.eclipse.jpt.ui.internal.mappings.details.StringWithDefaultChooser.StringHolder; +import org.eclipse.jpt.ui.internal.widgets.EnumComboViewer; import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; -import org.eclipse.jpt.ui.internal.xml.details.AccessTypeComboViewer.AccessHolder; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.IWorkbenchHelpSystem; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class XmlEntityMappingsDetailsPage extends BaseJpaDetailsPage +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------ | + * | Package: | |v| | + * | ------------------------------------------------------------ | + * | ------------------------------------------------------------ | + * | Schema: | |v| | + * | ------------------------------------------------------------ | + * | ------------------------------------------------------------ | + * | Catalog: | |v| | + * | ------------------------------------------------------------ | + * | ------------------------------------------------------------ | + * | Access Type: | |v| | + * | ------------------------------------------------------------ | + * | | + * | ------------------------------------------------------------------------- | + * | | | | + * | | PersistenceUnitMetadataComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see EntityMappings + * @see XmlEntityMappingsDetailsPage - The parent container + * @see PersistenceUnitMetadataComposite + * + * @version 2.0 + * @since 2.0 + */ +public class XmlEntityMappingsDetailsPage extends BaseJpaDetailsPage<EntityMappings> { - private EntityMappings entityMappings; - - private XmlPackageChooser xmlPackageChooser; - - private StringWithDefaultChooser xmlSchemaChooser; - - private StringWithDefaultChooser xmlCatalogChooser; - - private AccessTypeComboViewer accessComboViewer; - - private PersistenceUnitMetadataSection persistenceUnitMetadataSection; - - public XmlEntityMappingsDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, new BasicCommandStack(), widgetFactory); - } + /** + * Creates a new <code>XmlEntityMappingsDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public XmlEntityMappingsDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { - @Override - protected void initializeLayout(Composite composite) { - IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); - GridLayout layout = new GridLayout(2, false); - layout.horizontalSpacing = 6; - composite.setLayout(layout); - - GridData gridData; - - CommonWidgets.buildPackageLabel(composite, getWidgetFactory()); - - this.xmlPackageChooser = CommonWidgets.buildXmlPackageChooser(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.xmlPackageChooser.getControl().setLayoutData(gridData); - helpSystem.setHelp(xmlPackageChooser.getControl(), IJpaHelpContextIds.ENTITY_ORM_PACKAGE); - - - CommonWidgets.buildSchemaLabel(composite, getWidgetFactory()); - - this.xmlSchemaChooser = CommonWidgets.buildSchemaChooser(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.xmlSchemaChooser.getCombo().setLayoutData(gridData); - helpSystem.setHelp(xmlSchemaChooser.getControl(), IJpaHelpContextIds.ENTITY_ORM_SCHEMA); - - - CommonWidgets.buildCatalogLabel(composite, getWidgetFactory()); - - this.xmlCatalogChooser = CommonWidgets.buildCatalogChooser(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.xmlCatalogChooser.getCombo().setLayoutData(gridData); - helpSystem.setHelp(xmlCatalogChooser.getControl(), IJpaHelpContextIds.ENTITY_ORM_CATALOG); - - - CommonWidgets.buildAccessLabel(composite, getWidgetFactory()); - - this.accessComboViewer = CommonWidgets.buildAccessTypeComboViewer(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.accessComboViewer.getControl().setLayoutData(gridData); - helpSystem.setHelp(accessComboViewer.getControl(), IJpaHelpContextIds.ENTITY_ORM_ACCESS); - - this.persistenceUnitMetadataSection = new PersistenceUnitMetadataSection(composite, this.commandStack, getWidgetFactory()); - - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalSpan = 2; - this.persistenceUnitMetadataSection.getSection().setLayoutData(gridData); + super(parent, widgetFactory); } - - @Override - protected void doPopulate(IJpaContentNode contentNode) { - this.entityMappings = (EntityMappings) contentNode; - this.xmlPackageChooser.populate(this.entityMappings); - this.xmlSchemaChooser.populate(new SchemaHolder(this.entityMappings)); - this.xmlCatalogChooser.populate(new CatalogHolder(this.entityMappings)); - this.accessComboViewer.populate(new MyAccessHolder(this.entityMappings)); - if (this.entityMappings != null) { - this.persistenceUnitMetadataSection.populate(this.entityMappings.getPersistenceUnitMetadata()); - } - else { - this.persistenceUnitMetadataSection.populate(null); - } - } + private EnumComboViewer<EntityMappings, AccessType> buildAccessTypeCombo(Composite container) { - @Override - protected void doPopulate() { - this.xmlPackageChooser.populate(); - this.xmlSchemaChooser.populate(); - this.xmlCatalogChooser.populate(); - this.accessComboViewer.populate(); - this.persistenceUnitMetadataSection.populate(); - } - - @Override - public void dispose() { - this.xmlPackageChooser.dispose(); - this.xmlSchemaChooser.dispose(); - this.xmlCatalogChooser.dispose(); - this.accessComboViewer.dispose(); - this.persistenceUnitMetadataSection.dispose(); - super.dispose(); - } - - @Override - protected void engageListeners() { - } - - @Override - protected void disengageListeners() { + return new EnumComboViewer<EntityMappings, AccessType>(this, container) { + @Override + protected AccessType[] choices() { + return AccessType.values(); + } + + @Override + protected AccessType defaultValue() { + return subject().getDefaultAccess(); + } + + @Override + protected String displayString(AccessType value) { + return buildDisplayString( + JptUiXmlMessages.class, + XmlEntityMappingsDetailsPage.this, + value + ); + } + + @Override + protected AccessType getValue() { + return subject().getAccess(); + } + + @Override + protected String propertyName() { + return EntityMappings.SPECIFIED_ACCESS_PROPERTY; + } + + @Override + protected void setValue(AccessType value) { + subject().setSpecifiedAccess(value); + } + }; } - - private class MyAccessHolder extends XmlEObject implements AccessHolder{ - - private EntityMappingsInternal entityMappings; - MyAccessHolder(EntityMappings entityMappings) { - super(); - this.entityMappings = (EntityMappingsInternal) entityMappings; - } - public void setAccess(AccessType accessType) { - entityMappings.setSpecifiedAccess(accessType); - } - - public AccessType getAccess() { - return entityMappings.getSpecifiedAccess(); - } - - public Class featureClass() { - return EntityMappingsInternal.class; - } - - public int featureId() { - return OrmPackage.ENTITY_MAPPINGS_INTERNAL__SPECIFIED_ACCESS; - } - - public EObject wrappedObject() { - return this.entityMappings; - } - + private EnumComboViewer<EntityMappings, String> buildCatalogComboViewer(Composite container) { + + return new EnumComboViewer<EntityMappings, String>(this, container) { + @Override + protected String[] choices() { + return new String[0]; + } + + @Override + protected String defaultValue() { + return subject().getDefaultCatalog(); + } + + @Override + protected String displayString(String value) { + return value; + } + + @Override + protected String getValue() { + return subject().getSpecifiedCatalog(); + } + + @Override + protected String propertyName() { + return EntityMappings.SPECIFIED_CATALOG_PROPERTY; + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedCatalog(value); + } + }; } - - private class SchemaHolder extends XmlEObject implements StringHolder { - private EntityMappingsInternal entityMappings; - SchemaHolder(EntityMappings entityMappings) { - super(); - this.entityMappings = (EntityMappingsInternal) entityMappings; - } - - public Class featureClass() { - return EntityMappingsInternal.class; - } - - public int featureId() { - return OrmPackage.ENTITY_MAPPINGS_INTERNAL__SPECIFIED_SCHEMA; - } - - public boolean supportsDefault() { - return true; - } - - public int defaultFeatureId() { - return OrmPackage.ENTITY_MAPPINGS_INTERNAL__DEFAULT_SCHEMA; - } - - public String defaultItem() { - String defaultSchema = this.entityMappings.getDefaultSchema(); - if (defaultSchema != null) { - return NLS.bind(JptUiXmlMessages.XMLEntityMappingsPage_SchemaDefault, defaultSchema); + + private PropertyValueModel<PersistenceUnitMetadata> buildPersistentUnitMetadaHolder() { + return new TransformationPropertyValueModel<EntityMappings, PersistenceUnitMetadata>(getSubjectHolder()) { + @Override + protected PersistenceUnitMetadata transform_(EntityMappings value) { + return value.getPersistenceUnitMetadata(); } - return JptUiXmlMessages.XMLEntityMappingsPage_SchemaNoDefaultSpecified; - } - - public String getString() { - return this.entityMappings.getSpecifiedSchema(); - } - - public void setString(String newSchema) { - this.entityMappings.setSpecifiedSchema(newSchema); - } - - public EObject wrappedObject() { - return this.entityMappings; - } + }; } - - private class CatalogHolder extends XmlEObject implements StringHolder { - private EntityMappingsInternal entityMappings; - CatalogHolder(EntityMappings entityMappings) { - super(); - this.entityMappings = (EntityMappingsInternal) entityMappings; - } - - public Class featureClass() { - return EntityMappingsInternal.class; - } - - public int featureId() { - return OrmPackage.ENTITY_MAPPINGS_INTERNAL__SPECIFIED_CATALOG; - } - - public boolean supportsDefault() { - return true; - } - - public int defaultFeatureId() { - return OrmPackage.ENTITY_MAPPINGS_INTERNAL__DEFAULT_CATALOG; - } - - public String defaultItem() { - String defaultCatalog = this.entityMappings.getDefaultCatalog(); - if (defaultCatalog != null) { - return NLS.bind(JptUiXmlMessages.XMLEntityMappingsPage_CatalogDefault, defaultCatalog); + + private EnumComboViewer<EntityMappings, String> buildSchemaComboViewer(Composite container) { + + return new EnumComboViewer<EntityMappings, String>(this, container) { + @Override + protected String[] choices() { + return new String[0]; + } + + @Override + protected String defaultValue() { + return subject().getDefaultSchema(); + } + + @Override + protected String displayString(String value) { + return value; + } + + @Override + protected String getValue() { + return subject().getSpecifiedSchema(); + } + + @Override + protected String propertyName() { + return EntityMappings.SPECIFIED_SCHEMA_PROPERTY; } - return JptUiXmlMessages.XMLEntityMappingsPage_CatalogNoDefaultSpecified; - } - - public String getString() { - return this.entityMappings.getSpecifiedCatalog(); - } - - public void setString(String newCatalog) { - this.entityMappings.setSpecifiedCatalog(newCatalog); - } - - public EObject wrappedObject() { - return this.entityMappings; - } + + @Override + protected void setValue(String value) { + subject().setSpecifiedSchema(value); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Package widgets + XmlPackageChooser xmlCatalogChooser = new XmlPackageChooser( + this, + container + ); + + buildLabeledComposite( + container, + JptUiXmlMessages.XmlEntityMappingsDetailsPage_package, + xmlCatalogChooser.getControl(), + IJpaHelpContextIds.ENTITY_ORM_PACKAGE + ); + + // Schema widgets + EnumComboViewer<EntityMappings, String> schemaComboViewer = + buildSchemaComboViewer(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.XmlSchemaChooser_SchemaChooser, + schemaComboViewer.getControl(), + IJpaHelpContextIds.ENTITY_ORM_SCHEMA + ); + + // Catalog widgets + EnumComboViewer<EntityMappings, String> catalogComboViewer = + buildCatalogComboViewer(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.XmlCatalogChooser_CatalogChooser, + catalogComboViewer.getControl(), + IJpaHelpContextIds.ENTITY_ORM_CATALOG + ); + + // Access Type widgets + EnumComboViewer<EntityMappings, AccessType> accessTypeComposite = + buildAccessTypeCombo(container); + + buildLabeledComposite( + container, + JptUiXmlMessages.PersistentTypePage_AccessLabel, + accessTypeComposite.getControl(), + IJpaHelpContextIds.ENTITY_ORM_ACCESS + ); + + // Persistence Unit Metadata widgets + new PersistenceUnitMetadataComposite( + this, + buildPersistentUnitMetadaHolder(), + container + ); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaAttributeChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaAttributeChooser.java index 8f58be68b4..a2af9ceac6 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaAttributeChooser.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaAttributeChooser.java @@ -1,55 +1,67 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.xml.details; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; +import org.eclipse.jpt.core.internal.context.orm.XmlAttributeMapping; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.resource.orm.AttributeMapping; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class XmlJavaAttributeChooser extends BaseJpaController +/** + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public class XmlJavaAttributeChooser extends AbstractFormPane<XmlAttributeMapping<? extends AttributeMapping>> { - private XmlPersistentAttribute attribute; - private Adapter persistentAttributeListener; - private Text text; - - - public XmlJavaAttributeChooser(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildPersistentAttributeListener(); + + /** + * Creates a new <code>XmlJavaAttributeChooser</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public XmlJavaAttributeChooser(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends XmlAttributeMapping<? extends AttributeMapping>> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); } - - - private void buildPersistentAttributeListener() { - this.persistentAttributeListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - persistentAttributeChanged(notification); - } - }; + + + private XmlPersistentAttribute attribute() { + return (subject() != null) ? subject().persistentAttribute() : null; } - + + /* + * (non-Javadoc) + */ @Override - protected void buildWidget(Composite parent) { - text = getWidgetFactory().createText(parent, ""); + public void doPopulate() { + super.doPopulate(); + populateText(); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + text = buildText(container); text.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { @@ -57,77 +69,35 @@ public class XmlJavaAttributeChooser extends BaseJpaController } }); } - - private void textModified(ModifyEvent e) { - if (isPopulating()) { - return; - } - - String text = ((Text) e.getSource()).getText(); - attribute.setName(text); - - // TODO Does this need to be done? - //this.editingDomain.getCommandStack().execute(SetCommand.create(this.editingDomain, this.entity, MappingsPackage.eINSTANCE.getEntity_SpecifiedName(), text)); - } - - private void persistentAttributeChanged(Notification notification) { - if (notification.getFeatureID(XmlAttributeMapping.class) == - OrmPackage.XML_PERSISTENT_ATTRIBUTE__NAME) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (attribute != null) { - attribute.eAdapters().add(persistentAttributeListener); - } - } - - @Override - protected void disengageListeners() { - if (attribute != null) { - attribute.eAdapters().remove(persistentAttributeListener); - } - } - - @Override - public void doPopulate(EObject obj) { - attribute = (obj == null) ? null : ((XmlAttributeMapping) obj).getPersistentAttribute(); - populateText(); - } - - @Override - protected void doPopulate() { - populateText(); - } - + private void populateText() { - if (attribute == null) { + if (attribute() == null) { text.clearSelection(); return; } - - String name = attribute.getName(); - + + String name = attribute().getName(); + if (name == null) { name = ""; } setTextData(name); } - + private void setTextData(String textData) { if (! textData.equals(text.getText())) { text.setText(textData); } } - - public Control getControl() { - return text; + + private void textModified(ModifyEvent e) { + if (isPopulating()) { + return; + } + String text = ((Text) e.getSource()).getText(); + subject().setName(text); + + // TODO Does this need to be done? + //this.editingDomain.getCommandStack().execute(SetCommand.create(this.editingDomain, this.entity, MappingsPackage.eINSTANCE.getEntity_SpecifiedName(), text)); } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaClassChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaClassChooser.java index 3485245d26..54410df47f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaClassChooser.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlJavaClassChooser.java @@ -1,20 +1,15 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.xml.details; import org.eclipse.core.resources.IProject; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragmentRoot; @@ -28,12 +23,12 @@ import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionP import org.eclipse.jdt.ui.IJavaElementSearchConstants; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentType; -import org.eclipse.jpt.core.internal.content.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.context.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.resource.orm.TypeMapping; import org.eclipse.jpt.ui.internal.JptUiPlugin; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -43,8 +38,6 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.SelectionDialog; @@ -52,41 +45,55 @@ import org.eclipse.ui.progress.IProgressService; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; //TODO possibly help the user and if they have chosen a package at the entity-mappings level -//only insert the class name in the xml file if they choose a class from the package. +//only insert the class name in the xml file if they choose a class from the package. //Not sure if this should be driven by the UI or by ui api in the model -public class XmlJavaClassChooser extends BaseJpaController -{ - private XmlPersistentType persistentType; - private Adapter persistentTypeListener; - +public class XmlJavaClassChooser extends AbstractFormPane<XmlTypeMapping<?>> { + private Composite composite; private Text text; private JavaTypeCompletionProcessor javaTypeCompletionProcessor; - - public XmlJavaClassChooser(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildPersistentTypeListener(); + + /** + * Creates a new <code>XmlJavaClassChooser</code>. + * + * @param parentPane The parent controller of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public XmlJavaClassChooser(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends XmlTypeMapping<? extends TypeMapping>> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); } - - - private void buildPersistentTypeListener() { - persistentTypeListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - persistentTypeChanged(notification); - } - }; + + /** + * Creates a new <code>XmlJavaClassChooser</code>. + * + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public XmlJavaClassChooser(PropertyValueModel<? extends XmlTypeMapping<? extends TypeMapping>> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); } - + + /* + * (non-Javadoc) + */ @Override - protected void buildWidget(Composite parent) { - this.composite = getWidgetFactory().createComposite(parent); + protected void initializeLayout(Composite container) { + this.composite = getWidgetFactory().createComposite(container); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0; gridLayout.marginWidth = 1; gridLayout.numColumns = 2; this.composite.setLayout(gridLayout); - - text = getWidgetFactory().createText(this.composite, ""); + + text = getWidgetFactory().createText(this.composite); GridData data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; @@ -102,7 +109,7 @@ public class XmlJavaClassChooser extends BaseJpaController this.javaTypeCompletionProcessor = new JavaTypeCompletionProcessor(false, false); ControlContentAssistHelper.createTextContentAssistant(this.text, this.javaTypeCompletionProcessor); - + Button browseButton = getWidgetFactory().createButton(this.composite, "Browse...", SWT.FLAT); data = new GridData(); browseButton.setLayoutData(data); @@ -124,28 +131,24 @@ public class XmlJavaClassChooser extends BaseJpaController } private void textModified(ModifyEvent e) { - if (isPopulating()) { - return; - } - String text = ((Text) e.getSource()).getText(); - persistentType.setClass(text); - + subject().setClass(text); + // TODO Does this need to be done? //this.editingDomain.getCommandStack().execute(SetCommand.create(this.editingDomain, this.entity, MappingsPackage.eINSTANCE.getEntity_SpecifiedName(), text)); } - - + + protected IType chooseType() { IPackageFragmentRoot root= getPackageFragmentRoot(); if (root == null) { return null; - } - + } + IJavaElement[] elements= new IJavaElement[] { root.getJavaProject() }; IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements); IProgressService service = PlatformUI.getWorkbench().getProgressService(); - + SelectionDialog typeSelectionDialog; try { typeSelectionDialog = JavaUI.createTypeDialog(this.text.getShell(), service, scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, getType()); @@ -154,21 +157,21 @@ public class XmlJavaClassChooser extends BaseJpaController JptUiPlugin.log(e); throw new RuntimeException(e); } - typeSelectionDialog.setTitle(JptUiXmlMessages.XmlJavaClassChooser_XmlJavaClassDialog_title); - typeSelectionDialog.setMessage(JptUiXmlMessages.XmlJavaClassChooser_XmlJavaClassDialog_message); + typeSelectionDialog.setTitle(JptUiXmlMessages.XmlJavaClassChooser_XmlJavaClassDialog_title); + typeSelectionDialog.setMessage(JptUiXmlMessages.XmlJavaClassChooser_XmlJavaClassDialog_message); if (typeSelectionDialog.open() == Window.OK) { return (IType) typeSelectionDialog.getResult()[0]; } return null; } - + private String getType() { return this.text.getText(); } - + private IPackageFragmentRoot getPackageFragmentRoot() { - IProject project = this.persistentType.getJpaProject().project(); + IProject project = this.subject().jpaProject().project(); IJavaProject root = JavaCore.create(project); try { return root.getAllPackageFragmentRoots()[0]; @@ -179,57 +182,25 @@ public class XmlJavaClassChooser extends BaseJpaController return null; } - private void persistentTypeChanged(Notification notification) { - if (notification.getFeatureID(XmlPersistentType.class) == - OrmPackage.XML_PERSISTENT_TYPE__CLASS) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (persistentType != null) { - persistentType.eAdapters().add(persistentTypeListener); - } - } - - @Override - protected void disengageListeners() { - if (persistentType != null) { - persistentType.eAdapters().remove(persistentTypeListener); - } - } - - @Override - public void doPopulate(EObject obj) { - persistentType = (obj == null) ? null : ((XmlTypeMapping) obj).getPersistentType(); - populateText(); - } - @Override protected void doPopulate() { + super.doPopulate(); populateText(); } - + private void populateText() { - if (persistentType == null) { + if (this.subject() == null) { text.clearSelection(); return; } - + IPackageFragmentRoot root = getPackageFragmentRoot(); if (root != null) { this.javaTypeCompletionProcessor.setPackageFragment(root.getPackageFragment("")); } - - String javaClass = persistentType.getClass_(); - + String javaClass = this.subject().getClass_(); + if (javaClass == null) { setTextData(""); } @@ -237,14 +208,10 @@ public class XmlJavaClassChooser extends BaseJpaController setTextData(javaClass); } } - + private void setTextData(String textData) { if (! textData.equals(text.getText())) { text.setText(textData); } } - - public Control getControl() { - return this.composite; - } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlMappingMetadataCompleteCheckBox.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlMappingMetadataCompleteCheckBox.java deleted file mode 100644 index 5cdd03801e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlMappingMetadataCompleteCheckBox.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.details; - -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; -import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -public class XmlMappingMetadataCompleteCheckBox extends BaseJpaController -{ - private PersistenceUnitMetadata persistenceUnitMetadata; - private Adapter persistenceUnitMetadataListener; - - private Button button; - - - public XmlMappingMetadataCompleteCheckBox(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildPeristenceUnitMetadataListener(); - } - - private void buildPeristenceUnitMetadataListener() { - this.persistenceUnitMetadataListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - persistenceUnitMetadataChanged(notification); - } - }; - } - - @Override - protected void buildWidget(Composite parent) { - this.button = getWidgetFactory().createButton( - parent, - JptUiXmlMessages.XMLEntityMappingsPage_XmlMappingMetadataCompleteCheckBox, - SWT.CHECK); - - this.button.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - XmlMappingMetadataCompleteCheckBox.this.xmlMappingMetadataCompleteSelectionChanged(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - XmlMappingMetadataCompleteCheckBox.this.xmlMappingMetadataCompleteSelectionChanged(); - } - }); - } - - void xmlMappingMetadataCompleteSelectionChanged() { - boolean xmlMappingMetadataComplete = this.button.getSelection(); - if (this.persistenceUnitMetadata.isXmlMappingMetadataComplete() != xmlMappingMetadataComplete) { - this.persistenceUnitMetadata.setXmlMappingMetadataComplete(xmlMappingMetadataComplete); - } - } - - private void persistenceUnitMetadataChanged(Notification notification) { - if (notification.getFeatureID(PersistenceUnitMetadata.class) == - OrmPackage.PERSISTENCE_UNIT_METADATA__XML_MAPPING_METADATA_COMPLETE) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - populate(); - } - }); - } - } - - @Override - protected void engageListeners() { - if (this.persistenceUnitMetadata != null) { - this.persistenceUnitMetadata.eAdapters().add(this.persistenceUnitMetadataListener); - } - } - - @Override - protected void disengageListeners() { - if (this.persistenceUnitMetadata != null) { - this.persistenceUnitMetadata.eAdapters().remove(this.persistenceUnitMetadataListener); - } - } - - @Override - public void doPopulate(EObject obj) { - this.persistenceUnitMetadata = (PersistenceUnitMetadata) obj; - populateButton(); - } - - @Override - protected void doPopulate() { - populateButton(); - } - - private void populateButton() { - boolean xmlMappingMetadataComplete = false; - if (this.persistenceUnitMetadata != null) { - xmlMappingMetadataComplete = this.persistenceUnitMetadata.isXmlMappingMetadataComplete(); - } - - if (this.button.getSelection() != xmlMappingMetadataComplete) { - this.button.setSelection(xmlMappingMetadataComplete); - } - } - - - @Override - public Control getControl() { - return this.button; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPackageChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPackageChooser.java index 2800947b8b..a1119c2d20 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPackageChooser.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPackageChooser.java @@ -1,20 +1,16 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. + * 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.ui.internal.xml.details; import org.eclipse.core.resources.IProject; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; @@ -26,12 +22,10 @@ import org.eclipse.jdt.ui.JavaElementLabelProvider; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.XmlEObject; -import org.eclipse.jpt.core.internal.content.orm.EntityMappings; -import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; +import org.eclipse.jpt.core.internal.context.orm.EntityMappings; +import org.eclipse.jpt.core.internal.resource.orm.OrmPackage; import org.eclipse.jpt.ui.internal.JptUiPlugin; -import org.eclipse.jpt.ui.internal.details.BaseJpaController; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; @@ -42,59 +36,58 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class XmlPackageChooser extends BaseJpaController +/** + * + * @version 2.0 + * @since 2.0 + */ +public class XmlPackageChooser extends AbstractFormPane<EntityMappings> { - private EntityMappingsInternal entityMappings; - private Adapter entityMappingsListener; - private IContentAssistProcessor contentAssistProcessor; - - private Composite composite; + private IContentAssistProcessor contentAssistProcessor; + private Composite composite; private Text text; - - - public XmlPackageChooser(Composite parent, CommandStack theCommandStack, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, theCommandStack, widgetFactory); - buildSchemaHolderListener(); - } - - - private void buildSchemaHolderListener() { - this.entityMappingsListener = new AdapterImpl() { - public void notifyChanged(Notification notification) { - entityMappingsChanged(notification); - } - }; + + /** + * Creates a new <code>XmlPackageChooser</code>. + * + * @param parentPane The parent controller of this one + * @param parent The parent container + */ + public XmlPackageChooser(AbstractFormPane<? extends EntityMappings> parentPane, + Composite parent) { + + super(parentPane, parent); } - + + /* + * (non-Javadoc) + */ @Override - protected void buildWidget(Composite parent) { - this.composite = getWidgetFactory().createComposite(parent); - GridLayout gridLayout = new GridLayout(); - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 1; - gridLayout.numColumns = 2; - this.composite.setLayout(gridLayout); - this.text = getWidgetFactory().createText(this.composite, ""); + protected void initializeLayout(Composite container) { + this.composite = getWidgetFactory().createComposite(container); + GridLayout gridLayout = new GridLayout(); + gridLayout.marginHeight = 0; + gridLayout.marginWidth = 1; + gridLayout.numColumns = 2; + this.composite.setLayout(gridLayout); + this.text = getWidgetFactory().createText(this.composite); GridData data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - this.text.setLayoutData(data); + data.grabExcessHorizontalSpace = true; + data.horizontalAlignment = GridData.FILL; + this.text.setLayoutData(data); this.contentAssistProcessor = new JavaPackageCompletionProcessor(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_ROOT)); ControlContentAssistHelper.createTextContentAssistant(this.text, this.contentAssistProcessor); - this.text.addModifyListener( - new ModifyListener() { - public void modifyText(ModifyEvent e) { - textModified(e); - } - }); - + this.text.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + textModified(e); + } + }); + Button browseButton = getWidgetFactory().createButton(this.composite, "Browse...", SWT.FLAT); data = new GridData(); browseButton.setLayoutData(data); @@ -113,23 +106,19 @@ public class XmlPackageChooser extends BaseJpaController } }); } - + private void textModified(ModifyEvent e) { - if (isPopulating()) { - return; - } - String text = ((Text) e.getSource()).getText(); - this.entityMappings.setPackage(text); + this.subject().setPackage(text); //TODO set a JEM Package?? //.setJavaClass(JavaRefFactory.eINSTANCE.createClassRef(text)); - + // TODO Does this need to be done? //this.editingDomain.getCommandStack().execute(SetCommand.create(this.editingDomain, this.entity, MappingsPackage.eINSTANCE.getEntity_SpecifiedName(), text)); } - + private void entityMappingsChanged(Notification notification) { - if (notification.getFeatureID(EntityMappings.class) == + if (notification.getFeatureID(EntityMappings.class) == OrmPackage.ENTITY_MAPPINGS__PACKAGE) { Display.getDefault().asyncExec( new Runnable() { @@ -139,34 +128,30 @@ public class XmlPackageChooser extends BaseJpaController }); } } - + @Override protected void engageListeners() { - if (this.entityMappings != null) { - entityMappings.eAdapters().add(this.entityMappingsListener); - } + super.engageListeners(); +// if (this.subject() != null) { +// subject().eAdapters().add(this.entityMappingsListener); +// } } - + @Override protected void disengageListeners() { - if (this.entityMappings != null) { - this.entityMappings.eAdapters().remove(this.entityMappingsListener); - } + super.disengageListeners(); +// if (this.subject() != null) { +// this.subject().eAdapters().remove(this.entityMappingsListener); +// } } - - @Override - public void doPopulate(EObject obj) { - this.entityMappings = (EntityMappingsInternal) obj; - populateText(); - } - + @Override protected void doPopulate() { populateText(); } - + private void populateText() { - if (entityMappings == null) { + if (subject() == null) { text.clearSelection(); return; } @@ -175,9 +160,9 @@ public class XmlPackageChooser extends BaseJpaController if (root != null) { ((JavaPackageCompletionProcessor)this.contentAssistProcessor).setPackageFragmentRoot(root); } - - String package_ = this.entityMappings.getPackage(); - + + String package_ = this.subject().getPackage(); + if (package_ == null) { setTextData(""); } @@ -185,9 +170,9 @@ public class XmlPackageChooser extends BaseJpaController setTextData(package_); } } - + private IPackageFragmentRoot getPackageFragmentRoot() { - IProject project = ((XmlEObject) this.entityMappings).getJpaProject().project(); + IProject project = subject().jpaProject().project(); IJavaProject root = JavaCore.create(project); try { return root.getAllPackageFragmentRoots()[0]; @@ -197,30 +182,25 @@ public class XmlPackageChooser extends BaseJpaController } return null; } - + private void setTextData(String textData) { if (! textData.equals(text.getText())) { text.setText(textData); } } - - @Override - public Control getControl() { - return this.composite; - } - + /** - * Opens a selection dialog that allows to select a package. - * + * Opens a selection dialog that allows to select a package. + * * @return returns the selected package or <code>null</code> if the dialog has been canceled. * The caller typically sets the result to the package input field. * <p> * Clients can override this method if they want to offer a different dialog. * </p> - * + * * @since 3.2 */ - protected IPackageFragment choosePackage() { + protected IPackageFragment choosePackage() { SelectionDialog selectionDialog; try { selectionDialog = JavaUI.createPackageDialog(text.getShell(), getPackageFragmentRoot()); @@ -229,8 +209,8 @@ public class XmlPackageChooser extends BaseJpaController JptUiPlugin.log(e); throw new RuntimeException(e); } - selectionDialog.setTitle(JptUiXmlMessages.XmlPackageChooser_PackageDialog_title); - selectionDialog.setMessage(JptUiXmlMessages.XmlPackageChooser_PackageDialog_message); + selectionDialog.setTitle(JptUiXmlMessages.XmlPackageChooser_PackageDialog_title); + selectionDialog.setMessage(JptUiXmlMessages.XmlPackageChooser_PackageDialog_message); selectionDialog.setHelpAvailable(false); IPackageFragment pack= getPackageFragment(); if (pack != null) { @@ -245,8 +225,8 @@ public class XmlPackageChooser extends BaseJpaController /** * Returns the package fragment corresponding to the current input. - * - * @return a package fragment or <code>null</code> if the input + * + * @return a package fragment or <code>null</code> if the input * could not be resolved. */ public IPackageFragment getPackageFragment() { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentAttributeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentAttributeDetailsPage.java index 5e2bd16073..105204cdb3 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentAttributeDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentAttributeDetailsPage.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 ******************************************************************************/ @@ -13,18 +13,11 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.jpt.core.internal.IPersistentAttribute; -import org.eclipse.jpt.core.internal.IPersistentType; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentType; +import org.eclipse.jpt.core.internal.context.base.IAttributeMapping; +import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute; +import org.eclipse.jpt.core.internal.context.orm.XmlAttributeMapping; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentAttribute; +import org.eclipse.jpt.core.internal.resource.orm.AttributeMapping; import org.eclipse.jpt.ui.internal.details.PersistentAttributeDetailsPage; import org.eclipse.jpt.ui.internal.java.details.IAttributeMappingUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.BasicMappingUiProvider; @@ -37,182 +30,161 @@ import org.eclipse.jpt.ui.internal.java.mappings.properties.OneToManyMappingUiPr import org.eclipse.jpt.ui.internal.java.mappings.properties.OneToOneMappingUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.TransientMappingUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.VersionMappingUiProvider; +import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.swt.SWT; 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.swt.widgets.Display; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class XmlPersistentAttributeDetailsPage - extends PersistentAttributeDetailsPage +/** + * The default implementation of the details page used for the XML persistent + * attribute. + * + * @see IPersistentAttribute + * + * @version 2.0 + * @since 2.0 + */ +@SuppressWarnings("nls") +public class XmlPersistentAttributeDetailsPage extends PersistentAttributeDetailsPage<XmlPersistentAttribute> { + private List<IAttributeMappingUiProvider<? extends IAttributeMapping>> attributeMappingUiProviders; private XmlJavaAttributeChooser javaAttributeChooser; - - private Adapter persistentTypeListener; - - private IPersistentType persistentType; - - private List<IAttributeMappingUiProvider> attributeMappingUiProviders; - - public XmlPersistentAttributeDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { - super(parent, widgetFactory); - buildPersistentTypeListener(); - } - - private void buildPersistentTypeListener() { - this.persistentTypeListener = new AdapterImpl() { - @Override - public void notifyChanged(Notification notification) { - persistentTypeChanged(notification); - } - }; - } - - void persistentTypeChanged(Notification notification) { - if (notification.getFeatureID(XmlPersistentType.class) == - OrmPackage.XML_PERSISTENT_TYPE__SPECIFIED_ATTRIBUTE_MAPPINGS) { - Display.getDefault().asyncExec( - new Runnable() { - public void run() { - updateEnbabledState(); - } - }); - } - } - @Override - public ListIterator<IAttributeMappingUiProvider> attributeMappingUiProviders() { - if (this.attributeMappingUiProviders == null) { - this.attributeMappingUiProviders = new ArrayList<IAttributeMappingUiProvider>(); - this.addAttributeMappingUiProvidersTo(this.attributeMappingUiProviders); - } - return new CloneListIterator<IAttributeMappingUiProvider>(this.attributeMappingUiProviders); + /** + * Creates a new <code>XmlPersistentAttributeDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public XmlPersistentAttributeDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + super(parent, widgetFactory); } - protected void addAttributeMappingUiProvidersTo(List<IAttributeMappingUiProvider> providers) { + protected void addAttributeMappingUiProvidersTo(List<IAttributeMappingUiProvider<? extends IAttributeMapping>> providers) { providers.add(BasicMappingUiProvider.instance()); providers.add(EmbeddedMappingUiProvider.instance()); providers.add(EmbeddedIdMappingUiProvider.instance()); - providers.add(IdMappingUiProvider.instance()); - providers.add(ManyToManyMappingUiProvider.instance()); - providers.add(ManyToOneMappingUiProvider.instance()); - providers.add(OneToManyMappingUiProvider.instance()); + providers.add(IdMappingUiProvider.instance()); + providers.add(ManyToManyMappingUiProvider.instance()); + providers.add(ManyToOneMappingUiProvider.instance()); + providers.add(OneToManyMappingUiProvider.instance()); providers.add(OneToOneMappingUiProvider.instance()); providers.add(TransientMappingUiProvider.instance()); providers.add(VersionMappingUiProvider.instance()); } - - @Override - protected ListIterator<IAttributeMappingUiProvider> defaultAttributeMappingUiProviders() { - return EmptyListIterator.instance(); - } - + + /* + * (non-Javadoc) + */ @Override - protected IAttributeMappingUiProvider defaultAttributeMappingUiProvider(String key) { - throw new UnsupportedOperationException("Xml attributeMappings should not be default"); + public ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> attributeMappingUiProviders() { + if (this.attributeMappingUiProviders == null) { + this.attributeMappingUiProviders = new ArrayList<IAttributeMappingUiProvider<? extends IAttributeMapping>>(); + this.addAttributeMappingUiProvidersTo(this.attributeMappingUiProviders); + } + + return new CloneListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>>( + this.attributeMappingUiProviders + ); } - + + /* + * (non-Javadoc) + */ @Override - //bug 192035 - no default mapping option in xml - protected IAttributeMappingUiProvider[] attributeMappingUiProvidersFor(IPersistentAttribute persistentAttribute) { + @SuppressWarnings("unchecked") + protected IAttributeMappingUiProvider<? extends IAttributeMapping>[] attributeMappingUiProvidersFor(IPersistentAttribute persistentAttribute) { + //bug 192035 - no default mapping option in xml return CollectionTools.array(attributeMappingUiProviders(), new IAttributeMappingUiProvider[CollectionTools.size(attributeMappingUiProviders())]); } + /* + * (non-Javadoc) + */ @Override - protected void initializeLayout(Composite composite) { - composite.setLayout(new GridLayout(2, false)); - - GridData gridData; - - CommonWidgets.buildJavaAttributeNameLabel(composite, getWidgetFactory()); - - this.javaAttributeChooser = CommonWidgets.buildJavaAttributeChooser(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.javaAttributeChooser.getControl().setLayoutData(gridData); - - - buildMappingLabel(composite); - - ComboViewer mappingCombo = buildMappingCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - mappingCombo.getCombo().setLayoutData(gridData); - - PageBook book = buildMappingPageBook(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; - book.setLayoutData(gridData); - } - - @Override - protected void engageListeners() { - super.engageListeners(); - if (getAttribute() != null) { - this.persistentType = getAttribute().typeMapping().getPersistentType(); - this.persistentType.eAdapters().add(this.persistentTypeListener); - } + protected IAttributeMappingUiProvider<IAttributeMapping> defaultAttributeMappingUiProvider(String key) { + throw new UnsupportedOperationException("Xml attributeMappings should not be default"); } - + + /* + * (non-Javadoc) + */ @Override - protected void disengageListeners() { - if (this.persistentType != null) { - this.persistentType.eAdapters().remove(this.persistentTypeListener); - this.persistentType = null; - } - super.disengageListeners(); + protected ListIterator<IAttributeMappingUiProvider<? extends IAttributeMapping>> defaultAttributeMappingUiProviders() { + return EmptyListIterator.instance(); } - + + /* + * (non-Javadoc) + */ @Override - protected void doPopulate(IJpaContentNode persistentAttributeNode) { - super.doPopulate(persistentAttributeNode); - if (persistentAttributeNode == null) { - this.javaAttributeChooser.populate(null); - } - else { - XmlAttributeMapping mapping = ((XmlPersistentAttribute) persistentAttributeNode).getMapping(); - this.javaAttributeChooser.populate(mapping); - updateEnbabledState(); - } + public void doDispose() { + this.javaAttributeChooser.dispose(); + super.doDispose(); } - + + /* + * (non-Javadoc) + */ @Override protected void doPopulate() { super.doPopulate(); this.javaAttributeChooser.populate(); updateEnbabledState(); } - - @Override - public void dispose() { - this.javaAttributeChooser.dispose(); - super.dispose(); + + private PropertyValueModel<XmlAttributeMapping<? extends AttributeMapping>> getMappingHolder() { + return new TransformationPropertyValueModel<IPersistentAttribute, XmlAttributeMapping<? extends AttributeMapping>>(getSubjectHolder()) { + @Override + @SuppressWarnings("unchecked") + protected XmlAttributeMapping<? extends AttributeMapping> transform_(IPersistentAttribute value) { + return (XmlAttributeMapping<? extends AttributeMapping>) value.getMapping(); + } + }; } - - public void updateEnbabledState() { - if (getAttribute() == null || getAttribute().eContainer() == null) { - return; - } - boolean enabled = !((XmlPersistentAttribute) getAttribute()).isVirtual(); - updateEnabledState(enabled, getControl()); + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + this.javaAttributeChooser = new XmlJavaAttributeChooser( + this, + getMappingHolder(), + container + ); + + // Entity type widgets + buildLabeledComposite( + container, + JptUiXmlMessages.PersistentAttributePage_javaAttributeLabel, + buildMappingCombo(container).getControl() + ); + + // Properties pane + PageBook attributePane = buildMappingPageBook(container); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.verticalAlignment = SWT.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + + attributePane.setLayoutData(gridData); } - + public void updateEnabledState(boolean enabled, Control control) { control.setEnabled(enabled); if (control instanceof Composite) { @@ -221,4 +193,12 @@ public class XmlPersistentAttributeDetailsPage } } } + + public void updateEnbabledState() { + if (subject() == null || subject().parent() == null) { + return; + } + boolean enabled = !subject().isVirtual(); + updateEnabledState(enabled, getControl()); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentTypeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentTypeDetailsPage.java index 6b76696a37..c04fb1becd 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentTypeDetailsPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/details/XmlPersistentTypeDetailsPage.java @@ -1,9 +1,9 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This + * 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.ui.internal.xml.details; @@ -12,174 +12,130 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.ListIterator; - -import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jpt.core.internal.AccessType; -import org.eclipse.jpt.core.internal.IJpaContentNode; -import org.eclipse.jpt.core.internal.XmlEObject; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentType; -import org.eclipse.jpt.core.internal.content.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.context.base.ITypeMapping; +import org.eclipse.jpt.core.internal.context.orm.XmlPersistentType; +import org.eclipse.jpt.core.internal.context.orm.XmlTypeMapping; +import org.eclipse.jpt.core.internal.resource.orm.TypeMapping; +import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.details.PersistentTypeDetailsPage; import org.eclipse.jpt.ui.internal.java.details.ITypeMappingUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.EmbeddableUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.EntityUiProvider; import org.eclipse.jpt.ui.internal.java.mappings.properties.MappedSuperclassUiProvider; import org.eclipse.jpt.ui.internal.xml.JptUiXmlMessages; -import org.eclipse.jpt.ui.internal.xml.details.AccessTypeComboViewer.AccessHolder; import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -public class XmlPersistentTypeDetailsPage extends PersistentTypeDetailsPage +/** + * The default implementation of the details page used for the XML persistent + * attribute. + * + * @see XmlPersistentType + * + * @version 2.0 + * @since 2.0 + */ +public class XmlPersistentTypeDetailsPage extends PersistentTypeDetailsPage<XmlPersistentType> { - private XmlJavaClassChooser javaClassChooser; - - private MetaDataCompleteComboViewer metadataCompleteComboViewer; - - private AccessTypeComboViewer accessComboViewer; - - //Storing these here instead of querying IJpaPlatformUI, because the orm.xml schema - //is not extensible. We only need to support extensibility for java - private List<ITypeMappingUiProvider> xmlTypeMappingUiProviders; - - public XmlPersistentTypeDetailsPage(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) { + /** + * Storing these here instead of querying IJpaPlatformUI, because the orm.xml + * schema is not extensible. We only need to support extensibility for java. + */ + private List<ITypeMappingUiProvider<? extends ITypeMapping>> xmlTypeMappingUiProviders; + + /** + * Creates a new <code>XmlPersistentTypeDetailsPage</code>. + * + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public XmlPersistentTypeDetailsPage(Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + super(parent, widgetFactory); } - public ListIterator<ITypeMappingUiProvider> typeMappingUiProviders() { - if (this.xmlTypeMappingUiProviders == null) { - this.xmlTypeMappingUiProviders = new ArrayList<ITypeMappingUiProvider>(); - this.addXmlTypeMappingUiProvidersTo(this.xmlTypeMappingUiProviders); - } - return new CloneListIterator<ITypeMappingUiProvider>(this.xmlTypeMappingUiProviders); - } - - protected void addXmlTypeMappingUiProvidersTo(Collection<ITypeMappingUiProvider> providers) { + protected void addXmlTypeMappingUiProvidersTo(Collection<ITypeMappingUiProvider<? extends ITypeMapping>> providers) { providers.add(EntityUiProvider.instance()); - providers.add(MappedSuperclassUiProvider.instance()); - providers.add(EmbeddableUiProvider.instance()); + providers.add(MappedSuperclassUiProvider.instance()); + providers.add(EmbeddableUiProvider.instance()); } - + + private PropertyValueModel<XmlTypeMapping<? extends TypeMapping>> buildMappingHolder() { + return new TransformationPropertyValueModel<XmlPersistentType, XmlTypeMapping<? extends TypeMapping>>(getSubjectHolder()) { + @Override + protected XmlTypeMapping<? extends TypeMapping> transform_(XmlPersistentType value) { + return value.getMapping(); + } + }; + } + + /* + * (non-Javadoc) + */ @Override - protected void initializeLayout(Composite composite) { - composite.setLayout(new GridLayout(2, false)); - - GridData gridData; - - CommonWidgets.buildJavaClassLabel(composite, getWidgetFactory()); - - this.javaClassChooser = CommonWidgets.buildJavaClassChooser(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.javaClassChooser.getControl().setLayoutData(gridData); - - buildTypeMappingLabel(composite); - - ComboViewer typeMappingCombo = buildTypeMappingCombo(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - typeMappingCombo.getCombo().setLayoutData(gridData); - - buildMetadataCompleteLabel(composite); - this.metadataCompleteComboViewer = new MetaDataCompleteComboViewer(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.metadataCompleteComboViewer.getControl().setLayoutData(gridData); - - CommonWidgets.buildAccessLabel(composite, getWidgetFactory()); - this.accessComboViewer = CommonWidgets.buildAccessTypeComboViewer(composite, this.commandStack, getWidgetFactory()); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.BEGINNING; - gridData.grabExcessHorizontalSpace = true; - this.accessComboViewer.getControl().setLayoutData(gridData); + protected void initializeLayout(Composite container) { + + // Java class widgets + XmlJavaClassChooser xmlJavaClassChooser = + new XmlJavaClassChooser(this, buildMappingHolder(), container); + + buildLabeledComposite( + container, + JptUiXmlMessages.PersistentTypePage_javaClassLabel, + xmlJavaClassChooser.getControl() + ); + + // Type Mapping widgets + ComboViewer typeMappingCombo = buildTypeMappingCombo(container); + + buildLabeledComposite( + container, + JptUiMessages.PersistentTypePage_mapAs, + typeMappingCombo.getControl().getParent() + ); + + // Metadata complete widget + MetaDataCompleteComboViewer metadataCompleteComboViewer = + new MetaDataCompleteComboViewer(this, buildMappingHolder(), container); + + buildLabeledComposite( + container, + JptUiXmlMessages.PersistentTypePage_MetadataCompleteLabel, + metadataCompleteComboViewer.getControl() + ); - PageBook typeMappingPageBook = buildTypeMappingPageBook(composite); - gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; + // Access widgets + new AccessTypeComposite(this, buildMappingHolder(), container); + + // Type mapping pane + PageBook typeMappingPageBook = buildTypeMappingPageBook(container); + + GridData gridData = new GridData(); + gridData.horizontalAlignment = SWT.FILL; + gridData.verticalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalSpan = 2; + gridData.grabExcessVerticalSpace = true; + typeMappingPageBook.setLayoutData(gridData); } - - private Label buildMetadataCompleteLabel(Composite parent ) { - return getWidgetFactory().createLabel(parent, JptUiXmlMessages.PersistentTypePage_MetadataCompleteLabel); - } - - @Override - protected void doPopulate(IJpaContentNode persistentTypeNode) { - super.doPopulate(persistentTypeNode); - if (persistentTypeNode == null) { - this.javaClassChooser.populate(null); - this.metadataCompleteComboViewer.populate(null); - this.accessComboViewer.populate(new MyAccessHolder(null)); - } - else { - XmlTypeMapping mapping = ((XmlPersistentType) persistentTypeNode).getMapping(); - this.javaClassChooser.populate(mapping); - this.metadataCompleteComboViewer.populate(mapping); - this.accessComboViewer.populate(new MyAccessHolder(mapping)); - } - } - - @Override - protected void doPopulate() { - super.doPopulate(); - this.javaClassChooser.populate(); - this.metadataCompleteComboViewer.populate(); - this.accessComboViewer.populate(); - } + /* + * (non-Javadoc) + */ @Override - public void dispose() { - this.javaClassChooser.dispose(); - this.metadataCompleteComboViewer.dispose(); - this.accessComboViewer.dispose(); - super.dispose(); - } - - - private class MyAccessHolder extends XmlEObject implements AccessHolder{ - - private XmlTypeMapping xmlTypeMapping; - MyAccessHolder(XmlTypeMapping xmlTypeMapping) { - super(); - this.xmlTypeMapping = xmlTypeMapping; - } - public void setAccess(AccessType accessType) { - xmlTypeMapping.setSpecifiedAccess(accessType); - } - - public AccessType getAccess() { - return xmlTypeMapping.getSpecifiedAccess(); - } - - public Class featureClass() { - return XmlTypeMapping.class; - } - - public int featureId() { - return OrmPackage.XML_TYPE_MAPPING__SPECIFIED_ACCESS; - } - - public EObject wrappedObject() { - return this.xmlTypeMapping; + public ListIterator<ITypeMappingUiProvider<? extends ITypeMapping>> typeMappingUiProviders() { + if (this.xmlTypeMappingUiProviders == null) { + this.xmlTypeMappingUiProviders = new ArrayList<ITypeMappingUiProvider<? extends ITypeMapping>>(); + this.addXmlTypeMappingUiProvidersTo(this.xmlTypeMappingUiProviders); } + return new CloneListIterator<ITypeMappingUiProvider<? extends ITypeMapping>>(this.xmlTypeMappingUiProviders); } - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/EntityMappingsItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/EntityMappingsItemProvider.java deleted file mode 100644 index 171664b153..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/EntityMappingsItemProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.structure; - -import java.util.Collection; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsImages; - -public class EntityMappingsItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public EntityMappingsItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - @Override - public Collection getChildrenFeatures(Object object) { - if (childrenFeatures == null) { - super.getChildrenFeatures(object); - childrenFeatures.add(OrmPackage.Literals.ENTITY_MAPPINGS_INTERNAL__PERSISTENT_TYPES); - } - return childrenFeatures; - } - - @Override - public Object getParent(Object object) { - return null; - } - - @Override - public Object getImage(Object object) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.ENTITY_MAPPINGS); - } - - @Override - public String getText(Object object) { - // TODO - return "EntityMappings"; - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(EntityMappingsInternal.class)) { - case OrmPackage.ENTITY_MAPPINGS_INTERNAL__PERSISTENT_TYPES: - case OrmPackage.ENTITY_MAPPINGS_INTERNAL__TYPE_MAPPINGS: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), true, false)); - return; - } - super.notifyChanged(notification); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/JpaCoreXmlItemProviderAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/JpaCoreXmlItemProviderAdapterFactory.java deleted file mode 100644 index a79c0ffa0b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/JpaCoreXmlItemProviderAdapterFactory.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.structure; - -import java.util.ArrayList; -import java.util.Collection; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.edit.provider.ChangeNotifier; -import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; -import org.eclipse.emf.edit.provider.ComposedAdapterFactory; -import org.eclipse.emf.edit.provider.IChangeNotifier; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.INotifyChangedListener; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.jpt.core.internal.content.orm.util.OrmAdapterFactory; -import org.eclipse.ui.services.IDisposable; - -/** - * This is the factory that is used to provide the interfaces needed to support Viewers. - * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}. - * The adapters also support Eclipse property sheets. - * Note that most of the adapters are shared among multiple instances. - */ -public class JpaCoreXmlItemProviderAdapterFactory - extends OrmAdapterFactory - implements ComposeableAdapterFactory, - IChangeNotifier, - IDisposable -{ - /** - * This keeps track of the root adapter factory that delegates to this adapter factory. - */ - protected ComposedAdapterFactory parentAdapterFactory; - - /** - * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}. - */ - protected IChangeNotifier changeNotifier = new ChangeNotifier(); - - /** - * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}. - */ - protected Collection supportedTypes = new ArrayList(); - - public JpaCoreXmlItemProviderAdapterFactory() { - supportedTypes.add(IEditingDomainItemProvider.class); - supportedTypes.add(IStructuredItemContentProvider.class); - supportedTypes.add(ITreeItemContentProvider.class); - supportedTypes.add(IItemLabelProvider.class); - } - - - protected XmlRootContentNodeItemProvider xmlRootContentNodeItemProvider; - - public Adapter createXmlRootContentNodeAdapter() { - if (xmlRootContentNodeItemProvider == null) { - xmlRootContentNodeItemProvider = new XmlRootContentNodeItemProvider(this); - } - - return xmlRootContentNodeItemProvider; - } - - protected EntityMappingsItemProvider entityMappingsItemProvider; - - /** - * This creates an adapter for a {@link org.eclipse.jpt.core.internal.content.orm.EntityMappingsImpl}. - */ - public Adapter createEntityMappingsAdapter() { - if (entityMappingsItemProvider == null) { - entityMappingsItemProvider = new EntityMappingsItemProvider(this); - } - - return entityMappingsItemProvider; - } - - /** - * This keeps track of the one adapter used for all {@link org.eclipse.jpt.core.internal.content.orm.XmlPersistentType} instances. - */ - protected XmlPersistentTypeItemProvider xmlPersistentTypeItemProvider; - - /** - * This creates an adapter for a {@link org.eclipse.jpt.core.internal.content.orm.XmlPersistentType}. - */ - public Adapter createXmlPersistentTypeAdapter() { - if (xmlPersistentTypeItemProvider == null) { - xmlPersistentTypeItemProvider = new XmlPersistentTypeItemProvider( - this); - } - - return xmlPersistentTypeItemProvider; - } - - /** - * This keeps track of the one adapter used for all {@link org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute} instances. - */ - protected XmlPersistentAttributeItemProvider xmlPersistentAttributeItemProvider; - - /** - * This creates an adapter for a {@link org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute}. - */ - public Adapter createXmlPersistentAttributeAdapter() { - if (xmlPersistentAttributeItemProvider == null) { - xmlPersistentAttributeItemProvider = new XmlPersistentAttributeItemProvider( - this); - } - - return xmlPersistentAttributeItemProvider; - } - - /** - * This returns the root adapter factory that contains this factory. - */ - public ComposeableAdapterFactory getRootAdapterFactory() { - return parentAdapterFactory == null ? this : parentAdapterFactory - .getRootAdapterFactory(); - } - - /** - * This sets the composed adapter factory that contains this factory. - */ - public void setParentAdapterFactory( - ComposedAdapterFactory parentAdapterFactory) { - this.parentAdapterFactory = parentAdapterFactory; - } - - public boolean isFactoryForType(Object type) { - return supportedTypes.contains(type) || super.isFactoryForType(type); - } - - /** - * This implementation substitutes the factory itself as the key for the adapter. - */ - public Adapter adapt(Notifier notifier, Object type) { - return super.adapt(notifier, this); - } - - public Object adapt(Object object, Object type) { - if (isFactoryForType(type)) { - Object adapter = super.adapt(object, type); - if (!(type instanceof Class) - || (((Class) type).isInstance(adapter))) { - return adapter; - } - } - - return null; - } - - /** - * This adds a listener. - */ - public void addListener(INotifyChangedListener notifyChangedListener) { - changeNotifier.addListener(notifyChangedListener); - } - - /** - * This removes a listener. - */ - public void removeListener(INotifyChangedListener notifyChangedListener) { - changeNotifier.removeListener(notifyChangedListener); - } - - /** - * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}. - */ - public void fireNotifyChanged(Notification notification) { - changeNotifier.fireNotifyChanged(notification); - - if (parentAdapterFactory != null) { - parentAdapterFactory.fireNotifyChanged(notification); - } - } - - /** - * This disposes all of the item providers created by this factory. - */ - public void dispose() { - if (xmlRootContentNodeItemProvider != null) - xmlRootContentNodeItemProvider.dispose(); - if (entityMappingsItemProvider != null) - entityMappingsItemProvider.dispose(); - if (xmlPersistentTypeItemProvider != null) - xmlPersistentTypeItemProvider.dispose(); - if (xmlPersistentAttributeItemProvider != null) - xmlPersistentAttributeItemProvider.dispose(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlPersistentAttributeItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlPersistentAttributeItemProvider.java deleted file mode 100644 index e9f4260b1f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlPersistentAttributeItemProvider.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.structure; - -import org.eclipse.draw2d.ImageUtilities; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentAttribute; -import org.eclipse.jpt.core.internal.mappings.IBasic; -import org.eclipse.jpt.core.internal.mappings.IEmbedded; -import org.eclipse.jpt.core.internal.mappings.IEmbeddedId; -import org.eclipse.jpt.core.internal.mappings.IId; -import org.eclipse.jpt.core.internal.mappings.IManyToMany; -import org.eclipse.jpt.core.internal.mappings.IManyToOne; -import org.eclipse.jpt.core.internal.mappings.IOneToMany; -import org.eclipse.jpt.core.internal.mappings.IOneToOne; -import org.eclipse.jpt.core.internal.mappings.ITransient; -import org.eclipse.jpt.core.internal.mappings.IVersion; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsImages; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; - -public class XmlPersistentAttributeItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public XmlPersistentAttributeItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - @Override - public Object getImage(Object object) { - XmlAttributeMapping mapping = ((XmlPersistentAttribute) object).getMapping(); - - Image image; - if (mapping instanceof IBasic) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.BASIC); - } - else if (mapping instanceof IId) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.ID); - } - else if (mapping instanceof IVersion) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.VERSION); - } - else if (mapping instanceof IEmbedded) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.EMBEDDED); - } - else if (mapping instanceof IEmbeddedId) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.EMBEDDED_ID); - } - else if (mapping instanceof IOneToOne) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.ONE_TO_ONE); - } - else if (mapping instanceof IOneToMany) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.ONE_TO_MANY); - } - else if (mapping instanceof IManyToOne) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.MANY_TO_ONE); - } - else if (mapping instanceof IManyToMany) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.MANY_TO_MANY); - } - else if (mapping instanceof ITransient) { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.TRANSIENT); - } - else { - image = JptUiMappingsImages.getImage(JptUiMappingsImages.NULL_ATTRIBUTE_MAPPING); - } - - // apply "ghosting" - if (mapping.isVirtual()) { - Color offwhite = new Color(image.getDevice(), 250, 250, 250); - ImageData imageData = ImageUtilities.createShadedImage(image, offwhite); - image = new Image(image.getDevice(), imageData); - } - - return image; - } - - @Override - public String getText(Object object) { - return ((XmlPersistentAttribute) object).getName(); - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(XmlPersistentAttribute.class)) { - case OrmPackage.XML_PERSISTENT_ATTRIBUTE__MAPPING: - case OrmPackage.XML_PERSISTENT_ATTRIBUTE__NAME: - fireNotifyChanged(new ViewerNotification(notification, notification - .getNotifier(), false, true)); - return; - } - super.notifyChanged(notification); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlPersistentTypeItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlPersistentTypeItemProvider.java deleted file mode 100644 index f87750ae2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlPersistentTypeItemProvider.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.structure; - -import java.util.Collection; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jpt.core.internal.IPersistentType; -import org.eclipse.jpt.core.internal.ITypeMapping; -import org.eclipse.jpt.core.internal.JpaCorePackage; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; -import org.eclipse.jpt.core.internal.content.orm.XmlPersistentType; -import org.eclipse.jpt.core.internal.mappings.IEmbeddable; -import org.eclipse.jpt.core.internal.mappings.IEntity; -import org.eclipse.jpt.core.internal.mappings.IMappedSuperclass; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsImages; - -public class XmlPersistentTypeItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public XmlPersistentTypeItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - - @Override - protected Collection getChildrenFeatures(Object object) { - if (childrenFeatures == null) { - super.getChildrenFeatures(object); - childrenFeatures.add(OrmPackage.Literals.XML_PERSISTENT_TYPE__SPECIFIED_PERSISTENT_ATTRIBUTES); - childrenFeatures.add(OrmPackage.Literals.XML_PERSISTENT_TYPE__VIRTUAL_PERSISTENT_ATTRIBUTES); - } - return childrenFeatures; - } - - @Override - public Object getImage(Object object) { - ITypeMapping mapping = ((IPersistentType) object).getMapping(); - - if (mapping instanceof IEntity) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.ENTITY); - } - else if (mapping instanceof IEmbeddable) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.EMBEDDABLE); - } - else if (mapping instanceof IMappedSuperclass) { - return JptUiMappingsImages.getImage(JptUiMappingsImages.MAPPED_SUPERCLASS); - } - else { - return null; - } - } - - @Override - public String getText(Object object) { - return ((XmlPersistentType) object).getClass_(); - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(XmlPersistentType.class)) { - case JpaCorePackage.IPERSISTENT_TYPE__MAPPING_KEY: - case OrmPackage.XML_PERSISTENT_TYPE__CLASS: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), false, true)); - return; - - case OrmPackage.XML_PERSISTENT_TYPE__SPECIFIED_PERSISTENT_ATTRIBUTES: - case OrmPackage.XML_PERSISTENT_TYPE__VIRTUAL_PERSISTENT_ATTRIBUTES: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), true, false)); - return; - } - - super.notifyChanged(notification); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlRootContentNodeItemProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlRootContentNodeItemProvider.java deleted file mode 100644 index 969c7c8407..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlRootContentNodeItemProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.structure; - -import java.util.Collection; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; -import org.eclipse.emf.edit.provider.IItemLabelProvider; -import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; -import org.eclipse.emf.edit.provider.ITreeItemContentProvider; -import org.eclipse.emf.edit.provider.ItemProviderAdapter; -import org.eclipse.emf.edit.provider.ViewerNotification; -import org.eclipse.jpt.core.internal.content.orm.EntityMappings; -import org.eclipse.jpt.core.internal.content.orm.OrmPackage; - -public class XmlRootContentNodeItemProvider extends ItemProviderAdapter - implements IEditingDomainItemProvider, - IStructuredItemContentProvider, - ITreeItemContentProvider, - IItemLabelProvider -{ - public XmlRootContentNodeItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - } - - @Override - public Collection getChildrenFeatures(Object object) { - if (childrenFeatures == null) { - super.getChildrenFeatures(object); - childrenFeatures.add(OrmPackage.Literals.XML_ROOT_CONTENT_NODE__ENTITY_MAPPINGS); - } - return childrenFeatures; - } - - @Override - public void notifyChanged(Notification notification) { - updateChildren(notification); - - switch (notification.getFeatureID(EntityMappings.class)) { - case OrmPackage.XML_ROOT_CONTENT_NODE__ENTITY_MAPPINGS: - fireNotifyChanged( - new ViewerNotification( - notification, notification.getNotifier(), true, false)); - return; - } - super.notifyChanged(notification); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlStructureProvider.java deleted file mode 100644 index ca7dddcceb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/xml/structure/XmlStructureProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.xml.structure; - -import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; -import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jpt.core.internal.JptCorePlugin; -import org.eclipse.jpt.ui.internal.structure.IJpaStructureProvider; - -public class XmlStructureProvider implements IJpaStructureProvider { - - public String fileContentType() { - return JptCorePlugin.ORM_XML_CONTENT_TYPE; - } - - public ITreeContentProvider buildContentProvider() { - return new AdapterFactoryContentProvider(new JpaCoreXmlItemProviderAdapterFactory()); - } - - public ILabelProvider buildLabelProvider() { - return new AdapterFactoryLabelProvider(new JpaCoreXmlItemProviderAdapterFactory()); - } - - public void dispose() { - // TODO Auto-generated method stub - - } -} |