blob: b0fb500765b1e3af74c4f59987fa3903effaba2d [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2006, 2011 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.Cascade;
import org.eclipse.jpt.core.context.OneToManyMapping;
import org.eclipse.jpt.core.context.OneToManyRelationship;
import org.eclipse.jpt.ui.details.JpaComposite;
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.swt.widgets.Composite;
/**
* Here the layout of this pane:
* <pre>
* -----------------------------------------------------------------------------
* | ------------------------------------------------------------------------- |
* | | | |
* | | TargetEntityComposite | |
* | | | |
* | ------------------------------------------------------------------------- |
* | ------------------------------------------------------------------------- |
* | | | |
* | | JoiningStrategyComposite | |
* | | | |
* | ------------------------------------------------------------------------- |
* | ------------------------------------------------------------------------- |
* | | | |
* | | FetchTypeComposite | |
* | | | |
* | ------------------------------------------------------------------------- |
* | ------------------------------------------------------------------------- |
* | | | |
* | | CascadeComposite | |
* | | | |
* | ------------------------------------------------------------------------- |
* | ------------------------------------------------------------------------- |
* | | | |
* | | OrderingComposite | |
* | | | |
* | ------------------------------------------------------------------------- |
* -----------------------------------------------------------------------------</pre>
*
* @see OneToManyMapping
* @see CascadeComposite
* @see FetchTypeComposite
* @see JoinTableComposite
* @see OrderingComposite
* @see TargetEntityComposite
*
* @version 2.3
* @since 1.0
*/
public abstract class AbstractOneToManyMappingComposite<T extends OneToManyMapping, R extends OneToManyRelationship>
extends Pane<T>
implements JpaComposite
{
/**
* Creates a new <code>OneToManyMappingComposite</code>.
*
* @param subjectHolder The holder of the subject <code>IOneToManyMapping</code>
* @param parent The parent container
* @param widgetFactory The factory used to create various common widgets
*/
protected AbstractOneToManyMappingComposite(PropertyValueModel<? extends T> subjectHolder,
Composite parent,
WidgetFactory widgetFactory) {
super(subjectHolder, parent, widgetFactory);
}
@Override
protected void initializeLayout(Composite container) {
initializeOneToManyCollapsibleSection(container);
initializeJoiningStrategyCollapsibleSection(container);
initializeOrderingCollapsibleSection(container);
}
protected void initializeOneToManyCollapsibleSection(Composite container) {
container = addCollapsibleSection(
container,
JptUiDetailsMessages.OneToManySection_title,
new SimplePropertyValueModel<Boolean>(Boolean.TRUE)
);
this.initializeOneToManySection(container);
}
protected abstract void initializeOneToManySection(Composite container);
protected void initializeJoiningStrategyCollapsibleSection(Composite container) {
new OneToManyJoiningStrategyPane(this, buildJoiningHolder(), container);
}
protected void initializeOrderingCollapsibleSection(Composite container) {
new OrderingComposite(this, container);
}
protected PropertyValueModel<R> buildJoiningHolder() {
return new TransformationPropertyValueModel<T, R>(getSubjectHolder()) {
@SuppressWarnings("unchecked")
@Override
protected R transform_(T value) {
return (R) value.getRelationship();
}
};
}
protected PropertyValueModel<Cascade> buildCascadeHolder() {
return new TransformationPropertyValueModel<T, Cascade>(getSubjectHolder()) {
@Override
protected Cascade transform_(T value) {
return value.getCascade();
}
};
}
protected Composite addPane(Composite container, int groupBoxMargin) {
return addSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin);
}
}