| /******************************************************************************* |
| * 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 org.eclipse.jdt.core.IType; |
| import org.eclipse.jpt.core.JpaProject; |
| import org.eclipse.jpt.core.context.IdClass; |
| import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; |
| import org.eclipse.jpt.ui.internal.widgets.Pane; |
| import org.eclipse.jpt.ui.internal.widgets.ClassChooserPane; |
| import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; |
| import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; |
| import org.eclipse.swt.widgets.Composite; |
| |
| /** |
| * Here the layout of this pane: |
| * <pre> |
| * ----------------------------------------------------------------------------- |
| * | | |
| * | ClassChooserPane | |
| * | | |
| * -----------------------------------------------------------------------------</pre> |
| * |
| * @see IdClass |
| * @see ClassChooserPane |
| * @see AbstractEntityComposite - A parent container |
| * @see MappedSuperclassComposite - A parent container |
| * |
| * @version 2.0 |
| * @since 2.0 |
| */ |
| public class IdClassComposite extends Pane<IdClass> |
| { |
| /** |
| * Creates a new <code>IdClassComposite</code>. |
| * |
| * @param parentPane The parent pane of this one |
| * @param parent The parent container |
| */ |
| public IdClassComposite(Pane<? extends IdClass> parentPane, |
| Composite parent) { |
| |
| super(parentPane, parent); |
| } |
| |
| private ClassChooserPane<IdClass> addClassChooser(Composite container) { |
| |
| return new ClassChooserPane<IdClass>(this, container) { |
| |
| @Override |
| protected WritablePropertyValueModel<String> buildTextHolder() { |
| return new PropertyAspectAdapter<IdClass, String>(getSubjectHolder(), IdClass.ID_CLASS_PROPERTY) { |
| @Override |
| protected String buildValue_() { |
| return subject.getIdClass(); |
| } |
| |
| @Override |
| protected void setValue_(String value) { |
| |
| if (value.length() == 0) { |
| value = null; |
| } |
| |
| subject.setIdClass(value); |
| } |
| }; |
| } |
| |
| @Override |
| protected String getClassName() { |
| return getSubject().getIdClass(); |
| } |
| |
| @Override |
| protected String getLabelText() { |
| return JptUiMappingsMessages.IdClassComposite_label; |
| } |
| |
| @Override |
| protected JpaProject getJpaProject() { |
| return getSubject().getJpaProject(); |
| } |
| |
| @Override |
| protected void promptType() { |
| IType type = chooseType(); |
| |
| if (type != null) { |
| String className = type.getFullyQualifiedName('.'); |
| getSubject().setIdClass(className); |
| } |
| } |
| }; |
| } |
| |
| /* |
| * (non-Javadoc) |
| */ |
| @Override |
| protected void initializeLayout(Composite container) { |
| addClassChooser(container); |
| } |
| } |