diff options
author | kmoore | 2007-05-06 23:05:52 +0000 |
---|---|---|
committer | kmoore | 2007-05-06 23:05:52 +0000 |
commit | f4bf44aa6b97ba82134ba386482bdccefe836e86 (patch) | |
tree | 6a0f6226d8b7ada6f5a4030e136fff0e32cc77fb /jpa/plugins/org.eclipse.jpt.ui/src | |
parent | 765d3acc77568028486da87b942a21f741496d00 (diff) | |
download | webtools.dali-f4bf44aa6b97ba82134ba386482bdccefe836e86.tar.gz webtools.dali-f4bf44aa6b97ba82134ba386482bdccefe836e86.tar.xz webtools.dali-f4bf44aa6b97ba82134ba386482bdccefe836e86.zip |
142011 - editing of secondary tables
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src')
7 files changed, 616 insertions, 12 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JpaUiMappingsMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JpaUiMappingsMessages.java index 6d9b5589c6..c7a5f67575 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JpaUiMappingsMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JpaUiMappingsMessages.java @@ -170,6 +170,18 @@ public class JpaUiMappingsMessages extends NLS public static String OrderByComposite_customOrdering; public static String OrderByComposite_orderByLabel; + public static String SecondaryTablesComposite_secondaryTables; + public static String SecondaryTablesComposite_add; + public static String SecondaryTablesComposite_edit; + public static String SecondaryTablesComposite_remove; + + public static String SecondaryTableDialog_editSecondaryTable; + public static String SecondaryTableDialog_name; + public static String SecondaryTableDialog_catalog; + public static String SecondaryTableDialog_schema; + public static String SecondaryTableDialog_defaultSchema; + public static String SecondaryTableDialog_defaultCatalog; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, JpaUiMappingsMessages.class); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java index 2749946601..02aab134bc 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/CatalogCombo.java @@ -220,9 +220,9 @@ public class CatalogCombo extends BaseJpaController Database database = this.getDatabase(); if ( database != null) { - Iterator catalogs = database.catalogNames(); - for ( Iterator stream = CollectionTools.sort( catalogs); stream.hasNext(); ) { - this.combo.add(( String) stream.next()); + Iterator<String> catalogs = database.catalogNames(); + for ( Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext(); ) { + this.combo.add(stream.next()); } } } 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 4600b99d5a..83bf5c6779 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 @@ -38,6 +38,7 @@ public class EntityComposite extends BaseJpaComposite private TableComposite tableComposite; private InheritanceComposite inheritanceComposite; + private SecondaryTablesComposite secondaryTablesComposite; private OverridesComposite attributeOverridesComposite; public EntityComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { @@ -62,6 +63,11 @@ public class EntityComposite extends BaseJpaComposite gridData.grabExcessHorizontalSpace = true; attributeOverridesControl.setLayoutData(gridData); + Control secondaryTablesControl = buildSecondaryTablesComposite(composite); + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + secondaryTablesControl.setLayoutData(gridData); Control inheritanceControl = buildInheritanceComposite(composite); gridData = new GridData(); @@ -99,6 +105,28 @@ public class EntityComposite extends BaseJpaComposite return generalComposite; } + private Control buildSecondaryTablesComposite(Composite composite) { + Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); + section.setText(JpaUiMappingsMessages.SecondaryTablesComposite_secondaryTables); + + Composite client = getWidgetFactory().createComposite(section); + section.setClient(client); + + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + client.setLayout(layout); + + this.secondaryTablesComposite = new SecondaryTablesComposite(client, this.commandStack, getWidgetFactory()); + GridData gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + this.secondaryTablesComposite.getControl().setLayoutData(gridData); + + return section; + } + private Control buildInheritanceComposite(Composite composite) { Section section = getWidgetFactory().createSection(composite, SWT.FLAT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); section.setText(JpaUiMappingsMessages.EntityComposite_inheritance); @@ -149,6 +177,7 @@ public class EntityComposite extends BaseJpaComposite this.entity = (IEntity) obj; this.entityNameCombo.populate(obj); this.attributeOverridesComposite.populate(obj); + this.secondaryTablesComposite.populate(obj); this.inheritanceComposite.populate(obj); if (this.entity != null) { this.tableComposite.populate(this.entity.getTable()); @@ -162,6 +191,7 @@ public class EntityComposite extends BaseJpaComposite this.entityNameCombo.populate(); this.tableComposite.populate(); this.attributeOverridesComposite.populate(); + this.secondaryTablesComposite.populate(); this.inheritanceComposite.populate(); } @@ -176,6 +206,7 @@ public class EntityComposite extends BaseJpaComposite this.entityNameCombo.dispose(); this.tableComposite.dispose(); this.attributeOverridesComposite.dispose(); + this.secondaryTablesComposite.dispose(); this.inheritanceComposite.dispose(); super.dispose(); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java index bbb7215f58..af151f8555 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java @@ -370,6 +370,9 @@ public class PrimaryKeyJoinColumnsComposite extends BaseJpaComposite } Display.getDefault().asyncExec(new Runnable() { public void run() { + if (getControl().isDisposed()) { + return; + } pkJoinColumnsListViewer.refresh(); overrideDefaultJoinColumnsCheckBox.setSelection(entity.containsSpecifiedPrimaryKeyJoinColumns()); updatePrimaryKeyJoinColumnsEnablement(); @@ -393,10 +396,4 @@ public class PrimaryKeyJoinColumnsComposite extends BaseJpaComposite }); } } - - - public void dispose() { - disengageListeners(); - super.dispose(); - } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java index 13aa332ce6..312d344f05 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SchemaCombo.java @@ -243,9 +243,9 @@ public class SchemaCombo extends BaseJpaController Database database = this.getDatabase(); if ( database != null) { - Iterator schemata = database.schemaNames(); - for ( Iterator stream = CollectionTools.sort( schemata); stream.hasNext(); ) { - this.combo.add(( String) stream.next()); + Iterator<String> schemata = database.schemaNames(); + for ( Iterator<String> stream = CollectionTools.sort( schemata); stream.hasNext(); ) { + this.combo.add(stream.next()); } } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java new file mode 100644 index 0000000000..2349a93003 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTableDialog.java @@ -0,0 +1,234 @@ +/******************************************************************************* + * 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.jface.dialogs.Dialog; +import org.eclipse.jpt.core.internal.IJpaProject; +import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; +import org.eclipse.jpt.db.internal.ConnectionProfile; +import org.eclipse.jpt.db.internal.Database; +import org.eclipse.jpt.ui.internal.mappings.JpaUiMappingsMessages; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +public class SecondaryTableDialog extends Dialog { + + //if creating a new JoinColumn, this will be null, + //specify the JoinColumnOwner instead in the appropriate construtor + private ISecondaryTable secondaryTable; + private IEntity entity; + + protected Combo nameCombo; + protected Combo catalogCombo; + protected Combo schemaCombo; + + private String selectedName; + private String selectedSchema; + private String selectedCatalog; + + private boolean defaultSchemaSelected; + private boolean defaultCatalogSelected; + + SecondaryTableDialog(Shell parent, IEntity entity) { + super(parent); + this.entity = entity; + } + + SecondaryTableDialog(Shell parent, ISecondaryTable secondaryTable, IEntity entity) { + super(parent); + this.secondaryTable = secondaryTable; + this.entity = entity; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(getTitle()); + } + + protected String getTitle() { + return JpaUiMappingsMessages.SecondaryTableDialog_editSecondaryTable; + } + + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + GridLayout gridLayout = (GridLayout) composite.getLayout(); + gridLayout.numColumns = 2; + + Label nameLabel = new Label(composite, SWT.LEFT); + nameLabel.setText(JpaUiMappingsMessages.SecondaryTableDialog_name); + GridData gridData = new GridData(); + nameLabel.setLayoutData(gridData); + + this.nameCombo = new Combo(composite, SWT.LEFT); + gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalAlignment = SWT.FILL; + this.nameCombo.setLayoutData(gridData); + populateNameCombo(); + + Label catalogLabel = new Label(composite, SWT.LEFT); + catalogLabel.setText(JpaUiMappingsMessages.SecondaryTableDialog_catalog); + gridData = new GridData(); + catalogLabel.setLayoutData(gridData); + + this.catalogCombo = new Combo(composite, SWT.LEFT); + gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalAlignment = SWT.FILL; + this.catalogCombo.setLayoutData(gridData); + populateCatalogCombo(); + + Label schemaLabel = new Label(composite, SWT.LEFT); + schemaLabel.setText(JpaUiMappingsMessages.SecondaryTableDialog_schema); + gridData = new GridData(); + schemaLabel.setLayoutData(gridData); + + this.schemaCombo = new Combo(composite, SWT.LEFT); + gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + gridData.horizontalAlignment = SWT.FILL; + this.schemaCombo.setLayoutData(gridData); + populateSchemaCombo(); + + return composite; + } + + protected Database getDatabase() { + return this.getConnectionProfile().getDatabase(); + } + + private ConnectionProfile getConnectionProfile() { + IJpaProject project = (this.secondaryTable == null) ? this.entity.getJpaProject() : this.secondaryTable.getJpaProject(); + return project.connectionProfile(); + } + + protected void populateNameCombo() { + //TODO populate with the tables from the secondaryTable's schema +// Table table = getNameTable(); +// if (table != null) { +// for (Iterator i = table.columnNames(); i.hasNext(); ) { +// this.nameCombo.add((String) i.next()); +// } +// } + if (getSecondaryTable() != null) { + if (getSecondaryTable().getSpecifiedName() != null) { + this.nameCombo.setText(getSecondaryTable().getSpecifiedName()); + } + } + } + + protected void populateSchemaCombo() { + if (getSecondaryTable() != null) { + this.schemaCombo.add(NLS.bind(JpaUiMappingsMessages.SecondaryTableDialog_defaultSchema, getSecondaryTable().getDefaultSchema())); + } + + Database database = this.getDatabase(); + + if (database != null) { + Iterator<String> schemata = database.schemaNames(); + for (Iterator<String> stream = CollectionTools.sort(schemata); stream.hasNext(); ) { + this.schemaCombo.add(stream.next()); + } + } + + if (getSecondaryTable() != null) { + if (getSecondaryTable().getSpecifiedSchema() != null) { + this.schemaCombo.setText(getSecondaryTable().getSpecifiedSchema()); + } + else { + this.schemaCombo.select(0); + } + } + } + + protected void populateCatalogCombo() { + if (getSecondaryTable() != null) { + this.catalogCombo.add(NLS.bind(JpaUiMappingsMessages.SecondaryTableDialog_defaultCatalog, getSecondaryTable().getDefaultCatalog())); + } + Database database = this.getDatabase(); + + if (database != null) { + Iterator<String> catalogs = database.catalogNames(); + for (Iterator<String> stream = CollectionTools.sort(catalogs); stream.hasNext(); ) { + this.catalogCombo.add(stream.next()); + } + } + + if (getSecondaryTable() != null) { + if (getSecondaryTable().getSpecifiedCatalog() != null) { + this.catalogCombo.setText(getSecondaryTable().getSpecifiedCatalog()); + } + else { + this.catalogCombo.select(0); + } + } + } + + protected Combo getNameCombo() { + return this.nameCombo; + } + + protected Combo getSchemaCombo() { + return this.schemaCombo; + } + + protected Combo getCatalogCombo() { + return this.catalogCombo; + } + + protected ISecondaryTable getSecondaryTable() { + return this.secondaryTable; + } + + + protected String getSelectedName() { + return this.selectedName; + } + + protected String getSelectedCatalog() { + return this.selectedCatalog; + } + + protected String getSelectedSchema() { + return this.selectedSchema; + } + + protected boolean isDefaultSchemaSelected() { + return this.defaultSchemaSelected; + } + + protected boolean isDefaultCatalogSelected() { + return this.defaultCatalogSelected; + } + + public boolean close() { + this.selectedName = this.nameCombo.getText(); + this.selectedSchema = this.schemaCombo.getText(); + if (this.selectedSchema.equals("")) { + this.selectedSchema = null; + } + this.selectedCatalog = this.catalogCombo.getText(); + if (this.selectedCatalog.equals("")) { + this.selectedCatalog = null; + } + this.defaultSchemaSelected = this.schemaCombo.getSelectionIndex() == 0; + this.defaultCatalogSelected = this.catalogCombo.getSelectionIndex() == 0; + return super.close(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java new file mode 100644 index 0000000000..9037e2c68d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SecondaryTablesComposite.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * 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.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.IEntity; +import org.eclipse.jpt.core.internal.mappings.ISecondaryTable; +import org.eclipse.jpt.core.internal.mappings.ITable; +import org.eclipse.jpt.core.internal.mappings.JpaCoreMappingsPackage; +import org.eclipse.jpt.ui.internal.details.BaseJpaComposite; +import org.eclipse.jpt.ui.internal.mappings.JpaUiMappingsMessages; +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.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; + +//TODO need to support a list of tables +public class SecondaryTablesComposite extends BaseJpaComposite +{ + private IEntity entity; + private final Adapter entityListener; + private final Adapter secondaryTableListener; + + ListViewer secondaryTablesListViewer; + + private Button addButton; + private Button editButton; + private Button removeButton; + + + public SecondaryTablesComposite(Composite parent, CommandStack commandStack, TabbedPropertySheetWidgetFactory widgetFactory) { + super(parent, SWT.NULL, commandStack, widgetFactory); + this.entityListener = buildEntityListener(); + this.secondaryTableListener = buildSecondaryTableListener(); + } + + private Adapter buildEntityListener() { + return new AdapterImpl() { + public void notifyChanged(Notification notification) { + entityChanged(notification); + } + }; + } + + private Adapter buildSecondaryTableListener() { + return new AdapterImpl() { + public void notifyChanged(Notification notification) { + seoncaryTableChanged(notification); + } + }; + } + + @Override + protected void initializeLayout(Composite composite) { + GridLayout layout = new GridLayout(2, false); + layout.marginWidth = 0; + composite.setLayout(layout); + + GridData gridData = new GridData(); + + this.secondaryTablesListViewer = new ListViewer(composite, SWT.BORDER | SWT.MULTI); + this.secondaryTablesListViewer.setContentProvider(buildSecondaryTablesListContentProvider()); + this.secondaryTablesListViewer.setLabelProvider(buildSecondaryTablesListLabelProvider()); + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.verticalSpan = 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); + this.addButton.setText(JpaUiMappingsMessages.SecondaryTablesComposite_add); + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + this.addButton.setLayoutData(gridData); + this.addButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + + public void widgetSelected(SelectionEvent e) { + addSecondaryTable(); + } + }); + + this.editButton = new Button(composite, SWT.NONE); + this.editButton.setText(JpaUiMappingsMessages.SecondaryTablesComposite_edit); + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + this.editButton.setLayoutData(gridData); + this.editButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + + public void widgetSelected(SelectionEvent e) { + editSecondaryTable(); + } + }); + + this.removeButton = new Button(composite, SWT.NONE); + this.removeButton.setText(JpaUiMappingsMessages.SecondaryTablesComposite_remove); + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.BEGINNING; + this.removeButton.setLayoutData(gridData); + this.removeButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + // do nothing + } + + public void widgetSelected(SelectionEvent e) { + removeSecondaryTable(); + } + }); + + this.secondaryTablesListViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateEnablement(); + } + }); + } + + private IContentProvider buildSecondaryTablesListContentProvider() { + 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 ((IEntity) inputElement).getSecondaryTables().toArray(); + } + }; + } + + private ILabelProvider buildSecondaryTablesListLabelProvider() { + return new LabelProvider() { + public String getText(Object element) { + //TODO display a qualified name instead + ISecondaryTable secondaryTable = (ISecondaryTable) element; + return secondaryTable.getName(); + } + }; + } + + void addSecondaryTable() { + SecondaryTableDialog dialog = new SecondaryTableDialog(this.getControl().getShell(), this.entity); + addSecondaryTableFromDialog(dialog); + } + + private void addSecondaryTableFromDialog(SecondaryTableDialog dialog) { + if (dialog.open() == Window.OK) { + int index = this.entity.getSpecifiedSecondaryTables().size(); + String name = dialog.getSelectedName(); + String catalog = dialog.getSelectedCatalog(); + String schema = dialog.getSelectedSchema(); + ISecondaryTable secondaryTable = this.entity.createSecondaryTable(index); + this.entity.getSpecifiedSecondaryTables().add(secondaryTable); + secondaryTable.setSpecifiedName(name); + secondaryTable.setSpecifiedCatalog(catalog); + secondaryTable.setSpecifiedSchema(schema); + } + } + + void editSecondaryTable() { + ISecondaryTable secondaryTable = getSelectedSecondaryTable(); + SecondaryTableDialog dialog = new SecondaryTableDialog(this.getControl().getShell(), secondaryTable, this.entity); + editSecondaryTableFromDialog(dialog, secondaryTable); + } + + private void editSecondaryTableFromDialog(SecondaryTableDialog dialog, ISecondaryTable secondaryTable) { + if (dialog.open() == Window.OK) { + editSecondaryTableDialogOkd(dialog, secondaryTable); + } + } + + private void editSecondaryTableDialogOkd(SecondaryTableDialog dialog, ISecondaryTable secondaryTable) { + String name = dialog.getSelectedName(); + String catalog = dialog.getSelectedCatalog(); + String schema = dialog.getSelectedSchema(); + + if (secondaryTable.getSpecifiedName() == null || !secondaryTable.getSpecifiedName().equals(name)){ + secondaryTable.setSpecifiedName(name); + } + + if (dialog.isDefaultCatalogSelected()) { + if (secondaryTable.getSpecifiedCatalog() != null) { + secondaryTable.setSpecifiedCatalog(null); + } + } + else if (secondaryTable.getSpecifiedCatalog() == null || !secondaryTable.getSpecifiedCatalog().equals(catalog)){ + secondaryTable.setSpecifiedCatalog(catalog); + } + + if (dialog.isDefaultSchemaSelected()) { + if (secondaryTable.getSpecifiedSchema() != null) { + secondaryTable.setSpecifiedSchema(null); + } + } + else if (secondaryTable.getSpecifiedSchema() == null || !secondaryTable.getSpecifiedSchema().equals(schema)){ + secondaryTable.setSpecifiedSchema(schema); + } + } + + private ISecondaryTable getSelectedSecondaryTable() { + return (ISecondaryTable) ((StructuredSelection) this.secondaryTablesListViewer.getSelection()).getFirstElement(); + } + + + void removeSecondaryTable() { + ISelection selection = this.secondaryTablesListViewer.getSelection(); + if (selection instanceof StructuredSelection) { + for (Iterator<ISecondaryTable> i = ((StructuredSelection) selection).iterator(); i.hasNext(); ) { + this.entity.getSecondaryTables().remove(i.next()); + } + } + } + + void updateEnablement() { + this.editButton.setEnabled(!((StructuredSelection) this.secondaryTablesListViewer.getSelection()).isEmpty()); + this.removeButton.setEnabled(!((StructuredSelection) this.secondaryTablesListViewer.getSelection()).isEmpty()); + } + + public void doPopulate(EObject obj) { + this.entity = (IEntity) obj; + if (this.entity == null) { + this.secondaryTablesListViewer.setInput(null); + return; + } + + this.secondaryTablesListViewer.setInput(this.entity); + + updateEnablement(); + } + + @Override + protected void doPopulate() { + } + + protected void engageListeners() { + if (this.entity != null) { + 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); + } + this.entity.eAdapters().remove(this.entityListener); + } + } + + protected void entityChanged(Notification notification) { + if (notification.getFeatureID(IEntity.class) == JpaCoreMappingsPackage.IENTITY__SPECIFIED_SECONDARY_TABLES) { + if (notification.getEventType() == Notification.ADD) { + ((ISecondaryTable) notification.getNewValue()).eAdapters().add(this.secondaryTableListener); + } + else if (notification.getEventType() == Notification.REMOVE) { + ((ISecondaryTable) notification.getOldValue()).eAdapters().remove(this.secondaryTableListener); + } + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (getControl().isDisposed()) { + return; + } + secondaryTablesListViewer.refresh(); + updateEnablement(); + } + }); + } + } + + protected void seoncaryTableChanged(Notification notification) { + if (notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_NAME + || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_CATALOG + || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__SPECIFIED_SCHEMA + || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_CATALOG + || notification.getFeatureID(ITable.class) == JpaCoreMappingsPackage.ITABLE__DEFAULT_SCHEMA) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + if (getControl().isDisposed()) { + return; + } + secondaryTablesListViewer.refresh(); + } + }); + } + } +} |