/*******************************************************************************
* 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.parts.impl;
// Start of user code for imports
import org.eclipse.emf.eef.eefnr.parts.EefnrViewsRepository;
import org.eclipse.emf.eef.eefnr.parts.SamplePropertiesEditionPart;
import org.eclipse.emf.eef.eefnr.providers.EefnrMessages;
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.ISWTPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart;
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.parts.sequence.CompositionStep;
import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.SWTUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
// End of user code
/**
* @author <a href="mailto:nathalie.lepine@obeo.fr">Nathalie Lepine</a>
*
*/
public class SamplePropertiesEditionPartImpl extends CompositePropertiesEditionPart implements ISWTPropertiesEditionPart, SamplePropertiesEditionPart {
protected Text textRequiredProperty;
protected Text textOptionalProperty;
/**
* Default constructor
* @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
*
*/
public SamplePropertiesEditionPartImpl(IPropertiesEditionComponent editionComponent) {
super(editionComponent);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart#
* createFigure(org.eclipse.swt.widgets.Composite)
*
*/
public Composite createFigure(final Composite parent) {
view = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
view.setLayout(layout);
createControls(view);
return view;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart#
* createControls(org.eclipse.swt.widgets.Composite)
*
*/
public void createControls(Composite view) {
CompositionSequence sampleStep = new BindingCompositionSequence(propertiesEditionComponent);
CompositionStep propertiesStep = sampleStep.addStep(EefnrViewsRepository.Sample.Properties.class);
propertiesStep.addStep(EefnrViewsRepository.Sample.Properties.textRequiredProperty);
propertiesStep.addStep(EefnrViewsRepository.Sample.Properties.textOptionalProperty);
composer = new PartComposer(sampleStep) {
@Override
public Composite addToPart(Composite parent, Object key) {
if (key == EefnrViewsRepository.Sample.Properties.class) {
return createPropertiesGroup(parent);
}
if (key == EefnrViewsRepository.Sample.Properties.textRequiredProperty) {
return createTextRequiredPropertyText(parent);
}
if (key == EefnrViewsRepository.Sample.Properties.textOptionalProperty) {
return createTextOptionalPropertyText(parent);
}
return parent;
}
};
composer.compose(view);
}
/**
*
*/
protected Composite createPropertiesGroup(Composite parent) {
Group propertiesGroup = new Group(parent, SWT.NONE);
propertiesGroup.setText(EefnrMessages.SamplePropertiesEditionPart_PropertiesGroupLabel);
GridData propertiesGroupData = new GridData(GridData.FILL_HORIZONTAL);
propertiesGroupData.horizontalSpan = 3;
propertiesGroup.setLayoutData(propertiesGroupData);
GridLayout propertiesGroupLayout = new GridLayout();
propertiesGroupLayout.numColumns = 3;
propertiesGroup.setLayout(propertiesGroupLayout);
return propertiesGroup;
}
protected Composite createTextRequiredPropertyText(Composite parent) {
createDescription(parent, EefnrViewsRepository.Sample.Properties.textRequiredProperty, EefnrMessages.SamplePropertiesEditionPart_TextRequiredPropertyLabel);
textRequiredProperty = SWTUtils.createScrollableText(parent, SWT.BORDER);
GridData textRequiredPropertyData = new GridData(GridData.FILL_HORIZONTAL);
textRequiredProperty.setLayoutData(textRequiredPropertyData);
textRequiredProperty.addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
*
*/
@Override
@SuppressWarnings("synthetic-access")
public void focusLost(FocusEvent e) {
if (propertiesEditionComponent != null)
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(SamplePropertiesEditionPartImpl.this, EefnrViewsRepository.Sample.Properties.textRequiredProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, textRequiredProperty.getText()));
}
});
textRequiredProperty.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
*
*/
@Override
@SuppressWarnings("synthetic-access")
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
if (propertiesEditionComponent != null)
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(SamplePropertiesEditionPartImpl.this, EefnrViewsRepository.Sample.Properties.textRequiredProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, textRequiredProperty.getText()));
}
}
});
EditingUtils.setID(textRequiredProperty, EefnrViewsRepository.Sample.Properties.textRequiredProperty);
EditingUtils.setEEFtype(textRequiredProperty, "eef::Text"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(EefnrViewsRepository.Sample.Properties.textRequiredProperty, EefnrViewsRepository.SWT_KIND), null); //$NON-NLS-1$
// Start of user code for createTextRequiredPropertyText
// End of user code
return parent;
}
protected Composite createTextOptionalPropertyText(Composite parent) {
createDescription(parent, EefnrViewsRepository.Sample.Properties.textOptionalProperty, EefnrMessages.SamplePropertiesEditionPart_TextOptionalPropertyLabel);
textOptionalProperty = SWTUtils.createScrollableText(parent, SWT.BORDER);
GridData textOptionalPropertyData = new GridData(GridData.FILL_HORIZONTAL);
textOptionalProperty.setLayoutData(textOptionalPropertyData);
textOptionalProperty.addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
*
*/
@Override
@SuppressWarnings("synthetic-access")
public void focusLost(FocusEvent e) {
if (propertiesEditionComponent != null)
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(SamplePropertiesEditionPartImpl.this, EefnrViewsRepository.Sample.Properties.textOptionalProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, textOptionalProperty.getText()));
}
});
textOptionalProperty.addKeyListener(new KeyAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
*
*/
@Override
@SuppressWarnings("synthetic-access")
public void keyPressed(KeyEvent e) {
if (e.character == SWT.CR) {
if (propertiesEditionComponent != null)
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(SamplePropertiesEditionPartImpl.this, EefnrViewsRepository.Sample.Properties.textOptionalProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, textOptionalProperty.getText()));
}
}
});
EditingUtils.setID(textOptionalProperty, EefnrViewsRepository.Sample.Properties.textOptionalProperty);
EditingUtils.setEEFtype(textOptionalProperty, "eef::Text"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(EefnrViewsRepository.Sample.Properties.textOptionalProperty, EefnrViewsRepository.SWT_KIND), null); //$NON-NLS-1$
// Start of user code for createTextOptionalPropertyText
// End of user code
return parent;
}
/**
* {@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.eefnr.parts.SamplePropertiesEditionPart#getTextRequiredProperty()
*
*/
public String getTextRequiredProperty() {
return textRequiredProperty.getText();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.eefnr.parts.SamplePropertiesEditionPart#setTextRequiredProperty(String newValue)
*
*/
public void setTextRequiredProperty(String newValue) {
if (newValue != null) {
textRequiredProperty.setText(newValue);
} else {
textRequiredProperty.setText(""); //$NON-NLS-1$
}
boolean eefElementEditorReadOnlyState = isReadOnly(EefnrViewsRepository.Sample.Properties.textRequiredProperty);
if (eefElementEditorReadOnlyState && textRequiredProperty.isEnabled()) {
textRequiredProperty.setEnabled(false);
textRequiredProperty.setToolTipText(EefnrMessages.Sample_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !textRequiredProperty.isEnabled()) {
textRequiredProperty.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.eefnr.parts.SamplePropertiesEditionPart#getTextOptionalProperty()
*
*/
public String getTextOptionalProperty() {
return textOptionalProperty.getText();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.eefnr.parts.SamplePropertiesEditionPart#setTextOptionalProperty(String newValue)
*
*/
public void setTextOptionalProperty(String newValue) {
if (newValue != null) {
textOptionalProperty.setText(newValue);
} else {
textOptionalProperty.setText(""); //$NON-NLS-1$
}
boolean eefElementEditorReadOnlyState = isReadOnly(EefnrViewsRepository.Sample.Properties.textOptionalProperty);
if (eefElementEditorReadOnlyState && textOptionalProperty.isEnabled()) {
textOptionalProperty.setEnabled(false);
textOptionalProperty.setToolTipText(EefnrMessages.Sample_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !textOptionalProperty.isEnabled()) {
textOptionalProperty.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle()
*
*/
public String getTitle() {
return EefnrMessages.Sample_Part_Title;
}
// Start of user code additional methods
// End of user code
}