/*******************************************************************************
* Copyright (c) 2008, 2012 Obeo.
* 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:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.eef.eefnr.references.parts.forms;
// Start of user code for imports
import org.eclipse.emf.eef.eefnr.references.parts.AbstractEnabledSamplePropertiesEditionPart;
import org.eclipse.emf.eef.eefnr.references.parts.AbstractSamplePropertiesEditionPart;
import org.eclipse.emf.eef.eefnr.references.parts.ReferencesViewsRepository;
import org.eclipse.emf.eef.eefnr.references.providers.ReferencesMessages;
import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.api.providers.IPropertiesEditionPartProvider;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.services.PropertiesEditionPartProviderService;
import org.eclipse.emf.eef.runtime.part.impl.SectionPropertiesEditingPart;
import org.eclipse.emf.eef.runtime.ui.parts.PartComposer;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.BindingCompositionSequence;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionSequence;
import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.FormUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
// End of user code
/**
* @author <a href="mailto:nathalie.lepine@obeo.fr">Nathalie Lepine</a>
*
*/
public class AbstractEnabledSamplePropertiesEditionPartForm extends SectionPropertiesEditingPart implements IFormPropertiesEditionPart, AbstractEnabledSamplePropertiesEditionPart {
protected Button enabled;
private AbstractSamplePropertiesEditionPart abstractSamplePropertiesEditionPart;
/**
* For {@link ISection} use only.
*/
public AbstractEnabledSamplePropertiesEditionPartForm() { super(); }
/**
* Default constructor
* @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
*
*/
public AbstractEnabledSamplePropertiesEditionPartForm(IPropertiesEditionComponent editionComponent) {
super(editionComponent);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart#
* createFigure(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit)
*
*/
public Composite createFigure(final Composite parent, final FormToolkit widgetFactory) {
ScrolledForm scrolledForm = widgetFactory.createScrolledForm(parent);
Form form = scrolledForm.getForm();
view = form.getBody();
GridLayout layout = new GridLayout();
layout.numColumns = 3;
view.setLayout(layout);
createControls(widgetFactory, view);
return scrolledForm;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.IFormPropertiesEditionPart#
* createControls(org.eclipse.ui.forms.widgets.FormToolkit, org.eclipse.swt.widgets.Composite)
*
*/
public void createControls(final FormToolkit widgetFactory, Composite view) {
CompositionSequence abstractEnabledSampleStep = new BindingCompositionSequence(propertiesEditionComponent);
abstractEnabledSampleStep
.addStep(ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.class)
.addStep(ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled);
abstractEnabledSampleStep.addStep(ReferencesViewsRepository.AbstractEnabledSample.abstractReference);
composer = new PartComposer(abstractEnabledSampleStep) {
@Override
public Composite addToPart(Composite parent, Object key) {
if (key == ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.class) {
return createEnabledPropertiesGroup(widgetFactory, parent);
}
if (key == ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled) {
return createEnabledCheckbox(widgetFactory, parent);
}
if (key == ReferencesViewsRepository.AbstractEnabledSample.abstractReference) {
return createAbstractSample(widgetFactory, parent);
}
return parent;
}
};
composer.compose(view);
}
/**
*
*/
protected Composite createEnabledPropertiesGroup(FormToolkit widgetFactory, final Composite parent) {
Section enabledPropertiesSection = widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
enabledPropertiesSection.setText(ReferencesMessages.AbstractEnabledSamplePropertiesEditionPart_EnabledPropertiesGroupLabel);
GridData enabledPropertiesSectionData = new GridData(GridData.FILL_HORIZONTAL);
enabledPropertiesSectionData.horizontalSpan = 3;
enabledPropertiesSection.setLayoutData(enabledPropertiesSectionData);
Composite enabledPropertiesGroup = widgetFactory.createComposite(enabledPropertiesSection);
GridLayout enabledPropertiesGroupLayout = new GridLayout();
enabledPropertiesGroupLayout.numColumns = 3;
enabledPropertiesGroup.setLayout(enabledPropertiesGroupLayout);
enabledPropertiesSection.setClient(enabledPropertiesGroup);
return enabledPropertiesGroup;
}
protected Composite createEnabledCheckbox(FormToolkit widgetFactory, Composite parent) {
enabled = widgetFactory.createButton(parent, getDescription(ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled, ReferencesMessages.AbstractEnabledSamplePropertiesEditionPart_EnabledLabel), SWT.CHECK);
enabled.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*
*/
public void widgetSelected(SelectionEvent e) {
if (propertiesEditionComponent != null)
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(AbstractEnabledSamplePropertiesEditionPartForm.this, ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, new Boolean(enabled.getSelection())));
}
});
GridData enabledData = new GridData(GridData.FILL_HORIZONTAL);
enabledData.horizontalSpan = 2;
enabled.setLayoutData(enabledData);
EditingUtils.setID(enabled, ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled);
EditingUtils.setEEFtype(enabled, "eef::Checkbox"); //$NON-NLS-1$
FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled, ReferencesViewsRepository.FORM_KIND), null); //$NON-NLS-1$
// Start of user code for createEnabledCheckbox
// End of user code
return parent;
}
protected Composite createAbstractSample(FormToolkit widgetFactory, Composite container) {
IPropertiesEditionPartProvider provider = PropertiesEditionPartProviderService.getInstance().getProvider(ReferencesViewsRepository.class);
abstractSamplePropertiesEditionPart = (AbstractSamplePropertiesEditionPart)provider.getPropertiesEditionPart(ReferencesViewsRepository.AbstractSample.class, ReferencesViewsRepository.FORM_KIND, propertiesEditionComponent);
((IFormPropertiesEditionPart)abstractSamplePropertiesEditionPart).createControls(widgetFactory, container);
return container;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionListener#firePropertiesChanged(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
*
*/
public void firePropertiesChanged(IPropertiesEditionEvent event) {
// Start of user code for tab synchronization
// End of user code
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.references.parts.AbstractEnabledSamplePropertiesEditionPart#getEnabled()
*
*/
public Boolean getEnabled() {
return Boolean.valueOf(enabled.getSelection());
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.references.parts.AbstractEnabledSamplePropertiesEditionPart#setEnabled(Boolean newValue)
*
*/
public void setEnabled(Boolean newValue) {
if (newValue != null) {
enabled.setSelection(newValue.booleanValue());
} else {
enabled.setSelection(false);
}
boolean eefElementEditorReadOnlyState = isReadOnly(ReferencesViewsRepository.AbstractEnabledSample.EnabledProperties.enabled);
if (eefElementEditorReadOnlyState && enabled.isEnabled()) {
enabled.setEnabled(false);
enabled.setToolTipText(ReferencesMessages.AbstractEnabledSample_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !enabled.isEnabled()) {
enabled.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.references.parts.AbstractEnabledSamplePropertiesEditionPart#getAbstractSampleReferencedView()
*
*/
public IPropertiesEditionPart getAbstractSampleReferencedView() {
return (IPropertiesEditionPart) abstractSamplePropertiesEditionPart;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.references.parts.AbstractEnabledSamplePropertiesEditionPart#getName()
*
*/
public String getName() {
return abstractSamplePropertiesEditionPart.getName();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.references.parts.AbstractEnabledSamplePropertiesEditionPart#setName(String newValue)
*
*/
public void setName(String newValue) {
abstractSamplePropertiesEditionPart.setName(newValue);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle()
*
*/
public String getTitle() {
return ReferencesMessages.AbstractEnabledSample_Part_Title;
}
// Start of user code additional methods
// End of user code
}