| /******************************************************************************* |
| * Copyright (c) 2006, 2010 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.details; |
| |
| import org.eclipse.jpt.common.ui.WidgetFactory; |
| import org.eclipse.jpt.common.ui.internal.widgets.Pane; |
| import org.eclipse.jpt.core.context.BasicMapping; |
| import org.eclipse.jpt.core.context.Column; |
| import org.eclipse.jpt.core.context.Converter; |
| import org.eclipse.jpt.core.context.ConvertibleMapping; |
| import org.eclipse.jpt.core.context.EnumeratedConverter; |
| import org.eclipse.jpt.core.context.LobConverter; |
| import org.eclipse.jpt.core.context.TemporalConverter; |
| import org.eclipse.jpt.ui.details.JpaComposite; |
| import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; |
| import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; |
| 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.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| |
| /** |
| * Here the layout of this pane: |
| * <pre> |
| * ----------------------------------------------------------------------------- |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | ColumnComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | FetchTypeComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | TemporalTypeComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | EnumTypeComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | OptionalComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | LobComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * -----------------------------------------------------------------------------</pre> |
| * |
| * @see BasicMapping |
| * @see ColumnComposite |
| * @see EnumTypeComposite |
| * @see FetchTypeComposite |
| * @see LobComposite |
| * @see OptionalComposite |
| * @see TemporalTypeComposite |
| * |
| * @version 2.3 |
| * @since 1.0 |
| */ |
| public abstract class AbstractBasicMappingComposite<T extends BasicMapping> |
| extends Pane<T> |
| implements JpaComposite |
| { |
| /** |
| * Creates a new <code>BasicMappingComposite</code>. |
| * |
| * @param subjectHolder The holder of the subject <code>IBasicMapping</code> |
| * @param parent The parent container |
| * @param widgetFactory The factory used to create various common widgets |
| */ |
| protected AbstractBasicMappingComposite(PropertyValueModel<? extends T> subjectHolder, |
| Composite parent, |
| WidgetFactory widgetFactory) { |
| |
| super(subjectHolder, parent, widgetFactory); |
| } |
| |
| @Override |
| protected void initializeLayout(Composite container) { |
| initializeBasicCollapsibleSection(container); |
| initializeTypeCollapsibleSection(container); |
| } |
| |
| protected void initializeBasicCollapsibleSection(Composite container) { |
| container = addCollapsibleSection( |
| container, |
| JptUiDetailsMessages.BasicSection_title, |
| new SimplePropertyValueModel<Boolean>(Boolean.TRUE) |
| ); |
| |
| this.initializeBasicSection(container); |
| } |
| |
| protected void initializeBasicSection(Composite container) { |
| new ColumnComposite(this, buildColumnHolder(), container); |
| new FetchTypeComposite(this, container); |
| new OptionalComposite(this, addSubPane(container, 4)); |
| } |
| |
| protected void initializeTypeCollapsibleSection(Composite container) { |
| container = addCollapsibleSection( |
| container, |
| JptUiDetailsMessages.TypeSection_type |
| ); |
| this.initializeTypeSection(container); |
| } |
| |
| protected void initializeTypeSection(Composite container) { |
| ((GridLayout) container.getLayout()).numColumns = 2; |
| |
| // No converter |
| Button noConverterButton = addRadioButton( |
| container, |
| JptUiDetailsMessages.TypeSection_default, |
| buildConverterBooleanHolder(null), |
| null); |
| ((GridData) noConverterButton.getLayoutData()).horizontalSpan = 2; |
| |
| // Lob |
| Button lobButton = addRadioButton( |
| container, |
| JptUiDetailsMessages.TypeSection_lob, |
| buildConverterBooleanHolder(LobConverter.class), |
| null); |
| ((GridData) lobButton.getLayoutData()).horizontalSpan = 2; |
| |
| PropertyValueModel<Converter> converterHolder = buildConverterHolder(); |
| // Temporal |
| addRadioButton( |
| container, |
| JptUiDetailsMessages.TypeSection_temporal, |
| buildConverterBooleanHolder(TemporalConverter.class), |
| null); |
| registerSubPane(new TemporalTypeComposite(buildTemporalConverterHolder(converterHolder), container, getWidgetFactory())); |
| |
| |
| // Enumerated |
| addRadioButton( |
| container, |
| JptUiDetailsMessages.TypeSection_enumerated, |
| buildConverterBooleanHolder(EnumeratedConverter.class), |
| null); |
| registerSubPane(new EnumTypeComposite(buildEnumeratedConverterHolder(converterHolder), container, getWidgetFactory())); |
| } |
| |
| protected PropertyValueModel<Column> buildColumnHolder() { |
| return new TransformationPropertyValueModel<T, Column>(getSubjectHolder()) { |
| @Override |
| protected Column transform_(T value) { |
| return value.getColumn(); |
| } |
| }; |
| } |
| |
| protected PropertyValueModel<Converter> buildConverterHolder() { |
| return new PropertyAspectAdapter<T, Converter>(getSubjectHolder(), ConvertibleMapping.CONVERTER_PROPERTY) { |
| @Override |
| protected Converter buildValue_() { |
| return this.subject.getConverter(); |
| } |
| }; |
| } |
| |
| protected PropertyValueModel<TemporalConverter> buildTemporalConverterHolder(PropertyValueModel<Converter> converterHolder) { |
| return new TransformationPropertyValueModel<Converter, TemporalConverter>(converterHolder) { |
| @Override |
| protected TemporalConverter transform_(Converter converter) { |
| return converter.getType() == TemporalConverter.class ? (TemporalConverter) converter : null; |
| } |
| }; |
| } |
| |
| protected PropertyValueModel<EnumeratedConverter> buildEnumeratedConverterHolder(PropertyValueModel<Converter> converterHolder) { |
| return new TransformationPropertyValueModel<Converter, EnumeratedConverter>(converterHolder) { |
| @Override |
| protected EnumeratedConverter transform_(Converter converter) { |
| return converter.getType() == EnumeratedConverter.class ? (EnumeratedConverter) converter : null; |
| } |
| }; |
| } |
| |
| protected WritablePropertyValueModel<Boolean> buildConverterBooleanHolder(final Class<? extends Converter> converterType) { |
| return new PropertyAspectAdapter<BasicMapping, Boolean>(getSubjectHolder(), ConvertibleMapping.CONVERTER_PROPERTY) { |
| @Override |
| protected Boolean buildValue_() { |
| Converter converter = this.subject.getConverter(); |
| return Boolean.valueOf(converter.getType() == converterType); |
| } |
| |
| @Override |
| protected void setValue_(Boolean value) { |
| if (value.booleanValue()) { |
| this.subject.setConverter(converterType); |
| } |
| } |
| }; |
| } |
| } |