/**
* Generated with Acceleo
*/
package org.obeonetwork.dsl.database.parts.impl;
// Start of user code for imports
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
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.ButtonsModeEnum;
import org.eclipse.emf.eef.runtime.ui.widgets.EObjectFlatComboViewer;
import org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable;
import org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable.ReferencesTableListener;
import org.eclipse.emf.eef.runtime.ui.widgets.SWTUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableContentProvider;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.ViewerFilter;
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.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.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.obeonetwork.dsl.database.parts.DatabaseViewsRepository;
import org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart;
import org.obeonetwork.dsl.database.providers.DatabaseMessages;
// End of user code
/**
*
*
*/
public class ForeignKeyPropertiesEditionPartImpl extends CompositePropertiesEditionPart implements ISWTPropertiesEditionPart, ForeignKeyPropertiesEditionPart {
protected Text name;
protected EObjectFlatComboViewer target;
protected ReferencesTable elements;
protected List<ViewerFilter> elementsBusinessFilters = new ArrayList<ViewerFilter>();
protected List<ViewerFilter> elementsFilters = new ArrayList<ViewerFilter>();
protected Text comments;
/**
* Default constructor
* @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
*
*/
public ForeignKeyPropertiesEditionPartImpl(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 foreignKeyStep = new BindingCompositionSequence(propertiesEditionComponent);
CompositionStep propertiesStep = foreignKeyStep.addStep(DatabaseViewsRepository.ForeignKey.Properties.class);
propertiesStep.addStep(DatabaseViewsRepository.ForeignKey.Properties.name);
propertiesStep.addStep(DatabaseViewsRepository.ForeignKey.Properties.target);
propertiesStep.addStep(DatabaseViewsRepository.ForeignKey.Properties.elements);
propertiesStep.addStep(DatabaseViewsRepository.ForeignKey.Properties.comments);
composer = new PartComposer(foreignKeyStep) {
@Override
public Composite addToPart(Composite parent, Object key) {
if (key == DatabaseViewsRepository.ForeignKey.Properties.class) {
return createPropertiesGroup(parent);
}
if (key == DatabaseViewsRepository.ForeignKey.Properties.name) {
return createNameText(parent);
}
if (key == DatabaseViewsRepository.ForeignKey.Properties.target) {
return createTargetFlatComboViewer(parent);
}
if (key == DatabaseViewsRepository.ForeignKey.Properties.elements) {
return createElementsAdvancedTableComposition(parent);
}
if (key == DatabaseViewsRepository.ForeignKey.Properties.comments) {
return createCommentsTextarea(parent);
}
return parent;
}
};
composer.compose(view);
}
/**
*
*/
protected Composite createPropertiesGroup(Composite parent) {
Group propertiesGroup = new Group(parent, SWT.NONE);
propertiesGroup.setText(DatabaseMessages.ForeignKeyPropertiesEditionPart_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 createNameText(Composite parent) {
createDescription(parent, DatabaseViewsRepository.ForeignKey.Properties.name, DatabaseMessages.ForeignKeyPropertiesEditionPart_NameLabel);
name = SWTUtils.createScrollableText(parent, SWT.BORDER);
GridData nameData = new GridData(GridData.FILL_HORIZONTAL);
name.setLayoutData(nameData);
name.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(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
}
});
name.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(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
}
}
});
EditingUtils.setID(name, DatabaseViewsRepository.ForeignKey.Properties.name);
EditingUtils.setEEFtype(name, "eef::Text"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(DatabaseViewsRepository.ForeignKey.Properties.name, DatabaseViewsRepository.SWT_KIND), null); //$NON-NLS-1$
return parent;
}
/**
* @param parent the parent composite
*
*/
protected Composite createTargetFlatComboViewer(Composite parent) {
createDescription(parent, DatabaseViewsRepository.ForeignKey.Properties.target, DatabaseMessages.ForeignKeyPropertiesEditionPart_TargetLabel);
target = new EObjectFlatComboViewer(parent, !propertiesEditionComponent.isRequired(DatabaseViewsRepository.ForeignKey.Properties.target, DatabaseViewsRepository.SWT_KIND));
target.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
target.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.target, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.SET, null, getTarget()));
}
});
GridData targetData = new GridData(GridData.FILL_HORIZONTAL);
target.setLayoutData(targetData);
target.setID(DatabaseViewsRepository.ForeignKey.Properties.target);
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(DatabaseViewsRepository.ForeignKey.Properties.target, DatabaseViewsRepository.SWT_KIND), null); //$NON-NLS-1$
return parent;
}
/**
* @param container
*
*/
protected Composite createElementsAdvancedTableComposition(Composite parent) {
this.elements = new ReferencesTable(getDescription(DatabaseViewsRepository.ForeignKey.Properties.elements, DatabaseMessages.ForeignKeyPropertiesEditionPart_ElementsLabel), new ReferencesTableListener() {
public void handleAdd() {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.elements, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, null));
elements.refresh();
}
public void handleEdit(EObject element) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.elements, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, element));
elements.refresh();
}
public void handleMove(EObject element, int oldIndex, int newIndex) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.elements, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.MOVE, element, newIndex));
elements.refresh();
}
public void handleRemove(EObject element) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.elements, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.REMOVE, null, element));
elements.refresh();
}
public void navigateTo(EObject element) { }
});
for (ViewerFilter filter : this.elementsFilters) {
this.elements.addFilter(filter);
}
this.elements.setHelpText(propertiesEditionComponent.getHelpContent(DatabaseViewsRepository.ForeignKey.Properties.elements, DatabaseViewsRepository.SWT_KIND));
this.elements.createControls(parent);
this.elements.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.item != null && e.item.getData() instanceof EObject) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.elements, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.SELECTION_CHANGED, null, e.item.getData()));
}
}
});
GridData elementsData = new GridData(GridData.FILL_HORIZONTAL);
elementsData.horizontalSpan = 3;
this.elements.setLayoutData(elementsData);
this.elements.setLowerBound(0);
this.elements.setUpperBound(-1);
elements.setID(DatabaseViewsRepository.ForeignKey.Properties.elements);
elements.setEEFType("eef::AdvancedTableComposition"); //$NON-NLS-1$
return parent;
}
protected Composite createCommentsTextarea(Composite parent) {
Label commentsLabel = createDescription(parent, DatabaseViewsRepository.ForeignKey.Properties.comments, DatabaseMessages.ForeignKeyPropertiesEditionPart_CommentsLabel);
GridData commentsLabelData = new GridData(GridData.FILL_HORIZONTAL);
commentsLabelData.horizontalSpan = 3;
commentsLabel.setLayoutData(commentsLabelData);
comments = SWTUtils.createScrollableText(parent, SWT.BORDER | SWT.WRAP | SWT.MULTI | SWT.V_SCROLL);
GridData commentsData = new GridData(GridData.FILL_HORIZONTAL);
commentsData.horizontalSpan = 2;
commentsData.heightHint = 80;
commentsData.widthHint = 200;
comments.setLayoutData(commentsData);
comments.addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent)
*
*/
public void focusLost(FocusEvent e) {
if (propertiesEditionComponent != null)
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ForeignKeyPropertiesEditionPartImpl.this, DatabaseViewsRepository.ForeignKey.Properties.comments, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, comments.getText()));
}
});
EditingUtils.setID(comments, DatabaseViewsRepository.ForeignKey.Properties.comments);
EditingUtils.setEEFtype(comments, "eef::Textarea"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(DatabaseViewsRepository.ForeignKey.Properties.comments, DatabaseViewsRepository.SWT_KIND), null); //$NON-NLS-1$
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.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#getName()
*
*/
public String getName() {
return name.getText();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#setName(String newValue)
*
*/
public void setName(String newValue) {
if (newValue != null) {
name.setText(newValue);
} else {
name.setText(""); //$NON-NLS-1$
}
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#getTarget()
*
*/
public EObject getTarget() {
if (target.getSelection() instanceof StructuredSelection) {
Object firstElement = ((StructuredSelection) target.getSelection()).getFirstElement();
if (firstElement instanceof EObject)
return (EObject) firstElement;
}
return null;
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#initTarget(EObjectFlatComboSettings)
*/
public void initTarget(EObjectFlatComboSettings settings) {
target.setInput(settings);
if (current != null) {
target.setSelection(new StructuredSelection(settings.getValue()));
}
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#setTarget(EObject newValue)
*
*/
public void setTarget(EObject newValue) {
if (newValue != null) {
target.setSelection(new StructuredSelection(newValue));
} else {
target.setSelection(new StructuredSelection()); //$NON-NLS-1$
}
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#setTargetButtonMode(ButtonsModeEnum newValue)
*/
public void setTargetButtonMode(ButtonsModeEnum newValue) {
target.setButtonMode(newValue);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#addFilterTarget(ViewerFilter filter)
*
*/
public void addFilterToTarget(ViewerFilter filter) {
target.addFilter(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#addBusinessFilterTarget(ViewerFilter filter)
*
*/
public void addBusinessFilterToTarget(ViewerFilter filter) {
target.addBusinessRuleFilter(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#initElements(EObject current, EReference containingFeature, EReference feature)
*/
public void initElements(ReferencesTableSettings settings) {
if (current.eResource() != null && current.eResource().getResourceSet() != null)
this.resourceSet = current.eResource().getResourceSet();
ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
elements.setContentProvider(contentProvider);
elements.setInput(settings);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#updateElements()
*
*/
public void updateElements() {
elements.refresh();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#addFilterElements(ViewerFilter filter)
*
*/
public void addFilterToElements(ViewerFilter filter) {
elementsFilters.add(filter);
if (this.elements != null) {
this.elements.addFilter(filter);
}
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#addBusinessFilterElements(ViewerFilter filter)
*
*/
public void addBusinessFilterToElements(ViewerFilter filter) {
elementsBusinessFilters.add(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#isContainedInElementsTable(EObject element)
*
*/
public boolean isContainedInElementsTable(EObject element) {
return ((ReferencesTableSettings)elements.getInput()).contains(element);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#getComments()
*
*/
public String getComments() {
return comments.getText();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.ForeignKeyPropertiesEditionPart#setComments(String newValue)
*
*/
public void setComments(String newValue) {
if (newValue != null) {
comments.setText(newValue);
} else {
comments.setText(""); //$NON-NLS-1$
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle()
*
*/
public String getTitle() {
return DatabaseMessages.ForeignKey_Part_Title;
}
// Start of user code additional methods
// End of user code
}