| /******************************************************************************* |
| * Copyright (c) 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 org.eclipse.jpt.ui.internal.JpaHelpContextIds; |
| import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; |
| import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; |
| import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; |
| import org.eclipse.jpt.utility.model.value.PropertyValueModel; |
| import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; |
| import org.eclipse.osgi.util.NLS; |
| import org.eclipse.swt.widgets.Composite; |
| |
| /** |
| * Here the layout of this pane: |
| * <pre> |
| * ----------------------------------------------------------------------------- |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | BaseJoinColumnDialogPane | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | | |
| * | x Insertable | |
| * | | |
| * | x Nullable | |
| * | | |
| * | x Unique | |
| * | | |
| * | x Updatable | |
| * | | |
| * -----------------------------------------------------------------------------</pre> |
| * |
| * @see JoinColumnStateObject |
| * @see JoinColumnDialog - The parent container |
| * |
| * @version 2.0 |
| * @since 1.0 |
| */ |
| public class JoinColumnDialogPane<T extends JoinColumnStateObject> extends BaseJoinColumnDialogPane<T> |
| { |
| /** |
| * Creates a new <code>JoinColumnDialogPane</code>. |
| * |
| * @param subjectHolder The holder of this pane's subject |
| * @param parent The parent container |
| */ |
| public JoinColumnDialogPane(PropertyValueModel<? extends T> subjectHolder, |
| Composite parent) |
| { |
| super(subjectHolder, parent); |
| } |
| |
| private WritablePropertyValueModel<Boolean> buildInsertableHolder() { |
| return new PropertyAspectAdapter<T, Boolean>(getSubjectHolder(), JoinColumnStateObject.INSERTABLE_PROPERTY) { |
| @Override |
| protected Boolean buildValue_() { |
| return this.subject.getInsertable(); |
| } |
| |
| @Override |
| protected void setValue_(Boolean value) { |
| this.subject.setInsertable(value); |
| } |
| |
| @Override |
| protected void subjectChanged() { |
| Object oldValue = this.getValue(); |
| super.subjectChanged(); |
| Object newValue = this.getValue(); |
| |
| // Make sure the default value is appended to the text |
| if (oldValue == newValue && newValue == null) { |
| this.fireAspectChange(Boolean.TRUE, newValue); |
| } |
| } |
| }; |
| } |
| |
| private PropertyValueModel<String> buildInsertableStringHolder() { |
| |
| return new TransformationPropertyValueModel<Boolean, String>(buildInsertableHolder()) { |
| |
| @Override |
| protected String transform(Boolean value) { |
| |
| if ((getSubject() != null) && (value == null)) { |
| boolean defaultValue = getSubject().isDefaultInsertable(); |
| |
| String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : |
| JptUiMappingsMessages.Boolean_False; |
| |
| return NLS.bind( |
| JptUiMappingsMessages.JoinColumnDialogPane_insertableWithDefault, |
| defaultStringValue |
| ); |
| } |
| |
| return JptUiMappingsMessages.JoinColumnDialogPane_insertable; |
| } |
| }; |
| } |
| |
| private WritablePropertyValueModel<Boolean> buildNullableHolder() { |
| return new PropertyAspectAdapter<T, Boolean>( |
| getSubjectHolder(), |
| JoinColumnStateObject.NULLABLE_PROPERTY) |
| { |
| @Override |
| protected Boolean buildValue_() { |
| return this.subject.getNullable(); |
| } |
| |
| @Override |
| protected void setValue_(Boolean value) { |
| this.subject.setNullable(value); |
| } |
| |
| @Override |
| protected void subjectChanged() { |
| Object oldValue = this.getValue(); |
| super.subjectChanged(); |
| Object newValue = this.getValue(); |
| |
| // Make sure the default value is appended to the text |
| if (oldValue == newValue && newValue == null) { |
| this.fireAspectChange(Boolean.TRUE, newValue); |
| } |
| } |
| }; |
| } |
| |
| private PropertyValueModel<String> buildNullableStringHolder() { |
| |
| return new TransformationPropertyValueModel<Boolean, String>(buildNullableHolder()) { |
| |
| @Override |
| protected String transform(Boolean value) { |
| |
| if ((getSubject() != null) && (value == null)) { |
| boolean defaultValue = getSubject().isDefaultNullable(); |
| |
| String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : |
| JptUiMappingsMessages.Boolean_False; |
| |
| return NLS.bind( |
| JptUiMappingsMessages.JoinColumnDialogPane_nullableWithDefault, |
| defaultStringValue |
| ); |
| } |
| |
| return JptUiMappingsMessages.JoinColumnDialogPane_nullable; |
| } |
| }; |
| } |
| |
| private WritablePropertyValueModel<Boolean> buildUniqueHolder() { |
| return new PropertyAspectAdapter<T, Boolean>( |
| getSubjectHolder(), |
| JoinColumnStateObject.UNIQUE_PROPERTY) |
| { |
| @Override |
| protected Boolean buildValue_() { |
| return this.subject.getUnique(); |
| } |
| |
| @Override |
| protected void setValue_(Boolean value) { |
| this.subject.setUnique(value); |
| } |
| |
| @Override |
| protected void subjectChanged() { |
| Object oldValue = this.getValue(); |
| super.subjectChanged(); |
| Object newValue = this.getValue(); |
| |
| // Make sure the default value is appended to the text |
| if (oldValue == newValue && newValue == null) { |
| this.fireAspectChange(Boolean.TRUE, newValue); |
| } |
| } |
| }; |
| } |
| |
| private PropertyValueModel<String> buildUniqueStringHolder() { |
| |
| return new TransformationPropertyValueModel<Boolean, String>(buildUniqueHolder()) { |
| |
| @Override |
| protected String transform(Boolean value) { |
| |
| if ((getSubject() != null) && (value == null)) { |
| boolean defaultValue = getSubject().isDefaultUnique(); |
| |
| String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : |
| JptUiMappingsMessages.Boolean_False; |
| |
| return NLS.bind( |
| JptUiMappingsMessages.JoinColumnDialogPane_uniqueWithDefault, |
| defaultStringValue |
| ); |
| } |
| |
| return JptUiMappingsMessages.JoinColumnDialogPane_unique; |
| } |
| }; |
| } |
| |
| private WritablePropertyValueModel<Boolean> buildUpdatableHolder() { |
| return new PropertyAspectAdapter<T, Boolean>(getSubjectHolder(), JoinColumnStateObject.UPDATABLE_PROPERTY) { |
| @Override |
| protected Boolean buildValue_() { |
| return this.subject.getUpdatable(); |
| } |
| |
| @Override |
| protected void setValue_(Boolean value) { |
| this.subject.setUpdatable(value); |
| } |
| |
| @Override |
| protected void subjectChanged() { |
| Object oldValue = this.getValue(); |
| super.subjectChanged(); |
| Object newValue = this.getValue(); |
| |
| // Make sure the default value is appended to the text |
| if (oldValue == newValue && newValue == null) { |
| this.fireAspectChange(Boolean.TRUE, newValue); |
| } |
| } |
| }; |
| } |
| |
| private PropertyValueModel<String> buildUpdatableStringHolder() { |
| |
| return new TransformationPropertyValueModel<Boolean, String>(buildUpdatableHolder()) { |
| |
| @Override |
| protected String transform(Boolean value) { |
| |
| if ((getSubject() != null) && (value == null)) { |
| boolean defaultValue = getSubject().isDefaultUpdatable(); |
| |
| String defaultStringValue = defaultValue ? JptUiMappingsMessages.Boolean_True : |
| JptUiMappingsMessages.Boolean_False; |
| |
| return NLS.bind( |
| JptUiMappingsMessages.JoinColumnDialogPane_updatableWithDefault, |
| defaultStringValue |
| ); |
| } |
| |
| return JptUiMappingsMessages.JoinColumnDialogPane_updatable; |
| } |
| }; |
| } |
| |
| /* |
| * (non-Javadoc) |
| */ |
| @Override |
| protected void initializeLayout(Composite container) { |
| |
| super.initializeLayout(container); |
| |
| // Insertable tri-state check box |
| addTriStateCheckBoxWithDefault( |
| addSubPane(container, 4), |
| JptUiMappingsMessages.JoinColumnDialogPane_insertable, |
| buildInsertableHolder(), |
| buildInsertableStringHolder(), |
| JpaHelpContextIds.MAPPING_COLUMN_INSERTABLE |
| ); |
| |
| // Updatable tri-state check box |
| addTriStateCheckBoxWithDefault( |
| container, |
| JptUiMappingsMessages.JoinColumnDialogPane_updatable, |
| buildUpdatableHolder(), |
| buildUpdatableStringHolder(), |
| JpaHelpContextIds.MAPPING_COLUMN_UPDATABLE |
| ); |
| |
| // Unique tri-state check box |
| addTriStateCheckBoxWithDefault( |
| container, |
| JptUiMappingsMessages.ColumnComposite_unique, |
| buildUniqueHolder(), |
| buildUniqueStringHolder(), |
| JpaHelpContextIds.MAPPING_COLUMN_UNIQUE |
| ); |
| |
| // Nullable tri-state check box |
| addTriStateCheckBoxWithDefault( |
| container, |
| JptUiMappingsMessages.ColumnComposite_nullable, |
| buildNullableHolder(), |
| buildNullableStringHolder(), |
| JpaHelpContextIds.MAPPING_COLUMN_NULLABLE |
| ); |
| } |
| |
| /* |
| * (non-Javadoc) |
| */ |
| @Override |
| protected boolean isTableEditable() { |
| return true; |
| } |
| } |