diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details')
10 files changed, 0 insertions, 2068 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java deleted file mode 100644 index c3f744e135..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.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 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.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -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 GenericPersistenceUnitGeneralComposite extends PersistenceUnitGeneralComposite - implements JpaPageComposite -{ - /** - * 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 GenericPersistenceUnitGeneralComposite(PropertyValueModel<PersistenceUnit> subjectHolder, - Composite container, - WidgetFactory widgetFactory) { - - super(subjectHolder, container, widgetFactory); - } - - @Override - protected void initializeLayout(Composite container) { - - initializeGeneralPane(container); - initializeMappedClassesPane(container); - initializeJPAMappingDescriptorsPane(container); -// initializeJavaArchivesPane(container); - } - - - protected void initializeJPAMappingDescriptorsPane(Composite container) { - - container = addSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jpaMappingDescriptors, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jpaMappingDescriptors_description - ); - - updateGridData(container); - updateGridData(container.getParent()); - - new GenericPersistenceUnitMappingFilesComposite(this, container); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitMappingFilesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitMappingFilesComposite.java deleted file mode 100644 index 7b0c103e63..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitMappingFilesComposite.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.persistence.details; - -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.ui.internal.widgets.Pane; -import org.eclipse.swt.widgets.Composite; - -/** - * Here the layout of this pane: - * <pre> - * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------------- | - * | | | | - * | | AddRemoveListPane | | - * | | | | - * | ------------------------------------------------------------------------- | - * -----------------------------------------------------------------------------</pre> - * - * @see PersistenceUnit - * @see PersistenceUnitGeneralComposite - The parent container - * @see AddRemoveListPane - * - * @version 2.0 - * @since 2.0 - */ -public class GenericPersistenceUnitMappingFilesComposite extends PersistenceUnitMappingFilesComposite -{ - /** - * Creates a new <code>PersistenceUnitMappingFilesComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public GenericPersistenceUnitMappingFilesComposite(Pane<? extends PersistenceUnit> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - @Override - protected void initializeLayout(Composite container) { - addMappingFilesList(container); - } -}
\ 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 acb6b247a0..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitClassesComposite.java +++ /dev/null @@ -1,407 +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.AddRemoveListPane; -import org.eclipse.jpt.ui.internal.widgets.Pane; -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 Pane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitMappedClassesComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitClassesComposite(Pane<? extends PersistenceUnit> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - private void addMappedClass(ObjectListSelectionModel listSelectionModel) { - - IType type = chooseType(); - - if (type != null) { - String className = type.getFullyQualifiedName('.'); - if(classRefExists(className)) { - return; - } - ClassRef classRef = getSubject().addSpecifiedClassRef(); - classRef.setClassName(className); - listSelectionModel.setSelectedValue(classRef); - } - } - - private boolean classRefExists(String className) { - for ( ListIterator<ClassRef> i = getSubject().specifiedClassRefs(); i.hasNext(); ) { - ClassRef classRef = i.next(); - if( classRef.getClassName().equals(className)) { - return true; - } - } - return false; - } - - 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()) { - getSubject().removeSpecifiedClassRef((ClassRef) item); - } - } - }; - } - - private WritablePropertyValueModel<Boolean> buildExcludeUnlistedMappedClassesHolder() { - return new PropertyAspectAdapter<PersistenceUnit, Boolean>( - getSubjectHolder(), - PersistenceUnit.DEFAULT_EXCLUDE_UNLISTED_CLASSES_PROPERTY, - PersistenceUnit.SPECIFIED_EXCLUDE_UNLISTED_CLASSES_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 ((getSubject() != null) && (value == null)) { - - Boolean defaultValue = getSubject().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_REFS_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( - getShell(), - 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 getSubject().getJpaProject().getJavaProject().findType(className); - } - catch (JavaModelException e) { - JptUiPlugin.log(e); - } - } - - return null; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Description - addMultiLineLabel( - 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; - } - }; - - addTriStateCheckBoxWithDefault( - container, - JptUiPersistenceMessages.PersistenceUnitClassesComposite_excludeUnlistedMappedClasses, - buildExcludeUnlistedMappedClassesHolder(), - buildExcludeUnlistedMappedClassesStringHolder(), - null - ); - } - - 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 = getSubject().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 7071aa221a..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.FormPane; -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 FormPane<PersistenceUnit> - implements JpaPageComposite -{ - /** - * 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 addContainer(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 = addPane(parent, layout); - updateGridData(container); - - return container; - } - - /* - * (non-Javadoc) - */ - public String getHelpID() { - return JpaHelpContextIds.PERSISTENCE_UNIT_CONNECTION; - } - - private void initializeDatabasePane(Composite container) { - - container = addSection( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionComposite_database - ); - - new PersistenceUnitConnectionDatabaseComposite(this, container); - } - - private void initializeGeneralPane(Composite container) { - - container = addSection( - 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 826463384d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionDatabaseComposite.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.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.Pane; -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.Label; -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 Pane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitConnectionDatabaseComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitConnectionDatabaseComposite(Pane<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 - Label label = addUnmanagedLabel( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionDatabaseComposite_jtaDatasourceName); - Text text = addUnmanagedText( - container, - buildJTADatasourceNameHolder(), - null - ); - addLabeledComposite(container, label, text, null); - - installJTADatasourceNameEnabler(text, label); - - - // Non-JTA Datasource Name widgets - label = addUnmanagedLabel( - container, - JptUiPersistenceMessages.PersistenceUnitConnectionDatabaseComposite_nonJtaDatasourceName); - text = addUnmanagedText( - container, - buildNonJTADatasourceNameHolder(), - null - ); - addLabeledComposite(container, label, text, null); - - installNonJTADatasourceNameEnabler(text, label); - } - - private void installJTADatasourceNameEnabler(Text text, Label label) { - new ControlEnabler(buildJTADatasourceNameBooleanHolder(), text, label); - } - - private void installNonJTADatasourceNameEnabler(Text text, Label label) { - new ControlEnabler(buildNonJTADatasourceNameBooleanHolder(), text, label); - } -}
\ 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 f8620d7ad2..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.Pane; -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 Pane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitConnectionGeneralComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitConnectionGeneralComposite(Pane<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[] getChoices() { - return PersistenceUnitTransactionType.values(); - } - - @Override - protected PersistenceUnitTransactionType getDefaultValue() { - return getSubject().getDefaultTransactionType(); - } - - @Override - protected String displayString(PersistenceUnitTransactionType value) { - return buildDisplayString( - JptUiPersistenceMessages.class, - PersistenceUnitConnectionGeneralComposite.this, - value - ); - } - - @Override - protected PersistenceUnitTransactionType getValue() { - return getSubject().getSpecifiedTransactionType(); - } - - @Override - protected void setValue(PersistenceUnitTransactionType value) { - getSubject().setSpecifiedTransactionType(value); - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected void initializeLayout(Composite container) { - - // Transaction Type widgets - addLabeledComposite( - 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 a68b6ca479..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java +++ /dev/null @@ -1,239 +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.FormPane; -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 abstract class PersistenceUnitGeneralComposite extends FormPane<PersistenceUnit> - implements JpaPageComposite -{ - /** - * 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<? extends 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 addContainer(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 = addPane(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; - } - - protected void initializeGeneralPane(Composite container) { - - container = addSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_general - ); - - // Name widgets - addLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_name, - buildPersistenceUnitNameHolder() - ); - - // Persistence Provider widgets - addLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_persistenceProvider, - buildPersistenceProviderHolder() - ); - - // Description widgets - addLabeledText( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_description, - buildPersistenceUnitDescriptionHolder() - ); - } - - protected void initializeMappedClassesPane(Composite container) { - - container = addSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_mappedClasses - ); - - updateGridData(container); - updateGridData(container.getParent()); - - new PersistenceUnitClassesComposite(this, container); - } - - protected 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 e844f546b0..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.Pane; -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 Pane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitJPAMappingDescriptorsComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitJarFilesComposite(Pane<? 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 dad548ffad..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java +++ /dev/null @@ -1,360 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.persistence.details; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ListIterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.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.jpt.core.context.persistence.MappingFileRef; -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.XmlMappingFileViewerFilter; -import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; -import org.eclipse.jpt.ui.internal.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; -import org.eclipse.jpt.ui.internal.widgets.Pane; -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 abstract class PersistenceUnitMappingFilesComposite extends Pane<PersistenceUnit> -{ - /** - * Creates a new <code>PersistenceUnitMappingFilesComposite</code>. - * - * @param parentPane The parent pane of this one - * @param parent The parent container - */ - public PersistenceUnitMappingFilesComposite(Pane<? extends PersistenceUnit> parentPane, - Composite parent) { - - super(parentPane, parent); - } - - protected void addMappingFilesList(Composite container) { - // List pane - new AddRemoveListPane<PersistenceUnit>( - this, - container, - buildAdapter(), - buildItemListHolder(), - buildSelectedItemHolder(), - buildLabelProvider() - ) { - @Override - protected Composite addContainer(Composite parent) { - parent = super.addContainer(parent); - updateGridData(parent); - return parent; - } - - @Override - protected void initializeLayout(Composite container) { - super.initializeLayout(container); - updateGridData(getContainer()); - } - }; - } - - /** - * 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 = getSubject().getJpaProject().getProject(); - - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( - getShell(), - 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 XmlMappingFileViewerFilter(getSubject().getJpaProject())); - 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()) { - getSubject().removeSpecifiedMappingFileRef((MappingFileRef) item); - } - } - }; - } - - /* - * (non-Javadoc) - */ - @Override - protected Composite addContainer(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 = addPane(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_REFS_LIST) { - @Override - protected ListIterator<MappingFileRef> listIterator_() { - return this.subject.specifiedMappingFileRefs(); - } - - @Override - protected int size_() { - return this.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; - } - - for (Object result : dialog.getResult()) { - IFile file = (IFile) result; - IPath filePath = removeSourcePath(file); - String fileName = filePath.toPortableString(); - if(mappingFileRefExists(fileName)) { - continue; - } - MappingFileRef mappingFileRef = getSubject().addSpecifiedMappingFileRef(); - mappingFileRef.setFileName(fileName); - - listSelectionModel.addSelectedValue(mappingFileRef); - } - } - }; - } - - private boolean mappingFileRefExists(String fileName) { - for ( ListIterator<MappingFileRef> i = getSubject().specifiedMappingFileRefs(); i.hasNext(); ) { - MappingFileRef mappingFileRef = i.next(); - if( mappingFileRef.getFileName().equals(fileName)) { - return true; - } - } - return false; - } - - 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, ""); - } - }; - } - - /** - * 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 = getSubject().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 this.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(); - } - } -}
\ 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 1587a3004b..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitPropertiesComposite.java +++ /dev/null @@ -1,432 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.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.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.util.SWTUtil; -import org.eclipse.jpt.ui.internal.widgets.AddRemoveTablePane; -import org.eclipse.jpt.ui.internal.widgets.Pane; -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.event.ListChangeEvent; -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 Pane<PersistenceUnit> - implements JpaPageComposite -{ - private WritablePropertyValueModel<PersistenceUnit.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<PersistenceUnit.Property> buildPropertiesListHolder() { - return new ListAspectAdapter<PersistenceUnit, PersistenceUnit.Property>(getSubjectHolder(), PersistenceUnit.PROPERTIES_LIST) { - @Override - protected ListIterator<PersistenceUnit.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) { - - PersistenceUnit.Property property = getSubject().addProperty(); - propertyHolder.setValue(property); - - int index = getSubject().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()) { - getSubject().removeProperty((PersistenceUnit.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<PersistenceUnit.Property>(); - } - - /** - * {@inheritDoc} - */ - @Override - protected void initializeLayout(Composite container) { - - addLabel( - container, - JptUiPersistenceMessages.PersistenceUnitPropertiesComposite_properties_description - ); - - tablePane = new TablePane(container); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - } - - private static class PropertyColumnAdapter implements ColumnAdapter<PersistenceUnit.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(PersistenceUnit.Property subject) { - return new PropertyAspectAdapter<PersistenceUnit.Property, String>(PersistenceUnit.Property.NAME_PROPERTY, subject) { - @Override - protected String buildValue_() { - return subject.getName(); - } - - @Override - protected void setValue_(String value) { - subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<String> buildValueHolder(PersistenceUnit.Property subject) { - return new PropertyAspectAdapter<PersistenceUnit.Property, String>(PersistenceUnit.Property.VALUE_PROPERTY, subject) { - @Override - protected String buildValue_() { - return subject.getValue(); - } - - @Override - protected void setValue_(String value) { - subject.setValue(value); - } - }; - } - - public WritablePropertyValueModel<?>[] cellModels(PersistenceUnit.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) { - - PersistenceUnit.Property property = (PersistenceUnit.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()); - } - - @Override - protected Composite addContainer(Composite parent) { - Composite container = super.addContainer(parent); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - return container; - } - - 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) { - PersistenceUnit.Property propertyModel = (PersistenceUnit.Property) element; - String value = null; - - if (property == PersistenceUnit.Property.NAME_PROPERTY) { - value = propertyModel.getName(); - } - else if (property == PersistenceUnit.Property.VALUE_PROPERTY) { - value = propertyModel.getValue(); - } - - if (value == null) { - value = ""; - } - - return value; - } - - public void modify(Object element, String property, Object value) { - PersistenceUnit.Property propertyModel; - - if (element instanceof TableItem) { - TableItem tableItem = (TableItem) element; - propertyModel = (PersistenceUnit.Property) tableItem.getData(); - } - else { - propertyModel = (PersistenceUnit.Property) element; - } - - if (property == PersistenceUnit.Property.NAME_PROPERTY) { - propertyModel.setName(value.toString()); - } - else if (property == PersistenceUnit.Property.VALUE_PROPERTY) { - propertyModel.setValue(value.toString()); - } - } - }; - } - - @Override - protected ColumnAdapter<?> buildColumnAdapter() { - return new PropertyColumnAdapter(); - } - - private String[] buildColumnProperties() { - return new String[] { - SELECTION_COLUMN, - PersistenceUnit.Property.NAME_PROPERTY, - PersistenceUnit.Property.VALUE_PROPERTY - }; - } - - 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(); - table.setLayoutData(new GridData(GridData.FILL_BOTH)); - - // 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()); - } - - @Override - protected void itemsAdded(ListChangeEvent e) { - super.itemsAdded(e); - revalidateLayout(); - } - - @Override - protected void itemsRemoved(ListChangeEvent e) { - super.itemsRemoved(e); - revalidateLayout(); - } - - @Override - protected void listChanged(ListChangeEvent e) { - super.listChanged(e); - revalidateLayout(); - } - - /** - * Revalidates the table layout after the list of items has changed. The - * layout has to be done in a new UI thread because our listener might be - * notified before the table has been updated (table column added or removed). - */ - private void revalidateLayout() { - SWTUtil.asyncExec(new Runnable() { public void run() { - Table table = getMainControl(); - if (!table.isDisposed()) { - // We have to do a total relayout of the tab otherwise the - // table might become cut off at the bottom - SWTUtil.reflow(table); - } - }}); - } - } -}
\ No newline at end of file |