blob: 81ab94076b3011ad64d880afa7729f3e699b08ec [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 Fundación Tecnalia Research & Innovation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Huascar Espinoza - initial API and implementation
* Alejandra Ruíz - initial API and implementation
* Idoya Del Río - initial API and implementation
* Mari Carmen Palacios - initial API and implementation
* Angel López - initial API and implementation
*******************************************************************************/
/**
* Generated with Acceleo
*/
package org.eclipse.opencert.infra.properties.property.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.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.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.referencestable.ReferencesTableContentProvider;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart;
import org.eclipse.opencert.infra.properties.property.parts.PropertyViewsRepository;
import org.eclipse.opencert.infra.properties.property.providers.PropertyMessages;
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.Text;
// End of user code
/**
*
*
*/
public class PropertyModelPropertiesEditionPartImpl extends CompositePropertiesEditionPart implements ISWTPropertiesEditionPart, PropertyModelPropertiesEditionPart {
protected Text id;
protected Text name;
protected Text description;
protected ReferencesTable hasProperty;
protected List<ViewerFilter> hasPropertyBusinessFilters = new ArrayList<ViewerFilter>();
protected List<ViewerFilter> hasPropertyFilters = new ArrayList<ViewerFilter>();
/**
* Default constructor
* @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
*
*/
public PropertyModelPropertiesEditionPartImpl(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 propertyModelStep = new BindingCompositionSequence(propertiesEditionComponent);
CompositionStep propertiesStep = propertyModelStep.addStep(PropertyViewsRepository.PropertyModel.Properties.class);
propertiesStep.addStep(PropertyViewsRepository.PropertyModel.Properties.id);
propertiesStep.addStep(PropertyViewsRepository.PropertyModel.Properties.name);
propertiesStep.addStep(PropertyViewsRepository.PropertyModel.Properties.description);
propertiesStep.addStep(PropertyViewsRepository.PropertyModel.Properties.hasProperty);
composer = new PartComposer(propertyModelStep) {
@Override
public Composite addToPart(Composite parent, Object key) {
if (key == PropertyViewsRepository.PropertyModel.Properties.class) {
return createPropertiesGroup(parent);
}
if (key == PropertyViewsRepository.PropertyModel.Properties.id) {
return createIdText(parent);
}
if (key == PropertyViewsRepository.PropertyModel.Properties.name) {
return createNameText(parent);
}
if (key == PropertyViewsRepository.PropertyModel.Properties.description) {
return createDescriptionText(parent);
}
if (key == PropertyViewsRepository.PropertyModel.Properties.hasProperty) {
return createHasPropertyAdvancedTableComposition(parent);
}
return parent;
}
};
composer.compose(view);
}
/**
*
*/
protected Composite createPropertiesGroup(Composite parent) {
Group propertiesGroup = new Group(parent, SWT.NONE);
propertiesGroup.setText(PropertyMessages.PropertyModelPropertiesEditionPart_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 createIdText(Composite parent) {
createDescription(parent, PropertyViewsRepository.PropertyModel.Properties.id, PropertyMessages.PropertyModelPropertiesEditionPart_IdLabel);
id = SWTUtils.createScrollableText(parent, SWT.BORDER);
GridData idData = new GridData(GridData.FILL_HORIZONTAL);
id.setLayoutData(idData);
id.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(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.id, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, id.getText()));
}
});
id.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(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.id, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, id.getText()));
}
}
});
EditingUtils.setID(id, PropertyViewsRepository.PropertyModel.Properties.id);
EditingUtils.setEEFtype(id, "eef::Text"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(PropertyViewsRepository.PropertyModel.Properties.id, PropertyViewsRepository.SWT_KIND), null); //$NON-NLS-1$
// Start of user code for createIdText
// End of user code
return parent;
}
protected Composite createNameText(Composite parent) {
createDescription(parent, PropertyViewsRepository.PropertyModel.Properties.name, PropertyMessages.PropertyModelPropertiesEditionPart_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(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.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(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.name, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, name.getText()));
}
}
});
EditingUtils.setID(name, PropertyViewsRepository.PropertyModel.Properties.name);
EditingUtils.setEEFtype(name, "eef::Text"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(PropertyViewsRepository.PropertyModel.Properties.name, PropertyViewsRepository.SWT_KIND), null); //$NON-NLS-1$
// Start of user code for createNameText
// End of user code
return parent;
}
protected Composite createDescriptionText(Composite parent) {
createDescription(parent, PropertyViewsRepository.PropertyModel.Properties.description, PropertyMessages.PropertyModelPropertiesEditionPart_DescriptionLabel);
description = SWTUtils.createScrollableText(parent, SWT.BORDER);
GridData descriptionData = new GridData(GridData.FILL_HORIZONTAL);
description.setLayoutData(descriptionData);
description.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(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.description, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, description.getText()));
}
});
description.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(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.description, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.SET, null, description.getText()));
}
}
});
EditingUtils.setID(description, PropertyViewsRepository.PropertyModel.Properties.description);
EditingUtils.setEEFtype(description, "eef::Text"); //$NON-NLS-1$
SWTUtils.createHelpButton(parent, propertiesEditionComponent.getHelpContent(PropertyViewsRepository.PropertyModel.Properties.description, PropertyViewsRepository.SWT_KIND), null); //$NON-NLS-1$
// Start of user code for createDescriptionText
// End of user code
return parent;
}
/**
* @param container
*
*/
protected Composite createHasPropertyAdvancedTableComposition(Composite parent) {
this.hasProperty = new ReferencesTable(getDescription(PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertyMessages.PropertyModelPropertiesEditionPart_HasPropertyLabel), new ReferencesTableListener() {
public void handleAdd() {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, null));
hasProperty.refresh();
}
public void handleEdit(EObject element) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, element));
hasProperty.refresh();
}
public void handleMove(EObject element, int oldIndex, int newIndex) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.MOVE, element, newIndex));
hasProperty.refresh();
}
public void handleRemove(EObject element) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.REMOVE, null, element));
hasProperty.refresh();
}
public void navigateTo(EObject element) { }
});
for (ViewerFilter filter : this.hasPropertyFilters) {
this.hasProperty.addFilter(filter);
}
this.hasProperty.setHelpText(propertiesEditionComponent.getHelpContent(PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertyViewsRepository.SWT_KIND));
this.hasProperty.createControls(parent);
this.hasProperty.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.item != null && e.item.getData() instanceof EObject) {
propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(PropertyModelPropertiesEditionPartImpl.this, PropertyViewsRepository.PropertyModel.Properties.hasProperty, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.SELECTION_CHANGED, null, e.item.getData()));
}
}
});
GridData hasPropertyData = new GridData(GridData.FILL_HORIZONTAL);
hasPropertyData.horizontalSpan = 3;
this.hasProperty.setLayoutData(hasPropertyData);
this.hasProperty.setLowerBound(0);
this.hasProperty.setUpperBound(-1);
hasProperty.setID(PropertyViewsRepository.PropertyModel.Properties.hasProperty);
hasProperty.setEEFType("eef::AdvancedTableComposition"); //$NON-NLS-1$
// Start of user code for createHasPropertyAdvancedTableComposition
// 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.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#getId()
*
*/
public String getId() {
return id.getText();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#setId(String newValue)
*
*/
public void setId(String newValue) {
if (newValue != null) {
id.setText(newValue);
} else {
id.setText(""); //$NON-NLS-1$
}
boolean eefElementEditorReadOnlyState = isReadOnly(PropertyViewsRepository.PropertyModel.Properties.id);
if (eefElementEditorReadOnlyState && id.isEnabled()) {
id.setEnabled(false);
id.setToolTipText(PropertyMessages.PropertyModel_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !id.isEnabled()) {
id.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#getName()
*
*/
public String getName() {
return name.getText();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#setName(String newValue)
*
*/
public void setName(String newValue) {
if (newValue != null) {
name.setText(newValue);
} else {
name.setText(""); //$NON-NLS-1$
}
boolean eefElementEditorReadOnlyState = isReadOnly(PropertyViewsRepository.PropertyModel.Properties.name);
if (eefElementEditorReadOnlyState && name.isEnabled()) {
name.setEnabled(false);
name.setToolTipText(PropertyMessages.PropertyModel_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !name.isEnabled()) {
name.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#getDescription()
*
*/
public String getDescription() {
return description.getText();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#setDescription(String newValue)
*
*/
public void setDescription(String newValue) {
if (newValue != null) {
description.setText(newValue);
} else {
description.setText(""); //$NON-NLS-1$
}
boolean eefElementEditorReadOnlyState = isReadOnly(PropertyViewsRepository.PropertyModel.Properties.description);
if (eefElementEditorReadOnlyState && description.isEnabled()) {
description.setEnabled(false);
description.setToolTipText(PropertyMessages.PropertyModel_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !description.isEnabled()) {
description.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#initHasProperty(EObject current, EReference containingFeature, EReference feature)
*/
public void initHasProperty(ReferencesTableSettings settings) {
if (current.eResource() != null && current.eResource().getResourceSet() != null)
this.resourceSet = current.eResource().getResourceSet();
ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
hasProperty.setContentProvider(contentProvider);
hasProperty.setInput(settings);
boolean eefElementEditorReadOnlyState = isReadOnly(PropertyViewsRepository.PropertyModel.Properties.hasProperty);
if (eefElementEditorReadOnlyState && hasProperty.isEnabled()) {
hasProperty.setEnabled(false);
hasProperty.setToolTipText(PropertyMessages.PropertyModel_ReadOnly);
} else if (!eefElementEditorReadOnlyState && !hasProperty.isEnabled()) {
hasProperty.setEnabled(true);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#updateHasProperty()
*
*/
public void updateHasProperty() {
hasProperty.refresh();
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#addFilterHasProperty(ViewerFilter filter)
*
*/
public void addFilterToHasProperty(ViewerFilter filter) {
hasPropertyFilters.add(filter);
if (this.hasProperty != null) {
this.hasProperty.addFilter(filter);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#addBusinessFilterHasProperty(ViewerFilter filter)
*
*/
public void addBusinessFilterToHasProperty(ViewerFilter filter) {
hasPropertyBusinessFilters.add(filter);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.opencert.infra.properties.property.parts.PropertyModelPropertiesEditionPart#isContainedInHasPropertyTable(EObject element)
*
*/
public boolean isContainedInHasPropertyTable(EObject element) {
return ((ReferencesTableSettings)hasProperty.getInput()).contains(element);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle()
*
*/
public String getTitle() {
return PropertyMessages.PropertyModel_Part_Title;
}
// Start of user code additional methods
// End of user code
}