blob: c104501b512444d9a10b40743b97e3ade5852489 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008, 2012 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.options;
import org.eclipse.jpt.common.ui.internal.JptCommonUiMessages;
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
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.PropertyListValueModelAdapter;
import org.eclipse.jpt.common.utility.model.value.ListValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.Options;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.EclipseLinkHelpContextIds;
import org.eclipse.jpt.jpa.eclipselink.ui.internal.EclipseLinkUiMessages;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
/**
* SessionNameComposite
*/
public class SessionNameComposite extends Pane<Options>
{
/**
* Creates a new <code>SessionNameComposite</code>.
*
* @param parentPane The parent container of this one
* @param parent The parent container
*/
public SessionNameComposite(
Pane<? extends Options> parentPane,
Composite parent) {
super(parentPane, parent);
}
private PropertyValueModel<String> buildDefaultSessionNameHolder() {
return new PropertyAspectAdapter<Options, String>(this.getSubjectHolder(), Options.DEFAULT_SESSION_NAME) {
@Override
protected String buildValue_() {
return SessionNameComposite.this.getDefaultValue(subject);
}
};
}
private ListValueModel<String> buildDefaultSessionNameListHolder() {
return new PropertyListValueModelAdapter<String>(
this.buildDefaultSessionNameHolder()
);
}
private ModifiablePropertyValueModel<String> buildSessionNameHolder() {
return new PropertyAspectAdapter<Options, String>(this.getSubjectHolder(), Options.SESSION_NAME_PROPERTY) {
@Override
protected String buildValue_() {
String name = subject.getSessionName();
if (name == null) {
name = SessionNameComposite.this.getDefaultValue(subject);
}
return name;
}
@Override
protected void setValue_(String value) {
if (getDefaultValue(subject).equals(value)) {
value = null;
}
subject.setSessionName(value);
}
};
}
private String getDefaultValue(Options subject) {
String defaultValue = subject.getDefaultSessionName();
if (defaultValue != null) {
return NLS.bind(
JptCommonUiMessages.DefaultWithOneParam,
defaultValue
);
}
return JptCommonUiMessages.DefaultEmpty;
}
@Override
protected void initializeLayout(Composite container) {
Combo combo = addLabeledEditableCombo(
container,
EclipseLinkUiMessages.PersistenceXmlOptionsTab_sessionName,
this.buildDefaultSessionNameListHolder(),
this.buildSessionNameHolder(),
EclipseLinkHelpContextIds.PERSISTENCE_OPTIONS_SESSION_NAME
);
SWTUtil.attachDefaultValueHandler(combo);
}
}