/**
* Generated with Acceleo
*/
package org.obeonetwork.dsl.entityrelation.parts.forms;
// Start of user code for imports
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
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.IFormPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
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.parts.sequence.CompositionStep;
import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.EMFModelViewerDialog;
import org.eclipse.emf.eef.runtime.ui.widgets.FormUtils;
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.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
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.graphics.Image;
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.swt.widgets.Label;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
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;
import org.eclipse.ui.views.properties.tabbed.ISection;
import org.obeonetwork.dsl.entityrelation.parts.EntityrelationViewsRepository;
import org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart;
import org.obeonetwork.dsl.entityrelation.providers.EntityrelationMessages;
// End of user code
/**
*
*
*/
public class IdentifierPropertiesEditionPartForm extends SectionPropertiesEditingPart implements IFormPropertiesEditionPart, IdentifierPropertiesEditionPart {
protected Text name;
protected TableViewer attributes;
protected Button addAttributes;
protected Button removeAttributes;
protected List<ViewerFilter> attributesBusinessFilters = new ArrayList<ViewerFilter>();
protected List<ViewerFilter> attributesFilters = new ArrayList<ViewerFilter>();
protected Text comments;
/**
* For {@link ISection} use only.
*/
public IdentifierPropertiesEditionPartForm() { super(); }
/**
* Default constructor
* @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
*
*/
public IdentifierPropertiesEditionPartForm(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 identifierStep = new BindingCompositionSequence(propertiesEditionComponent);
CompositionStep propertiesStep = identifierStep.addStep(EntityrelationViewsRepository.Identifier.Properties.class);
propertiesStep.addStep(EntityrelationViewsRepository.Identifier.Properties.name);
propertiesStep.addStep(EntityrelationViewsRepository.Identifier.Properties.attributes);
propertiesStep.addStep(EntityrelationViewsRepository.Identifier.Properties.comments);
composer = new PartComposer(identifierStep) {
@Override
public Composite addToPart(Composite parent, Object key) {
if (key == EntityrelationViewsRepository.Identifier.Properties.class) {
return createPropertiesGroup(widgetFactory, parent);
}
if (key == EntityrelationViewsRepository.Identifier.Properties.name) {
return createNameText(widgetFactory, parent);
}
if (key == EntityrelationViewsRepository.Identifier.Properties.attributes) {
return createAttributesReferencesTable(widgetFactory, parent);
}
if (key == EntityrelationViewsRepository.Identifier.Properties.comments) {
return createCommentsTextarea(widgetFactory, parent);
}
return parent;
}
};
composer.compose(view);
}
/**
*
*/
protected Composite createPropertiesGroup(FormToolkit widgetFactory, final Composite parent) {
Section propertiesSection = widgetFactory.createSection(parent, Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
propertiesSection.setText(EntityrelationMessages.IdentifierPropertiesEditionPart_PropertiesGroupLabel);
GridData propertiesSectionData = new GridData(GridData.FILL_HORIZONTAL);
propertiesSectionData.horizontalSpan = 3;
propertiesSection.setLayoutData(propertiesSectionData);
Composite propertiesGroup = widgetFactory.createComposite(propertiesSection);
GridLayout propertiesGroupLayout = new GridLayout();
propertiesGroupLayout.numColumns = 3;
propertiesGroup.setLayout(propertiesGroupLayout);
propertiesSection.setClient(propertiesGroup);
return propertiesGroup;
}
protected Composite createNameText(FormToolkit widgetFactory, Composite parent) {
createDescription(parent, EntityrelationViewsRepository.Identifier.Properties.name, EntityrelationMessages.IdentifierPropertiesEditionPart_NameLabel);
name = widgetFactory.createText(parent, ""); //$NON-NLS-1$
name.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
widgetFactory.paintBordersFor(parent);
GridData nameData = new GridData(GridData.FILL_HORIZONTAL);
name.setLayoutData(nameData);
name.addFocusListener(new FocusAdapter() {
/**
* @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(
IdentifierPropertiesEditionPartForm.this,
EntityrelationViewsRepository.Identifier.Properties.name,
PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
propertiesEditionComponent
.firePropertiesChanged(new PropertiesEditionEvent(
IdentifierPropertiesEditionPartForm.this,
EntityrelationViewsRepository.Identifier.Properties.name,
PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_LOST,
null, name.getText()));
}
}
/**
* @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent)
*/
@Override
public void focusGained(FocusEvent e) {
if (propertiesEditionComponent != null) {
propertiesEditionComponent
.firePropertiesChanged(new PropertiesEditionEvent(
IdentifierPropertiesEditionPartForm.this,
null,
PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_GAINED,
null, null));
}
}
});
name.addKeyListener(new KeyAdapter() {
/**
* @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(IdentifierPropertiesEditionPartForm.this, EntityrelationViewsRepository.Identifier.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
}
}
});
EditingUtils.setID(name, EntityrelationViewsRepository.Identifier.Properties.name);
EditingUtils.setEEFtype(name, "eef::Text"); //$NON-NLS-1$
FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(EntityrelationViewsRepository.Identifier.Properties.name, EntityrelationViewsRepository.FORM_KIND), null); //$NON-NLS-1$
return parent;
}
/**
*
*/
protected Composite createAttributesReferencesTable(FormToolkit widgetFactory, Composite parent) {
Label attributesLabel = createDescription(parent, EntityrelationViewsRepository.Identifier.Properties.attributes, EntityrelationMessages.IdentifierPropertiesEditionPart_AttributesLabel);
GridData attributesLabelData = new GridData();
attributesLabelData.horizontalSpan = 3;
attributesLabel.setLayoutData(attributesLabelData);
attributes = createAttributesViewer(parent, widgetFactory, adapterFactory);
GridData attributesData = new GridData(GridData.FILL_HORIZONTAL);
attributesData.horizontalSpan = 2;
attributesData.minimumHeight = 120;
attributesData.heightHint = 120;
attributes.getTable().setLayoutData(attributesData);
EditingUtils.setID(attributes.getTable(), EntityrelationViewsRepository.Identifier.Properties.attributes);
EditingUtils.setEEFtype(attributes.getTable(), "eef::ReferencesTable::field"); //$NON-NLS-1$
createAttributesControlPanel(parent, widgetFactory);
return parent;
}
/**
*
*/
protected TableViewer createAttributesViewer(Composite container, FormToolkit widgetFactory, AdapterFactory adapter) {
org.eclipse.swt.widgets.Table table = widgetFactory.createTable(container, SWT.FULL_SELECTION);
table.setHeaderVisible(true);
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = GridData.FILL;
table.setLayoutData(gd);
table.setLinesVisible(true);
// Start of user code for table attributes s columns definition
TableColumn name = new TableColumn(table, SWT.NONE);
name.setWidth(80);
name.setText("Label"); //$NON-NLS-1$
// End of user code
TableViewer result = new TableViewer(table);
result.setLabelProvider(new ITableLabelProvider() {
// Start of user code for table attributes label provider
public String getColumnText(Object object, int columnIndex) {
AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
if (object instanceof EObject) {
switch (columnIndex) {
case 0:
return labelProvider.getText(object);
}
}
return ""; //$NON-NLS-1$
}
// End of user code
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void removeListener(ILabelProviderListener listener) {
}
});
return result;
}
/**
*
*/
protected void createAttributesControlPanel(Composite container, FormToolkit widgetFactory) {
Composite result = widgetFactory.createComposite(container, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
result.setLayout(layout);
addAttributes = widgetFactory.createButton(result, EntityrelationMessages.PropertiesEditionPart_AddListViewerLabel, SWT.NONE);
GridData addData = new GridData(GridData.FILL_HORIZONTAL);
addAttributes.setLayoutData(addData);
addAttributes.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*
*/
public void widgetSelected(SelectionEvent e) {
addAttributes();
}
});
EditingUtils.setID(addAttributes, EntityrelationViewsRepository.Identifier.Properties.attributes);
EditingUtils.setEEFtype(addAttributes, "eef::ReferencesTable::addbutton"); //$NON-NLS-1$
removeAttributes = widgetFactory.createButton(result, EntityrelationMessages.PropertiesEditionPart_RemoveListViewerLabel, SWT.NONE);
GridData removeData = new GridData(GridData.FILL_HORIZONTAL);
removeAttributes.setLayoutData(removeData);
removeAttributes.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*
*/
public void widgetSelected(SelectionEvent e) {
if (attributes.getSelection() instanceof IStructuredSelection) {
removeAttributes((IStructuredSelection) attributes.getSelection());
}
}
});
EditingUtils.setID(removeAttributes, EntityrelationViewsRepository.Identifier.Properties.attributes);
EditingUtils.setEEFtype(removeAttributes, "eef::ReferencesTable::removebutton"); //$NON-NLS-1$
}
/**
*
*/
protected void addAttributes() {
EMFModelViewerDialog dialog = new EMFModelViewerDialog(new AdapterFactoryLabelProvider(adapterFactory), attributes.getInput(), attributesFilters, attributesBusinessFilters, false, true) {
public void process(IStructuredSelection selection) {
for (Iterator iter = selection.iterator(); iter.hasNext();) {
EObject elem = (EObject) iter.next();
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(IdentifierPropertiesEditionPartForm.this, EntityrelationViewsRepository.Identifier.Properties.attributes, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
}
}
};
dialog.open();
attributes.refresh();
}
/**
* @param selection the attributes to remove
*
*/
protected void removeAttributes(IStructuredSelection selection) {
for (Iterator iter = selection.iterator(); iter.hasNext();) {
EObject elem = (EObject) iter.next();
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(IdentifierPropertiesEditionPartForm.this, EntityrelationViewsRepository.Identifier.Properties.attributes, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.REMOVE, null, elem));
}
attributes.refresh();
}
protected Composite createCommentsTextarea(FormToolkit widgetFactory, Composite parent) {
Label commentsLabel = createDescription(parent, EntityrelationViewsRepository.Identifier.Properties.comments, EntityrelationMessages.IdentifierPropertiesEditionPart_CommentsLabel);
GridData commentsLabelData = new GridData(GridData.FILL_HORIZONTAL);
commentsLabelData.horizontalSpan = 3;
commentsLabel.setLayoutData(commentsLabelData);
comments = widgetFactory.createText(parent, "", SWT.BORDER | SWT.WRAP | SWT.MULTI | SWT.V_SCROLL); //$NON-NLS-1$
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(
IdentifierPropertiesEditionPartForm.this,
EntityrelationViewsRepository.Identifier.Properties.comments,
PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, comments.getText()));
propertiesEditionComponent
.firePropertiesChanged(new PropertiesEditionEvent(
IdentifierPropertiesEditionPartForm.this,
EntityrelationViewsRepository.Identifier.Properties.comments,
PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_LOST,
null, comments.getText()));
}
}
/**
* @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent)
*/
@Override
public void focusGained(FocusEvent e) {
if (propertiesEditionComponent != null) {
propertiesEditionComponent
.firePropertiesChanged(new PropertiesEditionEvent(
IdentifierPropertiesEditionPartForm.this,
null,
PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_GAINED,
null, null));
}
}
});
EditingUtils.setID(comments, EntityrelationViewsRepository.Identifier.Properties.comments);
EditingUtils.setEEFtype(comments, "eef::Textarea"); //$NON-NLS-1$
FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(EntityrelationViewsRepository.Identifier.Properties.comments, EntityrelationViewsRepository.FORM_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.entityrelation.parts.IdentifierPropertiesEditionPart#getName()
*
*/
public String getName() {
return name.getText();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#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.entityrelation.parts.IdentifierPropertiesEditionPart#initAttributes(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)
*/
public void initAttributes(ReferencesTableSettings settings) {
if (current.eResource() != null && current.eResource().getResourceSet() != null)
this.resourceSet = current.eResource().getResourceSet();
ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
attributes.setContentProvider(contentProvider);
attributes.setInput(settings);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#updateAttributes()
*
*/
public void updateAttributes() {
attributes.refresh();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#addFilterAttributes(ViewerFilter filter)
*
*/
public void addFilterToAttributes(ViewerFilter filter) {
attributesFilters.add(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#addBusinessFilterAttributes(ViewerFilter filter)
*
*/
public void addBusinessFilterToAttributes(ViewerFilter filter) {
attributesBusinessFilters.add(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#isContainedInAttributesTable(EObject element)
*
*/
public boolean isContainedInAttributesTable(EObject element) {
return ((ReferencesTableSettings)attributes.getInput()).contains(element);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#getComments()
*
*/
public String getComments() {
return comments.getText();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.entityrelation.parts.IdentifierPropertiesEditionPart#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 EntityrelationMessages.Identifier_Part_Title;
}
// Start of user code additional methods
// End of user code
}