Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2007-05-03 20:42:11 -0400
committerkmoore2007-05-03 20:42:11 -0400
commit38f339b6dbe8ee73e6bb841f929f74169aca19d8 (patch)
tree3636631398607a58f89cb82cab32593827113449 /jpa
parent8d5e63b6fcaf80a6ca754ff9d8e71bd3cf48b98c (diff)
downloadwebtools.dali-38f339b6dbe8ee73e6bb841f929f74169aca19d8.tar.gz
webtools.dali-38f339b6dbe8ee73e6bb841f929f74169aca19d8.tar.xz
webtools.dali-38f339b6dbe8ee73e6bb841f929f74169aca19d8.zip
collapsed DiscriminatorColumnComposite into InheritanceComposite to clean up the layout
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/DiscriminatorColumnComposite.java379
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java306
2 files changed, 297 insertions, 388 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/DiscriminatorColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/DiscriminatorColumnComposite.java
deleted file mode 100644
index 15be0b46de..0000000000
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/DiscriminatorColumnComposite.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2007 Oracle. All rights reserved. This
- * program and the accompanying materials are made available under the terms of
- * the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Oracle. - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.ui.internal.mappings.details;
-
-import 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.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jpt.core.internal.IJpaProject;
-import org.eclipse.jpt.core.internal.mappings.DiscriminatorType;
-import org.eclipse.jpt.core.internal.mappings.IDiscriminatorColumn;
-import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
-import org.eclipse.jpt.db.internal.Connection;
-import org.eclipse.jpt.db.internal.ConnectionListener;
-import org.eclipse.jpt.db.internal.ConnectionProfile;
-import org.eclipse.jpt.db.internal.Database;
-import org.eclipse.jpt.db.internal.Schema;
-import org.eclipse.jpt.db.internal.Table;
-import org.eclipse.jpt.ui.internal.IJpaHelpContextIds;
-import org.eclipse.jpt.ui.internal.details.BaseJpaComposite;
-import org.eclipse.jpt.ui.internal.mappings.JpaUiMappingsMessages;
-import org.eclipse.jpt.ui.internal.widgets.CComboViewer;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-
-//TODO repopulate this panel based on the Entity table changing
-public class DiscriminatorColumnComposite extends BaseJpaComposite
-{
-
- private IDiscriminatorColumn discriminatorColumn;
- private final Adapter discriminatorColumnListener;
- private ConnectionListener connectionListener;
-
- private CCombo columnCombo;
- private CComboViewer discriminatorTypeViewer;
-
- private ConnectionProfile connectionProfile;
-
-
-
- public DiscriminatorColumnComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
- super(parent, SWT.NULL, commandStack, widgetFactory);
- this.discriminatorColumnListener = buildDiscriminatorColumnListener();
- this.connectionListener = buildConnectionListener();
- }
-
- private Adapter buildDiscriminatorColumnListener() {
- return new AdapterImpl() {
- public void notifyChanged(Notification notification) {
- discriminatorColumnChanged(notification);
- }
- };
- }
-
- private ConnectionListener buildConnectionListener() {
- return new ConnectionListener() {
-
- public void aboutToClose(Connection connection) {
- // not interested to this event.
- }
-
- public void closed(Connection connection) {
- getControl().getDisplay().asyncExec( new Runnable() {
- public void run() {
- if (getControl().isDisposed()) {
- return;
- }
- DiscriminatorColumnComposite.this.populateColumnCombo();
- }
- });
- }
-
- public void modified(Connection connection) {
- getControl().getDisplay().asyncExec( new Runnable() {
- public void run() {
- if (getControl().isDisposed()) {
- return;
- }
- DiscriminatorColumnComposite.this.populateColumnCombo();
- }
- });
- }
-
- public boolean okToClose(Connection connection) {
- // not interested to this event.
- return true;
- }
-
- public void opened(Connection connection) {
- getControl().getDisplay().asyncExec( new Runnable() {
- public void run() {
- if (getControl().isDisposed()) {
- return;
- }
- DiscriminatorColumnComposite.this.populateColumnCombo();
- }
- });
- }
-
- public void databaseChanged(Connection connection, final Database database) {
- return;
- }
-
- public void schemaChanged(Connection connection, final Schema schema) {
- return;
- }
-
- public void tableChanged(Connection connection, final Table table) {
- getControl().getDisplay().asyncExec( new Runnable() {
- public void run() {
- if(table == getDbTable()) {
- if (!getControl().isDisposed()) {
- DiscriminatorColumnComposite.this.populateColumnCombo();
- }
- }
- }
- });
- }
- };
- }
-
- @Override
- protected void initializeLayout(Composite composite) {
- GridLayout layout = new GridLayout();
- layout.marginWidth = 0;
- layout.numColumns = 2;
- composite.setLayout(layout);
-
- getWidgetFactory().createLabel(composite, JpaUiMappingsMessages.DiscriminatorColumnComposite_column);
-
- this.columnCombo = buildColumnCombo(composite);
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.grabExcessHorizontalSpace = true;
- this.columnCombo.setLayoutData(gridData);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(this.columnCombo, IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN);
-
- getWidgetFactory().createLabel(composite, JpaUiMappingsMessages.DiscriminatorColumnComposite_discriminatorType);
-
- this.discriminatorTypeViewer = buildDiscriminatorTypeCombo(composite);
- gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.grabExcessHorizontalSpace = true;
- this.discriminatorTypeViewer.getCombo().setLayoutData(gridData);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(this.discriminatorTypeViewer.getCombo(), IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_TYPE);
- }
-
-
- private CCombo buildColumnCombo(Composite parent) {
- final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT);
- combo.add(JpaUiMappingsMessages.ColumnComposite_defaultEmpty);
- combo.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if (isPopulating()) {
- return;
- }
- String tableText = ((CCombo) e.getSource()).getText();
- if (tableText.equals("")) { //$NON-NLS-1$
- tableText = null;
- if (discriminatorColumn.getSpecifiedName() == null || discriminatorColumn.getSpecifiedName().equals("")) { //$NON-NLS-1$
- return;
- }
- }
-
- if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) {
- tableText = null;
- }
-
- if (discriminatorColumn.getSpecifiedName() == null && tableText != null) {
- discriminatorColumn.setSpecifiedName(tableText);
- }
- if (discriminatorColumn.getSpecifiedName() != null && !discriminatorColumn.getSpecifiedName().equals(tableText)) {
- discriminatorColumn.setSpecifiedName(tableText);
- }
- }
- });
- return combo;
-
- }
-
- private CComboViewer buildDiscriminatorTypeCombo(Composite parent) {
- CCombo combo = getWidgetFactory().createCCombo(parent);
- CComboViewer discriminatorTypeViewer = new CComboViewer(combo);
- discriminatorTypeViewer.add(DiscriminatorType.VALUES.toArray());
-
- discriminatorTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- DiscriminatorColumnComposite.this.discriminatorTypeSelectionChanged(event.getSelection());
- }
- });
-
- return discriminatorTypeViewer;
- }
-
- void discriminatorTypeSelectionChanged(ISelection selection) {
- if (selection instanceof IStructuredSelection) {
- DiscriminatorType discriminatorType = (DiscriminatorType) ((IStructuredSelection) selection).getFirstElement();
- if ( ! this.discriminatorColumn.getDiscriminatorType().equals(discriminatorType)) {
- this.discriminatorColumn.setDiscriminatorType(discriminatorType);
- }
- }
- }
-
- protected void discriminatorColumnChanged(Notification notification) {
- if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__SPECIFIED_NAME) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if (getControl().isDisposed()) {
- return;
- }
- populateColumnName();
- }
- });
- }
- else if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__DEFAULT_NAME) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if (getControl().isDisposed()) {
- return;
- }
- populateDefaultColumnName();
- }
- });
- }
-
- else if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__DISCRIMINATOR_TYPE) {
- final DiscriminatorType discriminatorType = (DiscriminatorType) notification.getNewValue();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- if (((StructuredSelection) discriminatorTypeViewer.getSelection()).getFirstElement() != discriminatorType) {
- discriminatorTypeViewer.setSelection(new StructuredSelection(discriminatorType));
- }
- }
- });
- }
- }
-
- @Override
- protected void engageListeners() {
- if (this.discriminatorColumn != null) {
- this.discriminatorColumn.eAdapters().add(this.discriminatorColumnListener);
- this.addConnectionListener();
- }
- }
-
- @Override
- protected void disengageListeners() {
- if (this.discriminatorColumn != null) {
- this.removeConnectionListener();
- this.discriminatorColumn.eAdapters().remove(this.discriminatorColumnListener);
- }
- }
-
- private ConnectionProfile getConnectionProfile() {
- if(this.connectionProfile == null) {
- IJpaProject jpaProject = this.discriminatorColumn.getJpaProject();
- this.connectionProfile = jpaProject.connectionProfile();
- }
- return this.connectionProfile;
- }
-
- private void addConnectionListener() {
- this.getConnectionProfile().addConnectionListener(this.connectionListener);
- }
-
- private void removeConnectionListener() {
- this.getConnectionProfile().removeConnectionListener(this.connectionListener);
- }
-
- private Table getDbTable() {
- return this.discriminatorColumn.dbTable();
- }
-
- private void populateColumnCombo() {
- //TODO don't do instanceof check here - check on Table, or isRoot check on Entity
- //this.tableCombo.setEnabled(!(this.table instanceof SingleTableInheritanceChildTableImpl));
- populateDefaultColumnName();
-
- if (this.getConnectionProfile().isConnected()) {
- this.columnCombo.remove(1, this.columnCombo.getItemCount()-1);
- Table table = getDbTable();
- if (table != null) {
- for (Iterator i = CollectionTools.sort(CollectionTools.list(table.columnNames())).iterator(); i.hasNext();) {
- this.columnCombo.add((String) i.next());
- }
- }
- }
- else {
- this.columnCombo.remove(1, this.columnCombo.getItemCount()-1);
- }
- populateColumnName();
- }
-
- protected void populateDefaultColumnName() {
- String defaultTableName = discriminatorColumn.getDefaultName();
- int selectionIndex = columnCombo.getSelectionIndex();
- columnCombo.setItem(0, NLS.bind(JpaUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName));
- if (selectionIndex == 0) {
- //combo text does not update when switching between 2 mappings of the same type
- //that both have a default column name. clear the selection and then set it again
- columnCombo.clearSelection();
- columnCombo.select(0);
- }
- }
-
- protected void populateColumnName() {
- String tableName = this.discriminatorColumn.getSpecifiedName();
- String defaultName = this.discriminatorColumn.getDefaultName();
- if (tableName != null) {
- if (!this.columnCombo.getText().equals(tableName)) {
- this.columnCombo.setText(tableName);
- }
- }
- else {
- if (!this.columnCombo.getText().equals(NLS.bind(JpaUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultName))) {
- this.columnCombo.select(0);
- }
- }
- }
- public void doPopulate(EObject obj) {
- this.discriminatorColumn = (IDiscriminatorColumn) obj;
- if (this.discriminatorColumn != null) {
- populateColumnCombo();
- popuplateDiscriminatorTypeComboViewer();
- }
- }
-
- public void doPopulate() {
- if (this.discriminatorColumn != null) {
- populateColumnCombo();
- }
- }
-
- private void popuplateDiscriminatorTypeComboViewer() {
- if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.DEFAULT) {
- if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.DEFAULT) {
- this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.DEFAULT));
- }
- }
- else if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.CHAR) {
- if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.CHAR) {
- this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.CHAR));
- }
- }
- else if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.INTEGER) {
- if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.INTEGER) {
- this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.INTEGER));
- }
- }
- else {
- if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.STRING) {
- this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.STRING));
- }
- }
- }
-}
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java
index c5757ea89c..6bc0b7424b 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/InheritanceComposite.java
@@ -9,6 +9,7 @@
******************************************************************************/
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;
@@ -19,13 +20,23 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jpt.core.internal.IJpaProject;
+import org.eclipse.jpt.core.internal.mappings.DiscriminatorType;
+import org.eclipse.jpt.core.internal.mappings.IDiscriminatorColumn;
import org.eclipse.jpt.core.internal.mappings.IEntity;
import org.eclipse.jpt.core.internal.mappings.InheritanceType;
import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage;
+import org.eclipse.jpt.db.internal.Connection;
+import org.eclipse.jpt.db.internal.ConnectionListener;
+import org.eclipse.jpt.db.internal.ConnectionProfile;
+import org.eclipse.jpt.db.internal.Database;
+import org.eclipse.jpt.db.internal.Schema;
+import org.eclipse.jpt.db.internal.Table;
import org.eclipse.jpt.ui.internal.IJpaHelpContextIds;
import org.eclipse.jpt.ui.internal.details.BaseJpaComposite;
import org.eclipse.jpt.ui.internal.mappings.JpaUiMappingsMessages;
import org.eclipse.jpt.ui.internal.widgets.CComboViewer;
+import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
@@ -41,19 +52,29 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
public class InheritanceComposite extends BaseJpaComposite {
private IEntity entity;
+ private IDiscriminatorColumn discriminatorColumn;
private final Adapter entityListener;
+ private final Adapter discriminatorColumnListener;
private CComboViewer strategyViewer;
- private DiscriminatorColumnComposite discriminatorColumnComposite;
+ private CCombo columnCombo;
+ private CComboViewer discriminatorTypeViewer;
private CCombo discriminatorValueCombo;
+ private ConnectionListener connectionListener;
+
+ private ConnectionProfile connectionProfile;
+
+
private PrimaryKeyJoinColumnsComposite pkJoinColumnsComposite;
public InheritanceComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) {
super(parent, SWT.NULL, commandStack, widgetFactory);
this.entityListener = buildEntityListener();
+ this.discriminatorColumnListener = buildDiscriminatorColumnListener();
+ this.connectionListener = buildConnectionListener();
}
-
+
private Adapter buildEntityListener() {
return new AdapterImpl() {
public void notifyChanged(Notification notification) {
@@ -61,7 +82,81 @@ public class InheritanceComposite extends BaseJpaComposite {
}
};
}
+
+ private Adapter buildDiscriminatorColumnListener() {
+ return new AdapterImpl() {
+ public void notifyChanged(Notification notification) {
+ discriminatorColumnChanged(notification);
+ }
+ };
+ }
+ private ConnectionListener buildConnectionListener() {
+ return new ConnectionListener() {
+
+ public void aboutToClose(Connection connection) {
+ // not interested to this event.
+ }
+
+ public void closed(Connection connection) {
+ getControl().getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ InheritanceComposite.this.populateColumnCombo();
+ }
+ });
+ }
+
+ public void modified(Connection connection) {
+ getControl().getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ InheritanceComposite.this.populateColumnCombo();
+ }
+ });
+ }
+
+ public boolean okToClose(Connection connection) {
+ // not interested to this event.
+ return true;
+ }
+
+ public void opened(Connection connection) {
+ getControl().getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ InheritanceComposite.this.populateColumnCombo();
+ }
+ });
+ }
+
+ public void databaseChanged(Connection connection, final Database database) {
+ return;
+ }
+
+ public void schemaChanged(Connection connection, final Schema schema) {
+ return;
+ }
+
+ public void tableChanged(Connection connection, final Table table) {
+ getControl().getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if(table == getDbTable()) {
+ if (!getControl().isDisposed()) {
+ InheritanceComposite.this.populateColumnCombo();
+ }
+ }
+ }
+ });
+ }
+ };
+ }
@Override
protected void initializeLayout(Composite composite) {
@@ -80,12 +175,22 @@ public class InheritanceComposite extends BaseJpaComposite {
this.strategyViewer.getCombo().setLayoutData(gridData);
PlatformUI.getWorkbench().getHelpSystem().setHelp(this.strategyViewer.getCombo(), IJpaHelpContextIds.ENTITY_INHERITANCE_STRATEGY);
- this.discriminatorColumnComposite = new DiscriminatorColumnComposite(composite, this.commandStack, getWidgetFactory());
+ getWidgetFactory().createLabel(composite, JpaUiMappingsMessages.DiscriminatorColumnComposite_column);
+
+ this.columnCombo = buildColumnCombo(composite);
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ this.columnCombo.setLayoutData(gridData);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this.columnCombo, IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN);
+
+ getWidgetFactory().createLabel(composite, JpaUiMappingsMessages.DiscriminatorColumnComposite_discriminatorType);
+
+ this.discriminatorTypeViewer = buildDiscriminatorTypeCombo(composite);
gridData = new GridData();
- gridData.horizontalSpan = 2;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
- this.discriminatorColumnComposite.getControl().setLayoutData(gridData);
+ this.discriminatorTypeViewer.getCombo().setLayoutData(gridData);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this.discriminatorTypeViewer.getCombo(), IJpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_TYPE);
getWidgetFactory().createLabel(composite, JpaUiMappingsMessages.InheritanceComposite_discriminatorValue);
@@ -130,6 +235,60 @@ public class InheritanceComposite extends BaseJpaComposite {
}
}
+ private CCombo buildColumnCombo(Composite parent) {
+ final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT);
+ combo.add(JpaUiMappingsMessages.ColumnComposite_defaultEmpty);
+ combo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (isPopulating()) {
+ return;
+ }
+ String tableText = ((CCombo) e.getSource()).getText();
+ if (tableText.equals("")) { //$NON-NLS-1$
+ tableText = null;
+ if (discriminatorColumn.getSpecifiedName() == null || discriminatorColumn.getSpecifiedName().equals("")) { //$NON-NLS-1$
+ return;
+ }
+ }
+
+ if (tableText != null && combo.getItemCount() > 0 && tableText.equals(combo.getItem(0))) {
+ tableText = null;
+ }
+
+ if (discriminatorColumn.getSpecifiedName() == null && tableText != null) {
+ discriminatorColumn.setSpecifiedName(tableText);
+ }
+ if (discriminatorColumn.getSpecifiedName() != null && !discriminatorColumn.getSpecifiedName().equals(tableText)) {
+ discriminatorColumn.setSpecifiedName(tableText);
+ }
+ }
+ });
+ return combo;
+
+ }
+
+ private CComboViewer buildDiscriminatorTypeCombo(Composite parent) {
+ CCombo combo = getWidgetFactory().createCCombo(parent);
+ CComboViewer discriminatorTypeViewer = new CComboViewer(combo);
+ discriminatorTypeViewer.add(DiscriminatorType.VALUES.toArray());
+
+ discriminatorTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ InheritanceComposite.this.discriminatorTypeSelectionChanged(event.getSelection());
+ }
+ });
+
+ return discriminatorTypeViewer;
+ }
+
+ void discriminatorTypeSelectionChanged(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ DiscriminatorType discriminatorType = (DiscriminatorType) ((IStructuredSelection) selection).getFirstElement();
+ if ( ! this.discriminatorColumn.getDiscriminatorType().equals(discriminatorType)) {
+ this.discriminatorColumn.setDiscriminatorType(discriminatorType);
+ }
+ }
+ }
private CCombo buildDiscriminatorValueCombo(Composite parent) {
final CCombo combo = getWidgetFactory().createCCombo(parent, SWT.FLAT);
@@ -162,19 +321,21 @@ public class InheritanceComposite extends BaseJpaComposite {
public void doPopulate(EObject obj) {
this.entity = (IEntity) obj;
if (this.entity != null) {
- this.discriminatorColumnComposite.populate(this.entity.getDiscriminatorColumn());
+ this.discriminatorColumn = this.entity.getDiscriminatorColumn();
+ populateColumnCombo();
+ popuplateDiscriminatorTypeComboViewer();
populateStrategyComboViewer();
populateDiscriminatorValueCombo();
this.pkJoinColumnsComposite.populate(this.entity);
}
else {
- this.discriminatorColumnComposite.populate(null);
+ this.discriminatorColumn = null;
}
}
public void doPopulate() {
if (this.entity != null) {
- this.discriminatorColumnComposite.populate();
+ populateColumnCombo();
// popuplateStrategyComboViewer();
// popuplateDiscriminatorValueCombo();
}
@@ -184,6 +345,8 @@ public class InheritanceComposite extends BaseJpaComposite {
protected void engageListeners() {
if (this.entity != null) {
this.entity.eAdapters().add(this.entityListener);
+ this.discriminatorColumn.eAdapters().add(this.discriminatorColumnListener);
+ this.addConnectionListener();
}
}
@@ -191,9 +354,101 @@ public class InheritanceComposite extends BaseJpaComposite {
protected void disengageListeners() {
if (this.entity != null) {
this.entity.eAdapters().remove(this.entityListener);
+ this.removeConnectionListener();
+ this.discriminatorColumn.eAdapters().remove(this.discriminatorColumnListener);
+ }
+ }
+
+ private ConnectionProfile getConnectionProfile() {
+ if(this.connectionProfile == null) {
+ IJpaProject jpaProject = this.entity.getJpaProject();
+ this.connectionProfile = jpaProject.connectionProfile();
+ }
+ return this.connectionProfile;
+ }
+
+ private void addConnectionListener() {
+ this.getConnectionProfile().addConnectionListener(this.connectionListener);
+ }
+
+ private void removeConnectionListener() {
+ this.getConnectionProfile().removeConnectionListener(this.connectionListener);
+ }
+
+ private Table getDbTable() {
+ return this.discriminatorColumn.dbTable();
+ }
+
+ private void populateColumnCombo() {
+ //TODO don't do instanceof check here - check on Table, or isRoot check on Entity
+ //this.tableCombo.setEnabled(!(this.table instanceof SingleTableInheritanceChildTableImpl));
+ populateDefaultColumnName();
+
+ if (this.getConnectionProfile().isConnected()) {
+ this.columnCombo.remove(1, this.columnCombo.getItemCount()-1);
+ Table table = getDbTable();
+ if (table != null) {
+ for (Iterator i = CollectionTools.sort(CollectionTools.list(table.columnNames())).iterator(); i.hasNext();) {
+ this.columnCombo.add((String) i.next());
+ }
+ }
+ }
+ else {
+ this.columnCombo.remove(1, this.columnCombo.getItemCount()-1);
+ }
+ populateColumnName();
+ }
+
+ protected void populateDefaultColumnName() {
+ String defaultTableName = discriminatorColumn.getDefaultName();
+ int selectionIndex = columnCombo.getSelectionIndex();
+ columnCombo.setItem(0, NLS.bind(JpaUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultTableName));
+ if (selectionIndex == 0) {
+ //combo text does not update when switching between 2 mappings of the same type
+ //that both have a default column name. clear the selection and then set it again
+ columnCombo.clearSelection();
+ columnCombo.select(0);
+ }
+ }
+
+ protected void populateColumnName() {
+ String tableName = this.discriminatorColumn.getSpecifiedName();
+ String defaultName = this.discriminatorColumn.getDefaultName();
+ if (tableName != null) {
+ if (!this.columnCombo.getText().equals(tableName)) {
+ this.columnCombo.setText(tableName);
+ }
+ }
+ else {
+ if (!this.columnCombo.getText().equals(NLS.bind(JpaUiMappingsMessages.ColumnComposite_defaultWithOneParam, defaultName))) {
+ this.columnCombo.select(0);
+ }
}
}
+ private void popuplateDiscriminatorTypeComboViewer() {
+ if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.DEFAULT) {
+ if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.DEFAULT) {
+ this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.DEFAULT));
+ }
+ }
+ else if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.CHAR) {
+ if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.CHAR) {
+ this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.CHAR));
+ }
+ }
+ else if (this.discriminatorColumn.getDiscriminatorType() == DiscriminatorType.INTEGER) {
+ if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.INTEGER) {
+ this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.INTEGER));
+ }
+ }
+ else {
+ if (((StructuredSelection) this.discriminatorTypeViewer.getSelection()).getFirstElement() != DiscriminatorType.STRING) {
+ this.discriminatorTypeViewer.setSelection(new StructuredSelection(DiscriminatorType.STRING));
+ }
+ }
+ }
+
private void populateStrategyComboViewer() {
if (this.entity.getInheritanceStrategy() == InheritanceType.DEFAULT) {
if (((StructuredSelection) this.strategyViewer.getSelection()).getFirstElement() != InheritanceType.DEFAULT) {
@@ -288,8 +543,41 @@ public class InheritanceComposite extends BaseJpaComposite {
}
}
+ protected void discriminatorColumnChanged(Notification notification) {
+ if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__SPECIFIED_NAME) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ populateColumnName();
+ }
+ });
+ }
+ else if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__DEFAULT_NAME) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (getControl().isDisposed()) {
+ return;
+ }
+ populateDefaultColumnName();
+ }
+ });
+ }
+
+ else if (notification.getFeatureID(IDiscriminatorColumn.class) == JpaCoreMappingsPackage.IDISCRIMINATOR_COLUMN__DISCRIMINATOR_TYPE) {
+ final DiscriminatorType discriminatorType = (DiscriminatorType) notification.getNewValue();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (((StructuredSelection) discriminatorTypeViewer.getSelection()).getFirstElement() != discriminatorType) {
+ discriminatorTypeViewer.setSelection(new StructuredSelection(discriminatorType));
+ }
+ }
+ });
+ }
+ }
+
public void dispose() {
- this.discriminatorColumnComposite.dispose();
this.pkJoinColumnsComposite.dispose();
super.dispose();
}

Back to the top