diff options
author | kmoore | 2008-03-10 21:37:13 +0000 |
---|---|---|
committer | kmoore | 2008-03-10 21:37:13 +0000 |
commit | aff0c255418c1fb75b12380f21945bf7b0ac1e0d (patch) | |
tree | f16d1b8280bde55feb9d85769ca96c5770d82e61 | |
parent | 58cd77b967dbb807640dadcbbd5b15819be37bd3 (diff) | |
download | webtools.dali-aff0c255418c1fb75b12380f21945bf7b0ac1e0d.tar.gz webtools.dali-aff0c255418c1fb75b12380f21945bf7b0ac1e0d.tar.xz webtools.dali-aff0c255418c1fb75b12380f21945bf7b0ac1e0d.zip |
130580 - preliminary persistence.xml editor support - patch contribution from Pascal
28 files changed, 2362 insertions, 111 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF index a601d7418c..f5dbc8875b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF +++ b/jpa/plugins/org.eclipse.jpt.ui/META-INF/MANIFEST.MF @@ -32,7 +32,8 @@ Require-Bundle: org.eclipse.core.resources, org.eclipse.wst.common.project.facet.ui, org.eclipse.wst.sse.ui, org.eclipse.wst.web.ui, - org.eclipse.ui.navigator + org.eclipse.ui.navigator, + org.eclipse.ui.editors Eclipse-LazyStart: true Export-Package: org.eclipse.jpt.ui, org.eclipse.jpt.ui.details, diff --git a/jpa/plugins/org.eclipse.jpt.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.ui/plugin.xml index 0b1500e820..38f30d307b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/plugin.xml +++ b/jpa/plugins/org.eclipse.jpt.ui/plugin.xml @@ -398,5 +398,20 @@ </wizard-pages> </extension> - + +<!-- =================================================================================== --> +<!-- Extension: Persistence Editor --> +<!-- =================================================================================== --> + + <extension + point="org.eclipse.ui.editors"> + <editor + class="org.eclipse.jpt.ui.internal.editors.PersistenceEditor" + contributorClass="org.eclipse.jpt.ui.internal.editors.PersistenceContributor" + filenames="persistence.xml" + icon="$nl$/icons/full/obj16/jpa-file.gif" + id="org.eclipse.jpt.ui.internal.editors.PersistenceEditor" + name="persistence.xml"> + </editor> + </extension> </plugin> diff --git a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties index a03b1a8088..62edbc5f24 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties +++ b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui.properties @@ -1,6 +1,12 @@ ############################################################################### -# Copyright (c) 2006, 2007 Oracle. - initial API and implementation -############################################################################### +# 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 +############################################################################### AbstractChooserPane_browseButton=Browse... diff --git a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties new file mode 100644 index 0000000000..23c8b81c6e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties @@ -0,0 +1,46 @@ +############################################################################### +# Copyright (c) 2006, 2007 Oracle. All rights reserved. +# This program and the accompanying materials are made available under the terms of +# the Eclipse Public License v1.0, which accompanies this distribution and is available at +# http://www.eclipse.org/legal/epl-v10.html. +# +# Contributors: +# Oracle - initial API and implementation +############################################################################### + +Boolean_False=False +Boolean_True=True + +PersistenceEditor_Page_help=Help + +PersistenceUnitComposite_connection=Connection +PersistenceUnitComposite_general=General + +PersistenceUnitConnectionGeneralComposite_default=Default +PersistenceUnitConnectionGeneralComposite_description=Specify (TODO). +PersistenceUnitConnectionGeneralComposite_jta=JTA +PersistenceUnitConnectionGeneralComposite_persistenceProvider=Persistence Provider: +PersistenceUnitConnectionGeneralComposite_resource_local=Resource Local + +PersistenceUnitConnectionComposite_database=Database +PersistenceUnitConnectionComposite_general=General + +PersistenceUnitConnectionDatabaseComposite_description=Specify the (TODO). +PersistenceUnitConnectionDatabaseComposite_jtaDatasourceName=JTA Datasource Name: +PersistenceUnitConnectionDatabaseComposite_nonJtaDatasourceName=Non-JTA Datasource Name: + +PersistenceUnitConnectionGeneralComposite_transactionType=Transaction Type: + +PersistenceUnitGeneralComposite_general=General +PersistenceUnitGeneralComposite_javaArchives=Java Archives +PersistenceUnitGeneralComposite_jpaMappingDescriptors=JPA Mapping Descriptors +PersistenceUnitGeneralComposite_mappedClasses=Mapped Classes +PersistenceUnitGeneralComposite_persistenceProvider=Persistence Provider: + +PersistenceUnitJPAMappingDescriptorsComposite_ormNoName=<name not set> +PersistenceUnitJPAMappingDescriptorsComposite_description=Specify the list of JPA mapping descriptors (TODO). + +PersistenceUnitMappedClassesComposite_description=Specify the list of mapped classes to be included in this persistence unit. +PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClasses=Exclude Unlisted Mapped Classes +PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClassesWithDefault=Exclude Unlisted Mapped Classes ({0}) +PersistenceUnitMappedClassesComposite_mappedClassesNoName=<name not set> diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java index dacc9d3b3f..5448dd54b9 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java @@ -29,7 +29,7 @@ import org.eclipse.ui.navigator.ICommonLabelProvider; * ID. * * @see the org.eclipse.jpt.ui.jpaPlatform extension point - * + * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching * stability. It is available at this early stage to solicit feedback from @@ -49,16 +49,18 @@ public interface JpaPlatformUi * of these per view that uses it. */ ICommonLabelProvider buildNavigatorLabelProvider(); - + /** * Return a *new* structure provider for the given JPA file */ // TODO - binary java type support JpaStructureProvider buildStructureProvider(JpaFile jpaFile); - + JpaDetailsProvider detailsProvider(JpaStructureNode contextNode); void generateDDL(JpaProject project, IStructuredSelection selection); void generateEntities(JpaProject project, IStructuredSelection selection); -} + + JpaUiFactory getJpaUiFactory(); +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaUiFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaUiFactory.java index 7bb15f7a54..f7fa8e1adc 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaUiFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaUiFactory.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.ui; +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; @@ -21,9 +22,11 @@ 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.persistence.PersistenceUnit; import org.eclipse.jpt.core.context.java.JavaEntity; import org.eclipse.jpt.core.context.orm.OrmEntity; import org.eclipse.jpt.ui.details.JpaComposite; +import org.eclipse.jpt.ui.details.JpaPageComposite; import org.eclipse.jpt.ui.internal.widgets.WidgetFactory; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -207,6 +210,21 @@ public interface JpaUiFactory WidgetFactory widgetFactory); /** + * Creates the list of <code>JpaComposite</code>s used to edit a + * <code>PersistenceUnit</code>. The properties can be regrouped into + * sections that will be shown in the editor as pages. + * + * @param subjectHolder The holder of the pertistence unit + * @param parent The parent container + * @param widgetFactory The factory used to create the widgets + * @return A new <code>JpaComposite</code> + */ + ListIterator<JpaPageComposite<PersistenceUnit>> createPersistenceUnitComposites( + PropertyValueModel<PersistenceUnit> subjectHolder, + Composite parent, + WidgetFactory widgetFactory); + + /** * Creates a new <code>JpaComposite</code> used to edit a <code>TransientMapping</code>. * * @param subjectHolder The holder of the transient mapping diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/details/JpaPageComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/details/JpaPageComposite.java new file mode 100644 index 0000000000..95c830a514 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/details/JpaPageComposite.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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.details; + +import org.eclipse.swt.graphics.Image; + +/** + * A {@link JpaPageComposite} defines the common behavior of the JPA + * related widgets that is shown as a page within an editor. + * <p> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface JpaPageComposite<T> extends JpaComposite<T> { + + /** + * Returns the help ID. This ID will be used if the help button is invoked. + * + * @return Either the help ID of this page or <code>null</code> if no help + * is required + */ + String helpID(); + + /** + * The image of the tab showing this page. + * + * @return The page's image + */ + Image pageImage(); + + /** + * The text of the tab showing this page. + * + * @return The page's text + */ + String pageText(); +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java index 13998b4952..4e0ba7c8ad 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/BaseJpaUiFactory.java @@ -9,6 +9,8 @@ ******************************************************************************/ 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; @@ -23,8 +25,10 @@ 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.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; @@ -39,6 +43,8 @@ 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.widgets.WidgetFactory; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -150,6 +156,20 @@ public abstract class BaseJpaUiFactory implements JpaUiFactory 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)); + + return pages.listIterator(); + } + public JpaComposite<TransientMapping> createTransientMappingComposite( PropertyValueModel<TransientMapping> subjectHolder, Composite parent, diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java index b81c6f50e9..779d92d61a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/GenericJpaUiFactory.java @@ -9,7 +9,6 @@ ******************************************************************************/ 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). 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 index b32e98b9bc..ebee6d5faf 100644 --- 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 @@ -105,4 +105,8 @@ public interface JpaHelpContextIds { //Other public static final String PERSISTENCE_OUTLINE = PREFIX + "persistenceOutline"; + + //PersistenceUnit + public static final String PERSISTENCE_UNIT_GENERAL = PREFIX + "persistenceUnit_general"; + public static final String PERSISTENCE_UNIT_CONNECTION = PREFIX + "persistenceUnit_connection"; }
\ No newline at end of file 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 new file mode 100644 index 0000000000..eb972fe1d2 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceContributor.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.ide.IDEActionFactory; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * Manages the installation/deinstallation of global actions for multi-page editors. + * Responsible for the redirection of global actions to the active editor. + * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor. + */ +public class PersistenceContributor extends MultiPageEditorActionBarContributor { + private IEditorPart activeEditorPart; + private Action sampleAction; + /** + * Creates a multi-page contributor. + */ + public PersistenceContributor() { + super(); + createActions(); + } + /** + * 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) + * Method declared in AbstractMultiPageEditorActionBarContributor. + */ + + @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(); + } + } + private void createActions() { + sampleAction = new Action() { + @Override + public void run() { + MessageDialog.openInformation(null, "Java Persistence API Tools - UI", "Sample Action Executed"); + } + }; + sampleAction.setText("Sample Action"); + sampleAction.setToolTipText("Sample Action tool tip"); + sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); + } + @Override + public void contributeToMenu(IMenuManager manager) { + IMenuManager menu = new MenuManager("Editor &Menu"); + manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); + menu.add(sampleAction); + } + @Override + public void contributeToToolBar(IToolBarManager manager) { + manager.add(new Separator()); + manager.add(sampleAction); + } +} 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 new file mode 100644 index 0000000000..fffe207850 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/editors/PersistenceEditor.java @@ -0,0 +1,443 @@ +/******************************************************************************* + * 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.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.ResourcesPlugin; +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.details.JpaPageComposite; +import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; +import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry; +import org.eclipse.jpt.ui.internal.util.SWTUtil; +import org.eclipse.jpt.ui.internal.widgets.FormWidgetFactory; +import org.eclipse.jpt.ui.internal.widgets.WidgetFactory; +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.SWT; +import org.eclipse.swt.custom.BusyIndicator; +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.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.editors.text.TextEditor; +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.part.FileEditorInput; +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 TextEditor editor; + + /** + * The root of the holders used to retrieve the persistence unit and be + * notified when it changes. + */ + private WritablePropertyValueModel<IFileEditorInput> editorInputHolder; + + /** + * The listener used for being notified when the project is being closed. + */ + private IResourceChangeListener resourceChangeListener; + + /** + * The factory used to create the various widgets. + */ + private WidgetFactory widgetFactory; + + /** + * Creates a new <code>PersistenceEditor</code>. + */ + public PersistenceEditor() { + super(); + initialize(); + } + + /* + * (non-Javadoc) + */ + @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(); + String platformId = jpaProject.jpaPlatform().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(); + int index = addPage(editor, getEditorInput()); + setPageText(index, editor.getTitle()); + } + 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.jpaProject(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.persistenceXml(); + } + }; + } + + private IResourceChangeListener buildResourceChangeListener() { + return new IResourceChangeListener() { + public void resourceChanged(final IResourceChangeEvent event) { + + if (event.getType() == IResourceChangeEvent.PRE_CLOSE) { + + SWTUtil.asyncExec(new Runnable() { public void run() { + + IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages(); + + for (int index = 0; index<pages.length; index++){ + + FileEditorInput fileEditorInput = (FileEditorInput) editor.getEditorInput(); + + if (fileEditorInput.getFile().getProject().equals(event.getResource())) { + IEditorPart editorPart = pages[index].findEditor(editor.getEditorInput()); + pages[index].closeEditor(editorPart, true); + } + } + }}); + } + } + }; + } + + private PropertyValueModel<JpaRootContextNode> buildRootContextNodeHolder() { + return new TransformationPropertyValueModel<JpaProject, JpaRootContextNode>(buildJpaProjectHolder()) { + @Override + protected JpaRootContextNode transform_(JpaProject value) { + return value.rootContext(); + } + }; + } + + private WidgetFactory buildWidgetFactory() { + return new FormWidgetFactory( + new TabbedPropertySheetWidgetFactory() + ); + } + + /* + * (non-Javadoc) + */ + @Override + public void close(boolean save) { + super.close(save); + editorInputHolder.setValue(null); + } + + /* + * (non-Javadoc) + */ + @Override + public void dispose() { + + ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener); + resourceChangeListener = null; + + super.dispose(); + } + + /* + * (non-Javadoc) + */ + @Override + public void doSave(IProgressMonitor monitor) { + getEditor(getPageCount() - 1).doSave(monitor); + } + + /* + * (non-Javadoc) + */ + @Override + public void doSaveAs() { + } + + /* + * (non-Javadoc) + */ + @Override + public IFileEditorInput getEditorInput() { + return (IFileEditorInput) super.getEditorInput(); + } + + /* + * (non-Javadoc) + */ + @Override + public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException { + Assert.isLegal(editorInput instanceof IFileEditorInput, "Invalid Input: Must be IFileEditorInput"); + super.init(site, editorInput); + + editorInputHolder.setValue(getEditorInput()); + } + + /** + * Initializes this multi-page editor. + */ + private void initialize() { + + editorInputHolder = buildEditorInputHolder(); + widgetFactory = buildWidgetFactory(); + resourceChangeListener = buildResourceChangeListener(); + + ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener); + } + + /* + * (non-Javadoc) + */ + @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.jpaProject(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 { + + private JpaPageComposite<PersistenceUnit> page; + + private Page(JpaPageComposite<PersistenceUnit> page) { + + super(PersistenceEditor.this, + page.getClass().getName(), + page.pageText()); + + this.page = page; + } + + @Override + protected void createFormContent(IManagedForm managedForm) { + + ScrolledForm form = managedForm.getForm(); + managedForm.getToolkit().decorateFormHeading(form.getForm()); + + // Update the text and image + updateForm(form); + + // Add the page's control to this page + Composite body = form.getBody(); + body.setLayout(new GridLayout(1, false)); + updateGridData(body); + page.getControl().setParent(body); + + // This will finish the initialization of the buttons + updateHelpButton(); + form.updateToolBar(); + + // Populate the page + page.populate(); + } + + /* + * (non-Javadoc) + */ + @Override + public void dispose() { + page.dispose(); + super.dispose(); + } + + private void updateForm(ScrolledForm form) { + + form.setText(page.pageText()); + + Image image = page.pageImage(); + + if (image != null) { + form.setImage(image); + } + } + + 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); + } + + private void updateHelpButton() { + + String helpID = page.helpID(); + + 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); + } + }); + } + } + } +} 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 new file mode 100644 index 0000000000..517f6a29e6 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * 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 +{ + private static final String BUNDLE_NAME = "jpt_ui_persistence"; + + public static String Boolean_False; + public static String Boolean_True; + + public static String PersistenceEditor_Page_help; + + public static String PersistenceUnitComposite_connection; + public static String PersistenceUnitComposite_general; + + public static String PersistenceUnitConnectionComposite_database; + public static String PersistenceUnitConnectionComposite_general; + + public static String PersistenceUnitConnectionDatabaseComposite_description; + public static String PersistenceUnitConnectionDatabaseComposite_jtaDatasourceName; + public static String PersistenceUnitConnectionDatabaseComposite_nonJtaDatasourceName; + + public static String PersistenceUnitConnectionGeneralComposite_default; + public static String PersistenceUnitConnectionGeneralComposite_description; + public static String PersistenceUnitConnectionGeneralComposite_jta; + public static String PersistenceUnitConnectionGeneralComposite_serverProvider; + 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_mappedClasses; + public static String PersistenceUnitGeneralComposite_persistenceProvider; + + public static String PersistenceUnitJPAMappingDescriptorsComposite_description; + public static String PersistenceUnitJPAMappingDescriptorsComposite_ormNoName; + + public static String PersistenceUnitMappedClassesComposite_description; + public static String PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClasses; + public static String PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClassesWithDefault; + public static String PersistenceUnitMappedClassesComposite_mappedClassesNoName; + + static { + NLS.initializeMessages(BUNDLE_NAME, JptUiPersistenceMessages.class); + } + + private JptUiPersistenceMessages() { + throw new UnsupportedOperationException(); + } +} 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 new file mode 100644 index 0000000000..250386944b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitClassesComposite.java @@ -0,0 +1,345 @@ +/******************************************************************************* + * 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.persistence.ClassRef; +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.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.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.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); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + for (Object item : listSelectionModel.selectedValues()) { + subject().removeSpecifiedClassRef((ClassRef) 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 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); + } + }; + } + + 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.PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClassesWithDefault, + defaultStringValue + ); + } + } + + return JptUiPersistenceMessages.PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClasses; + } + }; + } + + private ListValueModel<ClassRef> buildItemListHolder() { + return new ItemPropertyListValueModelAdapter<ClassRef>( + buildListHolder(), + ClassRef.CLASS_NAME_PROPERTY + ); + } + + private ILabelProvider buildLabelProvider() { + return new LabelProvider() { + @Override + public Image getImage(Object element) { + // TODO + ClassRef classRef = (ClassRef) element; + String key = classRef.getJavaPersistentType().getMapping().getKey(); + System.out.println(key); + return JptUiPlugin.getImage(JptUiIcons.ENTITY); + } + + @Override + public String getText(Object element) { + ClassRef classRef = (ClassRef) element; + String name = classRef.getClassName(); + + if (name == null) { + name = JptUiPersistenceMessages.PersistenceUnitMappedClassesComposite_mappedClassesNoName; + } + + return name; + } + }; + } + + 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; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Description + buildMultiLineLabel( + container, + JptUiPersistenceMessages.PersistenceUnitMappedClassesComposite_description + ); + + // 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()); + } + }; + + buildTriStateCheckBoxWithDefault( + container, + JptUiPersistenceMessages.PersistenceUnitMappedClassesComposite_excludeUnlistedMappedClasses, + buildExcludeUnlistedMappedClassesHolder(), + buildExcludeUnlistedMappedClassesStringHolder() + ); + } + + private IPackageFragmentRoot packageFragmentRoot() { + IProject project = subject().jpaProject().project(); + IJavaProject root = JavaCore.create(project); + + try { + return root.getAllPackageFragmentRoots()[0]; + } + catch (JavaModelException e) { + JptUiPlugin.log(e); + } + + return null; + } + + 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/PersistenceUnitConnectionComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionComposite.java new file mode 100644 index 0000000000..a0cdb36d5c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionComposite.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * 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.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.ui.internal.widgets.WidgetFactory; +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 helpID() { + 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 pageImage() { + return null; + } + + /* + * (non-Javadoc) + */ + public String pageText() { + return JptUiPersistenceMessages.PersistenceUnitComposite_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 new file mode 100644 index 0000000000..4ba8ad3199 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionDatabaseComposite.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * 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> + * ----------------------------------------------------------------------------- + * | | + * | Description | + * | | + * | ------------------------------------------------ | + * | 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, false); + } + + 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) { + 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) { + subject.setNonJtaDataSource(value); + } + }; + } + + private PropertyValueModel<PersistenceUnitTransactionType> buildTransactionTypeHolder() { + return new PropertyAspectAdapter<PersistenceUnit, PersistenceUnitTransactionType>( + getSubjectHolder(), + PersistenceUnit.DEFAULT_TRANSACTION_TYPE_PROPERTY, + PersistenceUnit.TRANSACTION_TYPE_PROPERTY) + { + @Override + protected PersistenceUnitTransactionType buildValue_() { + return subject.getTransactionType(); + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Description + buildMultiLineLabel( + container, + JptUiPersistenceMessages.PersistenceUnitConnectionDatabaseComposite_description + ); + + // JTA Datasource Name widgets + Text text = buildLabeledText( + container, + JptUiPersistenceMessages.PersistenceUnitConnectionDatabaseComposite_jtaDatasourceName, + buildJTADatasourceNameHolder() + ); + + installJTADatasourceNameEnabler(text); + + // Non-JTA Datasource Name widgets + 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); + } +} 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 new file mode 100644 index 0000000000..4e2893b100 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitConnectionGeneralComposite.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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> + * ----------------------------------------------------------------------------- + * | | + * | Description | + * | | + * | ------------------------------------------------------ | + * | Transaction Type: | |v| | + * | ------------------------------------------------------ | + * -----------------------------------------------------------------------------</pre> + * + * @see PersistenceUnit + * @see PersistenceUnitGeneralComposite - 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, false); + } + + 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.TRANSACTION_TYPE_PROPERTY); + } + + @Override + protected PersistenceUnitTransactionType[] choices() { + return new PersistenceUnitTransactionType[] { + PersistenceUnitTransactionType.JTA, + PersistenceUnitTransactionType.RESOURCE_LOCAL + }; + } + + @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().getTransactionType(); + } + + @Override + protected void setValue(PersistenceUnitTransactionType value) { + if (value == PersistenceUnitTransactionType.DEFAULT || value == null) { + subject().setTransactionTypeToDefault(); + } + else { + subject().setTransactionType(value); + } + } + }; + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Description + buildMultiLineLabel( + container, + JptUiPersistenceMessages.PersistenceUnitConnectionGeneralComposite_description + ); + + // 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 new file mode 100644 index 0000000000..8f70063a0d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java @@ -0,0 +1,205 @@ +/******************************************************************************* + * 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.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.ui.internal.widgets.WidgetFactory; +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 --------------------------------------------------------------- | + * | --------------------------------------------------- | + * | Persistence Provider: | |v| | + * | --------------------------------------------------- | + * | | + * | - JPA Mapping Descriptors ----------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | PersistenceUnitJPAMappingDescriptorsComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - Mapped Classes -------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | PersistenceUnitMappedClassesComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see PersistenceUnit + * @see PersistenceUnitJPAMappingDescriptorsComposite + * @see PersistenceUnitJavaArchivesComposite + * @see PersistenceUnitMappedClassesComposite + * + * @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) { + subject.setProvider(value); + } + }; + } + + /* + * (non-Javadoc) + */ + public String helpID() { + return JpaHelpContextIds.PERSISTENCE_UNIT_GENERAL; + } + + private void initializeGeneralPane(Composite container) { + + container = buildSection( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_general + ); + + // Persistence Provider widgets + buildLabeledText( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_persistenceProvider, + buildPersistenceProviderHolder() + ); + } + + private void initializeJPAMappingDescriptorsPane(Composite container) { + + container = buildSection( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jpaMappingDescriptors + ); + + updateGridData(container); + updateGridData(container.getParent()); + + new PersistenceUnitMappingFilesComposite(this, container); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + initializeGeneralPane(container); + initializeJPAMappingDescriptorsPane(container); +// initializeJavaArchivesPane(container); + initializeMappedClassesPane(container); + } + + private void initializeMappedClassesPane(Composite container) { + + container = buildSection( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_mappedClasses + ); + + updateGridData(container); + updateGridData(container.getParent()); + + new PersistenceUnitClassesComposite(this, container); + } + + /* + * (non-Javadoc) + */ + public Image pageImage() { + return null; + } + + /* + * (non-Javadoc) + */ + public String pageText() { + return JptUiPersistenceMessages.PersistenceUnitComposite_general; + } + + 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 new file mode 100644 index 0000000000..b924710d18 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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 new file mode 100644 index 0000000000..fe7ea3e261 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * 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.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +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.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.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.FilteredResourcesSelectionDialog; + +/** + * 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 PersistenceUnitMappingFilesComposite extends AbstractPane<PersistenceUnit> +{ + /** + * Creates a new <code>PersistenceUnitJPAMappingDescriptorsComposite</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); + } + + private void addJPAMappingDescriptor(ObjectListSelectionModel listSelectionModel) { + + IProject project = subject().jpaProject().project(); + // TODO: Retrieve the META-INF directory + + FilteredResourcesSelectionDialog dialog = new FilteredResourcesSelectionDialog( + shell(), + true, + project, + IResource.FILE + ); + + if (dialog.open() == IDialogConstants.OK_ID) { + int index = subject().specifiedMappingFileRefsSize(); + + for (Object result : dialog.getResult()) { + IFile file = (IFile) result; + + MappingFileRef mappingFileRef = subject().addSpecifiedMappingFileRef(index++); + mappingFileRef.setFileName(file.getProjectRelativePath().toPortableString()); + + listSelectionModel.addSelectedValue(mappingFileRef); + } + } + } + + 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.PersistenceUnitJPAMappingDescriptorsComposite_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>(); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Description + buildMultiLineLabel( + container, + JptUiPersistenceMessages.PersistenceUnitJPAMappingDescriptorsComposite_description + ); + + // 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()); + } + }; + } + + 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/widgets/AbstractFormPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractFormPane.java index 947eb391a0..5440e4489e 100644 --- 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 @@ -12,7 +12,7 @@ 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.swt.widgets.Composite; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +import org.eclipse.ui.forms.widgets.FormToolkit; /** * The abstract pane to use when the pane is shown using the form look and feel, @@ -122,7 +122,7 @@ public abstract class AbstractFormPane<T extends Model> extends AbstractPane<T> */ protected AbstractFormPane(PropertyValueModel<? extends T> subjectHolder, Composite parent, - TabbedPropertySheetWidgetFactory widgetFactory) { + FormToolkit widgetFactory) { this(subjectHolder, parent, new FormWidgetFactory(widgetFactory)); } @@ -133,7 +133,7 @@ public abstract class AbstractFormPane<T extends Model> extends AbstractPane<T> * @return The factory used to create the widgets with the form style * (flat-style) look and feel */ - protected final TabbedPropertySheetWidgetFactory getFormWidgetFactory() { + protected final FormToolkit getFormWidgetFactory() { FormWidgetFactory widgetFactory = (FormWidgetFactory) getWidgetFactory(); return widgetFactory.getWidgetFactory(); } 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 index 27f387509e..769d9cfa22 100644 --- 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 @@ -468,6 +468,88 @@ public abstract class AbstractPane<T extends Model> } /** + * 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.value() != null ? expandedStateHolder.value() : 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 non-editable <code>Combo</code>. * * @param container The parent container @@ -1694,6 +1776,20 @@ public abstract class AbstractPane<T extends Model> } /** + * 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 @@ -1985,29 +2081,6 @@ public abstract class AbstractPane<T extends Model> * @param container The container of the new widget * @param sectionText The text of the new section * @param type The type of section to create - * @return The <code>Section</code>'s sub-pane - * - * @category Layout - */ - private Composite buildSection(Composite container, - String sectionText, - int type) { - - return this.buildSection( - container, - sectionText, - type, - new SimplePropertyValueModel<Boolean>(Boolean.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 @@ -2016,14 +2089,9 @@ public abstract class AbstractPane<T extends Model> */ private Composite buildSection(Composite container, String sectionText, - int type, - PropertyValueModel<Boolean> expandedStateHolder) { - - Section section = this.widgetFactory.createSection( - container, - ExpandableComposite.TWISTIE | type - ); + int type) { + Section section = this.widgetFactory.createSection(container, type); section.setText(sectionText); section.marginWidth = 0; section.marginHeight = 0; @@ -2036,42 +2104,9 @@ public abstract class AbstractPane<T extends Model> Composite subPane = this.buildSubPane(section); section.setClient(subPane); - expandedStateHolder.addPropertyChangeListener( - PropertyValueModel.VALUE, - buildExpandedStateChangeListener(section) - ); - - section.setExpanded( - expandedStateHolder.value() != null ? expandedStateHolder.value() : true - ); - return subPane; } - /** - * Creates a new <code>Section</code>. A sub-pane is automatically added as - * its client and is the returned <code>Composite</code>. - * - * @param container The container of the new widget - * @param sectionText The text of the new section - * @param expandedStateHolder The holder of the boolean that will dictate - * when to expand or collapse the section - * @return The <code>Section</code>'s sub-pane - * - * @category Layout - */ - protected final Composite buildSection(Composite container, - String sectionText, - PropertyValueModel<Boolean> expandedStateHolder) { - - return this.buildSection( - container, - sectionText, - ExpandableComposite.TITLE_BAR, - expandedStateHolder - ); - } - private SelectionListener buildSelectionListener(final WritablePropertyValueModel<String> selectionHolder) { return new SelectionAdapter() { @Override @@ -2266,8 +2301,7 @@ public abstract class AbstractPane<T extends Model> return this.buildSection( container, sectionText, - SWT.NULL, - expandedStateHolder + SWT.NULL ); } 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 index a2719f09bf..2cf4df20b2 100644 --- 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 @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ 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 index 7ab16ed6f9..74768ba4c7 100644 --- 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 @@ -11,6 +11,7 @@ package org.eclipse.jpt.ui.internal.widgets; 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; @@ -18,8 +19,12 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.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>IWidgetFactory</code> simply creates plain SWT widgets. @@ -127,7 +132,7 @@ public final class DefaultWidgetFactory implements WidgetFactory { * (non-Javadoc) */ public Label createLabel(Composite parent, String labelText) { - Label label = new Label(parent, SWT.LEFT); + Label label = new Label(parent, SWT.WRAP); label.setText(labelText); return label; } @@ -142,6 +147,34 @@ public final class DefaultWidgetFactory implements WidgetFactory { /* * (non-Javadoc) */ + 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.setText(labelText, false, false); + text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); + + return text; + } + + /* + * (non-Javadoc) + */ public Text createMultiLineText(Composite parent) { return new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); } 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 index 39aa111079..8a29b8ae10 100644 --- 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 @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ @@ -31,7 +31,7 @@ public abstract class EnumFormComboViewer<T extends Model, V> extends AbstractEn * @param parent The parent container * @param widgetFactory The factory used to create various widgets */ - protected EnumFormComboViewer(AbstractFormPane<? extends T> parentPane, + protected EnumFormComboViewer(AbstractPane<? extends T> parentPane, Composite parent) { super(parentPane, parent); @@ -44,7 +44,7 @@ public abstract class EnumFormComboViewer<T extends Model, V> extends AbstractEn * @param parent The parent container * @param widgetFactory The factory used to create various widgets */ - protected EnumFormComboViewer(AbstractFormPane<?> parentPane, + protected EnumFormComboViewer(AbstractPane<?> parentPane, PropertyValueModel<? extends T> subjectHolder, Composite parent) { 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 index 609f2ee9c9..a7221739d3 100644 --- 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 @@ -21,27 +21,30 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.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.views.properties.tabbed.TabbedPropertySheetWidgetFactory; +import org.eclipse.ui.forms.widgets.TableWrapData; +import org.eclipse.ui.forms.widgets.TableWrapLayout; /** * This <code>IWidgetFactory</code> is responsible to create the widgets - * using the <code>TabbedPropertySheetWidgetFactory</code> in order use the - * form style (flat-style) look and feel. + * using the <code>FormToolkit</code> in order use the form style (flat-style) + * look and feel. * - * @see TabbedPropertySheetWidgetFactory + * @see FormToolkit * * @version 2.0 * @since 2.0 */ @SuppressWarnings("nls") -public final class FormWidgetFactory implements WidgetFactory { +public class FormWidgetFactory implements WidgetFactory { /** * The actual factory responsible for creating the new widgets. */ - private final TabbedPropertySheetWidgetFactory widgetFactory; + private final FormToolkit widgetFactory; /** * Creates a new <code>FormWidgetFactory</code>. @@ -49,15 +52,14 @@ public final class FormWidgetFactory implements WidgetFactory { * @param widgetFactory The actual factory responsible for creating the new * widgets */ - public FormWidgetFactory(TabbedPropertySheetWidgetFactory widgetFactory) { + public FormWidgetFactory(FormToolkit widgetFactory) { super(); Assert.isNotNull(widgetFactory, "The widget factory cannot be null"); this.widgetFactory = widgetFactory; } - private Text buildText(Composite parent, int style) { - parent = fixTextBorderNotPainted(parent); + protected Text buildText(Composite parent, int style) { return widgetFactory.createText(parent, null, SWT.FLAT | style); } @@ -68,7 +70,7 @@ public final class FormWidgetFactory implements WidgetFactory { return this.createButton(parent, text, SWT.NULL); } - private Button createButton(Composite parent, String text, int style) { + protected final Button createButton(Composite parent, String text, int style) { return widgetFactory.createButton(parent, text, SWT.FLAT | style); } @@ -76,7 +78,21 @@ public final class FormWidgetFactory implements WidgetFactory { * (non-Javadoc) */ public CCombo createCCombo(Composite parent) { - return createCombo(parent, SWT.READ_ONLY); + return createCCombo(parent, SWT.READ_ONLY); + } + + protected CCombo createCCombo(Composite parent, int style) { + parent = fixComboBorderNotPainted(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; } /* @@ -93,23 +109,20 @@ public final class FormWidgetFactory implements WidgetFactory { return new Combo(parent, SWT.READ_ONLY); } - private CCombo createCombo(Composite parent, int style) { - parent = fixComboBorderNotPainted(parent); - return widgetFactory.createCCombo(parent, SWT.FLAT | style); - } - /* * (non-Javadoc) */ public Composite createComposite(Composite parent) { - return widgetFactory.createComposite(parent); + Composite composite = widgetFactory.createComposite(parent); + widgetFactory.paintBordersFor(composite); + return composite; } /* * (non-Javadoc) */ public CCombo createEditableCCombo(Composite parent) { - return createCombo(parent, SWT.NULL); + return createCCombo(parent, SWT.NULL); } /* @@ -123,7 +136,11 @@ public final class FormWidgetFactory implements WidgetFactory { * (non-Javadoc) */ public Group createGroup(Composite parent, String title) { - return widgetFactory.createGroup(parent, title); + Group group = new Group(parent, SWT.SHADOW_NONE); + group.setText(title); + group.setBackground(widgetFactory.getColors().getBackground()); + group.setForeground(widgetFactory.getColors().getForeground()); + return group; } /* @@ -137,14 +154,41 @@ public final class FormWidgetFactory implements WidgetFactory { * (non-Javadoc) */ public Label createLabel(Composite container, String labelText) { - return widgetFactory.createLabel(container, labelText); + return widgetFactory.createLabel(container, labelText, SWT.WRAP); } /* * (non-Javadoc) */ public List createList(Composite container, int style) { - return widgetFactory.createList(container, SWT.FLAT | style); + return new List(container, SWT.FLAT | style); + } + + /* + * (non-Javadoc) + */ + 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.setText(labelText, false, false); + text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); + + return text; } /* @@ -199,7 +243,7 @@ public final class FormWidgetFactory implements WidgetFactory { * @return A new <code>Composite</code> that has the necessary space to paint * the border */ - private Composite fixComboBorderNotPainted(Composite container) { + protected final Composite fixComboBorderNotPainted(Composite container) { GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0; @@ -229,15 +273,15 @@ public final class FormWidgetFactory implements WidgetFactory { * @return A new <code>Composite</code> that has the necessary space to paint * the border */ - private Composite fixTextBorderNotPainted(Composite container) { + protected final Composite fixTextBorderNotPainted(Composite container) { GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; - layout.marginTop = 2; - layout.marginLeft = 2; - layout.marginBottom = 2; - layout.marginRight = 2; + layout.marginTop = 1; + layout.marginLeft = 1; + layout.marginBottom = 1; + layout.marginRight = 1; GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; @@ -255,7 +299,7 @@ public final class FormWidgetFactory implements WidgetFactory { * * @return The factory creating the widgets with the form style (flat-style) */ - public TabbedPropertySheetWidgetFactory getWidgetFactory() { + 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/PropertySheetWidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PropertySheetWidgetFactory.java new file mode 100644 index 0000000000..a02405ea65 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/PropertySheetWidgetFactory.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.ui.internal.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>IWidgetFactory</code> is responsible to create the widgets + * using the <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); + } + + /* + * (non-Javadoc) + */ + @Override + protected Text buildText(Composite parent, int style) { + parent = fixTextBorderNotPainted(parent); + return getWidgetFactory().createText(parent, null, SWT.FLAT | style); + } + + /* + * (non-Javadoc) + */ + @Override + protected CCombo createCCombo(Composite parent, int style) { + parent = fixComboBorderNotPainted(parent); + return getWidgetFactory().createCCombo(parent, style); + } + + /* + * (non-Javadoc) + */ + @Override + public Composite createComposite(Composite parent) { + return getWidgetFactory().createComposite(parent); + } + + /* + * (non-Javadoc) + */ + @Override + public Group createGroup(Composite parent, String title) { + return getWidgetFactory().createGroup(parent, title); + } + + /* + * (non-Javadoc) + */ + @Override + public TabbedPropertySheetWidgetFactory getWidgetFactory() { + return (TabbedPropertySheetWidgetFactory) super.getWidgetFactory(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/WidgetFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/WidgetFactory.java index 38cb52f31b..7d15e6dbd0 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/WidgetFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/WidgetFactory.java @@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.FormText; import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.Section; @@ -126,6 +127,15 @@ public interface WidgetFactory { List createList(Composite container, int style); /** + * Creates a new label that can be wrapped on multiple lines. + * + * @param container The parent container + * @param labelText The label's text + * @return A new <code>FormText</code> + */ + FormText createMultiLineLabel(Composite container, String labelText); + + /** * Creates a new editable text area. * * @param parent The parent container @@ -171,6 +181,7 @@ public interface WidgetFactory { */ Text createText(Composite parent); + /** * Creates a new tri-state check box. * @@ -179,4 +190,4 @@ public interface WidgetFactory { * @return A new <code>Button</code> that has 3 selection states */ Button createTriStateCheckBox(Composite parent, String text); -} +}
\ No newline at end of file |