Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2007-05-09 15:07:58 +0000
committerkmoore2007-05-09 15:07:58 +0000
commitd4bed7e76ccca76bdee99a8d28c34969bced9e0a (patch)
tree5928da2c7ca2715b6f2fb85fdc731fc9d74e68a9 /jpa
parentef7935e0c50e1233ef629d81a642c4502ed0d641 (diff)
downloadwebtools.dali-d4bed7e76ccca76bdee99a8d28c34969bced9e0a.tar.gz
webtools.dali-d4bed7e76ccca76bdee99a8d28c34969bced9e0a.tar.xz
webtools.dali-d4bed7e76ccca76bdee99a8d28c34969bced9e0a.zip
142011 - editing of secondaryTable primary key join columns
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlEntityInternal.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IEntity.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_mappings.properties2
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java37
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java407
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java81
13 files changed, 546 insertions, 21 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java
index 3312e2f940..b661d91d07 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaEntity.java
@@ -1257,7 +1257,15 @@ public class JavaEntity extends JavaTypeMapping implements IEntity
}
public boolean containsSecondaryTable(String name) {
- for (ISecondaryTable secondaryTable : getSecondaryTables()) {
+ return containsSecondaryTable(name, getSecondaryTables());
+ }
+
+ public boolean containsSpecifiedSecondaryTable(String name) {
+ return containsSecondaryTable(name, getSpecifiedSecondaryTables());
+ }
+
+ private boolean containsSecondaryTable(String name, List<ISecondaryTable> secondaryTables) {
+ for (ISecondaryTable secondaryTable : secondaryTables) {
String secondaryTableName = secondaryTable.getName();
if (secondaryTableName != null && secondaryTableName.equals(name)) {
return true;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java
index 4018777447..651461299b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/java/mappings/JavaSecondaryTable.java
@@ -421,6 +421,10 @@ public class JavaSecondaryTable extends AbstractJavaTable
return new ISecondaryTable.PrimaryKeyJoinColumnOwner(this);
}
+ public boolean containsSpecifiedPrimaryKeyJoinColumns() {
+ return !this.getSpecifiedPrimaryKeyJoinColumns().isEmpty();
+ }
+
@Override
protected JavaUniqueConstraint createJavaUniqueConstraint(int index) {
return JavaUniqueConstraint.createSecondaryTableUniqueConstraint(this, getMember(), index);
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlEntityInternal.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlEntityInternal.java
index 4adbd6f3c7..30a91a231f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlEntityInternal.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlEntityInternal.java
@@ -476,7 +476,15 @@ public class XmlEntityInternal extends XmlTypeMapping
}
public boolean containsSecondaryTable(String name) {
- for (ISecondaryTable secondaryTable : getSecondaryTables()) {
+ return containsSecondaryTable(name, getSecondaryTables());
+ }
+
+ public boolean containsSpecifiedSecondaryTable(String name) {
+ return containsSecondaryTable(name, getSpecifiedSecondaryTables());
+ }
+
+ private boolean containsSecondaryTable(String name, List<ISecondaryTable> secondaryTables) {
+ for (ISecondaryTable secondaryTable : secondaryTables) {
String secondaryTableName = secondaryTable.getName();
if (secondaryTableName != null && secondaryTableName.equals(name)) {
return true;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java
index 6a07c64dce..6fde7390a2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/content/orm/XmlSecondaryTable.java
@@ -275,6 +275,10 @@ public class XmlSecondaryTable extends AbstractXmlTable
//when the XmlSecondaryTable is removed/added to the XmlEntity collection
}
+ public boolean containsSpecifiedPrimaryKeyJoinColumns() {
+ return !this.getSpecifiedPrimaryKeyJoinColumns().isEmpty();
+ }
+
public IPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(int index) {
return OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumn(new ISecondaryTable.PrimaryKeyJoinColumnOwner(this));
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IEntity.java
index 8ab8d7ff68..75b0ce3985 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/IEntity.java
@@ -543,6 +543,8 @@ public interface IEntity extends ITypeMapping
boolean containsSpecifiedAssociationOverride(String name);
boolean containsSecondaryTable(String name);
+
+ boolean containsSpecifiedSecondaryTable(String name);
ISecondaryTable createSecondaryTable(int index);
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java
index d252be5cca..c9f4abcbe8 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/mappings/ISecondaryTable.java
@@ -94,6 +94,8 @@ public interface ISecondaryTable extends ITable
* Create a primary key join column with the given index
*/
IPrimaryKeyJoinColumn createPrimaryKeyJoinColumn(int index);
+
+ boolean containsSpecifiedPrimaryKeyJoinColumns();
class PrimaryKeyJoinColumnOwner implements IAbstractJoinColumn.Owner
{
private ISecondaryTable secondaryTable;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java
index 46d09dc266..91711a03b1 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlEntityContext.java
@@ -247,7 +247,8 @@ public class XmlEntityContext extends XmlTypeContext
for (Iterator<ISecondaryTable> i = getEntity().getVirtualSecondaryTables().iterator(); i.hasNext(); ) {
ISecondaryTable secondaryTable = i.next();
- if (getXmlTypeMapping().isXmlMetadataComplete()) {
+
+ if (getXmlTypeMapping().isXmlMetadataComplete() || getEntity().containsSpecifiedSecondaryTable(secondaryTable.getName())) {
secondaryTablesToRemove.add(secondaryTable);
continue;
}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_mappings.properties b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_mappings.properties
index 32e290cfc4..d697849a10 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_mappings.properties
+++ b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_mappings.properties
@@ -125,7 +125,7 @@ PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault={0} -> Default
AttributeOverridesComposite_attributeOverrides=Attribute Overrides
AttributeOverridesComposite_overridDefault=Override Default
-
+OverridesComposite_joinColumn=Join Columns
InheritanceComposite_strategy=Strategy:
InheritanceComposite_discriminatorValue=Discriminator Value:
InheritanceComposite_discriminatorValueDefaultWithOneParam=Default ({0})
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java
index f94ca4f5e4..29cce84c7b 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java
@@ -129,10 +129,11 @@ public class JptUiMappingsMessages extends NLS
public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault;
public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault;
public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault;
-
public static String PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault;
+
public static String AttributeOverridesComposite_attributeOverrides;
public static String AttributeOverridesComposite_overridDefault;
+ public static String OverridesComposite_joinColumn;
public static String InheritanceComposite_strategy;
public static String InheritanceComposite_discriminatorValue;
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java
index d95b2b88a5..7ddf3c99e7 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EntityComposite.java
@@ -154,7 +154,7 @@ public class EntityComposite extends BaseJpaComposite
private Control buildAttributeOverridesComposite(Composite composite) {
Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
section.setText(JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides);
- section.setExpanded(true);
+ //section.setExpanded(true); //not going to expand this for now, it causes the scroll bar not to appear
Composite client = getWidgetFactory().createComposite(section);
section.setClient(client);
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java
new file mode 100644
index 0000000000..51a220df88
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnInSecondaryTableDialog.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Oracle. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Oracle. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.ui.internal.mappings.details;
+
+import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn;
+import org.eclipse.jpt.core.internal.mappings.ISecondaryTable;
+import org.eclipse.jpt.db.internal.Table;
+import org.eclipse.swt.widgets.Shell;
+
+public class PrimaryKeyJoinColumnInSecondaryTableDialog extends AbstractJoinColumnDialog<IPrimaryKeyJoinColumn> {
+
+ private ISecondaryTable secondaryTable;
+
+ PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, ISecondaryTable secondaryTable) {
+ super(parent);
+ this.secondaryTable = secondaryTable;
+ }
+
+ PrimaryKeyJoinColumnInSecondaryTableDialog(Shell parent, IPrimaryKeyJoinColumn joinColumn) {
+ super(parent, joinColumn);
+ this.secondaryTable = (ISecondaryTable) joinColumn.eContainer();
+ }
+
+ protected Table getNameTable() {
+ return this.secondaryTable.dbTable();
+ }
+
+ protected Table getReferencedNameTable() {
+ return this.secondaryTable.typeMapping().primaryDbTable();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
new file mode 100644
index 0000000000..6830991f4f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java
@@ -0,0 +1,407 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.ui.internal.mappings.details;
+
+import java.util.Iterator;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jpt.core.internal.mappings.IAbstractJoinColumn;
+import org.eclipse.jpt.core.internal.mappings.INamedColumn;
+import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn;
+import org.eclipse.jpt.core.internal.mappings.ISecondaryTable;
+import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
+import org.eclipse.jpt.ui.internal.IJpaHelpContextIds;
+import org.eclipse.jpt.ui.internal.details.BaseJpaComposite;
+import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
+
+public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends BaseJpaComposite
+{
+ private ISecondaryTable secondaryTable;
+ private final Adapter secondaryTableListener;
+ private final Adapter pkJoinColumnListener;
+
+ ListViewer pkJoinColumnsListViewer;
+
+ private Group pkJoinColumnsGroup;
+ Button overrideDefaultJoinColumnsCheckBox;
+ private Button pkJoinColumnsAddButton;
+ private Button pkJoinColumnsRemoveButton;
+ private Button pkJoinColumnsEditButton;
+
+
+ public PrimaryKeyJoinColumnsInSecondaryTableComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
+ super(parent, SWT.NULL, commandStack, widgetFactory);
+ this.secondaryTableListener = buildSecondaryTableListener();
+ this.pkJoinColumnListener = buildPkJoinColumnListener();
+ }
+
+ private Adapter buildSecondaryTableListener() {
+ return new AdapterImpl() {
+ public void notifyChanged(Notification notification) {
+ secondaryTableChanged(notification);
+ }
+ };
+ }
+
+ private Adapter buildPkJoinColumnListener() {
+ return new AdapterImpl() {
+ public void notifyChanged(Notification notification) {
+ pkJoinColumnChanged(notification);
+ }
+ };
+ }
+
+ @Override
+ protected void initializeLayout(Composite composite) {
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginWidth = 0;
+ composite.setLayout(layout);
+
+ GridData gridData = new GridData();
+ this.overrideDefaultJoinColumnsCheckBox = getWidgetFactory().createButton(
+ composite,
+ JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns,
+ SWT.CHECK);
+ this.overrideDefaultJoinColumnsCheckBox.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ if (PrimaryKeyJoinColumnsInSecondaryTableComposite.this.overrideDefaultJoinColumnsCheckBox.getSelection()) {
+ IPrimaryKeyJoinColumn defaultJoinColumn = PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.getDefaultPrimaryKeyJoinColumns().get(0);
+ String columnName = defaultJoinColumn.getDefaultName();
+ String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName();
+
+ IPrimaryKeyJoinColumn pkJoinColumn = PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.createPrimaryKeyJoinColumn(0);
+ PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().add(pkJoinColumn);
+ pkJoinColumn.setSpecifiedName(columnName);
+ pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ } else {
+ PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().clear();
+ }
+ }
+ });
+
+ this.pkJoinColumnsGroup =
+ getWidgetFactory().createGroup(
+ composite,
+ JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn);
+ this.pkJoinColumnsGroup.setLayout(new GridLayout(2, false));
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.horizontalSpan = 2;
+ this.pkJoinColumnsGroup.setLayoutData(gridData);
+
+ this.pkJoinColumnsListViewer = new ListViewer(this.pkJoinColumnsGroup, SWT.BORDER | SWT.MULTI);
+ this.pkJoinColumnsListViewer.setContentProvider(buildJoinColumnsListContentProvider());
+ this.pkJoinColumnsListViewer.setLabelProvider(buildJoinColumnsListLabelProvider());
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.verticalSpan = 3;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ this.pkJoinColumnsListViewer.getList().setLayoutData(gridData);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this.pkJoinColumnsListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS);
+
+ this.pkJoinColumnsAddButton = new Button(this.pkJoinColumnsGroup, SWT.NONE);
+ this.pkJoinColumnsAddButton.setText(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_add);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ this.pkJoinColumnsAddButton.setLayoutData(gridData);
+ this.pkJoinColumnsAddButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ addPrimaryKeyJoinColumn();
+ }
+ });
+
+ this.pkJoinColumnsEditButton = new Button(this.pkJoinColumnsGroup, SWT.NONE);
+ this.pkJoinColumnsEditButton.setText(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit);
+ this.pkJoinColumnsEditButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ editPrimaryKeyJoinColumn();
+ }
+ });
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ this.pkJoinColumnsEditButton.setLayoutData(gridData);
+
+ this.pkJoinColumnsRemoveButton = new Button(this.pkJoinColumnsGroup, SWT.NONE);
+ this.pkJoinColumnsRemoveButton.setText(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_remove);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ this.pkJoinColumnsRemoveButton.setLayoutData(gridData);
+ this.pkJoinColumnsRemoveButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // do nothing
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ removePrimaryKeyJoinColumn();
+ }
+ });
+
+ this.pkJoinColumnsListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updatePrimaryKeyJoinColumnsEnablement();
+ }
+ });
+ }
+
+ private IContentProvider buildJoinColumnsListContentProvider() {
+ return new IStructuredContentProvider(){
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // do nothing
+ }
+
+ public void dispose() {
+ // do nothing
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return ((ISecondaryTable) inputElement).getPrimaryKeyJoinColumns().toArray();
+ }
+ };
+ }
+
+ private ILabelProvider buildJoinColumnsListLabelProvider() {
+ return new LabelProvider() {
+ public String getText(Object element) {
+ IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) element;
+ return (PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns()) ?
+ buildJoinColumnLabel(joinColumn)
+ :
+ buildDefaultJoinColumnLabel(joinColumn);
+ }
+ };
+ }
+
+ String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) {
+ return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName());
+ }
+
+ String buildJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) {
+ if (joinColumn.getSpecifiedName() == null) {
+ if (joinColumn.getSpecifiedReferencedColumnName() == null) {
+ return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName());
+ }
+ return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsFirstDefault, joinColumn.getName(), joinColumn.getReferencedColumnName());
+ }
+ else if (joinColumn.getSpecifiedReferencedColumnName() == null) {
+ return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName());
+ }
+ else {
+ return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName());
+ }
+ }
+
+
+ void addPrimaryKeyJoinColumn() {
+ PrimaryKeyJoinColumnInSecondaryTableDialog dialog = new PrimaryKeyJoinColumnInSecondaryTableDialog(this.getControl().getShell(), this.secondaryTable);
+ addJoinColumnFromDialog(dialog);
+ }
+
+ private void addJoinColumnFromDialog(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) {
+ if (dialog.open() == Window.OK) {
+ int index = this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().size();
+ String name = dialog.getSelectedName();
+ String referencedColumnName = dialog.getReferencedColumnName();
+ IPrimaryKeyJoinColumn joinColumn = this.secondaryTable.createPrimaryKeyJoinColumn(index);
+ this.secondaryTable.getSpecifiedPrimaryKeyJoinColumns().add(joinColumn);
+ joinColumn.setSpecifiedName(name);
+ joinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ }
+ }
+
+ private IPrimaryKeyJoinColumn getSelectedJoinColumn() {
+ return (IPrimaryKeyJoinColumn) ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).getFirstElement();
+ }
+
+ void editPrimaryKeyJoinColumn() {
+ IPrimaryKeyJoinColumn joinColumn = getSelectedJoinColumn();
+ PrimaryKeyJoinColumnDialog dialog = new PrimaryKeyJoinColumnDialog(this.getControl().getShell(), joinColumn);
+ editJoinColumnFromDialog(dialog, joinColumn);
+ }
+
+ private void editJoinColumnFromDialog(PrimaryKeyJoinColumnDialog dialog, IPrimaryKeyJoinColumn joinColumn) {
+ if (dialog.open() == Window.OK) {
+ editJoinColumnDialogOkd(dialog, joinColumn);
+ }
+ }
+
+ private void editJoinColumnDialogOkd(PrimaryKeyJoinColumnDialog dialog, IPrimaryKeyJoinColumn joinColumn) {
+ String name = dialog.getSelectedName();
+ String referencedColumnName = dialog.getReferencedColumnName();
+
+ if (dialog.isDefaultNameSelected()) {
+ if (joinColumn.getSpecifiedName() != null) {
+ joinColumn.setSpecifiedName(null);
+ }
+ }
+ else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){
+ joinColumn.setSpecifiedName(name);
+ }
+
+ if (dialog.isDefaultReferencedColumnNameSelected()) {
+ if (joinColumn.getSpecifiedReferencedColumnName() != null) {
+ joinColumn.setSpecifiedReferencedColumnName(null);
+ }
+ }
+ else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){
+ joinColumn.setSpecifiedReferencedColumnName(referencedColumnName);
+ }
+ }
+
+ void removePrimaryKeyJoinColumn() {
+ ISelection selection = this.pkJoinColumnsListViewer.getSelection();
+ if (selection instanceof StructuredSelection) {
+ for (Iterator i = ((StructuredSelection) selection).iterator(); i.hasNext(); ) {
+ this.secondaryTable.getPrimaryKeyJoinColumns().remove(i.next());
+ }
+ }
+ }
+
+ void updatePrimaryKeyJoinColumnsEnablement() {
+ boolean groupEnabledState = this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns();
+ enableGroup(this.pkJoinColumnsGroup, groupEnabledState);
+
+ this.pkJoinColumnsRemoveButton.setEnabled(groupEnabledState && !((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).isEmpty());
+ this.pkJoinColumnsEditButton.setEnabled(groupEnabledState && ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).size() == 1);
+ }
+
+ private void enableGroup(Group group, boolean enabled) {
+ group.setEnabled(enabled);
+ for (int i = 0; i < group.getChildren().length; i++) {
+ group.getChildren()[i].setEnabled(enabled);
+ }
+ }
+
+
+ public void doPopulate(EObject obj) {
+ this.secondaryTable = (ISecondaryTable) obj;
+ if (this.secondaryTable == null) {
+ this.pkJoinColumnsListViewer.setInput(null);
+ return;
+ }
+
+ this.pkJoinColumnsListViewer.setInput(this.secondaryTable);
+
+
+ updatePrimaryKeyJoinColumnsEnablement();
+ this.overrideDefaultJoinColumnsCheckBox.setSelection(this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns());
+ }
+
+ @Override
+ protected void doPopulate() {
+ }
+
+ protected void engageListeners() {
+ if (this.secondaryTable != null) {
+ this.secondaryTable.eAdapters().add(this.secondaryTableListener);
+ for (IPrimaryKeyJoinColumn pkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) {
+ pkJoinColumn.eAdapters().add(this.pkJoinColumnListener);
+ }
+ }
+ }
+
+ protected void disengageListeners() {
+ if (this.secondaryTable != null) {
+ for (IPrimaryKeyJoinColumn pkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) {
+ pkJoinColumn.eAdapters().remove(this.pkJoinColumnListener);
+ }
+ this.secondaryTable.eAdapters().remove(this.secondaryTableListener);
+ }
+ }
+
+ protected void secondaryTableChanged(Notification notification) {
+ if (notification.getFeatureID(ISecondaryTable.class) == JpaCoreMappingsPackage.ISECONDARY_TABLE__SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS) {
+ if (notification.getEventType() == Notification.ADD) {
+ ((IPrimaryKeyJoinColumn) notification.getNewValue()).eAdapters().add(this.pkJoinColumnListener);
+ }
+ else if (notification.getEventType() == Notification.REMOVE) {
+ ((IPrimaryKeyJoinColumn) notification.getOldValue()).eAdapters().remove(this.pkJoinColumnListener);
+ }
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ pkJoinColumnsListViewer.refresh();
+ overrideDefaultJoinColumnsCheckBox.setSelection(secondaryTable.containsSpecifiedPrimaryKeyJoinColumns());
+ updatePrimaryKeyJoinColumnsEnablement();
+ }
+ });
+ }
+ }
+
+ protected void pkJoinColumnChanged(Notification notification) {
+ if (notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__SPECIFIED_NAME
+ || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__SPECIFIED_REFERENCED_COLUMN_NAME
+ || notification.getFeatureID(INamedColumn.class) == JpaCoreMappingsPackage.INAMED_COLUMN__DEFAULT_NAME
+ || notification.getFeatureID(IAbstractJoinColumn.class) == JpaCoreMappingsPackage.IABSTRACT_JOIN_COLUMN__DEFAULT_REFERENCED_COLUMN_NAME) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ pkJoinColumnsListViewer.refresh();
+ }
+ });
+ }
+ }
+
+ protected void enableWidgets(boolean enabled) {
+ this.pkJoinColumnsListViewer.getControl().setEnabled(enabled);
+ this.overrideDefaultJoinColumnsCheckBox.setEnabled(enabled);
+ this.pkJoinColumnsEditButton.setEnabled(enabled);
+ this.pkJoinColumnsRemoveButton.setEnabled(enabled);
+ this.pkJoinColumnsAddButton.setEnabled(enabled);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java
index 1f0e30d5a5..770648837a 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java
@@ -27,7 +27,6 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.jpt.core.internal.mappings.IEntity;
-import org.eclipse.jpt.core.internal.mappings.IPrimaryKeyJoinColumn;
import org.eclipse.jpt.core.internal.mappings.ISecondaryTable;
import org.eclipse.jpt.core.internal.mappings.ITable;
import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
@@ -43,7 +42,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-//TODO need to support a list of tables
+//TODO handle xml, how to handle virtual secondaryTables, adding them to xml, are they overriden, etc??
public class SecondaryTablesComposite extends BaseJpaComposite
{
private IEntity entity;
@@ -56,6 +55,7 @@ public class SecondaryTablesComposite extends BaseJpaComposite
private Button editButton;
private Button removeButton;
+ private PrimaryKeyJoinColumnsInSecondaryTableComposite pkJoinColumnsComposite;
public SecondaryTablesComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
super(parent, SWT.NULL, commandStack, widgetFactory);
@@ -86,20 +86,37 @@ public class SecondaryTablesComposite extends BaseJpaComposite
composite.setLayout(layout);
GridData gridData = new GridData();
-
- this.secondaryTablesListViewer = new ListViewer(composite, SWT.BORDER | SWT.MULTI);
- this.secondaryTablesListViewer.setContentProvider(buildSecondaryTablesListContentProvider());
- this.secondaryTablesListViewer.setLabelProvider(buildSecondaryTablesListLabelProvider());
+
+ Composite secondaryTablesComposite = new Composite(composite, SWT.NONE);
+ layout = new GridLayout(3, false);
+ layout.marginWidth = 0;
+ secondaryTablesComposite.setLayout(layout);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.verticalAlignment = GridData.FILL;
- gridData.verticalSpan = 3;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ secondaryTablesComposite.setLayoutData(gridData);
+
+ this.secondaryTablesListViewer = buildSecondaryTablesListViewer(secondaryTablesComposite);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalSpan = 3;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
this.secondaryTablesListViewer.getList().setLayoutData(gridData);
//PlatformUI.getWorkbench().getHelpSystem().setHelp(this.secondaryTablesListViewer.getList(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS);
- this.addButton = new Button(composite, SWT.NONE);
+ Composite buttonsComposite = new Composite(secondaryTablesComposite, SWT.NONE);
+ layout = new GridLayout(3, false);
+ layout.marginWidth = 0;
+ buttonsComposite.setLayout(layout);
+ gridData = new GridData();
+ gridData.horizontalAlignment = SWT.END;
+ buttonsComposite.setLayoutData(gridData);
+
+ this.addButton = new Button(buttonsComposite, SWT.NONE);
this.addButton.setText(JptUiMappingsMessages.SecondaryTablesComposite_add);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
@@ -114,7 +131,7 @@ public class SecondaryTablesComposite extends BaseJpaComposite
}
});
- this.editButton = new Button(composite, SWT.NONE);
+ this.editButton = new Button(buttonsComposite, SWT.NONE);
this.editButton.setText(JptUiMappingsMessages.SecondaryTablesComposite_edit);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
@@ -129,7 +146,7 @@ public class SecondaryTablesComposite extends BaseJpaComposite
}
});
- this.removeButton = new Button(composite, SWT.NONE);
+ this.removeButton = new Button(buttonsComposite, SWT.NONE);
this.removeButton.setText(JptUiMappingsMessages.SecondaryTablesComposite_remove);
gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
@@ -145,13 +162,42 @@ public class SecondaryTablesComposite extends BaseJpaComposite
}
});
- this.secondaryTablesListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ this.pkJoinColumnsComposite = new PrimaryKeyJoinColumnsInSecondaryTableComposite(composite, this.commandStack, getWidgetFactory());
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ this.pkJoinColumnsComposite.getControl().setLayoutData(gridData);
+ }
+
+ private ListViewer buildSecondaryTablesListViewer(Composite parent) {
+ ListViewer listViewer = new ListViewer(parent, SWT.SINGLE | SWT.BORDER);
+ listViewer.setLabelProvider(buildSecondaryTablesListLabelProvider());
+ listViewer.setContentProvider(buildSecondaryTablesListContentProvider());
+
+ listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateEnablement();
+ secondaryTablesListSelectionChanged(event);
}
});
+
+ return listViewer;
}
+ protected void secondaryTablesListSelectionChanged(SelectionChangedEvent event) {
+ if (((StructuredSelection) event.getSelection()).isEmpty()) {
+ this.pkJoinColumnsComposite.populate(null);
+ this.pkJoinColumnsComposite.enableWidgets(false);
+ }
+ else {
+ ISecondaryTable selectedSecondaryTable = getSelectedSecondaryTable();
+ this.pkJoinColumnsComposite.populate(selectedSecondaryTable);
+ this.pkJoinColumnsComposite.enableWidgets(true);
+ }
+ }
+
private IContentProvider buildSecondaryTablesListContentProvider() {
return new IStructuredContentProvider(){
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@@ -194,6 +240,8 @@ public class SecondaryTablesComposite extends BaseJpaComposite
secondaryTable.setSpecifiedName(name);
secondaryTable.setSpecifiedCatalog(catalog);
secondaryTable.setSpecifiedSchema(schema);
+
+ this.secondaryTablesListViewer.setSelection(new StructuredSelection(secondaryTable));
}
}
@@ -264,7 +312,12 @@ public class SecondaryTablesComposite extends BaseJpaComposite
}
this.secondaryTablesListViewer.setInput(this.entity);
-
+ if (!this.entity.getSecondaryTables().isEmpty()) {
+ this.secondaryTablesListViewer.setSelection(new StructuredSelection(this.entity.getSecondaryTables().get(0)));
+ }
+ else {
+ this.secondaryTablesListViewer.setSelection(null);
+ }
updateEnablement();
}
@@ -277,14 +330,12 @@ public class SecondaryTablesComposite extends BaseJpaComposite
this.entity.eAdapters().add(this.entityListener);
for (ISecondaryTable secondaryTable : this.entity.getSecondaryTables()) {
secondaryTable.eAdapters().add(this.secondaryTableListener);
- }
- //this.addConnectionListener();
+ }
}
}
protected void disengageListeners() {
if (this.entity != null) {
- //this.removeConnectionListener();
for (ISecondaryTable secondaryTable : this.entity.getSecondaryTables()) {
secondaryTable.eAdapters().remove(this.secondaryTableListener);
}

Back to the top