/**
* Generated with Acceleo
*/
package org.obeonetwork.dsl.database.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.database.Column;
import org.obeonetwork.dsl.database.parts.DatabaseViewsRepository;
import org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart;
import org.obeonetwork.dsl.database.providers.DatabaseMessages;
// End of user code
/**
*
*
*/
public class PrimaryKeyPropertiesEditionPartForm extends SectionPropertiesEditingPart implements IFormPropertiesEditionPart, PrimaryKeyPropertiesEditionPart {
protected Text name;
protected TableViewer columns;
protected Button addColumns;
protected Button removeColumns;
protected List<ViewerFilter> columnsBusinessFilters = new ArrayList<ViewerFilter>();
protected List<ViewerFilter> columnsFilters = new ArrayList<ViewerFilter>();
protected Text comments;
/**
* For {@link ISection} use only.
*/
public PrimaryKeyPropertiesEditionPartForm() { super(); }
/**
* Default constructor
* @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
*
*/
public PrimaryKeyPropertiesEditionPartForm(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 primaryKeyStep = new BindingCompositionSequence(propertiesEditionComponent);
CompositionStep propertiesStep = primaryKeyStep.addStep(DatabaseViewsRepository.PrimaryKey.Properties.class);
propertiesStep.addStep(DatabaseViewsRepository.PrimaryKey.Properties.name);
propertiesStep.addStep(DatabaseViewsRepository.PrimaryKey.Properties.columns);
propertiesStep.addStep(DatabaseViewsRepository.PrimaryKey.Properties.comments);
composer = new PartComposer(primaryKeyStep) {
@Override
public Composite addToPart(Composite parent, Object key) {
if (key == DatabaseViewsRepository.PrimaryKey.Properties.class) {
return createPropertiesGroup(widgetFactory, parent);
}
if (key == DatabaseViewsRepository.PrimaryKey.Properties.name) {
return createNameText(widgetFactory, parent);
}
if (key == DatabaseViewsRepository.PrimaryKey.Properties.columns) {
return createColumnsReferencesTable(widgetFactory, parent);
}
if (key == DatabaseViewsRepository.PrimaryKey.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(DatabaseMessages.PrimaryKeyPropertiesEditionPart_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, DatabaseViewsRepository.PrimaryKey.Properties.name, DatabaseMessages.PrimaryKeyPropertiesEditionPart_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(
PrimaryKeyPropertiesEditionPartForm.this,
DatabaseViewsRepository.PrimaryKey.Properties.name,
PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
propertiesEditionComponent
.firePropertiesChanged(new PropertiesEditionEvent(
PrimaryKeyPropertiesEditionPartForm.this,
DatabaseViewsRepository.PrimaryKey.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(
PrimaryKeyPropertiesEditionPartForm.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(PrimaryKeyPropertiesEditionPartForm.this, DatabaseViewsRepository.PrimaryKey.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
}
}
});
EditingUtils.setID(name, DatabaseViewsRepository.PrimaryKey.Properties.name);
EditingUtils.setEEFtype(name, "eef::Text"); //$NON-NLS-1$
FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(DatabaseViewsRepository.PrimaryKey.Properties.name, DatabaseViewsRepository.FORM_KIND), null); //$NON-NLS-1$
return parent;
}
/**
*
*/
protected Composite createColumnsReferencesTable(FormToolkit widgetFactory, Composite parent) {
Label columnsLabel = createDescription(parent, DatabaseViewsRepository.PrimaryKey.Properties.columns, DatabaseMessages.PrimaryKeyPropertiesEditionPart_ColumnsLabel);
GridData columnsLabelData = new GridData();
columnsLabelData.horizontalSpan = 3;
columnsLabel.setLayoutData(columnsLabelData);
columns = createColumnsViewer(parent, widgetFactory, adapterFactory);
GridData columnsData = new GridData(GridData.FILL_HORIZONTAL);
columnsData.horizontalSpan = 2;
columnsData.minimumHeight = 120;
columnsData.heightHint = 120;
columns.getTable().setLayoutData(columnsData);
EditingUtils.setID(columns.getTable(), DatabaseViewsRepository.PrimaryKey.Properties.columns);
EditingUtils.setEEFtype(columns.getTable(), "eef::ReferencesTable::field"); //$NON-NLS-1$
createColumnsControlPanel(parent, widgetFactory);
return parent;
}
/**
*
*/
protected TableViewer createColumnsViewer(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 columns s columns definition
TableColumn name = new TableColumn(table, SWT.NONE);
name.setWidth(160);
name.setText("Label"); //$NON-NLS-1$
TableColumn type = new TableColumn(table, SWT.NONE);
type.setWidth(160);
type.setText("Type"); //$NON-NLS-1$
// End of user code
TableViewer result = new TableViewer(table);
result.setLabelProvider(new ITableLabelProvider() {
// Start of user code for table columns label provider
public String getColumnText(Object object, int columnIndex) {
AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
if (object instanceof EObject) {
Column column = (Column)object;
switch (columnIndex) {
case 0:
return column.getName();
case 1:
return labelProvider.getText(column.getType());
}
}
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 createColumnsControlPanel(Composite container, FormToolkit widgetFactory) {
Composite result = widgetFactory.createComposite(container, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
result.setLayout(layout);
addColumns = widgetFactory.createButton(result, DatabaseMessages.PropertiesEditionPart_AddListViewerLabel, SWT.NONE);
GridData addData = new GridData(GridData.FILL_HORIZONTAL);
addColumns.setLayoutData(addData);
addColumns.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*
*/
public void widgetSelected(SelectionEvent e) {
addColumns();
}
});
EditingUtils.setID(addColumns, DatabaseViewsRepository.PrimaryKey.Properties.columns);
EditingUtils.setEEFtype(addColumns, "eef::ReferencesTable::addbutton"); //$NON-NLS-1$
removeColumns = widgetFactory.createButton(result, DatabaseMessages.PropertiesEditionPart_RemoveListViewerLabel, SWT.NONE);
GridData removeData = new GridData(GridData.FILL_HORIZONTAL);
removeColumns.setLayoutData(removeData);
removeColumns.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*
*/
public void widgetSelected(SelectionEvent e) {
if (columns.getSelection() instanceof IStructuredSelection) {
removeColumns((IStructuredSelection) columns.getSelection());
}
}
});
EditingUtils.setID(removeColumns, DatabaseViewsRepository.PrimaryKey.Properties.columns);
EditingUtils.setEEFtype(removeColumns, "eef::ReferencesTable::removebutton"); //$NON-NLS-1$
}
/**
*
*/
protected void addColumns() {
EMFModelViewerDialog dialog = new EMFModelViewerDialog(new AdapterFactoryLabelProvider(adapterFactory), columns.getInput(), columnsFilters, columnsBusinessFilters, false, true) {
public void process(IStructuredSelection selection) {
for (Iterator iter = selection.iterator(); iter.hasNext();) {
EObject elem = (EObject) iter.next();
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PrimaryKeyPropertiesEditionPartForm.this, DatabaseViewsRepository.PrimaryKey.Properties.columns, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, elem));
}
}
};
dialog.open();
columns.refresh();
}
/**
* @param selection the columns to remove
*
*/
protected void removeColumns(IStructuredSelection selection) {
for (Iterator iter = selection.iterator(); iter.hasNext();) {
EObject elem = (EObject) iter.next();
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PrimaryKeyPropertiesEditionPartForm.this, DatabaseViewsRepository.PrimaryKey.Properties.columns, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.REMOVE, null, elem));
}
columns.refresh();
}
protected Composite createCommentsTextarea(FormToolkit widgetFactory, Composite parent) {
Label commentsLabel = createDescription(parent, DatabaseViewsRepository.PrimaryKey.Properties.comments, DatabaseMessages.PrimaryKeyPropertiesEditionPart_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(
PrimaryKeyPropertiesEditionPartForm.this,
DatabaseViewsRepository.PrimaryKey.Properties.comments,
PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, comments.getText()));
propertiesEditionComponent
.firePropertiesChanged(new PropertiesEditionEvent(
PrimaryKeyPropertiesEditionPartForm.this,
DatabaseViewsRepository.PrimaryKey.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(
PrimaryKeyPropertiesEditionPartForm.this,
null,
PropertiesEditionEvent.FOCUS_CHANGED, PropertiesEditionEvent.FOCUS_GAINED,
null, null));
}
}
});
EditingUtils.setID(comments, DatabaseViewsRepository.PrimaryKey.Properties.comments);
EditingUtils.setEEFtype(comments, "eef::Textarea"); //$NON-NLS-1$
FormUtils.createHelpButton(widgetFactory, parent, propertiesEditionComponent.getHelpContent(DatabaseViewsRepository.PrimaryKey.Properties.comments, DatabaseViewsRepository.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.database.parts.PrimaryKeyPropertiesEditionPart#getName()
*
*/
public String getName() {
return name.getText();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#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.PrimaryKeyPropertiesEditionPart#initColumns(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)
*/
public void initColumns(ReferencesTableSettings settings) {
if (current.eResource() != null && current.eResource().getResourceSet() != null)
this.resourceSet = current.eResource().getResourceSet();
ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
columns.setContentProvider(contentProvider);
columns.setInput(settings);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#updateColumns()
*
*/
public void updateColumns() {
columns.refresh();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#addFilterColumns(ViewerFilter filter)
*
*/
public void addFilterToColumns(ViewerFilter filter) {
columnsFilters.add(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#addBusinessFilterColumns(ViewerFilter filter)
*
*/
public void addBusinessFilterToColumns(ViewerFilter filter) {
columnsBusinessFilters.add(filter);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#isContainedInColumnsTable(EObject element)
*
*/
public boolean isContainedInColumnsTable(EObject element) {
return ((ReferencesTableSettings)columns.getInput()).contains(element);
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#getComments()
*
*/
public String getComments() {
return comments.getText();
}
/**
* {@inheritDoc}
*
* @see org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart#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.PrimaryKey_Part_Title;
}
// Start of user code additional methods
// End of user code
}