diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java')
-rw-r--r-- | jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java | 672 |
1 files changed, 337 insertions, 335 deletions
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 index 8b06e17166..17266c904c 100644 --- 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 @@ -1,413 +1,415 @@ /******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. + * Copyright (c) 2007, 2008 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation ******************************************************************************/ package org.eclipse.jpt.ui.internal.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 java.util.ListIterator; 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.core.internal.context.base.IPrimaryKeyJoinColumn; +import org.eclipse.jpt.core.internal.context.base.ISecondaryTable; 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.jpt.ui.internal.util.ControlEnabler; +import org.eclipse.jpt.ui.internal.util.PaneEnabler; +import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane; +import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.ListValueModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; 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 +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | | + * | x Override Default | + * | | + * | - Primary Key Join Columns ---------------------------------------------- | + * | | | | + * | | AddRemoveListPane | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see ISecondaryTable + * @see EntityComposite - The container of this pane + * @see AddRemoveListPane + * + * @version 2.0 + * @since 1.0 + */ +public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractFormPane<ISecondaryTable> { - 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(); + /** + * Creates a new <code>PrimaryKeyJoinColumnsInSecondaryTableComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public PrimaryKeyJoinColumnsInSecondaryTableComposite(AbstractFormPane<?> parentPane, + PropertyValueModel<? extends ISecondaryTable> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + /** + * Creates a new <code>PrimaryKeyJoinColumnsInSecondaryTableComposite</code>. + * + * @param subjectHolder The holder of the subject <code>ISecondaryTable</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public PrimaryKeyJoinColumnsInSecondaryTableComposite(PropertyValueModel<? extends ISecondaryTable> subjectHolder, + Composite parent, + TabbedPropertySheetWidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private void addJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { + + ISecondaryTable secondaryTable = stateObject.getSecondaryTable(); + int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); + + IPrimaryKeyJoinColumn joinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(index); + joinColumn.setSpecifiedName(stateObject.getSelectedName()); + joinColumn.setSpecifiedReferencedColumnName(stateObject.getSpecifiedReferencedColumnName()); } - - private Adapter buildSecondaryTableListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - secondaryTableChanged(notification); + + private void addPrimaryKeyJoinColumn() { + + PrimaryKeyJoinColumnInSecondaryTableDialog dialog = + new PrimaryKeyJoinColumnInSecondaryTableDialog(shell(), subject()); + + dialog.openDialog(buildAddPrimaryKeyJoinColumnPostExecution()); + } + + private PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog> buildAddPrimaryKeyJoinColumnPostExecution() { + return new PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog>() { + public void execute(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { + if (dialog.wasConfirmed()) { + addJoinColumn(dialog.subject()); + } } }; } - - private Adapter buildPkJoinColumnListener() { - return new AdapterImpl() { - public void notifyChanged(Notification notification) { - pkJoinColumnChanged(notification); + + private PropertyValueModel<Boolean> buildControlBooleanHolder() { + return new TransformationPropertyValueModel<ISecondaryTable, Boolean>(getSubjectHolder()) { + @Override + protected Boolean transform(ISecondaryTable value) { + return (value != null); } }; } - - @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(); + + private String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + } + + private PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog> buildEditPrimaryKeyJoinColumnPostExecution() { + return new PostExecution<PrimaryKeyJoinColumnInSecondaryTableDialog>() { + public void execute(PrimaryKeyJoinColumnInSecondaryTableDialog dialog) { + if (dialog.wasConfirmed()) { + editPrimaryKeyJoinColumn(dialog.subject()); } } - }); - - 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 = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_add, - SWT.NONE); - 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 = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit, - SWT.NONE); - 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 = getWidgetFactory().createButton( - this.pkJoinColumnsGroup, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_remove, - SWT.NONE); - 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 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()); + } + + if (joinColumn.getSpecifiedReferencedColumnName() == null) { + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsSecDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + } + + return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParams, joinColumn.getName(), joinColumn.getReferencedColumnName()); } - + private ILabelProvider buildJoinColumnsListLabelProvider() { return new LabelProvider() { + @Override public String getText(Object element) { IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) element; - return (PrimaryKeyJoinColumnsInSecondaryTableComposite.this.secondaryTable.containsSpecifiedPrimaryKeyJoinColumns()) ? - buildJoinColumnLabel(joinColumn) - : + return subject().specifiedPrimaryKeyJoinColumnsSize() > 0 ? + buildJoinColumnLabel(joinColumn) : buildDefaultJoinColumnLabel(joinColumn); } }; } - - String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + + private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { + return new OverrideDefaultValueModel(getSubjectHolder()); } - - String buildJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - if (joinColumn.getSpecifiedName() == null) { - if (joinColumn.getSpecifiedReferencedColumnName() == null) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsBothDefault, joinColumn.getName(),joinColumn.getReferencedColumnName()); + + private AddRemovePane.Adapter buildPrimaryKeyJoinColumnAdapter() { + return new AddRemovePane.AbstractAdapter() { + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + addPrimaryKeyJoinColumn(); + } + + @Override + public boolean hasOptionalButton() { + return true; + } + + @Override + public String optionalButtonText() { + return JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_edit; } - 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); + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + editPrimaryKeyJoinColumn(listSelectionModel); + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + removePrimaryKeyJoinColumn(listSelectionModel); + } + }; } - - 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 WritablePropertyValueModel<IPrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnHolder() { + return new SimplePropertyValueModel<IPrimaryKeyJoinColumn>(); } - - private IPrimaryKeyJoinColumn getSelectedJoinColumn() { - return (IPrimaryKeyJoinColumn) ((StructuredSelection) this.pkJoinColumnsListViewer.getSelection()).getFirstElement(); + + private ListValueModel<IPrimaryKeyJoinColumn> buildPrimaryKeyJoinColumnListHolder() { + return new ListAspectAdapter<ISecondaryTable, IPrimaryKeyJoinColumn>( + getSubjectHolder(), + ISecondaryTable.DEFAULT_PRIMARY_KEY_JOIN_COLUMNS_LIST, + ISecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) + { + @Override + protected ListIterator<IPrimaryKeyJoinColumn> listIterator_() { + return subject.primaryKeyJoinColumns(); + } + }; } - void editPrimaryKeyJoinColumn() { - IPrimaryKeyJoinColumn joinColumn = getSelectedJoinColumn(); - PrimaryKeyJoinColumnInSecondaryTableDialog dialog = new PrimaryKeyJoinColumnInSecondaryTableDialog(this.getControl().getShell(), joinColumn); - editJoinColumnFromDialog(dialog, joinColumn); + private ListValueModel<IPrimaryKeyJoinColumn> buildSortedPrimaryKeyJoinColumnListHolder() { + return new SortedListValueModelAdapter<IPrimaryKeyJoinColumn>( + buildPrimaryKeyJoinColumnListHolder() + ); } - - private void editJoinColumnFromDialog(PrimaryKeyJoinColumnInSecondaryTableDialog dialog, IPrimaryKeyJoinColumn joinColumn) { - if (dialog.open() == Window.OK) { - editJoinColumnDialogOkd(dialog, joinColumn); - } + + private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { + + IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) listSelectionModel.selectedValue(); + + PrimaryKeyJoinColumnInSecondaryTableDialog dialog = + new PrimaryKeyJoinColumnInSecondaryTableDialog(shell(), joinColumn); + + dialog.openDialog(buildEditPrimaryKeyJoinColumnPostExecution()); } - - private void editJoinColumnDialogOkd(PrimaryKeyJoinColumnInSecondaryTableDialog dialog, IPrimaryKeyJoinColumn joinColumn) { - String name = dialog.getSelectedName(); - String referencedColumnName = dialog.getReferencedColumnName(); - if (dialog.isDefaultNameSelected()) { + private void editPrimaryKeyJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { + IPrimaryKeyJoinColumn joinColumn = stateObject.getJoinColumn(); + String name = stateObject.getSelectedName(); + String referencedColumnName = stateObject.getSpecifiedReferencedColumnName(); + + // Name + if (stateObject.isDefaultNameSelected()) { if (joinColumn.getSpecifiedName() != null) { joinColumn.setSpecifiedName(null); } } - else if (joinColumn.getSpecifiedName() == null || !joinColumn.getSpecifiedName().equals(name)){ + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + joinColumn.setSpecifiedName(name); } - - if (dialog.isDefaultReferencedColumnNameSelected()) { + + // Referenced Column Name + if (stateObject.isDefaultReferencedColumnNameSelected()) { if (joinColumn.getSpecifiedReferencedColumnName() != null) { joinColumn.setSpecifiedReferencedColumnName(null); } } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + 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); - } + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = groupBoxMargin(); + + // Override Default check box + Button overrideDefaultButton = buildCheckBox( + buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, + buildOverrideDefaultHolder() + ); + + installOverrideDefaultButtonEnabler(overrideDefaultButton); + + // Primary Key Join Columns group pane + container = buildTitledPane( + container, + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn + ); + + // Primary Key Join Columns add/remove list pane + AddRemoveListPane<ISecondaryTable> pkJoinColumnListPane = new AddRemoveListPane<ISecondaryTable>( + this, + container, + buildPrimaryKeyJoinColumnAdapter(), + buildSortedPrimaryKeyJoinColumnListHolder(), + buildPrimaryKeyJoinColumnHolder(), + buildJoinColumnsListLabelProvider() + ); + + helpSystem().setHelp( + pkJoinColumnListPane.getControl(), + IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS + ); + + installPrimaryKeyJoinColumnListPaneEnabler(pkJoinColumnListPane); } - - - 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()); + private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) { + + new ControlEnabler( + buildControlBooleanHolder(), + overrideDefaultButton + ); } - @Override - protected void doPopulate() { + private void installPrimaryKeyJoinColumnListPaneEnabler(AddRemoveListPane<ISecondaryTable> pkJoinColumnListPane) { + + new PaneEnabler( + buildControlBooleanHolder(), + pkJoinColumnListPane + ); } - protected void engageListeners() { - if (this.secondaryTable != null) { - this.secondaryTable.eAdapters().add(this.secondaryTableListener); - for (IPrimaryKeyJoinColumn pkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) { - pkJoinColumn.eAdapters().add(this.pkJoinColumnListener); - } + private void removePrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { + int[] selectedIndices = listSelectionModel.selectedIndices(); + + for (int index = selectedIndices.length; --index > 0; ) { + subject().removeSpecifiedPrimaryKeyJoinColumn(selectedIndices[index]); } } - - protected void disengageListeners() { - if (this.secondaryTable != null) { - for (IPrimaryKeyJoinColumn pkJoinColumn : this.secondaryTable.getPrimaryKeyJoinColumns()) { - pkJoinColumn.eAdapters().remove(this.pkJoinColumnListener); - } - this.secondaryTable.eAdapters().remove(this.secondaryTableListener); + + private class OverrideDefaultValueModel extends TransformationPropertyValueModel<ISecondaryTable, Boolean> + implements WritablePropertyValueModel<Boolean> + { + OverrideDefaultValueModel(PropertyValueModel<ISecondaryTable> valueHolder) { + super(valueHolder); + engageListChangeListener(valueHolder); } - } - - 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(); + + private void engageListChangeListener(PropertyValueModel<ISecondaryTable> valueHolder) { + new ListAspectAdapter<ISecondaryTable, IPrimaryKeyJoinColumn>(valueHolder, ISecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) { + @Override + protected void itemsAdded(ListChangeEvent e) { + super.itemsAdded(e); + valueChanged(e); + } + + @Override + protected void itemsMoved(ListChangeEvent e) { + super.itemsMoved(e); + valueChanged(e); + } + + @Override + protected void itemsRemoved(ListChangeEvent e) { + super.itemsRemoved(e); + valueChanged(e); + } + + @Override + protected void itemsReplaced(ListChangeEvent e) { + super.itemsReplaced(e); + valueChanged(e); + } + + @Override + protected void listChanged(ListChangeEvent e) { + super.listChanged(e); + valueChanged(e); + } + + @Override + protected void listCleared(ListChangeEvent e) { + super.listCleared(e); + valueChanged(e); } - }); + + @Override + protected ListIterator<IPrimaryKeyJoinColumn> listIterator_() { + return subject.specifiedPrimaryKeyJoinColumns(); + } + + @Override + protected int size_() { + return subject.specifiedPrimaryKeyJoinColumnsSize(); + } + + private void valueChanged(ListChangeEvent e) { + PropertyChangeEvent event = new PropertyChangeEvent(e.getSource(), e.aspectName(), null, subject); + OverrideDefaultValueModel.this.valueChanged(event); + } + }; } - } - 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(); + public void setValue(Boolean value) { + ISecondaryTable secondaryTable = subject(); + + if (value) { + IPrimaryKeyJoinColumn defaultJoinColumn = secondaryTable.defaultPrimaryKeyJoinColumns().next(); + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IPrimaryKeyJoinColumn pkJoinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); + pkJoinColumn.setSpecifiedName(columnName); + pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + else { + for (int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { + secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(index); } - }); + } } - } - - 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); - } -} + @Override + protected Boolean transform_(ISecondaryTable value) { + return value.specifiedPrimaryKeyJoinColumnsSize() > 0; + } + } +}
\ No newline at end of file |