diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java')
-rw-r--r-- | jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java new file mode 100644 index 0000000000..e4fae53f25 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnInAssociationOverrideDialog.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * 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.jface.viewers.ComboViewer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jpt.core.internal.IAttributeMapping; +import org.eclipse.jpt.core.internal.mappings.DefaultTrueBoolean; +import org.eclipse.jpt.core.internal.mappings.IAssociationOverride; +import org.eclipse.jpt.core.internal.mappings.IEntity; +import org.eclipse.jpt.core.internal.mappings.IJoinColumn; +import org.eclipse.jpt.core.internal.mappings.ISingleRelationshipMapping; +import org.eclipse.jpt.db.internal.Table; +import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; +import org.eclipse.jpt.ui.internal.mappings.JpaUiMappingsMessages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.help.IWorkbenchHelpSystem; + +public class JoinColumnInAssociationOverrideDialog extends AbstractJoinColumnDialog<IJoinColumn> { + private DefaultTrueBoolean insertable; + private ComboViewer insertableComboViewer; + + private DefaultTrueBoolean updatable; + private ComboViewer updatableComboViewer; + + private IAssociationOverride associationOverride; + + JoinColumnInAssociationOverrideDialog(Shell parent, IAssociationOverride associationOverride) { + super(parent); + this.associationOverride = associationOverride; + } + + JoinColumnInAssociationOverrideDialog(Shell parent, IJoinColumn joinColumn) { + super(parent, joinColumn); + this.associationOverride = (IAssociationOverride) joinColumn.eContainer(); + } + + protected Control createDialogArea(Composite parent) { + IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); + Composite composite = (Composite) super.createDialogArea(parent); + + Label insertableLabel = new Label(composite, SWT.LEFT); + insertableLabel.setText(JpaUiMappingsMessages.JoinColumnDialog_insertable); + insertableLabel.setLayoutData(new GridData()); + + this.insertableComboViewer = this.buildInsertableComboViewer(composite); + this.insertableComboViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); + helpSystem.setHelp(this.insertableComboViewer.getCombo(), IJpaHelpContextIds.MAPPING_COLUMN_INSERTABLE); + + Label updatableLabel = new Label(composite, SWT.LEFT); + updatableLabel.setText(JpaUiMappingsMessages.JoinColumnDialog_updatable); + updatableLabel.setLayoutData(new GridData()); + + this.updatableComboViewer = this.buildUpdatableComboViewer(composite); + this.updatableComboViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); + helpSystem.setHelp(this.updatableComboViewer.getCombo(), IJpaHelpContextIds.MAPPING_COLUMN_UPDATABLE); + + return composite; + } + + private ComboViewer buildInsertableComboViewer(Composite parent) { + ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY); + viewer.add(DefaultTrueBoolean.VALUES.toArray()); + DefaultTrueBoolean sel = (this.joinColumn() == null) ? DefaultTrueBoolean.DEFAULT : this.joinColumn().getInsertable(); + viewer.setSelection(new StructuredSelection(sel)); + return viewer; + } + + private ComboViewer buildUpdatableComboViewer(Composite parent) { + ComboViewer viewer = new ComboViewer(parent, SWT.READ_ONLY); + viewer.add(DefaultTrueBoolean.VALUES.toArray()); + DefaultTrueBoolean sel = (this.joinColumn() == null) ? DefaultTrueBoolean.DEFAULT : this.joinColumn().getUpdatable(); + viewer.setSelection(new StructuredSelection(sel)); + return viewer; + } + + protected Table getNameTable() { + return this.associationOverride.typeMapping().primaryDbTable(); + } + + protected Table getReferencedNameTable() { + IAttributeMapping attributeMapping = this.associationOverride.getOwner().attributeMapping(this.associationOverride.getName()); + if (attributeMapping == null) { + return null; + } + IEntity targetEntity = ((ISingleRelationshipMapping) attributeMapping).getResolvedTargetEntity(); + if (targetEntity != null) { + return targetEntity.primaryDbTable(); + } + return null; + } + + private IJoinColumn joinColumn() { + return this.getJoinColumn(); + } + + public DefaultTrueBoolean getInsertable() { + return this.insertable; + } + + public DefaultTrueBoolean getUpdatable() { + return this.updatable; + } + + public boolean close() { + ISelection selection = this.insertableComboViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + this.insertable = (DefaultTrueBoolean) ((IStructuredSelection) selection).getFirstElement(); + } + + selection = this.updatableComboViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + this.updatable = (DefaultTrueBoolean) ((IStructuredSelection) selection).getFirstElement(); + } + + return super.close(); + } + +} |