diff options
author | Nicolas FAUVERGUE | 2016-12-16 15:16:06 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-12-16 17:20:59 +0000 |
commit | 5b79cfb1b41f2089508ebda7c82675513fd3620c (patch) | |
tree | 6fdbcfeb9d424ff6dbe05fbd8461be10a0d38b50 /plugins/uml/nattable | |
parent | cc5807c3961121773e939142c9f7bd1717dc12f3 (diff) | |
download | org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.tar.gz org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.tar.xz org.eclipse.papyrus-5b79cfb1b41f2089508ebda7c82675513fd3620c.zip |
Bug 502533: [Property View] Property pages generated for DataType
shall be improved
- Modification of the compliance of the uml.nattable plugin to use
PapyrusObservableValue not deprecated.
Developed by Fanch Bonnabesse.
Change-Id: Ib2c5436de26a256ac136715a58de716bd816da2c
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/uml/nattable')
8 files changed, 675 insertions, 267 deletions
diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath index d0eeb4a7de0..eca7bdba8f0 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> <classpathentry kind="src" path="src"/> -</classpath>
\ No newline at end of file + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs index 94d61f00da6..b3aa6d60f94 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/.settings/org.eclipse.jdt.core.prefs @@ -1,10 +1,10 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF index 8d9d57aee06..645352bee60 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.papyrus.uml.tools;bundle-version="[3.0.0,4.0.0)";vis org.eclipse.papyrus.infra.emf.nattable;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.papyrus.uml.tools.utils;bundle-version="[3.0.0,4.0.0)", org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="[3.0.0,4.0.0)", - org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)" + org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.properties.ui;bundle-version="[2.0.0,3.0.0)" Bundle-Vendor: %Bundle-Vendor Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml index 0ffb58f6eca..bbaaf95c6e0 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/plugin.xml @@ -135,6 +135,10 @@ class="org.eclipse.papyrus.uml.nattable.config.MultiStringCellEditorConfiguration" order="1031"> </cellAxisConfiguration> + <cellAxisConfiguration + class="org.eclipse.papyrus.uml.nattable.config.UMLStereotypeSingleDataTypeCellEditorConfiguration" + order="2"> + </cellAxisConfiguration> </extension> <extension point="org.eclipse.papyrus.infra.services.labelprovider.labelProvider"> diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java new file mode 100644 index 00000000000..b6ed8d7c7ef --- /dev/null +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/config/UMLStereotypeSingleDataTypeCellEditorConfiguration.java @@ -0,0 +1,97 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 502533 + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.nattable.config; + +import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes; +import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry; +import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes; +import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter; +import org.eclipse.nebula.widgets.nattable.style.DisplayMode; +import org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; +import org.eclipse.papyrus.infra.nattable.utils.NattableConfigAttributes; +import org.eclipse.papyrus.uml.nattable.editor.DatatypeDialogCellEditor; +import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils; +import org.eclipse.uml2.uml.DataType; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.PrimitiveType; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Type; + +/** + * The cell editor for UML Datatype declared in the profile. + */ +public class UMLStereotypeSingleDataTypeCellEditorConfiguration implements ICellAxisConfiguration { + + /** + * The identifier. + */ + public static final String ID = "org.eclipse.papyrus.uml.nattable.celleditor.configuration.UMLStereotypeSingleDataTypeCellEditorConfiguration.dialog"; // $NON-NLS-0$ + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.configuration.IPapyrusNatTableConfiguration#getConfigurationId() + */ + @Override + public String getConfigurationId() { + return ID; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.configuration.IPapyrusNatTableConfiguration#getConfigurationDescription() + */ + public String getConfigurationDescription() { + return "This configuration provides a dialog to edit UML datatype"; //$NON-NLS-1$ + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration#handles(org.eclipse.papyrus.infra.nattable.model.nattable.Table, java.lang.Object) + */ + @Override + public boolean handles(final Table table, final Object axisElement) { + boolean result = false; + final String id = AxisUtils.getPropertyId(axisElement); + if (id != null && id.startsWith(UMLTableUtils.PROPERTY_OF_STEREOTYPE_PREFIX)) { + final Property prop = UMLTableUtils.getRealStereotypeProperty(table.getContext(), id); + final Type type = prop.getType(); + // TODO: Need to manage multi-valued datatype (it maybe must be the same cell editor) + if (null != prop && !prop.isMultivalued()) { + result = type instanceof DataType && !(type instanceof Enumeration) && !(type instanceof PrimitiveType); + } + } + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.celleditor.config.ICellAxisConfiguration#configureCellEditor(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry, java.lang.Object, java.lang.String) + */ + @Override + public void configureCellEditor(final IConfigRegistry configRegistry, final Object axis, final String configLabel) { + configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new TextPainter(), DisplayMode.EDIT, configLabel); + + final INattableModelManager modelManager = configRegistry.getConfigAttribute(NattableConfigAttributes.NATTABLE_MODEL_MANAGER_CONFIG_ATTRIBUTE, DisplayMode.NORMAL, NattableConfigAttributes.NATTABLE_MODEL_MANAGER_ID); + configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DatatypeDialogCellEditor(axis, modelManager.getTableAxisElementProvider()), DisplayMode.EDIT, configLabel); + } +} diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java index a4208ba1f48..bfbd6cb553c 100644 --- a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/AbstractUMLMultiValueCellEditor.java @@ -1,260 +1,271 @@ -/*****************************************************************************
- * Copyright (c) 2013, 2014 CEA LIST and others.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 402525
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.nattable.editor;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.nebula.widgets.nattable.NatTable;
-import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor;
-import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider;
-import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
-import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
-import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
-import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectionDialog;
-import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
-import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils;
-import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-
-/**
- *
- * Abstract Cell Editor for MultiValued properties
- *
- * @author Vincent Lorenzo
- *
- */
-public abstract class AbstractUMLMultiValueCellEditor extends AbstractDialogCellEditor {
-
- private Collection<Object> returnedValue;
-
- /**
- * the table axis element provider
- */
- protected ITableAxisElementProvider manager;
-
- /**
- * the axis element
- */
- private Object axisElement;
-
- /**
- *
- * Constructor.
- *
- * @param axisElement
- * the axis element
- * @param elementProvider
- * the table axis element provider
- */
- protected AbstractUMLMultiValueCellEditor(final Object axisElement, final ITableAxisElementProvider elementProvider) {
- this.manager = elementProvider;
- this.axisElement = axisElement;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#open()
- *
- * @return
- */
- @Override
- public int open() {
- int result = ((MultipleValueSelectionDialog) this.dialog).open();
- if (manager instanceof IAdaptable) {
- NatTable nattable = (NatTable) ((IAdaptable) manager).getAdapter(NatTable.class);
- if (nattable != null && !nattable.isDisposed()) {
- nattable.forceFocus();
- }
- }
- return result;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#createDialogInstance()
- *
- * @return
- */
- @Override
- public Object createDialogInstance() {
- int columnIndex = this.layerCell.getColumnIndex();
- int rowIndex = this.layerCell.getRowIndex();
- Object row = this.manager.getRowElement(rowIndex);
- Object column = this.manager.getColumnElement(columnIndex);
- row = AxisUtils.getRepresentedElement(row);
- column = AxisUtils.getRepresentedElement(column);
- Element editedElement = null;
- Object feature = null;
- if (row instanceof EObject && column == this.axisElement) {
- editedElement = (Element) row;
- feature = column;
- } else {
- editedElement = (Element) column;
- feature = row;
- }
-
- EStructuralFeature realFeature = null;
- EObject realEditedObject = null;
- Stereotype stereotype = null;
- List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null;
- if (feature instanceof EStructuralFeature) {
- realFeature = (EStructuralFeature) feature;
- realEditedObject = editedElement;
- } else {
- final String id = AxisUtils.getPropertyId(this.axisElement);
- stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id);
- stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0);
- realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0));
- Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id);
- realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName());
- }
- if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) {
- // TODO : not yet managed
- } else {
- this.dialog = createDialog(realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet());
- }
- return this.dialog;
- }
-
- /**
- *
- * @param realEditedObject
- * the real edited object : the stereotype application or the edited Element
- * @param realFeature
- * the real edited feature : the feature of the stereotype application or the the feature of the edited Element
- * @param stereotype
- * the stereotype if we are are editing a stereotype application
- * @param resourceSet
- * the resourceset
- * @return
- * the dialog to edit the property
- */
- protected Object createDialog(EObject realEditedObject, EStructuralFeature realFeature, Stereotype stereotype, ResourceSet resourceSet) {
- final UMLContentProvider p = new UMLContentProvider(realEditedObject, realFeature, stereotype, resourceSet);
- final String title = realFeature.getName();
- final boolean unique = realFeature.isUnique();
- final boolean ordered = realFeature.isOrdered();
- final int upperBound = realFeature.getUpperBound();
- final Object value = realEditedObject.eGet(realFeature);
- IElementSelector selector = getElementSelector(unique, new UMLLabelProvider(), p);
- final MultipleValueSelectionDialog dialog = new MultipleValueSelectionDialog(Display.getCurrent().getActiveShell(), selector, title, unique, ordered, upperBound) {
-
- @Override
- protected void okPressed() {
- super.okPressed();
- Collection<Object> newValue = new ArrayList<Object>();
- Object[] result = this.getResult();
- for (Object object : result) {
- newValue.add(object);
-
- }
- AbstractUMLMultiValueCellEditor.this.returnedValue = newValue;
- AbstractUMLMultiValueCellEditor.this.editHandler.commit(newValue, MoveDirectionEnum.NONE);
- }
-
- };
- dialog.setContextElement(realEditedObject);
- dialog.setLabelProvider(new UMLLabelProvider());
- if (value != null && value instanceof Collection) {
- Collection<?> coll = (Collection<?>) value;
- if (!coll.isEmpty()) {
- dialog.setInitialSelections(coll.toArray());
- }
- }
-
- ReferenceValueFactory factory = getFactory();
- if (factory != null) {
- dialog.setFactory(factory);
- }
-
- return dialog;
- }
-
- /**
- *
- * @return
- * the reference factory used to create to element
- */
- protected abstract ReferenceValueFactory getFactory();
-
- /**
- *
- * @param isUnique
- * @param labelProvider
- * @param contentProvider
- * @return
- * the element selector to use in the dialog
- */
- protected abstract IElementSelector getElementSelector(final boolean isUnique, final ILabelProvider labelProvider, final IStaticContentProvider contentProvider);
-
- @Override
- public Object getDialogInstance() {
- return this.dialog;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#getEditorValue()
- *
- * @return
- */
- @Override
- public Object getEditorValue() {
- return this.returnedValue;
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#setEditorValue(java.lang.Object)
- *
- * @param value
- */
- @Override
- public void setEditorValue(Object value) {
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#close()
- *
- */
- @Override
- public void close() {
- }
-
- /**
- *
- * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#isClosed()
- *
- * @return
- */
- @Override
- public boolean isClosed() {
- return false;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013, 2014 CEA LIST and others. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - bug 402525 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.nattable.editor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.nebula.widgets.nattable.NatTable; +import org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor; +import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; +import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider; +import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; +import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectionDialog; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; +import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils; +import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.widgets.Display; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * + * Abstract Cell Editor for MultiValued properties + * + * @author Vincent Lorenzo + * + */ +public abstract class AbstractUMLMultiValueCellEditor extends AbstractDialogCellEditor { + + private Collection<Object> returnedValue; + + /** + * the table axis element provider + */ + protected ITableAxisElementProvider manager; + + /** + * the axis element + */ + private Object axisElement; + + /** + * + * Constructor. + * + * @param axisElement + * the axis element + * @param elementProvider + * the table axis element provider + */ + protected AbstractUMLMultiValueCellEditor(final Object axisElement, final ITableAxisElementProvider elementProvider) { + this.manager = elementProvider; + this.axisElement = axisElement; + } + + /** + * Getter axisElement + * + * @return the axisElement + * @since 3.0 + */ + public Object getAxisElement() { + return axisElement; + } + + /** + * + * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#open() + * + * @return + */ + @Override + public int open() { + int result = ((Dialog) this.dialog).open(); + if (manager instanceof IAdaptable) { + NatTable nattable = (NatTable) ((IAdaptable) manager).getAdapter(NatTable.class); + if (nattable != null && !nattable.isDisposed()) { + nattable.forceFocus(); + } + } + return result; + } + + /** + * + * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#createDialogInstance() + * + * @return + */ + @Override + public Object createDialogInstance() { + int columnIndex = this.layerCell.getColumnIndex(); + int rowIndex = this.layerCell.getRowIndex(); + Object row = this.manager.getRowElement(rowIndex); + Object column = this.manager.getColumnElement(columnIndex); + row = AxisUtils.getRepresentedElement(row); + column = AxisUtils.getRepresentedElement(column); + Element editedElement = null; + Object feature = null; + if (row instanceof EObject && column == this.axisElement) { + editedElement = (Element) row; + feature = column; + } else { + editedElement = (Element) column; + feature = row; + } + + EStructuralFeature realFeature = null; + EObject realEditedObject = null; + Stereotype stereotype = null; + List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null; + if (feature instanceof EStructuralFeature) { + realFeature = (EStructuralFeature) feature; + realEditedObject = editedElement; + } else { + final String id = AxisUtils.getPropertyId(this.axisElement); + stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id); + stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0); + realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0)); + Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id); + realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName()); + } + if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) { + // TODO : not yet managed + } else { + this.dialog = createDialog(realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet()); + } + return this.dialog; + } + + /** + * + * @param realEditedObject + * the real edited object : the stereotype application or the edited Element + * @param realFeature + * the real edited feature : the feature of the stereotype application or the the feature of the edited Element + * @param stereotype + * the stereotype if we are are editing a stereotype application + * @param resourceSet + * the resourceset + * @return + * the dialog to edit the property + */ + protected Object createDialog(EObject realEditedObject, EStructuralFeature realFeature, Stereotype stereotype, ResourceSet resourceSet) { + final UMLContentProvider p = new UMLContentProvider(realEditedObject, realFeature, stereotype, resourceSet); + final String title = realFeature.getName(); + final boolean unique = realFeature.isUnique(); + final boolean ordered = realFeature.isOrdered(); + final int upperBound = realFeature.getUpperBound(); + final Object value = realEditedObject.eGet(realFeature); + IElementSelector selector = getElementSelector(unique, new UMLLabelProvider(), p); + final MultipleValueSelectionDialog dialog = new MultipleValueSelectionDialog(Display.getCurrent().getActiveShell(), selector, title, unique, ordered, upperBound) { + + @Override + protected void okPressed() { + super.okPressed(); + Collection<Object> newValue = new ArrayList<Object>(); + Object[] result = this.getResult(); + for (Object object : result) { + newValue.add(object); + + } + AbstractUMLMultiValueCellEditor.this.returnedValue = newValue; + AbstractUMLMultiValueCellEditor.this.editHandler.commit(newValue, MoveDirectionEnum.NONE); + } + + }; + dialog.setContextElement(realEditedObject); + dialog.setLabelProvider(new UMLLabelProvider()); + if (value != null && value instanceof Collection) { + Collection<?> coll = (Collection<?>) value; + if (!coll.isEmpty()) { + dialog.setInitialSelections(coll.toArray()); + } + } + + ReferenceValueFactory factory = getFactory(); + if (factory != null) { + dialog.setFactory(factory); + } + + return dialog; + } + + /** + * + * @return + * the reference factory used to create to element + */ + protected abstract ReferenceValueFactory getFactory(); + + /** + * + * @param isUnique + * @param labelProvider + * @param contentProvider + * @return + * the element selector to use in the dialog + */ + protected abstract IElementSelector getElementSelector(final boolean isUnique, final ILabelProvider labelProvider, final IStaticContentProvider contentProvider); + + @Override + public Object getDialogInstance() { + return this.dialog; + } + + /** + * + * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#getEditorValue() + * + * @return + */ + @Override + public Object getEditorValue() { + return this.returnedValue; + } + + /** + * + * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#setEditorValue(java.lang.Object) + * + * @param value + */ + @Override + public void setEditorValue(Object value) { + } + + /** + * + * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#close() + * + */ + @Override + public void close() { + } + + /** + * + * @see org.eclipse.nebula.widgets.nattable.edit.gui.AbstractDialogCellEditor#isClosed() + * + * @return + */ + @Override + public boolean isClosed() { + return false; + } + +} diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java new file mode 100644 index 00000000000..ab11c3726cf --- /dev/null +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/DatatypeDialogCellEditor.java @@ -0,0 +1,140 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.nattable.editor; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum; +import org.eclipse.papyrus.infra.nattable.manager.table.ITableAxisElementProvider; +import org.eclipse.papyrus.infra.nattable.utils.AxisUtils; +import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; +import org.eclipse.papyrus.infra.widgets.editors.IElementSelector; +import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider; +import org.eclipse.papyrus.uml.nattable.utils.UMLTableUtils; +import org.eclipse.swt.widgets.Display; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * The cell editor for the DataType with a dialog. + */ +public class DatatypeDialogCellEditor extends AbstractUMLMultiValueCellEditor { + + /** + * Constructor. + * + * @param axisElement + * The axis element. + * @param provider + * The table axis element provider. + */ + public DatatypeDialogCellEditor(final Object axisElement, final ITableAxisElementProvider provider) { + super(axisElement, provider); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#createDialogInstance() + */ + @Override + public Object createDialogInstance() { + int columnIndex = this.layerCell.getColumnIndex(); + int rowIndex = this.layerCell.getRowIndex(); + Object row = this.manager.getRowElement(rowIndex); + Object column = this.manager.getColumnElement(columnIndex); + row = AxisUtils.getRepresentedElement(row); + column = AxisUtils.getRepresentedElement(column); + Element editedElement = null; + Object feature = null; + if (row instanceof EObject && column == getAxisElement()) { + editedElement = (Element) row; + feature = column; + } else { + editedElement = (Element) column; + feature = row; + } + + EStructuralFeature realFeature = null; + EObject realEditedObject = null; + Stereotype stereotype = null; + List<Stereotype> stereotypesWithEditedFeatureAppliedOnElement = null; + if (feature instanceof EStructuralFeature) { + realFeature = (EStructuralFeature) feature; + realEditedObject = editedElement; + } else { + final String id = AxisUtils.getPropertyId(getAxisElement()); + stereotypesWithEditedFeatureAppliedOnElement = UMLTableUtils.getAppliedStereotypesWithThisProperty(editedElement, id); + stereotype = stereotypesWithEditedFeatureAppliedOnElement.get(0); + realEditedObject = editedElement.getStereotypeApplication(stereotypesWithEditedFeatureAppliedOnElement.get(0)); + Property prop = UMLTableUtils.getRealStereotypeProperty(editedElement, id); + realFeature = realEditedObject.eClass().getEStructuralFeature(prop.getName()); + } + if (stereotypesWithEditedFeatureAppliedOnElement != null && stereotypesWithEditedFeatureAppliedOnElement.size() > 1) { + // TODO : not yet managed + } else { + this.dialog = createDialog(realEditedObject, realFeature, stereotype, editedElement.eResource().getResourceSet()); + } + return this.dialog; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#getFactory() + */ + @Override + protected ReferenceValueFactory getFactory() { + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#getElementSelector(boolean, org.eclipse.jface.viewers.ILabelProvider, org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider) + */ + @Override + protected IElementSelector getElementSelector(final boolean isUnique, final ILabelProvider labelProvider, final IStaticContentProvider contentProvider) { + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.uml.nattable.editor.AbstractUMLMultiValueCellEditor#createDialog(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, org.eclipse.uml2.uml.Stereotype, org.eclipse.emf.ecore.resource.ResourceSet) + */ + @Override + protected Object createDialog(final EObject realEditedObject, final EStructuralFeature realFeature, final Stereotype stereotype, final ResourceSet resourceSet) { + return new EObjectTreeDialog(Display.getDefault().getActiveShell(), realEditedObject, realFeature, "DataType Edition") { // $NON-NLS-1$ + @Override + protected void okPressed() { + super.okPressed(); + Collection<Object> newValue = new ArrayList<Object>(); + Object[] result = this.getResult(); + for (Object object : result) { + newValue.add(object); + + } + DatatypeDialogCellEditor.this.editHandler.commit(newValue, MoveDirectionEnum.NONE); + } + }; + } +} diff --git a/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java new file mode 100644 index 00000000000..ae4b9f2e7fc --- /dev/null +++ b/plugins/uml/nattable/org.eclipse.papyrus.uml.nattable/src/org/eclipse/papyrus/uml/nattable/editor/EObjectTreeDialog.java @@ -0,0 +1,155 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.nattable.editor; + +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.properties.ui.modelelement.EObjectStructuredValueFactory; +import org.eclipse.papyrus.infra.services.edit.ui.databinding.PapyrusObservableValue; +import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; +import org.eclipse.papyrus.infra.services.labelprovider.service.impl.LabelProviderServiceImpl; +import org.eclipse.papyrus.infra.tools.databinding.DelegatingObservable; +import org.eclipse.papyrus.infra.ui.emf.dialog.EObjectTreeReferenceValueEditor; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.SelectionDialog; + +/** + * Dialog to display a EObjectTreeReferenceValueEditor + */ +public class EObjectTreeDialog extends SelectionDialog { + + /** + * EObject to edit. + */ + protected EObject editedObject; + + /** + * Feature of the EObject to edit. + */ + protected EStructuralFeature feature; + + /** + * + * Constructor. + * + * @param parentShell + * The parent shell. + * @param editedObject + * The object to edit. + * @param feature + * The structural feature. + */ + public EObjectTreeDialog(Shell parentShell, EObject editedObject, EStructuralFeature feature, String title) { + super(parentShell); + setTitle(title); + setHelpAvailable(false); + this.editedObject = editedObject; + this.feature = feature; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @SuppressWarnings("rawtypes") + @Override + protected Control createDialogArea(final Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + EObjectTreeReferenceValueEditor treeReferenceValueEditor = new EObjectTreeReferenceValueEditor(container, SWT.NONE); + + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(editedObject); + + PapyrusObservableValue papyrusObservableValue = new PapyrusObservableValue(editedObject, feature, editingDomain, GMFtoEMFCommandWrapper::wrap); + + IObservableValue wrap = (IObservableValue) DelegatingObservable.wrap(papyrusObservableValue); + + treeReferenceValueEditor.setModelObservable(wrap); + treeReferenceValueEditor.setLabelProvider(getLabelProviderForEObject(editedObject)); + treeReferenceValueEditor.setProvidersTreeViewer(); + + if (feature instanceof EReference) { + treeReferenceValueEditor.setValueFactory(new EObjectStructuredValueFactory((EReference) feature)); + } + + treeReferenceValueEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + return container; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.dialogs.SelectionDialog#configureShell(org.eclipse.swt.widgets.Shell) + */ + @Override + protected void configureShell(final Shell shell) { + super.configureShell(shell); + shell.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$ + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#getInitialSize() + */ + @Override + protected Point getInitialSize() { + return new Point(800, 600); + } + + /** + * Returns the ILabelProvider for an EObject. + * + * @param eObject + * The object which one search the label provider. + * @return The ILabelProvider for an EObject. + */ + private ILabelProvider getLabelProviderForEObject(final EObject eObject) { + LabelProviderService labelProviderService = new LabelProviderServiceImpl(); + try { + labelProviderService.startService(); + } catch (ServiceException ex) { + Activator.log.error(ex); + } + + return labelProviderService.getLabelProvider(eObject); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.dialogs.SelectionDialog#getResult() + */ + @Override + public Object[] getResult() { + // Return the editedObject for the result + Object[] objects = new Object[1]; + objects[0] = editedObject; + return objects; + } +} |