blob: 046b785107a44a68cd88f6498b483bbd97fafedc [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010, 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.jpa.eclipselink.ui.internal.persistence.connection;
import org.eclipse.jpt.common.ui.internal.util.PaneEnabler;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
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.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnitTransactionType;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Connection;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.EclipseLinkUiMessages;
import org.eclipse.swt.widgets.Composite;
/**
* JdbcExclusiveConnectionsPropertiesComposite
*/
public class JdbcExclusiveConnectionsPropertiesComposite<T extends Connection>
extends Pane<T>
{
public JdbcExclusiveConnectionsPropertiesComposite(Pane<T> parentComposite, Composite parent) {
super(parentComposite, parent);
}
@Override
protected void initializeLayout(Composite container) {
container = this.addTitledGroup(
this.addSubPane(container, 10),
EclipseLinkUiMessages.JdbcExclusiveConnectionsPropertiesComposite_GroupBox
);
// Exclusive connection mode
new JdbcExclusiveConnectionModeComposite<T>(this, container);
// Lazy Connection
new JdbcLazyConnectionComposite<T>(this, container);
this.installPaneEnabler();
}
private void installPaneEnabler() {
new PaneEnabler(this.buildPaneEnablerHolder(), this);
}
private PropertyValueModel<Boolean> buildPaneEnablerHolder() {
return new TransformationPropertyValueModel<PersistenceUnitTransactionType, Boolean>(this.buildTransactionTypeHolder()) {
@Override
protected Boolean transform(PersistenceUnitTransactionType value) {
return value == PersistenceUnitTransactionType.RESOURCE_LOCAL;
}
};
}
private PropertyValueModel<PersistenceUnitTransactionType> buildTransactionTypeHolder() {
return new PropertyAspectAdapter<PersistenceUnit, PersistenceUnitTransactionType>(
this.buildPersistenceUnitHolder(),
PersistenceUnit.SPECIFIED_TRANSACTION_TYPE_PROPERTY,
PersistenceUnit.DEFAULT_TRANSACTION_TYPE_PROPERTY) {
@Override
protected PersistenceUnitTransactionType buildValue_() {
return this.subject.getTransactionType();
}
};
}
private PropertyValueModel<PersistenceUnit> buildPersistenceUnitHolder() {
return new PropertyAspectAdapter<Connection, PersistenceUnit>(this.getSubjectHolder()) {
@Override
protected PersistenceUnit buildValue_() {
return this.subject.getPersistenceUnit();
}
};
}
}