| /******************************************************************************* |
| * Copyright (c) 2008, 2013 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0, which accompanies this distribution |
| * and is available at https://www.eclipse.org/legal/epl-2.0/. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.jpa.eclipselink.ui.internal.details; |
| |
| import org.eclipse.jface.resource.ResourceManager; |
| import org.eclipse.jpt.common.ui.WidgetFactory; |
| import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; |
| import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel; |
| import org.eclipse.jpt.common.utility.internal.transformer.TransformerTools; |
| import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; |
| import org.eclipse.jpt.jpa.core.context.BaseTemporalConverter; |
| import org.eclipse.jpt.jpa.core.context.Converter; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkConvert; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkConverterContainer; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkIdMapping; |
| import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkMutable; |
| import org.eclipse.jpt.jpa.eclipselink.ui.details.JptJpaEclipseLinkUiDetailsMessages; |
| import org.eclipse.jpt.jpa.ui.details.JptJpaUiDetailsMessages; |
| import org.eclipse.jpt.jpa.ui.internal.details.AbstractIdMappingComposite; |
| import org.eclipse.jpt.jpa.ui.internal.details.ColumnComposite; |
| import org.eclipse.jpt.jpa.ui.internal.details.TemporalTypeCombo; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.ui.forms.events.ExpansionAdapter; |
| import org.eclipse.ui.forms.events.ExpansionEvent; |
| import org.eclipse.ui.forms.widgets.ExpandableComposite; |
| import org.eclipse.ui.forms.widgets.Section; |
| |
| public abstract class EclipseLinkIdMappingComposite<T extends EclipseLinkIdMapping> |
| extends AbstractIdMappingComposite<T> |
| { |
| protected EclipseLinkIdMappingComposite( |
| PropertyValueModel<? extends T> mappingModel, |
| PropertyValueModel<Boolean> enabledModel, |
| Composite parentComposite, |
| WidgetFactory widgetFactory, |
| ResourceManager resourceManager) { |
| super(mappingModel, enabledModel, parentComposite, widgetFactory, resourceManager); |
| } |
| |
| @Override |
| protected Control initializeIdSection(Composite container) { |
| container = this.addSubPane(container); |
| |
| new ColumnComposite(this, buildColumnModel(), container); |
| new EclipseLinkMutableTriStateCheckBox(this, buildMutableModel(), container); |
| |
| return container; |
| } |
| |
| @Override |
| protected Control initializeTypeSection(Composite container) { |
| container = this.addSubPane(container, 2, 0, 0, 0, 0); |
| |
| // No converter |
| Button noConverterButton = addRadioButton( |
| container, |
| JptJpaUiDetailsMessages.TYPE_SECTION_DEFAULT, |
| buildConverterBooleanHolder(null), |
| null); |
| ((GridData) noConverterButton.getLayoutData()).horizontalSpan = 2; |
| |
| PropertyValueModel<Converter> converterHolder = buildConverterHolder(); |
| // Temporal |
| addRadioButton( |
| container, |
| JptJpaUiDetailsMessages.TYPE_SECTION_TEMPORAL, |
| buildConverterBooleanHolder(BaseTemporalConverter.class), |
| null); |
| new TemporalTypeCombo(this, this.buildTemporalConverterHolder(converterHolder), container); |
| |
| // EclipseLink Converter |
| Button elConverterButton = addRadioButton( |
| container, |
| JptJpaEclipseLinkUiDetailsMessages.TYPE_SECTION_CONVERTED, |
| buildConverterBooleanHolder(EclipseLinkConvert.class), |
| null); |
| ((GridData) elConverterButton.getLayoutData()).horizontalSpan = 2; |
| |
| PropertyValueModel<EclipseLinkConvert> convertModel = this.buildEclipseLinkConvertModel(converterHolder); |
| PropertyValueModel<Boolean> convertEnabledModel = buildIsNotNullModel(convertModel); |
| Label convertLabel = this.addLabel(container, JptJpaEclipseLinkUiDetailsMessages.ECLIPSELINK_CONVERT_COMPOSITE_CONVERTER_NAME_LABEL, convertEnabledModel); |
| GridData gridData = new GridData(); |
| gridData.horizontalIndent = 20; |
| convertLabel.setLayoutData(gridData); |
| new EclipseLinkConvertCombo(this, convertModel, convertEnabledModel, container); |
| |
| return container; |
| } |
| |
| protected PropertyValueModel<EclipseLinkConvert> buildEclipseLinkConvertModel(PropertyValueModel<Converter> converterModel) { |
| return new TransformationPropertyValueModel<Converter, EclipseLinkConvert>(converterModel, TransformerTools.nullCheck(EclipseLinkConvert.CONVERTER_TRANSFORMER)); |
| } |
| |
| protected PropertyValueModel<EclipseLinkMutable> buildMutableModel() { |
| return new PropertyAspectAdapter<T, EclipseLinkMutable>(getSubjectHolder()) { |
| @Override |
| protected EclipseLinkMutable buildValue_() { |
| return this.subject.getMutable(); |
| } |
| }; |
| } |
| |
| |
| protected void initializeConvertersCollapsibleSection(Composite container) { |
| final Section section = this.getWidgetFactory().createSection(container, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); |
| section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| section.setText(JptJpaEclipseLinkUiDetailsMessages.ECLIPSELINK_TYPE_MAPPING_COMPOSITE_CONVERTERS); |
| section.addExpansionListener(new ExpansionAdapter() { |
| @Override |
| public void expansionStateChanging(ExpansionEvent e) { |
| if (e.getState() && section.getClient() == null) { |
| section.setClient(EclipseLinkIdMappingComposite.this.initializeConvertersSection(section)); |
| } |
| } |
| }); |
| } |
| |
| protected Control initializeConvertersSection(Composite container) { |
| return new EclipseLinkConvertersComposite(this, this.buildConverterHolderValueModel(), container).getControl(); |
| } |
| |
| protected PropertyValueModel<EclipseLinkConverterContainer> buildConverterHolderValueModel() { |
| return new PropertyAspectAdapter<T, EclipseLinkConverterContainer>(getSubjectHolder()) { |
| @Override |
| protected EclipseLinkConverterContainer buildValue_() { |
| return this.subject.getConverterContainer(); |
| } |
| }; |
| } |
| } |