diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal')
310 files changed, 0 insertions, 57486 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/AsynchronousUiCommandExecutor.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/AsynchronousUiCommandExecutor.java deleted file mode 100644 index 95cf471acd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/AsynchronousUiCommandExecutor.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import org.eclipse.jpt.utility.Command; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.swt.widgets.Display; - -/** - * This implementation of CommandExecutor can be used by a non-UI - * thread to asynchronously modify a JPA project with any objects associated - * with documents that are currently displayed in the UI. - */ -public final class AsynchronousUiCommandExecutor - implements CommandExecutor -{ - public static final CommandExecutor INSTANCE = new AsynchronousUiCommandExecutor(); - - public static CommandExecutor instance() { - return INSTANCE; - } - - // ensure single instance - private AsynchronousUiCommandExecutor() { - super(); - } - - public void execute(Command command) { - this.display().asyncExec(this.buildRunnable(command)); - } - - private Runnable buildRunnable(final Command command) { - return new Runnable() { - public void run() { - command.execute(); - } - }; - } - - private Display display() { - Display display = Display.getCurrent(); - return (display != null) ? display : Display.getDefault(); - } - -} 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 deleted file mode 100644 index 21ad37ed84..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java +++ /dev/null @@ -1,190 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import java.util.ArrayList; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.JpaPageComposite; -import org.eclipse.jpt.ui.internal.java.details.JavaEntityComposite; -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.EmbeddedIdMappingComposite; -import org.eclipse.jpt.ui.internal.mappings.details.EmbeddedMappingComposite; -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.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.ui.internal.orm.details.OrmEntityComposite; -import org.eclipse.jpt.ui.internal.persistence.details.PersistenceUnitConnectionComposite; -import org.eclipse.jpt.ui.internal.persistence.details.PersistenceUnitGeneralComposite; -import org.eclipse.jpt.ui.internal.persistence.details.PersistenceUnitPropertiesComposite; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * The default implementation of the UI factory required to show the information - * related to a JPA mapping (type or attribute). - * - * @see JpaUiFactory - * - * @version 2.0 - * @since 1.0 - */ -public abstract class BaseJpaUiFactory implements JpaUiFactory -{ - public JpaComposite<BasicMapping> createBasicMappingComposite( - PropertyValueModel<BasicMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new BasicMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<Embeddable> createEmbeddableComposite( - PropertyValueModel<Embeddable> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new EmbeddableComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<EmbeddedIdMapping> createEmbeddedIdMappingComposite( - PropertyValueModel<EmbeddedIdMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new EmbeddedIdMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<EmbeddedMapping> createEmbeddedMappingComposite( - PropertyValueModel<EmbeddedMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new EmbeddedMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<JavaEntity> createJavaEntityComposite( - PropertyValueModel<JavaEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new JavaEntityComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<OrmEntity> createOrmEntityComposite( - PropertyValueModel<OrmEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new OrmEntityComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<IdMapping> createIdMappingComposite( - PropertyValueModel<IdMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new IdMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<ManyToManyMapping> createManyToManyMappingComposite( - PropertyValueModel<ManyToManyMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new ManyToManyMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<ManyToOneMapping> createManyToOneMappingComposite( - PropertyValueModel<ManyToOneMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new ManyToOneMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<MappedSuperclass> createMappedSuperclassComposite( - PropertyValueModel<MappedSuperclass> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new MappedSuperclassComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<OneToManyMapping> createOneToManyMappingComposite( - PropertyValueModel<OneToManyMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new OneToManyMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<OneToOneMapping> createOneToOneMappingComposite( - PropertyValueModel<OneToOneMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new OneToOneMappingComposite(subjectHolder, parent, widgetFactory); - } - - public ListIterator<JpaPageComposite<PersistenceUnit>> createPersistenceUnitComposites( - PropertyValueModel<PersistenceUnit> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - ArrayList<JpaPageComposite<PersistenceUnit>> pages = - new ArrayList<JpaPageComposite<PersistenceUnit>>(1); - - pages.add(new PersistenceUnitGeneralComposite(subjectHolder, parent, widgetFactory)); - pages.add(new PersistenceUnitConnectionComposite(subjectHolder, parent, widgetFactory)); - pages.add(new PersistenceUnitPropertiesComposite(subjectHolder, parent, widgetFactory)); - - return pages.listIterator(); - } - - public JpaComposite<TransientMapping> createTransientMappingComposite( - PropertyValueModel<TransientMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new TransientMappingComposite(subjectHolder, parent, widgetFactory); - } - - public JpaComposite<VersionMapping> createVersionMappingComposite( - PropertyValueModel<VersionMapping> subjectHolder, - Composite parent, - WidgetFactory 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 deleted file mode 100644 index 5f7bfce7d2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -/** - * The default implementation of the UI factory required to show the information - * related to a JPA mapping (type or attribute). - * - * @see JpaUiFactory - * - * @version 1.0 - * @since 1.0 - */ -public class GenericJpaUiFactory extends BaseJpaUiFactory -{ -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java deleted file mode 100644 index aef085440a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java +++ /dev/null @@ -1,55 +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; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; - -public class JpaFileAdapterFactory - implements IAdapterFactory -{ - @SuppressWarnings("unchecked") - private static final Class[] ADAPTER_LIST = - new Class[] { JpaFile.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(); - JpaProject jpaProject = JptCorePlugin.getJpaProject(file.getProject()); - - if (jpaProject == null) { - return null; - } - - return jpaProject.getJpaFile(file); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java deleted file mode 100644 index 85f791f7d2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import org.eclipse.jpt.ui.JptUiPlugin; - -/** - * Help context ids for the Dali JPA UI. - * <p> - * This interface contains constants only; it is not intended to be - * implemented. - * </p> - */ -@SuppressWarnings("nls") -public interface JpaHelpContextIds { - - //ContextID prefix - public static final String PREFIX = JptUiPlugin.PLUGIN_ID + "."; - - //Persistent Type composites - public static final String ENTITY_ACCESS_TYPE = PREFIX + "entity_accessType"; - public static final String ENTITY_ATTRIBUTE_OVERRIDES = PREFIX + "entity_attributeOverrides"; - public static final String ENTITY_ATTRIBUTE_OVERRIDES_COLUMN = PREFIX + "entity_attributeOverridesColumn"; - public static final String ENTITY_CATALOG = PREFIX + "entity_catalog"; - public static final String ENTITY_INHERITANCE_STRATEGY = PREFIX + "entity_inheritanceStrategy"; - public static final String ENTITY_INHERITANCE_DISCRIMINATOR_TYPE = PREFIX + "entity_inheritanceDiscriminatorType"; - public static final String ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN = PREFIX + "entity_inheritanceDiscriminatorColumn"; - public static final String ENTITY_INHERITANCE_DISCRIMINATOR_VALUE = PREFIX + "entity_inheritanceDiscriminatorValue"; - public static final String ENTITY_NAME = PREFIX + "entity_name"; - public static final String ENTITY_ORM_PACKAGE = PREFIX + "orm_package"; - public static final String ENTITY_ORM_SCHEMA = PREFIX + "orm_schema"; - public static final String ENTITY_ORM_CATALOG = PREFIX + "orm_catalog"; - public static final String ENTITY_ORM_ACCESS = PREFIX + "orm_access"; - public static final String ENTITY_ORM_CASCADE = PREFIX + "orm_cascade"; - public static final String ENTITY_ORM_XML = PREFIX + "orm_xml"; - public static final String ENTITY_SCHEMA = PREFIX + "entity_schema"; - public static final String ENTITY_TABLE = PREFIX + "entity_table"; - - //Persistent Attribute composites - public static final String MAPPING_CASCADE_TYPE = PREFIX + "mapping_cascadeType"; - public static final String MAPPING_COLUMN = PREFIX + "mapping_column"; - public static final String MAPPING_COLUMN_INSERTABLE = PREFIX + "mapping_columnInsertable"; - public static final String MAPPING_COLUMN_LENGTH = PREFIX + "mapping_columnLength"; - public static final String MAPPING_COLUMN_NULLABLE = PREFIX + "mapping_columnNullable"; - public static final String MAPPING_COLUMN_PRECISION = PREFIX + "mapping_columnPrecision"; - public static final String MAPPING_COLUMN_SCALE = PREFIX + "mapping_columnScale"; - public static final String MAPPING_COLUMN_TABLE = PREFIX + "mapping_columnTable"; - public static final String MAPPING_COLUMN_UNIQUE = PREFIX + "mapping_columnUnique"; - public static final String MAPPING_COLUMN_UPDATABLE= PREFIX + "mapping_columnUpdatable"; - public static final String MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES = PREFIX + "mapping_embeddedAttributeOverrides"; - public static final String MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES_COLUMN = PREFIX + "mapping_embeddedAttributeOverridesColumn"; - public static final String MAPPING_ENUMERATED = PREFIX + "mapping_enumerated"; - public static final String MAPPING_FETCH_TYPE = PREFIX + "mapping_fetchType"; - public static final String MAPPING_GENERATED_VALUE_STRATEGY = PREFIX + "mapping_generatedValueStrategy"; - public static final String MAPPING_GENERATED_VALUE_GENERATOR_NAME = PREFIX + "mapping_generatedValueGeneratorName"; - public static final String MAPPING_JOIN_COLUMN_NAME = PREFIX + "mapping_joinColumnName"; - public static final String MAPPING_JOIN_REFERENCED_COLUMN = PREFIX + "mapping_joinReferencedColumn"; - public static final String MAPPING_JOIN_TABLE_NAME = PREFIX + "mapping_joinTableName"; - public static final String MAPPING_JOIN_TABLE_COLUMNS = PREFIX + "mapping_joinTableJoinColumns"; - public static final String MAPPING_JOIN_TABLE_INVERSE_JOIN_COLUMNS = PREFIX + "mapping_joinTableInverseJoinColumns"; - public static final String MAPPING_LOB = PREFIX + "mapping_lob"; - public static final String MAPPING_MAP_AS = PREFIX + "mapping_mapAs"; - public static final String MAPPING_MAPPED_BY = PREFIX + "mapping_mappedBy"; - public static final String MAPPING_NAMED_NATIVE_QUERIES = "named_native_queries"; - public static final String MAPPING_NAMED_QUERIES = PREFIX + "named_queries"; - public static final String MAPPING_OPTIONAL = PREFIX + "mapping_optional"; - public static final String MAPPING_ORDER_BY = PREFIX + "mapping_orderBy"; - public static final String MAPPING_ORDER_BY_NO_ORDERING = PREFIX + "mapping_orderByNoOrdering"; - public static final String MAPPING_ORDER_BY_PRIMARY_KEY_ORDERING = PREFIX + "mapping_orderByPrimaryKeyOrdering"; - public static final String MAPPING_ORDER_BY_CUSTOM_ORDERING = PREFIX + "mapping_orderByCustomOrdering"; - public static final String MAPPING_PRIMARY_KEY_GENERATION = PREFIX + "mapping_primaryKeyGeneration"; - public static final String MAPPING_SEQUENCE_GENERATOR = PREFIX + "mapping_sequenceGenerator"; - public static final String MAPPING_SEQUENCE_GENERATOR_NAME = PREFIX + "mapping_sequenceGeneratorName"; - public static final String MAPPING_SEQUENCE_GENERATOR_SEQUENCE = PREFIX + "mapping_sequenceGeneratorSequence"; - public static final String MAPPING_TABLE_GENERATOR = PREFIX + "mapping_tableGenerator"; - public static final String MAPPING_TABLE_GENERATOR_CATALOG = PREFIX + "mapping_tableGeneratorCatalog"; - public static final String MAPPING_TABLE_GENERATOR_NAME = PREFIX + "mapping_tableGeneratorName"; - public static final String MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN = PREFIX + "mapping_tableGeneratorPrimaryKeyColumn"; - public static final String MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE = PREFIX + "mapping_tableGeneratorPrimaryKeyColumnValue"; - public static final String MAPPING_TABLE_GENERATOR_SCHEMA = PREFIX + "mapping_tableGeneratorSchema"; - public static final String MAPPING_TABLE_GENERATOR_TABLE= PREFIX + "mapping_tableGeneratorTable"; - public static final String MAPPING_TABLE_GENERATOR_VALUE_COLUMN = PREFIX + "mapping_tableGeneratorValueColumn"; - public static final String MAPPING_TARGET_ENTITY = PREFIX + "mapping_targetEntity"; - public static final String MAPPING_TEMPORAL = PREFIX + "mapping_temporal"; - - //Project properties - public static final String PROPERTIES_JAVA_PERSISTENCE = PREFIX + "properties_javaPersistence"; - public static final String PROPERTIES_JAVA_PERSISTENCE_CONNECTION = PREFIX + "properties_javaPersistenceConnection"; - public static final String PROPERTIES_JAVA_PERSISTENCE_SCHEMA = PREFIX + "properties_javaPersistenceSchema"; - - //Dialogs, Wizards - public static final String DIALOG_CREATE_ORM = PREFIX + "dialog_createORM"; - public static final String DIALOG_EDIT_INVERSE_JOIN_COLUNN = PREFIX + "dialog_editInverseJoinColumn"; - public static final String DIALOG_GENERATE_ENTITIES = PREFIX + "dialog_generateEntities"; - public static final String DIALOG_GENERATE_ENTITIES_SOURCE = PREFIX + "dialog_generateEntities_source"; - public static final String DIALOG_GENERATE_ENTITIES_PACKAGE = PREFIX + "dialog_generateEntities_package"; - public static final String DIALOG_GENERATE_ENTITIES_TABLES = PREFIX + "dialog_generateEntities_tables"; - public static final String DIALOG_JPA_FACET = PREFIX + "dialog_JPAFacet"; - public static final String DIALOG_JPA_PLATFORM = PREFIX + "dialog_JPAPlatform"; - public static final String NEW_JPA_PROJECT = PREFIX + "dialog_newJPAProject"; - public static final String NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH = PREFIX + "dialog_addJavaPersistence_classpath"; - public static final String NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE = PREFIX + "dialog_addJavaPersistence_database"; - public static final String NEW_JPA_PROJECT_CONTENT_PAGE_PACKAGING = PREFIX + "dialog_addJavaPersistence_packaging"; - public static final String NEW_JPA_PROJECT_CREATION_PAGE = PREFIX + "dialog_addJavaPersistence"; - - //Other - public static final String PERSISTENCE_OUTLINE = PREFIX + "persistenceOutline"; - - //PersistenceUnit - public static final String PERSISTENCE_UNIT_CONNECTION = PREFIX + "persistenceUnit_connection"; - public static final String PERSISTENCE_UNIT_GENERAL = PREFIX + "persistenceUnit_general"; - public static final String PERSISTENCE_UNIT_PROPERTIES = PREFIX + "persistenceUnit_properties"; -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaJavaCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaJavaCompletionProposalComputer.java deleted file mode 100644 index ad6bbbfd6f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaJavaCompletionProposalComputer.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import java.util.ArrayList; -import java.util.Collection; -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; -import org.eclipse.jface.text.contentassist.CompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * JPA Java code-completion proposal computer - */ -public class JpaJavaCompletionProposalComputer implements IJavaCompletionProposalComputer { - - public JpaJavaCompletionProposalComputer() { - super(); - } - - public void sessionStarted() { - // do nothing - } - - @SuppressWarnings("unchecked") - public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) { - return (context instanceof JavaContentAssistInvocationContext) ? - this.computeCompletionProposals((JavaContentAssistInvocationContext) context) - : - Collections.emptyList(); - } - - private List<ICompletionProposal> computeCompletionProposals(JavaContentAssistInvocationContext context) { - try { - return this.computeCompletionProposals_(context); - } catch (JavaModelException ex) { - throw new RuntimeException(ex); - } - } - - private List<ICompletionProposal> computeCompletionProposals_(JavaContentAssistInvocationContext context) throws JavaModelException { - ICompilationUnit cu = context.getCompilationUnit(); - if (cu == null) { - return Collections.emptyList(); - } - - JpaFile jpaFile = JptCorePlugin.getJpaFile((IFile) cu.getCorrespondingResource()); - if (jpaFile == null) { - return Collections.emptyList(); - } - - Collection<JpaStructureNode> rootStructureNodes = CollectionTools.collection(jpaFile.rootStructureNodes()); - if (rootStructureNodes.isEmpty()) { - return Collections.emptyList(); - } - - CompletionContext cc = context.getCoreContext(); - - // the context's "token" is really a sort of "prefix" - it does NOT - // correspond to the "start" and "end" we get below... - char[] prefix = cc.getToken(); - Filter<String> filter = ((prefix == null) ? Filter.Null.<String>instance() : new IgnoreCasePrefixFilter(prefix)); - // the token "start" is the offset of the token's first character - int tokenStart = cc.getTokenStart(); - // the token "end" is the offset of the token's last character (yuk) - int tokenEnd = cc.getTokenEnd(); - if (tokenStart == -1) { // not sure why this happens - see bug 242286 - return Collections.emptyList(); - } - -// System.out.println("prefix: " + ((prefix == null) ? "[null]" : new String(prefix))); -// System.out.println("token start: " + tokenStart); -// System.out.println("token end: " + tokenEnd); -// String source = cu.getSource(); -// String token = source.substring(Math.max(0, tokenStart), Math.min(source.length(), tokenEnd + 1)); -// System.out.println("token: =>" + token + "<="); -// 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 (JpaStructureNode structureNode : rootStructureNodes) { - for (Iterator<String> stream = ((JavaPersistentType) structureNode).javaCompletionProposals(context.getInvocationOffset(), filter, astRoot); stream.hasNext(); ) { - String s = stream.next(); - proposals.add(new CompletionProposal(s, tokenStart, tokenEnd - tokenStart + 1, s.length())); - } - } - return proposals; - } - - @SuppressWarnings("unchecked") - public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) { - return Collections.emptyList(); - } - - public String getErrorMessage() { - return null; - } - - public void sessionEnded() { - // do nothing - } - - private static class IgnoreCasePrefixFilter implements Filter<String> { - private final char[] prefix; - IgnoreCasePrefixFilter(char[] prefix) { - super(); - this.prefix = prefix; - } - public boolean accept(String s) { - return StringTools.stringStartsWithIgnoreCase(s.toCharArray(), prefix); - } - } - -} 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 deleted file mode 100644 index 4ad40adb32..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaMappingImageHelper.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.swt.graphics.Image; - -public class JpaMappingImageHelper -{ - public static Image imageForTypeMapping(String mappingKey) { - if (MappingKeys.NULL_TYPE_MAPPING_KEY == mappingKey) { - return JptUiPlugin.getImage(JptUiIcons.NULL_TYPE_MAPPING); - } - else if (MappingKeys.ENTITY_TYPE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.ENTITY); - } - else if (MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.EMBEDDABLE); - } - else if (MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.MAPPED_SUPERCLASS); - } - return null; - } - - public static Image imageForAttributeMapping(String mappingKey) { - if (MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY == mappingKey) { - return JptUiPlugin.getImage(JptUiIcons.NULL_ATTRIBUTE_MAPPING); - } - else if (MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.BASIC); - } - else if (MappingKeys.ID_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.ID); - } - else if (MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.VERSION); - } - else if (MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.EMBEDDED_ID); - } - else if (MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.EMBEDDED); - } - else if (MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.ONE_TO_ONE); - } - else if (MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.ONE_TO_MANY); - } - else if (MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.MANY_TO_ONE); - } - else if (MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY.equals(mappingKey)) { - return JptUiPlugin.getImage(JptUiIcons.MANY_TO_MANY); - } - else if (MappingKeys.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 deleted file mode 100644 index eb5fe697ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiIcons.java +++ /dev/null @@ -1,93 +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; - -import org.eclipse.draw2d.ImageUtilities; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; - -public class JptUiIcons -{ - public static Image ghost(Image image) { - Color lightgray = new Color(image.getDevice(), 223, 223, 223); - ImageData imageData = ImageUtilities.createShadedImage(image, lightgray); - return new Image(image.getDevice(), new Image(image.getDevice(), imageData), SWT.IMAGE_GRAY); - } - - - // **************** General JPA icons ************************************** - - 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$ - - public static final String WARNING = "full/obj16/warning"; //$NON-NLS-1$ - - - // **************** Wizard icons ******************************************* - - public static final String JPA_WIZ_BANNER = "full/wizban/jpa_facet_wizban"; //$NON-NLS-1$ - - public static final String ENTITY_WIZ_BANNER = "full/wizban/new_entity_wizban"; //$NON-NLS-1$ - - public static final String JPA_FILE_WIZ_BANNER = "full/wizban/new_jpa_file_wizban"; //$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 deleted file mode 100644 index 4bc3344563..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import org.eclipse.osgi.util.NLS; - -/** - * The resource strings used by the JPT UI classes. - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class JptUiMessages extends NLS { - - public static String AbstractChooserPane_browseButton; - public static String AddPersistentAttributeDialog_attributeLabel; - public static String AddPersistentAttributeDialog_mappingLabel; - public static String AddPersistentAttributeDialog_noMappingKeyError; - 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_noMappingKeyError; - public static String AddPersistentClassDialog_title; - public static String AddRemovePane_AddButtonText; - public static String AddRemovePane_RemoveButtonText; - public static String ClassChooserPane_dialogMessage; - public static String ClassChooserPane_dialogTitle; - 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_schema; - public static String DatabaseReconnectWizardPage_schemaInfo; - public static String EnumComboViewer_default; - public static String EnumComboViewer_defaultWithDefault; - public static String Error_openingEditor; - 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_tableColumn; - public static String GenerateEntitiesWizardPage_tables; - public static String GenericPlatformUiDialog_notSupportedMessageText; - public static String GenericPlatformUiDialog_notSupportedMessageTitle; - public static String JpaContent_label; - public static String JpaDetailsView_viewNotAvailable; - public static String JpaFacetWizardPage_connectionLabel; - public static String JpaFacetWizardPage_connectionLink; - public static String JpaFacetWizardPage_connectLink; - public static String JpaFacetWizardPage_createOrmXmlButton; - public static String JpaFacetWizardPage_defaultSchemaLabel; - public static String JpaFacetWizardPage_description; - public static String JpaFacetWizardPage_discoverClassesButton; - public static String JpaFacetWizardPage_jpaImplementationLabel; - public static String JpaFacetWizardPage_jpaPrefsLink; - public static String JpaFacetWizardPage_listClassesButton; - public static String JpaFacetWizardPage_none; - public static String JpaFacetWizardPage_overrideDefaultSchemaLabel; - 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 MapAsComposite_basic; - public static String MapAsComposite_basic_default; - public static String MapAsComposite_basic_default2; - public static String MapAsComposite_changeMappingType; - public static String MapAsComposite_default; - public static String MapAsComposite_dialogTitle; - public static String MapAsComposite_embeddable; - public static String MapAsComposite_embedded; - public static String MapAsComposite_embedded_default; - public static String MapAsComposite_embedded_default2; - public static String MapAsComposite_embeddedid; - public static String MapAsComposite_entity; - public static String MapAsComposite_id; - public static String MapAsComposite_labelText; - public static String MapAsComposite_manytomany; - public static String MapAsComposite_manytoone; - public static String MapAsComposite_mappedAttributeText; - public static String MapAsComposite_mappedsuperclass; - public static String MapAsComposite_mappedTypeText; - public static String MapAsComposite_onetomany; - public static String MapAsComposite_onetoone; - public static String MapAsComposite_transient; - public static String MapAsComposite_unmappedAttributeText; - public static String MapAsComposite_unmappedTypeText; - public static String MapAsComposite_version; - public static String MapAsComposite_virtualAttributeText; - public static String MappingFileWizard_title; - public static String MappingFileWizardPage_title; - public static String MappingFileWizardPage_desc; - public static String MappingFileWizardPage_projectLabel; - public static String MappingFileWizardPage_sourceFolderLabel; - public static String MappingFileWizardPage_filePathLabel; - public static String MappingFileWizardPage_accessLabel; - public static String MappingFileWizardPage_addToPersistenceUnitButton; - public static String MappingFileWizardPage_persistenceUnitLabel; - public static String MappingFileWizardPage_incorrectSourceFolderError; - public static String MappingFileWizardPage_accessLabel_sourceFolderDialogTitle; - public static String MappingFileWizardPage_accessLabel_sourceFolderDialogDesc; - 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 PackageChooserPane_dialogMessage; - public static String PackageChooserPane_dialogTitle; - public static String PersistenceItemLabelProviderFactory_persistenceLabel; - public static String PersistentAttributePage_mapAs; - public static String PersistentTypePage_mapAs; - - static { - NLS.initializeMessages("jpt_ui", 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/SynchronousUiCommandExecutor.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/SynchronousUiCommandExecutor.java deleted file mode 100644 index 8f93d27515..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/SynchronousUiCommandExecutor.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import org.eclipse.jpt.utility.Command; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.swt.widgets.Display; - -/** - * This implementation of CommandExecutor can be used by a non-UI - * thread to synchronously modify a JPA project with any objects associated - * with documents that are currently displayed in the UI. - */ -public final class SynchronousUiCommandExecutor - implements CommandExecutor -{ - public static final CommandExecutor INSTANCE = new SynchronousUiCommandExecutor(); - - public static CommandExecutor instance() { - return INSTANCE; - } - - // ensure single instance - private SynchronousUiCommandExecutor() { - super(); - } - - public void execute(Command command) { - this.display().syncExec(this.buildRunnable(command)); - } - - private Runnable buildRunnable(final Command command) { - return new Runnable() { - public void run() { - command.execute(); - } - }; - } - - private Display display() { - Display display = Display.getCurrent(); - return (display != null) ? display : Display.getDefault(); - } - -} 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 deleted file mode 100644 index 3d138638e7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/Tracing.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jpt.ui.JptUiPlugin; - -/** - * 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/GenerateDDLAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/GenerateDDLAction.java deleted file mode 100644 index 49bce355eb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/GenerateDDLAction.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.actions; - -import org.eclipse.jpt.core.JpaProject; - -/** - * GenerateDDLAction - */ -public class GenerateDDLAction extends ProjectAction { - - public GenerateDDLAction() { - super(); - } - - @Override - protected void execute(JpaProject project) { - this.jpaPlatformUi(project).generateDDL(project, this.getCurrentSelection()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/GenerateEntitiesAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/GenerateEntitiesAction.java deleted file mode 100644 index 5e745797ee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/GenerateEntitiesAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007, 2008 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.ui.internal.actions; - -import org.eclipse.jpt.core.JpaProject; - -/** - * GenerateEntitiesAction - */ -public class GenerateEntitiesAction extends ProjectAction { - public GenerateEntitiesAction() { - super(); - } - - @Override - protected void execute(JpaProject project) { - this.jpaPlatformUi(project).generateEntities(project, this.getCurrentSelection()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MigrateJavaProjectAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MigrateJavaProjectAction.java deleted file mode 100644 index 88c7ef401f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/MigrateJavaProjectAction.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.actions; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationOperation; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard; - -public class MigrateJavaProjectAction implements IObjectActionDelegate -{ - private ISelection currentSelection; - - - public MigrateJavaProjectAction() { - super(); - } - - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - // do nothing - } - - public void selectionChanged(IAction action, ISelection selection) { - this.currentSelection = selection; - } - - public void run(IAction action) { - // This action is currently enabled only for a singly selected, java, - // non-faceted IProject - IProject project = (IProject) ((IStructuredSelection) currentSelection).getFirstElement(); - execute(project); - } - - private void execute(IProject project) { - // add facets nature, java facet, and utility facet to project - JavaProjectMigrationOperation operation = - J2EEProjectUtilities.createFlexJavaProjectForProjectOperation(project, false); - operation.execute(null, null); - - IFacetedProject facetedProject; - try { - // get the faceted project - facetedProject = ProjectFacetsManager.create(project); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); - return; - } - - // launch the UI with JPA facet preselected - final ModifyFacetedProjectWizard wizard = new ModifyFacetedProjectWizard(facetedProject); - IFacetedProjectWorkingCopy facetedProjectWorkingCopy = wizard.getFacetedProjectWorkingCopy(); - IProjectFacetVersion jpa1_0 = ProjectFacetsManager.getProjectFacet(JptCorePlugin.FACET_ID).getDefaultVersion(); - facetedProjectWorkingCopy.addProjectFacet(jpa1_0); - - final WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); - dialog.open(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/OpenJpaResourceAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/OpenJpaResourceAction.java deleted file mode 100644 index 2b90f3ff58..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/OpenJpaResourceAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.actions; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.BaseSelectionListenerAction; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.part.FileEditorInput; - -public class OpenJpaResourceAction extends BaseSelectionListenerAction -{ - private JpaContextNode selectedNode; - - - public OpenJpaResourceAction() { - super("Open"); //$NON-NLS-1$ - } - - - @Override - public boolean updateSelection(IStructuredSelection s) { - selectedNode = null; - - if (! super.updateSelection(s)) { - return false; - } - - if (s.size() != 1) { - return false; - } - - if (s.getFirstElement() instanceof JpaRootContextNode) { - return false; - } - - selectedNode = (JpaContextNode) s.getFirstElement(); - - return true; - } - - @Override - public void run() { - if (! isEnabled()) { - return; - } - - IResource resource = selectedNode.getResource(); - - if (resource != null && resource.exists() && resource.getType() == IResource.FILE) { - openEditor((IFile) resource); - - - if (selectedNode instanceof JpaStructureNode) { - JpaSelectionManager selectionManager = - SelectionManagerFactory.getSelectionManager(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); - selectionManager.select(new DefaultJpaSelection((JpaStructureNode) selectedNode), null); - } - } - } - - protected void openEditor(IFile file) { - IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); - IContentType contentType = IDE.getContentType(file); - IEditorDescriptor editorDescriptor = registry.getDefaultEditor(file.getName(), contentType); - - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - - try { - page.openEditor(new FileEditorInput(file), editorDescriptor.getId()); - } - catch (Exception e) { - MessageDialog.openError(page.getWorkbenchWindow().getShell(), JptUiMessages.Error_openingEditor, e.getMessage()); - } - } -} 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 deleted file mode 100644 index 64739ed559..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/ProjectAction.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.actions; - -import java.util.Iterator; -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -/** - * Override any of the #execute() methods. - */ -public abstract class ProjectAction implements IObjectActionDelegate { - - private ISelection currentSelection; - - - public ProjectAction() { - super(); - } - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - // do nothing - } - - public void selectionChanged(IAction action, ISelection selection) { - this.currentSelection = selection; - } - - protected IStructuredSelection getCurrentSelection() { - if (this.currentSelection instanceof IStructuredSelection) { - return (IStructuredSelection) this.currentSelection; - } - return null; - } - - public void run(IAction action) { - if (this.currentSelection instanceof IStructuredSelection) { - for (Iterator stream = ((IStructuredSelection) this.currentSelection).iterator(); stream.hasNext(); ) { - this.execute(stream.next()); - } - } - } - - protected void execute(Object selection) { - IProject project = this.projectFromSelection(selection); - if (project != null) { - this.execute(project); - } - } - - protected IProject projectFromSelection(Object selection) { - if (selection instanceof IProject) { - return (IProject) selection; - } - if (selection instanceof IJavaProject) { - return ((IJavaProject) selection).getProject(); - } - return null; - } - - protected JpaPlatformUi jpaPlatformUi(JpaProject project) { - String coreJpaPlatformId = project.getJpaPlatform().getId(); - return JpaPlatformUiRegistry.instance().jpaPlatform(coreJpaPlatformId); - } - - protected void execute(IProject project) { - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject == null) { - return; - } - this.execute(jpaProject); - } - - protected void execute(JpaProject project) { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/SynchronizeClassesAction.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/SynchronizeClassesAction.java deleted file mode 100644 index 80adc8964a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/actions/SynchronizeClassesAction.java +++ /dev/null @@ -1,49 +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.actions; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.synch.SynchronizeClassesJob; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - -public class SynchronizeClassesAction - implements IObjectActionDelegate -{ - private IFile file; - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - // no-op for now - } - - public void run(IAction action) { - SynchronizeClassesJob job = new SynchronizeClassesJob(file); - job.schedule(); - } - - public void selectionChanged(IAction action, ISelection selection) { - // Action is contributed for IFile's named "persistence.xml" and - // for PeristenceXml objects. - // There is always only one element in actual selection. - Object selectedObject = ((StructuredSelection) selection).getFirstElement(); - - if (selectedObject instanceof IFile) { - file = (IFile) selectedObject; - } - else if (selectedObject instanceof PersistenceXml) { - file = (IFile) ((PersistenceXml) selectedObject).getResource(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java deleted file mode 100644 index 60b378464d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentAttributeToXmlAndMapHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.commands; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.internal.dialogs.AddPersistentAttributeToXmlAndMapDialog; -import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class AddPersistentAttributeToXmlAndMapHandler extends AbstractHandler -{ - @SuppressWarnings("unchecked") - public Object execute(ExecutionEvent executionEvent) throws ExecutionException { - final IWorkbenchWindow window = - HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent); - - final List<OrmPersistentAttribute> newAttributes = new ArrayList<OrmPersistentAttribute>(); - - IStructuredSelection selection - = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent); - - - // only applies for multiply selected OrmPersistentAttribute objects in a tree - for (OrmPersistentAttribute attribute : (Iterable<OrmPersistentAttribute>) CollectionTools.iterable(selection.iterator())) { - OrmPersistentType type = attribute.getOrmPersistentType(); - String attributeName = attribute.getName(); - - AddPersistentAttributeToXmlAndMapDialog dialog = new AddPersistentAttributeToXmlAndMapDialog(window.getShell(), attribute); - dialog.create(); - dialog.setBlockOnOpen(true); - dialog.open(); - - OrmPersistentAttribute newAttribute = type.getAttributeNamed(attributeName); - if (newAttribute != null) { - newAttributes.add(newAttribute); - } - } - - if (newAttributes.size() == 1) { - window.getShell().getDisplay().asyncExec( - new Runnable() { - public void run() { - JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window); - selectionManager.select(new DefaultJpaSelection(newAttributes.get(0)), null); - } - }); - } - - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentAttributeToXmlHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentAttributeToXmlHandler.java deleted file mode 100644 index 710e879c5c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentAttributeToXmlHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.commands; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class AddPersistentAttributeToXmlHandler extends AbstractHandler -{ - @SuppressWarnings("unchecked") - public Object execute(ExecutionEvent executionEvent) throws ExecutionException { - final IWorkbenchWindow window = - HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent); - - final List<OrmPersistentAttribute> newAttributes = new ArrayList<OrmPersistentAttribute>(); - - IStructuredSelection selection = - (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent); - - // only applies for multiply selected OrmPersistentAttribute objects in a tree - for (OrmPersistentAttribute attribute : (Iterable<OrmPersistentAttribute>) CollectionTools.iterable(selection.iterator())) { - OrmPersistentType type = attribute.getOrmPersistentType(); - String attributeName = attribute.getName(); - attribute.makeSpecified(); - OrmPersistentAttribute newAttribute = type.getAttributeNamed(attributeName); - if (newAttribute != null) { - newAttributes.add(newAttribute); - } - } - - if (newAttributes.size() == 1) { - window.getShell().getDisplay().asyncExec( - new Runnable() { - public void run() { - JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window); - selectionManager.select(new DefaultJpaSelection(newAttributes.get(0)), null); - } - }); - } - - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentClassHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentClassHandler.java deleted file mode 100644 index d91ba4bd87..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/AddPersistentClassHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.commands; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.internal.dialogs.AddPersistentClassDialog; -import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class AddPersistentClassHandler extends AbstractHandler -{ - public Object execute(ExecutionEvent executionEvent) throws ExecutionException { - final IWorkbenchWindow window = - HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent); - - IStructuredSelection selection - = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent); - - // only applies for a singly selected EntityMappings object in a tree - EntityMappings entityMappings = - (EntityMappings) selection.getFirstElement(); - - AddPersistentClassDialog dialog = - new AddPersistentClassDialog(window.getShell(), entityMappings); - dialog.create(); - dialog.setBlockOnOpen(true); - final OrmPersistentType type = dialog.openAndReturnType(); - - if (type != null) { - window.getShell().getDisplay().asyncExec( - new Runnable() { - public void run() { - JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window); - selectionManager.select(new DefaultJpaSelection(type), null); - } - }); - } - - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/PersistentAttributeMapAsHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/PersistentAttributeMapAsHandler.java deleted file mode 100644 index cefbbcd031..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/PersistentAttributeMapAsHandler.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.commands; - -import java.util.Iterator; -import java.util.Map; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.ui.internal.menus.PersistentAttributeMapAsContribution; -import org.eclipse.ui.ISources; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.commands.IElementUpdater; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.menus.UIElement; -import org.eclipse.ui.services.IEvaluationService; - -/** - * This handler is responsible to change the mapping type of the selected - * <code>PersistentAttribute</code>. - * <p> - * This handler is defined in the JPT plugin.xml. It will be invoked by the - * mapping action dynamically created by the <code>PersistentAttributeMapAsContribution</code>. - * - * @see PersistentAttribute - * @see PersistentAttributeMapAsContribution - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class PersistentAttributeMapAsHandler extends AbstractHandler - implements IElementUpdater -{ - /** - * The unique identifier of the Map As command used for <code>PersistentAttribute</code> - * defined in the <code>JptUiPlugin</code> plugin.xml. - */ - public static final String COMMAND_ID = "org.eclipse.jpt.ui.persistentAttributeMapAs"; - - /** - * The unique identifier of the Map As command parameter used for <code>PersistentAttribute</code> - * defined in the <code>JptUiPlugin</code> plugin.xml. - */ - public static final String COMMAND_PARAMETER_ID = "persistentAttributeMappingKey"; - - - /** - * Creates a new <code>PersistentAttributeMapAsHandler</code>. - */ - public PersistentAttributeMapAsHandler() { - super(); - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - - // Retrieve the selection from the ExecutionEvent - IStructuredSelection selection = (IStructuredSelection) - HandlerUtil.getCurrentSelectionChecked(event); - - // Retrieve the value of the unique parameter passed to the command - String mappingKey = event.getParameter(COMMAND_PARAMETER_ID); - - // Change the mapping key for all the selected items - for (Object item : selection.toArray()) { - PersistentAttribute attribute = (PersistentAttribute) item; - attribute.setSpecifiedMappingKey(mappingKey); - } - - return null; - } - - @SuppressWarnings("unchecked") - public void updateElement(UIElement element, Map parameters) { - // Retrieve the selection for the UIElement - - // Due to Bug 226746, we have to use API workaround to retrieve current - // selection - IEvaluationService es - = (IEvaluationService) element.getServiceLocator().getService(IEvaluationService.class); - IViewPart part = - (IViewPart) es.getCurrentState().getVariable(ISources.ACTIVE_PART_NAME); - IStructuredSelection selection - = (IStructuredSelection) part.getSite().getSelectionProvider().getSelection(); - - String commonMappingKey = commonMappingKey(selection); - - String handlerMappingKey = (String) parameters.get(COMMAND_PARAMETER_ID); - if (handlerMappingKey != null) { - element.setChecked(handlerMappingKey.equals(commonMappingKey)); - } - } - - @SuppressWarnings("unchecked") - protected String commonMappingKey(IStructuredSelection selection) { - String commonKey = null; - for (Iterator stream = selection.iterator(); stream.hasNext(); ) { - Object obj = stream.next(); - - if (! (obj instanceof PersistentAttribute)) { - return null; - } - - PersistentAttribute persistentAttribute = (PersistentAttribute) obj; - - if (commonKey == null) { - commonKey = persistentAttribute.getMappingKey(); - } - else if (! commonKey.equals(persistentAttribute.getMappingKey())) { - return null; - } - } - return commonKey; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/PersistentTypeMapAsHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/PersistentTypeMapAsHandler.java deleted file mode 100644 index b1a9030fde..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/PersistentTypeMapAsHandler.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.commands; - -import java.util.Iterator; -import java.util.Map; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.ui.internal.menus.PersistentTypeMapAsContribution; -import org.eclipse.ui.ISources; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.commands.IElementUpdater; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.menus.UIElement; -import org.eclipse.ui.services.IEvaluationService; - -/** - * This handler is responsible to change the mapping type of the selected - * <code>PersistentType</code>. - * <p> - * This handler is defined in the JPT plugin.xml. It will be invoked by the - * mapping action dynamically created by the <code>PersistentTypeMapAsContribution</code>. - * - * @see PersistentType - * @see PersistentTypeMapAsContribution - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class PersistentTypeMapAsHandler extends AbstractHandler - implements IElementUpdater -{ - /** - * The unique identifier of the Map As command used for {@link PersistentType} - * defined in the <code>JptUiPlugin</code> plugin.xml. - */ - public static final String COMMAND_ID = "org.eclipse.jpt.ui.persistentTypeMapAs"; - - /** - * The unique identifier of the Map As command parameter used for {@link PersistentType} - * defined in the <code>JptUiPlugin</code> plugin.xml. - */ - public static final String COMMAND_PARAMETER_ID = "persistentTypeMappingKey"; - - - /** - * Creates a new <code>PersistentTypeMapAsHandler</code>. - */ - public PersistentTypeMapAsHandler() { - super(); - } - - public Object execute(ExecutionEvent event) throws ExecutionException { - - // Retrieve the selection from the ExecutionEvent - IStructuredSelection selection = (IStructuredSelection) - HandlerUtil.getCurrentSelectionChecked(event); - - // Retrieve the value of the unique parameter passed to the command - String mappingKey = event.getParameter(COMMAND_PARAMETER_ID); - - // Change the mapping key for all the selected items - for (Object item : selection.toArray()) { - PersistentType type = (PersistentType) item; - type.setMappingKey(mappingKey); - } - - return null; - } - - @SuppressWarnings("unchecked") - public void updateElement(UIElement element, Map parameters) { - // Retrieve the selection for the UIElement - - // Due to Bug 226746, we have to use API workaround to retrieve current - // selection - IEvaluationService es - = (IEvaluationService) element.getServiceLocator().getService(IEvaluationService.class); - IViewPart part = - (IViewPart) es.getCurrentState().getVariable(ISources.ACTIVE_PART_NAME); - IStructuredSelection selection - = (IStructuredSelection) part.getSite().getSelectionProvider().getSelection(); - - String commonMappingKey = commonMappingKey(selection); - - String handlerMappingKey = (String) parameters.get(COMMAND_PARAMETER_ID); - if (handlerMappingKey != null) { - element.setChecked(handlerMappingKey.equals(commonMappingKey)); - } - } - - @SuppressWarnings("unchecked") - protected String commonMappingKey(IStructuredSelection selection) { - String commonKey = null; - for (Iterator stream = selection.iterator(); stream.hasNext(); ) { - Object obj = stream.next(); - - if (! (obj instanceof PersistentType)) { - return null; - } - - PersistentType persistentType = (PersistentType) obj; - - if (commonKey == null) { - commonKey = persistentType.getMappingKey(); - } - else if (! commonKey.equals(persistentType.getMappingKey())) { - return null; - } - } - return commonKey; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java deleted file mode 100644 index 9ebd38db41..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/RemovePersistentAttributeFromXmlHandler.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.commands; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class RemovePersistentAttributeFromXmlHandler extends AbstractHandler -{ - @SuppressWarnings("unchecked") - public Object execute(ExecutionEvent executionEvent) throws ExecutionException { - final IWorkbenchWindow window = - HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent); - - final List<OrmPersistentAttribute> newAttributes = new ArrayList<OrmPersistentAttribute>(); - - IStructuredSelection selection = - (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent); - - // only applies for multiply selected OrmPersistentAttribute objects in a tree - for (OrmPersistentAttribute attribute : (Iterable<OrmPersistentAttribute>) CollectionTools.iterable(selection.iterator())) { - OrmPersistentType type = attribute.getOrmPersistentType(); - String attributeName = attribute.getName(); - attribute.makeVirtual(); - OrmPersistentAttribute newAttribute = type.getAttributeNamed(attributeName); - if (newAttribute != null) { - newAttributes.add(newAttribute); - } - } - - if (newAttributes.size() == 1) { - window.getShell().getDisplay().asyncExec( - new Runnable() { - public void run() { - JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(window); - selectionManager.select(new DefaultJpaSelection(newAttributes.get(0)), null); - } - }); - } - - return null; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/RemovePersistentClassHandler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/RemovePersistentClassHandler.java deleted file mode 100644 index 2b60193472..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/commands/RemovePersistentClassHandler.java +++ /dev/null @@ -1,36 +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.commands; - -import java.util.Iterator; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.ui.handlers.HandlerUtil; - -public class RemovePersistentClassHandler extends AbstractHandler -{ - @SuppressWarnings("unchecked") - public Object execute(ExecutionEvent executionEvent) throws ExecutionException { - IStructuredSelection selection = - (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(executionEvent); - - // only applies for multiply selected OrmPersistentType objects in a tree - for (Iterator<OrmPersistentType> stream = selection.iterator(); stream.hasNext(); ) { - OrmPersistentType persistentType = stream.next(); - persistentType.getEntityMappings().removeOrmPersistentType(persistentType); - } - - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractJpaDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractJpaDetailsPage.java deleted file mode 100644 index 8dab43841f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/AbstractJpaDetailsPage.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaDetailsPage; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.forms.widgets.ScrolledForm; - -/** - * The base class for the details view. - * - * @see JpaContextNode - * - * @version 2.0 - * @since 1.0 - */ -public abstract class AbstractJpaDetailsPage<T extends JpaStructureNode> - extends AbstractFormPane<T> - implements JpaDetailsPage<T> -{ - /** - * Creates a new <code>BaseJpaDetailsPage</code>. - * - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - protected AbstractJpaDetailsPage(Composite parent, - WidgetFactory widgetFactory) { - - super(new SimplePropertyValueModel<T>(), parent, widgetFactory); - } - - protected JpaPlatformUi jpaPlatformUi() { - String platformId = subject().getJpaProject().getJpaPlatform().getId(); - return JpaPlatformUiRegistry.instance().jpaPlatform(platformId); - } - - protected JpaUiFactory jpaUiFactory() { - return jpaPlatformUi().getJpaUiFactory(); - } - - /** - * There is an issue with <code>ScrolledForm</code>, it doesn't repaint the - * entire content, this will retrieve it by going up the hierarchy of the - * given <code>Composite</code> and force a reflow on it. - * - * @param container The container used to find the <code>ScrolledForm</code> - */ - protected final void repaintDetailsView(Composite container) { - - while (container != null && - !(container instanceof ScrolledForm)) - { - container = container.getParent(); - } - - if (container != null) { - ScrolledForm scrolledForm = (ScrolledForm) container; - scrolledForm.reflow(true); - } - } - - /* - * (non-Javadoc) - */ - public final void setSubject(T subject) { - - SimplePropertyValueModel<T> subjectHolder = (SimplePropertyValueModel<T>) getSubjectHolder(); - - // Populate this page with the new subject - if (subject != null) { - subjectHolder.setValue(subject); - populate(); - } - // Dispose this page - else { - disengageListeners(); - subjectHolder.setValue(null); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BasicMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BasicMappingUiProvider.java deleted file mode 100644 index 47fa3194e1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/BasicMappingUiProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class BasicMappingUiProvider - implements AttributeMappingUiProvider<BasicMapping> -{ - - // singleton - private static final BasicMappingUiProvider INSTANCE = new BasicMappingUiProvider(); - - /** - * Ensure non-instantiability. - */ - private BasicMappingUiProvider() { - super(); - } - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<BasicMapping> instance() { - return INSTANCE; - } - - public JpaComposite<BasicMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<BasicMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createBasicMappingComposite(subjectHolder, parent, widgetFactory); - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_BasicLabel; - } - - public String getMappingKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddableUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddableUiProvider.java deleted file mode 100644 index c04bc40397..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddableUiProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class EmbeddableUiProvider implements TypeMappingUiProvider<Embeddable> -{ - // singleton - private static final EmbeddableUiProvider INSTANCE = new EmbeddableUiProvider(); - - /** - * Return the singleton. - */ - public static TypeMappingUiProvider<Embeddable> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EmbeddableUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentTypePage_EmbeddableLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForTypeMapping(getMappingKey()); - } - - public JpaComposite<Embeddable> buildPersistentTypeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<Embeddable> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createEmbeddableComposite(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/EmbeddedIdMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddedIdMappingUiProvider.java deleted file mode 100644 index 98798fa4c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddedIdMappingUiProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class EmbeddedIdMappingUiProvider - implements AttributeMappingUiProvider<EmbeddedIdMapping> -{ - - // singleton - private static final EmbeddedIdMappingUiProvider INSTANCE = new EmbeddedIdMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<EmbeddedIdMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EmbeddedIdMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_EmbeddedIdLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<EmbeddedIdMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<EmbeddedIdMapping> subjectHolder, - Composite parent, - WidgetFactory 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/details/EmbeddedMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddedMappingUiProvider.java deleted file mode 100644 index 0f21c8fe78..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/EmbeddedMappingUiProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class EmbeddedMappingUiProvider - implements AttributeMappingUiProvider<EmbeddedMapping> -{ - - // singleton - private static final EmbeddedMappingUiProvider INSTANCE = new EmbeddedMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<EmbeddedMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private EmbeddedMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_EmbeddedLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<EmbeddedMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<EmbeddedMapping> subjectHolder, - Composite parent, - WidgetFactory 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/details/IdMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IdMappingUiProvider.java deleted file mode 100644 index d50e8bab47..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/IdMappingUiProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class IdMappingUiProvider - implements AttributeMappingUiProvider<IdMapping> -{ - // singleton - private static final IdMappingUiProvider INSTANCE = new IdMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<IdMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private IdMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_IdLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<IdMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<IdMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createIdMappingComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/ManyToManyMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/ManyToManyMappingUiProvider.java deleted file mode 100644 index 7f515b6aae..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/ManyToManyMappingUiProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class ManyToManyMappingUiProvider - implements AttributeMappingUiProvider<ManyToManyMapping> -{ - // singleton - private static final ManyToManyMappingUiProvider INSTANCE = new ManyToManyMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<ManyToManyMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private ManyToManyMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_ManyToManyLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<ManyToManyMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<ManyToManyMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createManyToManyMappingComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/ManyToOneMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/ManyToOneMappingUiProvider.java deleted file mode 100644 index 5c40cc6239..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/ManyToOneMappingUiProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class ManyToOneMappingUiProvider - implements AttributeMappingUiProvider<ManyToOneMapping> -{ - // singleton - private static final ManyToOneMappingUiProvider INSTANCE = new ManyToOneMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<ManyToOneMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private ManyToOneMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_ManyToOneLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<ManyToOneMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<ManyToOneMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createManyToOneMappingComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/MappedSuperclassUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/MappedSuperclassUiProvider.java deleted file mode 100644 index 54c3240dab..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/MappedSuperclassUiProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class MappedSuperclassUiProvider implements TypeMappingUiProvider<MappedSuperclass> -{ - // singleton - private static final MappedSuperclassUiProvider INSTANCE = new MappedSuperclassUiProvider(); - - /** - * Return the singleton. - */ - public static TypeMappingUiProvider<MappedSuperclass> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private MappedSuperclassUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentTypePage_MappedSuperclassLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForTypeMapping(getMappingKey()); - } - - public JpaComposite<MappedSuperclass> buildPersistentTypeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<MappedSuperclass> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createMappedSuperclassComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingUiProvider.java deleted file mode 100644 index 217fe6d926..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToManyMappingUiProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class OneToManyMappingUiProvider - implements AttributeMappingUiProvider<OneToManyMapping> -{ - // singleton - private static final OneToManyMappingUiProvider INSTANCE = new OneToManyMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<OneToManyMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OneToManyMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_OneToManyLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<OneToManyMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<OneToManyMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createOneToManyMappingComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToOneMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToOneMappingUiProvider.java deleted file mode 100644 index 0904a3d729..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/OneToOneMappingUiProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class OneToOneMappingUiProvider - implements AttributeMappingUiProvider<OneToOneMapping> -{ - - // singleton - private static final OneToOneMappingUiProvider INSTANCE = new OneToOneMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<OneToOneMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OneToOneMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_OneToOneLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<OneToOneMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<OneToOneMapping> subjectHolder, - Composite parent, - WidgetFactory 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/details/PageBookManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PageBookManager.java deleted file mode 100644 index 993b8f88f4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PageBookManager.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Versant. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Versant. - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.part.PageBook; - -/** - * A wrapper for a <code>PageBook</code> with convenience methods. - */ -public class PageBookManager extends PageBook { - - 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<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> - * 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 - * the associated <code>Composite</code> is already active. - */ - public boolean activate(Object anObj) { - if(anObj != null && !anObj.equals(this.active) && this.pageRecords.containsKey(anObj)) { - Composite composite = this.pageRecords.get(anObj); - this.pageBook.showPage(composite); - this.active = anObj; - return true; - } else if((anObj == null || !anObj.equals(this.active)) && !this.pageRecords.containsKey(anObj)) { - this.pageBook.showPage(this.defaultComposite); - this.active = null; - } - return false; - } - - /** - * @param anObj - * @return Returns true if the associated <code>Composite</code> has been deactivated. - * Returns false if there is no <code>Composite</code> for the given <code>Object</code> - * or the <code>Composite</code> is already inactive. - */ - public boolean deactivate(Object anObj) { - if(anObj.equals(this.active)) { - this.pageBook.showPage(this.defaultComposite); - this.active = null; - return true; - } else { - return false; - } - } - - /** - * Associates the specified <code>Object</code> with the specified <code>Composite</code> - * 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 = 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. - * - * @param anObj <code>Object</code> whose mapping is to be removed from this <code>PageBookManager</code>. - * @return previous <code>Composite</code> associated with specified <code>Object</code>. - */ - public Composite remove(Object anObj) { - if(anObj.equals(this.active)) { - this.active = null; - this.pageBook.showPage(this.defaultComposite); - } - return this.pageRecords.remove(anObj); - } - - /** - * @param anObj whose presence in this map is to be tested - * @return true if this <code>PageBookManager</code> contains a mapping for the - * given <code>Object</code>. False otherwise. - */ - public boolean contains(Object anObj) { - return this.pageRecords.containsKey(anObj); - } - - public Composite get(Object key) { - return pageRecords.get(key); - } - - /** - * @return The currently active composite - */ - public Composite getActive() { - if(this.active == null) { - return this.defaultComposite; - } else { - return this.pageRecords.get(this.active); - } - } - - /** - * @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. - */ - public Composite getComposite() { - return this.pageBook; - } - - // a default composite which is show if the active composite - // gets deactivated - private class DefaultComposite extends Composite { - public DefaultComposite(Composite aParent, String aDefaultLabel) { - super(aParent, SWT.NONE); - setLayout(new FillLayout(SWT.VERTICAL)); - Label label = new Label(this, SWT.LEFT); - label.setText(aDefaultLabel); - } - } - - @Override - public void dispose() { - super.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 deleted file mode 100644 index 1dadb315aa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentAttributeDetailsPage.java +++ /dev/null @@ -1,333 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.Tracing; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.model.value.FilteringPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.part.PageBook; - -/** - * The abstract definition of the details page responsible to show the - * information for an persistent attribute. - * - * @see PersistentAttribute - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public abstract class PersistentAttributeDetailsPage<T extends PersistentAttribute> extends AbstractJpaDetailsPage<T> -{ - private JpaComposite<AttributeMapping> currentMappingComposite; - private String currentMappingKey; - private Map<String, JpaComposite<AttributeMapping>> mappingComposites; - 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, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistentAttribute.DEFAULT_MAPPING_PROPERTY); - propertyNames.add(PersistentAttribute.SPECIFIED_MAPPING_PROPERTY); - } - - protected AttributeMappingUiProvider<? extends AttributeMapping> attributeMappingUiProvider(String key) { - for (Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> i = attributeMappingUiProviders(); i.hasNext(); ) { - AttributeMappingUiProvider<? extends AttributeMapping> provider = i.next(); - if (provider.getMappingKey() == key) { - return provider; - } - } - throw new IllegalArgumentException("Unsupported attribute mapping UI provider key: "); - } - - protected abstract Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> - attributeMappingUiProviders(); - - protected abstract AttributeMappingUiProvider<? extends AttributeMapping>[] - attributeMappingUiProvidersFor(PersistentAttribute persistentAttribute); - - private PropertyAspectAdapter<PersistentAttribute, AttributeMapping> buildGenericMappingHolder() { - return new PropertyAspectAdapter<PersistentAttribute, AttributeMapping>( - getSubjectHolder(), - PersistentAttribute.DEFAULT_MAPPING_PROPERTY, - PersistentAttribute.SPECIFIED_MAPPING_PROPERTY) - { - @Override - protected AttributeMapping buildValue_() { - return subject.getMapping(); - } - }; - } - - @SuppressWarnings("unchecked") - protected JpaComposite<AttributeMapping> buildMappingComposite(PageBook pageBook, - String mappingKey) { - - AttributeMappingUiProvider<AttributeMapping> uiProvider = - (AttributeMappingUiProvider<AttributeMapping>) mappingUIProvider(mappingKey); - - return uiProvider.buildAttributeMappingComposite( - jpaUiFactory(), - buildMappingHolder(mappingKey), - pageBook, - getWidgetFactory() - ); - } - - private Filter<AttributeMapping> buildMappingFilter(String mappingKey) { - return new MappingFilter(mappingKey); - } - - private PropertyValueModel<AttributeMapping> buildMappingHolder(final String key) { - return new FilteringPropertyValueModel<AttributeMapping>( - 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); - this.mappingPageBook.showPage(this.buildLabel(this.mappingPageBook, "")); - return this.mappingPageBook; - } - - protected abstract AttributeMappingUiProvider<? extends AttributeMapping> - defaultAttributeMappingUiProvider(String key); - - protected abstract Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> - defaultAttributeMappingUiProviders(); - - /* - * (non-Javadoc) - */ - @Override - protected void doDispose() { - log(Tracing.UI_DETAILS_VIEW, "PersistentAttributeDetailsPage.doDispose()"); - - if (this.currentMappingComposite != null) { - this.currentMappingComposite.dispose(); - this.currentMappingComposite = null; - } - - this.mappingComposites.clear(); - super.doDispose(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - updateMappingPage(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - this.mappingComposites = new HashMap<String, JpaComposite<AttributeMapping>>(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void log(String flag, String message) { - super.log(flag, message); - - if (Tracing.UI_DETAILS_VIEW.equals(flag) && - Tracing.booleanDebugOption(Tracing.UI_DETAILS_VIEW)) - { - Tracing.log(message); - } - } - - private JpaComposite<AttributeMapping> mappingCompositeFor(String key) { - JpaComposite<AttributeMapping> 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; - } - - protected void mappingPageChanged(JpaComposite<AttributeMapping> mappingComposite) { - } - - private AttributeMappingUiProvider<? extends AttributeMapping> mappingUIProvider(String key) { - - if (this.subject().getMapping() == null || - this.subject().getMapping().isDefault()) { - - return defaultAttributeMappingUiProvider(key); - } - - return attributeMappingUiProvider(key); - } - - private void populateMappingPage(String mappingKey) { - - // Nothing to update - if (this.currentMappingKey == mappingKey) { - this.mappingPageChanged(this.currentMappingComposite); - return; - } - // Dispose the existing mapping pane - else if (this.currentMappingComposite != null) { - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentAttributeDetailsPage.populateMappingPage() disposing of current page: " + this.currentMappingKey - ); - - try { - this.currentMappingComposite.dispose(); - this.currentMappingComposite = null; - } - catch (Exception e) { - JptUiPlugin.log(e); - } - } - - this.currentMappingKey = mappingKey; - - // Change the current mapping pane with the new one - if (this.currentMappingKey != null) { - this.currentMappingComposite = mappingCompositeFor(mappingKey); - - try { - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentAttributeDetailsPage.populateMappingPage() populating new page: " + this.currentMappingKey - ); - - this.currentMappingComposite.populate(); - this.mappingPageBook.showPage(this.currentMappingComposite.getControl()); - this.mappingPageChanged(this.currentMappingComposite); - } - catch (Exception e) { - JptUiPlugin.log(e); - - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentAttributeDetailsPage.populateMappingPage() error encountered" - ); - - // An error was encountered either during the population, dispose it - try { - this.currentMappingComposite.dispose(); - } - catch (Exception exception) { - JptUiPlugin.log(e); - } - - this.mappingComposites.remove(this.currentMappingComposite); - this.currentMappingComposite = null; - - // Show an error message - // TODO: Replace the blank label with the error page - this.mappingPageBook.showPage(this.buildLabel(this.mappingPageBook, "")); - } - } - else { - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentAttributeDetailsPage.populateMappingPage() no page to show" - ); - - this.mappingPageBook.showPage(this.buildLabel(this.mappingPageBook, "")); - } - this.repaintDetailsView(this.mappingPageBook); - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == PersistentAttribute.DEFAULT_MAPPING_PROPERTY || - propertyName == PersistentAttribute.SPECIFIED_MAPPING_PROPERTY) { - - updateMappingPage(); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected boolean repopulateWithNullSubject() { - return false; - } - - private void updateMappingPage() { - AttributeMapping mapping = (this.subject() != null) ? this.subject().getMapping() : null; - populateMappingPage(mapping == null ? null : mapping.getKey()); - } - - private class MappingFilter implements Filter<AttributeMapping> { - private String mappingKey; - - MappingFilter(String mappingKey) { - super(); - this.mappingKey = mappingKey; - } - - public boolean accept(AttributeMapping mapping) { - return (mapping == null) || mappingKey.equals(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 deleted file mode 100644 index e5976febd2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/PersistentTypeDetailsPage.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * 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 java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.Tracing; -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.model.value.FilteringPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.PageBook; - -/** - * The abstract definition of the details page responsible to show the - * information for an persistent type. - * - * @see PersistentType - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public abstract class PersistentTypeDetailsPage<T extends PersistentType> extends AbstractJpaDetailsPage<T> -{ - private JpaComposite<? extends TypeMapping> currentMappingComposite; - private String currentMappingKey; - private Map<String, JpaComposite<? extends TypeMapping>> mappingComposites; - 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, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistentType.MAPPING_PROPERTY); - } - - private PropertyAspectAdapter<PersistentType, TypeMapping> buildGenericMappingHolder() { - return new PropertyAspectAdapter<PersistentType, TypeMapping>(getSubjectHolder(), PersistentType.MAPPING_PROPERTY) { - @Override - protected TypeMapping buildValue_() { - return subject.getMapping(); - } - }; - } - - @SuppressWarnings("unchecked") - protected JpaComposite<TypeMapping> buildMappingComposite(PageBook pageBook, - String key) { - - TypeMappingUiProvider<TypeMapping> uiProvider = - (TypeMappingUiProvider<TypeMapping>) typeMappingUiProvider(key); - - return uiProvider.buildPersistentTypeMappingComposite( - jpaUiFactory(), - buildMappingHolder(key), - pageBook, - getWidgetFactory() - ); - } - - private Filter<TypeMapping> buildMappingFilter(final String key) { - return new Filter<TypeMapping>() { - public boolean accept(TypeMapping value) { - return (value == null) || key.equals(value.getKey()); - } - }; - } - - private PropertyValueModel<TypeMapping> buildMappingHolder(String key) { - return new FilteringPropertyValueModel<TypeMapping>( - buildGenericMappingHolder(), - buildMappingFilter(key) - ); - } - - protected PageBook buildTypeMappingPageBook(Composite parent) { - - this.typeMappingPageBook = new PageBook(parent, SWT.NONE); - this.typeMappingPageBook.showPage(this.buildLabel(this.typeMappingPageBook, "")); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.TOP; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - - this.typeMappingPageBook.setLayoutData(gridData); - - return this.typeMappingPageBook; - } - - /* - * (non-Javadoc) - */ - @Override - protected void doDispose() { - log(Tracing.UI_DETAILS_VIEW, "PersistentTypeDetailsPage.doDispose()"); - - if (this.currentMappingComposite != null) { - this.currentMappingComposite.dispose(); - this.currentMappingComposite = null; - } - - this.mappingComposites.clear(); - super.doDispose(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - updateMappingPage(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - this.mappingComposites = new HashMap<String, JpaComposite<? extends TypeMapping>>(); - } - - private JpaComposite<? extends TypeMapping> mappingCompositeFor(String key) { - JpaComposite<? extends TypeMapping> mappingComposite = this.mappingComposites.get(key); - if (mappingComposite != null) { - return mappingComposite; - } - - mappingComposite = buildMappingComposite(this.typeMappingPageBook, key); - - if (mappingComposite != null) { - this.mappingComposites.put(key, mappingComposite); - } - - return mappingComposite; - } - - private void populateMappingPage(String mappingKey) { - - // Nothing to update - if (this.currentMappingKey == mappingKey) { - return; - } - // Dispose the existing mapping pane - else if (this.currentMappingComposite != null) { - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentTypeDetailsPage.populateMappingPage() disposing of current page: " + this.currentMappingKey - ); - - try { - this.currentMappingComposite.dispose(); - this.currentMappingComposite = null; - } - catch (Exception e) { - JptUiPlugin.log(e); - } - } - - this.currentMappingKey = mappingKey; - - // Change the current mapping pane with the new one - if (this.currentMappingKey != null) { - this.currentMappingComposite = mappingCompositeFor(mappingKey); - - // Show the new mapping pane - try { - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentTypeDetailsPage.populateMappingPage() populating new page: " + this.currentMappingKey - ); - - this.currentMappingComposite.populate(); - this.typeMappingPageBook.showPage(this.currentMappingComposite.getControl()); - } - catch (Exception e) { - JptUiPlugin.log(e); - - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentTypeDetailsPage.populateMappingPage() error encountered" - ); - - // An error was encountered either during the population, dispose it - try { - this.currentMappingComposite.dispose(); - } - catch (Exception exception) { - JptUiPlugin.log(e); - } - - this.mappingComposites.remove(this.currentMappingComposite); - this.currentMappingComposite = null; - - // Show an error message - // TODO: Replace the blank label with the error page - this.typeMappingPageBook.showPage(this.buildLabel(this.typeMappingPageBook, "")); - } - } - // Clear the mapping pane and show a blank page - else { - this.log( - Tracing.UI_DETAILS_VIEW, - "PersistentTypeDetailsPage.populateMappingPage() no page to show" - ); - - this.typeMappingPageBook.showPage(this.buildLabel(this.typeMappingPageBook, "")); - } - this.repaintDetailsView(this.typeMappingPageBook); - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == PersistentType.MAPPING_PROPERTY) { - updateMappingPage(); - } - } - - private TypeMappingUiProvider<? extends TypeMapping> typeMappingUiProvider(String key) { - for (Iterator<TypeMappingUiProvider<? extends TypeMapping>> iter = this.typeMappingUiProviders(); iter.hasNext();) { - TypeMappingUiProvider<? extends TypeMapping> provider = iter.next(); - if (provider.getMappingKey() == key) { - return provider; - } - } - throw new IllegalArgumentException("Unsupported type mapping UI provider key: " + key); - } - - protected abstract Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders(); - - private void updateMappingPage() { - TypeMapping 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/TransientMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/TransientMappingUiProvider.java deleted file mode 100644 index ab09a4f839..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/TransientMappingUiProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class TransientMappingUiProvider - implements AttributeMappingUiProvider<TransientMapping> -{ - - // singleton - private static final TransientMappingUiProvider INSTANCE = new TransientMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<TransientMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private TransientMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_TransientLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<TransientMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<TransientMapping> subjectHolder, - Composite parent, - WidgetFactory 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/details/VersionMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/VersionMappingUiProvider.java deleted file mode 100644 index cfc84ac08a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/details/VersionMappingUiProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class VersionMappingUiProvider - implements AttributeMappingUiProvider<VersionMapping> -{ - - // singleton - private static final VersionMappingUiProvider INSTANCE = new VersionMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<VersionMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private VersionMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentAttributePage_VersionLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<VersionMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<VersionMapping> subjectHolder, - Composite parent, - WidgetFactory 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/dialogs/AddPersistentAttributeToXmlAndMapDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java deleted file mode 100644 index b639d38531..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.dialogs; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.StatusDialog; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -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.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.details.BasicMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.EmbeddedIdMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.EmbeddedMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.IdMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.ManyToManyMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.ManyToOneMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.OneToManyMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.OneToOneMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.TransientMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.VersionMappingUiProvider; -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.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog -{ - private OrmPersistentAttribute unmappedPersistentAttribute; - private Text attributeText; - private ComboViewer mappingCombo; - - public AddPersistentAttributeToXmlAndMapDialog(Shell parentShell, OrmPersistentAttribute 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() { -// public void modifyText(ModifyEvent e) { -// validate(); -// } -// } -// ); - attributeText.setText(unmappedPersistentAttribute.getName()); - attributeText.setEditable(false); - - createLabel(composite, 1, JptUiMessages.AddPersistentClassDialog_mappingLabel); - - mappingCombo = new ComboViewer(createCombo(composite, 1)); - mappingCombo.getCombo().setFocus(); - mappingCombo.setContentProvider( - new IStructuredContentProvider() { - public void dispose() {} - - public Object[] getElements(Object inputElement) { - return new Object[] { - BasicMappingUiProvider.instance(), - EmbeddedMappingUiProvider.instance(), - EmbeddedIdMappingUiProvider.instance(), - IdMappingUiProvider.instance(), - ManyToManyMappingUiProvider.instance(), - ManyToOneMappingUiProvider.instance(), - OneToManyMappingUiProvider.instance(), - OneToOneMappingUiProvider.instance(), - TransientMappingUiProvider.instance(), - VersionMappingUiProvider.instance() - }; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} - }); - mappingCombo.setLabelProvider( - new LabelProvider() { - @Override - public String getText(Object element) { - return ((AttributeMappingUiProvider) element).getLabel(); - } - }); - mappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - validate(); - } - }); - 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); - - validate(); - - return dialogArea; - } - - private Label createLabel(Composite container, int span, String text) { - Label label = new Label(container, SWT.NONE); - label.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - 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); - gd.horizontalSpan = span; - gd.widthHint = 250; - 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); - gd.horizontalSpan = span; - combo.setLayoutData(gd); - return combo; - } - - public String getAttributeName() { - return attributeText.getText(); - } - - public String getMappingKey() { - StructuredSelection selection = (StructuredSelection) mappingCombo.getSelection(); - return (selection.isEmpty()) ? null : ((AttributeMappingUiProvider) selection.getFirstElement()).getMappingKey(); - } - - private void validate() { -// if (entityMappings.containsPersistentType(type)) { -// updateStatus( -// new Status( -// IStatus.WARNING, JptUiPlugin.PLUGIN_ID, -// JptUiMessages.AddPersistentClassDialog_duplicateClassWarning)); -// return; -// } -// - String mappingKey = getMappingKey(); - if (mappingKey == null) { - updateStatus( - new Status( - IStatus.ERROR, JptUiPlugin.PLUGIN_ID, - JptUiMessages.AddPersistentAttributeDialog_noMappingKeyError)); - return; - } - - updateStatus(Status.OK_STATUS); - } - - @Override - protected void okPressed() { - unmappedPersistentAttribute.makeSpecified(getMappingKey()); - super.okPressed(); - } -} 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 deleted file mode 100644 index c220f3a708..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentClassDialog.java +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.dialogs; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.search.IJavaSearchScope; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jdt.ui.IJavaElementSearchConstants; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.dialogs.StatusDialog; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -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.jface.window.Window; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.details.EmbeddableUiProvider; -import org.eclipse.jpt.ui.internal.details.MappedSuperclassUiProvider; -import org.eclipse.jpt.ui.internal.orm.details.OrmEntityUiProvider; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.progress.IProgressService; - -public class AddPersistentClassDialog extends StatusDialog -{ - private EntityMappings entityMappings; - - private Text classText; - - private Button classBrowseButton; - - private ComboViewer mappingCombo; - - private OrmPersistentType addedType; - - - 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); - - Composite composite = new Composite(dialogArea, SWT.NULL); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - composite.setLayout(new GridLayout(2, false)); - - createLabel(composite, 2, JptUiMessages.AddPersistentClassDialog_classLabel); - - this.classText = createText(composite, 1); - this.classText.addModifyListener( - new ModifyListener() { - public void modifyText(ModifyEvent e) { - validate(); - } - } - ); - - this.classBrowseButton = createButton(composite, 1, JptUiMessages.General_browse); - this.classBrowseButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - IType type = chooseType(); - if (type != null) { - classText.setText(type.getFullyQualifiedName('.')); - } - } - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - }); - - createLabel(composite, 2, JptUiMessages.AddPersistentClassDialog_mappingLabel); - - this.mappingCombo = new ComboViewer(createCombo(composite, 2)); - this.mappingCombo.setContentProvider( - new IStructuredContentProvider() { - public void dispose() {} - - public Object[] getElements(Object inputElement) { - return new Object[] { - MappedSuperclassUiProvider.instance(), - OrmEntityUiProvider.instance(), - EmbeddableUiProvider.instance() - }; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} - }); - this.mappingCombo.setLabelProvider( - new LabelProvider() { - @Override - public String getText(Object element) { - return ((TypeMappingUiProvider<?>) element).getLabel(); - } - }); - this.mappingCombo.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - validate(); - } - }); - 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); - - //getButton(IDialogConstants.OK_ID).setEnabled(false); // disabled to start - applyDialogFont(dialogArea); - - validate(); - - return dialogArea; - } - - private Label createLabel(Composite container, int span, String text) { - Label label = new Label(container, SWT.NONE); - label.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - 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); - gd.horizontalSpan = span; - gd.widthHint = 250; - text.setLayoutData(gd); - return text; - } - - private Button createButton(Composite container, int span, String text) { - Button button = new Button(container, SWT.NONE); - button.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - button.setLayoutData(gd); - return button; - } - - 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); - gd.horizontalSpan = span; - combo.setLayoutData(gd); - return combo; - } - - private JpaProject getJpaProject() { - return this.entityMappings.getJpaProject(); - } - - public String getClassName() { - return this.classText.getText(); - } - - public String getMappingKey() { - StructuredSelection selection = (StructuredSelection) this.mappingCombo.getSelection(); - return (selection.isEmpty()) ? null : ((TypeMappingUiProvider<?>) selection.getFirstElement()).getMappingKey(); - } - - protected IType chooseType() { - IJavaElement[] elements= new IJavaElement[] { getJpaProject().getJavaProject() }; - IJavaSearchScope scope= SearchEngine.createJavaSearchScope(elements); - IProgressService service = PlatformUI.getWorkbench().getProgressService(); - - SelectionDialog typeSelectionDialog; - try { - typeSelectionDialog = - JavaUI.createTypeDialog( - getShell(), service, scope, - IJavaElementSearchConstants.CONSIDER_CLASSES, - false, getClassName()); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - throw new RuntimeException(e); - } - typeSelectionDialog.setTitle(JptUiMessages.AddPersistentClassDialog_classDialog_title); - typeSelectionDialog.setMessage(JptUiMessages.AddPersistentClassDialog_classDialog_message); - - if (typeSelectionDialog.open() == Window.OK) { - return (IType) typeSelectionDialog.getResult()[0]; - } - return null; - } - - private void validate() { - String className = getClassName(); - - if (StringTools.stringIsEmpty(className)) { - updateStatus( - new Status( - IStatus.ERROR, JptUiPlugin.PLUGIN_ID, - JptUiMessages.AddPersistentClassDialog_noClassError)); - return; - } - - IType type; - try { - type = getJpaProject().getJavaProject().findType(className); - } - catch (JavaModelException jme) { - type = null; - } - - if (type == null) { - updateStatus( - new Status( - IStatus.WARNING, JptUiPlugin.PLUGIN_ID, - JptUiMessages.AddPersistentClassDialog_classNotFoundWarning)); - return; - } - - if (this.entityMappings.containsPersistentType(className)) { - updateStatus( - new Status( - IStatus.WARNING, JptUiPlugin.PLUGIN_ID, - JptUiMessages.AddPersistentClassDialog_duplicateClassWarning)); - return; - } - - String mappingKey = getMappingKey(); - if (mappingKey == null) { - updateStatus( - new Status( - IStatus.ERROR, JptUiPlugin.PLUGIN_ID, - JptUiMessages.AddPersistentClassDialog_noMappingKeyError)); - return; - } - - updateStatus(Status.OK_STATUS); - } - - @Override - protected void okPressed() { - this.addedType = this.entityMappings.addOrmPersistentType(getMappingKey(), getClassName()); - super.okPressed(); - } - - public OrmPersistentType openAndReturnType() { - super.open(); - return addedType; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceContributor.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceContributor.java deleted file mode 100644 index 140803aa3a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceContributor.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.editors; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.ide.IDEActionFactory; -import org.eclipse.ui.part.MultiPageEditorActionBarContributor; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; - -/** - * - * @version 2.0 - * @since 2.0 - */ -public class PersistenceContributor extends MultiPageEditorActionBarContributor { - - private IEditorPart activeEditorPart; - - /** - * Creates a new <code>PersistenceContributor</code>. - */ - public PersistenceContributor() { - super(); - } - - /* - * (non-Javadoc) - */ - @Override - public void contributeToMenu(IMenuManager manager) { - } - - /* - * (non-Javadoc) - */ - @Override - public void contributeToToolBar(IToolBarManager manager) { - } - - /** - * Returns the action registed with the given text editor. - * @return IAction or null if editor is null. - */ - protected IAction getAction(ITextEditor editor, String actionID) { - return (editor == null ? null : editor.getAction(actionID)); - } - - /* - * (non-Javadoc) - */ - @Override - public void setActivePage(IEditorPart part) { - - if (activeEditorPart == part) - return; - - activeEditorPart = part; - - IActionBars actionBars = getActionBars(); - if (actionBars != null) { - - ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null; - - actionBars.setGlobalActionHandler( - ActionFactory.DELETE.getId(), - getAction(editor, ITextEditorActionConstants.DELETE)); - actionBars.setGlobalActionHandler( - ActionFactory.UNDO.getId(), - getAction(editor, ITextEditorActionConstants.UNDO)); - actionBars.setGlobalActionHandler( - ActionFactory.REDO.getId(), - getAction(editor, ITextEditorActionConstants.REDO)); - actionBars.setGlobalActionHandler( - ActionFactory.CUT.getId(), - getAction(editor, ITextEditorActionConstants.CUT)); - actionBars.setGlobalActionHandler( - ActionFactory.COPY.getId(), - getAction(editor, ITextEditorActionConstants.COPY)); - actionBars.setGlobalActionHandler( - ActionFactory.PASTE.getId(), - getAction(editor, ITextEditorActionConstants.PASTE)); - actionBars.setGlobalActionHandler( - ActionFactory.SELECT_ALL.getId(), - getAction(editor, ITextEditorActionConstants.SELECT_ALL)); - actionBars.setGlobalActionHandler( - ActionFactory.FIND.getId(), - getAction(editor, ITextEditorActionConstants.FIND)); - actionBars.setGlobalActionHandler( - IDEActionFactory.BOOKMARK.getId(), - getAction(editor, IDEActionFactory.BOOKMARK.getId())); - actionBars.updateActionBars(); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceEditor.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceEditor.java deleted file mode 100644 index b93684fad5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceEditor.java +++ /dev/null @@ -1,447 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.editors; - -import java.util.ListIterator; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaPageComposite; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -import org.eclipse.jpt.ui.internal.widgets.FormWidgetFactory; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListPropertyValueModelAdapter; -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.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.IManagedForm; -import org.eclipse.ui.forms.editor.FormEditor; -import org.eclipse.ui.forms.editor.FormPage; -import org.eclipse.ui.forms.widgets.ScrolledForm; -import org.eclipse.ui.forms.widgets.TableWrapData; -import org.eclipse.ui.forms.widgets.TableWrapLayout; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.sse.ui.StructuredTextEditor; - -/** - * This is the editor for the JPA Persistence Configuration (persistence.xml). - * The pages shown before the XML source editor are retrieved from the - * <code>JpaUiFactory</code>. - * - * @see JpaUiFactory - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class PersistenceEditor extends FormEditor -{ - /** - * The XML text editor. - */ - private StructuredTextEditor editor; - - /** - * The root of the holders used to retrieve the persistence unit and be - * notified when it changes. - */ - private WritablePropertyValueModel<IFileEditorInput> editorInputHolder; - - /** - * The factory used to create the various widgets. - */ - private WidgetFactory widgetFactory; - - /** - * Creates a new <code>PersistenceEditor</code>. - */ - public PersistenceEditor() { - super(); - initialize(); - } - - @Override - @SuppressWarnings("unchecked") - public Object getAdapter(Class adapterClass) { - Object adapter = super.getAdapter(adapterClass); - if (adapter == null) { - adapter = editor.getAdapter(adapterClass); - } - return adapter; - } - - /** - * {@inheritDoc} - */ - @Override - protected void addPages() { - addPersistenceUnitPages(); - addXMLEditorPage(); - } - - /** - * Adds the pages that show the properties of the persistence configuration - * or its persistence units. - */ - private void addPersistenceUnitPages() { - - JpaProject jpaProject = jpaProject(); - - // The project doesn't have JPA - if (jpaProject == null) { - return; - } - - String platformId = jpaProject.getJpaPlatform().getId(); - JpaPlatformUi jpaPlatformUI = JpaPlatformUiRegistry.instance().jpaPlatform(platformId); - JpaUiFactory uiFactory = jpaPlatformUI.getJpaUiFactory(); - - ListIterator<JpaPageComposite<PersistenceUnit>> pages = uiFactory.createPersistenceUnitComposites( - buildPersistenceUnitHolder(), - getContainer(), - widgetFactory - ); - - while (pages.hasNext()) { - JpaPageComposite<PersistenceUnit> page = pages.next(); - - try { - FormPage formPage = new Page(page); - addPage(formPage); - } - catch (PartInitException e) { - // TODO - } - } - } - - /** - * Adds the page containing the XML editor. - */ - private void addXMLEditorPage() { - try { - editor = new StructuredTextEditor(); - editor.setEditorPart(this); - int index = addPage(editor, getEditorInput()); - setPageText(index, JptUiPersistenceMessages.PersistenceEditor_sourceTab); - } - catch (PartInitException e) { - // TODO - } - } - - private WritablePropertyValueModel<IFileEditorInput> buildEditorInputHolder() { - return new SimplePropertyValueModel<IFileEditorInput>(); - } - - private PropertyValueModel<JpaProject> buildJpaProjectHolder() { - return new TransformationPropertyValueModel<IFileEditorInput, JpaProject>(editorInputHolder) { - @Override - protected JpaProject transform_(IFileEditorInput value) { - return JptCorePlugin.getJpaProject(value.getFile().getProject()); - } - }; - } - - private PropertyValueModel<Persistence> buildPersistenceHolder() { - return new PropertyAspectAdapter<PersistenceXml, Persistence>(buildPersistenceXmlHolder(), PersistenceXml.PERSISTENCE_PROPERTY) { - @Override - protected Persistence buildValue_() { - return subject.getPersistence(); - } - }; - } - - private PropertyValueModel<PersistenceUnit> buildPersistenceUnitHolder() { - return new ListPropertyValueModelAdapter<PersistenceUnit>(buildPersistenceUnitListHolder()) { - @Override - protected PersistenceUnit buildValue() { - return listHolder.size() > 0 ? (PersistenceUnit) listHolder.get(0) : null; - } - }; - } - - private ListValueModel<PersistenceUnit> buildPersistenceUnitListHolder() { - return new ListAspectAdapter<Persistence, PersistenceUnit>(buildPersistenceHolder(), Persistence.PERSISTENCE_UNITS_LIST) { - @Override - protected ListIterator<PersistenceUnit> listIterator_() { - return subject.persistenceUnits(); - } - - @Override - protected int size_() { - return subject.persistenceUnitsSize(); - } - }; - } - - private PropertyValueModel<PersistenceXml> buildPersistenceXmlHolder() { - return new PropertyAspectAdapter<JpaRootContextNode, PersistenceXml>(buildRootContextNodeHolder(), JpaRootContextNode.PERSISTENCE_XML_PROPERTY) { - @Override - protected PersistenceXml buildValue_() { - return subject.getPersistenceXml(); - } - }; - } - - private PropertyValueModel<JpaRootContextNode> buildRootContextNodeHolder() { - return new TransformationPropertyValueModel<JpaProject, JpaRootContextNode>(buildJpaProjectHolder()) { - @Override - protected JpaRootContextNode transform_(JpaProject value) { - return value.getRootContext(); - } - }; - } - - private WidgetFactory buildWidgetFactory() { - return new FormWidgetFactory( - new TabbedPropertySheetWidgetFactory() - ); - } - - /** - * {@inheritDoc} - */ - @Override - public void dispose() { - - editorInputHolder.setValue(null); - - super.dispose(); - } - - /** - * {@inheritDoc} - */ - @Override - public void doSave(IProgressMonitor monitor) { - getEditor(getPageCount() - 1).doSave(monitor); - } - - /** - * {@inheritDoc} - */ - @Override - public void doSaveAs() { - } - - /** - * {@inheritDoc} - */ - @Override - public IFileEditorInput getEditorInput() { - return (IFileEditorInput) super.getEditorInput(); - } - - /** - * {@inheritDoc} - */ - @Override - public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException { - Assert.isLegal(editorInput instanceof IFileEditorInput, "Invalid Input: Must be IFileEditorInput"); - super.init(site, editorInput); - - setPartName(editorInput.getName()); - editorInputHolder.setValue(getEditorInput()); - } - - /** - * Initializes this multi-page editor. - */ - private void initialize() { - - widgetFactory = buildWidgetFactory(); - editorInputHolder = buildEditorInputHolder(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSaveAsAllowed() { - return false; - } - - /** - * Retrieves the JPA project associated with the project owning the editor - * intput file. - * - * @return The JPA project - */ - protected JpaProject jpaProject() { - return JptCorePlugin.getJpaProject(getEditorInput().getFile().getProject()); - } - - /** - * This extension over <code>FormPage</code> simply complete the layout by - * using the <code>JpaPageComposite</code>'s control as its form content. - */ - private class Page extends FormPage { - - /** - * The wrapped page that actually contains the widgets to show with this - * form page. - */ - private final JpaPageComposite<PersistenceUnit> page; - - /** - * Creates a new <code>Page</code>. - * - * @param page The wrapped <code>JpaPageComposite</code> - */ - private Page(JpaPageComposite<PersistenceUnit> page) { - - super(PersistenceEditor.this, - page.getClass().getName(), - page.getPageText()); - - this.page = page; - } - - /** - * {@inheritDoc} - */ - @Override - protected void createFormContent(IManagedForm managedForm) { - - ScrolledForm form = managedForm.getForm(); - managedForm.getToolkit().decorateFormHeading(form.getForm()); - - // Update the text and image - updateForm(form); - - // Update the layout - updateBody(form); - - // This will finish the initialization of the buttons - updateHelpButton(); - form.updateToolBar(); - - // Populate the page - page.populate(); - } - - /** - * {@inheritDoc} - */ - @Override - public void dispose() { - page.dispose(); - super.dispose(); - } - - /** - * {@inheritDoc} - */ - @Override - public void setFocus() { - page.getControl().setFocus(); - } - - /** - * Adds the page's control to this page. - * - * @param form The form containing the composite with which the page's - * control is parented - */ - private void updateBody(ScrolledForm form) { - - Composite body = form.getBody(); - - body.setLayout(new TableWrapLayout()); - - TableWrapData wrapData = new TableWrapData( - TableWrapData.FILL_GRAB, - TableWrapData.FILL_GRAB - ); - - page.getControl().setLayoutData(wrapData); - page.getControl().setParent(body); - } - - /** - * Updates the text and image of the form. - * - * @param form The form to have its title bar updated by setting the text - * and image, the image can be <code>null</code> - */ - private void updateForm(ScrolledForm form) { - - form.setText(page.getPageText()); - - Image image = page.getPageImage(); - - if (image != null) { - form.setImage(image); - } - } - - /** - * Adds a help button to the page's toolbar if a help ID exists. - */ - private void updateHelpButton() { - - String helpID = page.getHelpID(); - - if (helpID != null) { - Action helpAction = new HelpAction(helpID); - - ScrolledForm form = getManagedForm().getForm(); - IToolBarManager manager = form.getToolBarManager(); - manager.add(helpAction); - } - } - - private class HelpAction extends Action { - - private final String helpID; - - HelpAction(String helpID) { - super(JptUiPersistenceMessages.PersistenceEditor_page_help, - JFaceResources.getImageRegistry().getDescriptor(Dialog.DLG_IMG_HELP)); - - this.helpID = helpID; - } - - @Override - public void run() { - BusyIndicator.showWhile(getManagedForm().getForm().getDisplay(), new Runnable() { - public void run() { - PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpID); - } - }); - } - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/DefaultBasicMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/DefaultBasicMappingUiProvider.java deleted file mode 100644 index 0f331d7b12..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/DefaultBasicMappingUiProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class DefaultBasicMappingUiProvider - implements AttributeMappingUiProvider<BasicMapping> -{ - // singleton - private static final DefaultBasicMappingUiProvider INSTANCE = new DefaultBasicMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<BasicMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private DefaultBasicMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return NLS.bind( - JptUiMappingsMessages.DefaultBasicMappingUiProvider_Default, - JptUiMappingsMessages.PersistentAttributePage_BasicLabel - ); - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<BasicMapping> buildAttributeMappingComposite(JpaUiFactory factory, - PropertyValueModel<BasicMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createBasicMappingComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/DefaultEmbeddedMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/DefaultEmbeddedMappingUiProvider.java deleted file mode 100644 index 7232f6999f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/DefaultEmbeddedMappingUiProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class DefaultEmbeddedMappingUiProvider - implements AttributeMappingUiProvider<EmbeddedMapping> -{ - // singleton - private static final DefaultEmbeddedMappingUiProvider INSTANCE = new DefaultEmbeddedMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<EmbeddedMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private DefaultEmbeddedMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; - } - - public String getLabel() { - return NLS.bind( - JptUiMappingsMessages.DefaultEmbeddedMappingUiProvider_Default, - JptUiMappingsMessages.PersistentAttributePage_EmbeddedLabel - ); - } - - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - public JpaComposite<EmbeddedMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<EmbeddedMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createEmbeddedMappingComposite(subjectHolder, parent, 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 deleted file mode 100644 index 1f7f36fde4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaDetailsPage; -import org.eclipse.jpt.ui.details.JpaDetailsProvider; -import org.eclipse.swt.widgets.Composite; - -/** - * 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 JpaDetailsProvider -{ - /** - * Creates a new <code>JavaDetailsProvider</code>. - */ - public JavaDetailsProvider() { - super(); - } - - /* - * (non-Javadoc) - */ - public JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage( - Composite parent, - Object contentNodeId, - WidgetFactory widgetFactory) { - - if (contentNodeId == JavaStructureNodes.PERSISTENT_TYPE_ID) { - return new JavaPersistentTypeDetailsPage(parent, widgetFactory); - } - - if (contentNodeId == JavaStructureNodes.PERSISTENT_ATTRIBUTE_ID) { - return new JavaPersistentAttributeDetailsPage(parent, widgetFactory); - } - - 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/JavaEntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaEntityComposite.java deleted file mode 100644 index 5c237ca702..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaEntityComposite.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractEntityComposite; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * The pane used for a Java entity. - * - * @see JavaEntity - * @see BaseJpaUiFactory - The factory creating this pane - * @see JavaSecondaryTablesComposite - * - * @version 2.0 - * @since 1.0 - */ -public class JavaEntityComposite extends AbstractEntityComposite<JavaEntity> -{ - /** - * Creates a new <code>JavaEntityComposite</code>. - * - * @param subjectHolder The holder of the subject <code>JavaEntity</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public JavaEntityComposite(PropertyValueModel<? extends JavaEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected void buildSecondaryTablesComposite(Composite container) { - new JavaSecondaryTablesComposite(this, container); - } - - @Override - protected void buildInheritanceComposite(Composite container) { - new JavaInheritanceComposite(this, container); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaEntityUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaEntityUiProvider.java deleted file mode 100644 index baa36c4a2b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaEntityUiProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class JavaEntityUiProvider implements TypeMappingUiProvider<JavaEntity> -{ - // singleton - private static final JavaEntityUiProvider INSTANCE = new JavaEntityUiProvider(); - - /** - * Return the singleton. - */ - public static TypeMappingUiProvider<JavaEntity> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private JavaEntityUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentTypePage_EntityLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForTypeMapping(getMappingKey()); - } - - public JpaComposite<JavaEntity> buildPersistentTypeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<JavaEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createJavaEntityComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaInheritanceComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaInheritanceComposite.java deleted file mode 100644 index db97167753..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaInheritanceComposite.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractInheritanceComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * The pane used for java inheritance. - * - * @see JavaEntity - * @see JavaPrimaryKeyJoinColumnsComposite - * - * @version 2.0 - * @since 1.0 - */ -public class JavaInheritanceComposite extends AbstractInheritanceComposite<JavaEntity> { - - /** - * Creates a new <code>JavaInheritanceComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public JavaInheritanceComposite(AbstractPane<JavaEntity> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>JavaInheritanceComposite</code>. - * - * @param subjectHolder The holder of the subject <code>JavaEntity</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public JavaInheritanceComposite(PropertyValueModel<JavaEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected void buildPrimaryKeyJoinColumnsComposite(Composite container) { - new JavaPrimaryKeyJoinColumnsComposite(this, container); - } -}
\ 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 deleted file mode 100644 index 50ae6cc683..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeDetailsPage.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.PersistentAttributeDetailsPage; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.PageBook; - -/** - * The default implementation of the details page used for the Java persistent - * attribute. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | JavaPersistentAttributeMapAsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | Type mapping pane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see JavaPersistentAttribute - * @see JavaPersistentTypeMapAsComposite - * - * @version 2.0 - * @since 2.0 - */ -public class JavaPersistentAttributeDetailsPage extends PersistentAttributeDetailsPage<JavaPersistentAttribute> -{ - /** - * 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, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders() { - return 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. - */ - @Override - protected AttributeMappingUiProvider<? extends AttributeMapping>[] attributeMappingUiProvidersFor(PersistentAttribute persistentAttribute) { - AttributeMappingUiProvider<? extends AttributeMapping>[] providers = new AttributeMappingUiProvider<?>[CollectionTools.size(attributeMappingUiProviders()) + 1]; - providers[0] = defaultAttributeMappingUiProvider(persistentAttribute.getDefaultMappingKey()); - int i = 1; - for (Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> iterator = attributeMappingUiProviders(); iterator.hasNext(); ) { - providers[i++] = iterator.next(); - } - return providers; - } - - /* - * (non-Javadoc) - */ - @Override - protected AttributeMappingUiProvider<? extends AttributeMapping> defaultAttributeMappingUiProvider(String key) { - for (Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> i = defaultAttributeMappingUiProviders(); i.hasNext(); ) { - AttributeMappingUiProvider<? extends AttributeMapping> provider = i.next(); - - if (provider.getMappingKey() == key) { - return provider; - } - } - - return this.nullAttributeMappingUiProvider(); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> defaultAttributeMappingUiProviders() { - return jpaPlatformUi().defaultJavaAttributeMappingUiProviders(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Map as composite - new JavaPersistentAttributeMapAsComposite( - this, - buildSubPane(container, 0, 0, 5, 0) - ); - - // Mapping properties page - PageBook mappingPane = buildMappingPageBook(container); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.TOP; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - - mappingPane.setLayoutData(gridData); - } - - protected AttributeMappingUiProvider<AttributeMapping> 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/JavaPersistentAttributeMapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeMapAsComposite.java deleted file mode 100644 index da1e043e18..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentAttributeMapAsComposite.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.internal.mappings.details.PersistentAttributeMapAsComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.swt.widgets.Composite; - -/** - * This "Map As" composite is responsible for showing the mapping name and - * mapping type for an attribute declared in a Java type. - * - * @see JavaPersistentAttribute - * @see JavaPersistentAttributeDetailsPage - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class JavaPersistentAttributeMapAsComposite extends PersistentAttributeMapAsComposite<JavaPersistentAttribute> { - - /** - * Creates a new <code>JavaPersistentAttributeMapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public JavaPersistentAttributeMapAsComposite(AbstractPane<? extends JavaPersistentAttribute> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders() { - return jpaPlatformUi().javaAttributeMappingUiProviders(); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> defaultAttributeMappingUiProviders() { - return jpaPlatformUi().defaultJavaAttributeMappingUiProviders(); - } -} 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 deleted file mode 100644 index 78311b8fa6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPersistentTypeDetailsPage.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.PersistentTypeDetailsPage; -import org.eclipse.jpt.ui.internal.mappings.details.JavaPersistentTypeMapAsComposite; -import org.eclipse.swt.widgets.Composite; - -/** - * The default implementation of the details page used for the Java persistent - * type. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | JavaPersistentTypeMapAsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | Type mapping pane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see JavaPersistentType - * @see JavaPersistentTypeMapAsComposite - * - * @version 2.0 - * @since 2.0 - */ -public class JavaPersistentTypeDetailsPage extends PersistentTypeDetailsPage<JavaPersistentType> -{ - /** - * 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, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders() { - return jpaPlatformUi().javaTypeMappingUiProviders(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Map As composite - new JavaPersistentTypeMapAsComposite( - this, - buildSubPane(container, 0, 0, 5, 0) - ); - - // Type properties page - buildTypeMappingPageBook(container); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPrimaryKeyJoinColumnsComposite.java deleted file mode 100644 index 374da4cb7c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaPrimaryKeyJoinColumnsComposite.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractPrimaryKeyJoinColumnsComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * @see JavaEntity - * @see JavaInheritanceComposite - The container of this pane - * - * @version 2.0 - * @since 2.0 - */ -public class JavaPrimaryKeyJoinColumnsComposite extends AbstractPrimaryKeyJoinColumnsComposite<JavaEntity> -{ - - /** - * Creates a new <code>JavaPrimaryKeyJoinColumnsComposite</code>. - * - * @param parentPane The parent controller of this one - * @param parent The parent container - */ - public JavaPrimaryKeyJoinColumnsComposite(AbstractPane<? extends JavaEntity> subjectHolder, - Composite parent) { - - super(subjectHolder, parent); - } - - /** - * Creates a new <code>JavaPrimaryKeyJoinColumnsComposite</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 JavaPrimaryKeyJoinColumnsComposite(PropertyValueModel<? extends JavaEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected ListValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnsListHolder() { - return new PropertyListValueModelAdapter<PrimaryKeyJoinColumn>(buildDefaultJoinColumnHolder()); - } - - private PropertyValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnHolder() { - return new PropertyAspectAdapter<Entity, PrimaryKeyJoinColumn>(getSubjectHolder(), Entity.DEFAULT_PRIMARY_KEY_JOIN_COLUMN) { - @Override - protected PrimaryKeyJoinColumn buildValue_() { - return subject.getDefaultPrimaryKeyJoinColumn(); - } - }; - } - - @Override - protected void switchDefaultToSpecified() { - PrimaryKeyJoinColumn defaultJoinColumn = subject().getDefaultPrimaryKeyJoinColumn(); - - if (defaultJoinColumn != null) { - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - PrimaryKeyJoinColumn pkJoinColumn = subject().addSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - - this.joinColumnHolder.setValue(pkJoinColumn); - } - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaSecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaSecondaryTablesComposite.java deleted file mode 100644 index aa051bf954..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaSecondaryTablesComposite.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractSecondaryTablesComposite; -import org.eclipse.jpt.ui.internal.mappings.details.PrimaryKeyJoinColumnsInSecondaryTableComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PrimaryKeyJoinColumnsInSecondaryTableComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see EntityComposite - The container of this pane - * @see AddRemoveListPane - * @see PrimaryKeyJoinColumnsInSecondaryTableComposite - * - * @version 2.0 - * @since 1.0 - */ -public class JavaSecondaryTablesComposite extends AbstractSecondaryTablesComposite<JavaEntity> -{ - /** - * Creates a new <code>SecondaryTablesComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public JavaSecondaryTablesComposite(AbstractFormPane<? extends JavaEntity> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * 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 JavaSecondaryTablesComposite(PropertyValueModel<? extends JavaEntity> subjectHolder, - Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private ListValueModel<SecondaryTable> buildSecondaryTablesListModel() { - return new ItemPropertyListValueModelAdapter<SecondaryTable>(buildSecondaryTablesListHolder(), - Table.SPECIFIED_NAME_PROPERTY); - } - - private ListValueModel<SecondaryTable> buildSecondaryTablesListHolder() { - return new ListAspectAdapter<Entity, SecondaryTable>(getSubjectHolder(), Entity.SPECIFIED_SECONDARY_TABLES_LIST) { - @Override - protected ListIterator<SecondaryTable> listIterator_() { - return subject.specifiedSecondaryTables(); - } - - @Override - protected int size_() { - return subject.specifiedSecondaryTablesSize(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - WritablePropertyValueModel<SecondaryTable> secondaryTableHolder = - buildSecondaryTableHolder(); - - // Secondary Tables add/remove list pane - new AddRemoveListPane<Entity>( - this, - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), - buildSecondaryTablesAdapter(), - buildSecondaryTablesListModel(), - secondaryTableHolder, - buildSecondaryTableLabelProvider(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS//TODO need a help context id for this - ); - - // 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/java/details/NullAttributeMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/NullAttributeMappingUiProvider.java deleted file mode 100644 index d28d0337c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/NullAttributeMappingUiProvider.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class NullAttributeMappingUiProvider - implements AttributeMappingUiProvider<AttributeMapping> -{ - - // singleton - private static final NullAttributeMappingUiProvider INSTANCE = new NullAttributeMappingUiProvider(); - - /** - * Return the singleton. - */ - public static AttributeMappingUiProvider<AttributeMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private NullAttributeMappingUiProvider() { - super(); - } - - /* - * (non-Javadoc) - */ - public String getMappingKey() { - return MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY; - } - - /* - * (non-Javadoc) - */ - public String getLabel() { - return JptUiMappingsMessages.NullAttributeMappingUiProvider_label; - } - - /* - * (non-Javadoc) - */ - public Image getImage() { - return JpaMappingImageHelper.imageForAttributeMapping(getMappingKey()); - } - - /* - * (non-Javadoc) - */ - public JpaComposite<AttributeMapping> buildAttributeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<AttributeMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new NullComposite(subjectHolder, parent, widgetFactory); - } - - public static class NullComposite extends AbstractFormPane<AttributeMapping> - implements JpaComposite<AttributeMapping>{ - - NullComposite(PropertyValueModel<AttributeMapping> subjectHolder, - Composite parent, - WidgetFactory 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/java/details/NullTypeMappingUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/NullTypeMappingUiProvider.java deleted file mode 100644 index 9a60abbfee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/NullTypeMappingUiProvider.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.java.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -@SuppressWarnings("nls") -public class NullTypeMappingUiProvider implements TypeMappingUiProvider<TypeMapping> -{ - // singleton - private static final NullTypeMappingUiProvider INSTANCE = new NullTypeMappingUiProvider(); - - /** - * Return the singleton. - */ - public static TypeMappingUiProvider<TypeMapping> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private NullTypeMappingUiProvider() { - super(); - } - - public String getMappingKey() { - return null; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentTypePage_UnmappedLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForTypeMapping( - MappingKeys.NULL_TYPE_MAPPING_KEY - ); - } - - public JpaComposite<TypeMapping> buildPersistentTypeMappingComposite( - JpaUiFactory jpaUiFactory, - PropertyValueModel<TypeMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return new NullComposite(subjectHolder, parent, widgetFactory); - } - - - public static class NullComposite extends AbstractFormPane<TypeMapping> - implements JpaComposite<TypeMapping> - { - NullComposite(PropertyValueModel<TypeMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @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/jface/AbstractItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java deleted file mode 100644 index a4874cf6bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -/** - * Implementation of {@link ItemLabelProvider} that provides updating - * label information for a Model object. - * - * The typical subclass will override the following methods: - * #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 ItemLabelProvider -{ - 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 getText() { - return textModel().getValue(); - } - - public Image getImage() { - return imageModel().getValue(); - } - - 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 deleted file mode 100644 index 2a487e2090..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import java.util.Iterator; - -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.NullListValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -/** - * Implementation of {@link TreeItemContentProvider} that provides updating - * children information for a Model object. - * - * The typical subclass will override the following methods: - * #getParent() - * the default behavior for this method is to return null. there is no - * property value model for this as this should not be changing for a given - * node. all such changes will be provided by the parent side of the relationship. - * #buildChildrenModel() - * return a {@link ListValueModel} that represents the children for the represented - * model object. #buildChildrenModel(CollectionValueModel) and - * #buildChildrenModel(PropertyValueModel) are provided if the children are more - * easily represented as a collection or as a property (single child) - * the default behavior is to return a {@link NullListValueModel} - * - * Other methods may be overridden, but take care to preserve the logic provided - * by this class. - */ -public abstract class AbstractTreeItemContentProvider<E> - implements TreeItemContentProvider -{ - private DelegatingTreeContentAndLabelProvider treeContentProvider; - - private Model model; - - private 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 new PropertyListValueModelAdapter<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/DelegatingTreeContentAndLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java deleted file mode 100644 index 8b74901db1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java +++ /dev/null @@ -1,56 +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.jface; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; - -/** - * Extension of {@link DelegatingContentAndLabelProvider} that provides an extension - * to provide tree content - */ -public class DelegatingTreeContentAndLabelProvider extends DelegatingContentAndLabelProvider - implements ITreeContentProvider -{ - public DelegatingTreeContentAndLabelProvider( - TreeItemContentProviderFactory treeItemContentProviderFactory) { - super(treeItemContentProviderFactory); - } - - public DelegatingTreeContentAndLabelProvider( - TreeItemContentProviderFactory treeItemContentProviderFactory, - ItemLabelProviderFactory itemLabelProviderFactory) { - super(treeItemContentProviderFactory, itemLabelProviderFactory); - } - - - protected TreeItemContentProvider itemContentProvider(Object item) { - return (TreeItemContentProvider) super.itemContentProvider(item); - } - - public Object[] getChildren(Object parentElement) { - TreeItemContentProvider provider = itemContentProvider(parentElement); - return (provider == null) ? new Object[0] : provider.getChildren(); - } - - public Object getParent(Object element) { - TreeItemContentProvider provider = itemContentProvider(element); - return (provider == null) ? null : provider.getParent(); - } - - public boolean hasChildren(Object element) { - TreeItemContentProvider provider = itemContentProvider(element); - return (provider == null) ? false : provider.hasChildren(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ImageImageDescriptor.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ImageImageDescriptor.java deleted file mode 100644 index 7886475de5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ImageImageDescriptor.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; - -/** - * Image descriptor for an image. - */ -public class ImageImageDescriptor extends ImageDescriptor -{ - - private Image fImage; - - /** - * Constructor for ImagImageDescriptor. - */ - public ImageImageDescriptor(Image image) { - super(); - fImage = image; - } - - /* - * (non-Javadoc) - * - * @see Object#equals(Object) - */ - public boolean equals(Object obj) { - return (obj != null) && getClass().equals(obj.getClass()) && fImage.equals(((ImageImageDescriptor) obj).fImage); - } - - /* - * (non-Javadoc) - * - * @see ImageDescriptor#getImageData() - */ - public ImageData getImageData() { - return fImage.getImageData(); - } - - /* - * (non-Javadoc) - * - * @see Object#hashCode() - */ - public int hashCode() { - return fImage.hashCode(); - } -} 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 deleted file mode 100644 index 8483d32948..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.swt.graphics.Image; - -/** - * Null implementation of the ILabelProvider interface. - * Implemented as a singleton. - */ -public final class NullLabelProvider - implements ILabelProvider -{ - public static final NullLabelProvider INSTANCE = new NullLabelProvider(); - - public static ILabelProvider instance() { - return INSTANCE; - } - - /** - * Ensure a single instance. - */ - private NullLabelProvider() { - super(); - } - - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return null; - } - - public void addListener(ILabelProviderListener listener) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // do nothing - } - -} diff --git a/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 deleted file mode 100644 index fdb7e0ad36..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * Null implementation of the ILabelProvider interface. - * Implemented as a singleton. - */ -public final class NullTreeContentProvider - implements ITreeContentProvider -{ - private static final Object[] EMPTY_ARRAY = new Object[0]; - public static final NullTreeContentProvider INSTANCE = new NullTreeContentProvider(); - - public static ITreeContentProvider instance() { - return INSTANCE; - } - - /** - * Ensure a single instance. - */ - private NullTreeContentProvider() { - super(); - } - - public Object[] getChildren(Object parentElement) { - return EMPTY_ARRAY; - } - - public Object getParent(Object element) { - return null; - } - - public boolean hasChildren(Object element) { - return false; - } - - public Object[] getElements(Object inputElement) { - return EMPTY_ARRAY; - } - - public void dispose() { - // do nothing - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/StructuredContentProviderAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/StructuredContentProviderAdapter.java deleted file mode 100644 index 12ab567c04..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/StructuredContentProviderAdapter.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import java.util.ListIterator; -import org.eclipse.jface.viewers.AbstractListViewer; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * This adapter can be used to keep an AbstractListViewer - * (e.g. a ListViewer or ComboViewer) in synch with a ListValueModel - * (or a CollectionValueModel). - */ -public class StructuredContentProviderAdapter - implements IStructuredContentProvider -{ - /** The underlying model list. */ - protected ListValueModel listHolder; - - /** The list viewer we keep in synch with the model list. */ - protected final AbstractListViewer listViewer; - - /** A listener that allows us to forward changes made to the underlying model list. */ - protected final ListChangeListener listChangeListener; - - - // ********** static ********** - - /** - * Adapt the specified list viewer to the specified list holder so they - * stay in synch. - */ - public static StructuredContentProviderAdapter adapt(AbstractListViewer listViewer, ListValueModel listHolder) { - // we need only construct the adapter and it will hook up to the list viewer etc. - return new StructuredContentProviderAdapter(listViewer, listHolder); - } - - /** - * Adapt the specified list viewer to the specified list holder so they - * stay in synch. - */ - public static StructuredContentProviderAdapter adapt(AbstractListViewer listViewer, CollectionValueModel collectionHolder) { - // we need only construct the adapter and it will hook up to the list viewer etc. - return new StructuredContentProviderAdapter(listViewer, collectionHolder); - } - - - // ********** constructors ********** - - /** - * Constructor. - */ - protected StructuredContentProviderAdapter(AbstractListViewer listViewer, ListValueModel listHolder) { - super(); - this.listChangeListener = this.buildListChangeListener(); - this.listViewer = listViewer; - this.listViewer.setContentProvider(this); - // the list viewer will call back to #inputChanged(Viewer, Object, Object) - this.listViewer.setInput(listHolder); - } - - /** - * Constructor. - */ - protected StructuredContentProviderAdapter(AbstractListViewer listViewer, CollectionValueModel collectionHolder) { - this(listViewer, new CollectionListValueModelAdapter(collectionHolder)); - } - - - // ********** initialization ********** - - protected ListChangeListener buildListChangeListener() { - return new SWTListChangeListenerWrapper(this.buildListChangeListener_()); - } - - protected ListChangeListener buildListChangeListener_() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsAdded(e); - } - public void itemsRemoved(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsRemoved(e); - } - public void itemsReplaced(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsReplaced(e); - } - public void itemsMoved(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsMoved(e); - } - public void listCleared(ListChangeEvent e) { - StructuredContentProviderAdapter.this.listCleared(); - } - public void listChanged(ListChangeEvent e) { - StructuredContentProviderAdapter.this.listChanged(); - } - @Override - public String toString() { - return "list listener"; - } - }; - } - - - // ********** IStructuredContentProvider implementation ********** - - public Object[] getElements(Object inputElement) { - if (inputElement != this.listHolder) { - throw new IllegalArgumentException("invalid input element: " + inputElement); - } - return this.listHolder.toArray(); - } - - /** - * This is called by the list viewer, so don't update the list viewer here. - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (viewer != this.listViewer) { - throw new IllegalArgumentException("invalid viewer: " + viewer); - } - if (oldInput != this.listHolder) { - throw new IllegalArgumentException("invalid old input: " + oldInput); - } - this.modelChanged((ListValueModel) oldInput, (ListValueModel) newInput); - } - - public void dispose() { - // do nothing - listeners should've already been removed in #inputChanged(Viewer, Object, Object) - } - - - // ********** internal methods ********** - - protected void modelChanged(ListValueModel oldModel, ListValueModel newModel) { - if (oldModel != null) { - this.listHolder.removeListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); - } - this.listHolder = newModel; - if (newModel != null) { - this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); - } - } - - - // ********** public API ********** - - /** - * Return the underlying list model. - */ - public ListValueModel model() { - return this.listHolder; - } - - /** - * Set the underlying list model. - */ - public void setModel(ListValueModel listHolder) { - // the list viewer will call back to #inputChanged(Viewer, Object, Object) - this.listViewer.setInput(listHolder); - } - - /** - * Set the underlying collection model. - */ - public void setModel(CollectionValueModel collectionHolder) { - this.setModel(new CollectionListValueModelAdapter(collectionHolder)); - } - - - // ********** list change support ********** - - /** - * Items were added to the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsAdded(ListChangeEvent e) { - int i = e.getIndex(); - for (@SuppressWarnings("unchecked") ListIterator stream = e.items(); stream.hasNext(); i++) { - this.listViewer.insert(stream.next(), i); - } - } - - /** - * Items were removed from the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsRemoved(ListChangeEvent e) { - this.listViewer.remove(CollectionTools.array(e.items(), e.itemsSize())); - } - - /** - * Items were replaced in the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsReplaced(ListChangeEvent e) { - this.listViewer.remove(CollectionTools.array(e.replacedItems(), e.itemsSize())); - int i = e.getIndex(); - for (@SuppressWarnings("unchecked") ListIterator stream = e.items(); stream.hasNext(); i++) { - this.listViewer.insert(stream.next(), i); - } - } - - /** - * Items were moved in the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsMoved(ListChangeEvent e) { - int len = e.getMoveLength(); - Object[] items = new Object[len]; - int offset = e.getSourceIndex(); - for (int i = 0; i < len; i++) { - items[i] = this.listHolder.get(offset + i); - } - this.listViewer.remove(items); - - offset = e.getTargetIndex(); - for (int i = 0; i < len; i++) { - this.listViewer.insert(items[i], offset + i); - } - } - - /** - * The underlying model list was cleared. - * Synchronize the list viewer. - */ - protected void listCleared() { - this.listViewer.refresh(); - } - - /** - * The underlying model list has changed "dramatically". - * Synchronize the list viewer. - */ - protected void listChanged() { - this.listViewer.refresh(); - } - - - // ********** Object overrides ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.listHolder); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java deleted file mode 100644 index d83e78a62c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTCollectionChangeListenerWrapper.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.listeners; - -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.swt.widgets.Display; - -/** - * Wrap another collection change listener and forward events to it on the SWT - * UI thread. - */ -public class SWTCollectionChangeListenerWrapper - implements CollectionChangeListener -{ - private final CollectionChangeListener listener; - - public SWTCollectionChangeListenerWrapper(CollectionChangeListener listener) { - super(); - if (listener == null) { - throw new NullPointerException(); - } - this.listener = listener; - } - - public void itemsAdded(CollectionChangeEvent event) { - if (this.isExecutingUIThread()) { - this.itemsAdded_(event); - } else { - this.executeOnUIThread(this.buildItemsAddedRunnable(event)); - } - } - - public void itemsRemoved(CollectionChangeEvent event) { - if (this.isExecutingUIThread()) { - this.itemsRemoved_(event); - } else { - this.executeOnUIThread(this.buildItemsRemovedRunnable(event)); - } - } - - public void collectionCleared(CollectionChangeEvent event) { - if (this.isExecutingUIThread()) { - this.collectionCleared_(event); - } else { - this.executeOnUIThread(this.buildCollectionClearedRunnable(event)); - } - } - - public void collectionChanged(CollectionChangeEvent event) { - if (this.isExecutingUIThread()) { - this.collectionChanged_(event); - } else { - this.executeOnUIThread(this.buildCollectionChangedRunnable(event)); - } - } - - private Runnable buildItemsAddedRunnable(final CollectionChangeEvent event) { - return new Runnable() { - public void run() { - SWTCollectionChangeListenerWrapper.this.itemsAdded_(event); - } - @Override - public String toString() { - return "items added"; - } - }; - } - - private Runnable buildItemsRemovedRunnable(final CollectionChangeEvent event) { - return new Runnable() { - public void run() { - SWTCollectionChangeListenerWrapper.this.itemsRemoved_(event); - } - @Override - public String toString() { - return "items removed"; - } - }; - } - - private Runnable buildCollectionClearedRunnable(final CollectionChangeEvent event) { - return new Runnable() { - public void run() { - SWTCollectionChangeListenerWrapper.this.collectionCleared_(event); - } - @Override - public String toString() { - return "collection cleared"; - } - }; - } - - private Runnable buildCollectionChangedRunnable(final CollectionChangeEvent event) { - return new Runnable() { - public void run() { - SWTCollectionChangeListenerWrapper.this.collectionChanged_(event); - } - @Override - public String toString() { - return "collection changed"; - } - }; - } - - private boolean isExecutingUIThread() { - return Display.getCurrent() != null; - } - - /** - * Display#asyncExec(Runnable) seems to work OK; - * but using #syncExec(Runnable) can somtimes make things - * more predictable when debugging, at the risk of deadlocks. - */ - private void executeOnUIThread(Runnable r) { - Display.getDefault().asyncExec(r); -// Display.getDefault().syncExec(r); - } - - void itemsAdded_(CollectionChangeEvent event) { - this.listener.itemsAdded(event); - } - - void itemsRemoved_(CollectionChangeEvent event) { - this.listener.itemsRemoved(event); - } - - void collectionCleared_(CollectionChangeEvent event) { - this.listener.collectionCleared(event); - } - - void collectionChanged_(CollectionChangeEvent event) { - this.listener.collectionChanged(event); - } - - @Override - public String toString() { - return "SWT(" + this.listener.toString() + ")"; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTListChangeListenerWrapper.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTListChangeListenerWrapper.java deleted file mode 100644 index 2343c62cb2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTListChangeListenerWrapper.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.listeners; - -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.swt.widgets.Display; - -/** - * Wrap another list change listener and forward events to it on the SWT - * UI thread. - */ -public class SWTListChangeListenerWrapper - implements ListChangeListener -{ - private final ListChangeListener listener; - - public SWTListChangeListenerWrapper(ListChangeListener listener) { - super(); - if (listener == null) { - throw new NullPointerException(); - } - this.listener = listener; - } - - public void itemsAdded(ListChangeEvent event) { - if (this.isExecutingUIThread()) { - this.itemsAdded_(event); - } else { - this.executeOnUIThread(this.buildItemsAddedRunnable(event)); - } - } - - public void itemsRemoved(ListChangeEvent event) { - if (this.isExecutingUIThread()) { - this.itemsRemoved_(event); - } else { - this.executeOnUIThread(this.buildItemsRemovedRunnable(event)); - } - } - - public void itemsMoved(ListChangeEvent event) { - if (this.isExecutingUIThread()) { - this.itemsMoved_(event); - } else { - this.executeOnUIThread(this.buildItemsMovedRunnable(event)); - } - } - - public void itemsReplaced(ListChangeEvent event) { - if (this.isExecutingUIThread()) { - this.itemsReplaced_(event); - } else { - this.executeOnUIThread(this.buildItemsReplacedRunnable(event)); - } - } - - public void listCleared(ListChangeEvent event) { - if (this.isExecutingUIThread()) { - this.listCleared_(event); - } else { - this.executeOnUIThread(this.buildCollectionClearedRunnable(event)); - } - } - - public void listChanged(ListChangeEvent event) { - if (this.isExecutingUIThread()) { - this.listChanged_(event); - } else { - this.executeOnUIThread(this.buildCollectionChangedRunnable(event)); - } - } - - private Runnable buildItemsAddedRunnable(final ListChangeEvent event) { - return new Runnable() { - public void run() { - SWTListChangeListenerWrapper.this.itemsAdded_(event); - } - @Override - public String toString() { - return "items added"; - } - }; - } - - private Runnable buildItemsRemovedRunnable(final ListChangeEvent event) { - return new Runnable() { - public void run() { - SWTListChangeListenerWrapper.this.itemsRemoved_(event); - } - @Override - public String toString() { - return "items removed"; - } - }; - } - - private Runnable buildItemsMovedRunnable(final ListChangeEvent event) { - return new Runnable() { - public void run() { - SWTListChangeListenerWrapper.this.itemsMoved_(event); - } - @Override - public String toString() { - return "items moved"; - } - }; - } - - private Runnable buildItemsReplacedRunnable(final ListChangeEvent event) { - return new Runnable() { - public void run() { - SWTListChangeListenerWrapper.this.itemsReplaced_(event); - } - @Override - public String toString() { - return "items replaced"; - } - }; - } - - private Runnable buildCollectionClearedRunnable(final ListChangeEvent event) { - return new Runnable() { - public void run() { - SWTListChangeListenerWrapper.this.listCleared_(event); - } - @Override - public String toString() { - return "list cleared"; - } - }; - } - - private Runnable buildCollectionChangedRunnable(final ListChangeEvent event) { - return new Runnable() { - public void run() { - SWTListChangeListenerWrapper.this.listChanged_(event); - } - @Override - public String toString() { - return "list changed"; - } - }; - } - - private boolean isExecutingUIThread() { - return Display.getCurrent() != null; - } - - /** - * Display#asyncExec(Runnable) seems to work OK; - * but using #syncExec(Runnable) can somtimes make things - * more predictable when debugging, at the risk of deadlocks. - */ - private void executeOnUIThread(Runnable r) { - Display.getDefault().asyncExec(r); -// Display.getDefault().syncExec(r); - } - - void itemsAdded_(ListChangeEvent event) { - this.listener.itemsAdded(event); - } - - void itemsRemoved_(ListChangeEvent event) { - this.listener.itemsRemoved(event); - } - - void itemsMoved_(ListChangeEvent event) { - this.listener.itemsMoved(event); - } - - void itemsReplaced_(ListChangeEvent event) { - this.listener.itemsReplaced(event); - } - - void listCleared_(ListChangeEvent event) { - this.listener.listCleared(event); - } - - void listChanged_(ListChangeEvent event) { - this.listener.listChanged(event); - } - - @Override - public String toString() { - return "SWT(" + this.listener.toString() + ")"; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java deleted file mode 100644 index 99f0a6ff58..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTPropertyChangeListenerWrapper.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.listeners; - -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.swt.widgets.Display; - -/** - * Wrap another property change listener and forward events to it on the SWT - * UI thread. - */ -public class SWTPropertyChangeListenerWrapper - implements PropertyChangeListener -{ - private final PropertyChangeListener listener; - - public SWTPropertyChangeListenerWrapper(PropertyChangeListener listener) { - super(); - if (listener == null) { - throw new NullPointerException(); - } - this.listener = listener; - } - - public void propertyChanged(PropertyChangeEvent event) { - if (this.isExecutingUIThread()) { - this.propertyChanged_(event); - } else { - this.executeOnUIThread(this.buildRunnable(event)); - } - } - - private Runnable buildRunnable(final PropertyChangeEvent event) { - return new Runnable() { - public void run() { - SWTPropertyChangeListenerWrapper.this.propertyChanged_(event); - } - }; - } - - private boolean isExecutingUIThread() { - return Display.getCurrent() != null; - } - - /** - * Display#asyncExec(Runnable) seems to work OK; - * but using #syncExec(Runnable) can somtimes make things - * more predictable when debugging, at the risk of deadlocks. - */ - private void executeOnUIThread(Runnable r) { - Display.getDefault().asyncExec(r); -// Display.getDefault().syncExec(r); - } - - void propertyChanged_(PropertyChangeEvent event) { - this.listener.propertyChanged(event); - } - - @Override - public String toString() { - return "SWT(" + this.listener.toString() + ")"; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTStateChangeListenerWrapper.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTStateChangeListenerWrapper.java deleted file mode 100644 index 4a941336c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTStateChangeListenerWrapper.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.listeners; - -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.listener.StateChangeListener; -import org.eclipse.swt.widgets.Display; - -/** - * Wrap another state change listener and forward events to it on the SWT - * UI thread. - */ -public class SWTStateChangeListenerWrapper - implements StateChangeListener -{ - private final StateChangeListener listener; - - public SWTStateChangeListenerWrapper(StateChangeListener listener) { - super(); - if (listener == null) { - throw new NullPointerException(); - } - this.listener = listener; - } - - public void stateChanged(StateChangeEvent event) { - if (this.isExecutingUIThread()) { - this.stateChanged_(event); - } else { - this.executeOnUIThread(this.buildRunnable(event)); - } - } - - private Runnable buildRunnable(final StateChangeEvent event) { - return new Runnable() { - public void run() { - SWTStateChangeListenerWrapper.this.stateChanged_(event); - } - }; - } - - private boolean isExecutingUIThread() { - return Display.getCurrent() != null; - } - - /** - * Display#asyncExec(Runnable) seems to work OK; - * but using #syncExec(Runnable) can somtimes make things - * more predictable when debugging, at the risk of deadlocks. - */ - private void executeOnUIThread(Runnable r) { - Display.getDefault().asyncExec(r); -// Display.getDefault().syncExec(r); - } - - void stateChanged_(StateChangeEvent event) { - this.listener.stateChanged(event); - } - - @Override - public String toString() { - return "SWT(" + this.listener.toString() + ")"; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTTreeChangeListenerWrapper.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTTreeChangeListenerWrapper.java deleted file mode 100644 index 71e8cd0966..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/listeners/SWTTreeChangeListenerWrapper.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.listeners; - -import org.eclipse.jpt.utility.model.event.TreeChangeEvent; -import org.eclipse.jpt.utility.model.listener.TreeChangeListener; -import org.eclipse.swt.widgets.Display; - -/** - * Wrap another tree change listener and forward events to it on the SWT - * UI thread. - */ -public class SWTTreeChangeListenerWrapper - implements TreeChangeListener -{ - private final TreeChangeListener listener; - - public SWTTreeChangeListenerWrapper(TreeChangeListener listener) { - super(); - if (listener == null) { - throw new NullPointerException(); - } - this.listener = listener; - } - - public void nodeAdded(TreeChangeEvent event) { - if (this.isExecutingUIThread()) { - this.nodeAdded_(event); - } else { - this.executeOnUIThread(this.buildNodeAddedRunnable(event)); - } - } - - public void nodeRemoved(TreeChangeEvent event) { - if (this.isExecutingUIThread()) { - this.nodeRemoved_(event); - } else { - this.executeOnUIThread(this.buildNodeRemovedRunnable(event)); - } - } - - public void treeCleared(TreeChangeEvent event) { - if (this.isExecutingUIThread()) { - this.treeCleared_(event); - } else { - this.executeOnUIThread(this.buildTreeClearedRunnable(event)); - } - } - - public void treeChanged(TreeChangeEvent event) { - if (this.isExecutingUIThread()) { - this.treeChanged_(event); - } else { - this.executeOnUIThread(this.buildTreeChangedRunnable(event)); - } - } - - private Runnable buildNodeAddedRunnable(final TreeChangeEvent event) { - return new Runnable() { - public void run() { - SWTTreeChangeListenerWrapper.this.nodeAdded_(event); - } - @Override - public String toString() { - return "node added"; - } - }; - } - - private Runnable buildNodeRemovedRunnable(final TreeChangeEvent event) { - return new Runnable() { - public void run() { - SWTTreeChangeListenerWrapper.this.nodeRemoved_(event); - } - @Override - public String toString() { - return "node removed"; - } - }; - } - - private Runnable buildTreeClearedRunnable(final TreeChangeEvent event) { - return new Runnable() { - public void run() { - SWTTreeChangeListenerWrapper.this.treeCleared_(event); - } - @Override - public String toString() { - return "tree cleared"; - } - }; - } - - private Runnable buildTreeChangedRunnable(final TreeChangeEvent event) { - return new Runnable() { - public void run() { - SWTTreeChangeListenerWrapper.this.treeChanged_(event); - } - @Override - public String toString() { - return "tree changed"; - } - }; - } - - private boolean isExecutingUIThread() { - return Display.getCurrent() != null; - } - - /** - * Display#asyncExec(Runnable) seems to work OK; - * but using #syncExec(Runnable) can somtimes make things - * more predictable when debugging, at the risk of deadlocks. - */ - private void executeOnUIThread(Runnable r) { - Display.getDefault().asyncExec(r); -// Display.getDefault().syncExec(r); - } - - void nodeAdded_(TreeChangeEvent event) { - this.listener.nodeAdded(event); - } - - void nodeRemoved_(TreeChangeEvent event) { - this.listener.nodeRemoved(event); - } - - void treeCleared_(TreeChangeEvent event) { - this.listener.treeCleared(event); - } - - void treeChanged_(TreeChangeEvent event) { - this.listener.treeChanged(event); - } - - @Override - public String toString() { - return "SWT(" + this.listener.toString() + ")"; - } - -} 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 deleted file mode 100644 index 47c45aedf3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings; - -import org.eclipse.osgi.util.NLS; - -/** - * The localized strings used by the mapping panes. - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class JptUiMappingsMessages extends NLS { - - public static String AccessTypeCombo_default; - public static String AttributeOverridesComposite_attributeOverrides; - public static String AttributeOverridesComposite_overrideDefault; - public static String BasicGeneralSection_enumeratedLabel; - public static String BasicGeneralSection_fetchLabel; - public static String BasicGeneralSection_lobLabel; - public static String BasicGeneralSection_name; - public static String BasicGeneralSection_nameDefault; - public static String BasicGeneralSection_optionalLabel; - public static String BasicGeneralSection_optionalLabelDefault; - public static String BasicGeneralSection_temporalLabel; - public static String Boolean_False; - public static String Boolean_True; - 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 CatalogChooser_label; - public static String ColumnComposite_columnDefinition; - public static String ColumnComposite_columnSection; - public static String ColumnComposite_defaultEmpty; - public static String ColumnComposite_defaultWithOneParam; - public static String ColumnComposite_details; - public static String ColumnComposite_insertable; - public static String ColumnComposite_insertableWithDefault; - public static String ColumnComposite_length; - public static String ColumnComposite_name; - public static String ColumnComposite_nullable; - public static String ColumnComposite_nullableWithDefault; - public static String ColumnComposite_precision; - public static String ColumnComposite_scale; - public static String ColumnComposite_table; - public static String ColumnComposite_unique; - public static String ColumnComposite_uniqueWithDefault; - public static String ColumnComposite_updatable; - public static String ColumnComposite_updatableWithDefault; - public static String DefaultBasicMappingUiProvider_Default; - public static String DefaultEmbeddedMappingUiProvider_Default; - public static String DefaultWithoutValue; - public static String DefaultWithValue; - public static String DiscriminatorColumnComposite_defaultEmpty; - public static String DiscriminatorColumnComposite_discriminatorType; - public static String DiscriminatorColumnComposite_name; - public static String EntityComposite_inheritance; - public static String EntityComposite_queries; - public static String EntityComposite_tableDefault; - public static String EntityComposite_tableNoDefaultSpecified; - public static String EntityGeneralSection_name; - public static String EntityGeneralSection_nameDefaultEmpty; - public static String EntityGeneralSection_nameDefaultWithOneParam; - public static String EntityNameComposite_name; - public static String EnumTypeComposite_ordinal; - public static String EnumTypeComposite_string; - public static String FetchTypeComposite_eager; - public static String FetchTypeComposite_lazy; - public static String GeneratedValueComposite_auto; - public static String GeneratedValueComposite_generatedValue; - public static String GeneratedValueComposite_generatorName; - public static String GeneratedValueComposite_identity; - public static String GeneratedValueComposite_sequence; - public static String GeneratedValueComposite_strategy; - public static String GeneratedValueComposite_table; - public static String GeneratorComposite_allocationSize; - public static String GeneratorComposite_initialValue; - public static String IdClassComposite_label; - public static String IdMappingComposite_pk_generation; - public static String IdMappingComposite_primaryKeyGeneration; - public static String IdMappingComposite_sequenceGenerator; - public static String IdMappingComposite_tableGenerator; - public static String AbstractInheritanceComposite_char; - public static String InheritanceComposite_detailsGroupBox; - public static String InheritanceComposite_discriminatorColumnGroupBox; - public static String InheritanceComposite_discriminatorValue; - public static String AbstractInheritanceComposite_integer; - public static String AbstractInheritanceComposite_joined; - public static String AbstractInheritanceComposite_single_table; - public static String InheritanceComposite_strategy; - public static String AbstractInheritanceComposite_string; - public static String AbstractInheritanceComposite_table_per_class; - public static String InverseJoinColumnDialog_editInverseJoinColumnTitle; - public static String JoinColumnComposite_add; - public static String JoinColumnComposite_defaultEmpty; - public static String JoinColumnComposite_defaultWithOneParam; - public static String JoinColumnComposite_edit; - public static String JoinColumnComposite_joinColumn; - public static String JoinColumnComposite_mappingBetweenTwoParams; - public static String JoinColumnComposite_mappingBetweenTwoParamsBothDefault; - public static String JoinColumnComposite_mappingBetweenTwoParamsDefault; - public static String JoinColumnComposite_mappingBetweenTwoParamsFirstDefault; - public static String JoinColumnComposite_mappingBetweenTwoParamsSecDefault; - public static String JoinColumnComposite_name; - public static String JoinColumnComposite_overrideDefaultJoinColumns; - public static String JoinColumnComposite_remove; - public static String JoinColumnDialog_addJoinColumnDescriptionTitle; - public static String JoinColumnDialog_addJoinColumnTitle; - public static String JoinColumnDialog_description; - public static String JoinColumnDialog_editJoinColumnDescriptionTitle; - public static String JoinColumnDialog_editJoinColumnTitle; - public static String JoinColumnDialog_name; - public static String JoinColumnDialog_referencedColumnName; - public static String JoinColumnDialogPane_columnDefinition; - public static String JoinColumnDialogPane_defaultEmpty; - public static String JoinColumnDialogPane_defaultWithOneParam; - public static String JoinColumnDialogPane_insertable; - public static String JoinColumnDialogPane_insertableWithDefault; - public static String JoinColumnDialogPane_nullable; - public static String JoinColumnDialogPane_nullableWithDefault; - public static String JoinColumnDialogPane_table; - public static String JoinColumnDialogPane_unique; - public static String JoinColumnDialogPane_uniqueWithDefault; - public static String JoinColumnDialogPane_updatable; - public static String JoinColumnDialogPane_updatableWithDefault; - public static String JoinTableComposite_add; - public static String JoinTableComposite_defaultEmpty; - public static String JoinTableComposite_defaultWithOneParam; - public static String JoinTableComposite_edit; - public static String JoinTableComposite_inverseJoinColumn; - public static String JoinTableComposite_joinColumn; - public static String JoinTableComposite_mappingBetweenTwoParams; - public static String JoinTableComposite_mappingBetweenTwoParamsBothDefault; - public static String JoinTableComposite_mappingBetweenTwoParamsDefault; - public static String JoinTableComposite_mappingBetweenTwoParamsFirstDefault; - public static String JoinTableComposite_mappingBetweenTwoParamsSecDefault; - public static String JoinTableComposite_name; - public static String JoinTableComposite_overrideDefaultInverseJoinColumns; - public static String JoinTableComposite_overrideDefaultJoinColumns; - public static String JoinTableComposite_remove; - public static String MetaDataCompleteCombo_Default; - public static String MultiRelationshipMappingComposite_cascadeType; - public static String MultiRelationshipMappingComposite_fetchType; - public static String MultiRelationshipMappingComposite_general; - public static String MultiRelationshipMappingComposite_joinTable; - public static String MultiRelationshipMappingComposite_mappedBy; - public static String MultiRelationshipMappingComposite_targetEntity; - public static String NamedNativeQueryPropertyComposite_query; - public static String NamedNativeQueryPropertyComposite_queryHintsGroupBox; - public static String NamedNativeQueryPropertyComposite_resultClass; - public static String NamedQueryPropertyComposite_query; - public static String NamedQueryPropertyComposite_queryHintsGroupBox; - public static String NewNameStateObject_nameAlreadyExists; - public static String NewNameStateObject_nameMustBeSpecified; - public static String NoNameSet; - public static String NoneSelected; - public static String NonOwningMapping_mappedByLabel; - public static String NullAttributeMappingUiProvider_label; - public static String OptionalComposite_false; - public static String OptionalComposite_true; - public static String OrderByComposite_customOrdering; - public static String OrderByComposite_noOrdering; - public static String OrderByComposite_orderByGroup; - public static String OrderByComposite_orderByLabel; - public static String OrderByComposite_primaryKeyOrdering; - public static String OrmSecondaryTablesComposite_defineInXml; - public static String OverridesComposite_association; - public static String OverridesComposite_attribute; - public static String OverridesComposite_joinColumn; - public static String OverridesComposite_noName; - public static String PersistentAttributePage_BasicLabel; - public static String PersistentAttributePage_EmbeddedIdLabel; - public static String PersistentAttributePage_EmbeddedLabel; - public static String PersistentAttributePage_IdLabel; - public static String PersistentAttributePage_ManyToManyLabel; - public static String PersistentAttributePage_ManyToOneLabel; - public static String PersistentAttributePage_OneToManyLabel; - public static String PersistentAttributePage_OneToOneLabel; - public static String PersistentAttributePage_TransientLabel; - public static String PersistentAttributePage_VersionLabel; - public static String PersistentTypePage_EmbeddableLabel; - public static String PersistentTypePage_EntityLabel; - public static String PersistentTypePage_MappedSuperclassLabel; - public static String PersistentTypePage_UnmappedLabel; - public static String PrimaryKeyJoinColumnDialog_addDescriptionTitle; - public static String PrimaryKeyJoinColumnDialog_addTitle; - public static String PrimaryKeyJoinColumnDialog_editDescriptionTitle; - public static String PrimaryKeyJoinColumnDialog_editTitle; - public static String PrimaryKeyJoinColumnInSecondaryTableDialog_addDescriptionTitle; - public static String PrimaryKeyJoinColumnInSecondaryTableDialog_addTitle; - public static String PrimaryKeyJoinColumnInSecondaryTableDialog_editDescriptionTitle; - public static String PrimaryKeyJoinColumnInSecondaryTableDialog_editTitle; - public static String PrimaryKeyJoinColumnsComposite_defaultEmpty; - public static String PrimaryKeyJoinColumnsComposite_defaultWithOneParam; - public static String PrimaryKeyJoinColumnsComposite_edit; - public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams; - public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault; - public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault; - public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault; - public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault; - public static String PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns; - public static String PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn; - public static String QueriesComposite_addNamedNativeQuery; - public static String QueriesComposite_addNamedNativeQueryDescription; - public static String QueriesComposite_addNamedNativeQueryDescriptionTitle; - public static String QueriesComposite_addNamedNativeQueryTitle; - public static String QueriesComposite_addNamedQuery; - public static String QueriesComposite_addNamedQueryDescription; - public static String QueriesComposite_addNamedQueryDescriptionTitle; - public static String QueriesComposite_addNamedQueryTitle; - public static String QueriesComposite_displayString; - public static String QueriesComposite_edit; - public static String QueriesComposite_editNamedNativeQueryDescription; - public static String QueriesComposite_editNamedNativeQueryDescriptionTitle; - public static String QueriesComposite_editNamedNativeQueryTitle; - public static String QueriesComposite_editNamedQueryDescription; - public static String QueriesComposite_editNamedQueryDescriptionTitle; - public static String QueriesComposite_editNamedQueryTitle; - public static String QueriesComposite_label; - public static String QueryHintsComposite_nameColumn; - public static String QueryHintsComposite_valueColumn; - public static String SchemaChooser_label; - public static String SecondaryTableDialog_addSecondaryTable; - public static String SecondaryTableDialog_catalog; - public static String SecondaryTableDialog_defaultCatalog; - public static String SecondaryTableDialog_defaultSchema; - public static String SecondaryTableDialog_editSecondaryTable; - public static String SecondaryTableDialog_name; - public static String SecondaryTableDialog_schema; - public static String SecondaryTablesComposite_edit; - public static String SecondaryTablesComposite_secondaryTables; - public static String SequenceGeneratorComposite_default; - public static String SequenceGeneratorComposite_name; - public static String SequenceGeneratorComposite_sequence; - public static String SequenceGeneratorComposite_sequenceGenerator; - public static String TableChooser_label; - public static String TableComposite_defaultEmpty; - public static String TableComposite_defaultWithOneParam; - public static String TableComposite_tableSection; - public static String TableGeneratorComposite_catalog; - public static String TableGeneratorComposite_default; - public static String TableGeneratorComposite_name; - public static String TableGeneratorComposite_pkColumn; - public static String TableGeneratorComposite_pkColumnValue; - public static String TableGeneratorComposite_schema; - public static String TableGeneratorComposite_table; - public static String TableGeneratorComposite_tableGenerator; - public static String TableGeneratorComposite_valueColumn; - public static String TargetEntityChooser_browse; - public static String TargetEntityChooser_defaultEmpty; - public static String TargetEntityChooser_defaultWithOneParam; - public static String TargetEntityChooser_label; - public static String TargetEntityChooser_selectTypeTitle; - public static String TemporalTypeComposite_date; - public static String TemporalTypeComposite_time; - public static String TemporalTypeComposite_timestamp; - - static { - NLS.initializeMessages("jpt_ui_mappings", JptUiMappingsMessages.class); - } - - 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 deleted file mode 100644 index 01381a805a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java +++ /dev/null @@ -1,678 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.db; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.db.Catalog; -import org.eclipse.jpt.db.Column; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.ForeignKey; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Sequence; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.WidgetFactory; -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.AbstractPane; -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.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 JpaNode> extends AbstractPane<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(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>AbstractDatabaseObjectCombo</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - protected AbstractDatabaseObjectCombo(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, 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, - WidgetFactory widgetFactory) - { - super(subjectHolder, parent, widgetFactory); - } - - private ConnectionListener buildConnectionListener() { - - return new ConnectionListener() { - - public void aboutToClose(ConnectionProfile profile) { - log(Tracing.UI_DB, "aboutToClose"); - } - - public void catalogChanged(ConnectionProfile profile, - final Catalog catalog) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "catalogChanged: " + catalog.getName()); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.catalogChanged(catalog); - } - } - }); - } - - public void closed(ConnectionProfile profile) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "closed"); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.repopulate(); - } - } - }); - } - - public void columnChanged(ConnectionProfile profile, - final Column column) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "columnChanged: " + column.getName()); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.columnChanged(column); - } - } - }); - } - - public void databaseChanged(ConnectionProfile profile, - Database database) { - - log(Tracing.UI_DB, "databaseChanged"); - } - - public void foreignKeyChanged(ConnectionProfile profile, - final ForeignKey foreignKey) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "foreignKeyChanged: " + foreignKey.getName()); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.foreignKeyChanged(foreignKey); - } - } - }); - } - - public void modified(ConnectionProfile profile) { - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "modified"); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.repopulate(); - } - } - }); - } - - public boolean okToClose(ConnectionProfile profile) { - log(Tracing.UI_DB, "okToClose"); - return true; - } - - public void opened(ConnectionProfile profile) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "opened"); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.repopulate(); - } - } - }); - } - - public void schemaChanged(ConnectionProfile profile, - final Schema schema) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "schemaChanged: " + schema.getName()); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.schemaChanged(schema); - } - } - }); - } - - public void sequenceChanged(ConnectionProfile profile, - final Sequence sequence) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "sequenceChanged: " + sequence.getName()); - - if (!getCombo().isDisposed()) { - AbstractDatabaseObjectCombo.this.sequenceChanged(sequence); - } - } - }); - } - - public void tableChanged(ConnectionProfile profile, - final Table table) { - - SWTUtil.asyncExec(new Runnable() { - public void run() { - log(Tracing.UI_DB, "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; - if (combo.getData("populating") != Boolean.TRUE) {//check !TRUE because null is a possibility as well - valueChanged(combo.getText()); - } - } - } - }; - } - - /** - * If the value changes but the subject is null, then is invoked in order to - * create the subject. - */ - protected void buildSubject() { - } - - /** - * The - * - * @param catalog - */ - protected void catalogChanged(Catalog catalog) { - } - - /** - * Makes sure the combo shows nothing instead of the default value because - * the focus is still on the combo. The user can start typing something and - * we don't want to start the typing after the default value. - */ - private void clearDefaultValue() { - - if (this.combo.isFocusControl()) { - - setPopulating(true); - - try { - combo.setText(""); - } - finally { - setPopulating(false); - } - } - } - - /** - * The - * - * @param column - */ - protected void columnChanged(Column column) { - } - - /** - * Returns the JPA project's connection profile, which is never - * <code>null</code>. - * - * @return The connection set in the project's properties or <code>null</code> - * if it could not being retrieved - */ - protected final ConnectionProfile connectionProfile() { - JpaProject jpaProject = jpaProject(); - - if (jpaProject != null) { - return jpaProject.getConnectionProfile(); - } - - return null; - } - - /** - * 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); - - JpaProject jpaProject = jpaProject(); - - if (jpaProject != null) { - jpaProject.getConnectionProfile().removeConnectionListener(this.connectionListener); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - - super.doPopulate(); - 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); - - JpaProject jpaProject = jpaProject(); - - if (jpaProject != null) { - jpaProject.getConnectionProfile().addConnectionListener(this.connectionListener); - } - } - - /** - * The - * - * @param foreignKey - */ - protected void foreignKeyChanged(ForeignKey foreignKey) { - } - - 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 = buildEditableCCombo(container); - this.combo.addModifyListener(buildModifyListener()); - SWTUtil.attachDefaultValueHandler(this.combo); - } - - /** - * Determines if the subject should be created when the value changes. - * - * @return <code>false</code> is the default behavior - */ - protected boolean isBuildSubjectAllowed() { - return false; - } - - /** - * Retrives the <code>IJpaProject</code> that is required to register a - * <code>ConnectionListener</code> in order to keep the combo in sync with - * the associated online database. - * - * @return The JPA project - */ - protected JpaProject jpaProject() { - return subject() == null ? null : subject().getJpaProject(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void log(String flag, String message) { - - super.log(flag, message); - - if (Tracing.UI_DB.equals(flag) && - 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() { - - combo.removeAll(); - populateDefaultValue(); - - ConnectionProfile connectionProfile = connectionProfile(); - - if ((connectionProfile != null) && connectionProfile.isActive()) { - - for (Iterator<String> iter = CollectionTools.sort(values()); iter.hasNext(); ) { - combo.add(iter.next()); - } - } - - updateSelectedItem(); - } - - /** - * Adds the default value to the combo if one exists. - */ - private void populateDefaultValue() { - - String defaultValue = (subject() != null) ? defaultValue() : null; - - if (defaultValue != null) { - combo.add(NLS.bind( - JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, - defaultValue - )); - } - else { - combo.add(JptUiMappingsMessages.ColumnComposite_defaultEmpty); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - updateSelectedItem(); - } - - /** - * The - * - * @param schema - */ - protected void schemaChanged(Schema schema) { - } - - /** - * The - * - * @param sequence - */ - protected void sequenceChanged(Sequence sequence) { - } - - /** - * 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 table - */ - 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() { - - T subject = subject(); - - String value = (subject != null) ? value() : null; - String defaultValue = (subject != null) ? defaultValue() : null; - String displayString = JptUiMappingsMessages.ColumnComposite_defaultEmpty; - - if (defaultValue != null) { - displayString = NLS.bind( - JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, - defaultValue - ); - } - - // Make sure the default value is up to date - if (!combo.getItem(0).equals(displayString)) { - combo.remove(0); - combo.add(displayString, 0); - } - - // Select the new value - if (value != null) { - if (!value.equals(combo.getText())) { - //this prevents the cursor from being set back to the beginning of the line (bug 234418). - //The reason we are hitting this updateSelectedItem() code at all - //is because the context model is updating from the resource model - //in a way that causes change notifications to be fired (the annotation is added - //to the resource model, change notification occurs on the update thread, - //and then the name is set, these 2 threads can get in the wrong order). - //The valueChanged() method sets the populating flag to true, but in this case - //it is already set back to false when we receive notification back from the model - //because it has moved to the update thread and then jumps back on the UI thread. - combo.setText(value); - } - } - // Select the default value - else { - combo.select(0); - - //i think we can remove this, I don't believe the problem explained - //in the comments of this method is happening anymore. Not removing it now because we are working on 2.0RC3 - combo.setSelection(new Point(0, 0)); - } - } - - /** - * 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) { - - JpaNode subject = subject(); - - if ((subject == null) && !isBuildSubjectAllowed()) { - return; - } - - String oldValue = (subject != null) ? value() : null; - - // Check for null value - if (StringTools.stringIsEmpty(value)) { - value = null; - - if (StringTools.stringIsEmpty(oldValue)) { - return; - } - } - - // Convert the default value to null - if (value != null && - getCombo().getItemCount() > 0 && - value.equals(getCombo().getItem(0))) - { - value = null; - } - - // Nothing to change - if ((oldValue == value) && value == null) { - clearDefaultValue(); - return; - } - - // Build the subject before setting the value - if (subject == null) { - buildSubject(); - } - - // Set the new value - if ((value != null) && (oldValue == null) || - ((oldValue != null) && !oldValue.equals(value))) { - - setPopulating(true); - combo.setData("populating", Boolean.TRUE); - - try { - setValue(value); - } - finally { - setPopulating(false); - combo.setData("populating", Boolean.FALSE); - } - - if (value == null) { - clearDefaultValue(); - } - } - } - - /** - * 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 deleted file mode 100644 index 99144a1a9b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/CatalogCombo.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.db; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.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 JpaNode> extends AbstractDatabaseObjectCombo<T> -{ - /** - * Creates a new <code>CatalogCombo</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public CatalogCombo(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>CatalogCombo</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public CatalogCombo(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, 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, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected Iterator<String> values() { - return this.database().catalogNames(); - } -} 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 deleted file mode 100644 index 1ce1f4e1e8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.db; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * This database object combo handles showing a single or multiple tables' - * columns. - * - * @version 2.0 - * @since 2.0 - */ -public abstract class ColumnCombo<T extends JpaNode> extends AbstractDatabaseObjectCombo<T> -{ - /** - * Creates a new <code>ColumnCombo</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public ColumnCombo(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>ColumnCombo</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public ColumnCombo(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, 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, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /** - * Returns the databas tables that is used to retrieve the column names. - * - * @return The table of which its columns are displayed in the combo - */ - protected abstract Table table(); - - /* - * (non-Javadoc) - */ - @Override - protected void tableChanged(Table table) { - super.tableChanged(table); - - if ((subject() != null) && (table() == table)) { - doPopulate(); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<String> values() { - - if (subject() == null) { - return EmptyIterator.instance(); - } - - Table table = table(); - - if (table != null) { - return table.columnNames(); - } - - return EmptyIterator.<String>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 deleted file mode 100644 index f2f4a6fae5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SchemaCombo.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.db; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.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 JpaNode> extends AbstractDatabaseObjectCombo<T> -{ - /** - * Creates a new <code>SchemaCombo</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public SchemaCombo(AbstractPane<? extends T> parentPane, - Composite parent) - { - super(parentPane, parent); - } - - /** - * Creates a new <code>SchemaCombo</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public SchemaCombo(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) - { - super(parentPane, subjectHolder, 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, - WidgetFactory widgetFactory) - { - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected Iterator<String> values() { - return this.database().schemaNames(); - } - -} 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 deleted file mode 100644 index 66b993cf34..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/SequenceCombo.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.db; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.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 JpaNode> extends AbstractDatabaseObjectCombo<T> -{ - /** - * Creates a new <code>SequenceCombo</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public SequenceCombo(AbstractPane<? extends T> parentPane, Composite parent) - { - super(parentPane, parent); - } - - /** - * Creates a new <code>SequenceCombo</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public SequenceCombo(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, 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, - WidgetFactory 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 deleted file mode 100644 index bb48cf9daf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.db; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.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 JpaNode> extends AbstractDatabaseObjectCombo<T> -{ - /** - * Creates a new <code>TableCombo</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public TableCombo(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>TableCombo</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public TableCombo(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, 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, - WidgetFactory widgetFactory) - { - super(subjectHolder, parent, widgetFactory); - } - - /** - * Retrieves the name of the schema from where the table is located. - * - * @return The table's schema name - */ - protected abstract String schemaName(); - - /* - * (non-Javadoc) - */ - @Override - protected void tableChanged(Table table) { - super.tableChanged(table); - - if (table == table()) { - this.doPopulate(); - } - } - - /** - * Returns the selected database table. - * - * @return The selected table - */ - protected abstract Table table(); - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<String> values() { - Database database = database(); - String schemaName = schemaName(); - - if ((schemaName != null) && (database != null)) { - Schema schema = database.schemaNamed(schemaName); - - if (schema != null) { - return schema.tableNames(); - } - } - - 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/details/AbstractEmbeddedMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractEmbeddedMappingComposite.java deleted file mode 100644 index c9d9309f8a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractEmbeddedMappingComposite.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.BaseEmbeddedMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | EmbeddedAttributeOverridesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see BaseEmbeddedMapping - * @see BaseJpaUiFactory - The factory creating this pane - * @see EmbeddedAttributeOverridesComposite - * - * @version 2.0 - * @since 1.0 - */ -public abstract class AbstractEmbeddedMappingComposite<T extends BaseEmbeddedMapping> extends AbstractFormPane<T> - implements JpaComposite<T> -{ - /** - * Creates a new <code>AbstractEmbeddedMappingComposite</code>. - * - * @param subjectHolder The holder of the subject <code>BaseEmbeddedMapping</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - protected AbstractEmbeddedMappingComposite(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @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/AbstractEntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractEntityComposite.java deleted file mode 100644 index 9bd2e633f0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractEntityComposite.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | EntityNameComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | TableComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | IdClassComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - v Attribute Overrides ------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OverridesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - v Secondary Tables ---------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | Pane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - v Inheritance --------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | InheritanceComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - v Queries ------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | QueriesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - v Generators ---------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | GeneratorsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see EntityNameComposite - * @see InheritanceComposite - * @see IdClassComposite - * @see OverridesComposite - * @see TableComposite - * @see GeneratorsComposite - * - * TODO talk to JavaEditor people about what we can do to hook in TabbedProperties for the JavaEditor - * - * @version 2.0 - * @since 1.0 - */ -public abstract class AbstractEntityComposite<T extends Entity> extends AbstractFormPane<T> - implements JpaComposite<T> -{ - /** - * Creates a new <code>AbstractEntityComposite</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 AbstractEntityComposite(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - protected abstract void buildSecondaryTablesComposite(Composite container); - - protected abstract void buildInheritanceComposite(Composite container); - - private PropertyValueModel<Table> buildTableHolder() { - return new TransformationPropertyValueModel<Entity, Table>(getSubjectHolder()) { - @Override - protected Table transform_(Entity value) { - return value.getTable(); - } - }; - } - - private void initializeAttributeOverridesPane(Composite container) { - - container = buildCollapsableSection( - buildSubPane(container, 5), - JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides - ); - - new OverridesComposite(this, container); - } - - private void initializeGeneralPane(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - // Entity Name widgets - new EntityNameComposite( - this, - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin) - ); - - // Table widgets - new TableComposite( - this, - buildTableHolder(), - container - ); - - // Primary Key Class widgets - new IdClassComposite( - this, - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin) - ); - } - - private void initializeGeneratorsPane(Composite container) { - - container = buildCollapsableSection( - container, - JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration - ); - - new GeneratorsComposite(this, container); - } - - private void initializeInheritancePane(Composite container) { - - container = buildCollapsableSection( - container, - JptUiMappingsMessages.EntityComposite_inheritance - ); - - buildInheritanceComposite(container); - } - - @Override - protected void initializeLayout(Composite container) { - - initializeGeneralPane(container); - initializeAttributeOverridesPane(container); - initializeSecondaryTablesPane(container); - initializeInheritancePane(container); - initializeQueriesPane(container); - initializeGeneratorsPane(container); - } - - private void initializeQueriesPane(Composite container) { - - container = buildCollapsableSection( - container, - JptUiMappingsMessages.EntityComposite_queries - ); - - new QueriesComposite(this, container); - } - - private void initializeSecondaryTablesPane(Composite container) { - - container = buildCollapsableSection( - container, - JptUiMappingsMessages.SecondaryTablesComposite_secondaryTables - ); - - buildSecondaryTablesComposite(container); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractInheritanceComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractInheritanceComposite.java deleted file mode 100644 index 3491751a5b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractInheritanceComposite.java +++ /dev/null @@ -1,560 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; -import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; -import org.eclipse.jpt.ui.internal.util.LabeledLabel; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.jpt.utility.internal.StringConverter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ---------------------------------------------------- | - * | Strategy: | EnumComboViewer |v| | - * | ---------------------------------------------------- | - * | ---------------------------------------------------- | - * | Value: | I |v| | - * | ---------------------------------------------------- | - * | | - * | > Discriminator Column | - * | | - * | ---------------------------------------------------- | - * | Name: | ColumnCombo |v| | - * | ---------------------------------------------------- | - * | ---------------------------------------------------- | - * | Type: | EnumComboViewer |v| | - * | ---------------------------------------------------- | - * | ---------------------------------------------------- | - * | Column Definition: | I | | - * | ---------------------------------------------------- | - * | ------------- | - * | Length: | I |I| | - * | ------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PrimaryKeyJoinColumnsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see AbstractEntityComposite - The parent container - * @see ColumnCombo - * @see EnumComboViewer - * @see PrimaryKeyJoinColumnsComposite - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class AbstractInheritanceComposite<T extends Entity> extends AbstractPane<T> { - - /** - * A key used to represent the default value, this is required to convert - * the selected item from a combo to <code>null</code>. This key is most - * likely never typed the user and it will help to convert the value to - * <code>null</code> when it's time to set the new selected value into the - * model. - */ - protected static String DEFAULT_KEY = "?!#!?#?#?default?#?!#?!#?"; - - /** - * Creates a new <code>InheritanceComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public AbstractInheritanceComposite(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent, false); - } - - /** - * 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 AbstractInheritanceComposite(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private WritablePropertyValueModel<String> buildColumnDefinitionHolder(PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) { - - return new PropertyAspectAdapter<DiscriminatorColumn, String>(discriminatorColumnHolder, DiscriminatorColumn.COLUMN_DEFINITION_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getColumnDefinition(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setColumnDefinition(value); - } - }; - } - - private ListValueModel<String> buildDefaultDiscriminatorListValueHolder() { - return new PropertyListValueModelAdapter<String>( - buildDefaultDiscriminatorValueHolder() - ); - } - - private WritablePropertyValueModel<String> buildDefaultDiscriminatorValueHolder() { - return new PropertyAspectAdapter<Entity, String>(getSubjectHolder(), Entity.DEFAULT_DISCRIMINATOR_VALUE_PROPERTY) { - @Override - protected String buildValue_() { - String name = subject.getDefaultDiscriminatorValue(); - - if (name == null) { - name = DEFAULT_KEY; - } - else { - name = DEFAULT_KEY + name; - } - - return name; - } - }; - } - - private WritablePropertyValueModel<Integer> buildDefaultLengthHolder() { - return new PropertyAspectAdapter<DiscriminatorColumn, Integer>(buildDiscriminatorColumnHolder(), DiscriminatorColumn.DEFAULT_LENGTH_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getDefaultLength(); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Integer.MIN_VALUE, newValue); - } - } - }; - } - - private Control buildDefaultLengthLabel(Composite container) { - - Label label = buildLabel( - container, - JptUiMappingsMessages.DefaultWithoutValue - ); - - new LabeledControlUpdater( - new LabeledLabel(label), - buildDefaultLengthLabelHolder() - ); - - return label; - } - - private PropertyValueModel<String> buildDefaultLengthLabelHolder() { - - return new TransformationPropertyValueModel<Integer, String>(buildDefaultLengthHolder()) { - - @Override - protected String transform(Integer value) { - - Integer defaultValue = (subject() != null) ? subject().getDiscriminatorColumn().getDefaultLength() : - DiscriminatorColumn.DEFAULT_LENGTH; - - return NLS.bind( - JptUiMappingsMessages.DefaultWithValue, - defaultValue - ); - } - }; - } - - private ColumnCombo<DiscriminatorColumn> buildDiscriminatorColumnCombo( - Composite container, - PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) { - - return new ColumnCombo<DiscriminatorColumn>( - this, - discriminatorColumnHolder, - container) - { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(NamedColumn.SPECIFIED_NAME_PROPERTY); - propertyNames.add(NamedColumn.DEFAULT_NAME_PROPERTY); - } - - @Override - protected String defaultValue() { - return subject().getDefaultName(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedName(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedName(); - } - }; - } - - private PropertyValueModel<DiscriminatorColumn> buildDiscriminatorColumnHolder() { - return new TransformationPropertyValueModel<Entity, DiscriminatorColumn>(getSubjectHolder()) { - @Override - protected DiscriminatorColumn transform_(Entity value) { - return value.getDiscriminatorColumn(); - } - }; - } - - private EnumFormComboViewer<DiscriminatorColumn, DiscriminatorType> buildDiscriminatorTypeCombo( - Composite container, - PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) { - - return new EnumFormComboViewer<DiscriminatorColumn, DiscriminatorType>( - this, - discriminatorColumnHolder, - container) - { - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE_PROPERTY); - propertyNames.add(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY); - } - - @Override - protected DiscriminatorType[] choices() { - return DiscriminatorType.values(); - } - - @Override - protected DiscriminatorType defaultValue() { - return subject().getDefaultDiscriminatorType(); - } - - @Override - protected String displayString(DiscriminatorType value) { - return buildDisplayString( - JptUiMappingsMessages.class, - AbstractInheritanceComposite.class, - value - ); - } - - @Override - protected DiscriminatorType getValue() { - return subject().getSpecifiedDiscriminatorType(); - } - - @Override - protected void setValue(DiscriminatorType value) { - subject().setSpecifiedDiscriminatorType(value); - } - }; - } - - private StringConverter<String> buildDiscriminatorValueConverter() { - return new StringConverter<String>() { - public String convertToString(String value) { - - if (subject() == null) { - return null; - } - - if (value == null) { - value = subject().getDefaultDiscriminatorValue(); - - if (value != null) { - value = DEFAULT_KEY + value; - } - else { - value = DEFAULT_KEY; - } - } - - if (value.startsWith(DEFAULT_KEY)) { - String defaultName = value.substring(DEFAULT_KEY.length()); - - if (defaultName.length() > 0) { - value = NLS.bind( - JptUiMappingsMessages.DefaultWithValue, - defaultName - ); - } - else { - value = JptUiMappingsMessages.DefaultWithoutValue; - } - } - - return value; - } - }; - } - - private WritablePropertyValueModel<String> buildDiscriminatorValueHolder() { - return new PropertyAspectAdapter<Entity, String>(getSubjectHolder(), Entity.SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getSpecifiedDiscriminatorValue(); - } - - @Override - protected void setValue_(String value) { - - // Convert the default value or an empty string to null - if ((value != null) && - ((value.length() == 0) || value.startsWith(DEFAULT_KEY))) { - - value = null; - } - - subject.setSpecifiedDiscriminatorValue(value); - } - }; - } - - private ListValueModel<String> buildDiscriminatorValueListHolder() { - return buildDefaultDiscriminatorListValueHolder(); - } - - private WritablePropertyValueModel<Integer> buildLengthHolder(PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) { - - return new PropertyAspectAdapter<DiscriminatorColumn, Integer>(discriminatorColumnHolder, DiscriminatorColumn.SPECIFIED_LENGTH_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getSpecifiedLength(); - } - - @Override - protected void setValue_(Integer value) { - if (value == -1) { - value = null; - } - subject.setSpecifiedLength(value); - } - }; - } - - private EnumFormComboViewer<Entity, InheritanceType> buildStrategyCombo(Composite container) { - - return new EnumFormComboViewer<Entity, InheritanceType>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Entity.DEFAULT_INHERITANCE_STRATEGY_PROPERTY); - propertyNames.add(Entity.SPECIFIED_INHERITANCE_STRATEGY_PROPERTY); - } - - @Override - protected InheritanceType[] choices() { - return InheritanceType.values(); - } - - @Override - protected InheritanceType defaultValue() { - return subject().getDefaultInheritanceStrategy(); - } - - @Override - protected String displayString(InheritanceType value) { - return buildDisplayString( - JptUiMappingsMessages.class, - AbstractInheritanceComposite.class, - value - ); - } - - @Override - protected InheritanceType getValue() { - return subject().getSpecifiedInheritanceStrategy(); - } - - @Override - protected void setValue(InheritanceType value) { - subject().setSpecifiedInheritanceStrategy(value); - } - }; - } - - private void initializeDiscriminatorColumnPane(Composite container) { - - PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder = - buildDiscriminatorColumnHolder(); - - // Name widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.DiscriminatorColumnComposite_name, - buildDiscriminatorColumnCombo(container, discriminatorColumnHolder), - JpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN - ); - - // Discriminator Type widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.DiscriminatorColumnComposite_discriminatorType, - buildDiscriminatorTypeCombo(container, discriminatorColumnHolder), - JpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_TYPE - ); - - container = buildCollapsableSubSection( - buildSubPane(container, 10), - JptUiMappingsMessages.InheritanceComposite_detailsGroupBox, - new SimplePropertyValueModel<Boolean>(Boolean.FALSE) - ); - - // Length widgets - Spinner lengthSpinner = buildLabeledSpinner( - container, - JptUiMappingsMessages.ColumnComposite_length, - buildLengthHolder(discriminatorColumnHolder), - -1, - -1, - Integer.MAX_VALUE, - buildDefaultLengthLabel(container), - JpaHelpContextIds.MAPPING_COLUMN_LENGTH - ); - - updateGridData(container, lengthSpinner); - - // Column Definition widgets - buildLabeledText( - container, - JptUiMappingsMessages.ColumnComposite_columnDefinition, - buildColumnDefinitionHolder(discriminatorColumnHolder) - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - Composite subPane = buildSubPane( - container, 0, groupBoxMargin, 0, groupBoxMargin - ); - - // Strategy widgets - buildLabeledComposite( - subPane, - JptUiMappingsMessages.InheritanceComposite_strategy, - buildStrategyCombo(subPane), - JpaHelpContextIds.ENTITY_INHERITANCE_STRATEGY - ); - - // Discrinator Value widgets - CCombo discriminatorValueCombo = buildLabeledEditableCCombo( - subPane, - JptUiMappingsMessages.InheritanceComposite_discriminatorValue, - buildDiscriminatorValueListHolder(), - buildDiscriminatorValueHolder(), - buildDiscriminatorValueConverter(), - JpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_VALUE - ); - - // Discriminator Column sub-pane - Composite discriminatorColumnContainer = buildTitledPane( - buildSubPane(container, 10), - JptUiMappingsMessages.InheritanceComposite_discriminatorColumnGroupBox - ); - - initializeDiscriminatorColumnPane(discriminatorColumnContainer); - - // Primary Key Join Columns widgets - buildPrimaryKeyJoinColumnsComposite(buildSubPane(container, 5)); - } - - protected abstract void buildPrimaryKeyJoinColumnsComposite(Composite container); - - /** - * Changes the layout of the given container by changing which widget will - * grab the excess of horizontal space. By default, the center control grabs - * the excess space, we change it to be the right control. - * - * @param container The container containing the controls needing their - * <code>GridData</code> to be modified from the default values - * @param spinner The spinner that got created - */ - private void updateGridData(Composite container, Spinner spinner) { - - // It is possible the spinner's parent is not the container of the - // label, spinner and right control (a pane is sometimes required for - // painting the spinner's border) - Composite paneContainer = spinner.getParent(); - - while (container != paneContainer.getParent()) { - paneContainer = paneContainer.getParent(); - } - - Control[] controls = paneContainer.getChildren(); - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = false; - gridData.horizontalAlignment = GridData.BEGINNING; - controls[1].setLayoutData(gridData); - - controls[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - removeAlignRight(controls[2]); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractPrimaryKeyJoinColumnsComposite.java deleted file mode 100644 index cccea06381..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractPrimaryKeyJoinColumnsComposite.java +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.util.PaneEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -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.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListPropertyValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | - Join Columns ---------------------------------------------------------- | - * | | | | - * | | x Override Default | | - * | | | | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | AddRemoveListPane | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see InheritanceComposite - The container of this pane - * - * @version 2.0 - * @since 2.0 - */ -public abstract class AbstractPrimaryKeyJoinColumnsComposite<T extends Entity> extends AbstractPane<T> -{ - protected WritablePropertyValueModel<PrimaryKeyJoinColumn> joinColumnHolder; - - /** - * Creates a new <code>PrimaryKeyJoinColumnsComposite</code>. - * - * @param parentPane The parent controller of this one - * @param parent The parent container - */ - public AbstractPrimaryKeyJoinColumnsComposite(AbstractPane<? extends T> subjectHolder, - Composite parent) { - - super(subjectHolder, parent); - } - - /** - * 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 AbstractPrimaryKeyJoinColumnsComposite(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private void addJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { - - Entity subject = subject(); - int index = subject.specifiedPrimaryKeyJoinColumnsSize(); - - PrimaryKeyJoinColumn joinColumn = subject.addSpecifiedPrimaryKeyJoinColumn(index); - stateObject.updateJoinColumn(joinColumn); - } - - private void addPrimaryKeyJoinColumn() { - - PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog( - shell(), - subject(), - null - ); - - dialog.openDialog(buildAddPrimaryKeyJoinColumnPostExecution()); - } - - private PostExecution<PrimaryKeyJoinColumnDialog> buildAddPrimaryKeyJoinColumnPostExecution() { - return new PostExecution<PrimaryKeyJoinColumnDialog>() { - public void execute(PrimaryKeyJoinColumnDialog dialog) { - if (dialog.wasConfirmed()) { - addJoinColumn(dialog.subject()); - } - } - }; - } - - protected abstract ListValueModel<? extends PrimaryKeyJoinColumn> buildDefaultJoinColumnsListHolder(); - - private PostExecution<PrimaryKeyJoinColumnDialog> buildEditPrimaryKeyJoinColumnPostExecution() { - return new PostExecution<PrimaryKeyJoinColumnDialog>() { - public void execute(PrimaryKeyJoinColumnDialog dialog) { - if (dialog.wasConfirmed()) { - editJoinColumn(dialog.subject()); - } - } - }; - } - - private WritablePropertyValueModel<PrimaryKeyJoinColumn> buildJoinColumnHolder() { - return new SimplePropertyValueModel<PrimaryKeyJoinColumn>(); - } - - private String buildJoinColumnLabel(PrimaryKeyJoinColumn joinColumn) { - if (joinColumn.isVirtual()) { - return NLS.bind( - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, - joinColumn.getName(), - joinColumn.getReferencedColumnName() - ); - } - - 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 Adapter buildJoinColumnsAdapter() { - return new AbstractAdapter() { - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - addPrimaryKeyJoinColumn(); - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - editPrimaryKeyJoinColumn(listSelectionModel); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - - int[] selectedIndices = listSelectionModel.selectedIndices(); - Entity entity = subject(); - - for (int index = selectedIndices.length; --index >= 0; ) { - entity.removeSpecifiedPrimaryKeyJoinColumn(selectedIndices[index]); - } - } - }; - } - - private ILabelProvider buildJoinColumnsListLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - return buildJoinColumnLabel((PrimaryKeyJoinColumn) element); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() { - return new OverrideDefaultJoinColumnHolder(); - } - - private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListHolder() { - List<ListValueModel<? extends PrimaryKeyJoinColumn>> list = new ArrayList<ListValueModel<? extends PrimaryKeyJoinColumn>>(); - list.add(buildSpecifiedJoinColumnsListHolder()); - list.add(buildDefaultJoinColumnsListHolder()); - return new CompositeListValueModel<ListValueModel<? extends PrimaryKeyJoinColumn>, PrimaryKeyJoinColumn>(list); - } - - private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListModel() { - return new ItemPropertyListValueModelAdapter<PrimaryKeyJoinColumn>( - buildPrimaryKeyJoinColumnsListHolder(), - NamedColumn.SPECIFIED_NAME_PROPERTY, - NamedColumn.DEFAULT_NAME_PROPERTY, - BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, - BaseJoinColumn.DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY - ); - } - - private ListValueModel<PrimaryKeyJoinColumn> buildSpecifiedJoinColumnsListHolder() { - return new ListAspectAdapter<Entity, PrimaryKeyJoinColumn>(getSubjectHolder(), Entity.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) { - @Override - protected ListIterator<PrimaryKeyJoinColumn> listIterator_() { - return subject.specifiedPrimaryKeyJoinColumns(); - } - - @Override - protected int size_() { - return subject.specifiedPrimaryKeyJoinColumnsSize(); - } - }; - } - - private void editJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - - private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { - - PrimaryKeyJoinColumn joinColumn = (PrimaryKeyJoinColumn) listSelectionModel.selectedValue(); - - PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog( - shell(), - subject(), - joinColumn - ); - - dialog.openDialog(buildEditPrimaryKeyJoinColumnPostExecution()); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - joinColumnHolder = buildJoinColumnHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Primary Key Join Columns group pane - Group groupPane = buildTitledPane( - container, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn - ); - - // Override Default Join Columns check box - buildCheckBox( - buildSubPane(groupPane, 8), - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, - buildOverrideDefaultJoinColumnHolder() - ); - - // Primary Key Join Columns list pane - AddRemoveListPane<Entity> joinColumnsListPane = new AddRemoveListPane<Entity>( - this, - groupPane, - buildJoinColumnsAdapter(), - buildPrimaryKeyJoinColumnsListModel(), - joinColumnHolder, - buildJoinColumnsListLabelProvider(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS - ); - - installJoinColumnsListPaneEnabler(joinColumnsListPane); - } - - private void installJoinColumnsListPaneEnabler(AddRemoveListPane<Entity> pane) { - new PaneEnabler( - buildOverrideDefaultJoinColumnHolder(), - pane - ); - } - - private void updateJoinColumns(boolean selected) { - - if (isPopulating()) { - return; - } - - setPopulating(true); - - try { - // Add a join column by creating a specified one using the default - // one if it exists - if (selected) { - - switchDefaultToSpecified(); - } - // Remove all the specified join columns - else { - for (int index = subject().specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { - subject().removeSpecifiedPrimaryKeyJoinColumn(index); - } - } - } - finally { - setPopulating(false); - } - } - - protected abstract void switchDefaultToSpecified(); - - private class OverrideDefaultJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean> - implements WritablePropertyValueModel<Boolean> { - - public OverrideDefaultJoinColumnHolder() { - super(buildSpecifiedJoinColumnsListHolder()); - } - - @Override - protected Boolean buildValue() { - return listHolder.size() > 0; - } - - public void setValue(Boolean value) { - updateJoinColumns(value); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractSecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractSecondaryTablesComposite.java deleted file mode 100644 index e7cccff23c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractSecondaryTablesComposite.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.SecondaryTable; -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.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PrimaryKeyJoinColumnsInSecondaryTableComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OrmEntity - * @see OrmEntityComposite - The container of this pane - * @see AddRemoveListPane - * @see PrimaryKeyJoinColumnsInSecondaryTableComposite - * - * @version 2.0 - * @since 1.0 - */ -public abstract class AbstractSecondaryTablesComposite<T extends Entity> extends AbstractFormPane<T> -{ - /** - * Creates a new <code>SecondaryTablesComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public AbstractSecondaryTablesComposite(AbstractFormPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent, false); - } - - /** - * 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 AbstractSecondaryTablesComposite(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - 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(); - SecondaryTable secondaryTable = this.subject().addSpecifiedSecondaryTable(index); - secondaryTable.setSpecifiedName(name); - if (!dialog.isDefaultCatalogSelected()) { - secondaryTable.setSpecifiedCatalog(catalog); - } - if (!dialog.isDefaultSchemaSelected()) { - secondaryTable.setSpecifiedSchema(schema); - } - - listSelectionModel.setSelectedValue(secondaryTable); - } - } - - protected WritablePropertyValueModel<SecondaryTable> buildSecondaryTableHolder() { - return new SimplePropertyValueModel<SecondaryTable>(); - } - - protected ILabelProvider buildSecondaryTableLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - // TODO display a qualified name instead - SecondaryTable secondaryTable = (SecondaryTable) element; - if (secondaryTable.getName() != null) { - return secondaryTable.getName(); - } - return "";//TODO - } - }; - } - - protected SecondaryTableDialog buildSecondaryTableDialogForAdd() { - return new SecondaryTableDialog(getControl().getShell(), subject().getJpaProject(), subject().getTable().getDefaultSchema(), subject().getTable().getDefaultCatalog()); - } - - protected AddRemoveListPane.Adapter buildSecondaryTablesAdapter() { - return new AddRemoveListPane.AbstractAdapter() { - - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - SecondaryTableDialog dialog = buildSecondaryTableDialogForAdd(); - addSecondaryTableFromDialog(dialog, listSelectionModel); - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiMappingsMessages.SecondaryTablesComposite_edit; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - SecondaryTable secondaryTable = (SecondaryTable) listSelectionModel.selectedValue(); - SecondaryTableDialog dialog = new SecondaryTableDialog(getControl().getShell(), secondaryTable, subject().getJpaProject()); - editSecondaryTableFromDialog(dialog, secondaryTable); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - Entity entity = subject(); - int[] selectedIndices = listSelectionModel.selectedIndices(); - - for (int index = selectedIndices.length; --index >= 0; ) { - entity.removeSpecifiedSecondaryTable(selectedIndices[index]); - } - } - - @Override - public boolean enableOptionOnSelectionChange(ObjectListSelectionModel listSelectionModel) { - if (listSelectionModel.selectedValuesSize() != 1) { - return false; - } - SecondaryTable secondaryTable = (SecondaryTable) listSelectionModel.selectedValue(); - return !secondaryTable.isVirtual(); - } - - @Override - public boolean enableRemoveOnSelectionChange(ObjectListSelectionModel listSelectionModel) { - if (listSelectionModel.selectedValue() == null) { - return false; - } - SecondaryTable secondaryTable = (SecondaryTable) listSelectionModel.selectedValue(); - return !secondaryTable.isVirtual(); - } - }; - } - - private void editSecondaryTableDialogOkd(SecondaryTableDialog dialog, SecondaryTable secondaryTable) { - String name = dialog.getSelectedName(); - String catalog = dialog.getSelectedCatalog(); - String schema = dialog.getSelectedSchema(); - - if (secondaryTable.getSpecifiedName() == null || !secondaryTable.getSpecifiedName().equals(name)){ - secondaryTable.setSpecifiedName(name); - } - - if (dialog.isDefaultCatalogSelected()) { - if (secondaryTable.getSpecifiedCatalog() != null) { - secondaryTable.setSpecifiedCatalog(null); - } - } - else if (secondaryTable.getSpecifiedCatalog() == null || !secondaryTable.getSpecifiedCatalog().equals(catalog)){ - secondaryTable.setSpecifiedCatalog(catalog); - } - - if (dialog.isDefaultSchemaSelected()) { - if (secondaryTable.getSpecifiedSchema() != null) { - secondaryTable.setSpecifiedSchema(null); - } - } - else if (secondaryTable.getSpecifiedSchema() == null || !secondaryTable.getSpecifiedSchema().equals(schema)){ - secondaryTable.setSpecifiedSchema(schema); - } - } - - private void editSecondaryTableFromDialog(SecondaryTableDialog dialog, SecondaryTable secondaryTable) { - if (dialog.open() == Window.OK) { - editSecondaryTableDialogOkd(dialog, secondaryTable); - } - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnDialog.java deleted file mode 100644 index f00883a597..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnDialog.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractValidatingDialog; -import org.eclipse.swt.widgets.Shell; - -/** - * The abstract definition the dialog showing the information for a join column - * to edit or to create. - * - * @see BaseJoinColumnStateObject - * - * @version 2.0 - * @since 1.0 - */ -public abstract class BaseJoinColumnDialog<T extends BaseJoinColumnStateObject> extends AbstractValidatingDialog<T> { - - /** - * Either the join column to edit or <code>null</code> if this state object - * is used to create a new one. - */ - private BaseJoinColumn joinColumn; - - /** - * The owner of the join column to create or where it is located. - */ - private Object owner; - - /** - * Creates a new <code>BaseJoinColumnDialog</code>. - * - * @param parent The parent shell - * @param owner The owner of the join column to create or where it is located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public BaseJoinColumnDialog(Shell parent, - Object owner, - BaseJoinColumn joinColumn) { - - super(parent); - - this.owner = owner; - this.joinColumn = joinColumn; - } - - /* - * (non-Javadoc) - */ - @Override - protected String description() { - return JptUiMappingsMessages.JoinColumnDialog_description; - } - - /* - * (non-Javadoc) - */ - @Override - protected String descriptionTitle() { - - if (joinColumn == null) { - return JptUiMappingsMessages.JoinColumnDialog_addJoinColumnDescriptionTitle; - } - - return JptUiMappingsMessages.JoinColumnDialog_editJoinColumnDescriptionTitle; - } - - /** - * Returns the join column used by this state object for editing or - * <code>null</code> if this state object is used to create a new one. - * - * @return Either the edited join column or <code>null</code> - */ - public BaseJoinColumn getJoinColumn() { - return joinColumn; - } - - /** - * Returns the owner where the join column is located or where a new one can - * be added. - * - * @return The parent of the join column - */ - protected Object getOwner() { - return owner; - } - - /* - * (non-Javadoc) - */ - @Override - protected String title() { - - if (joinColumn == null) { - return JptUiMappingsMessages.JoinColumnDialog_addJoinColumnTitle; - } - - return JptUiMappingsMessages.JoinColumnDialog_editJoinColumnTitle; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnDialogPane.java deleted file mode 100644 index cda5bb4dee..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnDialogPane.java +++ /dev/null @@ -1,442 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.ListIterator; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; -import org.eclipse.jpt.utility.internal.StringConverter; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------- | - * | Name: | I |v| | - * | ------------------------------------------------- | - * | ------------------------------------------------- | - * | Referenced Column Name: | I |v| | - * | ------------------------------------------------- | - * | ------------------------------------------------- | - * | Table: | I |v| | - * | ------------------------------------------------- | - * | ------------------------------------------------- | - * | Column Definition: | I | | - * | ------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see BaseJoinColumnStateObject - * @see InverseJoinColumnInJoinTableDialog - A container of this pane - * @see JoinColumnInJoinTableDialog - A container of this pane - * @see PrimaryKeyJoinColumnDialog - A container of this pane - * @see PrimaryKeyJoinColumnInSecondaryTableDialog - A container of this pane - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class BaseJoinColumnDialogPane<T extends BaseJoinColumnStateObject> extends AbstractDialogPane<T> -{ - /** - * A key used to represent the default value, this is required to convert - * the selected item from a combo to <code>null</code>. This key is most - * likely never typed the user and it will help to convert the value to - * <code>null</code> when it's time to set the new selected value into the - * model. - */ - protected static String DEFAULT_KEY = "?!#!?#?#?default?#?!#?!#?"; - - /** - * Creates a new <code>BaseJoinColumnDialogPane</code>. - * - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public BaseJoinColumnDialogPane(PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(subjectHolder, parent); - } - - private WritablePropertyValueModel<String> buildColumnDefinitionHolder() { - return new PropertyAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), BaseJoinColumnStateObject.COLUMN_DEFINITION_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getColumnDefinition(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setColumnDefinition(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Composite buildContainer(Composite parent) { - return buildSubPane(parent, 0, 7, 0, 5); - } - - private PropertyValueModel<String> buildDefaultNameHolder() { - return new TransformationPropertyValueModel<BaseJoinColumnStateObject, String>(getSubjectHolder()) { - @Override - protected String transform_(BaseJoinColumnStateObject value) { - String name = value.getDefaultName(); - - if (name == null) { - name = DEFAULT_KEY; - } - else { - name = DEFAULT_KEY + name; - } - - return name; - } - }; - } - - private ListValueModel<String> buildDefaultNameListHolder() { - return new PropertyListValueModelAdapter<String>( - buildDefaultNameHolder() - ); - } - - private PropertyValueModel<String> buildDefaultReferencedColumnNameHolder() { - return new TransformationPropertyValueModel<BaseJoinColumnStateObject, String>(getSubjectHolder()) { - @Override - protected String transform_(BaseJoinColumnStateObject value) { - String name = value.getDefaultReferencedColumnName(); - - if (name == null) { - name = DEFAULT_KEY; - } - else { - name = DEFAULT_KEY + name; - } - - return name; - } - }; - } - - private ListValueModel<String> buildDefaultReferencedColumnNameListHolder() { - return new PropertyListValueModelAdapter<String>( - buildDefaultReferencedColumnNameHolder() - ); - } - - private PropertyValueModel<String> buildDefaultTableHolder() { - return new TransformationPropertyValueModel<BaseJoinColumnStateObject, String>(getSubjectHolder()) { - @Override - protected String transform_(BaseJoinColumnStateObject value) { - String name = value.getDefaultTable(); - - if (name == null) { - name = DEFAULT_KEY; - } - else { - name = DEFAULT_KEY + name; - } - - return name; - } - }; - } - - private ListValueModel<String> buildDefaultTableListHolder() { - return new PropertyListValueModelAdapter<String>( - buildDefaultTableHolder() - ); - } - - private StringConverter<String> buildDisplayableStringConverter(final DefaultValueHandler handler) { - return new StringConverter<String>() { - public String convertToString(String value) { - - if (subject() == null) { - return null; - } - - if (value == null) { - value = handler.getDefaultValue(); - - if (value != null) { - value = DEFAULT_KEY + value; - } - else { - value = DEFAULT_KEY; - } - } - - if (value.startsWith(DEFAULT_KEY)) { - String defaultName = value.substring(DEFAULT_KEY.length()); - - if (defaultName.length() > 0) { - value = NLS.bind( - JptUiMappingsMessages.DefaultWithValue, - defaultName - ); - } - else { - value = JptUiMappingsMessages.DefaultWithoutValue; - } - } - - return value; - } - }; - } - - private WritablePropertyValueModel<String> buildNameHolder() { - return new PropertyAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), BaseJoinColumnStateObject.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - - // Convert the default value or an empty string to null - if ((value != null) && - ((value.length() == 0) || value.startsWith(DEFAULT_KEY))) { - - value = null; - } - - subject.setName(value); - } - }; - } - - private ListValueModel<String> buildNameListHolder() { - return new ListAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), BaseJoinColumnStateObject.NAMES_LIST) { - @Override - protected ListIterator<String> listIterator_() { - return subject.names(); - } - @Override - protected int size_() { - return subject.columnsSize(); - } - }; - } - - private ListValueModel<String> buildNamesListHolder() { - ArrayList<ListValueModel<String>> holders = new ArrayList<ListValueModel<String>>(2); - holders.add(buildDefaultNameListHolder()); - holders.add(buildNameListHolder()); - return new CompositeListValueModel<ListValueModel<String>, String>(holders); - } - - private StringConverter<String> buildNameStringConverter() { - return buildDisplayableStringConverter(new DefaultValueHandler() { - public String getDefaultValue() { - return subject().getDefaultName(); - } - }); - } - - private WritablePropertyValueModel<String> buildReferencedColumnNameHolder() { - return new PropertyAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), BaseJoinColumnStateObject.REFERENCED_COLUMN_NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getReferencedColumnName(); - } - - @Override - protected void setValue_(String value) { - - // Convert the default value or an empty string to null - if ((value != null) && - ((value.length() == 0) || value.startsWith(DEFAULT_KEY))) { - - value = null; - } - - subject.setReferencedColumnName(value); - } - }; - } - - private ListValueModel<String> buildReferencedColumnNameListHolder() { - return new ListAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), BaseJoinColumnStateObject.REFERENCE_COLUMN_NAMES_LIST) { - @Override - protected ListIterator<String> listIterator_() { - return subject.referenceColumnNames(); - } - @Override - protected int size_() { - return subject.referenceColumnsSize(); - } - }; - } - - private ListValueModel<String> buildReferencedColumnNamesListHolder() { - ArrayList<ListValueModel<String>> holders = new ArrayList<ListValueModel<String>>(2); - holders.add(buildDefaultReferencedColumnNameListHolder()); - holders.add(buildReferencedColumnNameListHolder()); - return new CompositeListValueModel<ListValueModel<String>, String>(holders); - } - - private StringConverter<String> buildReferencedColumnNameStringConverter() { - return buildDisplayableStringConverter(new DefaultValueHandler() { - public String getDefaultValue() { - return subject().getDefaultReferencedColumnName(); - } - }); - } - - private WritablePropertyValueModel<String> buildTableHolder() { - return new PropertyAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), BaseJoinColumnStateObject.TABLE_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getTable(); - } - - @Override - protected void setValue_(String value) { - - // Convert the default value or an empty string to null - if ((value != null) && - ((value.length() == 0) || value.startsWith(DEFAULT_KEY))) { - - value = null; - } - - subject.setTable(value); - } - }; - } - - private ListValueModel<String> buildTableListHolder() { - return new ListAspectAdapter<BaseJoinColumnStateObject, String>(getSubjectHolder(), "") { - @Override - protected ListIterator<String> listIterator_() { - return subject.tables(); - } - }; - } - - private ListValueModel<String> buildTablesListHolder() { - ArrayList<ListValueModel<String>> holders = new ArrayList<ListValueModel<String>>(2); - holders.add(buildDefaultTableListHolder()); - holders.add(buildTableListHolder()); - return new CompositeListValueModel<ListValueModel<String>, String>(holders); - } - - private StringConverter<String> buildTableStringConverter() { - return buildDisplayableStringConverter(new DefaultValueHandler() { - public String getDefaultValue() { - return subject().getDefaultTable(); - } - }); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Name widgets - Combo nameCombo = buildLabeledEditableCombo( - container, - JptUiMappingsMessages.JoinColumnDialog_name, - buildNamesListHolder(), - buildNameHolder(), - buildNameStringConverter(), - JpaHelpContextIds.MAPPING_JOIN_COLUMN_NAME - ); - - SWTUtil.attachDefaultValueHandler(nameCombo); - - // Referenced Column Name widgets - Combo referencedColumnNameCombo = buildLabeledEditableCombo( - container, - JptUiMappingsMessages.JoinColumnDialog_referencedColumnName, - buildReferencedColumnNamesListHolder(), - buildReferencedColumnNameHolder(), - buildReferencedColumnNameStringConverter(), - JpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN - ); - - SWTUtil.attachDefaultValueHandler(referencedColumnNameCombo); - - // Table widgets - if (isTableEditable()) { - - Combo tableCombo = buildLabeledEditableCombo( - container, - JptUiMappingsMessages.JoinColumnDialogPane_table, - buildTablesListHolder(), - buildTableHolder(), - buildTableStringConverter(), - JpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN - ); - - SWTUtil.attachDefaultValueHandler(tableCombo); - } - else { - Combo tableCombo = buildLabeledCombo( - container, - JptUiMappingsMessages.JoinColumnDialogPane_table, - buildTablesListHolder(), - buildTableHolder(), - buildTableStringConverter(), - JpaHelpContextIds.MAPPING_JOIN_REFERENCED_COLUMN - ); - - tableCombo.setEnabled(false); - } - - // Column Definition widgets - buildLabeledText( - container, - JptUiMappingsMessages.JoinColumnDialogPane_columnDefinition, - buildColumnDefinitionHolder() - ); - } - - /** - * Determines whether the table combo should be editable or not. The default - * is to keep the combo read-only. - * - * @return <code>true</code> to support the editing of the selected table; - * <code>false</code> otherwise - */ - protected boolean isTableEditable() { - return false; - } - - protected static interface DefaultValueHandler { - String getDefaultValue(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnStateObject.java deleted file mode 100644 index 0a62f31055..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BaseJoinColumnStateObject.java +++ /dev/null @@ -1,417 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; -import org.eclipse.jpt.utility.internal.node.AbstractNode; -import org.eclipse.jpt.utility.internal.node.Node; - -/** - * The abstract definition of a state object used to edit or create a new - * join column. - * - * @see AbstractJoinColumn - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class BaseJoinColumnStateObject extends AbstractNode -{ - /** - * The SQL fragment that is used when generating the DDL for the column. - */ - private String columnDefinition; - - /** - * Either the join column is being edited or <code>null</code> the state - * object is being created. - */ - private BaseJoinColumn joinColumn; - - /** - * The join column's name or <code>null</code> if not defined. - */ - private String name; - - /** - * The owner of the join column to create or where it is located. - */ - private Object owner; - - /** - * The referenced column name or <code>null</code> if not defined. - */ - private String referencedColumnName; - - /** - * The table - */ - private String table; - - /** - * Keeps track of the <code>Validator</code> since this is the root object. - */ - private Validator validator; - - /** - * Identifies a change in the column definition property. - */ - public static final String COLUMN_DEFINITION_PROPERTY = "columnDefinition"; - - /** - * Identifies a change in the name property. - */ - public static final String NAME_PROPERTY = "name"; - - /** - * Identifies a change in the list of names. - */ - public static final String NAMES_LIST = "names"; - - /** - * Identifies a change in the list of reference column names. - */ - public static final String REFERENCE_COLUMN_NAMES_LIST = "referenceColumnNames"; - - /** - * Identifies a change in the referenced column name property. - */ - public static final String REFERENCED_COLUMN_NAME_PROPERTY = "referencedColumnName"; - - /** - * Identifies a change in the table property. - */ - public static final String TABLE_PROPERTY = "table"; - - /** - * Creates a new <code>AbstractJoinColumnStateObject</code>. - * - * @param owner The owner of the join column to create or where it is located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public BaseJoinColumnStateObject(Object owner, BaseJoinColumn joinColumn) { - super(null); - initialize(owner, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - protected final void checkParent(Node parentNode) { - // This is the root of the Join Column state object - } - - private ListIterator<String> columnNames(Table table) { - - if (table == null) { - return EmptyListIterator.instance(); - } - - List<String> names = CollectionTools.list(table.columnNames()); - Collections.sort(names); - return names.listIterator(); - } - - private int columnsSize(Table table) { - if (table == null) { - return 0; - } - return table.columnsSize(); - } - - /* - * (non-Javadoc) - */ - public final String displayString() { - return ""; - } - - /** - * Returns the SQL fragment that is used when generating the DDL for the - * column. - * - * @return The edited column name or <code>null</code> if not used - */ - public String getColumnDefinition() { - return columnDefinition; - } - - /** - * Returns the default name if the join column is being edited otherwise - * <code>null</code> is returned. - * - * @return Either the default name defined by the join column or <code>null</code> - */ - public String getDefaultName() { - if (this.joinColumn == null) { - return null; - } - - return this.joinColumn.getDefaultName(); - } - - /** - * Returns the default referenced column name if the join column is being - * edited otherwise <code>null</code> is returned. - * - * @return Either the default referenced column name defined by the join - * column or <code>null</code> - */ - public String getDefaultReferencedColumnName() { - if (this.joinColumn == null) { - return null; - } - - return this.joinColumn.getDefaultReferencedColumnName(); - } - - /** - * Returns - * - * @return - */ - public abstract String getDefaultTable(); - - /** - * Returns the edited join column or <code>null</code> if this state object - * is used to create a new one. - * - * @return The edited join column or <code>null</code> - */ - public BaseJoinColumn getJoinColumn() { - return this.joinColumn; - } - - /** - * Returns the name of the join column. - * - * @return Either join column's name or <code>null</code> to use the default - * name - */ - public String getName() { - return this.name; - } - - /** - * Returns the database table if one can be found. - * - * @return The database table - */ - public abstract Table getNameTable(); - - /** - * Returns the owner where the join column is located or where a new one can - * be added. - * - * @return The parent of the join column - */ - public Object getOwner() { - return owner; - } - - /** - * Returns the referenced column name of the join column. - * - * @return Either join column's referenced column name or <code>null</code> - * to use the default name - */ - public String getReferencedColumnName() { - return this.referencedColumnName; - } - - /** - * Returns - * - * @return - */ - public abstract Table getReferencedNameTable(); - - /** - * Returns - * - * @return - */ - public String getTable() { - return table; - } - - /* - * (non-Javadoc) - */ - @Override - public final Validator getValidator() { - return this.validator; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - validator = NULL_VALIDATOR; - } - - /** - * Initializes this state object. - * - * @param owner The owner of the join column to create or where it is located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - protected void initialize(Object owner, BaseJoinColumn joinColumn) { - - this.owner = owner; - this.joinColumn = joinColumn; - this.table = this.initialTable(); - - if (joinColumn != null) { - this.name = joinColumn.getSpecifiedName(); - this.columnDefinition = joinColumn.getColumnDefinition(); - this.referencedColumnName = joinColumn.getSpecifiedReferencedColumnName(); - } - } - - /** - * Returns - */ - protected abstract String initialTable(); - - /** - * Returns the column names if the database table can be resolved. - * - * @return The names of the table's columns or an empty iterator if the table - * can't be resolved - */ - public ListIterator<String> names() { - return columnNames(getNameTable()); - } - - public int columnsSize() { - return columnsSize(getNameTable()); - } - - /** - * Returns the reference column names if the database table can be resolved. - * - * @return The names of the table's columns or an empty iterator if the table - * can't be resolved - */ - public ListIterator<String> referenceColumnNames() { - return columnNames(getReferencedNameTable()); - } - - public int referenceColumnsSize() { - return columnsSize(getReferencedNameTable()); - } - - /** - * Sets the SQL fragment that is used when generating the DDL for the column. - * - * @param columnDefinition The new join column's column definition or - * <code>null</code> to clear the value - */ - public void setColumnDefinition(String columnDefinition) { - String oldColumnDefinition = this.columnDefinition; - this.columnDefinition = columnDefinition; - firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, columnDefinition); - } - - /** - * Sets the name of the join column. - * - * @param name The new join column's name or <code>null</code> to use the - * default name - */ - public void setName(String name) { - String oldName = this.name; - this.name = name; - firePropertyChanged(NAME_PROPERTY, oldName, name); - } - - /** - * Sets the referenced column name of the join column. - * - * @param referencedColumnName The new join column's referenced column name - * or <code>null</code> to use the default referenced column name - */ - public void setReferencedColumnName(String referencedColumnName) { - String oldReferencedColumnName = this.referencedColumnName; - this.referencedColumnName = referencedColumnName; - firePropertyChanged(REFERENCED_COLUMN_NAME_PROPERTY, oldReferencedColumnName, referencedColumnName); - } - - public void setTable(String table) { - String oldTable = this.table; - this.table = table; - firePropertyChanged(TABLE_PROPERTY, oldTable, table); - tableChanged(); - } - - /* - * (non-Javadoc) - */ - @Override - public final void setValidator(Validator validator) { - this.validator = validator; - } - - /** - * The table from which the column names are used has changed, notifies the - * listeners the list of names and reference column names should be updated. - */ - protected void tableChanged() { - fireListChanged(NAMES_LIST); - fireListChanged(REFERENCE_COLUMN_NAMES_LIST); - } - - /** - * Retrieves the list of all the table names contains in the associated - * schema. The default returns an empty iterator. - * - * @return The names of the tables - */ - public ListIterator<String> tables() { - return EmptyListIterator.instance(); - } - - /** - * Updates the given join column with the values contained in this state - * object. - * - * @param joinColumn The join column to update - */ - public void updateJoinColumn(BaseJoinColumn joinColumn) { - - // Name - if (valuesAreDifferent(name, joinColumn.getSpecifiedName())) { - joinColumn.setSpecifiedName(name); - } - - // Referenced Column Name - if (valuesAreDifferent(referencedColumnName, joinColumn.getSpecifiedReferencedColumnName())) { - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - - // Column Definition - if (valuesAreDifferent(columnDefinition, joinColumn.getColumnDefinition())) { - joinColumn.setColumnDefinition(columnDefinition); - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index b4ee94be74..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/BasicMappingComposite.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | ColumnComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | FetchTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | TemporalTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | EnumTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OptionalComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | LobComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see BasicMapping - * @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<BasicMapping> - implements JpaComposite<BasicMapping> -{ - /** - * 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<BasicMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<Column> buildColumnHolder() { - return new TransformationPropertyValueModel<BasicMapping, Column>(getSubjectHolder()) { - @Override - protected Column transform_(BasicMapping value) { - return value.getColumn(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - // Column widgets - new ColumnComposite(this, buildColumnHolder(), container); - - // Align the widgets under the ColumnComposite - container = buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); - - // Fetch Type widgets - new FetchTypeComposite(this, container); - - // Temporal Type widgets - new TemporalTypeComposite(this, container); - - // Enumerated widgets - new EnumTypeComposite(this, container); - - // Optional widgets - new OptionalComposite(this, buildSubPane(container, 4)); - - // Lob check box - new LobComposite(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/CascadeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CascadeComposite.java deleted file mode 100644 index 2201ff7caf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CascadeComposite.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.RelationshipMapping; -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.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | - Cascade --------------------------------------------------------------- | - * | | | | - * | | x All x Persist x Merge x Remove x Refresh | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Cascade - * @see RelationshipMapping - * @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<Cascade> -{ - /** - * 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 RelationshipMapping> parentPane, - PropertyValueModel<? extends Cascade> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent, false); - } - - /** - * 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 Cascade> subjectHolder, - Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private WritablePropertyValueModel<Boolean> buildCascadeTypeAllHolder() { - return new PropertyAspectAdapter<Cascade, Boolean>(getSubjectHolder(), Cascade.ALL_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.isAll(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setAll(value); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildCascadeTypeMergeHolder() { - return new PropertyAspectAdapter<Cascade, Boolean>(getSubjectHolder(), Cascade.MERGE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.isMerge(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setMerge(value); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildCascadeTypePersistHolder() { - return new PropertyAspectAdapter<Cascade, Boolean>(getSubjectHolder(), Cascade.PERSIST_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.isPersist(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setPersist(value); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildCascadeTypeRefreshHolder() { - return new PropertyAspectAdapter<Cascade, Boolean>(getSubjectHolder(), Cascade.REFRESH_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.isRefresh(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setRefresh(value); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildCascadeTypeRemoveHolder() { - return new PropertyAspectAdapter<Cascade, Boolean>(getSubjectHolder(), Cascade.REMOVE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.isRemove(); - } - - @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/ColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java deleted file mode 100644 index 5244341a7d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java +++ /dev/null @@ -1,825 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import java.util.Iterator; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; -import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; -import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; -import org.eclipse.jpt.ui.internal.util.LabeledLabel; -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.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | ColumnCombo | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | TableCombo | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | > Details | - * | | - * | x Insertable | - * | | - * | x Updatable | - * | | - * | x Unique | - * | | - * | x Nullable | - * | | - * | --------------- | - * | Length: | I |I| Default (XXX) | - * | --------------- | - * | --------------- | - * | Precision: | I |I| Default (XXX) | - * | --------------- | - * | --------------- | - * | Scale: | I |I| Default (XXX) | - * | --------------- | - * | ---------------------------------------------------- | - * | Column Definition: | I | | - * | ---------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Column - * @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 - * - * @version 2.0 - * @since 1.0 - */ -public class ColumnComposite extends AbstractFormPane<Column> { - - /** - * 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 Column> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * 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 - * @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 - */ - public ColumnComposite(AbstractFormPane<?> parentPane, - PropertyValueModel<? extends Column> subjectHolder, - Composite parent, - boolean automaticallyAlignWidgets) { - - super(parentPane, subjectHolder, parent, automaticallyAlignWidgets); - } - - /** - * 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 Column> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private ColumnCombo<Column> buildColumnCombo(Composite container) { - - return new ColumnCombo<Column>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Column.DEFAULT_NAME_PROPERTY); - propertyNames.add(Column.SPECIFIED_NAME_PROPERTY); - propertyNames.add(Column.DEFAULT_TABLE_PROPERTY); - propertyNames.add(Column.SPECIFIED_TABLE_PROPERTY); - } - - @Override - protected void propertyChanged(String propertyName) { - - if (propertyName == Column.DEFAULT_TABLE_PROPERTY || - propertyName == Column.SPECIFIED_TABLE_PROPERTY) { - - doPopulate(); - } - else { - super.propertyChanged(propertyName); - } - } - - @Override - protected String defaultValue() { - return subject().getDefaultName(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedName(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedName(); - } - }; - } - - private WritablePropertyValueModel<String> buildColumnDefinitionHolder() { - return new PropertyAspectAdapter<Column, String>(getSubjectHolder(), Column.COLUMN_DEFINITION_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getColumnDefinition(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setColumnDefinition(value); - } - }; - } - - private WritablePropertyValueModel<Integer> buildDefaultLengthHolder() { - return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.DEFAULT_LENGTH_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getDefaultLength(); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Integer.MIN_VALUE, newValue); - } - } - }; - } - - private Control buildDefaultLengthLabel(Composite container) { - - Label label = buildLabel( - container, - JptUiMappingsMessages.DefaultWithoutValue - ); - - new LabeledControlUpdater( - new LabeledLabel(label), - buildDefaultLengthLabelHolder() - ); - - return label; - } - - private PropertyValueModel<String> buildDefaultLengthLabelHolder() { - - return new TransformationPropertyValueModel<Integer, String>(buildDefaultLengthHolder()) { - - @Override - protected String transform(Integer value) { - - Integer defaultValue = (subject() != null) ? subject().getDefaultLength() : - Column.DEFAULT_LENGTH; - - return NLS.bind( - JptUiMappingsMessages.DefaultWithValue, - defaultValue - ); - } - }; - } - - private WritablePropertyValueModel<Integer> buildDefaultPrecisionHolder() { - return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.DEFAULT_PRECISION_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getDefaultPrecision(); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Integer.MIN_VALUE, newValue); - } - } - }; - } - - private Control buildDefaultPrecisionLabel(Composite container) { - - Label label = buildLabel( - container, - JptUiMappingsMessages.DefaultWithoutValue - ); - - new LabeledControlUpdater( - new LabeledLabel(label), - buildDefaultPrecisionLabelHolder() - ); - - return label; - } - - private PropertyValueModel<String> buildDefaultPrecisionLabelHolder() { - - return new TransformationPropertyValueModel<Integer, String>(buildDefaultPrecisionHolder()) { - - @Override - protected String transform(Integer value) { - - Integer defaultValue = (subject() != null) ? subject().getDefaultPrecision() : - Column.DEFAULT_PRECISION; - - return NLS.bind( - JptUiMappingsMessages.DefaultWithValue, - defaultValue - ); - } - }; - } - - private WritablePropertyValueModel<Integer> buildDefaultScaleHolder() { - return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.DEFAULT_SCALE_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getDefaultScale(); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private Control buildDefaultScaleLabel(Composite container) { - - Label label = buildLabel( - container, - JptUiMappingsMessages.DefaultWithoutValue - ); - - new LabeledControlUpdater( - new LabeledLabel(label), - buildDefaultScaleLabelHolder() - ); - - return label; - } - - private PropertyValueModel<String> buildDefaultScaleLabelHolder() { - - return new TransformationPropertyValueModel<Integer, String>(buildDefaultScaleHolder()) { - - @Override - protected String transform(Integer value) { - - Integer defaultValue = (subject() != null) ? subject().getDefaultScale() : - Column.DEFAULT_SCALE; - - return NLS.bind( - JptUiMappingsMessages.DefaultWithValue, - defaultValue - ); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildInsertableHolder() { - return new PropertyAspectAdapter<Column, Boolean>(getSubjectHolder(), Column.SPECIFIED_INSERTABLE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedInsertable(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedInsertable(value); - } - }; - } - - 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 - ); - } - } - - return JptUiMappingsMessages.ColumnComposite_insertable; - } - }; - } - - private WritablePropertyValueModel<Integer> buildLengthHolder() { - return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.SPECIFIED_LENGTH_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getSpecifiedLength(); - } - - @Override - protected void setValue_(Integer value) { - if (value == -1) { - value = null; - } - subject.setSpecifiedLength(value); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildNullableHolder() { - return new PropertyAspectAdapter<Column, Boolean>( - getSubjectHolder(), - Column.DEFAULT_NULLABLE_PROPERTY, - Column.SPECIFIED_NULLABLE_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedNullable(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedNullable(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private PropertyValueModel<String> buildNullableStringHolder() { - return new TransformationPropertyValueModel<Boolean, String>(buildNullableHolder()) { - @Override - protected String transform(Boolean value) { - - if ((subject() != null) && (value == null)) { - - Boolean defaultValue = subject().getDefaultNullable(); - - if (defaultValue != null) { - - String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : - JptUiMappingsMessages.Boolean_False; - - return NLS.bind( - JptUiMappingsMessages.ColumnComposite_nullableWithDefault, - defaultStringValue - ); - } - } - - return JptUiMappingsMessages.ColumnComposite_nullable; - } - }; - } - - private WritablePropertyValueModel<Integer> buildPrecisionHolder() { - return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.SPECIFIED_PRECISION_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getSpecifiedPrecision(); - } - - @Override - protected void setValue_(Integer value) { - if (value == -1) { - value = null; - } - subject.setSpecifiedPrecision(value); - } - }; - } - - private WritablePropertyValueModel<Integer> buildScaleHolder() { - return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.SPECIFIED_SCALE_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getSpecifiedScale(); - } - - @Override - protected void setValue_(Integer value) { - if (value == -1) { - value = null; - } - subject.setSpecifiedScale(value); - } - }; - } - - private TableCombo<Column> buildTableCombo(Composite container) { - - return new TableCombo<Column>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Column.DEFAULT_TABLE_PROPERTY); - propertyNames.add(Column.SPECIFIED_TABLE_PROPERTY); - } - - @Override - protected String defaultValue() { - return subject().getDefaultTable(); - } - - @Override - protected String schemaName() { - return null; - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedTable(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedTable(); - } - - @Override - protected Iterator<String> values() { - return subject().getOwner().getTypeMapping().associatedTableNamesIncludingInherited(); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildUniqueHolder() { - return new PropertyAspectAdapter<Column, Boolean>( - getSubjectHolder(), - Column.DEFAULT_UNIQUE_PROPERTY, - Column.SPECIFIED_UNIQUE_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedUnique(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedUnique(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private PropertyValueModel<String> buildUniqueStringHolder() { - - return new TransformationPropertyValueModel<Boolean, String>(buildUniqueHolder()) { - - @Override - protected String transform(Boolean value) { - - if ((subject() != null) && (value == null)) { - - Boolean defaultValue = subject().getDefaultUnique(); - - if (defaultValue != null) { - - String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : - JptUiMappingsMessages.Boolean_False; - - return NLS.bind( - JptUiMappingsMessages.ColumnComposite_uniqueWithDefault, - defaultStringValue - ); - } - } - - return JptUiMappingsMessages.ColumnComposite_unique; - } - }; - } - - private WritablePropertyValueModel<Boolean> buildUpdatableHolder() { - return new PropertyAspectAdapter<Column, Boolean>( - getSubjectHolder(), - Column.DEFAULT_UPDATABLE_PROPERTY, - Column.SPECIFIED_UPDATABLE_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedUpdatable(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedUpdatable(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - 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; - } - }; - } - - private void initializeDetailsPane(Composite container) { - - // Insertable tri-state check box - buildTriStateCheckBoxWithDefault( - buildSubPane(container, 4), - JptUiMappingsMessages.ColumnComposite_insertable, - buildInsertableHolder(), - buildInsertableStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_INSERTABLE - ); - - // Updatable tri-state check box - buildTriStateCheckBoxWithDefault( - container, - JptUiMappingsMessages.ColumnComposite_updatable, - buildUpdatableHolder(), - buildUpdatableStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_UPDATABLE - ); - - // Unique tri-state check box - buildTriStateCheckBoxWithDefault( - container, - JptUiMappingsMessages.ColumnComposite_unique, - buildUniqueHolder(), - buildUniqueStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_UNIQUE - ); - - // Nullable tri-state check box - buildTriStateCheckBoxWithDefault( - container, - JptUiMappingsMessages.ColumnComposite_nullable, - buildNullableHolder(), - buildNullableStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_NULLABLE - ); - - // Length widgets - Spinner lengthSpinner = buildLabeledSpinner( - container, - JptUiMappingsMessages.ColumnComposite_length, - buildLengthHolder(), - -1, - -1, - Integer.MAX_VALUE, - buildDefaultLengthLabel(container), - JpaHelpContextIds.MAPPING_COLUMN_LENGTH - ); - - updateGridData(container, lengthSpinner); - - // Precision widgets - Spinner precisionSpinner = buildLabeledSpinner( - container, - JptUiMappingsMessages.ColumnComposite_precision, - buildPrecisionHolder(), - -1, - -1, - Integer.MAX_VALUE, - buildDefaultPrecisionLabel(container), - JpaHelpContextIds.MAPPING_COLUMN_PRECISION - ); - - updateGridData(container, precisionSpinner); - - // Scale widgets - Spinner scaleSpinner = buildLabeledSpinner( - container, - JptUiMappingsMessages.ColumnComposite_scale, - buildScaleHolder(), - -1, - -1, - Integer.MAX_VALUE, - buildDefaultScaleLabel(container), - JpaHelpContextIds.MAPPING_COLUMN_SCALE - ); - - updateGridData(container, scaleSpinner); - - // Column Definition widgets - buildLabeledText( - container, - JptUiMappingsMessages.ColumnComposite_columnDefinition, - buildColumnDefinitionHolder() - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Column group pane - container = buildTitledPane( - container, - JptUiMappingsMessages.ColumnComposite_columnSection - ); - - // Column widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.ColumnComposite_name, - buildColumnCombo(container), - JpaHelpContextIds.MAPPING_COLUMN - ); - - // Table widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.ColumnComposite_table, - buildTableCombo(container), - JpaHelpContextIds.MAPPING_COLUMN_TABLE - ); - - // Details sub-pane - container = buildCollapsableSubSection( - container, - JptUiMappingsMessages.ColumnComposite_details, - new SimplePropertyValueModel<Boolean>(Boolean.FALSE) - ); - - initializeDetailsPane(buildSubPane(container, 0, 16)); - } - - /** - * Changes the layout of the given container by changing which widget will - * grab the excess of horizontal space. By default, the center control grabs - * the excess space, we change it to be the right control. - * - * @param container The container containing the controls needing their - * <code>GridData</code> to be modified from the default values - * @param spinner The spinner that got created - */ - private void updateGridData(Composite container, Spinner spinner) { - - // It is possible the spinner's parent is not the container of the - // label, spinner and right control (a pane is sometimes required for - // painting the spinner's border) - Composite paneContainer = spinner.getParent(); - - while (container != paneContainer.getParent()) { - paneContainer = paneContainer.getParent(); - } - - Control[] controls = paneContainer.getChildren(); - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = false; - gridData.horizontalAlignment = GridData.BEGINNING; - controls[1].setLayoutData(gridData); - - controls[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - removeAlignRight(controls[2]); - } -}
\ 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 deleted file mode 100644 index c1d01e6aff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddableComposite.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * This pane does not have any widgets. - * - * @see Embeddable - * @see BaseJpaUiFactory - The factory creating this pane - * @see EmbeddableUiProvider - * - * @version 2.0 - * @since 2.0 - */ -public class EmbeddableComposite extends AbstractFormPane<Embeddable> - implements JpaComposite<Embeddable> -{ - /** - * 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 Embeddable> subjectHolder, - Composite parent, - WidgetFactory 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/EmbeddedAttributeOverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java deleted file mode 100644 index 0534cb3ef7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java +++ /dev/null @@ -1,322 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseEmbeddedMapping; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.Adapter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -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.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | x Override Default | - * | | - * | ------------------------------------------------------------------------- | - * | | | | - * | | ColumnComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see EmbeddedMapping - * @see EmbeddedMappingComposite - The parent container - * @see ColumnComposite - * - * @version 2.0 - * @since 1.0 - */ -public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEmbeddedMapping> -{ - private WritablePropertyValueModel<AttributeOverride> attributeOverrideHolder; - - /** - * Creates a new <code>EmbeddedAttributeOverridesComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public EmbeddedAttributeOverridesComposite(AbstractFormPane<? extends BaseEmbeddedMapping> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * 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 BaseEmbeddedMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private WritablePropertyValueModel<AttributeOverride> buildAttributeOverrideHolder() { - return new SimplePropertyValueModel<AttributeOverride>(); - } - - private ILabelProvider buildAttributeOverrideLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - return buildOverrideDisplayString((AttributeOverride) element); - } - }; - } - - private Adapter buildAttributeOverridesAdapter() { - return new AddRemoveListPane.AbstractAdapter() { - - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - } - }; - } - - private ListValueModel<AttributeOverride> buildAttributeOverridesListHolder() { - List<ListValueModel<AttributeOverride>> list = new ArrayList<ListValueModel<AttributeOverride>>(); - list.add(buildSpecifiedAttributeOverridesListHolder()); - list.add(buildDefaultAttributeOverridesListHolder()); - return new CompositeListValueModel<ListValueModel<AttributeOverride>, AttributeOverride>(list); - } - - private ListValueModel<AttributeOverride> buildAttributeOverridesListModel() { - return new ItemPropertyListValueModelAdapter<AttributeOverride>( - buildAttributeOverridesListHolder(), - BaseOverride.NAME_PROPERTY - ); - } - - private PropertyValueModel<Column> buildColumnHolder(WritablePropertyValueModel<AttributeOverride> attributeOverrideHolder) { - return new TransformationPropertyValueModel<AttributeOverride, Column>(attributeOverrideHolder) { - @Override - protected Column transform_(AttributeOverride value) { - return value.getColumn(); - } - }; - } - - private ListValueModel<AttributeOverride> buildDefaultAttributeOverridesListHolder() { - return new ListAspectAdapter<BaseEmbeddedMapping, AttributeOverride>( - this.getSubjectHolder(), - BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST) - { - @Override - protected ListIterator<AttributeOverride> listIterator_() { - return subject.virtualAttributeOverrides(); - } - - @Override - protected int size_() { - return subject.virtualAttributeOverridesSize(); - } - }; - } - - private PropertyValueModel<Boolean> buildOverrideDefaultAttributeOverrideEnablerHolder() { - return new TransformationPropertyValueModel<AttributeOverride, Boolean>(attributeOverrideHolder) { - @Override - protected Boolean transform(AttributeOverride value) { - return (value != null); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultAttributeOverrideHolder() { - return new TransformationWritablePropertyValueModel<AttributeOverride, Boolean>(attributeOverrideHolder) { - @Override - public void setValue(Boolean value) { - updateAssociationOverride(value); - } - - @Override - protected Boolean transform_(AttributeOverride value) { - return !value.isVirtual(); - } - }; - } - - private String buildOverrideDisplayString(AttributeOverride override) { - - String name = override.getName(); - - if (StringTools.stringIsEmpty(name)) { - name = JptUiMappingsMessages.OverridesComposite_noName; - } - else { - name = name.trim(); - } - - return name; - } - - private ListValueModel<AttributeOverride> buildSpecifiedAttributeOverridesListHolder() { - return new ListAspectAdapter<BaseEmbeddedMapping, AttributeOverride>( - this.getSubjectHolder(), - BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST) - { - @Override - protected ListIterator<AttributeOverride> listIterator_() { - return subject.specifiedAttributeOverrides(); - } - - @Override - public int size_() { - return subject.specifiedAttributeOverridesSize(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - this.attributeOverrideHolder = buildAttributeOverrideHolder(); - } - - private AddRemoveListPane<BaseEmbeddedMapping> initializeAttributeOverridesList(Composite container) { - - return new AddRemoveListPane<BaseEmbeddedMapping>( - this, - buildSubPane(container, 8), - buildAttributeOverridesAdapter(), - buildAttributeOverridesListModel(), - attributeOverrideHolder, - buildAttributeOverrideLabelProvider(), - JpaHelpContextIds.MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES - ) - { - @Override - protected void initializeButtonPane(Composite container, String helpId) { - } - - @Override - protected void updateButtons() { - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Attribute Overrides group box - container = buildTitledPane( - container, - JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides - ); - - // Attribute Overrides list - initializeAttributeOverridesList(container); - - // Property pane - initializePropertyPane(buildSubPane(container, 5, 0)); - } - - private void initializePropertyPane(Composite container) { - - // Override Default check box - Button overrideDefaultButton = buildCheckBox( - buildSubPane(container, 0, groupBoxMargin()), - JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault, - buildOverrideDefaultAttributeOverrideHolder() - ); - - removeFromEnablementControl(overrideDefaultButton); - installOverrideDefaultButtonEnabler(overrideDefaultButton); - - // Column widgets - ColumnComposite columnComposite = new ColumnComposite( - this, - buildColumnHolder(attributeOverrideHolder), - container - ); - - installColumnCompositeEnabler(columnComposite); - removeFromEnablementControl(columnComposite.getControl()); - } - - private void installColumnCompositeEnabler(ColumnComposite columnComposite) { - new PaneEnabler( - buildOverrideDefaultAttributeOverrideHolder(), - columnComposite - ); - } - - private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) { - new ControlEnabler( - buildOverrideDefaultAttributeOverrideEnablerHolder(), - overrideDefaultButton - ); - } - - private void updateAssociationOverride(boolean selected) { - - if (isPopulating()) { - return; - } - - setPopulating(true); - - try { - AttributeOverride override = this.attributeOverrideHolder.getValue(); - - AttributeOverride newOverride = override.setVirtual(!selected); - this.attributeOverrideHolder.setValue(newOverride); - } - finally { - setPopulating(false); - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index 26185122b3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedIdMappingComposite.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here's the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | EmbeddedAttributeOverridesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see EmbeddedIdMapping - * @see BaseJpaUiFactory - The factory creating this pane - * - * @version 2.0 - * @since 1.0 - */ -public class EmbeddedIdMappingComposite extends AbstractEmbeddedMappingComposite<EmbeddedIdMapping> - implements JpaComposite<EmbeddedIdMapping> -{ - /** - * Creates a new <code>EmbeddedIdMappingComposite</code>. - * - * @param subjectHolder The holder of the subject <code>EmbeddedIdMapping</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public EmbeddedIdMappingComposite(PropertyValueModel<? extends EmbeddedIdMapping> subjectHolder, - Composite parent, - WidgetFactory 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/mappings/details/EmbeddedMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedMappingComposite.java deleted file mode 100644 index e43deea47d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedMappingComposite.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | EmbeddedAttributeOverridesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see EmbeddedMapping - * @see BaseJpaUiFactory - The factory creating this pane - * - * @version 2.0 - * @since 1.0 - */ -public class EmbeddedMappingComposite extends AbstractEmbeddedMappingComposite<EmbeddedMapping> - implements JpaComposite<EmbeddedMapping> -{ - /** - * Creates a new <code>EmbeddedMappingComposite</code>. - * - * @param subjectHolder The holder of the subject <code>EmbeddedMapping</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public EmbeddedMappingComposite(PropertyValueModel<? extends EmbeddedMapping> subjectHolder, - Composite parent, - WidgetFactory 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/mappings/details/EntityNameComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityNameComposite.java deleted file mode 100644 index ce20058618..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityNameComposite.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------ | - * | Entity Name: | I |v| | - * | ------------------------------------------------------------ | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see AbstractEntityComposite - The parent container - * - * @version 2.0 - * @since 1.0 - */ -public class EntityNameComposite extends AbstractPane<Entity> -{ - /** - * Creates a new <code>EntityNameComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public EntityNameComposite(AbstractPane<? extends Entity> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private PropertyValueModel<String> buildDefaultEntityNameHolder() { - return new PropertyAspectAdapter<Entity, String>(getSubjectHolder(), Entity.DEFAULT_NAME_PROPERTY) { - @Override - protected String buildValue_() { - return defaultValue(subject); - } - }; - } - - private ListValueModel<String> buildDefaultEntityNameListHolder() { - return new PropertyListValueModelAdapter<String>( - buildDefaultEntityNameHolder() - ); - } - - private WritablePropertyValueModel<String> buildEntityNameHolder() { - return new PropertyAspectAdapter<Entity, String>(getSubjectHolder(), Entity.SPECIFIED_NAME_PROPERTY, Entity.DEFAULT_NAME_PROPERTY) { - @Override - protected String buildValue_() { - - String name = subject.getSpecifiedName(); - - if (name == null) { - name = defaultValue(subject); - } - - return name; - } - - @Override - protected void setValue_(String value) { - - if (defaultValue(subject).equals(value)) { - value = null; - } - - subject.setSpecifiedName(value); - } - }; - } - - private String defaultValue(Entity subject) { - String defaultValue = subject.getDefaultName(); - - if (defaultValue != null) { - return NLS.bind( - JptUiMappingsMessages.EntityGeneralSection_nameDefaultWithOneParam, - defaultValue - ); - } - else { - return JptUiMappingsMessages.EntityGeneralSection_nameDefaultEmpty; - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - CCombo combo = buildLabeledEditableCCombo( - container, - JptUiMappingsMessages.EntityNameComposite_name, - buildDefaultEntityNameListHolder(), - buildEntityNameHolder(), - JpaHelpContextIds.ENTITY_NAME - ); - - SWTUtil.attachDefaultValueHandler(combo); - } -} 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 deleted file mode 100644 index 568a746741..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EnumTypeComposite.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | -------------------------------------------------------------- | - * | Enum Type: | |v| | - * | -------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see BasicMapping - * @see BasicMappingComposite - A container of this widget - * - * @version 2.0 - * @since 1.0 - */ -public class EnumTypeComposite extends AbstractFormPane<BasicMapping> -{ - /** - * Creates a new <code>FetchTypeComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public EnumTypeComposite(AbstractFormPane<? extends BasicMapping> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private EnumFormComboViewer<BasicMapping, EnumType> buildEnumTypeCombo(Composite container) { - - return new EnumFormComboViewer<BasicMapping, EnumType>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(BasicMapping.DEFAULT_ENUMERATED_PROPERTY); - propertyNames.add(BasicMapping.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) { - - buildLabeledComposite( - container, - JptUiMappingsMessages.BasicGeneralSection_enumeratedLabel, - buildEnumTypeCombo(container), - JpaHelpContextIds.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 deleted file mode 100644 index 1275243c8c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/FetchTypeComposite.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.Fetchable; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------ | - * | Fetch: | |v| | - * | ------------------------------------------------------------------ | - * -----------------------------------------------------------------------------</pre> - * - * @see Fetchable - * @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<Fetchable> { - - /** - * Creates a new <code>FetchTypeComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public FetchTypeComposite(AbstractFormPane<? extends Fetchable> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private EnumFormComboViewer<Fetchable, FetchType> buildFetchTypeCombo(Composite container) { - - return new EnumFormComboViewer<Fetchable, FetchType>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Fetchable.DEFAULT_FETCH_PROPERTY); - propertyNames.add(Fetchable.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) { - - buildLabeledComposite( - container, - JptUiMappingsMessages.BasicGeneralSection_fetchLabel, - buildFetchTypeCombo(container), - JpaHelpContextIds.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 deleted file mode 100644 index 12499e1bf1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratedValueComposite.java +++ /dev/null @@ -1,423 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.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> - * ----------------------------------------------------------------------------- - * | --------------------------------------------------------- | - * | Strategy: | I |v| | - * | --------------------------------------------------------- | - * | --------------------------------------------------------- | - * | Generator Name: | I |v| | - * | --------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see IdMapping - * @see GeneratedValue - * @see GenerationComposite - The parent container - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class GeneratedValueComposite extends AbstractFormPane<IdMapping> -{ - private PropertyChangeListener generatedValuePropertyChangeListener; - private CCombo generatorNameCombo; - private PropertyChangeListener generatorNamePropertyChangeListener; - private ListChangeListener generatorsListChangeListener; - - /** - * Creates a new <code>GeneratedValueComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public GeneratedValueComposite(AbstractFormPane<? extends IdMapping> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private PropertyChangeListener buildGeneratedValuePropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper( - buildGeneratedValuePropertyChangeListener_() - ); - } - - private PropertyChangeListener buildGeneratedValuePropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - disengageListeners((GeneratedValue) e.getOldValue()); - engageListeners((GeneratedValue) e.getNewValue()); - - if (!isPopulating()) { - setPopulating(true); - - try { - populateGeneratorNameCombo(); - } - finally { - setPopulating(false); - } - } - } - }; - } - - private ModifyListener buildGeneratorNameModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (isPopulating()) { - return; - } - - String generatorName = ((CCombo) e.getSource()).getText(); - GeneratedValue generatedValue = subject().getGeneratedValue(); - - if (StringTools.stringIsEmpty(generatorName)) { - - if ((generatedValue == null) || - StringTools.stringIsEmpty(generatedValue.getGenerator())) - { - return; - } - - generatorName = null; - } - - retrieveGeneratedValue().setSpecifiedGenerator(generatorName); - } - }; - } - - private PropertyChangeListener buildGeneratorNamePropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper( - buildGeneratorNamePropertyChangeListener_() - ); - } - - private PropertyChangeListener buildGeneratorNamePropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - if (!isPopulating()) { - setPopulating(true); - - try { - populateGeneratorName(); - } - finally { - setPopulating(false); - } - } - } - }; - } - - private ListChangeListener buildGeneratorsListChangeListener() { - return new SWTListChangeListenerWrapper( - buildGeneratorsListChangeListener_()); - } - - private ListChangeListener buildGeneratorsListChangeListener_() { - return new ListChangeAdapter() { - @Override - // should only have to listen to this event - others aren't created - public void listChanged(ListChangeEvent event) { - if (! isPopulating()) { - setPopulating(true); - - try { - populateGeneratorChoices(); - } - finally { - setPopulating(false); - } - } - - } - }; - } - - private PropertyValueModel<GeneratedValue> buildGeneratorValueHolder() { - return new PropertyAspectAdapter<IdMapping, GeneratedValue>(getSubjectHolder(), IdMapping.GENERATED_VALUE_PROPERTY) { - @Override - protected GeneratedValue buildValue_() { - return subject().getGeneratedValue(); - } - }; - } - - private EnumFormComboViewer<GeneratedValue, GenerationType> buildStrategyComboViewer(Composite parent) { - - return new EnumFormComboViewer<GeneratedValue, GenerationType>(this, buildGeneratorValueHolder(), parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(GeneratedValue.DEFAULT_STRATEGY_PROPERTY); - propertyNames.add(GeneratedValue.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) { - retrieveGeneratedValue().setSpecifiedStrategy(value); - } - }; - } - - private void disengageListeners(GeneratedValue generatedValue) { - - if (generatedValue != null) { - - generatedValue.removePropertyChangeListener( - GeneratedValue.DEFAULT_GENERATOR_PROPERTY, - generatorNamePropertyChangeListener - ); - - generatedValue.removePropertyChangeListener( - GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, - generatorNamePropertyChangeListener - ); - - generatedValue.getPersistenceUnit().removeListChangeListener( - PersistenceUnit.GENERATORS_LIST, - generatorsListChangeListener - ); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void disengageListeners(IdMapping subject) { - super.disengageListeners(subject); - - if (subject != null) { - subject.removePropertyChangeListener( - IdMapping.GENERATED_VALUE_PROPERTY, - generatedValuePropertyChangeListener - ); - disengageListeners(subject.getGeneratedValue()); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - populateGeneratorNameCombo(); - } - - private void engageListeners(GeneratedValue generatedValue) { - - if (generatedValue != null) { - - generatedValue.addPropertyChangeListener( - GeneratedValue.DEFAULT_GENERATOR_PROPERTY, - generatorNamePropertyChangeListener - ); - - generatedValue.addPropertyChangeListener( - GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, - generatorNamePropertyChangeListener - ); - - generatedValue.getPersistenceUnit().addListChangeListener( - PersistenceUnit.GENERATORS_LIST, - generatorsListChangeListener - ); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void engageListeners(IdMapping subject) { - super.engageListeners(subject); - - if (subject != null) { - engageListeners(subject.getGeneratedValue()); - subject.addPropertyChangeListener( - IdMapping.GENERATED_VALUE_PROPERTY, - generatedValuePropertyChangeListener - ); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - - generatedValuePropertyChangeListener = buildGeneratedValuePropertyChangeListener(); - generatorNamePropertyChangeListener = buildGeneratorNamePropertyChangeListener(); - generatorsListChangeListener = buildGeneratorsListChangeListener(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Strategy widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.GeneratedValueComposite_strategy, - buildStrategyComboViewer(container), - JpaHelpContextIds.MAPPING_GENERATED_VALUE_STRATEGY - ); - - // Generator Name widgets - generatorNameCombo = buildLabeledEditableCCombo( - container, - JptUiMappingsMessages.GeneratedValueComposite_generatorName, - buildGeneratorNameModifyListener(), - JpaHelpContextIds.MAPPING_GENERATED_VALUE_STRATEGY - ); - - generatorNameCombo.add(JptUiMappingsMessages.TableComposite_defaultEmpty); - } - - private void populateGeneratorChoices() { - if (subject() == null) { - this.generatorNameCombo.setItems(new String[0]); - } - else { - this.generatorNameCombo.setItems(this.sortedUniqueGeneratorNames()); - } - } - - private void populateGeneratorName() { - if (subject() == null) { - this.generatorNameCombo.setText(""); - } - else { - GeneratedValue generatedValue = subject().getGeneratedValue(); - - if (generatedValue == null) { - this.generatorNameCombo.setText(""); - } - else { - String generatorName = generatedValue.getGenerator(); - - if (StringTools.stringIsEmpty(generatorName)) { - this.generatorNameCombo.setText(""); - } - else if (!this.generatorNameCombo.getText().equals(generatorName)) { - this.generatorNameCombo.setText(generatorName); - } - } - } - } - - private void populateGeneratorNameCombo() { - populateGeneratorName(); - populateGeneratorChoices(); - } - - private GeneratedValue retrieveGeneratedValue() { - GeneratedValue generatedValue = subject().getGeneratedValue(); - - if (generatedValue == null) { - setPopulating(true); - - try { - generatedValue = subject().addGeneratedValue(); - } - finally { - setPopulating(false); - } - } - - return generatedValue; - } - - private String[] sortedUniqueGeneratorNames() { - return CollectionTools.array( - CollectionTools.sortedSet( - new TransformationIterator<Generator, String>( - new FilteringIterator<Generator, Generator>(subject().getPersistenceUnit().allGenerators()) - { - @Override - protected boolean accept(Generator o) { - return o.getName() != null; - } - }) - { - @Override - protected String transform(Generator next) { - return next.getName(); - } - }), - new String[0]); - } -}
\ 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 deleted file mode 100644 index b1bc1ab258..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GeneratorHolder; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.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 IdMapping - * @see GeneratedValueComposite - * @see TableGeneratorComposite - * @see SequenceGeneratorComposite - * @see IdMappingComposite - The parent container - * - * @version 2.0 - * @since 1.0 - */ -public class GenerationComposite extends AbstractFormPane<IdMapping> -{ - 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 IdMapping> parentPane, - Composite parent) - { - super(parentPane, parent, false); - } - - private WritablePropertyValueModel<Boolean> buildPrimaryKeyGenerationHolder() { - return new PropertyAspectAdapter<IdMapping, Boolean>(getSubjectHolder(), IdMapping.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<IdMapping, Boolean>(getSubjectHolder(), GeneratorHolder.SEQUENCE_GENERATOR_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getSequenceGenerator() != null; - } - - @Override - protected void setValue_(Boolean value) { - - if (value && (subject.getSequenceGenerator() == null)) { - - SequenceGenerator sequenceGenerator = subject.addSequenceGenerator(); - GeneratedValue 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<IdMapping, Boolean>(getSubjectHolder(), GeneratorHolder.TABLE_GENERATOR_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getTableGenerator() != null; - } - - @Override - protected void setValue_(Boolean value) { - - if (value && (subject.getTableGenerator() == null)) { - - TableGenerator tableGenerator = subject.addTableGenerator(); - GeneratedValue 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 = buildCollapsableSection( - container, - JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration, - new SimplePropertyValueModel<Boolean>(Boolean.TRUE) - ); - - // Primary Key Generation check box - Button primaryKeyGenerationCheckBox = buildCheckBox( - container, - JptUiMappingsMessages.IdMappingComposite_primaryKeyGeneration, - buildPrimaryKeyGenerationHolder(), - JpaHelpContextIds.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(buildSubPane(container, 10)); - - // Sequence Generator pane - initializeSequenceGeneratorPane(buildSubPane(container, 10)); - } - - private void initializeSequenceGeneratorPane(Composite container) { - - // Sequence Generator sub-section - container = buildCollapsableSubSection( - container, - JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, - sequenceGeneratorExpansionStateHolder - ); - - // Sequence Generator check box - Button sequenceGeneratorCheckBox = buildCheckBox( - container, - JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, - buildSequenceGeneratorBooleanHolder(), - JpaHelpContextIds.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 = buildCollapsableSubSection( - container, - JptUiMappingsMessages.IdMappingComposite_tableGenerator, - tableGeneratorExpansionStateHolder - ); - - Button tableGeneratorCheckBox = buildCheckBox( - container, - JptUiMappingsMessages.IdMappingComposite_tableGenerator, - buildTableGeneratorBooleanHolder(), - JpaHelpContextIds.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 deleted file mode 100644 index 6f70046bbe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java +++ /dev/null @@ -1,402 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.GeneratorHolder; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; -import org.eclipse.jpt.ui.internal.util.LabeledLabel; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; - -/** - * This is the generic pane for a generator. - * - * @see IdMapping - * @see Generator - * @see SequenceGeneratorComposite - A sub-pane - * @see TalbeGeneratorComposite - A sub-pane - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public abstract class GeneratorComposite<T extends Generator> extends AbstractPane<GeneratorHolder> -{ - /** - * Creates a new <code>GeneratorComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public GeneratorComposite(AbstractPane<? extends GeneratorHolder> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private WritablePropertyValueModel<Integer> buildAllocationSizeHolder() { - return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY) { - @Override - protected Integer buildValue_() { - Integer value = subject.getSpecifiedAllocationSize(); - if (value == null) { - return -1; - } - return value; - } - - @Override - public void setValue(Integer value) { - if (subject != null) { - setValue_(value); - return; - } - if (value == -1) { - return; - } - retrieveGenerator(subject()).setSpecifiedAllocationSize(value); - } - - @Override - protected void setValue_(Integer value) { - if (value == -1) { - value = null; - } - subject.setSpecifiedAllocationSize(value); - } - }; - } - - private WritablePropertyValueModel<Integer> buildDefaultAllocationSizeHolder() { - return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.DEFAULT_ALLOCATION_SIZE_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getDefaultAllocationSize(); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Integer.MIN_VALUE, newValue); - } - } - }; - } - - private Control buildDefaultAllocationSizeLabel(Composite container) { - - Label label = buildLabel( - container, - JptUiMappingsMessages.DefaultWithoutValue - ); - - new LabeledControlUpdater( - new LabeledLabel(label), - buildDefaultAllocationSizeLabelHolder() - ); - - return label; - } - - private PropertyValueModel<String> buildDefaultAllocationSizeLabelHolder() { - - return new TransformationPropertyValueModel<Integer, String>(buildDefaultAllocationSizeHolder()) { - - @Override - protected String transform(Integer value) { - - if (value != null) { - return NLS.bind(JptUiMappingsMessages.DefaultWithValue, value); - } - - return ""; - } - }; - } - - private WritablePropertyValueModel<Integer> buildDefaultInitialValueHolder() { - return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.DEFAULT_INITIAL_VALUE_PROPERTY) { - @Override - protected Integer buildValue_() { - return subject.getDefaultInitialValue(); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Integer.MIN_VALUE, newValue); - } - } - }; - } - - private Control buildDefaultInitialValueLabel(Composite container) { - - Label label = buildLabel( - container, - JptUiMappingsMessages.DefaultWithoutValue - ); - - new LabeledControlUpdater( - new LabeledLabel(label), - buildDefaultInitialValueLabelHolder() - ); - - return label; - } - - private PropertyValueModel<String> buildDefaultInitialValueLabelHolder() { - - return new TransformationPropertyValueModel<Integer, String>(buildDefaultInitialValueHolder()) { - - @Override - protected String transform(Integer value) { - - if (value != null) { - return NLS.bind(JptUiMappingsMessages.DefaultWithValue, value); - } - - return ""; - } - }; - } - - /** - * Creates the new <code>IGenerator</code>. - * - * @param subject The subject used to retrieve the generator - * @return The newly created <code>IGenerator</code> - */ - protected abstract T buildGenerator(GeneratorHolder subject); - - private PropertyValueModel<Generator> buildGeneratorHolder() { - return new PropertyAspectAdapter<GeneratorHolder, Generator>(getSubjectHolder(), propertyName()) { - @Override - protected Generator buildValue_() { - return GeneratorComposite.this.generator(subject); - } - }; - } - - protected final WritablePropertyValueModel<String> buildGeneratorNameHolder() { - return new PropertyAspectAdapter<Generator, String>(buildGeneratorHolder(), Generator.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - public void setValue(String value) { - if (subject != null) { - setValue_(value); - return; - } - if (value.length() == 0) { - return; - } - retrieveGenerator(subject()).setName(value); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<Integer> buildInitialValueHolder() { - return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.SPECIFIED_INITIAL_VALUE_PROPERTY) { - @Override - protected Integer buildValue_() { - Integer value = subject.getSpecifiedInitialValue(); - - if (value == null) { - return -1; - } - - return value; - } - - @Override - public void setValue(Integer value) { - if (subject != null) { - setValue_(value); - return; - } - if (value == -1) { - return; - } - retrieveGenerator(subject()).setSpecifiedInitialValue(value); - } - - @Override - protected void setValue_(Integer value) { - if (value == -1) { - value = null; - } - subject.setSpecifiedInitialValue(value); - } - }; - } - - /** - * Retrieves without creating the <code>Generator</code> from the subject. - * - * @return The <code>Generator</code> or <code>null</code> if it doesn't - * exists - */ - protected final T generator() { - return (this.subject() == null) ? null : this.generator(this.subject()); - } - - /** - * Retrieves without creating the <code>Generator</code> from the subject. - * - * @param subject The subject used to retrieve the generator - * @return The <code>Generator</code> or <code>null</code> if it doesn't - * exists - */ - protected abstract T generator(GeneratorHolder subject); - - /** - * Creates the labeled spinner responsible to edit the allocation size. The - * default value will be shown after the spinner. A value of -1 means the - * default value and the model has <code>null</code>. - * - * @param container The parent container - */ - protected void initializeAllocationSizeWidgets(Composite container) { - - Spinner spinner = buildLabeledSpinner( - container, - JptUiMappingsMessages.GeneratorComposite_allocationSize, - buildAllocationSizeHolder(), - -1, - -1, - Integer.MAX_VALUE, - buildDefaultAllocationSizeLabel(container) - ); - - updateGridData(container, spinner); - } - - /** - * Creates the labeled spinner responsible to edit the initial value. The - * default value will be shown after the spinner. A value of -1 means the - * default value and the model has <code>null</code>. - * - * @param container The parent container - */ - protected void initializeInitialValueWidgets(Composite container) { - - Spinner spinner = buildLabeledSpinner( - container, - JptUiMappingsMessages.GeneratorComposite_initialValue, - buildInitialValueHolder(), - -1, - -1, - Integer.MAX_VALUE, - buildDefaultInitialValueLabel(container) - ); - - - updateGridData(container, spinner); - } - - /** - * Retrieves the JPA project. - * - * @return The JPA project or <code>null</code> if the subject is <code>null</code> - */ - protected final JpaProject jpaProject() { - return this.subject() == null ? null : this.subject().getJpaProject(); - } - - /** - * 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(); - - /** - * Retrieves the <code>Generator</code> and if it is <code>null</code>, then - * create it. - * - * @param subject The subject used to retrieve the generator - * @return The <code>Generator</code> which should never be <code>null</code> - */ - protected final T retrieveGenerator(GeneratorHolder subject) { - T generator = this.generator(subject); - - if (generator == null) { - generator = this.buildGenerator(subject); - } - - return generator; - } - - /** - * Changes the layout of the given container by changing which widget will - * grab the excess of horizontal space. By default, the center control grabs - * the excess space, we change it to be the right control. - * - * @param container The container containing the controls needing their - * <code>GridData</code> to be modified from the default values - * @param spinner The spinner that got created - */ - private void updateGridData(Composite container, Spinner spinner) { - - // It is possible the spinner's parent is not the container of the - // label, spinner and right control (a pane is sometimes required for - // painting the spinner's border) - Composite paneContainer = spinner.getParent(); - - while (container != paneContainer.getParent()) { - paneContainer = paneContainer.getParent(); - } - - Control[] controls = paneContainer.getChildren(); - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = false; - gridData.horizontalAlignment = GridData.BEGINNING; - controls[1].setLayoutData(gridData); - - controls[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - removeAlignRight(controls[2]); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java deleted file mode 100644 index 6f7bdb5c81..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.GeneratorHolder; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | v Table Generator | - * | | - * | x Table Generator | - * | ----------------------------------------------------------------------- | - * | | | | - * | | TableGeneratorComposite | | - * | | | | - * | ----------------------------------------------------------------------- | - * | | - * | v Sequence Generator | - * | | - * | x Sequence Generator | - * | ----------------------------------------------------------------------- | - * | | | | - * | | SequenceGeneratorComposite | | - * | | | | - * | ----------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see GeneratorHolder - * @see TableGeneratorComposite - * @see SequenceGeneratorComposite - * @see AbstractEntityComposite - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class GeneratorsComposite extends AbstractPane<GeneratorHolder> -{ - private WritablePropertyValueModel<Boolean> sequenceGeneratorExpansionStateHolder; - private WritablePropertyValueModel<Boolean> tableGeneratorExpansionStateHolder; - - /** - * Creates a new <code>GeneratorsComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public GeneratorsComposite(AbstractPane<? extends GeneratorHolder> parentPane, - Composite parent) { - - super(parentPane, parent, false); - } - - private WritablePropertyValueModel<Boolean> buildSequenceGeneratorBooleanHolder() { - return new PropertyAspectAdapter<GeneratorHolder, Boolean>(getSubjectHolder(), GeneratorHolder.SEQUENCE_GENERATOR_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getSequenceGenerator() != null; - } - - @Override - protected void setValue_(Boolean value) { - - if (value && (subject.getSequenceGenerator() == null)) { - subject.addSequenceGenerator(); - } - else if (!value && (subject.getSequenceGenerator() != null)) { - subject.removeSequenceGenerator(); - } - } - }; - } - - private WritablePropertyValueModel<Boolean> buildTableGeneratorBooleanHolder() { - return new PropertyAspectAdapter<GeneratorHolder, Boolean>(getSubjectHolder(), GeneratorHolder.TABLE_GENERATOR_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getTableGenerator() != null; - } - - @Override - protected void setValue_(Boolean value) { - - if (value && (subject.getTableGenerator() == null)) { - subject.addTableGenerator(); - } - 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) { - - initializeTableGeneratorPane(container); - initializeSequenceGeneratorPane(container); - } - - private void initializeSequenceGeneratorPane(Composite container) { - - // Sequence Generator sub-section - container = buildCollapsableSubSection( - buildSubPane(container, 10), - JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, - sequenceGeneratorExpansionStateHolder - ); - - // Sequence Generator check box - Button sequenceGeneratorCheckBox = buildCheckBox( - buildSubPane(container, 5), - JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, - buildSequenceGeneratorBooleanHolder(), - JpaHelpContextIds.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 = buildCollapsableSubSection( - container, - JptUiMappingsMessages.IdMappingComposite_tableGenerator, - tableGeneratorExpansionStateHolder - ); - - Button tableGeneratorCheckBox = buildCheckBox( - buildSubPane(container, 5), - JptUiMappingsMessages.IdMappingComposite_tableGenerator, - buildTableGeneratorBooleanHolder(), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR - ); - - new TableGeneratorComposite( - this, - buildSubPane(container, 0, tableGeneratorCheckBox.getBorderWidth() + 16) - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdClassComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdClassComposite.java deleted file mode 100644 index 9572525351..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdClassComposite.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.context.IdClass; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.ClassChooserPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | ClassChooserPane | - * | | - * -----------------------------------------------------------------------------</pre> - * - * @see IdClass - * @see ClassChooserPane - * @see AbstractEntityComposite - A parent container - * @see MappedSuperclassComposite - A parent container - * - * @version 2.0 - * @since 2.0 - */ -public class IdClassComposite extends AbstractPane<IdClass> -{ - /** - * Creates a new <code>IdClassComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public IdClassComposite(AbstractPane<? extends IdClass> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private ClassChooserPane<IdClass> initializeClassChooser(Composite container) { - - return new ClassChooserPane<IdClass>(this, container) { - - @Override - protected WritablePropertyValueModel<String> buildTextHolder() { - return new PropertyAspectAdapter<IdClass, String>(getSubjectHolder(), IdClass.ID_CLASS_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getIdClass(); - } - - @Override - protected void setValue_(String value) { - - if (value.length() == 0) { - value = null; - } - - subject.setIdClass(value); - } - }; - } - - @Override - protected String className() { - return subject().getIdClass(); - } - - @Override - protected String labelText() { - return JptUiMappingsMessages.IdClassComposite_label; - } - - @Override - protected IPackageFragmentRoot packageFragmentRoot() { - IProject project = subject().getJpaProject().getProject(); - IJavaProject root = JavaCore.create(project); - - try { - return root.getAllPackageFragmentRoots()[0]; - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - - return null; - } - - @Override - protected void promptType() { - IType type = chooseType(); - - if (type != null) { - String className = type.getFullyQualifiedName('.'); - subject().setIdClass(className); - } - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - initializeClassChooser(container); - } -} 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 deleted file mode 100644 index d5dca15b37..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/IdMappingComposite.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | ColumnComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | TemporalTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | GenerationComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see IdMapping - * @see BaseJpaUiFactory - The factory creating this pane - * @see ColumnComposite - * @see TemporalTypeComposite - * @see GenerationComposite - * - * @version 2.0 - * @since 1.0 - */ -public class IdMappingComposite extends AbstractFormPane<IdMapping> - implements JpaComposite<IdMapping> -{ - /** - * 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 IdMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<? extends Column> buildColumnHolder() { - return new TransformationPropertyValueModel<IdMapping, Column>(getSubjectHolder()) { - @Override - protected Column transform_(IdMapping 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/InverseJoinColumnInJoinTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnInJoinTableDialog.java deleted file mode 100644 index f5bb927f0e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnInJoinTableDialog.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - -/** - * - * @see InverseJoinColumnInJoinTableStateObject - * @see BaseJoinColumnDialogPane - * - * @version 2.0 - * @since 2.0 - */ -public class InverseJoinColumnInJoinTableDialog extends BaseJoinColumnDialog<InverseJoinColumnInJoinTableStateObject> { - - /** - * Creates a new <code>JoinColumnInJoinTableDialog</code>. - * - * @param parent The parent shell - * @param joinTable The owner of the join column to create or where it is - * located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public InverseJoinColumnInJoinTableDialog(Shell parent, - JoinTable joinTable, - JoinColumn joinColumn) { - - super(parent, joinTable, joinColumn); - } - - /* - * non-Javadoc) - */ - @Override - protected AbstractDialogPane<InverseJoinColumnInJoinTableStateObject> buildLayout(Composite container) { - return new JoinColumnDialogPane<InverseJoinColumnInJoinTableStateObject>( - subjectHolder(), - container - ) - - { - @Override - protected boolean isTableEditable() { - return false; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected InverseJoinColumnInJoinTableStateObject buildStateObject() { - return new InverseJoinColumnInJoinTableStateObject( - getOwner(), - getJoinColumn() - ); - } - - /* - * (non-Javadoc) - */ - @Override - public JoinColumn getJoinColumn() { - return (JoinColumn) super.getJoinColumn(); - } - - /* - * (non-Javadoc) - */ - @Override - protected JoinTable getOwner() { - return (JoinTable) super.getOwner(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnInJoinTableStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnInJoinTableStateObject.java deleted file mode 100644 index 0fe221a43d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InverseJoinColumnInJoinTableStateObject.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; - -/** - * The state object used to create or edit a primary key join column on a join - * table. - * - * @see JoinColumn - * @see JoinTable - * @see InverseJoinColumnInJoinTableDialog - * - * @version 2.0 - * @since 2.0 - */ -public class InverseJoinColumnInJoinTableStateObject extends JoinColumnStateObject -{ - /** - * Creates a new <code>JoinColumnInJoinTableStateObject</code>. - * - * @param joinTable - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public InverseJoinColumnInJoinTableStateObject(JoinTable joinTable, - JoinColumn joinColumn) { - - super(joinTable, joinColumn); - } - - @Override - public String getDefaultTable() { - return null; - } - - @Override - public Table getNameTable() { - return getOwner().getDbTable(); - } - - @Override - public JoinTable getOwner() { - return (JoinTable) super.getOwner(); - } - - @Override - public Table getReferencedNameTable() { - Entity targetEntity = relationshipMapping().getResolvedTargetEntity(); - - if (targetEntity == null) { - return null; - } - - return targetEntity.getPrimaryDbTable(); - } - - @Override - protected Schema getSchema() { - return null; - } - - @Override - protected String initialTable() { - return getOwner().getName(); - } - - @Override - protected boolean isTableEditable() { - return false; - } - - /** - * Returns the mapping where the join column is located. - * - * @return The owner of the join column to create or to edit - */ - public RelationshipMapping relationshipMapping() { - return getOwner().getParent(); - } - - @Override - public ListIterator<String> tables() { - return new SingleElementListIterator<String>(initialTable()); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JavaPersistentTypeMapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JavaPersistentTypeMapAsComposite.java deleted file mode 100644 index de27d3438e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JavaPersistentTypeMapAsComposite.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import java.util.Iterator; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.java.details.NullTypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -/** - * This "Map As" composite is responsible for showing the mapping name and - * mapping type for a type declared in a Java type. - * - * @see JavaPersistentType - * @see JavaPersistentTypeDetailsPage - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class JavaPersistentTypeMapAsComposite extends PersistentTypeMapAsComposite<JavaPersistentType> -{ - /** - * Creates a new <code>JavaPersistentTypeMapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public JavaPersistentTypeMapAsComposite(AbstractPane<? extends JavaPersistentType> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected MappingUiProvider<JavaPersistentType> buildDefaultProvider() { - return new MappingUiProvider<JavaPersistentType>() { - - public Image getImage() { - return JpaMappingImageHelper.imageForTypeMapping(null); - } - - public String getLabel() { - return JptUiMessages.MapAsComposite_default; - } - - public String getMappingKey() { - return null; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders() { - - Collection<TypeMappingUiProvider<? extends TypeMapping>> providers = - CollectionTools.collection(jpaPlatformUi().javaTypeMappingUiProviders()); - - providers.remove(NullTypeMappingUiProvider.instance()); - return providers.iterator(); - } -} 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 deleted file mode 100644 index 0eb9d0f334..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java +++ /dev/null @@ -1,424 +0,0 @@ -/******************************************************************************* - * 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.ArrayList; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.SingleRelationshipMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -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.ui.internal.widgets.AddRemovePane.Adapter; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListPropertyValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | - Join Columns ---------------------------------------------------------- | - * | | | | - * | | x Override Default | | - * | | | | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | AddRemoveListPane | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see SingleRelationshipMapping - * @see JoinColumn - * @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<SingleRelationshipMapping> -{ - private WritablePropertyValueModel<JoinColumn> joinColumnHolder; - private WritablePropertyValueModel<Boolean> joinColumnPaneEnablerHolder; - - /** - * Creates a new <code>JoinColumnComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public JoinColumnComposite(AbstractFormPane<? extends SingleRelationshipMapping> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * 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 SingleRelationshipMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private void addJoinColumn() { - - JoinColumnInRelationshipMappingDialog dialog = - new JoinColumnInRelationshipMappingDialog(shell(), subject(), null); - - dialog.openDialog(buildAddJoinColumnPostExecution()); - } - - private void addJoinColumn(JoinColumnInRelationshipMappingStateObject stateObject) { - - SingleRelationshipMapping subject = subject(); - int index = subject.specifiedJoinColumnsSize(); - - JoinColumn joinColumn = subject.addSpecifiedJoinColumn(index); - stateObject.updateJoinColumn(joinColumn); - } - - private PostExecution<JoinColumnInRelationshipMappingDialog> buildAddJoinColumnPostExecution() { - return new PostExecution<JoinColumnInRelationshipMappingDialog>() { - public void execute(JoinColumnInRelationshipMappingDialog dialog) { - if (dialog.wasConfirmed()) { - addJoinColumn(dialog.subject()); - } - } - }; - } - - private PropertyValueModel<JoinColumn> buildDefaultJoinColumnHolder() { - return new PropertyAspectAdapter<SingleRelationshipMapping, JoinColumn>(getSubjectHolder(), SingleRelationshipMapping.DEFAULT_JOIN_COLUMN) { - @Override - protected JoinColumn buildValue_() { - return subject.getDefaultJoinColumn(); - } - }; - } - - private ListValueModel<JoinColumn> buildDefaultJoinColumnListHolder() { - return new PropertyListValueModelAdapter<JoinColumn>(buildDefaultJoinColumnHolder()); - } - - private PostExecution<JoinColumnInRelationshipMappingDialog> buildEditJoinColumnPostExecution() { - return new PostExecution<JoinColumnInRelationshipMappingDialog>() { - public void execute(JoinColumnInRelationshipMappingDialog dialog) { - if (dialog.wasConfirmed()) { - updateJoinColumn(dialog.subject()); - } - } - }; - } - - private WritablePropertyValueModel<JoinColumn> buildJoinColumnHolder() { - return new SimplePropertyValueModel<JoinColumn>(); - } - - private String buildJoinColumnLabel(JoinColumn joinColumn) { - if (joinColumn.isVirtual()) { - return NLS.bind( - JptUiMappingsMessages.JoinColumnComposite_mappingBetweenTwoParamsDefault, - joinColumn.getName(), - joinColumn.getReferencedColumnName() - ); - } - 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() - ); - } - } - - private SimplePropertyValueModel<Boolean> buildJoinColumnPaneEnablerHolder() { - return new SimplePropertyValueModel<Boolean>(Boolean.FALSE); - } - - private Adapter buildJoinColumnsAdapter() { - return new AddRemovePane.AbstractAdapter() { - - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - addJoinColumn(); - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiMappingsMessages.JoinColumnComposite_edit; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - editJoinColumn(listSelectionModel); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - removeJoinColumn(listSelectionModel); - } - }; - } - - private ListValueModel<JoinColumn> buildJoinColumnsListHolder() { - java.util.List<ListValueModel<JoinColumn>> list = new ArrayList<ListValueModel<JoinColumn>>(); - list.add(buildSpecifiedJoinColumnsListHolder()); - list.add(buildDefaultJoinColumnListHolder()); - return new CompositeListValueModel<ListValueModel<JoinColumn>, JoinColumn>(list); - } - - private ILabelProvider buildJoinColumnsListLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - JoinColumn joinColumn = (JoinColumn) element; - return buildJoinColumnLabel(joinColumn); - } - }; - } - - private ListValueModel<JoinColumn> buildJoinColumnsListModel() { - return new ItemPropertyListValueModelAdapter<JoinColumn>(buildJoinColumnsListHolder(), - NamedColumn.SPECIFIED_NAME_PROPERTY, - NamedColumn.DEFAULT_NAME_PROPERTY, - BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, - BaseJoinColumn.DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY); - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() { - return new OverrideDefaultJoinColumnHolder(); - } - - private ListValueModel<JoinColumn> buildSpecifiedJoinColumnsListHolder() { - return new ListAspectAdapter<SingleRelationshipMapping, JoinColumn>(getSubjectHolder(), SingleRelationshipMapping.SPECIFIED_JOIN_COLUMNS_LIST) { - @Override - protected ListIterator<JoinColumn> listIterator_() { - return subject.specifiedJoinColumns(); - } - - @Override - protected int size_() { - return subject.specifiedJoinColumnsSize(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - updateJoinColumnPaneEnablement(true); - } - - private void editJoinColumn(ObjectListSelectionModel listSelectionModel) { - - JoinColumn joinColumn = (JoinColumn) listSelectionModel.selectedValue(); - - JoinColumnInRelationshipMappingDialog dialog = - new JoinColumnInRelationshipMappingDialog(shell(), subject(), joinColumn); - - dialog.openDialog(buildEditJoinColumnPostExecution()); - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - super.enableWidgets(enabled); - updateJoinColumnPaneEnablement(enabled); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - - joinColumnHolder = buildJoinColumnHolder(); - joinColumnPaneEnablerHolder = buildJoinColumnPaneEnablerHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Join Columns group - Group groupPane = buildTitledPane( - container, - JptUiMappingsMessages.JoinColumnComposite_joinColumn - ); - - // Override Default Join Columns check box - buildCheckBox( - buildSubPane(groupPane, 8), - JptUiMappingsMessages.JoinColumnComposite_overrideDefaultJoinColumns, - buildOverrideDefaultJoinColumnHolder() - ); - - // Join Columns list pane - AddRemoveListPane<SingleRelationshipMapping> joinColumnsListPane = - new AddRemoveListPane<SingleRelationshipMapping>( - this, - groupPane, - buildJoinColumnsAdapter(), - buildJoinColumnsListModel(), - joinColumnHolder, - buildJoinColumnsListLabelProvider(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS - ); - - installJoinColumnsListPaneEnabler(joinColumnsListPane); - removeFromEnablementControl(joinColumnsListPane.getControl()); - } - - private void installJoinColumnsListPaneEnabler(AddRemoveListPane<SingleRelationshipMapping> pane) { - new PaneEnabler(joinColumnPaneEnablerHolder, pane); - } - - private void removeJoinColumn(ObjectListSelectionModel listSelectionModel) { - - int[] selectedIndices = listSelectionModel.selectedIndices(); - - for (int index = selectedIndices.length; --index >= 0; ) { - subject().removeSpecifiedJoinColumn(selectedIndices[index]); - } - } - - private void updateJoinColumn(JoinColumnInRelationshipMappingStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - - private void updateJoinColumnPaneEnablement(boolean enabled) { - - SingleRelationshipMapping subject = subject(); - enabled &= (subject != null) && subject.containsSpecifiedJoinColumns(); - joinColumnPaneEnablerHolder.setValue(enabled); - } - - private void updateJoinColumns(boolean selected) { - - if (isPopulating()) { - return; - } - - setPopulating(true); - - try { - SingleRelationshipMapping subject = subject(); - - // Add a join column by creating a specified one using the default - // one if it exists - if (selected) { - - JoinColumn defaultJoinColumn = subject.getDefaultJoinColumn();//TODO could be null, disable override default check box? - - if (defaultJoinColumn != null) { - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - JoinColumn joinColumn = subject.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - - joinColumnHolder.setValue(joinColumn); - } - } - // Remove all the specified join columns - else { - for (int index = subject.specifiedJoinColumnsSize(); --index >= 0; ) { - subject.removeSpecifiedJoinColumn(index); - } - } - - updateJoinColumnPaneEnablement(selected); - } - finally { - setPopulating(false); - } - } - - private class OverrideDefaultJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean> - implements WritablePropertyValueModel<Boolean> { - - public OverrideDefaultJoinColumnHolder() { - super(buildSpecifiedJoinColumnsListHolder()); - } - - @Override - protected Boolean buildValue() { - return listHolder.size() > 0; - } - - public void setValue(Boolean value) { - updateJoinColumns(value); - } - } -}
\ 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 deleted file mode 100644 index 419b1abdc6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialog.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - -/** - * The abstract definition of the dialog used to edit an <code>IJoinColumn</code>. - * - * @see JoinColumn - * @see JoinColumnStateObject - * @see JoinColumnDialogPane - * - * @version 2.0 - * @since 2.0 - */ -public abstract class JoinColumnDialog<T extends JoinColumnStateObject> extends BaseJoinColumnDialog<T> { - - /** - * Creates a new <code>AbstractJoinColumnDialog</code>. - * - * @param parent The parent shell - * @param owner The owner of the join column to create or where it is located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public JoinColumnDialog(Shell parent, Object owner, JoinColumn joinColumn) { - super(parent, owner, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - protected AbstractDialogPane<?> buildLayout(Composite container) { - return new JoinColumnDialogPane<T>(subjectHolder(), container); - } - - /* - * (non-Javadoc) - */ - @Override - public JoinColumn getJoinColumn() { - return (JoinColumn) super.getJoinColumn(); - } -}
\ 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 deleted file mode 100644 index af5589fe7c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | BaseJoinColumnDialogPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | x Insertable | - * | | - * | x Nullable | - * | | - * | x Unique | - * | | - * | x Updatable | - * | | - * -----------------------------------------------------------------------------</pre> - * - * @see JoinColumnStateObject - * @see JoinColumnDialog - The parent container - * - * @version 2.0 - * @since 1.0 - */ -public class JoinColumnDialogPane<T extends JoinColumnStateObject> extends BaseJoinColumnDialogPane<T> -{ - /** - * Creates a new <code>JoinColumnDialogPane</code>. - * - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public JoinColumnDialogPane(PropertyValueModel<? extends T> subjectHolder, - Composite parent) - { - super(subjectHolder, parent); - } - - private WritablePropertyValueModel<Boolean> buildInsertableHolder() { - return new PropertyAspectAdapter<T, Boolean>(getSubjectHolder(), JoinColumnStateObject.INSERTABLE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getInsertable(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setInsertable(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - 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.JoinColumnDialogPane_insertableWithDefault, - defaultStringValue - ); - } - } - - return JptUiMappingsMessages.JoinColumnDialogPane_insertable; - } - }; - } - - private WritablePropertyValueModel<Boolean> buildNullableHolder() { - return new PropertyAspectAdapter<T, Boolean>( - getSubjectHolder(), - JoinColumnStateObject.NULLABLE_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getNullable(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setNullable(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private PropertyValueModel<String> buildNullableStringHolder() { - - return new TransformationPropertyValueModel<Boolean, String>(buildNullableHolder()) { - - @Override - protected String transform(Boolean value) { - - if ((subject() != null) && (value == null)) { - - Boolean defaultValue = subject().getDefaultNullable(); - - if (defaultValue != null) { - - String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : - JptUiMappingsMessages.Boolean_False; - - return NLS.bind( - JptUiMappingsMessages.JoinColumnDialogPane_nullableWithDefault, - defaultStringValue - ); - } - } - - return JptUiMappingsMessages.JoinColumnDialogPane_nullable; - } - }; - } - - private WritablePropertyValueModel<Boolean> buildUniqueHolder() { - return new PropertyAspectAdapter<T, Boolean>( - getSubjectHolder(), - JoinColumnStateObject.UNIQUE_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getUnique(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setUnique(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private PropertyValueModel<String> buildUniqueStringHolder() { - - return new TransformationPropertyValueModel<Boolean, String>(buildUniqueHolder()) { - - @Override - protected String transform(Boolean value) { - - if ((subject() != null) && (value == null)) { - - Boolean defaultValue = subject().getDefaultUnique(); - - if (defaultValue != null) { - - String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : - JptUiMappingsMessages.Boolean_False; - - return NLS.bind( - JptUiMappingsMessages.JoinColumnDialogPane_uniqueWithDefault, - defaultStringValue - ); - } - } - - return JptUiMappingsMessages.JoinColumnDialogPane_unique; - } - }; - } - - private WritablePropertyValueModel<Boolean> buildUpdatableHolder() { - return new PropertyAspectAdapter<T, Boolean>(getSubjectHolder(), JoinColumnStateObject.UPDATABLE_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getUpdatable(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setUpdatable(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - 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.JoinColumnDialogPane_updatableWithDefault, - defaultStringValue - ); - } - } - - return JptUiMappingsMessages.JoinColumnDialogPane_updatable; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - super.initializeLayout(container); - - // Insertable tri-state check box - buildTriStateCheckBoxWithDefault( - buildSubPane(container, 4), - JptUiMappingsMessages.JoinColumnDialogPane_insertable, - buildInsertableHolder(), - buildInsertableStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_INSERTABLE - ); - - // Updatable tri-state check box - buildTriStateCheckBoxWithDefault( - container, - JptUiMappingsMessages.JoinColumnDialogPane_updatable, - buildUpdatableHolder(), - buildUpdatableStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_UPDATABLE - ); - - // Unique tri-state check box - buildTriStateCheckBoxWithDefault( - container, - JptUiMappingsMessages.ColumnComposite_unique, - buildUniqueHolder(), - buildUniqueStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_UNIQUE - ); - - // Nullable tri-state check box - buildTriStateCheckBoxWithDefault( - container, - JptUiMappingsMessages.ColumnComposite_nullable, - buildNullableHolder(), - buildNullableStringHolder(), - JpaHelpContextIds.MAPPING_COLUMN_NULLABLE - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected boolean isTableEditable() { - 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/JoinColumnInAssociationOverrideDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java deleted file mode 100644 index c1ec3e43e6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used to either create or edit a joing column that is located - * on an association override. - * - * @see JoinColumn - * @see AssociationOverride - * @see JoinColumnInAssociationOverrideStateObject - * @see JoinColumnDialogPane - * - * @version 2.0 - * @since 2.0 - */ -public class JoinColumnInAssociationOverrideDialog extends JoinColumnDialog<JoinColumnInAssociationOverrideStateObject> { - - /** - * Creates a new <code>JoinColumnInAssociationOverrideDialog</code>. - * - * @param parent The parent shell - * @param associationOverride The owner of the join column to create - * @param joinColumn The join column to edit or <code>null</code> if this is - * used to create a new one - */ - public JoinColumnInAssociationOverrideDialog(Shell parent, - AssociationOverride associationOverride, - JoinColumn joinColumn) { - - super(parent, associationOverride, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - protected JoinColumnInAssociationOverrideStateObject buildStateObject() { - return new JoinColumnInAssociationOverrideStateObject( - getOwner(), - getJoinColumn() - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected AssociationOverride getOwner() { - return (AssociationOverride) super.getOwner(); - } -}
\ 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 deleted file mode 100644 index 82e86c2bed..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideStateObject.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -/** - * @version 2.0 - * @since 2.0 - */ -public class JoinColumnInAssociationOverrideStateObject extends JoinColumnStateObject -{ - /** - * Creates a new <code>JoinColumnInAssociationOverrideStateObject</code>. - * - * @param associationOverride The owner of the join column to create - * @param joinColumn The join column to edit or <code>null</code> if this is - * used to create a new one - */ - public JoinColumnInAssociationOverrideStateObject(AssociationOverride associationOverride, - JoinColumn joinColumn) { - super(associationOverride, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - public String getDefaultTable() { - - if (getJoinColumn() != null) { - return getJoinColumn().getDefaultTable(); - } - - return typeMapping().getTableName(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getNameTable() { - return typeMapping().getPrimaryDbTable(); - } - - /* - * (non-Javadoc) - */ - @Override - public AssociationOverride getOwner() { - return (AssociationOverride) super.getOwner(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getReferencedNameTable() { - - AssociationOverride associationOverride = getOwner(); - RelationshipMapping relationshipMapping = associationOverride.getOwner().getRelationshipMapping(associationOverride.getName()); - - if (relationshipMapping == null){ - return null; - } - - Entity targetEntity = relationshipMapping.getResolvedTargetEntity(); - - if (targetEntity != null) { - return targetEntity.getPrimaryDbTable(); - } - - return null; - } - - /* - * (non-Javadoc) - */ - @Override - public Schema getSchema() { - return typeMapping().getDbSchema(); - } - - /** - * Returns the mapping where the join column is located. - * - * @return The owner of the join column to create or to edit - */ - public TypeMapping typeMapping() { - return getOwner().getOwner().getTypeMapping(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index d514c6ecc5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableDialog.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used to either create or edit a joing column that is located - * on a join table. - * - * @see JoinColumn - * @see JoinTable - * @see JoinColumnInJoinTableStateObject - * @see BaseJoinColumnDialogPane - * - * @version 2.0 - * @since 1.0 - */ -public class JoinColumnInJoinTableDialog extends BaseJoinColumnDialog<JoinColumnInJoinTableStateObject> { - - /** - * Creates a new <code>JoinColumnInJoinTableDialog</code>. - * - * @param parent The parent shell - * @param joinTable The parent of the join column to edit or to create - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public JoinColumnInJoinTableDialog(Shell parent, - JoinTable joinTable, - JoinColumn joinColumn) { - - super(parent, joinTable, joinColumn); - } - - /* - * non-Javadoc) - */ - @Override - protected AbstractDialogPane<JoinColumnInJoinTableStateObject> buildLayout(Composite container) { - return new JoinColumnDialogPane<JoinColumnInJoinTableStateObject>( - subjectHolder(), - container - ) { - @Override - protected boolean isTableEditable() { - return false; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected JoinColumnInJoinTableStateObject buildStateObject() { - return new JoinColumnInJoinTableStateObject( - getOwner(), - getJoinColumn() - ); - } - - /* - * (non-Javadoc) - */ - @Override - public JoinColumn getJoinColumn() { - return (JoinColumn) super.getJoinColumn(); - } - - /* - * (non-Javadoc) - */ - @Override - protected JoinTable getOwner() { - return (JoinTable) super.getOwner(); - } -}
\ 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 deleted file mode 100644 index bcf5eda735..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInJoinTableStateObject.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; - -/** - * The state object used to create or edit a primary key join column on a - * joint table. - * - * @see JoinColumn - * @see JoinTable - * @see InverseJoinColumnDialog - * @see InverseJoinColumnDialogPane - * @see JoinColumnInJoinTableDialog - * - * @version 2.0 - * @since 2.0 - */ -public class JoinColumnInJoinTableStateObject extends JoinColumnStateObject -{ - /** - * Creates a new <code>JoinColumnInJoinTableStateObject</code>. - * - * @param joinTable The owner of the join column to create or to edit - * @param joinColumn The join column to edit - */ - public JoinColumnInJoinTableStateObject(JoinTable joinTable, - JoinColumn joinColumn) { - super(joinTable, joinColumn); - } - - @Override - public String getDefaultTable() { - return null; - } - - @Override - public Table getNameTable() { - return getOwner().getDbTable(); - } - - @Override - public JoinTable getOwner() { - return (JoinTable) super.getOwner(); - } - - @Override - public Table getReferencedNameTable() { - return relationshipMapping().getTypeMapping().getPrimaryDbTable(); - } - - @Override - protected Schema getSchema() { - return null; - } - - @Override - protected String initialTable() { - return getOwner().getName(); - } - - @Override - protected boolean isTableEditable() { - return false; - } - - /** - * Returns the mapping owning the join table. - * - * @return The parent of the join table - */ - public RelationshipMapping relationshipMapping() { - return getOwner().getParent(); - } - - @Override - public ListIterator<String> tables() { - return new SingleElementListIterator<String>(initialTable()); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 8784d8f36c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingDialog.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used to either create or edit a joing column that is located - * on a relational mapping. - * - * @see JoinColumn - * @see RelationshipMapping - * @see JoinColumnInRelationshipMappingStateObject - * @see JoinColumnDialogPane - * - * @version 2.0 - * @since 2.0 - */ -public class JoinColumnInRelationshipMappingDialog extends JoinColumnDialog<JoinColumnInRelationshipMappingStateObject> { - - /** - * Creates a new <code>AbstractJoinColumnDialog</code>. - * - * @param parent The parent shell - * @param relationshipMapping The owner of the join column to edit or to - * create - * @param joinColumn The join column to edit or <code>null</code> if this is - * used to create a new one - */ - JoinColumnInRelationshipMappingDialog(Shell parent, - RelationshipMapping relationshipMapping, - JoinColumn joinColumn) { - - super(parent, relationshipMapping, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - protected JoinColumnInRelationshipMappingStateObject buildStateObject() { - return new JoinColumnInRelationshipMappingStateObject( - getOwner(), - getJoinColumn() - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected RelationshipMapping getOwner() { - return (RelationshipMapping) super.getOwner(); - } -}
\ 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 deleted file mode 100644 index fe205a4026..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInRelationshipMappingStateObject.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; - -/** - * The state object used to create or edit a primary key join column on a - * relationship mapping. - * - * @see JoinColumn - * @see RelationshipMapping - * @see JoinColumnInRelationshipMappingDialog - * - * @version 2.0 - * @since 2.0 - */ -public class JoinColumnInRelationshipMappingStateObject extends JoinColumnStateObject -{ - /** - * Creates a new <code>JoinColumnInRelationshipMappingStateObject</code>. - * - * @param relationshipMapping The owner of the join column to create - * @param joinColumn The join column to edit or <code>null</code> if this is - * used to create a new one - */ - public JoinColumnInRelationshipMappingStateObject(RelationshipMapping relationshipMapping, - JoinColumn joinColumn) { - super(relationshipMapping, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - public String getDefaultTable() { - - JoinColumn joinColumn = getJoinColumn(); - - if (joinColumn != null) { - return joinColumn.getDefaultTable(); - } - - return getOwner().getTypeMapping().getTableName(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getNameTable() { - Schema schema = getSchema(); - - if (schema == null) { - return null; - } - - String table = getTable(); - - if (table == null) { - table = getDefaultTable(); - } - - return schema.tableNamed(table); - } - - /* - * (non-Javadoc) - */ - @Override - public RelationshipMapping getOwner() { - return (RelationshipMapping) super.getOwner(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getReferencedNameTable() { - Entity targetEntity = getOwner().getResolvedTargetEntity(); - - if (targetEntity != null) { - return targetEntity.getPrimaryDbTable(); - } - - return null; - } - - /* - * (non-Javadoc) - */ - @Override - public Schema getSchema() { - return getOwner().getTypeMapping().getDbSchema(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 137f350259..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; - -/** - * The state object used to edit a <code>JoinColumn</code>. - * - * @see JoinColumn - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class JoinColumnStateObject extends BaseJoinColumnStateObject -{ - private Boolean insertable; - private Boolean nullable; - private Boolean unique; - private Boolean updatable; - - public static final String INSERTABLE_PROPERTY = "insertable"; - public static final String NULLABLE_PROPERTY = "nullable"; - public static final String UNIQUE_PROPERTY = "unique"; - public static final String UPDATABLE_PROPERTY = "updatable"; - - /** - * Creates a new <code>JoinColumnStateObject</code>. - * - * @param owner The owner of the join column to create or where it is located - * @param joinColumn The join column to edit - */ - public JoinColumnStateObject(Object owner, JoinColumn joinColumn) { - super(owner, joinColumn); - } - - public Boolean getDefaultInsertable() { - - JoinColumn joinColumn = getJoinColumn(); - - if (joinColumn != null) { - return joinColumn.getDefaultInsertable(); - } - - return BaseColumn.DEFAULT_INSERTABLE; - } - - public Boolean getDefaultNullable() { - - JoinColumn joinColumn = getJoinColumn(); - - if (joinColumn != null) { - return joinColumn.getDefaultNullable(); - } - - return BaseColumn.DEFAULT_NULLABLE; - } - - public Boolean getDefaultUnique() { - - JoinColumn joinColumn = getJoinColumn(); - - if (joinColumn != null) { - return joinColumn.getDefaultUnique(); - } - - return BaseColumn.DEFAULT_UNIQUE; - } - - public Boolean getDefaultUpdatable() { - - JoinColumn joinColumn = getJoinColumn(); - - if (joinColumn != null) { - return joinColumn.getDefaultUpdatable(); - } - - return BaseColumn.DEFAULT_UPDATABLE; - } - - public Boolean getInsertable() { - return insertable; - } - - @Override - public JoinColumn getJoinColumn() { - return (JoinColumn) super.getJoinColumn(); - } - - public Boolean getNullable() { - return nullable; - } - - protected abstract Schema getSchema(); - - public Boolean getUnique() { - return unique; - } - - public Boolean getUpdatable() { - return updatable; - } - - @Override - protected void initialize(Object owner, BaseJoinColumn baseJoinColumn) { - - super.initialize(owner, baseJoinColumn); - - if (baseJoinColumn != null) { - JoinColumn joinColumn = (JoinColumn) baseJoinColumn; - - insertable = joinColumn.getSpecifiedInsertable(); - nullable = joinColumn.getSpecifiedNullable(); - unique = joinColumn.getSpecifiedUnique(); - updatable = joinColumn.getSpecifiedUpdatable(); - } - } - - @Override - protected String initialTable() { - JoinColumn joinColumn = getJoinColumn(); - - if (joinColumn == null) { - return null; - } - - return joinColumn.getSpecifiedTable(); - } - - protected boolean isTableEditable() { - return true; - } - - public void setInsertable(Boolean insertable) { - Boolean oldInsertable = this.insertable; - this.insertable = insertable; - firePropertyChanged(INSERTABLE_PROPERTY, oldInsertable, insertable); - } - - public void setNullable(Boolean nullable) { - Boolean oldNullable = this.nullable; - this.nullable = nullable; - firePropertyChanged(NULLABLE_PROPERTY, oldNullable, nullable); - } - - public void setUnique(Boolean unique) { - Boolean oldUnique = this.unique; - this.unique = unique; - firePropertyChanged(UNIQUE_PROPERTY, oldUnique, unique); - } - - public void setUpdatable(Boolean updatable) { - Boolean oldUpdatable = this.updatable; - this.updatable = updatable; - firePropertyChanged(UPDATABLE_PROPERTY, oldUpdatable, updatable); - } - - /* - * (non-Javadoc) - */ - @Override - public ListIterator<String> tables() { - Schema schema = getSchema(); - - if (schema == null) { - return EmptyListIterator.instance(); - } - - List<String> names = CollectionTools.list(schema.tableNames()); - Collections.sort(names); - return names.listIterator(); - } - - /* - * (non-Javadoc) - */ - @Override - public void updateJoinColumn(BaseJoinColumn abstractJoinColumn) { - - super.updateJoinColumn(abstractJoinColumn); - - JoinColumn joinColumn = (JoinColumn) abstractJoinColumn; - - // Table - if (isTableEditable()) { - String table = getTable(); - - if (valuesAreDifferent(table, joinColumn.getSpecifiedTable())) { - joinColumn.setSpecifiedTable(table); - } - } - - // Insertable - if (joinColumn.getSpecifiedInsertable() != insertable){ - joinColumn.setSpecifiedInsertable(insertable); - } - - // Updatable - if (joinColumn.getSpecifiedUpdatable() != updatable){ - joinColumn.setSpecifiedUpdatable(updatable); - } - - // Unique - if (joinColumn.getSpecifiedUnique() != unique){ - joinColumn.setSpecifiedUnique(unique); - } - - // Nullable - if (joinColumn.getSpecifiedNullable() != nullable){ - joinColumn.setSpecifiedNullable(nullable); - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index 5d0d973d66..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java +++ /dev/null @@ -1,291 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.JpaNode; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Composite; - -/** - * 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 JpaNode> extends AbstractFormPane<T> -{ - /** - * The editor used to perform the common behaviors defined in the list pane. - */ - private IJoinColumnsEditor<T> joinColumnsEditor; - - /** - * 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 - * @param joinColumnsEditor The editor used to perform the common behaviors - * defined in the list pane - */ - public JoinColumnsComposite(AbstractFormPane<? extends T> parentPane, - Composite parent, - IJoinColumnsEditor<T> joinColumnsEditor) { - - super(parentPane, parent); - this.joinColumnsEditor = joinColumnsEditor; - initializeLayout2(); - } - - /** - * 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 - * @param joinColumnsEditor The editor used to perform the common behaviors - * defined in the list pane - */ - public JoinColumnsComposite(AbstractFormPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent, - IJoinColumnsEditor<T> joinColumnsEditor, - boolean automaticallyAlignWidgets) { - - super(parentPane, subjectHolder, parent, automaticallyAlignWidgets); - this.joinColumnsEditor = joinColumnsEditor; - initializeLayout2(); - } - - /** - * 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, - WidgetFactory widgetFactory, - IJoinColumnsEditor<T> joinColumnsEditor) { - - super(subjectHolder, parent, widgetFactory); - this.joinColumnsEditor = joinColumnsEditor; - initializeLayout2(); - } - - private WritablePropertyValueModel<JoinColumn> buildJoinColumnHolder() { - return new SimplePropertyValueModel<JoinColumn>(); - } - - private String buildJoinColumnLabel(JoinColumn joinColumn) { - - if (joinColumn.isVirtual()) { - return NLS.bind( - JptUiMappingsMessages.JoinTableComposite_mappingBetweenTwoParamsDefault, - joinColumn.getName(), - joinColumn.getReferencedColumnName() - ); - } - 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() - ); - } - - 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()); - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiMappingsMessages.JoinColumnComposite_edit; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - JoinColumn joinColumn = (JoinColumn) listSelectionModel.selectedValue(); - joinColumnsEditor.editJoinColumn(subject(), joinColumn); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - joinColumnsEditor.removeJoinColumns(subject(), listSelectionModel.selectedIndices()); - } - }; - } - - private ListValueModel<JoinColumn> buildJoinColumnsListModel() { - return new ItemPropertyListValueModelAdapter<JoinColumn>(buildJoinColumnsListHolder(), - NamedColumn.SPECIFIED_NAME_PROPERTY, - NamedColumn.DEFAULT_NAME_PROPERTY, - BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, - BaseJoinColumn.DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY); - } - - private ListValueModel<JoinColumn> buildJoinColumnsListHolder() { - java.util.List<ListValueModel<JoinColumn>> list = new ArrayList<ListValueModel<JoinColumn>>(); - list.add(buildSpecifiedJoinColumnsListHolder()); - list.add(buildDefaultJoinColumnListHolder()); - return new CompositeListValueModel<ListValueModel<JoinColumn>, JoinColumn>(list); - } - - private ListValueModel<JoinColumn> buildSpecifiedJoinColumnsListHolder() { - return new ListAspectAdapter<T, JoinColumn>(getSubjectHolder(), joinColumnsEditor.specifiedListPropertyName()) { - @Override - protected ListIterator<JoinColumn> listIterator_() { - return joinColumnsEditor.specifiedJoinColumns(subject); - } - - @Override - protected int size_() { - return joinColumnsEditor.specifiedJoinColumnsSize(subject); - } - }; - } - - - private ListValueModel<JoinColumn> buildDefaultJoinColumnListHolder() { - return new PropertyListValueModelAdapter<JoinColumn>(buildDefaultJoinColumnHolder()); - - } - - private PropertyValueModel<JoinColumn> buildDefaultJoinColumnHolder() { - return new PropertyAspectAdapter<T, JoinColumn>(getSubjectHolder(), joinColumnsEditor.defaultPropertyName()) { - @Override - protected JoinColumn buildValue_() { - return joinColumnsEditor.defaultJoinColumn(subject); - } - }; - } - - - private ILabelProvider buildJoinColumnsListLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - JoinColumn joinColumn = (JoinColumn) element; - - return buildJoinColumnLabel(joinColumn); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - } - - private void initializeLayout2() { - - // Join Columns list pane - AddRemoveListPane<T> listPane = new AddRemoveListPane<T>( - this, - getControl(), - buildJoinColumnsAdapter(), - buildJoinColumnsListModel(), - buildJoinColumnHolder(), - buildJoinColumnsListLabelProvider(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS - ); - - // Remove the list pane from this pane's enablement control because its - // enablement is managed by a PaneEnabler registered with this pane - removeFromEnablementControl(listPane.getMainControl()); - removeFromEnablementControl(listPane); - } - - /** - * The editor is used to complete the behavior of this pane. - */ - public static interface IJoinColumnsEditor<T> { - - void addJoinColumn(T subject); - void editJoinColumn(T subject, JoinColumn joinColumn); - boolean hasSpecifiedJoinColumns(T subject); - ListIterator<JoinColumn> specifiedJoinColumns(T subject); - int specifiedJoinColumnsSize(T subject); - JoinColumn defaultJoinColumn(T subject); - String specifiedListPropertyName(); - String defaultPropertyName(); - 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 deleted file mode 100644 index 7e86c88eb0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java +++ /dev/null @@ -1,578 +0,0 @@ -/******************************************************************************* - * 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.Collection; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -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.util.PaneEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.PostExecution; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.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.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | --------------------------------------------------------------- | - * | Name: | |v| | - * | --------------------------------------------------------------- | - * | | - * | - Join Columns ---------------------------------------------------------- | - * | | | | - * | | x Override Default | | - * | | | | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | JoinColumnsComposite | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * | | - * | - Inverse Join Columns -------------------------------------------------- | - * | | | | - * | | x Override Default | | - * | | | | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | JoinColumnsComposite | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see JoinTable - * @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<JoinTable> -{ - private WritablePropertyValueModel<Boolean> inverseJoinColumnsPaneEnablerHolder; - private WritablePropertyValueModel<Boolean> joinColumnsPaneEnablerHolder; - private Button overrideDefaultInverseJoinColumnsCheckBox; - private Button overrideDefaultJoinColumnsCheckBox; - - /** - * 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 JoinTable> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent, false); - } - - /** - * 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 JoinTable> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private void addInverseJoinColumn(JoinTable joinTable) { - - InverseJoinColumnInJoinTableDialog dialog = - new InverseJoinColumnInJoinTableDialog(shell(), joinTable, null); - - dialog.openDialog(buildAddInverseJoinColumnPostExecution()); - } - - private void addInverseJoinColumnFromDialog(InverseJoinColumnInJoinTableStateObject stateObject) { - - JoinTable subject = subject(); - int index = subject.specifiedInverseJoinColumnsSize(); - - JoinColumn joinColumn = subject.addSpecifiedInverseJoinColumn(index); - stateObject.updateJoinColumn(joinColumn); - } - - private void addJoinColumn(JoinTable joinTable) { - - JoinColumnInJoinTableDialog dialog = - new JoinColumnInJoinTableDialog(shell(), joinTable, null); - - dialog.openDialog(buildAddJoinColumnPostExecution()); - } - - private void addJoinColumnFromDialog(JoinColumnInJoinTableStateObject stateObject) { - - JoinTable subject = subject(); - int index = subject.specifiedJoinColumnsSize(); - - JoinColumn joinColumn = subject().addSpecifiedJoinColumn(index); - stateObject.updateJoinColumn(joinColumn); - } - - private PostExecution<InverseJoinColumnInJoinTableDialog> buildAddInverseJoinColumnPostExecution() { - return new PostExecution<InverseJoinColumnInJoinTableDialog>() { - public void execute(InverseJoinColumnInJoinTableDialog dialog) { - if (dialog.wasConfirmed()) { - addInverseJoinColumnFromDialog(dialog.subject()); - } - } - }; - } - - private PostExecution<JoinColumnInJoinTableDialog> buildAddJoinColumnPostExecution() { - return new PostExecution<JoinColumnInJoinTableDialog>() { - public void execute(JoinColumnInJoinTableDialog dialog) { - if (dialog.wasConfirmed()) { - addJoinColumnFromDialog(dialog.subject()); - } - } - }; - } - - private PostExecution<InverseJoinColumnInJoinTableDialog> buildEditInverseJoinColumnPostExecution() { - return new PostExecution<InverseJoinColumnInJoinTableDialog>() { - public void execute(InverseJoinColumnInJoinTableDialog dialog) { - if (dialog.wasConfirmed()) { - editInverseJoinColumn(dialog.subject()); - } - } - }; - } - - private PostExecution<JoinColumnInJoinTableDialog> buildEditJoinColumnPostExecution() { - return new PostExecution<JoinColumnInJoinTableDialog>() { - public void execute(JoinColumnInJoinTableDialog dialog) { - if (dialog.wasConfirmed()) { - editJoinColumn(dialog.subject()); - } - } - }; - } - - private InverseJoinColumnsProvider buildInverseJoinColumnsEditor() { - return new InverseJoinColumnsProvider(); - } - - private JoinColumnsProvider buildJoinColumnsEditor() { - return new JoinColumnsProvider(); - } - - private SimplePropertyValueModel<Boolean> buildJoinColumnsPaneEnablerHolder() { - return new SimplePropertyValueModel<Boolean>(Boolean.FALSE); - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { - return new SimplePropertyValueModel<Boolean>(); - } - - private SelectionListener buildOverrideDefaultInverseSelectionListener() { - return new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInverseJoinColumns(); - } - }; - } - - private SelectionListener buildOverrideDefaultSelectionListener() { - return new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateJoinColumns(); - } - }; - } - - private Composite buildPane(Composite container, int groupBoxMargin) { - return buildSubPane(container, 0, groupBoxMargin, 10, groupBoxMargin); - } - - private TableCombo<JoinTable> buildTableCombo(Composite container) { - - return new TableCombo<JoinTable>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Table.DEFAULT_NAME_PROPERTY); - propertyNames.add(Table.SPECIFIED_NAME_PROPERTY); - propertyNames.add(Table.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(Table.SPECIFIED_SCHEMA_PROPERTY); - propertyNames.add(Table.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(Table.SPECIFIED_CATALOG_PROPERTY); - } - - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - if (propertyName == Table.DEFAULT_SCHEMA_PROPERTY - || propertyName == Table.SPECIFIED_SCHEMA_PROPERTY - || propertyName == Table.DEFAULT_CATALOG_PROPERTY - || propertyName == Table.SPECIFIED_CATALOG_PROPERTY ) { - repopulate(); - } - } - - @Override - protected String defaultValue() { - return subject().getDefaultName(); - } - - @Override - protected String schemaName() { - return subject().getSchema(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedName(value); - } - - @Override - protected org.eclipse.jpt.db.Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedName(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - updateJoinColumnPanesEnablement(true); - } - - private void editInverseJoinColumn(InverseJoinColumnInJoinTableStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - - private void editInverseJoinColumn(JoinColumn joinColumn) { - - InverseJoinColumnInJoinTableDialog dialog = - new InverseJoinColumnInJoinTableDialog(shell(), subject(), joinColumn); - - dialog.openDialog(buildEditInverseJoinColumnPostExecution()); - } - - private void editJoinColumn(JoinColumn joinColumn) { - - JoinColumnInJoinTableDialog dialog = - new JoinColumnInJoinTableDialog(shell(), subject(), joinColumn); - - dialog.openDialog(buildEditJoinColumnPostExecution()); - } - - private void editJoinColumn(JoinColumnInJoinTableStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - super.enableWidgets(enabled); - updateJoinColumnPanesEnablement(enabled); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - - joinColumnsPaneEnablerHolder = buildJoinColumnsPaneEnablerHolder(); - inverseJoinColumnsPaneEnablerHolder = buildJoinColumnsPaneEnablerHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - // Name widgets - TableCombo<JoinTable> tableCombo = buildTableCombo(container); - - buildLabeledComposite( - buildPane(container, groupBoxMargin), - JptUiMappingsMessages.JoinTableComposite_name, - tableCombo.getControl(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_NAME - ); - - // Join Columns group pane - Group joinColumnGroupPane = buildTitledPane( - container, - JptUiMappingsMessages.JoinTableComposite_joinColumn - ); - - // Override Default Join Columns check box - overrideDefaultJoinColumnsCheckBox = buildCheckBox( - buildSubPane(joinColumnGroupPane, 8), - JptUiMappingsMessages.JoinTableComposite_overrideDefaultJoinColumns, - buildOverrideDefaultHolder() - ); - - overrideDefaultJoinColumnsCheckBox.addSelectionListener( - buildOverrideDefaultSelectionListener() - ); - - JoinColumnsComposite<JoinTable> joinColumnsComposite = new JoinColumnsComposite<JoinTable>( - this, - joinColumnGroupPane, - buildJoinColumnsEditor() - ); - - installJoinColumnsPaneEnabler(joinColumnsComposite); - removeFromEnablementControl(joinColumnsComposite.getControl()); - - // Inverse Join Columns group pane - Group inverseJoinColumnGroupPane = buildTitledPane( - container, - JptUiMappingsMessages.JoinTableComposite_inverseJoinColumn - ); - - // Override Default Inverse Join Columns check box - overrideDefaultInverseJoinColumnsCheckBox = buildCheckBox( - buildSubPane(inverseJoinColumnGroupPane, 8), - JptUiMappingsMessages.JoinTableComposite_overrideDefaultInverseJoinColumns, - buildOverrideDefaultHolder() - ); - - overrideDefaultInverseJoinColumnsCheckBox.addSelectionListener( - buildOverrideDefaultInverseSelectionListener() - ); - - JoinColumnsComposite<JoinTable> inverseJoinColumnsComposite = new JoinColumnsComposite<JoinTable>( - this, - inverseJoinColumnGroupPane, - buildInverseJoinColumnsEditor() - ); - - installInverseJoinColumnsPaneEnabler(inverseJoinColumnsComposite); - removeFromEnablementControl(inverseJoinColumnsComposite.getControl()); - } - - private void installInverseJoinColumnsPaneEnabler(JoinColumnsComposite<JoinTable> pane) { - new PaneEnabler(inverseJoinColumnsPaneEnablerHolder, pane); - } - - private void installJoinColumnsPaneEnabler(JoinColumnsComposite<JoinTable> pane) { - new PaneEnabler(joinColumnsPaneEnablerHolder, pane); - } - - private void updateInverseJoinColumns() { - - if (isPopulating()) { - return; - } - - JoinTable joinTable = subject(); - boolean selected = overrideDefaultInverseJoinColumnsCheckBox.getSelection(); - setPopulating(true); - - try { - // Add a join column by creating a specified one using the default - // one if it exists - if (selected) { - - JoinColumn defaultJoinColumn = joinTable.getDefaultInverseJoinColumn(); //TODO null check, override default button disabled - - if (defaultJoinColumn != null) { - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - JoinColumn joinColumn = joinTable.addSpecifiedInverseJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - else { - for (int index = joinTable.specifiedInverseJoinColumnsSize(); --index >= 0; ) { - joinTable.removeSpecifiedInverseJoinColumn(index); - } - } - - inverseJoinColumnsPaneEnablerHolder.setValue(selected); - } - finally { - setPopulating(false); - } - } - - private void updateJoinColumnPanesEnablement(boolean globalEnablement) { - - JoinTable subject = subject(); - boolean enabled = globalEnablement && (subject != null) && subject.containsSpecifiedJoinColumns(); - boolean inverseEnabled = globalEnablement && (subject != null) && subject.containsSpecifiedInverseJoinColumns(); - - overrideDefaultJoinColumnsCheckBox .setSelection(enabled); - overrideDefaultInverseJoinColumnsCheckBox.setSelection(inverseEnabled); - - joinColumnsPaneEnablerHolder .setValue(enabled); - inverseJoinColumnsPaneEnablerHolder.setValue(inverseEnabled); - } - - private void updateJoinColumns() { - - if (isPopulating()) { - return; - } - - JoinTable joinTable = subject(); - boolean selected = overrideDefaultJoinColumnsCheckBox.getSelection(); - setPopulating(true); - - try { - // Add a join column by creating a specified one using the default - // one if it exists - if (selected) { - - JoinColumn defaultJoinColumn = joinTable.getDefaultJoinColumn(); //TODO null check, override default button disabled - - if (defaultJoinColumn != null) { - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - JoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - else { - for (int index = joinTable.specifiedJoinColumnsSize(); --index >= 0; ) { - joinTable.removeSpecifiedJoinColumn(index); - } - } - - joinColumnsPaneEnablerHolder.setValue(selected); - } - finally { - setPopulating(false); - } - } - - private class InverseJoinColumnsProvider implements IJoinColumnsEditor<JoinTable> { - - public void addJoinColumn(JoinTable subject) { - JoinTableComposite.this.addInverseJoinColumn(subject); - } - - public JoinColumn defaultJoinColumn(JoinTable subject) { - return subject.getDefaultInverseJoinColumn(); - } - - public String defaultPropertyName() { - return JoinTable.DEFAULT_INVERSE_JOIN_COLUMN; - } - - public void editJoinColumn(JoinTable subject, JoinColumn joinColumn) { - JoinTableComposite.this.editInverseJoinColumn(joinColumn); - } - - public boolean hasSpecifiedJoinColumns(JoinTable subject) { - return subject.containsSpecifiedInverseJoinColumns(); - } - - public void removeJoinColumns(JoinTable subject, int[] selectedIndices) { - for (int index = selectedIndices.length; --index >= 0; ) { - subject.removeSpecifiedInverseJoinColumn(selectedIndices[index]); - } - } - - public ListIterator<JoinColumn> specifiedJoinColumns(JoinTable subject) { - return subject.specifiedInverseJoinColumns(); - } - - public int specifiedJoinColumnsSize(JoinTable subject) { - return subject.specifiedInverseJoinColumnsSize(); - } - - public String specifiedListPropertyName() { - return JoinTable.SPECIFIED_INVERSE_JOIN_COLUMNS_LIST; - } - } - - private class JoinColumnsProvider implements IJoinColumnsEditor<JoinTable> { - - public void addJoinColumn(JoinTable subject) { - JoinTableComposite.this.addJoinColumn(subject); - } - - public JoinColumn defaultJoinColumn(JoinTable subject) { - return subject.getDefaultJoinColumn(); - } - - public String defaultPropertyName() { - return JoinTable.DEFAULT_JOIN_COLUMN; - } - - public void editJoinColumn(JoinTable subject, JoinColumn joinColumn) { - JoinTableComposite.this.editJoinColumn(joinColumn); - } - - public boolean hasSpecifiedJoinColumns(JoinTable subject) { - return subject.containsSpecifiedJoinColumns(); - } - - public void removeJoinColumns(JoinTable subject, int[] selectedIndices) { - for (int index = selectedIndices.length; --index >= 0; ) { - subject.removeSpecifiedJoinColumn(selectedIndices[index]); - } - } - - public ListIterator<JoinColumn> specifiedJoinColumns(JoinTable subject) { - return subject.specifiedJoinColumns(); - } - - public int specifiedJoinColumnsSize(JoinTable subject) { - return subject.specifiedJoinColumnsSize(); - } - - public String specifiedListPropertyName() { - return JoinTable.SPECIFIED_JOIN_COLUMNS_LIST; - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index 49c04b2735..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/LobComposite.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * This composite simply shows the Lob check box. - * - * @see BasicMapping - * - * @version 2.0 - * @since 1.0 - */ -public class LobComposite extends AbstractFormPane<BasicMapping> -{ - /** - * Creates a new <code>LobComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public LobComposite(AbstractFormPane<? extends BasicMapping> 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 BasicMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyAspectAdapter<BasicMapping, Boolean> buildLobHolder() { - - return new PropertyAspectAdapter<BasicMapping, Boolean>(getSubjectHolder(), BasicMapping.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(), - JpaHelpContextIds.MAPPING_LOB - ); - } -} 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 deleted file mode 100644 index 9f4736c864..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToManyMappingComposite.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | TargetEntityComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | FetchTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | CascadeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrderingComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - Join Table ------------------------------------------------------------ | - * | | | | - * | | JoinTableComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see ManyToManyMapping - * @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<ManyToManyMapping> - implements JpaComposite<ManyToManyMapping> -{ - /** - * 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 ManyToManyMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<Cascade> buildCascadeHolder() { - return new TransformationPropertyValueModel<ManyToManyMapping, Cascade>(getSubjectHolder()) { - @Override - protected Cascade transform_(ManyToManyMapping value) { - return value.getCascade(); - } - }; - } - - private PropertyValueModel<JoinTable> buildJointTableHolder() { - return new TransformationPropertyValueModel<ManyToManyMapping, JoinTable>(getSubjectHolder()) { - @Override - protected JoinTable transform_(ManyToManyMapping 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(), buildSubPane(container, 5)); - - // Ordering widgets - new OrderingComposite(this, container); - } - - private void initializeJoinTablePane(Composite container) { - - container = buildCollapsableSection( - 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/ManyToOneMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneMappingComposite.java deleted file mode 100644 index ab8ccf5822..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ManyToOneMappingComposite.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | TargetEntityComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | FetchTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OptionalComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | CascadeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | JoinColumnComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see ManyToOneMapping - * @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<ManyToOneMapping> - implements JpaComposite<ManyToOneMapping> -{ - /** - * 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 ManyToOneMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<Cascade> buildCascadeHolder() { - return new TransformationPropertyValueModel<ManyToOneMapping, Cascade>(getSubjectHolder()) { - @Override - protected Cascade transform_(ManyToOneMapping 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(); - Composite subPane = buildPane(container, groupBoxMargin); - - // Target Entity widgets - new TargetEntityComposite(this, subPane); - - // Fetch Type widgets - new FetchTypeComposite(this, subPane); - - // Optional check box - new OptionalComposite(this, buildSubPane(subPane, 4)); - - // 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/MapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MapAsComposite.java deleted file mode 100644 index 941b891729..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MapAsComposite.java +++ /dev/null @@ -1,630 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.text.Collator; -import java.util.Comparator; -import java.util.Iterator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.resource.JFaceColors; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.PostExecution; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog; - -/** - * This map as composite simply shows a styled text where the name of the - * mapping and its type are displayed. The mapping type can be clicked on to - * invoke a dialog in order to change the type. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | Attribute 'name' is mapped as one to one. | - * | ¯¯¯¯¯¯¯¯¯¯ | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class MapAsComposite<T extends Model> extends AbstractPane<T> { - - private boolean dragEvent; - private boolean enabled; - private Cursor handCursor; - private MappingChangeHandler mappingChangeHandler; - private int mappingTypeLength; - private int mappingTypeStart; - private boolean mouseDown; - private int nameLength; - private int nameStart; - private StyledText styledText; - - /** - * The constant ID used to retrieve the dialog settings. - */ - private static final String DIALOG_SETTINGS = "org.eclipse.jpt.ui.dialogs.MapAsDialog"; - - /** - * Creates a new <code>MapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public MapAsComposite(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates the default provider responsible for clearing the mapping type. - * - * @return A provider that acts as a default mapping provider - */ - protected abstract MappingUiProvider<?> buildDefaultProvider(); - - /** - * Creates the handler responsible to give the information required for - * completing the behavior of this pane. - * - * @return A new <code>MappingChangeHandler</code> - */ - protected abstract MappingChangeHandler buildMappingChangeHandler(); - - private MouseListener buildMouseListener() { - return new MouseListener() { - public void mouseDoubleClick(MouseEvent e) { - } - - public void mouseDown(MouseEvent e) { - if (e.button == 1) { - mouseDown = true; - } - } - - public void mouseUp(MouseEvent e) { - mouseDown = false; - StyledText text = (StyledText) e.widget; - int offset = text.getCaretOffset(); - - if (dragEvent) { - dragEvent = false; - - if (isOverLink(offset)) { - text.setCursor(handCursor); - } - } - else if (isOverLink(offset)) { - text.setCursor(handCursor); - openMappingSelectionDialog(); - text.setCursor(null); - } - } - }; - } - - private MouseMoveListener buildMouseMoveListener() { - return new MouseMoveListener() { - public void mouseMove(MouseEvent e) { - StyledText text = (StyledText) e.widget; - - if (mouseDown) { - if (!dragEvent) { - text.setCursor(null); - } - - dragEvent = true; - return; - } - - int offset = -1; - - try { - offset = text.getOffsetAtLocation(new Point(e.x, e.y)); - } - catch (IllegalArgumentException ex) { - } - - if (isOverLink(offset)) { - text.setCursor(handCursor); - } - else { - text.setCursor(null); - } - } - }; - } - - private PostExecution<MappingSelectionDialog> buildPostExecution() { - - return new PostExecution<MappingSelectionDialog>() { - public void execute(MappingSelectionDialog dialog) { - - if (dialog.getReturnCode() == IDialogConstants.OK_ID) { - MappingUiProvider<?> provider = (MappingUiProvider<?>) dialog.getFirstResult(); - morphMapping(provider); - } - } - }; - } - - /** - * Creates the full localized string by formatting the label text returned - * by the <code>MappingChangeHandler</code> with the mapping name and the - * mapping type. - * - * @param name The display string of the mapping being edited - * @param mappingType The localized message describing the mapping type - * @return The localized string describing the mapping - */ - protected String buildText(String name, String mappingType) { - return NLS.bind( - mappingChangeHandler.labelText(), - name, - mappingType - ); - } - - /** - * Removes any style applied to the styled text. - */ - protected void clearStyleRange() { - styledText.setStyleRange(null); - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - updateDescription(); - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - this.enabled = enabled; - super.enableWidgets(enabled); - - if (!styledText.isDisposed()) { - styledText.setEnabled(enabled); - - if (enabled) { - updateLinkRange(); - } - else { - clearStyleRange(); - } - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - - super.initialize(); - - this.enabled = true; - this.mappingChangeHandler = buildMappingChangeHandler(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - handCursor = shell().getDisplay().getSystemCursor(SWT.CURSOR_HAND); - - styledText = new StyledText(container, SWT.WRAP | SWT.READ_ONLY); - styledText.addMouseListener(buildMouseListener()); - styledText.addMouseMoveListener(buildMouseMoveListener()); - styledText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - - /** - * Retreive the <code>MappingUiProvider</code> that provides the UI for the - * current mapping. - * - * @return The <code>MappingUiProvider</code> representing the type of the - * mapping being edited - */ - protected MappingUiProvider<?> initialSelection() { - - for (Iterator<? extends MappingUiProvider<?>> iter = mappingChangeHandler.providers(); iter.hasNext(); ) { - MappingUiProvider<?> provider = iter.next(); - - if (mappingKey() == provider.getMappingKey()) { - return provider; - } - } - - return null; - } - - /** - * Determines whether the given location is within the mapping type range. - * - * @param location The mouse location in character coordinate - * @return <code>true</code> if the mouse is over the mapping type text; - * <code>false</code> otherwise - */ - protected boolean isOverLink(int location) { - - return (location >= mappingTypeStart && - location <= mappingTypeStart + mappingTypeLength); - } - - /** - * Returns the mapping key representing the current mapping object. - * - * @return A non-<code>null</code> unique identifier representing the type - * of the mapping being edited - */ - protected abstract String mappingKey(); - - /** - * Aks the <code>MappingChangeHandler</code> to change the mapping type using - * the given <code>MappingUiProvider</code>. - * - * @param provider The provider used to determine the mapping type used for - * morphing the mapping being edited - */ - protected void morphMapping(MappingUiProvider<?> provider) { - mappingChangeHandler.morphMapping(provider); - } - - /** - * Opens the dialog that shows the registered mapping types in order for the - * user to select a provider in order to change the mapping type of the - * mapping being edited. - */ - protected void openMappingSelectionDialog() { - - MappingSelectionDialog dialog = new MappingSelectionDialog(); - SWTUtil.show(dialog, buildPostExecution()); - } - - /** - * Updates the description by recreating the label. - */ - protected void updateDescription() { - - clearStyleRange(); - updateText(); - - if (enabled) { - updateLinkRange(); - } - } - - /** - * Updates the colors of the text: (1) the name is shown in bold and (2) the - * mapping type is shown in bold and in hyperlink color. - */ - protected void updateLinkRange() { - - Color linkColor = JFaceColors.getHyperlinkText(shell().getDisplay()); - - // Make the name bold - StyleRange styleRange = new StyleRange( - nameStart, nameLength, - null, null, - SWT.BOLD - ); - styledText.setStyleRange(styleRange); - - // Make the mapping type shown as a hyperlink - if (mappingTypeStart > -1) { - styleRange = new StyleRange( - mappingTypeStart, mappingTypeLength, - linkColor, null - ); - - styleRange.underline = true; - styleRange.underlineColor = linkColor; - styleRange.underlineStyle = SWT.UNDERLINE_SINGLE; - styledText.setStyleRange(styleRange); - } - } - - /** - * Updates the styles text's input. - */ - protected void updateText() { - - String name = mappingChangeHandler.name(); - - if (name == null) { - name = JptUiMappingsMessages.NoNameSet; - } - - String mappingType = mappingChangeHandler.mappingType(); - String text = buildText(name, mappingType); - - mappingTypeStart = text.lastIndexOf(mappingType); - mappingTypeLength = mappingType.length(); - - nameStart = text.indexOf(name); - nameLength = name.length(); - - styledText.setText(text); - } - - /** - * This handler is responsible to give the text information and to open the - * mapping dialog if the user clicked on the mapping type. - */ - protected interface MappingChangeHandler { - - /** - * Returns the entire text describing the mapping (entity or mapping) and - * its type. - * - * @return A localized text with two arguments where the first one should - * be replaced by the name and the second be replaced by the mapping type - */ - String labelText(); - - /** - * Returns the displayable text representing the mapping type. - * - * @return A human readable text describing the mapping type - */ - String mappingType(); - - /** - * Morphes the current mapping into a new type by using the given provider. - * - * @param provider The provider that was selected for changing the mapping - */ - void morphMapping(MappingUiProvider<?> provider); - - /** - * Returns the name of the current mapping. - * - * @return The displayable name of the mapping - */ - String name(); - - /** - * Returns the list of providers that are registered with the JPT plugin. - * - * @return The supported types of mapping - */ - Iterator<? extends MappingUiProvider<?>> providers(); - } - - /** - * This dialog shows the list of possible mapping types and lets the user - * the option to filter them using a search field. - */ - protected class MappingSelectionDialog extends FilteredItemsSelectionDialog { - - private MappingUiProvider<?> defaultProvider; - - /** - * Creates a new <code>MappingSelectionDialog</code>. - */ - private MappingSelectionDialog() { - super(MapAsComposite.this.shell(), false); - setMessage(JptUiMessages.MapAsComposite_labelText); - setTitle(JptUiMessages.MapAsComposite_dialogTitle); - setListLabelProvider(buildLabelProvider()); - setDetailsLabelProvider(buildLabelProvider()); - } - - private ILabelProvider buildLabelProvider() { - return new LabelProvider() { - - @Override - public Image getImage(Object element) { - - if (element == null) { - return null; - } - - MappingUiProvider<?> provider = (MappingUiProvider<?>) element; - return provider.getImage(); - } - - @Override - public String getText(Object element) { - - if (element == null) { - return ""; - } - - MappingUiProvider<?> provider = (MappingUiProvider<?>) element; - return provider.getLabel(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Control createExtendedContentArea(Composite parent) { - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected ItemsFilter createFilter() { - return new MappingTypeItemsFilter(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void fillContentProvider(AbstractContentProvider provider, - ItemsFilter itemsFilter, - IProgressMonitor monitor) throws CoreException { - - monitor.beginTask(null, -1); - - try { - // Add the default provider - defaultProvider = buildDefaultProvider(); - - if (defaultProvider != null) { - provider.add(defaultProvider, itemsFilter); - } - - // Add the registered mapping providers to the dialog - for (Iterator<? extends MappingUiProvider<?>> iter = mappingChangeHandler.providers(); iter.hasNext(); ) { - MappingUiProvider<?> mappingProvider = iter.next(); - provider.add(mappingProvider, itemsFilter); - } - } - finally { - monitor.done(); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected IDialogSettings getDialogSettings() { - - IDialogSettings dialogSettings = JptUiPlugin.getPlugin().getDialogSettings(); - IDialogSettings settings = dialogSettings.getSection(DIALOG_SETTINGS); - - if (settings == null) { - settings = dialogSettings.addNewSection(DIALOG_SETTINGS); - } - - return settings; - } - - /* - * (non-Javadoc) - */ - @Override - public String getElementName(Object object) { - MappingUiProvider<?> provider = (MappingUiProvider<?>) object; - return provider.getLabel(); - } - - /* - * (non-Javadoc) - */ - @Override - protected Comparator<MappingUiProvider<?>> getItemsComparator() { - return new Comparator<MappingUiProvider<?>>() { - public int compare(MappingUiProvider<?> item1, MappingUiProvider<?> item2) { - - if (item1 == defaultProvider) { - return -1; - } - - if (item2 == defaultProvider) { - return 1; - } - - String displayString1 = item1.getLabel(); - String displayString2 = item2.getLabel(); - return Collator.getInstance().compare(displayString1, displayString2); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected IStatus validateItem(Object item) { - - if (item == null) { - return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, IStatus.ERROR, "", null); - } - - return Status.OK_STATUS; - } - - /** - * Create the filter responsible to remove any mapping type based on the - * pattern entered in the text field. - */ - private class MappingTypeItemsFilter extends ItemsFilter { - - /** - * Creates a new <code>MappingTypeItemsFilter</code>. - */ - MappingTypeItemsFilter() { - - super(); - - // Make sure that if the pattern is empty, we specify * in order - // to show all the mapping types - if (StringTools.stringIsEmpty(getPattern())) { - patternMatcher.setPattern("*"); - } - } - - /* - * (non-Javadoc) - */ - @Override - public boolean isConsistentItem(Object item) { - return true; - } - - /* - * (non-Javadoc) - */ - @Override - public boolean matchItem(Object item) { - MappingUiProvider<?> provider = (MappingUiProvider<?>) item; - return matches(provider.getLabel()); - } - } - } -} 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 deleted file mode 100644 index 7543af4735..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedByComposite.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import java.util.Iterator; -import org.eclipse.jpt.core.context.NonOwningMapping; -import org.eclipse.jpt.core.context.RelationshipMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.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.graphics.Point; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | -------------------------------------------------------------- | - * | Mapped By: | |v| | - * | -------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see NonOwningMapping - * @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<NonOwningMapping> -{ - private CCombo combo; - - /** - * Creates a new <code>MappedByComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public MappedByComposite(AbstractFormPane<? extends NonOwningMapping> 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 NonOwningMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - - propertyNames.add(RelationshipMapping.RESOLVED_TARGET_ENTITY_PROPERTY); - - propertyNames.add(NonOwningMapping.MAPPED_BY_PROPERTY); - } - - private ModifyListener buildComboModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (!isPopulating()) { - CCombo combo = (CCombo) e.widget; - if (combo.getData("populating") != Boolean.TRUE) {//check !TRUE because null is a possibility as well - valueChanged(combo.getText()); - } - } - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - - super.doPopulate(); - populateCombo(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - combo = buildLabeledEditableCCombo( - container, - JptUiMappingsMessages.NonOwningMapping_mappedByLabel, - buildComboModifyListener(), - JpaHelpContextIds.MAPPING_MAPPED_BY - ); - - SWTUtil.attachDefaultValueHandler(combo); - } - - private void populateCombo() { - - combo.removeAll(); - combo.add(JptUiMappingsMessages.NoneSelected); - - NonOwningMapping subject = subject(); - - if (subject != null) { - Iterator<String> iter = subject.candidateMappedByAttributeNames(); - - for (iter = CollectionTools.sort(iter); iter.hasNext(); ) { - combo.add(iter.next()); - } - } - - updateSelectedItem(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == NonOwningMapping.MAPPED_BY_PROPERTY || - propertyName == RelationshipMapping.RESOLVED_TARGET_ENTITY_PROPERTY) { - - populateCombo(); - } - } - - /** - * 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() { - - NonOwningMapping subject = subject(); - String value = (subject != null) ? subject.getMappedBy() : null; - - if (value != null) { - combo.setText(value); - } - else { - combo.select(0); - } - - combo.setSelection(new Point(0, 0)); - } - - private void valueChanged(String value) { - - NonOwningMapping subject = subject(); - String oldValue = (subject != null) ? subject.getMappedBy() : null; - - // Check for null value - if (StringTools.stringIsEmpty(value)) { - value = null; - - if (StringTools.stringIsEmpty(oldValue)) { - return; - } - } - - // The default value - if (JptUiMappingsMessages.NoneSelected.equals(value)) { - value = null; - } - - // Nothing to change - if ((oldValue == value) && value == null) { - return; - } - - // Set the new value - if ((value != null) && (oldValue == null) || - ((oldValue != null) && !oldValue.equals(value))) { - - setPopulating(true); - - try { - subject.setMappedBy(value); - } - finally { - setPopulating(false); - } - } - } -}
\ 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 deleted file mode 100644 index c473e95918..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/MappedSuperclassComposite.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | IdClassComposite | - * | | - * -----------------------------------------------------------------------------</pre> - * - * @see MappedSuperclass - * @see BaseJpaUiFactory - The factory creating this pane - * @see IdClassComposite - * - * @version 2.0 - * @since 2.0 - */ -public class MappedSuperclassComposite extends AbstractFormPane<MappedSuperclass> - implements JpaComposite<MappedSuperclass> -{ - /** - * 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 MappedSuperclass> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Primary Key Class widgets - new IdClassComposite(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/NamedNativeQueryPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/NamedNativeQueryPropertyComposite.java deleted file mode 100644 index 2122386850..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/NamedNativeQueryPropertyComposite.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.ClassChooserPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | --------------------------------------------- ------------- | - * | Result Class: | I | | Browse... | | - * | --------------------------------------------- ------------- | - * | --------------------------------------------- | - * | Query: | I | | - * | | | | - * | | | | - * | | | | - * | --------------------------------------------- | - * | | - * | - Query Hints ----------------------------------------------------------- | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | QueryHintsComposite | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see NamedNativeQuery - * @see NamedNativeQueriesComposite - The parent container - * @see ClassChooserPane - * - * @version 2.0 - * @since 2.0 - */ -public class NamedNativeQueryPropertyComposite extends AbstractPane<NamedNativeQuery> -{ - private ClassChooserPane<NamedNativeQuery> resultClassChooserPane; - - /** - * Creates a new <code>NamedNativeQueryPropertyComposite</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public NamedNativeQueryPropertyComposite(AbstractPane<?> parentPane, - PropertyValueModel<? extends NamedNativeQuery> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - private ClassChooserPane<NamedNativeQuery> buildClassChooser(Composite container) { - - return new ClassChooserPane<NamedNativeQuery>(this, container) { - - @Override - protected WritablePropertyValueModel<String> buildTextHolder() { - return new PropertyAspectAdapter<NamedNativeQuery, String>(getSubjectHolder(), NamedNativeQuery.RESULT_CLASS_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getResultClass(); - } - - @Override - protected void setValue_(String value) { - subject.setResultClass(value); - } - }; - } - - @Override - protected String className() { - return subject().getResultClass(); - } - - @Override - protected String labelText() { - return JptUiMappingsMessages.NamedNativeQueryPropertyComposite_resultClass; - } - - @Override - protected IPackageFragmentRoot packageFragmentRoot() { - IProject project = subject().getJpaProject().getProject(); - IJavaProject root = JavaCore.create(project); - - try { - return root.getAllPackageFragmentRoots()[0]; - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - - return null; - } - - @Override - protected void promptType() { - IType type = chooseType(); - - if (type != null) { - String className = type.getFullyQualifiedName('.'); - subject().setResultClass(className); - } - } - }; - } - - private WritablePropertyValueModel<String> buildQueryHolder() { - return new PropertyAspectAdapter<NamedNativeQuery, String>(getSubjectHolder(), Query.QUERY_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getQuery(); - } - - @Override - protected void setValue_(String value) { - subject.setQuery(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - super.enableWidgets(enabled); - resultClassChooserPane.enableWidgets(enabled); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Result class chooser - resultClassChooserPane = buildClassChooser(container); - - // Query text area - buildLabeledMultiLineText( - container, - JptUiMappingsMessages.NamedNativeQueryPropertyComposite_query, - buildQueryHolder(), - 4 - ); - - // Query Hints pane - container = buildTitledPane( - buildSubPane(container, 5), - JptUiMappingsMessages.NamedNativeQueryPropertyComposite_queryHintsGroupBox - ); - - new QueryHintsComposite(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/NamedQueryPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/NamedQueryPropertyComposite.java deleted file mode 100644 index 8ddbf092a2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/NamedQueryPropertyComposite.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------ | - * | Query: | I | | - * | | | | - * | | | | - * | ------------------------------------------------------------------ | - * | | - * | - Query Hints ----------------------------------------------------------- | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | QueryHintsComposite | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see NamedQuery - * @see NamedQueriesComposite - The parent container - * @see QueryHintsComposite - * - * @version 2.0 - * @since 2.0 - */ -public class NamedQueryPropertyComposite extends AbstractPane<NamedQuery> -{ - /** - * Creates a new <code>NamedQueryPropertyComposite</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public NamedQueryPropertyComposite(AbstractPane<?> parentPane, - PropertyValueModel<? extends NamedQuery> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - private WritablePropertyValueModel<String> buildQueryHolder() { - return new PropertyAspectAdapter<NamedQuery, String>(getSubjectHolder(), NamedQuery.QUERY_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getQuery(); - } - - @Override - protected void setValue_(String value) { - subject.setQuery(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Query text area - buildLabeledMultiLineText( - container, - JptUiMappingsMessages.NamedQueryPropertyComposite_query, - buildQueryHolder(), - 4 - ); - - // Query Hints pane - container = buildTitledPane( - buildSubPane(container, 5), - JptUiMappingsMessages.NamedQueryPropertyComposite_queryHintsGroupBox - ); - - new QueryHintsComposite(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/OneToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyMappingComposite.java deleted file mode 100644 index ac0590918c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToManyMappingComposite.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | TargetEntityComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | FetchTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | CascadeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrderingComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - Join Table ------------------------------------------------------------ | - * | | | | - * | | JoinTableComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OneToManyMapping - * @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<OneToManyMapping> - implements JpaComposite<OneToManyMapping> -{ - /** - * 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 OneToManyMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<Cascade> buildCascadeHolder() { - return new TransformationPropertyValueModel<OneToManyMapping, Cascade>(getSubjectHolder()) { - @Override - protected Cascade transform_(OneToManyMapping value) { - return value.getCascade(); - } - }; - } - - private PropertyValueModel<JoinTable> buildJointTableHolder() { - return new TransformationPropertyValueModel<OneToManyMapping, JoinTable>(getSubjectHolder()) { - @Override - protected JoinTable transform_(OneToManyMapping value) { - return value.getJoinTable(); - } - }; - } - - private void initializeGeneralPane(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - Composite subPane = buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); - - // Target Entity widgets - new TargetEntityComposite(this, subPane); - - // Fetch Type widgets - new FetchTypeComposite(this, subPane); - - // Mapped By widgets - new MappedByComposite(this, subPane); - - // Cascade widgets - new CascadeComposite(this, buildCascadeHolder(), buildSubPane(container, 4)); - - // Ordering widgets - new OrderingComposite(this, container); - } - - private void initializeJoinTablePane(Composite container) { - - container = buildCollapsableSection( - 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/OneToOneMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneMappingComposite.java deleted file mode 100644 index f913a2ac30..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OneToOneMappingComposite.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | TargetEntityComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | FetchTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | MappedByComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OptionalComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | CascadeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | JoinColumnComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OneToOneMapping - * @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<OneToOneMapping> - implements JpaComposite<OneToOneMapping> -{ - /** - * 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 OneToOneMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<Cascade> buildCascadeHolder() { - return new TransformationPropertyValueModel<OneToOneMapping, Cascade>(getSubjectHolder()) { - @Override - protected Cascade transform_(OneToOneMapping value) { - return value.getCascade(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - Composite subPane = buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); - - // Target Entity widgets - new TargetEntityComposite(this, subPane); - - // Fetch Type widgets - new FetchTypeComposite(this, subPane); - - // Mapped By widgets - new MappedByComposite(this, subPane); - - // Optional check box - new OptionalComposite(this, buildSubPane(subPane, 4)); - - // 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 deleted file mode 100644 index e64e791fcb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OptionalComposite.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Nullable; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.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 BasicMapping - * @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<Nullable> -{ - /** - * Creates a new <code>OptionalComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public OptionalComposite(AbstractFormPane<? extends Nullable> parentPane, - Composite parent) - { - super(parentPane, parent); - } - - private WritablePropertyValueModel<Boolean> buildOptionalHolder() { - return new PropertyAspectAdapter<Nullable, Boolean>(getSubjectHolder(), Nullable.SPECIFIED_OPTIONAL_PROPERTY) { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedOptional(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedOptional(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - 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(), - JpaHelpContextIds.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 deleted file mode 100644 index e77c720364..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.MultiRelationshipMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -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.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.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.Group; -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 | | - * | | ------------------------------------------------------------------- | | - * | | | I | | | - * | | ------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see MultiRelationshipMapping - * @see ManyToManyMappingComposite - A container of this pane - * @see OneToManyMappingComposite - A container of this pane - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class OrderingComposite extends AbstractFormPane<MultiRelationshipMapping> -{ - private Text customOrderingText; - - /** - * Creates a new <code>OrderingComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public OrderingComposite(AbstractFormPane<? extends MultiRelationshipMapping> 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 MultiRelationshipMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(MultiRelationshipMapping.ORDER_BY_PROPERTY); - } - - private ModifyListener buildCustomTextModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (!isPopulating()) { - Text text = (Text) e.widget; - valueChanged(text.getText()); - } - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - super.doPopulate(); - populateCustomOrdering(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Order By group - Group orderByGroup = buildTitledPane( - container, - JptUiMappingsMessages.OrderByComposite_orderByGroup, - JpaHelpContextIds.MAPPING_ORDER_BY); - - // No Ordering radio button - buildRadioButton( - buildSubPane(orderByGroup, 8), - JptUiMappingsMessages.OrderByComposite_noOrdering, - buildNoOrderingHolder(), - JpaHelpContextIds.MAPPING_ORDER_BY_NO_ORDERING - ); - - // Order by Primary Key radio button - buildRadioButton( - orderByGroup, - JptUiMappingsMessages.OrderByComposite_primaryKeyOrdering, - buildPrimaryKeyOrderingHolder(), - JpaHelpContextIds.MAPPING_ORDER_BY_PRIMARY_KEY_ORDERING - ); - - // Custom Ordering radio button - buildRadioButton( - orderByGroup, - JptUiMappingsMessages.OrderByComposite_customOrdering, - buildCustomOrderingHolder(), - JpaHelpContextIds.MAPPING_ORDER_BY_CUSTOM_ORDERING - ); - - // Custom Ordering text field - customOrderingText = buildText( - buildSubPane(orderByGroup, 0, 16), - JpaHelpContextIds.MAPPING_ORDER_BY - ); - - customOrderingText.addModifyListener(buildCustomTextModifyListener()); - installCustomTextEnabler(customOrderingText); - } - - private void installCustomTextEnabler(Text text) { - new ControlEnabler(buildCustomOrderingHolder(), text); - } - - private WritablePropertyValueModel<Boolean> buildCustomOrderingHolder() { - return new PropertyAspectAdapter<MultiRelationshipMapping, Boolean>(getSubjectHolder(), MultiRelationshipMapping.CUSTOM_ORDERING_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(subject.isCustomOrdering()); - } - - @Override - protected void setValue_(Boolean value) { - subject.setCustomOrdering(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildNoOrderingHolder() { - return new PropertyAspectAdapter<MultiRelationshipMapping, Boolean>(getSubjectHolder(), MultiRelationshipMapping.NO_ORDERING_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(subject.isNoOrdering()); - } - - @Override - protected void setValue_(Boolean value) { - subject.setNoOrdering(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildPrimaryKeyOrderingHolder() { - return new PropertyAspectAdapter<MultiRelationshipMapping, Boolean>(getSubjectHolder(), MultiRelationshipMapping.PK_ORDERING_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(subject.isPkOrdering()); - } - - @Override - protected void setValue_(Boolean value) { - subject.setPkOrdering(value.booleanValue()); - } - }; - } - private void populateCustomOrdering() { - - if ((subject() != null) && subject().getOrderBy() != null) { - customOrderingText.setText(subject().getOrderBy()); - } - else { - customOrderingText.setText(""); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == MultiRelationshipMapping.ORDER_BY_PROPERTY) { - populateCustomOrdering(); - } - } - - private void valueChanged(String value) { - - setPopulating(true); - - try { - subject().setOrderBy(value); - } - finally { - setPopulating(false); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrmPersistentAttributeMapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrmPersistentAttributeMapAsComposite.java deleted file mode 100644 index b72c6b29f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrmPersistentAttributeMapAsComposite.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.swt.widgets.Composite; - -/** - * This "Map As" composite is responsible for showing the mapping name and - * mapping type for an attribute declared within a JPA mapping descriptor file. - * - * @see OrmPersistentAttribute - * @see OrmPersistentAttributeDetailsPage - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class OrmPersistentAttributeMapAsComposite extends PersistentAttributeMapAsComposite<OrmPersistentAttribute> -{ - /** - * Creates a new <code>OrmPersistentAttributeMapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public OrmPersistentAttributeMapAsComposite(AbstractPane<? extends OrmPersistentAttribute> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders() { - return jpaPlatformUi().ormAttributeMappingUiProviders(); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> defaultAttributeMappingUiProviders() { - return jpaPlatformUi().defaultOrmAttributeMappingUiProviders(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrmPersistentTypeMapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrmPersistentTypeMapAsComposite.java deleted file mode 100644 index 97a6923344..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrmPersistentTypeMapAsComposite.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.swt.widgets.Composite; - -/** - * This "Map As" composite is responsible for showing the mapping name and - * mapping type for a type declared within a JPA mapping descriptor file. - * - * @see OrmPersistentType - * @see OrmPersistentTypeDetailsPage - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class OrmPersistentTypeMapAsComposite extends PersistentTypeMapAsComposite<OrmPersistentType> -{ - /** - * Creates a new <code>OrmPersistentTypeMapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public OrmPersistentTypeMapAsComposite(AbstractPane<? extends OrmPersistentType> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected MappingUiProvider<?> buildDefaultProvider() { - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders() { - return jpaPlatformUi().ormTypeMappingUiProviders(); - } -} 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 deleted file mode 100644 index 43bc625147..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java +++ /dev/null @@ -1,555 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.BaseOverride; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.IJoinColumnsEditor; -import org.eclipse.jpt.ui.internal.util.ControlSwitcher; -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.PostExecution; -import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -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.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.part.PageBook; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | - Attribute Overrides --------------------------------------------------- | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | AddRemoveListPane | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | | | | - * | | x Override Default | | - * | | | | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | PageBook (JoinColumnsComposite or ColumnComposite) | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see EntityComposite - The parent container - * @see ColumnComposite - * @see JoinColumnsComposite - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class OverridesComposite extends AbstractFormPane<Entity> -{ - private Composite columnPane; - private Composite joinColumnsPane; - private WritablePropertyValueModel<BaseOverride> overrideHolder; - - /** - * Creates a new <code>OverridesComposite</code>. - * - * @param parentPane The parent controller of this one - * @param parent The parent container - */ - public OverridesComposite(AbstractFormPane<? extends Entity> parentPane, - Composite parent) { - - super(parentPane, parent, false); - } - - /** - * 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 Entity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private void addJoinColumn(AssociationOverride subject) { - - JoinColumnInAssociationOverrideDialog dialog = - new JoinColumnInAssociationOverrideDialog(shell(), subject, null); - - dialog.openDialog(buildAddJoinColumnPostExecution()); - } - - private void addJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) { - - AssociationOverride associationOverride = stateObject.getOwner(); - int index = associationOverride.specifiedJoinColumnsSize(); - - JoinColumn joinColumn = associationOverride.addSpecifiedJoinColumn(index); - stateObject.updateJoinColumn(joinColumn); - } - - private PostExecution<JoinColumnInAssociationOverrideDialog> buildAddJoinColumnPostExecution() { - return new PostExecution<JoinColumnInAssociationOverrideDialog>() { - public void execute(JoinColumnInAssociationOverrideDialog dialog) { - if (dialog.wasConfirmed()) { - addJoinColumn(dialog.subject()); - } - } - }; - } - - private WritablePropertyValueModel<AssociationOverride> buildAssociationOverrideHolder() { - return new TransformationWritablePropertyValueModel<BaseOverride, AssociationOverride>(overrideHolder) { - @Override - protected AssociationOverride transform_(BaseOverride value) { - return (value instanceof AssociationOverride) ? (AssociationOverride) value : null; - } - }; - } - - private WritablePropertyValueModel<AttributeOverride> buildAttributeOverrideHolder() { - return new TransformationWritablePropertyValueModel<BaseOverride, AttributeOverride>(overrideHolder) { - @Override - protected AttributeOverride transform_(BaseOverride value) { - return (value instanceof AttributeOverride) ? (AttributeOverride) value : null; - } - }; - } - - private PropertyValueModel<Column> buildColumnHolder(PropertyValueModel<AttributeOverride> attributeOverrideHolder) { - return new TransformationPropertyValueModel<AttributeOverride, Column>(attributeOverrideHolder) { - @Override - protected Column transform_(AttributeOverride value) { - return value.getColumn(); - } - }; - } - - private ListValueModel<AssociationOverride> buildDefaultAssociationOverridesListHolder() { - return new ListAspectAdapter<Entity, AssociationOverride>(getSubjectHolder(), Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST) { - @Override - protected ListIterator<AssociationOverride> listIterator_() { - return subject.virtualAssociationOverrides(); - } - - @Override - protected int size_() { - return subject.virtualAssociationOverridesSize(); - } - }; - } - - private ListValueModel<AttributeOverride> buildDefaultAttributeOverridesListHolder() { - return new ListAspectAdapter<Entity, AttributeOverride>(getSubjectHolder(), Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST) { - @Override - protected ListIterator<AttributeOverride> listIterator_() { - return subject.virtualAttributeOverrides(); - } - - @Override - protected int size_() { - return subject.virtualAttributeOverridesSize(); - } - }; - } - - private PostExecution<JoinColumnInAssociationOverrideDialog> buildEditJoinColumnPostExecution() { - return new PostExecution<JoinColumnInAssociationOverrideDialog>() { - public void execute(JoinColumnInAssociationOverrideDialog dialog) { - if (dialog.wasConfirmed()) { - editJoinColumn(dialog.subject()); - } - } - }; - } - - private JoinColumnsProvider buildJoinColumnsEditor() { - return new JoinColumnsProvider(); - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultAssociationOverrideHolder() { - return new TransformationWritablePropertyValueModel<AssociationOverride, Boolean>(buildAssociationOverrideHolder()) { - @Override - public void setValue(Boolean value) { - updateOverride(value); - } - - @Override - protected Boolean transform_(AssociationOverride value) { - return !value.isVirtual(); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultAttributeOverrideHolder() { - return new TransformationWritablePropertyValueModel<AttributeOverride, Boolean>(buildAttributeOverrideHolder()) { - @Override - public void setValue(Boolean value) { - updateOverride(value); - } - - @Override - protected Boolean transform_(AttributeOverride value) { - return !value.isVirtual(); - } - }; - } - - private String buildOverrideDisplayString(BaseOverride override) { - String overrideType; - - // Retrieve the type - if (override instanceof AssociationOverride) { - overrideType = JptUiMappingsMessages.OverridesComposite_association; - } - else { - overrideType = JptUiMappingsMessages.OverridesComposite_attribute; - } - - // Format the name - String name = override.getName(); - - if (StringTools.stringIsEmpty(name)) { - name = JptUiMappingsMessages.OverridesComposite_noName; - } - - // Format: <name> (Attribute/Association Override) - StringBuilder sb = new StringBuilder(); - sb.append(name); - sb.append(" ("); - sb.append(overrideType); - sb.append(") "); - return sb.toString(); - } - - private WritablePropertyValueModel<BaseOverride> buildOverrideHolder() { - return new SimplePropertyValueModel<BaseOverride>(); - } - - private ILabelProvider buildOverrideLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - return buildOverrideDisplayString((BaseOverride) element); - } - }; - } - - private Adapter buildOverridesAdapter() { - return new AddRemoveListPane.AbstractAdapter() { - - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - } - }; - } - - private ListValueModel<BaseOverride> buildOverridesListHolder() { - List<ListValueModel<? extends BaseOverride>> list = new ArrayList<ListValueModel<? extends BaseOverride>>(); - list.add(buildSpecifiedAttributeOverridesListHolder()); - list.add(buildDefaultAttributeOverridesListHolder()); - list.add(buildSpecifiedAssociationOverridesListHolder()); - list.add(buildDefaultAssociationOverridesListHolder()); - return new CompositeListValueModel<ListValueModel<? extends BaseOverride>, BaseOverride>(list); - } - - private ListValueModel<BaseOverride> buildOverridesListModel() { - return new ItemPropertyListValueModelAdapter<BaseOverride>( - buildOverridesListHolder(), - BaseOverride.NAME_PROPERTY - ); - } - - private Transformer<BaseOverride, Control> buildPaneTransformer() { - return new Transformer<BaseOverride, Control>() { - public Control transform(BaseOverride override) { - - if (override instanceof AttributeOverride) { - return columnPane; - } - - if (override instanceof AssociationOverride) { - return joinColumnsPane; - } - - return null; - } - }; - } - - private ListValueModel<AssociationOverride> buildSpecifiedAssociationOverridesListHolder() { - return new ListAspectAdapter<Entity, AssociationOverride>(getSubjectHolder(), Entity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST) { - @Override - protected ListIterator<AssociationOverride> listIterator_() { - return subject.specifiedAssociationOverrides(); - } - - @Override - protected int size_() { - return subject.specifiedAssociationOverridesSize(); - } - }; - } - - private ListValueModel<AttributeOverride> buildSpecifiedAttributeOverridesListHolder() { - return new ListAspectAdapter<Entity, AttributeOverride>(getSubjectHolder(), Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST) { - @Override - protected ListIterator<AttributeOverride> listIterator_() { - return subject.specifiedAttributeOverrides(); - } - - @Override - protected int size_() { - return subject.specifiedAttributeOverridesSize(); - } - }; - } - - private void editJoinColumn(JoinColumn joinColumn) { - - JoinColumnInAssociationOverrideDialog dialog = - new JoinColumnInAssociationOverrideDialog( - shell(), - (AssociationOverride) overrideHolder.getValue(), - joinColumn - ); - - dialog.openDialog(buildEditJoinColumnPostExecution()); - } - - private void editJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - overrideHolder = buildOverrideHolder(); - } - - private void initializeColumnPane(PageBook pageBook) { - - int groupBoxMargin = groupBoxMargin(); - columnPane = buildSubPane(pageBook, 5); - - // Override Default check box - buildCheckBox( - buildSubPane(columnPane, 0, groupBoxMargin, 0, groupBoxMargin), - JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault, - buildOverrideDefaultAttributeOverrideHolder() - ); - - // Column widgets (for IOverrideAttribute) - ColumnComposite columnComposite = new ColumnComposite( - this, - buildColumnHolder(buildAttributeOverrideHolder()), - columnPane, - false - ); - - columnPane.setVisible(false); - installColumnsPaneEnabler(columnComposite); - } - - private void initializeJoinColumnsPane(PageBook pageBook) { - - joinColumnsPane = buildSubPane(pageBook); - - // Override Default check box - buildCheckBox( - buildSubPane(joinColumnsPane, 5, groupBoxMargin()), - JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault, - buildOverrideDefaultAssociationOverrideHolder() - ); - - Group joinColumnsGroupPane = buildTitledPane( - joinColumnsPane, - JptUiMappingsMessages.OverridesComposite_joinColumn - ); - - // Join Columns list pane (for IOverrideAssociation) - JoinColumnsComposite<AssociationOverride> joinColumnsComposite = - new JoinColumnsComposite<AssociationOverride>( - this, - buildAssociationOverrideHolder(), - joinColumnsGroupPane, - buildJoinColumnsEditor(), - false - ); - - joinColumnsPane.setVisible(false); - installJoinColumnsPaneEnabler(joinColumnsComposite); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Overrides group pane - container = buildTitledPane( - container, - JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides - ); - - // Overrides list pane - initializeOverridesList(container); - - // Property pane - PageBook pageBook = buildPageBook(container); - initializeJoinColumnsPane(pageBook); - initializeColumnPane(pageBook); - installOverrideControlSwitcher(overrideHolder, pageBook); - } - - private AddRemoveListPane<Entity> initializeOverridesList(Composite container) { - - return new AddRemoveListPane<Entity>( - this, - buildSubPane(container, 8), - buildOverridesAdapter(), - buildOverridesListModel(), - overrideHolder, - buildOverrideLabelProvider(), - JpaHelpContextIds.ENTITY_ATTRIBUTE_OVERRIDES - ) - { - @Override - protected void initializeButtonPane(Composite container, String helpId) { - } - - @Override - protected void updateButtons() { - } - }; - } - - private void installColumnsPaneEnabler(ColumnComposite pane) { - new PaneEnabler( - buildOverrideDefaultAttributeOverrideHolder(), - pane - ); - } - - private void installJoinColumnsPaneEnabler(JoinColumnsComposite<AssociationOverride> pane) { - new PaneEnabler( - buildOverrideDefaultAssociationOverrideHolder(), - pane - ); - } - - private void installOverrideControlSwitcher(PropertyValueModel<BaseOverride> overrideHolder, - PageBook pageBook) { - - new ControlSwitcher( - overrideHolder, - buildPaneTransformer(), - pageBook - ); - } - - private void updateOverride(boolean selected) { - - if (isPopulating()) { - return; - } - - setPopulating(true); - - try { - BaseOverride override = overrideHolder.getValue(); - - BaseOverride newOverride = override.setVirtual(!selected); - overrideHolder.setValue(newOverride); - } - finally { - setPopulating(false); - } - } - - private class JoinColumnsProvider implements IJoinColumnsEditor<AssociationOverride> { - - public void addJoinColumn(AssociationOverride subject) { - OverridesComposite.this.addJoinColumn(subject); - } - - public JoinColumn defaultJoinColumn(AssociationOverride subject) { - return null; - } - - public String defaultPropertyName() { - return AssociationOverride.DEFAULT_JOIN_COLUMNS_LIST; - } - - public void editJoinColumn(AssociationOverride subject, JoinColumn joinColumn) { - OverridesComposite.this.editJoinColumn(joinColumn); - } - - public boolean hasSpecifiedJoinColumns(AssociationOverride subject) { - return subject.containsSpecifiedJoinColumns(); - } - - public void removeJoinColumns(AssociationOverride subject, int[] selectedIndices) { - for (int index = selectedIndices.length; --index >= 0; ) { - subject.removeSpecifiedJoinColumn(selectedIndices[index]); - } - } - - public ListIterator<JoinColumn> specifiedJoinColumns(AssociationOverride subject) { - return subject.specifiedJoinColumns(); - } - - public int specifiedJoinColumnsSize(AssociationOverride subject) { - return subject.specifiedJoinColumnsSize(); - } - - public String specifiedListPropertyName() { - return AssociationOverride.SPECIFIED_JOIN_COLUMNS_LIST; - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PersistentAttributeMapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PersistentAttributeMapAsComposite.java deleted file mode 100644 index c10b0d8fdd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PersistentAttributeMapAsComposite.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import java.util.Iterator; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -/** - * This "Map As" composite is responsible for showing the mapping name and - * mapping type for an attribute. - * - * @see JavaPersistentAttributeMapAsComposite - * @see OrmPersistentAttributeMapAsComposite - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class PersistentAttributeMapAsComposite<T extends PersistentAttribute> extends MapAsComposite<T> { - - /** - * Creates a new <code>PersistentAttributeMapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistentAttributeMapAsComposite(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistentAttribute.DEFAULT_MAPPING_PROPERTY); - propertyNames.add(PersistentAttribute.SPECIFIED_MAPPING_PROPERTY); - propertyNames.add(PersistentAttribute.NAME_PROPERTY); - } - - /** - * Retrieves the list of providers that are registered with the JPT plugin. - * - * @return The supported types of mapping - */ - protected abstract Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders(); - - /* - * (non-Javadoc) - */ - @Override - protected MappingUiProvider<T> buildDefaultProvider() { - - if (subject().getDefaultMappingKey() == null) { - return null; - } - - return new MappingUiProvider<T>() { - - public Image getImage() { - String mappingKey = subject().getDefaultMappingKey(); - return JpaMappingImageHelper.imageForAttributeMapping(mappingKey); - } - - public String getLabel() { - String mappingKey = subject().getDefaultMappingKey(); - - return SWTUtil.buildDisplayString( - JptUiMessages.class, - MapAsComposite.class, - mappingKey + "_default2" - ); - } - - public String getMappingKey() { - return null; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected MappingChangeHandler buildMappingChangeHandler() { - return new MappingChangeHandler() { - - public String labelText() { - String mappingKey = subject().getMappingKey(); - - if (mappingKey != MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY) { - return JptUiMessages.MapAsComposite_mappedAttributeText; - } - if (subject().isVirtual()) { - return JptUiMessages.MapAsComposite_virtualAttributeText; - } - - return JptUiMessages.MapAsComposite_unmappedAttributeText; - } - - public String mappingType() { - String mappingKey = subject().getMappingKey(); - - if (mappingKey == null) { - return JptUiMessages.MapAsComposite_changeMappingType; - } - - if (subject().getSpecifiedMapping() == null) { - return SWTUtil.buildDisplayString( - JptUiMessages.class, - MapAsComposite.class, - mappingKey + "_default" - ); - } - - return SWTUtil.buildDisplayString( - JptUiMessages.class, - MapAsComposite.class, - mappingKey - ); - } - - public void morphMapping(MappingUiProvider<?> provider) { - subject().setSpecifiedMappingKey(provider.getMappingKey()); - } - - public String name() { - return subject().getName(); - } - - public Iterator<? extends MappingUiProvider<?>> providers() { - return attributeMappingUiProviders(); - } - }; - } - - /** - * Returns the list of providers that are registered with the JPT plugin. - * - * @return The supported default types of mapping - */ - protected abstract Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> - defaultAttributeMappingUiProviders(); - - /** - * Returns the JPT platform responsble to manage the user interface part of - * the JPT plug-in. - * - * @return The UI platform of the JPT plug-in - */ - protected JpaPlatformUi jpaPlatformUi() { - String platformId = subject().getJpaProject().getJpaPlatform().getId(); - return JpaPlatformUiRegistry.instance().jpaPlatform(platformId); - } - - /* - * (non-Javadoc) - */ - @Override - protected String mappingKey() { - return subject().getMappingKey(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == PersistentAttribute.SPECIFIED_MAPPING_PROPERTY || - propertyName == PersistentAttribute.DEFAULT_MAPPING_PROPERTY || - propertyName == PersistentAttribute.NAME_PROPERTY) { - - updateDescription(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PersistentTypeMapAsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PersistentTypeMapAsComposite.java deleted file mode 100644 index ed09f3c7ff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PersistentTypeMapAsComposite.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import java.util.Iterator; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.swt.widgets.Composite; - -/** - * This "Map As" composite is responsible for showing the mapping name and - * mapping type for a type. - * - * @see JavaPersistentTypeMapAsComposite - * @see OrmPersistentTypeMapAsComposite - * - * @version 2.0 - * @since 2.0 - */ -public abstract class PersistentTypeMapAsComposite<T extends PersistentType> extends MapAsComposite<T> -{ - /** - * Creates a new <code>PersistentTypeMapAsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistentTypeMapAsComposite(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistentType.MAPPING_PROPERTY); - propertyNames.add(PersistentType.NAME_PROPERTY); - } - - /* - * (non-Javadoc) - */ - @Override - protected MappingChangeHandler buildMappingChangeHandler() { - return new MappingChangeHandler() { - - public String labelText() { - String mappingKey = subject().getMappingKey(); - - if (mappingKey != null) { - return JptUiMessages.MapAsComposite_mappedTypeText; - } - - return JptUiMessages.MapAsComposite_unmappedTypeText; - } - - public String mappingType() { - String mappingKey = subject().getMappingKey(); - - if (mappingKey == null) { - return JptUiMessages.MapAsComposite_changeMappingType; - } - - return SWTUtil.buildDisplayString( - JptUiMessages.class, - MapAsComposite.class, - mappingKey - ); - } - - public void morphMapping(MappingUiProvider<?> provider) { - subject().setMappingKey(provider.getMappingKey()); - } - - public String name() { - return subject().getName(); - } - - public Iterator<? extends MappingUiProvider<?>> providers() { - return typeMappingUiProviders(); - } - }; - } - - /** - * Returns the JPT platform responsble to manage the user interface part of - * the JPT plug-in. - * - * @return The UI platform of the JPT plug-in - */ - protected JpaPlatformUi jpaPlatformUi() { - String platformId = subject().getJpaProject().getJpaPlatform().getId(); - return JpaPlatformUiRegistry.instance().jpaPlatform(platformId); - } - - /* - * (non-Javadoc) - */ - @Override - protected String mappingKey() { - return subject().getMappingKey(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == PersistentType.MAPPING_PROPERTY || - propertyName == PersistentType.NAME_PROPERTY) { - - updateDescription(); - } - } - - /** - * Retrieves the list of providers that are registered with the JPT plugin. - * - * @return The supported types of mapping - */ - protected abstract Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders(); -} 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 deleted file mode 100644 index 2764e26f16..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnDialog.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used to either create or edit a primary key join column that - * is located on an entity. - * - * @see PrimaryKeyJoinColumn - * @see Entity - * @see PrimaryKeyJoinColumnStateObject - * @see BaseJoinColumnDialogPane - * - * @version 2.0 - * @since 2.0 - */ -public class PrimaryKeyJoinColumnDialog extends BaseJoinColumnDialog<PrimaryKeyJoinColumnStateObject> { - - /** - * Creates a new <code>PrimaryKeyJoinColumnDialog</code>. - * - * @param parent The parent shell - * @param entity The owner of the join column to create or where it is - * located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public PrimaryKeyJoinColumnDialog(Shell parent, - Entity entity, - PrimaryKeyJoinColumn joinColumn) { - - super(parent, entity, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - protected AbstractDialogPane<PrimaryKeyJoinColumnStateObject> buildLayout(Composite container) { - return new BaseJoinColumnDialogPane<PrimaryKeyJoinColumnStateObject>( - subjectHolder(), - container - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected PrimaryKeyJoinColumnStateObject buildStateObject() { - return new PrimaryKeyJoinColumnStateObject(getOwner(), getJoinColumn()); - } - - /* - * (non-Javadoc) - */ - @Override - protected String descriptionTitle() { - - if (getJoinColumn() == null) { - return JptUiMappingsMessages.PrimaryKeyJoinColumnDialog_addDescriptionTitle; - } - - return JptUiMappingsMessages.PrimaryKeyJoinColumnDialog_editDescriptionTitle; - } - - /* - * (non-Javadoc) - */ - @Override - public PrimaryKeyJoinColumn getJoinColumn() { - return (PrimaryKeyJoinColumn) super.getJoinColumn(); - } - - /* - * (non-Javadoc) - */ - @Override - protected Entity getOwner() { - return (Entity) super.getOwner(); - } - - /* - * (non-Javadoc) - */ - @Override - protected String title() { - - if (getJoinColumn() == null) { - return JptUiMappingsMessages.PrimaryKeyJoinColumnDialog_addTitle; - } - - return JptUiMappingsMessages.PrimaryKeyJoinColumnDialog_editTitle; - } -}
\ No newline at end of file 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 deleted file mode 100644 index a152911cc3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractDialogPane; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used to either create or edit a primary key joing column that - * is within a secondary table. - * - * @see PrimaryKeyJoinColumn - * @see SecondaryTable - * @see BaseJoinColumnDialogPane - * @see PrimaryKeyJoinColumnInSecondaryTableStateObject - * - * @version 2.0 - * @since 2.0 - */ -public class PrimaryKeyJoinColumnInSecondaryTableDialog extends BaseJoinColumnDialog<PrimaryKeyJoinColumnInSecondaryTableStateObject> { - - /** - * Creates a new <code>PrimaryKeyJoinColumnInSecondaryTableDialog</code>. - * - * @param parent The parent shell - * @param secondaryTable The owner of the join column to create or where it - * is located - * @param joinColumn Either the join column to edit or <code>null</code> if - * this state object is used to create a new one - */ - public PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, - SecondaryTable secondaryTable, - PrimaryKeyJoinColumn joinColumn) { - - super(parent, secondaryTable, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - protected AbstractDialogPane<PrimaryKeyJoinColumnInSecondaryTableStateObject> buildLayout(Composite container) { - return new BaseJoinColumnDialogPane<PrimaryKeyJoinColumnInSecondaryTableStateObject>( - subjectHolder(), - container - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected PrimaryKeyJoinColumnInSecondaryTableStateObject buildStateObject() { - return new PrimaryKeyJoinColumnInSecondaryTableStateObject( - getOwner(), - getJoinColumn() - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected String descriptionTitle() { - - if (getJoinColumn() == null) { - return JptUiMappingsMessages.PrimaryKeyJoinColumnInSecondaryTableDialog_addDescriptionTitle; - } - - return JptUiMappingsMessages.PrimaryKeyJoinColumnInSecondaryTableDialog_editDescriptionTitle; - } - - /* - * (non-Javadoc) - */ - @Override - public PrimaryKeyJoinColumn getJoinColumn() { - return (PrimaryKeyJoinColumn) super.getJoinColumn(); - } - - /* - * (non-Javadoc) - */ - @Override - protected SecondaryTable getOwner() { - return (SecondaryTable) super.getOwner(); - } - - /* - * (non-Javadoc) - */ - @Override - protected String title() { - - if (getJoinColumn() == null) { - return JptUiMappingsMessages.PrimaryKeyJoinColumnInSecondaryTableDialog_addTitle; - } - - return JptUiMappingsMessages.PrimaryKeyJoinColumnInSecondaryTableDialog_editTitle; - } -}
\ 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 deleted file mode 100644 index bda9510d43..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableStateObject.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; - -/** - * The state object used to create or edit a primary key join column on an - * secondary table. - * - * @see PrimaryKeyJoinColumn - * @see SecondaryTable - * @see PrimaryKeyJoinColumnInSecondaryTableDialog - * - * @version 2.0 - * @since 2.0 - */ -public class PrimaryKeyJoinColumnInSecondaryTableStateObject extends BaseJoinColumnStateObject -{ - /** - * Creates a new <code>PrimaryKeyJoinColumnInSecondaryTableStateObject</code>. - * - * @param secondaryTable The owner of the join column to create or where it - * is located - * @param joinColumn The join column to edit or <code>null</code> if it is to - * create a new one - */ - public PrimaryKeyJoinColumnInSecondaryTableStateObject(SecondaryTable secondaryTable, - PrimaryKeyJoinColumn joinColumn) { - - super(secondaryTable, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - public String getDefaultTable() { - return null; - } - - /* - * (non-Javadoc) - */ - @Override - public PrimaryKeyJoinColumn getJoinColumn() { - return (PrimaryKeyJoinColumn) super.getJoinColumn(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getNameTable() { - return getOwner().getDbTable(); - } - - /* - * (non-Javadoc) - */ - @Override - public SecondaryTable getOwner() { - return (SecondaryTable) super.getOwner(); - } - - /* (non-Javadoc) - */ - @Override - public Table getReferencedNameTable() { - return getOwner().getParent().getPrimaryDbTable(); - } - - /* - * (non-Javadoc) - */ - @Override - protected String initialTable() { - return getOwner().getName(); - } - - /* - * (non-Javadoc) - */ - @Override - public ListIterator<String> tables() { - return new SingleElementListIterator<String>(initialTable()); - } -}
\ No newline at end of file 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 deleted file mode 100644 index fd319a1d76..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnStateObject.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; - -/** - * The state object used to create or edit a primary key join column on an - * entity. - * - * @see PrimaryKeyJoinColumn - * @see Entity - * @see PrimaryKeyJoinColumnDialog - * @see PrimaryKeyJoinColumnDialogPane - * - * @version 2.0 - * @since 2.0 - */ -public class PrimaryKeyJoinColumnStateObject extends BaseJoinColumnStateObject -{ - /** - * Creates a new <code>PrimaryKeyJoinColumnStateObject</code>. - * - * @param entity The owner of the join column to create or where it is - * located - * @param joinColumn The join column to edit or <code>null</code> if this is - * used to create a new one - */ - public PrimaryKeyJoinColumnStateObject(Entity entity, - PrimaryKeyJoinColumn joinColumn) { - super(entity, joinColumn); - } - - /* - * (non-Javadoc) - */ - @Override - public String getDefaultTable() { - return null; - } - - /* - * (non-Javadoc) - */ - @Override - public PrimaryKeyJoinColumn getJoinColumn() { - return (PrimaryKeyJoinColumn) super.getJoinColumn(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getNameTable() { - return getOwner().getPrimaryDbTable(); - } - - /* - * (non-Javadoc) - */ - @Override - public Entity getOwner() { - return (Entity) super.getOwner(); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getReferencedNameTable() { - return getOwner().getParentEntity().getPrimaryDbTable(); - } - - /* - * (non-Javadoc) - */ - @Override - protected String initialTable() { - return getOwner().getTableName(); - } - - /* - * (non-Javadoc) - */ - @Override - public ListIterator<String> tables() { - return new SingleElementListIterator<String>(initialTable()); - } -}
\ 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 deleted file mode 100644 index 08a33178bc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java +++ /dev/null @@ -1,427 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.BaseJoinColumn; -import org.eclipse.jpt.core.context.NamedColumn; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListPropertyValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | - Join Columns ---------------------------------------------------------- | - * | | | | - * | | x Override Default | | - * | | | | - * | | --------------------------------------------------------------------- | | - * | | | | | | - * | | | AddRemoveListPane | | | - * | | | | | | - * | | --------------------------------------------------------------------- | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see SecondaryTable - * @see EntityComposite - The container of this pane - * @see AddRemoveListPane - * - * @version 2.0 - * @since 1.0 - */ -public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractFormPane<SecondaryTable> -{ - private WritablePropertyValueModel<PrimaryKeyJoinColumn> joinColumnHolder; - - /** - * 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 SecondaryTable> 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 SecondaryTable> subjectHolder, - Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private void addJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { - - SecondaryTable secondaryTable = stateObject.getOwner(); - int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); - - PrimaryKeyJoinColumn joinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(index); - stateObject.updateJoinColumn(joinColumn); - } - - private void addPrimaryKeyJoinColumn() { - - PrimaryKeyJoinColumnInSecondaryTableDialog dialog = - new PrimaryKeyJoinColumnInSecondaryTableDialog(shell(), subject(), null); - - dialog.openDialog(buildAddPrimaryKeyJoinColumnPostExecution()); - } - - private PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog> buildAddPrimaryKeyJoinColumnPostExecution() { - return new PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog>() { - public void execute(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { - if (dialog.wasConfirmed()) { - addJoinColumn(dialog.subject()); - } - } - }; - } - - private PropertyValueModel<Boolean> buildControlBooleanHolder() { - return new TransformationPropertyValueModel<SecondaryTable, Boolean>(getSubjectHolder()) { - @Override - protected Boolean transform(SecondaryTable value) { - if (value == null) { - return Boolean.FALSE; - } - return Boolean.valueOf(!value.isVirtual()); - } - }; - } - - private PropertyValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnHolder() { - return new PropertyAspectAdapter<SecondaryTable, PrimaryKeyJoinColumn>(getSubjectHolder(), SecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMN) { - @Override - protected PrimaryKeyJoinColumn buildValue_() { - return subject.getDefaultPrimaryKeyJoinColumn(); - } - }; - } - - private ListValueModel<PrimaryKeyJoinColumn> buildDefaultJoinColumnListHolder() { - return new PropertyListValueModelAdapter<PrimaryKeyJoinColumn>( - buildDefaultJoinColumnHolder() - ); - } - - private PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog> buildEditPrimaryKeyJoinColumnPostExecution() { - return new PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog>() { - public void execute(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { - if (dialog.wasConfirmed()) { - editPrimaryKeyJoinColumn(dialog.subject()); - } - } - }; - } - - private String buildJoinColumnLabel(PrimaryKeyJoinColumn joinColumn) { - - if (joinColumn.isVirtual()) { - return NLS.bind( - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, - joinColumn.getName(), - joinColumn.getReferencedColumnName() - ); - } - - 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) { - PrimaryKeyJoinColumn joinColumn = (PrimaryKeyJoinColumn) element; - return buildJoinColumnLabel(joinColumn); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() { - return new OverrideDefaultJoinColumnHolder(); - } - - 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; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - editPrimaryKeyJoinColumn(listSelectionModel); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - removePrimaryKeyJoinColumn(listSelectionModel); - } - }; - } - - private WritablePropertyValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnHolder() { - return new SimplePropertyValueModel<PrimaryKeyJoinColumn>(); - } - - private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListHolder() { - List<ListValueModel<PrimaryKeyJoinColumn>> list = new ArrayList<ListValueModel<PrimaryKeyJoinColumn>>(); - list.add(buildSpecifiedJoinColumnsListHolder()); - list.add(buildDefaultJoinColumnListHolder()); - return new CompositeListValueModel<ListValueModel<PrimaryKeyJoinColumn>, PrimaryKeyJoinColumn>(list); - } - - private ListValueModel<PrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnsListModel() { - return new ItemPropertyListValueModelAdapter<PrimaryKeyJoinColumn>( - buildPrimaryKeyJoinColumnsListHolder(), - NamedColumn.SPECIFIED_NAME_PROPERTY, - NamedColumn.DEFAULT_NAME_PROPERTY, - BaseJoinColumn.SPECIFIED_REFERENCED_COLUMN_NAME_PROPERTY, - BaseJoinColumn.DEFAULT_REFERENCED_COLUMN_NAME_PROPERTY - ); - } - - private ListValueModel<PrimaryKeyJoinColumn> buildSpecifiedJoinColumnsListHolder() { - return new ListAspectAdapter<SecondaryTable, PrimaryKeyJoinColumn>(getSubjectHolder(), SecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) { - @Override - protected ListIterator<PrimaryKeyJoinColumn> listIterator_() { - return subject.specifiedPrimaryKeyJoinColumns(); - } - - @Override - protected int size_() { - return subject.specifiedPrimaryKeyJoinColumnsSize(); - } - }; - } - - private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { - - PrimaryKeyJoinColumn joinColumn = (PrimaryKeyJoinColumn) listSelectionModel.selectedValue(); - - PrimaryKeyJoinColumnInSecondaryTableDialog dialog = - new PrimaryKeyJoinColumnInSecondaryTableDialog( - shell(), - subject(), - joinColumn - ); - - dialog.openDialog(buildEditPrimaryKeyJoinColumnPostExecution()); - } - - private void editPrimaryKeyJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - joinColumnHolder = buildPrimaryKeyJoinColumnHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Primary Key Join Columns group pane - Group groupPane = buildTitledPane( - container, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn - ); - - // Override Default check box - Button button = buildCheckBox( - buildSubPane(groupPane, 8), - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, - buildOverrideDefaultJoinColumnHolder() - ); - - installOverrideDefaultButtonEnabler(button); - - // Primary Key Join Columns list pane - AddRemoveListPane<SecondaryTable> joinColumnsPane = new AddRemoveListPane<SecondaryTable>( - this, - groupPane, - buildPrimaryKeyJoinColumnAdapter(), - buildPrimaryKeyJoinColumnsListModel(), - joinColumnHolder, - buildJoinColumnsListLabelProvider(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS - ); - - installPrimaryKeyJoinColumnListPaneEnabler(joinColumnsPane); - } - - private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) { - - new ControlEnabler( - buildControlBooleanHolder(), - overrideDefaultButton - ); - } - - private void installPrimaryKeyJoinColumnListPaneEnabler(AddRemoveListPane<SecondaryTable> pkJoinColumnListPane) { - - new PaneEnabler( - buildOverrideDefaultJoinColumnHolder(), - pkJoinColumnListPane - ); - } - - private void removePrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { - int[] selectedIndices = listSelectionModel.selectedIndices(); - - for (int index = selectedIndices.length; --index >= 0; ) { - subject().removeSpecifiedPrimaryKeyJoinColumn(selectedIndices[index]); - } - } - - private void updateJoinColumns(boolean selected) { - - if (isPopulating()) { - return; - } - - setPopulating(true); - - try { - SecondaryTable secondaryTable = subject(); - - // Add a join column by creating a specified one using the default - // one if it exists - if (selected) { - - PrimaryKeyJoinColumn defaultJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - - if (defaultJoinColumn != null) { - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - PrimaryKeyJoinColumn pkJoinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - - joinColumnHolder.setValue(pkJoinColumn); - } - } - else { - for (int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(index); - } - } - } - finally { - setPopulating(false); - } - } - - private class OverrideDefaultJoinColumnHolder extends ListPropertyValueModelAdapter<Boolean> - implements WritablePropertyValueModel<Boolean> { - - public OverrideDefaultJoinColumnHolder() { - super(buildSpecifiedJoinColumnsListHolder()); - } - - @Override - protected Boolean buildValue() { - if (subject() == null) { - return Boolean.FALSE; - } - return !subject().isVirtual() && listHolder.size() > 0; - } - - public void setValue(Boolean value) { - updateJoinColumns(value); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/QueriesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/QueriesComposite.java deleted file mode 100644 index 490cb27c25..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/QueriesComposite.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHolder; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.util.ControlSwitcher; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; -import org.eclipse.jpt.ui.internal.widgets.NewNameDialog; -import org.eclipse.jpt.ui.internal.widgets.NewNameDialogBuilder; -import org.eclipse.jpt.ui.internal.widgets.PostExecution; -import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.part.PageBook; - -/** - * This pane shows the list of named queries and named native queries. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | NamedQueryPropertyComposite or NamedNativeQueryPropertyComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Entity - * @see Query - * @see NamedNativeQuery - * @see NamedQuery - * @see AbstractEntityComposite - The parent container - * @see NamedNativeQueryPropertyComposite - * @see NamedQueryPropertyComposite - * - * @version 2.0 - * @since 2.0 - */ -public class QueriesComposite extends AbstractPane<QueryHolder> -{ - private AddRemoveListPane<QueryHolder> listPane; - private NamedNativeQueryPropertyComposite namedNativeQueryPane; - private NamedQueryPropertyComposite namedQueryPane; - private WritablePropertyValueModel<Query> queryHolder; - - /** - * Creates a new <code>QueriesComposite</code>. - * - * @param parentPane The parent controller of this one - * @param parent The parent container - */ - public QueriesComposite(AbstractPane<? extends QueryHolder> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private void addNamedNativeQuery(ObjectListSelectionModel listSelectionModel) { - - NewNameDialogBuilder builder = new NewNameDialogBuilder(shell()); - builder.setDialogTitle(JptUiMappingsMessages.QueriesComposite_addNamedNativeQueryTitle); - builder.setDescription(JptUiMappingsMessages.QueriesComposite_addNamedNativeQueryDescription); - builder.setDescriptionTitle(JptUiMappingsMessages.QueriesComposite_addNamedNativeQueryDescriptionTitle); - builder.setLabelText(JptUiMappingsMessages.QueriesComposite_label); - builder.setExistingNames(namedNativeQueryNames()); - - NewNameDialog dialog = builder.buildDialog(); - dialog.openDialog(buildNewNamedNativeQueryPostExecution(listSelectionModel)); - } - - private void addNamedQuery(ObjectListSelectionModel listSelectionModel) { - - NewNameDialogBuilder builder = new NewNameDialogBuilder(shell()); - builder.setDialogTitle(JptUiMappingsMessages.QueriesComposite_addNamedQueryTitle); - builder.setDescription(JptUiMappingsMessages.QueriesComposite_addNamedQueryDescription); - builder.setDescriptionTitle(JptUiMappingsMessages.QueriesComposite_addNamedQueryDescriptionTitle); - builder.setLabelText(JptUiMappingsMessages.QueriesComposite_label); - builder.setExistingNames(namedQueryNames()); - - NewNameDialog dialog = builder.buildDialog(); - dialog.openDialog(buildNewNamedQueryPostExecution(listSelectionModel)); - } - - private ListValueModel<Query> buildDisplayableQueriesListHolder() { - return new ItemPropertyListValueModelAdapter<Query>( - buildQueriesListHolder(), - Query.NAME_PROPERTY - ); - } - - private PostExecution<NewNameDialog> buildEditNamedQueryPostExecution() { - return new PostExecution<NewNameDialog>() { - public void execute(NewNameDialog dialog) { - if (dialog.wasConfirmed()) { - Query query = queryHolder.getValue(); - query.setName(dialog.getName()); - } - } - }; - } - - private AddRemoveListPane<QueryHolder> buildListPane(Composite container) { - - return new AddRemoveListPane<QueryHolder>( - this, - container, - buildQueriesAdapter(), - buildDisplayableQueriesListHolder(), - queryHolder, - buildQueriesListLabelProvider(), - JpaHelpContextIds.MAPPING_NAMED_QUERIES - ) - { - @Override - protected void addCustomButtonAfterAddButton(Composite container, - String helpId) { - - Button button = buildButton( - container, - JptUiMappingsMessages.QueriesComposite_addNamedNativeQuery, - helpId, - buildNewNamedNativeQueryAction(getSelectionModel()) - ); - - addAlignRight(button); - } - }; - } - - private ListValueModel<NamedNativeQuery> buildNamedNativeQueriesListHolder() { - return new ListAspectAdapter<QueryHolder, NamedNativeQuery>( - getSubjectHolder(), - QueryHolder.NAMED_NATIVE_QUERIES_LIST) - { - @Override - protected ListIterator<NamedNativeQuery> listIterator_() { - return subject.namedNativeQueries(); - } - - @Override - protected int size_() { - return subject.namedNativeQueriesSize(); - } - }; - } - - private PropertyValueModel<NamedNativeQuery> buildNamedNativeQueryHolder() { - return new TransformationPropertyValueModel<Query, NamedNativeQuery>(queryHolder) { - @Override - protected NamedNativeQuery transform_(Query value) { - return (value instanceof NamedNativeQuery) ? (NamedNativeQuery) value : null; - } - }; - } - - private ListValueModel<NamedQuery> buildNamedQueriesListHolder() { - return new ListAspectAdapter<QueryHolder, NamedQuery>( - getSubjectHolder(), - QueryHolder.NAMED_QUERIES_LIST) - { - @Override - protected ListIterator<NamedQuery> listIterator_() { - return subject.namedQueries(); - } - - @Override - protected int size_() { - return subject.namedQueriesSize(); - } - }; - } - - private PropertyValueModel<NamedQuery> buildNamedQueryHolder() { - return new TransformationPropertyValueModel<Query, NamedQuery>(queryHolder) { - @Override - protected NamedQuery transform_(Query value) { - return (value instanceof NamedQuery) ? (NamedQuery) value : null; - } - }; - } - - protected Runnable buildNewNamedNativeQueryAction(final ObjectListSelectionModel selectionModel) { - return new Runnable() { - public void run() { - addNamedNativeQuery(selectionModel); - } - }; - } - - private PostExecution<NewNameDialog> buildNewNamedNativeQueryPostExecution(final ObjectListSelectionModel listSelectionModel) { - return new PostExecution<NewNameDialog>() { - public void execute(NewNameDialog dialog) { - if (dialog.wasConfirmed()) { - NamedNativeQuery namedNativeQuery = subject().addNamedNativeQuery(subject().namedNativeQueriesSize()); - namedNativeQuery.setName(dialog.getName()); - queryHolder.setValue(namedNativeQuery); - listSelectionModel.setSelectedValue(namedNativeQuery); - } - } - }; - } - - private PostExecution<NewNameDialog> buildNewNamedQueryPostExecution(final ObjectListSelectionModel selectionModel) { - return new PostExecution<NewNameDialog>() { - public void execute(NewNameDialog dialog) { - if (dialog.wasConfirmed()) { - Query query = subject().addNamedQuery(subject().namedQueriesSize()); - query.setName(dialog.getName()); - queryHolder.setValue(query); - selectionModel.setSelectedValue(query); - } - } - }; - } - - private Transformer<Query, Control> buildPaneTransformer() { - return new Transformer<Query, Control>() { - public Control transform(Query query) { - - if (query == null) { - return null; - } - - if (query instanceof NamedNativeQuery) { - return namedNativeQueryPane.getControl(); - } - - return namedQueryPane.getControl(); - } - }; - } - private Adapter buildQueriesAdapter() { - - return new AddRemoveListPane.AbstractAdapter() { - - @Override - public String addButtonText() { - return JptUiMappingsMessages.QueriesComposite_addNamedQuery; - } - - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - addNamedQuery(listSelectionModel); - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiMappingsMessages.QueriesComposite_edit; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - editQuery(listSelectionModel); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - for (Object item : listSelectionModel.selectedValues()) { - if (item instanceof NamedQuery) { - subject().removeNamedQuery((NamedQuery) item); - } - else { - subject().removeNamedNativeQuery((NamedNativeQuery) item); - } - } - } - }; - } - - private ListValueModel<Query> buildQueriesListHolder() { - List<ListValueModel<? extends Query>> list = new ArrayList<ListValueModel<? extends Query>>(); - list.add(buildNamedQueriesListHolder()); - list.add(buildNamedNativeQueriesListHolder()); - return new CompositeListValueModel<ListValueModel<? extends Query>, Query>(list); - } - - private ILabelProvider buildQueriesListLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - Query query = (Query) element; - String name = query.getName(); - - if (name == null) { - int index = -1; - - if (query instanceof NamedQuery) { - index = CollectionTools.indexOf(subject().namedQueries(), query); - } - else { - index = CollectionTools.indexOf(subject().namedNativeQueries(), query); - } - - name = NLS.bind(JptUiMappingsMessages.QueriesComposite_displayString, index); - } - - return name; - } - }; - } - - private WritablePropertyValueModel<Query> buildQueryHolder() { - return new SimplePropertyValueModel<Query>(); - } - - private void editQuery(ObjectListSelectionModel listSelectionModel) { - - Query query = queryHolder.getValue(); - - NewNameDialogBuilder builder = new NewNameDialogBuilder(shell()); - builder.setLabelText(JptUiMappingsMessages.QueriesComposite_label); - builder.setName(query.getName()); - - if (query instanceof NamedNativeQuery) { - builder.setDialogTitle(JptUiMappingsMessages.QueriesComposite_editNamedNativeQueryTitle); - builder.setDescription(JptUiMappingsMessages.QueriesComposite_editNamedNativeQueryDescription); - builder.setDescriptionTitle(JptUiMappingsMessages.QueriesComposite_editNamedNativeQueryDescriptionTitle); - builder.setExistingNames(namedNativeQueryNames()); - } - else { - builder.setDialogTitle(JptUiMappingsMessages.QueriesComposite_editNamedQueryTitle); - builder.setDescription(JptUiMappingsMessages.QueriesComposite_editNamedQueryDescription); - builder.setDescriptionTitle(JptUiMappingsMessages.QueriesComposite_editNamedQueryDescriptionTitle); - builder.setExistingNames(namedQueryNames()); - } - - NewNameDialog dialog = builder.buildDialog(); - dialog.openDialog(buildEditNamedQueryPostExecution()); - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - super.enableWidgets(enabled); - listPane.enableWidgets(enabled); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - queryHolder = buildQueryHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // List pane - listPane = buildListPane(container); - - // Property pane - PageBook pageBook = new PageBook(container, SWT.NULL); - pageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Named Query property pane - namedQueryPane = new NamedQueryPropertyComposite( - this, - buildNamedQueryHolder(), - pageBook - ); - - // Named Native Query property pane - namedNativeQueryPane = new NamedNativeQueryPropertyComposite( - this, - buildNamedNativeQueryHolder(), - pageBook - ); - - installPaneSwitcher(pageBook); - } - - private void installPaneSwitcher(PageBook pageBook) { - new ControlSwitcher(queryHolder, buildPaneTransformer(), pageBook); - } - - private Iterator<String> namedNativeQueryNames() { - return new TransformationIterator<Query, String>(subject().namedNativeQueries()) { - @Override - protected String transform(Query next) { - return next.getName(); - } - }; - } - - private Iterator<String> namedQueryNames() { - return new TransformationIterator<Query, String>(subject().namedQueries()) { - @Override - protected String transform(Query next) { - return next.getName(); - } - }; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/QueryHintsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/QueryHintsComposite.java deleted file mode 100644 index acb346e8e9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/QueryHintsComposite.java +++ /dev/null @@ -1,340 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.ListIterator; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.swt.ColumnAdapter; -import org.eclipse.jpt.ui.internal.util.PaneEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveTablePane; -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.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | AddRemoveTablePane | - * | | - * -----------------------------------------------------------------------------</pre> - * - * @see Query - * @see QueryHint - * @see AddRemoveTablePane - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class QueryHintsComposite extends AbstractPane<Query> -{ - private WritablePropertyValueModel<QueryHint> queryHintHolder; - - /** - * Creates a new <code>QueryHintsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public QueryHintsComposite(AbstractPane<? extends Query> parentPane, - Composite container) { - - super(parentPane, container); - } - - private PropertyValueModel<Boolean> buildPaneEnableHolder() { - return new TransformationPropertyValueModel<Query, Boolean>(getSubjectHolder()) { - @Override - protected Boolean transform(Query query) { - return (query != null); - } - }; - } - - private Adapter buildQueryHintAdapter() { - return new AddRemoveTablePane.AbstractAdapter() { - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - QueryHint queryHint = subject().addHint(subject().hintsSize()); - queryHintHolder.setValue(queryHint); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - for (Object item : listSelectionModel.selectedValues()) { - subject().removeHint((QueryHint) item); - } - } - }; - } - - private WritablePropertyValueModel<QueryHint> buildQueryHintHolder() { - return new SimplePropertyValueModel<QueryHint>(); - }; - - private ITableLabelProvider buildQueryHintLabelProvider() { - return new TableLabelProvider(); - } - - private ListValueModel<QueryHint> buildQueryHintListHolder() { - return new ListAspectAdapter<Query, QueryHint>(getSubjectHolder(), NamedQuery.HINTS_LIST) { - @Override - protected ListIterator<QueryHint> listIterator_() { - return subject.hints(); - } - - @Override - protected int size_() { - return subject.hintsSize(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - queryHintHolder = buildQueryHintHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - TablePane tablePane = new TablePane(container); - installPaneEnabler(tablePane); - } - - private PaneEnabler installPaneEnabler(TablePane tablePane) { - return new PaneEnabler(buildPaneEnableHolder(), tablePane); - } - - private static class QueryHintColumnAdapter implements ColumnAdapter<QueryHint> { - - static final int COLUMN_COUNT = 2; - static final int NAME_COLUMN_INDEX = 0; - static final int VALUE_COLUMN_INDEX = 1; - - private WritablePropertyValueModel<String> buildNameHolder(QueryHint subject) { - return new PropertyAspectAdapter<QueryHint, String>(QueryHint.NAME_PROPERTY, subject) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<?> buildValueHolder(QueryHint subject) { - return new PropertyAspectAdapter<QueryHint, String>(QueryHint.VALUE_PROPERTY, subject) { - @Override - protected String buildValue_() { - return subject.getValue(); - } - - @Override - protected void setValue_(String value) { - subject.setValue(value); - } - }; - } - - public WritablePropertyValueModel<?>[] cellModels(QueryHint subject) { - WritablePropertyValueModel<?>[] models = new WritablePropertyValueModel<?>[COLUMN_COUNT]; - models[NAME_COLUMN_INDEX] = buildNameHolder(subject); - models[VALUE_COLUMN_INDEX] = buildValueHolder(subject); - return models; - } - - public int columnCount() { - return COLUMN_COUNT; - } - - public String columnName(int columnIndex) { - - switch (columnIndex) { - case QueryHintColumnAdapter.NAME_COLUMN_INDEX: { - return JptUiMappingsMessages.QueryHintsComposite_nameColumn; - } - - case QueryHintColumnAdapter.VALUE_COLUMN_INDEX: { - return JptUiMappingsMessages.QueryHintsComposite_valueColumn; - } - - default: { - return null; - } - } - } - } - - private class TableLabelProvider extends LabelProvider - implements ITableLabelProvider { - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - public String getColumnText(Object element, int columnIndex) { - - QueryHint queryHint = (QueryHint) element; - String value = ""; - - switch (columnIndex) { - case QueryHintColumnAdapter.NAME_COLUMN_INDEX: { - value = queryHint.getName(); - break; - } - - case QueryHintColumnAdapter.VALUE_COLUMN_INDEX: { - value = queryHint.getValue(); - break; - } - } - - if (value == null) { - value = ""; - } - - return value; - } - } - - private class TablePane extends AddRemoveTablePane<Query> { - - private TablePane(Composite parent) { - super(QueryHintsComposite.this, - parent, - buildQueryHintAdapter(), - buildQueryHintListHolder(), - queryHintHolder, - buildQueryHintLabelProvider()); - } - - private CellEditor[] buildCellEditors(Table table) { - return new CellEditor[] { - new TextCellEditor(table), - new TextCellEditor(table) - }; - } - - private ICellModifier buildCellModifier() { - return new ICellModifier() { - - public boolean canModify(Object element, String property) { - return true; - } - - public Object getValue(Object element, String property) { - QueryHint queryHint = (QueryHint) element; - String value = ""; - - if (property == QueryHint.NAME_PROPERTY) { - value = queryHint.getName(); - } - else if (property == QueryHint.VALUE_PROPERTY) { - value = queryHint.getValue(); - } - - if (value == null) { - value = ""; - } - - return value; - } - - public void modify(Object element, String property, Object value) { - QueryHint queryHint; - - if (element instanceof TableItem) { - TableItem tableItem = (TableItem) element; - queryHint = (QueryHint) tableItem.getData(); - } - else { - queryHint = (QueryHint) element; - } - - if (property == QueryHint.NAME_PROPERTY) { - queryHint.setName(value.toString()); - } - else if (property == QueryHint.VALUE_PROPERTY) { - queryHint.setValue(value.toString()); - } - } - }; - } - - @Override - protected ColumnAdapter<?> buildColumnAdapter() { - return new QueryHintColumnAdapter(); - } - - private String[] buildColumnProperties() { - return new String[] { - QueryHint.NAME_PROPERTY, - QueryHint.VALUE_PROPERTY - }; - } - - @Override - protected void initializeMainComposite(Composite container, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider labelProvider, - String helpId) { - - super.initializeMainComposite( - container, - adapter, - listHolder, - selectedItemHolder, - labelProvider, - helpId - ); - - Table table = getMainControl(); - - TableViewer tableViewer = new TableViewer(table); - tableViewer.setCellEditors(buildCellEditors(table)); - tableViewer.setCellModifier(buildCellModifier()); - tableViewer.setColumnProperties(buildColumnProperties()); - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index 420d28e918..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Iterator; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; -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.graphics.Point; -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.swt.widgets.Shell; - -public class SecondaryTableDialog extends Dialog { - - //if creating a new SecondaryTable, this will be null, - //specify the defaultSchema and defaultCatalog instead in the appropriate construtor - private SecondaryTable secondaryTable; - private JpaProject jpaProject; - private String defaultSchema; - private String defaultCatalog; - - protected Combo nameCombo; - protected Combo catalogCombo; - protected Combo schemaCombo; - - private String selectedName; - private String selectedSchema; - private String selectedCatalog; - - private boolean defaultSchemaSelected; - private boolean defaultCatalogSelected; - - public SecondaryTableDialog(Shell parent, JpaProject jpaProject, String defaultSchema, String defaultCatalog) { - super(parent); - this.jpaProject = jpaProject; - this.defaultSchema = defaultSchema; - this.defaultCatalog = defaultCatalog; - } - - public SecondaryTableDialog(Shell parent, SecondaryTable secondaryTable, JpaProject jpaProject) { - super(parent); - this.secondaryTable = secondaryTable; - this.jpaProject = jpaProject; - } - - @Override - protected Point getInitialSize() { - Point size = super.getInitialSize(); - size.x = convertWidthInCharsToPixels(50); - return size; - } - - @Override - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(getTitle()); - } - - protected String getTitle() { - if (this.secondaryTable != null) { - return JptUiMappingsMessages.SecondaryTableDialog_editSecondaryTable; - } - return JptUiMappingsMessages.SecondaryTableDialog_addSecondaryTable; - } - - @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; - gridData.horizontalAlignment = SWT.FILL; - this.catalogCombo.setLayoutData(gridData); - populateCatalogCombo(); - - Label schemaLabel = new Label(composite, SWT.LEFT); - schemaLabel.setText(JptUiMappingsMessages.SecondaryTableDialog_schema); - gridData = new GridData(); - schemaLabel.setLayoutData(gridData); - - this.schemaCombo = new Combo(composite, SWT.LEFT); - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - this.schemaCombo.setLayoutData(gridData); - populateSchemaCombo(); - - - this.schemaCombo.addSelectionListener(new SelectionListener() { - - public void widgetSelected(SelectionEvent e) { - repopulateNameCombo(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - repopulateNameCombo(); - } - }); - - return composite; - } - - protected Database getDatabase() { - return this.getConnectionProfile().getDatabase(); - } - - private ConnectionProfile getConnectionProfile() { - return this.jpaProject.getConnectionProfile(); - } - - protected Schema getDefaultTableSchema() { - if (this.secondaryTable != null) { - return getTableSchema(this.secondaryTable.getDefaultSchema()); - } - return getTableSchema(this.defaultSchema); - } - - - protected Schema getTableSchema() { - if (this.secondaryTable != null) { - return getTableSchema(this.secondaryTable.getSchema()); - } - return getTableSchema(this.defaultSchema); - } - - protected Schema getTableSchema(String schemaName) { - Database database = this.getDatabase(); - if (database != null) { - return database.schemaNamed(schemaName); - } - return null; - } - - protected void populateNameCombo() { - Schema schema = this.getTableSchema(); - if (schema != null) { - Iterator<String> tables = schema.tableNames(); - for (Iterator<String> stream = CollectionTools.sort( tables); stream.hasNext(); ) { - this.nameCombo.add(stream.next()); - } - } - - if (getSecondaryTable() != null) { - if (getSecondaryTable().getSpecifiedName() != null) { - this.nameCombo.setText(getSecondaryTable().getSpecifiedName()); - } - } - } - - protected void repopulateNameCombo() { - String nameText = this.nameCombo.getText(); - this.nameCombo.removeAll(); - - Schema schema = null; - if (this.schemaCombo.getSelectionIndex() == 0) { - schema = this.getDefaultTableSchema(); - } - else if (this.schemaCombo.getText() != null) { - schema = this.getTableSchema(this.schemaCombo.getText()); - } - else { - schema = this.getTableSchema(); - } - - if (schema != null) { - Iterator<String> tables = schema.tableNames(); - for (Iterator<String> stream = CollectionTools.sort( tables); stream.hasNext(); ) { - this.nameCombo.add(stream.next()); - } - } - - this.nameCombo.setText(nameText); - } - - protected void populateSchemaCombo() { - String defaultSchema; - if (getSecondaryTable() != null) { - defaultSchema = getSecondaryTable().getDefaultSchema(); - } - else { - defaultSchema = this.defaultSchema; - } - if (defaultSchema != null) { - this.schemaCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultSchema, defaultSchema)); - } - Database database = this.getDatabase(); - - if (database != null) { - Iterator<String> schemata = database.schemaNames(); - for (Iterator<String> stream = CollectionTools.sort(schemata); stream.hasNext(); ) { - this.schemaCombo.add(stream.next()); - } - } - - if (getSecondaryTable() != null) { - if (getSecondaryTable().getSpecifiedSchema() != null) { - this.schemaCombo.setText(getSecondaryTable().getSpecifiedSchema()); - } - else { - this.schemaCombo.select(0); - } - } - else { - this.schemaCombo.select(0); - } - } - - protected void populateCatalogCombo() { - String defaultCatalog; - if (getSecondaryTable() != null) { - defaultCatalog = getSecondaryTable().getDefaultCatalog(); - } - else { - defaultCatalog = this.defaultCatalog; - } - if (defaultCatalog != null) { - this.catalogCombo.add(NLS.bind(JptUiMappingsMessages.SecondaryTableDialog_defaultCatalog, defaultCatalog)); - } - - Database database = this.getDatabase(); - - if (database != null) { - Iterator<String> catalogs = database.catalogNames(); - for (Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext(); ) { - this.catalogCombo.add(stream.next()); - } - } - - if (getSecondaryTable() != null) { - if (getSecondaryTable().getSpecifiedCatalog() != null) { - this.catalogCombo.setText(getSecondaryTable().getSpecifiedCatalog()); - } - else { - this.catalogCombo.select(0); - } - } - else { - this.catalogCombo.select(0); - } - } - - protected Combo getNameCombo() { - return this.nameCombo; - } - - protected Combo getSchemaCombo() { - return this.schemaCombo; - } - - protected Combo getCatalogCombo() { - return this.catalogCombo; - } - - protected SecondaryTable getSecondaryTable() { - return this.secondaryTable; - } - - - public String getSelectedName() { - return this.selectedName; - } - - public String getSelectedCatalog() { - return this.selectedCatalog; - } - - public String getSelectedSchema() { - return this.selectedSchema; - } - - public boolean isDefaultSchemaSelected() { - return this.defaultSchemaSelected; - } - - public boolean isDefaultCatalogSelected() { - return this.defaultCatalogSelected; - } - - @Override - public boolean close() { - this.selectedName = this.nameCombo.getText(); - this.selectedSchema = this.schemaCombo.getText(); - if (this.selectedSchema.equals("")) { - this.selectedSchema = null; - } - this.selectedCatalog = this.catalogCombo.getText(); - if (this.selectedCatalog.equals("")) { - this.selectedCatalog = null; - } - this.defaultSchemaSelected = this.schemaCombo.getSelectionIndex() == 0; - this.defaultCatalogSelected = this.catalogCombo.getSelectionIndex() == 0; - return super.close(); - } -} 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 deleted file mode 100644 index 89a0336f9f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.GeneratorHolder; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.db.SequenceCombo; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ----------------------------------------------------- | - * | Name: | I | | - * | ----------------------------------------------------- | - * | ----------------------------------------------------- | - * | Sequence Generator: | SequenceCombo | | - * | ----------------------------------------------------- | - * | ------------- | - * | Allocation Size: | I |I| | - * | ------------- | - * | ------------- | - * | Initial Value: | |I| | - * | ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see IdMapping - * @see SequenceGenerator - * @see GenerationComposite - The parent container - * @see SequenceCombo - * - * @version 2.0 - * @since 1.0 - */ -public class SequenceGeneratorComposite extends GeneratorComposite<SequenceGenerator> -{ - /** - * Creates a new <code>SequenceGeneratorComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public SequenceGeneratorComposite(AbstractPane<? extends GeneratorHolder> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected SequenceGenerator buildGenerator(GeneratorHolder subject) { - return subject.addSequenceGenerator(); - } - - private PropertyValueModel<SequenceGenerator> buildSequenceGeneratorHolder() { - return new PropertyAspectAdapter<GeneratorHolder, SequenceGenerator>(getSubjectHolder(), GeneratorHolder.SEQUENCE_GENERATOR_PROPERTY) { - @Override - protected SequenceGenerator buildValue_() { - return subject.getSequenceGenerator(); - } - }; - } - - private SequenceCombo<SequenceGenerator> buildSequenceNameCombo(Composite parent) { - - return new SequenceCombo<SequenceGenerator>(this, buildSequenceGeneratorHolder(), parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(SequenceGenerator.DEFAULT_SEQUENCE_NAME_PROPERTY); - propertyNames.add(SequenceGenerator.SPECIFIED_SEQUENCE_NAME_PROPERTY); - } - - @Override - protected void buildSubject() { - SequenceGeneratorComposite.this.buildGenerator( - SequenceGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultSequenceName(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return SequenceGeneratorComposite.this.jpaProject(); - } - - @Override - protected Schema schema() { - // TODO - return null; - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedSequenceName(value); - } - - @Override - protected String value() { - SequenceGenerator generator = generator(); - - if (generator != null) { - return generator.getSpecifiedSequenceName(); - } - - return null; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected SequenceGenerator generator(GeneratorHolder subject) { - return subject.getSequenceGenerator(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Name widgets - buildLabeledText( - container, - JptUiMappingsMessages.SequenceGeneratorComposite_name, - buildGeneratorNameHolder(), - JpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_NAME - ); - - // Sequence Generator widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.SequenceGeneratorComposite_sequence, - buildSequenceNameCombo(container), - JpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_SEQUENCE - ); - - // Allocation Size widgets - initializeAllocationSizeWidgets(container); - - // Initial Value widgets - initializeInitialValueWidgets(container); - } - - /* - * (non-Javadoc) - */ - @Override - protected String propertyName() { - return GeneratorHolder.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/TableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java deleted file mode 100644 index 62bdcad402..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -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.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | - Table ----------------------------------------------------------------- | - * | | ------------------------------------------------------------ | | - * | | Table: | TableCombo | | | - * | | ------------------------------------------------------------ | | - * | | ------------------------------------------------------------ | | - * | | Catalog: | CatalogCombo | | | - * | | ------------------------------------------------------------ | | - * | | ------------------------------------------------------------ | | - * | | Schema: | SchemaCombo | | | - * | | ------------------------------------------------------------ | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see Table - * @see EntityComposite - The parent container - * @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<Table> -{ - /** - * 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 Table> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * 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 Table> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private CatalogCombo<Table> buildCatalogCombo(Composite container) { - - return new CatalogCombo<Table>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Table.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(Table.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(); - } - }; - } - - private SchemaCombo<Table> buildSchemaCombo(Composite container) { - - return new SchemaCombo<Table>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Table.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(Table.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(); - } - }; - } - - private TableCombo<Table> buildTableCombo(Composite container) { - - return new TableCombo<Table>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(Table.DEFAULT_NAME_PROPERTY); - propertyNames.add(Table.SPECIFIED_NAME_PROPERTY); - propertyNames.add(Table.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(Table.SPECIFIED_SCHEMA_PROPERTY); - propertyNames.add(Table.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(Table.SPECIFIED_CATALOG_PROPERTY); - } - - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - if (propertyName == Table.DEFAULT_SCHEMA_PROPERTY - || propertyName == Table.SPECIFIED_SCHEMA_PROPERTY - || propertyName == Table.DEFAULT_CATALOG_PROPERTY - || propertyName == Table.SPECIFIED_CATALOG_PROPERTY ) { - repopulate(); - } - } - - @Override - protected String defaultValue() { - return subject().getDefaultName(); - } - - @Override - protected String schemaName() { - return subject().getSchema(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedName(value); - } - - @Override - protected org.eclipse.jpt.db.Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedName(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Table group pane - Group tableGroupPane = buildTitledPane( - container, - JptUiMappingsMessages.TableComposite_tableSection - ); - - // Table widgets - buildLabeledComposite( - tableGroupPane, - JptUiMappingsMessages.TableChooser_label, - buildTableCombo(tableGroupPane), - JpaHelpContextIds.ENTITY_TABLE - ); - - // Catalog widgets - buildLabeledComposite( - tableGroupPane, - JptUiMappingsMessages.CatalogChooser_label, - buildCatalogCombo(tableGroupPane), - JpaHelpContextIds.ENTITY_CATALOG - ); - - // Schema widgets - buildLabeledComposite( - tableGroupPane, - JptUiMappingsMessages.SchemaChooser_label, - buildSchemaCombo(tableGroupPane), - JpaHelpContextIds.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 deleted file mode 100644 index 3732245bff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java +++ /dev/null @@ -1,503 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.GeneratorHolder; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.db.CatalogCombo; -import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; -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.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ----------------------------------------------- | - * | Name: | I | | - * | ----------------------------------------------- | - * | ----------------------------------------------- | - * | Table: | TableCombo | | - * | ----------------------------------------------- | - * | ----------------------------------------------- | - * | Catalog: | CatalogCombo | | - * | ----------------------------------------------- | - * | ----------------------------------------------- | - * | Schema: | SchemaCombo | | - * | ----------------------------------------------- | - * | ----------------------------------------------- | - * | Primary Key Column: | ColumnCombo | | - * | ----------------------------------------------- | - * | ----------------------------------------------- | - * | Value Column: | ColumnCombo | | - * | ----------------------------------------------- | - * | ----------------------------------------------- | - * | Primary Key Column Value: | ColumnCombo | | - * | ----------------------------------------------- | - * | ------------- | - * | Allocation Size: | I |I| Default (XXX) | - * | ------------- | - * | ------------- | - * | Initial Value: | I |I| Default (XXX) | - * | ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see IdMapping - * @see TableGenerator - * @see GenerationComposite - The parent container - * @see CatalogCombo - * @see ColumnCombo - * @see SchemaCombo - * @see TableCombo - * - * @version 2.0 - * @since 1.0 - */ -public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> -{ - /** - * Creates a new <code>TableGeneratorComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public TableGeneratorComposite(AbstractPane<? extends GeneratorHolder> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private CatalogCombo<TableGenerator> buildCatalogCombo(Composite container) { - - return new CatalogCombo<TableGenerator>(this, buildTableGeneratorHolder(), container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_CATALOG_PROPERTY); - } - - @Override - protected void buildSubject() { - TableGeneratorComposite.this.buildGenerator( - TableGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultCatalog(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return TableGeneratorComposite.this.jpaProject(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedCatalog(value); - } - - @Override - protected String value() { - return subject().getSpecifiedCatalog(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected TableGenerator buildGenerator(GeneratorHolder subject) { - return subject.addTableGenerator(); - } - - private ColumnCombo<TableGenerator> buildPkColumnNameCombo(Composite parent) { - - return new ColumnCombo<TableGenerator>(this, buildTableGeneratorHolder(), parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_PK_COLUMN_NAME_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_PK_COLUMN_NAME_PROPERTY); - } - - @Override - protected void buildSubject() { - TableGeneratorComposite.this.buildGenerator( - TableGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultPkColumnName(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return TableGeneratorComposite.this.jpaProject(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedPkColumnName(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedPkColumnName(); - } - }; - } - - private ColumnCombo<TableGenerator> buildPkColumnValueCombo(Composite parent) { - - return new ColumnCombo<TableGenerator>(this, buildTableGeneratorHolder(), parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_PK_COLUMN_VALUE_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_PK_COLUMN_VALUE_PROPERTY); - } - - @Override - protected void buildSubject() { - TableGeneratorComposite.this.buildGenerator( - TableGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultPkColumnValue(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return TableGeneratorComposite.this.jpaProject(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedPkColumnValue(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedPkColumnValue(); - } - }; - } - - private SchemaCombo<TableGenerator> buildSchemaCombo(Composite container) { - - return new SchemaCombo<TableGenerator>(this, buildTableGeneratorHolder(), container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_SCHEMA_PROPERTY); - } - - @Override - protected void buildSubject() { - TableGeneratorComposite.this.buildGenerator( - TableGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultSchema(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return TableGeneratorComposite.this.jpaProject(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedSchema(value); - } - - @Override - protected String value() { - return subject().getSpecifiedSchema(); - } - }; - } - - private PropertyValueModel<TableGenerator> buildTableGeneratorHolder() { - return new PropertyAspectAdapter<GeneratorHolder, TableGenerator>(getSubjectHolder(), GeneratorHolder.TABLE_GENERATOR_PROPERTY) { - @Override - protected TableGenerator buildValue_() { - return subject.getTableGenerator(); - } - }; - } - - private TableCombo<TableGenerator> buildTableNameCombo(Composite parent) { - - return new TableCombo<TableGenerator>(this, buildTableGeneratorHolder(), parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_TABLE_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_TABLE_PROPERTY); - propertyNames.add(TableGenerator.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_SCHEMA_PROPERTY); - propertyNames.add(TableGenerator.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_CATALOG_PROPERTY); - } - - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - if (propertyName == TableGenerator.DEFAULT_SCHEMA_PROPERTY - || propertyName == TableGenerator.SPECIFIED_SCHEMA_PROPERTY - || propertyName == TableGenerator.DEFAULT_CATALOG_PROPERTY - || propertyName == TableGenerator.SPECIFIED_CATALOG_PROPERTY ) { - repopulate(); - } - } - - @Override - protected void buildSubject() { - TableGeneratorComposite.this.buildGenerator( - TableGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultTable(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return TableGeneratorComposite.this.jpaProject(); - } - - @Override - protected String schemaName() { - if (subject() != null) { - return subject().getSchema(); - } - if (TableGeneratorComposite.this.subject().getEntityMappings() != null) { - return TableGeneratorComposite.this.subject().getEntityMappings().getSchema(); - } - return TableGeneratorComposite.this.subject().getPersistenceUnit().getDefaultSchema(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedTable(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedTable(); - } - }; - } - - private ColumnCombo<TableGenerator> buildValueColumnCombo(Composite parent) { - - return new ColumnCombo<TableGenerator>(this, buildTableGeneratorHolder(), parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_VALUE_COLUMN_NAME_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_VALUE_COLUMN_NAME_PROPERTY); - } - - @Override - protected void buildSubject() { - TableGeneratorComposite.this.buildGenerator( - TableGeneratorComposite.this.subject() - ); - } - - @Override - protected String defaultValue() { - return subject().getDefaultValueColumnName(); - } - - @Override - protected boolean isBuildSubjectAllowed() { - return true; - } - - @Override - protected JpaProject jpaProject() { - return TableGeneratorComposite.this.jpaProject(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedValueColumnName(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedValueColumnName(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected TableGenerator generator(GeneratorHolder subject) { - return (subject != null) ? subject.getTableGenerator() : null; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Name widgets - buildLabeledText( - container, - JptUiMappingsMessages.TableGeneratorComposite_name, - buildGeneratorNameHolder(), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_NAME - ); - - // Table widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.TableGeneratorComposite_table, - buildTableNameCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_TABLE - ); - - // Schema widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.TableGeneratorComposite_schema, - buildSchemaCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_SCHEMA - ); - - // Catalog widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.TableGeneratorComposite_catalog, - buildCatalogCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_CATALOG - ); - - // Primary Key Column widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.TableGeneratorComposite_pkColumn, - buildPkColumnNameCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN - ); - - // Value Column widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.TableGeneratorComposite_valueColumn, - buildValueColumnCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_VALUE_COLUMN - ); - - // Primary Key Column Value widgets - buildLabeledComposite( - container, - JptUiMappingsMessages.TableGeneratorComposite_pkColumnValue, - buildPkColumnValueCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE - ); - - // Allocation Size widgets - initializeAllocationSizeWidgets(container); - - // Initial Value widgets - initializeInitialValueWidgets(container); - } - - /* - * (non-Javadoc) - */ - @Override - protected String propertyName() { - return GeneratorHolder.TABLE_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/TargetEntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityComposite.java deleted file mode 100644 index d4f03d87e0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TargetEntityComposite.java +++ /dev/null @@ -1,347 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.util.Collection; -import org.eclipse.jdt.core.IJavaElement; -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.context.RelationshipMapping; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -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.StringTools; -import org.eclipse.jpt.utility.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.graphics.Point; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PartInitException; -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: | I |v| | Browse... | | - * | ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ -------------------------------------------- ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see RelationshipMapping - * @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 - */ -@SuppressWarnings("nls") -public class TargetEntityComposite extends AbstractFormPane<RelationshipMapping> -{ - private CCombo combo; - - /** - * Creates a new <code>TargetEntityComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public TargetEntityComposite(AbstractFormPane<? extends RelationshipMapping> 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 RelationshipMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(RelationshipMapping.DEFAULT_TARGET_ENTITY_PROPERTY); - propertyNames.add(RelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY); - } - - private Runnable buildOpenTargetEntityAction() { - return new Runnable() { - public void run() { - TargetEntityComposite.this.openEditor(); - } - }; - } - - private Runnable buildOpenTypeAction() { - return new Runnable() { - public void run() { - BusyIndicator.showWhile(combo.getDisplay(), new Runnable() { - public void run() { - doOpenSelectionDialog(); - } - }); - } - }; - } - - private ModifyListener buildTargetEntityModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (!isPopulating()) { - CCombo combo = (CCombo) e.widget; - if (combo.getData("populating") != Boolean.TRUE) {//check !TRUE because null is a possibility as well - valueChanged(combo.getText()); - } - } - } - }; - } - - 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.combo.setText(type.getFullyQualifiedName('.')); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void doPopulate() { - - super.doPopulate(); - populateCombo(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - combo = buildEditableCCombo(container); - combo.add(JptUiMappingsMessages.TargetEntityChooser_defaultEmpty); - combo.addModifyListener(buildTargetEntityModifyListener()); - - SWTUtil.attachDefaultValueHandler(combo); - - Hyperlink labelLink = buildHyperLink(container, - JptUiMappingsMessages.TargetEntityChooser_label, - buildOpenTargetEntityAction() - ); - - buildLabeledComposite( - container, - labelLink, - combo, - buildTargetEntitySelectionButton(container), - JpaHelpContextIds.MAPPING_TARGET_ENTITY - ); - } - - private void openEditor() { - - String targetEntity = subject().getTargetEntity(); - - if (targetEntity != null) { - - try { - IType type = subject().getJpaProject().getJavaProject().findType(targetEntity); - - if (type != null) { - IJavaElement javaElement = type.getParent(); - JavaUI.openInEditor(javaElement, true, true); - } - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - catch (PartInitException e) { - JptUiPlugin.log(e); - } - } - } - - private void populateCombo() { - - combo.removeAll(); - populateDefaultValue(); - // TODO Add possible target entity names - updateSelectedItem(); - } - - /** - * Adds the default value to the combo if one exists. - */ - private void populateDefaultValue() { - - RelationshipMapping entity = subject(); - String defaultValue = (entity != null) ? entity.getDefaultTargetEntity() : null; - - if (defaultValue != null) { - combo.add(NLS.bind( - JptUiMappingsMessages.TargetEntityChooser_defaultWithOneParam, - defaultValue - )); - } - else { - combo.add(JptUiMappingsMessages.TargetEntityChooser_defaultEmpty); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - - if (propertyName == RelationshipMapping.DEFAULT_TARGET_ENTITY_PROPERTY || - propertyName == RelationshipMapping.SPECIFIED_TARGET_ENTITY_PROPERTY) { - - populateCombo(); - } - } - - /** - * 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() { - RelationshipMapping subject = subject(); - String value = (subject != null) ? subject.getSpecifiedTargetEntity() : null; - - if (value != null) { - combo.setText(value); - combo.setSelection(new Point(0, 0)); - } - else { - String defaultValue = (subject != null) ? subject.getDefaultTargetEntity() : null; - String displayString = JptUiMappingsMessages.TargetEntityChooser_defaultEmpty; - - if (defaultValue != null) { - displayString = NLS.bind( - JptUiMappingsMessages.ColumnComposite_defaultWithOneParam, - defaultValue - ); - } - - // Selected the default value - if (displayString != null) { - combo.select(0); - combo.setSelection(new Point(0, 0)); - } - // Remove the selection - else { - combo.select(-1); - } - } - } - - private void valueChanged(String value) { - - RelationshipMapping subject = subject(); - String oldValue = (subject != null) ? subject.getSpecifiedTargetEntity() : null; - - // Check for null value - if (StringTools.stringIsEmpty(value)) { - value = null; - - if (StringTools.stringIsEmpty(oldValue)) { - return; - } - } - - // The default value - if (value != null && - combo.getItemCount() > 0 && - value.equals(combo.getItem(0))) - { - value = null; - } - - // Nothing to change - if ((oldValue == value) && value == null) { - return; - } - - // Set the new value - if ((value != null) && (oldValue == null) || - ((oldValue != null) && !oldValue.equals(value))) { - - setPopulating(true); - - try { - subject.setSpecifiedTargetEntity(value); - } - finally { - setPopulating(false); - } - } - } -}
\ 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 deleted file mode 100644 index 7ef3e0e58a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TemporalTypeComposite.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import java.text.Collator; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import org.eclipse.jpt.core.context.ColumnMapping; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiMessages; -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.CollectionTools; -import org.eclipse.jpt.utility.internal.StringConverter; -import org.eclipse.jpt.utility.internal.model.value.ExtendedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | --------------------------------------------------------------- | - * | Temporal: | |v| | - * | --------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see ColumnMapping - * @see TemporalType - * @see BasicMappingComposite - A container of this pane - * @see IdMappingComposite - A container of this pane - * @see VersionMappingComposite - A container of this pane - * - * @version 2.0 - * @since 1.0 - */ -public class TemporalTypeComposite extends AbstractFormPane<ColumnMapping> { - - /** - * Creates a new <code>TemporalTypeComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public TemporalTypeComposite(AbstractFormPane<? extends ColumnMapping> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private ListValueModel<TemporalType> buildSortedTemporalTypeListHolder() { - List<TemporalType> types = CollectionTools.list(TemporalType.values()); - Collections.sort(types, buildTemporalTypeComparator()); - return new SimpleListValueModel<TemporalType>(types); - } - - private Comparator<TemporalType> buildTemporalTypeComparator() { - return new Comparator<TemporalType>() { - public int compare(TemporalType type1, TemporalType type2) { - String displayString1 = displayString(type1); - String displayString2 = displayString(type2); - return Collator.getInstance().compare(displayString1, displayString2); - } - }; - } - - private StringConverter<TemporalType> buildTemporalTypeConverter() { - return new StringConverter<TemporalType>() { - public String convertToString(TemporalType value) { - if (value == null) { - return JptUiMessages.EnumComboViewer_default; - } - return displayString(value); - } - }; - } - - private WritablePropertyValueModel<TemporalType> buildTemporalTypeHolder() { - return new PropertyAspectAdapter<ColumnMapping, TemporalType>(getSubjectHolder(), ColumnMapping.TEMPORAL_PROPERTY) { - @Override - protected TemporalType buildValue_() { - return subject.getTemporal(); - } - - @Override - protected void setValue_(TemporalType value) { - subject.setTemporal(value); - } - }; - } - - private ListValueModel<TemporalType> buildTemporalTypeListHolder() { - return new ExtendedListValueModelWrapper<TemporalType>( - (TemporalType) null, - buildSortedTemporalTypeListHolder() - ); - } - - private String displayString(TemporalType temporalType) { - return SWTUtil.buildDisplayString( - JptUiMappingsMessages.class, - TemporalTypeComposite.this, - temporalType.name() - ); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - buildLabeledCCombo( - container, - JptUiMappingsMessages.BasicGeneralSection_temporalLabel, - buildTemporalTypeListHolder(), - buildTemporalTypeHolder(), - buildTemporalTypeConverter(), - JpaHelpContextIds.MAPPING_TEMPORAL - ); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 0897956f8b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TransientMappingComposite.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * This pane does not have any widgets. - * - * @see TransientMapping - * @see BaseJpaUiFactory - The factory creating this pane - * - * @version 2.0 - * @since 1.0 - */ -public class TransientMappingComposite extends AbstractFormPane<TransientMapping> - implements JpaComposite<TransientMapping> -{ - /** - * 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 TransientMapping> subjectHolder, - Composite parent, - WidgetFactory 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/VersionMappingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionMappingComposite.java deleted file mode 100644 index e9fa46c4b8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/VersionMappingComposite.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.mappings.details; - -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | ColumnComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | TemporalTypeComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see VersionMapping - * @see BaseJpaUiFactory - The factory creating this pane - * @see ColumnComposite - * @see TemporalTypeComposite - * - * @version 2.0 - * @since 1.0 - */ -public class VersionMappingComposite extends AbstractFormPane<VersionMapping> - implements JpaComposite<VersionMapping> -{ - /** - * 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 VersionMapping> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private PropertyValueModel<Column> buildColumnHolder() { - return new TransformationPropertyValueModel<VersionMapping, Column>(getSubjectHolder()) { - @Override - protected Column transform_(VersionMapping value) { - return value.getColumn(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - // Column widgets - new ColumnComposite(this, buildColumnHolder(), container); - - // Temporal Type widgets - new TemporalTypeComposite( - this, - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin) - ); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java deleted file mode 100644 index e654d1362e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.menus; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.internal.jface.ImageImageDescriptor; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.ui.ISources; -import org.eclipse.ui.actions.CompoundContributionItem; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.menus.CommandContributionItem; -import org.eclipse.ui.menus.CommandContributionItemParameter; -import org.eclipse.ui.menus.IWorkbenchContribution; -import org.eclipse.ui.services.IServiceLocator; - -/** - * This menu contribution is responsible to populate the Map As menu with the - * registered mapping types defined in the <code>JptPlatformUi</code>. - * - * @see JpaPlatform - * @see JpaPlatformUi - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class MapAsContribution extends CompoundContributionItem - implements IWorkbenchContribution -{ - /** - * Keeps track of the <code>IServiceLocator</code> which is used to retrieve - * various services required for invoking the <code>PersistentAttributeMapAsHandler</code>. - */ - private IServiceLocator serviceLocator; - - - /** - * Creates a new <code>PersistentAttributeMapAsContribution</code>. - */ - public MapAsContribution() { - super(); - } - - - public void initialize(IServiceLocator serviceLocator) { - this.serviceLocator = serviceLocator; - } - - @Override - protected IContributionItem[] getContributionItems() { - // Retrieve the selection from the handler service - // which should be an IStructuredSelection of JpaStructureNodes - IHandlerService handlerService = - (IHandlerService) serviceLocator.getService(IHandlerService.class); - IStructuredSelection currentSelection = - (IStructuredSelection) handlerService.getCurrentState().getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); - - // Assume that all nodes are in the same project (which is very safe) - // and retrieve the mapping UI providers just from the first item - JpaStructureNode node = (JpaStructureNode) currentSelection.getFirstElement(); - - return CollectionTools.array( - new TransformationIterator<MappingUiProvider<?>, IContributionItem>(mappingUiProviders(node)) { - @Override - protected IContributionItem transform(MappingUiProvider<?> next) { - return contributionItem(next); - } - }, - new IContributionItem[0]); - } - - /** - * Retrieves the registered {@link MappingUiProvider}s from the given node, - * using its {@link JpaPlatformUi}. - * - * @param node A test node to determine the {@link JpaPlatformUi} and type - * of providers to return - * @return The list of registered {@link MappingUiProvider}s - */ - protected Iterator<? extends MappingUiProvider<?>> - mappingUiProviders(JpaStructureNode node) { - JpaPlatform jpaPlatform = node.getJpaProject().getJpaPlatform(); - JpaPlatformUi jpaPlatformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaPlatform); - return mappingUiProviders(jpaPlatformUi, node); - } - - /** - * Retrieves the registered {@link MappingUiProvider}s from the given - * {@link JpaPlatformUi} and {@link JpaStructureNode} (to determine type of - * mapping providers to retrieve). - * - * @param jpaPlatformUi The active {@link JpaPlatformUi} from where the - * provider can be retrieved - * @param node A test node to determine type of providers to return - * @return The list of registered {@link MappingUiProvider}s - */ - protected abstract Iterator<? extends MappingUiProvider<?>> - mappingUiProviders(JpaPlatformUi platformUi, JpaStructureNode node); - - protected IContributionItem contributionItem(MappingUiProvider<?> mappingUiProvider) { - CommandContributionItem item = - new CommandContributionItem(parameter(mappingUiProvider)); - return item; - } - - protected CommandContributionItemParameter parameter(MappingUiProvider<?> mappingUiProvider) { - CommandContributionItemParameter parameter = - new CommandContributionItemParameter( - serviceLocator, - createCommandContributionItemId(mappingUiProvider), - commandId(), - CommandContributionItem.STYLE_CHECK); - parameter.label = mappingUiProvider.getLabel(); - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put(commandParameterId(), mappingUiProvider.getMappingKey()); - parameter.parameters = parameters; - parameter.icon = new ImageImageDescriptor(mappingUiProvider.getImage()); - parameter.visibleEnabled = true; - return parameter; - } - - /** - * Retrieves the unique identifier of the command that will be invoked for - * changing the mapping type of the selected nodes. - * - * @return The unique identifier of the "map as" command - */ - protected abstract String commandId(); - - /** - * Retrieves the unique identifier of the mapping key command parameter that - * will be used for the new mapping type of the selected nodes. - * - * @return The unique identifier of the "map as" command parameter - */ - protected abstract String commandParameterId(); - - /** - * Returns an id for a {@link CommandContributionItem} in the form of - * "<commandId>.<mappingKey>" - * (for example "org.eclipse.jpt.core.ui.persistentTypeMapAs.entity") - */ - protected String createCommandContributionItemId(MappingUiProvider<?> mappingUiProvider) { - return commandId() + "." + mappingUiProvider.getMappingKey(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/PersistentAttributeMapAsContribution.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/PersistentAttributeMapAsContribution.java deleted file mode 100644 index 8947f9b43b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/PersistentAttributeMapAsContribution.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.menus; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.internal.commands.PersistentAttributeMapAsHandler; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * This menu contribution is responsible to populate the Map As menu with the - * registered attribute mapping types defined in the <code>JptPlatformUi</code> - * for <code>PersistentAttribute</code> objects. - * - * @see PersistentAttribute - * - * @version 2.0 - * @since 2.0 - */ -public class PersistentAttributeMapAsContribution extends MapAsContribution -{ - /** - * Creates a new <code>PersistentAttributeMapAsContribution</code>. - */ - public PersistentAttributeMapAsContribution() { - super(); - } - - /* - * (non-Javadoc) - */ - @Override - protected String commandId() { - return PersistentAttributeMapAsHandler.COMMAND_ID; - } - - @Override - protected String commandParameterId() { - return PersistentAttributeMapAsHandler.COMMAND_PARAMETER_ID; - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<? extends MappingUiProvider<?>> - mappingUiProviders(JpaPlatformUi jpaPlatformUi, JpaStructureNode node) { - if (node instanceof JavaPersistentAttribute) { - return jpaPlatformUi.javaAttributeMappingUiProviders(); - } - else if (node instanceof OrmPersistentAttribute) { - return jpaPlatformUi.ormAttributeMappingUiProviders(); - } - else { - return EmptyIterator.instance(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/PersistentTypeMapAsContribution.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/PersistentTypeMapAsContribution.java deleted file mode 100644 index 183a9a26e0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/PersistentTypeMapAsContribution.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.menus; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.details.MappingUiProvider; -import org.eclipse.jpt.ui.internal.commands.PersistentTypeMapAsHandler; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; - -/** - * This menu contribution is responsible to populate the Map As menu with the - * registered mapping types defined in the <code>JptPlatformUi</code> for - * <code>PersistentType</code> objects. - * - * @see JpaPlatform - * @see JpaPlatformUi - * @see PersistentType - * - * @version 2.0 - * @since 2.0 - */ -public class PersistentTypeMapAsContribution extends MapAsContribution -{ - /** - * Creates a new <code>PersistentTypeMapAsContribution</code>. - */ - public PersistentTypeMapAsContribution() { - super(); - } - - @Override - protected String commandId() { - return PersistentTypeMapAsHandler.COMMAND_ID; - } - - @Override - protected String commandParameterId() { - return PersistentTypeMapAsHandler.COMMAND_PARAMETER_ID; - } - - @Override - protected Iterator<? extends MappingUiProvider<?>> - mappingUiProviders(JpaPlatformUi jpaPlatformUi, JpaStructureNode node) { - if (node instanceof JavaPersistentType) { - return jpaPlatformUi.javaTypeMappingUiProviders(); - } - else if (node instanceof OrmPersistentType) { - return jpaPlatformUi.ormTypeMappingUiProviders(); - } - else { - return EmptyIterator.instance(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorActionProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorActionProvider.java deleted file mode 100644 index 35c0ab34f9..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorActionProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.navigator; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.ui.internal.actions.OpenJpaResourceAction; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.actions.ActionContext; -import org.eclipse.ui.navigator.CommonActionProvider; -import org.eclipse.ui.navigator.ICommonActionConstants; -import org.eclipse.ui.navigator.ICommonActionExtensionSite; -import org.eclipse.ui.navigator.ICommonMenuConstants; - -public class JpaNavigatorActionProvider extends CommonActionProvider -{ - private OpenJpaResourceAction openAction; - - public JpaNavigatorActionProvider() { - super(); - } - - public void init(ICommonActionExtensionSite aConfig) { - openAction = new OpenJpaResourceAction(); - } - - public void setContext(ActionContext aContext) { - if (aContext != null && aContext.getSelection() instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) aContext.getSelection(); - openAction.selectionChanged(selection); - } - - super.setContext(aContext); - } - - public void fillActionBars(IActionBars theActionBars) { - if (openAction.isEnabled()) { - theActionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openAction); - } - } - - public void fillContextMenu(IMenuManager aMenu) { - if (getContext() == null || getContext().getSelection().isEmpty()) { - return; - } - - if (openAction.isEnabled()) { - aMenu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openAction); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java deleted file mode 100644 index 6bda2b3b65..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentAndLabelProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.navigator; - -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; - -public class JpaNavigatorContentAndLabelProvider extends DelegatingTreeContentAndLabelProvider -{ - public JpaNavigatorContentAndLabelProvider() { - super(new JpaNavigatorTreeItemContentProviderFactory(), new JpaNavigatorItemLabelProviderFactory()); - } -} 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 deleted file mode 100644 index 7d88736920..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java +++ /dev/null @@ -1,217 +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.navigator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.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 JpaNavigatorContentAndLabelProvider delegate; - - private IFacetedProjectListener facetListener; - - private StructuredViewer viewer; - - - public JpaNavigatorContentProvider() { - super(); - facetListener = new FacetListener(); - FacetedProjectFramework.addListener( - facetListener, - IFacetedProjectEvent.Type.POST_INSTALL, - IFacetedProjectEvent.Type.POST_UNINSTALL, - IFacetedProjectEvent.Type.PROJECT_MODIFIED); - } - - - public JpaNavigatorContentAndLabelProvider delegate() { - return delegate; - } - - - // **************** IContentProvider implementation ************************ - - public void dispose() { - FacetedProjectFramework.removeListener(facetListener); - if (delegate != null) { - delegate.dispose(); - } - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (delegate != null) { - delegate.inputChanged(viewer, oldInput, newInput); - } - this.viewer = (StructuredViewer) viewer; - } - - - // **************** IStructuredContentProvider implementation ************** - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - - // **************** ITreeContentProvider implementation ******************** - - public Object getParent(Object element) { - if (delegate != null) { - return delegate.getParent(element); - } - - return null; - } - - public boolean hasChildren(Object element) { - if (element instanceof IAdaptable) { - IProject project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); - - if (project != null) { - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject != null) { - JpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaProject.getJpaPlatform()); - - return platformUi != null; - } - } - } - - if (delegate != null) { - return delegate.hasChildren(element); - } - - return false; - } - - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IAdaptable) { - IProject project = (IProject) ((IAdaptable) parentElement).getAdapter(IProject.class); - - if (project != null) { - JpaProject jpaProject = JptCorePlugin.getJpaProject(project); - if (jpaProject != null) { - JpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaProject.getJpaPlatform()); - - if (platformUi != null) { - return new Object[] {jpaProject.getRootContext()}; - } - } - } - } - - if (delegate != null) { - return delegate.getChildren(parentElement); - } - - return new Object[0]; - } - - - // **************** IMementoAware implementation *************************** - - public void saveState(IMemento memento) { - // no op - } - - public void restoreState(IMemento memento) { - // no op - } - - - // **************** ICommonContentProvider implementation ****************** - - public void init(ICommonContentExtensionSite config) { - if (delegate == null) { - JpaNavigatorLabelProvider labelProvider = (JpaNavigatorLabelProvider) config.getExtension().getLabelProvider(); - if (labelProvider != null && labelProvider.delegate() != null) { - delegate = labelProvider.delegate(); - } - else { - delegate = new JpaNavigatorContentAndLabelProvider(); - } - } - } - - - // **************** 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/JpaNavigatorItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java deleted file mode 100644 index 6cd1b187a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorItemLabelProviderFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.navigator; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; - -public class JpaNavigatorItemLabelProviderFactory - implements ItemLabelProviderFactory -{ - /** - * Exactly *one* of these factories is created for each view that utilizes it. - * Therefore, as we delegate to the platform UI for each project, we should - * maintain the same multiplicity. That is, if there is a delegate for each - * platform UI, we should maintain *one* delegate for each view. - * - * Key: platform id, Value: delegate content provider factory - */ - private final Map<String, ItemLabelProviderFactory> delegates; - - - public JpaNavigatorItemLabelProviderFactory() { - super(); - this.delegates = new HashMap<String, ItemLabelProviderFactory>(); - } - - public ItemLabelProvider buildItemLabelProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - ItemLabelProviderFactory delegate = getDelegate(item); - if (delegate != null) { - return delegate.buildItemLabelProvider(item, contentAndLabelProvider); - } - return null; - } - - - private ItemLabelProviderFactory getDelegate(Object element) { - if (! (element instanceof IAdaptable)) { - return null; - } - - JpaContextNode contextNode = (JpaContextNode) ((IAdaptable) element).getAdapter(JpaContextNode.class); - - if (contextNode == null) { - return null; - } - - JpaPlatform platform = contextNode.getJpaProject().getJpaPlatform(); - String platformId = platform.getId(); - if (delegates.containsKey(platformId)) { - return delegates.get(platformId); - } - JpaNavigatorProvider navigatorProvider = JpaNavigatorProviderLookup.provider(platform.getId()); - ItemLabelProviderFactory delegate = null; - if (navigatorProvider != null) { - delegate = navigatorProvider.getItemLabelProviderFactory(); - } - delegates.put(platformId, delegate); - return delegate; - } -} 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 deleted file mode 100644 index 4d92ba983f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorLabelProvider.java +++ /dev/null @@ -1,128 +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.navigator; - -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.navigator.ICommonContentExtensionSite; -import org.eclipse.ui.navigator.ICommonLabelProvider; - -/** - * This extension of navigator label provider delegates to the platform UI - * (see the org.eclipse.jpt.ui.jpaPlatform extension point) for navigator labels. - * - * This label provider provides a label for the root "JPA Content" node provided - * by the content provider (see {@link JpaNavigatorContentProvider}) and delegates - * to the label provider returned by the platform UI implementation for labels - * for children of the "JPA Content" node (or for any other sub-node). - */ -public class JpaNavigatorLabelProvider extends LabelProvider - implements ICommonLabelProvider -{ - private JpaNavigatorContentAndLabelProvider delegate; - - - public JpaNavigatorLabelProvider() { - super(); - } - - - public JpaNavigatorContentAndLabelProvider delegate() { - return delegate; - } - - - // **************** IBaseLabelProvider implementation ********************** - - public void addListener(ILabelProviderListener listener) { - if (delegate != null) { - delegate.addListener(listener); - } - super.addListener(listener); - } - - public void removeListener(ILabelProviderListener listener) { - super.removeListener(listener); - if (delegate != null) { - delegate.removeListener(listener); - } - } - - public boolean isLabelProperty(Object element, String property) { - if (delegate != null) { - return delegate.isLabelProperty(element, property); - } - - return super.isLabelProperty(element, property); - } - - public void dispose() { - if (delegate != null) { - delegate.dispose(); - } - super.dispose(); - } - - - // **************** ILabelProvider implementation ************************** - - public Image getImage(Object element) { - if (delegate != null) { - return delegate.getImage(element); - } - - return super.getImage(element); - } - - public String getText(Object element) { - if (delegate != null) { - return delegate.getText(element); - } - - return super.getText(element); - } - - - // **************** IDescriptionProvider implementation ******************** - - public String getDescription(Object element) { - // no op - defer to getText(element) - return getText(element); - } - - - // **************** IMementoAware implementation *************************** - - public void saveState(IMemento memento) { - // no op - } - - public void restoreState(IMemento memento) { - // no op - } - - - // **************** ICommonLabelProvider implementation ******************** - - public void init(ICommonContentExtensionSite config) { - if (delegate == null) { - JpaNavigatorContentProvider contentProvider = (JpaNavigatorContentProvider) config.getExtension().getContentProvider(); - if (contentProvider != null && contentProvider.delegate() != null) { - delegate = contentProvider.delegate(); - } - else { - delegate = new JpaNavigatorContentAndLabelProvider(); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorProviderLookup.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorProviderLookup.java deleted file mode 100644 index 879a024c0a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorProviderLookup.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.navigator; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; - -/** - * This class is only provided to minimize object construction. Only one - * {@link JpaNavigatorProvider} is required to be constructed for each platform UI. - */ -public class JpaNavigatorProviderLookup -{ - private static Map<String, JpaNavigatorProvider> providers; - - - public static JpaNavigatorProvider provider(String platformId) { - if (providers == null) { - providers = new HashMap<String, JpaNavigatorProvider>(); - } - if (providers.containsKey(platformId)) { - return providers.get(platformId); - } - JpaPlatformUi platform = JpaPlatformUiRegistry.instance().jpaPlatform(platformId); - if (platform == null) { - return null; - } - JpaNavigatorProvider provider = platform.buildNavigatorProvider(); - providers.put(platformId, provider); - return provider; - } - - // prevent construction - private JpaNavigatorProviderLookup() { - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java deleted file mode 100644 index d481b5671b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorTreeItemContentProviderFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.navigator; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; -import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; - -public class JpaNavigatorTreeItemContentProviderFactory - implements TreeItemContentProviderFactory -{ - /** - * Exactly *one* of these factories is created for each view that utilizes it. - * Therefore, as we delegate to the platform UI for each project, we should - * maintain the same multiplicity. That is, if there is a delegate for each - * platform UI, we should maintain *one* delegate for each view. - * - * Key: platform id, Value: delegate content provider factory - */ - private Map<String, TreeItemContentProviderFactory> delegates; - - - public JpaNavigatorTreeItemContentProviderFactory() { - super(); - this.delegates = new HashMap<String, TreeItemContentProviderFactory>(); - } - - public TreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - TreeItemContentProviderFactory delegate = getDelegate(item); - if (delegate != null) { - return delegate.buildItemContentProvider(item, contentAndLabelProvider); - } - return null; - } - - - private TreeItemContentProviderFactory getDelegate(Object element) { - if (! (element instanceof IAdaptable)) { - return null; - } - - JpaContextNode contextNode = (JpaContextNode) ((IAdaptable) element).getAdapter(JpaContextNode.class); - - if (contextNode == null) { - return null; - } - - JpaPlatform platform = contextNode.getJpaProject().getJpaPlatform(); - String platformId = platform.getId(); - if (delegates.containsKey(platformId)) { - return delegates.get(platformId); - } - JpaNavigatorProvider navigatorProvider = JpaNavigatorProviderLookup.provider(platform.getId()); - TreeItemContentProviderFactory delegate = null; - if (navigatorProvider != null) { - delegate = navigatorProvider.getTreeItemContentProviderFactory(); - } - delegates.put(platformId, delegate); - return delegate; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/JptUiOrmMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/JptUiOrmMessages.java deleted file mode 100644 index e0c9149759..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/JptUiOrmMessages.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm; - -import org.eclipse.osgi.util.NLS; - -/** - * The localized messages used by the ORM widgets. - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class JptUiOrmMessages { - - public static String AccessTypeComposite_access; - public static String AccessTypeComposite_field; - public static String AccessTypeComposite_property; - public static String Boolean_False; - public static String Boolean_True; - public static String EntityMappingsDetailsPage_access; - public static String EntityMappingsDetailsPage_catalog; - public static String EntityMappingsDetailsPage_field; - public static String EntityMappingsDetailsPage_package; - public static String EntityMappingsDetailsPage_property; - public static String EntityMappingsDetailsPage_schema; - public static String EntityMappingsPage_catalogDefault; - public static String EntityMappingsPage_catalogNoDefaultSpecified; - public static String EntityMappingsPage_schemaDefault; - public static String EntityMappingsPage_schemaNoDefaultSpecified; - public static String OrmGeneratorsComposite_addSequenceGenerator; - public static String OrmGeneratorsComposite_addSequenceGeneratorDescription; - public static String OrmGeneratorsComposite_addSequenceGeneratorDescriptionTitle; - public static String OrmGeneratorsComposite_addSequenceGeneratorTitle; - public static String OrmGeneratorsComposite_addTableGenerator; - public static String OrmGeneratorsComposite_addTableGeneratorDescription; - public static String OrmGeneratorsComposite_addTableGeneratorDescriptionTitle; - public static String OrmGeneratorsComposite_addTableGeneratorTitle; - public static String OrmGeneratorsComposite_displayString; - public static String OrmGeneratorsComposite_edit; - public static String OrmGeneratorsComposite_editSequenceGeneratorDescription; - public static String OrmGeneratorsComposite_editSequenceGeneratorDescriptionTitle; - public static String OrmGeneratorsComposite_editSequenceGeneratorTitle; - public static String OrmGeneratorsComposite_editTableGeneratorDescription; - public static String OrmGeneratorsComposite_editTableGeneratorDescriptionTitle; - public static String OrmGeneratorsComposite_editTableGeneratorTitle; - public static String OrmGeneratorsComposite_groupBox; - public static String OrmGeneratorsComposite_label; - public static String OrmJavaAttributeChooser_javaAttribute; - public static String OrmJavaClassChooser_javaClass; - public static String OrmPersistentTypeDetailsPage_metadataComplete; - public static String OrmPersistentTypeDetailsPage_metadataCompleteWithDefault; - public static String OrmQueriesComposite_groupBox; - public static String OrmSequenceGeneratorComposite_name; - public static String OrmSequenceGeneratorComposite_sequence; - public static String OrmTableGeneratorComposite_default; - public static String OrmTableGeneratorComposite_name; - public static String OrmTableGeneratorComposite_pkColumn; - public static String OrmTableGeneratorComposite_pkColumnValue; - public static String OrmTableGeneratorComposite_table; - public static String OrmTableGeneratorComposite_tableGenerator; - public static String OrmTableGeneratorComposite_valueColumn; - public static String PersistenceUnitMetadataComposite_access; - public static String PersistenceUnitMetadataComposite_cascadePersistCheckBox; - public static String PersistenceUnitMetadataComposite_catalog; - public static String PersistenceUnitMetadataComposite_field; - public static String PersistenceUnitMetadataComposite_persistenceUnitSection; - public static String PersistenceUnitMetadataComposite_property; - public static String PersistenceUnitMetadataComposite_schema; - public static String PersistenceUnitMetadataComposite_xmlMappingMetadataCompleteCheckBox; - public static String PersistenceUnitMetadataSection_catalogDefault; - public static String PersistenceUnitMetadataSection_schemaDefault; - - static { - NLS.initializeMessages("jpt_ui_orm", JptUiOrmMessages.class); - } - - private JptUiOrmMessages() { - throw new UnsupportedOperationException(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/AccessTypeComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/AccessTypeComposite.java deleted file mode 100644 index 0844be523f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/AccessTypeComposite.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------ | - * | Access Type: | |v| | - * | ------------------------------------------------------------ | - * -----------------------------------------------------------------------------</pre> - * - * @see XmlTypeMapping - * @see OrmPersistentTypeDetailsPage - A container of this pane - * - * @version 2.0 - * @since 1.0 - */ -public class AccessTypeComposite extends AbstractFormPane<OrmTypeMapping> { - - /** - * 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 OrmTypeMapping> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - private EnumFormComboViewer<OrmTypeMapping, AccessType> buildAccessTypeComboViewer(Composite container) { - - return new EnumFormComboViewer<OrmTypeMapping, AccessType>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(OrmTypeMapping.DEFAULT_ACCESS_PROPERTY); - propertyNames.add(OrmTypeMapping.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( - JptUiOrmMessages.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) { - - EnumFormComboViewer<OrmTypeMapping, AccessType> comboViewer = - buildAccessTypeComboViewer(container); - - buildLabeledComposite( - container, - JptUiOrmMessages.AccessTypeComposite_access, - comboViewer.getControl() - ); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/EntityMappingsDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/EntityMappingsDetailsPage.java deleted file mode 100644 index 9f91caa1c0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/EntityMappingsDetailsPage.java +++ /dev/null @@ -1,249 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.details.AbstractJpaDetailsPage; -import org.eclipse.jpt.ui.internal.mappings.db.CatalogCombo; -import org.eclipse.jpt.ui.internal.mappings.db.SchemaCombo; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | XmlPackageChooser | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------ | - * | Schema: | SchemaCombo | | - * | ------------------------------------------------------------ | - * | ------------------------------------------------------------ | - * | Catalog: | CatalogCombo | | - * | ------------------------------------------------------------ | - * | ------------------------------------------------------------ | - * | Access Type: | |v| | - * | ------------------------------------------------------------ | - * | | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PersistenceUnitMetadataComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmGeneratorsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmQueriesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see EntityMappings - * @see EntityMappingsDetailsPage - The parent container - * @see CatalogCombo - * @see EnumFormComboViewer - * @see OrmGeneratorsComposite - * @see OrmPackageChooser - * @see OrmQueriesComposite - * @see PersistenceUnitMetadataComposite - * @see SchemaCombo - * - * @version 2.0 - * @since 2.0 - */ -public class EntityMappingsDetailsPage extends AbstractJpaDetailsPage<EntityMappings> -{ - /** - * Creates a new <code>XmlEntityMappingsDetailsPage</code>. - * - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public EntityMappingsDetailsPage(Composite parent, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - private EnumFormComboViewer<EntityMappings, AccessType> buildAccessTypeCombo(Composite container) { - - return new EnumFormComboViewer<EntityMappings, AccessType>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(EntityMappings.DEFAULT_ACCESS_PROPERTY); - propertyNames.add(EntityMappings.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( - JptUiOrmMessages.class, - EntityMappingsDetailsPage.this, - value - ); - } - - @Override - protected AccessType getValue() { - return subject().getAccess(); - } - - @Override - protected void setValue(AccessType value) { - subject().setSpecifiedAccess(value); - } - }; - } - - private CatalogCombo<EntityMappings> buildCatalogCombo(Composite container) { - - return new CatalogCombo<EntityMappings>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(EntityMappings.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(EntityMappings.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(); - } - }; - } - - private PropertyValueModel<PersistenceUnitMetadata> buildPersistentUnitMetadaHolder() { - return new TransformationPropertyValueModel<EntityMappings, PersistenceUnitMetadata>(getSubjectHolder()) { - @Override - protected PersistenceUnitMetadata transform_(EntityMappings value) { - return value.getPersistenceUnitMetadata(); - } - }; - } - - private SchemaCombo<EntityMappings> buildSchemaCombo(Composite container) { - - return new SchemaCombo<EntityMappings>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(EntityMappings.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(EntityMappings.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(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Package widgets - new OrmPackageChooser(this, container); - - // Schema widgets - buildLabeledComposite( - container, - JptUiOrmMessages.EntityMappingsDetailsPage_schema, - buildSchemaCombo(container), - JpaHelpContextIds.ENTITY_ORM_SCHEMA - ); - - // Catalog widgets - buildLabeledComposite( - container, - JptUiOrmMessages.EntityMappingsDetailsPage_catalog, - buildCatalogCombo(container), - JpaHelpContextIds.ENTITY_ORM_CATALOG - ); - - // Access Type widgets - buildLabeledComposite( - container, - JptUiOrmMessages.EntityMappingsDetailsPage_access, - buildAccessTypeCombo(container), - JpaHelpContextIds.ENTITY_ORM_ACCESS - ); - - // Persistence Unit Metadata widgets - new PersistenceUnitMetadataComposite( - this, - buildPersistentUnitMetadaHolder(), - buildSubPane(container, 5) - ); - - // Generators pane - new OrmGeneratorsComposite( - this, - buildSubPane(container, 5) - ); - - // Queries pane - new OrmQueriesComposite( - this, - buildSubPane(container, 5) - ); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java deleted file mode 100644 index 3556e7c717..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaDetailsPage; -import org.eclipse.jpt.ui.details.JpaDetailsProvider; -import org.eclipse.swt.widgets.Composite; - -/** - * This provider is responsible for creating the {@link JpaDetailsPage} - * 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 OrmDetailsProvider - implements JpaDetailsProvider -{ - public OrmDetailsProvider() { - super(); - } - - public JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage( - Composite parent, - Object contentNodeId, - WidgetFactory widgetFactory) { - - if (contentNodeId == OrmStructureNodes.ENTITY_MAPPINGS_ID) { - return new EntityMappingsDetailsPage(parent, widgetFactory); - } - - if (contentNodeId == OrmStructureNodes.PERSISTENT_TYPE_ID) { - return new OrmPersistentTypeDetailsPage(parent, widgetFactory); - } - - if (contentNodeId == OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID) { - return new OrmPersistentAttributeDetailsPage(parent, widgetFactory); - } - - return null; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmEntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmEntityComposite.java deleted file mode 100644 index 804df18739..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmEntityComposite.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractEntityComposite; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * The pane used for an ORM entity. - * - * @see OrmEntity - * @see BaseJpaUiFactory - The factory creating this pane - * @see OrmSecondaryTablesComposite - * - * @version 2.0 - * @since 1.0 - */ -public class OrmEntityComposite extends AbstractEntityComposite<OrmEntity> -{ - /** - * Creates a new <code>OrmEntityComposite</code>. - * - * @param subjectHolder The holder of the subject <code>OrmEntity</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public OrmEntityComposite(PropertyValueModel<? extends OrmEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected void buildSecondaryTablesComposite(Composite container) { - new OrmSecondaryTablesComposite(this, container); - } - - @Override - protected void buildInheritanceComposite(Composite container) { - new OrmInheritanceComposite(this, container); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmEntityUiProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmEntityUiProvider.java deleted file mode 100644 index e46e9eeb4e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmEntityUiProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; - -public class OrmEntityUiProvider implements TypeMappingUiProvider<OrmEntity> -{ - // singleton - private static final OrmEntityUiProvider INSTANCE = new OrmEntityUiProvider(); - - /** - * Return the singleton. - */ - public static TypeMappingUiProvider<OrmEntity> instance() { - return INSTANCE; - } - - /** - * Ensure non-instantiability. - */ - private OrmEntityUiProvider() { - super(); - } - - public String getMappingKey() { - return MappingKeys.ENTITY_TYPE_MAPPING_KEY; - } - - public String getLabel() { - return JptUiMappingsMessages.PersistentTypePage_EntityLabel; - } - - public Image getImage() { - return JpaMappingImageHelper.imageForTypeMapping(getMappingKey()); - } - - public JpaComposite<OrmEntity> buildPersistentTypeMappingComposite( - JpaUiFactory factory, - PropertyValueModel<OrmEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - return factory.createOrmEntityComposite(subjectHolder, parent, widgetFactory); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmGeneratorsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmGeneratorsComposite.java deleted file mode 100644 index f0aa440737..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmGeneratorsComposite.java +++ /dev/null @@ -1,465 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmGenerator; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.util.ControlSwitcher; -import org.eclipse.jpt.ui.internal.util.PaneEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; -import org.eclipse.jpt.ui.internal.widgets.NewNameDialog; -import org.eclipse.jpt.ui.internal.widgets.NewNameDialogBuilder; -import org.eclipse.jpt.ui.internal.widgets.PostExecution; -import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.part.PageBook; - -/** - * This pane shows the list of named queries and named native queries. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmSequenceGeneratorComposite or OrmTableGeneratorComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see EntityMappings - * @see OrmGenerator - * @see OrmSequenceGenerator - * @see OrmTableGenerator - * @see EntityComposite - The parent container - * @see OrmSequenceGeneratorComposite - * @see OrmTableGeneratorComposite - * - * @version 2.0 - * @since 2.0 - */ -public class OrmGeneratorsComposite extends AbstractPane<EntityMappings> -{ - private WritablePropertyValueModel<OrmGenerator> generatorHolder; - private OrmSequenceGeneratorComposite sequenceGeneratorPane; - private OrmTableGeneratorComposite tableGeneratorPane; - private AddRemoveListPane<EntityMappings> listPane; - - /** - * Creates a new <code>OrmGeneratorsComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public OrmGeneratorsComposite(AbstractPane<? extends EntityMappings> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private void addSequenceGenerator(ObjectListSelectionModel listSelectionModel) { - - NewNameDialogBuilder builder = new NewNameDialogBuilder(shell()); - builder.setDialogTitle(JptUiOrmMessages.OrmGeneratorsComposite_addSequenceGeneratorTitle); - builder.setDescription(JptUiOrmMessages.OrmGeneratorsComposite_addSequenceGeneratorDescription); - builder.setDescriptionTitle(JptUiOrmMessages.OrmGeneratorsComposite_addSequenceGeneratorDescriptionTitle); - builder.setLabelText(JptUiOrmMessages.OrmGeneratorsComposite_label); - builder.setExistingNames(sequenceGeneratorNames()); - - NewNameDialog dialog = builder.buildDialog(); - dialog.openDialog(buildNewSequenceGeneratorPostExecution(listSelectionModel)); - } - - private void addTableGenerator(ObjectListSelectionModel listSelectionModel) { - - NewNameDialogBuilder builder = new NewNameDialogBuilder(shell()); - builder.setDialogTitle(JptUiOrmMessages.OrmGeneratorsComposite_addTableGeneratorTitle); - builder.setDescription(JptUiOrmMessages.OrmGeneratorsComposite_addTableGeneratorDescription); - builder.setDescriptionTitle(JptUiOrmMessages.OrmGeneratorsComposite_addTableGeneratorDescriptionTitle); - builder.setLabelText(JptUiOrmMessages.OrmGeneratorsComposite_label); - builder.setExistingNames(tableGeneratorNames()); - - NewNameDialog dialog = builder.buildDialog(); - dialog.openDialog(buildNewTableGeneratorPostExecution(listSelectionModel)); - } - - private ListValueModel<OrmGenerator> buildDisplayableGeneratorListHolder() { - return new ItemPropertyListValueModelAdapter<OrmGenerator>( - buildGeneratorsListHolder(), - Generator.NAME_PROPERTY - ); - } - - private PostExecution<NewNameDialog> buildEditGeneratorPostExecution() { - return new PostExecution<NewNameDialog>() { - public void execute(NewNameDialog dialog) { - if (dialog.wasConfirmed()) { - OrmGenerator generator = generatorHolder.getValue(); - generator.setName(dialog.getName()); - } - } - }; - } - - private Adapter buildGeneratorAdapter() { - - return new AddRemoveListPane.AbstractAdapter() { - - @Override - public String addButtonText() { - return JptUiOrmMessages.OrmGeneratorsComposite_addSequenceGenerator; - } - - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - addSequenceGenerator(listSelectionModel); - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiOrmMessages.OrmGeneratorsComposite_edit; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - editGenerator(listSelectionModel); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - for (Object item : listSelectionModel.selectedValues()) { - if (item instanceof OrmSequenceGenerator) { - subject().removeSequenceGenerator((OrmSequenceGenerator) item); - } - else { - subject().removeTableGenerator((OrmTableGenerator) item); - } - } - } - }; - } - - private WritablePropertyValueModel<OrmGenerator> buildGeneratorHolder() { - return new SimplePropertyValueModel<OrmGenerator>(); - } - - private ILabelProvider buildGeneratorLabelProvider() { - return new LabelProvider() { - @Override - public String getText(Object element) { - OrmGenerator generator = (OrmGenerator) element; - String name = generator.getName(); - - if (name == null) { - int index = -1; - - if (generator instanceof OrmSequenceGenerator) { - index = CollectionTools.indexOf(subject().sequenceGenerators(), generator); - } - else { - index = CollectionTools.indexOf(subject().tableGenerators(), generator); - } - - name = NLS.bind(JptUiOrmMessages.OrmGeneratorsComposite_displayString, index); - } - - return name; - } - }; - } - - private ListValueModel<OrmGenerator> buildGeneratorsListHolder() { - List<ListValueModel<? extends OrmGenerator>> list = new ArrayList<ListValueModel<? extends OrmGenerator>>(); - list.add(buildSequenceGeneratorListHolder()); - list.add(buildTableGeneratorListHolder()); - return new CompositeListValueModel<ListValueModel<? extends OrmGenerator>, OrmGenerator>(list); - } - - private PostExecution<NewNameDialog> buildNewSequenceGeneratorPostExecution(final ObjectListSelectionModel listSelectionModel) { - return new PostExecution<NewNameDialog>() { - public void execute(NewNameDialog dialog) { - if (dialog.wasConfirmed()) { - OrmSequenceGenerator generator = subject().addSequenceGenerator(subject().sequenceGeneratorsSize()); - generator.setName(dialog.getName()); - generatorHolder.setValue(generator); - listSelectionModel.setSelectedValue(generator); - } - } - }; - } - - private Runnable buildNewTableGeneratorAction(final ObjectListSelectionModel selectionModel) { - return new Runnable() { - public void run() { - addTableGenerator(selectionModel); - } - }; - } - - private PostExecution<NewNameDialog> buildNewTableGeneratorPostExecution(final ObjectListSelectionModel listSelectionModel) { - return new PostExecution<NewNameDialog>() { - public void execute(NewNameDialog dialog) { - if (dialog.wasConfirmed()) { - OrmTableGenerator generator = subject().addTableGenerator(subject().tableGeneratorsSize()); - generator.setName(dialog.getName()); - generatorHolder.setValue(generator); - listSelectionModel.setSelectedValue(generator); - } - } - }; - } - - private PropertyValueModel<Boolean> buildPaneEnablerHolder() { - return new TransformationPropertyValueModel<EntityMappings, Boolean>(getSubjectHolder()) { - @Override - protected Boolean transform(EntityMappings value) { - return (value != null); - } - }; - } - - private Transformer<OrmGenerator, Control> buildPaneTransformer() { - return new Transformer<OrmGenerator, Control>() { - public Control transform(OrmGenerator generator) { - - if (generator == null) { - return null; - } - - if (generator instanceof OrmSequenceGenerator) { - return sequenceGeneratorPane.getControl(); - } - - return tableGeneratorPane.getControl(); - } - }; - } - - private PropertyValueModel<OrmSequenceGenerator> buildSequenceGeneratorHolder() { - return new TransformationPropertyValueModel<OrmGenerator, OrmSequenceGenerator>(generatorHolder) { - @Override - protected OrmSequenceGenerator transform_(OrmGenerator value) { - return (value instanceof OrmSequenceGenerator) ? (OrmSequenceGenerator) value : null; - } - }; - } - - private ListValueModel<OrmSequenceGenerator> buildSequenceGeneratorListHolder() { - return new ListAspectAdapter<EntityMappings, OrmSequenceGenerator>( - getSubjectHolder(), - EntityMappings.SEQUENCE_GENERATORS_LIST) - { - @Override - protected ListIterator<OrmSequenceGenerator> listIterator_() { - return subject.sequenceGenerators(); - } - - @Override - protected int size_() { - return subject.sequenceGeneratorsSize(); - } - }; - } - - private PropertyValueModel<OrmTableGenerator> buildTableGeneratorHolder() { - return new TransformationPropertyValueModel<OrmGenerator, OrmTableGenerator>(generatorHolder) { - @Override - protected OrmTableGenerator transform_(OrmGenerator value) { - return (value instanceof OrmTableGenerator) ? (OrmTableGenerator) value : null; - } - }; - } - - private ListValueModel<OrmTableGenerator> buildTableGeneratorListHolder() { - return new ListAspectAdapter<EntityMappings, OrmTableGenerator>( - getSubjectHolder(), - EntityMappings.TABLE_GENERATORS_LIST) - { - @Override - protected ListIterator<OrmTableGenerator> listIterator_() { - return subject.tableGenerators(); - } - - @Override - protected int size_() { - return subject.tableGeneratorsSize(); - } - }; - } - - private void editGenerator(ObjectListSelectionModel listSelectionModel) { - - OrmGenerator generator = generatorHolder.getValue(); - - NewNameDialogBuilder builder = new NewNameDialogBuilder(shell()); - builder.setLabelText(JptUiOrmMessages.OrmGeneratorsComposite_label); - builder.setName(generator.getName()); - - if (generator instanceof OrmSequenceGenerator) { - builder.setDialogTitle(JptUiOrmMessages.OrmGeneratorsComposite_editSequenceGeneratorTitle); - builder.setDescription(JptUiOrmMessages.OrmGeneratorsComposite_editSequenceGeneratorDescription); - builder.setDescriptionTitle(JptUiOrmMessages.OrmGeneratorsComposite_editSequenceGeneratorDescriptionTitle); - builder.setExistingNames(sequenceGeneratorNames()); - } - else { - builder.setDialogTitle(JptUiOrmMessages.OrmGeneratorsComposite_editTableGeneratorTitle); - builder.setDescription(JptUiOrmMessages.OrmGeneratorsComposite_editTableGeneratorDescription); - builder.setDescriptionTitle(JptUiOrmMessages.OrmGeneratorsComposite_editTableGeneratorDescriptionTitle); - builder.setExistingNames(tableGeneratorNames()); - } - - NewNameDialog dialog = builder.buildDialog(); - dialog.openDialog(buildEditGeneratorPostExecution()); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - generatorHolder = buildGeneratorHolder(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - container = buildCollapsableSection( - container, - JptUiOrmMessages.OrmGeneratorsComposite_groupBox - ); - - // List pane - listPane = buildListPane(container); - installPaneEnabler(); - - // Property pane - PropertyValueModel<OrmSequenceGenerator> sequenceGeneratorHolder = - buildSequenceGeneratorHolder(); - PropertyValueModel<OrmTableGenerator> tableGeneratorHolder = - buildTableGeneratorHolder(); - - PageBook pageBook = new PageBook(container, SWT.NULL); - pageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Sequence Generator property pane - sequenceGeneratorPane = new OrmSequenceGeneratorComposite( - this, - sequenceGeneratorHolder, - pageBook - ); - - // Table Generator property pane - tableGeneratorPane = new OrmTableGeneratorComposite( - this, - tableGeneratorHolder, - pageBook - ); - - addAlignRight(sequenceGeneratorPane); - addAlignRight(tableGeneratorPane); - installPaneSwitcher(pageBook); - } - - private AddRemoveListPane<EntityMappings> buildListPane(Composite container) { - - return new AddRemoveListPane<EntityMappings>( - this, - container, - buildGeneratorAdapter(), - buildDisplayableGeneratorListHolder(), - generatorHolder, - buildGeneratorLabelProvider() - ) - { - @Override - protected void addCustomButtonAfterAddButton(Composite container, - String helpId) { - - Button button = buildButton( - container, - JptUiOrmMessages.OrmGeneratorsComposite_addTableGenerator, - helpId, - buildNewTableGeneratorAction(getSelectionModel()) - ); - - addAlignRight(button); - } - }; - } - - private void installPaneEnabler() { - new PaneEnabler( - buildPaneEnablerHolder(), - listPane - ); - } - - private void installPaneSwitcher(PageBook pageBook) { - new ControlSwitcher(generatorHolder, buildPaneTransformer(), pageBook); - } - - private Iterator<String> sequenceGeneratorNames() { - return new TransformationIterator<OrmSequenceGenerator, String>(subject().sequenceGenerators()) { - @Override - protected String transform(OrmSequenceGenerator next) { - return next.getName(); - } - }; - } - - private Iterator<String> tableGeneratorNames() { - return new TransformationIterator<OrmTableGenerator, String>(subject().tableGenerators()) { - @Override - protected String transform(OrmTableGenerator next) { - return next.getName(); - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmInheritanceComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmInheritanceComposite.java deleted file mode 100644 index b3abfae99c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmInheritanceComposite.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractInheritanceComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * The pane used for java inheritance. - * - * @see OrmEntity - * @see OrmPrimaryKeyJoinColumnsComposite - * - * @version 2.0 - * @since 1.0 - */ -public class OrmInheritanceComposite extends AbstractInheritanceComposite<OrmEntity> { - - /** - * Creates a new <code>OrmInheritanceComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public OrmInheritanceComposite(AbstractPane<OrmEntity> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>OrmInheritanceComposite</code>. - * - * @param subjectHolder The holder of the subject <code>OrmEntity</code> - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public OrmInheritanceComposite(PropertyValueModel<OrmEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected void buildPrimaryKeyJoinColumnsComposite(Composite container) { - new OrmPrimaryKeyJoinColumnsComposite(this, container); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmJavaAttributeChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmJavaAttributeChooser.java deleted file mode 100644 index 724b32a756..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmJavaAttributeChooser.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Text; - -/** - * @see OrmPersistentAttributeDetailsPage - The parent container - * - * @version 2.0 - * @since 1.0 - */ -public class OrmJavaAttributeChooser extends AbstractFormPane<OrmAttributeMapping> -{ - private Text text; - - /** - * 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 OrmJavaAttributeChooser(AbstractFormPane<?> parentPane, - PropertyValueModel<OrmAttributeMapping> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - private WritablePropertyValueModel<String> buildNameHolder() { - return new PropertyAspectAdapter<OrmAttributeMapping, String>(getSubjectHolder(), OrmAttributeMapping.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - if (subject.getPersistentAttribute().isVirtual()) { - return; - } - if (value.length() == 0) { - value = null; - } - subject.setName(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - super.enableWidgets(enabled); - - if (!text.isDisposed()) { - text.setEnabled(enabled); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - text = buildLabeledText( - container, - JptUiOrmMessages.OrmJavaAttributeChooser_javaAttribute, - buildNameHolder() - ); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmJavaClassChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmJavaClassChooser.java deleted file mode 100644 index 44dec7dcef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmJavaClassChooser.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.ClassChooserPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | ClassChooserPane | - * | | - * -----------------------------------------------------------------------------</pre> - * - * 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. - * Not sure if this should be driven by the UI or by ui api in the model - * - * @see OrmTypeMapping - * @see OrmPersistentTypeDetailsPage - The parent container - * @see ClassChooserPane - * - * @version 2.0 - * @since 1.0 - */ -public class OrmJavaClassChooser extends AbstractFormPane<OrmTypeMapping> { - - /** - * 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 OrmJavaClassChooser(AbstractFormPane<?> parentPane, - PropertyValueModel<? extends OrmTypeMapping> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * 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 OrmJavaClassChooser(PropertyValueModel<? extends OrmTypeMapping> subjectHolder, - Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private ClassChooserPane<OrmTypeMapping> initializeClassChooser(Composite container) { - - return new ClassChooserPane<OrmTypeMapping>(this, container) { - - @Override - protected WritablePropertyValueModel<String> buildTextHolder() { - return new PropertyAspectAdapter<OrmTypeMapping, String>(getSubjectHolder(), OrmTypeMapping.CLASS_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getClass_(); - } - - @Override - protected void setValue_(String value) { - subject.setClass(value); - } - }; - } - - @Override - protected String className() { - return subject().getClass_(); - } - - @Override - protected String labelText() { - return JptUiOrmMessages.OrmJavaClassChooser_javaClass; - } - - @Override - protected IPackageFragmentRoot packageFragmentRoot() { - IProject project = subject().getJpaProject().getProject(); - IJavaProject root = JavaCore.create(project); - - try { - return root.getAllPackageFragmentRoots()[0]; - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - - return null; - } - - @Override - protected void promptType() { - IType type = chooseType(); - - if (type != null) { - String className = type.getFullyQualifiedName('.'); - subject().setClass(className); - } - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - initializeClassChooser(container); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPackageChooser.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPackageChooser.java deleted file mode 100644 index a5b555e3ab..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPackageChooser.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.PackageChooserPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | PackageChooserPane | - * | | - * -----------------------------------------------------------------------------</pre> - * - * @see EntityMappings - * @see EntityMappingsDetailsPage - The parent container - * @see PackageChooserPane - * - * @version 2.0 - * @since 2.0 - */ -public class OrmPackageChooser extends AbstractFormPane<EntityMappings> -{ - /** - * Creates a new <code>XmlPackageChooser</code>. - * - * @param parentPane The parent controller of this one - * @param parent The parent container - */ - public OrmPackageChooser(AbstractFormPane<? extends EntityMappings> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - initializePackageChooserPane(container); - } - - private void initializePackageChooserPane(Composite container) { - - new PackageChooserPane<EntityMappings>(this, container) { - @Override - protected WritablePropertyValueModel<String> buildTextHolder() { - return new PropertyAspectAdapter<EntityMappings, String>(getSubjectHolder(), EntityMappings.PACKAGE_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getPackage(); - } - - @Override - protected void setValue_(String value) { - subject.setPackage(value); - } - }; - } - - @Override - protected String labelText() { - return JptUiOrmMessages.EntityMappingsDetailsPage_package; - } - - @Override - protected IPackageFragmentRoot packageFragmentRoot() { - IProject project = subject().getJpaProject().getProject(); - IJavaProject root = JavaCore.create(project); - - try { - return root.getAllPackageFragmentRoots()[0]; - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - - return null; - } - - @Override - protected String packageName() { - return subject().getPackage(); - } - - @Override - protected void promptPackage() { - IPackageFragment packageFragment = choosePackage(); - - if (packageFragment != null) { - String packageName = packageFragment.getElementName(); - subject().setPackage(packageName); - } - } - }; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPersistentAttributeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPersistentAttributeDetailsPage.java deleted file mode 100644 index 49bc907d32..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPersistentAttributeDetailsPage.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.ArrayList; -import java.util.Iterator; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaComposite; -import org.eclipse.jpt.ui.internal.details.PersistentAttributeDetailsPage; -import org.eclipse.jpt.ui.internal.mappings.details.OrmPersistentAttributeMapAsComposite; -import org.eclipse.jpt.ui.internal.util.PaneEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.PageBook; - -/** - * The default implementation of the details page used for the XML persistent - * attribute. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmPersistentAttributeMapAsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | Attribute mapping pane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OrmPersistentAttribute - * @see OrmPersistentAttributeMapAsComposite - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class OrmPersistentAttributeDetailsPage extends PersistentAttributeDetailsPage<OrmPersistentAttribute> -{ - /** - * Creates a new <code>OrmPersistentAttributeDetailsPage</code>. - * - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public OrmPersistentAttributeDetailsPage(Composite parent, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders() { - return jpaPlatformUi().ormAttributeMappingUiProviders(); - } - - /* - * (non-Javadoc) - */ - @Override - @SuppressWarnings("unchecked") - protected AttributeMappingUiProvider<? extends AttributeMapping>[] attributeMappingUiProvidersFor(PersistentAttribute persistentAttribute) { - //bug 192035 - no default mapping option in xml - return CollectionTools.array(attributeMappingUiProviders(), new AttributeMappingUiProvider[CollectionTools.size(attributeMappingUiProviders())]); - } - - private PropertyValueModel<Boolean> buildPaneEnablerHolder() { - return new TransformationPropertyValueModel<OrmPersistentAttribute, Boolean>(getSubjectHolder()) { - @Override - protected Boolean transform_(OrmPersistentAttribute value) { - return !value.isVirtual(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected AttributeMappingUiProvider<AttributeMapping> defaultAttributeMappingUiProvider(String key) { - throw new UnsupportedOperationException("Xml attributeMappings should not be default"); - } - - /* - * (non-Javadoc) - */ - @Override - protected Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> defaultAttributeMappingUiProviders() { - return jpaPlatformUi().defaultOrmAttributeMappingUiProviders(); - } - - private PropertyValueModel<OrmAttributeMapping> getMappingHolder() { - return new TransformationPropertyValueModel<PersistentAttribute, OrmAttributeMapping>(getSubjectHolder()) { - @Override - protected OrmAttributeMapping transform_(PersistentAttribute value) { - return (OrmAttributeMapping) value.getMapping(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - ArrayList<AbstractPane<?>> panes = new ArrayList<AbstractPane<?>>(2); - - // Map As composite - OrmPersistentAttributeMapAsComposite mapAsPane = new OrmPersistentAttributeMapAsComposite( - this, - buildSubPane(container, 0, 0, 5, 0) - ); - - panes.add(mapAsPane); - - // Entity type widgets - OrmJavaAttributeChooser javaAttributePane = - new OrmJavaAttributeChooser(this, getMappingHolder(), container); - - panes.add(javaAttributePane); - - // Mapping properties pane - PageBook attributePane = buildMappingPageBook(container); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.TOP; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - - attributePane.setLayoutData(gridData); - - installPaneEnabler(panes); - } - - private void installPaneEnabler(ArrayList<AbstractPane<?>> panes) { - new PaneEnabler(buildPaneEnablerHolder(), panes); - } - - /* - * (non-Javadoc) - */ - @Override - protected void mappingPageChanged(JpaComposite<AttributeMapping> mappingComposite) { - if (mappingComposite == null) { - return; - } - boolean enabled = false; - - if (subject() != null && subject().getParent() != null) { - enabled = !subject().isVirtual(); - } - - mappingComposite.enableWidgets(enabled); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPersistentTypeDetailsPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPersistentTypeDetailsPage.java deleted file mode 100644 index 1e9faf0bdf..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPersistentTypeDetailsPage.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.Iterator; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.PersistentTypeDetailsPage; -import org.eclipse.jpt.ui.internal.mappings.details.OrmPersistentTypeMapAsComposite; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.PageBook; - -/** - * The default implementation of the details page used for the XML persistent - * attribute. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmJavaClassChooser | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmPersistentTypeMapAsComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | X Metadata Complete | - * | | - * | ------------------------------------------------------------------------- | - * | | | | - * | | OrmJavaClassChooser | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | Type mapping pane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OrmPersistentType - * @see OrmJavaClassChooser - * @see AccessTypeComposite - * @see OrmPersistentTypeMapAsComposite - * - * @version 2.0 - * @since 2.0 - */ -public class OrmPersistentTypeDetailsPage extends PersistentTypeDetailsPage<OrmPersistentType> -{ - /** - * Creates a new <code>OrmPersistentTypeDetailsPage</code>. - * - * @param parent The parent container - * @param widgetFactory The factory used to create various common widgets - */ - public OrmPersistentTypeDetailsPage(Composite parent, - WidgetFactory widgetFactory) { - - super(parent, widgetFactory); - } - - private PropertyValueModel<OrmTypeMapping> buildMappingHolder() { - return new PropertyAspectAdapter<OrmPersistentType, OrmTypeMapping>(getSubjectHolder(), PersistentType.MAPPING_PROPERTY) { - @Override - protected OrmTypeMapping buildValue_() { - return subject.getMapping(); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildMetadataCompleteHolder() { - return new PropertyAspectAdapter<OrmTypeMapping, Boolean>( - buildMappingHolder(), - OrmTypeMapping.DEFAULT_METADATA_COMPLETE_PROPERTY, - OrmTypeMapping.SPECIFIED_METADATA_COMPLETE_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedMetadataComplete(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedMetadataComplete(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private PropertyValueModel<String> buildMetadataCompleteStringHolder() { - - return new TransformationPropertyValueModel<Boolean, String>(buildMetadataCompleteHolder()) { - - @Override - protected String transform(Boolean value) { - - if ((subject() != null) && (value == null)) { - - boolean defaultValue = subject().getMapping().isDefaultMetadataComplete(); - String defaultStringValue = defaultValue ? JptUiOrmMessages.Boolean_True : - JptUiOrmMessages.Boolean_False; - - return NLS.bind( - JptUiOrmMessages.OrmPersistentTypeDetailsPage_metadataCompleteWithDefault, - defaultStringValue - ); - } - - return JptUiOrmMessages.OrmPersistentTypeDetailsPage_metadataComplete; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Type Mapping widgets - new OrmPersistentTypeMapAsComposite( - this, - buildSubPane(container, 0, 0, 5, 0) - ); - - // Java class widgets - new OrmJavaClassChooser(this, buildMappingHolder(), container); - - // Access widgets - new AccessTypeComposite(this, buildMappingHolder(), container); - - // Metadata complete widgets - buildTriStateCheckBoxWithDefault( - container, - JptUiOrmMessages.OrmPersistentTypeDetailsPage_metadataComplete, - buildMetadataCompleteHolder(), - buildMetadataCompleteStringHolder() - ); - - // Type mapping pane - PageBook typeMappingPageBook = buildTypeMappingPageBook(container); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.TOP; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - - typeMappingPageBook.setLayoutData(gridData); - } - - /* - * (non-Javadoc) - */ - @Override - public Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders() { - return jpaPlatformUi().ormTypeMappingUiProviders(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPrimaryKeyJoinColumnsComposite.java deleted file mode 100644 index 0be48c2f38..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmPrimaryKeyJoinColumnsComposite.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractPrimaryKeyJoinColumnsComposite; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * @see OrmEntity - * @see OrmInheritanceComposite - The container of this pane - * - * @version 2.0 - * @since 2.0 - */ -public class OrmPrimaryKeyJoinColumnsComposite extends AbstractPrimaryKeyJoinColumnsComposite<OrmEntity> -{ - - /** - * Creates a new <code>OrmPrimaryKeyJoinColumnsComposite</code>. - * - * @param parentPane The parent controller of this one - * @param parent The parent container - */ - public OrmPrimaryKeyJoinColumnsComposite(AbstractPane<? extends OrmEntity> subjectHolder, - Composite parent) { - - super(subjectHolder, parent); - } - - /** - * Creates a new <code>OrmPrimaryKeyJoinColumnsComposite</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 OrmPrimaryKeyJoinColumnsComposite(PropertyValueModel<? extends OrmEntity> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - @Override - protected ListValueModel<OrmPrimaryKeyJoinColumn> buildDefaultJoinColumnsListHolder() { - return new ListAspectAdapter<OrmEntity, OrmPrimaryKeyJoinColumn>( - getSubjectHolder(), - OrmEntity.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST) - { - @Override - protected ListIterator<OrmPrimaryKeyJoinColumn> listIterator_() { - return subject.defaultPrimaryKeyJoinColumns(); - } -//TODO defaultPrimaryKeyJoinColumnsSize when I can change the API -// @Override -// protected int size_() { -// return subject.defaultPrimaryKeyJoinColumnsSize(); -// } - }; - } - - @Override - protected void switchDefaultToSpecified() { - ListIterator<OrmPrimaryKeyJoinColumn> defaultJoinColumns = subject().defaultPrimaryKeyJoinColumns(); - - int index = 0; - while (defaultJoinColumns.hasNext()) { - OrmPrimaryKeyJoinColumn defaultJoinColumn = defaultJoinColumns.next(); - String columnName = defaultJoinColumn.getName(); - String referencedColumnName = defaultJoinColumn.getReferencedColumnName(); - - PrimaryKeyJoinColumn pkJoinColumn = subject().addSpecifiedPrimaryKeyJoinColumn(index++); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - } - -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmQueriesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmQueriesComposite.java deleted file mode 100644 index b15e641cca..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmQueriesComposite.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.ui.internal.mappings.details.QueriesComposite; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.util.PaneEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | QueriesComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see EntityMappings - * @see EntityMappingsDetailsPage - The parent container - * @see QueriesComposite - * - * @version 2.0 - * @since 2.0 - */ -public class OrmQueriesComposite extends AbstractPane<EntityMappings> { - - /** - * Creates a new <code>OrmQueriesComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public OrmQueriesComposite(AbstractPane<? extends EntityMappings> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private PropertyValueModel<Boolean> buildPaneEnablerHolder() { - return new TransformationPropertyValueModel<EntityMappings, Boolean>(getSubjectHolder()) { - @Override - protected Boolean transform(EntityMappings value) { - return (value != null); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - container = buildCollapsableSection( - container, - JptUiOrmMessages.OrmQueriesComposite_groupBox - ); - - QueriesComposite queriesComposite = new QueriesComposite( - this, - container - ); - - installPaneEnabler(queriesComposite); - } - - private void installPaneEnabler(QueriesComposite queriesComposite) { - new PaneEnabler( - buildPaneEnablerHolder(), - queriesComposite - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmSecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmSecondaryTablesComposite.java deleted file mode 100644 index 2a69d5928f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmSecondaryTablesComposite.java +++ /dev/null @@ -1,204 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.details.AbstractSecondaryTablesComposite; -import org.eclipse.jpt.ui.internal.mappings.details.PrimaryKeyJoinColumnsInSecondaryTableComposite; -import org.eclipse.jpt.ui.internal.mappings.details.SecondaryTableDialog; -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.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListPropertyValueModelAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PrimaryKeyJoinColumnsInSecondaryTableComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OrmEntity - * @see OrmEntityComposite - The container of this pane - * @see AddRemoveListPane - * @see PrimaryKeyJoinColumnsInSecondaryTableComposite - * - * @version 2.0 - * @since 1.0 - */ -public class OrmSecondaryTablesComposite extends AbstractSecondaryTablesComposite<OrmEntity> -{ - /** - * Creates a new <code>OrmSecondaryTablesComposite</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - */ - public OrmSecondaryTablesComposite(AbstractFormPane<? extends OrmEntity> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * 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 OrmSecondaryTablesComposite(PropertyValueModel<? extends OrmEntity> subjectHolder, - Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - private WritablePropertyValueModel<Boolean> buildDefineInXmlHolder() { - return new DefineInXmlHolder(); - } - - private ListValueModel<OrmSecondaryTable> buildSecondaryTablesListHolder() { - List<ListValueModel<OrmSecondaryTable>> list = new ArrayList<ListValueModel<OrmSecondaryTable>>(); - list.add(buildSpecifiedSecondaryTablesListHolder()); - list.add(buildVirtualSecondaryTablesListHolder()); - return new CompositeListValueModel<ListValueModel<OrmSecondaryTable>, OrmSecondaryTable>(list); - } - - private ListValueModel<OrmSecondaryTable> buildSecondaryTablesListModel() { - return new ItemPropertyListValueModelAdapter<OrmSecondaryTable>(buildSecondaryTablesListHolder(), - Table.SPECIFIED_NAME_PROPERTY); - } - - private ListValueModel<OrmSecondaryTable> buildSpecifiedSecondaryTablesListHolder() { - return new ListAspectAdapter<OrmEntity, OrmSecondaryTable>(getSubjectHolder(), Entity.SPECIFIED_SECONDARY_TABLES_LIST) { - @Override - protected ListIterator<OrmSecondaryTable> listIterator_() { - return subject.specifiedSecondaryTables(); - } - - @Override - protected int size_() { - return subject.specifiedSecondaryTablesSize(); - } - }; - } - - private ListValueModel<OrmSecondaryTable> buildVirtualSecondaryTablesListHolder() { - return new ListAspectAdapter<OrmEntity, OrmSecondaryTable>(getSubjectHolder(), OrmEntity.VIRTUAL_SECONDARY_TABLES_LIST) { - @Override - protected ListIterator<OrmSecondaryTable> listIterator_() { - return subject.virtualSecondaryTables(); - } - - @Override - protected int size_() { - return subject.virtualSecondaryTablesSize(); - } - }; - } - - @Override - protected void initializeLayout(Composite container) { - - int groupBoxMargin = groupBoxMargin(); - - WritablePropertyValueModel<SecondaryTable> secondaryTableHolder = - buildSecondaryTableHolder(); - - WritablePropertyValueModel<Boolean> defineInXmlHolder = - buildDefineInXmlHolder(); - - // Override Define In XML check box - buildCheckBox( - buildSubPane(container, 0, groupBoxMargin), - JptUiMappingsMessages.OrmSecondaryTablesComposite_defineInXml, - defineInXmlHolder - ); - - // Secondary Tables add/remove list pane - AddRemoveListPane<Entity> listPane = new AddRemoveListPane<Entity>( - this, - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), - buildSecondaryTablesAdapter(), - buildSecondaryTablesListModel(), - secondaryTableHolder, - buildSecondaryTableLabelProvider(), - JpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS//TODO need a help context id for this - ); - - installListPaneEnabler(defineInXmlHolder, listPane); - - // Primary Key Join Columns pane - new PrimaryKeyJoinColumnsInSecondaryTableComposite( - this, - secondaryTableHolder, - container - ); - } - - private void installListPaneEnabler(WritablePropertyValueModel<Boolean> defineInXmlHolder, - AddRemoveListPane<Entity> listPane) { - - new PaneEnabler(defineInXmlHolder, listPane); - } - - @Override - protected SecondaryTableDialog buildSecondaryTableDialogForAdd() { - //defaultSchema and defaultCatalog should not be taken from the Table in this case. The table default schema could be what is the specified schema on the java table. - return new SecondaryTableDialog(getControl().getShell(), subject().getJpaProject(), subject().getEntityMappings().getDefaultSchema(), subject().getEntityMappings().getDefaultCatalog()); - } - - private class DefineInXmlHolder extends ListPropertyValueModelAdapter<Boolean> - implements WritablePropertyValueModel<Boolean> { - - public DefineInXmlHolder() { - super(buildVirtualSecondaryTablesListHolder()); - } - - @Override - protected Boolean buildValue() { - if (subject() == null) { - return Boolean.FALSE; - } - return Boolean.valueOf(subject().secondaryTablesDefinedInXml()); - } - - public void setValue(Boolean value) { - subject().setSecondaryTablesDefinedInXml(value.booleanValue()); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmSequenceGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmSequenceGeneratorComposite.java deleted file mode 100644 index 18a8421638..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmSequenceGeneratorComposite.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.ui.internal.mappings.db.SequenceCombo; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ----------------------------------------------------- | - * | Name: | I | | - * | ----------------------------------------------------- | - * | ----------------------------------------------------- | - * | Sequence Generator: | SequenceCombo | | - * | ----------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see OrmSequenceGenerator - * @see EntityMappings - * @see OrmGeneratorsComposite - The parent container - * @see SequenceCombo - * - * @version 2.0 - * @since 2.0 - */ -public class OrmSequenceGeneratorComposite extends AbstractPane<OrmSequenceGenerator> -{ - /** - * Creates a new <code>OrmSequenceGeneratorComposite</code>. - * - * @param parentPane The parent pane of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public OrmSequenceGeneratorComposite(AbstractPane<?> parentPane, - PropertyValueModel<OrmSequenceGenerator> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent, false); - } - - private WritablePropertyValueModel<String> buildGeneratorNameHolder() { - return new PropertyAspectAdapter<OrmSequenceGenerator, String>(getSubjectHolder(), OrmSequenceGenerator.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - public void setValue_(String value) { - subject.setName(value); - } - }; - } - - private SequenceCombo<OrmSequenceGenerator> buildSequenceNameCombo(Composite parent) { - - return new SequenceCombo<OrmSequenceGenerator>(this, parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(OrmSequenceGenerator.DEFAULT_SEQUENCE_NAME_PROPERTY); - propertyNames.add(OrmSequenceGenerator.SPECIFIED_SEQUENCE_NAME_PROPERTY); - } - - @Override - protected String defaultValue() { - return JptUiMappingsMessages.SequenceGeneratorComposite_default; - } - - @Override - protected Schema schema() { - // TODO - return null; - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedSequenceName(value); - } - - @Override - protected String value() { - return subject().getSpecifiedSequenceName(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Name widgets - buildLabeledText( - container, - JptUiOrmMessages.OrmSequenceGeneratorComposite_name, - buildGeneratorNameHolder(), - JpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_NAME - ); - - // Sequence Generator widgets - buildLabeledComposite( - container, - JptUiOrmMessages.OrmSequenceGeneratorComposite_sequence, - buildSequenceNameCombo(container), - JpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_SEQUENCE - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java deleted file mode 100644 index 49ea302cfa..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java +++ /dev/null @@ -1,282 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; -import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * 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 OrmTableGenerator - * @see OrmGeneratorsComposite - The parent container - * - * @version 2.0 - * @since 1.0 - */ -public class OrmTableGeneratorComposite extends AbstractPane<OrmTableGenerator> -{ - /** - * Creates a new <code>OrmTableGeneratorComposite</code>. - * - * @param parentPane The parent pane of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public OrmTableGeneratorComposite(AbstractPane<?> parentPane, - PropertyValueModel<OrmTableGenerator> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent, false); - } - - private WritablePropertyValueModel<String> buildGeneratorNameHolder() { - return new PropertyAspectAdapter<OrmTableGenerator, String>(getSubjectHolder(), Generator.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - public void setValue_(String value) { - subject.setName(value); - } - }; - } - - private ColumnCombo<OrmTableGenerator> buildPkColumnNameCombo(Composite parent) { - - return new ColumnCombo<OrmTableGenerator>(this, parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_PK_COLUMN_NAME_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_PK_COLUMN_NAME_PROPERTY); - } - - @Override - protected String defaultValue() { - return subject().getDefaultPkColumnName(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedPkColumnName(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedPkColumnName(); - } - }; - } - - private ColumnCombo<OrmTableGenerator> buildPkColumnValueCombo(Composite parent) { - - return new ColumnCombo<OrmTableGenerator>(this, parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_PK_COLUMN_VALUE_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_PK_COLUMN_VALUE_PROPERTY); - } - - @Override - protected String defaultValue() { - return subject().getDefaultPkColumnValue(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedPkColumnValue(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedPkColumnValue(); - } - }; - } - - private TableCombo<OrmTableGenerator> buildTableNameCombo(Composite parent) { - - return new TableCombo<OrmTableGenerator>(this, parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_TABLE_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_TABLE_PROPERTY); - propertyNames.add(TableGenerator.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_SCHEMA_PROPERTY); - propertyNames.add(TableGenerator.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_CATALOG_PROPERTY); - } - - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - if (propertyName == TableGenerator.DEFAULT_SCHEMA_PROPERTY - || propertyName == TableGenerator.SPECIFIED_SCHEMA_PROPERTY - || propertyName == TableGenerator.DEFAULT_CATALOG_PROPERTY - || propertyName == TableGenerator.SPECIFIED_CATALOG_PROPERTY ) { - repopulate(); - } - } - - @Override - protected String defaultValue() { - return subject().getDefaultTable(); - } - - @Override - protected String schemaName() { - return subject().getSchema(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedTable(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedTable(); - } - }; - } - - private ColumnCombo<OrmTableGenerator> buildValueColumnCombo(Composite parent) { - - return new ColumnCombo<OrmTableGenerator>(this, parent) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(TableGenerator.DEFAULT_VALUE_COLUMN_NAME_PROPERTY); - propertyNames.add(TableGenerator.SPECIFIED_VALUE_COLUMN_NAME_PROPERTY); - } - - @Override - protected String defaultValue() { - return subject().getDefaultValueColumnName(); - } - - @Override - protected void setValue(String value) { - subject().setSpecifiedValueColumnName(value); - } - - @Override - protected Table table() { - return subject().getDbTable(); - } - - @Override - protected String value() { - return subject().getSpecifiedValueColumnName(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Name widgets - buildLabeledText( - container, - JptUiOrmMessages.OrmTableGeneratorComposite_name, - buildGeneratorNameHolder(), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_NAME - ); - - // Table widgets - buildLabeledComposite( - container, - JptUiOrmMessages.OrmTableGeneratorComposite_table, - buildTableNameCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_TABLE - ); - - // Primary Key Column widgets - buildLabeledComposite( - container, - JptUiOrmMessages.OrmTableGeneratorComposite_pkColumn, - buildPkColumnNameCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN - ); - - // Value Column widgets - buildLabeledComposite( - container, - JptUiOrmMessages.OrmTableGeneratorComposite_valueColumn, - buildValueColumnCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_VALUE_COLUMN - ); - - // Primary Key Column Value widgets - buildLabeledComposite( - container, - JptUiOrmMessages.OrmTableGeneratorComposite_pkColumnValue, - buildPkColumnValueCombo(container), - JpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/PersistenceUnitMetadataComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/PersistenceUnitMetadataComposite.java deleted file mode 100644 index afd330628f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/PersistenceUnitMetadataComposite.java +++ /dev/null @@ -1,263 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.orm.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.mappings.db.CatalogCombo; -import org.eclipse.jpt.ui.internal.mappings.db.SchemaCombo; -import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.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: | SchemaCombo | | - * | ------------------------------------------------------------ | - * | ------------------------------------------------------------ | - * | Catalog: | CatalogCombo | | - * | ------------------------------------------------------------ | - * | ------------------------------------------------------------ | - * | Access Type: | |v| | - * | ------------------------------------------------------------ | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnitMetadata - * @see PersistenceUnitDefaults - * @see EntityMappingsDetailsPage - The parent container - * @see CatalogCombo - * @see SchemaCombo - * @see EnumFormComboViewer - * - * @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 EnumFormComboViewer<PersistenceUnitDefaults, AccessType> buildAccessTypeCombo(Composite container) { - - return new EnumFormComboViewer<PersistenceUnitDefaults, AccessType>(this, buildPersistenceUnitDefaultsHolder(), container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistenceUnitDefaults.ACCESS_PROPERTY); - } - - @Override - protected AccessType[] choices() { - return AccessType.values(); - } - - @Override - protected AccessType defaultValue() { - return null; - } - - @Override - protected String displayString(AccessType value) { - return buildDisplayString( - JptUiOrmMessages.class, - PersistenceUnitMetadataComposite.this, - value - ); - } - - @Override - protected AccessType getValue() { - return subject().getAccess(); - } - - @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 CatalogCombo<PersistenceUnitDefaults> buildCatalogCombo(Composite container) { - - return new CatalogCombo<PersistenceUnitDefaults>(this, buildPersistenceUnitDefaultsHolder(), container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistenceUnitDefaults.DEFAULT_CATALOG_PROPERTY); - propertyNames.add(PersistenceUnitDefaults.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(); - } - }; - } - - private PropertyValueModel<PersistenceUnitDefaults> buildPersistenceUnitDefaultsHolder() { - return new TransformationPropertyValueModel<PersistenceUnitMetadata, PersistenceUnitDefaults>(getSubjectHolder()) { - @Override - protected PersistenceUnitDefaults transform_(PersistenceUnitMetadata value) { - return value.getPersistenceUnitDefaults(); - } - }; - } - - private SchemaCombo<PersistenceUnitDefaults> buildSchemaCombo(Composite container) { - - return new SchemaCombo<PersistenceUnitDefaults>(this, buildPersistenceUnitDefaultsHolder(), container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistenceUnitDefaults.DEFAULT_SCHEMA_PROPERTY); - propertyNames.add(PersistenceUnitDefaults.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(); - } - }; - } - - 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 = buildCollapsableSection( - container, - JptUiOrmMessages.PersistenceUnitMetadataComposite_persistenceUnitSection - ); - - // XML mapping metadata complete check box - buildCheckBox( - container, - JptUiOrmMessages.PersistenceUnitMetadataComposite_xmlMappingMetadataCompleteCheckBox, - buildXmlMappingMetadataCompleteHolder(), - JpaHelpContextIds.ENTITY_ORM_XML - ); - - // Cascade Persist widgets - buildCheckBox( - container, - JptUiOrmMessages.PersistenceUnitMetadataComposite_cascadePersistCheckBox, - buildCascadePersistHolder(), - JpaHelpContextIds.ENTITY_ORM_CASCADE - ); - - // Schema widgets - buildLabeledComposite( - container, - JptUiOrmMessages.PersistenceUnitMetadataComposite_schema, - buildSchemaCombo(container), - JpaHelpContextIds.ENTITY_ORM_SCHEMA - ); - - // Catalog widgets - buildLabeledComposite( - container, - JptUiOrmMessages.PersistenceUnitMetadataComposite_catalog, - buildCatalogCombo(container), - JpaHelpContextIds.ENTITY_ORM_CATALOG - ); - - // Access Type widgets - buildLabeledComposite( - container, - JptUiOrmMessages.PersistenceUnitMetadataComposite_access, - buildAccessTypeCombo(container), - JpaHelpContextIds.ENTITY_ORM_ACCESS - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java deleted file mode 100644 index c386cfb830..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence; - -import org.eclipse.osgi.util.NLS; - -/** - * The localized messages used by the persistence editor. - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class JptUiPersistenceMessages -{ - public static String Boolean_False; - public static String Boolean_True; - - public static String PersistenceEditor_page_help; - public static String PersistenceEditor_sourceTab; - - public static String PersistenceUnitClassesComposite_description; - public static String PersistenceUnitClassesComposite_excludeUnlistedMappedClasses; - public static String PersistenceUnitClassesComposite_excludeUnlistedMappedClassesWithDefault; - public static String PersistenceUnitClassesComposite_mappedClassesNoName; - public static String PersistenceUnitClassesComposite_open; - - public static String PersistenceUnitConnectionComposite_connection; - public static String PersistenceUnitConnectionComposite_database; - public static String PersistenceUnitConnectionComposite_general; - - public static String PersistenceUnitConnectionDatabaseComposite_jtaDatasourceName; - public static String PersistenceUnitConnectionDatabaseComposite_nonJtaDatasourceName; - - public static String PersistenceUnitConnectionGeneralComposite_default; - public static String PersistenceUnitConnectionGeneralComposite_jta; - public static String PersistenceUnitConnectionGeneralComposite_resource_local; - public static String PersistenceUnitConnectionGeneralComposite_transactionType; - - public static String PersistenceUnitGeneralComposite_general; - public static String PersistenceUnitGeneralComposite_javaArchives; - public static String PersistenceUnitGeneralComposite_jpaMappingDescriptors; - public static String PersistenceUnitGeneralComposite_jpaMappingDescriptors_description; - public static String PersistenceUnitGeneralComposite_mappedClasses; - public static String PersistenceUnitGeneralComposite_name; - public static String PersistenceUnitGeneralComposite_persistenceProvider; - public static String PersistenceUnitGeneralComposite_description; - - public static String PersistenceUnitMappingFilesComposite_mappingFileDialog_message; - public static String PersistenceUnitMappingFilesComposite_mappingFileDialog_title; - public static String PersistenceUnitMappingFilesComposite_ormNoName; - - public static String PersistenceUnitPropertiesComposite_nameColumn; - public static String PersistenceUnitPropertiesComposite_properties; - public static String PersistenceUnitPropertiesComposite_properties_description; - public static String PersistenceUnitPropertiesComposite_valueColumn; - - static { - NLS.initializeMessages("jpt_ui_persistence", JptUiPersistenceMessages.class); - } - - private JptUiPersistenceMessages() { - throw new UnsupportedOperationException(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitClassesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitClassesComposite.java deleted file mode 100644 index 1e1e61ec98..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitClassesComposite.java +++ /dev/null @@ -1,392 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import java.util.ListIterator; -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.search.IJavaSearchScope; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jdt.ui.IJavaElementSearchConstants; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -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.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.progress.IProgressService; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | Description | - * | | - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | x Exclude Unlisted Mapped Classes | - * | | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitGeneralComposite - The parent container - * @see AddRemoveListPane - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class PersistenceUnitClassesComposite extends AbstractPane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitMappedClassesComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitClassesComposite(AbstractPane<? extends PersistenceUnit> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private void addMappedClass(ObjectListSelectionModel listSelectionModel) { - - IType type = chooseType(); - - if (type != null) { - ClassRef classRef = subject().addSpecifiedClassRef(); - classRef.setClassName(type.getFullyQualifiedName('.')); - listSelectionModel.setSelectedValue(classRef); - } - } - - private Adapter buildAdapter() { - return new AddRemoveListPane.AbstractAdapter() { - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - addMappedClass(listSelectionModel); - } - - @Override - public boolean enableOptionOnSelectionChange(ObjectListSelectionModel listSelectionModel) { - if (!super.enableOptionOnSelectionChange(listSelectionModel)) { - return false; - } - - return findType((ClassRef) listSelectionModel.selectedValue()) != null; - } - - @Override - public boolean hasOptionalButton() { - return true; - } - - @Override - public String optionalButtonText() { - return JptUiPersistenceMessages.PersistenceUnitClassesComposite_open; - } - - @Override - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - openMappedClass((ClassRef) listSelectionModel.selectedValue()); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - for (Object item : listSelectionModel.selectedValues()) { - subject().removeSpecifiedClassRef((ClassRef) item); - } - } - }; - } - - private WritablePropertyValueModel<Boolean> buildExcludeUnlistedMappedClassesHolder() { - return new PropertyAspectAdapter<PersistenceUnit, Boolean>( - getSubjectHolder(), - PersistenceUnit.DEFAULT_EXCLUDE_UNLISTED_CLASSED_PROPERTY, - PersistenceUnit.SPECIFIED_EXCLUDE_UNLISTED_CLASSED_PROPERTY) - { - @Override - protected Boolean buildValue_() { - return subject.getSpecifiedExcludeUnlistedClasses(); - } - - @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedExcludeUnlistedClasses(value); - } - - @Override - protected void subjectChanged() { - Object oldValue = this.getValue(); - super.subjectChanged(); - Object newValue = this.getValue(); - - // Make sure the default value is appended to the text - if (oldValue == newValue && newValue == null) { - this.fireAspectChange(Boolean.TRUE, newValue); - } - } - }; - } - - private PropertyValueModel<String> buildExcludeUnlistedMappedClassesStringHolder() { - - return new TransformationPropertyValueModel<Boolean, String>(buildExcludeUnlistedMappedClassesHolder()) { - - @Override - protected String transform(Boolean value) { - - if ((subject() != null) && (value == null)) { - - Boolean defaultValue = subject().getDefaultExcludeUnlistedClasses(); - - if (defaultValue != null) { - - String defaultStringValue = defaultValue ? JptUiPersistenceMessages.Boolean_True : - JptUiPersistenceMessages.Boolean_False; - - return NLS.bind( - JptUiPersistenceMessages.PersistenceUnitClassesComposite_excludeUnlistedMappedClassesWithDefault, - defaultStringValue - ); - } - } - - return JptUiPersistenceMessages.PersistenceUnitClassesComposite_excludeUnlistedMappedClasses; - } - }; - } - - private ILabelProvider buildLabelProvider() { - return new LabelProvider() { - @Override - public Image getImage(Object element) { - ClassRef classRef = (ClassRef) element; - JavaPersistentType persistentType = classRef.getJavaPersistentType(); - Image image = null; - - if (persistentType != null) { - image = JpaMappingImageHelper.imageForTypeMapping(persistentType.getMappingKey()); - } - - if (image != null) { - return image; - } - - return JptUiPlugin.getImage(JptUiIcons.WARNING); - } - - @Override - public String getText(Object element) { - ClassRef classRef = (ClassRef) element; - String name = classRef.getClassName(); - - if (name == null) { - name = JptUiPersistenceMessages.PersistenceUnitClassesComposite_mappedClassesNoName; - } - - return name; - } - }; - } - - private ListValueModel<ClassRef> buildItemListHolder() { - return new ItemPropertyListValueModelAdapter<ClassRef>( - buildListHolder(), - ClassRef.JAVA_PERSISTENT_TYPE_PROPERTY, - ClassRef.CLASS_NAME_PROPERTY - ); - } - - private ListValueModel<ClassRef> buildListHolder() { - return new ListAspectAdapter<PersistenceUnit, ClassRef>(getSubjectHolder(), PersistenceUnit.SPECIFIED_CLASS_REF_LIST) { - @Override - protected ListIterator<ClassRef> listIterator_() { - return subject.specifiedClassRefs(); - } - - @Override - protected int size_() { - return subject.specifiedClassRefsSize(); - } - }; - } - - private WritablePropertyValueModel<ClassRef> buildSelectedItemHolder() { - return new SimplePropertyValueModel<ClassRef>(); - } - - /** - * Prompts the user the Open Type dialog. - * - * @return Either the selected type or <code>null</code> if the user - * cancelled the dialog - */ - private IType chooseType() { - - IPackageFragmentRoot root = packageFragmentRoot(); - - 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( - shell(), - service, - scope, - IJavaElementSearchConstants.CONSIDER_CLASSES, - false, - "" - ); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - return null; - } - - typeSelectionDialog.setTitle(JptUiMessages.ClassChooserPane_dialogTitle); - typeSelectionDialog.setMessage(JptUiMessages.ClassChooserPane_dialogMessage); - - if (typeSelectionDialog.open() == Window.OK) { - return (IType) typeSelectionDialog.getResult()[0]; - } - - return null; - } - - private IType findType(ClassRef classRef) { - String className = classRef.getClassName(); - - if (className != null) { - try { - return subject().getJpaProject().getJavaProject().findType(className); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - } - - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Description - buildMultiLineLabel( - container, - JptUiPersistenceMessages.PersistenceUnitClassesComposite_description - ); - - // List pane - new AddRemoveListPane<PersistenceUnit>( - this, - container, - buildAdapter(), - buildItemListHolder(), - buildSelectedItemHolder(), - buildLabelProvider() - ) - { - @Override - protected void initializeTable(Table table) { - super.initializeTable(table); - - Composite container = table.getParent(); - GridData gridData = (GridData) container.getLayoutData(); - gridData.heightHint = 75; - } - }; - - buildTriStateCheckBoxWithDefault( - container, - JptUiPersistenceMessages.PersistenceUnitClassesComposite_excludeUnlistedMappedClasses, - buildExcludeUnlistedMappedClassesHolder(), - buildExcludeUnlistedMappedClassesStringHolder() - ); - } - - private void openMappedClass(ClassRef classRef) { - - IType type = findType(classRef); - - if (type != null) { - try { - IJavaElement javaElement = type.getParent(); - JavaUI.openInEditor(javaElement, true, true); - } - catch (PartInitException e) { - JptUiPlugin.log(e); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - } - } - - private IPackageFragmentRoot packageFragmentRoot() { - IProject project = subject().getJpaProject().getProject(); - IJavaProject root = JavaCore.create(project); - - try { - return root.getAllPackageFragmentRoots()[0]; - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - - return null; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionComposite.java deleted file mode 100644 index ab3d703856..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionComposite.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaPageComposite; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | - General --------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PersistenceUnitConnectionGeneralComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * | | - * | - Database -------------------------------------------------------------- | - * | ------------------------------------------------------------------------- | - * | | | | - * | | PersistenceUnitConnectionDatabaseComposite | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitConnectionGeneralComposite - * @see PersistenceUnitConnectionDatabaseComposite - * - * @version 2.0 - * @since 2.0 - */ -public class PersistenceUnitConnectionComposite extends AbstractFormPane<PersistenceUnit> - implements JpaPageComposite<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitConnectionComposite</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 PersistenceUnitConnectionComposite(PropertyValueModel<PersistenceUnit> subjectHolder, - Composite container, - WidgetFactory widgetFactory) { - - super(subjectHolder, container, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - protected Composite buildContainer(Composite parent) { - - GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 0; - layout.marginLeft = 0; - layout.marginBottom = 0; - layout.marginRight = 0; - layout.verticalSpacing = 15; - - Composite container = buildPane(parent, layout); - updateGridData(container); - - return container; - } - - /* - * (non-Javadoc) - */ - public String getHelpID() { - return JpaHelpContextIds.PERSISTENCE_UNIT_CONNECTION; - } - - private void initializeDatabasePane(Composite container) { - - container = buildSection( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionComposite_database - ); - - new PersistenceUnitConnectionDatabaseComposite(this, container); - } - - private void initializeGeneralPane(Composite container) { - - container = buildSection( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionComposite_general - ); - - new PersistenceUnitConnectionGeneralComposite(this, container); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - initializeGeneralPane(container); - initializeDatabasePane(container); - } - - /* - * (non-Javadoc) - */ - public Image getPageImage() { - return null; - } - - /* - * (non-Javadoc) - */ - public String getPageText() { - return JptUiPersistenceMessages.PersistenceUnitConnectionComposite_connection; - } - - private void updateGridData(Composite container) { - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - container.setLayoutData(gridData); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionDatabaseComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionDatabaseComposite.java deleted file mode 100644 index 3c3a3aaeb2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionDatabaseComposite.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.util.ControlEnabler; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Text; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------ | - * | JTA Datasource Name: | I | | - * | ------------------------------------------------ | - * | ------------------------------------------------ | - * | Non-JTA Datasource Name: | I | | - * | ------------------------------------------------ | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitConnectionComposite - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class PersistenceUnitConnectionDatabaseComposite extends AbstractPane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitConnectionDatabaseComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitConnectionDatabaseComposite(AbstractPane<PersistenceUnit> subjectHolder, - Composite container) { - - super(subjectHolder, container); - } - - private PropertyValueModel<Boolean> buildJTADatasourceNameBooleanHolder() { - return new TransformationPropertyValueModel<PersistenceUnitTransactionType, Boolean>(buildTransactionTypeHolder()) { - @Override - protected Boolean transform_(PersistenceUnitTransactionType value) { - return value == PersistenceUnitTransactionType.JTA; - } - }; - } - - private WritablePropertyValueModel<String> buildJTADatasourceNameHolder() { - return new PropertyAspectAdapter<PersistenceUnit, String>(getSubjectHolder(), PersistenceUnit.JTA_DATA_SOURCE_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getJtaDataSource(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setJtaDataSource(value); - } - }; - } - - private PropertyValueModel<Boolean> buildNonJTADatasourceNameBooleanHolder() { - return new TransformationPropertyValueModel<PersistenceUnitTransactionType, Boolean>(buildTransactionTypeHolder()) { - @Override - protected Boolean transform_(PersistenceUnitTransactionType value) { - return value == PersistenceUnitTransactionType.RESOURCE_LOCAL; - } - }; - } - - private WritablePropertyValueModel<String> buildNonJTADatasourceNameHolder() { - return new PropertyAspectAdapter<PersistenceUnit, String>(getSubjectHolder(), PersistenceUnit.NON_JTA_DATA_SOURCE_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getNonJtaDataSource(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setNonJtaDataSource(value); - } - }; - } - - private PropertyValueModel<PersistenceUnitTransactionType> buildTransactionTypeHolder() { - return new PropertyAspectAdapter<PersistenceUnit, PersistenceUnitTransactionType>( - getSubjectHolder(), - PersistenceUnit.DEFAULT_TRANSACTION_TYPE_PROPERTY, - PersistenceUnit.SPECIFIED_TRANSACTION_TYPE_PROPERTY) - { - @Override - protected PersistenceUnitTransactionType buildValue_() { - return subject.getTransactionType(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // JTA Datasource Name widgets - Text text = buildLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionDatabaseComposite_jtaDatasourceName, - buildJTADatasourceNameHolder() - ); - - installJTADatasourceNameEnabler(text); - - // Non-JTA Datasource Name widgets - text = buildLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionDatabaseComposite_nonJtaDatasourceName, - buildNonJTADatasourceNameHolder() - ); - - installNonJTADatasourceNameEnabler(text); - } - - private void installJTADatasourceNameEnabler(Text text) { - new ControlEnabler(buildJTADatasourceNameBooleanHolder(), text); - } - - private void installNonJTADatasourceNameEnabler(Text text) { - new ControlEnabler(buildNonJTADatasourceNameBooleanHolder(), text); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionGeneralComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionGeneralComposite.java deleted file mode 100644 index 4149abc57b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionGeneralComposite.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import java.util.Collection; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------ | - * | Transaction Type: | |v| | - * | ------------------------------------------------------ | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitConnectionComposite - The parent container - * - * @version 2.0 - * @since 2.0 - */ -public class PersistenceUnitConnectionGeneralComposite extends AbstractPane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitConnectionGeneralComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitConnectionGeneralComposite(AbstractPane<PersistenceUnit> subjectHolder, - Composite container) { - - super(subjectHolder, container); - } - - private EnumFormComboViewer<PersistenceUnit, PersistenceUnitTransactionType> buildTransactionTypeCombo(Composite container) { - - return new EnumFormComboViewer<PersistenceUnit, PersistenceUnitTransactionType>(this, container) { - - @Override - protected void addPropertyNames(Collection<String> propertyNames) { - super.addPropertyNames(propertyNames); - propertyNames.add(PersistenceUnit.SPECIFIED_TRANSACTION_TYPE_PROPERTY); - propertyNames.add(PersistenceUnit.DEFAULT_TRANSACTION_TYPE_PROPERTY); - } - - @Override - protected PersistenceUnitTransactionType[] choices() { - return PersistenceUnitTransactionType.values(); - } - - @Override - protected PersistenceUnitTransactionType defaultValue() { - return subject().getDefaultTransactionType(); - } - - @Override - protected String displayString(PersistenceUnitTransactionType value) { - return buildDisplayString( - JptUiPersistenceMessages.class, - PersistenceUnitConnectionGeneralComposite.this, - value - ); - } - - @Override - protected PersistenceUnitTransactionType getValue() { - return subject().getSpecifiedTransactionType(); - } - - @Override - protected void setValue(PersistenceUnitTransactionType value) { - subject().setSpecifiedTransactionType(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Transaction Type widgets - buildLabeledComposite( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionGeneralComposite_transactionType, - buildTransactionTypeCombo(container).getControl() - ); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java deleted file mode 100644 index db7cb4ee8b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaPageComposite; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | - General --------------------------------------------------------------- | - * | ------------------------------------------------- | - * | Name: | I | | - * | ------------------------------------------------- | - * | ------------------------------------------------- | - * | Persistence Provider: | |v| | - * | ------------------------------------------------- | - * | | - * | | - * | - Mapped Classes -------------------------------------------------------- | - * | | - * | Description | - * | | - * | ----------------------------------------------------------------------- | - * | | | | - * | | PersistenceUnitMappedClassesComposite | | - * | | | | - * | ----------------------------------------------------------------------- | - * | | - * | | - * | - XML Mapping Files ----------------------------------------------------- | - * | | - * | Description | - * | | - * | ----------------------------------------------------------------------- | - * | | | | - * | | PersistenceUnitMappingFilesComposite | | - * | | | | - * | ----------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitJarFilesComposite - * @see PersistenceUnitMappedClassesComposite - * @see PersistenceUnitMappingFilesComposite - * - * @version 2.0 - * @since 2.0 - */ -public class PersistenceUnitGeneralComposite extends AbstractFormPane<PersistenceUnit> - implements JpaPageComposite<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitGeneralComposite</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 PersistenceUnitGeneralComposite(PropertyValueModel<PersistenceUnit> subjectHolder, - Composite container, - WidgetFactory widgetFactory) { - - super(subjectHolder, container, widgetFactory); - } - -// private void initializeJavaArchivesPane(Composite container) { -// -// container = buildSection( -// container, -// JptUiPersistenceMessages.PersistenceUnitComposite_javaArchives -// ); -// -// new PersistenceUnitJavaArchivesComposite(this, container); -// } - - /* - * (non-Javadoc) - */ - @Override - protected Composite buildContainer(Composite parent) { - - GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 0; - layout.marginLeft = 0; - layout.marginBottom = 0; - layout.marginRight = 0; - layout.verticalSpacing = 15; - - Composite container = buildPane(parent, layout); - updateGridData(container); - - return container; - } - - private WritablePropertyValueModel<String> buildPersistenceProviderHolder() { - return new PropertyAspectAdapter<PersistenceUnit, String>(getSubjectHolder(), PersistenceUnit.PROVIDER_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getProvider(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setProvider(value); - } - }; - } - - private WritablePropertyValueModel<String> buildPersistenceUnitNameHolder() { - return new PropertyAspectAdapter<PersistenceUnit, String>(getSubjectHolder(), PersistenceUnit.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<String> buildPersistenceUnitDescriptionHolder() { - return new PropertyAspectAdapter<PersistenceUnit, String>(getSubjectHolder(), PersistenceUnit.DESCRIPTION_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getDescription(); - } - - @Override - protected void setValue_(String value) { - if (value.length() == 0) { - value = null; - } - subject.setDescription(value); - } - }; - } - - /* - * (non-Javadoc) - */ - public String getHelpID() { - return JpaHelpContextIds.PERSISTENCE_UNIT_GENERAL; - } - - /* - * (non-Javadoc) - */ - public Image getPageImage() { - return null; - } - - /* - * (non-Javadoc) - */ - public String getPageText() { - return JptUiPersistenceMessages.PersistenceUnitGeneralComposite_general; - } - - private void initializeGeneralPane(Composite container) { - - container = buildSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_general - ); - - // Name widgets - buildLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_name, - buildPersistenceUnitNameHolder() - ); - - // Persistence Provider widgets - buildLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_persistenceProvider, - buildPersistenceProviderHolder() - ); - - // Description widgets - buildLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_description, - buildPersistenceUnitDescriptionHolder() - ); - } - - private void initializeJPAMappingDescriptorsPane(Composite container) { - - container = buildSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jpaMappingDescriptors, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jpaMappingDescriptors_description - ); - - updateGridData(container); - updateGridData(container.getParent()); - - new PersistenceUnitMappingFilesComposite(this, container); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - initializeGeneralPane(container); - initializeMappedClassesPane(container); - initializeJPAMappingDescriptorsPane(container); -// initializeJavaArchivesPane(container); - - } - - private void initializeMappedClassesPane(Composite container) { - - container = buildSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_mappedClasses - ); - - updateGridData(container); - updateGridData(container.getParent()); - - new PersistenceUnitClassesComposite(this, container); - } - - private void updateGridData(Composite container) { - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - container.setLayoutData(gridData); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java deleted file mode 100644 index b924710d18..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | | - * | Description | - * | | - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitGeneralComposite - The parent container - * @see AddRemoveListPane - * - * @version 2.0 - * @since 2.0 - */ -public class PersistenceUnitJarFilesComposite extends AbstractPane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitJPAMappingDescriptorsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitJarFilesComposite(AbstractPane<? extends PersistenceUnit> parentPane, - Composite parent) { - - super(parentPane, parent, false); - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java deleted file mode 100644 index 2d5b0b1ec5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java +++ /dev/null @@ -1,446 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ListIterator; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.resource.orm.translators.OrmXmlMapper; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; -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.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.model.WorkbenchContentProvider; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceComparator; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitGeneralComposite - The parent container - * @see AddRemoveListPane - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class PersistenceUnitMappingFilesComposite extends AbstractPane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitMappingFilesComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitMappingFilesComposite(AbstractPane<? extends PersistenceUnit> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Prompts a dialog showing a tree structure of the source paths where the - * only files shown are JPA mapping descriptors file. The XML file has to be - * an XML file with the root tag: <entity-mappings>. - * - * @param listSelectionModel The selection model used to select the new files - */ - private void addJPAMappingDescriptor(ObjectListSelectionModel listSelectionModel) { - - IProject project = subject().getJpaProject().getProject(); - - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( - shell(), - new WorkbenchLabelProvider(), - new WorkbenchContentProvider() - ); - - dialog.setHelpAvailable(false); - dialog.setValidator(buildValidator()); - dialog.setTitle(JptUiPersistenceMessages.PersistenceUnitMappingFilesComposite_mappingFileDialog_title); - dialog.setMessage(JptUiPersistenceMessages.PersistenceUnitMappingFilesComposite_mappingFileDialog_message); - dialog.addFilter(new XmlFileViewerFilter(subject().getJpaProject().getJavaProject())); - dialog.setInput(project); - dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); - - SWTUtil.show( - dialog, - buildSelectionDialogPostExecution(listSelectionModel) - ); - } - - private Adapter buildAdapter() { - return new AddRemoveListPane.AbstractAdapter() { - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - addJPAMappingDescriptor(listSelectionModel); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - for (Object item : listSelectionModel.selectedValues()) { - subject().removeSpecifiedMappingFileRef((MappingFileRef) item); - } - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Composite buildContainer(Composite parent) { - - GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 0; - layout.marginLeft = 0; - layout.marginBottom = 0; - layout.marginRight = 0; - - Composite container = buildPane(parent, layout); - updateGridData(container); - - return container; - } - - private ListValueModel<MappingFileRef> buildItemListHolder() { - return new ItemPropertyListValueModelAdapter<MappingFileRef>( - buildListHolder(), - MappingFileRef.FILE_NAME_PROPERTY - ); - } - - private ILabelProvider buildLabelProvider() { - return new LabelProvider() { - @Override - public Image getImage(Object element) { - return JptUiPlugin.getImage(JptUiIcons.MAPPING_FILE_REF); - } - - @Override - public String getText(Object element) { - MappingFileRef mappingFileRef = (MappingFileRef) element; - String name = mappingFileRef.getFileName(); - - if (name == null) { - name = JptUiPersistenceMessages.PersistenceUnitMappingFilesComposite_ormNoName; - } - - return name; - } - }; - } - - private ListValueModel<MappingFileRef> buildListHolder() { - return new ListAspectAdapter<PersistenceUnit, MappingFileRef>(getSubjectHolder(), PersistenceUnit.SPECIFIED_MAPPING_FILE_REF_LIST) { - @Override - protected ListIterator<MappingFileRef> listIterator_() { - return subject.specifiedMappingFileRefs(); - } - - @Override - protected int size_() { - return subject.specifiedMappingFileRefsSize(); - } - }; - } - - private WritablePropertyValueModel<MappingFileRef> buildSelectedItemHolder() { - return new SimplePropertyValueModel<MappingFileRef>(); - } - - private PostExecution<ElementTreeSelectionDialog> buildSelectionDialogPostExecution(final ObjectListSelectionModel listSelectionModel) { - return new PostExecution<ElementTreeSelectionDialog>() { - public void execute(ElementTreeSelectionDialog dialog) { - - if (dialog.getReturnCode() == IDialogConstants.CANCEL_ID) { - return; - } - - int index = subject().specifiedMappingFileRefsSize(); - - for (Object result : dialog.getResult()) { - IFile file = (IFile) result; - IPath filePath = removeSourcePath(file); - - MappingFileRef mappingFileRef = subject().addSpecifiedMappingFileRef(index++); - mappingFileRef.setFileName(filePath.toPortableString()); - - listSelectionModel.addSelectedValue(mappingFileRef); - } - } - }; - } - - private ISelectionStatusValidator buildValidator() { - return new ISelectionStatusValidator() { - public IStatus validate(Object[] selection) { - - if (selection.length == 0) { - return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); - } - - for (Object item : selection) { - if (item instanceof IFolder) { - return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); - } - } - - return new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // List pane - new AddRemoveListPane<PersistenceUnit>( - this, - container, - buildAdapter(), - buildItemListHolder(), - buildSelectedItemHolder(), - buildLabelProvider() - ) { - @Override - protected Composite buildContainer(Composite parent) { - parent = super.buildContainer(parent); - updateGridData(parent); - return parent; - } - - @Override - protected void initializeLayout(Composite container) { - super.initializeLayout(container); - updateGridData(getContainer()); - } - }; - } - - /** - * Returns the path of the given file excluding the source folder. - * - * @param file The file to retrieve its path minus the source folder - * @return The relative path of the given path, the path is relative to the - * source path - */ - private IPath removeSourcePath(IFile file) { - IJavaProject javaProject = subject().getJpaProject().getJavaProject(); - IPath filePath = file.getProjectRelativePath(); - - try { - for (IClasspathEntry entry : javaProject.getRawClasspath()) { - - // Only check for source paths - if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { - - // Retrieve the source path relative to the project - IPath sourcePath = entry.getPath().removeFirstSegments(1); - - // Check to see if the file path starts with the source path - if (sourcePath.isPrefixOf(filePath)) { - int count = sourcePath.segmentCount(); - filePath = filePath.removeFirstSegments(count); - break; - } - } - } - } - catch (JavaModelException e) { - JptUiPlugin.log(e.getStatus()); - } - - return filePath; - } - - private void updateGridData(Composite container) { - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - container.setLayoutData(gridData); - } - - //TODO might we want to do this with content-types instead? is there - //the potential that an extender could hae a mapping file that doesn't have - //entity-mappings as the root node?? - /** - * This handler is responsible to parse the root tag (local name) only. - */ - private static class SAXHandler extends DefaultHandler { - - private String rootTagName; - - public String getRootTagName() { - return rootTagName; - } - - @Override - public InputSource resolveEntity(String publicId, - String systemId) throws IOException, SAXException { - - InputSource inputSource = new InputSource(); - inputSource.setByteStream(new ByteArrayInputStream(new byte[0])); - return inputSource; - } - - @Override - public void startElement(String uri, - String localName, - String name, - Attributes attributes) throws SAXException { - - this.rootTagName = name; - throw new SAXException(); - } - } - - /** - * This filter will deny showing any file that are not XML files or folders - * that don't contain any XML files in its sub-hierarchy. The XML files are - * partially parsed to only accept JPA mapping descriptors. - */ - private static class XmlFileViewerFilter extends ViewerFilter { - - private final IJavaProject javaProject; - - XmlFileViewerFilter(IJavaProject javaProject) { - super(); - this.javaProject = javaProject; - } - - /** - * Determines whether the given file (an XML file) is a JPA mapping - * descriptor file. It has to be a valid XML file with a root element - * named "entity-mappings". - * - * @param file The file to parse and see if it's a mapping descriptor file - * @return <code>true</code> if the given file is a valid XML file with a - * root element named "entity-mappings"; <code>false</code> in any other - * case - */ - private boolean isMappingFile(IFile file) { - try { - SAXParserFactory factory = SAXParserFactory.newInstance(); - SAXParser saxParser = factory.newSAXParser(); - SAXHandler handler = new SAXHandler(); - try { - saxParser.parse(file.getRawLocationURI().toURL().openStream(), handler); - } - catch (Exception e) { - // Ignore since it's caused by SAXHandler to stop the parsing - // the moment the local name is retrieved - } - return OrmXmlMapper.ENTITY_MAPPINGS.equalsIgnoreCase(handler.getRootTagName()); - } - catch (Exception e) { - JptUiPlugin.log(e); - return false; - } - } - - private boolean isXmlFile(IFile file) { - return "xml".equalsIgnoreCase(file.getFileExtension()); - } - - @Override - public boolean select(Viewer viewer, - Object parentElement, - Object element) { - - if (element instanceof IFile) { - IFile file = (IFile) element; - return isXmlFile(file) && isMappingFile(file); - } - else if (element instanceof IFolder) { - IFolder folder = (IFolder) element; - - try { - for (IClasspathEntry entry : javaProject.getRawClasspath()) { - if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { - if (!entry.getPath().isPrefixOf(folder.getFullPath().makeRelative())) - return false; - } - } - - for (IResource resource : folder.members()) { - if (select(viewer, folder, resource)) { - return true; - } - } - } - catch (JavaModelException e) { - JptUiPlugin.log(e.getStatus()); - } - catch (CoreException e) { - JptUiPlugin.log(e.getStatus()); - } - } - - return false; - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitPropertiesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitPropertiesComposite.java deleted file mode 100644 index 8249296d8c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitPropertiesComposite.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import java.util.ListIterator; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.details.JpaPageComposite; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.swt.ColumnAdapter; -import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveTablePane; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -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.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | - Properties ------------------------------------------------------------ | - * | | - * | Description | - * | | - * | ----------------------------------------------------------------------- | - * | | | | - * | | AddRemoveTablePane | | - * | | | | - * | ----------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see BaseJpaUiFactory - The invoker - * @see AddRemoveTablePane - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class PersistenceUnitPropertiesComposite extends AbstractPane<PersistenceUnit> - implements JpaPageComposite<PersistenceUnit> -{ - private WritablePropertyValueModel<Property> propertyHolder; - private TablePane tablePane; - - /** - * Creates a new <code>PersistenceUnitPropertiesComposite</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 PersistenceUnitPropertiesComposite(PropertyValueModel<PersistenceUnit> subjectHolder, - Composite container, - WidgetFactory widgetFactory) { - - super(subjectHolder, container, widgetFactory); - } - - private ListValueModel<Property> buildPropertiesListHolder() { - return new ListAspectAdapter<PersistenceUnit, Property>(getSubjectHolder(), PersistenceUnit.PROPERTIES_LIST) { - @Override - protected ListIterator<Property> listIterator_() { - return subject.properties(); - } - - @Override - protected int size_() { - return subject.propertiesSize(); - } - }; - } - - private ITableLabelProvider buildPropertyLabelProvider() { - return new TableLabelProvider(); - } - - private AddRemoveTablePane.Adapter buildTableAdapter() { - return new AddRemoveTablePane.AbstractAdapter() { - public void addNewItem(ObjectListSelectionModel listSelectionModel) { - - Property property = subject().addProperty(); - propertyHolder.setValue(property); - - int index = subject().propertiesSize() - 1; - TableItem tableItem = tablePane.getMainControl().getItem(index); - tablePane.getMainControl().showItem(tableItem); - - tablePane.getTableViewer().editElement( - property, - PropertyColumnAdapter.NAME_COLUMN - ); - } - - public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { - for (Object item : listSelectionModel.selectedValues()) { - subject().removeProperty((Property) item); - } - } - }; - } - - /** - * {@inheritDoc} - */ - public String getHelpID() { - return JpaHelpContextIds.PERSISTENCE_UNIT_PROPERTIES; - } - - /** - * {@inheritDoc} - */ - public Image getPageImage() { - return null; - } - - /** - * {@inheritDoc} - */ - public String getPageText() { - return JptUiPersistenceMessages.PersistenceUnitPropertiesComposite_properties; - } - - /** - * {@inheritDoc} - */ - @Override - protected void initialize() { - super.initialize(); - propertyHolder = new SimplePropertyValueModel<Property>(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void initializeLayout(Composite container) { - - buildLabel( - container, - JptUiPersistenceMessages.PersistenceUnitPropertiesComposite_properties_description - ); - - tablePane = new TablePane(container); - } - - private static class PropertyColumnAdapter implements ColumnAdapter<Property> { - - public static final int COLUMN_COUNT = 3; - public static final int NAME_COLUMN = 1; - public static final int SELECTION_COLUMN = 0; - public static final int VALUE_COLUMN = 2; - - private WritablePropertyValueModel<String> buildNameHolder(Property subject) { - return new PropertyAspectAdapter<Property, String>(Property.NAME_PROPERTY, subject) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<String> buildValueHolder(Property subject) { - return new PropertyAspectAdapter<Property, String>(Property.VALUE_PROPERTY, subject) { - @Override - protected String buildValue_() { - return subject.getValue(); - } - - @Override - protected void setValue_(String value) { - subject.setValue(value); - } - }; - } - - public WritablePropertyValueModel<?>[] cellModels(Property subject) { - WritablePropertyValueModel<?>[] holders = new WritablePropertyValueModel<?>[COLUMN_COUNT]; - holders[SELECTION_COLUMN] = new SimplePropertyValueModel<Object>(); - holders[NAME_COLUMN] = buildNameHolder(subject); - holders[VALUE_COLUMN] = buildValueHolder(subject); - return holders; - } - - public int columnCount() { - return COLUMN_COUNT; - } - - public String columnName(int columnIndex) { - - switch (columnIndex) { - case PropertyColumnAdapter.NAME_COLUMN: { - return JptUiPersistenceMessages.PersistenceUnitPropertiesComposite_nameColumn; - } - - case PropertyColumnAdapter.VALUE_COLUMN: { - return JptUiPersistenceMessages.PersistenceUnitPropertiesComposite_valueColumn; - } - - default: { - return null; - } - } - } - } - - private class TableLabelProvider extends LabelProvider - implements ITableLabelProvider { - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - public String getColumnText(Object element, int columnIndex) { - - Property property = (Property) element; - String value = null; - - switch (columnIndex) { - case PropertyColumnAdapter.NAME_COLUMN: { - value = property.getName(); - break; - } - - case PropertyColumnAdapter.VALUE_COLUMN: { - value = property.getValue(); - break; - } - } - - if (value == null) { - value = ""; - } - - return value; - } - } - - private class TablePane extends AddRemoveTablePane<PersistenceUnit> { - - private final String SELECTION_COLUMN = "selection"; - - private TableViewer tableViewer; - - private TablePane(Composite parent) { - super(PersistenceUnitPropertiesComposite.this, - parent, - buildTableAdapter(), - buildPropertiesListHolder(), - propertyHolder, - buildPropertyLabelProvider()); - } - - private CellEditor[] buildCellEditors(Table table) { - return new CellEditor[] { - null, - new TextCellEditor(table), - new TextCellEditor(table) - }; - } - - private ICellModifier buildCellModifier() { - return new ICellModifier() { - - public boolean canModify(Object element, String property) { - return !SELECTION_COLUMN.equals(property); - } - - public Object getValue(Object element, String property) { - Property propertyModel = (Property) element; - String value = null; - - if (property == Property.NAME_PROPERTY) { - value = propertyModel.getName(); - } - else if (property == Property.VALUE_PROPERTY) { - value = propertyModel.getValue(); - } - - if (value == null) { - value = ""; - } - - return value; - } - - public void modify(Object element, String property, Object value) { - Property propertyModel; - - if (element instanceof TableItem) { - TableItem tableItem = (TableItem) element; - propertyModel = (Property) tableItem.getData(); - } - else { - propertyModel = (Property) element; - } - - if (property == Property.NAME_PROPERTY) { - propertyModel.setName(value.toString()); - } - else if (property == Property.VALUE_PROPERTY) { - propertyModel.setValue(value.toString()); - } - } - }; - } - - @Override - protected ColumnAdapter<?> buildColumnAdapter() { - return new PropertyColumnAdapter(); - } - - private String[] buildColumnProperties() { - return new String[] { - SELECTION_COLUMN, - Property.NAME_PROPERTY, - Property.VALUE_PROPERTY - }; - } - - @Override - protected Composite buildContainer(Composite parent) { - Composite container = super.buildContainer(parent); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - return container; - } - - TableViewer getTableViewer() { - return tableViewer; - } - - @Override - protected void initializeMainComposite(Composite container, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider labelProvider, - String helpId) { - - super.initializeMainComposite( - container, - adapter, - listHolder, - selectedItemHolder, - labelProvider, - helpId - ); - - Table table = getMainControl(); - - // Make the selection column non-resizable since it's only used to - // ease the selection of rows - TableColumn selectionColumn = table.getColumn(PropertyColumnAdapter.SELECTION_COLUMN); - selectionColumn.setResizable(false); - selectionColumn.setWidth(20); - - // Install the editors - tableViewer = new TableViewer(table); - tableViewer.setCellEditors(buildCellEditors(table)); - tableViewer.setCellModifier(buildCellModifier()); - tableViewer.setColumnProperties(buildColumnProperties()); - - getContainer().setLayoutData(new GridData(GridData.FILL_BOTH)); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/perspective/JpaPerspectiveFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/perspective/JpaPerspectiveFactory.java deleted file mode 100644 index a8c746a3e2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/perspective/JpaPerspectiveFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.perspective; - -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.ui.IFolderLayout; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; -import org.eclipse.ui.navigator.resources.ProjectExplorer; -import org.eclipse.ui.progress.IProgressConstants; - -public class JpaPerspectiveFactory implements IPerspectiveFactory { - - public void createInitialLayout(IPageLayout layout) { - String editorArea = layout.getEditorArea(); - - //Package area - IFolderLayout folder = layout.createFolder( - "left", IPageLayout.LEFT, (float) 0.25, editorArea); //$NON-NLS-1$ - folder.addView(ProjectExplorer.VIEW_ID); - folder.addPlaceholder(JavaUI.ID_TYPE_HIERARCHY); - folder.addPlaceholder(IPageLayout.ID_RES_NAV); - - //Database Explorer area - layout.addView("org.eclipse.datatools.connectivity.DataSourceExplorerNavigator", //$NON-NLS-1$ - IPageLayout.BOTTOM, (float) 0.60, ProjectExplorer.VIEW_ID); - - //Problems/Console area - IFolderLayout outputFolder = layout.createFolder( - "bottom", IPageLayout.BOTTOM, (float) 0.60, editorArea); //$NON-NLS-1$ - outputFolder.addView(IPageLayout.ID_PROBLEM_VIEW); - outputFolder.addPlaceholder(IPageLayout.ID_BOOKMARKS); - outputFolder.addPlaceholder(IProgressConstants.PROGRESS_VIEW_ID); - - //JPA Details (Split with Problems/Console area) - layout.addView("org.eclipse.jpt.ui.jpaDetailsView", - IPageLayout.RIGHT, (float) .60, "bottom"); - - //JPA Structure area - IFolderLayout outlineFolder = layout.createFolder( - "right", IPageLayout.RIGHT, (float) 0.75, editorArea); //$NON-NLS-1$ - outlineFolder.addView("org.eclipse.jpt.ui.jpaStructureView"); - outlineFolder.addView(IPageLayout.ID_OUTLINE); - - layout.addActionSet(JavaUI.ID_ACTION_SET); - layout.addActionSet(JavaUI.ID_ELEMENT_CREATION_ACTION_SET); - layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); - - // views - java - layout.addShowViewShortcut(JavaUI.ID_PACKAGES); - layout.addShowViewShortcut(JavaUI.ID_TYPE_HIERARCHY); - layout.addShowViewShortcut(JavaUI.ID_SOURCE_VIEW); - layout.addShowViewShortcut(JavaUI.ID_JAVADOC_VIEW); - - // views - standard workbench - layout.addShowViewShortcut(ProjectExplorer.VIEW_ID); - layout.addShowViewShortcut(IPageLayout.ID_OUTLINE); - layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW); - layout.addShowViewShortcut(IPageLayout.ID_RES_NAV); - - // new actions - Java project creation wizard - layout.addNewWizardShortcut("org.eclipse.jpt.ui.wizard.newJpaProject"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewPackageCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewClassCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewInterfaceCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewEnumCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewAnnotationCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSourceFolderCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.jdt.ui.wizards.NewSnippetFileCreationWizard"); //$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");//$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");//$NON-NLS-1$ - layout.addNewWizardShortcut("org.eclipse.ui.editors.wizards.UntitledTextFileWizard");//$NON-NLS-1$ - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/JpaPlatformUiRegistry.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/JpaPlatformUiRegistry.java deleted file mode 100644 index 269437354a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/JpaPlatformUiRegistry.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -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.JpaPlatformUi; -import org.eclipse.jpt.ui.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 JpaPlatformUiRegistry -{ - // singleton - private static final JpaPlatformUiRegistry INSTANCE = new JpaPlatformUiRegistry(); - - /** - * Return the singleton. - */ - public static JpaPlatformUiRegistry instance() { - return INSTANCE; - } - - private static final String EXTENSION_ID = - "jpaPlatform"; //$NON-NLS-1$ - - private static final String EL_PLATFORM = - "jpaPlatform"; //$NON-NLS-1$ - - private static final String AT_ID = - "id"; //$NON-NLS-1$ - - private static final String AT_CLASS = - "class"; //$NON-NLS-1$ - - // key: String jpaPlatform id value: IConfigurationElement class descriptor - private Map<String, IConfigurationElement> jpaPlatforms; - - - /* (non Java doc) - * restrict access - */ - private JpaPlatformUiRegistry() { - buildJpaPlatforms(); - } - - - private void buildJpaPlatforms() { - this.jpaPlatforms = new HashMap<String, IConfigurationElement>(); - - for (Iterator<IConfigurationElement> stream = allConfigElements(); stream.hasNext(); ) { - buildJpaPlatform(stream.next()); - } - } - - private void buildJpaPlatform(IConfigurationElement configElement) { - if (! configElement.getName().equals(EL_PLATFORM)) { - return; - } - - String platformId = configElement.getAttribute(AT_ID); - String platformClass = configElement.getAttribute(AT_CLASS); - - if ((platformId == null) || (platformClass == null)) { - if (platformId == null) { - reportMissingAttribute(configElement, AT_ID); - } - if (platformClass == null) { - reportMissingAttribute(configElement, AT_CLASS); - } - return; - } - - if (this.jpaPlatforms.containsKey(platformId)) { - IConfigurationElement otherConfigElement = this.jpaPlatforms.get(platformId); - reportDuplicatePlatform(configElement, otherConfigElement); - } - - this.jpaPlatforms.put(platformId, configElement); - } - - public JpaPlatformUi jpaPlatform(String platformId) { - IConfigurationElement registeredConfigElement = this.jpaPlatforms.get(platformId); - - if (registeredConfigElement == null) { - return null; - } - - try { - return (JpaPlatformUi) registeredConfigElement.createExecutableExtension(AT_CLASS); - } - catch (CoreException ce) { - reportFailedInstantiation(registeredConfigElement); - return null; - } - } - - private Iterator<IConfigurationElement> allConfigElements() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = - registry.getExtensionPoint(JptUiPlugin.PLUGIN_ID, EXTENSION_ID); - IExtension[] extensions = extensionPoint.getExtensions(); - - return new CompositeIterator<IConfigurationElement>( - new TransformationIterator<IExtension, Iterator<IConfigurationElement>>(CollectionTools.iterator(extensions)) { - @Override - protected Iterator<IConfigurationElement> transform(IExtension extension) { - return CollectionTools.iterator(extension.getConfigurationElements()); - } - } - ); - } - - // TODO externalize strings - private void reportMissingAttribute(IConfigurationElement configElement, String attributeName) { - String message = - "An extension element \"" - + configElement.getName() - + "\" in plugin \"" - + configElement.getContributor().getName() - + "\" is missing a required attribute \"" - + attributeName - + "\"."; - JptUiPlugin.log(message); - } - - // TODO externalize strings - private void reportDuplicatePlatform( - IConfigurationElement oneConfigElement, IConfigurationElement otherConfigElement) { - String message = - "The plugins \"" - + oneConfigElement.getContributor().getName() - + "\" and \"" - + otherConfigElement.getContributor().getName() - + "\" have registered a duplicate attribute \"id\" " - + "for the extension element \"jpaPlatform\"."; - JptUiPlugin.log(message); - } - - // TODO externalize strings - private void reportFailedInstantiation(IConfigurationElement configElement) { - String message = - "Could not instantiate the class \"" - + configElement.getAttribute(AT_CLASS) - + "\" for the extension element \"" - + configElement.getName() - + "\" in the plugin \"" - + configElement.getContributor().getName() - + "\"."; - JptUiPlugin.log(message); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java deleted file mode 100644 index 3a1351101b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.base; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.java.JavaJpaContextNode; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.orm.OrmResourceModel; -import org.eclipse.jpt.core.resource.persistence.PersistenceResourceModel; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.JpaDetailsProvider; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.BasicMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.EmbeddableUiProvider; -import org.eclipse.jpt.ui.internal.details.EmbeddedIdMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.EmbeddedMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.IdMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.ManyToManyMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.ManyToOneMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.MappedSuperclassUiProvider; -import org.eclipse.jpt.ui.internal.details.OneToManyMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.OneToOneMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.TransientMappingUiProvider; -import org.eclipse.jpt.ui.internal.details.VersionMappingUiProvider; -import org.eclipse.jpt.ui.internal.java.details.DefaultBasicMappingUiProvider; -import org.eclipse.jpt.ui.internal.java.details.DefaultEmbeddedMappingUiProvider; -import org.eclipse.jpt.ui.internal.java.details.JavaDetailsProvider; -import org.eclipse.jpt.ui.internal.java.details.JavaEntityUiProvider; -import org.eclipse.jpt.ui.internal.java.details.NullAttributeMappingUiProvider; -import org.eclipse.jpt.ui.internal.java.details.NullTypeMappingUiProvider; -import org.eclipse.jpt.ui.internal.orm.details.OrmDetailsProvider; -import org.eclipse.jpt.ui.internal.orm.details.OrmEntityUiProvider; -import org.eclipse.jpt.ui.internal.structure.JavaResourceModelStructureProvider; -import org.eclipse.jpt.ui.internal.structure.OrmResourceModelStructureProvider; -import org.eclipse.jpt.ui.internal.structure.PersistenceResourceModelStructureProvider; -import org.eclipse.jpt.ui.structure.JpaStructureProvider; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; - -public abstract class BaseJpaPlatformUi implements JpaPlatformUi -{ - // TODO: Transformed into a List for testing - private List<JpaDetailsProvider> detailsProviders; - - private List<TypeMappingUiProvider<? extends TypeMapping>> javaTypeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> javaAttributeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> defaultJavaAttributeMappingUiProviders; - - private List<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> ormAttributeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> defaultOrmAttributeMappingUiProviders; - - private JpaUiFactory jpaUiFactory; - - - protected BaseJpaPlatformUi() { - super(); - this.jpaUiFactory = createJpaUiFactory(); - } - - - // **************** structure view content ********************************* - - public JpaStructureProvider buildStructureProvider(JpaFile jpaFile) { - ResourceModel resourceModel = jpaFile.getResourceModel(); - String resourceType = resourceModel.getResourceType(); - - if (resourceType == ResourceModel.JAVA_RESOURCE_TYPE) { - return new JavaResourceModelStructureProvider((JavaResourceModel) resourceModel); - } - else if (resourceType == ResourceModel.ORM_RESOURCE_TYPE) { - return new OrmResourceModelStructureProvider((OrmResourceModel) resourceModel); - } - else if (resourceType == ResourceModel.PERSISTENCE_RESOURCE_TYPE) { - return new PersistenceResourceModelStructureProvider((PersistenceResourceModel) resourceModel); - } - - return null; - } - - - // ********** behavior ********** - - protected abstract JpaUiFactory createJpaUiFactory(); - - public JpaUiFactory getJpaUiFactory() { - return this.jpaUiFactory; - } - - public Iterator<JpaDetailsProvider> detailsProviders() { - if (this.detailsProviders == null) { - this.detailsProviders = new ArrayList<JpaDetailsProvider>(); - this.addDetailsProvidersTo(this.detailsProviders); - } - return new CloneIterator<JpaDetailsProvider>(this.detailsProviders); - } - - /** - * Override this to specify more or different details providers. - * The default includes the JPA spec-defined java and orm.xml - */ - protected void addDetailsProvidersTo(Collection<JpaDetailsProvider> providers) { - providers.add(new JavaDetailsProvider()); - providers.add(new OrmDetailsProvider()); - } - - public JpaDetailsProvider detailsProvider(JpaStructureNode structureNode) { - // TODO: To implement, this is written only for testing - detailsProviders(); - if (structureNode instanceof JavaJpaContextNode) { - return detailsProviders.get(0); - } - else { - return detailsProviders.get(1); - } -// for (Iterator<IJpaDetailsProvider> i = this.detailsProviders(); i.hasNext(); ) { -// IJpaDetailsProvider provider = i.next(); -// if (provider.fileContentType().equals(fileContentType)) { -// return provider; -// } -// } -// return null; - } - - public ListIterator<TypeMappingUiProvider<? extends TypeMapping>> javaTypeMappingUiProviders() { - if (this.javaTypeMappingUiProviders == null) { - this.javaTypeMappingUiProviders = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); - this.addJavaTypeMappingUiProvidersTo(this.javaTypeMappingUiProviders); - } - return new CloneListIterator<TypeMappingUiProvider<? extends TypeMapping>>( - 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<TypeMappingUiProvider<? extends TypeMapping>> providers) { - providers.add(NullTypeMappingUiProvider.instance()); - providers.add(JavaEntityUiProvider.instance()); - providers.add(MappedSuperclassUiProvider.instance()); - providers.add(EmbeddableUiProvider.instance()); - } - - public ListIterator<AttributeMappingUiProvider<? extends AttributeMapping>> javaAttributeMappingUiProviders() { - if (this.javaAttributeMappingUiProviders == null) { - this.javaAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addJavaAttributeMappingUiProvidersTo(this.javaAttributeMappingUiProviders); - } - - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - 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, - * manyToMany, manyToOne, oneToMany, oneToOne, transient, and version - */ - protected void addJavaAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> 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(NullAttributeMappingUiProvider.instance()); - providers.add(OneToManyMappingUiProvider.instance()); - providers.add(OneToOneMappingUiProvider.instance()); - providers.add(TransientMappingUiProvider.instance()); - providers.add(VersionMappingUiProvider.instance()); - } - - public ListIterator<AttributeMappingUiProvider<? extends AttributeMapping>> defaultJavaAttributeMappingUiProviders() { - if (this.defaultJavaAttributeMappingUiProviders == null) { - this.defaultJavaAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addDefaultJavaAttributeMappingUiProvidersTo(this.defaultJavaAttributeMappingUiProviders); - } - - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - 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<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { - providers.add(DefaultBasicMappingUiProvider.instance()); - providers.add(DefaultEmbeddedMappingUiProvider.instance()); - } - - public void generateEntities(JpaProject project, IStructuredSelection selection) { - EntitiesGenerator.generate(project, selection); - } - - // *************** ORM mapping UI providers *************** - - public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> defaultOrmAttributeMappingUiProviders() { - if (this.defaultOrmAttributeMappingUiProviders == null) { - this.defaultOrmAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addDefaultOrmAttributeMappingUiProvidersTo(this.defaultOrmAttributeMappingUiProviders); - } - - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - this.defaultOrmAttributeMappingUiProviders - ); - } - - /** - * Override this to specify more or different default ORM attribute mapping - * ui providers. The default has no specific mappings. - */ - protected void addDefaultOrmAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { - } - - public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> ormAttributeMappingUiProviders() { - if (this.ormAttributeMappingUiProviders == null) { - this.ormAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addOrmAttributeMappingUiProvidersTo(this.ormAttributeMappingUiProviders); - } - - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - this.ormAttributeMappingUiProviders - ); - } - - /** - * Override this to specify more or different ORM attribute mapping ui - * providers. The default includes the JPA spec-defined basic, embedded, - * embeddedId, id, manyToMany, manyToOne, oneToMany, oneToOne, transient, - * and version. - */ - protected void addOrmAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> 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(OneToOneMappingUiProvider.instance()); - providers.add(TransientMappingUiProvider.instance()); - providers.add(VersionMappingUiProvider.instance()); - } - - public Iterator<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders() { - if (this.ormTypeMappingUiProviders == null) { - this.ormTypeMappingUiProviders = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); - this.addOrmTypeMappingUiProvidersTo(this.ormTypeMappingUiProviders); - } - - return new CloneListIterator<TypeMappingUiProvider<? extends TypeMapping>>( - this.ormTypeMappingUiProviders - ); - } - - /** - * Override this to specify more or different ORM 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 addOrmTypeMappingUiProvidersTo(List<TypeMappingUiProvider<? extends TypeMapping>> providers) { - providers.add(OrmEntityUiProvider.instance()); - providers.add(MappedSuperclassUiProvider.instance()); - providers.add(EmbeddableUiProvider.instance()); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/EntitiesGenerator.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/EntitiesGenerator.java deleted file mode 100644 index 6d27bdd58c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/EntitiesGenerator.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007, 2008 Oracle. All rights reserved. -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0, which accompanies this distribution -* and is available at http://www.eclipse.org/legal/epl-v10.html. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.base; - -import java.util.Collection; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.Dialog; -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.JpaProject; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.internal.synch.SynchronizeClassesJob; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.gen.internal.EntityGenerator; -import org.eclipse.jpt.gen.internal.PackageGenerator; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.wizards.GenerateEntitiesWizard; -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.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * EntitiesGenerator - */ -public class EntitiesGenerator -{ - private JpaProject project; - private IStructuredSelection selection; - - // ********** constructors ********** - - static public void generate( JpaProject project, IStructuredSelection selection) { - if(project == null) { - throw new NullPointerException(); - } - new EntitiesGenerator( project, selection).generate(); - } - - public EntitiesGenerator() { - super(); - } - - private EntitiesGenerator( JpaProject project, IStructuredSelection selection) { - super(); - this.project = project; - this.selection = selection; - } - - // ********** behavior ********** - - protected void generate() { - GenerateEntitiesWizard wizard = new GenerateEntitiesWizard(this.project, this.selection); - - WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard); - dialog.create(); - int returnCode = dialog.open(); - if (returnCode == Window.OK) { - WorkspaceJob genEntitiesRunnable = new GenerateEntitiesRunnable( - wizard.getPackageGeneratorConfig(), - wizard.getEntityGeneratorConfig(), - wizard.getSelectedTables(), - wizard.synchronizePersistenceXml(), - new OverwriteConfirmer(this.getCurrentShell()) - ); - - WorkspaceJob synchClassesRunnable = null; - - if (wizard.synchronizePersistenceXml()) { - // we currently only support *one* persistence.xml file per project - PersistenceXml persistenceXml = this.project.getRootContext().getPersistenceXml(); - if (persistenceXml != null) { - //TODO casting to IFile - just trying to get rid of all compiler errors for now - synchClassesRunnable = new SynchronizeClassesJob((IFile) persistenceXml.getResource()); - } - } - genEntitiesRunnable.schedule(); - if (synchClassesRunnable != null) { - synchClassesRunnable.schedule(); - } - } - } - - private Shell getCurrentShell() { - return Display.getCurrent().getActiveShell(); - } - - // ********** runnable ********** - - static class GenerateEntitiesRunnable extends WorkspaceJob { - private final PackageGenerator.Config packageConfig; - private final EntityGenerator.Config entityConfig; - private final Collection<Table> selectedTables; - private final EntityGenerator.OverwriteConfirmer overwriteConfirmer; - - GenerateEntitiesRunnable( - PackageGenerator.Config packageConfig, - EntityGenerator.Config entityConfig, - Collection<Table> selectedTables, - boolean synchronizePersistenceXml, - EntityGenerator.OverwriteConfirmer overwriteConfirmer - ) { - super("Generating Entities"); - this.packageConfig = packageConfig; - this.entityConfig = entityConfig; - this.selectedTables = selectedTables; - this.overwriteConfirmer = overwriteConfirmer; - setRule(packageConfig.getPackageFragment().getJavaProject().getProject()); - } - - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - PackageGenerator.generateEntities(this.packageConfig, this.entityConfig, this.selectedTables, this.overwriteConfirmer, monitor); - return Status.OK_STATUS; - } - - } - - // ********** overwrite confirmer ********** - - static class OverwriteConfirmer implements EntityGenerator.OverwriteConfirmer { - private Shell shell; - private boolean overwriteAll = false; - private boolean skipAll = false; - - OverwriteConfirmer(Shell shell) { - super(); - this.shell = shell; - } - - public boolean overwrite(final String className) { - if (this.overwriteAll) { - return true; - } - if (this.skipAll) { - return false; - } - return this.promptUser(className); - } - - private boolean promptUser(String className) { - - final OverwriteConfirmerDialog dialog = new OverwriteConfirmerDialog(this.shell, className); - //get on the UI thread synchronously, need feedback before continuing - this.shell.getDisplay().syncExec(new Runnable() { - public void run() { - dialog.open(); - } - }); - if (dialog.getReturnCode() == Window.CANCEL) { - throw new OperationCanceledException(); - } - if (dialog.yes()) { - return true; - } else if (dialog.yesToAll()) { - this.overwriteAll = true; - return true; - } else if (dialog.no()) { - return false; - } else if (dialog.noToAll()) { - this.skipAll = true; - return false; - } - throw new IllegalStateException(); - } - - } - - // ********** dialog ********** - - static class OverwriteConfirmerDialog extends Dialog { - private final String className; - private boolean yes = false; - private boolean yesToAll = false; - private boolean no = false; - private boolean noToAll = false; - - OverwriteConfirmerDialog(Shell parent, String className) { - super(parent); - 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(); - gridLayout.numColumns = 2; - - Label text = new Label(composite, SWT.LEFT); - text.setText(NLS.bind(JptUiMessages.OverwriteConfirmerDialog_text, this.className)); - text.setLayoutData(new GridData()); - - 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); - this.createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true); - this.createButton(parent, IDialogConstants.NO_TO_ALL_ID, IDialogConstants.NO_TO_ALL_LABEL, false); - this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - @Override - protected void buttonPressed(int buttonId) { - switch (buttonId) { - case IDialogConstants.YES_ID : - this.yesPressed(); - break; - case IDialogConstants.YES_TO_ALL_ID : - this.yesToAllPressed(); - break; - case IDialogConstants.NO_ID : - this.noPressed(); - break; - case IDialogConstants.NO_TO_ALL_ID : - this.noToAllPressed(); - break; - case IDialogConstants.CANCEL_ID : - this.cancelPressed(); - break; - default : - break; - } - } - - private void yesPressed() { - this.yes = true; - this.setReturnCode(OK); - this.close(); - } - - private void yesToAllPressed() { - this.yesToAll = true; - this.setReturnCode(OK); - this.close(); - } - - private void noPressed() { - this.no = true; - this.setReturnCode(OK); - this.close(); - } - - private void noToAllPressed() { - this.noToAll = true; - this.setReturnCode(OK); - this.close(); - } - - boolean yes() { - return this.yes; - } - - boolean yesToAll() { - return this.yesToAll; - } - - boolean no() { - return this.no; - } - - boolean noToAll() { - return this.noToAll; - } - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/ClassRefItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/ClassRefItemLabelProvider.java deleted file mode 100644 index e261aedc71..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/ClassRefItemLabelProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class ClassRefItemLabelProvider extends AbstractItemLabelProvider -{ - public ClassRefItemLabelProvider( - ClassRef classRef, DelegatingContentAndLabelProvider labelProvider) { - super(classRef, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new PropertyAspectAdapter<ClassRef, String>(ClassRef.CLASS_NAME_PROPERTY, (ClassRef) model()) { - @Override - protected String buildValue_() { - return subject.getClassName(); - } - }; - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - Image image = JptUiPlugin.getImage(JptUiIcons.CLASS_REF); - if (((ClassRef) model()).isVirtual()) { - image = JptUiIcons.ghost(image); - } - return new StaticPropertyValueModel<Image>(image); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java deleted file mode 100644 index 6945a8d4b6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/EntityMappingsItemLabelProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public 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)); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java deleted file mode 100644 index ffb36a3a96..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemContentProviderFactory.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.FilteringCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListCollectionValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class GenericNavigatorItemContentProviderFactory - implements TreeItemContentProviderFactory -{ - public TreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider; - - if (item instanceof JpaRootContextNode) { - return new RootContextItemContentProvider((JpaRootContextNode) item, treeContentAndLabelProvider); - } - else if (item instanceof PersistenceXml) { - return new PersistenceXmlItemContentProvider((PersistenceXml) item, treeContentAndLabelProvider); - } - else if (item instanceof PersistenceUnit) { - return new PersistenceUnitItemContentProvider((PersistenceUnit) item, treeContentAndLabelProvider); - } - else if (item instanceof OrmXml) { - return new OrmXmlItemContentProvider((OrmXml) item, treeContentAndLabelProvider); - } - else if (item instanceof OrmPersistentType) { - return new OrmPersistentTypeItemContentProvider((OrmPersistentType) item, treeContentAndLabelProvider); - } - else if (item instanceof JavaPersistentType) { - return new JavaPersistentTypeItemContentProvider((JavaPersistentType) item, treeContentAndLabelProvider); - } - else if (item instanceof PersistentAttribute) { - return new PersistentAttributeItemContentProvider((PersistentAttribute) item, treeContentAndLabelProvider); - } - return null; - } - - - public static class PersistenceUnitItemContentProvider extends AbstractTreeItemContentProvider<JpaContextNode> - { - public PersistenceUnitItemContentProvider( - PersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistenceUnit, contentProvider); - } - - @Override - public PersistenceUnit model() { - return (PersistenceUnit) super.model(); - } - - @Override - public PersistenceXml getParent() { - return (PersistenceXml) model().getPersistenceUnit().getParent(); - } - - @Override - protected ListValueModel<JpaContextNode> buildChildrenModel() { - List<ListValueModel<? extends JpaContextNode>> list = new ArrayList<ListValueModel<? extends JpaContextNode>>(); - list.add(buildSpecifiedOrmXmlLvm()); - list.add(buildImpliedOrmXmlLvm()); - list.add(buildPersistentTypeLvm()); - return new CompositeListValueModel<ListValueModel<? extends JpaContextNode>, JpaContextNode>(list); - } - - private ListValueModel<JpaContextNode> buildSpecifiedOrmXmlLvm() { - return new CollectionListValueModelAdapter<JpaContextNode>( - new FilteringCollectionValueModel<OrmXml>( - new ListCollectionValueModelAdapter<OrmXml>( - new TransformationListValueModelAdapter<MappingFileRef, OrmXml>( - new ItemPropertyListValueModelAdapter<MappingFileRef>( - new ListAspectAdapter<PersistenceUnit, MappingFileRef>( - PersistenceUnit.SPECIFIED_MAPPING_FILE_REF_LIST, - model()) { - @Override - protected ListIterator<MappingFileRef> listIterator_() { - return subject.specifiedMappingFileRefs(); - } - @Override - protected int size_() { - return subject.specifiedMappingFileRefsSize(); - } - }, MappingFileRef.ORM_XML_PROPERTY)) { - @Override - protected OrmXml transformItem(MappingFileRef item) { - return item.getOrmXml(); - } - })) { - @Override - protected Iterator<OrmXml> filter(Iterator<? extends OrmXml> items) { - return new FilteringIterator<OrmXml, OrmXml>(items) { - @Override - protected boolean accept(OrmXml o) { - return o != null; - } - }; - } - }); - } - - private ListValueModel<OrmXml> buildImpliedOrmXmlLvm() { - return new PropertyListValueModelAdapter<OrmXml>( - new PropertyAspectAdapter<MappingFileRef, OrmXml>( - new PropertyAspectAdapter<PersistenceUnit, MappingFileRef>( - PersistenceUnit.IMPLIED_MAPPING_FILE_REF_PROPERTY, - model()) { - @Override - protected MappingFileRef buildValue_() { - return subject.getImpliedMappingFileRef(); - } - }, - MappingFileRef.ORM_XML_PROPERTY) { - @Override - protected OrmXml buildValue_() { - return subject.getOrmXml(); - } - } - ); - } - - private ListValueModel<JpaContextNode> buildPersistentTypeLvm() { - return new CollectionListValueModelAdapter<JpaContextNode>( - new FilteringCollectionValueModel<PersistentType>( - new ListCollectionValueModelAdapter<PersistentType>( - new TransformationListValueModelAdapter<ClassRef, PersistentType>( - new ItemPropertyListValueModelAdapter<ClassRef>(buildClassRefLvm(), ClassRef.JAVA_PERSISTENT_TYPE_PROPERTY)) { - @Override - protected PersistentType transformItem(ClassRef item) { - return item.getJavaPersistentType(); - } - })) { - @Override - protected Iterator<PersistentType> filter(Iterator<? extends PersistentType> items) { - return new FilteringIterator<PersistentType, PersistentType>(items) { - @Override - protected boolean accept(PersistentType o) { - return o != null; - } - }; - } - }); - } - - private ListValueModel<ClassRef> buildClassRefLvm() { - ArrayList<ListValueModel<ClassRef>> holders = new ArrayList<ListValueModel<ClassRef>>(2); - holders.add(buildSpecifiedClassRefLvm()); - holders.add(buildImpliedClassRefLvm()); - return new CompositeListValueModel<ListValueModel<ClassRef>, ClassRef>(holders); - } - - private ListValueModel<ClassRef> buildSpecifiedClassRefLvm() { - return new ListAspectAdapter<PersistenceUnit, ClassRef>( - PersistenceUnit.SPECIFIED_CLASS_REF_LIST, model()) { - @Override - protected ListIterator<ClassRef> listIterator_() { - return subject.specifiedClassRefs(); - } - @Override - protected int size_() { - return subject.specifiedClassRefsSize(); - } - }; - } - - private ListValueModel<ClassRef> buildImpliedClassRefLvm() { - return new ListAspectAdapter<PersistenceUnit, ClassRef>( - PersistenceUnit.IMPLIED_CLASS_REF_LIST, model()) { - @Override - protected ListIterator<ClassRef> listIterator_() { - return subject.impliedClassRefs(); - } - @Override - protected int size_() { - return subject.impliedClassRefsSize(); - } - }; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java deleted file mode 100644 index 7ff974ca6d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorItemLabelProviderFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; - -public class GenericNavigatorItemLabelProviderFactory - implements ItemLabelProviderFactory -{ - public ItemLabelProvider buildItemLabelProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - if (item instanceof JpaRootContextNode) { - return new RootContextItemLabelProvider((JpaRootContextNode) item, contentAndLabelProvider); - } - else if (item instanceof PersistenceXml) { - return new PersistenceXmlItemLabelProvider((PersistenceXml) item, contentAndLabelProvider); - } - else if (item instanceof PersistenceUnit) { - return new PersistenceUnitItemLabelProvider((PersistenceUnit) item, contentAndLabelProvider); - } - else if (item instanceof OrmXml) { - return new OrmXmlItemLabelProvider((OrmXml) item, contentAndLabelProvider); - } - else if (item instanceof PersistentType) { - return new PersistentTypeItemLabelProvider((PersistentType) item, contentAndLabelProvider); - } - else if (item instanceof PersistentAttribute) { - return new PersistentAttributeItemLabelProvider((PersistentAttribute) item, contentAndLabelProvider); - } - return null; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorProvider.java deleted file mode 100644 index 8bb925c3c6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericNavigatorProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; -import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; - -public class GenericNavigatorProvider implements JpaNavigatorProvider -{ - public ItemLabelProviderFactory getItemLabelProviderFactory() { - return new GenericNavigatorItemLabelProviderFactory(); - } - - public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { - return new GenericNavigatorItemContentProviderFactory(); - } - - public void dispose() { - // TODO Auto-generated method stub - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java deleted file mode 100644 index ac4082afeb..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.internal.GenericJpaUiFactory; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; -import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -public class GenericPlatformUi extends BaseJpaPlatformUi -{ - public GenericPlatformUi() { - super(); - } - - - // **************** navigator content ************************************** - - public JpaNavigatorProvider buildNavigatorProvider() { - return new GenericNavigatorProvider(); - } - - - @Override - protected JpaUiFactory createJpaUiFactory() { - return new GenericJpaUiFactory(); - } - - public void generateDDL(JpaProject project, IStructuredSelection selection) { - this.displayNotSupportedMessage(JptUiMessages.GenericPlatformUiDialog_notSupportedMessageTitle, JptUiMessages.GenericPlatformUiDialog_notSupportedMessageText); - } - - protected void displayNotSupportedMessage(String title, String message) { - Shell currentShell = Display.getCurrent().getActiveShell(); - MessageDialog.openInformation(currentShell, title, message); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java deleted file mode 100644 index 5f515fb694..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/JavaPersistentTypeItemContentProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class JavaPersistentTypeItemContentProvider extends AbstractTreeItemContentProvider<JavaPersistentAttribute> -{ - public JavaPersistentTypeItemContentProvider( - JavaPersistentType persistentType, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistentType, contentProvider); - } - - @Override - public JavaPersistentType model() { - return (JavaPersistentType) super.model(); - } - @Override - public Object getParent() { - return model().getParent(); - } - - @Override - protected ListValueModel<JavaPersistentAttribute> buildChildrenModel() { - return new ListAspectAdapter<JavaPersistentType, JavaPersistentAttribute>(PersistentType.SPECIFIED_ATTRIBUTES_LIST, model()) { - @Override - protected ListIterator<JavaPersistentAttribute> listIterator_() { - return subject.attributes(); - } - - @Override - protected int size_() { - return subject.attributesSize(); - } - }; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java deleted file mode 100644 index 85c18c53c3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/MappingFileRefItemLabelProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class MappingFileRefItemLabelProvider extends AbstractItemLabelProvider -{ - public MappingFileRefItemLabelProvider( - MappingFileRef mappingFileRef, DelegatingContentAndLabelProvider labelProvider) { - super(mappingFileRef, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new PropertyAspectAdapter<MappingFileRef, String>(MappingFileRef.FILE_NAME_PROPERTY, (MappingFileRef) model()) { - @Override - protected String buildValue_() { - return subject.getFileName(); - } - }; - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - Image image = JptUiPlugin.getImage(JptUiIcons.MAPPING_FILE_REF); - if (((MappingFileRef) model()).isVirtual()) { - image = JptUiIcons.ghost(image); - } - return new StaticPropertyValueModel<Image>(image); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java deleted file mode 100644 index 0c15789050..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmPersistentTypeItemContentProvider.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class OrmPersistentTypeItemContentProvider extends AbstractTreeItemContentProvider<OrmPersistentAttribute> - { - public OrmPersistentTypeItemContentProvider( - OrmPersistentType persistentType, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistentType, contentProvider); - } - - @Override - public OrmPersistentType model() { - return (OrmPersistentType) super.model(); - } - - @Override - public Object getParent() { - return model().getParent(); - } - - @Override - protected ListValueModel<OrmPersistentAttribute> buildChildrenModel() { - List<ListValueModel<OrmPersistentAttribute>> list = new ArrayList<ListValueModel<OrmPersistentAttribute>>(2); - list.add(buildSpecifiedPersistentAttributesListHolder()); - list.add(buildVirtualPersistentAttributesListHolder()); - return new CompositeListValueModel<ListValueModel<OrmPersistentAttribute>, OrmPersistentAttribute>(list); - } - - - protected ListValueModel<OrmPersistentAttribute> buildSpecifiedPersistentAttributesListHolder() { - return new ListAspectAdapter<OrmPersistentType, OrmPersistentAttribute>(PersistentType.SPECIFIED_ATTRIBUTES_LIST, model()) { - @Override - protected ListIterator<OrmPersistentAttribute> listIterator_() { - return subject.specifiedAttributes(); - } - @Override - protected int size_() { - return subject.specifiedAttributesSize(); - } - }; - } - - protected ListValueModel<OrmPersistentAttribute> buildVirtualPersistentAttributesListHolder() { - return new ListAspectAdapter<OrmPersistentType, OrmPersistentAttribute>(OrmPersistentType.VIRTUAL_ATTRIBUTES_LIST, model()) { - @Override - protected ListIterator<OrmPersistentAttribute> listIterator_() { - return subject.virtualAttributes(); - } - @Override - protected int size_() { - return subject.virtualAttributesSize(); - } - }; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmXmlItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmXmlItemContentProvider.java deleted file mode 100644 index 1013407a20..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmXmlItemContentProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -public class OrmXmlItemContentProvider - extends AbstractTreeItemContentProvider<OrmPersistentType> -{ - public OrmXmlItemContentProvider( - OrmXml ormXml, DelegatingTreeContentAndLabelProvider contentProvider) { - super(ormXml, contentProvider); - } - - @Override - public OrmXml model() { - return (OrmXml) super.model(); - } - - @Override - public PersistenceUnit getParent() { - return model().getPersistenceUnit(); - } - - @Override - protected ListValueModel<OrmPersistentType> buildChildrenModel() { - return new ListAspectAdapter<EntityMappings, OrmPersistentType>( - buildEntityMappingsHolder(), - EntityMappings.PERSISTENT_TYPES_LIST) { - @Override - protected ListIterator<OrmPersistentType> listIterator_() { - return subject.ormPersistentTypes(); - } - @Override - protected int size_() { - return subject.ormPersistentTypesSize(); - } - }; - } - - protected PropertyValueModel<EntityMappings> buildEntityMappingsHolder() { - return new PropertyAspectAdapter<OrmXml, EntityMappings>( - OrmXml.ENTITY_MAPPINGS_PROPERTY, model()) { - @Override - protected EntityMappings buildValue_() { - return subject.getEntityMappings(); - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmXmlItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmXmlItemLabelProvider.java deleted file mode 100644 index 83151a9b26..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/OrmXmlItemLabelProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class OrmXmlItemLabelProvider extends AbstractItemLabelProvider -{ - public OrmXmlItemLabelProvider( - OrmXml ormXml, DelegatingContentAndLabelProvider labelProvider) { - super(ormXml, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new StaticPropertyValueModel<String>(((OrmXml) model()).getResource().getName()); - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.JPA_FILE)); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceItemLabelProvider.java deleted file mode 100644 index bf913aaf8a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceItemLabelProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class PersistenceItemLabelProvider extends AbstractItemLabelProvider -{ - public PersistenceItemLabelProvider( - Persistence 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)); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java deleted file mode 100644 index 8cea125d52..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class PersistenceUnitItemLabelProvider extends AbstractItemLabelProvider -{ - public PersistenceUnitItemLabelProvider( - PersistenceUnit persistenceUnit, DelegatingContentAndLabelProvider labelProvider) { - super(persistenceUnit, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new PropertyAspectAdapter<PersistenceUnit, String>(PersistenceUnit.NAME_PROPERTY, (PersistenceUnit) model()) { - @Override - protected String buildValue_() { - return subject.getName(); - } - }; - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.PERSISTENCE_UNIT)); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java deleted file mode 100644 index 746b79ea48..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceXmlItemContentProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class PersistenceXmlItemContentProvider - extends AbstractTreeItemContentProvider<PersistenceUnit> -{ - public PersistenceXmlItemContentProvider( - PersistenceXml persistenceXml, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistenceXml, contentProvider); - } - - - @Override - public JpaRootContextNode getParent() { - return (JpaRootContextNode) ((PersistenceXml) model()).getParent(); - } - - @Override - protected ListValueModel<PersistenceUnit> buildChildrenModel() { - return new ListAspectAdapter<Persistence, PersistenceUnit>( - new PropertyAspectAdapter<PersistenceXml, Persistence>( - PersistenceXml.PERSISTENCE_PROPERTY, (PersistenceXml) model()) { - @Override - protected Persistence buildValue_() { - return subject.getPersistence(); - } - }, - Persistence.PERSISTENCE_UNITS_LIST) { - @Override - protected ListIterator<PersistenceUnit> listIterator_() { - return subject.persistenceUnits(); - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java deleted file mode 100644 index c4374f8ec0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistenceXmlItemLabelProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class PersistenceXmlItemLabelProvider extends AbstractItemLabelProvider -{ - public PersistenceXmlItemLabelProvider( - PersistenceXml persistenceXml, DelegatingContentAndLabelProvider labelProvider) { - super(persistenceXml, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new StaticPropertyValueModel<String>(((PersistenceXml) model()).getResource().getName()); - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.JPA_FILE)); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java deleted file mode 100644 index 1787828742..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentAttributeItemContentProvider.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; - -@SuppressWarnings("unchecked") -public class PersistentAttributeItemContentProvider extends AbstractTreeItemContentProvider -{ - public PersistentAttributeItemContentProvider( - PersistentAttribute persistentAttribute, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistentAttribute, contentProvider); - } - - @Override - public Object getParent() { - return ((PersistentAttribute) model()).getParent(); - } - - @Override - public boolean hasChildren() { - return false; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java deleted file mode 100644 index 4adb421a6f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentAttributeItemLabelProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class PersistentAttributeItemLabelProvider extends AbstractItemLabelProvider -{ - public PersistentAttributeItemLabelProvider( - PersistentAttribute persistentAttribute, DelegatingContentAndLabelProvider labelProvider) { - super(persistentAttribute, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new PropertyAspectAdapter<PersistentAttribute, String>(PersistentAttribute.NAME_PROPERTY, (PersistentAttribute) model()) { - @Override - protected String buildValue_() { - return subject.getName(); - } - }; - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new PropertyAspectAdapter<PersistentAttribute, Image>( - new String[] {PersistentAttribute.DEFAULT_MAPPING_PROPERTY, PersistentAttribute.SPECIFIED_MAPPING_PROPERTY}, - (PersistentAttribute) model()) { - @Override - protected Image buildValue_() { - Image image = JpaMappingImageHelper.imageForAttributeMapping(subject.getMappingKey()); - if (((PersistentAttribute) model()).isVirtual()) { - return JptUiIcons.ghost(image); - } - return image; - } - }; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java deleted file mode 100644 index bd6b45633a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/PersistentTypeItemLabelProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.ui.internal.JpaMappingImageHelper; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class PersistentTypeItemLabelProvider extends AbstractItemLabelProvider -{ - public PersistentTypeItemLabelProvider( - PersistentType persistentType, DelegatingContentAndLabelProvider labelProvider) { - super(persistentType, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new PropertyAspectAdapter<PersistentType, String>(PersistentType.NAME_PROPERTY, (PersistentType) model()) { - @Override - protected String buildValue_() { - return subject.getName(); - } - }; - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new PropertyAspectAdapter<PersistentType, Image>(PersistentType.MAPPING_PROPERTY, (PersistentType) model()) { - @Override - protected Image buildValue_() { - return JpaMappingImageHelper.imageForTypeMapping(subject.getMappingKey()); - } - }; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/RootContextItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/RootContextItemContentProvider.java deleted file mode 100644 index c6e1311a2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/RootContextItemContentProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class RootContextItemContentProvider - extends AbstractTreeItemContentProvider<PersistenceXml> -{ - public RootContextItemContentProvider( - JpaRootContextNode rootContext, DelegatingTreeContentAndLabelProvider contentProvider) { - super(rootContext, contentProvider); - } - - @Override - public JpaRootContextNode model() { - return (JpaRootContextNode) super.model(); - } - - @Override - public IProject getParent() { - return model().getJpaProject().getProject(); - } - - @Override - protected ListValueModel<PersistenceXml> buildChildrenModel() { - return new PropertyListValueModelAdapter<PersistenceXml>( - new PropertyAspectAdapter<JpaRootContextNode, PersistenceXml>( - JpaRootContextNode.PERSISTENCE_XML_PROPERTY, - model()) { - @Override - protected PersistenceXml buildValue_() { - return subject.getPersistenceXml(); - } - }); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/RootContextItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/RootContextItemLabelProvider.java deleted file mode 100644 index 75adf5bb52..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/RootContextItemLabelProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.platform.generic; - -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -public class RootContextItemLabelProvider extends AbstractItemLabelProvider -{ - public RootContextItemLabelProvider( - JpaRootContextNode rootContextNode, DelegatingContentAndLabelProvider labelProvider) { - super(rootContextNode, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new StaticPropertyValueModel<String>(JptUiMessages.JpaContent_label); - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new StaticPropertyValueModel<Image>(JptUiPlugin.getImage(JptUiIcons.JPA_CONTENT)); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/prefs/JpaPreferencePage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/prefs/JpaPreferencePage.java deleted file mode 100644 index f1361e5f09..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/prefs/JpaPreferencePage.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.prefs; - -import java.io.IOException; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.preference.IPersistentPreferenceStore; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.prefs.JpaPreferenceConstants; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.swt.SWT; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; -import org.eclipse.ui.preferences.ScopedPreferenceStore; - -public class JpaPreferencePage extends PreferencePage - implements IWorkbenchPreferencePage -{ - public static final String ID = "org.eclipse.jpt.ui.jpaPreferencePage"; - - - private IPersistentPreferenceStore preferences; - - private IPreferenceStore userLibPreferences; - - private Label jpaLibLabel; - - private Combo jpaLibCombo; - - private Link userLibsLink; - - - public JpaPreferencePage() { - super(); - preferences = - new ScopedPreferenceStore( - new InstanceScope(), - JptCorePlugin.instance().getBundle().getSymbolicName()); - userLibPreferences = - new ScopedPreferenceStore( - new InstanceScope(), - JavaCore.getPlugin().getBundle().getSymbolicName()); - } - - public void init(IWorkbench workbench) {} - - public Control createContents(Composite parent) { - Composite container = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - - jpaLibLabel = createLabel(container, 1, JptUiMessages.JpaPreferencePage_defaultJpaLib); - - jpaLibCombo = createCombo(container, true); - - userLibsLink = new Link(container, SWT.NONE); - GridData data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - userLibsLink.setLayoutData(data); - userLibsLink.setText(JptUiMessages.JpaPreferencePage_userLibsLink); - userLibsLink.addSelectionListener( - new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - ((IWorkbenchPreferenceContainer) getContainer()) - .openPage(JavaUI.ID_USER_LIBRARY_PREFERENCE_PAGE, null); - } - } - ); - - performDefaults(); - return container; - } - - private Label createLabel(Composite container, int span, String text) { - Label label = new Label(container, SWT.NONE); - label.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - label.setLayoutData(gd); - return label; - } - - private Combo createCombo(Composite container, boolean fillHorizontal) { - Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); - if (fillHorizontal) { - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - else { - combo.setLayoutData(new GridData()); - } - return combo; - } - - private void fillJpaLibs() { - int index = jpaLibCombo.getSelectionIndex(); - String selectedJpaLib = null; - if (index >= 0) { - selectedJpaLib = jpaLibCombo.getItem(jpaLibCombo.getSelectionIndex()); - } - - jpaLibCombo.clearSelection(); - jpaLibCombo.setItems(JavaCore.getUserLibraryNames()); - - if (selectedJpaLib != null) { - int newIndex = CollectionTools.indexOf(jpaLibCombo.getItems(), selectedJpaLib); - if (newIndex >= 0) { - jpaLibCombo.select(newIndex); - } - } - } - - @Override - public void setVisible(boolean visible) { - super.setVisible(visible); - if (visible) { - fillJpaLibs(); - } - } - - public void performDefaults() { - fillJpaLibs(); - String defaultLib = preferences.getString(JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB); - int index = -1; - if (! StringTools.stringIsEmpty(defaultLib)) { - index = CollectionTools.indexOf(jpaLibCombo.getItems(), defaultLib); - } - if (index >= 0) { - jpaLibCombo.select(index); - } - - super.performDefaults(); - } - - public boolean performOk() { - int index = jpaLibCombo.getSelectionIndex(); - String defaultLib = (index >= 0) ? jpaLibCombo.getItem(index) : null; - if (! StringTools.stringIsEmpty(defaultLib)) { - preferences.setValue(JpaPreferenceConstants.PREF_DEFAULT_JPA_LIB, defaultLib); - } - try { - preferences.save(); - } - catch (IOException ioe) { - JptCorePlugin.log(ioe); - } - return true; - } - - public void dispose() { - // null pointer check - bug 168337 - if (jpaLibLabel != null) jpaLibLabel.dispose(); - if (jpaLibCombo != null) jpaLibCombo.dispose(); - super.dispose(); - } - - - -// private boolean libContainsJpaClasses() { -// return true; -// String jarLocation = getStringValue(); -// String errorMessage = JptUiMessages.JpaPreferencePage_invalidJpaLib; -// boolean hasError = false; -// -// try { -// JarFile jarFile = new JarFile(jarLocation); -// hasError = jarFile.getEntry("javax/persistence/EntityManager.class") == null; -// } -// catch (IOException ioe) { -// hasError = true; -// } -// -// if (hasError) { -// showErrorMessage(errorMessage); -// } -// else { -// clearErrorMessage(); -// } -// -// return ! hasError; -// } -// } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/DataModelPropertyPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/DataModelPropertyPage.java deleted file mode 100644 index cc0b64d8f2..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/DataModelPropertyPage.java +++ /dev/null @@ -1,309 +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.properties; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PropertyPage; -import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelSynchHelper; -import org.eclipse.wst.common.frameworks.internal.ui.ValidationStatus; - -public abstract class DataModelPropertyPage - extends PropertyPage - implements Listener, IDataModelListener -{ - protected IDataModel model; - - private ValidationStatus status = new ValidationStatus(); - private Map validationMap; - private String[] validationPropertyNames; - private boolean isValidating = false; - - protected DataModelSynchHelper synchHelper; - - private String infopopID; - - - protected DataModelPropertyPage(IDataModel model) { - super(); - this.model = model; - model.addListener(this); - synchHelper = initializeSynchHelper(model); - } - - - /** - * @return - */ - public DataModelSynchHelper initializeSynchHelper(IDataModel dm) { - return new DataModelSynchHelper(dm); - } - - - @Override - protected Control createContents(Composite parent) { - Composite top = createTopLevelComposite(parent); - setupInfopop(top); - setDefaults(); - addListeners(); - initializeValidationProperties(); - return top; - } - - private void initializeValidationProperties() { - validationPropertyNames = getValidationPropertyNames(); - if (validationPropertyNames == null || validationPropertyNames.length == 0) - validationMap = Collections.EMPTY_MAP; - else { - validationMap = new HashMap(validationPropertyNames.length); - for (int i = 0; i < validationPropertyNames.length; i++) - validationMap.put(validationPropertyNames[i], new Integer(i)); - } - } - - /** - * Subclass should return the model property names that need to be validated on this page in the - * order that they should present their messages. - * - * @return - */ - protected abstract String[] getValidationPropertyNames(); - - /** - * Return the top level Composite for this page. - */ - protected abstract Composite createTopLevelComposite(Composite parent); - - /** - * Set up info pop hooks if set. - */ - protected void setupInfopop(Control parent) { - if (getInfopopID() != null) - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, getInfopopID()); - } - - /** - * Setup the default values for this page. Subclasses should override to provide appropriate - * defaults. - */ - protected void setDefaults() { - restoreDefaultSettings(); - } - - /** - * Subclasses should implement this method if they have default settings that have been stored - * and need to be restored. - * - * @see storeDefaultSettings() - */ - protected void restoreDefaultSettings() { - } - - /** - * Add Listeners to controls at this point to avoid unnecessary events. Subclasses should - * override to add listeners to its controls. - */ - protected void addListeners() { - } - - /** - * Exiting the page. Subclasses may extend. - */ - protected void exit() { - } - - protected boolean getStatus(Integer key) { - return status.hasError(key); - } - - /** - * Sent when an event that the receiver has registered for occurs. If a subclass overrides this - * method, it must call super. - * - * @param event - * the event which occurred - */ - public void handleEvent(org.eclipse.swt.widgets.Event event) { - } - - /** - * Set the error message for this page based on the last error in the ValidationStatus. - */ - protected void setErrorMessage() { - String error = status.getLastErrMsg(); - if (error == null) { - if (getErrorMessage() != null) - setErrorMessage((String) null); - String warning = status.getLastWarningMsg(); - if (warning == null) { - if (getMessage() != null && getMessageType() == IMessageProvider.WARNING) - setMessage(null, IMessageProvider.WARNING); - else { - String info = status.getLastInfoMsg(); - if (info == null) { - if (getMessage() != null && getMessageType() == IMessageProvider.INFORMATION) - setMessage(null, IMessageProvider.INFORMATION); - } else if (!info.equals(getMessage())) { - setMessage(info, IMessageProvider.INFORMATION); - } - } - } else if (!warning.equals(getMessage())) - setMessage(warning, IMessageProvider.WARNING); - } else if (!error.equals(getErrorMessage())) - setErrorMessage(error); - } - - protected void setErrorStatus(Integer key, String errorMessage) { - status.setErrorStatus(key, errorMessage); - } - - protected void setWarningStatus(Integer key, String warningMessage) { - status.setWarningStatus(key, warningMessage); - } - - protected void setInfoStatus(Integer key, String infoMessage) { - status.setInfoStatus(key, infoMessage); - } - - protected void setOKStatus(Integer key) { - status.setOKStatus(key); - } - - /** - * This should be called by the Wizard just prior to running the performFinish operation. - * Subclasses should override to store their default settings. - */ - public void storeDefaultSettings() { - } - - /** - * The page is now being validated. At this time, each control is validated and then the - * controls are updated based on the results in the ValidationStatus which was updated during - * <code>validateControls()</code>. Finally, it will display the last error message and it - * will set the page complete. Subclasses will not typically override this method. - */ - protected void validatePage() { - if (!isValidating) { - isValidating = true; - try { - validateControlsBase(); - updateControls(); - setErrorMessage(); - setValid(status.getLastErrMsg() == null); - } - finally { - isValidating = false; - } - } - } - - /** - * Validate individual controls. Use validation keys to keep track of errors. - * - * @see setOKStatus(Integer) and setErrorMessage(Integer, String) - */ - protected final String validateControlsBase() { - if (!validationMap.isEmpty()) { - String propName; - for (int i = 0; i < validationPropertyNames.length; i++) { - propName = validationPropertyNames[i]; - Integer valKey = (Integer) validationMap.get(propName); - if (valKey != null) - validateProperty(propName, valKey); - if (!getStatus(valKey)) - return propName; - } - } - return null; - } - - /** - * @param propertyName - * @param validationkey - */ - private void validateProperty(String propertyName, Integer validationKey) { - setOKStatus(validationKey); - IStatus status1 = model.validateProperty(propertyName); - if (!status1.isOK()) { - String message = status1.isMultiStatus() ? status1.getChildren()[0].getMessage() : status1.getMessage(); - switch (status1.getSeverity()) { - case IStatus.ERROR : - setErrorStatus(validationKey, message); - break; - case IStatus.WARNING : - setWarningStatus(validationKey, message); - break; - case IStatus.INFO : - setInfoStatus(validationKey, message); - break; - } - } - } - - /** - * Update the enablement of controls after validation. Sublcasses should check the status of - * validation keys to determine enablement. - */ - protected void updateControls() { - } - - - /* - * If a property changes that we want to validate, force validation on this page. - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModelListener#propertyChanged(java.lang.String, - * java.lang.Object, java.lang.Object) - */ - public void propertyChanged(DataModelEvent event) { - String propertyName = event.getPropertyName(); - if (validationPropertyNames != null && (event.getFlag() == DataModelEvent.VALUE_CHG || (!isValid() && event.getFlag() == DataModelEvent.VALID_VALUES_CHG))) { - for (int i = 0; i < validationPropertyNames.length; i++) { - if (validationPropertyNames[i].equals(propertyName)) { - validatePage(); - break; - } - } - } - } - - /** - * @return Returns the model. - */ - protected IDataModel getDataModel() { - return model; - } - - public void dispose() { - super.dispose(); - if (synchHelper != null) { - synchHelper.dispose(); - synchHelper = null; - } - } - - protected String getInfopopID() { - return infopopID; - } - - public void setInfopopID(String infopopID) { - this.infopopID = infopopID; - } -} 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 deleted file mode 100644 index 3dc3fb42c1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java +++ /dev/null @@ -1,382 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.properties; - -import java.lang.reflect.InvocationTargetException; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.JpaModelManager; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.ui.internal.DTPUiTools; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.swt.SWT; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; - -public class JpaProjectPropertiesPage - extends DataModelPropertyPage - implements JpaFacetDataModelProperties -{ - private PlatformGroup platformGroup; - - private ConnectionGroup connectionGroup; - - private PersistentClassManagementGroup persistentClassManagementGroup; - - - /** - * Constructor for SamplePropertyPage. - */ - public JpaProjectPropertiesPage() { - super(DataModelFactory.createDataModel(new JpaFacetDataModelProvider())); - } - - - @Override - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - - platformGroup = new PlatformGroup(composite); - connectionGroup = new ConnectionGroup(composite); - persistentClassManagementGroup = new PersistentClassManagementGroup(composite); - - setRuntime(); - - Dialog.applyDialogFont(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE); - - return composite; - } - - private void setRuntime() { - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(getJpaProject().getProject()); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); - return; - } - IRuntime runtime = facetedProject.getPrimaryRuntime(); - model.setProperty(JpaFacetDataModelProperties.RUNTIME, runtime); - } - - @Override - protected String[] getValidationPropertyNames() { - return new String[] { - JpaFacetDataModelProperties.PLATFORM_ID, - JpaFacetDataModelProperties.CONNECTION, - JpaFacetDataModelProperties.USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, - JpaFacetDataModelProperties.USER_OVERRIDE_DEFAULT_SCHEMA, - JpaFacetDataModelProperties.DISCOVER_ANNOTATED_CLASSES - }; - } - - protected JpaProject getJpaProject() { - return (JpaProject) this.getElement().getAdapter(JpaProject.class); - } - - Combo createCombo(Composite container, int span, boolean fillHorizontal) { - Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); - GridData gd; - if (fillHorizontal) { - gd = new GridData(GridData.FILL_HORIZONTAL); - } - else { - gd = new GridData(); - } - gd.horizontalSpan = span; - combo.setLayoutData(gd); - return combo; - } - - Button createButton(Composite container, int span, String text, int style) { - Button button = new Button(container, SWT.NONE | style); - button.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - button.setLayoutData(gd); - return button; - } - - @Override - protected void performDefaults() { - platformGroup.performDefaults(); - connectionGroup.performDefaults(); - persistentClassManagementGroup.performDefaults(); - } - - @Override - public boolean performOk() { - JpaProject jpaProject = this.getJpaProject(); - if (jpaProject == null) { - return true; // the facet has been uninstalled during our trip to the properties - } - - boolean change = false; - boolean platformChange = false; - - IProject project = jpaProject.getProject(); - - String platform = this.model.getStringProperty(JpaFacetDataModelProperties.PLATFORM_ID); - if ( ! platform.equals(jpaProject.getJpaPlatform().getId())) { - change = true; - platformChange = true; - JptCorePlugin.setJpaPlatformId(project, platform); - } - - String connection = this.model.getStringProperty(JpaFacetDataModelProperties.CONNECTION); - if ( ! connection.equals(jpaProject.getDataSource().getConnectionProfileName())) { - change = true; - jpaProject.getDataSource().setConnectionProfileName(connection); - JptCorePlugin.setConnectionProfileName(project, connection); - } - - String userOverrideDefaultSchema = null; - if (this.model.getBooleanProperty(JpaFacetDataModelProperties.USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - userOverrideDefaultSchema = this.model.getStringProperty(JpaFacetDataModelProperties.USER_OVERRIDE_DEFAULT_SCHEMA); - } - String projectUserOverrideDefaultSchema = jpaProject.getUserOverrideDefaultSchemaName(); - if (! StringTools.stringsAreEqualIgnoreCase(userOverrideDefaultSchema, projectUserOverrideDefaultSchema)) { - change = true; - jpaProject.setUserOverrideDefaultSchemaName(userOverrideDefaultSchema); - JptCorePlugin.setUserOverrideDefaultSchemaName(project, userOverrideDefaultSchema); - } - - boolean discover = this.model.getBooleanProperty(JpaFacetDataModelProperties.DISCOVER_ANNOTATED_CLASSES); - if (discover != jpaProject.discoversAnnotatedClasses()) { - change = true; - jpaProject.setDiscoversAnnotatedClasses(discover); - JptCorePlugin.setDiscoverAnnotatedClasses(project, discover); - } - - if (platformChange) { - JpaModelManager.instance().rebuildJpaProject(project); - } - if (change) { - buildProject(project); - } - return true; - } - - private static void buildProject(final IProject project) { - IRunnableWithProgress r= new IRunnableWithProgress() { - public void run(IProgressMonitor pm) throws InvocationTargetException { - try { - project.build(IncrementalProjectBuilder.FULL_BUILD, pm); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); - } - } - }; - try { - PlatformUI.getWorkbench().getProgressService().run(true, false, r); - } - catch (InterruptedException ie) { /* nothing to do */ } - catch (InvocationTargetException ie) { /* nothing to do */ } - } - - - private final class PlatformGroup - { - final Combo platformCombo; - - - public PlatformGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // TODO - // PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IDaliHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); - - platformCombo = createCombo(group, 1, true); - synchHelper.synchCombo(platformCombo, PLATFORM_ID, null); - - performDefaults(); - } - - void performDefaults() { - String platformId = getJpaProject().getJpaPlatform().getId(); - model.setProperty(PLATFORM_ID, platformId); - } - } - - - private final class ConnectionGroup - { - final Combo connectionCombo; - - private Link connectionLink; - - private Link connectLink; - - private final Button overrideDefaultSchemaButton; - - private final Label defaultSchemaLabel; - - private final Combo defaultSchemaCombo; - - - public ConnectionGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_connectionLabel); - group.setLayout(new GridLayout(3, false)); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - connectionCombo = createCombo(group, 3, true); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION); - synchHelper.synchCombo(connectionCombo, CONNECTION, null); - connectionCombo.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateConnectLink(); - } - }); - - connectionLink = new Link(group, SWT.NONE); - GridData data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - connectionLink.setLayoutData(data); - connectionLink.setText(JptUiMessages.JpaFacetWizardPage_connectionLink); - connectionLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - openNewConnectionWizard(); - } - } - ); - - connectLink = new Link(group, SWT.NONE); - data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - connectLink.setLayoutData(data); - connectLink.setText(JptUiMessages.JpaFacetWizardPage_connectLink); - connectLink.setEnabled(false); - connectLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - openConnectionProfile(); - } - }); - - overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK); - synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, new Control[0]); - - defaultSchemaLabel = new Label(group, SWT.LEFT); - defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel); - GridData gd = new GridData(); - gd.horizontalSpan = 1; - defaultSchemaLabel.setLayoutData(gd); - - defaultSchemaCombo = createCombo(group, 1, true); - synchHelper.synchCombo( - defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA, - new Control[] {defaultSchemaLabel}); - - performDefaults(); - } - - void openNewConnectionWizard() { - String connectionName = DTPUiTools.createNewProfile(); - if (connectionName != null) { - model.setProperty(CONNECTION, connectionName); - } - } - - private void openConnectionProfile() { - ConnectionProfile connection = getConnectionProfile(); - connection.connect(); - model.setBooleanProperty(CONNECTION_ACTIVE, connection.isActive()); - updateConnectLink(); - return; - } - - private void updateConnectLink() { - ConnectionProfile connectionProfile = getConnectionProfile(); - connectLink.setEnabled(! connectionProfile.isNull() && ! connectionProfile.isConnected()); - } - - private ConnectionProfile getConnectionProfile() { - return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(model.getStringProperty(CONNECTION)); - } - - void performDefaults() { - String connectionName = getJpaProject().getDataSource().getConnectionProfileName(); - model.setProperty(CONNECTION, connectionName); - - String defaultSchema = getJpaProject().getUserOverrideDefaultSchemaName(); - model.setProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, defaultSchema != null); - model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, defaultSchema); - } - } - - - private final class PersistentClassManagementGroup - { - final Button discoverClassesButton; - - final Button listClassesButton; - - - public PersistentClassManagementGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_persistentClassManagementLabel); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); - - discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO); - synchHelper.synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null); - - listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO); - synchHelper.synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null); - - performDefaults(); - } - - void performDefaults() { - boolean discoverClasses = getJpaProject().discoversAnnotatedClasses(); - model.setProperty(DISCOVER_ANNOTATED_CLASSES, Boolean.valueOf(discoverClasses)); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelection.java deleted file mode 100644 index 4f64a64780..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelection.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import org.eclipse.jpt.core.JpaStructureNode; - -/** - * Straightforward implementation of the JpaSelection interface. - */ -public class DefaultJpaSelection - implements JpaSelection -{ - private final JpaStructureNode selectedNode; - - - public DefaultJpaSelection(JpaStructureNode selectedNode) { - super(); - if (selectedNode == null) { - throw new NullPointerException("A 'selectedNode' is required; otherwise use NULL_SELECTION."); - } - this.selectedNode = selectedNode; - } - - public JpaStructureNode getSelectedNode() { - return this.selectedNode; - } - - public boolean isEmpty() { - // by definition, this selection is never empty - // use IJpaSelection.NULL_SELECTION for empty selections - return false; - } - - @Override - public boolean equals(Object obj) { - if (! (obj instanceof JpaSelection)) { - return false; - } - JpaSelection other = (JpaSelection) obj; - return ( ! other.isEmpty()) && this.selectedNode.equals(other.getSelectedNode()); - } - - @Override - public int hashCode() { - return this.selectedNode.hashCode(); - } - - @Override - public String toString() { - return this.selectedNode.toString(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java deleted file mode 100644 index b83bca658a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/DefaultJpaSelectionManager.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IPageListener; -import org.eclipse.ui.IPartListener2; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartReference; -import org.eclipse.ui.IWorkbenchWindow; - -/** - * A {@link JpaSelectionManager} stores the current {@link JpaSelection} and - * notifies <code>ISelectionListener</code>s when the selection changes. - */ -public class DefaultJpaSelectionManager - implements JpaSelectionManager -{ - /* The window for which this object manages selections */ - private IWorkbenchWindow window; - - /* The set of pages for which this object is managing selections */ - private Set<IWorkbenchPage> pages; - - /* The active editor part */ - private IEditorPart activeEditor; - - private JpaSelection currentSelection; - - /* The map of <code>IJpaSelectionParticipant</code>s (keyed by part) */ - private Map<IWorkbenchPart, JpaSelectionParticipant> selectionParticipants; - - private IPageListener pageListener; - - private IPartListener2 partListener; - - - public DefaultJpaSelectionManager() { - super(); - pages = Collections.synchronizedSet(new HashSet<IWorkbenchPage>()); - selectionParticipants = Collections.synchronizedMap(new HashMap<IWorkbenchPart, JpaSelectionParticipant>()); - pageListener = new PageListener(); - partListener = new PartListener(); - currentSelection = DefaultJpaSelection.NULL_SELECTION; - } - - void init(IWorkbenchWindow aWindow) { - window = aWindow; - aWindow.addPageListener(pageListener); - initPage(aWindow.getActivePage()); - } - - private void initPage(IWorkbenchPage page) { - if ((page != null) && (! pages.contains(page))) { - page.addPartListener(partListener); - pages.add(page); - activateEditor(page.getActiveEditor()); - } - } - - private void disposePage(IWorkbenchPage page) { - if ((page != null) && (pages.contains(page))) { - page.removePartListener(partListener); - pages.remove(page); - } - } - - private void activateEditor(IEditorPart editor) { - if (editor == activeEditor) { - return; - } - if (activeEditor != null) { - inactivateEditor(activeEditor); - } - initPart(editor); - activeEditor = editor; - selectEditor(activeEditor); - } - - private void inactivateEditor(IEditorPart editor) { - - } - - void initPart(IWorkbenchPart part) { - if (part != null) { - if (selectionParticipants.get(part) == null) { - JpaSelectionParticipant selectionParticipant = - (JpaSelectionParticipant) part.getAdapter(JpaSelectionParticipant.class); - if (selectionParticipant != null) { - selectionParticipants.put(part, selectionParticipant); - } - } - } - } - - private void selectEditor(IEditorPart editor) { - selectPart(editor); - } - - void selectPart(IWorkbenchPart part) { - JpaSelectionParticipant selectionParticipant = getSelectionParticipant(part); - if (selectionParticipant != null) { - select(selectionParticipant.getSelection(), selectionParticipant); - } - } - - void hidePart(IWorkbenchPart part) { - JpaSelectionParticipant selectionParticipant = getSelectionParticipant(part); - if ((selectionParticipant != null) && (selectionParticipant.disposeOnHide())) { - closePart(part); - } - } - - void closePart(IWorkbenchPart part) { - JpaSelectionParticipant selectionParticipant = getSelectionParticipant(part); - if (selectionParticipant != null) { - disposePart(part); - checkForNoEditors(); - } - } - - void disposePart(IWorkbenchPart part) { - if ((part != null) && (selectionParticipants.containsKey(part))) { - selectionParticipants.remove(part).dispose(); - } - } - - void checkForNoEditors() { - IWorkbenchPage activePage = window.getActivePage(); - if ((activePage == null) - || (activePage.getActiveEditor() == null)) { - select(DefaultJpaSelection.NULL_SELECTION, null); - } - } - - public void register(IWorkbenchPart part) { - initPart(part); - } - - public boolean isRegistered(IWorkbenchPart part) { - return selectionParticipants.get(part) != null; - } - - public void select(JpaSelection newSelection, JpaSelectionParticipant source) { - if (currentSelection.equals(newSelection)) { - return; - } - - currentSelection = newSelection; - Object nonNullSource = (source == null) ? this : source; - fireSelectionChange( - new JpaSelectionEvent(newSelection, JpaSelectionEvent.SELECTION, nonNullSource) - ); - } - - public void deselect(JpaSelection oldSelection, JpaSelectionParticipant source) { - if (currentSelection.equals(oldSelection)) { - currentSelection = DefaultJpaSelection.NULL_SELECTION; - Object nonNullSource = (source == null) ? this : source; - fireSelectionChange( - new JpaSelectionEvent(oldSelection, JpaSelectionEvent.DESELECTION, nonNullSource) - ); - } - } - - private void fireSelectionChange(JpaSelectionEvent event) { - for (JpaSelectionParticipant sp : selectionParticipants.values()) { - sp.selectionChanged(event); - } - } - - private JpaSelectionParticipant getSelectionParticipant(IWorkbenchPart part) { - return selectionParticipants.get(part); - } - - public JpaSelection getCurrentSelection() { - return currentSelection; - } - - public void dispose() { - window.removePageListener(pageListener); - selectionParticipants.clear(); - - for (Iterator<IWorkbenchPage> stream = new CloneIterator<IWorkbenchPage>(this.pages); stream.hasNext(); ) { - this.disposePage(stream.next()); - } - - for (Iterator<IWorkbenchPart> stream = new CloneIterator<IWorkbenchPart>(selectionParticipants.keySet()); stream.hasNext(); ) { - this.disposePart(stream.next()); - } - } - - - private class PageListener implements IPageListener - { - public void pageActivated(IWorkbenchPage page) { - // nop - } - - PageListener() { - super(); - } - - public void pageClosed(IWorkbenchPage page) { - DefaultJpaSelectionManager.this.disposePage(page); - } - - public void pageOpened(IWorkbenchPage page) { - DefaultJpaSelectionManager.this.initPage(page); - } - } - - - private class PartListener implements IPartListener2 - { - PartListener() { - super(); - } - - public void partActivated(IWorkbenchPartReference partRef) { - IWorkbenchPart part = partRef.getPart(false); - if (part != null) { - DefaultJpaSelectionManager.this.initPart(part); - DefaultJpaSelectionManager.this.selectPart(part); - } - } - - public void partBroughtToTop(IWorkbenchPartReference partRef) { - // nop - } - - public void partClosed(IWorkbenchPartReference partRef) { - IWorkbenchPart part = partRef.getPart(false); - if (part != null) { - DefaultJpaSelectionManager.this.closePart(part); - DefaultJpaSelectionManager.this.disposePart(part); - DefaultJpaSelectionManager.this.checkForNoEditors(); - } - } - - public void partDeactivated(IWorkbenchPartReference partRef) { - // nop - } - - public void partHidden(IWorkbenchPartReference partRef) { - IWorkbenchPart part = partRef.getPart(false); - if (part != null) { - DefaultJpaSelectionManager.this.hidePart(part); - } - } - - public void partInputChanged(IWorkbenchPartReference partRef) { - // nop - } - - public void partOpened(IWorkbenchPartReference partRef) { - IWorkbenchPart part = partRef.getPart(false); - if (part != null) { - initPart(part); - } - } - - public void partVisible(IWorkbenchPartReference partRef) { - IWorkbenchPart part = partRef.getPart(false); - if (part != null) { - initPart(part); - } - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.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 deleted file mode 100644 index 2a8eef6a1d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaDetailsSelectionParticipant.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import org.eclipse.jpt.ui.internal.views.JpaDetailsView; - - -public class JpaDetailsSelectionParticipant - implements JpaSelectionParticipant -{ - private final JpaDetailsView detailsView; - - - public JpaDetailsSelectionParticipant(JpaDetailsView detailsView) { - super(); - this.detailsView = detailsView; - } - - public JpaSelection getSelection() { - return this.detailsView.getSelection(); - } - - public void selectionChanged(JpaSelectionEvent evt) { - this.detailsView.select(evt.getSelection()); - } - - public boolean disposeOnHide() { - return false; - } - - public void dispose() { - // NOP - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelection.java deleted file mode 100644 index 8655651a68..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelection.java +++ /dev/null @@ -1,37 +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.selection; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jpt.core.JpaStructureNode; - -@SuppressWarnings("nls") -public interface JpaSelection extends ISelection -{ - static JpaSelection NULL_SELECTION = - new JpaSelection() { - public JpaStructureNode getSelectedNode() { - return null; - } - - public boolean isEmpty() { - return true; - } - - @Override - public String toString() { - return "NULL SELECTION"; - } - }; - - - JpaStructureNode getSelectedNode(); -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionEvent.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionEvent.java deleted file mode 100644 index d28bafed11..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionEvent.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import java.util.EventObject; - -public class JpaSelectionEvent extends EventObject -{ - /** - * Serializable uid - * @since 0.5 - */ - private static final long serialVersionUID = 1L; - - - /** - * Indicates that the selection object is now selected - */ - public static int SELECTION = 1; - - /** - * Indicates that the selection object has now been deselected - */ - public static int DESELECTION = 2; - - - /** - * The selection object whose selection status has changed - */ - private JpaSelection selection; - - /** - * The type of the selection event, either a SELECTION or a DESELECTION - */ - private int type; - - - public JpaSelectionEvent(JpaSelection theSelection, int theType, Object source) { - super(source); - selection = theSelection; - type = theType; - } - - /** - * Return the selection object whose selection status has changed - */ - public JpaSelection getSelection() { - return selection; - } - - /** - * Return the type of selection event, either a SELECTION or a DESELECTION - */ - public int getType() { - return type; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java deleted file mode 100644 index 6ee3e33728..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionManager.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import org.eclipse.ui.IWorkbenchPart; - -public interface JpaSelectionManager -{ - /** - * Return the current selection. - * This will never be null, but it may be empty. - */ - public JpaSelection getCurrentSelection(); - - /** - * Not to be called lightly, this will affect the selection for all interested - * objects in a window. - * @param newSelection The new selection for the current window. - * @param source The selection participant (if any) that is causing the - * selection. May be null. - */ - public void select(JpaSelection newSelection, JpaSelectionParticipant source); - - /** - * Not to be called lightly, this will affect the selection for all interested - * objects in a window. - * @param oldSelection The oldSelection will be deselected, iff it matches - * the current selection. If so, the new selection will be an empty JpaSelection. - * @param source The selection participant (if any) that is causing the - * selection. May be null. - */ - public void deselect(JpaSelection oldSelection, JpaSelectionParticipant source); - - /** - * This may be used to register a part with the selection manager if the part - * is known to need access to the selection manager before it is ever activated - * or in the case it may be activated prior to the selection manager being - * created. - * - * It should not be necessary to deregister a part, as that happens when the - * part is closed. - */ - public void register(IWorkbenchPart part); - - /** - * Returns true if the part is currently registered to respond to selections - * from this selection manager - */ - public boolean isRegistered(IWorkbenchPart part); -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionParticipant.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionParticipant.java deleted file mode 100644 index c8cf11d6d3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaSelectionParticipant.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -public interface JpaSelectionParticipant -{ - /** - * Return the current selection of the participant - */ - JpaSelection getSelection(); - - /** - * The selection has changed in the central selection manager. - * Update this participant accordingly. - */ - void selectionChanged(JpaSelectionEvent evt); - - /** - * Return whether this selection participant should disconnect itself from - * its part when its part is hidden from view. - * <b>Typically</b> editor participants will return true and view participants will - * return false. - */ - boolean disposeOnHide(); - - /** - * This participant is no longer needed (most likely because its part has - * closed). Dispose of it. - */ - void dispose(); -} diff --git a/jpa/plugins/org.eclipse.jpt.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 deleted file mode 100644 index ba3a36884b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/JpaStructureSelectionParticipant.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jpt.ui.internal.views.structure.JpaStructureView; - -public class JpaStructureSelectionParticipant - implements JpaSelectionParticipant -{ - final JpaStructureView structureView; - - - public JpaStructureSelectionParticipant(JpaSelectionManager selectionManager, JpaStructureView structureView) { - super(); - this.structureView = structureView; - structureView.addSelectionChangedListener(new StructureViewSelectionListener(selectionManager, structureView)); - } - - public JpaSelection getSelection() { - return this.structureView.getJpaSelection(); - } - - public void selectionChanged(JpaSelectionEvent evt) { - if (evt.getSource() != this) { - this.structureView.select(evt.getSelection()); - } - } - - public boolean disposeOnHide() { - return false; - } - - public void dispose() { - // NOP - } - - - // ********** listener ********** - - private class StructureViewSelectionListener - implements ISelectionChangedListener - { - private final JpaSelectionManager selectionManager; - - StructureViewSelectionListener(JpaSelectionManager selectionManager, JpaStructureView structureView) { - super(); - this.selectionManager = selectionManager; - } - - public void selectionChanged(SelectionChangedEvent event) { - if (structureView.getViewSite().getWorkbenchWindow().getPartService().getActivePart() == structureView) { - selectionManager.select(this.structureViewSelection(), JpaStructureSelectionParticipant.this); - } - } - - private JpaSelection structureViewSelection() { - return JpaStructureSelectionParticipant.this.structureView.getJpaSelection(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.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 deleted file mode 100644 index 63c0d66869..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionManagerFactory.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -public class SelectionManagerFactory -{ - private static SelectionManagerFactory INSTANCE; - - private static Object MUTEX = new Object(); - - - /** - * Each <code>IWorkbenchWindow</code> has its own <code>JpaSelectionManager</code> - * to track the selection events in the <code>IWorkbenchWindow</code>. All - * <code>ISelectionListener</code>s in the same <code>IWorkbenchWindow</code> - * share the same <code>JpaSelectionManager</code>. - * - * @return The <code>JpaSelectionManager</code> associated with the current - * <code>IWorkbenchWindow</code> - */ - public static JpaSelectionManager getSelectionManager(IWorkbenchWindow window) { - if (INSTANCE == null) { - // this is thread safe for now. you never know whats comming - synchronized (MUTEX) { - if(INSTANCE == null) { - INSTANCE = new SelectionManagerFactory(); - // if we do the init inside the constructor we end up in a loop - // because the addWindowListener(this) does a callback to us - INSTANCE.init(); - } - } - } - return INSTANCE.internalGetSelectionManager(window); - } - - - private Map<IWorkbenchWindow, DefaultJpaSelectionManager> managers; - - private WindowListener windowListener; - - - private SelectionManagerFactory() { - managers = new HashMap<IWorkbenchWindow, DefaultJpaSelectionManager>(); - windowListener = new WindowListener(); - } - - private void init() { - IWorkbench workbench = PlatformUI.getWorkbench(); - workbench.addWindowListener(windowListener); - } - - /** - * Returns the JpaSelectionManager for the IWorkbenchWindow. - * Creates a new one if none exists yet. - */ - private DefaultJpaSelectionManager internalGetSelectionManager(IWorkbenchWindow window) { - if (window == null) { - throw new IllegalArgumentException("The IWorkbenchWindow cannot be null"); - } - - if (! managers.containsKey(window)) { - DefaultJpaSelectionManager manager = new DefaultJpaSelectionManager(); - this.managers.put(window, manager); - manager.init(window); - } - - return managers.get(window); - } - - - private class WindowListener implements IWindowListener - { - public void windowOpened(IWorkbenchWindow aWindow) {} - - public void windowClosed(IWorkbenchWindow aWindow) { - DefaultJpaSelectionManager 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 deleted file mode 100644 index ca9cc44540..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/SelectionParticipantFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.jpt.ui.internal.views.JpaDetailsView; -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 -{ - @SuppressWarnings("unchecked") - private static final Class[] ADAPTER_LIST = new Class[] { JpaSelectionParticipant.class }; - - @SuppressWarnings("unchecked") - public Class[] getAdapterList() { - return ADAPTER_LIST; - } - - @SuppressWarnings("unchecked") - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (! (adaptableObject instanceof IWorkbenchPart)) { - return null; - } - - JpaSelectionManager selectionManager = - SelectionManagerFactory.getSelectionManager(((IWorkbenchPart) adaptableObject).getSite().getWorkbenchWindow()); - if (adaptableObject instanceof ITextEditor) { - return new TextEditorSelectionParticipant(selectionManager, (ITextEditor) adaptableObject); - } - if (adaptableObject instanceof JpaStructureView) { - return new JpaStructureSelectionParticipant(selectionManager, (JpaStructureView) adaptableObject); - } - else if (adaptableObject instanceof JpaDetailsView) { - return new JpaDetailsSelectionParticipant((JpaDetailsView) adaptableObject); - } - else { - return null; - } - } - -} 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 deleted file mode 100644 index 2580b7ed71..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/selection/TextEditorSelectionParticipant.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.selection; - -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IPropertyListener; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.texteditor.ITextEditor; - -public class TextEditorSelectionParticipant - implements JpaSelectionParticipant -{ - private final JpaSelectionManager selectionManager; - - final ITextEditor textEditor; - - private final IPropertyListener editorInputListener; - - private final ISelectionChangedListener editorSelectionListener; - - private JpaSelection currentSelection; - - private boolean forwardSelection = true; // TODO this just smells wrong ~bjv - - - public TextEditorSelectionParticipant(JpaSelectionManager selectionManager, ITextEditor textEditor) { - super(); - this.selectionManager = selectionManager; - this.textEditor = textEditor; - this.editorInputListener = new EditorInputListener(); - this.textEditor.addPropertyListener(this.editorInputListener); - this.editorSelectionListener = new EditorSelectionListener(); - this.getPostSelectionProvider().addPostSelectionChangedListener(this.editorSelectionListener); - this.currentSelection = this.calculateSelection(); - } - - // ********** IJpaSelectionParticipant implementation ********** - - public JpaSelection getSelection() { - return this.currentSelection; - } - - public void selectionChanged(JpaSelectionEvent evt) { - JpaSelection newSelection = evt.getSelection(); - - if ((newSelection == JpaSelection.NULL_SELECTION) - || newSelection.equals(this.currentSelection)) { - return; - } - - if (getActiveTextEditor() != this.textEditor) { - return; - } - - this.forwardSelection = false; - TextRange textRange = newSelection.getSelectedNode().getSelectionTextRange(); - if (textRange != null) { - this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength()); - this.currentSelection = newSelection; - } - this.forwardSelection = true; - } - - public boolean disposeOnHide() { - return true; - } - - public void dispose() { - this.textEditor.removePropertyListener(this.editorInputListener); - this.getPostSelectionProvider().removePostSelectionChangedListener(this.editorSelectionListener); - } - - - // ********** internal methods ********** - - protected JpaSelection calculateSelection() { - ISelection selection = this.textEditor.getSelectionProvider().getSelection(); - if (! (selection instanceof ITextSelection)) { - return JpaSelection.NULL_SELECTION; - } - - JpaFile jpaFile = this.getJpaFile(); - if (jpaFile == null) { - return JpaSelection.NULL_SELECTION; - } - - return this.buildSelection(jpaFile.getStructureNode(((ITextSelection) selection).getOffset())); - } - - protected JpaSelection buildSelection(JpaStructureNode selectedNode) { - return (selectedNode == null) ? JpaSelection.NULL_SELECTION : new DefaultJpaSelection(selectedNode); - } - - protected IWorkbenchPage getActivePage() { - return this.textEditor.getEditorSite().getWorkbenchWindow().getActivePage(); - } - - protected IWorkbenchPart getActivePart() { - IWorkbenchPage activePage = getActivePage(); - return (activePage == null) ? null: activePage.getActivePart(); - } - - protected IEditorPart getActiveEditor() { - IWorkbenchPage activePage = getActivePage(); - return (activePage == null) ? null: activePage.getActiveEditor(); - } - - protected ITextEditor getActiveTextEditor() { - return getTextEditor(getActiveEditor()); - } - - protected ITextEditor getTextEditor(IWorkbenchPart part) { - return (part == null) ? null : (ITextEditor) part.getAdapter(ITextEditor.class); - } - - protected JpaFile getJpaFile() { - IEditorInput input = this.textEditor.getEditorInput(); - if ( ! (input instanceof IFileEditorInput)) { - return null; - } - return JptCorePlugin.getJpaFile(((IFileEditorInput) input).getFile()); - } - - protected IPostSelectionProvider getPostSelectionProvider() { - return (IPostSelectionProvider) this.textEditor.getSelectionProvider(); - } - - - // ********** listener callbacks ********** - - protected void editorInputChanged() { - this.selectionChanged(); - } - - protected void editorSelectionChanged(SelectionChangedEvent event) { - // This is a bit kludgey. We check to see if the selection event - // occurred when a participating part is active (and so, ostensibly, - // *because* of the participating part). If so, we reselect the valid - // text. - IWorkbenchPart activePart = getActivePart(); - if (getTextEditor(activePart) != this.textEditor && this.selectionManager.isRegistered(activePart)) { - if (this.currentSelection.isEmpty()) { - return; - } - - this.forwardSelection = false; - TextRange textRange = this.currentSelection.getSelectedNode().getSelectionTextRange(); - if (textRange != null) { - this.textEditor.selectAndReveal(textRange.getOffset(), textRange.getLength()); - } - this.forwardSelection = true; - - return; - } - - this.selectionChanged(); - } - - protected void selectionChanged() { - JpaSelection newSelection = this.calculateSelection(); - if (newSelection.equals(this.currentSelection)) { - return; - } - this.currentSelection = newSelection; - - if (this.forwardSelection) { - this.selectionManager.select(newSelection, this); - } - } - - - // ********** listeners ********** - - protected class EditorInputListener implements IPropertyListener { - protected EditorInputListener() { - super(); - } - public void propertyChanged(Object source, int propId) { - if ((source == TextEditorSelectionParticipant.this.textEditor) - && (propId == IEditorPart.PROP_INPUT)) { - TextEditorSelectionParticipant.this.editorInputChanged(); - } - } - } - - - protected class EditorSelectionListener implements ISelectionChangedListener { - protected EditorSelectionListener() { - super(); - } - public void selectionChanged(SelectionChangedEvent event) { - TextEditorSelectionParticipant.this.editorSelectionChanged(event); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.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 deleted file mode 100644 index 49f316475a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemContentProviderFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.PersistentAttributeItemContentProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; - -public abstract class GeneralJpaMappingItemContentProviderFactory - implements TreeItemContentProviderFactory -{ - public TreeItemContentProvider buildItemContentProvider( - Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider; - if (item instanceof PersistentType) { - return buildPersistentTypeItemContentProvider((PersistentType) item, treeContentProvider); - } - else if (item instanceof PersistentAttribute) { - return new PersistentAttributeItemContentProvider((PersistentAttribute) item, treeContentProvider); - } - return null; - } - - protected abstract TreeItemContentProvider buildPersistentTypeItemContentProvider(PersistentType persistentType, DelegatingTreeContentAndLabelProvider treeContentProvider); -} 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 deleted file mode 100644 index 26c0e98de0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/GeneralJpaMappingItemLabelProviderFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.ui.internal.platform.generic.PersistentAttributeItemLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.PersistentTypeItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; - -public abstract class GeneralJpaMappingItemLabelProviderFactory - implements ItemLabelProviderFactory -{ - public ItemLabelProvider buildItemLabelProvider( - Object item, DelegatingContentAndLabelProvider labelProvider) { - if (item instanceof PersistentType) { - return new PersistentTypeItemLabelProvider((PersistentType) item, labelProvider); - } - else if (item instanceof PersistentAttribute) { - return new PersistentAttributeItemLabelProvider((PersistentAttribute) item, labelProvider); - } - return null; - } -} 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 deleted file mode 100644 index 779f034e4d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemContentProviderFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.JavaPersistentTypeItemContentProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; - - -public class JavaItemContentProviderFactory extends GeneralJpaMappingItemContentProviderFactory -{ - @Override - public TreeItemContentProvider buildItemContentProvider( - Object item, DelegatingContentAndLabelProvider contentProvider) { - DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentProvider; - if (item instanceof JavaResourceModel) { - return new ResourceModelItemContentProvider((JavaResourceModel) item, treeContentProvider); - } - return super.buildItemContentProvider(item, treeContentProvider); - } - - @Override - protected TreeItemContentProvider buildPersistentTypeItemContentProvider(PersistentType persistentType, DelegatingTreeContentAndLabelProvider treeContentProvider) { - return new JavaPersistentTypeItemContentProvider((JavaPersistentType) persistentType, treeContentProvider); - } -} 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 deleted file mode 100644 index 82bc52ac7c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaItemLabelProviderFactory.java +++ /dev/null @@ -1,17 +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.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 deleted file mode 100644 index babcf8db55..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; - -public class JavaResourceModelStructureProvider - extends ResourceModelStructureProvider -{ - public JavaResourceModelStructureProvider(JavaResourceModel resourceModel) { - super(resourceModel); - } - - public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { - return new JavaItemContentProviderFactory(); - } - - public ItemLabelProviderFactory getItemLabelProviderFactory() { - return new JavaItemLabelProviderFactory(); - } -} 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 deleted file mode 100644 index 29a64cc345..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemContentProviderFactory.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import java.util.ListIterator; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmResourceModel; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.OrmPersistentTypeItemContentProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class OrmItemContentProviderFactory extends GeneralJpaMappingItemContentProviderFactory -{ - @Override - public TreeItemContentProvider buildItemContentProvider( - Object item, DelegatingContentAndLabelProvider contentProvider) { - DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentProvider; - if (item instanceof OrmResourceModel) { - return new ResourceModelItemContentProvider((OrmResourceModel) item, treeContentProvider); - } - if (item instanceof EntityMappings) { - return new EntityMappingsItemContentProvider((EntityMappings) item, treeContentProvider); - } - return super.buildItemContentProvider(item, treeContentProvider); - } - - @Override - protected TreeItemContentProvider buildPersistentTypeItemContentProvider(PersistentType persistentType, DelegatingTreeContentAndLabelProvider treeContentProvider) { - return new OrmPersistentTypeItemContentProvider((OrmPersistentType) persistentType, treeContentProvider); - } - - public static class EntityMappingsItemContentProvider extends AbstractTreeItemContentProvider<OrmPersistentType> - { - 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<OrmPersistentType> buildChildrenModel() { - return new ListAspectAdapter<EntityMappings, OrmPersistentType>( - EntityMappings.PERSISTENT_TYPES_LIST, (EntityMappings) model()) { - @Override - protected ListIterator<OrmPersistentType> listIterator_() { - return subject.ormPersistentTypes(); - } - }; - } - } -} 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 deleted file mode 100644 index 531f515718..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmItemLabelProviderFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.ui.internal.platform.generic.EntityMappingsItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; - -public class OrmItemLabelProviderFactory extends GeneralJpaMappingItemLabelProviderFactory -{ - public ItemLabelProvider buildItemLabelProvider( - Object item, DelegatingContentAndLabelProvider labelProvider) { - if (item instanceof EntityMappings) { - return new EntityMappingsItemLabelProvider((EntityMappings) item, labelProvider); - } - else return super.buildItemLabelProvider(item, labelProvider); - } -} 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 deleted file mode 100644 index 6b75a79846..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.resource.orm.OrmResourceModel; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; - -public class OrmResourceModelStructureProvider - extends ResourceModelStructureProvider -{ - public OrmResourceModelStructureProvider(OrmResourceModel resourceModel) { - super(resourceModel); - } - - public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { - return new OrmItemContentProviderFactory(); - } - - public ItemLabelProviderFactory getItemLabelProviderFactory() { - 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 deleted file mode 100644 index abc311897a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemContentProviderFactory.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.PersistenceResourceModel; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -public class PersistenceItemContentProviderFactory - implements TreeItemContentProviderFactory -{ - public TreeItemContentProvider buildItemContentProvider( - Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - DelegatingTreeContentAndLabelProvider treeContentProvider = (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider; - if (item instanceof PersistenceResourceModel) { - return new ResourceModelItemContentProvider((PersistenceResourceModel) item, treeContentProvider); - } - else if (item instanceof Persistence) { - return new PersistenceItemContentProvider((Persistence) item, treeContentProvider); - } - else if (item instanceof PersistenceUnit) { - return new PersistenceUnitItemContentProvider((PersistenceUnit) item, treeContentProvider); - } - else if (item instanceof MappingFileRef) { - return new MappingFileRefItemContentProvider((MappingFileRef) item, treeContentProvider); - } - else if (item instanceof ClassRef) { - return new ClassRefItemContentProvider((ClassRef) item, treeContentProvider); - } - return null; - } - - - public static class PersistenceItemContentProvider extends AbstractTreeItemContentProvider<PersistenceUnit> - { - public PersistenceItemContentProvider( - Persistence persistence, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistence, contentProvider); - } - - @Override - public Persistence model() { - return (Persistence) super.model(); - } - - @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<PersistenceUnit> buildChildrenModel() { - return new ListAspectAdapter<Persistence, PersistenceUnit>( - Persistence.PERSISTENCE_UNITS_LIST, model()) { - @Override - protected ListIterator<PersistenceUnit> listIterator_() { - return subject.persistenceUnits(); - } - @Override - protected int size_() { - return subject.persistenceUnitsSize(); - } - }; - } - } - - - public static class PersistenceUnitItemContentProvider extends AbstractTreeItemContentProvider<JpaStructureNode> - { - public PersistenceUnitItemContentProvider( - PersistenceUnit persistenceUnit, DelegatingTreeContentAndLabelProvider contentProvider) { - super(persistenceUnit, contentProvider); - } - - @Override - public PersistenceUnit model() { - return (PersistenceUnit) super.model(); - } - - @Override - public Persistence getParent() { - return model().getParent(); - } - - @Override - protected ListValueModel<JpaStructureNode> buildChildrenModel() { - ListValueModel<MappingFileRef> specifiedMappingFileLvm = - new ListAspectAdapter<PersistenceUnit, MappingFileRef>( - PersistenceUnit.SPECIFIED_MAPPING_FILE_REF_LIST, - model()) { - @Override - protected ListIterator<MappingFileRef> listIterator_() { - return subject.specifiedMappingFileRefs(); - } - @Override - protected int size_() { - return subject.specifiedMappingFileRefsSize(); - } - }; - - ListValueModel<MappingFileRef> impliedMappingFileLvm = - new PropertyListValueModelAdapter<MappingFileRef>( - new PropertyAspectAdapter<PersistenceUnit, MappingFileRef>( - PersistenceUnit.IMPLIED_MAPPING_FILE_REF_PROPERTY, - model()) { - @Override - protected MappingFileRef buildValue_() { - return subject.getImpliedMappingFileRef(); - } - } - ); - ListValueModel<ClassRef> specifiedClassLvm = - new ListAspectAdapter<PersistenceUnit, ClassRef>( - PersistenceUnit.SPECIFIED_CLASS_REF_LIST, - model()) { - @Override - protected ListIterator<ClassRef> listIterator_() { - return subject.specifiedClassRefs(); - } - @Override - protected int size_() { - return subject.specifiedClassRefsSize(); - } - }; - ListValueModel<ClassRef> impliedClassLvm = - new ListAspectAdapter<PersistenceUnit, ClassRef>( - PersistenceUnit.IMPLIED_CLASS_REF_LIST, - model()) { - @Override - protected ListIterator<ClassRef> listIterator_() { - return subject.impliedClassRefs(); - } - @Override - protected int size_() { - return subject.impliedClassRefsSize(); - } - }; - List<ListValueModel<? extends JpaStructureNode>> list = new ArrayList<ListValueModel<? extends JpaStructureNode>>(4); - list.add(specifiedMappingFileLvm); - list.add(impliedMappingFileLvm); - list.add(specifiedClassLvm); - list.add(impliedClassLvm); - - return new CompositeListValueModel<ListValueModel<? extends JpaStructureNode>, JpaStructureNode>(list); - } - } - - - public static class MappingFileRefItemContentProvider extends AbstractTreeItemContentProvider<MappingFileRef> - { - public MappingFileRefItemContentProvider( - MappingFileRef mappingFileRef, DelegatingTreeContentAndLabelProvider contentProvider) { - super(mappingFileRef, contentProvider); - } - - @Override - public Object getParent() { - return ((MappingFileRef) model()).getPersistenceUnit(); - } - - @Override - public boolean hasChildren() { - return false; - } - } - - - public static class ClassRefItemContentProvider extends AbstractTreeItemContentProvider<ClassRef> - { - public ClassRefItemContentProvider( - ClassRef classRef, DelegatingTreeContentAndLabelProvider contentProvider) { - super(classRef, contentProvider); - } - - @Override - public Object getParent() { - return ((ClassRef) model()).getPersistenceUnit(); - } - - @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 deleted file mode 100644 index 08196cfa6c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceItemLabelProviderFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.internal.platform.generic.ClassRefItemLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.MappingFileRefItemLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.PersistenceItemLabelProvider; -import org.eclipse.jpt.ui.internal.platform.generic.PersistenceUnitItemLabelProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; - -public class PersistenceItemLabelProviderFactory - implements ItemLabelProviderFactory -{ - public ItemLabelProvider buildItemLabelProvider( - Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - if (item instanceof Persistence) { - return new PersistenceItemLabelProvider((Persistence) item, contentAndLabelProvider); - } - else if (item instanceof PersistenceUnit) { - return new PersistenceUnitItemLabelProvider((PersistenceUnit) item, contentAndLabelProvider); - } - else if (item instanceof MappingFileRef) { - return new MappingFileRefItemLabelProvider((MappingFileRef) item, contentAndLabelProvider); - } - else if (item instanceof ClassRef) { - return new ClassRefItemLabelProvider((ClassRef) item, contentAndLabelProvider); - } - return null; - } -} 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 deleted file mode 100644 index 4c90e0f787..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.resource.persistence.PersistenceResourceModel; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; - -public class PersistenceResourceModelStructureProvider - extends ResourceModelStructureProvider -{ - public PersistenceResourceModelStructureProvider(PersistenceResourceModel resourceModel) { - super(resourceModel); - } - - public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { - return new PersistenceItemContentProviderFactory(); - } - - public ItemLabelProviderFactory getItemLabelProviderFactory() { - return new PersistenceItemLabelProviderFactory(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelItemContentProvider.java deleted file mode 100644 index 84b499803d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelItemContentProvider.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import java.util.Iterator; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -public class ResourceModelItemContentProvider extends AbstractTreeItemContentProvider<JpaStructureNode> -{ - public ResourceModelItemContentProvider( - ResourceModel resourceModel, - DelegatingTreeContentAndLabelProvider contentProvider) { - super(resourceModel, contentProvider); - } - - @Override - public Object getParent() { - return null; - } - - @Override - public ResourceModel model() { - return (ResourceModel) super.model(); - } - - @Override - protected ListValueModel<JpaStructureNode> buildChildrenModel() { - return new CollectionListValueModelAdapter<JpaStructureNode>(buildChildrenCollectionModel()); - } - - protected CollectionValueModel<JpaStructureNode> buildChildrenCollectionModel() { - return new CollectionAspectAdapter<JpaFile, JpaStructureNode>( - buildJpaFileValueModel(), JpaFile.ROOT_STRUCTURE_NODES_COLLECTION) { - @Override - protected Iterator<JpaStructureNode> iterator_() { - return subject.rootStructureNodes(); - } - }; - } - - protected PropertyValueModel<JpaFile> buildJpaFileValueModel() { - return new TransformationPropertyValueModel<ResourceModel, JpaFile>( - new SimplePropertyValueModel<ResourceModel>(model())) { - @Override - protected JpaFile transform_(ResourceModel value) { - return JptCorePlugin.getJpaFile(value.getFile()); - } - }; - } -}
\ No newline at end of file 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 deleted file mode 100644 index 41c2e536b4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java +++ /dev/null @@ -1,33 +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.structure; - -import org.eclipse.jpt.core.ResourceModel; -import org.eclipse.jpt.ui.structure.JpaStructureProvider; - -public abstract class ResourceModelStructureProvider - implements JpaStructureProvider -{ - protected ResourceModel resourceModel; - - - public ResourceModelStructureProvider(ResourceModel 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/AbstractComboModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/AbstractComboModelAdapter.java deleted file mode 100644 index ced984fa99..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/AbstractComboModelAdapter.java +++ /dev/null @@ -1,675 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import java.util.EventObject; -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -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.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -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.events.SelectionListener; - -/** - * This adapter provides a more object-oriented interface to the items and - * selected item in a combo. - * <p> - * <b>listHolder</b> contains the items in the combo.<br> - * <b>selectedItemHolder</b> contains the items in 'listHolder' that are - * selected in the combo. - * - * @param <E> The type of the items in <b>listHolder</b> - * @see ComboModelAdapter - * @see CComboModelAdapter - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class AbstractComboModelAdapter<E> { - - // ********** model ********** - /** - * A value model on the underlying model list. - */ - protected final ListValueModel<E> listHolder; - - /** - * A listener that allows us to synchronize the combo's contents with - * the model list. - */ - protected final ListChangeListener listChangeListener; - - /** - * A value model on the underlying model selection. - */ - protected final WritablePropertyValueModel<E> selectedItemHolder; - - /** - * A listener that allows us to synchronize the combo's selection with the - * model selection. - */ - protected final PropertyChangeListener selectedItemChangeListener; - - /** - * A converter that converts items in the model list - * to strings that can be put in the combo. - */ - protected StringConverter<E> stringConverter; - - // ********** UI ********** - /** - * The combo we keep synchronized with the model list. - */ - protected final ComboHolder comboHolder; - - /** - * A listener that allows us to synchronize our selection list holder - * with the combo's text. - */ - protected ModifyListener comboModifyListener; - - /** - * A listener that allows us to synchronize our selection list holder - * with the combo's selection. - */ - protected SelectionListener comboSelectionListener; - - /** - * 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 combo - * is disposed. - */ - protected final DisposeListener comboDisposeListener; - - - // ********** constructors ********** - - /** - * Constructor - the list holder, selections holder, combo, and - * string converter are required. - */ - protected AbstractComboModelAdapter( - ListValueModel<E> listHolder, - WritablePropertyValueModel<E> selectedItemHolder, - ComboHolder comboHolder, - StringConverter<E> stringConverter) - { - super(); - - Assert.isNotNull(listHolder, "The holder of the items"); - Assert.isNotNull(selectedItemHolder, "The holder of the selected item cannot be null"); - Assert.isNotNull(comboHolder, "The holder of the combo widget cannot be null"); - Assert.isNotNull(stringConverter, "The string converter cannot be null"); - - this.listHolder = listHolder; - this.selectedItemHolder = selectedItemHolder; - this.comboHolder = comboHolder; - this.stringConverter = stringConverter; - - this.listChangeListener = this.buildListChangeListener(); - this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); - - this.selectedItemChangeListener = this.buildSelectedItemChangeListener(); - this.selectedItemHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.selectedItemChangeListener); - - if (this.comboHolder.isEditable()) { - this.comboModifyListener = this.buildComboModifyListener(); - this.comboHolder.addModifyListener(this.comboModifyListener); - } - else { - this.comboSelectionListener = this.buildComboSelectionListener(); - this.comboHolder.addSelectionListener(this.comboSelectionListener); - } - - this.selectionChangeListeners = this.buildSelectionChangeListeners(); - this.doubleClickListeners = this.buildDoubleClickListeners(); - - this.comboDisposeListener = this.buildComboDisposeListener(); - this.comboHolder.addDisposeListener(this.comboDisposeListener); - - this.synchronizeCombo(); - } - - - // ********** initialization ********** - - protected ListChangeListener buildListChangeListener() { - return new SWTListChangeListenerWrapper(this.buildListChangeListener_()); - } - - protected ListChangeListener buildListChangeListener_() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent event) { - AbstractComboModelAdapter.this.listItemsAdded(event); - } - public void itemsRemoved(ListChangeEvent event) { - AbstractComboModelAdapter.this.listItemsRemoved(event); - } - public void itemsMoved(ListChangeEvent event) { - AbstractComboModelAdapter.this.listItemsMoved(event); - } - public void itemsReplaced(ListChangeEvent event) { - AbstractComboModelAdapter.this.listItemsReplaced(event); - } - public void listCleared(ListChangeEvent event) { - AbstractComboModelAdapter.this.listCleared(event); - } - public void listChanged(ListChangeEvent event) { - AbstractComboModelAdapter.this.listChanged(event); - } - @Override - public String toString() { - return "list listener"; - } - }; - } - - protected PropertyChangeListener buildSelectedItemChangeListener() { - return new SWTPropertyChangeListenerWrapper(this.buildSelectedItemChangeListener_()); - } - - protected PropertyChangeListener buildSelectedItemChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - AbstractComboModelAdapter.this.selectedItemChanged(e); - } - }; - } - - protected ModifyListener buildComboModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent event) { - AbstractComboModelAdapter.this.comboSelectionChanged(event); - } - - @Override - public String toString() { - return "combo modify listener"; - } - }; - } - - protected SelectionListener buildComboSelectionListener() { - return new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - AbstractComboModelAdapter.this.comboSelectionChanged(event); - } - - @Override - public String toString() { - return "combo modify listener"; - } - }; - } - - @SuppressWarnings("unchecked") - protected DoubleClickListener<E>[] buildDoubleClickListeners() { - return new DoubleClickListener[0]; - } - - @SuppressWarnings("unchecked") - protected SelectionChangeListener<E>[] buildSelectionChangeListeners() { - return new SelectionChangeListener[0]; - } - - protected DisposeListener buildComboDisposeListener() { - return new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - AbstractComboModelAdapter.this.comboDisposed(event); - } - - @Override - public String toString() { - return "combo dispose listener"; - } - }; - } - - protected void synchronizeCombo() { - this.synchronizeComboItems(); - this.synchronizeComboSelection(); - } - - - // ********** string converter ********** - - public void setStringConverter(StringConverter<E> stringConverter) { - Assert.isNotNull(stringConverter, "The StringConverter cannot be null"); - this.stringConverter = stringConverter; - this.synchronizeCombo(); - } - - - // ********** list ********** - - /** - * Use the string converter to convert the specified item to a - * string that can be added to the combo. - */ - protected String convert(E item) { - return this.stringConverter.convertToString(item); - } - - /** - * Brute force synchronization of combo with the model list. - */ - protected void synchronizeComboItems() { - if (this.comboHolder.isDisposed()) { - return; - } - int len = this.listHolder.size(); - String[] items = new String[len]; - for (int index = 0; index < len; index++) { - items[index] = this.convert(this.listHolder.get(index)); - } - try { - this.comboHolder.setPopulating(true); - this.comboHolder.setItems(items); - } - finally { - this.comboHolder.setPopulating(false); - } - } - - /** - * The model has changed - synchronize the combo. - */ - protected void listItemsAdded(ListChangeEvent event) { - if (this.comboHolder.isDisposed()) { - return; - } - - int count = this.comboHolder.getItemCount(); - int index = event.getIndex(); - - for (ListIterator<E> stream = this.items(event); stream.hasNext(); ) { - this.comboHolder.add(this.convert(stream.next()), index++); - } - - // When the combo is populated, it's possible the selection was already - // set but no items was found, resync the selected item - if (count == 0) { - synchronizeComboSelection(); - } - } - - /** - * The model has changed - synchronize the combo. - */ - protected void listItemsRemoved(ListChangeEvent event) { - if (this.comboHolder.isDisposed()) { - return; - } - this.comboHolder.remove(event.getIndex(), event.getIndex() + event.itemsSize() - 1); - this.synchronizeComboSelection(); - } - - /** - * The model has changed - synchronize the combo. - */ - protected void listItemsMoved(ListChangeEvent event) { - if (this.comboHolder.isDisposed()) { - return; - } - int target = event.getTargetIndex(); - int source = event.getSourceIndex(); - int len = event.getMoveLength(); - int loStart = Math.min(target, source); - int hiStart = Math.max(target, source); - // make a copy of the affected items... - String[] subArray = CollectionTools.subArray(this.comboHolder.getItems(), loStart, hiStart + len - loStart); - // ...move them around... - subArray = CollectionTools.move(subArray, target - loStart, source - loStart, len); - // ...and then put them back - for (int index = 0; index < subArray.length; index++) { - this.comboHolder.setItem(loStart + index, subArray[index]); - } - } - - /** - * The model has changed - synchronize the combo. - */ - protected void listItemsReplaced(ListChangeEvent event) { - if (this.comboHolder.isDisposed()) { - return; - } - int index = event.getIndex(); - for (ListIterator<E> stream = this.items(event); stream.hasNext(); ) { - this.comboHolder.setItem(index++, this.convert(stream.next())); - } - } - - /** - * The model has changed - synchronize the combo. - */ - protected void listCleared(ListChangeEvent event) { - if (this.comboHolder.isDisposed()) { - return; - } - this.comboHolder.removeAll(); - } - - /** - * The model has changed - synchronize the combo. - */ - protected void listChanged(ListChangeEvent event) { - this.synchronizeComboItems(); - } - - // minimized unchecked code - @SuppressWarnings("unchecked") - protected ListIterator<E> items(ListChangeEvent event) { - return ((ListIterator<E>) event.items()); - } - - - // ********** selected items ********** - - protected int indexOf(E item) { - int length = this.listHolder.size(); - for (int index = 0; index < length; index++) { - if (valuesAreEqual(this.listHolder.get(index), item)) { - return index; - } - } - return -1; - } - - protected void synchronizeComboSelection() { - if (this.comboHolder.isDisposed() || this.comboHolder.isPopulating()) { - return; - } - - E selectedValue = this.selectedItemHolder.getValue(); - this.comboHolder.setPopulating(true); - - try { - this.comboHolder.deselectAll(); - String selectedItem = this.convert(selectedValue); - if (selectedItem == null) { - selectedItem = ""; - } - this.comboHolder.setText(selectedItem); - this.notifyListeners(selectedValue); - } - finally { - this.comboHolder.setPopulating(false); - } - } - - protected void selectedItemChanged(PropertyChangeEvent event) { - this.synchronizeComboSelection(); - } - - // minimized unchecked code - @SuppressWarnings("unchecked") - protected Iterator<E> items(CollectionChangeEvent event) { - return ((Iterator<E>) event.items()); - } - - - /** - * Return whether the values are equal, with the appropriate null checks. - * Convenience method for checking whether an attribute value has changed. - */ - protected final boolean valuesAreEqual(Object value1, Object value2) { - if ((value1 == null) && (value2 == null)) { - return true; // both are null - } - if ((value1 == null) || (value2 == null)) { - return false; // one is null but the other is not - } - return value1.equals(value2); - } - - // ********** combo events ********** - - protected void comboSelectionChanged(SelectionEvent event) { - this.selectionChanged(); - } - - protected void comboSelectionChanged(ModifyEvent event) { - this.selectionChanged(); - } - - protected void selectionChanged() { - if (!this.comboHolder.isPopulating()) { - E selectedItem = this.selectedItem(); - this.comboHolder.setPopulating(true); - try { - this.selectedItemHolder.setValue(selectedItem); - this.notifyListeners(selectedItem); - } - finally { - this.comboHolder.setPopulating(false); - } - } - } - - private void notifyListeners(E selectedItem) { - if (this.selectionChangeListeners.length > 0) { - SelectionChangeEvent<E> scEvent = new SelectionChangeEvent<E>(this, selectedItem); - for (SelectionChangeListener<E> selectionChangeListener : this.selectionChangeListeners) { - selectionChangeListener.selectionChanged(scEvent); - } - } - } - - @SuppressWarnings("unchecked") - protected E selectedItem() { - if (this.comboHolder.isDisposed()) { - return null; - } - - if (this.comboHolder.isEditable()) { - String text = this.comboHolder.getText(); - - if (text.length() == 0) { - return null; - } - - for (int index = this.listHolder.size(); --index >= 0; ) { - E item = this.listHolder.get(index); - String value = this.convert(item); - if (valuesAreEqual(text, value)) { - return item; - } - } - - // TODO: Find a way to prevent this type cast (it'll work if E is - // String but it won't work if E is something else), maybe use a - // BidiStringConverter instead of StringConverter - try { - return (E) text; - } - catch (ClassCastException e) { - return null; - } - } - - int index = this.comboHolder.getSelectionIndex(); - - if (index == -1) { - return null; - } - - return this.listHolder.get(index); - } - - protected void comboDoubleClicked(SelectionEvent event) { - if (this.comboHolder.isDisposed()) { - return; - } - if (this.doubleClickListeners.length > 0) { - // there should be only a single item selected during a double-click(?) - E selection = this.listHolder.get(this.comboHolder.getSelectionIndex()); - DoubleClickEvent<E> dcEvent = new DoubleClickEvent<E>(this, selection); - for (DoubleClickListener<E> doubleClickListener : this.doubleClickListeners) { - doubleClickListener.doubleClick(dcEvent); - } - } - } - - - // ********** dispose ********** - - protected void comboDisposed(DisposeEvent event) { - // the combo is not yet "disposed" when we receive this event - // so we can still remove our listeners - this.comboHolder.removeDisposeListener(this.comboDisposeListener); - if (this.comboHolder.isEditable()) { - this.comboHolder.removeModifyListener(this.comboModifyListener); - } - else { - this.comboHolder.removeSelectionListener(this.comboSelectionListener); - } - this.selectedItemHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.selectedItemChangeListener); - 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(AbstractComboModelAdapter<E> source, E selection) { - super(source); - if (selection == null) { - throw new NullPointerException(); - } - this.selection = selection; - } - - @Override - @SuppressWarnings("unchecked") - public AbstractComboModelAdapter<E> getSource() { - return (AbstractComboModelAdapter<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 E selectedItem; - private static final long serialVersionUID = 1L; - - protected SelectionChangeEvent(AbstractComboModelAdapter<E> source, E selectedItem) { - super(source); - this.selectedItem = selectedItem; - } - - @Override - @SuppressWarnings("unchecked") - public AbstractComboModelAdapter<E> getSource() { - return (AbstractComboModelAdapter<E>) super.getSource(); - } - - public E selectedItem() { - return this.selectedItem; - } - } - - // ********** Internal member ********** - - /** - * This holder is required for supporting <code>Combo</code> and - * <code>CCombo</code> transparently. - */ - protected static interface ComboHolder { - void add(String item, int index); - void addDisposeListener(DisposeListener disposeListener); - void addModifyListener(ModifyListener modifyListener); - void addSelectionListener(SelectionListener selectionListener); - void deselectAll(); - int getItemCount(); - String[] getItems(); - int getSelectionIndex(); - String getText(); - boolean isDisposed(); - boolean isEditable(); - boolean isPopulating(); - void removeDisposeListener(DisposeListener disposeListener); - void removeModifyListener(ModifyListener modifyListener); - void removeSelectionListener(SelectionListener selectionListener); - void setItem(int index, String item); - void setItems(String[] items); - void setPopulating(boolean populating); - void setText(String item); - void remove(int start, int end); - void removeAll(); - } -} 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 deleted file mode 100644 index dbd0ffc707..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/BooleanButtonModelAdapter.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.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; -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. - */ -@SuppressWarnings("nls") -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.getValue()); - } - - - // ********** 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 SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - BooleanButtonModelAdapter.this.buttonSelected(event); - } - @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.getNewValue()); - } - - protected void setButtonSelection(Boolean b) { - if (this.button.isDisposed()) { - return; - } - 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) { - if (this.button.isDisposed()) { - return; - } - this.booleanHolder.setValue(Boolean.valueOf(this.button.getSelection())); - } - - - // ********** dispose ********** - - protected void buttonDisposed(DisposeEvent event) { - // the button is not yet "disposed" when we receive this event - // so we can still remove our listeners - 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/CComboModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/CComboModelAdapter.java deleted file mode 100644 index 65a8d12e2f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/CComboModelAdapter.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jpt.utility.internal.StringConverter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionListener; - -/** - * This adapter provides a more object-oriented interface to the items and - * selected item in a <code>CCombo</code>. - * <p> - * <b>listHolder</b> contains the items in the <code>CCombo</code>.<br> - * <b>selectedItemHolder</b> contains the items in 'listHolder' that are - * selected in the <code>CCombo</code>. - * - * @param <E> The type of the items in <b>listHolder</b> - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class CComboModelAdapter<E> extends AbstractComboModelAdapter<E> { - - // ********** static methods ********** - - /** - * Constructor - the list holder, selections holder, combo, and - * string converter are required. - */ - protected CComboModelAdapter( - ListValueModel<E> listHolder, - WritablePropertyValueModel<E> selectedItemHolder, - CCombo combo, - StringConverter<E> stringConverter) - { - super(listHolder, - selectedItemHolder, - new CComboHolder(combo), - stringConverter); - } - - /** - * Adapt the specified model list and selection to the specified combo. - * Use the default string converter to convert the model items to strings - * to be displayed in the combo, which calls #toString() on the - * items in the model list. - */ - public static <T> CComboModelAdapter<T> adapt( - ListValueModel<T> listHolder, - WritablePropertyValueModel<T> selectedItemHolder, - CCombo combo) - { - return adapt( - listHolder, - selectedItemHolder, - combo, - StringConverter.Default.<T>instance() - ); - } - - - // ********** constructors ********** - - /** - * Adapt the specified model list and selection to the specified combo. - * Use the specified string converter to convert the model items to strings - * to be displayed in the combo. - */ - public static <T> CComboModelAdapter<T> adapt( - ListValueModel<T> listHolder, - WritablePropertyValueModel<T> selectedItemHolder, - CCombo combo, - StringConverter<T> stringConverter) - { - return new CComboModelAdapter<T>( - listHolder, - selectedItemHolder, - combo, - stringConverter - ); - } - - - // ********** Internal member ********** - - private static class CComboHolder implements ComboHolder { - private final CCombo combo; - private final boolean editable; - private String selectedItem; - - CComboHolder(CCombo combo) { - super(); - this.combo = combo; - this.editable = combo.getEditable(); - } - - public void add(String item, int index) { - this.combo.add(item, index); - - // It is possible the selected item was set before the combo is being - // populated, update the selected item if it's matches the item being - // added - if ((this.selectedItem != null) && this.selectedItem.equals(item)) { - this.setText(this.selectedItem); - this.selectedItem = null; - } - } - - public void addDisposeListener(DisposeListener disposeListener) { - this.combo.addDisposeListener(disposeListener); - } - - public void addModifyListener(ModifyListener modifyListener) { - this.combo.addModifyListener(modifyListener); - } - - public void addSelectionListener(SelectionListener selectionListener) { - this.combo.addSelectionListener(selectionListener); - } - - public void deselectAll() { - this.combo.deselectAll(); - } - - public int getItemCount() { - return this.combo.getItemCount(); - } - - public String[] getItems() { - return this.combo.getItems(); - } - - public int getSelectionIndex() { - return this.combo.getSelectionIndex(); - } - - public String getText() { - return this.combo.getText(); - } - - public boolean isDisposed() { - return this.combo.isDisposed(); - } - - public boolean isEditable() { - return editable; - } - - public boolean isPopulating() { - return this.combo.getData("populating") == Boolean.TRUE; - } - - public void remove(int start, int end) { - this.combo.remove(start, end); - } - - public void removeAll() { - this.combo.removeAll(); - } - - public void removeDisposeListener(DisposeListener disposeListener) { - this.combo.removeDisposeListener(disposeListener); - } - - public void removeModifyListener(ModifyListener modifyListener) { - this.combo.removeModifyListener(modifyListener); - } - - public void removeSelectionListener(SelectionListener selectionListener) { - this.combo.removeSelectionListener(selectionListener); - } - - public void setItem(int index, String item) { - this.combo.setItem(index, item); - } - - public void setItems(String[] items) { - this.combo.setItems(items); - } - - public void setPopulating(boolean populating) { - this.combo.setData("populating", Boolean.valueOf(populating)); - } - - public void setText(String item) { - - // Keep track of the selected item since it's possible the selected - // item is before the combo is populated - if (this.combo.getItemCount() == 0) { - this.selectedItem = item; - } - else { - this.selectedItem = null; - } - - this.combo.setText(item); - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ColumnAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ColumnAdapter.java deleted file mode 100644 index d221ee3f23..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ColumnAdapter.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * This adapter is used by the table model adapter to convert a model object - * into the models used for each of the cells for the object's corresponding row - * in the table. - * - * @version 2.0 - * @since 2.0 - */ -public interface ColumnAdapter<V> { - - /** - * Return the cell models for the specified subject - * that corresponds to a single row in the table. - */ - WritablePropertyValueModel<?>[] cellModels(V subject); - - /** - * Returns the number of columns in the table. Typically this is static. - * - * @return The number of columns - */ - int columnCount(); - - /** - * Returns the name of the column at the specified index. - * - * @param columnIndex The index of the column to retrieve its display text - * @return The display text of the column - */ - String columnName(int columnIndex); - - /** - * Returns whether the specified column is editable. Typically this is the - * same for every row. - * - * @param columnIndex The index of the column for which we determine if - * the content can be modified - * @return <code>true</code> to allow editing of the cell at the given - * column index; <code>false</code> to keep it not editable - */ -// boolean columnIsEditable(int columnIndex); -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java deleted file mode 100644 index 964788b118..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ComboModelAdapter.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jpt.utility.internal.StringConverter; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Combo; - -/** - * This adapter provides a more object-oriented interface to the items and - * selected item in a <code>Combo</code>. - * <p> - * <b>listHolder</b> contains the items in the <code>Combo</code>.<br> - * <b>selectedItemHolder</b> contains the items in 'listHolder' that are - * selected in the <code>Combo</code>. - * - * @param <E> The type of the items in <b>listHolder</b> - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class ComboModelAdapter<E> extends AbstractComboModelAdapter<E> { - - // ********** static methods ********** - - /** - * Adapt the specified model list and selection to the specified combo. - * Use the default string converter to convert the model items to strings - * to be displayed in the combo, which calls #toString() on the - * items in the model list. - */ - public static <T> ComboModelAdapter<T> adapt( - ListValueModel<T> listHolder, - WritablePropertyValueModel<T> selectedItemHolder, - Combo combo) - { - return adapt( - listHolder, - selectedItemHolder, - combo, - StringConverter.Default.<T>instance() - ); - } - - /** - * Adapt the specified model list and selection to the specified combo. - * Use the specified string converter to convert the model items to strings - * to be displayed in the combo. - */ - public static <T> ComboModelAdapter<T> adapt( - ListValueModel<T> listHolder, - WritablePropertyValueModel<T> selectedItemHolder, - Combo combo, - StringConverter<T> stringConverter) - { - return new ComboModelAdapter<T>( - listHolder, - selectedItemHolder, - combo, - stringConverter - ); - } - - - // ********** constructors ********** - - /** - * Constructor - the list holder, selections holder, combo, and - * string converter are required. - */ - protected ComboModelAdapter( - ListValueModel<E> listHolder, - WritablePropertyValueModel<E> selectedItemHolder, - Combo combo, - StringConverter<E> stringConverter) - { - super(listHolder, - selectedItemHolder, - new SWTComboHolder(combo), - stringConverter); - } - - - // ********** Internal member ********** - - private static class SWTComboHolder implements ComboHolder { - private final Combo combo; - private final boolean editable; - private String selectedItem; - - SWTComboHolder(Combo combo) { - super(); - this.combo = combo; - this.editable = (combo.getStyle() & SWT.READ_ONLY) == 0; - } - - public void add(String item, int index) { - this.combo.add(item, index); - - // It is possible the selected item was set before the combo is being - // populated, update the selected item if it's matches the item being - // added - if ((this.selectedItem != null) && this.selectedItem.equals(item)) { - this.setText(this.selectedItem); - this.selectedItem = null; - } - } - - public void addDisposeListener(DisposeListener disposeListener) { - this.combo.addDisposeListener(disposeListener); - } - - public void addModifyListener(ModifyListener modifyListener) { - this.combo.addModifyListener(modifyListener); - } - - public void addSelectionListener(SelectionListener selectionListener) { - this.combo.addSelectionListener(selectionListener); - } - - public void deselectAll() { - this.combo.deselectAll(); - } - - public int getItemCount() { - return this.combo.getItemCount(); - } - - public String[] getItems() { - return this.combo.getItems(); - } - - public int getSelectionIndex() { - return this.combo.getSelectionIndex(); - } - - public String getText() { - return this.combo.getText(); - } - - public boolean isDisposed() { - return this.combo.isDisposed(); - } - - public boolean isEditable() { - return this.editable; - } - - public boolean isPopulating() { - return this.combo.getData("populating") == Boolean.TRUE; - } - - public void remove(int start, int end) { - this.combo.remove(start, end); - } - - public void removeAll() { - this.combo.removeAll(); - } - - public void removeDisposeListener(DisposeListener disposeListener) { - this.combo.removeDisposeListener(disposeListener); - } - - public void removeModifyListener(ModifyListener modifyListener) { - this.combo.removeModifyListener(modifyListener); - } - - public void removeSelectionListener(SelectionListener selectionListener) { - this.combo.removeSelectionListener(selectionListener); - } - - public void setItem(int index, String item) { - this.combo.setItem(index, item); - } - - public void setItems(String[] items) { - this.combo.setItems(items); - } - - public void setPopulating(boolean populating) { - this.combo.setData("populating", Boolean.valueOf(populating)); - } - - public void setText(String item) { - - // Keep track of the selected item since it's possible the selected - // item is before the combo is populated - if (this.combo.getItemCount() == 0) { - this.selectedItem = item; - } - else { - this.selectedItem = null; - } - - this.combo.select(this.combo.indexOf(item)); - this.combo.setText(item); - } - } -} 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 deleted file mode 100644 index 08f1a21839..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/ListBoxModelAdapter.java +++ /dev/null @@ -1,627 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -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.value.PropertyCollectionValueModelAdapter; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.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. - */ -@SuppressWarnings("nls") -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() { - if (this.listBox.isDisposed()) { - return; - } - 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) { - if (this.listBox.isDisposed()) { - return; - } - int i = event.getIndex(); - 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) { - if (this.listBox.isDisposed()) { - return; - } - this.listBox.remove(event.getIndex(), event.getIndex() + event.itemsSize() - 1); - } - - /** - * The model has changed - synchronize the list box. - */ - protected void listItemsMoved(ListChangeEvent event) { - if (this.listBox.isDisposed()) { - return; - } - int target = event.getTargetIndex(); - int source = event.getSourceIndex(); - int len = event.getMoveLength(); - 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) { - if (this.listBox.isDisposed()) { - return; - } - int i = event.getIndex(); - 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) { - if (this.listBox.isDisposed()) { - return; - } - 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() { - if (this.listBox.isDisposed()) { - return; - } - 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) { - if (this.listBox.isDisposed()) { - return; - } - 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) { - if (this.listBox.isDisposed()) { - return; - } - 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) { - if (this.listBox.isDisposed()) { - return; - } - 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() { - if (this.listBox.isDisposed()) { - return Collections.emptySet(); - } - @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.listBox.isDisposed()) { - return; - } - 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) { - // the list box is not yet "disposed" when we receive this event - // so we can still remove our listeners - 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/SpinnerModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/SpinnerModelAdapter.java deleted file mode 100644 index 9f997ed645..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/SpinnerModelAdapter.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Spinner; - -/** - * - */ -@SuppressWarnings("nls") -public class SpinnerModelAdapter { - - /** - * A value model on the underlying model list. - */ - protected final WritablePropertyValueModel<Integer> numberHolder; - - /** - * A listener that allows us to synchronize the spinner's contents with - * the model list. - */ - protected final PropertyChangeListener propertyChangeListener; - - /** - * The spinner we keep synchronized with the model string. - */ - protected final Spinner spinner; - - /** - * A listener that allows us to synchronize our selection number holder - * with the spinner's value. - */ - protected final ModifyListener spinnerModifyListener; - - /** - * A listener that allows us to stop listening to stuff when the spinner - * is disposed. - */ - protected final DisposeListener spinnerDisposeListener; - - /** - * The value shown when the number holder's value is <code>null</code>. - */ - protected final int defaultValue; - - /** - * This lock is used to prevent the listeners to be notified when the value - * changes from the spinner or from the holder. - */ - private boolean locked; - - // ********** static methods ********** - - /** - * Adapt the specified model list and selections to the specified spinner. - * Use the specified string converter to convert the model items to strings - * to be displayed in the spinner. - */ - public static SpinnerModelAdapter adapt( - WritablePropertyValueModel<Integer> numberHolder, - Spinner spinner, - int defaultValue) - { - return new SpinnerModelAdapter(numberHolder, spinner, defaultValue); - } - - - // ********** constructors ********** - - /** - * Constructor - the list holder, selections holder, list box, and - * string converter are required. - */ - protected SpinnerModelAdapter(WritablePropertyValueModel<Integer> numberHolder, - Spinner spinner, - int defaultValue) { - super(); - if ((numberHolder == null) || (spinner == null)) { - throw new NullPointerException(); - } - this.numberHolder = numberHolder; - this.spinner = spinner; - this.defaultValue = defaultValue; - - this.propertyChangeListener = this.buildPropertyChangeListener(); - this.numberHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.propertyChangeListener); - - this.spinnerModifyListener = this.buildSpinnerModifyListener(); - this.spinner.addModifyListener(this.spinnerModifyListener); - - this.spinnerDisposeListener = this.buildSpinnerDisposeListener(); - this.spinner.addDisposeListener(this.spinnerDisposeListener); - - this.updateSpinner(numberHolder.getValue()); - } - - - // ********** initialization ********** - - protected PropertyChangeListener buildPropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper(this.buildPropertyChangeListener_()); - } - - protected PropertyChangeListener buildPropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - SpinnerModelAdapter.this.valueChanged(event); - } - @Override - public String toString() { - return "spinner listener"; - } - }; - } - - protected ModifyListener buildSpinnerModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent e) { - SpinnerModelAdapter.this.spinnerModified(e); - } - @Override - public String toString() { - return "spinner selection listener"; - } - }; - } - - protected DisposeListener buildSpinnerDisposeListener() { - return new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - SpinnerModelAdapter.this.spinnerDisposed(event); - } - @Override - public String toString() { - return "spinner dispose listener"; - } - }; - } - - - // ********** model events ********** - - protected void valueChanged(PropertyChangeEvent event) { - if (!this.locked) { - this.updateSpinner((Integer) event.getNewValue()); - } - } - - - // ********** spinner events ********** - - protected void spinnerModified(ModifyEvent event) { - if (!this.locked) { - this.locked = true; - try { - this.numberHolder.setValue(this.spinner.getSelection()); - } - finally { - this.locked = false; - } - } - } - - protected void spinnerDisposed(DisposeEvent event) { - // the spinner is not yet "disposed" when we receive this event - // so we can still remove our listeners - this.spinner.removeDisposeListener(this.spinnerDisposeListener); - this.spinner.removeModifyListener(this.spinnerModifyListener); - this.numberHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.propertyChangeListener); - } - - // ********** update ********** - - protected void updateSpinner(Integer value) { - if (this.spinner.isDisposed()) { - return; - } - // the model can be null, but the spinner cannot - if (value == null) { - value = defaultValue; - } - this.locked = true; - try { - this.spinner.setSelection(value); - } - finally { - this.locked = false; - } - } - - // ********** standard methods ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.numberHolder); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TableItemModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TableItemModelAdapter.java deleted file mode 100644 index 12675863ce..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TableItemModelAdapter.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** - * This adapter can be used to keep a table item in synch with the properties of - * a model. - */ -@SuppressWarnings("nls") -public class TableItemModelAdapter { - - /** The table item we synchronize with the model. */ - protected final TableItem tableItem; - - /** - * A listener that allows us to stop listening to stuff when the button - * is disposed. - */ - protected final DisposeListener tableItemDisposeListener; - - /** - * Client-supplied adapter that provides with the various column settings and - * converts the objects in the LVM into an array of cell models. - */ - private ColumnAdapter<Object> columnAdapter; - - /** - * The value models used to listen to each property that are display by the - * table item. - */ - private WritablePropertyValueModel<?>[] valueHolders; - - /** - * The list of <code>PropertyChangeListener</code>s used to be notified when - * the properties of the model being display into a row change. - */ - private PropertyChangeListener[] propertyChangeListeners; - - /** - * The label used to format the objects into a string representation. - */ - private ITableLabelProvider labelProvider; - - // ********** static methods ********** - - /** - * Adapt the specified boolean to the specified button. - * If the boolean is null, the button's value will be "unselected". - */ - public static TableItemModelAdapter adapt(TableItem tableItem, ColumnAdapter<?> columnAdapter, ITableLabelProvider labelProvider) { - return new TableItemModelAdapter(tableItem, columnAdapter, labelProvider); - } - - - // ********** constructors ********** - - /** - * Constructor - the boolean holder and button are required. - */ - @SuppressWarnings("unchecked") - protected TableItemModelAdapter(TableItem tableItem, ColumnAdapter<?> columnAdapter, ITableLabelProvider labelProvider) { - super(); - if (tableItem == null || columnAdapter == null || labelProvider == null) { - throw new NullPointerException(); - } - this.tableItem = tableItem; - this.labelProvider = labelProvider; - this.columnAdapter = (ColumnAdapter<Object>) columnAdapter; - - this.tableItemDisposeListener = this.buildTableItemDisposeListener(); - this.tableItem.addDisposeListener(this.tableItemDisposeListener); - - this.valueHolders = this.columnAdapter.cellModels(tableItem.getData()); - this.propertyChangeListeners = this.buildPropertyChangeListeners(); - - for (int index = this.columnAdapter.columnCount(); --index >= 0; ) { - tableItemChanged(index, tableItem.getData(), false); - valueHolders[index].addPropertyChangeListener(PropertyValueModel.VALUE, propertyChangeListeners[index]); - } - } - - - // ********** initialization ********** - - private PropertyChangeListener[] buildPropertyChangeListeners() { - PropertyChangeListener[] listeners = new PropertyChangeListener[columnAdapter.columnCount()]; - for (int index = listeners.length; --index >= 0; ) { - listeners[index] = buildPropertyChangeListener(index); - } - return listeners; - } - - - protected PropertyChangeListener buildPropertyChangeListener(int index) { - return new SWTPropertyChangeListenerWrapper( - this.buildPropertyChangeListener_(index) - ); - } - - protected PropertyChangeListener buildPropertyChangeListener_(int index) { - return new TableItemPropertyChangeListener(index); - } - - protected DisposeListener buildTableItemDisposeListener() { - return new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - TableItemModelAdapter.this.tableItemDisposed(event); - } - @Override - public String toString() { - return "TableItem dispose listener"; - } - }; - } - - - // ********** behavior ********** - - protected void tableItemChanged(int index, Object subject, boolean revalidate) { - - if (!this.tableItem.isDisposed()) { - this.updateTableItemText(index, subject); - this.updateTableItemImage(index, subject); - - if (revalidate) { - this.layoutTable(); - } - } - } - - private void updateTableItemText(int index, Object subject) { - String text = this.labelProvider.getColumnText(subject, index); - if (text == null) { - text = ""; - } - this.tableItem.setText(index, text); - } - - private void updateTableItemImage(int index, Object subject) { - Image image = this.labelProvider.getColumnImage(subject, index); - this.tableItem.setImage(index, image); - } - - private void layoutTable() { - // Refresh the table in order to show the scrollbar if required - Point size = this.tableItem.getParent().getParent().computeSize(SWT.DEFAULT, SWT.DEFAULT); - this.tableItem.getParent().setSize(size); - } - - // ********** dispose ********** - - protected void tableItemDisposed(DisposeEvent event) { - // the button is not yet "disposed" when we receive this event - // so we can still remove our listeners - this.tableItem.removeDisposeListener(this.tableItemDisposeListener); - - for (int index = valueHolders.length; --index >= 0; ) { - valueHolders[index].removePropertyChangeListener(PropertyValueModel.VALUE, propertyChangeListeners[index]); - } - } - - - // ********** standard methods ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - private class TableItemPropertyChangeListener implements PropertyChangeListener { - - private final int index; - - TableItemPropertyChangeListener(int index) { - super(); - this.index = index; - } - - public void propertyChanged(PropertyChangeEvent event) { - if (!tableItem.isDisposed()) { - Table table = tableItem.getParent(); - tableItemChanged(index, tableItem.getData(), table.getColumnCount() == 0); - } - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TableModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TableModelAdapter.java deleted file mode 100644 index db29c8843c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TableModelAdapter.java +++ /dev/null @@ -1,693 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.EventObject; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.viewers.ITableLabelProvider; -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.StringTools; -import org.eclipse.jpt.utility.internal.model.value.PropertyCollectionValueModelAdapter; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.SWT; -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.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; - -/** - * This adapter provides a more object-oriented interface to the items and - * selected items in a table. - * 'listHolder' contains the data of a single column in the column. - * 'selectedItemsHolder' contains the data of a single column in 'listHolder' - * that are selected in the table. - */ -@SuppressWarnings("nls") -public class TableModelAdapter<E> { - - // ********** model ********** - /** - * A value model on the underlying model list. - */ - protected final ListValueModel<E> listHolder; - - /** - * A listener that allows us to synchronize the table'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 table's selection with - * the model selections. - */ - protected final CollectionChangeListener selectedItemsChangeListener; - - /** - * The table we keep synchronized with the model list. - */ - protected final Table table; - - /** - * A listener that allows us to synchronize our selection list holder - * with the table's selection. - */ - protected final SelectionListener tableSelectionListener; - - /** - * 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 table - * is disposed. - */ - protected final DisposeListener tableDisposeListener; - - /** - * This label provider is responsible to convert a property at a column index - * to a string value. - */ - protected final ITableLabelProvider labelProvider; - - /** - * The column adapter is responsible to return the count of columns and to - * create the value holders for all the properties. - */ - private ColumnAdapter<E> columnAdapter; - - /** - * Keeps track of the <code>TableItemModelAdapter</code>s that were created - * for each item of the list holder. - */ - private List<TableItemModelAdapter> tableItemModelAdapters; - - - // ********** static methods ********** - - /** - * Adapt the specified model list and selection to the specified table. - * Use the specified string converter to convert the model items to strings - * to be displayed in the table. - */ - public static <T> TableModelAdapter<T> adapt( - ListValueModel<T> listHolder, - PropertyValueModel<T> selectedItemHolder, - Table table, - ColumnAdapter<T> columnAdapter, - ITableLabelProvider labelProvider) - { - return new TableModelAdapter<T>( - listHolder, - new PropertyCollectionValueModelAdapter<T>(selectedItemHolder), - table, - columnAdapter, - labelProvider - ); - } - - - // ********** constructors ********** - - /** - * Constructor - the list holder, selections holder, table, and - * string converter are required. - */ - protected TableModelAdapter( - ListValueModel<E> listHolder, - CollectionValueModel<E> selectedItemsHolder, - Table table, - ColumnAdapter<E> columnAdapter, - ITableLabelProvider labelProvider) - { - super(); - if ((listHolder == null) || (selectedItemsHolder == null) || (table == null) || (labelProvider == null)) { - throw new NullPointerException(); - } - this.listHolder = listHolder; - this.selectedItemsHolder = selectedItemsHolder; - this.table = table; - this.columnAdapter = columnAdapter; - this.labelProvider = labelProvider; - this.tableItemModelAdapters = new ArrayList<TableItemModelAdapter>(columnAdapter.columnCount()); - - this.listChangeListener = this.buildListChangeListener(); - this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); - - this.selectedItemsChangeListener = this.buildSelectedItemsChangeListener(); - this.selectedItemsHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.selectedItemsChangeListener); - - this.tableSelectionListener = this.buildTableSelectionListener(); - this.table.addSelectionListener(this.tableSelectionListener); - - this.selectionChangeListeners = this.buildSelectionChangeListeners(); - this.doubleClickListeners = this.buildDoubleClickListeners(); - - this.tableDisposeListener = this.buildTableDisposeListener(); - this.table.addDisposeListener(this.tableDisposeListener); - - this.synchronizeTable(); - } - - - // ********** initialization ********** - - protected ListChangeListener buildListChangeListener() { - return new SWTListChangeListenerWrapper(this.buildListChangeListener_()); - } - - protected ListChangeListener buildListChangeListener_() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent event) { - TableModelAdapter.this.listItemsAdded(event); - } - public void itemsRemoved(ListChangeEvent event) { - TableModelAdapter.this.listItemsRemoved(event); - } - public void itemsMoved(ListChangeEvent event) { - TableModelAdapter.this.listItemsMoved(event); - } - public void itemsReplaced(ListChangeEvent event) { - TableModelAdapter.this.listItemsReplaced(event); - } - public void listCleared(ListChangeEvent event) { - TableModelAdapter.this.listCleared(event); - } - public void listChanged(ListChangeEvent event) { - TableModelAdapter.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) { - TableModelAdapter.this.selectedItemsAdded(event); - } - public void itemsRemoved(CollectionChangeEvent event) { - TableModelAdapter.this.selectedItemsRemoved(event); - } - public void collectionCleared(CollectionChangeEvent event) { - TableModelAdapter.this.selectedItemsCleared(event); - } - public void collectionChanged(CollectionChangeEvent event) { - TableModelAdapter.this.selectedItemsChanged(event); - } - @Override - public String toString() { - return "selected items listener"; - } - }; - } - - protected SelectionListener buildTableSelectionListener() { - return new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - TableModelAdapter.this.tableSelectionChanged(event); - } - public void widgetDefaultSelected(SelectionEvent event) { - TableModelAdapter.this.tableDoubleClicked(event); - } - @Override - public String toString() { - return "table selection listener"; - } - }; - } - - @SuppressWarnings("unchecked") - protected DoubleClickListener<E>[] buildDoubleClickListeners() { - return new DoubleClickListener[0]; - } - - @SuppressWarnings("unchecked") - protected SelectionChangeListener<E>[] buildSelectionChangeListeners() { - return new SelectionChangeListener[0]; - } - - protected DisposeListener buildTableDisposeListener() { - return new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - TableModelAdapter.this.tableDisposed(event); - } - @Override - public String toString() { - return "table dispose listener"; - } - }; - } - - protected void synchronizeTable() { - this.synchronizeTableColumns(); - this.synchronizeTableItems(); - this.synchronizeTableSelection(); - } - - - // ********** list ********** - - /** - * Creates the table colums. - */ - protected void synchronizeTableColumns() { - if (this.table.isDisposed()) { - return; - } - - int columnCount = this.columnAdapter.columnCount(); - - for (int index = 0; index < columnCount; index++) { - TableColumn tableColumn = new TableColumn(this.table, SWT.NULL, index); - tableColumn.setMoveable(false); - tableColumn.setResizable(true); - tableColumn.setWidth(100); - - String columnName = this.columnAdapter.columnName(index); - - if (columnName == null) { - columnName = ""; - } - - tableColumn.setText(columnName); - } - } - - /** - * Brute force synchronization of table with the model list. - */ - protected void synchronizeTableItems() { - if (this.table.isDisposed()) { - return; - } - - for (int index = table.getItemCount(); --index >= 0; ) { - this.table.remove(index); - this.tableItemModelAdapters.remove(index); - } - - int itemCount = this.listHolder.size(); - - for (int index = 0; index < itemCount; index++) { - - TableItem tableItem = new TableItem(this.table, SWT.NULL, index); - tableItem.setData(this.listHolder.get(index)); - - TableItemModelAdapter adapter = buildItemModel(tableItem); - tableItemModelAdapters.add(adapter); - } - } - - /** - * The model has changed - synchronize the table. - */ - protected void listItemsAdded(ListChangeEvent event) { - - if (this.table.isDisposed()) { - return; - } - - int index = event.getIndex(); - - for (ListIterator<E> stream = this.items(event); stream.hasNext(); index++) { - - TableItem tableItem = new TableItem(this.table, SWT.NULL, index); - tableItem.setData(stream.next()); - - TableItemModelAdapter adapter = this.buildItemModel(tableItem); - tableItemModelAdapters.add(index, adapter); - } - } - - /** - * The model has changed - synchronize the table. - */ - protected void listItemsRemoved(ListChangeEvent event) { - - if (this.table.isDisposed()) { - return; - } - - this.table.remove(event.getIndex(), event.getIndex() + event.itemsSize() - 1); - - for (int index = event.getIndex() + event.itemsSize(); --index >= event.getIndex(); ) { - tableItemModelAdapters.remove(index); - } - } - - /** - * The model has changed - synchronize the table. - */ - protected void listItemsMoved(ListChangeEvent event) { - - if (this.table.isDisposed()) { - return; - } - - int length = event.getMoveLength(); - int sourceIndex = event.getSourceIndex(); - int targetIndex = event.getTargetIndex(); - int lowStartIndex = Math.min(targetIndex, sourceIndex); - int hiStartIndex = Math.max(targetIndex, sourceIndex); - - Object[] items = new Object[hiStartIndex - lowStartIndex + length]; - int itemsIndex = items.length; - - // Remove the TableItems wrapping the moved items - for (int index = hiStartIndex + length; --index >= lowStartIndex; ) { - - TableItemModelAdapter tableItemModel = this.tableItemModelAdapters.get(index); - items[--itemsIndex] = tableItemModel.tableItem.getData(); - - // Remove the TableItem, which will also dispose TableItemModelAdapter - this.table.remove(index); - } - - // Move the items so they can retrieved in the right order when - // re-creating the TableItems - CollectionTools.move( - items, - targetIndex - lowStartIndex, - sourceIndex - lowStartIndex, - length - ); - - itemsIndex = 0; - - // Add TableItems for the moved items - for (int index = lowStartIndex; index <= hiStartIndex + length - 1; index++) { - - // Create the new TableItem - TableItem tableItem = new TableItem(this.table, SWT.NULL, index); - tableItem.setData(items[itemsIndex++]); - - // Adapt it with a model adapter - TableItemModelAdapter adapter = this.buildItemModel(tableItem); - tableItemModelAdapters.set(index, adapter); - } - } - - - private TableItemModelAdapter buildItemModel(TableItem tableItem) { - return TableItemModelAdapter.adapt( - tableItem, - columnAdapter, - labelProvider - ); - } - - /** - * The model has changed - synchronize the table. - */ - protected void listItemsReplaced(ListChangeEvent event) { - if (this.table.isDisposed()) { - return; - } - - int rowIndex = event.getIndex(); - - for (ListIterator<E> stream = this.items(event); stream.hasNext(); ) { - TableItem tableItem = this.table.getItem(rowIndex); - tableItem.setData(stream.next()); - - TableItemModelAdapter adapter = tableItemModelAdapters.get(rowIndex); - - int columnCount = this.columnAdapter.columnCount(); - boolean revalidate = (columnCount == 1); - - for (int columnIndex = columnCount; --columnIndex >= 0; ) { - adapter.tableItemChanged(columnIndex, tableItem.getData(), revalidate); - } - - rowIndex++; - } - } - - /** - * The model has changed - synchronize the table. - */ - protected void listCleared(ListChangeEvent event) { - if (this.table.isDisposed()) { - return; - } - this.table.removeAll(); - } - - /** - * The model has changed - synchronize the table. - */ - protected void listChanged(ListChangeEvent event) { - this.synchronizeTableItems(); - } - - // 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 synchronizeTableSelection() { - if (this.table.isDisposed()) { - return; - } - 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.table.deselectAll(); - this.table.select(indices); - } - - protected void selectedItemsAdded(CollectionChangeEvent event) { - if (this.table.isDisposed()) { - return; - } - 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.table.select(indices); - } - - protected void selectedItemsRemoved(CollectionChangeEvent event) { - if (this.table.isDisposed()) { - return; - } - 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.table.deselect(indices); - } - - protected void selectedItemsCleared(CollectionChangeEvent event) { - if (this.table.isDisposed()) { - return; - } - this.table.deselectAll(); - } - - protected void selectedItemsChanged(CollectionChangeEvent event) { - this.synchronizeTableSelection(); - } - - // minimized unchecked code - @SuppressWarnings("unchecked") - protected Iterator<E> items(CollectionChangeEvent event) { - return ((Iterator<E>) event.items()); - } - - - // ********** list box events ********** - - @SuppressWarnings("unchecked") - protected void tableSelectionChanged(SelectionEvent event) { - if (this.selectionChangeListeners.length > 0) { - SelectionChangeEvent<E> scEvent = new SelectionChangeEvent(this, this.selectedItems()); - for (SelectionChangeListener<E> selectionChangeListener : this.selectionChangeListeners) { - selectionChangeListener.selectionChanged(scEvent); - } - } - } - - @SuppressWarnings("unchecked") - protected Collection<E> selectedItems() { - if (this.table.isDisposed()) { - return Collections.emptySet(); - } - ArrayList<E> selectedItems = new ArrayList(this.table.getSelectionCount()); - for (int selectionIndex : this.table.getSelectionIndices()) { - selectedItems.add(this.listHolder.get(selectionIndex)); - } - return selectedItems; - } - - @SuppressWarnings("unchecked") - protected void tableDoubleClicked(SelectionEvent event) { - if (this.table.isDisposed()) { - return; - } - if (this.doubleClickListeners.length > 0) { - // there should be only a single item selected during a double-click(?) - E selection = this.listHolder.get(this.table.getSelectionIndex()); - DoubleClickEvent<E> dcEvent = new DoubleClickEvent(this, selection); - for (DoubleClickListener<E> doubleClickListener : this.doubleClickListeners) { - doubleClickListener.doubleClick(dcEvent); - } - } - } - - - // ********** dispose ********** - - protected void tableDisposed(DisposeEvent event) { - // the table is not yet "disposed" when we receive this event - // so we can still remove our listeners - this.table.removeDisposeListener(this.tableDisposeListener); - this.table.removeSelectionListener(this.tableSelectionListener); - 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(TableModelAdapter<E> source, E selection) { - super(source); - if (selection == null) { - throw new NullPointerException(); - } - this.selection = selection; - } - - @Override - @SuppressWarnings("unchecked") - public TableModelAdapter<E> getSource() { - return (TableModelAdapter<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(TableModelAdapter<E> source, Collection<E> selection) { - super(source); - if (selection == null) { - throw new NullPointerException(); - } - this.selection = selection; - } - - @Override - @SuppressWarnings("unchecked") - public TableModelAdapter<E> getSource() { - return (TableModelAdapter<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/TextFieldModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TextFieldModelAdapter.java deleted file mode 100644 index 97789dc359..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TextFieldModelAdapter.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.swt; - -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Text; - -/** - * - */ -@SuppressWarnings("nls") -public class TextFieldModelAdapter { - - /** - * A value model on the underlying model list. - */ - protected final WritablePropertyValueModel<String> textHolder; - - /** - * A listener that allows us to synchronize the text field's contents with - * the model list. - */ - protected final PropertyChangeListener propertyChangeListener; - - /** - * The text field we keep synchronized with the model string. - */ - protected final Text textField; - - /** - * A listener that allows us to synchronize our selection list holder - * with the list box's selection. - */ - protected final ModifyListener textFieldModifyListener; - - /** - * A listener that allows us to stop listening to stuff when the list box - * is disposed. - */ - protected final DisposeListener textFieldDisposeListener; - - /** - * Flag to prevent setting the model during text field population. - * This can be a problem for virtual model objects where we never - * want to call the setter and can't depend on the setter change - * notification to stop the notification cycle. - */ - protected boolean populating; - - // ********** static methods ********** - - /** - * 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 TextFieldModelAdapter adapt( - WritablePropertyValueModel<String> textHolder, - Text textField) - { - return new TextFieldModelAdapter(textHolder, textField); - } - - - // ********** constructors ********** - - /** - * Constructor - the list holder, selections holder, list box, and - * string converter are required. - */ - protected TextFieldModelAdapter(WritablePropertyValueModel<String> textHolder, Text textField) { - super(); - if ((textHolder == null) || (textField == null)) { - throw new NullPointerException(); - } - this.textHolder = textHolder; - this.textField = textField; - - this.propertyChangeListener = this.buildPropertyChangeListener(); - this.textHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.propertyChangeListener); - - this.textFieldModifyListener = this.buildTextFieldModifyListener(); - this.textField.addModifyListener(this.textFieldModifyListener); - - this.textFieldDisposeListener = this.buildTextFieldDisposeListener(); - this.textField.addDisposeListener(this.textFieldDisposeListener); - - String text = textHolder.getValue(); - setText((text == null) ? "" : text); - } - - - // ********** initialization ********** - - protected PropertyChangeListener buildPropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper(this.buildPropertyChangeListener_()); - } - - protected PropertyChangeListener buildPropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - TextFieldModelAdapter.this.textChanged(event); - } - @Override - public String toString() { - return "text listener"; - } - }; - } - - protected ModifyListener buildTextFieldModifyListener() { - return new ModifyListener() { - public void modifyText(ModifyEvent event) { - TextFieldModelAdapter.this.textFieldModified(event); - } - @Override - public String toString() { - return "text field modify listener"; - } - }; - } - - protected DisposeListener buildTextFieldDisposeListener() { - return new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - TextFieldModelAdapter.this.textFieldDisposed(event); - } - @Override - public String toString() { - return "text field dispose listener"; - } - }; - } - - - // ********** model events ********** - - protected void textChanged(PropertyChangeEvent event) { - if (this.textField.isDisposed()) { - return; - } - String text = (String) event.getNewValue(); - // the model can be null, but the text field cannot - if (text == null) { - text = ""; - } - if ( ! text.equals(this.textField.getText())) { // ??? - setText(text); - } - } - - protected void setText(String text) { - this.populating = true; - try { - this.textField.setText(text); - } - finally { - this.populating = false; - } - } - - // ********** text field events ********** - - protected void textFieldModified(ModifyEvent event) { - if (this.populating) { - return; - } - this.textHolder.setValue(this.textField.getText()); - } - - protected void textFieldDisposed(DisposeEvent event) { - // the text field is not yet "disposed" when we receive this event - // so we can still remove our listeners - this.textField.removeDisposeListener(this.textFieldDisposeListener); - this.textField.removeModifyListener(this.textFieldModifyListener); - this.textHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.propertyChangeListener); - } - - - // ********** standard methods ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.textHolder); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TriStateCheckBoxModelAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TriStateCheckBoxModelAdapter.java deleted file mode 100644 index 1ca8be53e8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/swt/TriStateCheckBoxModelAdapter.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.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 TriStateCheckBoxModelAdapter { - - /** 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 "partially checked" - * (i.e. the button will be checked but grayed out). - */ - public static TriStateCheckBoxModelAdapter adapt(WritablePropertyValueModel<Boolean> booleanHolder, TriStateCheckBox button) { - return new TriStateCheckBoxModelAdapter(booleanHolder, button); - } - - - // ********** constructors ********** - - /** - * Constructor - the boolean holder and button are required. - */ - protected TriStateCheckBoxModelAdapter(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.getValue()); - } - - - // ********** initialization ********** - - protected PropertyChangeListener buildBooleanChangeListener() { - return new SWTPropertyChangeListenerWrapper(this.buildBooleanChangeListener_()); - } - - protected PropertyChangeListener buildBooleanChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - TriStateCheckBoxModelAdapter.this.booleanChanged(event); - } - @Override - public String toString() { - return "tri-state boolean listener"; - } - }; - } - - protected SelectionListener buildButtonSelectionListener() { - return new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent event) { - TriStateCheckBoxModelAdapter.this.buttonSelected(event); - } - @Override - public String toString() { - return "tri-state button selection listener"; - } - }; - } - - protected DisposeListener buildButtonDisposeListener() { - return new DisposeListener() { - public void widgetDisposed(DisposeEvent event) { - TriStateCheckBoxModelAdapter.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.getNewValue()); - } - - protected void setButtonSelection(Boolean selection) { - if (this.button.isDisposed()) { - return; - } - this.button.setSelection(selection); - } - - /** - * The button has been "selected" - synchronize the model. - */ - protected void buttonSelected(SelectionEvent event) { - if (this.button.isDisposed()) { - return; - } - this.booleanHolder.setValue(button.getSelection()); - } - - - // ********** dispose ********** - - protected void buttonDisposed(DisposeEvent event) { - // the button is not yet "disposed" when we receive this event - // so we can still remove our listeners - 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/ControlAligner.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java deleted file mode 100644 index 5bbcb64b6a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java +++ /dev/null @@ -1,913 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.StringTools; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; - -/** - * 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. It is also possible to align controls on the right side of the - * main component, a spacer can be used for extra space. - * <p> - * Here's an example: - * <pre> - * - Group Box 1 --------------------------------------------------------------- - * | -------------------------------------- -------------- | - * | Name: | I | | Browsse... | | - * | -------------------------------------- -------------- | - * | --------- | - * | 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 -{ - /** - * Flag used to prevent a validation so it can be done after an operation - * completed. - */ - private boolean autoValidate; - - /** - * The utility class used to support bound properties. - */ - private Collection<Listener> changeSupport; - - /** - * The listener added to each of the controls that listens only to a text - * change. - */ - private Listener listener; - - /** - * 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 0. - */ - 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); - - /** - * The types of events to listen in order to properly adjust the size of all - * the widgets. - */ - private static final int[] EVENT_TYPES = { - SWT.Dispose, - SWT.Hide, - SWT.Resize, - SWT.Show - }; - - /** - * Creates a new <code>ControlAligner</code>. - */ - public ControlAligner() { - super(); - initialize(); - } - - /** - * Creates a new <code>ControlAligner</code>. - * - * @param controls The collection of <code>Control</code>s - */ - public ControlAligner(Collection<? extends Control> controls) { - this(); - addAllControls(controls); - } - - /** - * Adds the given control. Its width will be used along with the width of all - * the other registered controls in order to get the greater witdh and use - * it as the width for all the controls. - * - * @param control The <code>Control</code> to be added - */ - public void add(Control control) { - - Assert.isNotNull(control, "Can't add null to this ControlAligner"); - - Wrapper wrapper = buildWrapper(control); - wrapper.addListener(listener); - wrappers.add(wrapper); - - revalidate(false); - } - - /** - * Adds the given control. Its width will be used along with the width of all - * the other registered controls in order to get the greater witdh and use - * it as the width for all the controls. - * - * @param controlAligner The <code>ControlAligner</code> to be added - * @exception IllegalArgumentException Can't add the <code>ControlAligner</code> - * to itself - */ - public void add(ControlAligner controlAligner) { - - Assert.isNotNull(controlAligner, "Can't add null to this ControlAligner"); - Assert.isLegal(controlAligner != this, "Can't add the ControlAligner to itself"); - - Wrapper wrapper = buildWrapper(controlAligner); - wrapper.addListener(listener); - wrappers.add(wrapper); - - if (!controlAligner.wrappers.isEmpty()) { - revalidate(false); - } - } - - /** - * 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 aligners The collection of <code>ControlAligner</code>s - */ - public void addAllControlAligners(Collection<ControlAligner> aligners) { - - // Deactivate the auto validation while adding all the Controls and/or - // ControlAligners in order to improve performance - boolean oldAutoValidate = autoValidate; - autoValidate = false; - - for (ControlAligner aligner : aligners) { - add(aligner); - } - - autoValidate = oldAutoValidate; - revalidate(false); - } - - /** - * 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 controls The collection of <code>Control</code>s - */ - public void addAllControls(Collection<? extends Control> controls) { - - // Deactivate the auto validation while adding all the Controls and/or - // ControlAligners in order to improve performance - boolean oldAutoValidate = autoValidate; - autoValidate = false; - - for (Control control : controls) { - add(control); - } - - autoValidate = oldAutoValidate; - revalidate(false); - } - - /** - * Adds the given <code>ControListener</code>. - * - * @param listener The <code>Listener</code> to be added - */ - private void addListener(Listener listener) { - - if (changeSupport == null) { - changeSupport = new ArrayList<Listener>(); - } - - 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); - } - - /** - * Calculates the width taken by the widgets and returns the maximum width. - * - * @param recalculateSize <code>true</code> to recalculate the preferred size - * of all the wrappers contained within them rather than using the cached - * size; <code>false</code> to use the cached size - */ - private int calculateWidth(boolean recalculateSize) { - - int width = 0; - - for (Wrapper wrapper : wrappers) { - Point size = wrapper.cachedSize(); - - // The size has not been calculated yet - if (recalculateSize || (size.x == 0)) { - size = wrapper.calculateSize(); - } - - // Only keep the greatest width - width = Math.max(size.x, width); - } - - return width; - } - - /** - * 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)) { - Event event = new Event(); - event.widget = SWTUtil.getShell(); - event.data = this; - - for (Listener listener : changeSupport) { - listener.handleEvent(event); - } - } - } - - /** - * Disposes this <code>ControlAligner</code>, this can improve the speed of - * disposing a pane. When a pane is disposed, this aligner doesn't need to - * revalidate its size upon dispose of its widgets. - */ - public void dispose() { - - for (Iterator<Wrapper> iter = wrappers.iterator(); iter.hasNext(); ) { - Wrapper wrapper = iter.next(); - wrapper.removeListener(listener); - iter.remove(); - } - - this.wrappers.clear(); - } - - /** - * Returns the length of the widest control. If the length was not - * calculated, then this value is 0. - * - * @return The width of the widest control or 0 if the length has not been - * calculated yet - */ - public int getMaximumWidth() { - return maximumWidth; - } - - /** - * Initializes this <code>ControlAligner</code>. - */ - private void initialize() { - - this.autoValidate = true; - this.maximumWidth = 0; - this.listener = new ListenerHandler(); - 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.locked()) { - Point size = wrapper.cachedSize(); - size.x = size.y = 0; - wrapper.setSize(DEFAULT_SIZE); - } - } - - /** - * Updates the maximum length based on the widest control. This methods - * does not update the width of the controls. - * - * @param recalculateSize <code>true</code> to recalculate the preferred size - * of all the wrappers contained within them rather than using the cached - * size; <code>false</code> to use the cached size - */ - private void recalculateWidth(boolean recalculateSize) { - - int width = calculateWidth(recalculateSize); - - try { - locked = true; - setMaximumWidth(width); - } - finally { - locked = false; - } - } - - /** - * Removes the given control. Its preferred width will not be used when - * calculating the preferred width. - * - * @param control The control to be removed - * @exception AssertionFailedException If the given <code>Control</code> is - * <code>null</code> - */ - public void remove(Control control) { - - Assert.isNotNull(control, "The Control to remove cannot be null"); - - Wrapper wrapper = retrieveWrapper(control); - wrapper.removeListener(listener); - wrappers.remove(wrapper); - - revalidate(true); - } - - /** - * Removes the given <code>ControlAligner</code>. Its preferred width - * will not be used when calculating the preferred witdh. - * - * @param controlAligner The <code>ControlAligner</code> to be removed - * @exception AssertionFailedException If the given <code>ControlAligner</code> - * is <code>null</code> - */ - public void remove(ControlAligner controlAligner) { - - Assert.isNotNull(controlAligner, "The ControlAligner to remove cannot be null"); - - Wrapper wrapper = retrieveWrapper(controlAligner); - wrapper.removeListener(listener); - wrappers.remove(wrapper); - - revalidate(true); - } - - /** - * Removes the given <code>Listener</code>. - * - * @param listener The <code>Listener</code> to be removed - */ - private void removeListener(Listener 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.source() == 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. - * - * @param recalculateSize <code>true</code> to recalculate the preferred size - * of all the wrappers contained within them rather than using the cached - * size; <code>false</code> to use the cached size - */ - private void revalidate(boolean recalculateSize) { - - if (autoValidate) { - recalculateWidth(recalculateSize); - updateWrapperSize(recalculateSize); - } - } - - /** - * Bases on the information contained in the given <code>Event</code>, - * resize the controls. - * - * @param event The <code>Event</code> sent by the UI thread when the state - * of a widget changed - */ - private void revalidate(Event event) { - - // We don't need to revalidate during a revalidation process - if (locked) { - return; - } - - Object source; - - if (event.widget != SWTUtil.getShell()) { - source = event.widget; - Control control = (Control) source; - - // When a dialog is opened, we need to actually force a layout of - // the controls, this is required because the control is actually - // not visible when the preferred width is caculated - if (control == control.getShell()) { - if (event.type == SWT.Dispose) { - return; - } - - source = null; - } - } - else { - source = event.data; - } - - // Either remove the ControlWrapper if the widget was disposed or - // invalidate the widget in order to recalculate the preferred size - if (source != null) { - if (event.type == SWT.Dispose) { - Wrapper wrapper = retrieveWrapper(source); - wrappers.remove(wrapper); - } - else { - invalidate(source); - } - } - - // Now revalidate all the Controls and ControlAligners - revalidate(true); - } - - /** - * Sets the length of the widest control. If the length was not calulcated, - * then this value is 0. - * - * @param maximumWidth The width of the widest control - */ - private void setMaximumWidth(int maximumWidth) { - - int oldMaximumWidth = this.maximumWidth; - 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(); - sb.append("maximumWidth="); - sb.append(maximumWidth); - sb.append(", wrappers="); - sb.append(wrappers); - return StringTools.buildToStringFor(this, sb); - } - - /** - * Updates the size of every <code>Wrapper</code> based on the maximum width. - * - * @param forceRevalidate <code>true</code> to revalidate the wrapper's size - * even though its current size might be the same as the maximum width; - * <code>false</code> to only revalidate the wrappers with a different width - */ - private void updateWrapperSize(boolean forceRevalidate) { - - for (Wrapper wrapper : wrappers) { - Point cachedSize = wrapper.cachedSize(); - - // No need to change the size of the wrapper since it's always using - // the maximum width - if (forceRevalidate || (cachedSize.x != maximumWidth)) { - Point size = new Point(maximumWidth, cachedSize.y); - wrapper.setSize(size); - } - } - } - - /** - * This <code>Wrapper</code> encapsulates a {@link ControlAligner}. - */ - private class ControlAlignerWrapper implements Wrapper { - /** - * The cached size, which is {@link ControlAligner#maximumWidth}. - */ - private final 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; - this.cachedSize = new Point(controlAligner.maximumWidth, 0); - } - - /* - * (non-Javadoc) - */ - public void addListener(Listener listener) { - controlAligner.addListener(listener); - } - - /* - * (non-Javadoc) - */ - public Point cachedSize() { - cachedSize.x = controlAligner.maximumWidth; - return cachedSize; - } - - /* - * (non-Javadoc) - */ - public Point calculateSize() { - - Point size = new Point(controlAligner.calculateWidth(false), 0); - - if (size.x != SWT.DEFAULT) { - cachedSize.x = size.x; - } - else { - cachedSize.x = 0; - } - - if (size.y != SWT.DEFAULT) { - cachedSize.y = size.y; - } - else { - cachedSize.y = 0; - } - - return size; - } - - /* - * (non-Javadoc) - */ - public boolean locked() { - return controlAligner.locked; - } - - /* - * (non-Javadoc) - */ - public void removeListener(Listener listener) { - controlAligner.removeListener(listener); - } - - /* - * (non-Javadoc) - */ - public void setSize(Point size) { - - if (size == DEFAULT_SIZE) { - controlAligner.maximumWidth = 0; - } - else if (controlAligner.maximumWidth != size.x) { - controlAligner.maximumWidth = size.x; - controlAligner.updateWrapperSize(true); - } - } - - /* - * (non-Javadoc) - */ - public Object source() { - return controlAligner; - } - - /* - * (non-Javadoc) - */ - @Override - public String toString() { - - StringBuffer sb = new StringBuffer(); - sb.append("Cached size="); - sb.append(cachedSize); - sb.append(", ControlAligner="); - sb.append(controlAligner); - return StringTools.buildToStringFor(this, sb); - } - } - - /** - * 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; - this.cachedSize = new Point(0, 0); - } - - /* - * (non-Javadoc) - */ - public void addListener(Listener listener) { - - for (int eventType : EVENT_TYPES) { - control.addListener(eventType, listener); - } - } - - /* - * (non-Javadoc) - */ - public Point cachedSize() { - return cachedSize; - } - - /* - * (non-Javadoc) - */ - public Point calculateSize() { - - cachedSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); - - // Update right away the control's GridData - GridData gridData = (GridData) control.getLayoutData(); - - if (gridData == null) { - gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - control.setLayoutData(gridData); - } - - gridData.widthHint = cachedSize.x; - gridData.heightHint = cachedSize.y; - - // Make sure the size is not -1 - if (cachedSize.x == SWT.DEFAULT) { - cachedSize.x = 0; - } - - if (cachedSize.y == SWT.DEFAULT) { - cachedSize.y = 0; - } - - return cachedSize; - } - - /* - * (non-Javadoc) - */ - public boolean locked() { - return false; - } - - /* - * (non-Javadoc) - */ - public void removeListener(Listener listener) { - - for (int eventType : EVENT_TYPES) { - control.removeListener(eventType, listener); - } - } - - /* - * (non-Javadoc) - */ - public void setSize(Point size) { - - if (control.isDisposed()) { - return; - } - - // Update the GridData with the new size - GridData gridData = (GridData) control.getLayoutData(); - - if (gridData == null) { - gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - control.setLayoutData(gridData); - } - - gridData.widthHint = size.x; - gridData.heightHint = size.y; - - // Force the control to be resized, and tell its parent to layout - // its widgets - if (size.x > 0) { -// locked = true; -// try { -//// control.getParent().layout(new Control[] { control }); -// control.getParent().layout(true); -// } -// finally { -// locked = false; -// } - Rectangle bounds = control.getBounds(); - - // Only update the control's width if it's - // different from the current size - if (bounds.width != size.x) { - locked = true; - - try { -// control.setBounds(bounds.x, bounds.y, size.x, size.y); - control.getParent().layout(true); - } - finally - { - locked = false; - } - } - } - } - - /* - * (non-Javadoc) - */ - public Control source() { - return control; - } - - /* - * (non-Javadoc) - */ - @Override - public String toString() { - - StringBuffer sb = new StringBuffer(); - sb.append("Cached size="); - sb.append(cachedSize); - sb.append(", Control="); - sb.append(control); - return StringTools.buildToStringFor(this, sb); - } - } - - /** - * The listener added to each of the control that is notified in order to - * revalidate the preferred size. - */ - private class ListenerHandler implements Listener { - public void handleEvent(Event event) { - ControlAligner.this.revalidate(event); - } - } - - /** - * This <code>Wrapper</code> helps to encapsulate heterogeneous objects and - * apply the same behavior on them. - */ - private interface Wrapper { - /** - * Adds the given <code>Listener</code> to wrapped object in order to - * receive notification when its property changed. - * - * @param listener The <code>Listener</code> to be added - */ - void addListener(Listener listener); - - /** - * Returns the cached size of the encapsulated source. - * - * @return A non-<code>null</code> <code>Point</code> where the x is the - * width and the y is the height of the widget - */ - Point cachedSize(); - - /** - * Calculates the preferred size the wrapped object would take by itself. - * - * @return The calculated size - */ - Point calculateSize(); - - /** - * 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> - */ - boolean locked(); - - /** - * Removes the given <code>Listener</code>. - * - * @param listener The <code>Listener</code> to be removed - */ - void removeListener(Listener listener); - - /** - * Sets the size on the encapsulated source. - * - * @param size The new size - */ - void setSize(Point size); - - /** - * Returns the encapsulated object. - * - * @return The object that is been wrapped - */ - Object source(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 472918aecc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.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 StateController -{ - /** - * 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); - } - }); - } - - /** - * This holder holds onto a <code>Control</code> and update its enabled state. - */ - private static class ControlHolder implements IControlHolder { - - private final Control control; - - ControlHolder(Control control) { - super(); - this.control = control; - } - - public void updateState(boolean state) { - if (!this.control.isDisposed()) { - this.control.setEnabled(state); - } - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java deleted file mode 100644 index 1efb77d9f4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.util; - -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.part.PageBook; - -/** - * This controller is responsible to switch the active page based on a value. A - * <code>Transformer</code> is used to transformed that value into a - * <code>Control</code>. - * - * @version 2.0 - * @since 2.0 - */ -public final class ControlSwitcher -{ - /** - * The widget that is used to show the active <code>Control</code>. - */ - private PageBook pageBook; - - /** - * The <code>Transformer</code> used to transform the value into a - * <code>Control</code>. - */ - private Transformer<?, Control> paneTransformer; - - /** - * Creates a new <code>ControlSwitcher</code>. - * - * @param switchHolder The holder of the value that will be used to retrieve - * the right <code>Control</code> when passed to the given transformer - * @param paneTransformer The <code>Transformer</code> used to transform the value into a - * <code>Control</code> - * @param pageBook The <code>Transformer</code> used to transform the value - * into a <code>Control</code> - */ - public <T> ControlSwitcher(PropertyValueModel<? extends T> switchHolder, - Transformer<T, Control> paneTransformer, - PageBook pageBook) - { - super(); - initialize(switchHolder, paneTransformer, pageBook); - } - - private PropertyChangeListener buildPropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper( - buildPropertyChangeListener_() - ); - } - - private PropertyChangeListener buildPropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - switchPanes(e.getNewValue()); - } - }; - } - - /** - * Initializes this <code>ControlSwitcher</code>. - * - * @param switchHolder The holder of the value that will be used to retrieve - * the right <code>Control</code> when passed to the given transformer - * @param paneTransformer The <code>Transformer</code> used to transform the value into a - * <code>Control</code> - * @param pageBook The <code>Transformer</code> used to transform the value - * into a <code>Control</code> - */ - private void initialize(PropertyValueModel<?> switchHolder, - Transformer<?, Control> paneTransformer, - PageBook pageBook) - { - this.pageBook = pageBook; - this.paneTransformer = paneTransformer; - - switchHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - buildPropertyChangeListener() - ); - - switchPanes(switchHolder.getValue()); - } - - /** - * Switches the active page by transforming the given value into its - * corresponding pane. - * - * @param value The state passed to the transformer in order to retrieve the - * new pane - */ - private void switchPanes(Object value) { - - if (pageBook.isDisposed()) { - return; - } - - // Retrieve the Control for the new value - Control pane = transform(value); - boolean visible = (pane != null); - - // Show the new page - if (visible) { - pageBook.showPage(pane); - } - else { - // Note: We can't null due to a bug in PageBook - pageBook.showPage(new Label(pageBook, SWT.SEPARATOR | SWT.HORIZONTAL)); - } - - if (pageBook.isVisible() != visible) { - pageBook.setVisible(visible); - } - - // Revalidate the parents in order to update the layout - SWTUtil.reflow(pageBook); - } - - @SuppressWarnings("unchecked") - private Control transform(Object value) { - return ((Transformer<Object, Control>) paneTransformer).transform(value); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlVisibilityEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlVisibilityEnabler.java deleted file mode 100644 index c74ab6a7e8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlVisibilityEnabler.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Control; - -/** - * This <code>ControlVisibilityEnabler</code> keeps the "visible" state of a - * collection of controls in synch with the provided boolean holder. - * - * @version 2.0 - * @since 2.0 - */ -public class ControlVisibilityEnabler extends StateController -{ - /** - * Creates a new <code>ControlVisibilityEnabler</code> with a default value - * of <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param controls The collection of controls whose "visible" state is - * kept in sync with the boolean holder's value - */ - public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Collection<? extends Control> controls) { - - this(booleanHolder, controls, false); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controls The collection of controls whose "visible" 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 ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Collection<? extends Control> controls, - boolean defaultValue) { - - this(booleanHolder, controls.iterator(), defaultValue); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code> with a default value of - * <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param control The control whose "visible" state is - * kept in sync with the boolean holder's value - */ - public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Control control) { - - this(booleanHolder, control, false); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code> with a default value of - * <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param controls The collection of controls whose "visible" state is - * kept in sync with the boolean holder's value - */ - public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Control... controls) { - - this(booleanHolder, CollectionTools.iterator(controls), false); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param control The control whose "visible" 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 ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Control control, - boolean defaultValue) { - - this(booleanHolder, CollectionTools.singletonIterator(control), false); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controls The collection of controls whose "visible" 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 ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Control[] controls, - boolean defaultValue) { - - this(booleanHolder, CollectionTools.iterator(controls), defaultValue); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code> with a default value - * of <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param controls An iterator on the collection of controls whose "visible" - * state is kept in sync with the boolean holder's value - */ - public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Iterator<? extends Control> controls) { - - this(booleanHolder, controls, false); - } - - /** - * Creates a new <code>ControlVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controls An iterator on the collection of controls whose "visible" - * 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 ControlVisibilityEnabler(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); - } - }); - } - - /** - * This holder holds onto a <code>Control</code> and update its visible state. - */ - private static class ControlHolder implements IControlHolder { - private final Control control; - - ControlHolder(Control control) { - super(); - this.control = control; - } - - public void updateState(boolean state) { - if (!this.control.isDisposed()) { - this.control.setVisible(state); - } - } - } -} 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 deleted file mode 100644 index 4febb30c35..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledButton.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.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 - * @exception AssertionFailedException If the given <code>Button</code> is - * <code>null</code> - */ - public LabeledButton(Button button) { - super(); - - Assert.isNotNull(button, "The button cannot be null"); - this.button = button; - } - - /* - * (non-Javadoc) - */ - public void setImage(Image image) { - if (!this.button.isDisposed()) { - this.button.setImage(image); - this.button.getParent().layout(true); - } - } - - /* - * (non-Javadoc) - */ - public void setText(String text) { - if (!this.button.isDisposed()) { - this.button.setText(text); - this.button.getParent().layout(true); - } - } -} 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 deleted file mode 100644 index 8a9716fa96..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControl.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.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 setImage(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 deleted file mode 100644 index e6333aaeb7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledControlUpdater.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.util; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.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 or - * <code>null</code> if the text never changes - * @param textHolder The holder this class will listen for changes or - * <code>null</code> if the image never changes - */ - public LabeledControlUpdater(LabeledControl labeledControl, - PropertyValueModel<String> textHolder, - PropertyValueModel<Image> imageHolder) - { - super(); - initialize(labeledControl, textHolder, imageHolder); - } - - private PropertyChangeListener buildIconListener() { - return new SWTPropertyChangeListenerWrapper(buildIconListener_()); - } - - private PropertyChangeListener buildIconListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - LabeledControlUpdater.this.setImage((Image) e.getNewValue()); - } - - @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.getNewValue()); - } - - @Override - public String toString() { - return "LabeledControlUpdater.textListener"; - } - }; - } - - private void initialize(LabeledControl labeledControl, - PropertyValueModel<String> textHolder, - PropertyValueModel<Image> imageHolder) - { - Assert.isNotNull(labeledControl, "The LabeledControl cannot be null"); - - this.labeledControl = labeledControl; - - if (textHolder != null) { - textHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildTextListener()); - setText(textHolder.getValue()); - } - - if (imageHolder != null) { - imageHolder.addPropertyChangeListener(PropertyValueModel.VALUE, buildIconListener()); - setImage(imageHolder.getValue()); - } - } - - private void setImage(Image icon) { - labeledControl.setImage(icon); - } - - private void setText(String text) { - - if (text == null) { - text = ""; - } - - labeledControl.setText(text); - } -}
\ No newline at end of file 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 deleted file mode 100644 index ad4030b9a5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/LabeledLabel.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.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 - * @exception AssertionFailedException If the given <code>Label</code> is - * <code>null</code> - */ - public LabeledLabel(Label label) { - super(); - - Assert.isNotNull(label, "The label cannot be null"); - this.label = label; - } - - /* - * (non-Javadoc) - */ - public void setImage(Image image) { - if (!this.label.isDisposed()) { - this.label.setImage(image); - this.label.getParent().layout(true); - } - } - - /* - * (non-Javadoc) - */ - public void setText(String text) { - if (!this.label.isDisposed()) { - this.label.setText(text); - this.label.getParent().layout(true); - } - } -} 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 deleted file mode 100644 index 63685b1b52..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * 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 StateController -{ - /** - * 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); - } - }); - } - - /** - * This holder holds onto an <code>AbstractPane</code> and update its enabled - * state. - */ - private static class PaneHolder implements IControlHolder { - private final AbstractPane<?> pane; - - PaneHolder(AbstractPane<?> pane) { - super(); - this.pane = pane; - } - - public void updateState(boolean state) { - - Composite container = this.pane.getControl(); - - if (!container.isDisposed()) { - - // Remove the enablement from the pane's control since this enabler - // is responsible to manage its enablement state - boolean enablementManaged = this.pane.isEnablementManaged(container); - this.pane.addToEnablementControl(container); - - // Now we can change the enablement state of the pane's widgets - this.pane.enableWidgets(state); - - // Restore the enablement state - if (enablementManaged) { - this.pane.removeFromEnablementControl(container); - } - } - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneVisibilityEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneVisibilityEnabler.java deleted file mode 100644 index aee7581b62..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneVisibilityEnabler.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.model.value.PropertyValueModel; - -/** - * This <code>PaneVisibilityEnabler</code> keeps the "visible" state of a - * collection of controls in synch with the provided boolean holder. - * - * @version 2.0 - * @since 2.0 - */ -public class PaneVisibilityEnabler extends StateController -{ - /** - * Creates a new <code>PaneVisibilityEnabler</code> with a default value of - * <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param pane The pane whose "visible" state is kept in sync with the - * boolean holder's value - */ - public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - AbstractPane<?> pane) { - - this(booleanHolder, pane, false); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code> with a default value of - * <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param panes The collection of panes whose "visible" state is kept in sync - * with the boolean holder's value - */ - public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - AbstractPane<?>... panes) { - - this(booleanHolder, CollectionTools.collection(panes), false); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param pane The pane whose "visible" 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 PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - AbstractPane<?> pane, - boolean defaultValue) { - - this(booleanHolder, CollectionTools.singletonIterator(pane), false); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param panes The collection of panes whose "visible" 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 PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - AbstractPane<?>[] panes, - boolean defaultValue) { - - this(booleanHolder, CollectionTools.iterator(panes), defaultValue); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code> with a default value of - * <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param panes The collection of panes whose "visible" state is kept in sync - * with the boolean holder's value - */ - public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Collection<? extends AbstractPane<?>> panes) { - - this(booleanHolder, panes, false); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param panes The collection of panes whose "visible" 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 PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Collection<? extends AbstractPane<?>> panes, - boolean defaultValue) { - - this(booleanHolder, panes.iterator(), defaultValue); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code> with a default value of - * <code>false</code> (i.e. not visible). - * - * @param booleanHolder A value model on the underlying boolean model - * @param panes An iterator on the collection of panes whose "visible" state - * is kept in sync with the boolean holder's value - */ - public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, - Iterator<? extends AbstractPane<?>> panes) { - - this(booleanHolder, panes, false); - } - - /** - * Creates a new <code>PaneVisibilityEnabler</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param panes An iterator on the collection of panes whose "visible" 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 PaneVisibilityEnabler(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); - } - }); - } - - /** - * This holder holds onto an <code>AbstractPane</code> and update its visible - * state. - */ - private static class PaneHolder implements IControlHolder { - private final AbstractPane<?> pane; - - PaneHolder(AbstractPane<?> pane) { - super(); - this.pane = pane; - } - - public void updateState(boolean state) { - this.pane.setVisible(state); - } - } -} 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 deleted file mode 100644 index 741fa067af..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/SWTUtil.java +++ /dev/null @@ -1,684 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.util; - -import java.util.Locale; -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.jpt.utility.internal.ClassTools; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.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; -import org.eclipse.ui.forms.widgets.ScrolledForm; - -/** - * A suite of utility methods related to the user interface. - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class SWTUtil { - - /** - * Causes the <code>run()</code> method of the given runnable to be invoked - * by the user-interface thread at the next reasonable opportunity. The caller - * of this method continues to run in parallel, and is not notified when the - * runnable has completed. - * - * @param runnable Code to run on the user-interface thread - * @exception org.eclipse.swt.SWTException - * <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @see #syncExec - */ - public static void asyncExec(Runnable runnable) { - getStandardDisplay().asyncExec(runnable); - } - - /** - * Tweaks the given <code>CCombo</code> to remove the default value when the - * widget receives the focus and to show the default when the widget loses - * the focus. - * - * @param combo The widget having a default value that is always at the - * beginning of the list - */ - public static void attachDefaultValueHandler(CCombo combo) { - CComboHandler handler = new CComboHandler(); - combo.addFocusListener(handler); - combo.addModifyListener(handler); - } - - /** - * Tweaks the given <code>Combo</code> to remove the default value when the - * widget receives the focus and to show the default when the widget loses - * the focus. - * - * @param combo The widget having a default value that is always at the - * beginning of the list - */ - public static void attachDefaultValueHandler(Combo combo) { - ComboHandler handler = new ComboHandler(); - combo.addFocusListener(handler); - combo.addModifyListener(handler); - } - - /** - * 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 - */ - public static String buildDisplayString(Class<?> nlsClass, - Class<?> compositeClass, - Object value) { - - StringBuilder sb = new StringBuilder(); - sb.append(ClassTools.shortNameFor(compositeClass)); - sb.append("_"); - sb.append(value.toString().toLowerCase(Locale.ENGLISH));//bug 234953 - //TODO in a future release we should not be converting the key using 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 - */ - public static final String buildDisplayString(Class<?> nlsClass, - Object composite, - Object value) { - - return buildDisplayString(nlsClass, composite.getClass(), value); - } - - /** - * 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; - } - - /** - * Returns the Platform UI workbench. - * - * @return The workbench for this plug-in - */ - public static IWorkbench getWorkbench() { - return PlatformUI.getWorkbench(); - } - - /** - * Relays out the parents of the <code>Control</code>. This was taken from - * the widget <code>Section</code>. - * - * @param pane The pane to revalidate as well as its parents - */ - public static void reflow(Composite pane) { - - for (Composite composite = pane; composite != null; ) { - composite.setRedraw(false); - composite = composite.getParent(); - - if (composite instanceof ScrolledForm) { - break; - } - } - - for (Composite composite = pane; composite != null; ) { - composite.layout(true); - composite = composite.getParent(); - - if (composite instanceof ScrolledForm) { - ((ScrolledForm) composite).reflow(true); - break; - } - } - - for (Composite composite = pane; composite != null; ) { - composite.setRedraw(true); - composite = composite.getParent(); - - if (composite instanceof ScrolledForm) { - break; - } - } - } - - /** - * 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 - * @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 - */ - 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 - */ - 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(); - } - - /** - * This handler is responsible for removing the default value when the combo - * has the focus or when the selected item is the default value and to select - * it when the combo loses the focus. - */ - private static class CComboHandler implements ModifyListener, - FocusListener { - - /** - * This flag is used to prevent the methods of this handler from - * interacting with each other. - */ - private boolean locked; - - /* - * (non-Javadoc) - */ - public void focusGained(FocusEvent e) { - - if (locked) { - return; - } - - CCombo combo = (CCombo) e.widget; - - if (combo.getSelectionIndex() == 0) { - combo.setData("populating", Boolean.TRUE); - locked = true; - - // The text has to be changed outside of the context of this - // listener otherwise the combo won't update because it's currently - // notifying its listeners - asyncExec(new RemoveDefault(combo, Boolean.FALSE)); - } - } - - /* - * (non-Javadoc) - */ - public void focusLost(FocusEvent e) { - - if (locked) { - return; - } - - CCombo combo = (CCombo) e.widget; - - if (combo.getText().length() == 0) { - combo.setData("populating", Boolean.TRUE); - locked = true; - - try { - combo.setText(combo.getItem(0)); - } - finally { - combo.setData("populating", Boolean.FALSE); - locked = false; - } - } - } - - /* - * (non-Javadoc) - */ - public void modifyText(ModifyEvent e) { - - if (locked) { - return; - } - - CCombo combo = (CCombo) e.widget; - - if (combo.isFocusControl() && - combo.getSelectionIndex() <= 0) { - - // Make sure the current text is the default value - String currentValue = combo.getText(); - - if (currentValue.length() > 0 && - combo.getItemCount() > 0 && - !currentValue.equals(combo.getItem(0))) { - - return; - } - - // Remove the default value - Object populating = combo.getData("populating"); - combo.setData("populating", Boolean.TRUE); - locked = true; - - // The text has to be changed outside of the context of this - // listener otherwise the combo won't update because it's currently - // notifying its listeners - asyncExec(new ModifyText(combo, populating)); - } - } - - private class ModifyText implements Runnable { - private final CCombo combo; - private final Object populating; - - public ModifyText(CCombo combo, Object populating) { - super(); - this.combo = combo; - this.populating = populating; - } - - public void run() { - if (this.combo.isDisposed()) { - CComboHandler.this.locked = false; - } - else { - try { - String text = this.combo.getText(); - - if (text.length() == 0) { - text = this.combo.getItem(0); - this.combo.setText(text); - } - - this.combo.setSelection(new Point(0, text.length())); - } - finally { - this.combo.setData("populating", this.populating); - CComboHandler.this.locked = false; - } - } - } - } - - private class RemoveDefault implements Runnable { - private final CCombo combo; - private final Object populating; - - public RemoveDefault(CCombo combo, Object populating) { - super(); - this.combo = combo; - this.populating = populating; - } - - public void run() { - if (this.combo.isDisposed()) { - CComboHandler.this.locked = false; - } - else { - try { - this.combo.setText(""); - } - finally { - this.combo.setData("populating", this.populating); - CComboHandler.this.locked = false; - } - } - } - } - } - - /** - * This handler is responsible for removing the default value when the combo - * has the focus or when the selected item is the default value and to select - * it when the combo loses the focus. - */ - private static class ComboHandler implements ModifyListener, - FocusListener { - - /** - * This flag is used to prevent the methods of this handler from - * interacting with each other. - */ - private boolean locked; - - /* - * (non-Javadoc) - */ - public void focusGained(FocusEvent e) { - - if (locked) { - return; - } - - Combo combo = (Combo) e.widget; - - if (combo.getSelectionIndex() == 0) { - combo.setData("populating", Boolean.TRUE); - locked = true; - - // The text has to be changed outside of the context of this - // listener otherwise the combo won't update because it's currently - // notifying its listeners - asyncExec(new RemoveDefault(combo, Boolean.FALSE)); - } - } - - /* - * (non-Javadoc) - */ - public void focusLost(FocusEvent e) { - - if (locked) { - return; - } - - Combo combo = (Combo) e.widget; - - if (combo.getText().length() == 0) { - combo.setData("populating", Boolean.TRUE); - locked = true; - - try { - combo.select(0); - } - finally { - combo.setData("populating", Boolean.FALSE); - locked = false; - } - } - } - - /* - * (non-Javadoc) - */ - public void modifyText(ModifyEvent e) { - - if (locked) { - return; - } - - Combo combo = (Combo) e.widget; - - if (combo.isFocusControl() && - combo.getSelectionIndex() == 0) { - - Object populating = combo.getData("populating"); - combo.setData("populating", Boolean.TRUE); - locked = true; - - // The text has to be changed outside of the context of this - // listener otherwise the combo won't update because it's currently - // notifying its listeners - asyncExec(new ModifyText(combo, populating)); - } - } - - private class ModifyText implements Runnable { - private final Combo combo; - private final Object populating; - - public ModifyText(Combo combo, Object populating) { - super(); - this.combo = combo; - this.populating = populating; - } - - public void run() { - if (this.combo.isDisposed()) { - ComboHandler.this.locked = false; - } - else { - try { - String text = this.combo.getText(); - - if (text.length() == 0) { - text = this.combo.getItem(0); - this.combo.setText(text); - } - - this.combo.setSelection(new Point(0, text.length())); - } - finally { - this.combo.setData("populating", this.populating); - ComboHandler.this.locked = false; - } - } - } - } - - private class RemoveDefault implements Runnable { - private final Combo combo; - private final Object populating; - - public RemoveDefault(Combo combo, Object populating) { - super(); - this.combo = combo; - this.populating = populating; - } - - public void run() { - if (this.combo.isDisposed()) { - ComboHandler.this.locked = false; - } - else { - try { - this.combo.setText(""); - } - finally { - this.combo.setData("populating", this.populating); - ComboHandler.this.locked = false; - } - } - } - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/StateController.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/StateController.java deleted file mode 100644 index 6ac334a17d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/StateController.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -/** - * A <code>StateController</code> keeps the state of a collection of widgets in - * synch with the provided boolean holder. - * - * @see ControlEnabler - * @see ControlVisibilityEnabler - * @see PaneEnabler - * @see PaneVisibilityEnabler - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -abstract class StateController -{ - /** - * 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 state is kept in sync - * with the boolean holder's value. - */ - private Collection<IControlHolder> controlHolders; - - /** - * The default setting for the state; for when the underlying model is - * <code>null</code>. The default [default value] is <code>false<code>. - */ - private boolean defaultValue; - - /** - * Creates a new <code>StateController</code>. - */ - StateController() { - super(); - initialize(); - } - - /** - * Creates a new <code>StateController</code> with a default value of - * <code>false</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of <code>IControlHolder</code>s whose - * state is kept in sync with the boolean holder's value - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - Collection<IControlHolder> controlHolders) { - - this(booleanHolder, controlHolders, false); - } - - /** - * Creates a new <code>StateController</code> with a default value of - * <code>false</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of <code>IControlHolder</code>s whose - * 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> - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - Collection<IControlHolder> controlHolders, - boolean defaultValue) { - - this(); - initialize(booleanHolder, controlHolders, defaultValue); - } - - /** - * Creates a new <code>StateController</code> with a default value of - * <code>false</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolder The <code>IControlHolder</code> whose state is kept - * in sync with the boolean holder's value - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - IControlHolder controlHolder) { - - this(booleanHolder, controlHolder, false); - } - - /** - * Creates a new <code>StateController</code> with a default value of - * <code>false</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of <code>IControlHolder</code>s whose - * state is kept in sync with the boolean holder's value - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - IControlHolder... controlHolders) { - - this(booleanHolder, CollectionTools.collection(controlHolders), false); - } - - /** - * Creates a new <code>StateController</code> with a default value of - * <code>false</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolder The <code>IControlHolder</code> whose 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> - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - IControlHolder controlHolder, - boolean defaultValue) { - - this(booleanHolder, new IControlHolder[] { controlHolder }, false); - } - - /** - * Creates a new <code>StateController</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of <code>IControlHolder</code>s whose - * 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> - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - IControlHolder[] controlHolders, - boolean defaultValue) { - - this(); - this.initialize(booleanHolder, CollectionTools.collection(controlHolders), defaultValue); - } - - /** - * Creates a new <code>StateController</code> with a default value of - * <code>false</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders An iterator on the collection of - * <code>IControlHolder</code>s whose state is kept in sync with the boolean - * holder's value - */ - StateController(PropertyValueModel<Boolean> booleanHolder, - Iterator<IControlHolder> controlHolders) { - - this(booleanHolder, CollectionTools.collection(controlHolders), false); - } - - /** - * Creates a new <code>StateController</code>. - * - * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders An iterator on the collection of - * <code>IControlHolder</code>s whose 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> - */ - StateController(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 SWTPropertyChangeListenerWrapper( - buildBooleanChangeListener_() - ) - { - @Override - public String toString() { - return "StateController.SWTPropertyChangeListenerWrapper"; - } - }; - } - - /** - * Creates a listener for the boolean holder. - * - * @return A new <code>PropertyChangeListener</code> - */ - private PropertyChangeListener buildBooleanChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - updateState(booleanValue(booleanHolder.getValue())); - } - - @Override - public String toString() { - return "StateController.PropertyChangeListener"; - } - }; - } - - /** - * Returns an <code>Iterator</code> over the collection of - * <code>IControlHolder</code>s. - * - * @return The iteration of <code>IControlHolder</code>s - */ - protected final Iterator<IControlHolder> controlHolders() { - return new CloneIterator<IControlHolder>(this.controlHolders); - } - - /** - * Initializes this <code>StateController</code> by building the appropriate - * listeners. - */ - protected void initialize() { - this.booleanChangeListener = this.buildBooleanChangeListener(); - } - - /** - * Initializes this <code>StateController</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.updateState(); - } - - /** - * Updates the state of the control holders. - */ - protected void updateState() { - this.updateState(booleanValue(booleanHolder.getValue())); - } - - /** - * Updates the state of the <code>Control</code>s. - * - * @param state The new state the widgets need to have - */ - protected void updateState(boolean state) { - for (IControlHolder controlHolder : this.controlHolders) { - controlHolder.updateState(state); - } - } - - /** - * The holder of the actual widget. - */ - static interface IControlHolder { - - /** - * Updates the state of the wrapped control. - * - * @param state The new state the control should have - */ - void updateState(boolean state); - } -} 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 deleted file mode 100644 index a037b12bd1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/TableLayoutComposite.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.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; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -/** - * 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 - * layout manager. - * - * copied from jdt.internal.ui.util - */ -public class TableLayoutComposite extends Composite { - - /** - * The number of extra pixels taken as horizontal trim by the table column. - * To ensure there are N pixels available for the content of the column, - * assign N+COLUMN_TRIM for the column width. - * - * @since 3.1 - */ - private static int COLUMN_TRIM = "carbon".equals(SWT.getPlatform()) ? 24 : 3; //$NON-NLS-1$ - - private List<ColumnLayoutData> columns= new ArrayList<ColumnLayoutData>(); - - /** - * Creates a new <code>TableLayoutComposite</code>. - */ - public TableLayoutComposite(Composite parent, int style) { - super(parent, style); - addControlListener(new ControlAdapter() { - @Override - public void controlResized(ControlEvent e) { - Rectangle area= getClientArea(); - Table table= (Table)getChildren()[0]; - Point preferredSize= computeTableSize(table); - int width= area.width - 2 * table.getBorderWidth(); - if (preferredSize.y > area.height) { - // Subtract the scrollbar width from the total column width - // if a vertical scrollbar will be required - Point vBarSize = table.getVerticalBar().getSize(); - width -= vBarSize.x; - } - layoutTable(table, width, area, table.getSize().x < area.width); - } - }); - } - - /** - * Adds a new column of data to this table layout. - * - * @param data the column layout data - */ - public void addColumnData(ColumnLayoutData data) { - columns.add(data); - } - - //---- Helpers ------------------------------------------------------------------------------------- - - private Point computeTableSize(Table table) { - Point result= table.computeSize(SWT.DEFAULT, SWT.DEFAULT); - - int width= 0; - int size= columns.size(); - for (int i= 0; i < size; ++i) { - ColumnLayoutData layoutData= columns.get(i); - if (layoutData instanceof ColumnPixelData) { - ColumnPixelData col= (ColumnPixelData) layoutData; - width += col.width; - if (col.addTrim) { - width += COLUMN_TRIM; - } - } else if (layoutData instanceof ColumnWeightData) { - ColumnWeightData col= (ColumnWeightData) layoutData; - width += col.minimumWidth; - } else { - Assert.isTrue(false, "Unknown column layout data"); //$NON-NLS-1$ - } - } - if (width > result.x) - result.x= width; - return result; - } - - private void layoutTable(Table table, int width, Rectangle area, boolean increase) { - // XXX: Layout is being called with an invalid value the first time - // it is being called on Linux. This method resets the - // Layout to null so we make sure we run it only when - // the value is OK. - if (width <= 1) - return; - - TableColumn[] tableColumns= table.getColumns(); - int size= Math.min(columns.size(), tableColumns.length); - int[] widths= new int[size]; - int fixedWidth= 0; - int numberOfWeightColumns= 0; - int totalWeight= 0; - - // First calc space occupied by fixed columns - for (int i= 0; i < size; i++) { - ColumnLayoutData col= columns.get(i); - if (col instanceof ColumnPixelData) { - ColumnPixelData cpd= (ColumnPixelData) col; - int pixels= cpd.width; - if (cpd.addTrim) { - pixels += COLUMN_TRIM; - } - widths[i]= pixels; - fixedWidth += pixels; - } else if (col instanceof ColumnWeightData) { - ColumnWeightData cw= (ColumnWeightData) col; - numberOfWeightColumns++; - // first time, use the weight specified by the column data, otherwise use the actual width as the weight - // int weight = firstTime ? cw.weight : tableColumns[i].getWidth(); - int weight= cw.weight; - totalWeight += weight; - } else { - Assert.isTrue(false, "Unknown column layout data"); //$NON-NLS-1$ - } - } - - // Do we have columns that have a weight - if (numberOfWeightColumns > 0) { - // Now distribute the rest to the columns with weight. - int rest= width - fixedWidth; - int totalDistributed= 0; - for (int i= 0; i < size; ++i) { - ColumnLayoutData col= columns.get(i); - if (col instanceof ColumnWeightData) { - ColumnWeightData cw= (ColumnWeightData) col; - // calculate weight as above - // int weight = firstTime ? cw.weight : tableColumns[i].getWidth(); - int weight= cw.weight; - int pixels= totalWeight == 0 ? 0 : weight * rest / totalWeight; - if (pixels < cw.minimumWidth) - pixels= cw.minimumWidth; - totalDistributed += pixels; - widths[i]= pixels; - } - } - - // Distribute any remaining pixels to columns with weight. - int diff= rest - totalDistributed; - for (int i= 0; diff > 0; ++i) { - if (i == size) - i= 0; - ColumnLayoutData col= columns.get(i); - if (col instanceof ColumnWeightData) { - ++widths[i]; - --diff; - } - } - } - - if (increase) { - table.setSize(area.width, area.height); - } - for (int i= 0; i < size; i++) { - tableColumns[i].setWidth(widths[i]); - } - if (!increase) { - table.setSize(area.width, area.height); - } - } -} 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 deleted file mode 100644 index bb4499bb4b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/AbstractJpaView.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2006, 2008 Versant. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Versant and Others. - initial API and implementation - ********************************************************************************/ -package org.eclipse.jpt.ui.internal.views; - -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.ui.internal.selection.JpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.jpt.ui.internal.widgets.FormWidgetFactory; -import org.eclipse.jpt.ui.internal.widgets.PropertySheetWidgetFactory; -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.FormToolkit; -import org.eclipse.ui.forms.widgets.ScrolledForm; -import org.eclipse.ui.part.PageBook; -import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * This is the abstract implementation of the JPA view. The selection is changed - * by receiving a <code>IJpaSelection</code>. - * - * @see JpaSelection - * - * @version 2.0 - * @since 1.0 - */ -public abstract class AbstractJpaView extends ViewPart -{ - /** - * The default page used when nothing can be shown. - */ - private Composite defaultComposite; - - /** - * The string to display when there is no view content - */ - private String defaultLabel; - - /** - * The container of the current page. - */ - private PageBook pageBook; - - /** - * The factory used to create the various widgets. - */ - private WidgetFactory widgetFactory; - - /** - * Creates a new <code>AbstractJpaView</code>. - * - * @param defaultLabel - */ - public AbstractJpaView(String defaultLabel) { - super(); - this.defaultLabel = defaultLabel; - this.initialize(); - } - - private Composite buildDefaultComposite() { - Composite composite = widgetFactory.createComposite(pageBook); - composite.setLayout(new FillLayout(SWT.VERTICAL)); - getWidgetFactory().createLabel(composite, defaultLabel); - return composite; - } - - /* - * (non-Javadoc) - */ - @Override - public final void createPartControl(Composite parent) { - pageBook = new PageBook(parent, SWT.NONE); - - defaultComposite = buildDefaultComposite(); - pageBook.showPage(defaultComposite); - - subcreatePartControl(parent); - - JpaSelectionManager selectionManager = - SelectionManagerFactory.getSelectionManager(getViewSite().getWorkbenchWindow()); - - selectionManager.register(this); - select(selectionManager.getCurrentSelection()); - } - - protected final PageBook getPageBook() { - return pageBook; - } - - public final WidgetFactory getWidgetFactory() { - return this.widgetFactory; - } - - /** - * Initializes this JPA view. - */ - protected void initialize() { - this.widgetFactory = new PropertySheetWidgetFactory( - new TabbedPropertySheetWidgetFactory() - ); - } - - private FormToolkit getFormWidgetFactory() { - return ((FormWidgetFactory) widgetFactory).getWidgetFactory(); - } - - /** - * The selection has changed, update the current page by using the given - * selection state. - * - * @param jpaSelection The new selection used to update this JPA view - */ - public abstract void select(JpaSelection jpaSelection); - - /* - * (non-Javadoc) - */ - @Override - public void setFocus() { - pageBook.setFocus(); - } - - /** - * Changes the current page and show the default one. - */ - protected void showDefaultPage() { - showPage(defaultComposite); - } - - /** - * Changes the current page and show the given one. - * - * @param page The new page to show, <code>null</code> can't be passed - */ - protected final void showPage(Control page) { - 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 = getFormWidgetFactory().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 deleted file mode 100644 index 3001902588..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.views; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.details.JpaDetailsPage; -import org.eclipse.jpt.ui.details.JpaDetailsProvider; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.Tracing; -import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; -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; - -/** - * 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 JpaDetailsPage<JpaStructureNode> currentPage; - - /** - * The current selection used to show the right <code>IJpaDetailsPage</code>. - */ - private JpaSelection currentSelection; - - /** - * key: Object content node id, value: Composite page. - */ - private Map<Object, JpaDetailsPage<? extends JpaStructureNode>> detailsPages; - - /** - * Creates a new <code>JpaDetailsView</code>. - */ - public JpaDetailsView() { - super(JptUiMessages.JpaDetailsView_viewNotAvailable); - } - - private JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(JpaStructureNode structureNode) { - JpaDetailsProvider detailsProvider = getDetailsProvider(structureNode); - - if (detailsProvider == null) { - return null; - } - - String id = structureNode.getId(); - - Composite container = getWidgetFactory().createComposite(getPageBook()); - container.setLayout(new FillLayout(SWT.HORIZONTAL)); - - JpaDetailsPage<? extends JpaStructureNode> page = detailsProvider.buildDetailsPage( - container, - id, - getWidgetFactory() - ); - - if (page != null) { - this.detailsPages.put(id, page); - } - - return page; - } - - /* - * (non-Javadoc) - */ - @Override - public void dispose() { - - detailsPages.clear(); - - currentSelection = JpaSelection.NULL_SELECTION; - currentPage = null; - - super.dispose(); - } - - private JpaDetailsPage<? extends JpaStructureNode> getDetailsPage(JpaStructureNode structureNode) { - if (detailsPages.containsKey(structureNode.getId())) { - JpaDetailsPage<? extends JpaStructureNode> page = detailsPages.get(structureNode.getId()); - - if ((page != null) && - (page.getControl().isDisposed())) { - detailsPages.remove(structureNode.getId()); - } - else { - return page; - } - } - return buildDetailsPage(structureNode); - } - - private JpaDetailsProvider getDetailsProvider(JpaStructureNode structureNode) { - - String platformId = structureNode.getJpaProject().getJpaPlatform().getId(); - JpaPlatformUi jpaPlatformUI = JpaPlatformUiRegistry.instance().jpaPlatform(platformId); - return jpaPlatformUI.detailsProvider(structureNode); - - //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 JpaSelection getSelection() { - return currentSelection; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - - this.currentSelection = JpaSelection.NULL_SELECTION; - this.detailsPages = new HashMap<Object, JpaDetailsPage<? extends JpaStructureNode>>(); - } - - private void log(String message) { - if (Tracing.booleanDebugOption(Tracing.UI_DETAILS_VIEW)) { - Tracing.log(message); - } - } - - /* - * (non-Javadoc) - */ - @Override - public void select(JpaSelection jpaSelection) { - if (jpaSelection.equals(currentSelection)) { - return; - } - - currentSelection = jpaSelection; - - if (jpaSelection != JpaSelection.NULL_SELECTION) { - JpaStructureNode newNode = jpaSelection.getSelectedNode(); - JpaDetailsPage<? extends JpaStructureNode> newPage = getDetailsPage(newNode); - setCurrentPage(newPage); - } - else { - setCurrentPage(null); - } - } - - /** - * Changes the current page and shows the given page. - * - * @param newPage The new page to display - */ - @SuppressWarnings("unchecked") - private void setCurrentPage(JpaDetailsPage<? extends JpaStructureNode> page) { - - // Unpopulate old page - if (currentPage != null) { - try { - log("JpaDetailsView.setCurrentPage() : disposing of current page"); - - currentPage.setSubject(null); - } - catch (Exception e) { - JptUiPlugin.log(e); - } - } - - JpaDetailsPage<JpaStructureNode> newPage = (JpaDetailsPage<JpaStructureNode>) page; - - // Populate new page - if (page != null) { - try { - log("JpaDetailsView.setCurrentPage() : populating new page"); - newPage.setSubject(currentSelection.getSelectedNode()); - } - catch (Exception e) { - // Show error page - page = null; - JptUiPlugin.log(e); - } - } - else { - log("JpaDetailsView.setCurrentPage() : No page to populate"); - } - - //no need to show the page again if it is still the same - if (newPage != null && currentPage == newPage) { - return; - } - currentPage = newPage; - - // Show new page - if (page == null) { - showDefaultPage(); - } - else { - showPage(page.getControl()); - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index b72ffcea4b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java +++ /dev/null @@ -1,193 +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.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.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelection; -import org.eclipse.jpt.ui.structure.JpaStructureProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.part.IPageSite; -import org.eclipse.ui.part.Page; - -public class JpaStructurePage extends Page - implements ISelectionProvider, ISelectionChangedListener -{ - private JpaStructureProvider structureProvider; - - private ListenerList selectionChangedListeners; - - private Composite control; - - private TreeViewer viewer; - - private JpaStructureView jpaStructureView; - - public JpaStructurePage(JpaStructureView jpaStructureView, JpaStructureProvider structureProvider) { - this.jpaStructureView = jpaStructureView; - 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.getTreeItemContentProviderFactory(), - structureProvider.getItemLabelProviderFactory()); - 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); - this.jpaStructureView.getSite().registerContextMenu(mgr, viewer); - } - - /** - * Called when the context menu is about to open. - * Delegates to the action group using the viewer's selection as the action context. - * @since 2.0 - */ - protected void fillContextMenu(IMenuManager manager) { - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - @Override - public Control getControl() { - return control; - } - - @Override - public void setFocus() { - control.setFocus(); - } - - - - void select(JpaSelection selection) { - if (selection.isEmpty()) { - viewer.setSelection(StructuredSelection.EMPTY); - } - else { - viewer.setSelection(new StructuredSelection(selection.getSelectedNode()), true); - } - } - - - // **************** ISelectionProvider impl ******************************** - - public void addSelectionChangedListener(ISelectionChangedListener listener) { - selectionChangedListeners.add(listener); - } - - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - selectionChangedListeners.remove(listener); - } - - public ITreeSelection getSelection() { - return (ITreeSelection) viewer.getSelection(); - } - - public JpaSelection getJpaSelection() { - ITreeSelection viewerSelection = getSelection(); - - if (viewerSelection.isEmpty() || viewerSelection.size() > 1) { - return JpaSelection.NULL_SELECTION; - } - return new DefaultJpaSelection((JpaStructureNode) viewerSelection.getFirstElement()); - } - - - public void setSelection(ISelection selection) { - if (viewer != null) { - viewer.setSelection(selection); - } - } - - - - // **************** 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 deleted file mode 100644 index 35b1adb814..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.views.structure; - -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.ui.JpaPlatformUi; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.selection.JpaSelection; -import org.eclipse.jpt.ui.internal.selection.JpaSelectionManager; -import org.eclipse.jpt.ui.internal.selection.SelectionManagerFactory; -import org.eclipse.jpt.ui.structure.JpaStructureProvider; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.part.IPage; -import org.eclipse.ui.part.MessagePage; -import org.eclipse.ui.part.PageBook; -import org.eclipse.ui.part.PageBookView; - -public class JpaStructureView extends PageBookView -{ - public JpaStructureView() { - super(); - } - - @Override - public void createPartControl(Composite parent) { - super.createPartControl(parent); - - JpaSelectionManager selectionManager = - SelectionManagerFactory.getSelectionManager(getViewSite().getWorkbenchWindow()); - - selectionManager.register(this); - select(selectionManager.getCurrentSelection()); - } - - @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) { - JpaStructureProvider structureProvider = - structureProvider(part); - if (structureProvider != null) { - JpaStructurePage page = new JpaStructurePage(this, structureProvider); - initPage(page); - page.createControl(getPageBook()); - return new PageRec(part, page); - } - return null; - } - - private JpaStructureProvider structureProvider(IWorkbenchPart part) { - JpaFile jpaFile = - (JpaFile) part.getAdapter(JpaFile.class); - - if (jpaFile == null) { - return null; - } - - JpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaFile.getJpaProject().getJpaPlatform()); - return platformUi.buildStructureProvider(jpaFile); - } - - @Override - protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { - JpaStructurePage page = (JpaStructurePage) pageRecord.page; - removeSelectionChangedListener(page); - page.dispose(); - pageRecord.dispose(); - } - - public JpaSelection getJpaSelection() { - if (getCurrentPage() != getDefaultPage()) { - return ((JpaStructurePage) getCurrentPage()).getJpaSelection(); - } - else { - return JpaSelection.NULL_SELECTION; - } - } - - public void select(JpaSelection 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/AbstractChooserPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractChooserPane.java deleted file mode 100644 index 0c28ac9214..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractChooserPane.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -/** - * A chooser is simply a pane with three widgets, the label on the left, a main - * widget, usually a text field, and a right widget which is usually a browse - * button. - * - * @see ClassChooserPane - * @see PackageChooserPane - * - * @version 2.0 - * @since 2.0 - */ -public abstract class AbstractChooserPane<T extends Model> extends AbstractPane<T> -{ - /** - * The control shown after the label (left control). - */ - private Control mainControl; - - /** - * The control shown after the main control. - */ - private Control rightControl; - - /** - * Creates a new <code>AbstractChooserPane</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public AbstractChooserPane(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>AbstractChooserPane</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public AbstractChooserPane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * Returns the text of the browse button. This method is called by - * {@link #buildRightControl(Composite)}. - * - * @return "Browse..." - */ - protected String browseButtonText() { - return JptUiMessages.AbstractChooserPane_browseButton; - } - - /** - * Creates the action responsible to perform the action when the Browse is - * clicked. - * - * @return A new <code>Runnable</code> performing the actual action of the - * button - */ - protected abstract Runnable buildBrowseAction(); - - /** - * Creates the left control. By default a label is created and its text is - * retrieved by {@link #labelText()}. - * - * @param container The parent container - * @return The newly created left control - */ - protected Control buildLeftControl(Composite container) { - return buildLabel(container, labelText()); - } - - /** - * Creates the main control of this pane. - * - * @param container The parent container - * @return The newly created main control - */ - protected abstract Control buildMainControl(Composite container); - - /** - * Creates the right control. By default a browse button is created and its - * action is performed by {@link #buildBrowseAction()} and its text is - * retrieved by {@link #browseButtonText()}. - * - * @param container The parent container - * @return The newly created right control - */ - protected Control buildRightControl(Composite container) { - return buildButton( - container, - browseButtonText(), - buildBrowseAction() - ); - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - - super.enableWidgets(enabled); - - if (!mainControl.isDisposed()) { - mainControl.setEnabled(enabled); - } - - if (!rightControl.isDisposed()) { - rightControl.setEnabled(enabled); - } - } - - /** - * Returns the help topic ID for the controls of this pane. - * - * @return <code>null</code> is returned otherwise the subclass can return an ID - */ - protected String helpId() { - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - mainControl = buildMainControl(container); - rightControl = buildRightControl(container); - - buildLabeledComposite( - container, - buildLeftControl(container), - mainControl, - rightControl, - helpId() - ); - } - - /** - * The text of the label. This method is called by - * {@link #buildLeftControl(Composite)}. - * - * @return The localized text of the left control (which is a label by - * default) - */ - protected abstract String labelText(); -} 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 deleted file mode 100644 index 5a269e9aa1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialog.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.node.Node; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -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 main content pane of this dialog. - */ - private AbstractDialogPane<?> pane; - - /** - * 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(); - } - - /** - * Initializes the main pane of this dialog. This method is invoked only - * when the dialog is requested to show on screen and not during - * initialization. - * - * @param container The container to which the widgets should be added to, - * the layout is already set - */ - protected abstract AbstractDialogPane<?> buildLayout(Composite container); - - /** - * Creates the state object (model object) that will be used to keep track - * of the information entered in this dialog. The state object will be stored - * in the subject holder and can be retrieved using {@link #subject()}. - * - * @return A new state object - */ - protected T buildStateObject() { - return null; - } - - /** - * Creates the <code>Validator</code> that will be notified when changes are - * made to the state object. - * - * @return The validator that will be set on the state object - */ - Node.Validator buildValidator() { - return Node.NULL_VALIDATOR; - } - - /* - * (non-Javadoc) - */ - @Override - public boolean close() { - - // Dispose the pane in order to remove any listeners that could - // have been installed outside the scrope of the state object - if (pane != null) { - pane.dispose(); - pane = null; - } - - return super.close(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(title()); - } - - /** - * {@inheritDoc} - */ - @Override - public void create() { - super.create(); - installSubject(); - } - - /* - * (non-Javadoc) - */ - @Override - protected Control createContents(Composite parent) { - if (hasTitleArea()) { - return super.createContents(parent); - } - - return createDefaultContent(parent); - } - - /** - * Creates the default main container of this dialog when the title area is - * not required. The top part is the dialog area populated by the subclass - * and the lower part is the button pane having the OK and Cancel buttons. - * - * @param parent The parent container - * @return The - */ - private Composite createDefaultContent(Composite parent) { - - Composite composite = new Composite(parent, SWT.NULL); - - GridLayout layout = new GridLayout(1, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.verticalSpacing = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - applyDialogFont(composite); - initializeDialogUnits(composite); - dialogArea = createDialogArea(composite); - buttonBar = createButtonBar(composite); - - return composite; - } - - /* - * (non-Javadoc) - */ - @Override - protected Composite createDialogArea(Composite parent) { - - // If the title area needs to be shown, then leave the superclass to - // create the necessary widgets - if (hasTitleArea()) { - parent = (Composite) super.createDialogArea(parent); - } - - // Create the main area's container - Composite container = new Composite(parent, SWT.NULL); - container.setLayout(new GridLayout(1, false)); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - container.setLayoutData(gridData); - - // Initialize the content pane - pane = buildLayout(container); - pane.populate(); - - // Initialize the UI part, which requires the widgets being created - initializeUI(); - - return parent; - } - - /** - * Determines whether the description area (where a title, description and - * image) should be visible or hidden. <code>AbstractValidatingDialog</code> - * automatically show the description area in order to show problems. - * - * @return <code>false</code> by default, which means the methods used to - * update the title, description and image shouldn't be called; <code>true</code> - * to make the description pane visible - */ - protected 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>(); - } - - /** - * Initializes the UI part of this dialog, this is called after the widgets - * have been created. - */ - protected void initializeUI() { - } - - /** - * Creates the state object, if one is needed and install a <code>Validator</code> - * in order to receive notification of changes done to that state object. The - * subject can be retrieved from the subject holder. - */ - private void installSubject() { - - T subject = buildStateObject(); - - if (subject != null) { - subject.setValidator(buildValidator()); - } - - 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); - } - - /** - * Gives access to the dialog's main pane. - * - * @return The pane showing the custom widgets - */ - AbstractDialogPane<?> pane() { - return pane; - } - - /** - * 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 subjectHolder.getValue(); - } - - /** - * Returns the holder of the subject. - * - * @return The subject holder used to be passed to the dialog pane, which is - * an instance of <code>AbstractDialogPane</code> - */ - protected final PropertyValueModel<T> subjectHolder() { - return subjectHolder; - } - - /** - * Retrieves the dialog's title. The title passed to the constructor will be - * returned by default but if it wasn't specified, this method can be used - * to return it. - * - * @return Either the title passed to the constructor or a different title - */ - protected String title() { - return title; - } - - /** - * Determines whether the dialog was cancelled or not. - * - * @return <code>true</code> if the dialog was cancelled; <code>false</code> - * if it was confirmed - */ - public final boolean wasCancelled() { - return getReturnCode() == CANCEL; - } - - /** - * Determines whether the dialog was confirmed or not. - * - * @return <code>true</code> if the dialog was confirmed; <code>false</code> - * if it was cancelled - */ - public final boolean wasConfirmed() { - return getReturnCode() == OK; - } -}
\ No newline at end of file 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 deleted file mode 100644 index 18bf5a5868..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractDialogPane.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jpt.utility.internal.node.Node; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; - -/** - * 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, DefaultWidgetFactory.instance()); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractEnumComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractEnumComboViewer.java deleted file mode 100644 index 4c7ff02ba1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractEnumComboViewer.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import java.text.Collator; -import java.util.Arrays; -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.WidgetFactory; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.osgi.util.NLS; -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") -abstract class AbstractEnumComboViewer<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. - */ - public static final String NULL_VALUE = "null"; - - /** - * Creates a new <code>AbstractEnumComboViewer</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - AbstractEnumComboViewer(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>AbstractEnumComboViewer</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - AbstractEnumComboViewer(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * Creates a new <code>AbstractEnumComboViewer</code>. - * - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - AbstractEnumComboViewer(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /** - * 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(); - if (sortChoices()) { - Arrays.sort(choices, buildComparator()); - } - - Object[] extendedChoices = new Object[choices.length + 1]; - System.arraycopy(choices, 0, extendedChoices, 1, choices.length); - extendedChoices[0] = NULL_VALUE; - - return extendedChoices; - } - - /** - * Return true to sort the choices in alphabetical order - * @return - */ - protected boolean sortChoices() { - return true; - } - - /** - * Creates the <code>ComboViewer</code> with the right combo widgets. - * - * @param container The container of the combo - * @return A new <code>ComboViewer</code> containing the right combo widget - */ - abstract ComboViewer buildComboViewer(Composite container); - - 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) { - - return SWTUtil.buildDisplayString(nlsClass, compositeClass, value); - } - - /** - * 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 SWTUtil.buildDisplayString(nlsClass, composite, 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); - } - - final 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); - } - - private ISelectionChangedListener buildSelectionChangedListener() { - return new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent e) { - if (!isPopulating()) { - StructuredSelection selection = (StructuredSelection) e.getSelection(); - valueChanged(selection.getFirstElement()); - } - } - }; - } - - /** - * 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(); - } - - /** - * Returns - * - * @return - */ - final ComboViewer getComboViewer() { - return comboViewer; - } - - /** - * 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 final void initializeLayout(Composite container) { - - this.comboViewer = this.buildComboViewer(container); - this.comboViewer.addSelectionChangedListener(buildSelectionChangedListener()); - } - - /** - * Populates the combo by re-adding all the items. - */ - private void populateCombo() { - - removeAll(); - comboViewer.add(buildChoices()); - updateSelection(); - } - - /* - * (non-Javadoc) - */ - @Override - protected void propertyChanged(String propertyName) { - super.propertyChanged(propertyName); - this.populateCombo(); - } - - /** - * Removes all the items from the combo. - */ - abstract void removeAll(); - - /** - * 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 cursor, which is required to show the entire selected item - * within the combo's area. - */ - abstract void updateCursor(); - - /** - * Updates the combo's selected item. - */ - private void updateSelection() { - comboViewer.setSelection(buildSelection()); - updateCursor(); - } - - /** - * The selection changes, notify the subclass to set the value. - * - * @param value The new selected item - */ - @SuppressWarnings("unchecked") - private void valueChanged(Object value) { - - // Convert the default "null" value to a real null - if (value == NULL_VALUE) { - value = null; - } - - setPopulating(true); - - try { - setValue((V) value); - } - finally { - setPopulating(false); - } - } -} 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 deleted file mode 100644 index 40937a12d5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractFormPane.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.forms.widgets.FormToolkit; - -/** - * 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>AbstractFormPane</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, - WidgetFactory 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, - FormToolkit widgetFactory) { - - this(subjectHolder, parent, new FormWidgetFactory(widgetFactory)); - } - - /** - * Returns the actual widget factory wrapped by the <code>IWidgetFactory</code>. - * - * @return The factory used to create the widgets with the form style - * (flat-style) look and feel - */ - protected final FormToolkit getFormWidgetFactory() { - FormWidgetFactory widgetFactory = (FormWidgetFactory) getWidgetFactory(); - return widgetFactory.getWidgetFactory(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 97705009ad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java +++ /dev/null @@ -1,4423 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.jface.viewers.ILabelProvider; -import org.eclipse.jpt.ui.WidgetFactory; -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.CComboModelAdapter; -import org.eclipse.jpt.ui.internal.swt.ComboModelAdapter; -import org.eclipse.jpt.ui.internal.swt.SpinnerModelAdapter; -import org.eclipse.jpt.ui.internal.swt.TextFieldModelAdapter; -import org.eclipse.jpt.ui.internal.swt.TriStateCheckBoxModelAdapter; -import org.eclipse.jpt.ui.internal.util.ControlAligner; -import org.eclipse.jpt.ui.internal.util.LabeledButton; -import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.StringConverter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyListener; -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.Point; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -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.Spinner; -import org.eclipse.swt.widgets.Table; -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; -import org.eclipse.ui.part.PageBook; - -/** - * 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; - - /** - * - */ - private ArrayList<AbstractPane<?>> internalPanesForEnablementControl; - - /** - * 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 WidgetFactory widgetFactory; - - /** - * The collection of <code>Control</code>s that are displayed in this pane, - * which will have their enablement state updated when - * {@link #enableWidgets(boolean)} is called. - */ - private ArrayList<Control> widgets; - - /** - * 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, - WidgetFactory 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) { - } - - /** - * Indicates that the given <code>Control</code> has its enablement state - * managed by this pane, i.e. through {@link #enableWidgets(boolean)}. - * - * @param control The <code>Control</code> to manage its enablement state - * automatically - * - * @category Layout - */ - public final void addToEnablementControl(Control control) { - control.setData("enablement", null); - } - - private PropertyChangeListener buildAspectChangeListener() { - return new SWTPropertyChangeListenerWrapper(buildAspectChangeListener_()); - } - - private PropertyChangeListener buildAspectChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - //subject() could have changed or is null because of the possibility of - //"jumping" on the UI thread here and a selection change occuring - if (e.getSource() == subject()) { - updatePane(e.getPropertyName()); - } - } - }; - } - - /** - * 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); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - SWTUtil.asyncExec(buttonAction); - } - }); - - if (helpId != null) { - helpSystem().setHelp(button, helpId); - } - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = false; - gridData.horizontalAlignment = GridData.FILL; - button.setLayoutData(gridData); - - return button; - } - - /** - * Creates a new non-editable <code>CCombo</code>. - * - * @param container The parent container - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final CCombo buildCCombo(Composite container) { - - CCombo combo = this.widgetFactory.createCCombo(container); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return combo; - } - - /** - * Creates a new non-editable <code>CCombo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildCCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder) { - - return this.buildCCombo( - container, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance() - ); - } - - /** - * Creates a new non-editable <code>CCombo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildCCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter) { - - CCombo combo = this.buildCCombo(container); - - CComboModelAdapter.adapt( - listHolder, - selectedItemHolder, - combo, - stringConverter - ); - - return combo; - } - - /** - * Creates a new <code>ComboViewer</code> using a <code>CCombo</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 buildCComboViewer(Composite container, - IBaseLabelProvider labelProvider) { - - CCombo combo = this.buildCCombo(container); - ComboViewer viewer = new ComboViewer(combo); - viewer.setLabelProvider(labelProvider); - return viewer; - } - - /** - * 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 <code>Section</code> that can be collapsed. 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 buildCollapsableSection(Composite container, - String sectionText) { - - return this.buildCollapsableSection( - container, - sectionText, - new SimplePropertyValueModel<Boolean>(Boolean.FALSE) - ); - } - - /** - * Creates a new <code>Section</code>. 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 buildCollapsableSection(Composite container, - String sectionText, - int type, - PropertyValueModel<Boolean> expandedStateHolder) { - - Composite subPane = this.buildSection( - container, - sectionText, - ExpandableComposite.TWISTIE | type - ); - - Section section = (Section) subPane.getParent(); - - expandedStateHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - buildExpandedStateChangeListener(section) - ); - - section.setExpanded( - expandedStateHolder.getValue() != null ? expandedStateHolder.getValue() : true - ); - - return subPane; - } - - /** - * Creates a new <code>Section</code>. 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 buildCollapsableSection(Composite container, - String sectionText, - PropertyValueModel<Boolean> expandedStateHolder) { - - return this.buildCollapsableSection( - container, - sectionText, - ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE, - expandedStateHolder - ); - } - - /** - * Creates a new <code>Section</code>. 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 buildCollapsableSubSection(Composite container, - String sectionText, - PropertyValueModel<Boolean> expandedStateHolder) { - - return this.buildCollapsableSection( - container, - sectionText, - SWT.NULL, - expandedStateHolder - ); - } - - /** - * Creates a new non-editable <code>Combo</code>. - * - * @param container The parent container - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final Combo buildCombo(Composite container) { - - Combo combo = this.widgetFactory.createCombo(container); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return combo; - } - - /** - * Creates a new non-editable <code>Combo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder) { - - return this.buildCombo( - container, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance() - ); - } - - /** - * Creates a new non-editable <code>Combo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter) { - - Combo combo = this.buildCombo(container); - - ComboModelAdapter.adapt( - listHolder, - selectedItemHolder, - combo, - stringConverter - ); - - return combo; - } - - /** - * Creates a new <code>ComboViewer</code> using a <code>Combo</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) { - - Combo combo = this.buildCombo(container); - ComboViewer viewer = new ComboViewer(combo); - viewer.setLabelProvider(labelProvider); - return viewer; - } - - /** - * Creates the main container of this pane. The layout and layout data are - * automatically set. - * - * @param parent The parent container - * @return The newly created <code>Composite</code> that will holds all the - * widgets created by this pane through {@link #initializeLayout(Composite)} - * - * @category Layout - */ - protected Composite buildContainer(Composite parent) { - return this.buildSubPane(parent); - } - - /** - * Creates a new editable <code>CCombo</code>. - * - * @param container The parent container - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildEditableCCombo(Composite container) { - - CCombo combo = this.widgetFactory.createEditableCCombo(container); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return combo; - } - - /** - * Creates a new editable <code>CCombo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildEditableCCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder) { - - return this.buildEditableCCombo( - container, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance() - ); - } - - /** - * Creates a new editable <code>CCombo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildEditableCCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter) { - - CCombo combo = this.buildEditableCCombo(container); - - CComboModelAdapter.adapt( - listHolder, - selectedItemHolder, - combo, - stringConverter - ); - - return combo; - } - - /** - * Creates a new editable <code>ComboViewer</code> using a <code>CCombo</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 buildEditableCComboViewer(Composite container, - IBaseLabelProvider labelProvider) { - - CCombo combo = this.buildEditableCCombo(container); - ComboViewer viewer = new ComboViewer(combo); - viewer.setLabelProvider(labelProvider); - return viewer; - } - - /** - * Creates a new editable <code>Combo</code>. - * - * @param container The parent container - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final Combo buildEditableCombo(Composite container) { - - Combo combo = this.widgetFactory.createEditableCombo(container); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return combo; - } - - /** - * Creates a new editable <code>Combo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildEditableCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder) { - - return this.buildEditableCombo( - container, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance() - ); - } - - /** - * Creates a new editable <code>Combo</code>. - * - * @param container The parent container - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildEditableCombo(Composite container, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter) { - - Combo combo = this.buildEditableCombo(container); - - ComboModelAdapter.adapt( - listHolder, - selectedItemHolder, - combo, - stringConverter - ); - - return combo; - } - - /** - * Creates a new editable <code>ComboViewer</code> using a <code>Combo</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 buildEditableComboViewer(Composite container, - IBaseLabelProvider labelProvider) { - - Combo combo = this.buildEditableCombo(container); - ComboViewer viewer = new ComboViewer(combo); - viewer.setLabelProvider(labelProvider); - return viewer; - } - - 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.getNewValue(); - 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> - * - * @category Layout - */ - protected final Hyperlink buildHyperLink(Composite parent, - String text, - final Runnable hyperLinkAction) { - - Hyperlink link = this.widgetFactory.createHyperlink(parent, text); - this.widgets.add(link); - - link.addMouseListener(new MouseAdapter() { - @Override - public void mouseUp(MouseEvent e) { - - Hyperlink hyperLink = (Hyperlink) e.widget; - - if (hyperLink.isEnabled()) { - 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 labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - String helpId) { - - return this.buildLabeledCCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - helpId - ); - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - Control rightControl, - String helpId) { - - CCombo combo = this.buildCCombo( - container, - listHolder, - selectedItemHolder, - stringConverter - ); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - String helpId) { - - return this.buildLabeledCCombo( - container, - labelText, - listHolder, - selectedItemHolder, - stringConverter, - null, - helpId - ); - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param comboListener The listener that will be notified when the selection - * changes - * @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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildLabeledCCombo(Composite container, - String labelText, - ModifyListener comboListener, - Control rightControl, - String helpId) { - - CCombo combo = this.buildCCombo(container); - combo.addModifyListener(comboListener); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * 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 helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildLabeledCCombo(Composite container, - String labelText, - ModifyListener comboListener, - String helpId) { - - return this.buildLabeledCCombo( - container, - labelText, - comboListener, - null, - helpId - ); - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 <V> Combo buildLabeledCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - Control rightControl, - String helpId) { - - return this.buildLabeledCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - rightControl, - helpId - ); - } - - /** - * Creates a new container that will have the given center control labeled - * with the given label. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 <V> Combo buildLabeledCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - String helpId) { - - return this.buildLabeledCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - helpId - ); - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 <V> Combo buildLabeledCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - Control rightControl, - String helpId) { - - Combo combo = this.buildCombo( - container, - listHolder, - selectedItemHolder, - stringConverter - ); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 <V> Combo buildLabeledCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - String helpId) { - - return this.buildLabeledCombo( - container, - labelText, - listHolder, - selectedItemHolder, - stringConverter, - null, - helpId - ); - } - - /** - * Creates a new container that will have a non-editable combo labeled with - * the given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param comboListener The listener that will be notified when the selection - * changes - * @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 Combo buildLabeledCombo(Composite container, - String labelText, - ModifyListener comboListener, - Control rightControl, - String helpId) { - - Combo combo = this.buildCombo(container); - combo.addModifyListener(comboListener); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * 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 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 Combo buildLabeledCombo(Composite container, - String labelText, - ModifyListener comboListener, - String helpId) { - - return this.buildLabeledCombo( - container, - labelText, - comboListener, - null, - helpId - ); - } - - /** - * 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); - this.widgets.add(leftControl); - - // Center control - centerControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - this.widgets.add(centerControl); - - // 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) { - Composite spacer = this.buildPane(container); - spacer.setLayout(this.buildSpacerLayout()); - rightControl = spacer; - } - else { - rightControl.setParent(container); - - // Register the help id for the right control - if (helpId != null) { - helpSystem().setHelp(rightControl, helpId); - } - } - - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL_HORIZONTAL; - gridData.grabExcessHorizontalSpace = false; - - rightControl.setLayoutData(gridData); - this.rightControlAligner.add(rightControl); - this.widgets.add(rightControl); - - 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 - * @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, - Control label, - Control centerControl, - String helpId) { - - return this.buildLabeledComposite( - container, - label, - centerControl, - null, - helpId - ); - } - - /** - * 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 composite labeled - * with the given label text. - * - * @param container The parent container - * @param labelText The text to label the main composite - * @param centerPane 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, - AbstractPane<?> centerPane, - Control rightCentrol, - String helpId) { - - return this.buildLabeledComposite( - container, - labelText, - centerPane.getControl(), - 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 centerPane 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, - AbstractPane<?> centerPane, - String helpId) { - - return this.buildLabeledComposite( - container, - labelText, - centerPane.getControl(), - 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) { - - return this.buildLabeledComposite( - container, - this.buildLabel(container, labelText), - 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 the given center control labeled - * with the given label. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledEditableCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - Control rightControl, - String helpId) { - - return this.buildLabeledEditableCCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - rightControl, - helpId - ); - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledEditableCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - String helpId) { - - return this.buildLabeledEditableCCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - null, - helpId - ); - } - - /** - * Creates a new container that will have the given center control labeled - * with the given label. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledEditableCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - Control rightControl, - String helpId) { - - CCombo combo = this.buildEditableCCombo( - container, - listHolder, - selectedItemHolder, - stringConverter - ); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final <V> CCombo buildLabeledEditableCCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - String helpId) { - - return this.buildLabeledEditableCCombo( - container, - labelText, - listHolder, - selectedItemHolder, - stringConverter, - null, - helpId - ); - } - - /** - * 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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildLabeledEditableCCombo(Composite container, - String labelText, - ModifyListener comboListener, - Control rightControl, - String helpId) { - - CCombo combo = this.buildEditableCCombo(container); - combo.addModifyListener(comboListener); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param comboListener The listener that will be notified when the selection - * changes - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildLabeledEditableCCombo(Composite container, - String labelText, - ModifyListener comboListener, - String helpId) { - - return this.buildLabeledEditableCCombo( - container, - labelText, - comboListener, - null, - helpId - ); - } - - /** - * 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 labelProvider The provider responsible to convert the combo's items - * into human readable strings - * @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 newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildLabeledEditableCComboViewer(Composite container, - String labelText, - ModifyListener comboListener, - ILabelProvider labelProvider, - Control rightControl, - String helpId) { - - ComboViewer comboViewer = this.buildEditableCComboViewer( - container, - labelProvider - ); - - CCombo combo = comboViewer.getCCombo(); - combo.addModifyListener(comboListener); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param comboListener The listener that will be notified when the selection - * changes - * @param labelProvider The provider responsible to convert the combo's items - * into human readable strings - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>CCombo</code> - * - * @category Layout - */ - protected final CCombo buildLabeledEditableCComboViewer(Composite container, - String labelText, - ModifyListener comboListener, - ILabelProvider labelProvider, - String helpId) { - - return this.buildLabeledEditableCComboViewer( - container, - labelText, - comboListener, - null, - helpId - ); - } - - /** - * Creates a new container that will have the given center control labeled - * with the given label. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @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 newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildLabeledEditableCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - Control rightControl, - String helpId) { - - return this.buildLabeledEditableCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - rightControl, - helpId - ); - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildLabeledEditableCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - String helpId) { - - return this.buildLabeledEditableCombo( - container, - labelText, - listHolder, - selectedItemHolder, - StringConverter.Default.<V>instance(), - null, - helpId - ); - } - - /** - * Creates a new container that will have the given center control labeled - * with the given label. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @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 newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildLabeledEditableCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - Control rightControl, - String helpId) { - - Combo combo = this.buildEditableCombo( - container, - listHolder, - selectedItemHolder, - stringConverter - ); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param listHolder The <code>ListValueHolder</code> - * @param selectedItemHolder The holder of the selected item - * @param stringConverter The converter responsible to transform each item - * into a string representation - * @param helpId The topic help ID to be registered for the given center - * compositer - * @return The newly created <code>Combo</code> - * - * @category Layout - */ - protected final <V> Combo buildLabeledEditableCombo(Composite container, - String labelText, - ListValueModel<V> listHolder, - WritablePropertyValueModel<V> selectedItemHolder, - StringConverter<V> stringConverter, - String helpId) { - - return this.buildLabeledEditableCombo( - container, - labelText, - listHolder, - selectedItemHolder, - stringConverter, - null, - helpId - ); - } - - /** - * 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 Combo buildLabeledEditableCombo(Composite container, - String labelText, - ModifyListener comboListener, - Control rightControl, - String helpId) { - - Combo combo = this.buildEditableCombo(container); - combo.addModifyListener(comboListener); - - this.buildLabeledComposite( - container, - labelText, - (combo.getParent() != container) ? combo.getParent() : combo, - rightControl, - helpId - ); - - return combo; - } - - /** - * Creates a new container that will have an editable combo labeled with the - * given text. - * - * @param container The parent container - * @param labelText The text of the label - * @param comboListener The listener that will be notified when the selection - * changes - * @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 Combo buildLabeledEditableCombo(Composite container, - String labelText, - ModifyListener comboListener, - String helpId) { - - return this.buildLabeledEditableCombo( - container, - labelText, - comboListener, - null, - helpId - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text area's label - * @param textHolder The holder of the text field's input - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledMultiLineText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder) { - - return this.buildLabeledMultiLineText( - container, - labelText, - textHolder, - null - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text area's label - * @param textHolder The holder of the text field's input - * @param rightControl The widget to be placed to the right of the text area - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledMultiLineText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - Control rightControl, - String helpId) { - - Text text = this.buildMultiLineText(container, textHolder); - - this.buildLabeledComposite( - container, - labelText, - text, - rightControl, - helpId - ); - - return text; - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text area's label - * @param textHolder The holder of the text field's input - * @param lineCount The number of lines the text area should display - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledMultiLineText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - int lineCount) { - - return this.buildLabeledMultiLineText( - container, - labelText, - textHolder, - lineCount, - null - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text area's label - * @param textHolder The holder of the text field's input - * @param lineCount The number of lines the text area should display - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledMultiLineText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - int lineCount, - String helpId) { - - Text text = this.buildMultiLineText(container, textHolder, lineCount); - - container = this.buildLabeledComposite( - container, - labelText, - text, - helpId - ); - - int textHeight = text.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; - - // Specify the number of lines the text area should display - GridData gridData = (GridData) text.getLayoutData(); - gridData.heightHint = text.getLineHeight() * lineCount; - - // Move the label to the top of its cell - Control label = container.getChildren()[0]; - int labelHeight = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; - - gridData = (GridData) label.getLayoutData(); - gridData.verticalAlignment = SWT.TOP; - gridData.verticalIndent += (Math.abs(textHeight - labelHeight) / 2); - - return text; - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text area's label - * @param textHolder The holder of the text field's input - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledMultiLineText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - String helpId) { - - return this.buildLabeledMultiLineText( - container, - labelText, - textHolder, - 3, - helpId - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledPasswordText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder) { - - return this.buildLabeledPasswordText( - container, - labelText, - textHolder, - null - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text field's label - * @param rightComponent The component to be placed to the right of the text - * field - * @param textHolder The holder of the text field's input - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledPasswordText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - Control rightComponent, - String helpId) { - - Text text = this.buildPasswordText(container, textHolder); - - this.buildLabeledComposite( - container, - labelText, - text, - rightComponent, - helpId - ); - - return text; - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledPasswordText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - String helpId) { - - return this.buildLabeledPasswordText( - container, - labelText, - textHolder, - null, - helpId - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledPawordText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - String helpId) { - - return this.buildLabeledPasswordText( - container, - labelText, - textHolder, - null, - helpId - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param labelText The label's text - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildLabeledSpinner(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue) { - - return this.buildLabeledSpinner( - container, - labelText, - numberHolder, - defaultValue, - 0, - Integer.MAX_VALUE, - null, - null - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param labelText The label's text - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param rightControl The widget to be placed to the right of spinner - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildLabeledSpinner(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - Control rightControl) { - - return this.buildLabeledSpinner( - container, - labelText, - numberHolder, - defaultValue, - 0, - Integer.MAX_VALUE, - rightControl, - null - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param labelText The label's text - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param minimumValue The minimum value that the spinner will allow - * @param maximumValue The maximum value that the spinner will allow - * @param rightControl The widget to be placed to the right of spinner - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildLabeledSpinner(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue, - Control rightControl) { - - return this.buildLabeledSpinner( - parent, - labelText, - numberHolder, - defaultValue, - minimumValue, - maximumValue, - rightControl, - null - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param labelText The label's text - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param minimumValue The minimum value that the spinner will allow - * @param maximumValue The maximum value that the spinner will allow - * @param rightControl The widget to be placed to the right of spinner - * @param helpId The topic help ID to be registered for the spinner - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildLabeledSpinner(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue, - Control rightControl, - String helpId) { - - Spinner spinner = this.buildSpinner( - parent, - numberHolder, - defaultValue, - minimumValue, - maximumValue - ); - - buildLabeledComposite( - parent, - labelText, - (spinner.getParent() != parent) ? spinner.getParent() : spinner, - rightControl, - helpId - ); - - GridData gridData = (GridData) spinner.getLayoutData(); - gridData.horizontalAlignment = GridData.BEGINNING; - - return spinner; - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param labelText The label's text - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param minimumValue The minimum value that the spinner will allow - * @param maximumValue The maximum value that the spinner will allow - * @param helpId The topic help ID to be registered for the spinner - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildLabeledSpinner(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue, - String helpId) { - - return this.buildLabeledSpinner( - parent, - labelText, - numberHolder, - defaultValue, - 0, - Integer.MAX_VALUE, - null, - helpId - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param labelText The label's text - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param helpId The topic help ID to be registered for the spinner - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildLabeledSpinner(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - String helpId) { - - return this.buildLabeledSpinner( - parent, - labelText, - numberHolder, - defaultValue, - 0, - Integer.MAX_VALUE, - null, - null - ); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder) { - - return this.buildLabeledText(container, labelText, textHolder, null); - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param labelText The text field's label - * @param rightComponent The component to be placed to the right of the text - * field - * @param textHolder The holder of the text field's input - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - Control rightComponent, - String helpId) { - - Text text = this.buildText(container); - TextFieldModelAdapter.adapt(textHolder, text); - - this.buildLabeledComposite( - container, - labelText, - text, - rightComponent, - helpId - ); - - return text; - } - - /** - * Creates a new container that will have a text field as the center control - * labeled with the given label. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @param helpId The topic help ID to be registered for the text field - * @return The newly created <code>Text</code> - * - * @category Layout - */ - protected final Text buildLabeledText(Composite container, - String labelText, - WritablePropertyValueModel<String> textHolder, - String helpId) { - - return this.buildLabeledText( - container, - labelText, - textHolder, - null, - 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 - * @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)); - list.setLayoutData(new GridData(GridData.FILL_BOTH)); - this.widgets.add(list); - - if (helpId != null) { - helpSystem().setHelp(list, helpId); - } - - return list; - } - - /** - * Creates a new lable expanding on multiple lines. - * - * @param parent The parent container - * @param labelText The label's text - * - * @category Layout - */ - protected final void buildMultiLineLabel(Composite container, - String labelText) { - - this.widgetFactory.createMultiLineLabel(container, labelText); - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @param container The parent container - * @return The newly created <code>Text</code> widget - * - * @category Layout - */ - protected final Text buildMultiLineText(Composite container) { - return this.buildMultiLineText(container, 3, null); - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @param container The parent container - * @param lineCount The number of lines the text area should display - * @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 buildMultiLineText(Composite container, - int lineCount, - String helpId) { - - Text text = this.widgetFactory.createMultiLineText(container); - - GridData gridData = new GridData(GridData.FILL_HORIZONTAL); - gridData.heightHint = text.getLineHeight() * lineCount; - text.setLayoutData(gridData); - - if (helpId != null) { - helpSystem().setHelp(text, helpId); - } - - return text; - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @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 buildMultiLineText(Composite container, String helpId) { - - return this.buildMultiLineText(container, 3, helpId); - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @return The newly created <code>Text</code> widget - * - * @category Layout - */ - protected final Text buildMultiLineText(Composite container, - WritablePropertyValueModel<String> textHolder) { - - return this.buildMultiLineText(container, textHolder, null); - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @param lineCount The number of lines the text area should display - * @return The newly created <code>Text</code> widget - * - * @category Layout - */ - protected final Text buildMultiLineText(Composite container, - WritablePropertyValueModel<String> textHolder, - int lineCount) { - - return this.buildMultiLineText(container, textHolder, lineCount, null); - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @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 buildMultiLineText(Composite container, - WritablePropertyValueModel<String> textHolder, - int lineCount, - String helpId) { - - Text text = this.buildMultiLineText(container, lineCount, helpId); - TextFieldModelAdapter.adapt(textHolder, text); - return text; - } - - /** - * Creates a new <code>Text</code> widget that has multiple lines. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @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 buildMultiLineText(Composite container, - WritablePropertyValueModel<String> textHolder, - String helpId) { - - return this.buildMultiLineText(container, textHolder, 3, helpId); - } - - /** - * Creates a new <code>PageBook</code> and set the proper layout and layout - * data. - * - * @param container The parent container - * @return The newly created <code>PageBook</code> - * - * @category Layout - */ - protected final PageBook buildPageBook(Composite container) { - - PageBook pageBook = new PageBook(container, SWT.NULL); - pageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return pageBook; - } - - /** - * 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 container, Layout layout) { - - container = this.widgetFactory.createComposite(container); - container.setLayout(layout); - container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return container; - } - - /** - * Creates a new <code>Text</code> widget. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @return The newly created <code>Text</code> widget - * - * @category Layout - */ - protected final Text buildPasswordText(Composite container, - WritablePropertyValueModel<String> textHolder) { - - Text text = this.widgetFactory.createPasswordText(container); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - TextFieldModelAdapter.adapt(textHolder, text); - - return text; - } - - /** - * 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.createPushButton(parent, buttonText); - - 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>. 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>. 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) { - - return this.buildSection(container, sectionText, null, type); - } - - /** - * Creates a new <code>Section</code>. 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 description The section's description - * @return The <code>Section</code>'s sub-pane - * - * @category Layout - */ - protected final Composite buildSection(Composite container, - String sectionText, - String description) { - - return this.buildSection( - container, - sectionText, - description, - ExpandableComposite.TITLE_BAR - ); - } - - /** - * Creates a new <code>Section</code>. 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 description The section's description or <code>null</code> if none - * was provider - * @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, - String description, - int type) { - - Section section = this.widgetFactory.createSection(container, type | ((description != null) ? Section.DESCRIPTION : SWT.NULL)); - section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - section.setText(sectionText); - section.marginWidth = 0; - section.marginHeight = 0; - - if (description != null) { - section.setDescription(description); - } - - Composite subPane = this.buildSubPane(section); - section.setClient(subPane); - - return subPane; - } - - 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]); - } - } - }; - } - - /** - * Creates the layout responsible to compute the size of the spacer created - * for the right control when none was given. The spacer helps to align all - * the right controls. - * - * @category Layout - */ - private Layout buildSpacerLayout() { - return new Layout() { - @Override - protected Point computeSize(Composite composite, - int widthHint, - int heightHint, - boolean flushCache) { - - return new Point(widthHint, heightHint); - } - - @Override - protected void layout(Composite composite, boolean flushCache) { - GridData data = (GridData) composite.getLayoutData(); - composite.setBounds(0, 0, data.widthHint, data.heightHint); - } - }; - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildSpinner(Composite parent, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue) { - - return this.buildSpinner( - parent, - numberHolder, - defaultValue, - 0, - Integer.MAX_VALUE - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param minimumValue The minimum value that the spinner will allow - * @param maximumValue The maximum value that the spinner will allow - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildSpinner(Composite parent, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue) { - - return this.buildSpinner( - parent, - numberHolder, - defaultValue, - minimumValue, - maximumValue, - null - ); - } - - /** - * Creates a new spinner. - * - * @param parent The parent container - * @param numberHolder The holder of the integer value - * @param defaultValue The value shown when the holder has <code>null</code> - * @param minimumValue The minimum value that the spinner will allow - * @param maximumValue The maximum value that the spinner will allow - * @param helpId The topic help ID to be registered for the new button - * @return The newly created <code>Spinner</code> - * - * @category Layout - */ - protected final Spinner buildSpinner(Composite parent, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue, - String helpId) { - - Spinner spinner = this.widgetFactory.createSpinner(parent); - spinner.setMinimum(minimumValue); - spinner.setMaximum(maximumValue); - spinner.setLayoutData(new GridData(GridData.BEGINNING)); - - SpinnerModelAdapter.adapt(numberHolder, spinner, defaultValue); - - if (helpId != null) { - helpSystem().setHelp(spinner, helpId); - } - - return spinner; - } - - private PropertyChangeListener buildSubjectChangeListener() { - return new SWTPropertyChangeListenerWrapper(this.buildSubjectChangeListener_()); - } - - private PropertyChangeListener buildSubjectChangeListener_() { - return new PropertyChangeListener() { - @SuppressWarnings("unchecked") - public void propertyChanged(PropertyChangeEvent e) { - AbstractPane.this.subjectChanged((T) e.getOldValue(), (T) e.getNewValue()); - } - }; - } - - /** - * 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; - - container = this.buildPane(container, layout); - - return container; - } - - /** - * Creates a new <code>Section</code>. 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.buildCollapsableSubSection( - container, - sectionText, - new SimplePropertyValueModel<Boolean>(Boolean.TRUE) - ); - } - - /** - * Creates a new table. - * - * @param container The parent container - * @return The newly created <code>Table</code> - * - * @category Layout - */ - protected final Table buildTable(Composite container) { - return this.buildTable(container, null); - } - - /** - * Creates a new table. - * - * @param container The parent container - * @param style The style to apply to the table - * @return The newly created <code>Table</code> - * - * @category Layout - */ - protected final Table buildTable(Composite container, int style) { - return this.buildTable(container, style, null); - } - - /** - * Creates a new table. - * - * @param container The parent container - * @param style The style to apply to the table - * @param helpId The topic help ID to be registered for the new table or - * <code>null</code> if no help ID is required - * @return The newly created <code>Table</code> - * - * @category Layout - */ - protected final Table buildTable(Composite container, - int style, - String helpId) { - - Table table = this.widgetFactory.createTable(container, style); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - GridData gridData = new GridData(GridData.FILL_BOTH); - gridData.heightHint = table.getItemHeight() * 4; - table.setLayoutData(gridData); - this.widgets.add(table); - - if (helpId != null) { - helpSystem().setHelp(table, helpId); - } - - return table; - } - - /** - * Creates a new table. - * - * @param container The parent container - * @param helpId The topic help ID to be registered for the new table or - * <code>null</code> if no help ID is required - * @return The newly created <code>Table</code> - * - * @category Layout - */ - protected final Table buildTable(Composite container, String helpId) { - - return this.buildTable( - container, - SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.MULTI, - helpId - ); - } - - /** - * Creates a new <code>Text</code> widget. - * - * @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. - * - * @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); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - if (helpId != null) { - helpSystem().setHelp(text, helpId); - } - - return text; - } - - /** - * Creates a new <code>Text</code> widget. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @return The newly created <code>Text</code> widget - * - * @category Layout - */ - protected final Text buildText(Composite container, - WritablePropertyValueModel<String> textHolder) { - - return this.buildText(container, textHolder, null); - } - - /** - * Creates a new <code>Text</code> widget. - * - * @param container The parent container - * @param textHolder The holder of the text field's input - * @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, - WritablePropertyValueModel<String> textHolder, - String helpId) { - - Text text = this.widgetFactory.createText(container); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - TextFieldModelAdapter.adapt(textHolder, text); - - 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); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - GridLayout layout = new GridLayout(1, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 5; - layout.marginLeft = 5; - layout.marginBottom = 5; - layout.marginRight = 5; - group.setLayout(layout); - - 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; - - if (toggleButtonType == SWT.PUSH) { - button = this.widgetFactory.createPushButton(parent, buttonText); - } - else if (toggleButtonType == SWT.RADIO) { - button = this.widgetFactory.createRadioButton(parent, buttonText); - } - else if (toggleButtonType == SWT.CHECK) { - button = this.widgetFactory.createCheckBox(parent, buttonText); - } - else { - button = this.widgetFactory.createButton(parent, buttonText); - } - - button.setLayoutData(new GridData()); - BooleanButtonModelAdapter.adapt(booleanHolder, button); - this.widgets.add(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> - * - * @category Layout - */ - 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> - * - * @category Layout - */ - protected final TriStateCheckBox buildTriStateCheckBox(Composite parent, - String text, - WritablePropertyValueModel<Boolean> booleanHolder, - String helpId) { - - TriStateCheckBox checkBox = new TriStateCheckBox( - parent, - text, - this.getWidgetFactory() - ); - - TriStateCheckBoxModelAdapter.adapt( - booleanHolder, - checkBox - ); - - this.widgets.add(checkBox.getCheckBox()); - - if (helpId != null) { - helpSystem().setHelp(checkBox.getCheckBox(), 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> - * - * @category Layout - */ - 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> - * - * @category Layout - */ - 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 LabeledButton(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(Tracing.UI_LAYOUT, " ->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(Tracing.UI_LAYOUT, "dispose()"); - this.performDispose(); - this.disengageListeners(); - } - } - - /** - * Requests this pane to dispose itself. - * - * @category Populate - */ - protected void doDispose() { - this.log(Tracing.UI_LAYOUT, " ->doDispose()"); - - this.leftControlAligner.dispose(); - this.rightControlAligner.dispose(); - } - - /** - * Requests this pane to populate its widgets with the subject's values. - * - * @category Populate - */ - protected void doPopulate() { - this.log(Tracing.UI_LAYOUT, " ->doPopulate()"); - } - - /** - * Changes the enablement state of the children <code>Control</code>s. - * - * @param enabled <code>true</code> to enable the widgets or <code>false</code> - * to disable them - * - * @category Layout - */ - private void enableChildren(boolean enabled) { - - // Only update the enablement state of the child widgets if this pane - // has its enablement managed by enableWidgets() (i.e. not done manually) - if (this.isEnablementManaged(container)) { - - for (Control control : this.widgets) { - - // Make sure to check if the child control doesn't have its - // enablement state manually managed - if (this.isEnablementManaged(control)) { - control.setEnabled(enabled); - } - } - } - } - - /** - * 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) { - - if (!container.isDisposed()) { - this.enableChildren(enabled); - - for (AbstractPane<?> subPane : this.subPanes) { - if (this.isPaneEnablementManaged(subPane)) { - subPane.enableWidgets(enabled); - } - } - } - } - - /** - * Installs the listeners on the subject in order to be notified from changes - * made outside of this panes and notifies the sub-panes to do the same. - * - * @category Populate - */ - protected void engageListeners() { - - this.log(Tracing.UI_LAYOUT, " ->engageListeners()"); - - this.engageSubjectHolder(); - 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); - } - } - } - - private void engageSubjectHolder() { - this.subjectHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - this.subjectChangeListener - ); - } - - /** - * 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 the factory responsible for creating the widgets. - * - * @return The factory used by this pane to create the widgets - * - * @category Layout - */ - protected final WidgetFactory 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(SWTUtil.getShell(), ""); - 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, - WidgetFactory widgetFactory) - { - Assert.isNotNull(subjectHolder, "The subject holder cannot be null"); - - this.subjectHolder = (PropertyValueModel<T>) subjectHolder; - this.widgetFactory = widgetFactory; - this.subPanes = new ArrayList<AbstractPane<?>>(); - this.widgets = new ArrayList<Control>(); - this.leftControlAligner = new ControlAligner(); - this.rightControlAligner = new ControlAligner(); - this.subjectChangeListener = this.buildSubjectChangeListener(); - this.aspectChangeListener = this.buildAspectChangeListener(); - this.internalPanesForEnablementControl = new ArrayList<AbstractPane<?>>(); - - this.initialize(); - } - - /** - * Initializes the layout of this pane. - * - * @param container The parent container - * - * @category Layout - */ - protected abstract void initializeLayout(Composite container); - - /** - * Determines whether the enablement state is managed by this pane or is - * manually managed. - * - * @param control The <code>Control</code> to verify how its enablement state - * is managed - * @return <code>true</code> if the enablement state can be changed when - * {@link #enableWidgets(boolean)} is called; <code>false</code> if its - * enablement state is manually changed - */ - public final boolean isEnablementManaged(Control control) { - return control.getData("enablement") != Boolean.FALSE; - } - - /** - * Determines whether the given pane has its enablement state managed by this - * pane. - * - * @param subPane The sub-pane to verify how its enablement state is being - * managed - * @return <code>true</code> if the sub-pane's enablement state is managed by - * this state; <code>false</code> if it's manually managed - * - * @category Layout - */ - private boolean isPaneEnablementManaged(AbstractPane<?> subPane) { - - return // Test 1: This pane is being automatically managed and the - // sub-pane was registered has an internal pane, which means its - // enablement state is being managed automatically as well. A - // sub-pane is managed automatically only when PaneEnabler changes - // the enablement management checks - this.isEnablementManaged(container) && - this.internalPanesForEnablementControl.contains(subPane) || - - // Test 2: Check to see if the pane is automatically managed - this.isEnablementManaged(subPane.getControl()); - } - - /** - * 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 flag - * @param message The logging message - */ - protected void log(String flag, String message) { - - if (Tracing.UI_LAYOUT.equals(flag) && - 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(Tracing.UI_LAYOUT, " ->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(Tracing.UI_LAYOUT, "populate()"); - this.engageListeners(); - this.repopulate(); - } - } - - /** - * 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 <code>AbstractPane</code>'s <code>Control</code> from - * having its enablement state managed by this pane. However, if this pane - * has its enablement state modified, the given pane will receive that - * notification. - * - * @param pane The pane to have its enablement state not managed by this pane - */ - public void removeFromEnablementControl(AbstractPane<?> pane) { - this.removeFromEnablementControl(pane.getControl()); - this.internalPanesForEnablementControl.add(pane); - } - - /** - * Removes the given <code>Control</code> from having its enablement state - * being managed by this pane. - * - * @param control The <code>Control</code> that has its enablement state - * manually controlled - */ - public void removeFromEnablementControl(Control control) { - control.setData("enablement", Boolean.FALSE); - } - - /** - * 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(Tracing.UI_LAYOUT, " ->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 - * @category Populate - */ - protected boolean repopulateWithNullSubject() { - return true; - } - - /** - * Sets the internal flag that is used to determine whether the pane is being - * populated or not. During population, it is required to not update the - * widgets when the model is updated nor to update the model when the widgets - * are being synchronized with the model's values. - * - * @param populating - * - * @category Populate - */ - protected final void setPopulating(boolean populating) { - this.populating = populating; - } - - /** - * Either show or hides this pane. - * - * @param visible The new visibility state - */ - public void setVisible(boolean visible) { - if (!this.container.isDisposed()) { - this.container.setVisible(visible); - } - } - - /** - * 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.getValue(); - } - - /** - * The subject has changed, disconnects any listeners from the old subject - * and connects those listeners onto the new subject. - * - * @param oldsubject The old subject or <code>null</code> if none was set - * @param newSubject The new subject or <code>null</code> if none needs to be - * set - * - * @category Populate - */ - protected final void subjectChanged(T oldSubject, T newSubject) { - if (!this.container.isDisposed()) { - - this.log(Tracing.UI_LAYOUT, "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 (!isPopulating() && !container.isDisposed()) { - populating = true; - - try { - propertyChanged(propertyName); - } - finally { - populating = false; - } - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index 4b70fcd78e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractValidatingDialog.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -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 - final Node.Validator buildValidator() { - return new Node.Validator() { - public void pause() { - } - - public void resume() { - } - - public void validate() { - AbstractValidatingDialog.this.validate(); - } - }; - } - - /** - * Clears the error message from the description pane. - */ - protected final void clearErrorMessage() { - setErrorMessage(null); - } - - /** - * Returns the description shown in the description pane. - * - * @return The description under the description's title - */ - protected String description() { - return null; - } - - /** - * Returns the image shown in the description pane. - * - * @return The image of the description pane or <code>null</code> if none is - * required - */ - protected Image descriptionImage() { - return null; - } - - /** - * Returns the title of the description pane. - * - * @return The title shown in the description pane - */ - protected String descriptionTitle() { - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected Point getInitialSize() { - Point result = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); - Point paneSize = pane().getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT); - int width = convertHorizontalDLUsToPixels(400); - result.x = Math.max(width, paneSize.x); - return result; - } - - /* - * (non-Javadoc) - */ - @Override - protected final boolean hasTitleArea() { - return true; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeUI() { - - super.initializeUI(); - - // Update the description title - String descriptionTitle = descriptionTitle(); - - if (descriptionTitle != null) { - setTitle(descriptionTitle); - } - - // Update the description title - String description = description(); - - if (description != null) { - setMessage(description); - } - - // Update the description image - Image image = descriptionImage(); - - if (image != null) { - setTitleImage(image); - } - } - - /** - * Updates the description pane by showing the given error message and format - * the text with the given list of arguments if any exists. - * - * @param errorMessage The error message to show in the description pane - * @param arguments The list of arguments used to format the error message - */ - protected final void setErrorMessage(String errorMessage, Object... arguments) { - setErrorMessage(NLS.bind(errorMessage, arguments)); - } - - /** - * 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(); - setErrorMessage(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(); - } - } - - /** - * Validates the state object and based on its status, update the description - * pane to show the first error if any exists and update the enablement of - * the OK button. - */ - private void validate() { - subject().validateBranch(); - updateErrorMessage(); - getButton(OK).setEnabled(!subject().hasBranchProblems()); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 5797e748bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java +++ /dev/null @@ -1,547 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.ui.internal.swt.ColumnAdapter; -import org.eclipse.jpt.ui.internal.swt.TableModelAdapter; -import org.eclipse.jpt.ui.internal.swt.TableModelAdapter.SelectionChangeEvent; -import org.eclipse.jpt.ui.internal.swt.TableModelAdapter.SelectionChangeListener; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Layout; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; - -/** - * This implementation of the <code>AddRemovePane</code> uses a <code>Table</code> - * as its main widget, a <code>List</code> can't be used because it doesn't - * support showing images. However, the table is displayed like a list. - * <p> - * Here the layot of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------- ----------- | - * | | Item 1 | | Add... | | - * | | ... | ----------- | - * | | Item n | ----------- | - * | | | | Edit... | | - * | | | ----------- | - * | | | ----------- | - * | | | | Remove | | - * | | | ----------- | - * | ------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 1.0 - */ -@SuppressWarnings("nls") -public class AddRemoveListPane<T extends Model> extends AddRemovePane<T> -{ - /** - * Flag used to prevent circular - */ - private boolean locked; - - /** - * The main widget of this add/remove pane. - */ - private Table table; - - /** - * 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 table 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 table 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 table 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 table 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 ColumnAdapter<Object> buildColumnAdapter() { - return new ColumnAdapter<Object>() { - public WritablePropertyValueModel<?>[] cellModels(Object subject) { - WritablePropertyValueModel<?>[] valueHolders = new WritablePropertyValueModel<?>[1]; - valueHolders[0] = new SimplePropertyValueModel<Object>(subject); - return valueHolders; - } - - public int columnCount() { - return 1; - } - - public String columnName(int columnIndex) { - return ""; - } - }; - } - - private ListChangeListener buildListChangeListener() { - return new SWTListChangeListenerWrapper(buildListChangeListener_()); - } - - private ListChangeListener buildListChangeListener_() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent e) { - if (!table.isDisposed()) { - table.getParent().layout(); - } - } - - public void itemsMoved(ListChangeEvent e) { - if (!table.isDisposed()) { - table.getParent().layout(); - } - } - - public void itemsRemoved(ListChangeEvent e) { - if (!table.isDisposed()) { - table.getParent().layout(); - } - } - - public void itemsReplaced(ListChangeEvent e) { - if (!table.isDisposed()) { - table.getParent().layout(); - } - } - - public void listChanged(ListChangeEvent e) { - if (!table.isDisposed()) { - table.getParent().layout(); - } - } - - public void listCleared(ListChangeEvent e) { - if (!table.isDisposed()) { - table.getParent().layout(); - } - } - }; - } - - private SimplePropertyValueModel<Object> buildSelectedItemHolder() { - return new SimplePropertyValueModel<Object>(); - } - - private PropertyChangeListener buildSelectedItemPropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper( - buildSelectedItemPropertyChangeListener_() - ); - } - - private PropertyChangeListener buildSelectedItemPropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - if (table.isDisposed()) { - return; - } - - if (!locked) { - locked = true; - - try { - Object value = e.getNewValue(); - getSelectionModel().setSelectedValue(e.getNewValue()); - int index = -1; - - if (value != null) { - index = CollectionTools.indexOf(getListHolder().iterator(), value); - } - - table.select(index); - updateButtons(); - } - finally { - locked = false; - } - } - } - }; - } - - private SelectionChangeListener<Object> buildSelectionListener() { - return new SelectionChangeListener<Object>() { - public void selectionChanged(SelectionChangeEvent<Object> e) { - AddRemoveListPane.this.selectionChanged(); - } - }; - } - - private Composite buildTableContainer(Composite container) { - - container = buildPane(container, buildTableContainerLayout()); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - return container; - } - - private Layout buildTableContainerLayout() { - return new Layout() { - @Override - protected Point computeSize(Composite composite, - int widthHint, - int heightHint, - boolean flushCache) { - - Table table = (Table) composite.getChildren()[0]; - packColumn(table); - - // Calculate the table size and adjust it with the hints - Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); - - if (widthHint != SWT.DEFAULT) { - size.x = widthHint; - } - - if (heightHint != SWT.DEFAULT) { - size.y = heightHint; - } - - return size; - } - - private boolean isVerticalScrollbarBarVisible(Table table, - Rectangle clientArea) { - - // Get the height of all the rows - int height = table.getItemCount() * table.getItemHeight(); - - // Remove the border from the height - height += (table.getBorderWidth() * 2); - - return (clientArea.height < height); - } - - @Override - protected void layout(Composite composite, boolean flushCache) { - - Rectangle bounds = composite.getClientArea(); - - if (bounds.width > 0) { - - Table table = (Table) composite.getChildren()[0]; - table.setBounds(0, 0, bounds.width, bounds.height); - - updateTableColumnWidth( - table, - bounds.width, - isVerticalScrollbarBarVisible(table, bounds) - ); - } - } - - private void packColumn(Table table) { - - TableColumn tableColumn = table.getColumn(0); - - table.setRedraw(false); - table.setLayoutDeferred(true); - tableColumn.pack(); - table.setLayoutDeferred(false); - table.setRedraw(true); - - // Cache the column width so it can be used in - // updateTableColumnWidth() when determine which width to use - table.setData( - "column.width", - Integer.valueOf(tableColumn.getWidth()) - ); - } - - private void updateTableColumnWidth(Table table, - int width, - boolean verticalScrollbarBarVisible) { - - // Remove the border from the width - width -= (table.getBorderWidth() * 2); - - // Remove the scrollbar from the width if it is shown - if (verticalScrollbarBarVisible) { - width -= table.getVerticalBar().getSize().x; - } - - TableColumn tableColumn = table.getColumn(0); - - // Retrieve the cached column width, which is required for - // determining which width to use (the column width or the - // calculated width) - Integer columnWitdh = (Integer) table.getData("column.width"); - - // Use the calculated width if the column is smaller, otherwise - // use the column width and a horizontal scroll bar will show up - width = Math.max(width, columnWitdh); - - // Adjust the column width - tableColumn.setWidth(width); - } - }; - } - - private ITableLabelProvider buiTableLabelProvider(IBaseLabelProvider labelProvider) { - return new TableLabelProvider((ILabelProvider) labelProvider); - } - - /* - * (non-Javadoc) - */ - @Override - public Table getMainControl() { - return table; - } - - /* - * (non-Javadoc) - */ - @Override - @SuppressWarnings("unchecked") - protected void initializeMainComposite(Composite container, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider labelProvider, - String helpId) { - - table = buildTable( - buildTableContainer(container), - SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI, - helpId - ); - - removeFromEnablementControl(table); - - TableModelAdapter model = TableModelAdapter.adapt( - (ListValueModel<Object>) listHolder, - buildSelectedItemHolder(), - table, - buildColumnAdapter(), - buiTableLabelProvider(labelProvider) - ); - - model.addSelectionChangeListener(buildSelectionListener()); - - selectedItemHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - buildSelectedItemPropertyChangeListener() - ); - - listHolder.addListChangeListener( - ListValueModel.LIST_VALUES, - buildListChangeListener() - ); - - initializeTable(table); - } - - /** - * Initializes the given table, which acts like a list in our case. - * - * @param table The main widget of this pane - */ - protected void initializeTable(Table table) { - - table.setData("column.width", new Integer(0)); - table.setHeaderVisible(false); - table.setLinesVisible(false); - } - - /** - * The selection has changed, update (1) the selected item holder, (2) the - * selection model and (3) the buttons. - */ - private void selectionChanged() { - - if (locked) { - return; - } - - locked = true; - - try { - WritablePropertyValueModel<Object> selectedItemHolder = getSelectedItemHolder(); - ObjectListSelectionModel selectionModel = getSelectionModel(); - int selectionCount = table.getSelectionCount(); - - if (selectionCount == 0) { - selectedItemHolder.setValue(null); - selectionModel.clearSelection(); - } - else if (selectionCount != 1) { - selectedItemHolder.setValue(null); - selectionModel.clearSelection(); - - for (int index : table.getSelectionIndices()) { - selectionModel.addSelectionInterval(index, index); - } - } - else { - int selectedIndex = table.getSelectionIndex(); - Object selectedItem = getListHolder().get(selectedIndex); - - selectedItemHolder.setValue(selectedItem); - selectionModel.setSelectedValue(selectedItem); - } - - updateButtons(); - } - finally { - locked = false; - } - } - - /** - * This label provider simply delegates the rendering to the provided - * <code>ILabelProvider</code>. - */ - private class TableLabelProvider extends LabelProvider - implements ITableLabelProvider { - - private ILabelProvider labelProvider; - - TableLabelProvider(ILabelProvider labelProvider) { - super(); - this.labelProvider = labelProvider; - } - - public Image getColumnImage(Object element, int columnIndex) { - return labelProvider.getImage(element); - } - - public String getColumnText(Object element, int columnIndex) { - return labelProvider.getText(element); - } - } -}
\ No newline at end of file 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 deleted file mode 100644 index 2a1df95058..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java +++ /dev/null @@ -1,860 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import java.util.Arrays; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; - -/** - * The abstract definition of a pane that has buttons for adding, removing and - * possibly editing the items. - * - * @see AddRemoveListPane - * - * @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 boolean enabled; - private IBaseLabelProvider 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, - IBaseLabelProvider 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, - IBaseLabelProvider 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, - IBaseLabelProvider 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, - IBaseLabelProvider labelProvider, - String helpId) { - - super(parentPane, subjectHolder, parent); - - initialize( - adapter, - listHolder, - selectedItemHolder, - labelProvider - ); - - initializeLayout( - adapter, - listHolder, - selectedItemHolder, - labelProvider, - helpId - ); - } - - /** - * Gives the possibility to add buttons after the Add button and before the - * optional button. - * - * @param container The parent container - * @param helpId The topic help ID to be registered with the buttons - * - * @category Layout - */ - protected void addCustomButtonAfterAddButton(Composite container, - String helpId) { - } - - /** - * Gives the possibility to add buttons after the optional button and before - * the Remove button. - * - * @param container The parent container - * @param helpId The topic help ID to be registered with the buttons - * - * @category Layout - */ - protected void addCustomButtonAfterOptionalButton(Composite container, - String 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 buildListChangeListener() { - return new SWTListChangeListenerWrapper(buildListChangeListener_()); - } - - private ListChangeListener buildListChangeListener_() { - return new ListChangeListener() { - - public void itemsAdded(ListChangeEvent e) { - } - - public void itemsMoved(ListChangeEvent e) { - } - - public void itemsRemoved(ListChangeEvent e) { - Object selectedItem = selectedItemHolder.getValue(); - - if (selectedItem == null) { - updateButtons(); - return; - } - - if (CollectionTools.contains(e.items(), selectedItem)) { - selectedItemHolder.setValue(null); - updateButtons(); - } - } - - public void itemsReplaced(ListChangeEvent e) { - } - - public void listChanged(ListChangeEvent e) { - } - - public void listCleared(ListChangeEvent e) { - selectedItemHolder.setValue(null); - updateButtons(); - } - }; - } - - /** - * @category Option - */ - private Runnable buildOptionalAction() { - return new Runnable() { - public void run() { - AddRemovePane.this.editItem(); - } - }; - } - - /** - * @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)); - } - - /** - * @category Option - */ - protected void editItem() { - this.adapter.optionOnSelection(getSelectionModel()); - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - - super.enableWidgets(enabled); - this.enabled = enabled; - - if (!this.getMainControl().isDisposed()) { - this.getMainControl().setEnabled(enabled); - } - - this.updateButtons(); - } - - protected final Composite getContainer() { - return container; - } - - protected IBaseLabelProvider getLabelProvider() { - return labelProvider; - } - - protected final ListValueModel<?> getListHolder() { - return listHolder; - } - - /** - * Returns - * - * @return - */ - public abstract Composite getMainControl(); - - protected final WritablePropertyValueModel<Object> getSelectedItemHolder() { - return selectedItemHolder; - } - - public final ObjectListSelectionModel getSelectionModel() { - return selectionModel; - } - - /** - * Initializes this add/remove pane. - * - * @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 - * - * @category Initialization - */ - @SuppressWarnings("unchecked") - protected void initialize(Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider 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)); - - this.listHolder.addListChangeListener( - ListValueModel.LIST_VALUES, - buildListChangeListener() - ); - } - - /** - * Initializes the pane containing the buttons (Add, optional (if required) - * and Remove). - * - * @param container The parent container - * @param helpId The topic help ID to be registered with the buttons - * - * @category Layout - */ - protected void initializeButtonPane(Composite container, String helpId) { - - container = buildSubPane(container); - - GridData gridData = new GridData(); - gridData.grabExcessVerticalSpace = true; - gridData.verticalAlignment = SWT.TOP; - container.setLayoutData(gridData); - - // Add button - addButton = buildAddButton(container); - addAlignRight(addButton); - removeFromEnablementControl(addButton); - - // Custom button - addCustomButtonAfterAddButton(container, helpId); - - // Optional button - if (adapter.hasOptionalButton()) { - optionalButton = buildOptionalButton(container); - removeFromEnablementControl(optionalButton); - addAlignRight(optionalButton); - } - - // Custom button - addCustomButtonAfterOptionalButton(container, helpId); - - // Remove button - removeButton = buildRemoveButton(container); - removeFromEnablementControl(removeButton); - 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); - } - } - } - - /** - * Initializes this add/remove pane by creating the widgets. The subclass is - * required to build the main widget. - * - * @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 - * - * @category Layout - */ - protected void initializeLayout(Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider labelProvider, - String helpId) { - - initializeMainComposite( - container, - adapter, - listHolder, - selectedItemHolder, - labelProvider, - helpId); - - initializeButtonPane(container, helpId); - enableWidgets(subject() != null); - } - - /** - * {@inheritDoc} - */ - @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 - * - * @category Layout - */ - protected abstract void initializeMainComposite(Composite container, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider labelProvider, - String helpId); - - /** - * @category Remove - */ - protected void removeItems() { - - // Keep track of the selected indices so we can select an item - // before the lowest index - int[] indices = selectionModel.selectedIndices(); - Arrays.sort(indices); - - // Notify the adapter to remove the selected items - adapter.removeSelectedItems(selectionModel); - - // Select a new item - if (getListHolder().size() > 0) { - int index = Math.min(indices[0], getListHolder().size() - 1); - Object item = getListHolder().get(index); - selectedItemHolder.setValue(item); - } - // The list is empty, clear the value - else { - selectedItemHolder.setValue(null); - } - } - - /** - * Selects the given value, which can be <code>null</code>. - * - * @param value The new selected value - */ - public void setSelectedItem(Object value) { - selectedItemHolder.setValue(value); - } - - /** - * @category UpdateButtons - */ - protected void updateAddButton(Button addButton) { - addButton.setEnabled( - enabled && - subject() != null - ); - } - - /** - * @category UpdateButtons - */ - protected void updateButtons() { - if (!container.isDisposed()) { - updateAddButton(addButton); - updateRemoveButton(removeButton); - updateOptionalButton(optionalButton); - } - } - - /** - * @category UpdateButtons - */ - protected void updateOptionalButton(Button optionalButton) { - if (optionalButton != null) { - optionalButton.setEnabled( - enabled && - adapter.enableOptionOnSelectionChange(selectionModel) - ); - } - } - - /** - * @category UpdateButtons - */ - protected void updateRemoveButton(Button removeButton) { - removeButton.setEnabled( - enabled && - adapter.enableRemoveOnSelectionChange(selectionModel) - ); - } - - /** - * An abstract implementation of <code>Adapter</code>. - */ - public static abstract class AbstractAdapter implements Adapter { - - /** - * The text of the add button. - */ - private String addButtonText; - - /** - * Determines whether the optional button should be shown or not. - */ - private boolean hasOptionalButton; - - /** - * The text of the optional button, if used. - */ - private String optionalButtonText; - - /** - * The text of the remove button. - */ - private String removeButtonText; - - /** - * Creates a new <code>AbstractAdapter</code> with default text for the - * add and remove buttons. - */ - public AbstractAdapter() { - this(JptUiMessages.AddRemovePane_AddButtonText, - JptUiMessages.AddRemovePane_RemoveButtonText); - } - - /** - * Creates a new <code>AbstractAdapter</code> with default text for the - * add and remove buttons. - * - * @param hasOptionalButton <code>true</code> to show an optional button - * and to use the behavior related to the optional button; - * <code>false</code> to not use it - */ - public AbstractAdapter(boolean hasOptionalButton) { - this(); - this.setHasOptionalButton(hasOptionalButton); - } - - /** - * Creates a new <code>AbstractAdapter</code> with default text for the - * add and remove buttons. - * - * @param optionalButtonText The text of the optional button, which means - * the optional button will be shown - */ - public AbstractAdapter(String optionalButtonText) { - this(true); - this.setOptionalButtonText(optionalButtonText); - } - - /** - * Creates a new <code>AbstractAdapter</code>. - * - * @param addButtonText The add button's text - * @param removeButtonText The remove button's text - */ - public AbstractAdapter(String addButtonText, - String removeButtonText) { - - super(); - this.addButtonText = addButtonText; - this.removeButtonText = removeButtonText; - } - - /** - * Creates a new <code>AbstractAdapter</code>. - * - * @param addButtonText The add button's text - * @param removeButtonText The remove button's text - * @param optionalButtonText The text of the optional button, which means - * the optional button will be shown - */ - public AbstractAdapter(String addButtonText, - String removeButtonText, - String optionalButtonText) { - - this(optionalButtonText); - this.setAddButtonText(addButtonText); - this.setRemoveButtonText(removeButtonText); - } - - /* - * (non-Javadoc) - */ - public String addButtonText() { - return addButtonText; - } - - /* - * (non-Javadoc) - */ - public boolean enableOptionOnSelectionChange(ObjectListSelectionModel listSelectionModel) { - return listSelectionModel.selectedValuesSize() == 1; - } - - public boolean enableRemoveOnSelectionChange(ObjectListSelectionModel listSelectionModel) { - return listSelectionModel.selectedValue() != null; - } - - /* - * (non-Javadoc) - */ - public boolean hasOptionalButton() { - return hasOptionalButton; - } - - /* - * (non-Javadoc) - */ - public String optionalButtonText() { - return optionalButtonText; - } - - /* - * (non-Javadoc) - */ - public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { - } - - /* - * (non-Javadoc) - */ - public String removeButtonText() { - return removeButtonText; - } - - /** - * Changes the text of the add button. This method has to be called before - * the <code>AddRemoveListPane</code> is initialized. - * - * @param addButtonText The add button's text - */ - public void setAddButtonText(String addButtonText) { - this.addButtonText = addButtonText; - } - - /** - * Changes the state of the optional button, meaning if it should be shown - * between the add and remove buttons or not. - * - * @param hasOptionalButton <code>true</code> to show an optional button - * and to use the behavior related to the optional button; - * <code>false</code> to not use it - */ - public void setHasOptionalButton(boolean hasOptionalButton) { - this.hasOptionalButton = hasOptionalButton; - } - - /** - * Changes the text of the optional button. This method has to be called - * before the <code>AddRemoveListPane</code> is initialized. This does not - * make the optional button visible. - * - * @param optionalButtonText The optional button's text - */ - public void setOptionalButtonText(String optionalButtonText) { - this.optionalButtonText = optionalButtonText; - } - - /** - * Changes the text of the remove button. This method has to be called - * before the <code>AddRemoveListPane</code> is initialized. - * - * @param removeButtonText The remove button's text - */ - 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 { - - /** - * The add button's text. - * - * @return The text shown on the add button - */ - 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); - - /** - * Invoked when selection changes. Implementation dictates whether remove button - * should be enabled. - */ - boolean enableRemoveOnSelectionChange(ObjectListSelectionModel listSelectionModel); - - /** - * Determines whether an optional button should be added between the add - * and remove buttons. - * - * @return <code>true</code> to show an optional button and to use the - * behavior related to the optional button; <code>false</code> to not use - * it - */ - boolean hasOptionalButton(); - - /** - * Resource string key for the optional button. - */ - String optionalButtonText(); - - /** - * Invoked when the user selects the optional button - */ - void optionOnSelection(ObjectListSelectionModel listSelectionModel); - - /** - * The remove button's text. - * - * @return The text shown on the remove button - */ - String removeButtonText(); - - /** - * Invoked when the user selects the Remove button. - */ - void removeSelectedItems(ObjectListSelectionModel listSelectionModel); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveTablePane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveTablePane.java deleted file mode 100644 index 4d16676401..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveTablePane.java +++ /dev/null @@ -1,316 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.ui.internal.swt.ColumnAdapter; -import org.eclipse.jpt.ui.internal.swt.TableModelAdapter; -import org.eclipse.jpt.ui.internal.swt.TableModelAdapter.SelectionChangeEvent; -import org.eclipse.jpt.ui.internal.swt.TableModelAdapter.SelectionChangeListener; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; - -/** - * This implementation of the <code>AddRemovePane</code> uses a <code>Table</code> - * as its main widget. - * <p> - * Here the layot of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------- ----------- | - * | | Column 1 | Column 2 | ... | Column i | ... | Colunm n | | Add... | | - * | |-----------------------------------------------------------| ----------- | - * | | | | | | | | ----------- | - * | |-----------------------------------------------------------| | Edit... | | - * | | | | | | | | ----------- | - * | |-----------------------------------------------------------| ----------- | - * | | | | | | | | | Remove | | - * | |-----------------------------------------------------------| ----------- | - * | ------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 1.0 - */ -public abstract class AddRemoveTablePane<T extends Model> extends AddRemovePane<T> -{ - /** - * Flag used to prevent circular - */ - private boolean locked; - - /** - * The main widget of this add/remove pane. - */ - private Table table; - - /** - * Creates a new <code>AddRemoveTablePane</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 AddRemoveTablePane(AbstractPane<? extends T> parentPane, - Composite parent, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - ITableLabelProvider labelProvider) { - - super(parentPane, - parent, - adapter, - listHolder, - selectedItemHolder, - labelProvider); - - } - - /** - * Creates a new <code>AddRemoveTablePane</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 AddRemoveTablePane(AbstractPane<? extends T> parentPane, - Composite parent, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - ITableLabelProvider labelProvider, - String helpId) { - - super(parentPane, - parent, - adapter, - listHolder, - selectedItemHolder, - labelProvider, - helpId); - } - - /** - * Creates a new <code>AddRemoveTablePane</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 AddRemoveTablePane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - ITableLabelProvider labelProvider) { - - super(parentPane, - subjectHolder, - parent, - adapter, - listHolder, - selectedItemHolder, - labelProvider); - } - - /** - * Creates a new <code>AddRemoveTablePane</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 AddRemoveTablePane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - ITableLabelProvider labelProvider, - String helpId) { - - super(parentPane, - subjectHolder, - parent, - adapter, - listHolder, - selectedItemHolder, - labelProvider, - helpId); - } - - protected abstract ColumnAdapter<?> buildColumnAdapter(); - - private WritablePropertyValueModel<Object> buildSelectedItemHolder() { - return new SimplePropertyValueModel<Object>(); - } - - private PropertyChangeListener buildSelectedItemPropertyChangeListener() { - return new SWTPropertyChangeListenerWrapper( - buildSelectedItemPropertyChangeListener_() - ); - } - - private PropertyChangeListener buildSelectedItemPropertyChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - if (table.isDisposed()) { - return; - } - - if (!locked) { - locked = true; - - try { - Object value = e.getNewValue(); - getSelectionModel().setSelectedValue(e.getNewValue()); - int index = -1; - - if (value != null) { - index = CollectionTools.indexOf(getListHolder().iterator(), value); - } - - table.select(index); - updateButtons(); - } - finally { - locked = false; - } - } - } - }; - } - - private SelectionChangeListener<Object> buildSelectionListener() { - return new SelectionChangeListener<Object>() { - public void selectionChanged(SelectionChangeEvent<Object> e) { - AddRemoveTablePane.this.selectionChanged(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - public Table getMainControl() { - return table; - } - - /* - * (non-Javadoc) - */ - @Override - @SuppressWarnings("unchecked") - protected void initializeMainComposite(Composite container, - Adapter adapter, - ListValueModel<?> listHolder, - WritablePropertyValueModel<?> selectedItemHolder, - IBaseLabelProvider labelProvider, - String helpId) - { - table = buildTable(container, helpId); - table.setHeaderVisible(true); - - removeFromEnablementControl(table); - - TableModelAdapter<Object> tableModel = TableModelAdapter.adapt( - (ListValueModel<Object>) listHolder, - buildSelectedItemHolder(), - table, - (ColumnAdapter<Object>) buildColumnAdapter(), - (ITableLabelProvider) labelProvider - ); - - tableModel.addSelectionChangeListener(buildSelectionListener()); - - selectedItemHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - buildSelectedItemPropertyChangeListener() - ); - } - - /** - * The selection has changed, update (1) the selected item holder, (2) the - * selection model and (3) the buttons. - */ - private void selectionChanged() { - - if (locked) { - return; - } - - locked = true; - - try { - WritablePropertyValueModel<Object> selectedItemHolder = getSelectedItemHolder(); - ObjectListSelectionModel selectionModel = getSelectionModel(); - int selectionCount = table.getSelectionCount(); - - if (selectionCount == 0) { - selectedItemHolder.setValue(null); - selectionModel.clearSelection(); - } - else if (selectionCount != 1) { - selectedItemHolder.setValue(null); - selectionModel.clearSelection(); - - for (int index : table.getSelectionIndices()) { - selectionModel.addSelectionInterval(index, index); - } - } - else { - int selectedIndex = table.getSelectionIndex(); - Object selectedItem = getListHolder().get(selectedIndex); - - selectedItemHolder.setValue(selectedItem); - selectionModel.setSelectedValue(selectedItem); - } - - updateButtons(); - } - finally { - locked = false; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java deleted file mode 100644 index 9e18102b33..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/ClassChooserPane.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.search.IJavaSearchScope; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper; -import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor; -import org.eclipse.jdt.ui.IJavaElementSearchConstants; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.progress.IProgressService; - -/** - * This chooser allows the user to choose a type when browsing and it adds code - * completion support to the text field, which is the main component. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | !---------------------------------------------------- ------------- | - * | Label: | I | | Browse... | | - * | ---------------------------------------------------- ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class ClassChooserPane<T extends Model> extends AbstractChooserPane<T> -{ - /** - * The code completion manager. - */ - private JavaTypeCompletionProcessor javaTypeCompletionProcessor; - - /** - * Creates a new <code>ClassChooserPane</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public ClassChooserPane(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>ClassChooserPane</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public ClassChooserPane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * {@inheritDoc} - */ - @Override - protected final Runnable buildBrowseAction() { - return new Runnable() { - public void run() { - promptType(); - } - }; - } - - /** - * {@inheritDoc} - */ - @Override - protected Control buildMainControl(Composite container) { - - Text text = buildText(container, buildTextHolder()); - - ControlContentAssistHelper.createTextContentAssistant( - text, - javaTypeCompletionProcessor - ); - - return text; - } - - /** - * Creates the value holder of the subject's property. - * - * @return The holder of the class name - */ - protected abstract WritablePropertyValueModel<String> buildTextHolder(); - - /** - * Prompts the user the Open Type dialog. - * - * @return Either the selected type or <code>null</code> if the user - * cancelled the dialog - */ - protected IType chooseType() { - - IPackageFragmentRoot root = packageFragmentRoot(); - - 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( - shell(), - service, - scope, - IJavaElementSearchConstants.CONSIDER_CLASSES, - false, - className() != null ? ClassTools.shortNameForClassNamed(className()) : "" - ); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - return null; - } - - typeSelectionDialog.setTitle(JptUiMessages.ClassChooserPane_dialogTitle); - typeSelectionDialog.setMessage(JptUiMessages.ClassChooserPane_dialogMessage); - - if (typeSelectionDialog.open() == Window.OK) { - return (IType) typeSelectionDialog.getResult()[0]; - } - - return null; - } - - /** - * Returns the class name from its subject. - * - * @return The class name or <code>null</code> if none is defined - */ - protected abstract String className(); - - /** - * {@inheritDoc} - */ - @Override - protected void doPopulate() { - super.doPopulate(); - updatePackageFragment(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void initialize() { - super.initialize(); - - // TODO bug 156185 - when this is fixed there should be api for this - this.javaTypeCompletionProcessor = new JavaTypeCompletionProcessor(false, false); - } - - /** - * Retrieves the ?? - * - * @return Either the root of the package fragment or <code>null</code> if it - * can't be retrieved - */ - protected abstract IPackageFragmentRoot packageFragmentRoot(); - - /** - * The browse button was clicked, its action invokes this action which should - * prompt the user to select a class and set it. - */ - protected abstract void promptType(); - - private void updatePackageFragment() { - - if (subject() != null) { - IPackageFragmentRoot root = packageFragmentRoot(); - - if (root != null) { - javaTypeCompletionProcessor.setPackageFragment(root.getPackageFragment("")); - return; - } - } - - javaTypeCompletionProcessor.setPackageFragment(null); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java deleted file mode 100644 index feb75a9138..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/DefaultWidgetFactory.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -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.Spinner; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.forms.widgets.FormText; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Hyperlink; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.forms.widgets.TableWrapData; -import org.eclipse.ui.forms.widgets.TableWrapLayout; - -/** - * This <code>WidgetFactory</code> simply creates plain SWT widgets. - * - * @version 2.0 - * @since 2.0 - */ -public class DefaultWidgetFactory implements WidgetFactory { - - /** - * The singleton instance of this <code>IWidgetFactory</code> - */ - private static final WidgetFactory INSTANCE = new DefaultWidgetFactory(); - - /** - * Creates a new <code>DefaultWidgetFactory</code>. - */ - private DefaultWidgetFactory() { - super(); - } - - /** - * Returns the singleton instance of this <code>IWidgetFactory</code>. - * - * @return The singleton instance of this <code>IWidgetFactory</code> - */ - public static WidgetFactory instance() { - return INSTANCE; - } - - /** - * {@inheritDoc} - */ - public Button createButton(Composite parent, String text) { - return this.createButton(parent, text, SWT.NULL); - } - - /** - * Creates a new button. - * - * @param parent The parent container - * @param text The button's text - * @param style The style to apply to the button, which determines its type: - * toggle, push, check box, radio - * @return The newly created <code>Button</code> - */ - private Button createButton(Composite parent, String text, int style) { - Button button = new Button(parent, style); - button.setText(text); - return button; - } - - /** - * {@inheritDoc} - */ - public CCombo createCCombo(Composite parent) { - return new CCombo(parent, SWT.BORDER | SWT.READ_ONLY); - } - - /** - * {@inheritDoc} - */ - public Button createCheckBox(Composite parent, String text) { - return this.createButton(parent, text, SWT.CHECK); - } - - /** - * {@inheritDoc} - */ - public Combo createCombo(Composite parent) { - return new Combo(parent, SWT.BORDER | SWT.READ_ONLY); - } - - /** - * {@inheritDoc} - */ - public Composite createComposite(Composite parent) { - return new Composite(parent, SWT.NULL); - } - - /** - * {@inheritDoc} - */ - public CCombo createEditableCCombo(Composite parent) { - return new CCombo(parent, SWT.BORDER); - } - - /** - * {@inheritDoc} - */ - public Combo createEditableCombo(Composite parent) { - return new Combo(parent, SWT.BORDER); - } - - /** - * {@inheritDoc} - */ - public Group createGroup(Composite parent, String title) { - Group group = new Group(parent, SWT.NULL); - group.setText(title); - return group; - } - - /** - * {@inheritDoc} - */ - public Hyperlink createHyperlink(Composite parent, String text) { - Hyperlink hyperlink = new Hyperlink(parent, SWT.NULL); - hyperlink.setText(text); - return hyperlink; - } - - /** - * {@inheritDoc} - */ - public Label createLabel(Composite parent, String labelText) { - Label label = new Label(parent, SWT.WRAP); - label.setText(labelText); - return label; - } - - /** - * {@inheritDoc} - */ - public List createList(Composite parent, int style) { - return new List(parent, SWT.BORDER | style); - } - - /** - * {@inheritDoc} - */ - public FormText createMultiLineLabel(Composite parent, String labelText) { - - Composite container = new Composite(parent, SWT.NONE); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - container.setLayoutData(gridData); - - TableWrapLayout layout = new TableWrapLayout(); - layout.numColumns = 1; - layout.bottomMargin = 0; - layout.leftMargin = 0; - layout.rightMargin = 0; - layout.topMargin = 0; - container.setLayout(layout); - - FormToolkit widgetFactory = new FormToolkit(parent.getDisplay()); - FormText text = widgetFactory.createFormText(container, true); - text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); - text.setText(labelText, false, false); - - return text; - } - - /** - * {@inheritDoc} - */ - public Text createMultiLineText(Composite parent) { - return new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - } - - /** - * {@inheritDoc} - */ - public Text createPasswordText(Composite parent) { - return new Text(parent, SWT.BORDER | SWT.PASSWORD); - } - - /** - * {@inheritDoc} - */ - public Button createPushButton(Composite parent, String text) { - return this.createButton(parent, text, SWT.PUSH); - } - - /** - * {@inheritDoc} - */ - public Button createRadioButton(Composite parent, String text) { - return this.createButton(parent, text, SWT.RADIO); - } - - /** - * {@inheritDoc} - */ - public Section createSection(Composite parent, int style) { - return new Section(parent, style); - } - - /** - * {@inheritDoc} - */ - public Spinner createSpinner(Composite parent) { - return new Spinner(parent, SWT.NULL); - } - - /** - * {@inheritDoc} - */ - public Table createTable(Composite parent, int style) { - return new Table(parent, SWT.BORDER | style); - } - - /** - * {@inheritDoc} - */ - public Text createText(Composite parent) { - return new Text(parent, SWT.BORDER); - } - - /** - * {@inheritDoc} - */ - public Button createTriStateCheckBox(Composite parent, String text) { - TriStateCheckBox checkBox = new TriStateCheckBox(parent, text, this); - return checkBox.getCheckBox(); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumDialogComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumDialogComboViewer.java deleted file mode 100644 index aa65171b53..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumDialogComboViewer.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; - -/** - * This <code>EnumComboViewer</code> should be used within a dialog pane. - * - * @version 2.0 - * @since 2.0 - */ -public abstract class EnumDialogComboViewer<T extends Model, V> extends AbstractEnumComboViewer<T, V> -{ - /** - * Creates a new <code>EnumDialogComboViewer</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - protected EnumDialogComboViewer(AbstractDialogPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>EnumDialogComboViewer</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - protected EnumDialogComboViewer(AbstractDialogPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * Creates a new <code>EnumDialogComboViewer</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 EnumDialogComboViewer(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - ComboViewer buildComboViewer(Composite container) { - ComboViewer comboViewer = buildComboViewer(container, buildLabelProvider()); - comboViewer.getCombo().setVisibleItemCount(Integer.MAX_VALUE); - return comboViewer; - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - - super.enableWidgets(enabled); - - Combo combo = getCombo(); - - if (combo.isDisposed()) { - combo.setEnabled(enabled); - } - } - - protected final Combo getCombo() { - return getComboViewer().getCombo(); - } - - /* - * (non-Javadoc) - */ - @Override - void removeAll() { - getCombo().removeAll(); - } - - /* - * (non-Javadoc) - */ - @Override - void updateCursor() { - getCombo().setSelection(new Point(0, 0)); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumFormComboViewer.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumFormComboViewer.java deleted file mode 100644 index 59187b01c5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/EnumFormComboViewer.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; - -/** - * This <code>EnumComboViewer</code> should be used within a form pane. - * - * @version 2.0 - * @since 1.0 - */ -public abstract class EnumFormComboViewer<T extends Model, V> extends AbstractEnumComboViewer<T, V> -{ - /** - * Creates a new <code>EnumFormComboViewer</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - protected EnumFormComboViewer(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>EnumFormComboViewer</code>. - * - * @param parentPane The parent container of this one - * @param parent The parent container - * @param widgetFactory The factory used to create various widgets - */ - protected EnumFormComboViewer(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * Creates a new <code>EnumFormComboViewer</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 EnumFormComboViewer(PropertyValueModel<? extends T> subjectHolder, - Composite parent, - WidgetFactory widgetFactory) { - - super(subjectHolder, parent, widgetFactory); - } - - /* - * (non-Javadoc) - */ - @Override - ComboViewer buildComboViewer(Composite container) { - ComboViewer comboViewer = buildCComboViewer(container, buildLabelProvider()); - comboViewer.getCCombo().setVisibleItemCount(Integer.MAX_VALUE); - return comboViewer; - } - - /* - * (non-Javadoc) - */ - @Override - public void enableWidgets(boolean enabled) { - - super.enableWidgets(enabled); - - CCombo combo = getCombo(); - - if (combo.isDisposed()) { - combo.setEnabled(enabled); - } - } - - protected final CCombo getCombo() { - return this.getComboViewer().getCCombo(); - } - - /* - * (non-Javadoc) - */ - @Override - void removeAll() { - getCombo().removeAll(); - } - - /* - * (non-Javadoc) - */ - @Override - void updateCursor() { - getCombo().setSelection(new Point(0, 0)); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FileChooserPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FileChooserPane.java deleted file mode 100644 index 764aa02ddc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FileChooserPane.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.model.WorkbenchContentProvider; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceComparator; - -/** - * This chooser allows the user to choose a file when browsing. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ---------------------------------------------------- ------------- | - * | Label: | I | | Browse... | | - * | ---------------------------------------------------- ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public abstract class FileChooserPane<T extends Model> extends AbstractChooserPane<T> -{ - private WritablePropertyValueModel<String> textHolder; - - /** - * Creates a new <code>FileChooserPane</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public FileChooserPane(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>FileChooserPane</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public FileChooserPane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected Runnable buildBrowseAction() { - return new Runnable() { - public void run() { - promptFile(); - } - }; - } - - /** - * Creates the <code>ViewerFilter</code> that will filter the content of the - * dialog and only displays what is valid. - * - * @return A new <code>ViewerFilter</code> - */ - protected ViewerFilter buildFilter() { - return new ViewerFilter() { - @Override - public boolean select(Viewer viewer, - Object parentElement, - Object element) { - - return true; - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Control buildMainControl(Composite container) { - return buildText(container, textHolder); - } - - private PostExecution<ElementTreeSelectionDialog> buildSelectionDialogPostExecution() { - return new PostExecution<ElementTreeSelectionDialog>() { - public void execute(ElementTreeSelectionDialog dialog) { - if (dialog.getReturnCode() == IDialogConstants.OK_ID) { - textHolder.setValue(dialog.getResult()[0].toString()); - } - } - }; - } - - /** - * Creates the value holder of the subject's property. - * - * @return The holder of the class name - */ - protected abstract WritablePropertyValueModel<String> buildTextHolder(); - - /** - * Creates the validator that will show a status message based on what is - * selected in the selection dialog. - * - * @return A new <code>ISelectionStatusValidator</code> - */ - protected ISelectionStatusValidator buildValidator() { - return new ISelectionStatusValidator() { - public IStatus validate(Object[] selection) { - - if (selection.length != 1) { - return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); - } - - return new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""); - } - }; - } - - /** - * Returns the message to be shown in the selection dialog. - * - * @return A non-<code>null</code> string shown above the text field of the - * selection dialog - */ - protected abstract String dialogMessage(); - - /** - * Returns the selection dialog's title. - * - * @return A non-<code>null</code> string - */ - protected abstract String dialogTitle(); - - /** - * Retrieves the root input that will be used by the selection dialog. - * - * @return The input used to display its content in a selection dialog - */ - protected abstract IResource getDialogInput(); - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - textHolder = buildTextHolder(); - } - - /** - * The browse button was clicked, its action invokes this action which should - * prompt the user to select a file and set it. - */ - protected void promptFile() { - - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( - shell(), - new WorkbenchLabelProvider(), - new WorkbenchContentProvider() - ); - - dialog.setHelpAvailable(false); - dialog.setValidator(buildValidator()); - dialog.setTitle(dialogTitle()); - dialog.setMessage(dialogMessage()); - dialog.addFilter(buildFilter()); - dialog.setInput(getDialogInput()); - dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); - - SWTUtil.show(dialog, buildSelectionDialogPostExecution()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FolderChooserPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FolderChooserPane.java deleted file mode 100644 index 618578bc65..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FolderChooserPane.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.DirectoryDialog; - -/** - * This chooser allows the user to choose a folder when browsing. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ---------------------------------------------------- ------------- | - * | Label: | I | | Browse... | | - * | ---------------------------------------------------- ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 2.0 - */ -public abstract class FolderChooserPane<T extends Model> extends AbstractChooserPane<T> -{ - private WritablePropertyValueModel<String> textHolder; - - /** - * Creates a new <code>FolderChooserPane</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public FolderChooserPane(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>FolderChooserPane</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public FolderChooserPane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /** - * {@inheritDoc} - */ - @Override - protected Runnable buildBrowseAction() { - return new Runnable() { - public void run() { - promptFolder(); - } - }; - } - - /** - * {@inheritDoc} - */ - @Override - protected Control buildMainControl(Composite container) { - return buildText(container, textHolder); - } - - /** - * Creates the value holder of the subject's property. - * - * @return The holder of the class name - */ - protected abstract WritablePropertyValueModel<String> buildTextHolder(); - - /** - * Returns the message to be shown in the selection dialog. - * - * @return A non-<code>null</code> string shown above the text field of the - * selection dialog - */ - protected abstract String dialogMessage(); - - /** - * Returns the selection dialog's title. - * - * @return A non-<code>null</code> string - */ - protected abstract String dialogTitle(); - - /** - * Returns the path that the dialog will use to filter the directories it - * shows to the argument, which may be null. If the string is null, then the - * operating system's default filter path will be used. - * <p> - * Note that the path string is platform dependent. For convenience, either - * '/' or '\' can be used as a path separator. - * </p> - * - * @return The filter path - */ - protected String filterPath() { - return null; - } - - /** - * {@inheritDoc} - */ - @Override - protected void initialize() { - super.initialize(); - textHolder = buildTextHolder(); - } - - /** - * The browse button was clicked, its action invokes this action which should - * prompt the user to select a folder and set it. - */ - protected void promptFolder() { - - DirectoryDialog dialog = new DirectoryDialog(shell()); - dialog.setMessage(dialogMessage()); - dialog.setText(dialogTitle()); - dialog.setFilterPath(filterPath()); - String directory = dialog.open(); - - if (directory != null) { - textHolder.setValue(directory); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java deleted file mode 100644 index db31c1840a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/FormWidgetFactory.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.forms.widgets.FormText; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Hyperlink; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.forms.widgets.TableWrapData; -import org.eclipse.ui.forms.widgets.TableWrapLayout; - -/** - * This <code>WidgetFactory</code> is responsible to create the widgets - * using the <code>FormToolkit</code> in order use the form style (flat-style) - * look and feel. - * - * @see FormToolkit - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public class FormWidgetFactory implements WidgetFactory { - - /** - * The actual factory responsible for creating the new widgets. - */ - private final FormToolkit widgetFactory; - - /** - * Creates a new <code>FormWidgetFactory</code>. - * - * @param widgetFactory The actual factory responsible for creating the new - * widgets - */ - public FormWidgetFactory(FormToolkit widgetFactory) { - super(); - - Assert.isNotNull(widgetFactory, "The widget factory cannot be null"); - this.widgetFactory = widgetFactory; - } - - /** - * Wraps the given <code>Composite</code> into a new <code>Composite</code> - * in order to have the widgets' border painted. Except for <code>CCombo</code>, - * the top and bottom margins have to be 2 pixel and the left and right - * margins have to be 1 pixel. - * - * @param container The parent of the sub-pane - * @return A new <code>Composite</code> that has the necessary space to paint - * the border - */ - protected Composite createBorderContainer(Composite container) { - - GridLayout layout = new GridLayout(1, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 2; - layout.marginLeft = 1; - layout.marginBottom = 2; - layout.marginRight = 1; - - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - - container = widgetFactory.createComposite(container); - container.setLayoutData(gridData); - container.setLayout(layout); - - return container; - } - - /** - * {@inheritDoc} - */ - public Button createButton(Composite parent, String text) { - return createButton(parent, text, SWT.NULL); - } - - /** - * Creates a new button. - * - * @param parent The parent container - * @param text The button's text - * @param style The style to apply to the button, which determines its type: - * toggle, push, check box, radio - * @return The newly created <code>Button</code> - */ - protected Button createButton(Composite parent, String text, int style) { - return widgetFactory.createButton(parent, text, SWT.FLAT | style); - } - - /** - * {@inheritDoc} - */ - public CCombo createCCombo(Composite parent) { - return createCCombo(parent, SWT.READ_ONLY); - } - - /** - * Creates a new combo. - * - * @param parent The parent container - * @param style The style to apply to the combo, usually read-only, flat - * @return The newly created <code>CCombo</code> - */ - protected CCombo createCCombo(Composite parent, int style) { - parent = createBorderContainer(parent); - - CCombo combo = new CCombo(parent, style); - widgetFactory.adapt(combo, true, false); - - // Bugzilla 145837 - workaround for no borders on Windows XP - if (widgetFactory.getBorderStyle() == SWT.BORDER) { - combo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - } - - return combo; - } - - /** - * {@inheritDoc} - */ - public Button createCheckBox(Composite parent, String text) { - return createButton(parent, text, SWT.CHECK); - } - - /** - * {@inheritDoc} - */ - public Combo createCombo(Composite parent) { - return new Combo(parent, SWT.READ_ONLY); - } - - /** - * {@inheritDoc} - */ - public Composite createComposite(Composite parent) { - Composite composite = widgetFactory.createComposite(parent); - widgetFactory.paintBordersFor(composite); - return composite; - } - - /** - * {@inheritDoc} - */ - public CCombo createEditableCCombo(Composite parent) { - return createCCombo(parent, SWT.NULL); - } - - /** - * {@inheritDoc} - */ - public Combo createEditableCombo(Composite parent) { - Combo combo = new Combo(parent, SWT.FLAT); - combo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - return combo; - } - - /** - * {@inheritDoc} - */ - public Group createGroup(Composite parent, String title) { - Group group = new Group(parent, SWT.SHADOW_NONE); - group.setText(title); - group.setBackground(widgetFactory.getColors().getBackground()); - group.setForeground(widgetFactory.getColors().getForeground()); - return group; - } - - /** - * {@inheritDoc} - */ - public Hyperlink createHyperlink(Composite parent, String text) { - return widgetFactory.createHyperlink(parent, text, SWT.FLAT); - } - - /** - * {@inheritDoc} - */ - public Label createLabel(Composite container, String labelText) { - return widgetFactory.createLabel(container, labelText, SWT.WRAP); - } - - /** - * {@inheritDoc} - */ - public List createList(Composite container, int style) { - List list = new List(container, SWT.FLAT | style); - list.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - return list; - } - - /** - * {@inheritDoc} - */ - public FormText createMultiLineLabel(Composite parent, String labelText) { - - Composite container = widgetFactory.createComposite(parent, SWT.NONE); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - container.setLayoutData(gridData); - - TableWrapLayout layout = new TableWrapLayout(); - layout.numColumns = 1; - layout.bottomMargin = 0; - layout.leftMargin = 0; - layout.rightMargin = 0; - layout.topMargin = 0; - container.setLayout(layout); - - FormText text = widgetFactory.createFormText(container, true); - text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); - text.setText(labelText, false, false); - - return text; - } - - /** - * {@inheritDoc} - */ - public Text createMultiLineText(Composite parent) { - return createText(parent, SWT.MULTI | SWT.V_SCROLL); - } - - /** - * {@inheritDoc} - */ - public Text createPasswordText(Composite parent) { - return createText(parent, SWT.PASSWORD); - } - - /** - * {@inheritDoc} - */ - public Button createPushButton(Composite parent, String text) { - return createButton(parent, text, SWT.PUSH); - } - - /** - * {@inheritDoc} - */ - public Button createRadioButton(Composite parent, String text) { - return createButton(parent, text, SWT.RADIO); - } - - /** - * {@inheritDoc} - */ - public Section createSection(Composite parent, int style) { - return widgetFactory.createSection(parent, SWT.FLAT | style); - } - - /** - * {@inheritDoc} - */ - public Spinner createSpinner(Composite parent) { - parent = createBorderContainer(parent); - - Spinner spinner = new Spinner(parent, SWT.FLAT); - spinner.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - widgetFactory.adapt(spinner, true, false); - - return spinner; - } - - /** - * {@inheritDoc} - */ - public Table createTable(Composite parent, int style) { - Table table = this.widgetFactory.createTable(parent, SWT.BORDER | style); - table.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - return table; - } - - /** - * {@inheritDoc} - */ - public Text createText(Composite parent) { - return createText(parent, SWT.NULL); - } - - protected Text createText(Composite parent, int style) { - return widgetFactory.createText(parent, null, SWT.FLAT | style); - } - - /** - * {@inheritDoc} - */ - public Button createTriStateCheckBox(Composite parent, String text) { - TriStateCheckBox checkBox = new TriStateCheckBox(parent, text, this); - return checkBox.getCheckBox(); - } - - /** - * Returns the actual factory responsible for creating the new widgets. - * - * @return The factory creating the widgets with the form style (flat-style) - */ - public FormToolkit getWidgetFactory() { - return widgetFactory; - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameDialog.java deleted file mode 100644 index 9632ba0e10..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameDialog.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import java.util.Collection; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * The dialog used to requests a name from the user. - * - * @version 2.0 - * @since 2.0 - */ -public class NewNameDialog extends AbstractValidatingDialog<NewNameStateObject> -{ - private String description; - private Image descriptionImage; - private String descriptionTitle; - private String labelText; - private String name; - private Collection<String> names; - - /** - * Creates a new <code>NewNameDialog</code>. - * - * @param parentShell - * @param dialogTitle - * @param descriptionTitle - * @param descriptionImage - * @param description - * @param labelText - * @param name - * @param names - */ - NewNameDialog(Shell parentShell, - String dialogTitle, - String descriptionTitle, - Image descriptionImage, - String description, - String labelText, - String name, - Collection<String> names) - { - super(parentShell, dialogTitle); - - this.name = name; - this.names = names; - this.labelText = labelText; - this.description = description; - this.descriptionImage = descriptionImage; - this.descriptionTitle = descriptionTitle; - } - - /* - * (non-Javadoc) - */ - @Override - protected AbstractDialogPane<NewNameStateObject> buildLayout(Composite container) { - return new DialogPane(container); - } - - /* - * (non-Javadoc) - */ - @Override - protected NewNameStateObject buildStateObject() { - return new NewNameStateObject(name, names); - } - - /* - * (non-Javadoc) - */ - @Override - public void create() { - super.create(); - - DialogPane pane = (DialogPane) pane(); - pane.selectAll(); - - getButton(OK).setEnabled(false); - } - - /* - * (non-Javadoc) - */ - @Override - protected String description() { - return description; - } - - /* - * (non-Javadoc) - */ - @Override - protected Image descriptionImage() { - return descriptionImage; - } - - /* (non-Javadoc) - */ - @Override - protected String descriptionTitle() { - return descriptionTitle; - } - - /** - * Returns the text field's input, which is the new name the user entered. - * - * @return The name the user entered - */ - public String getName() { - return subject().getName(); - } - - private class DialogPane extends AbstractDialogPane<NewNameStateObject> { - - private Text text; - - DialogPane(Composite parent) { - super(NewNameDialog.this.subjectHolder(), parent); - } - - private WritablePropertyValueModel<String> buildNameHolder() { - return new PropertyAspectAdapter<NewNameStateObject, String>(getSubjectHolder(), NewNameStateObject.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - subject.setName(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - text = buildLabeledText( - container, - labelText, - buildNameHolder() - ); - } - - void selectAll() { - text.selectAll(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameDialogBuilder.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameDialogBuilder.java deleted file mode 100644 index 1a4024eff7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameDialogBuilder.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import org.eclipse.core.runtime.Assert; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Shell; - -/** - * This builder is responsible to create a fully initialized - * <code>NewNameDialog</code> once all the properties have been set. - * - * @see NewNameDialog - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public final class NewNameDialogBuilder { - - /** - * The message to show in the description area. - */ - private String description; - - /** - * The image of the description area. - */ - private Image descriptionImage; - - /** - * The title to show in the description area. - */ - private String descriptionTitle; - - /** - * The title of the new name dialog. - */ - private String dialogTitle; - - /** - * The text field's label. - */ - private String labelText; - - /** - * The initial input or <code>null</code> if no initial value can be - * specified. - */ - private String name; - - /** - * The collection of names that can't be used or an empty collection if none - * are available. - */ - private Collection<String> names; - - /** - * The parent shell of the new name dialog. - */ - private Shell parentShell; - - /** - * Creates a new <code>NewNameDialogBuilder</code>. - * - * @param parentShell The parent shell of the new name dialog - */ - public NewNameDialogBuilder(Shell parentShell) { - super(); - initialize(parentShell); - } - - /** - * Creates the dialog that will be used to request a new name from the user. - * - * @return The initialized dialog - */ - public NewNameDialog buildDialog() { - return new NewNameDialog( - parentShell, - dialogTitle, - descriptionTitle, - descriptionImage, - description, - labelText, - name, - names - ); - } - - /** - * Initializes this builder. - * - * @param parentShell The parent shell of the new name dialog - */ - protected void initialize(Shell parentShell) { - - Assert.isNotNull(parentShell, "The parent shell cannot be null"); - - this.parentShell = parentShell; - this.names = Collections.emptyList(); - } - - /** - * Sets the description to be shown in the description area under the title. - * - * @param description The message to show in the description area - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Sets the image to be shown to the right side of the description area. - * - * @param descriptionImage The image of the description area - */ - public void setDescriptionImage(Image descriptionImage) { - this.descriptionImage = descriptionImage; - } - - /** - * Sets the title to be shown in the description area. - * - * @param descriptionTitle The title to show in the description area - */ - public void setDescriptionTitle(String descriptionTitle) { - this.descriptionTitle = descriptionTitle; - } - - /** - * Sets the dialog's title. - * - * @param dialogTitle The title of the new name dialog - */ - public void setDialogTitle(String dialogTitle) { - this.dialogTitle = dialogTitle; - } - - /** - * Sets the existing names that will be used to validate the text field's - * input and prevent the user from using it. - * - * @param names The collection of names that can't be used - */ - public void setExistingNames(Iterator<String> names) { - this.names = CollectionTools.collection(names); - } - - /** - * Sets the text to label the text field. - * - * @param labelText The text field's label - */ - public void setLabelText(String labelText) { - this.labelText = labelText; - } - - /** - * Sets the initial name if one exists. It is valid to leave this - * <code>null</code> when the user has to enter something. - * - * @param name The initial input - */ - public void setName(String name) { - this.name = name; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameStateObject.java deleted file mode 100644 index fb592307f7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NewNameStateObject.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import java.util.Collection; -import java.util.List; -import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.node.AbstractNode; -import org.eclipse.jpt.utility.internal.node.Node; -import org.eclipse.jpt.utility.internal.node.Problem; - -/** - * This is the state object used by the <code>NewNameDialog</code>, which stores - * the current name and validates it when it is modified. - * - * @see NewNameDialog - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -final class NewNameStateObject extends AbstractNode -{ - /** - * The initial input or <code>null</code> if no initial value can be - * specified. - */ - private String name; - - /** - * The collection of names that can't be used or an empty collection if none - * are available. - */ - private Collection<String> names; - - /** - * The <code>Validator</code> used to validate this state object. - */ - private Validator validator; - - /** - * Notifies a change in the name property. - */ - static final String NAME_PROPERTY = "name"; - - /** - * Creates a new <code>NewNameStateObject</code>. - * - * @param name The initial input or <code>null</code> if no initial value can - * be specified - * @param names The collection of names that can't be used or an empty - * collection if none are available - */ - NewNameStateObject(String name, Collection<String> names) { - super(null); - - this.name = name; - this.names = names; - } - - /** - * Validates the name property. - * - * @param currentProblems The list to which <code>Problem</code>s can be - * added - */ - private void addNameProblems(List<Problem> currentProblems) { - - if (StringTools.stringIsEmpty(name)) { - currentProblems.add(buildProblem(JptUiMappingsMessages.NewNameStateObject_nameMustBeSpecified)); - } - else if (names.contains(name.trim())) { - currentProblems.add(buildProblem(JptUiMappingsMessages.NewNameStateObject_nameAlreadyExists)); - } - } - - /* - * (non-Javadoc) - */ - @Override - protected void addProblemsTo(List<Problem> currentProblems) - { - super.addProblemsTo(currentProblems); - addNameProblems(currentProblems); - } - - /* - * (non-Javadoc) - */ - @Override - protected void checkParent(Node parentNode) { - } - - /* - * (non-Javadoc) - */ - public String displayString() { - return null; - } - - /** - * Returns the current name stored in this state object. - * - * @return The current name or <code>null</code> - */ - String getName() { - return name; - } - - /** - * Sets the current name stored in this state object or <code>null</code> to - * clear it. - * - * @param name The new name or <code>null</code> - */ - public void setName(String name) { - String oldName = this.name; - this.name = name; - firePropertyChanged(NAME_PROPERTY, oldName, name); - } - - /* - * (non-Javadoc) - */ - @Override - public void setValidator(Validator validator) { - this.validator = validator; - } - - /* - * (non-Javadoc) - */ - @Override - public Validator getValidator() { - return validator; - } -} 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 deleted file mode 100644 index 1f5edba3ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/NullPostExecution.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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/PackageChooserPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PackageChooserPane.java deleted file mode 100644 index 8d1cb19b2c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PackageChooserPane.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper; -import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaPackageCompletionProcessor; -import org.eclipse.jdt.ui.JavaElementLabelProvider; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.dialogs.SelectionDialog; - -/** - * This chooser allows the user to choose a package when browsing and it adds - * code completion support to the text field, which is the main component. - * <p> - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | !---------------------------------------------------- ------------- | - * | Label: | I | | Browse... | | - * | ---------------------------------------------------- ------------- | - * -----------------------------------------------------------------------------</pre> - * - * @version 2.0 - * @since 2.0 - */ -public abstract class PackageChooserPane<T extends Model> extends AbstractChooserPane<T> -{ - /** - * The code completion manager. - */ - private JavaPackageCompletionProcessor javaPackageCompletionProcessor; - - /** - * Creates a new <code>PackageChooserPane</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PackageChooserPane(AbstractPane<? extends T> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - /** - * Creates a new <code>PackageChooserPane</code>. - * - * @param parentPane The parent container of this one - * @param subjectHolder The holder of this pane's subject - * @param parent The parent container - */ - public PackageChooserPane(AbstractPane<?> parentPane, - PropertyValueModel<? extends T> subjectHolder, - Composite parent) { - - super(parentPane, subjectHolder, parent); - } - - /* - * (non-Javadoc) - */ - @Override - protected final Runnable buildBrowseAction() { - return new Runnable() { - public void run() { - promptPackage(); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Control buildMainControl(Composite container) { - - WritablePropertyValueModel<String> textHolder = buildTextHolder(); - - textHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - buildTextChangeListener() - ); - - Text text = buildText(container, textHolder); - - ControlContentAssistHelper.createTextContentAssistant( - text, - javaPackageCompletionProcessor - ); - - return text; - } - - private PropertyChangeListener buildTextChangeListener() { - return new SWTPropertyChangeListenerWrapper(buildTextChangeListener_()); - } - - private PropertyChangeListener buildTextChangeListener_() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - if (subject() != null) { - IPackageFragmentRoot root = packageFragmentRoot(); - - if (root != null) { - javaPackageCompletionProcessor.setPackageFragmentRoot(root); - } - } - } - }; - } - - /** - * Creates the value holder of the subject's property. - * - * @return The holder of the package name - */ - protected abstract WritablePropertyValueModel<String> buildTextHolder(); - - /** - * Prompts the user the Open Package dialog. - * - * @return Either the selected package or <code>null</code> if the user - * cancelled the dialog - */ - protected IPackageFragment choosePackage() { - - SelectionDialog selectionDialog; - - try { - selectionDialog = JavaUI.createPackageDialog( - shell(), - packageFragmentRoot() - ); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - return null; - } - - selectionDialog.setTitle(JptUiMessages.ClassChooserPane_dialogTitle); - selectionDialog.setMessage(JptUiMessages.ClassChooserPane_dialogMessage); - - IPackageFragment pack = packageFragment(); - - if (pack != null) { - selectionDialog.setInitialSelections(new Object[] { pack }); - } - - if (selectionDialog.open() == Window.OK) { - return (IPackageFragment) selectionDialog.getResult()[0]; - } - - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initialize() { - super.initialize(); - - // TODO bug 156185 - when this is fixed there should be api for this - this.javaPackageCompletionProcessor = new JavaPackageCompletionProcessor( - new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_ROOT) - ); - } - - private IPackageFragment packageFragment() { - String packageName = packageName(); - - if (packageName == null) { - return null; - } - - return packageFragmentRoot().getPackageFragment(packageName); - } - - /** - * Retrieves the ?? - * - * @return Either the root of the package fragment or <code>null</code> if it - * can't be retrieved - */ - protected abstract IPackageFragmentRoot packageFragmentRoot(); - - /** - * Returns the package name from its subject. - * - * @return The package name or <code>null</code> if none is defined - */ - protected abstract String packageName(); - - /** - * The browse button was clicked, its action invokes this action which should - * prompt the user to select a package and set it. - */ - protected abstract void promptPackage(); -} 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 deleted file mode 100644 index 0b6b920ba1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PostExecution.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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/PropertySheetWidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PropertySheetWidgetFactory.java deleted file mode 100644 index 5d54f8270d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PropertySheetWidgetFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; - -/** - * This <code>WidgetFactory</code> is responsible to create the widgets using - * <code>TabbedPropertySheetWidgetFactory</code> in order use the form style - * (flat-style) look and feel. - * - * @see TabbedPropertySheetWidgetFactory - * - * @version 2.0 - * @since 2.0 - */ -public class PropertySheetWidgetFactory extends FormWidgetFactory { - - /** - * Creates a new <code>PropertySheetWidgetFactory</code>. - * - * @param widgetFactory The actual factory responsible for creating the new - * widgets - */ - public PropertySheetWidgetFactory(TabbedPropertySheetWidgetFactory widgetFactory) { - super(widgetFactory); - } - - /** - * {@inheritDoc} - */ - @Override - protected CCombo createCCombo(Composite parent, int style) { - parent = createBorderContainer(parent); - return getWidgetFactory().createCCombo(parent, style); - } - - /** - * {@inheritDoc} - */ - @Override - public Composite createComposite(Composite parent) { - return getWidgetFactory().createComposite(parent); - } - - /** - * {@inheritDoc} - */ - @Override - public Group createGroup(Composite parent, String title) { - return getWidgetFactory().createGroup(parent, title); - } - - /** - * {@inheritDoc} - */ - @Override - protected Text createText(Composite parent, int style) { - parent = createBorderContainer(parent); - return getWidgetFactory().createText(parent, null, SWT.FLAT | style); - } - - /** - * {@inheritDoc} - */ - @Override - public TabbedPropertySheetWidgetFactory getWidgetFactory() { - return (TabbedPropertySheetWidgetFactory) super.getWidgetFactory(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index b6f4c7ec29..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/TriStateCheckBox.java +++ /dev/null @@ -1,287 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.widgets; - -import org.eclipse.jpt.ui.WidgetFactory; -import org.eclipse.swt.events.DisposeListener; -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.widgets.Button; -import org.eclipse.swt.widgets.Composite; - -/** - * This <code>TriStateCheckBox</code> can display one of three states: - * unchecked, checked, or partially checked. It can be modified via a mouse - * selection, via a keyboard selection, or programmatically. The selection state is - * represented by a <code>Boolean</code> value where a <code>null</code> - * value means partially checked. - * <p> - * The order of state changes is: unchecked -> partially checked -> checked. - * - * @version 2.0 - * @since 2.0 - */ -@SuppressWarnings("nls") -public final class TriStateCheckBox -{ - /** - * A check box button. - */ - private final Button button; - - /** - * The current selection state. - */ - private TriState state; - - /** - * Creates a new <code>TriStateCheckBox</code> with no text. - * - * @param parent The parent composite - * @param widgetFactory The factory used to create the check box - */ - public TriStateCheckBox(Composite parent, WidgetFactory widgetFactory) { - this(parent, null, widgetFactory); - } - - /** - * Creates a new <code>TriStateCheckBox</code>. - * - * @param parent The parent composite - * @param text The check box's text - * @param widgetFactory The factory used to create the check box - */ - public TriStateCheckBox(Composite parent, - String text, - WidgetFactory widgetFactory) { - super(); - this.state = TriState.UNCHECKED; - this.button = widgetFactory.createCheckBox(parent, text); - this.button.addSelectionListener(this.buildSelectionListener()); - } - - /** - * Convenience method: Adds a dispose listener to the check box. - * The source of any events sent to the listener will be the check box widget. - */ - public void addDisposeListener(DisposeListener disposeListener) { - this.button.addDisposeListener(disposeListener); - } - - /** - * Convenience method: Adds a selection listener to the check box. - * The source of any events sent to the listener will be the check box widget. - */ - public void addSelectionListener(SelectionListener selectionListener) { - this.button.addSelectionListener(selectionListener); - } - - private SelectionListener buildSelectionListener() { - return new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - TriStateCheckBox.this.checkBoxClicked(); - } - }; - } - - /** - * The check box was clicked, change the tri-state to the next value and - * update the check box's state. - */ - void checkBoxClicked() { - this.state = this.nextState(); - this.updateCheckBox(); - } - - /** - * Disposes the check box widget. - */ - public void dispose() { - this.button.dispose(); - } - - /** - * Returns the <code>Button</code> used to show a tri-state check box. - * - * @return The <code>Button</code> used to show a tri-state check box - */ - public Button getCheckBox() { - return this.button; - } - - /** - * Returns the check box's image. - * - * @return The check box's image. - */ - public Image getImage() { - return this.button.getImage(); - } - - /** - * Returns the check box's selection state. - * - * @return Either <code>true</code> or <code>false</code> for checked or - * unchecked; or <code>null</code> for partially selected - */ - public Boolean getSelection() { - return (this.state == TriState.PARTIALLY_CHECKED) ? null : Boolean.valueOf(this.state == TriState.CHECKED); - } - - /** - * Returns the check box's text. - * - * @return The text of the check box - */ - public String getText() { - return this.button.getText(); - } - - /** - * Returns whether the check box is disposed. - * - * @return <code>true</code> if the check box is disposed; <code>false</code> - * otherwise - */ - public boolean isDisposed() { - return this.button.isDisposed(); - } - - /** - * Returns whether the check box is enabled. - * - * @return <code>true</code> if the check box is enabled; <code>false</code> - * otherwise - */ - public boolean isEnabled() { - return this.button.isEnabled(); - } - - /** - * Returns the next state: - * UNCHECKED -> PARTIALLY_CHECKED - * PARTIALLY_CHECKED -> CHECKED - * CHECKED -> UNCHECKED - */ - private TriState nextState() { - switch (this.state) { - case UNCHECKED: - return TriState.PARTIALLY_CHECKED; - case PARTIALLY_CHECKED: - return TriState.CHECKED; - case CHECKED: - return TriState.UNCHECKED; - default: - throw new IllegalStateException("unknown state: " + this.state); - } - } - - /** - * Convenience method: Removes a dispose listener from the check box. - */ - public void removeDisposeListener(DisposeListener disposeListener) { - this.button.removeDisposeListener(disposeListener); - } - - /** - * Convenience method: Removes a selection listener from the check box. - */ - public void removeSelectionListener(SelectionListener selectionListener) { - this.button.removeSelectionListener(selectionListener); - } - - /** - * Changes the check box's enablement state. - * - * @param enabled <code>true</code> to enable the check box or <code>false</code> - * to disable it - */ - public void setEnabled(boolean enabled) { - this.button.setEnabled(enabled); - } - - /** - * Sets the check box's image. - * - * @param image The new image of the check box - */ - public void setImage(Image image) { - this.button.setImage(image); - } - - /** - * Changes the check box's selection state. - * - * @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 old = this.state; - this.state = this.stateForBoolean(selection); - if (old != this.state) { - this.updateCheckBox(); - } - } - - /** - * Sets the check box's text. - * - * @param text The new text of the check box - */ - public void setText(String text) { - this.button.setText(text); - } - - /** - * Returns the tri-state corresponding to the boolean. - * - * @param selection The boolean to be converted to a tri-state - */ - private TriState stateForBoolean(Boolean selection) { - return (selection == null) ? TriState.PARTIALLY_CHECKED : - selection.booleanValue() ? TriState.CHECKED : TriState.UNCHECKED; - } - - /** - * Updates the selection state of the of the check box based on the tri-state - * value. - */ - void updateCheckBox() { - switch (this.state) { - case UNCHECKED: - this.button.setSelection(false); - this.button.setGrayed(false); - break; - case PARTIALLY_CHECKED: - this.button.setSelection(true); - this.button.setGrayed(true); - break; - case CHECKED: - this.button.setSelection(true); - this.button.setGrayed(false); - break; - default: - throw new IllegalStateException("unknown state: " + this.state); - } - } - - /** - * An enum containing the possible selections. - */ - enum TriState { - CHECKED, - PARTIALLY_CHECKED, - UNCHECKED - } - -} 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 deleted file mode 100644 index 1c04312695..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/DatabaseReconnectWizardPage.java +++ /dev/null @@ -1,353 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.db.ConnectionAdapter; -import org.eclipse.jpt.db.ConnectionListener; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.db.ui.internal.DTPUiTools; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.swt.SWT; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.PlatformUI; - -public class DatabaseReconnectWizardPage extends WizardPage -{ - private JpaProject jpaProject; - - private ConnectionProfile profile; - - private ConnectionListener connectionListener; - - private DatabaseGroup databaseGroup; - - public DatabaseReconnectWizardPage(JpaProject jpaProject) { - super("Database Settings"); //$NON-NLS-1$ - this.jpaProject = jpaProject; - setTitle(JptUiMessages.DatabaseReconnectWizardPage_databaseConnection); - setMessage(JptUiMessages.DatabaseReconnectWizardPage_reconnectToDatabase); - } - - public void createControl(Composite parent) { - this.setPageComplete(false); - Composite top = this.createTopLevelComposite(parent); - this.setControl(top); - } - - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - this.databaseGroup = new DatabaseGroup(composite); - Dialog.applyDialogFont(parent); - // TODO Add Help - testing - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION); - return composite; - } - - private Label createLabel(Composite container, int span, String text) { - Label label = new Label(container, SWT.NONE); - label.setText(text); - GridData gd = new GridData(); - gd.horizontalIndent = 30; - gd.horizontalSpan = span; - label.setLayoutData(gd); - return label; - } - - private Combo createCombo(Composite container, boolean fillHorizontal) { - Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE); - if (fillHorizontal) { - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - else { - combo.setLayoutData(new GridData()); - } - return combo; - } - - /** - * Initialize a grid layout with the default Dialog settings. - */ - protected GridLayout initGridLayout(GridLayout layout, boolean margins) { - layout.horizontalSpacing = this.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - layout.verticalSpacing = this.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - if (margins) { - layout.marginWidth = this.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.marginHeight = this.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - } - else { - layout.marginWidth = 0; - layout.marginHeight = 0; - } - return layout; - } - - public Collection<Table> getTables() { - Schema schema = this.getDefaultSchema(); - if (schema != null && schema.getName() != null) { - return CollectionTools.collection(schema.tables()); - } - return Collections.<Table> emptyList(); - } - - private void updateGenerateEntitiesPage(Schema schema) { - if (this.getWizard() instanceof GenerateEntitiesWizard) { - GenerateEntitiesWizard generateEntitiesWizard = ((GenerateEntitiesWizard) this.getWizard()); - generateEntitiesWizard.updatePossibleTables(CollectionTools.collection(schema.tables())); - } - } - - @Override - public void dispose() { - this.removeConnectionListener(); - super.dispose(); - } - - private void removeConnectionListener() { - if (this.connectionListener != null) { - if (this.profile != null) { - this.profile.removeConnectionListener(this.connectionListener); - } - this.connectionListener = null; - } - } - - ConnectionProfile getProjectConnectionProfile() { - String profileName = this.jpaProject.getDataSource().getConnectionProfileName(); - return this.connectionProfileNamed(profileName); - } - - ConnectionProfile connectionProfileNamed(String profileName) { - return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(profileName); - } - - Schema getDefaultSchema() { - return this.jpaProject.getDefaultSchema(); - } - - public String getSelectedConnectionProfileName() { - return this.databaseGroup.getConnectionProfileName(); - } - - public void clearConnectionProfileName() { - this.databaseGroup.clearConnectionProfileName(); - } - // ********** member classes ********** - private final class DatabaseGroup - { - private final Group group; - - private final Combo connectionCombo; - - private final Combo schemaCombo; - - private Link addConnectionLink; - - private Link reconnectLink; - - public DatabaseGroup(Composite composite) { - this.group = new Group(composite, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - this.group.setLayout(layout); - this.group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - this.group.setText(JptUiMessages.DatabaseReconnectWizardPage_database); - // TODO Add Help - // PlatformUI.getWorkbench().getHelpSystem().setHelp( this.group, - // IDaliHelpContextIds.XXX); - 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(); - } - }); - 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(); - } - }); - createLabel(this.group, 2, JptUiMessages.DatabaseReconnectWizardPage_schemaInfo); - this.addConnectionLink = new Link(this.group, SWT.NONE); - GridData data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - this.addConnectionLink.setLayoutData(data); - this.addConnectionLink.setText(JptUiMessages.DatabaseReconnectWizardPage_addConnectionLink); - this.addConnectionLink.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - openNewConnectionWizard(); - } - }); - this.reconnectLink = new Link(this.group, SWT.NONE); - data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - this.reconnectLink.setLayoutData(data); - this.reconnectLink.setText(JptUiMessages.DatabaseReconnectWizardPage_reconnectLink); - this.reconnectLink.setEnabled(false); - this.reconnectLink.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - openConnectionProfileNamed(getConnectionProfileName()); - } - }); - this.populateConnectionCombo(); - this.populateSchemaCombo(); - } - - private ConnectionProfile connectionProfileNamed(String profileName) { - return DatabaseReconnectWizardPage.this.connectionProfileNamed(profileName); - } - - private Iterator<String> dtpConnectionProfileNames() { - return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNames(); - } - - private String getProjectConnectionProfileName() { - return jpaProject.getDataSource().getConnectionProfileName(); - } - - private void openConnectionProfileNamed(String connectionProfileName) { - DatabaseReconnectWizardPage.this.removeConnectionListener(); - DatabaseReconnectWizardPage.this.profile = this.connectionProfileNamed(connectionProfileName); - DatabaseReconnectWizardPage.this.profile.connect(); - if (DatabaseReconnectWizardPage.this.profile.isActive()) { - this.populateSchemaCombo(); - DatabaseReconnectWizardPage.this.connectionListener = this.buildConnectionListener(); - DatabaseReconnectWizardPage.this.profile.addConnectionListener(DatabaseReconnectWizardPage.this.connectionListener); - } - return; - } - - private void populateConnectionCombo() { - // clear out connection entries from previous login. - this.connectionCombo.removeAll(); - for (Iterator<String> i = CollectionTools.sort(this.dtpConnectionProfileNames()); i.hasNext();) { - this.connectionCombo.add(i.next()); - } - String connectionName = getProjectConnectionProfileName(); - if (!StringTools.stringIsEmpty(connectionName)) { - this.connectionCombo.select(connectionCombo.indexOf(connectionName)); - this.reconnectLink.setEnabled(true); - } - } - - private void handleConnectionChange() { - this.reconnectLink.setEnabled(true); - this.populateSchemaCombo(); - } - - private void handleSchemaChange() { - ConnectionProfile connectionProfile = this.connectionProfileNamed(getConnectionProfileName()); - Schema schema = connectionProfile.getDatabase().schemaNamed(this.getSchemaName()); - DatabaseReconnectWizardPage.this.updateGenerateEntitiesPage(schema); - DatabaseReconnectWizardPage.this.setPageComplete(true); - } - - private void populateSchemaCombo() { - // clear out schema entries from previous connection selection - this.schemaCombo.removeAll(); - ConnectionProfile connectionProfile = this.connectionProfileNamed(getConnectionProfileName()); - for (Iterator<String> stream = CollectionTools.sort(connectionProfile.getDatabase().schemaNames()); stream.hasNext();) { - this.schemaCombo.add(stream.next()); - } - // get default schema name from the project - Schema schema = getDefaultSchema(); - if (schema != null && schema.getName() != null) { - schema = connectionProfile.getDatabase().schemaNamed(schema.getName()); // verify - // schema - // exist - if (schema != null) { - this.schemaCombo.select(this.schemaCombo.indexOf(schema.getName())); - DatabaseReconnectWizardPage.this.updateGenerateEntitiesPage(schema); - DatabaseReconnectWizardPage.this.setPageComplete(true); - } - } - } - - private String getConnectionProfileName() { - return this.connectionCombo.getText(); - } - - private String getSchemaName() { - return this.schemaCombo.getText(); - } - - void clearConnectionProfileName() { - this.connectionCombo.setText(""); - } - - private void openNewConnectionWizard() { - String addedProfileName = DTPUiTools.createNewProfile(); - ConnectionProfile addedProfile = this.connectionProfileNamed(addedProfileName); - if (!addedProfile.isNull()) { - addedProfile.connect(); - this.populateConnectionCombo(); - this.connectionCombo.select(connectionCombo.indexOf(addedProfile.getName())); - this.handleConnectionChange(); - } - } - - private ConnectionListener buildConnectionListener() { - return new ConnectionAdapter() { - @Override - public void opened(ConnectionProfile profile) { - if (DatabaseReconnectWizardPage.this.profile.equals(profile)) { - DatabaseGroup.this.populateSchemaCombo(); - } - } - - @Override - public void aboutToClose(ConnectionProfile profile) { - if (DatabaseReconnectWizardPage.this.profile.equals(profile)) { - DatabaseReconnectWizardPage.this.removeConnectionListener(); - } - } - }; - } - } -} 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 deleted file mode 100644 index 4b663e604a..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizard.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards; - -import java.util.Collection; -import java.util.Collections; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.Schema; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.gen.internal.EntityGenerator; -import org.eclipse.jpt.gen.internal.PackageGenerator; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class GenerateEntitiesWizard extends Wizard { - - private JpaProject jpaProject; - - private IStructuredSelection selection; - - /** this page is only built when the project is not connected to the db */ - private DatabaseReconnectWizardPage dbSettingsPage; - - private GenerateEntitiesWizardPage generateEntitiesPage; - - private PackageGenerator.Config packageGeneratorConfig; - - private EntityGenerator.Config entityGeneratorConfig; - - private boolean synchronizePersistenceXml; - - private Collection<Table> selectedTables; - - public GenerateEntitiesWizard( JpaProject jpaProject, IStructuredSelection selection) { - super(); - this.jpaProject = jpaProject; - this.selection = selection; - this.packageGeneratorConfig = new PackageGenerator.Config(); - this.entityGeneratorConfig = new EntityGenerator.Config(); - this.setWindowTitle( JptUiMessages.GenerateEntitiesWizard_generateEntities); - } - - @Override - public void addPages() { - super.addPages(); - this.dbSettingsPage = new DatabaseReconnectWizardPage( this.jpaProject); - this.addPage(this.dbSettingsPage); - this.generateEntitiesPage = new GenerateEntitiesWizardPage(); - this.addPage( this.generateEntitiesPage); - this.generateEntitiesPage.init( this.selection); - } - - @Override - public boolean performFinish() { - this.packageGeneratorConfig.setPackageFragment( this.buildPackageFragment()); - - this.entityGeneratorConfig.setConvertToCamelCase( this.generateEntitiesPage.convertToCamelCase()); - this.entityGeneratorConfig.setFieldAccessType( this.generateEntitiesPage.fieldAccessType()); - this.entityGeneratorConfig.setCollectionTypeName( this.generateEntitiesPage.getCollectionTypeName()); - this.entityGeneratorConfig.setFieldVisibility( this.generateEntitiesPage.getFieldVisibility()); - this.entityGeneratorConfig.setMethodVisibility( this.generateEntitiesPage.getMethodVisibility()); - this.entityGeneratorConfig.setGenerateGettersAndSetters( this.generateEntitiesPage.generateGettersAndSetters()); - this.entityGeneratorConfig.setGenerateDefaultConstructor( this.generateEntitiesPage.generateDefaultConstructor()); - this.entityGeneratorConfig.setSerializable( this.generateEntitiesPage.serializable()); - this.entityGeneratorConfig.setGenerateSerialVersionUID( this.generateEntitiesPage.generateSerialVersionUID()); - this.entityGeneratorConfig.setGenerateEmbeddedIdForCompoundPK( this.generateEntitiesPage.generateEmbeddedIdForCompoundPK()); - this.entityGeneratorConfig.setOverrideEntityNames( this.generateEntitiesPage.getOverrideEntityNames()); - - this.synchronizePersistenceXml = this.generateEntitiesPage.synchronizePersistenceXml(); - - this.selectedTables = this.generateEntitiesPage.getSelectedTables(); - return true; - } - - private IPackageFragment buildPackageFragment() { - IPackageFragmentRoot packageFragmentRoot = this.generateEntitiesPage.getPackageFragmentRoot(); - IPackageFragment packageFragment = this.generateEntitiesPage.getPackageFragment(); - - if ( packageFragment == null) { - packageFragment= packageFragmentRoot.getPackageFragment( ""); //$NON-NLS-1$ - } - - if ( packageFragment.exists()) { - return packageFragment; - } - - try { - return packageFragmentRoot.createPackageFragment( packageFragment.getElementName(), true, null); - } - catch ( JavaModelException ex) { - throw new RuntimeException( ex); - } - } - - Collection<Table> getPossibleTables() { - if ( this.dbSettingsPage != null) { - return this.dbSettingsPage.getTables(); - } - return ( this.projectDefaultSchemaExists()) ? CollectionTools.collection( this.getDefaultSchema().tables()) : Collections.<Table>emptyList(); - } - - ConnectionProfile getProjectConnectionProfile() { - return this.jpaProject.getConnectionProfile(); - } - - JpaProject getJpaProject(){ - return this.jpaProject; - } - - Schema getDefaultSchema() { - return getJpaProject().getDefaultSchema(); - } - - public PackageGenerator.Config getPackageGeneratorConfig() { - return this.packageGeneratorConfig; - } - - public EntityGenerator.Config getEntityGeneratorConfig() { - return this.entityGeneratorConfig; - } - - public Collection<Table> getSelectedTables() { - return this.selectedTables; - } - - public boolean synchronizePersistenceXml(){ - return this.synchronizePersistenceXml; - } - - @Override - public boolean canFinish() { - boolean canFinish = true; - if ( ! this.generateEntitiesPage.isPageComplete()) { - canFinish = false; - } - return canFinish; - } - - private boolean projectDefaultSchemaExists() { - return ( this.getDefaultSchema() != null); - } - - /** - * updatePossibleTables is called when schema’s PossibleTables changed. - * The dbSettingsPage is mainly the source of changes, - * and the generateEntitiesPage needs to be kept in sync. - */ - void updatePossibleTables( Collection<Table> possibleTables) { - this.generateEntitiesPage.updateTablesListViewer( possibleTables); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java deleted file mode 100644 index af851c959b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/GenerateEntitiesWizardPage.java +++ /dev/null @@ -1,518 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.gen.internal.EntityGenerator; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.util.TableLayoutComposite; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -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.Group; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.ui.PlatformUI; - -// TODO determine name collisions -class GenerateEntitiesWizardPage extends NewTypeWizardPage { - - CheckboxTableViewer tableTable; - - private boolean convertToCamelCase = true; - private boolean fieldAccessType = true; - private String collectionTypeName = Set.class.getName(); - private int fieldVisibility = EntityGenerator.Config.PRIVATE; - private int methodVisibility = EntityGenerator.Config.PUBLIC; - private boolean generateGettersAndSetters = true; - private boolean generateDefaultConstructor = true; - private boolean serializable = true; - private boolean generateSerialVersionUID = true; - private boolean generateEmbeddedIdForCompoundPK = true; - private boolean synchronizePersistenceXml = false; - private Map<Table, String> overrideEntityNames; - - static final String[] TABLE_TABLE_COLUMN_PROPERTIES = { "table", "entityName" }; - private static final int TABLE_COLUMN_INDEX = 0; - private static final int ENTITY_NAME_COLUMN_INDEX = 1; - - - GenerateEntitiesWizardPage() { - super(true, "Generate Entities"); //$NON-NLS-1$ - setTitle(JptUiMessages.GenerateEntitiesWizardPage_generateEntities); - setMessage(JptUiMessages.GenerateEntitiesWizardPage_chooseEntityTable); - } - - // -------- Initialization --------- - /** - * The wizard owning this page is responsible for calling this method with the - * current selection. The selection is used to initialize the fields of the wizard - * page. - * - * @param selection used to initialize the fields - */ - void init(IStructuredSelection selection) { - IJavaElement jelem= getInitialJavaElement(selection); - initContainerPage(jelem); - initTypePage(jelem); - doStatusUpdate(); - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - int nColumns= 4; - GridLayout layout = new GridLayout(); - layout.numColumns = nColumns; - composite.setLayout(layout); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.DIALOG_GENERATE_ENTITIES); - - createContainerControls(composite, nColumns); - createPackageControls(composite, nColumns); - - final Button synchronizeClassesCheckBox = new Button(composite, SWT.CHECK); - synchronizeClassesCheckBox.setText(JptUiMessages.GenerateEntitiesWizardPage_synchronizeClasses); - synchronizeClassesCheckBox.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - setSynchronizePersistenceXml(synchronizeClassesCheckBox.getSelection()); - } - }); - - Group tablesGroup = new Group(composite, SWT.SHADOW_ETCHED_IN); - tablesGroup.setLayout(new GridLayout(2, false)); - tablesGroup.setText(JptUiMessages.GenerateEntitiesWizardPage_tables); - GridData data = new GridData(); - data.horizontalSpan = 4; - data.verticalAlignment = SWT.FILL; - data.horizontalAlignment = SWT.FILL; - data.grabExcessHorizontalSpace = true; - data.grabExcessVerticalSpace = true; - tablesGroup.setLayoutData(data); - - createTablesSelectionControl(tablesGroup); - createButtonComposite(tablesGroup); - - GenerateEntitiesWizard generateEntitiesWizard = ((GenerateEntitiesWizard)this.getWizard()); - Collection<Table> possibleTables = generateEntitiesWizard.getPossibleTables(); - initTablesSelectionControl(possibleTables); - - //set initial selection state of the synchronize classes checkbox - synchronizeClassesCheckBox.setSelection(!generateEntitiesWizard.getJpaProject().discoversAnnotatedClasses()); - setSynchronizePersistenceXml(synchronizeClassesCheckBox.getSelection()); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.tableTable.getControl(), JpaHelpContextIds.DIALOG_GENERATE_ENTITIES_TABLES); - - setControl(composite); - this.setPageComplete( false); - } - - private void selectAllTables(){ - this.tableTable.setAllChecked(true); - doStatusUpdate(); - } - - private void deselectAllTables(){ - this.tableTable.setAllChecked(false); - doStatusUpdate(); - } - - private void initTablesSelectionControl(Collection<Table> possibleTables) { - this.overrideEntityNames = new HashMap<Table, String>(possibleTables.size()); - this.tableTable.setInput(possibleTables); - } - - private void createTablesSelectionControl(Composite parent) { - TableLayoutComposite layout= new TableLayoutComposite(parent, SWT.NONE); - addColumnLayoutData(layout); - - final org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(layout, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - TableColumn tableNameColumn = new TableColumn(table, SWT.NONE, TABLE_COLUMN_INDEX); - tableNameColumn.setText(JptUiMessages.GenerateEntitiesWizardPage_tableColumn); - tableNameColumn.setResizable(true); - - TableColumn entityNameColumn = new TableColumn(table, SWT.NONE, ENTITY_NAME_COLUMN_INDEX); - entityNameColumn.setText(JptUiMessages.GenerateEntitiesWizardPage_entityNameColumn); - entityNameColumn.setResizable(true); - - GridData gd= new GridData(GridData.FILL_BOTH); - gd.heightHint= SWTUtil.getTableHeightHint(table, 20); - gd.widthHint = 600; - layout.setLayoutData(gd); - - this.tableTable = new CheckboxTableViewer(table); - this.tableTable.setUseHashlookup(true); - this.tableTable.setLabelProvider(this.buildTableTableLabelProvider()); - this.tableTable.setContentProvider(this.buildTableTableContentProvider()); - this.tableTable.setSorter(new ViewerSorter() { - @Override - public int compare(Viewer viewer, Object e1, Object e2) { - return ((Table) e1).getName().compareTo(((Table) e2).getName()); - } - }); - - this.tableTable.addPostSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - handleTablesListSelectionChanged(event); - } - }); - - table.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.F2 && e.stateMask == SWT.NONE) { - editEntityNameIfPossible(); - e.doit= false; - } - } - }); - - this.addCellEditors(); - } - - private void createButtonComposite(Group tablesGroup){ - - Composite buttonComposite = new Composite(tablesGroup, SWT.NULL); - GridLayout buttonLayout = new GridLayout(1, false); - buttonComposite.setLayout(buttonLayout); - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - buttonComposite.setLayoutData(data); - - Button selectAllButton = new Button(buttonComposite, SWT.PUSH); - selectAllButton.setText(JptUiMessages.General_selectAll); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - selectAllButton.setLayoutData(gridData); - selectAllButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - selectAllTables(); - - } - }); - - Button deselectAllButton = new Button(buttonComposite, SWT.PUSH); - deselectAllButton.setText(JptUiMessages.General_deselectAll); - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - deselectAllButton.setLayoutData(gridData); - deselectAllButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // do nothing - } - - public void widgetSelected(SelectionEvent e) { - deselectAllTables(); - } - }); - } - - - private void addColumnLayoutData(TableLayoutComposite layout) { - layout.addColumnData(new ColumnWeightData(50, true)); - layout.addColumnData(new ColumnWeightData(50, true)); - } - - void editEntityNameIfPossible(){ - Object[] selected = ((IStructuredSelection) this.tableTable.getSelection()).toArray(); - if (selected.length != 1) { - return; - } - this.tableTable.editElement(selected[0], ENTITY_NAME_COLUMN_INDEX); - } - - private void addCellEditors() { - this.tableTable.setColumnProperties(TABLE_TABLE_COLUMN_PROPERTIES); - - TextCellEditor[] editors = new TextCellEditor[TABLE_TABLE_COLUMN_PROPERTIES.length]; - editors[ENTITY_NAME_COLUMN_INDEX]= new TextCellEditor(this.tableTable.getTable(), SWT.SINGLE); - - this.tableTable.setCellEditors(editors); - this.tableTable.setCellModifier(this.buildTableTableCellModifier()); - } - - void handleTablesListSelectionChanged(SelectionChangedEvent event) { - this.setPageComplete(true); - if ( ! this.hasTablesSelected()) { - this.setPageComplete(false); - } - } - - private IBaseLabelProvider buildTableTableLabelProvider() { - return new TableTableLabelProvider(); - } - - private IContentProvider buildTableTableContentProvider() { - return new TableTableContentProvider(); - } - - private ICellModifier buildTableTableCellModifier() { - return new TableTableCellModifier(); - } - - Collection<Table> getSelectedTables() { - ArrayList<Table> selectedTables = new ArrayList<Table>(); - for (Object selectedTable : this.tableTable.getCheckedElements()) - selectedTables.add((Table) selectedTable); - return selectedTables; - } - - private boolean hasTablesSelected() { - return (this.tableTable != null) ? (this.getSelectedTables().size() > 0) : false; - } - - void updateTablesListViewer(Collection<Table> possibleTables) { - if (this.tableTable != null) { - this.initTablesSelectionControl(possibleTables); - } - } - - @Override - protected void handleFieldChanged(String fieldName) { - super.handleFieldChanged(fieldName); - - doStatusUpdate(); - } - - private void doStatusUpdate() { - // status of all used components - IStatus[] status= new IStatus[] { - fContainerStatus, - fPackageStatus - }; - // the mode severe status will be displayed and the OK button enabled/disabled. - this.updateStatus(status); - } - - /** - * Update the status line and the OK button according to the given status - */ - @Override - protected void updateStatus(IStatus status) { - super.updateStatus(status); - if (this.isPageComplete() && ! this.hasTablesSelected()) { - this.setPageComplete(false); - } - } - - String entityName(Table table) { - String overrideEntityName = this.overrideEntityNames.get(table); - return (overrideEntityName != null) ? overrideEntityName : this.defaultEntityName(table); - } - - private String defaultEntityName(Table table) { - String entityName = table.getShortJavaClassName(); - if (this.convertToCamelCase) { - entityName = StringTools.convertUnderscoresToCamelCase(entityName); - } - return entityName; - } - - void setOverrideEntityName(Table table, String name) { - if (table.getShortJavaClassName().equals(name)) { - this.overrideEntityNames.remove(table); - } else { - this.overrideEntityNames.put(table, name); - } - } - - boolean convertToCamelCase() { - return this.convertToCamelCase; - } - - boolean fieldAccessType() { - return this.fieldAccessType; - } - - String getCollectionTypeName() { - return this.collectionTypeName; - } - - int getFieldVisibility() { - return this.fieldVisibility; - } - - int getMethodVisibility() { - return this.methodVisibility; - } - - boolean generateGettersAndSetters() { - return this.generateGettersAndSetters; - } - - boolean generateDefaultConstructor() { - return this.generateDefaultConstructor; - } - - boolean serializable() { - return this.serializable; - } - - boolean generateSerialVersionUID() { - return this.generateSerialVersionUID; - } - - boolean generateEmbeddedIdForCompoundPK() { - return this.generateEmbeddedIdForCompoundPK; - } - - boolean synchronizePersistenceXml() { - return this.synchronizePersistenceXml; - } - - private void setSynchronizePersistenceXml(boolean synchronizePersistenceXml){ - this.synchronizePersistenceXml = synchronizePersistenceXml; - } - - /** - * key = table - * value = override entity name - */ - Map<Table, String> getOverrideEntityNames() { - return this.overrideEntityNames; - } - - - // ********** inner classes ********** - - private class TableTableLabelProvider extends LabelProvider implements ITableLabelProvider { - - TableTableLabelProvider() { - super(); - } - - @Override - public String getText(Object element) { - return ((Table) element).getName(); - } - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - public String getColumnText(Object element, int columnIndex) { - if (element == null) { - return null; - } - switch (columnIndex) { - case TABLE_COLUMN_INDEX: - return ((Table) element).getName(); - - case ENTITY_NAME_COLUMN_INDEX: - return GenerateEntitiesWizardPage.this.entityName((Table) element); - } - throw new IllegalArgumentException("invalid column index: " + columnIndex); - } - - } - - - private class TableTableContentProvider implements IStructuredContentProvider { - - TableTableContentProvider() { - super(); - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public Object[] getElements(Object inputElement) { - return ((Collection<?>) inputElement).toArray(); - } - - } - - - private class TableTableCellModifier implements ICellModifier { - - TableTableCellModifier() { - super(); - } - - public boolean canModify(Object element, String property) { - return property.equals(TABLE_TABLE_COLUMN_PROPERTIES[ENTITY_NAME_COLUMN_INDEX]); - } - - public Object getValue(Object element, String property) { - if (property.equals(TABLE_TABLE_COLUMN_PROPERTIES[ENTITY_NAME_COLUMN_INDEX])) { - return GenerateEntitiesWizardPage.this.entityName((Table) element); - } - return null; - } - - public void modify(Object element, String property, Object value) { - if (element instanceof TableItem) { - element= ((TableItem) element).getData(); - } - if ( ! (element instanceof Table)) { - return; - } - - boolean unchanged = false; - Table table = (Table) element; - if (property.equals(TABLE_TABLE_COLUMN_PROPERTIES[ENTITY_NAME_COLUMN_INDEX])) { - unchanged = GenerateEntitiesWizardPage.this.entityName(table).equals(value); - GenerateEntitiesWizardPage.this.setOverrideEntityName(table, (String) value); - } - if (! unchanged) { - GenerateEntitiesWizardPage.this.tableTable.update(table, new String[] { property }); - } - } - - } - -} 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 deleted file mode 100644 index 22851d2db7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java +++ /dev/null @@ -1,389 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.preference.PreferenceDialog; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.db.ConnectionProfile; -import org.eclipse.jpt.db.JptDbPlugin; -import org.eclipse.jpt.db.ui.internal.DTPUiTools; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.prefs.JpaPreferencePage; -import org.eclipse.swt.SWT; -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.Combo; -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.Link; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; -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.ui.ModifyFacetedProjectWizard; -import org.eclipse.wst.web.ui.internal.wizards.DataModelFacetInstallPage; - -public class JpaFacetWizardPage extends DataModelFacetInstallPage - implements JpaFacetDataModelProperties -{ - public JpaFacetWizardPage() { - super("jpt.jpa.facet.install.page"); //$NON-NLS-1$ - setTitle(JptUiMessages.JpaFacetWizardPage_title); - setDescription(JptUiMessages.JpaFacetWizardPage_description); - setImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_WIZ_BANNER)); - } - - - @Override - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - composite.setLayout(layout); - - new PlatformGroup(composite); - new ConnectionGroup(composite); - new ClasspathConfigGroup(composite); - new PersistentClassManagementGroup(composite); - new OrmXmlGroup(composite); - - setUpRuntimeListener(); - - Dialog.applyDialogFont(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, JpaHelpContextIds.DIALOG_JPA_FACET); - - return composite; - } - - private void setUpRuntimeListener() { - final IFacetedProjectWorkingCopy wc = ( (ModifyFacetedProjectWizard) getWizard() ).getFacetedProjectWorkingCopy(); - // must do it manually the first time - model.setProperty(RUNTIME, wc.getPrimaryRuntime()); - wc.addListener( - new IFacetedProjectListener() { - public void handleEvent( final IFacetedProjectEvent event ) { - model.setProperty(RUNTIME, wc.getPrimaryRuntime()); - } - }, - IFacetedProjectEvent.Type.PRIMARY_RUNTIME_CHANGED - ); - } - - private Button createButton(Composite container, int span, String text, int style) { - Button button = new Button(container, SWT.NONE | style); - button.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - button.setLayoutData(gd); - return button; - } - - private Combo createCombo(Composite container, int span, boolean fillHorizontal) { - Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); - GridData gd; - if (fillHorizontal) { - gd = new GridData(GridData.FILL_HORIZONTAL); - } - else { - gd = new GridData(); - } - gd.horizontalSpan = span; - combo.setLayoutData(gd); - return combo; - } - - @Override - protected String[] getValidationPropertyNames() { - return new String[] { - PLATFORM_ID, - CONNECTION, - USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, - USER_OVERRIDE_DEFAULT_SCHEMA, - USE_SERVER_JPA_IMPLEMENTATION, - JPA_LIBRARY, - DISCOVER_ANNOTATED_CLASSES - }; - } - - @Override - public boolean isPageComplete() { - if (! super.isPageComplete()) { - return false; - } - else { - return (model.validate().getSeverity() != IStatus.ERROR); - } - } - - @Override - public void setVisible(boolean visible) { - super.setVisible(visible); - if (visible) { - setErrorMessage(); - } - } - - - private final class PlatformGroup - { - private final Combo platformCombo; - - - public PlatformGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_JPA_PLATFORM); - - platformCombo = createCombo(group, 1, true); - synchHelper.synchCombo(platformCombo, PLATFORM_ID, null); - } - } - - - private final class ConnectionGroup - { - private final Combo connectionCombo; - - private Link connectionLink; - - private Link connectLink; - - private final Button overrideDefaultSchemaButton; - - private final Label defaultSchemaLabel; - - private final Combo defaultSchemaCombo; - - - public ConnectionGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_connectionLabel); - group.setLayout(new GridLayout(3, false)); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); - - connectionCombo = createCombo(group, 3, true); - synchHelper.synchCombo(connectionCombo, CONNECTION, null); - connectionCombo.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateConnectLink(); - } - }); - - connectionLink = new Link(group, SWT.NONE); - GridData data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - connectionLink.setLayoutData(data); - connectionLink.setText(JptUiMessages.JpaFacetWizardPage_connectionLink); - connectionLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - openNewConnectionWizard(); - } - } - ); - - connectLink = new Link(group, SWT.NONE); - data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - connectLink.setLayoutData(data); - connectLink.setText(JptUiMessages.JpaFacetWizardPage_connectLink); - connectLink.setEnabled(false); - connectLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - openConnectionProfile(); - } - }); - - overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK); - overrideDefaultSchemaButton.setSelection(false); - synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, null); - - defaultSchemaLabel = new Label(group, SWT.LEFT); - defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel); - GridData gd = new GridData(); - gd.horizontalSpan = 1; - defaultSchemaLabel.setLayoutData(gd); - - defaultSchemaCombo = createCombo(group, 1, true); - synchHelper.synchCombo( - defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA, - new Control[] {defaultSchemaLabel}); - } - - private void openNewConnectionWizard() { - String connectionName = DTPUiTools.createNewProfile(); - if (connectionName != null) { - model.setProperty(CONNECTION, connectionName); - } - } - - private void openConnectionProfile() { - ConnectionProfile connection = getConnectionProfile(); - connection.connect(); - model.setBooleanProperty(CONNECTION_ACTIVE, connection.isActive()); - updateConnectLink(); - return; - } - - private void updateConnectLink() { - ConnectionProfile connectionProfile = getConnectionProfile(); - connectLink.setEnabled(! connectionProfile.isNull() && ! connectionProfile.isConnected()); - } - - private ConnectionProfile getConnectionProfile() { - return JptDbPlugin.instance().getConnectionProfileRepository().connectionProfileNamed(model.getStringProperty(CONNECTION)); - } - } - - - private final class ClasspathConfigGroup - { - private final Button useServerLibButton; - - private final Button specifyLibButton; - - private final Combo jpaLibCombo; - - private final Link jpaPrefsLink; - - private final Link userLibsLink; - - - public ClasspathConfigGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_jpaImplementationLabel); - group.setLayout(new GridLayout(2, false)); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); - - useServerLibButton = createButton(group, 2, JptUiMessages.JpaFacetWizardPage_userServerLibLabel, SWT.RADIO); - synchHelper.synchRadio(useServerLibButton, USE_SERVER_JPA_IMPLEMENTATION, null); - - specifyLibButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_specifyLibLabel, SWT.RADIO); - synchHelper.synchRadio(specifyLibButton, USE_USER_JPA_LIBRARY, null); - - jpaLibCombo = createCombo(group, 1, true); - synchHelper.synchCombo(jpaLibCombo, JPA_LIBRARY, null); - - jpaPrefsLink = new Link(group, SWT.NONE); - GridData data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - jpaPrefsLink.setLayoutData(data); - jpaPrefsLink.setText(JptUiMessages.JpaFacetWizardPage_jpaPrefsLink); - jpaPrefsLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - promptToConfigJpaPrefs(); - } - } - ); - - userLibsLink = new Link(group, SWT.NONE); - data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - userLibsLink.setLayoutData(data); - userLibsLink.setText(JptUiMessages.JpaFacetWizardPage_userLibsLink); - userLibsLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - promptToConfigUserLibraries(); - } - } - ); - } - - private void promptToConfigJpaPrefs() { - PreferenceDialog dlg = - PreferencesUtil.createPreferenceDialogOn( - getShell(), - JpaPreferencePage.ID, - new String[] {JpaPreferencePage.ID}, - null); - dlg.open(); - model.notifyPropertyChange(JPA_LIBRARY, IDataModel.VALID_VALUES_CHG); - model.notifyPropertyChange(JPA_LIBRARY, IDataModel.DEFAULT_CHG); - } - - private void promptToConfigUserLibraries() { - PreferenceDialog dlg = - PreferencesUtil.createPreferenceDialogOn( - getShell(), - JavaUI.ID_USER_LIBRARY_PREFERENCE_PAGE, - new String[] {JavaUI.ID_USER_LIBRARY_PREFERENCE_PAGE}, - null); - dlg.open(); - model.notifyPropertyChange(JPA_LIBRARY, IDataModel.VALID_VALUES_CHG); - } - } - - - private final class PersistentClassManagementGroup - { - private final Button discoverClassesButton; - - private final Button listClassesButton; - - - public PersistentClassManagementGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_persistentClassManagementLabel); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); - - discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO); - synchHelper.synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null); - - listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO); - synchHelper.synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null); - } - } - - - private final class OrmXmlGroup - { - private final Button createOrmXmlButton; - - - public OrmXmlGroup(Composite composite) { - Composite group = new Composite(composite, SWT.NONE); - group.setLayout(new GridLayout()); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.DIALOG_CREATE_ORM); - - createOrmXmlButton = new Button(group, SWT.CHECK); - createOrmXmlButton.setText(JptUiMessages.JpaFacetWizardPage_createOrmXmlButton); - synchHelper.synchCheckbox(createOrmXmlButton, CREATE_ORM_XML, null); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java deleted file mode 100644 index 437a2c4b9f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectFirstPage.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards; - -import org.eclipse.jpt.ui.internal.JpaHelpContextIds; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jst.j2ee.ui.project.facet.UtilityProjectFirstPage; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public class NewJpaProjectFirstPage extends UtilityProjectFirstPage -{ - public NewJpaProjectFirstPage(IDataModel dataModel, String pageName) { - super(dataModel, pageName); - setTitle(JptUiMessages.NewJpaProjectWizard_firstPage_title); - setDescription(JptUiMessages.NewJpaProjectWizard_firstPage_description); - setInfopopID(JpaHelpContextIds.NEW_JPA_PROJECT); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java deleted file mode 100644 index 53d34954f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/NewJpaProjectWizard.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jst.j2ee.ui.project.facet.UtilityProjectWizard; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -public class NewJpaProjectWizard extends UtilityProjectWizard { - - public NewJpaProjectWizard() { - super(); - setWindowTitle(JptUiMessages.NewJpaProjectWizard_title); - } - - public NewJpaProjectWizard(IDataModel model) { - super(model); - setWindowTitle(JptUiMessages.NewJpaProjectWizard_title); - } - - // TODO - when we have a data model to add -// protected IDataModel createDataModel() { -// return DataModelFactory.createDataModel(new UtilityProjectCreationDataModelProvider()); -// } - - @Override - protected ImageDescriptor getDefaultPageImageDescriptor() { - return JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_WIZ_BANNER); - } - - @Override - protected IFacetedProjectTemplate getTemplate() { - return ProjectFacetsManager.getTemplate("jpt.jpa.template"); - } - - @Override - protected IWizardPage createFirstPage() { - return new NewJpaProjectFirstPage(model, "first.page"); //$NON-NLS-1$ - } - - @Override - protected String getFinalPerspectiveID() { - return "org.eclipse.jpt.ui.jpaPerspective"; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java deleted file mode 100644 index 5dfd091bc4..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/AnnotatedEntityTemplate.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*; -import java.util.*; - -public class AnnotatedEntityTemplate -{ - protected static String nl; - public static synchronized AnnotatedEntityTemplate create(String lineSeparator) - { - nl = lineSeparator; - AnnotatedEntityTemplate result = new AnnotatedEntityTemplate(); - nl = null; - return result; - } - - public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; - protected final String TEXT_1 = "package "; - protected final String TEXT_2 = ";"; - protected final String TEXT_3 = NL; - protected final String TEXT_4 = NL + "import "; - protected final String TEXT_5 = ";"; - protected final String TEXT_6 = NL + NL + "/**" + NL + " * Entity implementation class for Entity: "; - protected final String TEXT_7 = NL + " *" + NL + " */"; - protected final String TEXT_8 = NL; - protected final String TEXT_9 = "(name=\""; - protected final String TEXT_10 = "\")"; - protected final String TEXT_11 = NL + "@Table(name=\""; - protected final String TEXT_12 = "\")"; - protected final String TEXT_13 = NL; - protected final String TEXT_14 = NL + "@IdClass("; - protected final String TEXT_15 = ".class)"; - protected final String TEXT_16 = NL + "public class "; - protected final String TEXT_17 = " extends "; - protected final String TEXT_18 = " implements "; - protected final String TEXT_19 = ", "; - protected final String TEXT_20 = " {" + NL + "" + NL + "\t"; - protected final String TEXT_21 = " " + NL + "\t@Id"; - protected final String TEXT_22 = NL + "\tprivate "; - protected final String TEXT_23 = " "; - protected final String TEXT_24 = ";"; - protected final String TEXT_25 = NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tpublic "; - protected final String TEXT_26 = "() {" + NL + "\t\tsuper();" + NL + "\t}"; - protected final String TEXT_27 = " " + NL + "\t@Id "; - protected final String TEXT_28 = " " + NL + "\tpublic "; - protected final String TEXT_29 = " get"; - protected final String TEXT_30 = "() {" + NL + "\t\treturn this."; - protected final String TEXT_31 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set"; - protected final String TEXT_32 = "("; - protected final String TEXT_33 = " "; - protected final String TEXT_34 = ") {" + NL + "\t\tthis."; - protected final String TEXT_35 = " = "; - protected final String TEXT_36 = ";" + NL + "\t}"; - protected final String TEXT_37 = NL + " " + NL + "}"; - protected final String TEXT_38 = NL; - - public String generate(Object argument) - { - final StringBuffer stringBuffer = new StringBuffer(); - CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument; -if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") { - stringBuffer.append(TEXT_1); - stringBuffer.append(model.getJavaPackageName()); - stringBuffer.append(TEXT_2); - } - stringBuffer.append(TEXT_3); - Collection<String> imports = model.getImports(false); -for (String anImport : imports) { - stringBuffer.append(TEXT_4); - stringBuffer.append(anImport); - stringBuffer.append(TEXT_5); - } - stringBuffer.append(TEXT_6); - stringBuffer.append(model.getEntityName()); - stringBuffer.append(TEXT_7); - stringBuffer.append(TEXT_8); - stringBuffer.append(model.getArtifactType()); - String ENTITY_NAME = model.getEntityName(); -if (model.isEntityNameSet()) { - stringBuffer.append(TEXT_9); - stringBuffer.append(ENTITY_NAME); - stringBuffer.append(TEXT_10); - } - if (model.isTableNameSet()) { - stringBuffer.append(TEXT_11); - stringBuffer.append(model.getTableName()); - stringBuffer.append(TEXT_12); - } - stringBuffer.append(TEXT_13); - stringBuffer.append(model.getInheritanceStrategy()); - if (model.isCompositePK()) { - stringBuffer.append(TEXT_14); - stringBuffer.append(model.getIdClassName()); - stringBuffer.append(TEXT_15); - } - stringBuffer.append(TEXT_16); - stringBuffer.append(model.getClassName()); - String superClass = model.getSuperclassName(); - if (! "".equals(superClass)) { - stringBuffer.append(TEXT_17); - stringBuffer.append(superClass); - } - - List<String> interfaces = model.getInterfaces(); - if (interfaces.size()>0) { - stringBuffer.append(TEXT_18); - } - for (int i=0; i<interfaces.size(); i++) { - String INTERFACE = (String) interfaces.get(i); - if (i>0) { - stringBuffer.append(TEXT_19); - } - stringBuffer.append(INTERFACE); - } - stringBuffer.append(TEXT_20); - List<EntityRow> fields = model.getEntityFields(); - List<String> pkFields = model.getPKFields(); - for (EntityRow entity : fields) { - String NAME = entity.getName(); - if (pkFields.contains(NAME) && model.isFieldAccess()) { - - stringBuffer.append(TEXT_21); - } - stringBuffer.append(TEXT_22); - stringBuffer.append(entity.getType()); - stringBuffer.append(TEXT_23); - stringBuffer.append(entity.getName()); - stringBuffer.append(TEXT_24); - } - stringBuffer.append(TEXT_25); - stringBuffer.append(model.getClassName()); - stringBuffer.append(TEXT_26); - - fields = model.getEntityFields(); - if (fields != null) for (int i=0; i<fields.size(); i++) { - EntityRow field = (EntityRow) fields.get(i); - String TYPE = field.getType(); - String NAME = field.getName(); - String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1); - if (pkFields.contains(NAME) && !model.isFieldAccess()) { - - stringBuffer.append(TEXT_27); - } - stringBuffer.append(TEXT_28); - stringBuffer.append(TYPE); - stringBuffer.append(TEXT_29); - stringBuffer.append(METHOD); - stringBuffer.append(TEXT_30); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_31); - stringBuffer.append(METHOD); - stringBuffer.append(TEXT_32); - stringBuffer.append(TYPE); - stringBuffer.append(TEXT_33); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_34); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_35); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_36); - } - stringBuffer.append(TEXT_37); - stringBuffer.append(TEXT_38); - return stringBuffer.toString(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java deleted file mode 100644 index 06a7ea6f6f..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityClassWizardPage.java +++ /dev/null @@ -1,471 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import java.io.File; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.viewers.DecoratingLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.internal.wizard.NewJavaClassWizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.model.WorkbenchContentProvider; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacet; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -public class EntityClassWizardPage extends NewJavaClassWizardPage{ - - private static final String JPA_FACET = "jpt.jpa";//$NON-NLS-1$ - private static final String XML_EXTENSION = ".xml";//$NON-NLS-1$ - private static final String PERSISTENCE_XML = "persistence.xml";//$NON-NLS-1$ - private static final String META_INF = "META-INF";//$NON-NLS-1$ - private static final String EMPTY = "";//$NON-NLS-1$ - private static final char SLASH = '/'; //$NON-NLS-1$ - private static final String SINGLE_TABLE = "SINGLE_TABLE";//$NON-NLS-1$ - private static final String TABLE_PER_CLASS = "TABLE_PER_CLASS";//$NON-NLS-1$ - private static final String JOINED = "JOINED";//$NON-NLS-1$ - private static final String[] INHERITANCE_STRATEGIES = new String[] { - EMPTY, - SINGLE_TABLE, - TABLE_PER_CLASS, - JOINED }; - private Combo inheritanceStrategyCombo; - private Button entityButton; - private Button mapedAsSuperclassButton; - private Button inheritanceButton; - private Label displayNameLabel; - private Button xmlSupportButton; - private boolean isFirstCheck = true; - private Text ormXmlName; - private Button browseButton; - - public EntityClassWizardPage(IDataModel model, String pageName, - String pageDesc, String pageTitle, String moduleType) { - super(model, pageName, pageDesc, pageTitle, moduleType); - } - - /* Create top level composite (class properties) and add the entity's specific inheritance group - * @see org.eclipse.jst.j2ee.internal.wizard.NewJavaClassWizardPage#createTopLevelComposite(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = super.createTopLevelComposite(parent); - createInheritanceControl(composite); - inheritanceButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean isChecked = inheritanceButton.getSelection(); - if (isChecked) { - entityButton.setSelection(true); - mapedAsSuperclassButton.setSelection(false); - } - inheritanceStrategyCombo.setEnabled(isChecked); - model.setBooleanProperty(IEntityDataModelProperties.ENTITY, true); - model.setBooleanProperty(IEntityDataModelProperties.MAPPED_AS_SUPERCLASS, false); - entityButton.setEnabled(!isChecked); - mapedAsSuperclassButton.setEnabled(!isChecked); - } - }); - createXMLstorageControl(composite); - xmlSupportButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean isChecked = xmlSupportButton.getSelection(); - ormXmlName.setEnabled(isChecked); - browseButton.setEnabled(isChecked); - if (isFirstCheck) { - ormXmlName.setText(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - isFirstCheck = false; - } - //Disable the choose alternative XML : see enhancement request 152461 - //The creation of alternative mapping is problematic - disableMappingXMLChooseGroup(); - } - }); - return composite; - } - - /** - * Create the inheritance group - * @param parent the main composite - */ - private void createInheritanceControl(Composite parent) { - Group group = createGroup(parent, EntityWizardMsg.INHERITANCE_GROUP); - entityButton = createRadioButton(group, EntityWizardMsg.ENTITY, IEntityDataModelProperties.ENTITY); - mapedAsSuperclassButton = createRadioButton(group, EntityWizardMsg.MAPPED_AS_SUPERCLASS, IEntityDataModelProperties.MAPPED_AS_SUPERCLASS); - inheritanceButton = createCheckButton(group, GridData.HORIZONTAL_ALIGN_FILL, 1/*horizontal span*/, EntityWizardMsg.INHERITANCE_CHECK_BOX, IEntityDataModelProperties.INHERITANCE); - createComboBox(group, IEntityDataModelProperties.INHERITANCE_STRATEGY); - } - - /** - * Create the group, which manage entity mapping registration - * @param parent the main composite - */ - private void createXMLstorageControl(Composite parent) { - Group group = createGroup(parent, EntityWizardMsg.XML_STORAGE_GROUP); - xmlSupportButton = createCheckButton(group, GridData.FILL_HORIZONTAL, 3/*horizontal span*/, EntityWizardMsg.XML_SUPPORT, IEntityDataModelProperties.XML_SUPPORT); - createBrowseGroup(group, EntityWizardMsg.CHOOSE_XML, IEntityDataModelProperties.XML_NAME); - ormXmlName.setEnabled(false); - browseButton.setEnabled(false); - } - - /** - * @param parent the main composite - * @param text the name/title of the group - * @return the created group - */ - private Group createGroup(Composite parent, String text) { - Group group = new Group(parent, SWT.NONE); - GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL); - groupGridData.horizontalSpan = 3; - group.setLayoutData(groupGridData); - group.setLayout(new GridLayout(3, false)); - group.setText(text); - return group; - } - - /** - * Create radio button - * @param parent the main composite - inheritance group - * @param text the label of the button - * @param property the related property to which this button will be synchronized - * @return the created button - */ - private Button createRadioButton(Composite parent, String text, String property) { - Button button = new Button(parent, SWT.RADIO); - GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL); - groupGridData.horizontalSpan = 3; - button.setLayoutData(groupGridData); - button.setText(text); - synchHelper.synchRadio(button, property, /*dependentControls*/ null); - return button; - } - - /** - * Create check button - * @param parent the main composite - inheritance group - * @param text the label of the button - * @param property the related property to which this button will be synchronized - * @return the created button - */ - private Button createCheckButton(Composite parent, int fillStrategy, int horizontalSpan, String text, String property) { - final Button button = new Button(parent, SWT.CHECK); - GridData groupGridData = new GridData(fillStrategy); - groupGridData.horizontalSpan = horizontalSpan; - button.setLayoutData(groupGridData); - button.setText(text); - synchHelper.synchCheckbox(button, property, /*dependentControls*/ null); - return button; - } - - /** - * Create combo box, which presents the set of possible inheritance strategies - * @param parent the main composite - inheritance group - * @param property the related property to which this button will be synchronized - * @return - */ - private Combo createComboBox(Composite parent, String property) { - inheritanceStrategyCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY); - GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL); - groupGridData.horizontalSpan = 2; - inheritanceStrategyCombo.setLayoutData(groupGridData); - inheritanceStrategyCombo.setItems(INHERITANCE_STRATEGIES); - synchHelper.synchCombo(inheritanceStrategyCombo, property, /*dependentControls*/ null); - inheritanceStrategyCombo.setEnabled(false); - return inheritanceStrategyCombo; - - } - - /** - * Create XML group - * @param parent the main composite - * @param label the name of the group - * @param property the related property to which this group will be synchronized - * @return the created group - */ - private void createBrowseGroup(Composite parent, String label, String property) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout(3, false)); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - displayNameLabel = new Label(composite, SWT.LEFT); - displayNameLabel.setText(label); - displayNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - ormXmlName = new Text(composite, SWT.SINGLE | SWT.BORDER); - ormXmlName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - browseButton = new Button(composite, SWT.PUSH); - browseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL); - GridData browseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - browseButtonData.horizontalSpan = 1; - browseButton.setLayoutData(browseButtonData); - browseButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - handleChooseXmlButtonPressed(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // Do nothing - } - }); - synchHelper.synchText(ormXmlName, property, /*dependentControls*/null); - ormXmlName.setEnabled(false); - //Disable the choose alternative XML : see enhancement request 152461 - //The creation of alternative mapping is problematic - disableMappingXMLChooseGroup(); - } - - /** - * Process browsing when the Browse... button have been pressed. Allow choosing of - * XML for entity mapping registration - * - */ - private void handleChooseXmlButtonPressed() { - IProject project = (IProject) getDataModel().getProperty(INewJavaClassDataModelProperties.PROJECT); - if (project == null) { - return; - } - ISelectionStatusValidator validator = getDialogSelectionValidator(); - ViewerFilter filter = getDialogViewerFilter(); - ITreeContentProvider contentProvider = new WorkbenchContentProvider(); - ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); - SelectMappingXMLDialog dialog = new SelectMappingXMLDialog(getShell(), labelProvider, contentProvider); - dialog.setValidator(validator); - dialog.setTitle(EntityWizardMsg.MAPPING_XML_TITLE); - dialog.setMessage(EntityWizardMsg.CHOOSE_MAPPING_XML_MESSAGE); - dialog.addFilter(filter); - - IFile rootFolder = project.getFile(J2EEProjectUtilities.getSourceContainers(project)[0].getResource().getName() + SLASH + ormXmlName.getText().trim());//TODO - dialog.setInput(J2EEProjectUtilities.getManifestFile(project).getParent().getParent()); - - if (project != null) - dialog.setInitialSelection(rootFolder); - if (dialog.open() == Window.OK) { - ormXmlName.setText(dialog.getChosenName()); - model.validateProperty(IEntityDataModelProperties.XML_NAME); - } - } - - /** - * This method can be extended by subclasses, as it does some basic validation. - * @return new instance of the Selection validator for the SelectMappingXMLDialog - */ - protected ISelectionStatusValidator getDialogSelectionValidator() { - return new ISelectionStatusValidator() { - public IStatus validate(Object[] selection) { - if (selection != null && selection.length > 0 && selection[0] != null && !(selection[0] instanceof IProject)) - return WTPCommonPlugin.OK_STATUS; - return WTPCommonPlugin.createErrorStatus(EntityWizardMsg.INCORRECT_XML_NAME); - } - }; - } - - /** - * This method create filter for the browse/add alternative mapping XML - * @return new instance of viewer filter for the SelectMappingXMLDialog - */ - protected ViewerFilter getDialogViewerFilter() { - return new ViewerFilter() { - @Override - public boolean select(Viewer viewer, Object parent, Object element) { - if (element instanceof IFolder) { - IProject project = (IProject) getDataModel().getProperty(INewJavaClassDataModelProperties.PROJECT); - IFolder folder = (IFolder)element; - if (folder.contains(J2EEProjectUtilities.getManifestFile(project))) { - return true; - } - return false; - } else if (element instanceof IFile) { - IFile file = (IFile) element; - if (file.getName().endsWith(XML_EXTENSION) && !file.getName().equals(PERSISTENCE_XML)) { - return true; - } - } - return false; - } - }; - } - - private void disableMappingXMLChooseGroup() { - //Disable the choose alternative XML : see enhancement request 152461 - //The creation of alternative mapping is problematic - displayNameLabel.setEnabled(false); - ormXmlName.setEnabled(false); - browseButton.setEnabled(false); - - } - - /** - * This method is used by the project list initializer. The method checks - * if the specified project is valid to include it in the project list. - * - * <p>Subclasses of this wizard page should override this method to - * adjust filtering of the projects to their needs. </p> - * - * @param project reference to the project to be checked - * - * @return <code>true</code> if the project is valid to be included in - * the project list, <code>false</code> - otherwise. - */ - @Override - protected boolean isProjectValid(IProject project) { - IProjectFacet jpaFacet = ProjectFacetsManager.getProjectFacet(JPA_FACET); - IFacetedProject fProject = null; - try { - fProject = ProjectFacetsManager.create(project); - } catch (CoreException e) { - return false; - } - return (project.isAccessible() && fProject != null && fProject.hasProjectFacet(jpaFacet)); - } - - private class SelectMappingXMLDialog extends ElementTreeSelectionDialog{ - - private Text newXmlName; - private String xmlName = EMPTY; - private IStatus currentStatus = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY, null); - - public SelectMappingXMLDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) { - super(parent, labelProvider, contentProvider); - } - - /* - * @see Dialog#createDialogArea(Composite) - */ - @Override - protected Control createDialogArea(Composite parent) { - Composite composite = (Composite)super.createDialogArea(parent); - Label fileNameLabel = new Label(composite, SWT.LEFT); - fileNameLabel.setText(EntityWizardMsg.XML_NAME_TITLE); - fileNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - newXmlName = new Text(composite, SWT.SINGLE | SWT.BORDER); - newXmlName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - newXmlName.addKeyListener(new KeyAdapter() { - @Override - public void keyReleased(KeyEvent e) { - super.keyReleased(e); - xmlName = newXmlName.getText(); - TreeSelection selection = (TreeSelection)getTreeViewer().getSelection(); - IResource selectedResource = (IResource)selection.getFirstElement(); - if (selectedResource instanceof IFile) { - getTreeViewer().setSelection(new TreeSelection(new TreePath(getSegments(selectedResource.getParent())))); - } - updateOKStatus(); - } - - }); - return composite; - } - - /** - * @return the name of the alternative mapping XML - */ - public String getChosenName() { - String result = EMPTY; - Object element = getFirstResult(); - if (element instanceof IContainer) { - IContainer container = (IContainer) element; - result = container.getFullPath().toString() + File.separatorChar + xmlName; - } else { - IFile f = (IFile) element; - result = f.getFullPath().toOSString(); - } - result = removeRedundantSegmentFromName(result); - return result; - } - - @Override - /* - * @see ElementTreeSelectionDialog#updateOKStatus(Composite) - */ - protected void updateOKStatus() { - super.updateOKStatus(); - TreeSelection selection = (TreeSelection)getTreeViewer().getSelection(); - IResource selectedResource = (IResource)selection.getFirstElement(); - if (selectedResource instanceof IFile) { - IFile file = (IFile)selectedResource; - xmlName = file.getName(); - newXmlName.setText(xmlName); - currentStatus = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY, null); - } - if (!xmlName.endsWith(XML_EXTENSION)) { - currentStatus = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, EntityWizardMsg.INCORRECT_XML_NAME, null); - } else { - currentStatus = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, EMPTY, null); - } - updateStatus(currentStatus); - } - - /** - * This method is for internal purposes only - * @param input non formated path to the mapping XML - * @return the formated path to the mapping XML - */ - private String removeRedundantSegmentFromName(String input) { - String output = input.substring(input.indexOf(META_INF)); - output = output.replace(File.separatorChar, SLASH); - return output; - } - - /** - * This method is for internal purposes only. It is intended to create correct - * selection of the resource resource - * @param resource - * @return the segments of the resource - */ - private Object[] getSegments(IResource resource) { - Object[] segments = new Object[resource.getFullPath().segments().length]; - for (int i = segments.length - 1; i > -1; i--) { - segments[i] = resource; - resource = resource.getParent(); - } - return segments; - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java deleted file mode 100644 index 3cf301e9d0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityFieldsWizardPage.java +++ /dev/null @@ -1,214 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties; -import org.eclipse.swt.SWT; -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.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; - -public class EntityFieldsWizardPage extends DataModelWizardPage { - - private Text entityNameText; - private Text tableNameText; - private Button tableNameCheckButton; - private Button fieldAccessButton; - private Button propertyAccessButton; - private boolean isNonEntity = true; - private boolean isButtonsCreated = false; - - public EntityFieldsWizardPage(IDataModel model, String pageName) { - super(model, pageName); - setDescription(EntityWizardMsg.ADD_ENTITY_WIZARD_PAGE_DESCRIPTION); - this.setTitle(EntityWizardMsg.ENTITY_PROPERTIES_TITLE); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.ui.wizard.WTPWizardPage#getValidationPropertyNames() - */ - @Override - protected String[] getValidationPropertyNames() { - return new String[]{IEntityDataModelProperties.ENTITY_FIELDS}; - } - - /* Create the main composite and add to it the entity properties - * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#createTopLevelComposite(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout()); - GridData data = new GridData(GridData.FILL_BOTH); - data.widthHint = 300; - data.heightHint = 450; - composite.setLayoutData(data); - composite.pack(); - - entityNameText = createNameGroup(composite, EntityWizardMsg.ENTITY_NAME, IEntityDataModelProperties.ENTITY_NAME); - Group group = createGroup(composite, EntityWizardMsg.TABLE_NAME_GROUP); - tableNameCheckButton= createCheckButton(group, EntityWizardMsg.USE_DEFAULT, IEntityDataModelProperties.TABLE_NAME_DEFAULT); - tableNameText = createNameGroup(group, EntityWizardMsg.TABLE_NAME, IEntityDataModelProperties.TABLE_NAME); - tableNameText.setEnabled(!tableNameCheckButton.getSelection()); - isButtonsCreated = true; - initNameGroup(); - EntityRowTableWizardSection initSection = new EntityRowTableWizardSection(composite, model, IEntityDataModelProperties.ENTITY_FIELDS); - - Group accessTypeGroup = createGroup(composite, EntityWizardMsg.ACCESS_TYPE); - fieldAccessButton = createRadioButton(accessTypeGroup, EntityWizardMsg.FIELD_BASED, IEntityDataModelProperties.FIELD_ACCESS_TYPE); - propertyAccessButton = createRadioButton(accessTypeGroup, EntityWizardMsg.PROPERTY_BASED, IEntityDataModelProperties.PROPERTY_ACCESS_TYPE); - - - IStatus projectStatus = validateProjectName(); - if (!projectStatus.isOK()) { - setErrorMessage(projectStatus.getMessage()); - composite.setEnabled(false); - } - Dialog.applyDialogFont(parent); - return composite; - } - - /** - * @return the status of the project name correctness - */ - protected IStatus validateProjectName() { - // check for empty - if (model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME) == null || model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME).trim().length() == 0) { - return WTPCommonPlugin.createErrorStatus(EntityWizardMsg.NO_JPA_PROJECTS); - } - return WTPCommonPlugin.OK_STATUS; - } - - /** - * Create named group - * @param parent the main composite - * @param label the name of the group - * @param property the related property to which this group will be synchronized - * @return the created group - */ - protected Text createNameGroup(Composite parent, String label, String property) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout(3, false)); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Label displayNameLabel = new Label(composite, SWT.LEFT); - displayNameLabel.setText(label); - displayNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - Text nameText = new Text(composite, SWT.SINGLE | SWT.BORDER); - nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - synchHelper.synchText(nameText, property, /*dependentControls*/null); - return nameText; - } - - /** - * Create group - * @param parent the main composite - * @param text the name of the group - * @return the created group - */ - private Group createGroup(Composite parent, String text) { - Group group = new Group(parent, SWT.NONE); - GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL); - groupGridData.horizontalSpan = 3; - group.setLayoutData(groupGridData); - group.setLayout(new GridLayout(3, false)); - group.setText(text); - return group; - } - - /** - * Create check button - * @param parent the main composite - inheritance group - * @param text the label of the button - * @param property the related property to which this button will be synchronized - * @return the created button - */ - private Button createCheckButton(Composite parent, String text, String property) { - final Button button = new Button(parent, SWT.CHECK); - GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL); - groupGridData.horizontalSpan = 3; - button.setLayoutData(groupGridData); - button.setText(text); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean isChecked = button.getSelection(); - if (tableNameText != null) { - tableNameText.setEnabled(!isChecked); - } - } - }); - synchHelper.synchCheckbox(button, property, /*dependentControls*/ null); - return button; - } - - /** - * Create radio button - * @param parent the main composite - inheritance group - * @param text the label of the button - * @param property the related property to which this button will be synchronized - * @return the created button - */ - private Button createRadioButton(Composite parent, String text, String property) { - Button button = new Button(parent, SWT.RADIO); - GridData groupGridData = new GridData(GridData.FILL_HORIZONTAL); - groupGridData.horizontalSpan = 3; - button.setLayoutData(groupGridData); - button.setText(text); - synchHelper.synchRadio(button, property, /*dependentControls*/ null); - return button; - } - - /* - * If a property changes that we want to validate, force validation on this page. - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModelListener#propertyChanged(java.lang.String, - * java.lang.Object, java.lang.Object) - */ - @Override - public void propertyChanged(DataModelEvent event) { - String propertyName = event.getPropertyName(); - if (IEntityDataModelProperties.MAPPED_AS_SUPERCLASS.equals(propertyName)) { - initNameGroup(); - } - super.propertyChanged(event); - } - - /** - * The methods is for the internal use only. It will set the entity and table name - * group to be disabled if the created artifact is not entity - */ - private void initNameGroup() { - isNonEntity = model.getBooleanProperty(IEntityDataModelProperties.MAPPED_AS_SUPERCLASS); - if (isButtonsCreated) { - entityNameText.setEnabled(!isNonEntity); - tableNameCheckButton.setEnabled(!isNonEntity); - tableNameText.setEnabled(!tableNameCheckButton.getSelection()); - } - } -} - - diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java deleted file mode 100644 index bd725f8d7d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityRowTableWizardSection.java +++ /dev/null @@ -1,745 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.search.IJavaSearchConstants; -import org.eclipse.jdt.core.search.IJavaSearchScope; -import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.IDoubleClickListener; -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.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow; -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.IEntityDataModelProperties; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.jst.j2ee.internal.dialogs.TypeSearchEngine; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -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.Combo; -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.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * The class presents the table with entity fields. In the java file are included also content - * and label provider, add and edit entity dialogs as well as help internal objects - listener - * and callback from the dialog to the main composite (table). - * - */ -public class EntityRowTableWizardSection extends Composite { - - /** - * The possible entity types, mentioned in the specification (Chapter 2.1.1 Persistent Fields and Properties p.20) - */ - protected final static String[] VALID_TYPES = {"int", "long", "short", "char", "boolean", "byte", "double", "float", "java.lang.String", - "byte[]", "char[]", "java.lang.Byte[]", "java.lang.Character[]", "java.math.BigDecimal", "java.math.BigInteger", "java.sql.Date", "java.sql.Time", "java.sql.Timestamp", - "java.util.Date", "java.util.Calendar"}; - - private CheckboxTableViewer mTableViewer = null; - private Table mTableWidget = null; - private final int PK_COLUMN = 0; - private final int NAME_COLUMN = 1; - private final int TYPE_COLUMN = 2; - - - - - private Button addButton; - private Button editButton; - private Button removeButton; - private String title = EntityWizardMsg.ENTITY_FIELDS; - private String[] labelsForCombo = VALID_TYPES; - private String[] labelsForText = new String[]{EntityWizardMsg.TYPE_TEXT_FIELD, EntityWizardMsg.NAME_TEXT_FIELD}; - private IDataModel model; - private String propertyName; - private Image labelProviderImage = null; - private DialogCallback callback; - - - /** - * @param parent the main composite - Entity fields page - * @param model the data model representation - * @param propertyName data property name - */ - public EntityRowTableWizardSection(Composite parent, IDataModel model, String propertyName) { - super(parent, SWT.NONE); - this.model = model; - this.propertyName = propertyName; - - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 4; - layout.marginWidth = 0; - this.setLayout(layout); - this.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label titleLabel = new Label(this, SWT.LEFT); - titleLabel.setText(title); - GridData data = new GridData(); - data.horizontalSpan = 2; - titleLabel.setLayoutData(data); - - mTableWidget = new Table(this, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER); - mTableWidget.setHeaderVisible(true); - mTableWidget.setLinesVisible(true); - - mTableViewer = new CheckboxTableViewer(mTableWidget); - data = new GridData(GridData.FILL_BOTH); - data.verticalSpan = 2; - mTableWidget.setLayoutData(data); - mTableViewer.setContentProvider(new EntityRowContentProvider()); - mTableViewer.setLabelProvider(new EntityRowLabelProvider()); - - final Composite buttonComposition = new Composite(this, SWT.NULL); - layout = new GridLayout(); - layout.marginHeight = 0; - buttonComposition.setLayout(layout); - buttonComposition.setLayoutData(new GridData(GridData.FILL_VERTICAL | GridData.VERTICAL_ALIGN_BEGINNING)); - - addButton = new Button(buttonComposition, SWT.PUSH); - addButton.setText(EntityWizardMsg.ADD_BUTTON_LABEL); - addButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL)); - addButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - handleAddButtonSelected(); - } - public void widgetDefaultSelected(SelectionEvent event) { - //Do nothing - } - }); - - editButton = new Button(buttonComposition, SWT.PUSH); - editButton.setText(EntityWizardMsg.EDIT_BUTTON_LABEL); - editButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL)); - editButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - handleEditButtonSelected(); - } - public void widgetDefaultSelected(SelectionEvent event) { - //Do nothing - } - }); - editButton.setEnabled(false); - mTableViewer.addDoubleClickListener(new IDoubleClickListener() { - public void doubleClick(DoubleClickEvent event) { - handleEditButtonSelected(); - } - }); - - removeButton = new Button(buttonComposition, SWT.PUSH); - removeButton.setText(EntityWizardMsg.REMOVE_BUTTON_LABEL); - removeButton.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL)); - removeButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent event) { - handleRemoveButtonSelected(); - } - public void widgetDefaultSelected(SelectionEvent event) { - //Do nothing - } - }); - removeButton.setEnabled(false); - - mTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - if (editButton != null) { - boolean enabled = ((IStructuredSelection) selection).size() == 1; - editButton.setEnabled(enabled); - } - removeButton.setEnabled(!selection.isEmpty()); - } - }); - - - final TableColumn pkColumn = new TableColumn(mTableWidget, SWT.CHECK); - pkColumn.setText(EntityWizardMsg.KEY); - pkColumn.pack(); - pkColumn.setResizable(false); - - TableColumn nameColumn = new TableColumn(mTableWidget, SWT.NONE); - nameColumn.setText(EntityWizardMsg.NAME_COLUMN); - - TableColumn typeColumn = new TableColumn(mTableWidget, SWT.NONE); - typeColumn.setText(EntityWizardMsg.TYPE_COLUMN); - - this.addControlListener(new ControlAdapter() { - @Override - public void controlResized(ControlEvent e) { - Table table = mTableViewer.getTable(); - TableColumn[] columns = table.getColumns(); - Point buttonArea = buttonComposition.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Rectangle area = table.getParent().getClientArea(); - Point preferredSize = mTableViewer.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT); - int width = area.width - 2 * table.getBorderWidth()- buttonArea.x - columns.length * 2 - pkColumn.getWidth(); - if (preferredSize.y > area.height + table.getHeaderHeight()) { - // Subtract the scrollbar width from the total column width - // if a vertical scrollbar will be required - Point vBarSize = table.getVerticalBar().getSize(); - width -= vBarSize.x; - } - Point oldSize = table.getSize(); - int consumeWidth = 0; - int col = columns.length - 1; - for (int i = 1; i < columns.length; i++) { - if (oldSize.x > area.width) { - // table is getting smaller so make the columns - // smaller first and then resize the table to - // match the client area width - consumeWidth = setColumntWidth(width, columns, consumeWidth, i); - table.setSize(area.width - buttonArea.x - (col * 2 + pkColumn.getWidth()), area.height); - } else { - // table is getting bigger so make the table - // bigger first and then make the columns wider - // to match the client area width - consumeWidth = setColumntWidth(width, columns, consumeWidth, i); - table.setSize(area.width - buttonArea.x - (col * 2 + pkColumn.getWidth()), area.height); - } - } - } - - private int setColumntWidth(int width, TableColumn[] columns, - int consumeWidth, int i) { - if (i < columns.length - 1) { - columns[i].setWidth(width / (columns.length - 1)); - consumeWidth += columns[i].getWidth(); - } else { - columns[i].setWidth(width - consumeWidth); - } - return consumeWidth; - } - }); - - mTableViewer.addCheckStateListener(new PKFieldCheckStateListener()); - callback = new FieldDialogCallback(); - } - - /** - * This method process the Add... button pressed event. It opens dialog to - * add new entity field - */ - private void handleAddButtonSelected() { - AddFieldDialog dialog = new AddFieldDialog(getShell(), title, labelsForCombo, labelsForText); - int result = dialog.open(); - if (result == Window.CANCEL) { - return; - } - EntityRow entityRow = dialog.getEntityRow(); - addEntityRow(entityRow); - if (!entityRow.couldBeKey()) { - mTableViewer.setGrayed(entityRow, true); - } - } - - /** - * Add new entity to the table input - * - * @param entity - * the entity which have to be added to the table - */ - private void addEntityRow(EntityRow entity) { - if (entity == null) - return; - List<EntityRow> valueList = (ArrayList<EntityRow>) mTableViewer.getInput(); - if (valueList == null) - valueList = new ArrayList<EntityRow>(); - valueList.add(entity); - setInput(valueList); - } - - /** - * This method process the Edit... button pressed event. It opens dialog to edit chosen entity field - */ - private void handleEditButtonSelected() { - ISelection s = mTableViewer.getSelection(); - if (!(s instanceof IStructuredSelection)) - return; - IStructuredSelection selection = (IStructuredSelection) s; - if (selection.size() != 1) - return; - - Object selectedObj = selection.getFirstElement(); - EntityRow entityForEdit = (EntityRow) selectedObj; - int index = mTableWidget.getSelectionIndex(); - boolean isChecked = mTableViewer.getChecked(entityForEdit); - - EditFieldDialog dialog = new EditFieldDialog(getShell(), title, labelsForCombo, labelsForText, entityForEdit); - dialog.open(); - EntityRow entityRow = dialog.getEntityRow(); - if (entityRow != null) { - editEntityRow(index, entityRow); - mTableViewer.setChecked(entityRow, isChecked); - if (!entityRow.couldBeKey()) { - mTableViewer.setChecked(entityRow, false); - mTableViewer.setGrayed(entityRow, true); - } else { - mTableViewer.setGrayed(entityRow, false); - } - } - } - - /** - * Edit chosen entity from the table - * @param index the index of the entity in the table - * @param newEntity the edited entity field - */ - private void editEntityRow(int index, EntityRow newEntity) { - if (newEntity == null) - return; - - List<EntityRow> valueList = (ArrayList<EntityRow>) mTableViewer.getInput(); - if (valueList == null) { - valueList = new ArrayList(); - } - - if (index == -1) { - valueList.add(newEntity); - } else { - valueList.set(index, newEntity); - } - - setInput(valueList); - } - - /** - * This method process the Remove button pressed event. - */ - private void handleRemoveButtonSelected() { - ISelection selection = mTableViewer.getSelection(); - if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) - return; - List selectedObject = ((IStructuredSelection) selection).toList(); - removeEntityRow(selectedObject); - } - - /** - * Removes the selected entities from the table - * @param entities list with entities, which should be removed - */ - private void removeEntityRow(Collection entities) { - List<EntityRow> valueList = (ArrayList<EntityRow>) mTableViewer.getInput(); - valueList.removeAll(entities); - setInput(valueList); - } - - /** - * Set the input of the table - * @param input the list with entities which have to be presented in the table - */ - private void setInput(List input) { - mTableViewer.setInput(input); - // Create a new list to trigger property change - ArrayList<EntityRow> newInput = new ArrayList<EntityRow>(); - newInput.addAll(input); - model.setProperty(propertyName, newInput); - } - - /** - * @return the TableViewer of the table - */ - public TableViewer getTableViewer() { - return mTableViewer; - } - - // PROVIDERS FOR THE FIELD TABLE - - /** - * The content provider for the table items - */ - protected class EntityRowContentProvider implements IStructuredContentProvider { - public boolean isDeleted(Object element) { - return false; - } - public Object[] getElements(Object element) { - if (element instanceof List) { - return ((List) element).toArray(); - } - return new Object[0]; - } - public void inputChanged(Viewer aViewer, Object oldInput, Object newInput) { - //Default nothing - } - public void dispose() { - //Default nothing - } - } - - /** - * The label provider for the table items - */ - protected class EntityRowLabelProvider extends LabelProvider implements ITableLabelProvider { - public Image getColumnImage(Object element, int columnIndex) { - if (columnIndex == 0) { - return labelProviderImage; - } - return null; - } - - public String getColumnText(Object element, int columnIndex) { - EntityRow entity = (EntityRow) element; - if (columnIndex == NAME_COLUMN) { - return entity.getName(); - } - if (columnIndex == TYPE_COLUMN) { - return entity.getType(); - } - if (entity.couldBeKey()) { - mTableViewer.setChecked(entity, entity.isKey()); - } - return ""; - } - - @Override - public Image getImage(Object element) { - return labelProviderImage; - } - - @Override - public String getText(Object element) { - String[] array = (String[]) element; - if (array.length > 0) { - return array[0]; - } else { - return super.getText(element); - } - } - } - // END - PROVIDERS FOR THE FIELD TABLE - - /** - * Listener for the Primary Key check box in the table item - */ - private class PKFieldCheckStateListener implements ICheckStateListener { - - public void checkStateChanged(CheckStateChangedEvent event) { - Object[] checkedElements = mTableViewer.getCheckedElements(); - List<String> pkFields = new ArrayList<String>(); - for (Object object : checkedElements) { - EntityRow entity = (EntityRow)object; - if (entity.couldBeKey()) { - pkFields.add(entity.getName()); - } else { - mTableViewer.setChecked(entity, false); - } - } - model.setProperty(IEntityDataModelProperties.PK_FIELDS, pkFields); - } - - } - - // CALLBACK MECHANISM - /** - * Callback interface used by the Add/Edit-FieldDialog classes. - */ - public interface DialogCallback { - - /** - * Validates the text fields. - * <p>Used to decide whether to enable the OK button of the dialog. - * If the method returns <code>true</code> the OK button is enabled, - * otherwise the OK button is disabled.</p> - * @param combo contains the predefined types - * @param texts the name of the entity field - * @return <code>true</code> if the values in the text fields are - * valid, <code>false</code> otherwise. - */ - public boolean validate(Combo combo, Text[] texts); - - /** - * Retrieves the entity presentation object from the fields of the dialog. - * <p>Implementers of the callback can use these method to do some - * preprocessing (like trimming) of the data in the text fields before - * using it. The returned values will be the actual data that will be - * put in the table viewer.</p> - * @param combo contains the predefined types - * @param texts the name of the entity field - * @return the entity presentation object retrieved from the dialog - */ - public EntityRow retrieveResultStrings(Combo combo, Text[] texts); - - } - - /** - * Implementation of the <code>FieldDialogCallback</code> interface for - * both "Name" and "Types" table columns. - */ - public class FieldDialogCallback implements DialogCallback { - - /** - * The first text field should not be empty. - */ - public boolean validate(Combo combo, Text[] texts) { - if (texts.length > 0) { - return texts[0].getText().trim().length() > 0; - } - return true; - } - - /** - * Just retrieves the unmodified values of the text fields as a - * entity field presentation - * @see org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityRow - */ - public EntityRow retrieveResultStrings(Combo combo, Text[] texts) { - EntityRow entity = new EntityRow(); - entity.setFqnTypeName(combo.getText()); - entity.setName(texts[0].getText()); - return entity; - } - } - - // THE DIALOGS USED FOR ADD/EDIT OF ENTITY FIELDS - BEGIN - - /** - * The dialog which collect the information (name and type) for the new entity field - */ - private class AddFieldDialog extends Dialog implements ModifyListener, SelectionListener { - protected String windowTitle; - protected String[] labelsForCombo; - protected String[] labelsForText; - protected Text[] texts; - protected EntityRow entityRow; - protected Combo combo; - - /** - * Constructs AddFieldDialog - * @param shell - * @param windowTitle dialog label - * @param labelsForCombo the elements for the combo - * @param labelsForText name text - */ - public AddFieldDialog(Shell shell, String windowTitle, String[] labelsForCombo, String[] labelsForText) { - super(shell); - this.windowTitle = windowTitle; - this.labelsForCombo = labelsForCombo; - this.labelsForText = labelsForText; - } - - /* Create the area of dialog - * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ - @Override - public Control createDialogArea(Composite parent) { - - Composite composite = (Composite) super.createDialogArea(parent); - getShell().setText(windowTitle); - - GridLayout layout = new GridLayout(); - layout.numColumns = 4; - composite.setLayout(layout); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - data.widthHint = 300; - composite.setLayoutData(data); - - Label label = new Label(composite, SWT.LEFT); - label.setText(labelsForText[0]); - label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - - - combo = new Combo(composite, SWT.SINGLE | SWT.BORDER);// | SWT.READ_ONLY); - combo.setItems(labelsForCombo); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 2; - combo.setLayoutData(data); - - Button browseButton = new Button(composite, SWT.PUSH); - browseButton.setText(EntityWizardMsg.BROWSE_BUTTON_LABEL); - GridData browseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - browseButtonData.horizontalSpan = 1; - browseButton.setLayoutData(browseButtonData); - browseButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - handleChooseEntityTypeButtonPressed(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // Do nothing - } - }); - - int n = labelsForText.length; - texts = new Text[n-1]; - for (int i = 1; i < n; i++) { - Label labelI = new Label(composite, SWT.LEFT); - labelI.setText(labelsForText[i]); - labelI.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - texts[i-1] = new Text(composite, SWT.SINGLE | SWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = 100; - texts[i-1].setLayoutData(data); - } - - combo.setFocus(); - Dialog.applyDialogFont(parent); - return composite; - } - - /** - * Process browsing when the Browse... button have been pressed. Allow adding of entity field - * with arbitrary type. - * @see org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog - */ - private void handleChooseEntityTypeButtonPressed() { - //getControl().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT)); - IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT); - if (packRoot == null) { - return; - } - - // this eliminates the non-exported classpath entries - final IJavaSearchScope scope = TypeSearchEngine.createJavaSearchScopeForAProject(packRoot.getJavaProject(), true, true); - - // This includes all entries on the classpath. - FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(getShell(), false, null/*getWizard().getContainer()*/, scope, IJavaSearchConstants.TYPE); - dialog.setTitle(EntityWizardMsg.TYPE_DIALOG_TITLE); - dialog.setMessage(EntityWizardMsg.TYPE_DIALOG_DESCRIPTION); - - if (dialog.open() == Window.OK) { - IType type = (IType) dialog.getFirstResult(); - String superclassFullPath = IEntityDataModelProperties.EMPTY_STRING; - if (type != null) { - superclassFullPath = type.getFullyQualifiedName(); - } - combo.setText(superclassFullPath); - //getControl().setCursor(null); - return; - } - //getControl().setCursor(null); - } - - - /* Create the content of the dialog - * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite) - */ - @Override - protected Control createContents(Composite parent) { - Composite composite = (Composite) super.createContents(parent); - - combo.addSelectionListener(this); - for (int i = 0; i < texts.length; i++) { - texts[i].addModifyListener(this); - } - - updateOKButton(); - - return composite; - } - - /* Processes OK button pressed event. - * @see org.eclipse.jface.dialogs.Dialog#okPressed() - */ - @Override - protected void okPressed() { - entityRow = callback.retrieveResultStrings(combo, texts); - super.okPressed(); - } - - /** - * @return the entity representation with the information collected from the dialog - */ - public EntityRow getEntityRow() { - return entityRow; - } - - /* Processes text modifying event - * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) - */ - public void modifyText(ModifyEvent e) { - updateOKButton(); - } - - /** - * Sets state of the OK button in accordance with validate method of the callback object - * @see DialogCallback - */ - private void updateOKButton() { - getButton(IDialogConstants.OK_ID).setEnabled(callback.validate(combo, texts)); - } - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetDefaultSelected(SelectionEvent e) { - // TODO Auto-generated method stub - - } - /* Update OK button when the appropriate event occurs - * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetSelected(SelectionEvent e) { - updateOKButton(); - } - } - - /** - * Constructs EditFieldDialog - */ - private class EditFieldDialog extends AddFieldDialog { - protected EntityRow entityRow; - /** - * EditFieldDialog constructor comment. - */ - public EditFieldDialog(Shell shell, String windowTitle, String[] labelsForCombo, String[] labelsForText, EntityRow entity) { - super(shell, windowTitle, labelsForCombo, labelsForText); - this.entityRow = entity; - } - - /* Create the area of the dialog - * @see org.eclipse.jpt.ui.internal.wizards.entity.EntityRowTableWizardSection.AddFieldDialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ - @Override - public Control createDialogArea(Composite parent) { - - Composite composite = (Composite) super.createDialogArea(parent); - - combo.setText(entityRow.getFqnTypeName()); - texts[0].setText(entityRow.getName()); - - return composite; - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java deleted file mode 100644 index a5309c4a95..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityTemplate.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*; -import java.util.*; - -public class EntityTemplate -{ - protected static String nl; - public static synchronized EntityTemplate create(String lineSeparator) - { - nl = lineSeparator; - EntityTemplate result = new EntityTemplate(); - nl = null; - return result; - } - - public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; - protected final String TEXT_1 = "package "; - protected final String TEXT_2 = ";"; - protected final String TEXT_3 = NL; - protected final String TEXT_4 = NL + "import "; - protected final String TEXT_5 = ";"; - protected final String TEXT_6 = NL + NL + "/**" + NL + " * Entity implementation class for Entity: "; - protected final String TEXT_7 = NL + " *" + NL + " */" + NL + "public class "; - protected final String TEXT_8 = " extends "; - protected final String TEXT_9 = " implements "; - protected final String TEXT_10 = ", "; - protected final String TEXT_11 = " {" + NL + "" + NL + "\t"; - protected final String TEXT_12 = " " + NL + "\tprivate "; - protected final String TEXT_13 = " "; - protected final String TEXT_14 = ";"; - protected final String TEXT_15 = NL + "\tprivate static final long serialVersionUID = 1L;\t" + NL + "\tpublic "; - protected final String TEXT_16 = "() {" + NL + "\t\tsuper();" + NL + "\t} " + NL + "\t"; - protected final String TEXT_17 = " " + NL + "\tpublic "; - protected final String TEXT_18 = " get"; - protected final String TEXT_19 = "() {" + NL + " \t\treturn this."; - protected final String TEXT_20 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set"; - protected final String TEXT_21 = "("; - protected final String TEXT_22 = " "; - protected final String TEXT_23 = ") {" + NL + "\t\tthis."; - protected final String TEXT_24 = " = "; - protected final String TEXT_25 = ";" + NL + "\t}" + NL + "\t"; - protected final String TEXT_26 = NL + " " + NL + "}"; - protected final String TEXT_27 = NL; - - public String generate(Object argument) - { - final StringBuffer stringBuffer = new StringBuffer(); - CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument; -if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") { - stringBuffer.append(TEXT_1); - stringBuffer.append(model.getJavaPackageName()); - stringBuffer.append(TEXT_2); - } - stringBuffer.append(TEXT_3); - Collection<String> imports = model.getImports(false); -for (String anImport : imports) { - stringBuffer.append(TEXT_4); - stringBuffer.append(anImport); - stringBuffer.append(TEXT_5); - } - stringBuffer.append(TEXT_6); - stringBuffer.append(model.getEntityName()); - stringBuffer.append(TEXT_7); - stringBuffer.append(model.getClassName()); - String superClass = model.getSuperclassName(); - if (! "".equals(superClass)) { - stringBuffer.append(TEXT_8); - stringBuffer.append(superClass); - } - - List<String> interfaces = model.getInterfaces(); - if (interfaces.size()>0) { - stringBuffer.append(TEXT_9); - } - for (int i=0; i<interfaces.size(); i++) { - String INTERFACE = (String) interfaces.get(i); - if (i>0) { - stringBuffer.append(TEXT_10); - } - stringBuffer.append(INTERFACE); - } - stringBuffer.append(TEXT_11); - List<EntityRow> fields = model.getEntityFields(); - for (EntityRow entity : fields) { - - stringBuffer.append(TEXT_12); - stringBuffer.append(entity.getType()); - stringBuffer.append(TEXT_13); - stringBuffer.append(entity.getName()); - stringBuffer.append(TEXT_14); - } - stringBuffer.append(TEXT_15); - stringBuffer.append(model.getClassName()); - stringBuffer.append(TEXT_16); - - fields = model.getEntityFields(); - if (fields != null) for (int i=0; i<fields.size(); i++) { - EntityRow field = (EntityRow) fields.get(i); - String TYPE = field.getType(); - String NAME = field.getName(); - String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1); - - stringBuffer.append(TEXT_17); - stringBuffer.append(TYPE); - stringBuffer.append(TEXT_18); - stringBuffer.append(METHOD); - stringBuffer.append(TEXT_19); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_20); - stringBuffer.append(METHOD); - stringBuffer.append(TEXT_21); - stringBuffer.append(TYPE); - stringBuffer.append(TEXT_22); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_23); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_24); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_25); - } - stringBuffer.append(TEXT_26); - stringBuffer.append(TEXT_27); - return stringBuffer.toString(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java deleted file mode 100644 index e212dbd707..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizard.java +++ /dev/null @@ -1,137 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import static org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.*; -import java.lang.reflect.InvocationTargetException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.EntityDataModelProvider; -import org.eclipse.jst.j2ee.internal.plugin.J2EEEditorUtility; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard; - -public class EntityWizard extends DataModelWizard implements INewWizard { - - - private static final String PAGE_ONE = "pageOne"; //$NON-NLS-1$ - private static final String PAGE_TWO = "pageTwo"; //$NON-NLS-1$ - - /** - * Constructs the Entity wizard - * @param model the data model - */ - public EntityWizard(IDataModel model) { - super(model); - setWindowTitle(EntityWizardMsg.ENTITY_WIZARD_TITLE); - setDefaultPageImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.ENTITY_WIZ_BANNER)); - } - - /** - * Empty constructor - */ - public EntityWizard(){ - this(null); - } - - /* Adds the two pages of the entity wizard - * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#doAddPages() - */ - @Override - protected void doAddPages() { - EntityClassWizardPage page1 = new EntityClassWizardPage( - getDataModel(), - PAGE_ONE, - EntityWizardMsg.ADD_ENTITY_WIZARD_PAGE_DESCRIPTION, - EntityWizardMsg.ADD_ENTITY_WIZARD_PAGE_TITLE, - J2EEProjectUtilities.EJB); - addPage(page1); - EntityFieldsWizardPage page2 = new EntityFieldsWizardPage(getDataModel(), PAGE_TWO); - addPage(page2); - } - - /* Return the default data model provider (EntityDataModelProvider in our case) - * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#getDefaultProvider() - */ - @Override - protected IDataModelProvider getDefaultProvider() { - return new EntityDataModelProvider(); - } - - /* Check whether the mandatory information is set and wizard could finish - * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#canFinish() - */ - @Override - public boolean canFinish() { - return getDataModel().isValid(); - } - - /* - * Override the parent method in order to open the generated entity class in java editor - * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard#postPerformFinish() - */ - @Override - protected void postPerformFinish() throws InvocationTargetException { - try { - String className = getDataModel().getStringProperty(QUALIFIED_CLASS_NAME); - IProject p = (IProject) getDataModel().getProperty(PROJECT); - IJavaProject javaProject = J2EEEditorUtility.getJavaProject(p); - IFile file = (IFile) javaProject.findType(className).getResource(); - openEditor(file); - } catch (Exception cantOpen) { - JptUiPlugin.log(cantOpen); - } - } - - /** - * This method is intended for internal use only. It will open the file, sent as parameter - * in its own java editor - * @param file who should be opened - */ - private void openEditor(final IFile file) { - if (getDataModel().getBooleanProperty(OPEN_IN_EDITOR)) { - if (file != null) { - getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - try { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, file, true); - } - catch (PartInitException e) { - JptUiPlugin.log(e); - } - } - }); - } - } - } - - /* Implement the abstract method from IWorkbenchWizard - * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) - */ - public void init(IWorkbench workbench, IStructuredSelection selection) { - getDataModel(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java deleted file mode 100644 index 7fe698b5b5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/EntityWizardMsg.java +++ /dev/null @@ -1,123 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.osgi.util.NLS; - -public class EntityWizardMsg extends NLS { - - private static final String BUNDLE_NAME = "jpt_ui_entity_wizard";//$NON-NLS-1$ - private static ResourceBundle resourceBundle; - - public static String ENTITY_WIZARD_TITLE; - public static String ADD_ENTITY_WIZARD_PAGE_TITLE; - public static String ADD_ENTITY_WIZARD_PAGE_DESCRIPTION; - public static String DEFAULT_PACKAGE_WARNING; - public static String ENTITY_PROPERTIES_TITLE; - public static String ENTITY_PROPERTIES_DESCRIPTION; - public static String ENTITY; - public static String MAPPED_AS_SUPERCLASS; - public static String INHERITANCE_GROUP; - public static String INHERITANCE_CHECK_BOX; - public static String XML_STORAGE_GROUP; - public static String XML_SUPPORT; - public static String CHOOSE_XML; - public static String MAPPING_XML_TITLE; - public static String XML_NAME_TITLE; - public static String INCORRECT_XML_NAME; - public static String CHOOSE_MAPPING_XML_MESSAGE; - public static String TYPE_DIALOG_TITLE; - public static String TYPE_DIALOG_DESCRIPTION; - public static String ENTITY_NAME; - public static String TABLE_NAME; - public static String TABLE_NAME_GROUP; - public static String USE_DEFAULT; - public static String ENTITY_FIELDS; - public static String KEY; - public static String NAME_COLUMN; - public static String TYPE_COLUMN; - public static String NAME_TEXT_FIELD; - public static String TYPE_TEXT_FIELD; - public static String BROWSE_BUTTON_LABEL; - public static String ADD_BUTTON_LABEL; - public static String EDIT_BUTTON_LABEL; - public static String REMOVE_BUTTON_LABEL; - public static String DUPLICATED_ENTITY_NAMES_MESSAGE; - public static String ACCESS_TYPE; - public static String FIELD_BASED; - public static String PROPERTY_BASED; - public static String NO_JPA_PROJECTS; - public static String APPLY_CHANGES_TO_PERSISTENCE_XML; - public static String ADD_MAPPED_SUPERCLASS_TO_XML; - public static String ADD_ENTITY_TO_XML; - private EntityWizardMsg() { - // prevent instantiation of class - } - - static { - NLS.initializeMessages(BUNDLE_NAME, EntityWizardMsg.class); - } - - /** - * Returns the resource bundle used by all classes in this Project - */ - public static ResourceBundle getResourceBundle() { - try { - return ResourceBundle.getBundle(BUNDLE_NAME);//$NON-NLS-1$ - } catch (MissingResourceException e) { - // does nothing - this method will return null and getString(String) will return - // the key it was called with - } - return null; - } - - /** - * Returns the externalized string, mapped to this key - * @param key - * @return the text mapped to the key parameter - */ - public static String getString(String key) { - if (resourceBundle == null) { - resourceBundle = getResourceBundle(); - } - - if (resourceBundle != null) { - try { - return resourceBundle.getString(key); - } catch (MissingResourceException e) { - //exception during string obtaining - return "-" + key + "-";//$NON-NLS-2$//$NON-NLS-1$ - } - } - //return key, because the relevant string missing in the bundle - return "+" + key + "+";//$NON-NLS-2$//$NON-NLS-1$ - } - - /** - * Returns the formated string, mapped to this key - * @param key - * @param arguments - * @return the formated text, mapped to this key, with substituted arguments - */ - public static String getString(String key, Object[] arguments) { - try { - return MessageFormat.format(getString(key), arguments); - } catch (IllegalArgumentException e) { - return getString(key); - } - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java deleted file mode 100644 index 1ea33feaff..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/IdClassTemplate.java +++ /dev/null @@ -1,255 +0,0 @@ -package org.eclipse.jpt.ui.internal.wizards.entity; - -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.*; -import java.util.*; - -public class IdClassTemplate -{ - protected static String nl; - public static synchronized IdClassTemplate create(String lineSeparator) - { - nl = lineSeparator; - IdClassTemplate result = new IdClassTemplate(); - nl = null; - return result; - } - - public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; - protected final String TEXT_1 = "package "; - protected final String TEXT_2 = ";"; - protected final String TEXT_3 = NL; - protected final String TEXT_4 = NL + "import "; - protected final String TEXT_5 = ";"; - protected final String TEXT_6 = NL + NL + "/**" + NL + " * ID class for entity: "; - protected final String TEXT_7 = NL + " *" + NL + " */ " + NL + "public class "; - protected final String TEXT_8 = " "; - protected final String TEXT_9 = " implements "; - protected final String TEXT_10 = ", "; - protected final String TEXT_11 = " { " + NL + " " + NL + "\t"; - protected final String TEXT_12 = " " + NL + "\tprivate "; - protected final String TEXT_13 = " "; - protected final String TEXT_14 = ";"; - protected final String TEXT_15 = NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tpublic "; - protected final String TEXT_16 = "() {}" + NL + "" + NL + "\t"; - protected final String TEXT_17 = NL + NL + "\tpublic "; - protected final String TEXT_18 = " get"; - protected final String TEXT_19 = "() {" + NL + "\t\treturn this."; - protected final String TEXT_20 = ";" + NL + "\t}" + NL + "" + NL + "\tpublic void set"; - protected final String TEXT_21 = "("; - protected final String TEXT_22 = " "; - protected final String TEXT_23 = ") {" + NL + "\t\tthis."; - protected final String TEXT_24 = " = "; - protected final String TEXT_25 = ";" + NL + "\t}" + NL + "\t"; - protected final String TEXT_26 = NL + " " + NL + "\t/*" + NL + "\t * @see java.lang.Object#equals(Object)" + NL + "\t */\t" + NL + "\tpublic boolean equals(Object o) {" + NL + "\t\tif (o == this) {" + NL + "\t\t\treturn true;" + NL + "\t\t}" + NL + "\t\tif (!(o instanceof "; - protected final String TEXT_27 = ")) {" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\t"; - protected final String TEXT_28 = " other = ("; - protected final String TEXT_29 = ") o;" + NL + "\t\treturn true"; - protected final String TEXT_30 = NL + "\t\t\t&& "; - protected final String TEXT_31 = "() == other."; - protected final String TEXT_32 = "()"; - protected final String TEXT_33 = NL + "\t\t\t&& (Double.doubleToLongBits("; - protected final String TEXT_34 = "()) == Double.doubleToLongBits(other."; - protected final String TEXT_35 = "()))"; - protected final String TEXT_36 = NL + "\t\t\t&& (Float.floatToIntBits("; - protected final String TEXT_37 = "()) == Float.floatToIntBits(other."; - protected final String TEXT_38 = "()))"; - protected final String TEXT_39 = NL + "\t\t\t&& ("; - protected final String TEXT_40 = "() == null ? other."; - protected final String TEXT_41 = "() == null : "; - protected final String TEXT_42 = "().equals(other."; - protected final String TEXT_43 = "()))"; - protected final String TEXT_44 = ";" + NL + "\t}" + NL + "\t" + NL + "\t/*\t " + NL + "\t * @see java.lang.Object#hashCode()" + NL + "\t */\t" + NL + "\tpublic int hashCode() {" + NL + "\t\tfinal int prime = 31;" + NL + "\t\tint result = 1;"; - protected final String TEXT_45 = NL + "\t\tresult = prime * result + ("; - protected final String TEXT_46 = "() ? 1 : 0);"; - protected final String TEXT_47 = NL + "\t\tresult = prime * result + "; - protected final String TEXT_48 = "();"; - protected final String TEXT_49 = NL + "\t\tresult = prime * result + ((int) "; - protected final String TEXT_50 = "());"; - protected final String TEXT_51 = NL + "\t\tresult = prime * result + ((int) ("; - protected final String TEXT_52 = "() ^ ("; - protected final String TEXT_53 = "() >>> 32)));"; - protected final String TEXT_54 = NL + "\t\tresult = prime * result + ((int) (Double.doubleToLongBits("; - protected final String TEXT_55 = "() ) ^ (Double.doubleToLongBits("; - protected final String TEXT_56 = "()) >>> 32)));"; - protected final String TEXT_57 = NL + "\t\tresult = prime * result + Float.floatToIntBits("; - protected final String TEXT_58 = "());"; - protected final String TEXT_59 = NL + "\t\tresult = prime * result + ("; - protected final String TEXT_60 = "() == null ? 0 : "; - protected final String TEXT_61 = "().hashCode());"; - protected final String TEXT_62 = NL + "\t\treturn result;" + NL + "\t}" + NL + " " + NL + " " + NL + "}"; - protected final String TEXT_63 = NL; - - public String generate(Object argument) - { - final StringBuffer stringBuffer = new StringBuffer(); - CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument; -if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") { - stringBuffer.append(TEXT_1); - stringBuffer.append(model.getJavaPackageName()); - stringBuffer.append(TEXT_2); - } - stringBuffer.append(TEXT_3); - Collection<String> imports = model.getImports(true); -for (String anImport : imports) { - stringBuffer.append(TEXT_4); - stringBuffer.append(anImport); - stringBuffer.append(TEXT_5); - } - stringBuffer.append(TEXT_6); - stringBuffer.append(model.getClassName()); - stringBuffer.append(TEXT_7); - stringBuffer.append(model.getIdClassName()); - stringBuffer.append(TEXT_8); - List<String> interfaces = model.getInterfaces(); - if (interfaces.size()>0) { - stringBuffer.append(TEXT_9); - } - for (int i=0; i<interfaces.size(); i++) { - String INTERFACE = (String) interfaces.get(i); - if (i>0) { - stringBuffer.append(TEXT_10); - } - stringBuffer.append(INTERFACE); - } - stringBuffer.append(TEXT_11); - List<EntityRow> fields = model.getEntityFields(); - List<String> pkFields = model.getPKFields(); - for (int i=0; i<fields.size(); i++) { - EntityRow entity = (EntityRow) fields.get(i); - if (!pkFields.contains(entity.getName())) { - continue; - } - - stringBuffer.append(TEXT_12); - stringBuffer.append(entity.getType()); - stringBuffer.append(TEXT_13); - stringBuffer.append(entity.getName()); - stringBuffer.append(TEXT_14); - } - stringBuffer.append(TEXT_15); - stringBuffer.append(model.getIdClassName()); - stringBuffer.append(TEXT_16); - - fields = model.getEntityFields(); - if (fields != null) for (int i=0; i<fields.size(); i++) { - EntityRow field = (EntityRow) fields.get(i); - String TYPE = field.getType(); - String NAME = field.getName(); - if (!pkFields.contains(NAME)) { - continue; - } - String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1); - - stringBuffer.append(TEXT_17); - stringBuffer.append(TYPE); - stringBuffer.append(TEXT_18); - stringBuffer.append(METHOD); - stringBuffer.append(TEXT_19); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_20); - stringBuffer.append(METHOD); - stringBuffer.append(TEXT_21); - stringBuffer.append(TYPE); - stringBuffer.append(TEXT_22); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_23); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_24); - stringBuffer.append(NAME); - stringBuffer.append(TEXT_25); - } - stringBuffer.append(TEXT_26); - stringBuffer.append(model.getIdClassName()); - stringBuffer.append(TEXT_27); - stringBuffer.append(model.getIdClassName()); - stringBuffer.append(TEXT_28); - stringBuffer.append(model.getIdClassName()); - stringBuffer.append(TEXT_29); - if (fields != null) for (int i=0; i<fields.size(); i++) { - EntityRow field = (EntityRow) fields.get(i); - String NAME = field.getName(); - if (!pkFields.contains(NAME)) { - continue; - } - String TYPE = field.getType(); - String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1); - if (TYPE.equals("boolean") || TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short") || TYPE.equals("int") || TYPE.equals("long")) { - stringBuffer.append(TEXT_30); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_31); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_32); - } else if (TYPE.equals("double")) { - stringBuffer.append(TEXT_33); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_34); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_35); - } else if (TYPE.equals("float")) { - stringBuffer.append(TEXT_36); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_37); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_38); - } else { - stringBuffer.append(TEXT_39); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_40); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_41); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_42); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_43); - } - } - stringBuffer.append(TEXT_44); - if (fields != null) for (int i=0; i<fields.size(); i++) { - EntityRow field = (EntityRow) fields.get(i); - String NAME = field.getName(); - if (!pkFields.contains(NAME)) { - continue; - } - String TYPE = field.getType(); - String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1); - if (TYPE.equals("boolean")) { - stringBuffer.append(TEXT_45); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_46); - } else if (TYPE.equals("int")) { - stringBuffer.append(TEXT_47); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_48); - } else if (TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short")) { - stringBuffer.append(TEXT_49); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_50); - } else if (TYPE.equals("long")) { - stringBuffer.append(TEXT_51); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_52); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_53); - } else if (TYPE.equals("double")) { - stringBuffer.append(TEXT_54); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_55); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_56); - } else if (TYPE.equals("float")) { - stringBuffer.append(TEXT_57); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_58); - } else { - stringBuffer.append(TEXT_59); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_60); - stringBuffer.append(GET_METHOD); - stringBuffer.append(TEXT_61); - } - } - stringBuffer.append(TEXT_62); - stringBuffer.append(TEXT_63); - return stringBuffer.toString(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java deleted file mode 100644 index 095eb7e7d3..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/CreateEntityTemplateModel.java +++ /dev/null @@ -1,385 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity.data.model; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public class CreateEntityTemplateModel { - - protected IDataModel dataModel; - - private static final String DOT = "."; //$NON-NLS-1$ - private static final String BRACKET = "["; //$NON-NLS-1$ - private static final String PK_SUFFIX = "PK"; //$NON-NLS-1$ - private static final String QUALIFIED_SERIALIZABLE = "java.io.Serializable"; //$NON-NLS-1$ - private static final String PERSISTENCE_PACKAGE = "javax.persistence.*"; //$NON-NLS-1$ - private static final String ENTITY_ANNOTATION = "@Entity"; //$NON-NLS-1$ - private static final String MAPPED_AS_SUPERCLASS_TYPE = "@MappedSuperclass"; //$NON-NLS-1$ - private static final String INHERITANCE_TYPE = "@Inheritance"; //$NON-NLS-1$ - - /** - * Constructs entity model as expansion of the data model - * @param dataModel - */ - public CreateEntityTemplateModel(IDataModel dataModel) { - this.dataModel = dataModel; - } - - /** - * Returns the necessary imports on depends of entity (primary keys) fields. It is used from - * JET emmiter when it generates entity (IdClass) - * @param isIdClass flag, which indicates the case. When it is false, the result is - * the import list for the entity class, in other case the results is the set for the IdClass - * generation - * @return the imports collection with the imports for the generated java class - */ - public Collection<String> getImports(boolean isIdClass) { - Collection<String> collection = new TreeSet<String>(); - - String className = getClassName(); - String superclassName = getQualifiedSuperclassName(); - - if (superclassName != null && superclassName.length() > 0 && - !equalSimpleNames(className, superclassName)) { - collection.add(superclassName); - } - - List interfaces = getQualifiedInterfaces(); - if (interfaces != null) { - Iterator iterator = interfaces.iterator(); - while (iterator.hasNext()) { - String iface = (String) iterator.next(); - if (!equalSimpleNames(getClassName(), iface)) { - collection.add(iface); - } - } - } - if (isIdClass) { - collection.addAll(getIdClassImportList()); - } else { - collection.add(PERSISTENCE_PACKAGE); - collection.addAll(getFieldImportList()); - - } - return collection; - } - - /** - * @return class name of the entity - */ - public String getClassName() { - return getProperty(INewJavaClassDataModelProperties.CLASS_NAME).trim(); - } - - /** - * @return package name when the entity will be generated - */ - public String getJavaPackageName() { - return getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE).trim(); - } - - /** - * @return fully qualified java class name - */ - public String getQualifiedJavaClassName() { - if (!getJavaPackageName().equals(IEntityDataModelProperties.EMPTY_STRING)) { - return getJavaPackageName() + DOT + getClassName(); - } - return getClassName(); - } - - /** - * @return the name - */ - public String getSuperclassName() { - String qualified = getQualifiedSuperclassName(); - if (equalSimpleNames(getClassName(), qualified)) { - return qualified; - } else { - return Signature.getSimpleName(qualified); - } - } - - /** - * @return fully qualified name of the entity's super class - */ - public String getQualifiedSuperclassName() { - return getProperty(INewJavaClassDataModelProperties.SUPERCLASS).trim(); - } - - /** - * @return list with the interfaces implemented from entity class - */ - public List<String> getInterfaces() { - List qualifiedInterfaces = getQualifiedInterfaces(); - List<String> interfaces = new ArrayList<String>(qualifiedInterfaces.size()); - - Iterator iter = qualifiedInterfaces.iterator(); - while (iter.hasNext()) { - String qualified = (String) iter.next(); - if (equalSimpleNames(getClassName(), qualified)) { - interfaces.add(qualified); - } else { - interfaces.add(Signature.getSimpleName(qualified)); - } - } - - return interfaces; - } - - /** - * @return list with the interfaces (fully qualified named) implemented from entity class - */ - public List getQualifiedInterfaces() { - List interfaces = (List) this.dataModel.getProperty(INewJavaClassDataModelProperties.INTERFACES); - if (interfaces == null){ - interfaces = new ArrayList(); - } - interfaces.add(QUALIFIED_SERIALIZABLE); - return interfaces; - } - - /** - * Returns the value of the specified string property - * @param propertyName - * @return string value of teh specified propert - */ - protected String getProperty(String propertyName) { - return dataModel.getStringProperty(propertyName); - } - - /** - * This methods is used for the comparison of fully qualified types - * @param name1 first type name - * @param name2 second type name - * @return whether the simple names of the types are equal - */ - protected boolean equalSimpleNames(String name1, String name2) { - String simpleName1 = Signature.getSimpleName(name1); - String simpleName2 = Signature.getSimpleName(name2); - return simpleName1.equals(simpleName2); - } - - /** - * @return the type of the artifact - Entity or Mapped superclass - */ - public String getArtifactType() { - if(dataModel.getBooleanProperty(IEntityDataModelProperties.MAPPED_AS_SUPERCLASS)) { - return MAPPED_AS_SUPERCLASS_TYPE; - } - return ENTITY_ANNOTATION; - } - - /** - * @return whether entity set inheritance strategy - */ - public boolean isInheritanceSet() { - return dataModel.getBooleanProperty(IEntityDataModelProperties.INHERITANCE); - } - - /** - * @return the name of the inheritance strategy, as it is defined in the specification - */ - public String getInheritanceStrategyName() { - return getProperty(IEntityDataModelProperties.INHERITANCE_STRATEGY); - } - - /** - * @return the constructed @Inheritance annotation with the relevant strategy - * if it is chosen - */ - public String getInheritanceStrategy() { - String result = IEntityDataModelProperties.EMPTY_STRING; - if (isInheritanceSet()) { - result = INHERITANCE_TYPE; - if (!getProperty(IEntityDataModelProperties.INHERITANCE_STRATEGY).equals(IEntityDataModelProperties.EMPTY_STRING)) { //$NON-NLS-1$ - result += "(strategy=InheritanceType." + getProperty(IEntityDataModelProperties.INHERITANCE_STRATEGY) + ")"; //$NON-NLS-1$ $NON-NLS-2$ - - } - } - return result; - } - - /** - * @return whether the generated artifact is not entity - */ - public boolean isNonEntitySuperclass() { - return !dataModel.getBooleanProperty(IEntityDataModelProperties.ENTITY); - } - - /** - * @return true the created artifact will be annotated - * @return false the entity mappings will be registered in XML - */ - public boolean isArtifactsAnnotated() { - return !dataModel.getBooleanProperty(IEntityDataModelProperties.XML_SUPPORT); - } - - public boolean isMappingXMLDefault() { - if (getMappingXMLName().equals(IEntityDataModelProperties.EMPTY_STRING)) { - return true; - } - return getMappingXMLName().equals(JptCorePlugin.getDefaultOrmXmlDeploymentURI(getProject())); - } - - public String getMappingXMLName() { - return dataModel.getStringProperty(IEntityDataModelProperties.XML_NAME).trim(); - } - - public IFile getMappingXmlFile() { - IFile ormFile = null; - IProject project = getProject(); - IPackageFragmentRoot[] sourceFragments = J2EEProjectUtilities.getSourceContainers(project); - for (IPackageFragmentRoot packageFragmentRoot : sourceFragments) { - ormFile = project.getFile(packageFragmentRoot.getResource().getName() + File.separator + getMappingXMLName()); - if (ormFile.exists()) { - break; - } - } - return ormFile; - } - - /** - * @return the entity name (could be different from the class name) - * See <code>isEntityNameSet()<code> - */ - public String getEntityName() { - return getProperty(IEntityDataModelProperties.ENTITY_NAME).trim(); - } - - /** - * @return whether the entity name is different than class name - */ - public boolean isEntityNameSet() { - boolean result = false; - if (!getClassName().equals(getEntityName())) { - result = true; - } - return result; - } - - /** - * @return whether the table name is specified explicitly - */ - public boolean isTableNameSet() { - return !dataModel.getBooleanProperty(IEntityDataModelProperties.TABLE_NAME_DEFAULT); - } - - /** - * @return the table name (if it is specified) - * See <code>isTableNameSet()<code> - */ - public String getTableName() { - return getProperty(IEntityDataModelProperties.TABLE_NAME).trim(); - } - - /** - * @return list with the entity fields - */ - public List<EntityRow> getEntityFields() { - ArrayList<EntityRow> fields = (ArrayList<EntityRow>) dataModel.getProperty(IEntityDataModelProperties.ENTITY_FIELDS); - if (fields == null){ - return new ArrayList<EntityRow>(); - } else - return fields; - } - - /** - * @return list with the imports necessary for the entity (based on its fields) - */ - public List<String> getFieldImportList() { - List<String> imports = new ArrayList<String>(); - List<EntityRow> entities = getEntityFields(); - for (EntityRow entityRow : entities) { - if (!imports.contains(entityRow.getFqnTypeName()) && !entityRow.getType().equals(entityRow.getFqnTypeName())) { - String fqnTypeName = entityRow.getFqnTypeName(); - //remove the array brackets [] for the java.lang.Byte[] & java.lang.Character[] - if (fqnTypeName.indexOf(BRACKET) != -1) { - fqnTypeName = fqnTypeName.substring(0, fqnTypeName.indexOf("[")); - } - imports.add(fqnTypeName); - } - } - return imports; - } - /** - * @return list with the imports necessary for the id class (based on its fields - primary keys of the entity) - */ - public List<String> getIdClassImportList() { - List<String> imports = new ArrayList<String>(); - List<EntityRow> entities = getEntityFields(); - List<String> pkFields = getPKFields(); - for (EntityRow entityRow : entities) { - String name = entityRow.getName(); - if (pkFields.contains(name)) { - if (!imports.contains(entityRow.getFqnTypeName()) && !entityRow.getType().equals(entityRow.getFqnTypeName())) { - imports.add(entityRow.getFqnTypeName()); - } - } - } - return imports; - } - - /** - * @return whether the access type is field based - */ - public boolean isFieldAccess() { - return dataModel.getBooleanProperty(IEntityDataModelProperties.FIELD_ACCESS_TYPE); - } - - /** - * @return the primary key is composite (more than one annotated as primary key field) - */ - public boolean isCompositePK() { - return getPKFields().size() > 1; - } - - /** - * @return list with primary key name(s) - */ - public List<String> getPKFields() { - return (ArrayList<String>)dataModel.getProperty(IEntityDataModelProperties.PK_FIELDS); - } - - /** - * @return constructed name of the id class (entity name + PK as suffix) - */ - public String getIdClassName() { - return getClassName() + PK_SUFFIX; - } - - /** - * @return IProject presentation of JPA project - */ - public IProject getProject() { - String projectName = dataModel.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME); - return ProjectUtilities.getProject(projectName); - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java deleted file mode 100644 index 311e15861c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityDataModelProvider.java +++ /dev/null @@ -1,212 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity.data.model; - -import java.util.ArrayList; -import java.util.Set; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.core.JavaConventions; -import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg; -import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation; -import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages; -import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; - -public class EntityDataModelProvider extends NewJavaClassDataModelProvider implements IEntityDataModelProperties{ - - @Override - public IDataModelOperation getDefaultOperation() { - return new NewEntityClassOperation(getDataModel()); - } - - /** - * Extends: <code>IDataModelProvider#getPropertyNames()</code> - * and add own data model's properties specific for the entity model - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames() - */ - - - @Override - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(INHERITANCE); - propertyNames.add(ENTITY); - propertyNames.add(MAPPED_AS_SUPERCLASS); - propertyNames.add(INHERITANCE_STRATEGY); - propertyNames.add(XML_SUPPORT); - propertyNames.add(XML_NAME); - propertyNames.add(ENTITY_NAME); - propertyNames.add(TABLE_NAME_DEFAULT); - propertyNames.add(TABLE_NAME); - propertyNames.add(ENTITY_FIELDS); - propertyNames.add(PK_FIELDS); - propertyNames.add(FIELD_ACCESS_TYPE); - propertyNames.add(PROPERTY_ACCESS_TYPE); - return propertyNames; - } - - /** - * Returns the default value of the parameter (which should present a valid data model property). - * This method does not accept a null parameter. It may return null. - * - * @see NewJavaClassDataModelProvider#getDefaultProperty(String) - * @see IDataModelProvider#getDefaultProperty(String) - * - * @param propertyName - * @return Object default value of property - */ - @Override - public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(INHERITANCE)) { - return Boolean.FALSE; - } else if (propertyName.equals(ENTITY)) { - return Boolean.TRUE; - } else if (propertyName.equals(MAPPED_AS_SUPERCLASS)) { - return Boolean.FALSE; - } else if (propertyName.equals(XML_SUPPORT)) { - return Boolean.FALSE; - } else if (propertyName.equals(XML_NAME)) { - return EMPTY_STRING; - } else if (propertyName.equals(ENTITY_NAME)) { - return getStringProperty(CLASS_NAME); - } else if (propertyName.equals(TABLE_NAME_DEFAULT)) { - return Boolean.TRUE; - } else if (propertyName.equals(TABLE_NAME)) { - return getStringProperty(CLASS_NAME); - } else if (propertyName.equals(INHERITANCE_STRATEGY)) { - return EMPTY_STRING; - } else if (propertyName.equals(SUPERCLASS)) { - return EMPTY_STRING; - } else if (propertyName.equals(ENTITY_FIELDS)) { - return new ArrayList<EntityRow>(); - } else if (propertyName.equals(PK_FIELDS)) { - return new ArrayList<String>(); - } else if (propertyName.equals(FIELD_ACCESS_TYPE)) { - return Boolean.TRUE; - } else if (propertyName.equals(PROPERTY_ACCESS_TYPE)) { - return Boolean.FALSE; - } - // Otherwise check super for default value for property - return super.getDefaultProperty(propertyName); - } - - /* Adds additional check to the model validation - * @see org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider#validate(java.lang.String) - */ - @Override - public IStatus validate(String propertyName) { - IStatus result = super.validate(propertyName); - if (propertyName.equals(JAVA_PACKAGE)) { - return validateJavaPackage(getStringProperty(propertyName)); - } - if (propertyName.equals(SUPERCLASS) && EMPTY_STRING.equals(getStringProperty(propertyName))) { - return WTPCommonPlugin.OK_STATUS; - } - //Should be check existing of the class with the relevant name - if (propertyName.equals(CLASS_NAME)) { - String classNameValue = getStringProperty(propertyName); - result = super.validateJavaClassName(getStringProperty(propertyName)); - if (result.isOK()){ - return super.canCreateTypeInClasspath(classNameValue); - } - } - if (propertyName.equals(XML_NAME)) { -// String xmlName = getStringProperty(propertyName); -// xmlName = xmlName.substring(xmlName.lastIndexOf(File.separator) + 1); -// return ResourcesPlugin.getWorkspace().validateName(xmlName, IResource.FILE); - } - if (propertyName.equals(ENTITY_FIELDS)) { - return validateFieldsList((ArrayList<EntityRow>) getProperty(propertyName)); - } - return result; - } - - /** - * This method is intended for internal use only. It will be used to validate the correctness of entity package - * in accordance with Java convention requirements. This method will accept a null parameter. - * - * @see NewFilterClassDataModelProvider#validate(String) - * - * @param packName - * @return IStatus is the package name satisfies Java convention requirements - */ - - private IStatus validateJavaPackage(String packName) { - if (packName == null || packName.equals(EMPTY_STRING)) { - return WTPCommonPlugin.createWarningStatus(EntityWizardMsg.DEFAULT_PACKAGE_WARNING); - } - // Use standard java conventions to validate the package name - IStatus javaStatus = JavaConventions.validatePackageName(packName); - if (javaStatus.getSeverity() == IStatus.ERROR) { - String msg = J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage(); - return WTPCommonPlugin.createErrorStatus(msg); - } else if (javaStatus.getSeverity() == IStatus.WARNING) { - String msg = J2EECommonMessages.ERR_JAVA_PACKAGE_NAME_WARNING + javaStatus.getMessage(); - return WTPCommonPlugin.createWarningStatus(msg); - } - // java package name is valid - return WTPCommonPlugin.OK_STATUS; - } - - - /** - * This method is intended for internal use only. It will be used to validate the entity fields - * list to ensure there are not any duplicates. This method will accept a null parameter. - * - * @see NewFilterClassDataModelProvider#validate(String) - * - * @param entities - * @return IStatus is the fields names are unique - */ - private IStatus validateFieldsList(ArrayList<EntityRow> entities) { - if (entities != null && !entities.isEmpty()) { - // Ensure there are not duplicate entries in the list - boolean dup = hasDuplicatesInEntityFields(entities); - if (dup) { - String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE; - return WTPCommonPlugin.createErrorStatus(msg); - } - } - // Return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * This method is intended for internal use only. It provides a simple algorithm for detecting - * if there are duplicate entries in a list. It will accept a null parameter. It will return - * boolean. - * - * @param input - * @return boolean are there duplications in the list - */ - private boolean hasDuplicatesInEntityFields(ArrayList<EntityRow> input) { - if (input == null) { - return false; - } - int n = input.size(); - // nested for loops to check each element to see if other elements are the same - for (int i = 0; i < n; i++) { - EntityRow entity = input.get(i); - for (int j = i + 1; j < n; j++) { - EntityRow intEntity = input.get(j); - if (intEntity.getName().equals(entity.getName())) { - return true; - } - - } - } - return false; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java deleted file mode 100644 index 52d7b0ddc5..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/EntityRow.java +++ /dev/null @@ -1,217 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity.data.model; - -import java.util.Arrays; -import java.util.List; - -public class EntityRow { - - private static final String DOT = "."; - private boolean key = false; - private String name = ""; - private String type = ""; - private String fqnTypeName = ""; - private boolean isSimpleType = false; - - private final static String[] PK_TYPES = {"int", "long", "short", "char", "boolean", "byte", "double", "float", - "java.lang.String", "java.sql.Date", "java.util.Date", "java.lang.Integer", "java.lang.Long", "java.lang.Short", - "java.lang.Character", "java.lang.Boolean", "java.lang.Byte", "java.lang.Double", "java.lang.Float"}; - - private final static List<String> VALID_PK_TYPES = Arrays.asList(PK_TYPES); - - - /** - * Constructs <code>EntityColumn</code>. - */ - public EntityRow() { - super(); - } - - - /** - * - * Constructs <code>EntityColumn</code> with the following parameters - * - * @param fqnTypeName - fully qualified name of the entity field type - * @param name - name of the entity field - * @param isKey - flag which indicates whether the entity field is primary key or part of composite primary key - */ - public EntityRow(String fqnTypeName, String name, boolean isKey) { - super(); - this.fqnTypeName = type; - this.name = name; - this.key = isKey; - if (fqnTypeName.indexOf(DOT) == -1) { - type = fqnTypeName; - isSimpleType = true; - } else { - type = getSimpleName(fqnTypeName); - } - } - - - /** - * @return whether the presented entity field is primary key or part of composite primary key - */ - public boolean isKey() { - return key; - } - - /** - * Sets the presented entity field to be primary key (or part of composite primari key) - * - * @param key - */ - public void setKey(boolean key) { - this.key = key; - } - - /** - * Check whether the type of the entity is allowed to be primary key. - * The limitation in the current implementation is that Embedded PK are not checked - * @return whether the type of field could be used as primary key - */ - public boolean couldBeKey() { - boolean result = false; - result = VALID_PK_TYPES.contains(getFqnTypeName()); - return result; - } - - /** - * @return the name of the entity field - */ - public String getName() { - return name; - } - - /** - * Sets the name of the presented entity field - * @param name - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the type (as a simple name) of the entity field - */ - public String getType() { - return type; - } - - /** - * Sets the type (as a simple name) of the entity field - * - * @param type - */ - public void setType(String type) { - this.type = type; - } - - /** - * @return the type (as fully qualified name) of the entity field - */ - public String getFqnTypeName() { - return fqnTypeName; - } - - /** - * Sets the fully qualified type name of the entity field - * - * @param fqnTypeName - */ - public void setFqnTypeName(String fqnTypeName) { - this.fqnTypeName = fqnTypeName; - if (fqnTypeName.indexOf(DOT) == -1) { - setType(fqnTypeName); - setSimpleType(true); - } else { - setType(getSimpleName(fqnTypeName)); - } - - } - - /** - * @return is the type of the entity field is primitive type - */ - public boolean isSimpleType() { - return isSimpleType; - } - - /** - * Sets the flag which indicate the type of the entity field as primitive type - * - * @param isSimpleType - */ - public void setSimpleType(boolean isSimpleType) { - this.isSimpleType = isSimpleType; - } - - /** - * @return whether the type of the entity field is boolean. The information could be used - * when the name of getter should be constructed - */ - public boolean isBoolean() { - return "boolean".equals(getType()); - } - - /** - * For internal purpose only - * Convert fully qualified name to the simple one - * @param fullyName - * @return the simple name form the fully qualified name parameter(last segment) - */ - private String getSimpleName(String fullyName) { - return fullyName.substring(fullyName.lastIndexOf(DOT) + 1); - - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((fqnTypeName == null) ? 0 : fqnTypeName.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - - /* - * Implement equals, depending from name of the entity field and its type. - * The type is presented from the fully qualified name - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final EntityRow other = (EntityRow) obj; - if (fqnTypeName == null) { - if (other.fqnTypeName != null) - return false; - } else if (!fqnTypeName.equals(other.fqnTypeName)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java deleted file mode 100644 index 9a03daa303..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/model/IEntityDataModelProperties.java +++ /dev/null @@ -1,33 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity.data.model; - -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; - -public interface IEntityDataModelProperties extends INewJavaClassDataModelProperties, IAnnotationsDataModel { - - public static final String ENTITY = "IEntityDataModelProperties.ENTITY"; //$NON-NLS-1$ - public static final String MAPPED_AS_SUPERCLASS = "IEntityDataModelProperties.MAPPED_AS_SUPERCLASS"; //$NON-NLS-1$ - public static final String INHERITANCE = "IEntityDataModelProperties.INHERITANCE"; //$NON-NLS-1$ - public static final String INHERITANCE_STRATEGY = "IEntityDataModelProperties.INHERITANCE_STRATEGY"; //$NON-NLS-1$ - public static final String XML_SUPPORT = "IEntityDataModelProperties.XML_SUPPORT"; //$NON-NLS-1$XML_SUPPORT - public static final String XML_NAME = "IEntityDataModelProperties.XML_NAME"; //$NON-NLS-1$XML_SUPPORT - public static final String ENTITY_NAME = "IEntityDataModelProperties.ENTITY_NAME"; //$NON-NLS-1$ - public static final String TABLE_NAME_DEFAULT = "IEntityDataModelProperties.TABLE_NAME_DEFAULT"; //$NON-NLS-1$ - public static final String TABLE_NAME = "IEntityDataModelProperties.TABLE_NAME"; //$NON-NLS-1$ - public static final String ENTITY_FIELDS = "IEntityDataModelProperties.ENTITY_FIELDS"; //$NON-NLS-1$ - public static final String PK_FIELDS = "IEntityDataModelProperties.PK_FIELDS"; //$NON-NLS-1$ - public static final String FIELD_ACCESS_TYPE = "IEntityDataModelProperties.FIELD_ACCESS_TYPE"; //$NON-NLS-1$ - public static final String PROPERTY_ACCESS_TYPE = "IEntityDataModelProperties.PROPERTY_ACCESS_TYPE"; //$NON-NLS-1$ - public static final String EMPTY_STRING = ""; //$NON-NLS-1$ -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java deleted file mode 100644 index 45645a338d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/entity/data/operation/NewEntityClassOperation.java +++ /dev/null @@ -1,611 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2008 by SAP AG, Walldorf. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAP AG - initial API and implementation - * Dimiter Dimitrov, d.dimitrov@sap.com - initial API and implementation - ***********************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.entity.data.operation; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.codegen.jet.JETEmitter; -import org.eclipse.emf.codegen.jet.JETException; -import org.eclipse.emf.common.util.EList; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaModelMarker; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.resource.orm.AccessType; -import org.eclipse.jpt.core.resource.orm.Attributes; -import org.eclipse.jpt.core.resource.orm.Inheritance; -import org.eclipse.jpt.core.resource.orm.InheritanceType; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmPackage; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.orm.XmlIdClass; -import org.eclipse.jpt.core.resource.orm.XmlIdImpl; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlTable; -import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.wizards.entity.AnnotatedEntityTemplate; -import org.eclipse.jpt.ui.internal.wizards.entity.EntityTemplate; -import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg; -import org.eclipse.jpt.ui.internal.wizards.entity.IdClassTemplate; -import org.eclipse.jpt.ui.internal.wizards.entity.data.model.CreateEntityTemplateModel; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsController; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsControllerManager; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.project.WTPJETEmitter; -import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditProviderOperation; -import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.enablement.nonui.WFTWrappedException; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; - -/** - * The NewEntityClassOperation is IDataModelOperation following the - * IDataModel wizard and operation framework. - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider - * - * This operation is used to generate java classes for the new JPA entity. It uses - * EntityDataModelProvider to store the appropriate properties required to generate the new entity. - * @see org.eclipse.jpt.ui.internal.wizards.entity.data.modelEntityDataModelProvider - * - * A WTPJetEmitter entity template is used to create the class with the entity template. - * @see org.eclipse.jst.j2ee.internal.project.WTPJETEmitter - * @see org.eclipse.jpt.ui.internal.wizards.entity.data.model.CreateEntityTemplateModel - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class NewEntityClassOperation extends AbstractDataModelOperation { - - private static final String DOT_JAVA = ".java"; //$NON-NLS-1$ - private static final String SEPARATOR = "/";//$NON-NLS-1$ - private static final String VERSION_STRING = "1.0";//$NON-NLS-1$ - private static final String FIELD = "FIELD";//$NON-NLS-1$ - private static final String PROPERTY = "PROPERTY";//$NON-NLS-1$ - protected static final String WTP_CUSTOMIZATION_PLUGIN = "WTP_CUSTOMIZATION_PLUGIN"; //$NON-NLS-1$ - protected static final String ANNOTATED_ENTITY_TEMPLATE_FILE = "/templates/annotated_entity.javajet"; //$NON-NLS-1$ - protected static final String ENTITY_TEMPLATE_FILE = "/templates/entity.javajet"; //$NON-NLS-1$ - protected static final String IDCLASS_TEMPLATE_FILE = "/templates/idClass.javajet"; //$NON-NLS-1$ - protected static final String BUILDER_ID = "builderId"; //$NON-NLS-1$ - private static final String EMPTY_STRING = "";//$NON-NLS-1$ - private static final String SINGLE_TABLE = "SINGLE_TABLE";//$NON-NLS-1$ - - /** - * Method name of template implementation classes. - */ - protected static final String GENERATE_METHOD = "generate"; //$NON-NLS-1$ - - /** - * This is the constructor which should be used when creating a NewEntityClassOperation. - * An instance of the CreateEntityTemplateModel should be passed in. This does not accept - * null parameter. It will not return null. - * - * @see ArtifactEditProviderOperation#ArtifactEditProviderOperation(IDataModel) - * @see CreateEntityTemplateModel - * - * @param dataModel - * @return NewFilterClassOperation - */ - public NewEntityClassOperation(IDataModel dataModel) { - super(dataModel); - } - - /** - * The implementation of the execute method drives the running of the operation. - * This implementation will create the java source folder, create the java package, and then - * the entity (or mapped as superclass) and ID class files will be created using templates. - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#execute(org.eclipse.core.runtime.IProgressMonitor) - * @see NewEntityClassOperation#generateUsingTemplates(IProgressMonitor, - * IPackageFragment) - * - * @param monitor - * @throws CoreException - * @throws InterruptedException - * @throws InvocationTargetException - */ - public IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // Create source folder if it does not exist - createJavaSourceFolder(); - // Create java package if it does not exist - IPackageFragment pack = createJavaPackage(); - // Generate filter class using templates - try { - generateUsingTemplates(monitor, pack); - } catch (Exception e) { - return WTPCommonPlugin.createErrorStatus(e.toString()); - } - return OK_STATUS; - } - - /** - * This method will return the java package as specified by the new java - * class data model. If the package does not exist, it will create the - * package. This method should not return null. - * - * @see INewJavaClassDataModelProperties#JAVA_PACKAGE - * @see IPackageFragmentRoot#createPackageFragment(java.lang.String, - * boolean, org.eclipse.core.runtime.IProgressMonitor) - * - * @return IPackageFragment the java package - */ - protected final IPackageFragment createJavaPackage() { - // Retrieve the package name from the java class data model - String packageName = model.getStringProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE); - IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model - .getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT); - IPackageFragment pack = packRoot.getPackageFragment(packageName); - // Handle default package - if (pack == null) { - pack = packRoot.getPackageFragment(""); //$NON-NLS-1$ - } - - // Create the package fragment if it does not exist - if (!pack.exists()) { - String packName = pack.getElementName(); - try { - pack = packRoot.createPackageFragment(packName, true, null); - } catch (JavaModelException e) { - Logger.getLogger().log(e); - } - } - // Return the package - return pack; - } - - /** - * This implementation uses the creation of a CreateEntityTemplateModel and the WTPJETEmitter - * to create the java class with the annotated tags. This method accepts null for monitor, it does not accept null - * for fragment. If annotations are not being used the tags will be omitted from the class. - * - * @see CreateEntityTemplateModel - * @see NewEntityClassOperation#generateTemplateSource(CreateEntityTemplateModel, - * IProgressMonitor) - * - * @param monitor - * @param fragment - * @throws CoreException - * @throws WFTWrappedException - */ - protected void generateUsingTemplates(IProgressMonitor monitor, IPackageFragment fragment) throws WFTWrappedException, CoreException { - // Create the entity template model - CreateEntityTemplateModel tempModel = createTemplateModel(); - IProject project = getTargetProject(); - String entityClassSource = null; - String idClassSource = null; - // Generate the java source based on the entity template models - try { - if (tempModel.isArtifactsAnnotated()) { - AnnotatedEntityTemplate tempImpl = AnnotatedEntityTemplate.create(null); - entityClassSource = generateTemplateSource(tempModel, ANNOTATED_ENTITY_TEMPLATE_FILE, tempImpl, monitor); - } else { - EntityTemplate tempImpl = EntityTemplate.create(null); - entityClassSource = generateTemplateSource(tempModel, ENTITY_TEMPLATE_FILE, tempImpl, monitor); - } - if (tempModel.isCompositePK()) { - IdClassTemplate tempImpl = IdClassTemplate.create(null); - idClassSource = generateTemplateSource(tempModel, IDCLASS_TEMPLATE_FILE, tempImpl, monitor); - } - } catch (Exception e) { - throw new WFTWrappedException(e); - } - if (fragment != null) { - // Create the java file - String javaFileName = tempModel.getClassName() + DOT_JAVA; - ICompilationUnit cu = fragment.getCompilationUnit(javaFileName); - // Add the compilation unit to the java file - if (cu == null || !cu.exists()) { - cu = fragment.createCompilationUnit(javaFileName, entityClassSource, true, monitor); - } - IFile aFile = (IFile) cu.getResource(); - // Let the annotations controller process the annotated resource - if (tempModel.isArtifactsAnnotated()) { - AnnotationsController controller = AnnotationsControllerManager.INSTANCE.getAnnotationsController(project); - if (controller != null) { - controller.process(aFile); - } - } - //Create IdClass if the primary key is complex - if (idClassSource != null) { - String entityPKName = tempModel.getIdClassName() + DOT_JAVA; - ICompilationUnit cu1 = fragment.getCompilationUnit(entityPKName); - // Add the compilation unit to the java file - if (cu1 == null || !cu1.exists()) { - cu1 = fragment.createCompilationUnit(entityPKName, idClassSource, true, monitor); - } - } - } - - if (!tempModel.isArtifactsAnnotated()) { - if (tempModel.isNonEntitySuperclass()) { - addMappedSuperclassToXLM(tempModel, project).schedule(); - } else { - addEntityToXML(tempModel, project).schedule(); - } - } - if (!tempModel.isMappingXMLDefault() || !JptCorePlugin.discoverAnnotatedClasses(project)) { - registerMappingXML(tempModel, project).schedule(); - } - } - - /** - * This method is intended for internal use only. This method will create an - * instance of the CreateEntityTemplateModel model to be used in conjunction - * with the WTPJETEmitter. This method will not return null. - * - * @see CreateEntityTemplateModel - * @see NewEntityClassOperation#generateUsingTemplates(IProgressMonitor, - * IPackageFragment) - * - * @return CreateFilterTemplateModel - */ - private CreateEntityTemplateModel createTemplateModel() { - CreateEntityTemplateModel templateModel = new CreateEntityTemplateModel(model); - return templateModel; - } - - /** - * This method is intended for internal use only. This will use the - * WTPJETEmitter to create an annotated java file based on the passed template model. - * This method does not accept null parameters. It will not return null. - * If annotations are not used, it will use the non annotated template to omit the annotated tags. - * - * @see NewEntityClassOperation#generateUsingTemplates(IProgressMonitor, - * IPackageFragment) - * @see JETEmitter#generate(org.eclipse.core.runtime.IProgressMonitor, - * java.lang.Object[]) - * @see CreateEntityTemplateModel - * - * @param templateModel - * @param monitor - * @param template_file - * @return String the source for the java file - * @throws JETException - * @throws NoSuchMethodException - * @throws SecurityException - * @throws InvocationTargetException - * @throws IllegalAccessException - */ - private String generateTemplateSource(CreateEntityTemplateModel templateModel, String templateFile, Object templateImpl, IProgressMonitor monitor) - throws JETException, SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - Preferences preferences = J2EEPlugin.getDefault().getPluginPreferences(); - boolean dynamicTranslation = preferences.getBoolean(J2EEPlugin.DYNAMIC_TRANSLATION_OF_JET_TEMPLATES_PREF_KEY); - if (dynamicTranslation) { - URL templateURL = FileLocator.find(JptUiPlugin.getPlugin().getBundle(), new Path(templateFile), null); - cleanUpOldEmitterProject(); - WTPJETEmitter emitter = new WTPJETEmitter(templateURL.toString(), this.getClass().getClassLoader()); - emitter.setIntelligentLinkingEnabled(true); - emitter.addVariable(WTP_CUSTOMIZATION_PLUGIN, JptUiPlugin.PLUGIN_ID); - return emitter.generate(monitor, new Object[] { templateModel }); - } else { - Method method = templateImpl.getClass().getMethod(GENERATE_METHOD, new Class[] { Object.class }); - return (String) method.invoke(templateImpl, templateModel); - } - } - - /** - * This method is intended for internal use only. It will clean up the old emmiter project - * in order to prevent generation issues - */ - private void cleanUpOldEmitterProject() { - IProject project = ProjectUtilities.getProject(WTPJETEmitter.PROJECT_NAME); - if (project == null || !project.exists()) - return; - try { - IMarker[] markers = project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); - for (int i = 0, l = markers.length; i < l; i++) { - if (((Integer) markers[i].getAttribute(IMarker.SEVERITY)).intValue() == IMarker.SEVERITY_ERROR) { - project.delete(true, new NullProgressMonitor()); - break; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * This method will return the java source folder as specified in the java - * class data model. It will create the java source folder if it does not - * exist. This method may return null. - * - * @see INewJavaClassDataModelProperties#SOURCE_FOLDER - * @see IFolder#create(boolean, boolean, - * org.eclipse.core.runtime.IProgressMonitor) - * - * @return IFolder the java source folder - */ - protected final IFolder createJavaSourceFolder() { - // Get the source folder name from the data model - String folderFullPath = model.getStringProperty(INewJavaClassDataModelProperties.SOURCE_FOLDER); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFolder folder = root.getFolder(new Path(folderFullPath)); - // If folder does not exist, create the folder with the specified path - if (!folder.exists()) { - try { - folder.create(true, true, null); - } catch (CoreException e) { - Logger.getLogger().log(e); - } - } - // Return the source folder - return folder; - } - - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) - throws ExecutionException { - return doExecute(monitor, info); - } - - public IProject getTargetProject() { - String projectName = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME); - return ProjectUtilities.getProject(projectName); - } - - /** - * Adds entity to ORM XML in separate job - * @param model entity data model - * @param project JPA project in which the entity will be created - * @return - */ - private Job addEntityToXML(final CreateEntityTemplateModel model, final IProject project) { - Job job = new Job(EntityWizardMsg.ADD_ENTITY_TO_XML) { - @Override - protected IStatus run(IProgressMonitor monitor) { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForWrite(project); - try { - String xmlUri = JptCorePlugin.getDefaultOrmXmlDeploymentURI(project); - OrmResource resource = oae.getResource(xmlUri); - if (!model.isMappingXMLDefault()) { - resource = oae.getResource(model.getMappingXmlFile()); - } - - XmlEntityMappings entityMappings = resource.getEntityMappings(); - if (entityMappings == null) { - entityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion(VERSION_STRING); - } - - XmlEntity xmlEntity = OrmFactory.eINSTANCE.createXmlEntity(); - xmlEntity.setClassName(model.getQualifiedJavaClassName()); - if (model.isInheritanceSet()) { - Inheritance inheritance = OrmFactory.eINSTANCE.createInheritance(); - String inheritanceStrategy = model.getInheritanceStrategyName(); - if (inheritanceStrategy.equals(EMPTY_STRING)) { - inheritanceStrategy = SINGLE_TABLE; - } - InheritanceType inheritanceType = OrmFactory.eINSTANCE.createInheritanceTypeFromString(null, inheritanceStrategy);// TODO - inheritance.setStrategy(inheritanceType); - xmlEntity.setInheritance(inheritance); - } - - if (model.isEntityNameSet()) { - xmlEntity.setName(model.getEntityName()); - } - if (model.isTableNameSet()) { - XmlTable xmlTable = OrmFactory.eINSTANCE.createXmlTable(); - xmlTable.setName(model.getTableName()); - xmlEntity.setTable(xmlTable); - } - if (model.isCompositePK()) { - XmlIdClass idClass = OrmFactory.eINSTANCE.createXmlIdClass(); - idClass.setClassName(model.getIdClassName()); - xmlEntity.setIdClass(idClass); - } - List<String> pkFields = model.getPKFields(); - if (pkFields.size() > 0) { - Attributes entityAttributes = OrmFactory.eINSTANCE.createAttributes(); - List<XmlIdImpl> ids = new ArrayList<XmlIdImpl>(); - for (String fieldName : pkFields) { - XmlIdImpl idImpl = OrmFactory.eINSTANCE.createXmlIdImpl(); - idImpl.setName(fieldName); - ids.add(idImpl); - } - entityAttributes.eSet(OrmPackage.ATTRIBUTES__IDS, ids); - xmlEntity.setAttributes(entityAttributes); - } - - String accessTypeString = FIELD; - if (!model.isFieldAccess()) { - accessTypeString = PROPERTY; - } - AccessType accessType = OrmFactory.eINSTANCE.createAccessTypeFromString(null, accessTypeString);// TODO - xmlEntity.setAccess(accessType); - EList<XmlEntity> entities = entityMappings.getEntities(); - entities.add(xmlEntity); - resource.getContents().add(entityMappings); - oae.save(null); - } catch (Exception e) { - JptUiPlugin.log(e); - oae.dispose(); - } finally { - oae.dispose(); - } - return Status.OK_STATUS; - } - }; - return job; - } - - /** - * Adds mapped superclass to ORM XML in separate job - * - * @param model entity data model - * @param project JPA project in which the entity will be created - * @return the created job - */ - private Job addMappedSuperclassToXLM(final CreateEntityTemplateModel model, final IProject project) { - Job job = new Job(EntityWizardMsg.ADD_MAPPED_SUPERCLASS_TO_XML) { - @Override - protected IStatus run(IProgressMonitor monitor) { - OrmArtifactEdit oae = OrmArtifactEdit.getArtifactEditForWrite(project); - try { - //OrmResource resource = oae.getResource(JptCorePlugin.ormXmlDeploymentURI(project)); - String xmlUri = JptCorePlugin.getDefaultOrmXmlDeploymentURI(project); - if (!model.isMappingXMLDefault()) { - xmlUri = model.getMappingXMLName(); - } - OrmResource resource = oae.getResource(xmlUri); - XmlEntityMappings entityMappings = resource.getEntityMappings(); - if (entityMappings == null) { - entityMappings = OrmFactory.eINSTANCE.createXmlEntityMappings(); - entityMappings.setVersion(VERSION_STRING); - } - - XmlMappedSuperclass xmlMappedSuperclass = OrmFactory.eINSTANCE.createXmlMappedSuperclass(); - xmlMappedSuperclass.setClassName(model.getQualifiedJavaClassName()); - - if (model.isCompositePK()) { - XmlIdClass idClass = OrmFactory.eINSTANCE.createXmlIdClass(); - idClass.setClassName(model.getIdClassName()); - xmlMappedSuperclass.setIdClass(idClass); - } - - List<String> pkFields = model.getPKFields(); - if (pkFields.size() > 0) { - Attributes entityAttributes = OrmFactory.eINSTANCE.createAttributes(); - List<XmlIdImpl> ids = new ArrayList<XmlIdImpl>(); - for (String fieldName : pkFields) { - XmlIdImpl idImpl = OrmFactory.eINSTANCE.createXmlIdImpl(); - idImpl.setName(fieldName); - ids.add(idImpl); - } - entityAttributes.eSet(OrmPackage.ATTRIBUTES__IDS, ids); - xmlMappedSuperclass.setAttributes(entityAttributes); - } - - String accessTypeString = FIELD; - if (!model.isFieldAccess()) { - accessTypeString = PROPERTY; - } - AccessType accessType = OrmFactory.eINSTANCE.createAccessTypeFromString(null, accessTypeString); - xmlMappedSuperclass.setAccess(accessType); - entityMappings.getMappedSuperclasses().add(xmlMappedSuperclass); - - resource.getContents().add(entityMappings); - oae.save(null); - } catch (Exception e) { - JptUiPlugin.log(e); - } finally { - oae.dispose(); - } - return Status.OK_STATUS; - } - }; - return job; - } - - /** - * Register alternative mapping XML and/or classes in the persistence.xml - * - * @param model entity data model - * @param project JPA project in which the entity will be created - * @return the created job - */ - private Job registerMappingXML(final CreateEntityTemplateModel model, final IProject project) { - Job job = new Job(EntityWizardMsg.APPLY_CHANGES_TO_PERSISTENCE_XML) { - @Override - protected IStatus run(IProgressMonitor monitor) { - String fileName = getLastSegment(model.getMappingXMLName()); - PersistenceArtifactEdit pae = PersistenceArtifactEdit.getArtifactEditForWrite(project); - try { - PersistenceResource persistenceResource = pae.getResource(JptCorePlugin.getPersistenceXmlDeploymentURI(project)); - XmlPersistence xmlPersistence = persistenceResource.getPersistence(); - EList<XmlPersistenceUnit> persistenceUnits = xmlPersistence.getPersistenceUnits(); - XmlPersistenceUnit persistenceUnit = persistenceUnits.get(0);// Multiply persistence unit support - if (!model.isMappingXMLDefault()) { - boolean newXmlMappingFile = true; - EList<XmlMappingFileRef> xmlMappingFiles = persistenceUnit.getMappingFiles(); - for (XmlMappingFileRef fileRef : xmlMappingFiles) { - if (fileName.equals(fileRef.getFileName())) { - newXmlMappingFile = false; - break; - } - } - if (newXmlMappingFile) { - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName(fileName); - persistenceUnit.getMappingFiles().add(xmlMappingFileRef); - } - } - if (!model.isNonEntitySuperclass() && !JptCorePlugin.discoverAnnotatedClasses(project)) { - XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - classRef.setJavaClass(model.getQualifiedJavaClassName()); - persistenceUnit.getClasses().add(classRef); - } - persistenceResource.getContents().add(xmlPersistence); - pae.save(null); - } catch (Exception e) { - JptUiPlugin.log(e); - } finally { - pae.dispose(); - } - return Status.OK_STATUS; - } - }; - return job; - - } - - /** - * @param input the name of mapping XML from the class wizard page. It is relative path from the source folder - * and includes META-INF folder - * @return the simple name of the mapping XML - */ - private String getLastSegment(String input) { - String output = input; - if (input.indexOf(SEPARATOR) != -1) { - output = input.substring(input.lastIndexOf(SEPARATOR) + 1); - } - return output; - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java deleted file mode 100644 index 04e198336d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizard.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.orm; - -import java.lang.reflect.InvocationTargetException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard; - -public class MappingFileWizard extends DataModelWizard - implements INewWizard -{ - private MappingFileWizardPage page; - - - public MappingFileWizard() { - this(null); - } - - public MappingFileWizard(IDataModel dataModel) { - super(dataModel); - setWindowTitle(JptUiMessages.MappingFileWizard_title); - setDefaultPageImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_FILE_WIZ_BANNER)); - } - - - @Override - protected void doAddPages() { - super.doAddPages(); - page = new MappingFileWizardPage(getDataModel(), "Page_1"); - addPage(page); - } - - @Override - protected IDataModelProvider getDefaultProvider() { - return new OrmFileCreationDataModelProvider(); - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - // check for project, source folder, persistence unit? - if (selection == null || selection.isEmpty()) { - return; - } - - Object firstSelection = selection.getFirstElement(); - - PersistenceUnit pUnit = extractPersistenceUnit(firstSelection); - IFolder sourceFolder = extractSourceFolder(pUnit, firstSelection); - IProject project = extractProject(pUnit, sourceFolder, firstSelection); - - if (project != null) { - getDataModel().setStringProperty(OrmFileCreationDataModelProperties.PROJECT_NAME, project.getName()); - } - if (sourceFolder != null) { - getDataModel().setStringProperty(OrmFileCreationDataModelProperties.SOURCE_FOLDER, sourceFolder.getFullPath().toPortableString()); - } - if (pUnit != null) { - getDataModel().setBooleanProperty(OrmFileCreationDataModelProperties.ADD_TO_PERSISTENCE_UNIT, true); - getDataModel().setStringProperty(OrmFileCreationDataModelProperties.PERSISTENCE_UNIT, pUnit.getName()); - } - } - - private PersistenceUnit extractPersistenceUnit(Object selection) { - if (selection instanceof PersistenceUnit) { - return (PersistenceUnit) selection; - } - PersistenceUnit pUnit = null; - if (selection instanceof JpaContextNode) { - try { - pUnit = ((JpaContextNode) selection).getPersistenceUnit(); - } - catch (Exception e) { /* do nothing, just continue */ } - } - if (pUnit == null && selection instanceof IAdaptable) { - pUnit = (PersistenceUnit) ((IAdaptable) selection).getAdapter(PersistenceUnit.class); - - } - return pUnit; - } - - private IFolder extractSourceFolder(PersistenceUnit pUnit, Object selection) { - IJavaProject javaProject = null; - IFolder srcFolder = null; - if (pUnit != null) { - javaProject = pUnit.getJpaProject().getJavaProject(); - srcFolder = findSourceFolder(javaProject, pUnit.getResource()); - if (srcFolder != null) { - return srcFolder; - } - - } - if (selection instanceof IResource) { - javaProject = JavaCore.create(((IResource) selection).getProject()); - if (javaProject.exists()) { - srcFolder = findSourceFolder(javaProject, (IResource) selection); - if (srcFolder != null) { - return srcFolder; - } - } - } - - if (selection instanceof IAdaptable) { - IResource resource = (IResource) ((IAdaptable) selection).getAdapter(IResource.class); - if (resource != null) { - javaProject = JavaCore.create((resource).getProject()); - if (javaProject.exists()) { - srcFolder = findSourceFolder(javaProject, resource); - if (srcFolder != null) { - return srcFolder; - } - } - } - } - return null; - } - - private IFolder findSourceFolder(IJavaProject javaProject, IResource resource) { - if (JptCorePlugin.getJpaProject(javaProject.getProject()) == null) { - // not even a jpa project - return null; - } - while (resource != null && ! (resource instanceof IFolder)) { - resource = resource.getParent(); - } - if (resource == null) { - return null; - } - IFolder folder = (IFolder) resource; - try { - IPackageFragmentRoot packageFragmentRoot = null; - while (packageFragmentRoot == null && folder != null) { - packageFragmentRoot = javaProject.findPackageFragmentRoot(folder.getFullPath()); - if (packageFragmentRoot == null) { - IPackageFragment packageFragment = javaProject.findPackageFragment(folder.getFullPath()); - if (packageFragment != null) { - packageFragmentRoot = (IPackageFragmentRoot) packageFragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - } - } - if (packageFragmentRoot == null) { - try { - folder = (IFolder) folder.getParent(); - } - catch (ClassCastException cce) { - folder = null; - } - } - } - if (packageFragmentRoot == null) { - return null; - } - if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { - return (IFolder) packageFragmentRoot.getResource(); - } - } - catch (JavaModelException jme) { /* do nothing, return null */ } - return null; - } - - private IProject extractProject(PersistenceUnit pUnit, IFolder sourceFolder, Object selection) { - if (pUnit != null) { - return pUnit.getJpaProject().getProject(); - } - if (sourceFolder != null) { - return sourceFolder.getProject(); - } - - IProject project = null; - if (selection instanceof IResource) { - project = ((IResource) selection).getProject(); - } - if (project == null && selection instanceof IJavaElement) { - project = ((IJavaElement) selection).getJavaProject().getProject(); - } - if (project == null && selection instanceof JpaContextNode) { - project = ((JpaContextNode) selection).getJpaProject().getProject(); - } - if (project == null && selection instanceof IAdaptable) { - project = (IProject) ((IAdaptable) selection).getAdapter(IProject.class); - if (project == null) { - IResource resource = (IResource) ((IAdaptable) selection).getAdapter(IResource.class); - if (resource != null) { - project = resource.getProject(); - } - } - if (project == null) { - IJavaElement javaElement = (IJavaElement) ((IAdaptable) selection).getAdapter(IJavaElement.class); - if (javaElement != null) { - project = javaElement.getJavaProject().getProject(); - } - } - } - - if (project != null && JptCorePlugin.getJpaProject(project) != null) { - return project; - } - - return null; - } - - protected void postPerformFinish() throws InvocationTargetException { - try { - String projectName = (String) getDataModel().getProperty(OrmFileCreationDataModelProperties.PROJECT_NAME); - IProject project = ProjectUtilities.getProject(projectName); - String sourceFolder = getDataModel().getStringProperty(OrmFileCreationDataModelProperties.SOURCE_FOLDER); - String filePath = getDataModel().getStringProperty(OrmFileCreationDataModelProperties.FILE_PATH); - - IFile file = project.getWorkspace().getRoot().getFile(new Path(sourceFolder).append(filePath)); - openEditor(file); - } - catch (Exception cantOpen) { - throw new InvocationTargetException(cantOpen); - } - } - - private void openEditor(final IFile file) { - if (file != null) { - getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - try { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, file, true); - } - catch (PartInitException e) { - JptUiPlugin.log(e); - } - } - }); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java deleted file mode 100644 index cc1b313fbe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java +++ /dev/null @@ -1,271 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.wizards.orm; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.DecoratingLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; -import org.eclipse.jpt.ui.JptUiPlugin; -import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -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.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.model.WorkbenchContentProvider; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage; - -public class MappingFileWizardPage extends DataModelWizardPage - implements OrmFileCreationDataModelProperties -{ - private Label projectNameLabel; - - private Combo projectNameCombo; - - private Label sourceFolderLabel; - - private Text sourceFolderText; - - private Label filePathLabel; - - private Text filePathText; - - private Label accessLabel; - - private Combo accessCombo; - - private Button addToPersistenceUnitButton; - - private Label persistenceUnitLabel; - - private Combo persistenceUnitCombo; - - - public MappingFileWizardPage(IDataModel dataModel, String pageName) { - super(dataModel, pageName); - setTitle(JptUiMessages.MappingFileWizardPage_title); - setDescription(JptUiMessages.MappingFileWizardPage_desc); - setPageComplete(false); - } - - - @Override - protected String[] getValidationPropertyNames() { - return new String[] { - PROJECT_NAME, - SOURCE_FOLDER, - FILE_PATH, - DEFAULT_ACCESS, - ADD_TO_PERSISTENCE_UNIT, - PERSISTENCE_UNIT - }; - } - - @Override - protected Composite createTopLevelComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - layout.numColumns = 3; - composite.setLayout(layout); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - data.widthHint = 300; - composite.setLayoutData(data); - - projectNameLabel = new Label(composite, SWT.NONE); - projectNameLabel.setText(JptUiMessages.MappingFileWizardPage_projectLabel); //$NON-NLS-1$ - data = new GridData(); - projectNameLabel.setLayoutData(data); - - projectNameCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = 300; - data.horizontalSpan = 1; - projectNameCombo.setLayoutData(data); - synchHelper.synchCombo(projectNameCombo, PROJECT_NAME, null); - new Label(composite, SWT.NONE); - - sourceFolderLabel = new Label(composite, SWT.NONE); - sourceFolderLabel.setText(JptUiMessages.MappingFileWizardPage_sourceFolderLabel); //$NON-NLS-1$ - data = new GridData(); - sourceFolderLabel.setLayoutData(data); - - sourceFolderText = new Text(composite, SWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = 300; - data.horizontalSpan = 1; - sourceFolderText.setLayoutData(data); - synchHelper.synchText(sourceFolderText, SOURCE_FOLDER, null); - - Button sourceFolderButton = new Button(composite, SWT.PUSH); - sourceFolderButton.setText(JptUiMessages.General_browse); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 1; - sourceFolderButton.addSelectionListener( - new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) { - handleSourceFolderButtonPressed(); - } - }); - - filePathLabel = new Label(composite, SWT.NONE); - filePathLabel.setText(JptUiMessages.MappingFileWizardPage_filePathLabel); //$NON-NLS-1$ - data = new GridData(); - filePathLabel.setLayoutData(data); - - filePathText = new Text(composite, SWT.BORDER | SWT.READ_ONLY); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = 300; - data.horizontalSpan = 1; - filePathText.setLayoutData(data); - synchHelper.synchText(filePathText, FILE_PATH, null); - new Label(composite, SWT.NONE); - - accessLabel = new Label(composite, SWT.NONE); - accessLabel.setText(JptUiMessages.MappingFileWizardPage_accessLabel); //$NON-NLS-1$ - data = new GridData(); - accessLabel.setLayoutData(data); - - accessCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = 300; - data.horizontalSpan = 1; - accessCombo.setLayoutData(data); - synchHelper.synchCombo(accessCombo, DEFAULT_ACCESS, null); - new Label(composite, SWT.NONE); - - addToPersistenceUnitButton = new Button(composite, SWT.CHECK | SWT.BEGINNING); - addToPersistenceUnitButton.setText(JptUiMessages.MappingFileWizardPage_addToPersistenceUnitButton); - data = new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan = 3; - addToPersistenceUnitButton.setLayoutData(data); - synchHelper.synchCheckbox(addToPersistenceUnitButton, ADD_TO_PERSISTENCE_UNIT, null); - - persistenceUnitLabel = new Label(composite, SWT.NONE); - persistenceUnitLabel.setText(JptUiMessages.MappingFileWizardPage_persistenceUnitLabel); //$NON-NLS-1$ - data = new GridData(); - persistenceUnitLabel.setLayoutData(data); - - persistenceUnitCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); - data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = 300; - data.horizontalSpan = 1; - persistenceUnitCombo.setLayoutData(data); - synchHelper.synchCombo(persistenceUnitCombo, PERSISTENCE_UNIT, null); - - new Label(composite, SWT.NONE); - -// classText.setFocus(); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, getInfopopID()); - Dialog.applyDialogFont(parent); - return composite; - } - - private void handleSourceFolderButtonPressed() { - ISelectionStatusValidator validator = getSourceFolderDialogSelectionValidator(); - ViewerFilter filter = getSourceFolderDialogViewerFilter(); - ITreeContentProvider contentProvider = new WorkbenchContentProvider(); - ILabelProvider labelProvider = new DecoratingLabelProvider( - new WorkbenchLabelProvider(), - PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider); - dialog.setValidator(validator); - dialog.setTitle(JptUiMessages.MappingFileWizardPage_accessLabel_sourceFolderDialogTitle); - dialog.setMessage(JptUiMessages.MappingFileWizardPage_accessLabel_sourceFolderDialogDesc); - dialog.addFilter(filter); - String projectName = model.getStringProperty(PROJECT_NAME); - if (projectName==null || projectName.length()==0) { - return; - } - IProject project = ProjectUtilities.getProject(projectName); - dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); - - if (project != null) { - dialog.setInitialSelection(project); - } - if (dialog.open() == Window.OK) { - Object element = dialog.getFirstResult(); - if (element instanceof IContainer) { - IContainer container = (IContainer) element; - model.setProperty(SOURCE_FOLDER, container.getFullPath().toPortableString()); - } - } - } - - private ISelectionStatusValidator getSourceFolderDialogSelectionValidator() { - return new ISelectionStatusValidator() { - public IStatus validate(Object[] selection) { - if (selection != null && selection[0] != null && ! (selection[0] instanceof IProject)) { - return Status.OK_STATUS; - } - return new Status(Status.ERROR, JptUiPlugin.PLUGIN_ID, JptUiMessages.MappingFileWizardPage_incorrectSourceFolderError); - } - }; - } - - private ViewerFilter getSourceFolderDialogViewerFilter() { - return new ViewerFilter() { - public boolean select(Viewer viewer, Object parent, Object element) { - if (element instanceof IProject) { - IProject project = (IProject) element; - return project.getName().equals(model.getProperty(PROJECT_NAME)); - } - else if (element instanceof IFolder) { - IFolder folder = (IFolder) element; - // only show source folders - IProject project = ProjectUtilities.getProject(model.getStringProperty(PROJECT_NAME)); - IPackageFragmentRoot[] sourceFolders = J2EEProjectUtilities.getSourceContainers(project); - for (int i = 0; i < sourceFolders.length; i++) { - if (sourceFolders[i].getResource()!= null && sourceFolders[i].getResource().equals(folder)) { - return true; - } - } - } - return false; - } - }; - } - - void init(IWorkbench workbench, IStructuredSelection selection) { - - } -} |