/**
* Generated with Acceleo
*/
package org.obeonetwork.dsl.database.components;
// Start of user code for imports
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.context.PropertiesEditingContext;
import org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext;
import org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext;
import org.eclipse.emf.eef.runtime.impl.components.SinglePartPropertiesEditingComponent;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.utils.EEFConverterUtil;
import org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy;
import org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy;
import org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.obeonetwork.dsl.database.Column;
import org.obeonetwork.dsl.database.DatabasePackage;
import org.obeonetwork.dsl.database.Table;
import org.obeonetwork.dsl.database.parts.DatabaseViewsRepository;
import org.obeonetwork.dsl.database.parts.TablePropertiesEditionPart;
// End of user code
/**
*
*
*/
public class TableTablePropertiesEditionComponent extends SinglePartPropertiesEditingComponent {
public static String TABLE_PART = "Table"; //$NON-NLS-1$
/**
* Settings for columns ReferencesTable
*/
protected ReferencesTableSettings columnsSettings;
/**
* Default constructor
*
*/
public TableTablePropertiesEditionComponent(PropertiesEditingContext editingContext, EObject table, String editing_mode) {
super(editingContext, table, editing_mode);
parts = new String[] { TABLE_PART };
repositoryKey = DatabaseViewsRepository.class;
partKey = DatabaseViewsRepository.Table.class;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
* org.eclipse.emf.ecore.resource.ResourceSet)
*
*/
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
setInitializing(true);
if (editingPart != null && key == partKey) {
editingPart.setContext(elt, allResource);
final Table table = (Table)elt;
final TablePropertiesEditionPart tablePart = (TablePropertiesEditionPart)editingPart;
// init values
if (table.getName() != null && isAccessible(DatabaseViewsRepository.Table.Properties.name))
tablePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, table.getName()));
if (isAccessible(DatabaseViewsRepository.Table.Properties.columns)) {
columnsSettings = new ReferencesTableSettings(table, DatabasePackage.eINSTANCE.getAbstractTable_Columns());
tablePart.initColumns(columnsSettings);
}
if (table.getComments() != null && isAccessible(DatabaseViewsRepository.Table.Properties.comments))
tablePart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, table.getComments()));
// init filters
if (isAccessible(DatabaseViewsRepository.Table.Properties.columns)) {
tablePart.addFilterToColumns(new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
return (element instanceof String && element.equals("")) || (element instanceof Column); //$NON-NLS-1$
}
});
// Start of user code for additional businessfilters for columns
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
/**
* {@inheritDoc}
* @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#associatedFeature(java.lang.Object)
*/
public EStructuralFeature associatedFeature(Object editorKey) {
if (editorKey == DatabaseViewsRepository.Table.Properties.name) {
return DatabasePackage.eINSTANCE.getNamedElement_Name();
}
if (editorKey == DatabaseViewsRepository.Table.Properties.columns) {
return DatabasePackage.eINSTANCE.getAbstractTable_Columns();
}
if (editorKey == DatabaseViewsRepository.Table.Properties.comments) {
return DatabasePackage.eINSTANCE.getDatabaseElement_Comments();
}
return super.associatedFeature(editorKey);
}
/**
* {@inheritDoc}
* @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
*
*/
public void updateSemanticModel(final IPropertiesEditionEvent event) {
Table table = (Table)semanticObject;
if (DatabaseViewsRepository.Table.Properties.name == event.getAffectedEditor()) {
table.setName((java.lang.String)EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String)event.getNewValue()));
}
if (DatabaseViewsRepository.Table.Properties.columns == event.getAffectedEditor()) {
if (event.getKind() == PropertiesEditionEvent.ADD) {
EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, columnsSettings, editingContext.getAdapterFactory());
PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy policy = provider.getPolicy(context);
if (policy instanceof CreateEditingPolicy) {
policy.execute();
}
}
} else if (event.getKind() == PropertiesEditionEvent.EDIT) {
EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory());
PropertiesEditingProvider provider = (PropertiesEditingProvider)editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy editionPolicy = provider.getPolicy(context);
if (editionPolicy != null) {
editionPolicy.execute();
}
}
} else if (event.getKind() == PropertiesEditionEvent.REMOVE) {
columnsSettings.removeFromReference((EObject) event.getNewValue());
} else if (event.getKind() == PropertiesEditionEvent.MOVE) {
columnsSettings.move(event.getNewIndex(), (Column) event.getNewValue());
}
}
if (DatabaseViewsRepository.Table.Properties.comments == event.getAffectedEditor()) {
table.setComments((java.lang.String)EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String)event.getNewValue()));
}
}
/**
* {@inheritDoc}
* @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updatePart(org.eclipse.emf.common.notify.Notification)
*/
public void updatePart(Notification msg) {
if (editingPart.isVisible()) {
TablePropertiesEditionPart tablePart = (TablePropertiesEditionPart)editingPart;
if (DatabasePackage.eINSTANCE.getNamedElement_Name().equals(msg.getFeature()) && tablePart != null && isAccessible(DatabaseViewsRepository.Table.Properties.name)) {
if (msg.getNewValue() != null) {
tablePart.setName(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, msg.getNewValue()));
} else {
tablePart.setName("");
}
}
if (DatabasePackage.eINSTANCE.getAbstractTable_Columns().equals(msg.getFeature()) && isAccessible(DatabaseViewsRepository.Table.Properties.columns))
tablePart.updateColumns();
if (DatabasePackage.eINSTANCE.getDatabaseElement_Comments().equals(msg.getFeature()) && tablePart != null && isAccessible(DatabaseViewsRepository.Table.Properties.comments)){
if (msg.getNewValue() != null) {
tablePart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, msg.getNewValue()));
} else {
tablePart.setComments("");
}
}
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#isRequired(java.lang.Object, int)
*
*/
public boolean isRequired(Object key, int kind) {
return key == DatabaseViewsRepository.Table.Properties.name || key == DatabaseViewsRepository.PrimaryKey.Properties.name;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
*
*/
public Diagnostic validateValue(IPropertiesEditionEvent event) {
Diagnostic ret = Diagnostic.OK_INSTANCE;
if (event.getNewValue() != null) {
try {
if (DatabaseViewsRepository.Table.Properties.name == event.getAffectedEditor()) {
Object newValue = event.getNewValue();
if (newValue instanceof String) {
newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getNamedElement_Name().getEAttributeType(), (String)newValue);
}
ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getNamedElement_Name().getEAttributeType(), newValue);
}
if (DatabaseViewsRepository.Table.Properties.comments == event.getAffectedEditor()) {
Object newValue = event.getNewValue();
if (newValue instanceof String) {
newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getDatabaseElement_Comments().getEAttributeType(), (String)newValue);
}
ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getDatabaseElement_Comments().getEAttributeType(), newValue);
}
} catch (IllegalArgumentException iae) {
ret = BasicDiagnostic.toDiagnostic(iae);
} catch (WrappedException we) {
ret = BasicDiagnostic.toDiagnostic(we);
}
}
return ret;
}
}