blob: 21d2c6be992c00584e60013eb8ffdc148085de99 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008 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.mappings.details;
import java.util.Collection;
import java.util.Iterator;
import org.eclipse.jpt.core.context.PersistentType;
import org.eclipse.jpt.core.context.TypeMapping;
import org.eclipse.jpt.ui.JpaPlatformUi;
import org.eclipse.jpt.ui.details.MappingUiProvider;
import org.eclipse.jpt.ui.details.TypeMappingUiProvider;
import org.eclipse.jpt.ui.internal.JptUiMessages;
import org.eclipse.jpt.ui.internal.platform.JpaPlatformUiRegistry;
import org.eclipse.jpt.ui.internal.util.SWTUtil;
import org.eclipse.jpt.ui.internal.widgets.Pane;
import org.eclipse.swt.widgets.Composite;
/**
* This "Map As" composite is responsible for showing the mapping name and
* mapping type for a type.
*
* @see JavaPersistentTypeMapAsComposite
* @see OrmPersistentTypeMapAsComposite
*
* @version 2.0
* @since 2.0
*/
public abstract class PersistentTypeMapAsComposite<T extends PersistentType> extends MapAsComposite<T>
{
/**
* Creates a new <code>PersistentTypeMapAsComposite</code>.
*
* @param parentPane The parent pane of this one
* @param parent The parent container
*/
public PersistentTypeMapAsComposite(Pane<? extends T> parentPane,
Composite parent) {
super(parentPane, parent);
}
/*
* (non-Javadoc)
*/
@Override
protected void addPropertyNames(Collection<String> propertyNames) {
super.addPropertyNames(propertyNames);
propertyNames.add(PersistentType.MAPPING_PROPERTY);
propertyNames.add(PersistentType.NAME_PROPERTY);
}
/*
* (non-Javadoc)
*/
@Override
protected MappingChangeHandler buildMappingChangeHandler() {
return new MappingChangeHandler() {
public String getLabelText() {
String mappingKey = getSubject().getMappingKey();
if (mappingKey != null) {
return JptUiMessages.MapAsComposite_mappedTypeText;
}
return JptUiMessages.MapAsComposite_unmappedTypeText;
}
public String getMappingType() {
String mappingKey = getSubject().getMappingKey();
if (mappingKey == null) {
return JptUiMessages.MapAsComposite_changeMappingType;
}
return SWTUtil.buildDisplayString(
JptUiMessages.class,
MapAsComposite.class,
mappingKey
);
}
public void morphMapping(MappingUiProvider<?> provider) {
getSubject().setMappingKey(provider.getMappingKey());
}
public String getName() {
return getSubject().getName();
}
public Iterator<? extends MappingUiProvider<?>> providers() {
return typeMappingUiProviders();
}
};
}
/**
* Returns the JPT platform responsble to manage the user interface part of
* the JPT plug-in.
*
* @return The UI platform of the JPT plug-in
*/
protected JpaPlatformUi getJpaPlatformUi() {
String platformId = getSubject().getJpaProject().getJpaPlatform().getId();
return JpaPlatformUiRegistry.instance().getJpaPlatformUi(platformId);
}
/*
* (non-Javadoc)
*/
@Override
protected String getMappingKey() {
return getSubject().getMappingKey();
}
/*
* (non-Javadoc)
*/
@Override
protected void propertyChanged(String propertyName) {
super.propertyChanged(propertyName);
if (propertyName == PersistentType.MAPPING_PROPERTY ||
propertyName == PersistentType.NAME_PROPERTY) {
updateDescription();
}
}
/**
* Retrieves the list of providers that are registered with the JPT plugin.
*
* @return The supported types of mapping
*/
protected abstract Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders();
}