| /******************************************************************************* |
| * Copyright (c) 2009, 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.jpa.ui.internal.jpa2.persistence.connection; |
| |
| import java.util.Collection; |
| |
| import org.eclipse.jpt.common.ui.internal.widgets.EnumFormComboViewer; |
| 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.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.core.jpa2.context.persistence.connection.JpaConnection2_0; |
| import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds; |
| import org.eclipse.jpt.jpa.ui.internal.jpa2.persistence.JptUiPersistence2_0Messages; |
| import org.eclipse.swt.widgets.Composite; |
| |
| /** |
| * TransactionTypeComposite |
| */ |
| public class TransactionTypeComposite extends Pane<JpaConnection2_0> |
| { |
| /** |
| * Creates a new <code>TransactionTypeComposite</code>. |
| * |
| * @param parentController |
| * The parent container of this one |
| * @param parent |
| * The parent container |
| */ |
| public TransactionTypeComposite( |
| Pane<? extends JpaConnection2_0> parentComposite, |
| Composite parent) { |
| |
| super( parentComposite, parent); |
| } |
| |
| private EnumFormComboViewer<PersistenceUnit, PersistenceUnitTransactionType> buildTransactionTypeCombo(Composite container) { |
| |
| return new EnumFormComboViewer<PersistenceUnit, PersistenceUnitTransactionType>(this, |
| this.buildPersistenceUnitHolder(), |
| container) { |
| @Override |
| protected void addPropertyNames(Collection<String> propertyNames) { |
| super.addPropertyNames(propertyNames); |
| propertyNames.add(PersistenceUnit.SPECIFIED_TRANSACTION_TYPE_PROPERTY); |
| propertyNames.add(PersistenceUnit.DEFAULT_TRANSACTION_TYPE_PROPERTY); |
| } |
| |
| @Override |
| protected PersistenceUnitTransactionType[] getChoices() { |
| return PersistenceUnitTransactionType.values(); |
| } |
| |
| @Override |
| protected PersistenceUnitTransactionType getDefaultValue() { |
| return this.getSubject().getDefaultTransactionType(); |
| } |
| |
| @Override |
| protected String displayString(PersistenceUnitTransactionType value) { |
| return this.buildDisplayString(JptUiPersistence2_0Messages.class, TransactionTypeComposite.this, value); |
| } |
| |
| @Override |
| protected PersistenceUnitTransactionType getValue() { |
| return this.getSubject().getSpecifiedTransactionType(); |
| } |
| |
| @Override |
| protected void setValue(PersistenceUnitTransactionType value) { |
| this.getSubject().setSpecifiedTransactionType(value); |
| |
| if (value == PersistenceUnitTransactionType.RESOURCE_LOCAL) { |
| clearJTAProperties(); |
| } |
| else { |
| clearResourceLocalProperties(); |
| } |
| } |
| }; |
| } |
| |
| private PropertyValueModel<PersistenceUnit> buildPersistenceUnitHolder() { |
| return new PropertyAspectAdapter<JpaConnection2_0, PersistenceUnit>(this.getSubjectHolder()) { |
| @Override |
| protected PersistenceUnit buildValue_() { |
| return this.subject.getPersistenceUnit(); |
| } |
| }; |
| } |
| |
| private void clearJTAProperties() { |
| this.getSubject().getPersistenceUnit().setJtaDataSource(null); |
| } |
| |
| private void clearResourceLocalProperties() { |
| JpaConnection2_0 connection = this.getSubject(); |
| connection.getPersistenceUnit().setNonJtaDataSource(null); |
| connection.setDriver(null); |
| connection.setUrl(null); |
| connection.setUser(null); |
| connection.setPassword(null); |
| } |
| |
| @Override |
| protected void initializeLayout( Composite container) { |
| |
| this.addLabeledComposite( |
| container, |
| JptUiPersistence2_0Messages.TransactionTypeComposite_transactionTypeLabel, |
| this.buildTransactionTypeCombo( container), |
| JpaHelpContextIds.PERSISTENCE_XML_CONNECTION // TODO - Review for JPA 2.0 |
| ); |
| } |
| } |