| /******************************************************************************* |
| * Copyright (c) 2011, 2013 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0, which accompanies this distribution |
| * and is available at https://www.eclipse.org/legal/epl-2.0/. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.jpa.ui.internal.details; |
| |
| import org.eclipse.jface.resource.ResourceManager; |
| import org.eclipse.jpt.common.ui.WidgetFactory; |
| 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.QueryContainer; |
| import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass; |
| import org.eclipse.jpt.jpa.ui.details.JptJpaUiDetailsMessages; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.ui.forms.events.ExpansionAdapter; |
| import org.eclipse.ui.forms.events.ExpansionEvent; |
| import org.eclipse.ui.forms.widgets.ExpandableComposite; |
| import org.eclipse.ui.forms.widgets.Section; |
| |
| /** |
| * Here the layout of this pane: |
| * <pre> |
| * ----------------------------------------------------------------------------- |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | IdClassComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * | | |
| * | - v Queries ------------------------------------------------------------- | |
| * | ------------------------------------------------------------------------- | |
| * | | | | |
| * | | QueriesComposite | | |
| * | | | | |
| * | ------------------------------------------------------------------------- | |
| * -----------------------------------------------------------------------------</pre> |
| */ |
| public abstract class AbstractJavaMappedSuperclassComposite<T extends JavaMappedSuperclass> |
| extends AbstractMappedSuperclassComposite<T> { |
| /** |
| * Creates a new <code>MappedSuperclassComposite</code>. |
| * |
| * @param subjectHolder The holder of this pane's subject |
| * @param parent The parent container |
| * @param widgetFactory The factory used to create various common widgets |
| */ |
| public AbstractJavaMappedSuperclassComposite( |
| PropertyValueModel<? extends T> mappedSuperclassModel, |
| Composite parentComposite, |
| WidgetFactory widgetFactory, |
| ResourceManager resourceManager) { |
| super(mappedSuperclassModel, parentComposite, widgetFactory, resourceManager); |
| } |
| |
| @Override |
| protected void initializeLayout(Composite container) { |
| this.initializeMappedSuperclassCollapsibleSection(container); |
| this.initializeQueriesCollapsibleSection(container); |
| } |
| |
| protected void initializeQueriesCollapsibleSection(Composite container) { |
| final Section section = this.getWidgetFactory().createSection(container, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); |
| section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| section.setText(JptJpaUiDetailsMessages.ENTITY_COMPOSITE_QUERIES); |
| |
| section.addExpansionListener(new ExpansionAdapter() { |
| @Override |
| public void expansionStateChanging(ExpansionEvent e) { |
| if (e.getState() && section.getClient() == null) { |
| section.setClient(initializeQueriesSection(section)); |
| } |
| } |
| }); |
| } |
| |
| protected Control initializeQueriesSection(Composite container) { |
| return new QueriesComposite(this, this.buildQueryContainerModel(), container).getControl(); |
| } |
| |
| protected PropertyValueModel<QueryContainer> buildQueryContainerModel() { |
| return new PropertyAspectAdapter<T, QueryContainer>(this.getSubjectHolder()) { |
| @Override |
| protected QueryContainer buildValue_() { |
| return this.subject.getQueryContainer(); |
| } |
| }; |
| } |
| } |